Doxygen
Loading...
Searching...
No Matches
LatexCodeGenerator Class Reference

Generator for LaTeX code fragments. More...

#include <src/latexgen.h>

+ Inheritance diagram for LatexCodeGenerator:
+ Collaboration diagram for LatexCodeGenerator:

Public Member Functions

 LatexCodeGenerator (TextStream *t, const QCString &relPath, const QCString &sourceFile)
 
 LatexCodeGenerator (TextStream *t)
 
void setTextStream (TextStream *t)
 
OutputType type () const override
 
std::unique_ptr< OutputCodeIntfclone () override
 
void codify (const QCString &text) override
 
void stripCodeComments (bool b) override
 
void startSpecialComment () override
 
void endSpecialComment () override
 
void setStripIndentAmount (size_t amount) override
 
void writeCodeLink (CodeSymbolType type, const QCString &ref, const QCString &file, const QCString &anchor, const QCString &name, const QCString &tooltip) override
 
void writeTooltip (const QCString &, const DocLinkInfo &, const QCString &, const QCString &, const SourceLinkInfo &, const SourceLinkInfo &) override
 
void writeLineNumber (const QCString &, const QCString &, const QCString &, int, bool) override
 
void startCodeLine (int) override
 
void endCodeLine () override
 
void startFontClass (const QCString &) override
 
void endFontClass () override
 
void writeCodeAnchor (const QCString &) override
 
void startCodeFragment (const QCString &style) override
 
void endCodeFragment (const QCString &style) override
 
void startFold (int, const QCString &, const QCString &) override
 
void endFold () override
 
void incUsedTableLevel ()
 
void decUsedTableLevel ()
 
int usedTableLevel () const
 
void setRelativePath (const QCString &path)
 
void setSourceFileName (const QCString &sourceFileName)
 
void setInsideTabbing (bool b)
 
bool insideTabbing () const
 
- Public Member Functions inherited from OutputCodeIntf
 OutputCodeIntf ()=default
 

Private Member Functions

void _writeCodeLink (const QCString &className, const QCString &ref, const QCString &file, const QCString &anchor, const QCString &name, const QCString &tooltip)
 
void docify (const QCString &str)
 

Private Attributes

bool m_streamSet = false
 
TextStreamm_t
 
QCString m_relPath
 
QCString m_sourceFileName
 
size_t m_col = 0
 
bool m_doxyCodeLineOpen = false
 
int m_usedTableLevel = 0
 
bool m_insideTabbing = false
 
bool m_stripCodeComments = false
 
bool m_hide = false
 
size_t m_stripIndentAmount = 0
 

Detailed Description

Generator for LaTeX code fragments.

Definition at line 27 of file latexgen.h.

Constructor & Destructor Documentation

◆ LatexCodeGenerator() [1/2]

LatexCodeGenerator::LatexCodeGenerator ( TextStream * t,
const QCString & relPath,
const QCString & sourceFile )

Definition at line 57 of file latexgen.cpp.

58 : m_t(t), m_relPath(relPath), m_sourceFileName(sourceFileName)
59{
60}
TextStream * m_t
Definition latexgen.h:80
QCString m_sourceFileName
Definition latexgen.h:82
QCString m_relPath
Definition latexgen.h:81

References m_relPath, m_sourceFileName, and m_t.

◆ LatexCodeGenerator() [2/2]

LatexCodeGenerator::LatexCodeGenerator ( TextStream * t)

Definition at line 62 of file latexgen.cpp.

62 : m_t(t)
63{
64}

References m_t.

Member Function Documentation

◆ _writeCodeLink()

void LatexCodeGenerator::_writeCodeLink ( const QCString & className,
const QCString & ref,
const QCString & file,
const QCString & anchor,
const QCString & name,
const QCString & tooltip )
private

◆ clone()

std::unique_ptr< OutputCodeIntf > LatexCodeGenerator::clone ( )
inlineoverridevirtual

Implements OutputCodeIntf.

Definition at line 35 of file latexgen.h.

35{ return std::make_unique<LatexCodeGenerator>(*this); }

