diff options
author | albert-github <albert.tests@gmail.com> | 2014-11-28 13:44:07 (GMT) |
---|---|---|
committer | albert-github <albert.tests@gmail.com> | 2014-11-28 13:44:07 (GMT) |
commit | 329a4ddc036ac9dfe72b11d62cb4043bc8488c20 (patch) | |
tree | 8ca50b460259cbadced0e68f100ba3fb620faed7 /src/docbookvisitor.cpp | |
parent | 0fea3d4ca57187f271d7580ff16f32b7ab4657df (diff) | |
download | Doxygen-329a4ddc036ac9dfe72b11d62cb4043bc8488c20.zip Doxygen-329a4ddc036ac9dfe72b11d62cb4043bc8488c20.tar.gz Doxygen-329a4ddc036ac9dfe72b11d62cb4043bc8488c20.tar.bz2 |
Limit images sizes and make more uniform (LaTeX)
This patch adjusts some problems regarding image sizes in LaTeX output of doxygen (a.o. Bug 738299 - When using msc or PlantUML, the default latex for the created image should include [width=\linewidth]) this has been done is such a way that all the "image" commands (i.e. image, dot, dotfile, msc, mscfile, diafile, startuml) operate in a similar way / have the same possibilities.
- commands.doc
Adjusted documentation to reflect changes.
- cmdmapper.cpp
- cmdmapper.h
Added utility function to map command id back to command name
- doctokenizer.h
- doctokenizer.l
Handle Caption and Size indication. Required also that some other rules had to be tightened a bit (like usage of {} in startuml and usage of "" for captions. This was already described in the documentation in this way).
- docparser.cpp
- docparser.h
Created routine to uniformly handle the Caption and size indications and store them in a general way.
- latexgen.cpp
Replaced graphicx package by adjustbox package (includes graphicx) to support "min width" etc.
- doxygen.sty templates\latex
Added commands to make commands with and without caption behave similar.
- docbookvisitor.cpp
- docbookvisitor.h
- htmldocvisitor.cpp
- latexdocvisitor.cpp
- latexdocvisitor.h
- printdocvisitor.h
- xmldocvisitor.cpp
Created routine to uniformly handle the Caption and size indications in a general way.
- indexpage.xml (testing\022)
- indexpage.xml (testing\031)
- class_receiver.xml (testing\037)
- class_sender.xml (testing\037)
Adjusted example output.
Diffstat (limited to 'src/docbookvisitor.cpp')
-rw-r--r-- | src/docbookvisitor.cpp | 272 |
1 files changed, 98 insertions, 174 deletions
diff --git a/src/docbookvisitor.cpp b/src/docbookvisitor.cpp index a227dd8..0d5f260 100644 --- a/src/docbookvisitor.cpp +++ b/src/docbookvisitor.cpp @@ -36,6 +36,68 @@ #include "htmlentity.h" #include "plantuml.h" +static void visitPreStart(FTextStream &t, const bool hasCaption, QCString name, QCString width, QCString height) +{ + QCString tmpStr; + t << " <figure>" << endl; + t << " <title></title>" << endl; + t << " <mediaobject>" << endl; + t << " <imageobject>" << endl; + t << " <imagedata"; + if (!width.isEmpty()) + { + tmpStr = width; + tmpStr = tmpStr.replace(QRegExp("min *width"),"minwidth"); + tmpStr = tmpStr.replace(QRegExp("max *width"),"maxwidth"); + tmpStr = tmpStr.replace(QRegExp("="),"=\""); + tmpStr = tmpStr.replace(QRegExp(","),"\" ") + "\""; + tmpStr = tmpStr.replace(QRegExp("\"\""),"\""); + tmpStr = tmpStr.replace(QRegExp("\\"),"\\\\"); + t << " " << tmpStr; + } + else + { + t << " width=\"50%\""; + } + if (!height.isEmpty()) + { + tmpStr = height; + tmpStr = tmpStr.replace(QRegExp("min *height"),"mindepth"); + tmpStr = tmpStr.replace(QRegExp("max *height"),"maxdepth"); + tmpStr = tmpStr.replace(QRegExp("height="),"depth="); + tmpStr = tmpStr.replace(QRegExp("="),"=\""); + tmpStr = tmpStr.replace(QRegExp(","),"\" ") + "\""; + tmpStr = tmpStr.replace(QRegExp("\"\""),"\""); + tmpStr = tmpStr.replace(QRegExp("\\"),"\\\\"); + t << " " << tmpStr; + } + t << " align=\"center\" valign=\"middle\" scalefit=\"1\" fileref=\"" << name << "\">"; + t << "</imagedata>" << endl; + t << " </imageobject>" << endl; + if (hasCaption) + { + t << " <caption>" << endl; + } +} + +static void visitPostEnd(FTextStream &t, const bool hasCaption) +{ + t << endl; + if (hasCaption) + { + t << " </caption>" << endl; + } + t << " </mediaobject>" << endl; + t << " </figure>" << endl; +} + +static void visitCaption(DocbookDocVisitor *parent, QList<DocNode> children) +{ + QListIterator<DocNode> cli(children); + DocNode *n; + for (cli.toFirst();(n=cli.current());++cli) n->accept(parent); +} + DocbookDocVisitor::DocbookDocVisitor(FTextStream &t,CodeOutputInterface &ci) : DocVisitor(DocVisitor_Docbook), m_t(t), m_ci(ci), m_insidePre(FALSE), m_hide(FALSE) { @@ -205,14 +267,7 @@ void DocbookDocVisitor::visit(DocVerbatim *s) } file.writeBlock( stext, stext.length() ); file.close(); - m_t << " <figure>" << endl; - m_t << " <title>" << name << "</title>" << endl; - m_t << " <mediaobject>" << endl; - m_t << " <imageobject>" << endl; - writeDotFile(baseName); - m_t << " </imageobject>" << endl; - m_t << " </mediaobject>" << endl; - m_t << " </figure>" << endl; + writeDotFile(baseName, s); m_t << "</para>" << endl; } break; @@ -238,14 +293,7 @@ void DocbookDocVisitor::visit(DocVerbatim *s) text+="}"; file.writeBlock( text, text.length() ); file.close(); - m_t << " <figure>" << endl; - m_t << " <title>" << name << "</title>" << endl; - m_t << " <mediaobject>" << endl; - m_t << " <imageobject>" << endl; - writeMscFile(baseName); - m_t << " </imageobject>" << endl; - m_t << " </mediaobject>" << endl; - m_t << " </figure>" << endl; + writeMscFile(baseName,s); m_t << "</para>" << endl; } break; @@ -259,14 +307,8 @@ void DocbookDocVisitor::visit(DocVerbatim *s) { shortName=shortName.right(shortName.length()-i-1); } - m_t << " <figure>" << endl; - m_t << " <title>" << shortName << "</title>" << endl; - m_t << " <mediaobject>" << endl; - m_t << " <imageobject>" << endl; - writePlantUMLFile(baseName); - m_t << " </imageobject>" << endl; - m_t << " </mediaobject>" << endl; - m_t << " </figure>" << endl; + m_t << "<para>" << endl; + writePlantUMLFile(baseName,s); m_t << "</para>" << endl; } break; @@ -850,8 +892,13 @@ void DocbookDocVisitor::visitPre(DocImage *img) { if (m_hide) return; m_t << endl; - m_t << " <figure>" << endl; - m_t << " <title>"; + QCString baseName=img->name(); + int i; + if ((i=baseName.findRev('/'))!=-1 || (i=baseName.findRev('\\'))!=-1) + { + baseName=baseName.right(baseName.length()-i-1); + } + visitPreStart(m_t, img -> hasCaption(), baseName, img -> width(), img -> height()); } else { @@ -865,39 +912,14 @@ void DocbookDocVisitor::visitPost(DocImage *img) if (img->type()==DocImage::DocBook) { if (m_hide) return; - QCString typevar; - m_t << "</title>" << endl; - m_t << " <mediaobject>" << endl; - m_t << " <imageobject>" << endl; + visitPostEnd(m_t, img -> hasCaption()); + // copy the image to the output dir QCString baseName=img->name(); int i; if ((i=baseName.findRev('/'))!=-1 || (i=baseName.findRev('\\'))!=-1) { baseName=baseName.right(baseName.length()-i-1); } - m_t << " <imagedata"; - if (!img->width().isEmpty()) - { - m_t << " width=\""; - filter(img->width()); - m_t << "\""; - } - else - { - m_t << " width=\"50%\""; - } - if (!img->height().isEmpty()) - { - m_t << " depth=\""; - filter(img->height()); - m_t << "\""; - } - m_t << " align=\"center\" valign=\"middle\" scalefit=\"1\" fileref=\"" << baseName << "\">"; - m_t << "</imagedata>" << endl; - m_t << " </imageobject>" << endl; - m_t << " </mediaobject>" << endl; - m_t << " </figure>" << endl; - // copy the image to the output dir QCString m_file; bool ambig; FileDef *fd=findFileDef(Doxygen::imageNameDict, baseName, ambig); @@ -1203,7 +1225,7 @@ void DocbookDocVisitor::popEnabled() delete v; } -void DocbookDocVisitor::writeMscFile(const QCString &baseName) +void DocbookDocVisitor::writeMscFile(const QCString &baseName, DocVerbatim *s) { QCString shortName = baseName; int i; @@ -1213,13 +1235,12 @@ void DocbookDocVisitor::writeMscFile(const QCString &baseName) } QCString outDir = Config_getString("DOCBOOK_OUTPUT"); writeMscGraphFromFile(baseName+".msc",outDir,shortName,MSC_BITMAP); - m_t << " <imagedata"; - m_t << " width=\"50%\""; - m_t << " align=\"center\" valign=\"middle\" scalefit=\"1\" fileref=\"" << shortName << ".png" << "\">"; - m_t << "</imagedata>" << endl; + visitPreStart(m_t, s->hasCaption(), shortName, s->width(),s->height()); + visitCaption(this, s->m_children); + visitPostEnd(m_t, s->hasCaption()); } -void DocbookDocVisitor::writePlantUMLFile(const QCString &baseName) +void DocbookDocVisitor::writePlantUMLFile(const QCString &baseName, DocVerbatim *s) { QCString shortName = baseName; int i; @@ -1229,10 +1250,9 @@ void DocbookDocVisitor::writePlantUMLFile(const QCString &baseName) } QCString outDir = Config_getString("DOCBOOK_OUTPUT"); generatePlantUMLOutput(baseName,outDir,PUML_BITMAP); - m_t << " <imagedata"; - m_t << " width=\"50%\""; - m_t << " align=\"center\" valign=\"middle\" scalefit=\"1\" fileref=\"" << shortName << ".png" << "\">"; - m_t << "</imagedata>" << endl; + visitPreStart(m_t, s->hasCaption(), shortName, s->width(),s->height()); + visitCaption(this, s->m_children); + visitPostEnd(m_t, s->hasCaption()); } void DocbookDocVisitor::startMscFile(const QCString &fileName, @@ -1255,50 +1275,17 @@ void DocbookDocVisitor::startMscFile(const QCString &fileName, QCString outDir = Config_getString("DOCBOOK_OUTPUT"); writeMscGraphFromFile(fileName,outDir,baseName,MSC_BITMAP); m_t << "<para>" << endl; - m_t << " <figure>" << endl; - m_t << " <title></title>" << endl; - m_t << " <mediaobject>" << endl; - m_t << " <imageobject>" << endl; - m_t << " <imagedata"; - if (!width.isEmpty()) - { - m_t << " width=\""; - m_t << width; - m_t << "\""; - } - else - { - m_t << " width=\"50%\""; - } - if (!height.isEmpty()) - { - m_t << " depth=\""; - m_t << height; - m_t << "\""; - } - m_t << " align=\"center\" valign=\"middle\" scalefit=\"1\" fileref=\"" << baseName << ".png" << "\">"; - m_t << "</imagedata>" << endl; - m_t << " </imageobject>" << endl; - if (hasCaption) - { - m_t << " <caption>" << endl; - } + visitPreStart(m_t, hasCaption, baseName + ".png", width, height); } void DocbookDocVisitor::endMscFile(bool hasCaption) { if (m_hide) return; - m_t << "endl"; - if (hasCaption) - { - m_t << " </caption>" << endl; - } - m_t << " </mediaobject>" << endl; - m_t << " </figure>" << endl; + visitPostEnd(m_t, hasCaption); m_t << "</para>" << endl; } -void DocbookDocVisitor::writeDiaFile(const QCString &baseName) +void DocbookDocVisitor::writeDiaFile(const QCString &baseName, DocVerbatim *s) { QCString shortName = baseName; int i; @@ -1308,9 +1295,9 @@ void DocbookDocVisitor::writeDiaFile(const QCString &baseName) } QCString outDir = Config_getString("DOCBOOK_OUTPUT"); writeDiaGraphFromFile(baseName+".dia",outDir,shortName,DIA_BITMAP); - m_t << " <imagedata"; - m_t << " align=\"center\" fileref=\"" << shortName << ".png" << "\">"; - m_t << "</imagedata>" << endl; + visitPreStart(m_t, s->hasCaption(), shortName, s->width(),s->height()); + visitCaption(this, s->m_children); + visitPostEnd(m_t, s->hasCaption()); } void DocbookDocVisitor::startDiaFile(const QCString &fileName, @@ -1333,46 +1320,17 @@ void DocbookDocVisitor::startDiaFile(const QCString &fileName, QCString outDir = Config_getString("DOCBOOK_OUTPUT"); writeDiaGraphFromFile(fileName,outDir,baseName,DIA_BITMAP); m_t << "<para>" << endl; - m_t << " <figure>" << endl; - m_t << " <title></title>" << endl; - m_t << " <mediaobject>" << endl; - m_t << " <imageobject>" << endl; - m_t << " <imagedata"; - if (!width.isEmpty()) - { - m_t << " width=\""; - m_t << width; - m_t << "\""; - } - else if (!height.isEmpty()) - { - m_t << " depth=\""; - m_t << height; - m_t << "\""; - } - m_t << " align=\"center\" fileref=\"" << baseName << ".png" << "\">"; - m_t << "</imagedata>" << endl; - m_t << " </imageobject>" << endl; - if (hasCaption) - { - m_t << " <caption>" << endl; - } + visitPreStart(m_t, hasCaption, baseName + ".png", width, height); } void DocbookDocVisitor::endDiaFile(bool hasCaption) { if (m_hide) return; - m_t << "endl"; - if (hasCaption) - { - m_t << " </caption>" << endl; - } - m_t << " </mediaobject>" << endl; - m_t << " </figure>" << endl; + visitPostEnd(m_t, hasCaption); m_t << "</para>" << endl; } -void DocbookDocVisitor::writeDotFile(const QCString &baseName) +void DocbookDocVisitor::writeDotFile(const QCString &baseName, DocVerbatim *s) { QCString shortName = baseName; int i; @@ -1383,11 +1341,9 @@ void DocbookDocVisitor::writeDotFile(const QCString &baseName) QCString outDir = Config_getString("DOCBOOK_OUTPUT"); QCString imgExt = Config_getEnum("DOT_IMAGE_FORMAT"); writeDotGraphFromFile(baseName+".dot",outDir,shortName,GOF_BITMAP); - m_t << " <imagedata"; - //If no width is specified use default value for PDF rendering - m_t << " width=\"50%\""; - m_t << " align=\"center\" valign=\"middle\" scalefit=\"1\" fileref=\"" << shortName << "." << imgExt << "\">"; - m_t << "</imagedata>" << endl; + visitPreStart(m_t, s->hasCaption(), baseName + ".dot", s->width(),s->height()); + visitCaption(this, s->m_children); + visitPostEnd(m_t, s->hasCaption()); } void DocbookDocVisitor::startDotFile(const QCString &fileName, @@ -1411,46 +1367,14 @@ void DocbookDocVisitor::startDotFile(const QCString &fileName, QCString imgExt = Config_getEnum("DOT_IMAGE_FORMAT"); writeDotGraphFromFile(fileName,outDir,baseName,GOF_BITMAP); m_t << "<para>" << endl; - m_t << " <figure>" << endl; - m_t << " <title></title>" << endl; - m_t << " <mediaobject>" << endl; - m_t << " <imageobject>" << endl; - m_t << " <imagedata"; - if (!width.isEmpty()) - { - m_t << " width=\""; - m_t << width; - m_t << "\""; - } - else - { - m_t << " width=\"50%\""; - } - if (!height.isEmpty()) - { - m_t << " depth=\""; - m_t << height; - m_t << "\""; - } - m_t << " align=\"center\" valign=\"middle\" scalefit=\"1\" fileref=\"" << baseName << "." << imgExt << "\">"; - m_t << "</imagedata>" << endl; - m_t << " </imageobject>" << endl; - if (hasCaption) - { - m_t << " <caption>" << endl; - } + visitPreStart(m_t, hasCaption, baseName + "." + imgExt, width, height); } void DocbookDocVisitor::endDotFile(bool hasCaption) { if (m_hide) return; - m_t << "endl"; - if (hasCaption) - { - m_t << " </caption>" << endl; - } - m_t << " </mediaobject>" << endl; - m_t << " </figure>" << endl; + m_t << endl; + visitPostEnd(m_t, hasCaption); m_t << "</para>" << endl; } |