PocketWord.h Source File documentation

PocketWord.h
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
2 /* libwps
3 * Version: MPL 2.0 / LGPLv2.1+
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 *
9 * Major Contributor(s):
10 * Copyright (C) 2020 Laurent Alonso (alonso.laurent@gmail.com)
11 *
12 * For minor contributions see the git repository.
13 *
14 * Alternatively, the contents of this file may be used under the terms
15 * of the GNU Lesser General Public License Version 2.1 or later
16 * (LGPLv2.1+), in which case the provisions of the LGPLv2.1+ are
17 * applicable instead of those above.
18 *
19 * For further information visit http://libwps.sourceforge.net
20 */
21
22 #ifndef POCKET_WORD_H
23 #define POCKET_WORD_H
24
25 #include <memory>
26 #include <vector>
27
28 #include <librevenge-stream/librevenge-stream.h>
29 #include "libwps_internal.h"
30 #include "libwps_tools_win.h"
31
32 #include "WPSParser.h"
33
34 namespace PocketWordParserInternal
35 {
36 class SubDocument;
37
38 struct State;
39 }
40
45 class PocketWordParser : public WPSParser
46 {
47 friend class PocketWordParserInternal::SubDocument;
48
49 public:
51 PocketWordParser(RVNGInputStreamPtr &input, WPSHeaderPtr &header,
52 libwps_tools_win::Font::Type encoding=libwps_tools_win::Font::UNKNOWN);
54 ~PocketWordParser() override;
56 void parse(librevenge::RVNGTextInterface *documentInterface) override;
58 bool checkHeader(WPSHeader *header, bool strict=false);
59
60 private:
61 PocketWordParser(const PocketWordParser &) = delete;
62 PocketWordParser &operator=(const PocketWordParser &) = delete;
63
65 std::shared_ptr<WPSContentListener> createListener(librevenge::RVNGTextInterface *interface);
66
67 protected:
69 bool createZones();
71 bool readFontNames(WPSEntry const &entry);
73 bool readPageDims(WPSEntry const &entry);
75 bool readParagraphList(WPSEntry const &entry, std::vector<int> &paraId);
77 bool readParagraphDims(WPSEntry const &entry);
79 bool readParagraphUnkn(WPSEntry const &entry);
81 bool readSound(WPSEntry const &entry, WPSEmbeddedObject &object);
83 bool readSoundData(WPSEntry const &entry, long pictSize, WPSEmbeddedObject &object);
85 bool readUnkn8(WPSEntry const &entry);
87 bool readUnkn2021(WPSEntry const &entry, int type);
89 bool checkFilePosition(long pos) const;
91 void checkUnparsed();
92
94 void sendData();
96 bool sendParagraph(size_t paraId);
97
98 // State
99
101 std::shared_ptr<WPSContentListener> m_listener;
103 std::shared_ptr<PocketWordParserInternal::State> m_state;
104 };
105
106 #endif /* POCKET_WORD_H */
107 /* vim:set shiftwidth=4 softtabstop=4 noexpandtab: */
PocketWordParser::m_state
std::shared_ptr< PocketWordParserInternal::State > m_state
the main state
Definition: PocketWord.h:103
WPSTextSubDocument.h
PocketWordParserInternal::State::m_version
int m_version
the file version
Definition: PocketWord.cpp:102
PocketWordParser::readParagraphUnkn
bool readParagraphUnkn(WPSEntry const &entry)
try to read a paragraph unknown zone: tabs, link?
Definition: PocketWord.cpp:902
PocketWordParser::readUnkn8
bool readUnkn8(WPSEntry const &entry)
try to read the unknown zone 8: one by file, maybe prefs
Definition: PocketWord.cpp:1158
WPSParagraph.h
PocketWordParserInternal::State::getEntry
WPSEntry getEntry(int id, int &type) const
returns an entry corresponding to a file identificator
Definition: PocketWord.cpp:70
PocketWordParser::m_listener
std::shared_ptr< WPSContentListener > m_listener
the listener (if set)
Definition: PocketWord.h:101
WPSParagraph::m_justify
libwps::Justification m_justify
the justification
Definition: WPSParagraph.h:116
WPS_STRIKEOUT_BIT
#define WPS_STRIKEOUT_BIT
Definition: libwps_internal.h:507
WPSParagraph::m_listLevelIndex
int m_listLevelIndex
the actual level index
Definition: WPSParagraph.h:121
libwps::DebugStream::str
static std::string str()
Definition: WPSDebug.h:200
libwps::DebugFile::open
static bool open(std::string const &)
Definition: WPSDebug.h:215
PocketWordParserInternal::State::m_pageSpan
WPSPageSpan m_pageSpan
the page span
Definition: PocketWord.cpp:116
WPS_BOLD_BIT
#define WPS_BOLD_BIT
Definition: libwps_internal.h:506
libwps::DebugFile::addPos
static void addPos(long)
Definition: WPSDebug.h:220
WPSEntry::end
long end() const
returns the end offset
Definition: WPSEntry.h:78
libwps::Debug::dumpFile
bool dumpFile(librevenge::RVNGBinaryData &, char const *)
Definition: WPSDebug.h:180
WPSEntry::setLength
void setLength(long l)
sets the zone size
Definition: WPSEntry.h:62
WPSParagraph::m_margins
double m_margins[3]
the margins
Definition: WPSParagraph.h:101
libwps_tools_win::Font::Type
Type
enum Type
Definition: libwps_tools_win.h:46
PocketWordParser::readSound
bool readSound(WPSEntry const &entry, WPSEmbeddedObject &object)
try to read a sound definition (maybe a picture)
Definition: PocketWord.cpp:1009
PocketWordParser::readParagraphDims
bool readParagraphDims(WPSEntry const &entry)
try to read a paragraph dimensions' zone which follows the paragraph zone
Definition: PocketWord.cpp:859
WPS_UNDERLINE_BIT
#define WPS_UNDERLINE_BIT
Definition: libwps_internal.h:508
libwps::BULLET
@ BULLET
Definition: libwps_internal.h:246
libwps::DebugFile::reset
static void reset()
Definition: WPSDebug.h:224
WPSPageSpan::setMarginRight
void setMarginRight(const double marginRight)
Definition: WPSPageSpan.h:134
libwps::DebugFile::skipZone
static void skipZone(long, long)
Definition: WPSDebug.h:226
PocketWordParser::~PocketWordParser
~PocketWordParser() override
destructor
Definition: PocketWord.cpp:132
WPSHeader.h
WPS_REVERSEVIDEO_BIT
#define WPS_REVERSEVIDEO_BIT
Definition: libwps_internal.h:511
PocketWordParser::PocketWordParser
PocketWordParser(const PocketWordParser &)=delete
WPSFont
define the font properties
Definition: WPSFont.h:37
WPSPosition::Char
@ Char
Definition: WPSPosition.h:43
WPSEntry::valid
bool valid(bool checkId=false) const
returns true if the zone length is positive
Definition: WPSEntry.h:89
WPS_ITALICS_BIT
#define WPS_ITALICS_BIT
Definition: libwps_internal.h:502
PocketWordParser::readSoundData
bool readSoundData(WPSEntry const &entry, long pictSize, WPSEmbeddedObject &object)
try to read a sound data (maybe a picture)
Definition: PocketWord.cpp:1117
PocketWordParserInternal::State::m_idToFontNameMap
std::map< int, librevenge::RVNGString > m_idToFontNameMap
the correspondance between index and font name
Definition: PocketWord.cpp:118
WPSParagraph::m_listLevel
ListLevel m_listLevel
the actual level
Definition: WPSParagraph.h:123
WPSEntry
basic class to store an entry in a file This contained :
Definition: WPSEntry.h:39
WPSHeader::setMajorVersion
void setMajorVersion(int version)
Definition: WPSHeader.h:94
WPSParser
Definition: WPSParser.h:36
WPSPageSpan.h
WPSEntry::setId
void setId(int i)
sets the id
Definition: WPSEntry.h:163
PocketWordParser::createListener
std::shared_ptr< WPSContentListener > createListener(librevenge::RVNGTextInterface *interface)
creates the main listener
Definition: PocketWord.cpp:150
WPSList::Level::m_type
libwps::NumberingType m_type
the type of the level
Definition: WPSList.h:98
PocketWordParser::parse
void parse(librevenge::RVNGTextInterface *documentInterface) override
called by WPSDocument to parse the file
Definition: PocketWord.cpp:181
Vec2f
Vec2< float > Vec2f
Vec2 of float.
Definition: libwps_internal.h:704
WPSPosition::setRelativePosition
void setRelativePosition(AnchorTo anchor, XPos X=XLeft, YPos Y=YTop)
sets the relative position
Definition: WPSPosition.h:214
WPSHeader::setNeedEncoding
void setNeedEncoding(bool needEncoding)
Definition: WPSHeader.h:84
libwps::ParseException
Definition: libwps_internal.h:152
WPS_DEBUG_MSG
#define WPS_DEBUG_MSG(M)
Definition: libwps_internal.h:134
libwps::readU32
uint32_t readU32(librevenge::RVNGInputStream *input)
Definition: libwps_internal.cpp:76
WPSFont::m_color
WPSColor m_color
the font color
Definition: WPSFont.h:91
libwps_tools_win::Font::unicode
static unsigned long unicode(unsigned char c, Type type)
converts a character in unicode, knowing the character and the font type
Definition: libwps_tools_win.cpp:7160
WPSParagraph
class to store the paragraph properties
Definition: WPSParagraph.h:58
WPSEntry::setBegin
void setBegin(long off)
sets the begin offset
Definition: WPSEntry.h:57
WPSContentListener.h
WPSHeader
Definition: WPSHeader.h:32
libwps_tools_win::Font::UNKNOWN
@ UNKNOWN
Definition: libwps_tools_win.h:63
libwps::appendUnicode
void appendUnicode(uint32_t val, librevenge::RVNGString &buffer)
adds an unicode character to a string ( with correct encoding ).
Definition: libwps_internal.cpp:836
PocketWordParser::sendParagraph
bool sendParagraph(size_t paraId)
try to read and send a paragraph
Definition: PocketWord.cpp:535
WPSFont.h
PocketWordParser::checkFilePosition
bool checkFilePosition(long pos) const
check if the file position is correct or not
Definition: PocketWord.cpp:136
PocketWordParser::checkUnparsed
void checkUnparsed()
try to parse the unparsed zones
Definition: PocketWord.cpp:278
WPSEntry.h
WPSFont::m_attributes
uint32_t m_attributes
the font attributes defined as a set of bits
Definition: WPSFont.h:87
PocketWordParser::readFontNames
bool readFontNames(WPSEntry const &entry)
try to read the font names
Definition: PocketWord.cpp:347
PocketWordParserInternal::State::m_encoding
libwps_tools_win::Font::Type m_encoding
the file encoding
Definition: PocketWord.cpp:104
PocketWordParserInternal::State
the state of PocketWord
Definition: PocketWord.cpp:51
libwps::DebugFile::addNote
static void addNote(char const *)
Definition: WPSDebug.h:221
WPSParser::getInput
RVNGInputStreamPtr & getInput()
Definition: WPSParser.h:47
PocketWordParserInternal::State::m_idToEntryMap
std::map< int, size_t > m_idToEntryMap
the file id to (type, entry) index
Definition: PocketWord.cpp:111
WPSEntry::begin
long begin() const
returns the begin offset
Definition: WPSEntry.h:73
WPSFont::m_size
double m_size
font size
Definition: WPSFont.h:85
PocketWordParser::readPageDims
bool readPageDims(WPSEntry const &entry)
try to read the page dimension
Definition: PocketWord.cpp:436
WPSEmbeddedObject
small class use to define a embedded object
Definition: libwps_internal.h:1077
WPSEntry::id
int id() const
returns the entry id
Definition: WPSEntry.h:158
WPSPageSpan::setMarginTop
void setMarginTop(const double marginTop)
Definition: WPSPageSpan.h:138
WPSEntry::length
long length() const
returns the length of the zone
Definition: WPSEntry.h:83
WPSHeaderPtr
std::shared_ptr< WPSHeader > WPSHeaderPtr
shared pointer to WPSHeader
Definition: libwps_internal.h:109
PocketWordParserInternal::State::m_badFile
bool m_badFile
some file does not respect the unique indice conditions, ...
Definition: PocketWord.cpp:106
libwps::DebugStream
Definition: WPSDebug.h:192
PocketWordParser
This class parses some Pocket Word.
Definition: PocketWord.h:46
libwps::readU8
uint8_t readU8(librevenge::RVNGInputStream *input)
Definition: libwps_internal.cpp:40
PocketWordParserInternal::State::m_eof
long m_eof
the last file position
Definition: PocketWord.cpp:100
WPSPageSpan::setMarginBottom
void setMarginBottom(const double marginBottom)
Definition: WPSPageSpan.h:142
PocketWordParser::checkHeader
bool checkHeader(WPSHeader *header, bool strict=false)
checks if the document header is correct (or not)
Definition: PocketWord.cpp:1238
libwps_tools_win.h
PocketWordParser::createZones
bool createZones()
try to read the different zones
Definition: PocketWord.cpp:221
WPSParser.h
WPSParser::ascii
libwps::DebugFile & ascii()
a DebugFile used to write what we recognize when we parse the document
Definition: WPSParser.h:65
PocketWordParser::readUnkn2021
bool readUnkn2021(WPSEntry const &entry, int type)
try to read the unknown zone 20 and 21: one by file, find always no data, maybe style
Definition: PocketWord.cpp:1199
WPSPageSpan
Definition: WPSPageSpan.h:39
libwps::readData
bool readData(RVNGInputStreamPtr &input, unsigned long size, librevenge::RVNGBinaryData &data)
try to read sz bytes from input and store them in a librevenge::RVNGBinaryData
Definition: libwps_internal.cpp:332
PocketWordParser::SubDocument
friend class PocketWordParserInternal::SubDocument
Definition: PocketWord.h:47
PocketWordParserInternal::State::getColor
bool getColor(int id, WPSColor &col) const
try to retrieve a color
Definition: PocketWord.cpp:85
PocketWordParserInternal::State::m_typeToEntryMap
std::map< int, std::vector< size_t > > m_typeToEntryMap
a type to a list of (type,entry) indices
Definition: PocketWord.cpp:113
libwps::readU16
uint16_t readU16(librevenge::RVNGInputStream *input)
Definition: libwps_internal.cpp:64
WPSList::Level::m_bullet
librevenge::RVNGString m_bullet
the bullet if we have an bullet level
Definition: WPSList.h:101
libwps_tools_win::Language::name
std::string name(long id)
returns the name given Windows© id
Definition: libwps_tools_win.cpp:7332
WPSPosition.h
RVNGInputStreamPtr
std::shared_ptr< librevenge::RVNGInputStream > RVNGInputStreamPtr
shared pointer to librevenge::RVNGInputStream
Definition: libwps_internal.h:87
WPSPosition
Class to define the position of an object (textbox, picture, ..) in the document.
Definition: WPSPosition.h:40
PocketWord.h
WPSDebug.h
libwps::DebugFile::addDelimiter
static void addDelimiter(long, char)
Definition: WPSDebug.h:222
libwps_tools_win::Font::WIN3_WEUROPE
@ WIN3_WEUROPE
Definition: libwps_tools_win.h:52
libwps::read16
int16_t read16(librevenge::RVNGInputStream *input)
Definition: libwps_internal.cpp:71
libwps_internal.h
WPSColor
the class to store a color
Definition: libwps_internal.h:281
WPSList::Level::m_labelIndent
double m_labelIndent
the list indent
Definition: WPSList.h:93
PocketWordParserInternal
Definition: PocketWord.cpp:47
PocketWordParser::PocketWordParser
PocketWordParser(RVNGInputStreamPtr &input, WPSHeaderPtr &header, libwps_tools_win::Font::Type encoding=libwps_tools_win::Font::UNKNOWN)
constructor
Definition: PocketWord.cpp:124
WPSEntry::setParsed
void setParsed(bool ok=true) const
sets the flag m_parsed to true or false
Definition: WPSEntry.h:120
PocketWordParser::readParagraphList
bool readParagraphList(WPSEntry const &entry, std::vector< int > &paraId)
try to read a paragraph list
Definition: PocketWord.cpp:959
libwps::JustificationCenter
@ JustificationCenter
Definition: libwps_internal.h:249
WPSPageSpan::setMarginLeft
void setMarginLeft(const double marginLeft)
Definition: WPSPageSpan.h:130
PocketWordParser::sendData
void sendData()
try to send all the data
Definition: PocketWord.cpp:1290
libwps::JustificationRight
@ JustificationRight
Definition: libwps_internal.h:250
PocketWordParser::operator=
PocketWordParser & operator=(const PocketWordParser &)=delete
WPSFont::m_name
librevenge::RVNGString m_name
font name
Definition: WPSFont.h:83
PocketWordParserInternal::State::m_typeEntryList
std::vector< std::pair< int, WPSEntry > > m_typeEntryList
the list of type, entry
Definition: PocketWord.cpp:109
libwps::DebugFile::setStream
static void setStream(RVNGInputStreamPtr)
Definition: WPSDebug.h:212
PocketWordParserInternal::State::State
State(libwps_tools_win::Font::Type encoding)
constructor
Definition: PocketWord.cpp:53