◆ codify()

void LatexCodeGenerator::codify ( const QCString & text)
overridevirtual

Implements OutputCodeIntf.

Definition at line 76 of file latexgen.cpp.

77{
78 if (!str.isEmpty())
79 {
80 const char *p=str.data();
81 char c = 0;
82 //char cs[5];
83 int tabSize = Config_getInt(TAB_SIZE);
84 static THREAD_LOCAL char *result = nullptr;
85 static THREAD_LOCAL int lresult = 0;
86 if (m_hide) // only update column count
87 {
89 }
90 else // actually output content and keep track of m_col
91 {
92 while ((c=*p))
93 {
94 switch(c)
95 {
96 case 0x0c: p++; // remove ^L
97 break;
98 case ' ': if (m_col>=m_stripIndentAmount)
99 {
100 *m_t << (m_doxyCodeLineOpen ? "\\ " : " ");
101 }
102 m_col++;
103 p++;
104 break;
105 case '^': *m_t <<"\\string^";
106 m_col++;
107 p++;
108 break;
109 case '`': *m_t <<"\\`{}";
110 m_col++;
111 p++;
112 break;
113 case '\t': {
114 int spacesToNextTabStop = tabSize - (m_col%tabSize);
115 while (spacesToNextTabStop--)
116 {
118 {
119 *m_t << (m_doxyCodeLineOpen ? "\\ " : " ");
120 }
121 m_col++;
122 }
123 p++;
124 }
125 break;
126 case '\n': *m_t << '\n';
127 m_col=0;
128 p++;
129 break;
130 default:
131 {
132 int i=0;
133
134#undef COPYCHAR
135// helper macro to copy a single utf8 character, dealing with multibyte chars.
136#define COPYCHAR() do { \
137 int bytes = getUTF8CharNumBytes(c); \
138 if (lresult < (i + bytes + 1)) \
139 { \
140 lresult += 512; \
141 result = static_cast<char *>(realloc(result, lresult)); \
142 } \
143 for (int j=0; j<bytes && *p; j++) \
144 { \
145 result[i++]=*p++; \
146 } \
147 m_col++; \
148 } while(0)
149
150 // gather characters until we find whitespace or another special character
151 COPYCHAR();
152 while ((c=*p) &&
153 c!=0x0c && c!='\t' && c!='\n' && c!=' ' && c!='^'
154 )
155 {
156 COPYCHAR();
157 }
158 result[i]=0; // add terminator
159 filterLatexString(*m_t,result,
160 m_insideTabbing, // insideTabbing
161 true, // insidePre
162 false, // insideItem
163 m_usedTableLevel>0, // insideTable
164 false // keepSpaces
165 );
166 }
167 break;
168 }
169 }
170 }
171 }
172}
size_t m_stripIndentAmount
Definition latexgen.h:89
bool m_doxyCodeLineOpen
Definition latexgen.h:84
#define Config_getInt(name)
Definition config.h:34
#define THREAD_LOCAL
Definition doxygen.h:30
#define COPYCHAR()
void filterLatexString(TextStream &t, const QCString &str, bool insideTabbing, bool insidePre, bool insideItem, bool insideTable, bool keepSpaces, const bool retainNewline=false)
size_t updateColumnCount(const char *s, size_t col)
Definition util.cpp:7208

References Config_getInt, COPYCHAR, QCString::data(), filterLatexString(), QCString::isEmpty(), m_col, m_doxyCodeLineOpen, m_hide, m_insideTabbing, m_stripIndentAmount, m_t, m_usedTableLevel, THREAD_LOCAL, and updateColumnCount().

Referenced by endCodeLine(), writeCodeLink(), and writeLineNumber().

◆ decUsedTableLevel()

void LatexCodeGenerator::decUsedTableLevel ( )
inline

Definition at line 65 of file latexgen.h.

References m_usedTableLevel.

◆ docify()

void LatexCodeGenerator::docify ( const QCString & str)
private

◆ endCodeFragment()

