#include "synrtfexporter.h" SynRTFExporter::SynRTFExporter():SynExporter() { mDefaultFilter = "Rich Text Format Documents (*.rtf)|*.rtf"; mClipboardFormat = "application/x-qt-windows-mime;value=\"Rich Format Text\""; //mClipboardFormat = "Rich Format Text"; // setup array of chars to be replaced mReplaceReserved['\\'] = "\\\\"; mReplaceReserved['{'] = "\\{"; mReplaceReserved['}'] = "\\}"; } QString SynRTFExporter::ColorToRTF(const QColor &AColor) const { return QString("\\red%1\\green%2\\blue%3;") .arg(AColor.red()) .arg(AColor.green()) .arg(AColor.blue()); } int SynRTFExporter::GetColorIndex(const QColor &AColor) { int index = mListColors.indexOf(AColor); if (index<0) { mListColors.append(AColor); index = mListColors.length()-1; } return index; } QString SynRTFExporter::GetFontTable() { QString Result = "{\\fonttbl{\\f0\\fmodern\\fcharset134 " + ReplaceReservedChars(mFont.family()); Result = Result + ";}}" + lineBreak(); return Result; } void SynRTFExporter::FormatAttributeDone(bool , bool , SynFontStyles FontStylesChanged) { // nothing to do about the color, but reset the font style if (FontStylesChanged.testFlag(SynFontStyle::fsBold)) { mAttributesChanged = true; AddData("\\b0"); } if (FontStylesChanged.testFlag(SynFontStyle::fsItalic)) { mAttributesChanged = true; AddData("\\i0"); } if (FontStylesChanged.testFlag(SynFontStyle::fsUnderline)) { mAttributesChanged = true; AddData("\\ul0"); } if (FontStylesChanged.testFlag(SynFontStyle::fsStrikeOut)) { mAttributesChanged = true; AddData("\\strike0"); } } void SynRTFExporter::FormatAttributeInit(bool BackgroundChanged, bool ForegroundChanged, SynFontStyles FontStylesChanged) { // background color if (BackgroundChanged) { AddData(QString("\\chshdng0\\chcbpat%1\\cb%2\\highlight%3 ") .arg(GetColorIndex(mLastBG)) .arg(GetColorIndex(mLastBG)) .arg(GetColorIndex(mLastBG))); mAttributesChanged = true; } // text color if (ForegroundChanged) { AddData(QString("\\cf%1").arg(GetColorIndex(mLastFG))); mAttributesChanged = true; } // font styles // nothing to do about the color, but reset the font style if (FontStylesChanged.testFlag(SynFontStyle::fsBold)) { mAttributesChanged = true; AddData("\\b0"); } if (FontStylesChanged.testFlag(SynFontStyle::fsItalic)) { mAttributesChanged = true; AddData("\\i0"); } if (FontStylesChanged.testFlag(SynFontStyle::fsUnderline)) { mAttributesChanged = true; AddData("\\ul0"); } if (FontStylesChanged.testFlag(SynFontStyle::fsStrikeOut)) { mAttributesChanged = true; AddData("\\strike0"); } if (mAttributesChanged) { AddData(" "); mAttributesChanged = false; } } void SynRTFExporter::FormatAfterLastAttribute() { // no need to reset the font style here... } void SynRTFExporter::FormatBeforeFirstAttribute(bool BackgroundChanged, bool ForegroundChanged, SynFontStyles FontStylesChanged) { FormatAttributeInit(BackgroundChanged, ForegroundChanged, FontStylesChanged); } void SynRTFExporter::FormatNewLine() { AddNewLine(); AddData("\\par "); } QString SynRTFExporter::GetFooter() { return "}"; } QString SynRTFExporter::GetFormatName() { return "RTF"; } QString SynRTFExporter::GetHeader() { QString Result = "{\\rtf1\\ansi\\deff0\\deftab720" + GetFontTable(); // all the colors Result = Result + "{\\colortbl"; for (int i = 0; i