Skip to content

Commit 10b2b8f

Browse files
committed
Improve formula handling and rendering.
Also added option HTML_FORMULA_FORMAT to generate SVG files for images (requires pdf2svg)
1 parent b107d34 commit 10b2b8f

File tree

10 files changed

+406
-352
lines changed

10 files changed

+406
-352
lines changed

src/commentscan.l

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717
%option prefix="commentscanYY"
1818
%option reentrant
1919
%option extra-type="struct commentscanYY_state *"
20+
%top{
21+
#include <stdint.h>
22+
}
2023

2124
%{
2225

@@ -2862,21 +2865,9 @@ static QCString addFormula(yyscan_t yyscanner)
28622865
struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
28632866
QCString formLabel;
28642867
QCString fText=yyextra->formulaText.simplifyWhiteSpace();
2865-
Formula *f=0;
2866-
if ((f=Doxygen::formulaDict->find(fText))==0)
2867-
{
2868-
f = new Formula(fText);
2869-
Doxygen::formulaList->append(f);
2870-
Doxygen::formulaDict->insert(fText,f);
2871-
formLabel.sprintf("\\_form#%d",f->getId());
2872-
Doxygen::formulaNameDict->insert(formLabel,f);
2873-
}
2874-
else
2875-
{
2876-
formLabel.sprintf("\\_form#%d",f->getId());
2877-
}
2878-
int i;
2879-
for (i=0;i<yyextra->formulaNewLines;i++) formLabel+="@_fakenl"; // add fake newlines to
2868+
int id = FormulaManager::instance().addFormula(fText);
2869+
formLabel.sprintf("\\_form#%d",id);
2870+
for (int i=0;i<yyextra->formulaNewLines;i++) formLabel+="@_fakenl"; // add fake newlines to
28802871
// keep the warnings
28812872
// correctly aligned.
28822873
return formLabel;

src/config.xml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2357,6 +2357,17 @@ The \c DOCSET_PUBLISHER_NAME tag identifies the documentation publisher.
23572357
]]>
23582358
</docs>
23592359
</option>
2360+
<option type='enum' id='HTML_FORMULA_FORMAT' defval='PNG' depends='GENERATE_HTML'>
2361+
<docs>
2362+
<![CDATA[
2363+
If the \c HTML_FORMULA_FORMAT option is set to \c SVG, doxygen will use the pdf2svg
2364+
tool (see https://github.com/dawbarton/pdf2svg) to generate formulas as SVG images instead of
2365+
PNGs for the HTML output. These images will generally look nicer at scaled resolutions.
2366+
]]>
2367+
</docs>
2368+
<value name="PNG" desc="The default"/>
2369+
<value name="SVG" desc="Looks nicer but requires the pdf2svg tool"/>
2370+
</option>
23602371
<option type='int' id='FORMULA_FONTSIZE' minval='8' maxval='50' defval='10' depends='GENERATE_HTML'>
23612372
<docs>
23622373
<![CDATA[

src/docparser.cpp

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2223,15 +2223,13 @@ bool DocXRefItem::parse()
22232223
DocFormula::DocFormula(DocNode *parent,int id) :
22242224
m_relPath(g_relPath)
22252225
{
2226-
m_parent = parent;
2227-
QCString formCmd;
2228-
formCmd.sprintf("\\_form#%d",id);
2229-
Formula *formula=Doxygen::formulaNameDict->find(formCmd);
2230-
if (formula)
2226+
m_parent = parent;
2227+
QCString text = FormulaManager::instance().findFormula(id);
2228+
if (!text.isEmpty())
22312229
{
2232-
m_id = formula->getId();
2230+
m_id = id;
22332231
m_name.sprintf("form_%d",m_id);
2234-
m_text = formula->getFormulaText();
2232+
m_text = text;
22352233
}
22362234
else // wrong \_form#<n> command
22372235
{

src/doxygen.cpp

Lines changed: 34 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,6 @@ MemberNameSDict *Doxygen::functionNameSDict = 0;
126126
FileNameList *Doxygen::inputNameList = 0; // all input files
127127
FileNameDict *Doxygen::inputNameDict = 0;
128128
GroupSDict *Doxygen::groupSDict = 0;
129-
FormulaList *Doxygen::formulaList = 0; // all formulas
130-
FormulaDict *Doxygen::formulaDict = 0; // all formulas
131-
FormulaDict *Doxygen::formulaNameDict = 0; // the label name of all formulas
132129
PageSDict *Doxygen::pageSDict = 0;
133130
PageSDict *Doxygen::exampleSDict = 0;
134131
SectionDict *Doxygen::sectionDict = 0; // all page sections
@@ -197,7 +194,6 @@ void clearAll()
197194
Doxygen::pageSDict->clear();
198195
Doxygen::exampleSDict->clear();
199196
Doxygen::inputNameList->clear();
200-
Doxygen::formulaList->clear();
201197
Doxygen::sectionDict->clear();
202198
Doxygen::inputNameDict->clear();
203199
Doxygen::includeNameDict->clear();
@@ -206,11 +202,10 @@ void clearAll()
206202
Doxygen::dotFileNameDict->clear();
207203
Doxygen::mscFileNameDict->clear();
208204
Doxygen::diaFileNameDict->clear();
209-
Doxygen::formulaDict->clear();
210-
Doxygen::formulaNameDict->clear();
211205
Doxygen::tagDestinationDict.clear();
212206
delete Doxygen::citeDict;
213207
delete Doxygen::mainPage; Doxygen::mainPage=0;
208+
FormulaManager::instance().clear();
214209
}
215210

216211
class Statistics
@@ -281,10 +276,6 @@ void statistics()
281276
fprintf(stderr,"--- typedefDict stats ----\n");
282277
fprintf(stderr,"--- namespaceAliasDict stats ----\n");
283278
Doxygen::namespaceAliasDict.statistics();
284-
fprintf(stderr,"--- formulaDict stats ----\n");
285-
Doxygen::formulaDict->statistics();
286-
fprintf(stderr,"--- formulaNameDict stats ----\n");
287-
Doxygen::formulaNameDict->statistics();
288279
fprintf(stderr,"--- tagDestinationDict stats ----\n");
289280
Doxygen::tagDestinationDict.statistics();
290281
fprintf(stderr,"--- g_compoundKeywordDict stats ----\n");
@@ -9576,66 +9567,6 @@ int readFileOrDirectory(const char *s,
95769567

95779568
//----------------------------------------------------------------------------
95789569

9579-
void readFormulaRepository(QCString dir, bool cmp)
9580-
{
9581-
static int current_repository = 0;
9582-
int new_repository = 0;
9583-
QFile f(dir+"/formula.repository");
9584-
if (f.open(IO_ReadOnly)) // open repository
9585-
{
9586-
msg("Reading formula repository...\n");
9587-
QTextStream t(&f);
9588-
QCString line;
9589-
Formula *f;
9590-
while (!t.eof())
9591-
{
9592-
line=t.readLine().utf8();
9593-
int se=line.find(':'); // find name and text separator.
9594-
if (se==-1)
9595-
{
9596-
warn_uncond("formula.repository is corrupted!\n");
9597-
break;
9598-
}
9599-
else
9600-
{
9601-
QCString formName = line.left(se);
9602-
QCString formText = line.right(line.length()-se-1);
9603-
if (cmp)
9604-
{
9605-
if ((f=Doxygen::formulaDict->find(formText))==0)
9606-
{
9607-
term("discrepancy between formula repositories! Remove "
9608-
"formula.repository and from_* files from output directories.");
9609-
}
9610-
QCString formLabel;
9611-
formLabel.sprintf("\\_form#%d",f->getId());
9612-
if (formLabel != formName)
9613-
{
9614-
term("discrepancy between formula repositories! Remove "
9615-
"formula.repository and from_* files from output directories.");
9616-
}
9617-
new_repository++;
9618-
}
9619-
else
9620-
{
9621-
f=new Formula(formText);
9622-
Doxygen::formulaList->append(f);
9623-
Doxygen::formulaDict->insert(formText,f);
9624-
Doxygen::formulaNameDict->insert(formName,f);
9625-
current_repository++;
9626-
}
9627-
}
9628-
}
9629-
}
9630-
if (cmp && (current_repository != new_repository))
9631-
{
9632-
term("size discrepancy between formula repositories! Remove "
9633-
"formula.repository and from_* files from output directories.");
9634-
}
9635-
}
9636-
9637-
//----------------------------------------------------------------------------
9638-
96399570
static void expandAliases()
96409571
{
96419572
QDictIterator<QCString> adi(Doxygen::aliasDict);
@@ -9935,10 +9866,6 @@ void initDoxygen()
99359866
Doxygen::citeDict = new CiteDict(257);
99369867
Doxygen::genericsDict = new GenericsSDict;
99379868
Doxygen::indexList = new IndexList;
9938-
Doxygen::formulaList = new FormulaList;
9939-
Doxygen::formulaList->setAutoDelete(TRUE);
9940-
Doxygen::formulaDict = new FormulaDict(1009);
9941-
Doxygen::formulaNameDict = new FormulaDict(1009);
99429869
Doxygen::sectionDict = new SectionDict(257);
99439870
Doxygen::sectionDict->setAutoDelete(TRUE);
99449871

@@ -9968,10 +9895,9 @@ void initDoxygen()
99689895

99699896
void cleanUpDoxygen()
99709897
{
9898+
FormulaManager::instance().clear();
9899+
99719900
delete Doxygen::sectionDict;
9972-
delete Doxygen::formulaNameDict;
9973-
delete Doxygen::formulaDict;
9974-
delete Doxygen::formulaList;
99759901
delete Doxygen::indexList;
99769902
delete Doxygen::genericsDict;
99779903
delete Doxygen::inputNameDict;
@@ -11036,18 +10962,22 @@ void parseInput()
1103610962

1103710963
if (Config_getBool(GENERATE_HTML) && !Config_getBool(USE_MATHJAX))
1103810964
{
11039-
readFormulaRepository(Config_getString(HTML_OUTPUT));
10965+
FormulaManager::instance().readFormulas(Config_getString(HTML_OUTPUT));
1104010966
}
1104110967
if (Config_getBool(GENERATE_RTF))
1104210968
{
1104310969
// in case GENERRATE_HTML is set we just have to compare, both repositories should be identical
11044-
readFormulaRepository(Config_getString(RTF_OUTPUT),Config_getBool(GENERATE_HTML) && !Config_getBool(USE_MATHJAX));
10970+
FormulaManager::instance().readFormulas(Config_getString(RTF_OUTPUT),
10971+
Config_getBool(GENERATE_HTML) &&
10972+
!Config_getBool(USE_MATHJAX));
1104510973
}
1104610974
if (Config_getBool(GENERATE_DOCBOOK))
1104710975
{
1104810976
// in case GENERRATE_HTML is set we just have to compare, both repositories should be identical
11049-
readFormulaRepository(Config_getString(DOCBOOK_OUTPUT),
11050-
(Config_getBool(GENERATE_HTML) && !Config_getBool(USE_MATHJAX)) || Config_getBool(GENERATE_RTF));
10977+
FormulaManager::instance().readFormulas(Config_getString(DOCBOOK_OUTPUT),
10978+
(Config_getBool(GENERATE_HTML) &&
10979+
!Config_getBool(USE_MATHJAX)) ||
10980+
Config_getBool(GENERATE_RTF));
1105110981
}
1105210982

1105310983
/**************************************************************************
@@ -11477,6 +11407,29 @@ void generateOutput()
1147711407
}
1147811408
g_s.end();
1147911409

11410+
const FormulaManager &fm = FormulaManager::instance();
11411+
if (fm.hasFormulas() && generateHtml
11412+
&& !Config_getBool(USE_MATHJAX))
11413+
{
11414+
g_s.begin("Generating images for formulas in HTML...\n");
11415+
fm.generateImages(Config_getString(HTML_OUTPUT), Config_getEnum(HTML_FORMULA_FORMAT)=="SVG" ?
11416+
FormulaManager::Format::Vector : FormulaManager::Format::Bitmap, FormulaManager::HighDPI::On);
11417+
g_s.end();
11418+
}
11419+
if (fm.hasFormulas() && generateRtf)
11420+
{
11421+
g_s.begin("Generating images for formulas in RTF...\n");
11422+
fm.generateImages(Config_getString(RTF_OUTPUT),FormulaManager::Format::Bitmap);
11423+
g_s.end();
11424+
}
11425+
11426+
if (fm.hasFormulas() && generateDocbook)
11427+
{
11428+
g_s.begin("Generating images for formulas in Docbook...\n");
11429+
fm.generateImages(Config_getString(DOCBOOK_OUTPUT),FormulaManager::Format::Bitmap);
11430+
g_s.end();
11431+
}
11432+
1148011433
g_s.begin("Generating example documentation...\n");
1148111434
generateExampleDocs();
1148211435
g_s.end();
@@ -11516,27 +11469,6 @@ void generateOutput()
1151611469
generateDirDocs(*g_outputList);
1151711470
g_s.end();
1151811471

11519-
if (Doxygen::formulaList->count()>0 && generateHtml
11520-
&& !Config_getBool(USE_MATHJAX))
11521-
{
11522-
g_s.begin("Generating bitmaps for formulas in HTML...\n");
11523-
Doxygen::formulaList->generateBitmaps(Config_getString(HTML_OUTPUT));
11524-
g_s.end();
11525-
}
11526-
if (Doxygen::formulaList->count()>0 && generateRtf)
11527-
{
11528-
g_s.begin("Generating bitmaps for formulas in RTF...\n");
11529-
Doxygen::formulaList->generateBitmaps(Config_getString(RTF_OUTPUT));
11530-
g_s.end();
11531-
}
11532-
11533-
if (Doxygen::formulaList->count()>0 && generateDocbook)
11534-
{
11535-
g_s.begin("Generating bitmaps for formulas in Docbook...\n");
11536-
Doxygen::formulaList->generateBitmaps(Config_getString(DOCBOOK_OUTPUT));
11537-
g_s.end();
11538-
}
11539-
1154011472
if (Config_getBool(SORT_GROUP_NAMES))
1154111473
{
1154211474
Doxygen::groupSDict->sort();

src/doxygen.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,6 @@ class Doxygen
116116
static StringDict namespaceAliasDict;
117117
static GroupSDict *groupSDict;
118118
static NamespaceSDict *namespaceSDict;
119-
static FormulaList *formulaList;
120-
static FormulaDict *formulaDict;
121-
static FormulaDict *formulaNameDict;
122119
static StringDict tagDestinationDict;
123120
static StringDict aliasDict;
124121
static QIntDict<MemberGroupInfo> memGrpInfoDict;

0 commit comments

Comments
 (0)