void LatexCodeGenerator::endCodeFragment ( const QCString & style)
overridevirtual

Implements OutputCodeIntf.

Definition at line 306 of file latexgen.cpp.

307{
308 //endCodeLine checks is there is still an open code line, if so closes it.
309 endCodeLine();
310
311 *m_t << "\\end{" << style << "}\n";
312}
void endCodeLine() override
Definition latexgen.cpp:278

References endCodeLine(), and m_t.

◆ endCodeLine()

void LatexCodeGenerator::endCodeLine ( )
overridevirtual

Implements OutputCodeIntf.

Definition at line 278 of file latexgen.cpp.

279{
280 if (m_hide) return;
282 {
283 *m_t << "}";
285 }
286 codify("\n");
287}
void codify(const QCString &text) override
Definition latexgen.cpp:76
#define FALSE
Definition qcstring.h:34

References codify(), FALSE, m_doxyCodeLineOpen, m_hide, and m_t.

Referenced by endCodeFragment().

◆ endFold()

void LatexCodeGenerator::endFold ( )
inlineoverridevirtual

Implements OutputCodeIntf.

Definition at line 61 of file latexgen.h.

61{}

◆ endFontClass()

void LatexCodeGenerator::endFontClass ( )
overridevirtual

Implements OutputCodeIntf.

Definition at line 295 of file latexgen.cpp.

296{
297 if (m_hide) return;
298 *m_t << "}";
299}

References m_hide, and m_t.

◆ endSpecialComment()

void LatexCodeGenerator::endSpecialComment ( )
overridevirtual

Implements OutputCodeIntf.

Definition at line 184 of file latexgen.cpp.

185{
186 m_hide = false;
187}

References m_hide.

◆ incUsedTableLevel()

void LatexCodeGenerator::incUsedTableLevel ( )
inline

Definition at line 64 of file latexgen.h.

References m_usedTableLevel.

◆ insideTabbing()

bool LatexCodeGenerator::insideTabbing ( ) const
inline

Definition at line 71 of file latexgen.h.

71{ return m_insideTabbing; }

References m_insideTabbing.

◆ setInsideTabbing()

void LatexCodeGenerator::setInsideTabbing ( bool b)
inline

Definition at line 70 of file latexgen.h.

70{ m_insideTabbing=b; }

References m_insideTabbing.

◆ setRelativePath()

void LatexCodeGenerator::setRelativePath ( const QCString & path)

Definition at line 66 of file latexgen.cpp.

67{
68 m_relPath = path;
69}

References m_relPath.

◆ setSourceFileName()

void LatexCodeGenerator::setSourceFileName ( const QCString & sourceFileName)

Definition at line 71 of file latexgen.cpp.

72{
73 m_sourceFileName = name;
74}

References m_sourceFileName.

◆ setStripIndentAmount()

void LatexCodeGenerator::setStripIndentAmount ( size_t amount)
overridevirtual

Implements OutputCodeIntf.

Definition at line 189 of file latexgen.cpp.

190{
191 m_stripIndentAmount = amount;
192}

References m_stripIndentAmount.

◆ setTextStream()

void LatexCodeGenerator::setTextStream ( TextStream * t)
inline

Definition at line 32 of file latexgen.h.

32{ m_t = t; }

References m_t.

◆ startCodeFragment()

void LatexCodeGenerator::startCodeFragment ( const QCString & style)
overridevirtual

Implements OutputCodeIntf.

Definition at line 301 of file latexgen.cpp.

302{
303 *m_t << "\n\\begin{" << style << "}{" << m_usedTableLevel << "}\n";
304}

References m_t, and m_usedTableLevel.

◆ startCodeLine()

void LatexCodeGenerator::startCodeLine ( int )
overridevirtual

Implements OutputCodeIntf.

Definition at line 267 of file latexgen.cpp.

268{
269 if (m_hide) return;
270 m_col=0;
272 {
273 *m_t << "\\DoxyCodeLine{";
275 }
276}
#define TRUE
Definition qcstring.h:37

References m_col, m_doxyCodeLineOpen, m_hide, m_t, and TRUE.

