Skip to content

Commit

Permalink
Add source code possibility for RTF output
Browse files Browse the repository at this point in the history
Analogous to Latex and HTML output the possibility to have source code shown in RTF output is created.
Based on question: http://doxygen.10944.n7.nabble.com/RTF-lack-of-source-code-tc6936.html
  • Loading branch information
albert-github committed Dec 10, 2014
1 parent dc37f6c commit 05eb230
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 13 deletions.
10 changes: 10 additions & 0 deletions src/config.xml
Expand Up @@ -2683,6 +2683,16 @@ EXTRA_PACKAGES=times
Syntax is similar to doxygen's config file.
A template extensions file can be generated using
<code>doxygen -e rtf extensionFile</code>.
]]>
</docs>
</option>
<option type='bool' id='RTF_SOURCE_CODE' defval='0' depends='GENERATE_RTF'>
<docs>
<![CDATA[
If the \c RTF_SOURCE_CODE tag is set to \c YES then doxygen will include
source code with syntax highlighting in the RTF output.
<br>Note that which sources are shown also depends on other settings
such as \ref cfg_source_browser "SOURCE_BROWSER".
]]>
</docs>
</option>
Expand Down
66 changes: 55 additions & 11 deletions src/definition.cpp
Expand Up @@ -911,6 +911,7 @@ QCString Definition::getSourceAnchor() const
void Definition::writeSourceDef(OutputList &ol,const char *)
{
static bool latexSourceCode = Config_getBool("LATEX_SOURCE_CODE");
static bool rtfSourceCode = Config_getBool("RTF_SOURCE_CODE");
ol.pushGeneratorState();
//printf("Definition::writeSourceRef %d %p\n",bodyLine,bodyDef);
QCString fn = getSourceFileBase();
Expand All @@ -930,21 +931,28 @@ void Definition::writeSourceDef(OutputList &ol,const char *)
// write text left from linePos marker
ol.parseText(refText.left(lineMarkerPos));
ol.pushGeneratorState();
ol.disable(OutputGenerator::RTF);
ol.disable(OutputGenerator::Man);
if (!latexSourceCode)
{
ol.disable(OutputGenerator::Latex);
}
// write line link (HTML, LaTeX optionally)
if (!rtfSourceCode)
{
ol.disable(OutputGenerator::RTF);
}
// write line link (HTML, LaTeX optionally, RTF optionally)
ol.writeObjectLink(0,fn,anchorStr,lineStr);
ol.enableAll();
ol.disable(OutputGenerator::Html);
if (latexSourceCode)
{
ol.disable(OutputGenerator::Latex);
}
// write normal text (Man/RTF, Latex optionally)
if (rtfSourceCode)
{
ol.disable(OutputGenerator::RTF);
}
// write normal text (Man, Latex optionally, RTF optionally)
ol.docify(lineStr);
ol.popGeneratorState();

Expand All @@ -953,21 +961,28 @@ void Definition::writeSourceDef(OutputList &ol,const char *)
fileMarkerPos-lineMarkerPos-2));

ol.pushGeneratorState();
ol.disable(OutputGenerator::RTF);
ol.disable(OutputGenerator::Man);
if (!latexSourceCode)
{
ol.disable(OutputGenerator::Latex);
}
// write file link (HTML, LaTeX optionally)
if (!rtfSourceCode)
{
ol.disable(OutputGenerator::RTF);
}
// write file link (HTML, LaTeX optionally, RTF optionally)
ol.writeObjectLink(0,fn,0,m_impl->body->fileDef->name());
ol.enableAll();
ol.disable(OutputGenerator::Html);
if (latexSourceCode)
{
ol.disable(OutputGenerator::Latex);
}
// write normal text (Man/RTF, Latex optionally)
if (rtfSourceCode)
{
ol.disable(OutputGenerator::RTF);
}
// write normal text (Man, Latex optionally, RTF optionally)
ol.docify(m_impl->body->fileDef->name());
ol.popGeneratorState();

Expand All @@ -980,12 +995,15 @@ void Definition::writeSourceDef(OutputList &ol,const char *)
// write text left from file marker
ol.parseText(refText.left(fileMarkerPos));
ol.pushGeneratorState();
ol.disable(OutputGenerator::RTF);
ol.disable(OutputGenerator::Man);
if (!latexSourceCode)
{
ol.disable(OutputGenerator::Latex);
}
if (!rtfSourceCode)
{
ol.disable(OutputGenerator::RTF);
}
// write file link (HTML only)
ol.writeObjectLink(0,fn,0,m_impl->body->fileDef->name());
ol.enableAll();
Expand All @@ -994,7 +1012,11 @@ void Definition::writeSourceDef(OutputList &ol,const char *)
{
ol.disable(OutputGenerator::Latex);
}
// write normal text (Latex/Man only)
if (rtfSourceCode)
{
ol.disable(OutputGenerator::RTF);
}
// write normal text (RTF/Latex/Man only)
ol.docify(m_impl->body->fileDef->name());
ol.popGeneratorState();

