"Fossies" - the Fresh Open Source Software Archive

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

    1 /***************************************************************************
    2                           rtfcode.h  -  description
    3                              -------------------
    4     begin                : Die Jul 9 2002
    5     copyright            : (C) 2002-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 #ifndef RTFGENERATOR_H
   29 #define RTFGENERATOR_H
   30 
   31 #include <string>
   32 
   33 #include "codegenerator.h"
   34 
   35 namespace highlight
   36 {
   37 
   38 /**
   39    PageSize contains the RTF page dimensions.
   40 */
   41 struct PageSize {
   42     /// RTF page width
   43     int width;
   44     /// RTF page height
   45     int height;
   46 
   47     PageSize()
   48     {
   49         width = 0;
   50         height = 0;
   51     }
   52 
   53     /** Constructor to define page dimensions
   54         @param w width
   55         @param h height*/
   56     PageSize ( int w, int h )
   57     {
   58         width=w;
   59         height = h;
   60     }
   61 
   62 };
   63 
   64 /** mapping of page size names and dimensions */
   65 typedef  map<string, struct PageSize> PagesizeMap;
   66 
   67 /**
   68    \brief This class generates RTF.
   69 
   70    It contains information about the resulting document structure (document
   71    header and footer), the colour system, white space handling and text
   72    formatting attributes.
   73 
   74 * @author Andre Simon
   75 */
   76 
   77 class RtfGenerator : public highlight::CodeGenerator
   78 {
   79 public:
   80 
   81     RtfGenerator();
   82 
   83     ~RtfGenerator();
   84 
   85     /**  Define RTF page size
   86          @param ps RTF page size (a3, a4, a5, b4, b5, b6, letter, legal) */
   87     void setRTFPageSize ( const string & ps );
   88 
   89     /** @param cs flag to enable character styles*/
   90     void setRTFCharStyles ( bool cs );
   91     
   92     /** @param pc flag to enable page color output */
   93     void setRTFPageColor ( bool pc );
   94 
   95 private:
   96 
   97     /** prints document header
   98      */
   99     string getHeader();
  100 
  101     /** Prints document footer*/
  102     string getFooter();
  103 
  104     /** Prints document body*/
  105     void printBody();
  106 
  107     /** initialize tags in specific format according to colouring information provided in DucumentStyle */
  108     void initOutputTags();
  109 
  110     /** Map of several pagesizes */
  111     PagesizeMap psMap;
  112 
  113     /** name of page size which is mapped to page dimensions*/
  114     string pageSize;
  115 
  116     /** flag to add character styles */
  117     bool addCharStyles;
  118 
  119     /** flag to add page color */
  120     bool addPageColor;
  121     
  122     /** flag to enable Unicode conversion */
  123     bool isUtf8;
  124     
  125     /** utf-8 to utf-16 conversion variables */
  126     unsigned long utf16Char;
  127     size_t utf8SeqLen;
  128     
  129     /** @return escaped character*/
  130     virtual string maskCharacter ( unsigned char );
  131 
  132     /**\return text formatting attributes in RTF format */
  133     string  getAttributes ( const ElementStyle & col );
  134 
  135     /** @param styleNumber number of current style
  136         @param elem associated element style
  137         @return RTF formatting sequence (colour index + bold + italic)*/
  138     string getOpenTag ( int styleNumber,const ElementStyle &elem );
  139 
  140     /** @param styleNumber number of current style
  141         @param elem associated element style
  142         @param styleName style name
  143         @return RTF character style definition */
  144     string getCharStyle ( int styleNumber,const ElementStyle &elem, const string&styleName );
  145 
  146     /** @param elem associated element style
  147         @return RTF formatting sequnce to close element formatting */
  148     string getCloseTag ( const ElementStyle &elem );
  149 
  150     /** @param styleID current style ID
  151         @return matching sequence to begin a new element formatting*/
  152     string getKeywordOpenTag ( unsigned int styleID );
  153 
  154     /** @param styleID current style ID
  155         @return matching  sequence to stop element formatting*/
  156     string getKeywordCloseTag ( unsigned int styleID );
  157 };
  158 
  159 }
  160 #endif