/****************************************************************************** * * * * * Copyright (C) 1997-2015 by Dimitri van Heesch. * * Permission to use, copy, modify, and distribute this software and its * documentation under the terms of the GNU General Public License is hereby * granted. No representations are made about the suitability of this software * for any purpose. It is provided "as is" without express or implied warranty. * See the GNU General Public License for more details. * * Documents produced by Doxygen are derivative works derived from the * input used in their production; they are not affected by this license. * */ #ifndef PRINTDOCVISITOR_H #define PRINTDOCVISITOR_H #include "htmlentity.h" #include "emoji.h" #include "message.h" /*! Visitor implementation for pretty printing */ class PrintDocVisitor { public: PrintDocVisitor() : m_indent(0), m_needsEnter(FALSE), m_insidePre(FALSE) {} //-------------------------------------- void operator()(const DocWord &w) { indent_leaf(); printf("%s",qPrint(w.word())); } void operator()(const DocLinkedWord &w) { indent_leaf(); printf("%s",qPrint(w.word())); } void operator()(const DocWhiteSpace &w) { indent_leaf(); if (m_insidePre) { printf("%s",qPrint(w.chars())); } else { printf(" "); } } void operator()(const DocSymbol &s) { indent_leaf(); const char *res = HtmlEntityMapper::instance()->utf8(s.symbol(),TRUE); if (res) { printf("%s",res); } else { printf("print: non supported HTML-entity found: %s\n",HtmlEntityMapper::instance()->html(s.symbol(),TRUE)); } } void operator()(const DocEmoji &s) { indent_leaf(); const char *res = EmojiEntityMapper::instance()->name(s.index()); if (res) { printf("%s",res); } else { printf("print: non supported emoji found: %s\n",qPrint(s.name())); } } void operator()(const DocURL &u) { indent_leaf(); printf("%s",qPrint(u.url())); } void operator()(const DocLineBreak &) { indent_leaf(); printf("
"); } void operator()(const DocHorRuler &) { indent_leaf(); printf("
"); } void operator()(const DocStyleChange &s) { indent_leaf(); switch (s.style()) { case DocStyleChange::Bold: if (s.enable()) printf(""); else printf(""); break; case DocStyleChange::S: if (s.enable()) printf(""); else printf(""); break; case DocStyleChange::Strike: if (s.enable()) printf(""); else printf(""); break; case DocStyleChange::Del: if (s.enable()) printf(""); else printf(""); break; case DocStyleChange::Underline: if (s.enable()) printf(""); else printf(""); break; case DocStyleChange::Ins: if (s.enable()) printf(""); else printf(""); break; case DocStyleChange::Italic: if (s.enable()) printf(""); else printf(""); break; case DocStyleChange::Code: if (s.enable()) printf(""); else printf(""); break; case DocStyleChange::Subscript: if (s.enable()) printf(""); else printf(""); break; case DocStyleChange::Superscript: if (s.enable()) printf(""); else printf(""); break; case DocStyleChange::Center: if (s.enable()) printf("
"); else printf("
"); break; case DocStyleChange::Small: if (s.enable()) printf(""); else printf(""); break; case DocStyleChange::Cite: if (s.enable()) printf(""); else printf(""); break; case DocStyleChange::Preformatted: if (s.enable()) printf("
"); else printf("
"); break; case DocStyleChange::Div: if (s.enable()) printf("
"); else printf("
"); break; case DocStyleChange::Span: if (s.enable()) printf(""); else printf(""); break; case DocStyleChange::Summary: if (s.enable()) { indent_pre(); printf("\n"); } else { indent_post(); printf("\n"); } break; } } void operator()(const DocVerbatim &s) { indent_leaf(); switch(s.type()) { case DocVerbatim::Code: printf(""); break; case DocVerbatim::Verbatim: printf(""); break; case DocVerbatim::JavaDocLiteral: printf(""); break; case DocVerbatim::JavaDocCode: printf(""); break; case DocVerbatim::HtmlOnly: printf(""); break; case DocVerbatim::RtfOnly: printf(""); break; case DocVerbatim::ManOnly: printf(""); break; case DocVerbatim::LatexOnly: printf(""); break; case DocVerbatim::XmlOnly: printf(""); break; case DocVerbatim::DocbookOnly: printf(""); break; case DocVerbatim::Dot: printf(""); break; case DocVerbatim::Msc: printf(""); break; case DocVerbatim::PlantUML: printf(""); break; } printf("%s",qPrint(s.text())); switch(s.type()) { case DocVerbatim::Code: printf(""); break; case DocVerbatim::Verbatim: printf(""); break; case DocVerbatim::JavaDocLiteral: printf(""); break; case DocVerbatim::JavaDocCode: printf(""); break; case DocVerbatim::HtmlOnly: printf(""); break; case DocVerbatim::RtfOnly: printf(""); break; case DocVerbatim::ManOnly: printf(""); break; case DocVerbatim::LatexOnly: printf(""); break; case DocVerbatim::XmlOnly: printf(""); break; case DocVerbatim::DocbookOnly: printf(""); break; case DocVerbatim::Dot: printf(""); break; case DocVerbatim::Msc: printf(""); break; case DocVerbatim::PlantUML: printf(""); break; } } void operator()(const DocAnchor &a) { indent_leaf(); printf("",qPrint(a.anchor())); } void operator()(const DocInclude &inc) { indent_leaf(); printf(""); } void operator()(const DocIncOperator &op) { indent_leaf(); printf(""); } void operator()(const DocFormula &f) { indent_leaf(); printf("",qPrint(f.name()),qPrint(f.text())); } void operator()(const DocIndexEntry &i) { indent_leaf(); printf("%s"); } void operator()(const DocCite &cite) { indent_leaf(); printf("\n", qPrint(cite.ref()),qPrint(cite.file()),qPrint(cite.anchor()), qPrint(cite.text())); } void operator()(const DocSeparator &) { indent_leaf(); printf(""); } //-------------------------------------- template void visitChildren(const T &t) { for (const auto &child : t.children()) { std::visit(*this, child); } } void operator()(const DocAutoList &l) { indent_pre(); if (l.isEnumList()) { printf("
    \n"); } else { printf("
      \n"); } visitChildren(l); indent_post(); if (l.isEnumList()) { printf("