◆ startFold()

void LatexCodeGenerator::startFold ( int ,
const QCString & ,
const QCString &  )
inlineoverridevirtual

Implements OutputCodeIntf.

Definition at line 60 of file latexgen.h.

60{}

◆ startFontClass()

void LatexCodeGenerator::startFontClass ( const QCString & name)
overridevirtual

Implements OutputCodeIntf.

Definition at line 289 of file latexgen.cpp.

290{
291 if (m_hide) return;
292 *m_t << "\\textcolor{" << name << "}{";
293}

References m_hide, and m_t.

◆ startSpecialComment()

void LatexCodeGenerator::startSpecialComment ( )
overridevirtual

Implements OutputCodeIntf.

Definition at line 179 of file latexgen.cpp.

180{
182}
bool m_stripCodeComments
Definition latexgen.h:87

References m_hide, and m_stripCodeComments.

◆ stripCodeComments()

void LatexCodeGenerator::stripCodeComments ( bool b)
overridevirtual

Implements OutputCodeIntf.

Definition at line 174 of file latexgen.cpp.

175{
177}

References m_stripCodeComments.

◆ type()

OutputType LatexCodeGenerator::type ( ) const
inlineoverridevirtual

Implements OutputCodeIntf.

Definition at line 34 of file latexgen.h.

34{ return OutputType::Latex; }

References Latex.

◆ usedTableLevel()

int LatexCodeGenerator::usedTableLevel ( ) const
inline

Definition at line 66 of file latexgen.h.

66{ return m_usedTableLevel; }

References m_usedTableLevel.

◆ writeCodeAnchor()

void LatexCodeGenerator::writeCodeAnchor ( const QCString & )
inlineoverridevirtual

Implements OutputCodeIntf.

Definition at line 57 of file latexgen.h.

57{}

◆ writeCodeLink()

void LatexCodeGenerator::writeCodeLink ( CodeSymbolType type,
const QCString & ref,
const QCString & file,
const QCString & anchor,
const QCString & name,
const QCString & tooltip )
overridevirtual

Implements OutputCodeIntf.

Definition at line 194 of file latexgen.cpp.

198{
199 if (m_hide) return;
200 bool pdfHyperlinks = Config_getBool(PDF_HYPERLINKS);
201 bool usePDFLatex = Config_getBool(USE_PDFLATEX);
202 size_t l = name.length();
203 if (ref.isEmpty() && usePDFLatex && pdfHyperlinks)
204 {
205 *m_t << "\\mbox{\\hyperlink{";
206 if (!f.isEmpty()) *m_t << stripPath(f);
207 if (!f.isEmpty() && !anchor.isEmpty()) *m_t << "_";
208 if (!anchor.isEmpty()) *m_t << anchor;
209 *m_t << "}{";
210 codify(name);
211 *m_t << "}}";
212 }
213 else
214 {
215 codify(name);
216 }
217 m_col+=l;
218}
size_t length() const
Returns the length of the string, not counting the 0-terminator.
Definition qcstring.h:153
bool isEmpty() const
Returns TRUE iff the string is empty.
Definition qcstring.h:150
#define Config_getBool(name)
Definition config.h:33
QCString stripPath(const QCString &s)
Definition util.cpp:5292

References codify(), Config_getBool, QCString::isEmpty(), QCString::length(), m_col, m_hide, m_t, and stripPath().

Referenced by writeLineNumber().

◆ writeLineNumber()

void LatexCodeGenerator::writeLineNumber ( const QCString & ref,
const QCString & fileName,
const QCString & anchor,
int l,
bool writeLineAnchor )
overridevirtual

Implements OutputCodeIntf.

Definition at line 220 of file latexgen.cpp.

