Public Member Functions | Private Member Functions | Private Attributes | List of all members
LatexCodeGenerator Class Reference

#include <latexgen.h>

Inheritance diagram for LatexCodeGenerator:
CodeOutputInterface

Public Member Functions

 LatexCodeGenerator (FTextStream &t, const QCString &relPath, const QCString &sourceFile)
 
 LatexCodeGenerator ()
 
void setTextStream (FTextStream &t)
 
void setRelativePath (const QCString &path)
 
void setSourceFileName (const QCString &sourceFileName)
 
void codify (const char *text)
 
void writeCodeLink (const char *ref, const char *file, const char *anchor, const char *name, const char *tooltip)
 
void writeTooltip (const char *, const DocLinkInfo &, const char *, const char *, const SourceLinkInfo &, const SourceLinkInfo &)
 
void writeLineNumber (const char *, const char *, const char *, int)
 
void startCodeLine (bool)
 
void endCodeLine ()
 
void startFontClass (const char *)
 
void endFontClass ()
 
void writeCodeAnchor (const char *)
 
void setCurrentDoc (Definition *, const char *, bool)
 
void addWord (const char *, bool)
 
- Public Member Functions inherited from CodeOutputInterface
virtual ~CodeOutputInterface ()
 

Private Member Functions

void _writeCodeLink (const char *className, const char *ref, const char *file, const char *anchor, const char *name, const char *tooltip)
 
void docify (const char *str)
 

Private Attributes

bool m_streamSet
 
FTextStream m_t
 
QCString m_relPath
 
QCString m_sourceFileName
 
int m_col
 
bool m_prettyCode
 

Detailed Description

Definition at line 27 of file latexgen.h.

Constructor & Destructor Documentation

LatexCodeGenerator::LatexCodeGenerator ( FTextStream t,
const QCString relPath,
const QCString sourceFile 
)

Definition at line 43 of file latexgen.cpp.

44  : m_relPath(relPath), m_sourceFileName(sourceFileName), m_col(0)
45 {
46  m_prettyCode=Config_getBool("LATEX_SOURCE_CODE");
47  setTextStream(t);
48 }
void setTextStream(FTextStream &t)
Definition: latexgen.cpp:55
QCString m_sourceFileName
Definition: latexgen.h:64
QCString m_relPath
Definition: latexgen.h:63
#define Config_getBool(val)
Definition: config.cpp:664
LatexCodeGenerator::LatexCodeGenerator ( )

Definition at line 50 of file latexgen.cpp.

50  : m_col(0), m_streamSet(FALSE)
51 {
52  m_prettyCode=Config_getBool("LATEX_SOURCE_CODE");
53 }
const bool FALSE
Definition: qglobal.h:370
#define Config_getBool(val)
Definition: config.cpp:664

Member Function Documentation

void LatexCodeGenerator::_writeCodeLink ( const char *  className,
const char *  ref,
const char *  file,
const char *  anchor,
const char *  name,
const char *  tooltip 
)
private
void LatexCodeGenerator::addWord ( const char *  ,
bool   
)
inlinevirtual

Implements CodeOutputInterface.

Definition at line 53 of file latexgen.h.

53 {}
void LatexCodeGenerator::codify ( const char *  s)
virtual

Writes an code fragment to the output. This function should keep spaces visible, should break lines at a newline and should convert tabs to the right number of spaces.

Implements CodeOutputInterface.

Definition at line 71 of file latexgen.cpp.