\n"); } else { printf("\n"); } } void operator()(const DocAutoListItem &li) { indent_pre(); printf("
  • \n"); visitChildren(li); indent_post(); printf("
  • \n"); } void operator()(const DocPara &p) { indent_pre(); printf("\n"); visitChildren(p); indent_post(); printf("\n"); } void operator()(const DocRoot &r) { indent_pre(); printf("\n"); visitChildren(r); indent_post(); printf("\n"); } void operator()(const DocSimpleSect &s) { indent_pre(); printf("\n"); if (s.title()) { std::visit(*this, *s.title()); } visitChildren(s); indent_post(); printf("\n"); } void operator()(const DocTitle &t) { indent_pre(); printf("\n"); visitChildren(t); indent_post(); printf("\n"); } void operator()(const DocSimpleList &l) { indent_pre(); printf("
      \n"); visitChildren(l); indent_post(); printf("
    \n"); } void operator()(const DocSimpleListItem &li) { indent_pre(); printf("
  • \n"); if (li.paragraph()) { visit(*this,*li.paragraph()); } indent_post(); printf("
  • \n"); } void operator()(const DocSection &s) { indent_pre(); printf("\n",s.level()); visitChildren(s); indent_post(); printf("\n",s.level()); } void operator()(const DocHtmlList &s) { indent_pre(); if (s.type()==DocHtmlList::Ordered) { printf("\n"); } else { printf("
      \n"); } visitChildren(s); indent_post(); if (s.type()==DocHtmlList::Ordered) { printf("\n"); } else { printf("
    \n"); } } void operator()(const DocHtmlListItem &li) { indent_pre(); printf("\n"); visitChildren(li); indent_post(); printf("\n"); } void operator()(const DocHtmlDescList &l) { indent_pre(); printf("
    \n"); visitChildren(l); indent_post(); printf("
    \n"); } void operator()(const DocHtmlDescTitle &dt) { indent_pre(); printf("
    \n"); visitChildren(dt); indent_post(); printf("
    \n"); } void operator()(const DocHtmlDescData &dd) { indent_pre(); printf("
    \n"); visitChildren(dd); indent_post(); printf("
    \n"); } void operator()(const DocHtmlTable &t) { indent_pre(); printf("\n", t.numRows(),t.numColumns()); visitChildren(t); if (t.caption()) { std::visit(*this, *t.caption()); } indent_post(); printf("
    \n"); } void operator()(const DocHtmlRow &tr) { indent_pre(); printf("\n"); visitChildren(tr); indent_post(); printf("\n"); } void operator()(const DocHtmlCell &c) { indent_pre(); printf("\n",c.isHeading()?'h':'d'); visitChildren(c); indent_post(); printf("\n",c.isHeading()?'h':'d'); } void operator()(const DocHtmlCaption &c) { indent_pre(); printf("\n"); visitChildren(c); indent_post(); printf("\n"); } void operator()(const DocInternal &i) { indent_pre(); printf("\n"); visitChildren(i); indent_post(); printf("\n"); } void operator()(const DocHRef &href) { indent_pre(); printf("\n",qPrint(href.url())); visitChildren(href); indent_post(); printf("\n"); } void operator()(const DocHtmlDetails &details) { indent_pre(); printf("\n"); visitChildren(details); indent_post(); printf("\n"); } void operator()(const DocHtmlHeader &header) { indent_pre(); printf("\n",header.level()); visitChildren(header); indent_post(); printf("\n",header.level()); } void operator()(const DocImage &img) { indent_pre(); printf("\n",qPrint(img.width()),qPrint(img.height()),img.isInlineImage() ? "yes" : "no"); visitChildren(img); indent_post(); printf("\n"); } void operator()(const DocDotFile &df) { indent_pre(); printf("\n",qPrint(df.name())); visitChildren(df); indent_post(); printf("\n"); } void operator()(const DocMscFile &df) { indent_pre(); printf("\n",qPrint(df.name())); visitChildren(df); indent_post(); printf("\n"); } void operator()(const DocDiaFile &df) { indent_pre(); printf("\n",qPrint(df.name())); visitChildren(df); indent_post(); printf("\n"); } void operator()(const DocLink &lnk) { indent_pre(); printf("\n", qPrint(lnk.ref()),qPrint(lnk.file()),qPrint(lnk.anchor())); visitChildren(lnk); indent_post(); printf("\n"); } void operator()(const DocRef &ref) { indent_pre(); printf("\n", qPrint(ref.ref()),qPrint(ref.file()),qPrint(ref.anchor()), qPrint(ref.targetTitle()),ref.hasLinkText()?"yes":"no", ref.refToAnchor()?"yes":"no", ref.refToSection()?"yes":"no", ref.refToTable()?"yes":"no"); visitChildren(ref); indent_post(); printf("\n"); } void operator()(const DocSecRefItem &ref) { indent_pre(); printf("\n",qPrint(ref.target())); visitChildren(ref); indent_post(); printf("\n"); } void operator()(const DocSecRefList &rl) { indent_pre(); printf("\n"); visitChildren(rl); indent_post(); printf("\n"); } void operator()(const DocParamList &pl) { indent_pre(); printf(""); if (!pl.parameters().empty()) { printf(""); for (const auto ¶m : pl.parameters()) { std::visit(*this,param); } printf(""); } printf("\n"); indent_post(); printf("\n"); } void operator()(const DocParamSect &ps) { indent_pre(); printf("\n"); visitChildren(ps); indent_post(); printf("\n"); } void operator()(const DocXRefItem &x) { indent_pre(); printf("\n", qPrint(x.file()),qPrint(x.anchor()),qPrint(x.title())); visitChildren(x); indent_post(); printf("\n"); } void operator()(const DocInternalRef &r) { indent_pre(); printf("\n",qPrint(r.file()),qPrint(r.anchor())); visitChildren(r); indent_post(); printf("\n"); } void operator()(const DocText &t) { indent_pre(); printf("\n"); visitChildren(t); indent_post(); printf("\n"); } void operator()(const DocHtmlBlockQuote &q) { indent_pre(); printf("
    \n"); visitChildren(q); indent_post(); printf("
    \n"); } void operator()(const DocVhdlFlow &vf) { indent_pre(); printf("\n"); visitChildren(vf); indent_post(); printf("\n"); } void operator()(const DocParBlock &pb) { indent_pre(); printf("\n"); visitChildren(pb); indent_post(); printf("\n"); } private: // helper functions void indent() { if (m_needsEnter) printf("\n"); for (int i=0;i