doxygen
latexdocvisitor.h
1 /******************************************************************************
2  *
3  * Copyright (C) 1997-2021 by Dimitri van Heesch.
4  *
5  * Permission to use, copy, modify, and distribute this software and its
6  * documentation under the terms of the GNU General Public License is hereby
7  * granted. No representations are made about the suitability of this software
8  * for any purpose. It is provided "as is" without express or implied warranty.
9  * See the GNU General Public License for more details.
10  *
11  * Documents produced by Doxygen are derivative works derived from the
12  * input used in their production; they are not affected by this license.
13  *
14  */
15 
16 #ifndef LATEXDOCVISITOR_H
17 #define LATEXDOCVISITOR_H
18 
19 #include <stack>
20 
21 #include "qcstring.h"
22 #include "docvisitor.h"
23 #include "docnode.h"
24 
25 class OutputCodeList;
26 class LatexCodeGenerator;
27 class TextStream;
28 
29 enum class TexOrPdf
30 {
31  NO,
32  TEX,
33  PDF,
34 };
35 
38 {
39  public:
41  const QCString &langExt, int hierarchyLevel = 0);
42 
43  //--------------------------------------
44  // visitor functions for leaf nodes
45  //--------------------------------------
46 
47  void operator()(const DocWord &);
48  void operator()(const DocLinkedWord &);
49  void operator()(const DocWhiteSpace &);
50  void operator()(const DocSymbol &);
51  void operator()(const DocEmoji &);
52  void operator()(const DocURL &);
53  void operator()(const DocLineBreak &);
54  void operator()(const DocHorRuler &);
55  void operator()(const DocStyleChange &);
56  void operator()(const DocVerbatim &);
57  void operator()(const DocAnchor &);
58  void operator()(const DocInclude &);
59  void operator()(const DocIncOperator &);
60  void operator()(const DocFormula &);
61  void operator()(const DocIndexEntry &);
62  void operator()(const DocSimpleSectSep &);
63  void operator()(const DocCite &);
64  void operator()(const DocSeparator &);
65 
66  //--------------------------------------
67  // visitor functions for compound nodes
68  //--------------------------------------
69 
70  void operator()(const DocAutoList &);
71  void operator()(const DocAutoListItem &);
72  void operator()(const DocPara &);
73  void operator()(const DocRoot &);
74  void operator()(const DocSimpleSect &);
75  void operator()(const DocTitle &);
76  void operator()(const DocSimpleList &);
77  void operator()(const DocSimpleListItem &);
78  void operator()(const DocSection &s);
79  void operator()(const DocHtmlList &s);
80  void operator()(const DocHtmlListItem &);
81  void operator()(const DocHtmlDescList &);
82  void operator()(const DocHtmlDescTitle &);
83  void operator()(const DocHtmlDescData &);
84  void operator()(const DocHtmlTable &t);
85  void operator()(const DocHtmlCaption &);
86  void operator()(const DocHtmlRow &);
87  void operator()(const DocHtmlCell &);
88  void operator()(const DocInternal &);
89  void operator()(const DocHRef &);
90  void operator()(const DocHtmlSummary &);
91  void operator()(const DocHtmlDetails &);
92  void operator()(const DocHtmlHeader &);
93  void operator()(const DocImage &);
94  void operator()(const DocDotFile &);
95  void operator()(const DocMscFile &);
96  void operator()(const DocDiaFile &);
97  void operator()(const DocLink &lnk);
98  void operator()(const DocRef &ref);
99  void operator()(const DocSecRefItem &);
100  void operator()(const DocSecRefList &);
101  void operator()(const DocParamSect &);
102  void operator()(const DocParamList &);
103  void operator()(const DocXRefItem &);
104  void operator()(const DocInternalRef &);
105  void operator()(const DocText &);
106  void operator()(const DocHtmlBlockQuote &);
107  void operator()(const DocVhdlFlow &);
108  void operator()(const DocParBlock &);
109 
110  private:
111  template<class T>
112  void visitChildren(const T &t)
113  {
114  for (const auto &child : t.children())
115  {
116  std::visit(*this, child);
117  }
118  }
119 
120  struct ActiveRowSpan
121  {
122  ActiveRowSpan(const DocHtmlCell &c,size_t rs,size_t cs,size_t col)
123  : cell(c), rowSpan(rs), colSpan(cs), column(col) {}
124  const DocHtmlCell &cell;
125  size_t rowSpan;
126  size_t colSpan;
127  size_t column;
128  };
129 
130  typedef std::vector<ActiveRowSpan> RowSpanList;
131 
132  //--------------------------------------
133  // helper functions
134  //--------------------------------------
135 
136  void filter(const QCString &str, const bool retainNewLine = false);
137  void startLink(const QCString &ref,const QCString &file,
138  const QCString &anchor,bool refToTable=false,bool refToSection=false);
139  void endLink(const QCString &ref,const QCString &file,
140  const QCString &anchor,bool refToTable=false,bool refToSection=false, SectionType sectionType = SectionType::Anchor);
141  QCString escapeMakeIndexChars(const char *s);
142  void startDotFile(const QCString &fileName,const QCString &width,
143  const QCString &height, bool hasCaption,
144  const QCString &srcFile,int srcLine);
145  void endDotFile(bool hasCaption);
146 
147  void startMscFile(const QCString &fileName,const QCString &width,
148  const QCString &height, bool hasCaption,
149  const QCString &srcFile,int srcLine);
150  void endMscFile(bool hasCaption);
151  void writeMscFile(const QCString &fileName, const DocVerbatim &s);
152 
153  void startDiaFile(const QCString &fileName,const QCString &width,
154  const QCString &height, bool hasCaption,
155  const QCString &srcFile,int srcLine);
156  void endDiaFile(bool hasCaption);
157  void writeDiaFile(const QCString &fileName, const DocVerbatim &s);
158  void writePlantUMLFile(const QCString &fileName, const DocVerbatim &s);
159  void visitCaption(const DocNodeList &children);
160 
161  void incIndentLevel();
162  void decIndentLevel();
163  int indentLevel() const;
164  const char *getSectionName(int level) const;
165 
166  //--------------------------------------
167  // state variables
168  //--------------------------------------
169 
170  TextStream &m_t;
171  OutputCodeList &m_ci;
172  LatexCodeGenerator &m_lcg;
173  bool m_insidePre;
174  bool m_insideItem;
175  bool m_hide;
176  QCString m_langExt;
177  int m_hierarchyLevel;
178  TexOrPdf m_texOrPdf = TexOrPdf::NO;
179 
180  struct TableState
181  {
182  RowSpanList rowSpans;
183  size_t numCols = 0;
184  size_t currentColumn = 0;
185  bool inRowSpan = false;
186  bool inColSpan = false;
187  bool firstRow = false;
188  };
189  std::stack<TableState> m_tableStateStack; // needed for nested tables
190  RowSpanList m_emptyRowSpanList;
191 
192  static const int maxIndentLevels = 13;
193  int m_indentLevel = 0;
194 
195  struct LatexListItemInfo
196  {
197  bool isEnum = false;
198  };
199 
200  LatexListItemInfo m_listItemInfo[maxIndentLevels];
201 
202  void pushTableState()
203  {
204  m_tableStateStack.emplace();
205  }
206  void popTableState()
207  {
208  m_tableStateStack.pop();
209  }
210  size_t currentColumn() const
211  {
212  return !m_tableStateStack.empty() ? m_tableStateStack.top().currentColumn : 0;
213  }
214  void setCurrentColumn(size_t col)
215  {
216  if (!m_tableStateStack.empty()) m_tableStateStack.top().currentColumn = col;
217  }
218  size_t numCols() const
219  {
220  return !m_tableStateStack.empty() ? m_tableStateStack.top().numCols : 0;
221  }
222  void setNumCols(size_t num)
223  {
224  if (!m_tableStateStack.empty()) m_tableStateStack.top().numCols = num;
225  }
226  bool inRowSpan() const
227  {
228  return !m_tableStateStack.empty() ? m_tableStateStack.top().inRowSpan : FALSE;
229  }
230  void setInRowSpan(bool b)
231  {
232  if (!m_tableStateStack.empty()) m_tableStateStack.top().inRowSpan = b;
233  }
234  bool inColSpan() const
235  {
236  return !m_tableStateStack.empty() ? m_tableStateStack.top().inColSpan : FALSE;
237  }
238  void setInColSpan(bool b)
239  {
240  if (!m_tableStateStack.empty()) m_tableStateStack.top().inColSpan = b;
241  }
242  bool firstRow() const
243  {
244  return !m_tableStateStack.empty() ? m_tableStateStack.top().firstRow : FALSE;
245  }
246  void setFirstRow(bool b)
247  {
248  if (!m_tableStateStack.empty()) m_tableStateStack.top().firstRow = b;
249  }
250  RowSpanList &rowSpans()
251  {
252  return !m_tableStateStack.empty() ? m_tableStateStack.top().rowSpans : m_emptyRowSpanList;
253  }
254  void addRowSpan(ActiveRowSpan &&span)
255  {
256  if (!m_tableStateStack.empty()) m_tableStateStack.top().rowSpans.push_back(std::move(span));
257  }
258  bool insideTable() const
259  {
260  return !m_tableStateStack.empty();
261  }
262 
263 };
264 #endif
Node representing a separator.
Definition: docnode.h:343
Node representing an HTML blockquote.
Definition: docnode.h:1252
Node representing a URL (or email address)
Definition: docnode.h:185
Node representing a word.
Definition: docnode.h:150
Node representing some amount of white space.
Definition: docnode.h:332
Node representing a Hypertext reference.
Definition: docnode.h:784
Root node of a text fragment.
Definition: docnode.h:1265
Node representing a horizontal ruler.
Definition: docnode.h:213
Node representing a simple section title.
Definition: docnode.h:579
Node representing a reference to some item.
Definition: docnode.h:739
Node representing a style change.
Definition: docnode.h:262
Node representing an auto List.
Definition: docnode.h:542
Node representing an emoji.
Definition: docnode.h:319
Node representing a citation of some bibliographic reference.
Definition: docnode.h:242
Text streaming class that buffers data.
Definition: textstream.h:35
Node representing a HTML table caption.
Definition: docnode.h:1189
Root node of documentation tree.
Definition: docnode.h:1274
Node representing a HTML table cell.
Definition: docnode.h:1154
Node representing an entry in the index.
Definition: docnode.h:523
Node representing a simple section.
Definition: docnode.h:978
Node representing a paragraph in the documentation tree.
Definition: docnode.h:1041
Concrete visitor implementation for LaTeX output.
Definition: latexdocvisitor.h:37
Node representing a special symbol.
Definition: docnode.h:306
Helper base class for functionality shared by all visitors.
Definition: docvisitor.h:28
Node Html details.
Definition: docnode.h:818
Node representing a VHDL flow chart.
Definition: docnode.h:710
Node representing a Html description list.
Definition: docnode.h:862
Node representing a HTML list item.
Definition: docnode.h:1126
Node representing a msc file.
Definition: docnode.h:692
Node representing a verbatim, unparsed text fragment.
Definition: docnode.h:354
Node representing a Html description item.
Definition: docnode.h:849
Node Html heading.
Definition: docnode.h:834
Node representing a HTML table.
Definition: docnode.h:1230
Node representing a dia file.
Definition: docnode.h:701
Node representing a HTML table row.
Definition: docnode.h:1207
Definition: docnode.h:116
Node representing a line break.
Definition: docnode.h:199
Generator for LaTeX code fragments.
Definition: latexgen.h:27
Node representing a list of section references.
Definition: docnode.h:920
Class representing a list of different code generators.
Definition: outputlist.h:199
Node representing a reference to a section.
Definition: docnode.h:896
Node representing an item of a cross-referenced list.
Definition: docnode.h:500
Node representing a parameter section.
Definition: docnode.h:1014
Node representing an image.
Definition: docnode.h:612
Node representing a parameter list.
Definition: docnode.h:1086
Definition: section.h:28
Node representing a normal section.
Definition: docnode.h:875
Node representing a Html list.
Definition: docnode.h:961
Node representing an internal reference to some item.
Definition: docnode.h:768
Node representing an included text block from file.
Definition: docnode.h:413
Node representing an block of paragraphs.
Definition: docnode.h:940
Node representing an anchor.
Definition: docnode.h:226
Node representing a separator between two simple sections of the same type.
Definition: docnode.h:1005
Node representing a simple list item.
Definition: docnode.h:1114
Node representing a HTML description data.
Definition: docnode.h:1142
This is an alternative implementation of QCString.
Definition: qcstring.h:93
Node representing a word that can be linked to something.
Definition: docnode.h:162
Node representing a simple list.
Definition: docnode.h:951
Node representing a dot file.
Definition: docnode.h:683
Node representing an item of a auto list.
Definition: docnode.h:566
Node representing an internal section of documentation.
Definition: docnode.h:930
Node representing an item of a cross-referenced list.
Definition: docnode.h:591
Node representing a include/dontinclude operator block.
Definition: docnode.h:450
Node Html summary.
Definition: docnode.h:805