1 /* 2 * Copyright (C) 2004-2010 Geometer Plus <contact@geometerplus.com> 3 * 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. 8 * 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. 13 * 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. 18 */ 19 20 /* 21 * Information about Palm Markup Language was taken from next sources: 22 * http://www.m.ereader.com/ereader/help/dropbook/pml.htm 23 * http://ccit205.wikispaces.com/Palm+Markup+Language+(PML) 24 */ 25 26 #ifndef __PMLREADER_H__ 27 #define __PMLREADER_H__ 28 29 #include <string> 30 31 #include <ZLEncodingConverter.h> 32 #include <ZLTextAlignmentType.h> 33 34 #include "../EncodedTextReader.h" 35 #include "../../bookmodel/FBTextKind.h" 36 37 class ZLInputStream; 38 39 class PmlReader : public EncodedTextReader { 40 41 public: 42 virtual bool readDocument(ZLInputStream &stream); 43 44 protected: 45 PmlReader(const std::string &encoding); 46 virtual ~PmlReader(); 47 48 protected: 49 enum FontProperty { 50 FONT_BOLD, 51 FONT_ITALIC, 52 FONT_UNDERLINED, 53 FONT_SUBSCRIPT, 54 FONT_SUPERSCRIPT 55 }; 56 57 enum FontSizeType { 58 NORMAL, 59 SMALLER, 60 LARGER 61 }; 62 63 64 virtual void addCharData(const char *data, size_t len, bool convert) = 0; 65 virtual void addLink(FBTextKind kind, const std::string &id, bool on) = 0; 66 virtual void addLinkLabel(const std::string &label) = 0; 67 virtual void addImageReference(const std::string &id) = 0; 68 virtual void setFontSize() = 0; 69 virtual void switchFontProperty(FontProperty property) = 0; 70 virtual void newLine() = 0; 71 virtual void newPage() = 0; 72 virtual void newParagraph() = 0; 73 74 void interrupt(); 75 76 private: 77 bool parseDocument(ZLInputStream &stream); 78 void processTag(std::string &tagName, const std::string ¶meter = ourDefaultParameter); 79 void processCharData(const char* data, size_t len, bool convert = true); 80 void processFontProperty(FontProperty property); 81 void processAlignment(ZLTextAlignmentType alignment); 82 void processFontSize(FontSizeType sizeType); 83 void processIndent(const std::string ¶meter =ourDefaultParameter); 84 void processLink(FBTextKind kind, const std::string ¶meter); 85 86 static size_t findTagLength(const char* ptr); 87 88 protected: 89 struct PmlReaderState { 90 bool Bold; 91 bool Italic; 92 bool Underlined; 93 bool SmallCaps; 94 bool Subscript; 95 bool Superscript; 96 97 ZLTextAlignmentType Alignment; 98 FontSizeType FontSize; 99 100 unsigned short Indent; 101 bool IndentBlockOn; 102 bool BoldBlockOn; 103 bool FootnoteLinkOn; 104 bool InternalLinkOn; 105 bool InvisibleText; 106 }; 107 108 PmlReaderState myState; 109 110 private: 111 char* myStreamBuffer; 112 113 bool myIsInterrupted; 114 const static std::string ourDefaultParameter; 115 }; 116 117 #endif /* __PMLREADER_H__ */ 118