72 {
73  if (str)
74  {
75  const char *p=str;
76  char c;
77  //char cs[5];
78  int spacesToNextTabStop;
79  static int tabSize = Config_getInt("TAB_SIZE");
80  const int maxLineLen = 108;
81  QCString result(4*maxLineLen+1); // worst case for 1 line of 4-byte chars
82  int i;
83  while ((c=*p))
84  {
85  switch(c)
86  {
87  case 0x0c: p++; // remove ^L
88  break;
89  case '\t': spacesToNextTabStop =
90  tabSize - (m_col%tabSize);
91  m_t << Doxygen::spaces.left(spacesToNextTabStop);
92  m_col+=spacesToNextTabStop;
93  p++;
94  break;
95  case '\n': m_t << '\n'; m_col=0; p++;
96  break;
97  default:
98  i=0;
99 
100 #undef COPYCHAR
101 // helper macro to copy a single utf8 character, dealing with multibyte chars.
102 #define COPYCHAR() do { \
103  result[i++]=c; p++; \
104  if (c<0) /* multibyte utf-8 character */ \
105  { \
106  /* 1xxx.xxxx: >=2 byte character */ \
107  result[i++]=*p++; \
108  if (((uchar)c&0xE0)==0xE0) \
109  { \
110  /* 111x.xxxx: >=3 byte character */ \
111  result[i++]=*p++; \
112  } \
113  if (((uchar)c&0xF0)==0xF0) \
114  { \
115  /* 1111.xxxx: 4 byte character */ \
116  result[i++]=*p++; \
117  } \
118  } \
119  m_col++; \
120  } while(0)
121 
122  // gather characters until we find whitespace or are at
123  // the end of a line
124  COPYCHAR();
125  if (m_col>=maxLineLen) // force line break
126  {
127  m_t << "\n ";
128  m_col=0;
129  }
130  else // copy more characters
131  {
132  while (m_col<maxLineLen && (c=*p) &&
133  c!=0x0c && c!='\t' && c!='\n' && c!=' '
134  )
135  {
136  COPYCHAR();
137  }
138  if (m_col>=maxLineLen) // force line break
139  {
140  m_t << "\n ";
141  m_col=0;
142  }
143  }
144  result[i]=0; // add terminator
145  //if (m_prettyCode)
146  //{
148  //}
149  //else
150  //{
151  // t << result;
152  //}
153  break;
154  }
155  }
156  }
157 }
static QCString result
const bool FALSE
Definition: qglobal.h:370
QCString left(uint len) const
Definition: qcstring.cpp:213
#define Config_getInt(val)
Definition: config.cpp:661
p
Definition: test.py:223
void filterLatexString(FTextStream &t, const char *str, bool insideTabbing, bool insidePre, bool insideItem, bool keepSpaces)
Definition: util.cpp:6533
#define COPYCHAR()
FTextStream m_t
Definition: latexgen.h:62
static QCString spaces
Definition: doxygen.h:151
const bool TRUE
Definition: qglobal.h:371
static QCString str
void LatexCodeGenerator::docify ( const char *  str)
private
void LatexCodeGenerator::endCodeLine ( )
virtual

Ends a line of code started with startCodeLine()

Implements CodeOutputInterface.

Definition at line 228 of file latexgen.cpp.

229 {
230  codify("\n");
231 }
void codify(const char *text)
Definition: latexgen.cpp:71
void LatexCodeGenerator::endFontClass ( )
virtual

Ends a block started with startFontClass()

Implements CodeOutputInterface.

Definition at line 238 of file latexgen.cpp.

239 {
240  m_t << "}";
241 }
FTextStream m_t
Definition: latexgen.h:62
void LatexCodeGenerator::setCurrentDoc ( Definition ,
const char *  ,
bool   
)
inlinevirtual

Implements CodeOutputInterface.

Definition at line 52 of file latexgen.h.

52 {}
void LatexCodeGenerator::setRelativePath ( const QCString path)

Definition at line 61 of file latexgen.cpp.

62 {
63  m_relPath = path;
64 }
QCString m_relPath
Definition: latexgen.h:63
void LatexCodeGenerator::setSourceFileName ( const QCString sourceFileName)

Definition at line 66 of file latexgen.cpp.

67 {
69 }
static QCString name
Definition: declinfo.cpp:673
QCString m_sourceFileName
Definition: latexgen.h:64
void LatexCodeGenerator::setTextStream ( FTextStream t)

Definition at line 55 of file latexgen.cpp.

56 {
57  m_streamSet = t.device()!=0;
58  m_t.setDevice(t.device());
59 }
void setDevice(QIODevice *)
QIODevice * device() const
FTextStream m_t
Definition: latexgen.h:62
void LatexCodeGenerator::startCodeLine ( bool  )
virtual

Implements CodeOutputInterface.

Definition at line 223 of file latexgen.cpp.

224 {
225  m_col=0;
226 }
void LatexCodeGenerator::startFontClass ( const char *  clsName)
virtual

Starts a block with a certain meaning. Used for syntax highlighting, which elements of the same type are rendered using the same 'font class'.

Parameters
clsNameThe category name.

Implements CodeOutputInterface.

Definition at line 233 of file latexgen.cpp.

234 {
235  m_t << "\\textcolor{" << name << "}{";
236 }
static QCString name
Definition: declinfo.cpp:673
FTextStream m_t
Definition: latexgen.h:62
void LatexCodeGenerator::writeCodeAnchor ( const char *  name)
inlinevirtual

Write an anchor to a source listing.

Parameters
nameThe name of the anchor.

Implements CodeOutputInterface.

Definition at line 51 of file latexgen.h.

51 {}
void LatexCodeGenerator::writeCodeLink ( const char *  ref,
const char *  file,
const char *  anchor,
const char *  name,
const char *  tooltip 
)
virtual

Writes a link to an object in a code fragment.

Parameters
refIf this is non-zero, the object is to be found in an external documentation file.
fileThe file in which the object is located.
anchorThe anchor uniquely identifying the object within the file.
nameThe text to display as a placeholder for the link.
tooltipThe tooltip to display when the mouse is on the link.

