HanMacWrdJParser.hxx Source File documentation

HanMacWrdJParser.hxx
Go to the documentation of this file.
1/* -*- Mode: C++; c-default-style: "k&r"; indent-tabs-mode: nil; tab-width: 2; c-basic-offset: 2 -*- */
2
3/* libmwaw
4* Version: MPL 2.0 / LGPLv2+
5*
6* The contents of this file are subject to the Mozilla Public License Version
7* 2.0 (the "License"); you may not use this file except in compliance with
8* the License or as specified alternatively below. You may obtain a copy of
9* the License at http://www.mozilla.org/MPL/
10*
11* Software distributed under the License is distributed on an "AS IS" basis,
12* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13* for the specific language governing rights and limitations under the
14* License.
15*
16* Major Contributor(s):
17* Copyright (C) 2002 William Lachance (wrlach@gmail.com)
18* Copyright (C) 2002,2004 Marc Maurer (uwog@uwog.net)
19* Copyright (C) 2004-2006 Fridrich Strba (fridrich.strba@bluewin.ch)
20* Copyright (C) 2006, 2007 Andrew Ziem
21* Copyright (C) 2011, 2012 Alonso Laurent (alonso@loria.fr)
22*
23*
24* All Rights Reserved.
25*
26* For minor contributions see the git repository.
27*
28* Alternatively, the contents of this file may be used under the terms of
29* the GNU Lesser General Public License Version 2 or later (the "LGPLv2+"),
30* in which case the provisions of the LGPLv2+ are applicable
31* instead of those above.
32*/
33
34/*
35 * Parser to convert HanMac Word-J document
36 */
37#ifndef HAN_MAC_WRD_J_PARSER
38# define HAN_MAC_WRD_J_PARSER
39
40#include <iostream>
41#include <string>
42#include <vector>
43
44#include <librevenge/librevenge.h>
45
46#include "MWAWDebug.hxx"
47
48#include "MWAWParser.hxx"
49
50namespace HanMacWrdJParserInternal
51{
52struct State;
53class SubDocument;
54}
55
56class HanMacWrdJGraph;
57class HanMacWrdJText;
58
60 struct HanMacWrdJZoneHeader {
62 explicit HanMacWrdJZoneHeader(bool isMain)
63 : m_length(0)
64 , m_n(0)
65 , m_fieldSize(0)
66 , m_id(0)
67 , m_isMain(isMain)
68 {
69 for (auto &val : m_values) val = 0;
70 }
71
73 friend std::ostream &operator<<(std::ostream &o, HanMacWrdJZoneHeader const &h)
74 {
75 if (h.m_n) o << "N=" << h.m_n << ",";
76 if (h.m_id) o << "zId=" << std::hex << h.m_id << std::dec << ",";
77 bool toPrint[4]= {true, true, true, true};
78 if (h.m_isMain) {
79 if (h.m_values[0]+h.m_n == h.m_values[1])
80 toPrint[0]=toPrint[1]=false;
81 else if (h.m_values[0]+h.m_n == h.m_values[2])
82 toPrint[0]=toPrint[2]=false;
83 else
84 o << "###N,";
85 }
86 for (int i=0; i < 4; i++)
87 if (toPrint[i] && h.m_values[i]) o << "h" << i << "=" << h.m_values[i] << ",";
88 return o;
89 }
91 long m_length;
93 int m_n;
95 int m_fieldSize;
97 long m_id;
99 int m_values[4];
101 bool m_isMain;
102};
103
109 class HanMacWrdJParser final : public MWAWTextParser
110{
111 friend class HanMacWrdJGraph;
112 friend class HanMacWrdJText;
113 friend class HanMacWrdJParserInternal::SubDocument;
114
115public:
117 HanMacWrdJParser(MWAWInputStreamPtr const &input, MWAWRSRCParserPtr const &rsrcParser, MWAWHeader *header);
119 ~HanMacWrdJParser() final;
120
122 bool checkHeader(MWAWHeader *header, bool strict=false) final;
123
124 // the main parse function
125 void parse(librevenge::RVNGTextInterface *documentInterface) final;
126
127protected:
129 void init();
130
132 void createDocument(librevenge::RVNGTextInterface *documentInterface);
133
135 bool createZones();
136
138 MWAWVec2f getPageLeftTop() const;
139
141 void newPage(int number);
142
143 // interface with the text parser
144
146 bool sendText(long id, long cPos, MWAWListenerPtr listener=MWAWListenerPtr());
148 bool canSendTextAsGraphic(long id, long cPos);
149
150 // interface with the graph parser
151
153 bool sendZone(long zId);
155 bool getColor(int colId, int patternId, MWAWColor &color) const;
156
157 //
158 // low level
159 //
160
163 bool checkEntry(MWAWEntry &entry);
164
166 bool readZonesList();
168 bool readZone(MWAWEntry &entry);
169
171 bool readClassicHeader(HanMacWrdJZoneHeader &header, long endPos=-1);
173 bool decodeZone(MWAWEntry const &entry, librevenge::RVNGBinaryData &data);
174
176 bool readPrintInfo(MWAWEntry const &entry);
178 bool readHeaderEnd();
179#ifdef DEBUG
181 bool readZoneWithHeader(MWAWEntry const &entry);
182#endif
184 bool readZoneA(MWAWEntry const &entry);
186 bool readZoneB(MWAWEntry const &entry);
187
188protected:
189 //
190 // data
191 //
193 std::shared_ptr<HanMacWrdJParserInternal::State> m_state;
194
196 std::shared_ptr<HanMacWrdJGraph> m_graphParser;
197
199 std::shared_ptr<HanMacWrdJText> m_textParser;
200};
201#endif
202// vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab:
MWAWDebug.hxx
MWAWParser.hxx
HanMacWrdJGraph
the main class to read the graphic part of a HanMac Word-J file
Definition HanMacWrdJGraph.hxx:79
HanMacWrdJParserInternal::SubDocument
Internal: the subdocument of a HanMacWrdJParser.
Definition HanMacWrdJParser.cxx:100
HanMacWrdJParser
the main class to read a HanMac Word-J file
Definition HanMacWrdJParser.hxx:110
HanMacWrdJParser::getPageLeftTop
MWAWVec2f getPageLeftTop() const
returns the page left top point ( in inches)
Definition HanMacWrdJParser.cxx:215
HanMacWrdJParser::sendText
bool sendText(long id, long cPos, MWAWListenerPtr listener=MWAWListenerPtr())
send a text zone
Definition HanMacWrdJParser.cxx:190
HanMacWrdJParser::m_textParser
std::shared_ptr< HanMacWrdJText > m_textParser
the text parser
Definition HanMacWrdJParser.hxx:199
HanMacWrdJParser::sendZone
bool sendZone(long zId)
send a zone
Definition HanMacWrdJParser.cxx:200
HanMacWrdJParser::readZoneA
bool readZoneA(MWAWEntry const &entry)
try to read the zone A ( a big zone containing 5 sub zone ? )
Definition HanMacWrdJParser.cxx:705
HanMacWrdJParser::init
void init()
inits all internal variables
Definition HanMacWrdJParser.cxx:176
HanMacWrdJParser::createDocument
void createDocument(librevenge::RVNGTextInterface *documentInterface)
creates the listener which will be associated to the document
Definition HanMacWrdJParser.cxx:296
HanMacWrdJParser::decodeZone
bool decodeZone(MWAWEntry const &entry, librevenge::RVNGBinaryData &data)
try to decode a zone
Definition HanMacWrdJParser.cxx:1168
HanMacWrdJParser::HanMacWrdJParser
HanMacWrdJParser(MWAWInputStreamPtr const &input, MWAWRSRCParserPtr const &rsrcParser, MWAWHeader *header)
constructor
Definition HanMacWrdJParser.cxx:163
HanMacWrdJParser::checkHeader
bool checkHeader(MWAWHeader *header, bool strict=false) final
checks if the document header is correct (or not)
Definition HanMacWrdJParser.cxx:1036
HanMacWrdJParser::m_state
std::shared_ptr< HanMacWrdJParserInternal::State > m_state
the state
Definition HanMacWrdJParser.hxx:193
HanMacWrdJParser::m_graphParser
std::shared_ptr< HanMacWrdJGraph > m_graphParser
the graph parser
Definition HanMacWrdJParser.hxx:196
HanMacWrdJParser::readClassicHeader
bool readClassicHeader(HanMacWrdJZoneHeader &header, long endPos=-1)
try to read a header of classic zone
Definition HanMacWrdJParser.cxx:237
HanMacWrdJParser::readZonesList
bool readZonesList()
try to read the zones list
Definition HanMacWrdJParser.cxx:463
HanMacWrdJParser::createZones
bool createZones()
finds the different objects zones in a Hapanese File
Definition HanMacWrdJParser.cxx:339
HanMacWrdJParser::checkEntry
bool checkEntry(MWAWEntry &entry)
look in entry.begin() to see if a entry exists at this position, if so fills entry....
Definition HanMacWrdJParser.cxx:421
HanMacWrdJParser::parse
void parse(librevenge::RVNGTextInterface *documentInterface) final
virtual function used to parse the input
Definition HanMacWrdJParser.cxx:261
HanMacWrdJParser::newPage
void newPage(int number)
adds a new page
Definition HanMacWrdJParser.cxx:224
HanMacWrdJParser::readZoneB
bool readZoneB(MWAWEntry const &entry)
try to read the zone B
Definition HanMacWrdJParser.cxx:805
HanMacWrdJParser::~HanMacWrdJParser
~HanMacWrdJParser() final
destructor
Definition HanMacWrdJParser.cxx:172
HanMacWrdJParser::getColor
bool getColor(int colId, int patternId, MWAWColor &color) const
returns the color associated with a pattern
Definition HanMacWrdJParser.cxx:207
HanMacWrdJParser::readHeaderEnd
bool readHeaderEnd()
try to read a unknown zone, just after the header (simillar to HanMacWrd Zoneb)
Definition HanMacWrdJParser.cxx:885
HanMacWrdJParser::readZone
bool readZone(MWAWEntry &entry)
try to read a generic zone
Definition HanMacWrdJParser.cxx:509
HanMacWrdJParser::canSendTextAsGraphic
bool canSendTextAsGraphic(long id, long cPos)
check if we can send a textzone as graphic
Definition HanMacWrdJParser.cxx:195
HanMacWrdJParser::readPrintInfo
bool readPrintInfo(MWAWEntry const &entry)
try to read a printinfo zone
Definition HanMacWrdJParser.cxx:602
HanMacWrdJText
the main class to read the text part of HanMac Word-J file
Definition HanMacWrdJText.hxx:63
MWAWEntry
basic class to store an entry in a file This contained :
Definition MWAWEntry.hxx:47
MWAWHeader
a function used by MWAWDocument to store the version of document
Definition MWAWHeader.hxx:57
MWAWTextParser
virtual class which defines the ancestor of all text zone parser
Definition MWAWParser.hxx:299
MWAWVec2< float >
MWAWRSRCParserPtr
std::shared_ptr< MWAWRSRCParser > MWAWRSRCParserPtr
a smart pointer of MWAWRSRCParser
Definition libmwaw_internal.hxx:561
MWAWListenerPtr
std::shared_ptr< MWAWListener > MWAWListenerPtr
a smart pointer of MWAWListener
Definition libmwaw_internal.hxx:553
MWAWInputStreamPtr
std::shared_ptr< MWAWInputStream > MWAWInputStreamPtr
a smart pointer of MWAWInputStream
Definition libmwaw_internal.hxx:551
HanMacWrdJParserInternal
Internal: the structures of a HanMacWrdJParser.
Definition HanMacWrdJParser.cxx:63
librevenge
Definition MWAWDocument.hxx:57
HanMacWrdJZoneHeader
a class use to store the classic header find before file zone
Definition HanMacWrdJParser.hxx:60
HanMacWrdJZoneHeader::m_n
int m_n
the number of item
Definition HanMacWrdJParser.hxx:93
HanMacWrdJZoneHeader::m_values
int m_values[4]
4 unknown field : freeN?, totalN?, totalN1?, ?
Definition HanMacWrdJParser.hxx:99
HanMacWrdJZoneHeader::m_fieldSize
int m_fieldSize
the field size
Definition HanMacWrdJParser.hxx:95
HanMacWrdJZoneHeader::m_length
long m_length
the zone size
Definition HanMacWrdJParser.hxx:91
HanMacWrdJZoneHeader::m_isMain
bool m_isMain
true if this is the main header
Definition HanMacWrdJParser.hxx:101
HanMacWrdJZoneHeader::operator<<
friend std::ostream & operator<<(std::ostream &o, HanMacWrdJZoneHeader const &h)
operator<<
Definition HanMacWrdJParser.hxx:73
HanMacWrdJZoneHeader::HanMacWrdJZoneHeader
HanMacWrdJZoneHeader(bool isMain)
constructor
Definition HanMacWrdJParser.hxx:62
HanMacWrdJZoneHeader::m_id
long m_id
the zone id
Definition HanMacWrdJParser.hxx:97
MWAWColor
the class to store a color
Definition libmwaw_internal.hxx:192