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 114 of file rtfgen.cpp.

114 : m_t(t)
115{
116}
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 153 of file rtfgen.cpp.

154{
155 // note that RTF does not have a "verbatim", so "\n" means
156 // nothing... add a "newParagraph()";
157 const int tabSize = Config_getInt(TAB_SIZE);
158 if (!str.empty())
159 {
160 char c;
161 const char *p=str.data();
162 if (m_hide)
163 {
165 }
166 else
167 {
168 while ((c=*p++))
169 {
170 switch(c)
171 {
172 case '\t': {
173 int spacesToNextTabStop = tabSize - (m_col%tabSize);
174 while (spacesToNextTabStop--)
175 {
176 if (m_col>=m_stripIndentAmount) *m_t << " ";
177 m_col++;
178 }
179 }
180 break;
181 case ' ': if (m_col>=m_stripIndentAmount) *m_t << " ";
182 m_col++;
183 break;
184 case '\n': *m_t << "\\par\n";
185 m_col=0;
186 break;
187 case '{': *m_t << "\\{"; m_col++; break;
188 case '}': *m_t << "\\}"; m_col++; break;
189 case '\\': *m_t << "\\\\"; m_col++; break;
190 default: p=writeUTF8Char(*m_t,p-1); m_col++; break;
191 }
192 }
193 }
194 }
195}
size_t m_stripIndentAmount
Definition rtfgen.h:74
size_t m_col
Definition rtfgen.h:67
#define Config_getInt(name)
Definition config.h:34
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:197
size_t updateColumnCount(const char *s, size_t col)
Definition util.cpp:6924

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 225 of file rtfgen.cpp.

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

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

◆ endCodeLine()

void RTFCodeGenerator::endCodeLine ( )
overridevirtual

Implements OutputCodeIntf.

Definition at line 288 of file rtfgen.cpp.

289{
290 if (m_hide) return;
291 if (m_doxyCodeLineOpen) *m_t << "\\par\n";
292 m_doxyCodeLineOpen = false;
293}
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 320 of file rtfgen.cpp.

321{
322 if (m_hide) return;
323 *m_t << "}";
324}

References m_hide, and m_t.

◆ endSpecialComment()

void RTFCodeGenerator::endSpecialComment ( )
overridevirtual

Implements OutputCodeIntf.

Definition at line 207 of file rtfgen.cpp.

208{
209 m_hide = false;
210}

References m_hide.

◆ rtf_Code_DepthStyle()

DString RTFCodeGenerator::rtf_Code_DepthStyle ( )
private

Definition at line 326 of file rtfgen.cpp.

327{
328 DString n=makeIndexName("CodeExample",m_indentLevel);
329 return rtf_Style[n.str()].reference();
330}
const std::string & str() const
Definition dstring.h:634
int m_indentLevel
Definition rtfgen.h:71
static DString makeIndexName(const DString &s, int i)
Definition rtfgen.cpp:104
StyleDataMap rtf_Style
Definition rtfstyle.cpp:361

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 332 of file rtfgen.cpp.

333{
334 m_sourceFileName = name;
335}
DString m_sourceFileName
Definition rtfgen.h:70

References m_sourceFileName.

Referenced by RTFGenerator, and RTFGenerator::setSourceFileName().

◆ setStripIndentAmount()

void RTFCodeGenerator::setStripIndentAmount ( size_t amount)
overridevirtual

Implements OutputCodeIntf.

Definition at line 212 of file rtfgen.cpp.

213{
214 m_stripIndentAmount = amount;
215}

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 217 of file rtfgen.cpp.

218{
219 DBG_RTF(*m_t << "{\\comment (startCodeFragment) }\n")
220 *m_t << "{\n";
221 *m_t << "\\par\n";
223}
DString rtf_Code_DepthStyle()
Definition rtfgen.cpp:326
char rtf_Style_Reset[]
Definition rtfstyle.cpp:49

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

◆ startCodeLine()

void RTFCodeGenerator::startCodeLine ( int )
overridevirtual

Implements OutputCodeIntf.

Definition at line 281 of file rtfgen.cpp.

282{
283 if (m_hide) return;
284 m_doxyCodeLineOpen = true;
285 m_col=0;
286}

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 295 of file rtfgen.cpp.

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

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

◆ startSpecialComment()

void RTFCodeGenerator::startSpecialComment ( )
overridevirtual

Implements OutputCodeIntf.

Definition at line 202 of file rtfgen.cpp.

203{
205}
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 197 of file rtfgen.cpp.

198{
200}

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 118 of file rtfgen.cpp.

122{
123 m_col+=name.length();
124 if (m_hide) return;
125 if (ref.empty() && Config_getBool(RTF_HYPERLINKS))
126 {
127 DString refName;
128 if (!f.empty())
129 {
130 refName+=stripPath(f);
131 }
132 if (!anchor.empty())
133 {
134 refName+='_';
135 refName+=anchor;
136 }
137
138 *m_t << "{\\field {\\*\\fldinst { HYPERLINK \\\\l \"";
139 *m_t << rtfFormatBmkStr(refName);
140 *m_t << "\" }{}";
141 *m_t << "}{\\fldrslt {\\cs37\\ul\\cf2 ";
142
143 codify(name);
144
145 *m_t << "}}}\n";
146 }
147 else
148 {
149 codify(name);
150 }
151}
bool empty() const
Returns true iff the string is empty (std::string compatible alias for isEmpty()).
Definition dstring.h:153
size_t length() const
Returns the length of the string, not counting the 0-terminator.
Definition dstring.h:156
void codify(const DString &text) override
Definition rtfgen.cpp:153
#define Config_getBool(name)
Definition config.h:33
DString rtfFormatBmkStr(const DString &name)
Definition rtfgen.cpp:2873
DString stripPath(const DString &s)
Definition util.cpp:4998

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 237 of file rtfgen.cpp.

238{
239 if (m_hide) return;
240 bool rtfHyperlinks = Config_getBool(RTF_HYPERLINKS);
241
242 m_doxyCodeLineOpen = true;
243 if (Config_getBool(SOURCE_BROWSER))
244 {
245 DString lineNumber;
246 lineNumber.sprintf("%05d",l);
247
248 DString lineAnchor;
249 if (!m_sourceFileName.empty())
250 {
251 lineAnchor.sprintf("_l%05d",l);
253 }
254 bool showTarget = rtfHyperlinks && !lineAnchor.empty() && writeLineAnchor;
255 if (showTarget)
256 {
257 *m_t << "{\\bkmkstart ";
258 *m_t << rtfFormatBmkStr(lineAnchor);
259 *m_t << "}";
260 *m_t << "{\\bkmkend ";
261 *m_t << rtfFormatBmkStr(lineAnchor);
262 *m_t << "}\n";
263 }
264 if (!fileName.empty())
265 {
266 writeCodeLink(CodeSymbolType::Default,ref,fileName,anchor,lineNumber,DString());
267 }
268 else
269 {
270 *m_t << lineNumber;
271 }
272 *m_t << " ";
273 }
274 else
275 {
276 *m_t << l << " ";
277 }
278 m_col=0;
279}
DString()=default
DString & prepend(const char *s)
Definition dstring.h:504
DString & sprintf(const char *format,...)
Definition dstring.cpp:29
void writeCodeLink(CodeSymbolType type, const DString &ref, const DString &file, const DString &anchor, const DString &name, const DString &tooltip) override
Definition rtfgen.cpp:118
DString stripExtensionGeneral(const DString &fName, const DString &ext)
Definition util.cpp:4983

References Config_getBool, Default, DString::DString(), 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, and setSourceFileName().

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: