WPS8.h
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
00002 /* libwpd
00003  * Copyright (C) 2006, 2007 Andrew Ziem
00004  * Copyright (C) 2003-2005 William Lachance (william.lachance@sympatico.ca)
00005  * Copyright (C) 2003 Marc Maurer (uwog@uwog.net)
00006  *
00007  * This library is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU Library General Public
00009  * License as published by the Free Software Foundation; either
00010  * version 2 of the License, or (at your option) any later version.
00011  *
00012  * This library is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015  * Library General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU Library General Public
00018  * License along with this library; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
00020  *
00021  */
00022 
00023 #ifndef WPS8_H
00024 #define WPS8_H
00025 
00026 #include <vector>
00027 #include <map>
00028 #include <libwpd/WPXString.h>
00029 
00030 #include "libwps_internal.h"
00031 #include "WPS.h"
00032 #include "WPSContentListener.h"
00033 #include <libwpd-stream/WPXStream.h>
00034 #include "WPSParser.h"
00035 
00036 typedef WPSContentListener WPS8ContentListener;
00037 
00038 class WPS8Parser : public WPSParser
00039 {
00040 public:
00041         WPS8Parser(WPXInputStreamPtr &input, WPSHeaderPtr &header);
00042         ~WPS8Parser();
00043 
00044         void parse(WPXDocumentInterface *documentInterface);
00045 protected:
00046         struct Zone;
00047         typedef std::multimap<std::string, Zone> IndexMultiMap; /* string is name */
00048         struct Note;
00049         struct Stream;
00050 private:
00051         void readFontsTable(WPXInputStreamPtr &input);
00052         void readStreams(WPXInputStreamPtr &input);
00053         void readNotes(std::vector<Note> &dest, WPXInputStreamPtr &input, const char *key);
00054         void appendUTF16LE(WPXInputStreamPtr &input);
00055         void readTextRange(WPXInputStreamPtr &input, uint32_t startpos, uint32_t endpos, uint16_t stream);
00056         void readNote(WPXInputStreamPtr &input, bool is_endnote);
00057         bool readFODPage(WPXInputStreamPtr &input, std::vector<WPSFOD> &FODs, uint16_t page_size);
00058         void parseHeaderIndexEntry(WPXInputStreamPtr &input);
00059         void parseHeaderIndex(WPXInputStreamPtr &input);
00060         void parsePages(std::vector<WPSPageSpan> &pageList, WPXInputStreamPtr &input);
00061         void parse(WPXInputStreamPtr &stream);
00062         void propertyChangeDelta(uint32_t newTextAttributeBits);
00063         void propertyChange(std::string rgchProp, uint16_t &specialCode);
00064         void propertyChangePara(std::string rgchProp);
00066         shared_ptr<WPS8ContentListener> m_listener;
00067         uint32_t m_offset_eot; /* stream offset to end of text */
00068         uint32_t m_oldTextAttributeBits;
00069         IndexMultiMap m_headerIndexTable;
00070         std::vector<WPSFOD> m_CHFODs; /* CHaracter FOrmatting Descriptors */
00071         std::vector<WPSFOD> m_PAFODs; /* PAragraph FOrmatting Descriptors */
00072         std::vector<std::string> m_fontNames;
00073         std::vector<Stream> m_streams;
00074         std::vector<Note> m_footnotes;
00075         int m_actualFootnote;
00076         std::vector<Note> m_endnotes;
00077         int m_actualEndnote;
00078 
00079 protected:
00082         struct Zone
00083         {
00084                 Zone() : m_offset(0), m_length(0) {}
00085                 virtual ~Zone() {}
00086                 uint32_t const &begin() const
00087                 {
00088                         return m_offset;
00089                 }
00090                 uint32_t end() const
00091                 {
00092                         return m_offset+m_length;
00093                 }
00094                 uint32_t const &length() const
00095                 {
00096                         return m_length;
00097                 }
00098                 void setBegin(uint32_t pos)
00099                 {
00100                         m_offset = pos;
00101                 }
00102                 void setLength(uint32_t _length)
00103                 {
00104                         m_length = _length;
00105                 }
00106                 void setEnd(uint32_t _end)
00107                 {
00108                         m_length = _end-m_offset;
00109                 }
00110 
00111                 bool valid() const
00112                 {
00113                         return m_offset && m_length;
00114                 }
00115         protected:
00116                 uint32_t m_offset;
00117                 uint32_t m_length;
00118         };
00119 
00120         struct Note : public Zone
00121         {
00122                 Note() : Zone(), m_textOffset(0) {}
00123                 uint32_t m_textOffset;
00124         };
00125 
00126         struct Stream : public Zone
00127         {
00128                 Stream() : Zone(), m_type(Z_Dummy) {}
00129 
00130                 enum Type {Z_Dummy=0, Z_Body=1, Z_Footnotes=2, Z_Endnotes = 3}  m_type;
00131         };
00132 };
00133 
00134 
00135 #endif /* WPS8_H */
00136 /* vim:set shiftwidth=4 softtabstop=4 noexpandtab: */