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 #include <ZLInputStream.h>
22 #include "RtfDescriptionReader.h"
23 #include "../FormatPlugin.h"
25 RtfDescriptionReader::RtfDescriptionReader(BookDescription
&description
) : RtfReader(description
.encoding()), myDescription(description
) {
28 void RtfDescriptionReader::setEncoding(int code
) {
29 ZLEncodingCollection
&collection
= ZLEncodingCollection::instance();
30 ZLEncodingConverterInfoPtr info
= collection
.info(code
);
32 myConverter
= info
->createConverter();
33 myDescription
.encoding() = info
->name();
35 myConverter
= collection
.defaultConverter();
39 bool RtfDescriptionReader::readDocument(const std::string
&fileName
) {
41 bool code
= RtfReader::readDocument(fileName
);
42 if (myDescription
.encoding().empty()) {
43 myDescription
.encoding() = PluginCollection::instance().DefaultEncodingOption
.value();
48 void RtfDescriptionReader::addCharData(const char *data
, size_t len
, bool convert
) {
51 myConverter
->convert(myBuffer
, data
, data
+ len
);
53 myBuffer
.append(data
, len
);
58 void RtfDescriptionReader::switchDestination(DestinationType destination
, bool on
) {
59 switch (destination
) {
60 case DESTINATION_INFO
:
65 case DESTINATION_TITLE
:
68 myDescription
.title() = myBuffer
;
72 case DESTINATION_AUTHOR
:
75 myDescription
.addAuthor(myBuffer
);
82 if (!myDescription
.title().empty() &&
83 (myDescription
.author() != 0) &&
84 !myDescription
.encoding().empty()) {
89 void RtfDescriptionReader::insertImage(const std::string
&, const std::string
&, size_t, size_t) {
92 void RtfDescriptionReader::setFontProperty(FontProperty
) {
95 void RtfDescriptionReader::newParagraph() {
98 void RtfDescriptionReader::setAlignment() {