2 rtf2html.h - A simple RTF Parser
4 Copyright (c) 2002 by Vladimir Shutoff <vovan@shutoff.ru> (original code)
5 Copyright (c) 2004 by Thiago S. Barcelos <barcelos@ime.usp.br> (Kopete port)
6 Kopete (c) 2002-2003 by the Kopete developers <kopete-devel@kde.org>
8 *************************************************************************
10 * This program is free software; you can redistribute it and/or modify *
11 * it under the terms of the GNU General Public License as published by *
12 * the Free Software Foundation; either version 2 of the License, or *
13 * (at your option) any later version. *
15 *************************************************************************
24 #include <qtextcodec.h>
60 ParStyle() { dir
= DirLTR
; }
61 void clearFormatting();
64 enum {DirLTR
, DirRTL
} dir
;
72 void setText(const char* str
);
73 void setFontTbl() { m_bFontTbl
= true; }
74 void setColors() { m_bColors
= true; resetColors(); }
75 void setRed(unsigned char val
) { setColor(val
, &m_nRed
); }
76 void setGreen(unsigned char val
) { setColor(val
, &m_nGreen
); }
77 void setBlue(unsigned char val
) { setColor(val
, &m_nBlue
); }
78 void setFont(unsigned nFont
);
79 void setEncoding(unsigned nFont
);
81 void setFontColor(unsigned short color
);
82 void setFontBgColor(unsigned short color
);
83 void setFontSizeHalfPoints(unsigned short sizeInHalfPoints
);
84 void setFontSize(unsigned short sizeInPoints
);
87 void setUnderline(bool);
88 void startParagraph();
89 bool isParagraphOpen() const;
90 void clearParagraphFormatting();
91 void setParagraphDirLTR();
92 void setParagraphDirRTL();
96 void resetTag(TagEnum tag
);
101 void resetColors() { m_nRed
= m_nGreen
= m_nBlue
= 0; m_bColorInit
= false; }
102 void setColor(unsigned char val
, unsigned char *p
)
103 { *p
= val
; m_bColorInit
=true; }
105 // Marks the position in m_tags where this level begun.
106 unsigned m_nTagsStartPos
;
108 // True when parsing the fonts table
110 // True when parsing the colors table.
112 // True when inside a 'fname' block.
114 // False until we get the tagged font name.
115 bool m_bTaggedFontNameOk
;
117 unsigned char m_nRed
;
118 unsigned char m_nGreen
;
119 unsigned char m_nBlue
;
121 unsigned m_nFont
; // 1-based
122 unsigned m_nEncoding
;
123 unsigned m_nFontColor
; // 1-based
124 unsigned m_nFontSize
;
125 unsigned m_nFontBgColor
; // 1-based
134 OutTag(TagEnum _tag
, unsigned _param
) : tag(_tag
), param(_param
) {}
152 QString
Parse(const char *rtf
, const char *encoding
);
154 // Paragraph-specific functions:
156 QString
quoteString(const QString
&_str
, quoteMode mode
= quoteHTML
);
157 // Appends a string with formatting into the paragraph buffer.
158 void PrintUnquoted(const char *str
, ...);
159 // Quotes and appends a string to the paragraph buffer.
160 void PrintQuoted(const QString
&str
);
161 // Writes down the tags from oTags into the paragraph buffer.
163 // Retrieves the top not-yet-written tag.
164 OutTag
* getTopOutTag(TagEnum tagType
);
165 // Writes down the paragraph buffer and resets the paragraph state.
166 void FlushParagraph();
168 // Document-wide functions:
170 void PutTag(TagEnum n
)
179 // True if the paragraph was opened explicitly.
180 bool bExplicitParagraph
;
181 // The paragraph's HTML buffer.
183 // Defines the paragraph's formatting.
185 // Tags which weren't yet printed out.
186 vector
<OutTag
> oTags
;
190 // The document HTML buffer.
193 vector
<FontDef
> fonts
;
195 vector
<QColor
> colors
;
196 // Stack of tags (across all levels, not just current level)
199 // RTF parser internals
202 const char *encoding
;