"Fossies" - the Fresh Open Source Software Archive

Member "ansifilter-2.18-x64/src/rtfgenerator.cpp" (30 Jan 2021, 18427 Bytes) of package /windows/misc/ansifilter-2.18-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 latest Fossies "Diffs" side-by-side code changes report for "rtfgenerator.cpp": 2.17_vs_2.18.

    1 /***************************************************************************
    2                           rtfcode.cpp  -  description
    3                              -------------------
    4     copyright            : (C) 2007-2017 by Andre Simon
    5     email                : a.simon@mailbox.org
    6  ***************************************************************************/
    7 
    8 /*
    9 This file is part of ANSIFilter.
   10 
   11 ANSIFilter is free software: you can redistribute it and/or modify
   12 it under the terms of the GNU General Public License as published by
   13 the Free Software Foundation, either version 3 of the License, or
   14 (at your option) any later version.
   15 
   16 ANSIFilter is distributed in the hope that it will be useful,
   17 but WITHOUT ANY WARRANTY; without even the implied warranty of
   18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
   19 GNU General Public License for more details.
   20 
   21 You should have received a copy of the GNU General Public License
   22 along with ANSIFilter.  If not, see <http://www.gnu.org/licenses/>.
   23 */
   24 
   25 #include <sstream>
   26 
   27 #include "charcodes.h"
   28 #include "version.h"
   29 #include "rtfgenerator.h"
   30 #include "stylecolour.h"
   31 
   32 namespace ansifilter
   33 {
   34 
   35 
   36 RtfGenerator::RtfGenerator()
   37 : CodeGenerator(RTF),
   38     pageSize("a4"), // Default: DIN A4
   39     isUtf8(false),
   40     utf16Char(0),
   41     utf8SeqLen(0)
   42 {
   43     newLineTag = "\\line\n";
   44     spacer=" ";
   45 
   46     // Page dimensions
   47     psMap["a3"] = PageSize(16837,23811);
   48     psMap["a4"] = PageSize(11905,16837);
   49     psMap["a5"] = PageSize(8390,11905);
   50 
   51     psMap["b4"] = PageSize(14173,20012);
   52     psMap["b5"] = PageSize(9977,14173);
   53     psMap["b6"] = PageSize(7086,9977);
   54 
   55     psMap["letter"] = PageSize(12240,15840);
   56     psMap["legal"] = PageSize(12240,20163);
   57 }
   58 
   59 RtfGenerator::~RtfGenerator()
   60 {}
   61 
   62 string RtfGenerator::getAttributes( const StyleColour & col)
   63 {
   64     stringstream s;
   65     s  << "\\red"<< col.getRed(RTF)
   66        << "\\green"<<col.getGreen(RTF)
   67        << "\\blue"<<col.getBlue(RTF)
   68        << ";";
   69     return s.str();
   70 }
   71 
   72 string RtfGenerator::getOpenTag()
   73 {
   74     ostringstream s;
   75     if (elementStyle.getFgColourID()>=0) {
   76         s << "{\\cf"<<(elementStyle.getFgColourID()+ 1);
   77     }
   78     if (elementStyle.getBgColourID()>=0) {
   79         s <<  "\\chcbpat"<<(elementStyle.getBgColourID()+1);
   80     }
   81     s <<"{";
   82     if (!parseCP437 &&  elementStyle.isBold()) s << "\\b ";
   83     if (elementStyle.isItalic()) s << "\\i ";
   84     if (elementStyle.isUnderline()) s << "\\ul ";
   85     return  s.str();
   86 }
   87 
   88 string  RtfGenerator::getCloseTag()
   89 {
   90     ostringstream s;
   91     if (!parseCP437 && elementStyle.isBold()) s << "\\b0 ";
   92     if (elementStyle.isItalic()) s << "\\i0 ";
   93     if (elementStyle.isUnderline()) s << "\\ul0 ";
   94     s << "}}";
   95     return  s.str();
   96 }
   97 
   98 /* '{{\\field{\\*\\fldinst HYPERLINK "'..token..'" }{\\fldrslt\\ul\\ulc0 '..token..'}}}' */
   99 
  100 string RtfGenerator::getHyperlink(string uri, string txt){
  101     ostringstream os;
  102     os <<"{{\\field{\\*\\fldinst HYPERLINK \""<<uri<<"\" }{\\fldrslt\\ul\\ulc0 "<<txt<<"}}}";
  103     return os.str();
  104 }
  105 
  106 string RtfGenerator::getHeader()
  107 {
  108     return string();
  109 }
  110 
  111 void RtfGenerator::printBody()
  112 {
  113     isUtf8 = encoding == "utf-8" || encoding == "UTF-8"; // FIXME
  114 
  115     *out << "{\\rtf1";
  116 
  117     if (parseCP437)
  118       *out<< "\\cpg437";
  119     else
  120       *out<< "\\ansi";
  121 
  122     *out <<" \\deff1"
  123          << "{\\fonttbl{\\f1\\fmodern\\fprq1\\fcharset0 " ;
  124     *out << font ;
  125     *out << ";}}"
  126          << "{\\colortbl;";
  127 
  128     for (int i=0;i<16;i++){
  129       *out << getAttributes(StyleColour(rgb2html(workingPalette[i])));
  130     }
  131 
  132     *out << "}\n";
  133 
  134     *out  << "\\paperw"<< psMap[pageSize].width <<"\\paperh"<< psMap[pageSize].height
  135           << "\\margl1134\\margr1134\\margt1134\\margb1134\\sectd" // page margins
  136           << "\\plain\\f1\\fs" ;  // Font formatting
  137 
  138     int fontSizeRTF=0;
  139     StringTools::str2num<int>(fontSizeRTF, fontSize, std::dec);
  140     *out << ((fontSizeRTF)? fontSizeRTF*2: 20);  // RTF needs double amount
  141     *out << "\n\\pard";
  142 
  143     //TODO save 24bit colors in RTF
  144     if (parseCP437/*||parseAsciiBin||parseAsciiTundra*/) *out << "\\cbpat1{";
  145 
  146     processInput();
  147 
  148     if (parseCP437/*||parseAsciiBin||parseAsciiTundra*/) *out << "}";
  149 
  150     *out << "}"<<endl;
  151 }
  152 
  153 string RtfGenerator::getFooter()
  154 {
  155     return string();
  156 }
  157 
  158 string RtfGenerator::maskCharacter(unsigned char c)
  159 {
  160   if (isUtf8 && c > 0x7f  && utf8SeqLen==0){
  161 
  162     //http://stackoverflow.com/questions/7153935/how-to-convert-utf-8-stdstring-to-utf-16-stdwstring
  163 
  164     if (c <= 0xDF)
  165     {
  166       utf16Char = c&0x1F;
  167       utf8SeqLen = 1;
  168     }
  169     else if (c <= 0xEF)
  170     {
  171       utf16Char = c&0x0F;
  172       utf8SeqLen = 2;
  173     }
  174     else if (c <= 0xF7)
  175     {
  176       utf16Char = c&0x07;
  177       utf8SeqLen = 3;
  178     } else {
  179       utf8SeqLen = 0;
  180     }
  181     return "";
  182   }
  183 
  184   if (utf8SeqLen) {
  185     utf16Char <<= 6;
  186     utf16Char += c & 0x3f;
  187     --utf8SeqLen;
  188 
  189     if (!utf8SeqLen){
  190       string m ( "\\u" );
  191       m += to_string(utf16Char);
  192       m += '?';
  193       utf16Char=0L;
  194       return m;
  195     } else {
  196       return "";
  197     }
  198   }
  199 
  200   switch (c) {
  201     case '}' :
  202     case '{' :
  203     case '\\' : {
  204         string m;
  205         m="\\";
  206         return m+=c;
  207     }
  208     break;
  209     case '\t' : // see deletion of nonprintable chars below
  210         return "\t";
  211         break;
  212 
  213     case '0':
  214     case '1':
  215     case '2':
  216     case '3':
  217     case '4':
  218     case '5':
  219     case '6':
  220     case '7':
  221     case '8':
  222     case '9': {
  223         string m;
  224         m="{";
  225         m+=c;
  226         m+="}";
  227         return m;
  228     }
  229     break;
  230 
  231     case AUML_LC:
  232         return "\\'e4";
  233         break;
  234     case OUML_LC:
  235         return "\\'f6";
  236         break;
  237     case UUML_LC:
  238         return "\\'fc";
  239         break;
  240     case AUML_UC:
  241         return "\\'c4";
  242         break;
  243     case OUML_UC:
  244         return "\\'d6";
  245         break;
  246     case UUML_UC:
  247         return "\\'dc";
  248         break;
  249 
  250     case AACUTE_LC:
  251         return "\\'e1";
  252         break;
  253     case EACUTE_LC:
  254         return "\\'e9";
  255         break;
  256     case OACUTE_LC:
  257         return "\\'f3";
  258         break;
  259     case UACUTE_LC:
  260         return "\\'fa";
  261         break;
  262 
  263     case AGRAVE_LC:
  264         return "\\'e0";
  265         break;
  266     case EGRAVE_LC:
  267         return "\\'e8";
  268         break;
  269     case OGRAVE_LC:
  270         return "\\'f2";
  271         break;
  272     case UGRAVE_LC:
  273         return "\\'f9";
  274         break;
  275 
  276     case AACUTE_UC:
  277         return "\\'c1";
  278         break;
  279     case EACUTE_UC:
  280         return "\\'c9";
  281         break;
  282     case OACUTE_UC:
  283         return "\\'d3";
  284         break;
  285     case UACUTE_UC:
  286         return "\\'da";
  287         break;
  288     case AGRAVE_UC:
  289         return "\\'c0";
  290         break;
  291     case EGRAVE_UC:
  292         return "\\'c8";
  293         break;
  294     case OGRAVE_UC:
  295         return "\\'d2";
  296         break;
  297     case UGRAVE_UC:
  298         return "\\'d9";
  299         break;
  300 
  301     case SZLIG:
  302         return "\\'df";
  303         break;
  304 
  305     default : {
  306         if (c>0x1f ) {
  307             return string( 1, c );
  308         } else {
  309             return "";
  310         }
  311     }
  312   }
  313 }
  314 
  315 string RtfGenerator::unicodeFromHTML(const string &htmlEntity){
  316   if (htmlEntity.length()!=8) return "";
  317 
  318   string decCode = "\\u", hexCode = htmlEntity.substr(3,4);
  319 
  320   int x=0;
  321   std::istringstream iss(hexCode);
  322 
  323   iss >> std::hex >> x;
  324   decCode += to_string(x);
  325   decCode +="?";
  326 
  327   return decCode;
  328 }
  329 
  330 string RtfGenerator::maskCP437Character(unsigned char c)
  331 {
  332   switch (c) {
  333     case 0:
  334    // case ' ' :
  335       return " "; break;
  336 
  337     case '}' :
  338     case '{' :
  339     case '\\' : {
  340       string m;
  341       m="\\";
  342       return m+=c;
  343     }
  344     break;
  345     case '\t' : // see deletion of nonprintable chars below
  346       return "\t";
  347       break;
  348 
  349 
  350     case '0':
  351     case '1':
  352     case '2':
  353     case '3':
  354     case '4':
  355     case '5':
  356     case '6':
  357     case '7':
  358     case '8':
  359     case '9': {
  360       string m;
  361       m="{";
  362       m+=c;
  363       m+="}";
  364       return m;
  365     }
  366     break;
  367 
  368     case 0x01:
  369       return unicodeFromHTML("&#x263a;");
  370       break;
  371     case 0x02:
  372       return unicodeFromHTML("&#x263b;");
  373       break;
  374     case 0x03:
  375       return unicodeFromHTML("&#x2665;");
  376       break;
  377     case 0x04:
  378       return unicodeFromHTML("&#x2666;");
  379       break;
  380     case 0x05:
  381       return unicodeFromHTML("&#x2663;");
  382       break;
  383     case 0x06:
  384       return unicodeFromHTML("&#x2660;");
  385       break;
  386     case 0x08:
  387       return unicodeFromHTML("&#x25d8;");
  388       break;
  389     case 0x0a:
  390       return unicodeFromHTML("&#x25d9;");
  391       break;
  392     case 0x0b:
  393       return unicodeFromHTML("&#x2642;");
  394       break;
  395     case 0x0c:
  396       return unicodeFromHTML("&#x2640;");
  397       break;
  398 
  399     case 0x10:
  400       return unicodeFromHTML("&#x25BA;");
  401       break;
  402     case 0x11:
  403       return unicodeFromHTML("&#x25C4;");
  404       break;
  405     case 0x12:
  406       return unicodeFromHTML("&#x2195;");
  407       break;
  408     case 0x13:
  409       return unicodeFromHTML("&#x203C;");
  410       break;
  411     case 0x14:
  412       return unicodeFromHTML("&#x00b6;");
  413       break;
  414     case 0x15:
  415       return unicodeFromHTML("&#x00a7;");
  416       break;
  417     case 0x16:
  418       return unicodeFromHTML("&#x25ac;");
  419       break;
  420     case 0x17:
  421       return unicodeFromHTML("&#x21A8;");
  422       break;
  423     case 0x18:
  424       return unicodeFromHTML("&#x2191;");
  425       break;
  426     case 0x19:
  427       return unicodeFromHTML("&#x2193;");
  428       break;
  429     case 0x1a:
  430       return unicodeFromHTML("&#x2192;");
  431       break;
  432     case 0x1b:
  433       return unicodeFromHTML("&#x2190;");
  434       break;
  435     case 0x1c:
  436       return unicodeFromHTML("&#x221F;");
  437       break;
  438     case 0x1d:
  439       return unicodeFromHTML("&#x2194;");
  440       break;
  441     case 0x1e:
  442       return unicodeFromHTML("&#x25B2;");
  443       break;
  444     case 0x1f:
  445       return unicodeFromHTML("&#x25BC;");
  446       break;
  447 
  448     case 0x80:
  449       return unicodeFromHTML("&#x00c7;");
  450       break;
  451     case 0x81:
  452       return unicodeFromHTML("&#x00fc;");
  453       break;
  454     case 0x82:
  455       return unicodeFromHTML("&#x00e9;");
  456       break;
  457     case 0x83:
  458       return unicodeFromHTML("&#x00e2;");
  459       break;
  460     case 0x84:
  461       return unicodeFromHTML("&#x00e4;");
  462       break;
  463     case 0x85:
  464       return unicodeFromHTML("&#x00e0;");
  465       break;
  466     case 0x86:
  467       return unicodeFromHTML("&#x00e5;");
  468       break;
  469     case 0x87:
  470       return unicodeFromHTML("&#x00e7;");
  471       break;
  472     case 0x88:
  473       return unicodeFromHTML("&#x00ea;");
  474       break;
  475     case 0x89:
  476       return unicodeFromHTML("&#x00eb;");
  477       break;
  478     case 0x8a:
  479       return unicodeFromHTML("&#x00e8;");
  480       break;
  481     case 0x8b:
  482       return unicodeFromHTML("&#x00ef;");
  483       break;
  484     case 0x8c:
  485       return unicodeFromHTML("&#x00ee;");
  486       break;
  487     case 0x8d:
  488       return unicodeFromHTML("&#x00ec;");
  489       break;
  490     case 0x8e:
  491       return unicodeFromHTML("&#x00c4;");
  492       break;
  493     case 0x8f:
  494       return unicodeFromHTML("&#x00c5;");
  495       break;
  496 
  497     case 0x90:
  498       return unicodeFromHTML("&#x00c9;");
  499       break;
  500     case 0x91:
  501       return unicodeFromHTML("&#x00e6;");
  502       break;
  503     case 0x92:
  504       return unicodeFromHTML("&#x00c6;");
  505       break;
  506     case 0x93:
  507       return unicodeFromHTML("&#x00f4;");
  508       break;
  509     case 0x94:
  510       return unicodeFromHTML("&#x00f6;");
  511       break;
  512     case 0x95:
  513       return unicodeFromHTML("&#x00f2;");
  514       break;
  515     case 0x96:
  516       return unicodeFromHTML("&#x00fb;");
  517       break;
  518     case 0x97:
  519       return unicodeFromHTML("&#x00f9;");
  520       break;
  521     case 0x98:
  522       return unicodeFromHTML("&#x00ff;");
  523       break;
  524     case 0x99:
  525       return unicodeFromHTML("&#x00d6;");
  526       break;
  527     case 0x9a:
  528       return unicodeFromHTML("&#x00dc;");
  529       break;
  530     case 0x9b:
  531       return unicodeFromHTML("&#x00a2;");
  532       break;
  533     case 0x9c:
  534       return unicodeFromHTML("&#x00a3;");
  535       break;
  536     case 0x9d:
  537       return unicodeFromHTML("&#x00a5;");
  538       break;
  539     case 0x9e:
  540       return unicodeFromHTML("&#x20a7;");
  541       break;
  542     case 0x9f:
  543       return unicodeFromHTML("&#x0192;");
  544       break;
  545 
  546     case 0xa0:
  547       return unicodeFromHTML("&#x00e1;");
  548       break;
  549     case 0xa1:
  550       return unicodeFromHTML("&#x00ed;");
  551       break;
  552     case 0xa2:
  553       return unicodeFromHTML("&#x00f3;");
  554       break;
  555     case 0xa3:
  556       return unicodeFromHTML("&#x00fa;");
  557       break;
  558     case 0xa4:
  559       return unicodeFromHTML("&#x00f1;");
  560       break;
  561     case 0xa5:
  562       return unicodeFromHTML("&#x00d1;");
  563       break;
  564     case 0xa6:
  565       return unicodeFromHTML("&#x00aa;");
  566       break;
  567     case 0xa7:
  568       return unicodeFromHTML("&#x00ba;");
  569       break;
  570     case 0xa8:
  571       return unicodeFromHTML("&#x00bf;");
  572       break;
  573     case 0xa9:
  574       return unicodeFromHTML("&#x2310;");
  575       break;
  576     case 0xaa:
  577       return unicodeFromHTML("&#x00ac;");
  578       break;
  579     case 0xab:
  580       return unicodeFromHTML("&#x00bd;");
  581       break;
  582     case 0xac:
  583       return unicodeFromHTML("&#x00bc;");
  584       break;
  585     case 0xad:
  586       return unicodeFromHTML("&#x00a1;");
  587       break;
  588     case 0xae:
  589       return unicodeFromHTML("&#x00ab;");
  590       break;
  591     case 0xaf:
  592       return unicodeFromHTML("&#x00bb;");
  593       break;
  594 
  595       //shades
  596     case 0xb0:
  597       return "\\u9617?";
  598       break;
  599     case 0xb1:
  600       return "\\u9618?";
  601       break;
  602     case 0xb2:
  603       return "\\u9619?";
  604       break;
  605 
  606       //box drawings
  607     case 0xb3:
  608       return "\\u9474?";
  609       break;
  610     case 0xb4:
  611       return "\\u9508?";
  612       break;
  613     case 0xb5:
  614       return "\\u9569?";
  615       break;
  616     case 0xb6:
  617       return "\\u9570?";
  618       break;
  619     case 0xb7:
  620       return "\\u9558?";
  621       break;
  622     case 0xb8:
  623       return "\\u9557?";
  624       break;
  625     case 0xb9:
  626       return "\\u9571?";
  627       break;
  628     case 0xba:
  629       return "\\u9553?";
  630       break;
  631     case 0xbb:
  632       return "\\u9559?";
  633       break;
  634     case 0xbc:
  635       return "\\u9565?";
  636       break;
  637     case 0xbd:
  638       return "\\u9564?";
  639       break;
  640     case 0xbe:
  641       return "\\u9563?";
  642       break;
  643     case 0xbf:
  644       return "\\u9488?";
  645       break;
  646 
  647     case 0xc0:
  648       return "\\u9492?";
  649       break;
  650     case 0xc1:
  651       return "\\u9524?";
  652       break;
  653     case 0xc2:
  654       return "\\u9516?";
  655       break;
  656     case 0xc3:
  657       return "\\u9500?";
  658       break;
  659     case 0xc4:
  660       return "\\u9472?";
  661       break;
  662     case 0xc5:
  663       return "\\u9532?";
  664       break;
  665     case 0xc6:
  666       return "\\u9566?";
  667       break;
  668     case 0xc7:
  669       return "\\u9567?";
  670       break;
  671     case 0xc8:
  672       return "\\u9562?";
  673       break;
  674     case 0xc9:
  675       return "\\u9556?";
  676       break;
  677     case 0xca:
  678       return "\\u9577?";
  679       break;
  680     case 0xcb:
  681       return "\\u9574?";
  682       break;
  683     case 0xcc:
  684       return "\\u9568?";
  685       break;
  686     case 0xcd:
  687       return "\\u9552?";
  688       break;
  689     case 0xce:
  690       return "\\u9580?";
  691       break;
  692     case 0xcf:
  693       return "\\u9575?";
  694       break;
  695 
  696     case 0xd0:
  697       return "\\u9576?";
  698       break;
  699     case 0xd1:
  700       return "\\u9572?";
  701       break;
  702     case 0xd2:
  703       return "\\u9573?";
  704       break;
  705     case 0xd3:
  706       return "\\u9561?";
  707       break;
  708     case 0xd4:
  709       return "\\u9560?";
  710       break;
  711     case 0xd5:
  712       return "\\u9554?";
  713       break;
  714     case 0xd6:
  715       return "\\u9555?";
  716       break;
  717     case 0xd7:
  718       return "\\u9579?";
  719       break;
  720     case 0xd8:
  721       return "\\u9578?";
  722       break;
  723     case 0xd9:
  724       return "\\u9496?";
  725       break;
  726     case 0xda:
  727       return "\\u9484?";
  728       break;
  729 
  730       //https://de.wikipedia.org/wiki/Unicodeblock_Blockelemente
  731     case 0xdb:
  732       return "\\u9608?";
  733       break;
  734     case 0xdc:
  735       return "\\u9604?";
  736       break;
  737     case 0xdd:
  738       return "\\u9612?";
  739       break;
  740     case 0xde:
  741       return "\\u9616?";
  742       break;
  743     case 0xdf:
  744       return "\\u9600?";
  745       break;
  746 
  747     case 0xe0:
  748       return unicodeFromHTML("&#x03b1;");
  749       break;
  750     case 0xe1:
  751       return unicodeFromHTML("&#x00df;");
  752       break;
  753     case 0xe2:
  754       return unicodeFromHTML("&#x0393;");
  755       break;
  756     case 0xe3:
  757       return unicodeFromHTML("&#x03c0;");
  758       break;
  759     case 0xe4:
  760       return unicodeFromHTML("&#x03a3;");
  761       break;
  762     case 0xe5:
  763       return unicodeFromHTML("&#x03c3;");
  764       break;
  765     case 0xe6:
  766       return unicodeFromHTML("&#x00b5;");
  767       break;
  768     case 0xe7:
  769       return unicodeFromHTML("&#x03c4;");
  770       break;
  771     case 0xe8:
  772       return unicodeFromHTML("&#x03a6;");
  773       break;
  774     case 0xe9:
  775       return unicodeFromHTML("&#x0398;");
  776       break;
  777     case 0xea:
  778       return unicodeFromHTML("&#x03a9;");
  779       break;
  780     case 0xeb:
  781       return unicodeFromHTML("&#x03b4;");
  782       break;
  783 
  784     case 0xec:
  785       return unicodeFromHTML("&#x221e;");
  786       break;
  787     case 0xed:
  788       return unicodeFromHTML("&#x03c6;");
  789       break;
  790     case 0xee:
  791       return unicodeFromHTML("&#x03b5;");
  792       break;
  793     case 0xef:
  794       return unicodeFromHTML("&#x2229;");
  795       break;
  796 
  797     case 0xf0:
  798       return unicodeFromHTML("&#x2261;");
  799       break;
  800 
  801     case 0xf1:
  802       return unicodeFromHTML("&#x00b1;");
  803       break;
  804     case 0xf2:
  805       return unicodeFromHTML("&#x2265;");
  806       break;
  807     case 0xf3:
  808       return unicodeFromHTML("&#x2264;");
  809       break;
  810     case 0xf4:
  811       return unicodeFromHTML("&#x2320;");
  812       break;
  813     case 0xf5:
  814       return unicodeFromHTML("&#x2321;");
  815       break;
  816     case 0xf6:
  817       return unicodeFromHTML("&#x00f7;");
  818       break;
  819     case 0xf7:
  820       return unicodeFromHTML("&#x2248;");
  821       break;
  822     case 0xf8:
  823       return unicodeFromHTML("&#x00b0;");
  824       break;
  825 
  826     case 0xf9:
  827       return unicodeFromHTML("&#x2219;");
  828       break;
  829     case 0xfa:
  830       return unicodeFromHTML("&#x00b7;");
  831       break;
  832     case 0xfb:
  833       return unicodeFromHTML("&#x221a;");
  834       break;
  835     case 0xfc:
  836       return unicodeFromHTML("&#x207F;");
  837       break;
  838     case 0xfd:
  839       return unicodeFromHTML("&#x20b2;");
  840       break;
  841     case 0xfe:
  842       return unicodeFromHTML("&#x25a0;");
  843       break;
  844 
  845     case 0xff:
  846       return " ";
  847       break;
  848 
  849     default : {
  850       if (c ) {
  851         return string( 1, c );
  852       } else {
  853         return "";
  854       }
  855     }
  856   }
  857 }
  858 
  859 void RtfGenerator::setPageSize(const string & ps)
  860 {
  861     if (psMap.count(ps)) pageSize = ps;
  862 }
  863 
  864 void RtfGenerator::insertLineNumber ()
  865 {
  866     if ( showLineNumbers && !parseCP437 ) {
  867 
  868         ostringstream lnum;
  869         lnum << setw ( 5 ) << right;
  870         if( numberCurrentLine ) {
  871             lnum << lineNumber;
  872             *out <<lnum.str()<<spacer;
  873         } else {
  874             *out << lnum.str(); //for indentation
  875         }
  876     }
  877 }
  878 
  879 }