Doxygen
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 59 of file latexgen.cpp.

60 : m_t(t), m_relPath(relPath), m_sourceFileName(sourceFileName)
61{
62}
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 64 of file latexgen.cpp.

64 : m_t(t)
65{
66}

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 78 of file latexgen.cpp.

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

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 308 of file latexgen.cpp.

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

References endCodeLine(), and m_t.

◆ endCodeLine()

void LatexCodeGenerator::endCodeLine ( )
overridevirtual

Implements OutputCodeIntf.

Definition at line 280 of file latexgen.cpp.

281{
282 if (m_hide) return;
284 {
285 *m_t << "}";
287 }
288 codify("\n");
289}
void codify(const QCString &text) override
Definition latexgen.cpp:78
#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 297 of file latexgen.cpp.

298{
299 if (m_hide) return;
300 *m_t << "}";
301}

References m_hide, and m_t.

◆ endSpecialComment()

void LatexCodeGenerator::endSpecialComment ( )
overridevirtual

Implements OutputCodeIntf.

Definition at line 186 of file latexgen.cpp.

187{
188 m_hide = false;
189}

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 68 of file latexgen.cpp.

69{
70 m_relPath = path;
71}

References m_relPath.

◆ setSourceFileName()

void LatexCodeGenerator::setSourceFileName ( const QCString & sourceFileName)

Definition at line 73 of file latexgen.cpp.

74{
75 m_sourceFileName = name;
76}

References m_sourceFileName.

◆ setStripIndentAmount()

void LatexCodeGenerator::setStripIndentAmount ( size_t amount)
overridevirtual

Implements OutputCodeIntf.

Definition at line 191 of file latexgen.cpp.

192{
193 m_stripIndentAmount = amount;
194}

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 303 of file latexgen.cpp.

304{
305 *m_t << "\n\\begin{" << style << "}{" << m_usedTableLevel << "}\n";
306}

References m_t, and m_usedTableLevel.

◆ startCodeLine()

void LatexCodeGenerator::startCodeLine ( int )
overridevirtual

Implements OutputCodeIntf.

Definition at line 269 of file latexgen.cpp.

270{
271 if (m_hide) return;
272 m_col=0;
274 {
275 *m_t << "\\DoxyCodeLine{";
277 }
278}
#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 291 of file latexgen.cpp.

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

References m_hide, and m_t.

◆ startSpecialComment()

void LatexCodeGenerator::startSpecialComment ( )
overridevirtual

Implements OutputCodeIntf.

Definition at line 181 of file latexgen.cpp.

182{
184}
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 176 of file latexgen.cpp.

177{
179}

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 196 of file latexgen.cpp.

200{
201 if (m_hide) return;
202 bool pdfHyperlinks = Config_getBool(PDF_HYPERLINKS);
203 bool usePDFLatex = Config_getBool(USE_PDFLATEX);
204 size_t l = name.length();
205 if (ref.isEmpty() && usePDFLatex && pdfHyperlinks)
206 {
207 *m_t << "\\mbox{\\hyperlink{";
208 if (!f.isEmpty()) *m_t << stripPath(f);
209 if (!f.isEmpty() && !anchor.isEmpty()) *m_t << "_";
210 if (!anchor.isEmpty()) *m_t << anchor;
211 *m_t << "}{";
212 codify(name);
213 *m_t << "}}";
214 }
215 else
216 {
217 codify(name);
218 }
219 m_col+=l;
220}
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:5457

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 222 of file latexgen.cpp.

223{
224 if (m_hide) return;
225 bool usePDFLatex = Config_getBool(USE_PDFLATEX);
226 bool pdfHyperlinks = Config_getBool(PDF_HYPERLINKS);
228 {
229 *m_t << "\\DoxyCodeLine{";
231 }
232 if (Config_getBool(SOURCE_BROWSER))
233 {
234 QCString lineNumber;
235 lineNumber.sprintf("%05d",l);
236
237 QCString lineAnchor;
238 if (!m_sourceFileName.isEmpty())
239 {
240 lineAnchor.sprintf("_l%05d",l);
242 }
243 bool showTarget = usePDFLatex && pdfHyperlinks && !lineAnchor.isEmpty() && writeLineAnchor;
244 if (showTarget)
245 {
246 *m_t << "\\Hypertarget{" << stripPath(lineAnchor) << "}";
247 }
248 if (!fileName.isEmpty())
249 {
250 writeCodeLink(CodeSymbolType::Default,ref,fileName,anchor,lineNumber,QCString());
251 }
252 else
253 {
254 codify(lineNumber);
255 }
256 *m_t << "\\ ";
257 }
258 else
259 {
260 QCString lineNumber;
261 lineNumber.sprintf("%05d",l);
262 codify(lineNumber);
263 *m_t << "\\ ";
264 }
265 m_col=0;
266}
void writeCodeLink(CodeSymbolType type, const QCString &ref, const QCString &file, const QCString &anchor, const QCString &name, const QCString &tooltip) override
Definition latexgen.cpp:196
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:5420

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: