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

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 QCString &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 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 l, 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 &) override
 
void startFold (int, const QCString &, const QCString &) override
 
void endFold () override
 
- Public Member Functions inherited from OutputCodeIntf
 OutputCodeIntf ()=default
 

Private Member Functions

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

Private Attributes

size_t m_col = 0
 
TextStreamm_t
 
bool m_doxyCodeLineOpen = false
 
QCString 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 QCString & 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.isEmpty())
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:7207

References Config_getInt, QCString::data(), QCString::isEmpty(), m_col, m_hide, m_stripIndentAmount, m_t, updateColumnCount(), and writeUTF8Char().

Referenced by writeCodeLink().

◆ endCodeFragment()

void RTFCodeGenerator::endCodeFragment ( const QCString & )
overridevirtual

Implements OutputCodeIntf.

Definition at line 225 of file rtfgen.cpp.

226{
227 endCodeLine();
228
229 DBG_RTF(*m_t << "{\\comment (endCodeFragment) }\n")
230 *m_t << "}\n";
231 //m_omitParagraph = TRUE;
232}
void endCodeLine() override
Definition rtfgen.cpp:285
#define DBG_RTF(x)

References DBG_RTF, endCodeLine(), and m_t.

◆ endCodeLine()

void RTFCodeGenerator::endCodeLine ( )
overridevirtual

Implements OutputCodeIntf.

Definition at line 285 of file rtfgen.cpp.

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

318{
319 if (m_hide) return;
320 *m_t << "}";
321}

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()

QCString RTFCodeGenerator::rtf_Code_DepthStyle ( )
private

Definition at line 323 of file rtfgen.cpp.

324{
325 QCString n=makeIndexName("CodeExample",m_indentLevel);
326 return rtf_Style[n.str()].reference();
327}
const std::string & str() const
Definition qcstring.h:526
int m_indentLevel
Definition rtfgen.h:71
static QCString makeIndexName(const QCString &s, int i)
Definition rtfgen.cpp:104
StyleDataMap rtf_Style
Definition rtfstyle.cpp:362

References m_indentLevel, makeIndexName(), rtf_Style, and QCString::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.

◆ setSourceFileName()

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

Definition at line 329 of file rtfgen.cpp.

330{
331 m_sourceFileName = name;
332}
QCString m_sourceFileName
Definition rtfgen.h:70

References m_sourceFileName.

◆ 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.

◆ startCodeFragment()

void RTFCodeGenerator::startCodeFragment ( const QCString & 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}
QCString rtf_Code_DepthStyle()
Definition rtfgen.cpp:323
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 278 of file rtfgen.cpp.

279{
280 if (m_hide) return;
281 m_doxyCodeLineOpen = true;
282 m_col=0;
283}

References m_col, m_doxyCodeLineOpen, and m_hide.

◆ startFold()

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

Implements OutputCodeIntf.

Definition at line 59 of file rtfgen.h.

59{}

◆ startFontClass()

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

Implements OutputCodeIntf.

Definition at line 292 of file rtfgen.cpp.

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

References m_hide, m_t, and QCString::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 QCString & )
inlineoverridevirtual

Implements OutputCodeIntf.

Definition at line 56 of file rtfgen.h.

56{}

◆ writeCodeLink()

void RTFCodeGenerator::writeCodeLink ( CodeSymbolType type,
const QCString & ref,
const QCString & file,
const QCString & anchor,
const QCString & name,
const QCString & 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.isEmpty() && Config_getBool(RTF_HYPERLINKS))
126 {
127 QCString refName;
128 if (!f.isEmpty())
129 {
130 refName+=stripPath(f);
131 }
132 if (!anchor.isEmpty())
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}
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
void codify(const QCString &text) override
Definition rtfgen.cpp:153
#define Config_getBool(name)
Definition config.h:33
QCString rtfFormatBmkStr(const QCString &name)
Definition rtfgen.cpp:2869
QCString stripPath(const QCString &s)
Definition util.cpp:5292

References codify(), Config_getBool, QCString::isEmpty(), QCString::length(), m_col, m_hide, m_t, rtfFormatBmkStr(), and stripPath().

Referenced by writeLineNumber().

◆ writeLineNumber()

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

Implements OutputCodeIntf.

Definition at line 234 of file rtfgen.cpp.

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

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

◆ writeTooltip()

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

Implements OutputCodeIntf.

Definition at line 44 of file rtfgen.h.

50 {}

Friends And Related Symbol Documentation

◆ 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

QCString 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: