/src/libmwaw/src/lib/NisusWrtGraph.cxx
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 | | #include <cmath> |
35 | | #include <iomanip> |
36 | | #include <iostream> |
37 | | #include <limits> |
38 | | #include <map> |
39 | | #include <sstream> |
40 | | |
41 | | #include <librevenge/librevenge.h> |
42 | | |
43 | | #include "MWAWTextListener.hxx" |
44 | | #include "MWAWFont.hxx" |
45 | | #include "MWAWFontConverter.hxx" |
46 | | #include "MWAWPictMac.hxx" |
47 | | #include "MWAWPosition.hxx" |
48 | | #include "MWAWRSRCParser.hxx" |
49 | | #include "MWAWSubDocument.hxx" |
50 | | |
51 | | #include "NisusWrtParser.hxx" |
52 | | #include "NisusWrtStruct.hxx" |
53 | | |
54 | | #include "NisusWrtGraph.hxx" |
55 | | |
56 | | /** Internal: the structures of a NisusWrtGraph */ |
57 | | namespace NisusWrtGraphInternal |
58 | | { |
59 | | //! a RSSO entry in a pict file |
60 | | struct RSSOEntry { |
61 | | //! constructor |
62 | | RSSOEntry() |
63 | 0 | : m_id(-1) |
64 | 0 | , m_position() |
65 | 0 | { |
66 | 0 | } |
67 | | //! operator<< |
68 | | friend std::ostream &operator<<(std::ostream &o, RSSOEntry const &entry) |
69 | 0 | { |
70 | 0 | o << "id=" << entry.m_id << ","; |
71 | 0 | o << "box=" << entry.m_position << ","; |
72 | 0 | return o; |
73 | 0 | } |
74 | | //! the id |
75 | | int m_id; |
76 | | //! the bdbox |
77 | | MWAWBox2f m_position; |
78 | | }; |
79 | | //////////////////////////////////////// |
80 | | //! Internal: the state of a NisusWrtGraph |
81 | | struct State { |
82 | | //! constructor |
83 | | State() |
84 | 8.34k | : m_numPages(0) |
85 | 8.34k | , m_maxPageGraphic(0) |
86 | 8.34k | , m_idPictMap() |
87 | 8.34k | , m_idRssoMap() |
88 | 8.34k | { |
89 | 8.34k | } |
90 | | |
91 | | int m_numPages /* the number of pages */; |
92 | | //! the last page containing page graphic |
93 | | int m_maxPageGraphic; |
94 | | //! the map pictId -> pictEntry |
95 | | std::map<int, MWAWEntry> m_idPictMap; |
96 | | //! the map id -> rssoEntry |
97 | | std::map<int, MWAWEntry> m_idRssoMap; |
98 | | }; |
99 | | |
100 | | //////////////////////////////////////// |
101 | | //! Internal: the subdocument of a NisusWrtGraph |
102 | | class SubDocument final : public MWAWSubDocument |
103 | | { |
104 | | public: |
105 | | SubDocument(NisusWrtGraph &pars, MWAWInputStreamPtr const &input, int id, MWAWPosition const &pos) |
106 | 0 | : MWAWSubDocument(pars.m_mainParser, input, MWAWEntry()) |
107 | 0 | , m_graphParser(&pars) |
108 | 0 | , m_id(id) |
109 | 0 | , m_position(pos) |
110 | 0 | { |
111 | 0 | } |
112 | | |
113 | | //! destructor |
114 | 0 | ~SubDocument() final {} |
115 | | |
116 | | //! operator!= |
117 | | bool operator!=(MWAWSubDocument const &doc) const final; |
118 | | |
119 | | //! the parser function |
120 | | void parse(MWAWListenerPtr &listener, libmwaw::SubDocumentType type) final; |
121 | | |
122 | | protected: |
123 | | /** the graph parser */ |
124 | | NisusWrtGraph *m_graphParser; |
125 | | //! the pict id |
126 | | int m_id; |
127 | | //! the pict position |
128 | | MWAWPosition m_position; |
129 | | private: |
130 | | SubDocument(SubDocument const &orig) = delete; |
131 | | SubDocument &operator=(SubDocument const &orig) = delete; |
132 | | }; |
133 | | |
134 | | void SubDocument::parse(MWAWListenerPtr &listener, libmwaw::SubDocumentType /*type*/) |
135 | 0 | { |
136 | 0 | if (!listener.get()) { |
137 | 0 | MWAW_DEBUG_MSG(("NisusWrtGraphInternal::SubDocument::parse: no listener\n")); |
138 | 0 | return; |
139 | 0 | } |
140 | 0 | if (!m_graphParser) { |
141 | 0 | MWAW_DEBUG_MSG(("NisusWrtGraphInternal::SubDocument::parse: no graph parser\n")); |
142 | 0 | return; |
143 | 0 | } |
144 | 0 | long pos = m_input->tell(); |
145 | 0 | m_graphParser->sendPicture(m_id, true, m_position); |
146 | 0 | m_input->seek(pos, librevenge::RVNG_SEEK_SET); |
147 | 0 | } |
148 | | |
149 | | bool SubDocument::operator!=(MWAWSubDocument const &doc) const |
150 | 0 | { |
151 | 0 | if (MWAWSubDocument::operator!=(doc)) return true; |
152 | 0 | auto const *sDoc = dynamic_cast<SubDocument const *>(&doc); |
153 | 0 | if (!sDoc) return true; |
154 | 0 | if (m_graphParser != sDoc->m_graphParser) return true; |
155 | 0 | if (m_id != sDoc->m_id) return true; |
156 | 0 | if (m_position != sDoc->m_position) return true; |
157 | 0 | return false; |
158 | 0 | } |
159 | | } |
160 | | |
161 | | //////////////////////////////////////////////////////////// |
162 | | // constructor/destructor, ... |
163 | | //////////////////////////////////////////////////////////// |
164 | | NisusWrtGraph::NisusWrtGraph(NisusWrtParser &parser) |
165 | 8.34k | : m_parserState(parser.getParserState()) |
166 | 8.34k | , m_state(new NisusWrtGraphInternal::State) |
167 | 8.34k | , m_mainParser(&parser) |
168 | 8.34k | { |
169 | 8.34k | } |
170 | | |
171 | | NisusWrtGraph::~NisusWrtGraph() |
172 | 8.34k | { } |
173 | | |
174 | | int NisusWrtGraph::version() const |
175 | 67.1k | { |
176 | 67.1k | return m_parserState->m_version; |
177 | 67.1k | } |
178 | | |
179 | | int NisusWrtGraph::numPages() const |
180 | 4.37k | { |
181 | 4.37k | return m_state->m_maxPageGraphic; |
182 | 4.37k | } |
183 | | |
184 | | //////////////////////////////////////////////////////////// |
185 | | // |
186 | | // Intermediate level |
187 | | // |
188 | | //////////////////////////////////////////////////////////// |
189 | | bool NisusWrtGraph::createZones() |
190 | 3.62k | { |
191 | 3.62k | MWAWRSRCParserPtr rsrcParser = m_mainParser->getRSRCParser(); |
192 | 3.62k | if (!rsrcParser) { |
193 | 0 | MWAW_DEBUG_MSG(("NisusWrtGraph::createZones: can not find the entry map\n")); |
194 | 0 | return false; |
195 | 0 | } |
196 | 3.62k | auto &entryMap = rsrcParser->getEntriesMap(); |
197 | | |
198 | | // the different pict zones |
199 | 3.62k | auto it = entryMap.lower_bound("PICT"); |
200 | 12.0k | while (it != entryMap.end()) { |
201 | 12.0k | if (it->first != "PICT") |
202 | 3.62k | break; |
203 | 8.40k | MWAWEntry const &entry = it++->second; |
204 | 8.40k | m_state->m_idPictMap[entry.id()]=entry; |
205 | 8.40k | } |
206 | 3.62k | it = entryMap.lower_bound("RSSO"); |
207 | 3.62k | while (it != entryMap.end()) { |
208 | 3.62k | if (it->first != "RSSO") |
209 | 3.62k | break; |
210 | 0 | MWAWEntry const &entry = it++->second; |
211 | 0 | m_state->m_idRssoMap[entry.id()]=entry; |
212 | 0 | } |
213 | | |
214 | | // number of page graphic |
215 | 3.62k | it = entryMap.lower_bound("PGRA"); |
216 | 7.23k | while (it != entryMap.end()) { |
217 | 7.23k | if (it->first != "PGRA") |
218 | 3.62k | break; |
219 | 3.60k | MWAWEntry const &entry = it++->second; |
220 | 3.60k | readPGRA(entry); |
221 | 3.60k | } |
222 | | |
223 | | // a picture position ? |
224 | 3.62k | it = entryMap.lower_bound("PLAC"); |
225 | 7.78k | while (it != entryMap.end()) { |
226 | 7.78k | if (it->first != "PLAC") |
227 | 3.62k | break; |
228 | 4.15k | MWAWEntry const &entry = it++->second; |
229 | 4.15k | readPLAC(entry); |
230 | 4.15k | } |
231 | 3.62k | it = entryMap.lower_bound("PLDT"); |
232 | 7.13k | while (it != entryMap.end()) { |
233 | 7.13k | if (it->first != "PLDT") |
234 | 3.62k | break; |
235 | 3.50k | MWAWEntry &entry = it++->second; |
236 | 3.50k | entry.setName("PLDT"); |
237 | 3.50k | NisusWrtStruct::RecursifData data(NisusWrtStruct::Z_Main); |
238 | 3.50k | data.read(*m_mainParser, entry); |
239 | 3.50k | readPLDT(data); |
240 | 3.50k | } |
241 | | |
242 | 3.62k | return true; |
243 | 3.62k | } |
244 | | |
245 | | // read the PLAC zone ( a list of picture placement ? ) |
246 | | bool NisusWrtGraph::readPLAC(MWAWEntry const &entry) |
247 | 4.15k | { |
248 | 4.15k | if ((!entry.valid()&&entry.length()) || (entry.length()%202)) { |
249 | 2.77k | MWAW_DEBUG_MSG(("NisusWrtGraph::readPLAC: the entry is bad\n")); |
250 | 2.77k | return false; |
251 | 2.77k | } |
252 | 1.38k | entry.setParsed(true); |
253 | 1.38k | MWAWInputStreamPtr input = m_mainParser->rsrcInput(); |
254 | 1.38k | libmwaw::DebugFile &ascFile = m_mainParser->rsrcAscii(); |
255 | 1.38k | long pos = entry.begin(); |
256 | 1.38k | input->seek(pos, librevenge::RVNG_SEEK_SET); |
257 | | |
258 | 1.38k | auto numElt = int(entry.length()/202); |
259 | 1.38k | libmwaw::DebugStream f; |
260 | 1.38k | f << "Entries(PLAC)[" << entry.id() << "]:N=" << numElt; |
261 | 1.38k | ascFile.addPos(pos-4); |
262 | 1.38k | ascFile.addNote(f.str().c_str()); |
263 | | |
264 | 2.73k | for (int i = 0; i < numElt; i++) { |
265 | 1.35k | pos = input->tell(); |
266 | 1.35k | f.str(""); |
267 | 1.35k | f << "PLAC" << i << ":"; |
268 | 1.35k | auto val = static_cast<int>(input->readULong(2)); |
269 | 1.35k | f << "pictId=" << val; |
270 | 1.35k | ascFile.addDelimiter(input->tell(),'|'); |
271 | 1.35k | ascFile.addPos(pos); |
272 | 1.35k | ascFile.addNote(f.str().c_str()); |
273 | 1.35k | input->seek(pos+202, librevenge::RVNG_SEEK_SET); |
274 | 1.35k | } |
275 | 1.38k | return true; |
276 | 4.15k | } |
277 | | |
278 | | // read PLDT zone: a unknown zone (a type, an id/anchor type? and a bdbox ) |
279 | | bool NisusWrtGraph::readPLDT(NisusWrtStruct::RecursifData const &data) |
280 | 3.50k | { |
281 | 3.50k | if (!data.m_info || data.m_info->m_zoneType >= 3) { |
282 | 0 | MWAW_DEBUG_MSG(("NisusWrtGraph::readPLDT: find unexpected zoneType\n")); |
283 | 0 | return false; |
284 | 0 | } |
285 | | |
286 | 3.50k | if (!data.m_childList.size()) |
287 | 1.90k | return true; |
288 | | |
289 | 1.60k | if (data.m_childList.size() > 1) { |
290 | 0 | MWAW_DEBUG_MSG(("NisusWrtGraph::readPLDT: level 0 node contains more than 1 node\n")); |
291 | 0 | } |
292 | 1.60k | if (data.m_childList[0].isLeaf()) { |
293 | 0 | MWAW_DEBUG_MSG(("NisusWrtGraph::readPLDT: level 1 node is a leaf\n")); |
294 | 0 | return false; |
295 | 0 | } |
296 | 1.60k | auto const &mainData = *data.m_childList[0].m_data; |
297 | | // NisusWrtGraphInternal::Zone &zone = m_state->m_zones[static_cast<int>(data.m_info->m_zoneType)]; |
298 | 1.60k | MWAWInputStreamPtr input = m_mainParser->rsrcInput(); |
299 | 1.60k | libmwaw::DebugFile &ascFile = m_mainParser->rsrcAscii(); |
300 | 1.60k | libmwaw::DebugStream f; |
301 | | |
302 | 1.60k | long val; |
303 | 4.18k | for (auto const &mData : mainData.m_childList) { |
304 | 4.18k | if (mData.isLeaf()) { |
305 | 0 | MWAW_DEBUG_MSG(("NisusWrtGraph::readPLDT: oops some level 2 node are leaf\n")); |
306 | 0 | continue; |
307 | 0 | } |
308 | 4.18k | NisusWrtStruct::RecursifData const &dt=*mData.m_data; |
309 | | /* type == 7fffffff and wh = 2 */ |
310 | 4.18k | if (dt.m_childList.size() != 1) { |
311 | 2.81k | MWAW_DEBUG_MSG(("NisusWrtGraph::readPLDT: find an odd number of 3 leavers\n")); |
312 | 2.81k | continue; |
313 | 2.81k | } |
314 | 1.36k | auto const &child= dt.m_childList[0]; |
315 | 1.36k | if (!child.isLeaf() || child.m_entry.length() < 14) { |
316 | 40 | MWAW_DEBUG_MSG(("NisusWrtGraph::readPLDT: find an odd level 3 leaf\n")); |
317 | 40 | continue; |
318 | 40 | } |
319 | | |
320 | 1.32k | long pos = child.m_entry.begin(); |
321 | 1.32k | input->seek(pos, librevenge::RVNG_SEEK_SET); |
322 | 1.32k | f.str(""); |
323 | 1.32k | std::string type(""); // find different small string here |
324 | 6.64k | for (int i = 0; i < 4; i++) |
325 | 5.31k | type += char(input->readULong(1)); |
326 | 1.32k | f << type << ","; |
327 | 1.32k | val = input->readLong(2); // a small number find 4,5,b,d |
328 | 1.32k | if (val) f << "f0=" << val << ","; |
329 | 1.32k | int dim[4]; |
330 | 5.31k | for (auto &d : dim) d = static_cast<int>(input->readLong(2)); |
331 | 1.32k | f << "bdbox=(" << dim[1] << "x" << dim[0] << "<->" |
332 | 1.32k | << dim[3] << "x" << dim[2] << "),"; |
333 | 1.32k | ascFile.addPos(pos-12); |
334 | 1.32k | ascFile.addNote(f.str().c_str()); |
335 | 1.32k | } |
336 | 1.60k | return true; |
337 | 1.60k | } |
338 | | |
339 | | //! read the PGRA resource: the number of page graphic ? (id 20000) |
340 | | bool NisusWrtGraph::readPGRA(MWAWEntry const &entry) |
341 | 3.60k | { |
342 | 3.60k | if (!entry.valid() || entry.length() < 2) { |
343 | 1.13k | MWAW_DEBUG_MSG(("NisusWrtGraph::readPGRA: the entry is bad\n")); |
344 | 1.13k | return false; |
345 | 1.13k | } |
346 | 2.46k | if (entry.id() != 20000) { |
347 | 1.23k | MWAW_DEBUG_MSG(("NisusWrtGraph::readPGRA: the entry id %d is odd\n", entry.id())); |
348 | 1.23k | } |
349 | 2.46k | entry.setParsed(true); |
350 | 2.46k | MWAWInputStreamPtr input = m_mainParser->rsrcInput(); |
351 | 2.46k | libmwaw::DebugFile &ascFile = m_mainParser->rsrcAscii(); |
352 | 2.46k | long pos = entry.begin(); |
353 | 2.46k | input->seek(pos, librevenge::RVNG_SEEK_SET); |
354 | | |
355 | 2.46k | libmwaw::DebugStream f; |
356 | 2.46k | if (entry.id() != 20000) |
357 | 1.23k | f << "Entries(PGRA)[#" << entry.id() << "]:"; |
358 | 1.22k | else |
359 | 1.22k | f << "Entries(PGRA):"; |
360 | | // a number between 0 and 2: seems related to PICT20000 -> PICT20000+N-1 |
361 | 2.46k | m_state->m_maxPageGraphic = static_cast<int>(input->readLong(2)); |
362 | 2.46k | f << "lastPage[withGraphic]=" << m_state->m_maxPageGraphic << ","; |
363 | | |
364 | 2.46k | if (entry.length()!=2) |
365 | 1.25k | f << "###size=" << entry.length() << ","; |
366 | | |
367 | 2.46k | ascFile.addPos(pos-4); |
368 | 2.46k | ascFile.addNote(f.str().c_str()); |
369 | 2.46k | return true; |
370 | 3.60k | } |
371 | | |
372 | | //////////////////////////////////////////////////////////// |
373 | | // low level |
374 | | //////////////////////////////////////////////////////////// |
375 | | std::vector<NisusWrtGraphInternal::RSSOEntry> NisusWrtGraph::findRSSOEntry(MWAWInputStreamPtr input) const |
376 | 2.61k | { |
377 | 2.61k | std::vector<NisusWrtGraphInternal::RSSOEntry> listRSSO; |
378 | 2.61k | if (!input) { |
379 | 0 | MWAW_DEBUG_MSG(("NisusWrtGraph::findRSSOEntry: can not find the input\n")); |
380 | 0 | return listRSSO; |
381 | 0 | } |
382 | | |
383 | 2.61k | input->seek(10, librevenge::RVNG_SEEK_SET); |
384 | 2.61k | auto header = static_cast<int>(input->readULong(2)); |
385 | 2.61k | if (header==0x0011) { |
386 | 2.57k | if (input->readULong(2) != 0x2ff) |
387 | 19 | return listRSSO; |
388 | | // ok look like a pict2 |
389 | 2.57k | } |
390 | 34 | else if (header != 0x1101) |
391 | 34 | return listRSSO; |
392 | | |
393 | | // look for: 00a1006400104e495349000900b3000901dc01f90002 |
394 | 464k | while (!input->isEnd()) { |
395 | 462k | long pos = input->tell(); |
396 | 462k | auto val=static_cast<int>(input->readULong(4)); |
397 | 462k | int depl = 0; |
398 | 462k | if (val == 0x104e4953) ; |
399 | 462k | else if (val == 0x4e495349) depl=-1; |
400 | 460k | else if (val == 0x49534900) depl=-2; |
401 | 460k | else if (val == 0x53490009) depl=-3; |
402 | 460k | else continue; |
403 | 1.91k | input->seek(depl-8, librevenge::RVNG_SEEK_CUR); |
404 | 1.91k | bool ok = input->readULong(1) == 0xa1; |
405 | 1.91k | ok = ok && input->readULong(4) == 0x00640010; |
406 | 1.91k | ok = ok && input->readULong(4) == 0x4e495349; |
407 | 1.91k | ok = ok && input->readULong(2) == 0x0009; |
408 | 1.91k | if (!ok) { |
409 | 1.91k | input->seek(pos+4, librevenge::RVNG_SEEK_SET); |
410 | 1.91k | continue; |
411 | 1.91k | } |
412 | 0 | float dim[4]; |
413 | 0 | for (float &i : dim) i = float(input->readLong(2)); |
414 | 0 | if (input->isEnd()) break; |
415 | 0 | NisusWrtGraphInternal::RSSOEntry rsso; |
416 | 0 | rsso.m_id = static_cast<int>(input->readLong(2)); |
417 | 0 | if (input->isEnd()) break; |
418 | 0 | rsso.m_position=MWAWBox2f(MWAWVec2f(dim[1], dim[0]), MWAWVec2f(dim[3], dim[2])); |
419 | 0 | if (rsso.m_id > 0) |
420 | 0 | listRSSO.push_back(rsso); |
421 | 0 | else if (version() > 3) { |
422 | 0 | MWAW_DEBUG_MSG(("NisusWrtGraph::findRSSOEntry: find odd rsso id%d\n", rsso.m_id)); |
423 | 0 | } |
424 | 0 | } |
425 | | |
426 | 2.55k | return listRSSO; |
427 | 2.61k | } |
428 | | |
429 | | //////////////////////////////////////////////////////////// |
430 | | // send data |
431 | | //////////////////////////////////////////////////////////// |
432 | | bool NisusWrtGraph::sendPicture(int pictId, bool inPictRsrc, MWAWPosition pictPos) |
433 | 69.8k | { |
434 | 69.8k | MWAWRSRCParserPtr rsrcParser = m_mainParser->getRSRCParser(); |
435 | 69.8k | MWAWTextListenerPtr listener=m_parserState->m_textListener; |
436 | 69.8k | if (!listener) { |
437 | 0 | MWAW_DEBUG_MSG(("NisusWrtGraph::sendPicture: can not find the listener\n")); |
438 | 0 | return true; |
439 | 0 | } |
440 | 69.8k | std::map<int, MWAWEntry> &pictMap = inPictRsrc ? |
441 | 69.8k | m_state->m_idPictMap : m_state->m_idRssoMap; |
442 | 69.8k | if (pictMap.find(pictId) == pictMap.end()) { |
443 | 67.1k | if (version() <= 3 && !inPictRsrc) |
444 | 0 | return true; |
445 | 67.1k | MWAW_DEBUG_MSG(("NisusWrtGraph::sendPicture: can not find the picture\n")); |
446 | 67.1k | return false; |
447 | 67.1k | } |
448 | 2.67k | MWAWEntry &entry = pictMap.find(pictId)->second; |
449 | 2.67k | librevenge::RVNGBinaryData data; |
450 | 2.67k | bool ok = rsrcParser->parsePICT(entry, data) && data.size(); |
451 | 2.67k | if (!ok) { |
452 | 68 | MWAW_DEBUG_MSG(("NisusWrtGraph::sendPicture: can not read the picture\n")); |
453 | 68 | } |
454 | 2.67k | entry.setParsed(true); |
455 | 2.67k | if (!ok) return true; |
456 | | |
457 | 2.61k | std::vector<NisusWrtGraphInternal::RSSOEntry> listRSSO; |
458 | 2.61k | if (inPictRsrc) { |
459 | | // we must first look for RSSO entry |
460 | 2.61k | MWAWInputStreamPtr dataInput=MWAWInputStream::get(data,false); |
461 | 2.61k | if (dataInput) |
462 | 2.61k | listRSSO=findRSSOEntry(dataInput); |
463 | 2.61k | } |
464 | | |
465 | 2.61k | if (listRSSO.size() && (pictPos.m_anchorTo == MWAWPosition::Char || |
466 | 0 | pictPos.m_anchorTo == MWAWPosition::CharBaseLine)) { |
467 | | // we need to create a frame |
468 | 0 | MWAWPosition framePos(pictPos.origin(), pictPos.size(), librevenge::RVNG_POINT);; |
469 | 0 | framePos.setRelativePosition(MWAWPosition::Char, |
470 | 0 | MWAWPosition::XLeft, MWAWPosition::YTop); |
471 | 0 | framePos.m_wrapping = MWAWPosition::WBackground; |
472 | 0 | pictPos.setRelativePosition(MWAWPosition::Frame); |
473 | 0 | pictPos.setOrigin(MWAWVec2f(0,0)); |
474 | 0 | MWAWSubDocumentPtr subdoc |
475 | 0 | (new NisusWrtGraphInternal::SubDocument(*this, m_mainParser->rsrcInput(), pictId, pictPos)); |
476 | 0 | listener->insertTextBox(framePos, subdoc); |
477 | 0 | return true; |
478 | 0 | } |
479 | | // first the picture |
480 | 2.61k | listener->insertPicture(pictPos, MWAWEmbeddedObject(data, "image/pict")); |
481 | | // then the author possible picture |
482 | 2.61k | pictPos.setClippingPosition(MWAWVec2f(), MWAWVec2f()); |
483 | 2.61k | for (auto const &rssoEntry : listRSSO) { |
484 | 0 | MWAWPosition rssoPos(pictPos); |
485 | 0 | rssoPos.setOrigin(pictPos.origin()+rssoEntry.m_position.min()); |
486 | 0 | rssoPos.setSize(rssoEntry.m_position.size()); |
487 | 0 | sendPicture(rssoEntry.m_id, false, rssoPos); |
488 | 0 | } |
489 | 2.61k | return true; |
490 | 2.61k | } |
491 | | |
492 | | bool NisusWrtGraph::sendPageGraphics() |
493 | 3.62k | { |
494 | 3.62k | MWAWRSRCParserPtr rsrcParser = m_mainParser->getRSRCParser(); |
495 | 3.62k | if (!m_parserState->m_textListener) { |
496 | 0 | MWAW_DEBUG_MSG(("NisusWrtGraph::sendPageGraphics: can not find the listener\n")); |
497 | 0 | return true; |
498 | 0 | } |
499 | 3.62k | MWAWVec2f LT = 72.f*m_mainParser->getPageLeftTop(); |
500 | 901k | for (int i = 0; i < m_state->m_maxPageGraphic; i++) { |
501 | 898k | if (m_state->m_idPictMap.find(20000+i)==m_state->m_idPictMap.end()) |
502 | 898k | continue; |
503 | 20 | MWAWEntry &entry = m_state->m_idPictMap.find(20000+i)->second; |
504 | 20 | librevenge::RVNGBinaryData data; |
505 | 20 | if (!rsrcParser->parsePICT(entry, data) || !data.size()) { |
506 | 19 | MWAW_DEBUG_MSG(("NisusWrtGraph::sendPageGraphics: can not read the file picture\n")); |
507 | 19 | continue; |
508 | 19 | } |
509 | 1 | MWAWInputStreamPtr dataInput=MWAWInputStream::get(data, false); |
510 | 1 | if (!dataInput) continue; |
511 | 1 | dataInput->seek(0, librevenge::RVNG_SEEK_SET); |
512 | 1 | MWAWBox2f box; |
513 | 1 | if (MWAWPictData::check(dataInput, static_cast<int>(data.size()), box) == MWAWPict::MWAW_R_BAD) { |
514 | 0 | MWAW_DEBUG_MSG(("NisusWrtGraph::sendPageGraphics: can not determine the picture type\n")); |
515 | 0 | continue; |
516 | 0 | } |
517 | 1 | MWAWPosition pictPos(box.min()+LT, box.size(), librevenge::RVNG_POINT); |
518 | 1 | pictPos.setRelativePosition(MWAWPosition::Page); |
519 | 1 | pictPos.m_wrapping = MWAWPosition::WBackground; |
520 | 1 | pictPos.setPage(i+1); |
521 | 1 | sendPicture(20000+i, true, pictPos); |
522 | 1 | } |
523 | 3.62k | return true; |
524 | 3.62k | } |
525 | | |
526 | | void NisusWrtGraph::flushExtra() |
527 | 0 | { |
528 | 0 | for (auto const &it : m_state->m_idPictMap) { |
529 | 0 | MWAWEntry const &entry = it.second; |
530 | 0 | if (entry.isParsed()) continue; |
531 | 0 | MWAW_DEBUG_MSG(("NisusWrtGraph::sendPicture: picture unparsed: %d\n", entry.id())); |
532 | 0 | MWAWPosition pictPos(MWAWVec2f(0,0), MWAWVec2f(1.,1.)); |
533 | 0 | pictPos.setRelativePosition(MWAWPosition::Char); |
534 | 0 | sendPicture(entry.id(), true, pictPos); |
535 | 0 | } |
536 | 0 | for (auto const &it : m_state->m_idRssoMap) { |
537 | 0 | MWAWEntry const &entry = it.second; |
538 | 0 | if (entry.isParsed()) continue; |
539 | 0 | MWAW_DEBUG_MSG(("NisusWrtGraph::sendPicture: rsso picture unparsed: %d\n", entry.id())); |
540 | 0 | MWAWPosition pictPos(MWAWVec2f(0,0), MWAWVec2f(1.,1.)); |
541 | 0 | pictPos.setRelativePosition(MWAWPosition::Char); |
542 | 0 | sendPicture(entry.id(), false, pictPos); |
543 | 0 | } |
544 | 0 | } |
545 | | // vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab: |