Implements CodeOutputInterface.

Definition at line 160 of file latexgen.cpp.

163 {
164  static bool pdfHyperlinks = Config_getBool("PDF_HYPERLINKS");
165  static bool usePDFLatex = Config_getBool("USE_PDFLATEX");
166  int l = qstrlen(name);
167  if (m_col+l>80)
168  {
169  m_t << "\n ";
170  m_col=0;
171  }
172  if (!ref && usePDFLatex && pdfHyperlinks)
173  {
174  m_t << "\\hyperlink{";
175  if (f) m_t << stripPath(f);
176  if (f && anchor) m_t << "_";
177  if (anchor) m_t << anchor;
178  m_t << "}{";
179  codify(name);
180  m_t << "}";
181  }
182  else
183  {
184  m_t << name;
185  }
186  m_col+=l;
187 }
static QCString name
Definition: declinfo.cpp:673
static QCString stripPath(const QCString &s)
Definition: tagreader.cpp:1287
static QStrList * l
Definition: config.cpp:1044
Q_EXPORT uint qstrlen(const char *str)
Definition: qcstring.h:81
void codify(const char *text)
Definition: latexgen.cpp:71
#define Config_getBool(val)
Definition: config.cpp:664
FTextStream m_t
Definition: latexgen.h:62
void LatexCodeGenerator::writeLineNumber ( const char *  ref,
const char *  file,
const char *  anchor,
int  lineNumber 
)
virtual

Writes the line number of a source listing

Parameters
refExternal reference (when imported from a tag file)
fileThe file part of the URL pointing to the docs.
anchorThe anchor part of the URL pointing to the docs.
lineNumberThe line number to write

Implements CodeOutputInterface.

Definition at line 189 of file latexgen.cpp.

190 {
191  static bool usePDFLatex = Config_getBool("USE_PDFLATEX");
192  static bool pdfHyperlinks = Config_getBool("PDF_HYPERLINKS");
193  if (m_prettyCode)
194  {
195  QCString lineNumber;
196  lineNumber.sprintf("%05d",l);
197 
199  {
200  QCString lineAnchor;
201  lineAnchor.sprintf("_l%05d",l);
202  lineAnchor.prepend(m_sourceFileName);
203  //if (!m_prettyCode) return;
204  if (usePDFLatex && pdfHyperlinks)
205  {
206  m_t << "\\hypertarget{" << stripPath(lineAnchor) << "}{}";
207  }
208  writeCodeLink(ref,fileName,anchor,lineNumber,0);
209  }
210  else
211  {
212  codify(lineNumber);
213  }
214  m_t << " ";
215  }
216  else
217  {
218  m_t << l << " ";
219  }
220 }
bool isEmpty() const
Definition: qcstring.h:189
void writeCodeLink(const char *ref, const char *file, const char *anchor, const char *name, const char *tooltip)
Definition: latexgen.cpp:160
static QCString stripPath(const QCString &s)
Definition: tagreader.cpp:1287
QCString m_sourceFileName
Definition: latexgen.h:64
static QStrList * l
Definition: config.cpp:1044
fileName
Definition: dumpTree.py:9
void codify(const char *text)
Definition: latexgen.cpp:71
QCString & prepend(const char *s)
Definition: qcstring.cpp:387
#define Config_getBool(val)
Definition: config.cpp:664
QCString & sprintf(const char *format,...)
Definition: qcstring.cpp:27
FTextStream m_t
Definition: latexgen.h:62
void LatexCodeGenerator::writeTooltip ( const char *  id,
const DocLinkInfo docInfo,
const char *  decl,
const char *  desc,
const SourceLinkInfo defInfo,
const SourceLinkInfo declInfo 
)
inlinevirtual

Writes a tool tip definition

Parameters
idunique identifier for the tooltip
docInfoInfo about the symbol's documentation.
declfull declaration of the symbol (for functions)
descbrief description for the symbol
defInfoInfo about the symbol's definition in the source code
declInfoInfo about the symbol's declaration in the source code

Implements CodeOutputInterface.

Definition at line 39 of file latexgen.h.

45  {}

Member Data Documentation

int LatexCodeGenerator::m_col
private

Definition at line 65 of file latexgen.h.

bool LatexCodeGenerator::m_prettyCode
private

Definition at line 66 of file latexgen.h.

QCString LatexCodeGenerator::m_relPath
private

Definition at line 63 of file latexgen.h.

QCString LatexCodeGenerator::m_sourceFileName
private

Definition at line 64 of file latexgen.h.

bool LatexCodeGenerator::m_streamSet
private

Definition at line 61 of file latexgen.h.

FTextStream LatexCodeGenerator::m_t
private

Definition at line 62 of file latexgen.h.


The documentation for this class was generated from the following files: