gui
[lbook_fbreader.git] / fbreader / src / formats / rtf / RtfDescriptionReader.cpp
blob0fed62ef51a435de782595188b6feba4ffa46410
1 /*
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
17 * 02110-1301, USA.
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);
31 if (!info.isNull()) {
32 myConverter = info->createConverter();
33 myDescription.encoding() = info->name();
34 } else {
35 myConverter = collection.defaultConverter();
39 bool RtfDescriptionReader::readDocument(const std::string &fileName) {
40 myDoRead = false;
41 bool code = RtfReader::readDocument(fileName);
42 if (myDescription.encoding().empty()) {
43 myDescription.encoding() = PluginCollection::instance().DefaultEncodingOption.value();
45 return code;
48 void RtfDescriptionReader::addCharData(const char *data, size_t len, bool convert) {
49 if (myDoRead) {
50 if (convert) {
51 myConverter->convert(myBuffer, data, data + len);
52 } else {
53 myBuffer.append(data, len);
58 void RtfDescriptionReader::switchDestination(DestinationType destination, bool on) {
59 switch (destination) {
60 case DESTINATION_INFO:
61 if (!on) {
62 interrupt();
64 break;
65 case DESTINATION_TITLE:
66 myDoRead = on;
67 if (!on) {
68 myDescription.title() = myBuffer;
69 myBuffer.erase();
71 break;
72 case DESTINATION_AUTHOR:
73 myDoRead = on;
74 if (!on) {
75 myDescription.addAuthor(myBuffer);
76 myBuffer.erase();
78 break;
79 default:
80 break;
82 if (!myDescription.title().empty() &&
83 (myDescription.author() != 0) &&
84 !myDescription.encoding().empty()) {
85 interrupt();
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() {