"Fossies" - the Fresh Open Source Software Archive

Member "highlight-3.57-x64/src/core/bbcodegenerator.cpp" (12 May 2020, 4279 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. See also the last Fossies "Diffs" side-by-side code changes report for "bbcodegenerator.cpp": 3.53_vs_3.54.

    1 /***************************************************************************
    2                     bbcodegenerator.cpp  -  description
    3                              -------------------
    4     begin                : Jul 21 2009
    5     copyright            : (C) 2004-2016 by Andre Simon
    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 "bbcodegenerator.h"
   31 
   32 namespace highlight
   33 {
   34 
   35 BBCodeGenerator::BBCodeGenerator() : CodeGenerator ( BBCODE )
   36 {
   37     newLineTag = "\n";
   38     spacer = " ";
   39 }
   40 
   41 BBCodeGenerator::~BBCodeGenerator() {}
   42 
   43 string BBCodeGenerator::getHeader()
   44 {
   45     return string();
   46 }
   47 
   48 void BBCodeGenerator::printBody()
   49 {
   50     *out << "[size="<<getBaseFontSize()<<"]";
   51     processRootState();
   52     *out << "[/size]";
   53 }
   54 
   55 string BBCodeGenerator::getFooter()
   56 {
   57     return string();
   58 }
   59 
   60 string  BBCodeGenerator::getOpenTag (const ElementStyle & elem )
   61 {
   62     ostringstream s;
   63 
   64     s << "[color=#";
   65     s  << elem.getColour().getRed ( HTML )
   66        << elem.getColour().getGreen ( HTML )
   67        << elem.getColour().getBlue ( HTML )
   68        << "]";
   69 
   70     if ( elem.isBold() ) s << "[b]";
   71     if ( elem.isItalic() ) s << "[i]";
   72     if ( elem.isUnderline() ) s << "[u]";
   73     return  s.str();
   74 }
   75 
   76 string  BBCodeGenerator::getCloseTag ( const ElementStyle &elem )
   77 {
   78     ostringstream s;
   79     if ( elem.isUnderline() ) s << "[/u]";
   80     if ( elem.isItalic() ) s << "[/i]";
   81     if ( elem.isBold() ) s << "[/b]";
   82     s << "[/color]";
   83     return  s.str();
   84 }
   85 
   86 void BBCodeGenerator::initOutputTags ()
   87 {
   88     openTags.push_back ( getOpenTag ( docStyle.getDefaultStyle() ) );
   89     openTags.push_back ( getOpenTag ( docStyle.getStringStyle() ) );
   90     openTags.push_back ( getOpenTag ( docStyle.getNumberStyle() ) );
   91     openTags.push_back ( getOpenTag ( docStyle.getSingleLineCommentStyle() ) );
   92     openTags.push_back ( getOpenTag ( docStyle.getCommentStyle() ) );
   93     openTags.push_back ( getOpenTag ( docStyle.getEscapeCharStyle() ) );
   94     openTags.push_back ( getOpenTag ( docStyle.getPreProcessorStyle() ) );
   95     openTags.push_back ( getOpenTag ( docStyle.getPreProcStringStyle() ) );
   96     openTags.push_back ( getOpenTag ( docStyle.getLineStyle() ) );
   97     openTags.push_back ( getOpenTag ( docStyle.getOperatorStyle() ) );
   98     openTags.push_back ( getOpenTag ( docStyle.getInterpolationStyle() ) );
   99 
  100     closeTags.push_back ( getCloseTag ( docStyle.getDefaultStyle() ) );
  101     closeTags.push_back ( getCloseTag ( docStyle.getStringStyle() ) );
  102     closeTags.push_back ( getCloseTag ( docStyle.getNumberStyle() ) );
  103     closeTags.push_back ( getCloseTag ( docStyle.getSingleLineCommentStyle() ) );
  104     closeTags.push_back ( getCloseTag ( docStyle.getCommentStyle() ) );
  105     closeTags.push_back ( getCloseTag ( docStyle.getEscapeCharStyle() ) );
  106     closeTags.push_back ( getCloseTag ( docStyle.getPreProcessorStyle() ) );
  107     closeTags.push_back ( getCloseTag ( docStyle.getPreProcStringStyle() ) );
  108     closeTags.push_back ( getCloseTag ( docStyle.getLineStyle() ) );
  109     closeTags.push_back ( getCloseTag ( docStyle.getOperatorStyle() ) );
  110     closeTags.push_back ( getCloseTag ( docStyle.getInterpolationStyle() ) );
  111 }
  112 
  113 string BBCodeGenerator::maskCharacter ( unsigned char c )
  114 {
  115     return string ( 1, c );
  116 }
  117 
  118 string BBCodeGenerator::getKeywordOpenTag ( unsigned int styleID )
  119 {
  120     return getOpenTag (docStyle.getKeywordStyle ( currentSyntax->getKeywordClasses() [styleID] ) );
  121 }
  122 
  123 string BBCodeGenerator::getKeywordCloseTag ( unsigned int styleID )
  124 {
  125     return getCloseTag ( docStyle.getKeywordStyle ( currentSyntax->getKeywordClasses() [styleID] ) );
  126 }
  127 
  128 }