"Fossies" - the Fresh Open Source Software Archive

Member "ansifilter-2.18/src/pangogenerator.cpp" (30 Jan 2021, 3368 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 "pangogenerator.cpp" see the Fossies "Dox" file reference documentation.

    1 /***************************************************************************
    2                      pangogenerator.cpp  -  description
    3                              -------------------
    4 
    5     copyright            : (C) 2014 by Dominik Schmidt
    6 
    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 "pangogenerator.h"
   31 #include "version.h"
   32 
   33 namespace ansifilter
   34 {
   35 
   36 PangoGenerator::PangoGenerator ():
   37     CodeGenerator(PANGO),
   38     fileSuffix(".pango")
   39 {
   40     newLineTag="\n";
   41     styleCommentOpen="";
   42     styleCommentClose="";
   43     spacer=" ";
   44 }
   45 
   46 string PangoGenerator::getOpenTag()
   47 {
   48     ostringstream fmtStream;
   49 
   50 
   51     if (elementStyle.isBold()) {
   52         fmtStream<< " font-weight=\"bold\"";
   53     }
   54     if (elementStyle.isItalic()) {
   55         fmtStream<< " font-style=\"italic\"";
   56     }
   57     if (elementStyle.isUnderline()) {
   58         fmtStream<< " underline=\"single\"";
   59     }
   60 
   61     if (elementStyle.isFgColorSet()) {
   62         fmtStream << " fgcolor=\"#"
   63            << elementStyle.getFgColour().getRed(HTML)
   64            << elementStyle.getFgColour().getGreen(HTML)
   65            << elementStyle.getFgColour().getBlue(HTML)
   66            << "\"";
   67     }
   68     if (elementStyle.isBgColorSet()) {
   69         fmtStream <<" bgcolor=\"#"
   70            << elementStyle.getBgColour().getRed(HTML)
   71            << elementStyle.getBgColour().getGreen(HTML)
   72            << elementStyle.getBgColour().getBlue(HTML)
   73            << "\"";
   74     }  
   75     string fmt  = fmtStream.str();
   76     tagIsOpen = fmt.size()>0;
   77     if (tagIsOpen) {
   78         ostringstream spanTag;
   79         spanTag<< "<span "<<fmt<<">";
   80         return spanTag.str();
   81     }
   82     return "";
   83 }
   84 
   85 string PangoGenerator::getCloseTag()
   86 {
   87     string retVal = tagIsOpen ? "</span>"  : "";
   88     tagIsOpen = false;
   89     return retVal;
   90 }
   91 string PangoGenerator::getHeader()
   92 {
   93 
   94     int fontSizePango=0;
   95     StringTools::str2num<int>(fontSizePango, fontSize, std::dec);
   96 
   97     ostringstream os;
   98     os << "<span";
   99     os << " font_family=\""<<font << "\"";
  100     os << " font_size=\""<<((fontSizePango)? fontSizePango*1024: 1024*10) << "\"";
  101     os << ">";
  102     return os.str();
  103 }
  104 
  105 string PangoGenerator::getFooter()
  106 {
  107     return "</span>";
  108 }
  109 
  110 void PangoGenerator::printBody()
  111 {
  112     processInput();
  113 }
  114 
  115 string PangoGenerator::maskCharacter(unsigned char c)
  116 {
  117     switch (c) {
  118     case '<' :
  119         return "&lt;";
  120         break;
  121     case '>' :
  122         return "&gt;";
  123         break;
  124     case '&' :
  125         return "&amp;";
  126         break;
  127     case '\t':
  128         return "\t";
  129         break;
  130     
  131     default :
  132         if (c>0x1f ) { // printable?
  133             return string( 1, c );
  134         } else {
  135             return "";
  136         }
  137     }
  138 }
  139 }