diff options
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 8609347..35cc342 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); @@ -1205,7 +1227,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; @@ -1215,13 +1237,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; @@ -1231,10 +1252,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, @@ -1257,50 +1277,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; @@ -1310,9 +1297,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, @@ -1335,46 +1322,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; @@ -1385,11 +1343,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, @@ -1413,46 +1369,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; } |