221{
222 if (m_hide) return;
223 bool usePDFLatex = Config_getBool(USE_PDFLATEX);
224 bool pdfHyperlinks = Config_getBool(PDF_HYPERLINKS);
226 {
227 *m_t << "\\DoxyCodeLine{";
229 }
230 if (Config_getBool(SOURCE_BROWSER))
231 {
232 QCString lineNumber;
233 lineNumber.sprintf("%05d",l);
234
235 QCString lineAnchor;
236 if (!m_sourceFileName.isEmpty())
237 {
238 lineAnchor.sprintf("_l%05d",l);
240 }
241 bool showTarget = usePDFLatex && pdfHyperlinks && !lineAnchor.isEmpty() && writeLineAnchor;
242 if (showTarget)
243 {
244 *m_t << "\\Hypertarget{" << stripPath(lineAnchor) << "}";
245 }
246 if (!fileName.isEmpty())
247 {
248 writeCodeLink(CodeSymbolType::Default,ref,fileName,anchor,lineNumber,QCString());
249 }
250 else
251 {
252 codify(lineNumber);
253 }
254 *m_t << "\\ ";
255 }
256 else
257 {
258 QCString lineNumber;
259 lineNumber.sprintf("%05d",l);
260 codify(lineNumber);
261 *m_t << "\\ ";
262 }
263 m_col=0;
264}
void writeCodeLink(CodeSymbolType type, const QCString &ref, const QCString &file, const QCString &anchor, const QCString &name, const QCString &tooltip) override
Definition latexgen.cpp:194
QCString & prepend(const char *s)
Definition qcstring.h:407
QCString & sprintf(const char *format,...)
Definition qcstring.cpp:29
QCString stripExtensionGeneral(const QCString &fName, const QCString &ext)
Definition util.cpp:5255

References codify(), Config_getBool, Default, QCString::isEmpty(), m_col, m_doxyCodeLineOpen, m_hide, m_sourceFileName, m_t, QCString::prepend(), QCString::sprintf(), stripExtensionGeneral(), stripPath(), TRUE, and writeCodeLink().

◆ writeTooltip()

void LatexCodeGenerator::writeTooltip ( const QCString & ,
const DocLinkInfo & ,
const QCString & ,
const QCString & ,
const SourceLinkInfo & ,
const SourceLinkInfo &  )
inlineoverridevirtual

Implements OutputCodeIntf.

Definition at line 45 of file latexgen.h.

51 {}

Member Data Documentation

◆ m_col

size_t LatexCodeGenerator::m_col = 0
private

Definition at line 83 of file latexgen.h.

Referenced by codify(), startCodeLine(), writeCodeLink(), and writeLineNumber().

◆ m_doxyCodeLineOpen

bool LatexCodeGenerator::m_doxyCodeLineOpen = false
private

Definition at line 84 of file latexgen.h.

Referenced by codify(), endCodeLine(), startCodeLine(), and writeLineNumber().

◆ m_hide

bool LatexCodeGenerator::m_hide = false
private

◆ m_insideTabbing

bool LatexCodeGenerator::m_insideTabbing = false
private

Definition at line 86 of file latexgen.h.

Referenced by codify(), insideTabbing(), and setInsideTabbing().

◆ m_relPath

QCString LatexCodeGenerator::m_relPath
private

Definition at line 81 of file latexgen.h.

Referenced by LatexCodeGenerator(), and setRelativePath().

◆ m_sourceFileName

QCString LatexCodeGenerator::m_sourceFileName
private

Definition at line 82 of file latexgen.h.

Referenced by LatexCodeGenerator(), setSourceFileName(), and writeLineNumber().

◆ m_streamSet

bool LatexCodeGenerator::m_streamSet = false
private

Definition at line 79 of file latexgen.h.

◆ m_stripCodeComments

bool LatexCodeGenerator::m_stripCodeComments = false
private

Definition at line 87 of file latexgen.h.

Referenced by startSpecialComment(), and stripCodeComments().

◆ m_stripIndentAmount

size_t LatexCodeGenerator::m_stripIndentAmount = 0
private

Definition at line 89 of file latexgen.h.

Referenced by codify(), and setStripIndentAmount().

◆ m_t

◆ m_usedTableLevel

int LatexCodeGenerator::m_usedTableLevel = 0
private

The documentation for this class was generated from the following files: