Skip to content

Commit

Permalink
Improve formula handling and rendering.
Browse files Browse the repository at this point in the history
Also added option HTML_FORMULA_FORMAT to generate SVG files for images (requires pdf2svg)
  • Loading branch information
doxygen committed Feb 12, 2020
1 parent b107d34 commit 10b2b8f
Show file tree
Hide file tree
Showing 10 changed files with 406 additions and 352 deletions.
21 changes: 6 additions & 15 deletions src/commentscan.l
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
%option prefix="commentscanYY"
%option reentrant
%option extra-type="struct commentscanYY_state *"
%top{
#include <stdint.h>
}

%{

Expand Down Expand Up @@ -2862,21 +2865,9 @@ static QCString addFormula(yyscan_t yyscanner)
struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
QCString formLabel;
QCString fText=yyextra->formulaText.simplifyWhiteSpace();
Formula *f=0;
if ((f=Doxygen::formulaDict->find(fText))==0)
{
f = new Formula(fText);
Doxygen::formulaList->append(f);
Doxygen::formulaDict->insert(fText,f);
formLabel.sprintf("\\_form#%d",f->getId());
Doxygen::formulaNameDict->insert(formLabel,f);
}
else
{
formLabel.sprintf("\\_form#%d",f->getId());
}
int i;
for (i=0;i<yyextra->formulaNewLines;i++) formLabel+="@_fakenl"; // add fake newlines to
int id = FormulaManager::instance().addFormula(fText);
formLabel.sprintf("\\_form#%d",id);
for (int i=0;i<yyextra->formulaNewLines;i++) formLabel+="@_fakenl"; // add fake newlines to
// keep the warnings
// correctly aligned.
return formLabel;
Expand Down
11 changes: 11 additions & 0 deletions src/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2357,6 +2357,17 @@ The \c DOCSET_PUBLISHER_NAME tag identifies the documentation publisher.
]]>
</docs>
</option>
<option type='enum' id='HTML_FORMULA_FORMAT' defval='PNG' depends='GENERATE_HTML'>
<docs>
<![CDATA[
If the \c HTML_FORMULA_FORMAT option is set to \c SVG, doxygen will use the pdf2svg
tool (see https://github.com/dawbarton/pdf2svg) to generate formulas as SVG images instead of
PNGs for the HTML output. These images will generally look nicer at scaled resolutions.
]]>
</docs>
<value name="PNG" desc="The default"/>
<value name="SVG" desc="Looks nicer but requires the pdf2svg tool"/>
</option>
<option type='int' id='FORMULA_FONTSIZE' minval='8' maxval='50' defval='10' depends='GENERATE_HTML'>
<docs>
<![CDATA[
Expand Down
12 changes: 5 additions & 7 deletions src/docparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2223,15 +2223,13 @@ bool DocXRefItem::parse()
DocFormula::DocFormula(DocNode *parent,int id) :
m_relPath(g_relPath)
{
m_parent = parent;
QCString formCmd;
formCmd.sprintf("\\_form#%d",id);
Formula *formula=Doxygen::formulaNameDict->find(formCmd);
if (formula)
m_parent = parent;
QCString text = FormulaManager::instance().findFormula(id);
if (!text.isEmpty())
{
m_id = formula->getId();
m_id = id;
m_name.sprintf("form_%d",m_id);
m_text = formula->getFormulaText();
m_text = text;
}
else // wrong \_form#<n> command
{
Expand Down
136 changes: 34 additions & 102 deletions src/doxygen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,6 @@ MemberNameSDict *Doxygen::functionNameSDict = 0;
FileNameList *Doxygen::inputNameList = 0; // all input files
FileNameDict *Doxygen::inputNameDict = 0;
GroupSDict *Doxygen::groupSDict = 0;
FormulaList *Doxygen::formulaList = 0; // all formulas
FormulaDict *Doxygen::formulaDict = 0; // all formulas
FormulaDict *Doxygen::formulaNameDict = 0; // the label name of all formulas
PageSDict *Doxygen::pageSDict = 0;
PageSDict *Doxygen::exampleSDict = 0;
SectionDict *Doxygen::sectionDict = 0; // all page sections
Expand Down Expand Up @@ -197,7 +194,6 @@ void clearAll()
Doxygen::pageSDict->clear();
Doxygen::exampleSDict->clear();
Doxygen::inputNameList->clear();
Doxygen::formulaList->clear();
Doxygen::sectionDict->clear();
Doxygen::inputNameDict->clear();
Doxygen::includeNameDict->clear();
Expand All @@ -206,11 +202,10 @@ void clearAll()
Doxygen::dotFileNameDict->clear();
Doxygen::mscFileNameDict->clear();
Doxygen::diaFileNameDict->clear();
Doxygen::formulaDict->clear();
Doxygen::formulaNameDict->clear();
Doxygen::tagDestinationDict.clear();
delete Doxygen::citeDict;
delete Doxygen::mainPage; Doxygen::mainPage=0;
FormulaManager::instance().clear();
}

class Statistics
Expand Down Expand Up @@ -281,10 +276,6 @@ void statistics()
fprintf(stderr,"--- typedefDict stats ----\n");
fprintf(stderr,"--- namespaceAliasDict stats ----\n");
Doxygen::namespaceAliasDict.statistics();
fprintf(stderr,"--- formulaDict stats ----\n");
Doxygen::formulaDict->statistics();
fprintf(stderr,"--- formulaNameDict stats ----\n");
Doxygen::formulaNameDict->statistics();
fprintf(stderr,"--- tagDestinationDict stats ----\n");
Doxygen::tagDestinationDict.statistics();
fprintf(stderr,"--- g_compoundKeywordDict stats ----\n");
Expand Down Expand Up @@ -9576,66 +9567,6 @@ int readFileOrDirectory(const char *s,

//----------------------------------------------------------------------------

void readFormulaRepository(QCString dir, bool cmp)
{
static int current_repository = 0;
int new_repository = 0;
QFile f(dir+"/formula.repository");
if (f.open(IO_ReadOnly)) // open repository
{
msg("Reading formula repository...\n");
QTextStream t(&f);
QCString line;
Formula *f;
while (!t.eof())
{
line=t.readLine().utf8();
int se=line.find(':'); // find name and text separator.
if (se==-1)
{
warn_uncond("formula.repository is corrupted!\n");
break;
}
else
{
QCString formName = line.left(se);
QCString formText = line.right(line.length()-se-1);
if (cmp)
{
if ((f=Doxygen::formulaDict->find(formText))==0)
{
term("discrepancy between formula repositories! Remove "
"formula.repository and from_* files from output directories.");
}
QCString formLabel;
formLabel.sprintf("\\_form#%d",f->getId());
if (formLabel != formName)
{
term("discrepancy between formula repositories! Remove "
"formula.repository and from_* files from output directories.");
}
new_repository++;
}
else
{
f=new Formula(formText);
Doxygen::formulaList->append(f);
Doxygen::formulaDict->insert(formText,f);
Doxygen::formulaNameDict->insert(formName,f);
current_repository++;
}
}
}
}
if (cmp && (current_repository != new_repository))
{
term("size discrepancy between formula repositories! Remove "
"formula.repository and from_* files from output directories.");
}
}

//----------------------------------------------------------------------------

static void expandAliases()
{
QDictIterator<QCString> adi(Doxygen::aliasDict);
Expand Down Expand Up @@ -9935,10 +9866,6 @@ void initDoxygen()
Doxygen::citeDict = new CiteDict(257);
Doxygen::genericsDict = new GenericsSDict;
Doxygen::indexList = new IndexList;
Doxygen::formulaList = new FormulaList;
Doxygen::formulaList->setAutoDelete(TRUE);
Doxygen::formulaDict = new FormulaDict(1009);
Doxygen::formulaNameDict = new FormulaDict(1009);
Doxygen::sectionDict = new SectionDict(257);
Doxygen::sectionDict->setAutoDelete(TRUE);

Expand Down Expand Up @@ -9968,10 +9895,9 @@ void initDoxygen()

void cleanUpDoxygen()
{
FormulaManager::instance().clear();

delete Doxygen::sectionDict;
delete Doxygen::formulaNameDict;
delete Doxygen::formulaDict;
delete Doxygen::formulaList;
delete Doxygen::indexList;
delete Doxygen::genericsDict;
delete Doxygen::inputNameDict;
Expand Down Expand Up @@ -11036,18 +10962,22 @@ void parseInput()

if (Config_getBool(GENERATE_HTML) && !Config_getBool(USE_MATHJAX))
{
readFormulaRepository(Config_getString(HTML_OUTPUT));
FormulaManager::instance().readFormulas(Config_getString(HTML_OUTPUT));
}
if (Config_getBool(GENERATE_RTF))
{
// in case GENERRATE_HTML is set we just have to compare, both repositories should be identical
readFormulaRepository(Config_getString(RTF_OUTPUT),Config_getBool(GENERATE_HTML) && !Config_getBool(USE_MATHJAX));
FormulaManager::instance().readFormulas(Config_getString(RTF_OUTPUT),
Config_getBool(GENERATE_HTML) &&
!Config_getBool(USE_MATHJAX));
}
if (Config_getBool(GENERATE_DOCBOOK))
{
// in case GENERRATE_HTML is set we just have to compare, both repositories should be identical
readFormulaRepository(Config_getString(DOCBOOK_OUTPUT),
(Config_getBool(GENERATE_HTML) && !Config_getBool(USE_MATHJAX)) || Config_getBool(GENERATE_RTF));
FormulaManager::instance().readFormulas(Config_getString(DOCBOOK_OUTPUT),
(Config_getBool(GENERATE_HTML) &&
!Config_getBool(USE_MATHJAX)) ||
Config_getBool(GENERATE_RTF));
}

/**************************************************************************
Expand Down Expand Up @@ -11477,6 +11407,29 @@ void generateOutput()
}
g_s.end();

const FormulaManager &fm = FormulaManager::instance();
if (fm.hasFormulas() && generateHtml
&& !Config_getBool(USE_MATHJAX))
{
g_s.begin("Generating images for formulas in HTML...\n");
fm.generateImages(Config_getString(HTML_OUTPUT), Config_getEnum(HTML_FORMULA_FORMAT)=="SVG" ?
FormulaManager::Format::Vector : FormulaManager::Format::Bitmap, FormulaManager::HighDPI::On);
g_s.end();
}
if (fm.hasFormulas() && generateRtf)
{
g_s.begin("Generating images for formulas in RTF...\n");
fm.generateImages(Config_getString(RTF_OUTPUT),FormulaManager::Format::Bitmap);
g_s.end();
}

if (fm.hasFormulas() && generateDocbook)
{
g_s.begin("Generating images for formulas in Docbook...\n");
fm.generateImages(Config_getString(DOCBOOK_OUTPUT),FormulaManager::Format::Bitmap);
g_s.end();
}

g_s.begin("Generating example documentation...\n");
generateExampleDocs();
g_s.end();
Expand Down Expand Up @@ -11516,27 +11469,6 @@ void generateOutput()
generateDirDocs(*g_outputList);
g_s.end();

if (Doxygen::formulaList->count()>0 && generateHtml
&& !Config_getBool(USE_MATHJAX))
{
g_s.begin("Generating bitmaps for formulas in HTML...\n");
Doxygen::formulaList->generateBitmaps(Config_getString(HTML_OUTPUT));
g_s.end();
}
if (Doxygen::formulaList->count()>0 && generateRtf)
{
g_s.begin("Generating bitmaps for formulas in RTF...\n");
Doxygen::formulaList->generateBitmaps(Config_getString(RTF_OUTPUT));
g_s.end();
}

if (Doxygen::formulaList->count()>0 && generateDocbook)
{
g_s.begin("Generating bitmaps for formulas in Docbook...\n");
Doxygen::formulaList->generateBitmaps(Config_getString(DOCBOOK_OUTPUT));
g_s.end();
}

if (Config_getBool(SORT_GROUP_NAMES))
{
Doxygen::groupSDict->sort();
Expand Down
3 changes: 0 additions & 3 deletions src/doxygen.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,6 @@ class Doxygen
static StringDict namespaceAliasDict;
static GroupSDict *groupSDict;
static NamespaceSDict *namespaceSDict;
static FormulaList *formulaList;
static FormulaDict *formulaDict;
static FormulaDict *formulaNameDict;
static StringDict tagDestinationDict;
static StringDict aliasDict;
static QIntDict<MemberGroupInfo> memGrpInfoDict;
Expand Down
Loading

0 comments on commit 10b2b8f

Please sign in to comment.