2 * Copyright (C) 2004-2008 Geometer Plus <contact@geometerplus.com>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program 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 General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
20 #ifndef __RTFREADER_H__
21 #define __RTFREADER_H__
27 #include <ZLEncodingConverter.h>
29 #include <ZLTextAlignmentType.h>
31 #include "../EncodedTextReader.h"
36 class RtfReader
: public EncodedTextReader
{
39 static void fillKeywordMap();
40 static void addAction(const std::string
&tag
, RtfCommand
*command
);
43 static std::map
<std::string
, RtfCommand
*> ourKeywordMap
;
46 RtfReader(const std::string
&encoding
);
50 virtual bool readDocument(const std::string
&fileName
);
53 enum DestinationType
{
60 DESTINATION_STYLESHEET
,
70 virtual void addCharData(const char *data
, size_t len
, bool convert
) = 0;
71 virtual void insertImage(const std::string
&mimeType
, const std::string
&fileName
, size_t startOffset
, size_t size
) = 0;
72 virtual void setEncoding(int code
) = 0;
73 virtual void switchDestination(DestinationType destination
, bool on
) = 0;
74 virtual void setAlignment() = 0;
75 virtual void setFontProperty(FontProperty property
) = 0;
76 virtual void newParagraph() = 0;
82 void processKeyword(const std::string
&keyword
, int *parameter
= 0);
83 void processCharData(const char *data
, size_t len
, bool convert
= true);
86 struct RtfReaderState
{
90 ZLTextAlignmentType Alignment
;
91 DestinationType Destination
;
96 RtfReaderState myState
;
101 std::string myFileName
;
102 shared_ptr
<ZLInputStream
> myStream
;
103 char *myStreamBuffer
;
105 std::stack
<RtfReaderState
> myStateStack
;
107 int myBinaryDataSize
;
108 std::string myNextImageMimeType
;
112 friend class RtfNewParagraphCommand
;
113 friend class RtfFontPropertyCommand
;
114 friend class RtfAlignmentCommand
;
115 friend class RtfCharCommand
;
116 friend class RtfDestinationCommand
;
117 friend class RtfStyleCommand
;
118 friend class RtfSpecialCommand
;
119 friend class RtfPictureCommand
;
120 friend class RtfFontResetCommand
;
121 friend class RtfCodepageCommand
;
126 virtual ~RtfCommand();
129 virtual void run(RtfReader
&reader
, int *parameter
) const = 0;
132 class RtfNewParagraphCommand
: public RtfCommand
{
134 void run(RtfReader
&reader
, int *parameter
) const;
137 class RtfFontPropertyCommand
: public RtfCommand
{
140 RtfFontPropertyCommand(RtfReader::FontProperty property
);
141 void run(RtfReader
&reader
, int *parameter
) const;
144 RtfReader::FontProperty myProperty
;
147 class RtfAlignmentCommand
: public RtfCommand
{
149 RtfAlignmentCommand(ZLTextAlignmentType alignment
);
150 void run(RtfReader
&reader
, int *parameter
) const;
153 ZLTextAlignmentType myAlignment
;
156 class RtfCharCommand
: public RtfCommand
{
158 RtfCharCommand(const std::string
&chr
);
159 void run(RtfReader
&reader
, int *parameter
) const;
165 class RtfDestinationCommand
: public RtfCommand
{
167 RtfDestinationCommand(RtfReader::DestinationType dest
);
168 void run(RtfReader
&reader
, int *parameter
) const;
171 RtfReader::DestinationType myDestination
;
174 class RtfStyleCommand
: public RtfCommand
{
176 void run(RtfReader
&reader
, int *parameter
) const;
179 class RtfSpecialCommand
: public RtfCommand
{
180 void run(RtfReader
&reader
, int *parameter
) const;
183 class RtfPictureCommand
: public RtfCommand
{
185 RtfPictureCommand(const std::string
&mimeType
);
186 void run(RtfReader
&reader
, int *parameter
) const;
189 const std::string myMimeType
;
192 class RtfFontResetCommand
: public RtfCommand
{
194 void run(RtfReader
&reader
, int *parameter
) const;
197 class RtfCodepageCommand
: public RtfCommand
{
199 void run(RtfReader
&reader
, int *parameter
) const;
202 #endif /* __RTFREADER_H__ */