"Fossies" - the Fresh Open Source Software Archive

Member "highlight-3.57-x64/src/include/xterm256generator.h" (12 May 2020, 3714 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 "xterm256generator.h": 3.53_vs_3.54.

    1 /***************************************************************************
    2                        xterm256generator.h  -  description
    3                              -------------------
    4     begin                : Oct 13 2006
    5     copyright            : (C) 2006-2018 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 #ifndef XTERM256GENERATOR_H
   29 #define XTERM256GENERATOR_H
   30 
   31 #include <string>
   32 
   33 #include "codegenerator.h"
   34 
   35 
   36 namespace highlight
   37 {
   38 
   39 /**
   40    \brief This class generates xterm 256 and 16m color escape sequences.
   41 
   42    It contains information about the resulting document structure (document
   43    header and footer), the colour system, white space handling and text
   44    formatting attributes.
   45 
   46 * @author Andre Simon
   47 */
   48 
   49 class Xterm256Generator : public highlight::CodeGenerator
   50 {
   51 public:
   52     Xterm256Generator();
   53     ~Xterm256Generator();
   54 
   55     
   56     /** @param b toggle truecolor mode */
   57     void setESCTrueColor(bool b);
   58     
   59     
   60     /** @param p initial canvas width (0 to disable) */
   61     void setESCCanvasPadding(unsigned int p);
   62     
   63 private:
   64 
   65     /** prints document header
   66      */
   67     string getHeader();
   68 
   69     /** Prints document footer*/
   70     string getFooter();
   71 
   72     /** Prints document body*/
   73     void printBody();
   74 
   75     /** \return escaped character*/
   76     virtual string maskCharacter ( unsigned char );
   77 
   78     /** initialize tags in specific format according to colouring information provided in DucumentStyle */
   79     void initOutputTags();
   80 
   81     /** @param style associated element style
   82         @return formatting sequence */
   83     string getOpenTag (const ElementStyle &style );
   84 
   85     /** @param styleID current style ID
   86         @return matching sequence to begin a new element formatting*/
   87     string getKeywordOpenTag ( unsigned int styleID );
   88 
   89     /** @param styleID current style ID
   90         @return matching sequence to close element formatting*/
   91     string getKeywordCloseTag ( unsigned int styleID );
   92 
   93     /** @return Newline string */
   94     string getNewLine();
   95     
   96     /** convert an xterm color value (0-253) to 3 unsigned chars rgb
   97         @param color xterm color
   98         @param rgb RGB destination string */
   99     void xterm2rgb ( unsigned char color, unsigned char* rgb );
  100 
  101     /** fill the colortable for use with rgb2xterm */
  102     void maketable();
  103 
  104     /** selects the nearest xterm color for a 3xBYTE rgb value
  105         @param RGB colour string */
  106     unsigned char rgb2xterm ( unsigned char* rgb );
  107     
  108     // set true if "True Color" escape codes should be used instead of 256 color approximation
  109     bool use16mColours;
  110     
  111     string canvasColSeq;
  112     
  113     unsigned int canvasPadding;
  114 
  115     /// Flag to determine if colourtable is calculated
  116     static bool initialized;
  117 
  118     /// color tzable for nearest match calculation
  119     static unsigned char colortable[254][3];
  120 
  121     /// the 6 value iterations in the xterm color cube
  122     static const unsigned char valuerange[] ;
  123 
  124     /// 16 basic colors
  125     static const unsigned char basic16[16][3];
  126 };
  127 
  128 }
  129 #endif