"Fossies" - the Fresh Open Source Software Archive

Member "ansifilter-2.18/src/texgenerator.cpp" (30 Jan 2021, 5563 Bytes) of package /linux/privat/ansifilter-2.18.tar.bz2:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "texgenerator.cpp" see the Fossies "Dox" file reference documentation and the last Fossies "Diffs" side-by-side code changes report: 2.13_vs_2.14.

    1 /***************************************************************************
    2                      texgenerator.cpp  -  description
    3                              -------------------
    4 
    5     copyright            : (C) 2008-2015 by Andre Simon
    6     email                : a.simon@mailbox.org
    7  ***************************************************************************/
    8 
    9 /*
   10 This file is part of ANSIFilter.
   11 
   12 ANSIFilter is free software: you can redistribute it and/or modify
   13 it under the terms of the GNU General Public License as published by
   14 the Free Software Foundation, either version 3 of the License, or
   15 (at your option) any later version.
   16 
   17 ANSIFilter is distributed in the hope that it will be useful,
   18 but WITHOUT ANY WARRANTY; without even the implied warranty of
   19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
   20 GNU General Public License for more details.
   21 
   22 You should have received a copy of the GNU General Public License
   23 along with ANSIFilter.  If not, see <http://www.gnu.org/licenses/>.
   24 */
   25 
   26 #include <fstream>
   27 #include <iostream>
   28 #include <sstream>
   29 
   30 #include "texgenerator.h"
   31 #include "charcodes.h"
   32 #include "version.h"
   33 
   34 namespace ansifilter
   35 {
   36 
   37 TeXGenerator::TeXGenerator ():
   38     CodeGenerator(TEX),
   39     fileSuffix(".tex")
   40 {
   41     /*This makes TeX to use every par it encounters (the \\leavevmode has
   42     no effect when TeX is in horizontal mode and when TeX is in vertical
   43     mode, it switches it to horizontal mode).*/
   44     newLineTag="\\leavevmode\\par\n";
   45     styleCommentOpen="%";
   46     spacer  = "\\ ";
   47 }
   48 
   49 string TeXGenerator::getOpenTag()
   50 {
   51     ostringstream fmtStream;
   52 
   53     if (elementStyle.isBold()) {
   54         fmtStream<< "\\bf";
   55     }
   56     if (elementStyle.isItalic()) {
   57         fmtStream<< "\\it";
   58     }
   59 
   60     fmtStream << "\\textColor{"
   61               << elementStyle.getFgColour().getRed(TEX) << " "
   62               << elementStyle.getFgColour().getGreen(TEX) << " "
   63               << elementStyle.getFgColour().getBlue(TEX)
   64               << " 0}";
   65 
   66     return "{" + fmtStream.str();       
   67 }
   68 
   69 string TeXGenerator::getCloseTag()
   70 {
   71     return "}";
   72 }
   73 
   74 string TeXGenerator::getGeneratorComment()
   75 {
   76     ostringstream s;
   77     s <<"% TeX generated by ansifilter "
   78       << ANSIFILTER_VERSION << ", " <<  ANSIFILTER_URL <<"\n";
   79 
   80     return s.str();
   81 }
   82 
   83 string TeXGenerator::getHeader()
   84 {
   85     ostringstream os;
   86     os << styleCommentOpen <<docTitle << "\n"
   87        << "\\nopagenumbers\n"
   88        << "\\input colordvi\n";
   89     if (!styleSheetPath.empty()) {
   90         os <<  "\\input "<<styleSheetPath<<"\n";
   91     }
   92     os << "{\n"
   93        << "\\tt\n";
   94     return os.str();
   95 }
   96 
   97 string TeXGenerator::getFooter()
   98 {
   99     string footer;
  100     footer = "\n}\n\\bye\n";
  101     
  102     if (!omitVersionInfo)
  103         footer += getGeneratorComment();
  104     
  105     return footer;
  106 }
  107 
  108 void TeXGenerator::printBody()
  109 {
  110     processInput();
  111 }
  112 
  113 string TeXGenerator::maskCharacter(unsigned char c)
  114 {
  115     switch (c) {
  116     case '{':
  117     case '}': {
  118         string m( "$\\" );
  119         m += c;
  120         m += '$';
  121         return m;
  122     }
  123     break;
  124     case '^':
  125         return "{\\bf\\^{}}";
  126         break;
  127     case '_':
  128     case '&':
  129     case '$':
  130     case '#':
  131     case '%': {
  132         string m( "\\" );
  133         m += c;
  134         m += "{}";
  135         return m;
  136     }
  137     break;
  138     case '\\':
  139         return "$\\backslash$";
  140         break;
  141     case ' ':
  142         return spacer;
  143         break;
  144     case '+':
  145     case '-':
  146     case '<':
  147     case '>':
  148     case '=': {
  149         string m( "$\\mathord{" );
  150         m += c;
  151         m += "}$";
  152         return m;
  153     }
  154     break;
  155     case AUML_LC:
  156         return "\\\"a";
  157         break;
  158     case OUML_LC:
  159         return "\\\"o";
  160         break;
  161     case UUML_LC:
  162         return "\\\"u";
  163         break;
  164     case AUML_UC:
  165         return "\\\"A";
  166         break;
  167     case OUML_UC:
  168         return "\\\"O";
  169         break;
  170     case UUML_UC:
  171         return "\\\"U";
  172         break;
  173     case AACUTE_LC:
  174         return "\\'a";
  175         break;
  176     case EACUTE_LC:
  177         return "\\'e";
  178         break;
  179     case OACUTE_LC:
  180         return "\\'o";
  181         break;
  182     case UACUTE_LC:
  183         return "\\'u";
  184         break;
  185     case AGRAVE_LC:
  186         return "\\`a";
  187         break;
  188     case EGRAVE_LC:
  189         return "\\`e";
  190         break;
  191     case OGRAVE_LC:
  192         return "\\`o";
  193         break;
  194     case UGRAVE_LC:
  195         return "\\`u";
  196         break;
  197     case AACUTE_UC:
  198         return "\\'A";
  199         break;
  200     case EACUTE_UC:
  201         return "\\'E";
  202         break;
  203     case OACUTE_UC:
  204         return "\\'O";
  205         break;
  206     case UACUTE_UC:
  207         return "\\'U";
  208         break;
  209     case AGRAVE_UC:
  210         return "\\`A";
  211         break;
  212     case EGRAVE_UC:
  213         return "\\`E";
  214         break;
  215     case UGRAVE_UC:
  216         return "\\`O";
  217         break;
  218     case OGRAVE_UC:
  219         return "\\`U";
  220         break;
  221     case SZLIG:
  222         return "\\ss ";
  223         break;
  224 
  225     case '\t' : // see deletion of nonprintable chars below
  226         return "\t";
  227         break;
  228 
  229     default :
  230         if (c>0x1f ) { // printable?
  231             return string( 1, c );
  232         } else {
  233             return "";
  234         }
  235     }
  236 }
  237 
  238 void TeXGenerator::insertLineNumber ()
  239 {
  240     if ( showLineNumbers ) {
  241 
  242         ostringstream lnum;
  243         lnum << setw ( 5 ) << right;
  244         if( numberCurrentLine ) {
  245             if (lineNumber>1) 
  246               *out << getCloseTag();
  247             lnum << lineNumber;
  248             *out <<"{\\textColor{1 1 1 0} "<<lnum.str()<<spacer<<"}";
  249             *out << getOpenTag();
  250         } else {
  251             *out << lnum.str(); //for indentation
  252         }
  253     }
  254 }
  255 
  256 }