1 /*
2     Copyright (C)  2010  Brad Hards <bradh@frogmouth.net>
3 
4     This library is free software: you can redistribute it and/or modify
5     it under the terms of the GNU Lesser General Public License as published by
6     the Free Software Foundation, either version 2.1 of the License, or
7     (at your option) any later version.
8 
9     This library is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     GNU Lesser General Public License for more details.
13 
14     You should have received a copy of the GNU Lesser General Public License
15     along with this program.  If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #ifndef RTFREADER_TEXTDOCUMENTRTFOUTPUT_H
19 #define RTFREADER_TEXTDOCUMENTRTFOUTPUT_H
20 
21 #include "AbstractRtfOutput.h"
22 
23 class QImage;
24 class QTextCursor;
25 class QTextDocument;
26 class QTextImageFormat;
27 
28 #include <QStack>
29 #include <QTextCharFormat>
30 #include "rtfreader_export.h"
31 namespace RtfReader
32 {
33     class Reader;
34 
35     class RTFREADER_EXPORT TextDocumentRtfOutput: public AbstractRtfOutput
36     {
37       public:
38 	explicit TextDocumentRtfOutput( QTextDocument *document );
39 
40 	~TextDocumentRtfOutput() override;
41 
42 	void startGroup() override;
43 
44 	void endGroup() override;
45 
46 	void appendText( const QByteArray &text ) override;
47 	void appendText( const QString &text ) override;
48 
49 	void insertPar() override;
50 
51 	void insertTab() override;
52 
53 	void insertLeftQuote() override;
54 	void insertRightQuote() override;
55 	void insertLeftDoubleQuote() override;
56 	void insertRightDoubleQuote() override;
57 
58 	void insertEnDash() override;
59 	void insertEmDash() override;
60 
61 	void insertEnSpace() override;
62 	void insertEmSpace() override;
63 
64 	void insertBullet() override;
65 
66 	void setFontItalic( const int value ) override;
67 
68 	void setFontBold( const int value ) override;
69 
70 	void setFontUnderline( const int value ) override;
71 
72 	void setFontStrikeout( const bool value ) override;
73 
74 	void setFontPointSize( const int pointSize ) override;
75 
76 	void setForegroundColour( const int colourIndex ) override;
77 	void setHighlightColour( const int colourIndex ) override;
78 	void setParagraphPatternBackgroundColour( const int colourIndex ) override;
79 
80 	void setFont( const int fontIndex ) override;
81 
82 	void setDefaultFont( const int fontIndex ) override;
83 
84 	void setFontSuperscript() override;
85 	void setFontSubscript() override;
86 
87 	void setTextDirectionLeftToRight() override;
88 	void setTextDirectionRightToLeft() override;
89 
90 	void appendToColourTable( const QColor &colour ) override;
91 
92 	void insertFontTableEntry( FontTableEntry fontTableEntry, quint32 fontTableIndex ) override;
93 	void insertStyleSheetTableEntry( quint32 stylesheetTableIndex, StyleSheetTableEntry stylesheetTableEntry ) override;
94 
95 	void resetParagraphFormat() override;
96 	void resetCharacterProperties() override;
97 
98 	void setParagraphAlignmentLeft() override;
99 	void setParagraphAlignmentCentred() override;
100 	void setParagraphAlignmentJustified() override;
101 	void setParagraphAlignmentRight() override;
102 
103 	void setFirstLineIndent( const int twips ) override;
104 	void setLeftIndent( const int twips ) override;
105 	void setRightIndent( const int twips ) override;
106 
107 	void createImage( const QByteArray &data, const QTextImageFormat &format ) override;
108 
109 	void setPageHeight( const int pageHeight ) override;
110 	void setPageWidth( const int pageWidth ) override;
111 
112 	void setSpaceBefore( const int twips ) override;
113 	void setSpaceAfter( const int twips ) override;
114 
115       protected:
116 	// The text cursor on the document being generated
117 	QTextCursor *m_cursor;
118 
119 	QStack<QTextCharFormat> m_textCharFormatStack;
120 
121 	QTextBlockFormat m_paragraphFormat;
122 
123 	QList<QColor> m_colourTable;
124 
125 	QHash<int, FontTableEntry> m_fontTable;
126 	int m_defaultFontIndex;
127 	bool m_haveSetFont;
128 
129 	QHash<int, StyleSheetTableEntry> m_stylesheetTable;
130 
131 	QTextDocument *m_document;
132 	QTextCodec *m_codec = nullptr;
133 
134 	/**
135 	  Convenience routine to convert a size in twips into pixels
136 	*/
137 	qreal pixelsFromTwips( const int twips );
138 
139       };
140 }
141 
142 #endif
143