/*************************************************************************** rtfcode.cpp - description ------------------- begin : Die Jul 9 2002 copyright : (C) 2002-2007 by Andre Simon email : andre.simon1@gmx.de ***************************************************************************/ /* This file is part of Highlight. Highlight is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. Highlight is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with Highlight. If not, see . */ #include #include "charcodes.h" #include "version.h" #include "rtfgenerator.h" using namespace std; namespace highlight { string RtfGenerator::getAttributes ( const ElementStyle & col ) { stringstream s; s << "\\red"<< col.getColour().getRed ( RTF ) << "\\green"< ( fontSize, this->getBaseFontSize(), std::dec ); s << ( ( fontSize ) ? fontSize*2: 20 ); // RTF needs double amount if ( elem.isBold() ) s << "\\b"; if ( elem.isItalic() ) s << "\\i"; if ( elem.isUnderline() ) s << "\\ul"; s << "\\sbasedon222\\snext0 "<< styleName << ";}\n"; return s.str(); } // {\*\cs2\additive\cf2\f1\fs20\sbasedon222\snext0 HL Default;} string RtfGenerator::getCloseTag ( const ElementStyle &elem ) { ostringstream s; if ( elem.isBold() ) s << "\\b0 "; if ( elem.isItalic() ) s << "\\i0 "; if ( elem.isUnderline() ) s << "\\ul0 "; s << "}}"; return s.str(); } RtfGenerator::RtfGenerator() : CodeGenerator ( RTF ), pageSize ( "a4" ), // Default: DIN A4 addCharStyles ( false ) { newLineTag = "}\\par\\pard\n\\cbpat1{"; spacer = " "; // Page dimensions psMap["a3"] = PageSize ( 16837,23811 ); psMap["a4"] = PageSize ( 11905,16837 ); psMap["a5"] = PageSize ( 8390,11905 ); psMap["b4"] = PageSize ( 14173,20012 ); psMap["b5"] = PageSize ( 9977,14173 ); psMap["b6"] = PageSize ( 7086,9977 ); psMap["letter"] = PageSize ( 12240,15840 ); psMap["legal"] = PageSize ( 12240,20163 ); } RtfGenerator::~RtfGenerator() {} string RtfGenerator::getHeader() { return string(); } void RtfGenerator::printBody() { *out << "{\\rtf1\\ansi\\uc0 \\deff1" << "{\\fonttbl{\\f1\\fmodern\\fprq1\\fcharset0 " ; *out << this->getBaseFont() ; *out << ";}}" << "{\\colortbl;"; *out << "\\red" << ( docStyle.getBgColour().getRed ( RTF ) ); *out << "\\green" << ( docStyle.getBgColour().getGreen ( RTF ) ); *out << "\\blue" << ( docStyle.getBgColour().getBlue ( RTF ) ); *out << ";"; *out << getAttributes ( docStyle.getDefaultStyle() ); *out << getAttributes ( docStyle.getStringStyle() ); *out << getAttributes ( docStyle.getNumberStyle() ); *out << getAttributes ( docStyle.getSingleLineCommentStyle() ); *out << getAttributes ( docStyle.getCommentStyle() ); *out << getAttributes ( docStyle.getEscapeCharStyle() ); *out << getAttributes ( docStyle.getDirectiveStyle() ); *out << getAttributes ( docStyle.getDirectiveStringStyle() ); *out << getAttributes ( docStyle.getLineStyle() ); *out << getAttributes ( docStyle.getSymbolStyle() ); /* For output formats which can refer to external styles it is more safe to use the colour theme's keyword class names, since the language definitions (which may change during a batch conversion) do not have to define all keyword classes, that are needed to highlight all input files correctly. It is ok for RTF to use the language definition's class names, because RTF does not refer to external styles. We cannot use the theme's class names, because KSIterator returns an alphabetically ordered list, which is not good because RTF is dependent on the order. We access the keyword style with an ID, which is calculated ignoring the alphabetic order. */ vector keywordClasses = langInfo.getKeywordClasses(); for ( unsigned int i=0;i ( fontSize, this->getBaseFontSize(), std::dec ); *out << ( ( fontSize ) ? fontSize*2: 20 ); // RTF needs double amount *out << "\n\\pard \\cbpat1{"; processRootState(); *out << "}}"<