Expand All @@ -1003,12 +1025,15 @@ void Definition::writeSourceDef(OutputList &ol,const char *)
lineMarkerPos-fileMarkerPos-2));

ol.pushGeneratorState();
ol.disable(OutputGenerator::RTF);
ol.disable(OutputGenerator::Man);
if (!latexSourceCode)
{
ol.disable(OutputGenerator::Latex);
}
if (!rtfSourceCode)
{
ol.disable(OutputGenerator::RTF);
}
ol.disableAllBut(OutputGenerator::Html);
// write line link (HTML only)
ol.writeObjectLink(0,fn,anchorStr,lineStr);
Expand All @@ -1018,6 +1043,10 @@ void Definition::writeSourceDef(OutputList &ol,const char *)
{
ol.disable(OutputGenerator::Latex);
}
if (rtfSourceCode)
{
ol.disable(OutputGenerator::RTF);
}
// write normal text (Latex/Man only)
ol.docify(lineStr);
ol.popGeneratorState();
Expand Down Expand Up @@ -1107,6 +1136,7 @@ void Definition::_writeSourceRefList(OutputList &ol,const char *scopeName,
const QCString &text,MemberSDict *members,bool /*funcOnly*/)
{
static bool latexSourceCode = Config_getBool("LATEX_SOURCE_CODE");
static bool rtfSourceCode = Config_getBool("RTF_SOURCE_CODE");
static bool sourceBrowser = Config_getBool("SOURCE_BROWSER");
static bool refLinkSource = Config_getBool("REFERENCES_LINK_SOURCE");
ol.pushGeneratorState();
Expand Down Expand Up @@ -1159,12 +1189,15 @@ void Definition::_writeSourceRefList(OutputList &ol,const char *scopeName,
ol.pushGeneratorState();
//ol.disableAllBut(OutputGenerator::Html);

ol.disable(OutputGenerator::RTF);
ol.disable(OutputGenerator::Man);
if (!latexSourceCode)
{
ol.disable(OutputGenerator::Latex);
}
if (!rtfSourceCode)
{
ol.disable(OutputGenerator::RTF);
}
const int maxLineNrStr = 10;
char anchorStr[maxLineNrStr];
qsnprintf(anchorStr,maxLineNrStr,"l%05d",md->getStartBodyLine());
Expand All @@ -1179,6 +1212,10 @@ void Definition::_writeSourceRefList(OutputList &ol,const char *scopeName,
{
ol.disable(OutputGenerator::Latex);
}
if (!rtfSourceCode)
{
ol.disable(OutputGenerator::RTF);
}
ol.docify(name);
ol.popGeneratorState();
}
Expand All @@ -1187,12 +1224,15 @@ void Definition::_writeSourceRefList(OutputList &ol,const char *scopeName,
// for HTML write a real link
ol.pushGeneratorState();
//ol.disableAllBut(OutputGenerator::Html);
ol.disable(OutputGenerator::RTF);
ol.disable(OutputGenerator::Man);
if (!latexSourceCode)
{
ol.disable(OutputGenerator::Latex);
}
if (!rtfSourceCode)
{
ol.disable(OutputGenerator::RTF);
}

ol.writeObjectLink(md->getReference(),
md->getOutputFileBase(),
Expand All @@ -1206,6 +1246,10 @@ void Definition::_writeSourceRefList(OutputList &ol,const char *scopeName,
{
ol.disable(OutputGenerator::Latex);
}
if (rtfSourceCode)
{
ol.disable(OutputGenerator::RTF);
}
ol.docify(name);
ol.popGeneratorState();
}
Expand Down
9 changes: 8 additions & 1 deletion src/filedef.cpp
Expand Up @@ -333,6 +333,10 @@ void FileDef::writeDetailedDescription(OutputList &ol,const QCString &title)
{
ol.disable(OutputGenerator::Latex);
}
if (ol.isEnabled(OutputGenerator::RTF) && !Config_getBool("RTF_SOURCE_CODE"))
{
ol.disable(OutputGenerator::RTF);
}

ol.startParagraph();
QCString refText = theTranslator->trDefinedInSourceFile();
Expand Down Expand Up @@ -910,6 +914,7 @@ void FileDef::writeSource(OutputList &ol,bool sameTu,QStrList &filesInSameTu)
static bool generateTreeView = Config_getBool("GENERATE_TREEVIEW");
static bool filterSourceFiles = Config_getBool("FILTER_SOURCE_FILES");
static bool latexSourceCode = Config_getBool("LATEX_SOURCE_CODE");
static bool rtfSourceCode = Config_getBool("RTF_SOURCE_CODE");
DevNullCodeDocInterface devNullIntf;
QCString title = m_docname;
if (!m_fileVersion.isEmpty())
Expand All @@ -918,8 +923,8 @@ void FileDef::writeSource(OutputList &ol,bool sameTu,QStrList &filesInSameTu)
}
QCString pageTitle = theTranslator->trSourceFile(title);
ol.disable(OutputGenerator::Man);
ol.disable(OutputGenerator::RTF);
if (!latexSourceCode) ol.disable(OutputGenerator::Latex);
if (!rtfSourceCode) ol.disable(OutputGenerator::RTF);

bool isDocFile = isDocumentationFile();
bool genSourceFile = !isDocFile && generateSourceFile();
Expand Down Expand Up @@ -951,10 +956,12 @@ void FileDef::writeSource(OutputList &ol,bool sameTu,QStrList &filesInSameTu)
if (isLinkable())
{
if (latexSourceCode) ol.disable(OutputGenerator::Latex);
if (rtfSourceCode) ol.disable(OutputGenerator::RTF);
ol.startTextLink(getOutputFileBase(),0);
ol.parseText(theTranslator->trGotoDocumentation());
ol.endTextLink();
if (latexSourceCode) ol.enable(OutputGenerator::Latex);
if (rtfSourceCode) ol.enable(OutputGenerator::RTF);
}

(void)sameTu;
Expand Down
13 changes: 13 additions & 0 deletions src/rtfgen.cpp
Expand Up @@ -66,6 +66,7 @@ RTFGenerator::RTFGenerator() : OutputGenerator()
m_bstartedBody = FALSE;
m_omitParagraph = FALSE;
m_numCols = 0;
m_prettyCode=Config_getBool("RTF_SOURCE_CODE");
}

RTFGenerator::~RTFGenerator()
Expand Down Expand Up @@ -539,6 +540,8 @@ void RTFGenerator::endIndexSection(IndexSections is)
{
bool fortranOpt = Config_getBool("OPTIMIZE_FOR_FORTRAN");
bool vhdlOpt = Config_getBool("OPTIMIZE_OUTPUT_VHDL");
static bool sourceBrowser = Config_getBool("SOURCE_BROWSER");

switch (is)
{
case isTitlePageStart:
Expand Down Expand Up @@ -810,6 +813,11 @@ void RTFGenerator::endIndexSection(IndexSections is)
t << "{\\field\\fldedit{\\*\\fldinst INCLUDETEXT \"";
t << fd->getOutputFileBase();
t << ".rtf\" \\\\*MERGEFORMAT}{\\fldrslt includedstuff}}\n";
if (sourceBrowser && m_prettyCode && fd->generateSourceFile())
{
t << "\\par " << rtf_Style_Reset << endl;
t << "{\\field\\fldedit{\\*\\fldinst INCLUDETEXT \"" << fd->getSourceFileBase() << ".rtf\" \\\\*MERGEFORMAT}{\\fldrslt includedstuff}}\n";
}
isFirst=FALSE;
}
else
Expand All @@ -819,6 +827,11 @@ void RTFGenerator::endIndexSection(IndexSections is)
t << "{\\field\\fldedit{\\*\\fldinst INCLUDETEXT \"";
t << fd->getOutputFileBase();
t << ".rtf\" \\\\*MERGEFORMAT}{\\fldrslt includedstuff}}\n";
if (sourceBrowser && m_prettyCode && fd->generateSourceFile())
{
t << "\\par " << rtf_Style_Reset << endl;
t << "{\\field\\fldedit{\\*\\fldinst INCLUDETEXT \"" << fd->getSourceFileBase() << ".rtf\" \\\\*MERGEFORMAT}{\\fldrslt includedstuff}}\n";
}
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/rtfgen.h
Expand Up @@ -126,7 +126,7 @@ class RTFGenerator : public OutputGenerator
void writeAnchor(const char *fileName,const char *name);
void startCodeFragment();
void endCodeFragment();
void writeLineNumber(const char *,const char *,const char *,int l) { t << l << " "; }
void writeLineNumber(const char *,const char *,const char *,int l) { t << QString("%1").arg(l,5) << " "; }
void startCodeLine(bool) { col=0; }
void endCodeLine() { lineBreak(); }
void startEmphasis() { t << "{\\i "; }
Expand Down Expand Up @@ -277,6 +277,7 @@ class RTFGenerator : public OutputGenerator
void incrementIndentLevel();
void decrementIndentLevel();
int col;
bool m_prettyCode;

bool m_bstartedBody; // has startbody been called yet?
int m_listLevel; // // RTF does not really have a addative indent...manually set list level.
Expand Down

0 comments on commit 05eb230

Please sign in to comment.