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

Generator for RTF code fragments. More...

#include <src/rtfgen.h>

Inheritance diagram for RTFCodeGenerator:
Collaboration diagram for RTFCodeGenerator:

Public Member Functions

 RTFCodeGenerator (TextStream *t)
void setTextStream (TextStream *t)
OutputType type () const override
void codify (const DString &text) override
void stripCodeComments (bool b) override
void startSpecialComment () override
void endSpecialComment () override
void setStripIndentAmount (size_t amount) override
std::unique_ptr< OutputCodeIntfclone () 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 l, 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 &) override
void startFold (int, const DString &, const DString &) override
void endFold () override
Public Member Functions inherited from OutputCodeIntf
 OutputCodeIntf ()=default

Private Member Functions

void setSourceFileName (const DString &name)
void setIndentLevel (int level)
DString rtf_Code_DepthStyle ()

Private Attributes

size_t m_col = 0
TextStreamm_t
bool m_doxyCodeLineOpen = false
DString m_sourceFileName
int m_indentLevel = 0
bool m_stripCodeComments = false
bool m_hide = false
size_t m_stripIndentAmount = 0

Friends

class RTFGenerator

Detailed Description

Generator for RTF code fragments.

Definition at line 27 of file rtfgen.h.

Constructor & Destructor Documentation

◆ RTFCodeGenerator()

RTFCodeGenerator::RTFCodeGenerator ( TextStream * t)

Definition at line 117 of file rtfgen.cpp.

117 : m_t(t)
118{
119}
TextStream * m_t
Definition rtfgen.h:68

References m_t.

Member Function Documentation

◆ clone()

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

Implements OutputCodeIntf.

Definition at line 39 of file rtfgen.h.

39{ return std::make_unique<RTFCodeGenerator>(*this); }

◆ codify()

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

Implements OutputCodeIntf.

Definition at line 156 of file rtfgen.cpp.

157{
158 // note that RTF does not have a "verbatim", so "\n" means
159 // nothing... add a "newParagraph()";
160 const int tabSize = Config_getInt(TAB_SIZE);
161 if (!str.empty())
162 {
163 char c;
164 const char *p=str.data();
165 if (m_hide)
166 {
168 }
169 else
170 {
171 while ((c=*p++))
172 {
173 switch(c)
174 {
175 case '\t': {
176 int spacesToNextTabStop = tabSize - (m_col%tabSize);
177 while (spacesToNextTabStop--)
178 {
179 if (m_col>=m_stripIndentAmount) *m_t << " ";
180 m_col++;
181 }
182 }
183 break;
184 case ' ': if (m_col>=m_stripIndentAmount) *m_t << " ";
185 m_col++;
186 break;
187 case '\n': *m_t << "\\par\n";
188 m_col=0;
189 break;
190 case '{': *m_t << "\\{"; m_col++; break;
191 case '}': *m_t << "\\}"; m_col++; break;
192 case '\\': *m_t << "\\\\"; m_col++; break;
193 default: p=writeUTF8Char(*m_t,p-1); m_col++; break;
194 }
195 }
196 }
197 }
198}
size_t m_stripIndentAmount
Definition rtfgen.h:74
size_t m_col
Definition rtfgen.h:67
#define Config_getInt(name)
Definition config.h:34
size_t updateColumnCount(const char *s, size_t col)
Definition outputgen.cpp:58
const char * writeUTF8Char(TextStream &t, const char *s)
Writes the UTF8 character pointed to by s to stream t and returns a pointer to the next character.
Definition utf8.cpp:201

References Config_getInt, DString::data(), DString::empty(), m_col, m_hide, m_stripIndentAmount, m_t, updateColumnCount(), and writeUTF8Char().

Referenced by writeCodeLink().

◆ endCodeFragment()

void RTFCodeGenerator::endCodeFragment ( const DString & )
overridevirtual

Implements OutputCodeIntf.

Definition at line 228 of file rtfgen.cpp.

229{
230 bool wasHidden = m_hide;
231 m_hide = false;
232 endCodeLine();
233 m_hide = wasHidden;
234
235 DBG_RTF(*m_t << "{\\comment (endCodeFragment) }\n")
236 *m_t << "}\n";
237 //m_omitParagraph = true;
238}
void endCodeLine() override
Definition rtfgen.cpp:291
#define DBG_RTF(x)

References DBG_RTF, endCodeLine(), m_hide, and m_t.

◆ endCodeLine()

void RTFCodeGenerator::endCodeLine ( )
overridevirtual

Implements OutputCodeIntf.

Definition at line 291 of file rtfgen.cpp.

292{
293 if (m_hide) return;
294 if (m_doxyCodeLineOpen) *m_t << "\\par\n";
295 m_doxyCodeLineOpen = false;
296}
bool m_doxyCodeLineOpen
Definition rtfgen.h:69

References m_doxyCodeLineOpen, m_hide, and m_t.

Referenced by endCodeFragment().

◆ endFold()

void RTFCodeGenerator::endFold ( )
inlineoverridevirtual

Implements OutputCodeIntf.

Definition at line 60 of file rtfgen.h.

60{}

◆ endFontClass()

void RTFCodeGenerator::endFontClass ( )
overridevirtual

Implements OutputCodeIntf.

Definition at line 323 of file rtfgen.cpp.

324{
325 if (m_hide) return;
326 *m_t << "}";
327}

References m_hide, and m_t.

◆ endSpecialComment()

void RTFCodeGenerator::endSpecialComment ( )
overridevirtual

Implements OutputCodeIntf.

Definition at line 210 of file rtfgen.cpp.

211{
212 m_hide = false;
213}

References m_hide.

◆ rtf_Code_DepthStyle()

DString RTFCodeGenerator::rtf_Code_DepthStyle ( )
private

Definition at line 329 of file rtfgen.cpp.

330{
331 DString n=makeIndexName("CodeExample",m_indentLevel);
332 return rtf_Style[n.str()].reference();
333}
const std::string & str() const
Definition dstring.h:645
int m_indentLevel
Definition rtfgen.h:71
static DString makeIndexName(const DString &s, int i)
Definition rtfgen.cpp:107
StyleDataMap rtf_Style
Definition rtfstyle.cpp:366

References m_indentLevel, makeIndexName(), rtf_Style, and DString::str().

Referenced by startCodeFragment().

◆ setIndentLevel()

void RTFCodeGenerator::setIndentLevel ( int level)
inlineprivate

Definition at line 65 of file rtfgen.h.

65{ m_indentLevel=level; }

References m_indentLevel.

Referenced by RTFGenerator::decIndentLevel(), and RTFGenerator::incIndentLevel().

◆ setSourceFileName()

void RTFCodeGenerator::setSourceFileName ( const DString & name)
private

Definition at line 335 of file rtfgen.cpp.

336{
337 m_sourceFileName = name;
338}
DString m_sourceFileName
Definition rtfgen.h:70

References m_sourceFileName.

Referenced by RTFGenerator::setSourceFileName().

◆ setStripIndentAmount()

void RTFCodeGenerator::setStripIndentAmount ( size_t amount)
overridevirtual

Implements OutputCodeIntf.

Definition at line 215 of file rtfgen.cpp.

216{
217 m_stripIndentAmount = amount;
218}

References m_stripIndentAmount.

◆ setTextStream()

void RTFCodeGenerator::setTextStream ( TextStream * t)
inline

Definition at line 31 of file rtfgen.h.

31{ m_t = t; }

References m_t.

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

◆ startCodeFragment()

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

Implements OutputCodeIntf.

Definition at line 220 of file rtfgen.cpp.

221{
222 DBG_RTF(*m_t << "{\\comment (startCodeFragment) }\n")
223 *m_t << "{\n";
224 *m_t << "\\par\n";
226}
DString rtf_Code_DepthStyle()
Definition rtfgen.cpp:329
char rtf_Style_Reset[]
Definition rtfstyle.cpp:54

References DBG_RTF, m_t, rtf_Code_DepthStyle(), and rtf_Style_Reset.

◆ startCodeLine()

void RTFCodeGenerator::startCodeLine ( int )
overridevirtual

Implements OutputCodeIntf.

Definition at line 284 of file rtfgen.cpp.

285{
286 if (m_hide) return;
287 m_doxyCodeLineOpen = true;
288 m_col=0;
289}

References m_col, m_doxyCodeLineOpen, and m_hide.

◆ startFold()

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

Implements OutputCodeIntf.

Definition at line 59 of file rtfgen.h.

59{}

◆ startFontClass()

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

Implements OutputCodeIntf.

Definition at line 298 of file rtfgen.cpp.

299{
300 if (m_hide) return;
301 int cod = 2;
302 static const std::unordered_map<std::string,int> map {
303 { "keyword", 17 },
304 { "keywordtype", 18 },
305 { "keywordflow", 19 },
306 { "comment", 20 },
307 { "preprocessor", 21 },
308 { "stringliteral", 22 },
309 { "charliteral", 23 },
310 { "vhdldigit", 24 },
311 { "vhdlchar", 25 },
312 { "vhdlkeyword", 26 },
313 { "vhdllogic", 27 }
314 };
315 auto it = map.find(name.str());
316 if (it != map.end())
317 {
318 cod = it->second;
319 }
320 *m_t << "{\\cf" << cod << " ";
321}

References m_hide, m_t, and DString::str().

◆ startSpecialComment()

void RTFCodeGenerator::startSpecialComment ( )
overridevirtual

Implements OutputCodeIntf.

Definition at line 205 of file rtfgen.cpp.

206{
208}
bool m_stripCodeComments
Definition rtfgen.h:72

References m_hide, and m_stripCodeComments.

◆ stripCodeComments()

void RTFCodeGenerator::stripCodeComments ( bool b)
overridevirtual

Implements OutputCodeIntf.

Definition at line 200 of file rtfgen.cpp.

201{
203}

References m_stripCodeComments.

◆ type()

OutputType RTFCodeGenerator::type ( ) const
inlineoverridevirtual

Implements OutputCodeIntf.

Definition at line 33 of file rtfgen.h.

33{ return OutputType::RTF; }

References RTF.

◆ writeCodeAnchor()

void RTFCodeGenerator::writeCodeAnchor ( const DString & )
inlineoverridevirtual

Implements OutputCodeIntf.

Definition at line 56 of file rtfgen.h.

56{}

◆ writeCodeLink()

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

Implements OutputCodeIntf.

Definition at line 121 of file rtfgen.cpp.

125{
126 m_col+=name.length();
127 if (m_hide) return;
128 if (ref.empty() && Config_getBool(RTF_HYPERLINKS))
129 {
130 DString refName;
131 if (!f.empty())
132 {
133 refName+=stripPath(f);
134 }
135 if (!anchor.empty())
136 {
137 refName+='_';
138 refName+=anchor;
139 }
140
141 *m_t << "{\\field {\\*\\fldinst { HYPERLINK \\\\l \"";
142 *m_t << rtfFormatBmkStr(refName);
143 *m_t << "\" }{}";
144 *m_t << "}{\\fldrslt {\\cs37\\ul\\cf2 ";
145
146 codify(name);
147
148 *m_t << "}}}\n";
149 }
150 else
151 {
152 codify(name);
153 }
154}
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
void codify(const DString &text) override
Definition rtfgen.cpp:156
#define Config_getBool(name)
Definition config.h:33
DString rtfFormatBmkStr(const DString &name)
Definition rtfgen.cpp:2879
DString stripPath(const DString &s)
Definition util.cpp:3960

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

Referenced by writeLineNumber().

◆ writeLineNumber()

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

Implements OutputCodeIntf.

Definition at line 240 of file rtfgen.cpp.

241{
242 if (m_hide) return;
243 bool rtfHyperlinks = Config_getBool(RTF_HYPERLINKS);
244
245 m_doxyCodeLineOpen = true;
246 if (Config_getBool(SOURCE_BROWSER))
247 {
248 DString lineNumber;
249 lineNumber.sprintf("%05d",l);
250
251 DString lineAnchor;
252 if (!m_sourceFileName.empty())
253 {
254 lineAnchor.sprintf("_l%05d",l);
256 }
257 bool showTarget = rtfHyperlinks && !lineAnchor.empty() && writeLineAnchor;
258 if (showTarget)
259 {
260 *m_t << "{\\bkmkstart ";
261 *m_t << rtfFormatBmkStr(lineAnchor);
262 *m_t << "}";
263 *m_t << "{\\bkmkend ";
264 *m_t << rtfFormatBmkStr(lineAnchor);
265 *m_t << "}\n";
266 }
267 if (!fileName.empty())
268 {
269 writeCodeLink(CodeSymbolType::Default,ref,fileName,anchor,lineNumber,DString());
270 }
271 else
272 {
273 *m_t << lineNumber;
274 }
275 *m_t << " ";
276 }
277 else
278 {
279 *m_t << l << " ";
280 }
281 m_col=0;
282}
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 rtfgen.cpp:121
DString stripExtensionGeneral(const DString &fName, const DString &ext)
Definition util.cpp:3945

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

◆ writeTooltip()

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

Implements OutputCodeIntf.

Definition at line 44 of file rtfgen.h.

50 {}

◆ RTFGenerator

friend class RTFGenerator
friend

Definition at line 63 of file rtfgen.h.

References RTFGenerator.

Referenced by RTFGenerator.

Member Data Documentation

◆ m_col

size_t RTFCodeGenerator::m_col = 0
private

Definition at line 67 of file rtfgen.h.

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

◆ m_doxyCodeLineOpen

bool RTFCodeGenerator::m_doxyCodeLineOpen = false
private

Definition at line 69 of file rtfgen.h.

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

◆ m_hide

bool RTFCodeGenerator::m_hide = false
private

◆ m_indentLevel

int RTFCodeGenerator::m_indentLevel = 0
private

Definition at line 71 of file rtfgen.h.

Referenced by rtf_Code_DepthStyle(), and setIndentLevel().

◆ m_sourceFileName

DString RTFCodeGenerator::m_sourceFileName
private

Definition at line 70 of file rtfgen.h.

Referenced by setSourceFileName(), and writeLineNumber().

◆ m_stripCodeComments

bool RTFCodeGenerator::m_stripCodeComments = false
private

Definition at line 72 of file rtfgen.h.

Referenced by startSpecialComment(), and stripCodeComments().

◆ m_stripIndentAmount

size_t RTFCodeGenerator::m_stripIndentAmount = 0
private

Definition at line 74 of file rtfgen.h.

Referenced by codify(), and setStripIndentAmount().

◆ m_t


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