From ee1ea269e1c684cf5ff39ed836fd8af288837275 Mon Sep 17 00:00:00 2001 From: albert-github Date: Thu, 26 Apr 2018 15:56:25 +0200 Subject: Bug 768240 - Make maxLineLen of latex output configurable Removing the automatic line breaking after 108 characters (also didn't work properly with e.g. executive paper size). Due to new implementation some character encodings had to be changed as well as well as handling of the single quote in formulas. --- src/latexdocvisitor.cpp | 16 +++++++- src/latexgen.cpp | 96 ++++++++++++++++++++++++++++++++------------- templates/latex/doxygen.sty | 62 +++++++++++++++++++++++------ 3 files changed, 133 insertions(+), 41 deletions(-) diff --git a/src/latexdocvisitor.cpp b/src/latexdocvisitor.cpp index 5a67c15..86ceade 100644 --- a/src/latexdocvisitor.cpp +++ b/src/latexdocvisitor.cpp @@ -526,7 +526,19 @@ void LatexDocVisitor::visit(DocIncOperator *op) void LatexDocVisitor::visit(DocFormula *f) { if (m_hide) return; - m_t << f->text(); + const char *p=f->text(); + char c; + if (p) + { + while ((c=*p++)) + { + switch (c) + { + case '\'': m_t << "\\text{'}"; break; + default: m_t << c; break; + } + } + } } void LatexDocVisitor::visit(DocIndexEntry *i) @@ -927,7 +939,7 @@ static void writeStartTableCommand(FTextStream &t,const DocNode *n,int cols) } else { - t << "\\tabulinesep=1mm\n\\begin{longtabu} spread 0pt [c]{*{" << cols << "}{|X[-1]}|}\n"; + t << "\\tabulinesep=1mm\n\\begin{longtabu}spread 0pt [c]{*{" << cols << "}{|X[-1]}|}\n"; } //return isNested ? "TabularNC" : "TabularC"; } diff --git a/src/latexgen.cpp b/src/latexgen.cpp index 9b07fe6..7d72974 100644 --- a/src/latexgen.cpp +++ b/src/latexgen.cpp @@ -38,6 +38,7 @@ #include "filename.h" #include "resourcemgr.h" +static bool DoxyCodeOpen = FALSE; //------------------------------- LatexCodeGenerator::LatexCodeGenerator(FTextStream &t,const QCString &relPath,const QCString &sourceFileName) @@ -77,8 +78,8 @@ void LatexCodeGenerator::codify(const char *str) //char cs[5]; int spacesToNextTabStop; static int tabSize = Config_getInt(TAB_SIZE); - const int maxLineLen = 108; - QCString result(4*maxLineLen+1); // worst case for 1 line of 4-byte chars + static char *result = NULL; + static int lresult = 0; int i; while ((c=*p)) { @@ -86,9 +87,17 @@ void LatexCodeGenerator::codify(const char *str) { case 0x0c: p++; // remove ^L break; + case ' ': m_t <<" "; + m_col++; + p++; + break; + case '^': m_t <<"\\string^"; + m_col++; + p++; + break; case '\t': spacesToNextTabStop = tabSize - (m_col%tabSize); - m_t << Doxygen::spaces.left(spacesToNextTabStop); + for (i = 0; i < spacesToNextTabStop; i++) m_t <<" "; m_col+=spacesToNextTabStop; p++; break; @@ -100,6 +109,11 @@ void LatexCodeGenerator::codify(const char *str) #undef COPYCHAR // helper macro to copy a single utf8 character, dealing with multibyte chars. #define COPYCHAR() do { \ + if (lresult < (i + 5)) \ + { \ + lresult += 512; \ + result = (char *)realloc(result, lresult); \ + } \ result[i++]=c; p++; \ if (c<0) /* multibyte utf-8 character */ \ { \ @@ -116,30 +130,16 @@ void LatexCodeGenerator::codify(const char *str) result[i++]=*p++; \ } \ } \ - m_col++; \ + m_col++; \ } while(0) - // gather characters until we find whitespace or are at - // the end of a line + // gather characters until we find whitespace or another special character COPYCHAR(); - if (m_col>=maxLineLen) // force line break - { - m_t << "\n "; - m_col=0; - } - else // copy more characters + while ((c=*p) && + c!=0x0c && c!='\t' && c!='\n' && c!=' ' && c!='^' + ) { - while (m_col=maxLineLen) // force line break - { - m_t << "\n "; - m_col=0; - } + COPYCHAR(); } result[i]=0; // add terminator //if (m_prettyCode) @@ -190,6 +190,11 @@ void LatexCodeGenerator::writeLineNumber(const char *ref,const char *fileName,co { static bool usePDFLatex = Config_getBool(USE_PDFLATEX); static bool pdfHyperlinks = Config_getBool(PDF_HYPERLINKS); + if (!DoxyCodeOpen) + { + m_t << "\\DoxyCodeLine{"; + DoxyCodeOpen = TRUE; + } if (m_prettyCode) { QCString lineNumber; @@ -223,10 +228,20 @@ void LatexCodeGenerator::writeLineNumber(const char *ref,const char *fileName,co void LatexCodeGenerator::startCodeLine(bool) { m_col=0; + if (!DoxyCodeOpen) + { + m_t << "\\DoxyCodeLine{"; + DoxyCodeOpen = TRUE; + } } void LatexCodeGenerator::endCodeLine() { + if (DoxyCodeOpen) + { + m_t << "}"; + DoxyCodeOpen = FALSE; + } codify("\n"); } @@ -472,8 +487,7 @@ static void writeDefaultHeaderPart1(FTextStream &t) t << "% Packages required by doxygen\n" "\\usepackage{fixltx2e}\n" // for \textsubscript "\\usepackage{calc}\n" - "\\usepackage{doxygen}\n" - "\\usepackage[export]{adjustbox} % also loads graphicx\n"; + "\\usepackage{doxygen}\n"; QStrList extraLatexStyle = Config_getList(LATEX_EXTRA_STYLESHEET); for (uint i=0; i