"Fossies" - the Fresh Open Source Software Archive

Member "highlight-3.57-x64/src/core/pangogenerator.cpp" (12 May 2020, 3808 Bytes) of package /windows/www/highlight-3.57-x64.zip:


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.

    1 /***************************************************************************
    2                    PangoGenerator.cpp  -  description
    3                              -------------------
    4     begin                : Sept 5 2014
    5     copyright            : (C) 2014 by Dominik Schmidt
    6     email                : a.simon@mailbox.org
    7  ***************************************************************************/
    8 
    9 
   10 /*
   11 This file is part of Highlight.
   12 
   13 Highlight is free software: you can redistribute it and/or modify
   14 it under the terms of the GNU General Public License as published by
   15 the Free Software Foundation, either version 3 of the License, or
   16 (at your option) any later version.
   17 
   18 Highlight is distributed in the hope that it will be useful,
   19 but WITHOUT ANY WARRANTY; without even the implied warranty of
   20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
   21 GNU General Public License for more details.
   22 
   23 You should have received a copy of the GNU General Public License
   24 along with Highlight.  If not, see <http://www.gnu.org/licenses/>.
   25 */
   26 
   27 
   28 #include <sstream>
   29 
   30 #include "pangogenerator.h"
   31 
   32 namespace highlight
   33 {
   34 
   35 string PangoGenerator::getOpenTag ( const ElementStyle & elem )
   36 {
   37     return "<span "+getAttributes ( elem ) + ">";
   38 }
   39 
   40 string PangoGenerator::getAttributes ( const ElementStyle & elem )
   41 {
   42     ostringstream s;
   43     s << "foreground=\"#"
   44       << ( elem.getColour().getRed ( HTML ) )
   45       << ( elem.getColour().getGreen ( HTML ) )
   46       << ( elem.getColour().getBlue ( HTML ) )
   47       << "\""
   48       << ( elem.isBold() ?     " weight=\"bold\"" :"" )
   49       << ( elem.isItalic() ?   " style=\"italic\"" :"" )
   50       << ( elem.isUnderline() ? " underline=\"single\"" :"" );
   51     return s.str();
   52 }
   53 
   54 PangoGenerator::PangoGenerator() : CodeGenerator ( PANGO )
   55 {
   56 
   57     newLineTag = "\n";
   58     spacer = " ";
   59 }
   60 
   61 PangoGenerator::~PangoGenerator() {}
   62 
   63 void PangoGenerator::initOutputTags()
   64 {
   65     openTags.push_back ( "" );
   66     openTags.push_back ( getOpenTag ( docStyle.getStringStyle() ) );
   67     openTags.push_back ( getOpenTag ( docStyle.getNumberStyle() ) );
   68     openTags.push_back ( getOpenTag ( docStyle.getSingleLineCommentStyle() ) );
   69     openTags.push_back ( getOpenTag ( docStyle.getCommentStyle() ) );
   70     openTags.push_back ( getOpenTag ( docStyle.getEscapeCharStyle() ) );
   71     openTags.push_back ( getOpenTag ( docStyle.getPreProcessorStyle() ) );
   72     openTags.push_back ( getOpenTag ( docStyle.getPreProcStringStyle() ) );
   73     openTags.push_back ( getOpenTag ( docStyle.getLineStyle() ) );
   74     openTags.push_back ( getOpenTag ( docStyle.getOperatorStyle() ) );
   75     openTags.push_back ( getOpenTag ( docStyle.getInterpolationStyle() ) );
   76 
   77     closeTags.push_back ( "" );
   78     for (unsigned int i=1; i<NUMBER_BUILTIN_STATES; i++ ) {
   79         closeTags.push_back ( "</span>" );
   80     }
   81 }
   82 
   83 string PangoGenerator::getHeader()
   84 {
   85     return string();
   86 }
   87 
   88 void PangoGenerator::printBody()
   89 {
   90     int fontSize=0;
   91     StringTools::str2num<int> ( fontSize, this->getBaseFontSize(), std::dec );
   92 
   93     *out << "<span size=\""<<( ( fontSize ) ? fontSize*1024: 10*1024 ) << "\" "
   94          << "font_family=\"" << getBaseFont() << "\""
   95          <<">";
   96     processRootState();
   97     *out << "</span>";
   98 }
   99 
  100 string PangoGenerator::getFooter()
  101 {
  102     return string();
  103 }
  104 
  105 string PangoGenerator::maskCharacter ( unsigned char c )
  106 {
  107     switch ( c ) {
  108     case '<' :
  109         return "&lt;";
  110         break;
  111     case '>' :
  112         return "&gt;";
  113         break;
  114     case '&' :
  115         return "&amp;";
  116         break;
  117     default :
  118         return string ( 1, c );
  119     }
  120 }
  121 
  122 string PangoGenerator::getKeywordOpenTag ( unsigned int styleID )
  123 {
  124     return getOpenTag (docStyle.getKeywordStyle ( currentSyntax->getKeywordClasses() [styleID] ) );
  125 }
  126 
  127 string PangoGenerator::getKeywordCloseTag ( unsigned int styleID )
  128 {
  129     return "</span>";
  130 }
  131 
  132 }