MSWrite.h Source File documentation

MSWrite.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) 2015 Sean Young <sean@mess.org>
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 MS_WRITE_H
23 #define MS_WRITE_H
24
25 #include <vector>
26
27 #include <librevenge-stream/librevenge-stream.h>
28 #include "libwps_internal.h"
29 #include "libwps_tools_win.h"
30
31 #include "WPSParser.h"
32 #include "WPSEntry.h"
33 #include "WPSFont.h"
34 #include "WPSPageSpan.h"
35 #include "WPSParagraph.h"
36
37 namespace MSWriteParserInternal
38 {
39 class SubDocument;
40
41 struct Paragraph : public WPSParagraph
42 {
43 enum Location { MAIN, HEADER, FOOTER, FOOTNOTE };
44 Paragraph()
45 : WPSParagraph()
46 , m_fcFirst(0)
47 , m_fcLim(0)
48 , m_Location(MAIN)
49 , m_graphics(false)
50 , m_firstpage(false)
51 , m_skiptab(false)
52 , m_headerUseMargin(false)
53 , m_interLine(0.0)
54 , m_HeaderFooterOccurrence(WPSPageSpan::ALL) { }
55 uint32_t m_fcFirst, m_fcLim;
56 Location m_Location;
57 bool m_graphics, m_firstpage, m_skiptab, m_headerUseMargin;
58 double m_interLine;
59 WPSPageSpan::HeaderFooterOccurrence m_HeaderFooterOccurrence;
60 };
61
62 struct Font : public WPSFont
63 {
64 Font()
65 : WPSFont()
66 , m_fcFirst(0)
67 , m_fcLim(0)
68 , m_special(false)
69 , m_footnote(false)
70 , m_annotation(false)
71 , m_encoding(libwps_tools_win::Font::UNKNOWN) { }
72 uint32_t m_fcFirst, m_fcLim;
73 bool m_special, m_footnote, m_annotation;
74 libwps_tools_win::Font::Type m_encoding;
75 };
76
77 struct Footnote
78 {
79 Footnote()
80 : m_fcFtn(0)
81 , m_fcRef(0) { }
82 uint32_t m_fcFtn, m_fcRef;
83 };
84
85 struct Section
86 {
88 Section()
89 : m_fcLim(0)
90 , m_bkc(1)
91 , m_yaMac(11)
92 , m_xaMac(8.5)
93 , m_yaTop(1)
94 , m_dyaText(9)
95 , m_xaLeft(1.25)
96 , m_dxaText(6)
97 , m_startPageNumber(0xffff)
98 , m_yaHeader(0.75)
99 , m_yaFooter(10.25) /* 11-0.75inch*/
100 , m_endFtns(false)
101 , m_columns(1)
102 , m_dxaColumns(0.5)
103 , m_dxaGutter(0.0)
104 , m_Main() { }
105 uint32_t m_fcLim;
106 unsigned m_bkc;
107 double m_yaMac, m_xaMac;
108 double m_yaTop;
109 double m_dyaText;
110 double m_xaLeft;
111 double m_dxaText;
112 uint16_t m_startPageNumber;
113 double m_yaHeader;
114 double m_yaFooter;
115 bool m_endFtns;
116 unsigned m_columns;
117 double m_dxaColumns, m_dxaGutter;
118 WPSEntry m_Main;
119 };
120
121 }
122
127 class MSWriteParser : public WPSParser
128 {
129 friend class MSWriteParserInternal::SubDocument;
130 friend struct MSWriteParserInternal::Paragraph;
131 friend struct MSWriteParserInternal::Font;
132
133 public:
134 MSWriteParser(RVNGInputStreamPtr &input, WPSHeaderPtr &header,
135 libwps_tools_win::Font::Type encoding=libwps_tools_win::Font::WIN3_WEUROPE);
136
137
138 ~MSWriteParser() override;
139 void parse(librevenge::RVNGTextInterface *documentInterface) override;
140
141 private:
142 MSWriteParser(const MSWriteParser &) = delete;
143 MSWriteParser &operator=(const MSWriteParser &) = delete;
144
145 std::shared_ptr<WPSContentListener> createListener(librevenge::RVNGTextInterface *interface);
146 protected:
147 void readStructures();
148 virtual libwps_tools_win::Font::Type getFileEncoding(libwps_tools_win::Font::Type hint);
149 void readFIB();
150 virtual void readFFNTB();
151 void readFOD(unsigned page, void (MSWriteParser::*parseFOD)(uint32_t fcFirst, uint32_t fcLim, unsigned size));
152 virtual void readPAP(uint32_t fcFirst, uint32_t fcLim, unsigned cch);
153 virtual void readCHP(uint32_t fcFirst, uint32_t fcLim, unsigned cch);
154 virtual void readSUMD();
155 virtual void readFNTB();
156 virtual void readSED();
157 void readText(WPSEntry const &e, MSWriteParserInternal::Paragraph::Location location);
158 int numPages();
159 void processObject(WPSPosition &pos, unsigned long lastPos);
160 bool processDDB(librevenge::RVNGBinaryData &bmpdata, WPSPosition &pos, unsigned width, unsigned height, unsigned byte_width, unsigned planes, unsigned bits_pixel, unsigned size);
161 bool processDIB(librevenge::RVNGBinaryData &bmpdata, unsigned size);
162 bool processWMF(librevenge::RVNGBinaryData &wmfdata, unsigned size);
163 void processEmbeddedOLE(WPSPosition &pos, unsigned long lastPos);
164 bool processStaticOLE(librevenge::RVNGBinaryData &, std::string &mimetype, WPSPosition &pos, unsigned long lastPos);
165 bool readString(std::string &res, unsigned long lastPos);
166 virtual void insertSpecial(uint8_t val, uint32_t fc, MSWriteParserInternal::Paragraph::Location location);
167 virtual void insertControl(uint8_t val, uint32_t fc);
168 void insertNote(bool annotation, uint32_t fcPos, librevenge::RVNGString &label);
169 unsigned insertString(const unsigned char *str, unsigned size, libwps_tools_win::Font::Type type);
170 static void getPageStyle(MSWriteParserInternal::Section &sep, WPSPageSpan &pageSpan);
171 void getHeaderFooters(uint32_t first, MSWriteParserInternal::Section &sep, WPSPageSpan &pageSpan);
172 void startSection(MSWriteParserInternal::Section &section);
173
175 bool checkFilePosition(uint32_t pos) const
176 {
177 return pos<=m_fileLength;
178 }
179 // State
181 uint32_t m_fileLength;
182 uint32_t m_fcMac;
183
184 std::vector<MSWriteParserInternal::Paragraph> m_paragraphList;
185 std::vector<MSWriteParserInternal::Font> m_fontList;
186 std::vector<MSWriteParserInternal::Footnote> m_footnotes;
187 std::vector<MSWriteParserInternal::Section> m_sections;
188 std::vector<librevenge::RVNGString> m_fonts;
189 libwps_tools_win::Font::Type m_fontType;
190
191 std::shared_ptr<WPSContentListener> m_listener; /* the listener (if set)*/
192
193 librevenge::RVNGPropertyList m_metaData;
194 };
195
196 #endif /* MS_WRITE_H */
197 /* vim:set shiftwidth=4 softtabstop=4 noexpandtab: */
MSWriteParserInternal::Font::m_special
bool m_special
Definition: MSWrite.h:73
MSWriteParser::m_fontList
std::vector< MSWriteParserInternal::Font > m_fontList
Definition: MSWrite.h:185
MSWriteParser::startSection
void startSection(MSWriteParserInternal::Section &section)
Definition: MSWrite.cpp:1751
MSWriteParserInternal::Section::m_bkc
unsigned m_bkc
Definition: MSWrite.h:106
MSWriteParserInternal
Definition: MSWrite.cpp:38
WPSParagraph
class to store the paragraph properties
Definition: WPSParagraph.h:57
MSWriteParserInternal::Section::m_dxaText
double m_dxaText
Definition: MSWrite.h:111
MSWriteParserInternal::Paragraph::HEADER
Definition: MSWrite.h:43
MSWriteParserInternal::Footnote::Footnote
Footnote()
Definition: MSWrite.h:79
MSWriteParser::readString
bool readString(std::string &res, unsigned long lastPos)
Definition: MSWrite.cpp:1142
MSWriteParserInternal::Section::m_xaLeft
double m_xaLeft
Definition: MSWrite.h:110
MSWriteParserInternal::Section::m_dyaText
double m_dyaText
Definition: MSWrite.h:109
MSWriteParserInternal::Section::m_fcLim
uint32_t m_fcLim
Definition: MSWrite.h:105
MSWriteParser::insertNote
void insertNote(bool annotation, uint32_t fcPos, librevenge::RVNGString &label)
Definition: MSWrite.cpp:1714
MSWriteParser::readSED
virtual void readSED()
Definition: MSWrite.cpp:445
MSWriteParser::numPages
int numPages()
MSWriteParser::m_paragraphList
std::vector< MSWriteParserInternal::Paragraph > m_paragraphList
Definition: MSWrite.h:184
MSWriteParser::m_fonts
std::vector< librevenge::RVNGString > m_fonts
Definition: MSWrite.h:188
MSWriteParser::readFFNTB
virtual void readFFNTB()
Definition: MSWrite.cpp:347
MSWriteParserInternal::Section::m_yaMac
double m_yaMac
Definition: MSWrite.h:107
MSWriteParserInternal::Section::m_columns
unsigned m_columns
Definition: MSWrite.h:116
libwps_tools_win.h
MSWriteParserInternal::Section::m_xaMac
double m_xaMac
Definition: MSWrite.h:107
MSWriteParser::operator=
MSWriteParser & operator=(const MSWriteParser &)=delete
WPSFont
define the font properties
Definition: WPSFont.h:36
WPSParser.h
MSWriteParserInternal::Section::m_startPageNumber
uint16_t m_startPageNumber
Definition: MSWrite.h:112
MSWriteParserInternal::Font::m_footnote
bool m_footnote
Definition: MSWrite.h:73
MSWriteParserInternal::Paragraph::m_skiptab
bool m_skiptab
Definition: MSWrite.h:57
MSWriteParserInternal::Font::m_fcLim
uint32_t m_fcLim
Definition: MSWrite.h:72
MSWriteParserInternal::Paragraph::m_graphics
bool m_graphics
Definition: MSWrite.h:57
MSWriteParserInternal::Paragraph::m_fcFirst
uint32_t m_fcFirst
Definition: MSWrite.h:55
MSWriteParserInternal::Font::m_encoding
libwps_tools_win::Font::Type m_encoding
Definition: MSWrite.h:74
MSWriteParserInternal::Paragraph::m_interLine
double m_interLine
Definition: MSWrite.h:58
MSWriteParser::getHeaderFooters
void getHeaderFooters(uint32_t first, MSWriteParserInternal::Section &sep, WPSPageSpan &pageSpan)
Definition: MSWrite.cpp:760
MSWriteParserInternal::Font::m_annotation
bool m_annotation
Definition: MSWrite.h:73
WPSParser
Definition: WPSParser.h:35
libwps_tools_win::Font::Type
Type
enum Type
Definition: libwps_tools_win.h:46
MSWriteParser::MSWriteParser
MSWriteParser(RVNGInputStreamPtr &input, WPSHeaderPtr &header, libwps_tools_win::Font::Type encoding=libwps_tools_win::Font::WIN3_WEUROPE)
Definition: MSWrite.cpp:283
MSWriteParser::processStaticOLE
bool processStaticOLE(librevenge::RVNGBinaryData &, std::string &mimetype, WPSPosition &pos, unsigned long lastPos)
Definition: MSWrite.cpp:1520
MSWriteParserInternal::Section::m_yaTop
double m_yaTop
Definition: MSWrite.h:108
MSWriteParser::getPageStyle
static void getPageStyle(MSWriteParserInternal::Section &sep, WPSPageSpan &pageSpan)
Definition: MSWrite.cpp:503
MSWriteParserInternal::SubDocument
Internal: the subdocument of a MSWriteParser.
Definition: MSWrite.cpp:41
MSWriteParserInternal::Section::m_Main
WPSEntry m_Main
Definition: MSWrite.h:118
MSWriteParserInternal::Section::m_yaHeader
double m_yaHeader
Definition: MSWrite.h:113
MSWriteParser::readFNTB
virtual void readFNTB()
Definition: MSWrite.cpp:1681
MSWriteParser::readText
void readText(WPSEntry const &e, MSWriteParserInternal::Paragraph::Location location)
Definition: MSWrite.cpp:923
MSWriteParserInternal::Paragraph::m_fcLim
uint32_t m_fcLim
Definition: MSWrite.h:55
MSWriteParserInternal::Font::m_fcFirst
uint32_t m_fcFirst
Definition: MSWrite.h:72
MSWriteParser::m_fontType
libwps_tools_win::Font::Type m_fontType
Definition: MSWrite.h:189
MSWriteParserInternal::Paragraph::m_HeaderFooterOccurrence
WPSPageSpan::HeaderFooterOccurrence m_HeaderFooterOccurrence
Definition: MSWrite.h:59
MSWriteParser::m_metaData
librevenge::RVNGPropertyList m_metaData
Definition: MSWrite.h:193
MSWriteParser::m_footnotes
std::vector< MSWriteParserInternal::Footnote > m_footnotes
Definition: MSWrite.h:186
libwps_internal.h
MSWriteParserInternal::Footnote::m_fcFtn
uint32_t m_fcFtn
Definition: MSWrite.h:82
WPSEntry.h
MSWriteParser::processEmbeddedOLE
void processEmbeddedOLE(WPSPosition &pos, unsigned long lastPos)
Definition: MSWrite.cpp:1577
MSWriteParser::readCHP
virtual void readCHP(uint32_t fcFirst, uint32_t fcLim, unsigned cch)
Definition: MSWrite.cpp:704
WPSParagraph.h
MSWriteParserInternal::Section::m_yaFooter
double m_yaFooter
Definition: MSWrite.h:114
MSWriteParserInternal::Paragraph::m_firstpage
bool m_firstpage
Definition: MSWrite.h:57
MSWriteParser::insertString
unsigned insertString(const unsigned char *str, unsigned size, libwps_tools_win::Font::Type type)
Definition: MSWrite.cpp:1126
MSWriteParserInternal::Paragraph::FOOTNOTE
Definition: MSWrite.h:43
MSWriteParserInternal::Font
Definition: MSWrite.h:62
WPSPageSpan.h
MSWriteParserInternal::Font::Font
Font()
Definition: MSWrite.h:64
MSWriteParser::readFIB
void readFIB()
Definition: MSWrite.cpp:321
MSWriteParser::insertSpecial
virtual void insertSpecial(uint8_t val, uint32_t fc, MSWriteParserInternal::Paragraph::Location location)
Definition: MSWrite.cpp:1093
RVNGInputStreamPtr
std::shared_ptr< librevenge::RVNGInputStream > RVNGInputStreamPtr
shared pointer to librevenge::RVNGInputStream
Definition: libwps_internal.h:87
MSWriteParser::m_listener
std::shared_ptr< WPSContentListener > m_listener
Definition: MSWrite.h:191
MSWriteParserInternal::Section::m_dxaColumns
double m_dxaColumns
Definition: MSWrite.h:117
MSWriteParser::createListener
std::shared_ptr< WPSContentListener > createListener(librevenge::RVNGTextInterface *interface)
Definition: MSWrite.cpp:898
MSWriteParserInternal::Paragraph::Paragraph
Paragraph()
Definition: MSWrite.h:44
MSWriteParser::m_fcMac
uint32_t m_fcMac
Definition: MSWrite.h:182
WPSPageSpan::HeaderFooterOccurrence
HeaderFooterOccurrence
Definition: WPSPageSpan.h:44
MSWriteParser
This class parses Microsoft Write 3.0 and 3.1.
Definition: MSWrite.h:127
MSWriteParserInternal::Section::m_dxaGutter
double m_dxaGutter
Definition: MSWrite.h:117
MSWriteParser::readSUMD
virtual void readSUMD()
Definition: MSWrite.cpp:1676
MSWriteParserInternal::Paragraph::MAIN
Definition: MSWrite.h:43
MSWriteParserInternal::Paragraph::m_headerUseMargin
bool m_headerUseMargin
Definition: MSWrite.h:57
MSWriteParser::parse
void parse(librevenge::RVNGTextInterface *documentInterface) override
Definition: MSWrite.cpp:1761
MSWriteParser::insertControl
virtual void insertControl(uint8_t val, uint32_t fc)
Definition: MSWrite.cpp:1099
MSWriteParser::processDIB
bool processDIB(librevenge::RVNGBinaryData &bmpdata, unsigned size)
Definition: MSWrite.cpp:1477
MSWriteParser::readPAP
virtual void readPAP(uint32_t fcFirst, uint32_t fcLim, unsigned cch)
Definition: MSWrite.cpp:605
MSWriteParser::processDDB
bool processDDB(librevenge::RVNGBinaryData &bmpdata, WPSPosition &pos, unsigned width, unsigned height, unsigned byte_width, unsigned planes, unsigned bits_pixel, unsigned size)
Definition: MSWrite.cpp:1292
MSWriteParserInternal::Section::m_endFtns
bool m_endFtns
Definition: MSWrite.h:115
MSWriteParserInternal::Footnote::m_fcRef
uint32_t m_fcRef
Definition: MSWrite.h:82
libwps_tools_win
some Windows© classes and tools
Definition: libwps_tools_win.cpp:31
MSWriteParser::~MSWriteParser
~MSWriteParser() override
Definition: MSWrite.cpp:309
MSWriteParser::readStructures
void readStructures()
Definition: MSWrite.cpp:1686
MSWriteParser::checkFilePosition
bool checkFilePosition(uint32_t pos) const
check if the file position is correct or not
Definition: MSWrite.h:175
WPSPageSpan
Definition: WPSPageSpan.h:38
MSWriteParserInternal::Section
Definition: MSWrite.h:85
MSWriteParserInternal::Paragraph::m_Location
Location m_Location
Definition: MSWrite.h:56
MSWriteParser::m_sections
std::vector< MSWriteParserInternal::Section > m_sections
Definition: MSWrite.h:187
WPSFont.h
WPSEntry
basic class to store an entry in a file This contained :
Definition: WPSEntry.h:38
MSWriteParser::readFOD
void readFOD(unsigned page, void(MSWriteParser::*parseFOD)(uint32_t fcFirst, uint32_t fcLim, unsigned size))
Definition: MSWrite.cpp:550
WPSPosition
Class to define the position of an object (textbox, picture, ..) in the document. ...
Definition: WPSPosition.h:39
MSWriteParserInternal::Paragraph::Location
Location
Definition: MSWrite.h:43
MSWriteParser::processWMF
bool processWMF(librevenge::RVNGBinaryData &wmfdata, unsigned size)
Definition: MSWrite.cpp:1657
libwps_tools_win::Font::WIN3_WEUROPE
Definition: libwps_tools_win.h:52
MSWriteParser::getFileEncoding
virtual libwps_tools_win::Font::Type getFileEncoding(libwps_tools_win::Font::Type hint)
Definition: MSWrite.cpp:313
WPSHeaderPtr
std::shared_ptr< WPSHeader > WPSHeaderPtr
shared pointer to WPSHeader
Definition: libwps_internal.h:109
MSWriteParser::m_fileLength
uint32_t m_fileLength
the last file position
Definition: MSWrite.h:181
MSWriteParser::processObject
void processObject(WPSPosition &pos, unsigned long lastPos)
Definition: MSWrite.cpp:1183
MSWriteParserInternal::Paragraph
Definition: MSWrite.h:41
MSWriteParserInternal::Section::Section
Section()
constructor
Definition: MSWrite.h:88
MSWriteParserInternal::Paragraph::FOOTER
Definition: MSWrite.h:43
MSWriteParserInternal::Footnote
Definition: MSWrite.h:77