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

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

Private Member Functions

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

Private Attributes

bool m_streamSet = false
TextStreamm_t
DString m_relPath
DString 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 26 of file latexgen.h.

Constructor & Destructor Documentation

◆ LatexCodeGenerator() [1/2]

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

Definition at line 60 of file latexgen.cpp.

61 : m_t(t), m_relPath(relPath), m_sourceFileName(sourceFileName)
62{
63}
TextStream * m_t
Definition latexgen.h:79
DString m_relPath
Definition latexgen.h:80
DString m_sourceFileName
Definition latexgen.h:81

References m_relPath, m_sourceFileName, and m_t.

◆ LatexCodeGenerator() [2/2]

LatexCodeGenerator::LatexCodeGenerator ( TextStream * t)

Definition at line 65 of file latexgen.cpp.

65 : m_t(t)
66{
67}

References m_t.

Member Function Documentation

◆ _writeCodeLink()

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

◆ clone()

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

Implements OutputCodeIntf.

Definition at line 34 of file latexgen.h.

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

◆ codify()

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

Implements OutputCodeIntf.

Definition at line 79 of file latexgen.cpp.

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

References Config_getInt, COPYCHAR, DString::data(), DString::empty(), filterLatexString(), 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

◆ docify()

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

◆ endCodeFragment()

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

Implements OutputCodeIntf.

Definition at line 309 of file latexgen.cpp.

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

References endCodeLine(), m_hide, and m_t.

◆ endCodeLine()

void LatexCodeGenerator::endCodeLine ( )
overridevirtual

Implements OutputCodeIntf.

Definition at line 281 of file latexgen.cpp.

282{
283 if (m_hide) return;
285 {
286 *m_t << "}";
287 m_doxyCodeLineOpen = false;
288 }
289 codify("\n");
290}
void codify(const DString &text) override
Definition latexgen.cpp:79

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

Referenced by endCodeFragment().

◆ endFold()

void LatexCodeGenerator::endFold ( )
inlineoverridevirtual

Implements OutputCodeIntf.

Definition at line 60 of file latexgen.h.

60{}

◆ endFontClass()

void LatexCodeGenerator::endFontClass ( )
overridevirtual

Implements OutputCodeIntf.

Definition at line 298 of file latexgen.cpp.

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

References m_hide, and m_t.

◆ endSpecialComment()

void LatexCodeGenerator::endSpecialComment ( )
overridevirtual

Implements OutputCodeIntf.

Definition at line 187 of file latexgen.cpp.

188{
189 m_hide = false;
190}

References m_hide.

◆ incUsedTableLevel()

void LatexCodeGenerator::incUsedTableLevel ( )
inline

◆ insideTabbing()

◆ setInsideTabbing()

◆ setRelativePath()

void LatexCodeGenerator::setRelativePath ( const DString & path)

Definition at line 69 of file latexgen.cpp.

70{
71 m_relPath = path;
72}

References m_relPath.

Referenced by LatexGenerator::startFile().

◆ setSourceFileName()

void LatexCodeGenerator::setSourceFileName ( const DString & sourceFileName)

Definition at line 74 of file latexgen.cpp.

75{
76 m_sourceFileName = name;
77}

References m_sourceFileName.

Referenced by LatexGenerator::endFile(), and LatexGenerator::startFile().

◆ setStripIndentAmount()

void LatexCodeGenerator::setStripIndentAmount ( size_t amount)
overridevirtual

Implements OutputCodeIntf.

Definition at line 192 of file latexgen.cpp.

193{
194 m_stripIndentAmount = amount;
195}

References m_stripIndentAmount.

◆ setTextStream()

void LatexCodeGenerator::setTextStream ( TextStream * t)
inline

Definition at line 31 of file latexgen.h.

31{ m_t = t; }

References m_t.

Referenced by LatexGenerator::LatexGenerator(), and LatexGenerator::operator=().

◆ startCodeFragment()

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

Implements OutputCodeIntf.

Definition at line 304 of file latexgen.cpp.

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

References m_t, and m_usedTableLevel.

◆ startCodeLine()

void LatexCodeGenerator::startCodeLine ( int )
overridevirtual

Implements OutputCodeIntf.

Definition at line 270 of file latexgen.cpp.

271{
272 if (m_hide) return;
273 m_col=0;
275 {
276 *m_t << "\\DoxyCodeLine{";
277 m_doxyCodeLineOpen = true;
278 }
279}

References m_col, m_doxyCodeLineOpen, m_hide, and m_t.

◆ startFold()

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

Implements OutputCodeIntf.

Definition at line 59 of file latexgen.h.

59{}

◆ startFontClass()

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

Implements OutputCodeIntf.

Definition at line 292 of file latexgen.cpp.

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

References m_hide, and m_t.

◆ startSpecialComment()

void LatexCodeGenerator::startSpecialComment ( )
overridevirtual

Implements OutputCodeIntf.

Definition at line 182 of file latexgen.cpp.

183{
185}
bool m_stripCodeComments
Definition latexgen.h:86

References m_hide, and m_stripCodeComments.

◆ stripCodeComments()

void LatexCodeGenerator::stripCodeComments ( bool b)
overridevirtual

Implements OutputCodeIntf.

Definition at line 177 of file latexgen.cpp.

178{
180}

References m_stripCodeComments.

◆ type()

OutputType LatexCodeGenerator::type ( ) const
inlineoverridevirtual

Implements OutputCodeIntf.

Definition at line 33 of file latexgen.h.

33{ return OutputType::Latex; }

References Latex.

◆ usedTableLevel()

int LatexCodeGenerator::usedTableLevel ( ) const
inline

◆ writeCodeAnchor()

void LatexCodeGenerator::writeCodeAnchor ( const DString & )
inlineoverridevirtual

Implements OutputCodeIntf.

Definition at line 56 of file latexgen.h.

56{}

◆ writeCodeLink()

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

Implements OutputCodeIntf.

Definition at line 197 of file latexgen.cpp.

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

References codify(), Config_getBool, DString::empty(), DString::length(), m_col, m_hide, m_t, and stripPath().

Referenced by writeLineNumber().

◆ writeLineNumber()

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

Implements OutputCodeIntf.

Definition at line 223 of file latexgen.cpp.

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

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

◆ writeTooltip()

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

Implements OutputCodeIntf.

Definition at line 44 of file latexgen.h.

50 {}

Member Data Documentation

◆ m_col

size_t LatexCodeGenerator::m_col = 0
private

Definition at line 82 of file latexgen.h.

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

◆ m_doxyCodeLineOpen

bool LatexCodeGenerator::m_doxyCodeLineOpen = false
private

Definition at line 83 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 85 of file latexgen.h.

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

◆ m_relPath

DString LatexCodeGenerator::m_relPath
private

Definition at line 80 of file latexgen.h.

Referenced by LatexCodeGenerator(), and setRelativePath().

◆ m_sourceFileName

DString LatexCodeGenerator::m_sourceFileName
private

Definition at line 81 of file latexgen.h.

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

◆ m_streamSet

bool LatexCodeGenerator::m_streamSet = false
private

Definition at line 78 of file latexgen.h.

◆ m_stripCodeComments

bool LatexCodeGenerator::m_stripCodeComments = false
private

Definition at line 86 of file latexgen.h.

Referenced by startSpecialComment(), and stripCodeComments().

◆ m_stripIndentAmount

size_t LatexCodeGenerator::m_stripIndentAmount = 0
private

Definition at line 88 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: