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

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

63 : m_t(t)
64{
65}

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

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

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

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

References endCodeLine(), m_hide, and m_t.

◆ endCodeLine()

void LatexCodeGenerator::endCodeLine ( )
overridevirtual

Implements OutputCodeIntf.

Definition at line 279 of file latexgen.cpp.

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

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

References m_hide, and m_t.

◆ endSpecialComment()

void LatexCodeGenerator::endSpecialComment ( )
overridevirtual

Implements OutputCodeIntf.

Definition at line 185 of file latexgen.cpp.

186{
187 m_hide = false;
188}

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

68{
69 m_relPath = path;
70}

References m_relPath.

◆ setSourceFileName()

void LatexCodeGenerator::setSourceFileName ( const QCString & sourceFileName)

Definition at line 72 of file latexgen.cpp.

73{
74 m_sourceFileName = name;
75}

References m_sourceFileName.

◆ setStripIndentAmount()

void LatexCodeGenerator::setStripIndentAmount ( size_t amount)
overridevirtual

Implements OutputCodeIntf.

Definition at line 190 of file latexgen.cpp.

191{
192 m_stripIndentAmount = amount;
193}

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

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

References m_t, and m_usedTableLevel.

◆ startCodeLine()

void LatexCodeGenerator::startCodeLine ( int )
overridevirtual

Implements OutputCodeIntf.

Definition at line 268 of file latexgen.cpp.

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

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

References m_hide, and m_t.

◆ startSpecialComment()

void LatexCodeGenerator::startSpecialComment ( )
overridevirtual

Implements OutputCodeIntf.

Definition at line 180 of file latexgen.cpp.

181{
183}
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 175 of file latexgen.cpp.

176{
178}

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

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

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

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

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: