/src/libmwaw/src/lib/HanMacWrdJParser.hxx
Line | Count | Source |
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 | | |
50 | | namespace HanMacWrdJParserInternal |
51 | | { |
52 | | struct State; |
53 | | class SubDocument; |
54 | | } |
55 | | |
56 | | class HanMacWrdJGraph; |
57 | | class HanMacWrdJText; |
58 | | |
59 | | /** a class use to store the classic header find before file zone */ |
60 | | struct HanMacWrdJZoneHeader { |
61 | | //! constructor |
62 | | explicit HanMacWrdJZoneHeader(bool isMain) |
63 | 369k | : m_length(0) |
64 | 369k | , m_n(0) |
65 | 369k | , m_fieldSize(0) |
66 | 369k | , m_id(0) |
67 | 369k | , m_isMain(isMain) |
68 | 369k | { |
69 | 1.47M | for (auto &val : m_values) val = 0; |
70 | 369k | } |
71 | | |
72 | | //! operator<< |
73 | | friend std::ostream &operator<<(std::ostream &o, HanMacWrdJZoneHeader const &h) |
74 | 0 | { |
75 | 0 | if (h.m_n) o << "N=" << h.m_n << ","; |
76 | 0 | if (h.m_id) o << "zId=" << std::hex << h.m_id << std::dec << ","; |
77 | 0 | bool toPrint[4]= {true, true, true, true}; |
78 | 0 | if (h.m_isMain) { |
79 | 0 | if (h.m_values[0]+h.m_n == h.m_values[1]) |
80 | 0 | toPrint[0]=toPrint[1]=false; |
81 | 0 | else if (h.m_values[0]+h.m_n == h.m_values[2]) |
82 | 0 | toPrint[0]=toPrint[2]=false; |
83 | 0 | else |
84 | 0 | o << "###N,"; |
85 | 0 | } |
86 | 0 | for (int i=0; i < 4; i++) |
87 | 0 | if (toPrint[i] && h.m_values[i]) o << "h" << i << "=" << h.m_values[i] << ","; |
88 | 0 | return o; |
89 | 0 | } |
90 | | //! the zone size |
91 | | long m_length; |
92 | | //! the number of item |
93 | | int m_n; |
94 | | //! the field size |
95 | | int m_fieldSize; |
96 | | //! the zone id |
97 | | long m_id; |
98 | | //! 4 unknown field : freeN?, totalN?, totalN1?, ? |
99 | | int m_values[4]; |
100 | | //! true if this is the main header |
101 | | bool m_isMain; |
102 | | }; |
103 | | |
104 | | /** \brief the main class to read a HanMac Word-J file |
105 | | * |
106 | | * |
107 | | * |
108 | | */ |
109 | | class HanMacWrdJParser final : public MWAWTextParser |
110 | | { |
111 | | friend class HanMacWrdJGraph; |
112 | | friend class HanMacWrdJText; |
113 | | friend class HanMacWrdJParserInternal::SubDocument; |
114 | | |
115 | | public: |
116 | | //! constructor |
117 | | HanMacWrdJParser(MWAWInputStreamPtr const &input, MWAWRSRCParserPtr const &rsrcParser, MWAWHeader *header); |
118 | | //! destructor |
119 | | ~HanMacWrdJParser() final; |
120 | | |
121 | | //! checks if the document header is correct (or not) |
122 | | bool checkHeader(MWAWHeader *header, bool strict=false) final; |
123 | | |
124 | | // the main parse function |
125 | | void parse(librevenge::RVNGTextInterface *documentInterface) final; |
126 | | |
127 | | protected: |
128 | | //! inits all internal variables |
129 | | void init(); |
130 | | |
131 | | //! creates the listener which will be associated to the document |
132 | | void createDocument(librevenge::RVNGTextInterface *documentInterface); |
133 | | |
134 | | //! finds the different objects zones in a Hapanese File |
135 | | bool createZones(); |
136 | | |
137 | | //! returns the page left top point ( in inches) |
138 | | MWAWVec2f getPageLeftTop() const; |
139 | | |
140 | | //! adds a new page |
141 | | void newPage(int number); |
142 | | |
143 | | // interface with the text parser |
144 | | |
145 | | //! send a text zone |
146 | | bool sendText(long id, long cPos, MWAWListenerPtr listener=MWAWListenerPtr()); |
147 | | //! check if we can send a textzone as graphic |
148 | | bool canSendTextAsGraphic(long id, long cPos); |
149 | | |
150 | | // interface with the graph parser |
151 | | |
152 | | //! send a zone |
153 | | bool sendZone(long zId); |
154 | | //! returns the color associated with a pattern |
155 | | bool getColor(int colId, int patternId, MWAWColor &color) const; |
156 | | |
157 | | // |
158 | | // low level |
159 | | // |
160 | | |
161 | | /** look in entry.begin() to see if a entry exists at this position, |
162 | | if so fills entry.end(), entry.id(), ...*/ |
163 | | bool checkEntry(MWAWEntry &entry); |
164 | | |
165 | | /** try to read the zones list */ |
166 | | bool readZonesList(); |
167 | | /** try to read a generic zone */ |
168 | | bool readZone(MWAWEntry &entry); |
169 | | |
170 | | /** try to read a header of classic zone */ |
171 | | bool readClassicHeader(HanMacWrdJZoneHeader &header, long endPos=-1); |
172 | | /** try to decode a zone */ |
173 | | bool decodeZone(MWAWEntry const &entry, librevenge::RVNGBinaryData &data); |
174 | | |
175 | | /** try to read a printinfo zone*/ |
176 | | bool readPrintInfo(MWAWEntry const &entry); |
177 | | /** try to read a unknown zone, just after the header (simillar to HanMacWrd Zoneb) */ |
178 | | bool readHeaderEnd(); |
179 | | #ifdef DEBUG |
180 | | /** try to read a unknown zones with header data */ |
181 | | bool readZoneWithHeader(MWAWEntry const &entry); |
182 | | #endif |
183 | | /** try to read the zone A ( a big zone containing 5 sub zone ? )*/ |
184 | | bool readZoneA(MWAWEntry const &entry); |
185 | | /** try to read the zone B*/ |
186 | | bool readZoneB(MWAWEntry const &entry); |
187 | | |
188 | | protected: |
189 | | // |
190 | | // data |
191 | | // |
192 | | //! the state |
193 | | std::shared_ptr<HanMacWrdJParserInternal::State> m_state; |
194 | | |
195 | | //! the graph parser |
196 | | std::shared_ptr<HanMacWrdJGraph> m_graphParser; |
197 | | |
198 | | //! the text parser |
199 | | std::shared_ptr<HanMacWrdJText> m_textParser; |
200 | | }; |
201 | | #endif |
202 | | // vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab: |