Coverage Report

Created: 2026-03-12 06:42

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libmwaw/src/lib/BeagleWksDBParser.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 <set>
39
#include <sstream>
40
41
#include <librevenge/librevenge.h>
42
43
#include "MWAWCell.hxx"
44
#include "MWAWFontConverter.hxx"
45
#include "MWAWHeader.hxx"
46
#include "MWAWList.hxx"
47
#include "MWAWParagraph.hxx"
48
#include "MWAWPosition.hxx"
49
#include "MWAWPrinter.hxx"
50
#include "MWAWRSRCParser.hxx"
51
#include "MWAWSpreadsheetListener.hxx"
52
#include "MWAWSubDocument.hxx"
53
54
#include "BeagleWksStructManager.hxx"
55
56
#include "BeagleWksDBParser.hxx"
57
58
/** Internal: the structures of a BeagleWksDBParser */
59
namespace BeagleWksDBParserInternal
60
{
61
//! Internal: the cell of a BeagleWksDBParser
62
struct Cell final : public MWAWCell {
63
  //! the cell type
64
  enum Type { Text, Number, Date, Time, Picture, Formula, Memo, Unknown };
65
  //! constructor
66
  explicit Cell(MWAWVec2i pos=MWAWVec2i(0,0))
67
65.9k
    : MWAWCell()
68
65.9k
    , m_type(Unknown)
69
65.9k
    , m_name("")
70
65.9k
    , m_content()
71
65.9k
    , m_formula(-1)
72
65.9k
    , m_pictureId(-1)
73
65.9k
    , m_isEmpty(false)
74
65.9k
  {
75
65.9k
    setPosition(pos);
76
65.9k
  }
77
83.2k
  Cell(Cell const &)=default;
78
  //! destructor
79
  ~Cell() final;
80
  //! returns true if the field has no content
81
  bool empty() const
82
65.2k
  {
83
65.2k
    return m_content.empty() && (m_type!=Picture || m_pictureId<=0);
84
65.2k
  }
85
  //! the cell type
86
  Type m_type;
87
  //! the field name
88
  std::string m_name;
89
  //! the cell content
90
  MWAWCellContent m_content;
91
  //! the formula id
92
  int m_formula;
93
  //! picture id
94
  int m_pictureId;
95
  //! flag to know if the cell is empty
96
  bool m_isEmpty;
97
};
98
99
Cell::~Cell()
100
149k
{
101
149k
}
102
103
//! Internal: the spreadsheet of a BeagleWksDBParser
104
struct Database {
105
  //! constructor
106
  Database()
107
14.5k
    : m_numFields(0)
108
14.5k
    , m_fields()
109
14.5k
    , m_records()
110
14.5k
    , m_memos()
111
14.5k
    , m_name("Sheet0")
112
14.5k
  {
113
14.5k
  }
114
  //! convert the m_widthCols, m_heightRows in a vector of of point size
115
  static std::vector<float> convertInPoint(std::vector<int> const &list, float defSize)
116
0
  {
117
0
    size_t numElt = list.size();
118
0
    std::vector<float> res;
119
0
    res.resize(numElt);
120
0
    for (size_t i = 0; i < numElt; i++) {
121
0
      if (list[i] < 0) res[i] = defSize;
122
0
      else res[i] = float(list[i]);
123
0
    }
124
0
    return res;
125
0
  }
126
  //! update a field with the record data
127
  void updateWithContent(Cell &cell, MWAWVec2i const &pos, MWAWCellContent const &content) const;
128
  //! the number of rows
129
  int m_numFields;
130
  //! the list of fields
131
  std::vector<Cell> m_fields;
132
  //! the list of not empty cells (one list by row )
133
  std::vector<std::vector<MWAWCellContent> > m_records;
134
  /** the list of memo strings entry */
135
  std::vector<MWAWEntry> m_memos;
136
  //! the database name
137
  std::string m_name;
138
};
139
140
void Database::updateWithContent(Cell &cell, MWAWVec2i const &pos, MWAWCellContent const &content) const
141
65.2k
{
142
65.2k
  cell.setPosition(pos);
143
65.2k
  switch (cell.m_type) {
144
11.4k
  case Cell::Formula:
145
11.4k
    cell.m_content.m_contentType=MWAWCellContent::C_FORMULA;
146
11.4k
    break;
147
2.90k
  case Cell::Number:
148
23.1k
  case Cell::Date:
149
23.3k
  case Cell::Time:
150
31.9k
  case Cell::Text:
151
31.9k
    cell.m_content=content;
152
31.9k
    break;
153
3.99k
  case Cell::Memo: {
154
3.99k
    if (!content.isValueSet()) break;
155
1.03k
    auto id=int(0.1+content.m_value);
156
1.03k
    if (id<1 || id>static_cast<int>(m_memos.size())) {
157
1.03k
      MWAW_DEBUG_MSG(("BeagleWksDBParserInternal::Database::updateWithContent: can not retrieve the memo content\n"));
158
1.03k
      break;
159
1.03k
    }
160
0
    cell.m_content.m_contentType=MWAWCellContent::C_TEXT;
161
0
    cell.m_content.m_textEntry=m_memos[size_t(id-1)];
162
0
    break;
163
1.03k
  }
164
105
  case Cell::Picture:
165
105
    cell.m_pictureId=int(0.1+content.m_value);
166
105
    break;
167
#if !defined(__clang__)
168
  default:
169
#endif
170
17.7k
  case Cell::Unknown:
171
17.7k
    break;
172
65.2k
  }
173
65.2k
  auto const &format=cell.getFormat();
174
  // change the reference date from 1/1/1904 to 1/1/1900
175
65.2k
  if (format.m_format==MWAWCell::F_DATE && cell.m_content.isValueSet())
176
10
    cell.m_content.setValue(cell.m_content.m_value+1460.);
177
  // and try to update the 1D formula in 2D
178
65.2k
  auto &formula=cell.m_content.m_formula;
179
65.2k
  for (auto &instr : formula) {
180
0
    if (instr.m_type==MWAWCellContent::FormulaInstruction::F_Cell) {
181
0
      --instr.m_position[0][0];
182
0
      instr.m_position[0][1]=pos[1];
183
0
    }
184
0
    else if (instr.m_type==MWAWCellContent::FormulaInstruction::F_CellList) {
185
0
      --instr.m_position[0][0];
186
0
      --instr.m_position[1][0];
187
0
      instr.m_position[0][1]=instr.m_position[1][1]=pos[1];
188
0
    }
189
0
  }
190
65.2k
}
191
192
////////////////////////////////////////
193
//! Internal: the state of a BeagleWksDBParser
194
struct State {
195
  //! constructor
196
  State()
197
14.5k
    : m_databaseBegin(-1)
198
14.5k
    , m_database()
199
14.5k
    , m_typeEntryMap()
200
14.5k
    , m_actPage(0)
201
14.5k
    , m_numPages(0)
202
14.5k
    , m_headerHeight(0)
203
14.5k
    , m_footerHeight(0)
204
14.5k
  {
205
14.5k
  }
206
  /** the database begin position */
207
  long m_databaseBegin;
208
  /** the database */
209
  Database m_database;
210
  /** the type entry map */
211
  std::multimap<std::string, MWAWEntry> m_typeEntryMap;
212
  int m_actPage /** the actual page */, m_numPages /** the number of page of the final document */;
213
214
  int m_headerHeight /** the header height if known */,
215
      m_footerHeight /** the footer height if known */;
216
};
217
218
////////////////////////////////////////
219
//! Internal: the subdocument of a BeagleWksDBParser
220
class SubDocument final : public MWAWSubDocument
221
{
222
public:
223
  SubDocument(BeagleWksDBParser &pars, MWAWInputStreamPtr const &input, MWAWEntry const &entry)
224
81
    : MWAWSubDocument(&pars, input, entry)
225
81
  {
226
81
  }
227
228
  //! destructor
229
0
  ~SubDocument() final {}
230
231
  //! operator!=
232
  bool operator!=(MWAWSubDocument const &doc) const final
233
0
  {
234
0
    return MWAWSubDocument::operator!=(doc);
235
0
  }
236
237
  //! the parser function
238
  void parse(MWAWListenerPtr &listener, libmwaw::SubDocumentType type) final;
239
240
protected:
241
private:
242
  SubDocument(SubDocument const &orig) = delete;
243
  SubDocument &operator=(SubDocument const &orig) = delete;
244
};
245
246
void SubDocument::parse(MWAWListenerPtr &listener, libmwaw::SubDocumentType /*type*/)
247
81
{
248
81
  if (!listener.get()) {
249
0
    MWAW_DEBUG_MSG(("BeagleWksDBParserInternal::SubDocument::parse: no listener\n"));
250
0
    return;
251
0
  }
252
81
  auto *parser=dynamic_cast<BeagleWksDBParser *>(m_parser);
253
81
  if (!parser) {
254
0
    MWAW_DEBUG_MSG(("BeagleWksDBParserInternal::SubDocument::parse: can not find the parser\n"));
255
0
    return;
256
0
  }
257
81
  long pos = m_input->tell();
258
81
  listener->setFont(MWAWFont(3,12)); // fixme
259
81
  parser->sendText(m_zone, true);
260
81
  m_input->seek(pos, librevenge::RVNG_SEEK_SET);
261
81
}
262
263
}
264
265
266
////////////////////////////////////////////////////////////
267
// constructor/destructor, ...
268
////////////////////////////////////////////////////////////
269
BeagleWksDBParser::BeagleWksDBParser(MWAWInputStreamPtr const &input, MWAWRSRCParserPtr const &rsrcParser, MWAWHeader *header)
270
7.01k
  : MWAWSpreadsheetParser(input, rsrcParser, header)
271
7.01k
  , m_state()
272
7.01k
  , m_structureManager()
273
7.01k
{
274
7.01k
  init();
275
7.01k
}
276
277
BeagleWksDBParser::~BeagleWksDBParser()
278
7.01k
{
279
7.01k
}
280
281
void BeagleWksDBParser::init()
282
7.01k
{
283
7.01k
  resetSpreadsheetListener();
284
7.01k
  setAsciiName("main-1");
285
286
7.01k
  m_state.reset(new BeagleWksDBParserInternal::State);
287
7.01k
  m_structureManager.reset(new BeagleWksStructManager(getParserState()));
288
289
  // reduce the margin (in case, the page is not defined)
290
7.01k
  getPageSpan().setMargins(0.1);
291
7.01k
}
292
293
MWAWInputStreamPtr BeagleWksDBParser::rsrcInput()
294
0
{
295
0
  return getRSRCParser()->getInput();
296
0
}
297
298
libmwaw::DebugFile &BeagleWksDBParser::rsrcAscii()
299
0
{
300
0
  return getRSRCParser()->ascii();
301
0
}
302
303
////////////////////////////////////////////////////////////
304
// position and height
305
////////////////////////////////////////////////////////////
306
MWAWVec2f BeagleWksDBParser::getPageLeftTop() const
307
0
{
308
0
  return MWAWVec2f(float(getPageSpan().getMarginLeft()),
309
0
                   float(getPageSpan().getMarginTop()+m_state->m_headerHeight/72.0));
310
0
}
311
312
////////////////////////////////////////////////////////////
313
// the parser
314
////////////////////////////////////////////////////////////
315
void BeagleWksDBParser::parse(librevenge::RVNGSpreadsheetInterface *docInterface)
316
548
{
317
548
  if (!getInput().get() || !checkHeader(nullptr))  throw(libmwaw::ParseException());
318
548
  bool ok = false;
319
548
  try {
320
    // create the asciiFile
321
548
    ascii().setStream(getInput());
322
548
    ascii().open(asciiName());
323
324
548
    checkHeader(nullptr);
325
548
    ok = createZones();
326
548
    if (ok) {
327
297
      createDocument(docInterface);
328
297
      sendDatabase();
329
297
    }
330
548
    ascii().reset();
331
548
  }
332
548
  catch (...) {
333
0
    MWAW_DEBUG_MSG(("BeagleWksDBParser::parse: exception catched when parsing\n"));
334
0
    ok = false;
335
0
  }
336
337
548
  resetSpreadsheetListener();
338
548
  if (!ok) throw(libmwaw::ParseException());
339
548
}
340
341
////////////////////////////////////////////////////////////
342
// create the document
343
////////////////////////////////////////////////////////////
344
void BeagleWksDBParser::createDocument(librevenge::RVNGSpreadsheetInterface *documentInterface)
345
297
{
346
297
  if (!documentInterface) return;
347
297
  if (getSpreadsheetListener()) {
348
0
    MWAW_DEBUG_MSG(("BeagleWksDBParser::createDocument: listener already exist\n"));
349
0
    return;
350
0
  }
351
352
  // update the page
353
297
  m_state->m_actPage = 0;
354
355
  // create the page list
356
297
  int numPages = 1;
357
297
  m_state->m_numPages = numPages;
358
359
297
  MWAWEntry header, footer;
360
297
  m_structureManager->getHeaderFooterEntries(header,footer);
361
297
  std::vector<MWAWPageSpan> pageList;
362
297
  MWAWPageSpan ps(getPageSpan());
363
297
  if (header.valid()) {
364
39
    std::shared_ptr<BeagleWksDBParserInternal::SubDocument> subDoc
365
39
    (new BeagleWksDBParserInternal::SubDocument(*this, getInput(), header));
366
39
    MWAWHeaderFooter hf(MWAWHeaderFooter::HEADER, MWAWHeaderFooter::ALL);
367
39
    hf.m_subDocument=subDoc;
368
39
    ps.setHeaderFooter(hf);
369
39
  }
370
297
  if (footer.valid()) {
371
42
    std::shared_ptr<BeagleWksDBParserInternal::SubDocument> subDoc
372
42
    (new BeagleWksDBParserInternal::SubDocument(*this, getInput(), footer));
373
42
    MWAWHeaderFooter hf(MWAWHeaderFooter::FOOTER, MWAWHeaderFooter::ALL);
374
42
    hf.m_subDocument=subDoc;
375
42
    ps.setHeaderFooter(hf);
376
42
  }
377
297
  ps.setPageSpan(numPages);
378
297
  pageList.push_back(ps);
379
380
297
  MWAWSpreadsheetListenerPtr listen(new MWAWSpreadsheetListener(*getParserState(), pageList, documentInterface));
381
297
  setSpreadsheetListener(listen);
382
297
  listen->startDocument();
383
297
}
384
385
386
////////////////////////////////////////////////////////////
387
//
388
// Intermediate level
389
//
390
////////////////////////////////////////////////////////////
391
bool BeagleWksDBParser::createZones()
392
548
{
393
548
  readRSRCZones();
394
548
  MWAWInputStreamPtr input = getInput();
395
548
  if (input->seek(66, librevenge::RVNG_SEEK_SET) || !readPrintInfo())
396
0
    return false;
397
548
  long pos = input->tell();
398
548
  if (!input->checkPosition(pos+70)) {
399
28
    MWAW_DEBUG_MSG(("BeagleWksDBParser::createZones: the file can not contains Zones\n"));
400
28
    return false;
401
28
  }
402
403
  // now read the list of zones
404
520
  libmwaw::DebugStream f;
405
520
  input->seek(pos, librevenge::RVNG_SEEK_SET);
406
520
  f << "Entries(Zones):";
407
4.04k
  for (int i=0; i<7; ++i) { // checkme: at least 2 zones, maybe 7
408
3.54k
    MWAWEntry entry;
409
3.54k
    entry.setBegin(input->readLong(4));
410
3.54k
    entry.setLength(input->readLong(4));
411
3.54k
    entry.setId(static_cast<int>(input->readLong(2)));
412
3.54k
    if (entry.length()==0) continue;
413
1.91k
    entry.setType(i==1?"Frame":"Unknown");
414
1.91k
    f << entry.type() << "[" << entry.id() << "]="
415
1.91k
      << std::hex << entry.begin() << "<->" << entry.end() << ",";
416
1.91k
    if (!entry.valid() || !input->checkPosition(entry.end())) {
417
1.65k
      f << "###";
418
1.65k
      if (i<2) {
419
17
        MWAW_DEBUG_MSG(("BeagleWksDBParser::createZones: can not read the header zone, stop\n"));
420
17
        ascii().addPos(pos);
421
17
        ascii().addNote(f.str().c_str());
422
17
        return false;
423
17
      }
424
1.63k
      MWAW_DEBUG_MSG(("BeagleWksDBParser::createZones: can not zones entry %d\n",i));
425
1.63k
      continue;
426
1.65k
    }
427
266
    m_state->m_typeEntryMap.insert
428
266
    (std::multimap<std::string, MWAWEntry>::value_type(entry.type(),entry));
429
266
  }
430
503
  ascii().addPos(pos);
431
503
  ascii().addNote(f.str().c_str());
432
433
  // now parse the different zones
434
503
  auto it=m_state->m_typeEntryMap.find("FontNames");
435
503
  if (it!=m_state->m_typeEntryMap.end())
436
503
    m_structureManager->readFontNames(it->second);
437
503
  it=m_state->m_typeEntryMap.find("Frame");
438
503
  if (it!=m_state->m_typeEntryMap.end())
439
11
    m_structureManager->readFrame(it->second);
440
441
  // now parse the different zones
442
767
  for (auto const &eIt : m_state->m_typeEntryMap) {
443
767
    MWAWEntry const &entry=eIt.second;
444
767
    if (entry.isParsed())
445
231
      continue;
446
536
    f.str("");
447
536
    f << "Entries(" << entry.type() << ")[" << entry.id() << "]:";
448
536
    ascii().addPos(entry.begin());
449
536
    ascii().addNote(f.str().c_str());
450
536
    ascii().addPos(entry.end());
451
536
    ascii().addNote("_");
452
536
  }
453
454
503
  input->seek(m_state->m_databaseBegin, librevenge::RVNG_SEEK_SET);
455
503
  pos = input->tell();
456
503
  if (!m_structureManager->readDocumentInfo())
457
371
    input->seek(pos, librevenge::RVNG_SEEK_SET);
458
503
  pos = input->tell();
459
503
  if (!m_structureManager->readDocumentPreferences())
460
419
    input->seek(pos, librevenge::RVNG_SEEK_SET);
461
503
  if (!readDatabase())
462
401
    return m_state->m_database.m_records.size()!=0;
463
102
  pos=input->tell();
464
102
  auto N=static_cast<int>(input->readULong(2));
465
102
  if (N==0) {
466
28
    ascii().addPos(pos);
467
28
    ascii().addNote("_");
468
28
  }
469
74
  else {
470
    // unsure about the parsing of this zone: find N=2+000602000d02
471
74
    f.str("");
472
74
    f << "Entries(UnknZone0):";
473
74
    if (!input->checkPosition(pos+2+3*N)) {
474
55
      MWAW_DEBUG_MSG(("BeagleWksDBParser::createZones: can not read UnkZone0\n"));
475
55
      f << "###";
476
55
      ascii().addPos(pos);
477
55
      ascii().addNote(f.str().c_str());
478
55
      return true;
479
55
    }
480
19
    f << "unkn0=[";
481
17.0k
    for (int i=0; i< N; ++i)
482
17.0k
      f << input->readLong(2) << ",";
483
19
    f << "],";
484
19
    f << "unkn1=[";
485
17.0k
    for (int i=0; i< N; ++i)
486
17.0k
      f << input->readLong(1) << ",";
487
19
    f << "],";
488
19
  }
489
47
  ascii().addPos(pos);
490
47
  ascii().addNote(f.str().c_str());
491
47
  pos=input->tell();
492
47
  N=static_cast<int>(input->readULong(2));
493
47
  if (N==0) {
494
27
    ascii().addPos(pos);
495
27
    ascii().addNote("_");
496
27
  }
497
20
  else {
498
20
    MWAW_DEBUG_MSG(("BeagleWksDBParser::createZones: find data in UnkZone1\n"));
499
20
    f.str("");
500
20
    f << "Entries(UnknZone1):###";
501
20
    ascii().addPos(pos);
502
20
    ascii().addNote(f.str().c_str());
503
20
    return true;
504
20
  }
505
506
27
  pos=input->tell();
507
27
  f.str("");
508
27
  f << "Entries(Memo):";
509
27
  auto dSz=static_cast<long>(input->readULong(2));
510
27
  long endPos=pos+2+dSz;
511
27
  N=static_cast<int>(input->readULong(2));
512
27
  if (dSz<2+2*long(N) || !input->checkPosition(endPos)) {
513
17
    MWAW_DEBUG_MSG(("BeagleWksDBParser::createZones: find data in UnkZone1\n"));
514
17
    f << "###";
515
17
    ascii().addPos(pos);
516
17
    ascii().addNote(f.str().c_str());
517
17
    return true;
518
17
  }
519
10
  ascii().addPos(pos);
520
10
  ascii().addNote(f.str().c_str());
521
2.28k
  for (int i=0; i<N; ++i) {
522
2.27k
    pos=input->tell();
523
2.27k
    f.str("");
524
2.27k
    f << "Memo-"<< i << ":";
525
2.27k
    auto val=static_cast<int>(input->readLong(1));
526
2.27k
    if (val) f << "f0=" << val << ",";
527
2.27k
    auto sSz=static_cast<int>(input->readULong(1));
528
2.27k
    if (pos+2+sSz>endPos) {
529
2
      MWAW_DEBUG_MSG(("BeagleWksDBParser::createZones: can not read a memo\n"));
530
2
      f << "###";
531
2
      ascii().addPos(pos);
532
2
      ascii().addNote(f.str().c_str());
533
2
      return true;
534
2
    }
535
2.27k
    MWAWEntry memo;
536
2.27k
    memo.setBegin(input->tell());
537
2.27k
    memo.setLength(sSz);
538
2.27k
    m_state->m_database.m_memos.push_back(memo);
539
2.27k
    std::string text("");
540
27.5k
    for (int c=0; c<sSz; ++c) text+=char(input->readULong(1));
541
2.27k
    f << text << ",";
542
2.27k
    ascii().addPos(pos);
543
2.27k
    ascii().addNote(f.str().c_str());
544
2.27k
  }
545
8
  input->seek(endPos, librevenge::RVNG_SEEK_SET);
546
547
8
  pos=input->tell();
548
8
  f.str("");
549
8
  f << "Entries(UnknZone2):";
550
8
  dSz=long(input->readULong(2));
551
8
  endPos=pos+6+dSz;
552
8
  auto val=static_cast<int>(input->readULong(2));
553
8
  if ((dSz%2) || val!=0xeb || !input->checkPosition(endPos)) {
554
4
    MWAW_DEBUG_MSG(("BeagleWksDBParser::createZones: can not read zone2\n"));
555
4
    f << "###";
556
4
    ascii().addPos(pos);
557
4
    ascii().addNote(f.str().c_str());
558
4
    return true;
559
4
  }
560
4
  N=static_cast<int>(input->readULong(2));
561
4
  if (N) f << "N=" << N << ",";
562
4
  if (dSz==2*N) {
563
4
    f << "unkn=[";
564
4
    for (int i=0; i<N; ++i)
565
0
      f << input->readLong(2) << ",";
566
4
    f << "],";
567
4
  }
568
0
  else
569
0
    f << "###,";
570
4
  input->seek(endPos, librevenge::RVNG_SEEK_SET);
571
4
  ascii().addPos(pos);
572
4
  ascii().addNote(f.str().c_str());
573
574
  /* now the formula zone */
575
4
  auto &fields=m_state->m_database.m_fields;
576
4
  int n=0;
577
16
  for (auto &field : fields) {
578
16
    ++n;
579
16
    if (field.m_type!=BeagleWksDBParserInternal::Cell::Formula)
580
16
      continue;
581
0
    pos=input->tell();
582
0
    f.str("");
583
0
    f << "Entries(Formula):";
584
0
    auto id=static_cast<int>(input->readLong(2));
585
0
    if (id!=n-1) f << "#id=" << id << ",";
586
0
    dSz=static_cast<int>(input->readULong(2));
587
0
    endPos=pos+4+dSz;
588
0
    if (dSz==0 || !input->checkPosition(pos+4+dSz)) {
589
0
      MWAW_DEBUG_MSG(("BeagleWksDBParser::createZones: can not read a formula\n"));
590
0
      f << "###";
591
0
      ascii().addPos(pos);
592
0
      ascii().addNote(f.str().c_str());
593
0
      return true;
594
0
    }
595
0
    std::vector<MWAWCellContent::FormulaInstruction> formula;
596
0
    std::string error("");
597
0
    if (m_structureManager->readFormula(endPos, MWAWVec2i(id,9), formula, error)) {
598
0
      field.m_content.m_formula = formula;
599
0
      field.m_content.m_contentType = MWAWCellContent::C_FORMULA;
600
0
    }
601
0
    else
602
0
      f << "###";
603
0
    for (auto const &fo : formula)
604
0
      f << fo;
605
0
    input->seek(endPos, librevenge::RVNG_SEEK_SET);
606
0
    ascii().addPos(pos);
607
0
    ascii().addNote(f.str().c_str());
608
0
  }
609
  /*
610
    now find
611
    000000000001000100000000 or
612
    000200000003000100020000
613
   */
614
4
  ascii().addPos(input->tell());
615
4
  ascii().addNote("Entries(ZoneEnd)");
616
4
  return true;
617
4
}
618
619
bool BeagleWksDBParser::readRSRCZones()
620
548
{
621
548
  MWAWRSRCParserPtr rsrcParser = getRSRCParser();
622
548
  if (!rsrcParser)
623
535
    return true;
624
625
13
  auto const &entryMap = rsrcParser->getEntriesMap();
626
  // the 1 zone
627
13
  char const *zNames[] = {"wPos", "DMPF" };
628
39
  for (int z = 0; z < 2; ++z) {
629
26
    auto it = entryMap.lower_bound(zNames[z]);
630
31
    while (it != entryMap.end()) {
631
15
      if (it->first != zNames[z])
632
10
        break;
633
5
      MWAWEntry const &entry = it++->second;
634
5
      switch (z) {
635
5
      case 0: // 1001
636
5
        m_structureManager->readwPos(entry);
637
5
        break;
638
0
      case 1: // find in one file with id=4661 6a1f 4057
639
0
        m_structureManager->readFontStyle(entry);
640
0
        break;
641
      /* find also
642
         - edpt: see sendPicture
643
         - DMPP: the paragraph style
644
         - sect and alis: position?, alis=filesystem alias(dir, filename, path...)
645
      */
646
0
      default:
647
0
        break;
648
5
      }
649
5
    }
650
26
  }
651
13
  return true;
652
13
}
653
654
////////////////////////////////////////////////////////////
655
// read the print info
656
////////////////////////////////////////////////////////////
657
bool BeagleWksDBParser::readPrintInfo()
658
2.23k
{
659
2.23k
  MWAWInputStreamPtr input = getInput();
660
2.23k
  long pos = input->tell();
661
2.23k
  if (!input->checkPosition(pos+0x70))
662
60
    return false;
663
664
2.17k
  libmwaw::DebugStream f;
665
  // print info
666
2.17k
  libmwaw::PrinterInfo info;
667
2.17k
  if (!info.read(input)) return false;
668
2.13k
  f << "Entries(PrintInfo):"<< info;
669
670
2.13k
  MWAWVec2i paperSize = info.paper().size();
671
2.13k
  MWAWVec2i pageSize = info.page().size();
672
2.13k
  if (pageSize.x() <= 0 || pageSize.y() <= 0 ||
673
2.07k
      paperSize.x() <= 0 || paperSize.y() <= 0) return false;
674
675
  // define margin from print info
676
2.01k
  MWAWVec2i lTopMargin= -1 * info.paper().pos(0);
677
2.01k
  MWAWVec2i rBotMargin=info.paper().pos(1) - info.page().pos(1);
678
679
  // move margin left | top
680
2.01k
  int decalX = lTopMargin.x() > 14 ? lTopMargin.x()-14 : 0;
681
2.01k
  int decalY = lTopMargin.y() > 14 ? lTopMargin.y()-14 : 0;
682
2.01k
  lTopMargin -= MWAWVec2i(decalX, decalY);
683
2.01k
  rBotMargin += MWAWVec2i(decalX, decalY);
684
685
  // decrease right | bottom
686
2.01k
  int rightMarg = rBotMargin.x() -10;
687
2.01k
  if (rightMarg < 0) rightMarg=0;
688
2.01k
  int botMarg = rBotMargin.y() -50;
689
2.01k
  if (botMarg < 0) botMarg=0;
690
691
2.01k
  getPageSpan().setMarginTop(lTopMargin.y()/72.0);
692
2.01k
  getPageSpan().setMarginBottom(botMarg/72.0);
693
2.01k
  getPageSpan().setMarginLeft(lTopMargin.x()/72.0);
694
2.01k
  getPageSpan().setMarginRight(rightMarg/72.0);
695
2.01k
  getPageSpan().setFormLength(paperSize.y()/72.);
696
2.01k
  getPageSpan().setFormWidth(paperSize.x()/72.);
697
698
2.01k
  ascii().addPos(pos);
699
2.01k
  ascii().addNote(f.str().c_str());
700
2.01k
  input->seek(pos+0x78, librevenge::RVNG_SEEK_SET);
701
2.01k
  if (long(input->tell()) != pos+0x78) {
702
0
    MWAW_DEBUG_MSG(("BeagleWksDBParser::readPrintInfo: file is too short\n"));
703
0
    return false;
704
0
  }
705
2.01k
  ascii().addPos(input->tell());
706
707
2.01k
  return true;
708
2.01k
}
709
710
////////////////////////////////////////////////////////////
711
// database
712
////////////////////////////////////////////////////////////
713
bool BeagleWksDBParser::readDatabase()
714
503
{
715
503
  if (!readFields() || !readLayouts()) return false;
716
717
322
  MWAWInputStreamPtr &input= getInput();
718
322
  long pos=input->tell();
719
322
  if (!input->checkPosition(pos+6)) {
720
0
    MWAW_DEBUG_MSG(("BeagleWksDBParser::readDatabase: can not find the database header\n"));
721
0
    return false;
722
0
  }
723
322
  libmwaw::DebugStream f;
724
322
  f << "Entries(DbRow):";
725
322
  int val;
726
966
  for (int i=0; i<2; ++i) { // f0=0|1
727
644
    val =static_cast<int>(input->readLong(2));
728
644
    if (val) f << "f" << i << "=" << val << ",";
729
644
  }
730
322
  val =static_cast<int>(input->readLong(2));
731
322
  if (val!=7) f << "f2=" << val << ",";
732
322
  auto N=static_cast<int>(input->readLong(2));
733
322
  f << "N=" << N << ",";
734
322
  val =static_cast<int>(input->readLong(2));
735
322
  if (val) f << "f3=" << val << ",";
736
322
  ascii().addPos(pos);
737
322
  ascii().addNote(f.str().c_str());
738
739
6.36k
  for (int i=0; i<=N; ++i) {
740
6.23k
    if (!readRow()) return false;
741
6.23k
  }
742
743
124
  pos=input->tell();
744
124
  f.str("");
745
124
  f << "Entries(DbFld):";
746
124
  val =static_cast<int>(input->readLong(2));
747
124
  if (val) f << "f0=" << val << ",";
748
124
  N=static_cast<int>(input->readULong(2));
749
124
  f << "N=" << N << ",";
750
124
  val =static_cast<int>(input->readLong(2));
751
124
  if (val) f << "f1=" << val << ",";
752
124
  auto dSz =static_cast<int>(input->readULong(2));
753
124
  f << "dSz=" << dSz << ",";
754
124
  if (dSz<14 || dSz>(input->size()-pos-8)/(N+1)) {
755
22
    MWAW_DEBUG_MSG(("BeagleWksDBParser::readDatabase: can not find the database field format\n"));
756
22
    f << "###";
757
22
    ascii().addPos(pos);
758
22
    ascii().addNote(f.str().c_str());
759
22
    return false;
760
22
  }
761
102
  ascii().addPos(pos);
762
102
  ascii().addNote(f.str().c_str());
763
764
102
  auto &database=m_state->m_database;
765
102
  size_t numFields=database.m_fields.size();
766
102
  if (N+1>static_cast<int>(numFields)) {
767
97
    MWAW_DEBUG_MSG(("BeagleWksDBParser::readDatabase: the number of field seems too small, must increase them\n"));
768
97
    database.m_fields.resize(size_t(N+1));
769
97
  }
770
102
  std::string extra("");
771
58.6k
  for (int i=0; i<=N; ++i) {
772
58.5k
    pos=input->tell();
773
58.5k
    f.str("");
774
58.5k
    f << "DbFld" << i << ":";
775
58.5k
    val=static_cast<int>(input->readULong(2));
776
58.5k
    if (val!=1) f << "f0=" << val << ",";
777
58.5k
    val=static_cast<int>(input->readLong(2));
778
58.5k
    if (val!=0x4b) f << "f1=" << val << ",";
779
    // checkme: maybe we must use the read id here...
780
58.5k
    auto &field=database.m_fields[size_t(i)];
781
58.5k
    if (readFormat(field, extra)) {
782
58.5k
      f << extra << ",";
783
58.5k
      if (dSz>14) { // find also dSz=18 which add c0000034 here
784
56.6k
        ascii().addDelimiter(input->tell(),'|');
785
56.6k
        input->seek(pos+dSz-2, librevenge::RVNG_SEEK_SET);
786
56.6k
        ascii().addDelimiter(input->tell(),'|');
787
56.6k
      }
788
58.5k
      val=static_cast<int>(input->readLong(2));
789
58.5k
      if (val!=i) f << "#id=" << val << ",";
790
58.5k
    }
791
58.5k
    input->seek(pos+dSz, librevenge::RVNG_SEEK_SET);
792
58.5k
    ascii().addPos(pos);
793
58.5k
    ascii().addNote(f.str().c_str());
794
58.5k
  }
795
102
  return true;
796
124
}
797
798
/* read a cell format
799
800
   \note: this function is very simillar to BeagleWksSSParser readCellSheet, maybe, we can merge them
801
 */
802
bool BeagleWksDBParser::readFormat(MWAWCell &cell, std::string &extra)
803
58.7k
{
804
58.7k
  MWAWInputStreamPtr &input= getInput();
805
58.7k
  long pos=input->tell();
806
58.7k
  if (!input->checkPosition(pos+8)) {
807
0
    MWAW_DEBUG_MSG(("BeagleWksDBParser::readFormat: the zone is too short\n"));
808
0
    return false;
809
0
  }
810
58.7k
  libmwaw::DebugStream f;
811
58.7k
  MWAWFont font;
812
58.7k
  MWAWCell::Format format;
813
58.7k
  auto val=static_cast<int>(input->readULong(1));
814
58.7k
  if (val) f << "f0=" << std::hex << val << std::dec << ",";
815
58.7k
  val=static_cast<int>(input->readLong(1));
816
58.7k
  if (val>0)
817
26.9k
    font.setSize(float(val));
818
58.7k
  val=static_cast<int>(input->readLong(2));
819
58.7k
  if (val>=0)
820
46.0k
    font.setId(val);
821
58.7k
  auto flag=static_cast<int>(input->readULong(1));
822
58.7k
  uint32_t flags=0;
823
58.7k
  if (flag&0x8) flags |= MWAWFont::boldBit;
824
58.7k
  if (flag&0x10) flags |= MWAWFont::italicBit;
825
58.7k
  if (flag&0x20) font.setUnderlineStyle(MWAWFont::Line::Simple);
826
58.7k
  if (flag&0x40) flags |= MWAWFont::embossBit;
827
58.7k
  if (flag&0x80) flags |= MWAWFont::shadowBit;
828
58.7k
  font.setFlags(flags);
829
58.7k
  f << font.getDebugString(getParserState()->m_fontConverter);
830
58.7k
  if (flag&7) f << "flags=" << (flag&7) << ",";
831
832
58.7k
  auto form=static_cast<int>(input->readULong(1));
833
58.7k
  if (form) {
834
39.4k
    if (form & 0x10)
835
14.3k
      format.m_thousandHasSeparator=true;
836
39.4k
    switch (form>>5) {
837
13.3k
    case 0: // generic (or picture, memo, etc)
838
13.3k
      break;
839
6.13k
    case 1:
840
6.13k
      format.m_format=MWAWCell::F_NUMBER;
841
6.13k
      format.m_numberFormat=MWAWCell::F_NUMBER_CURRENCY;
842
6.13k
      break;
843
4.06k
    case 2:
844
4.06k
      format.m_format=MWAWCell::F_NUMBER;
845
4.06k
      format.m_numberFormat=MWAWCell::F_NUMBER_PERCENT;
846
4.06k
      break;
847
3.28k
    case 3:
848
3.28k
      format.m_format=MWAWCell::F_NUMBER;
849
3.28k
      format.m_numberFormat=MWAWCell::F_NUMBER_SCIENTIFIC;
850
3.28k
      break;
851
2.90k
    case 4:
852
2.90k
      format.m_format=MWAWCell::F_NUMBER;
853
2.90k
      format.m_numberFormat=MWAWCell::F_NUMBER_DECIMAL;
854
2.90k
      break;
855
1.68k
    case 5:
856
1.68k
      format.m_format=MWAWCell::F_DATE;
857
1.68k
      format.m_DTFormat="%m/%d/%y";
858
1.68k
      break;
859
2.62k
    case 6:
860
2.62k
      switch (form & 0x7) {
861
442
      case 0:
862
442
        format.m_format=MWAWCell::F_DATE;
863
442
        format.m_DTFormat="%b %d, %Y";
864
442
        break;
865
303
      case 1:
866
303
        format.m_format=MWAWCell::F_DATE;
867
303
        format.m_DTFormat="%B %d, %Y";
868
303
        break;
869
240
      case 2:
870
240
        format.m_format=MWAWCell::F_DATE;
871
240
        format.m_DTFormat="%a, %b %d, %Y";
872
240
        break;
873
251
      case 3:
874
251
        format.m_format=MWAWCell::F_DATE;
875
251
        format.m_DTFormat="%A, %B %d, %Y";
876
251
        break;
877
272
      case 4:
878
272
        format.m_format=MWAWCell::F_TIME;
879
272
        format.m_DTFormat="%I:%M %p";
880
272
        break;
881
473
      case 5:
882
473
        format.m_format=MWAWCell::F_TIME;
883
473
        format.m_DTFormat="%I:%M:%S %p";
884
473
        break;
885
476
      case 6:
886
476
        format.m_format=MWAWCell::F_TIME;
887
476
        format.m_DTFormat="%H:%M";
888
476
        break;
889
168
      case 7:
890
168
        format.m_format=MWAWCell::F_TIME;
891
168
        format.m_DTFormat="%H:%M:%S";
892
168
        break;
893
0
      default:
894
0
        break;
895
2.62k
      }
896
2.62k
      form &= 0x8;
897
2.62k
      break;
898
5.37k
    default:
899
5.37k
      f << "#form=7:";
900
5.37k
      break;
901
39.4k
    }
902
39.4k
    if (form & 0xf)
903
35.4k
      format.m_digits=(form & 0xf);
904
39.4k
    f << format;
905
39.4k
  }
906
907
58.7k
  val=static_cast<int>(input->readULong(1));
908
58.7k
  if (val&0xF0) f << "col?="<<std::hex << (val>>4) << std::dec << ",";
909
58.7k
  if (val&0xf) f << "bord?="<<std::hex << (val&0xF) << std::dec << ",";
910
911
58.7k
  val=static_cast<int>(input->readULong(1));
912
58.7k
  switch ((val>>5)&7) {
913
32.5k
  case 0:
914
32.5k
    cell.setHAlignment(MWAWCell::HALIGN_LEFT);
915
32.5k
    f << "left,";
916
32.5k
    break;
917
6.12k
  case 1:
918
6.12k
    cell.setHAlignment(MWAWCell::HALIGN_RIGHT);
919
6.12k
    f << "right,";
920
6.12k
    break;
921
4.06k
  case 2:
922
4.06k
    cell.setHAlignment(MWAWCell::HALIGN_CENTER);
923
4.06k
    f << "center,";
924
4.06k
    break;
925
3.37k
  case 3: // default
926
3.37k
    break;
927
2.77k
  case 4:
928
2.77k
    cell.setHAlignment(MWAWCell::HALIGN_LEFT);
929
2.77k
    f << "filled,";
930
2.77k
    break;
931
9.86k
  default:
932
9.86k
    f << "#align=" << ((val>>5)&7) << ",";
933
9.86k
    break;
934
58.7k
  }
935
58.7k
  cell.setFormat(format);
936
  // checkme, this flags seem important, but I am not sure of their meanings
937
58.7k
  if (val&0x10)
938
14.6k
    cell.setFont(font);
939
58.7k
  val &= 0xF;
940
58.7k
  if (val!=0x3) f << "flags2=" << std::hex << val << std::dec << ",";
941
58.7k
  extra=f.str();
942
58.7k
  return true;
943
58.7k
}
944
945
946
////////////////////////////////////////////////////////////
947
// read the row data
948
////////////////////////////////////////////////////////////
949
bool BeagleWksDBParser::readRow()
950
6.23k
{
951
6.23k
  MWAWInputStreamPtr &input= getInput();
952
6.23k
  long pos=input->tell();
953
6.23k
  libmwaw::DebugStream f;
954
955
6.23k
  auto id=static_cast<int>(input->readLong(2));
956
6.23k
  f << "DbRow" << id << ":";
957
6.23k
  auto val=static_cast<int>(input->readLong(2));
958
6.23k
  if (val) f << "f0=" << val << ",";
959
6.23k
  auto dSz=long(input->readULong(2));
960
6.23k
  long endPos=pos+6+dSz;
961
6.23k
  if (dSz<18 || !input->checkPosition(endPos)) {
962
198
    MWAW_DEBUG_MSG(("BeagleWksDBParser::readRow: can not find the database row %d\n", id));
963
198
    f << "###";
964
198
    ascii().addPos(pos);
965
198
    ascii().addNote(f.str().c_str());
966
198
    return false;
967
198
  }
968
6.04k
  val=static_cast<int>(input->readLong(2)); // 0|78|86
969
6.04k
  if (val) f << "f1=" << val << ",";
970
6.04k
  val=static_cast<int>(input->readLong(2));
971
6.04k
  if (val!=-1) f << "f2=" << val << ",";
972
6.04k
  f << "fl?=[" << std::hex;
973
30.2k
  for (int i=0; i<4; ++i) {
974
24.1k
    val=static_cast<int>(input->readULong(2));
975
24.1k
    if (val) f << val << ",";
976
662
    else f << "_,";
977
24.1k
  }
978
6.04k
  f << std::dec << "],";
979
  // now a format
980
6.04k
  f << "fId=" << input->readULong(2) << ",";
981
6.04k
  f << "fSz=" << input->readULong(2) << ",";
982
6.04k
  val=static_cast<int>(input->readULong(2));
983
6.04k
  if (val!=dSz) f << "#dSz1=" << val << ",";
984
985
6.04k
  ascii().addPos(pos);
986
6.04k
  ascii().addNote(f.str().c_str());
987
988
6.04k
  auto &database=m_state->m_database;
989
6.04k
  database.m_records.resize(database.m_records.size()+1);
990
6.04k
  auto &records=database.m_records.back();
991
6.04k
  int fd=0;
992
65.7k
  for (auto const &field : database.m_fields) {
993
65.7k
    pos=input->tell();
994
65.7k
    if (pos>=endPos) break;
995
65.6k
    f.str("");
996
65.6k
    f << "DbRow" << id << "-" << fd++ << ":";
997
65.6k
    auto fSz=static_cast<int>(input->readULong(1));
998
65.6k
    if (fSz==0xFF) {
999
254
      ascii().addPos(pos);
1000
254
      ascii().addNote("_");
1001
254
      break;
1002
254
    }
1003
65.4k
    if (pos+fSz+2>endPos) {
1004
136
      input->seek(pos, librevenge::RVNG_SEEK_SET);
1005
136
      MWAW_DEBUG_MSG(("BeagleWksDBParser::readRow: file size seems bad\n"));
1006
136
      break;
1007
136
    }
1008
65.2k
    val=static_cast<int>(input->readULong(1));
1009
65.2k
    if (val!=0x20) f << "fl=" << std::hex << val << std::dec << ",";
1010
65.2k
    MWAWCellContent content;
1011
65.2k
    if (fSz && fSz<8) {
1012
38.0k
      MWAW_DEBUG_MSG(("BeagleWksDBParser::readRow: find some very short field\n"));
1013
38.0k
      f << "###sz=" << fSz << ",";
1014
38.0k
    }
1015
27.2k
    else if (fSz) {
1016
124k
      for (int i=0; i<4; ++i) {
1017
99.2k
        val=static_cast<int>(input->readULong(2));
1018
99.2k
        if (val) f << "f" << i << "=" << std::hex << val << std::dec << ",";
1019
99.2k
      }
1020
24.8k
      switch (field.m_type) {
1021
3.14k
      case BeagleWksDBParserInternal::Cell::Formula:
1022
3.14k
        if (fSz>20) break;
1023
2.80k
        val=static_cast<int>(input->readULong(2));
1024
2.80k
        if (val) f << "g0=" << std::hex << val << std::dec << ",";
1025
2.80k
        MWAW_FALLTHROUGH;
1026
3.84k
      case BeagleWksDBParserInternal::Cell::Memo: // memoId
1027
3.87k
      case BeagleWksDBParserInternal::Cell::Picture: // pictId
1028
5.51k
      case BeagleWksDBParserInternal::Cell::Number:
1029
12.6k
      case BeagleWksDBParserInternal::Cell::Date:
1030
12.7k
      case BeagleWksDBParserInternal::Cell::Time: {
1031
        // will be changed by sendDatabase for memo, formula, ...
1032
12.7k
        content.m_contentType=MWAWCellContent::C_NUMBER;
1033
12.7k
        if (input->tell()+10>endPos) {
1034
6
          MWAW_DEBUG_MSG(("BeagleWksDBParser::readRow: can not read some field\n"));
1035
6
          f << "###";
1036
6
          break;
1037
6
        }
1038
12.7k
        double value;
1039
12.7k
        bool isNan;
1040
12.7k
        if (!input->readDouble10(value,isNan)) {
1041
53
          f << "#" << value << ",";
1042
53
          break;
1043
53
        }
1044
12.7k
        content.setValue(value);
1045
12.7k
        f << value << ",";
1046
12.7k
        break;
1047
12.7k
      }
1048
6.78k
      case BeagleWksDBParserInternal::Cell::Text: {
1049
6.78k
        content.m_contentType=MWAWCellContent::C_TEXT;
1050
6.78k
        content.m_textEntry.setBegin(input->tell());
1051
6.78k
        content.m_textEntry.setEnd(pos+fSz+2);
1052
6.78k
        std::string text("");
1053
120k
        while (input->tell()<pos+fSz+2) text+=char(input->readULong(1));
1054
6.78k
        f << text << ",";
1055
6.78k
      }
1056
6.78k
      break;
1057
4.94k
      case BeagleWksDBParserInternal::Cell::Unknown:
1058
#if !defined(__clang__)
1059
      default:
1060
#endif
1061
4.94k
        f << "type=" << static_cast<int>(field.m_type) << ",";
1062
4.94k
        break;
1063
24.8k
      }
1064
24.8k
    }
1065
65.2k
    records.push_back(content);
1066
65.2k
    if ((fSz%2)) ++fSz;
1067
65.2k
    input->seek(pos+fSz+2, librevenge::RVNG_SEEK_SET);
1068
65.2k
    ascii().addPos(pos);
1069
65.2k
    ascii().addNote(f.str().c_str());
1070
65.2k
  }
1071
1072
6.04k
  pos=input->tell();
1073
6.04k
  if (pos!=endPos) {
1074
5.96k
    MWAW_DEBUG_MSG(("BeagleWksDBParser::readRow: find some extra data\n"));
1075
5.96k
    input->seek(endPos, librevenge::RVNG_SEEK_SET);
1076
5.96k
    ascii().addPos(pos);
1077
5.96k
    ascii().addNote("DbRow:#end");
1078
5.96k
  }
1079
6.04k
  return true;
1080
6.04k
}
1081
1082
////////////////////////////////////////////////////////////
1083
// read the fields
1084
////////////////////////////////////////////////////////////
1085
bool BeagleWksDBParser::readFields()
1086
503
{
1087
503
  MWAWInputStreamPtr &input= getInput();
1088
503
  auto &database=m_state->m_database;
1089
503
  long pos=input->tell();
1090
503
  if (!input->checkPosition(pos+6)) {
1091
2
    MWAW_DEBUG_MSG(("BeagleWksDBParser::readFields: can not find the field zone\n"));
1092
2
    return false;
1093
2
  }
1094
501
  libmwaw::DebugStream f;
1095
501
  f << "Entries(Field):";
1096
501
  auto val=static_cast<int>(input->readLong(2));
1097
501
  if (val) f << "f0=" << val << ",";
1098
501
  val=static_cast<int>(input->readLong(2));
1099
501
  if (val!=0x2c) // may a type
1100
488
    f << "f1=" << val << ",";
1101
501
  database.m_numFields=static_cast<int>(input->readULong(2));
1102
501
  f << "num[fields]=" << database.m_numFields << ",";
1103
501
  if (!input->checkPosition(pos+database.m_numFields*64)) {
1104
26
    MWAW_DEBUG_MSG(("BeagleWksDBParser::readFields: can not find the fields zone\n"));
1105
26
    f << "###";
1106
26
    ascii().addPos(pos);
1107
26
    ascii().addNote(f.str().c_str());
1108
26
    return false;
1109
26
  }
1110
475
  ascii().addPos(pos);
1111
475
  ascii().addNote(f.str().c_str());
1112
1113
7.78k
  for (int fld=0; fld<database.m_numFields; ++fld) {
1114
7.40k
    pos=input->tell();
1115
7.40k
    f.str("");
1116
7.40k
    f << "Field-" << fld << ":";
1117
7.40k
    BeagleWksDBParserInternal::Cell field;
1118
7.40k
    auto dSz=long(input->readULong(2));
1119
7.40k
    long endPos=pos+4+dSz;
1120
7.40k
    if (dSz<0x3c || !input->checkPosition(endPos)) {
1121
94
      MWAW_DEBUG_MSG(("BeagleWksDBParser::readFields: can not read a field\n"));
1122
94
      f << "###";
1123
94
      ascii().addPos(pos);
1124
94
      ascii().addNote(f.str().c_str());
1125
94
      return false;
1126
94
    }
1127
7.30k
    auto id=static_cast<int>(input->readLong(2));
1128
7.30k
    if (id) f << "id=" << id << ",";
1129
7.30k
    auto sSz=static_cast<int>(input->readULong(1));
1130
7.30k
    if (sSz+1>dSz) {
1131
2
      MWAW_DEBUG_MSG(("BeagleWksDBParser::readFields: can not read a field\n"));
1132
2
      f << "###";
1133
2
      ascii().addPos(pos);
1134
2
      ascii().addNote(f.str().c_str());
1135
2
      return false;
1136
2
    }
1137
82.8k
    for (int i=0; i<sSz; ++i) field.m_name += char(input->readULong(1));
1138
7.30k
    f << "\"" << field.m_name << "\",";
1139
7.30k
    ascii().addDelimiter(input->tell(),'|');
1140
7.30k
    input->seek(endPos-10, librevenge::RVNG_SEEK_SET);
1141
7.30k
    ascii().addDelimiter(input->tell(),'|');
1142
1143
7.30k
    MWAWCell::Format format;
1144
7.30k
    auto &content=field.m_content;
1145
7.30k
    auto type=static_cast<int>(input->readLong(1));
1146
7.30k
    switch (type) {
1147
357
    case 0:
1148
357
      field.m_type = BeagleWksDBParserInternal::Cell::Text;
1149
357
      content.m_contentType=MWAWCellContent::C_TEXT;
1150
357
      f << "text,";
1151
357
      break;
1152
707
    case 1:
1153
707
      field.m_type = BeagleWksDBParserInternal::Cell::Number;
1154
707
      content.m_contentType=MWAWCellContent::C_NUMBER;
1155
707
      f << "number,";
1156
707
      break;
1157
1.86k
    case 2:
1158
1.86k
      field.m_type = BeagleWksDBParserInternal::Cell::Date;
1159
1.86k
      content.m_contentType=MWAWCellContent::C_NUMBER;
1160
1.86k
      f << "date,";
1161
1.86k
      break;
1162
70
    case 3:
1163
70
      field.m_type = BeagleWksDBParserInternal::Cell::Time;
1164
70
      content.m_contentType=MWAWCellContent::C_NUMBER;
1165
70
      f << "time,";
1166
70
      break;
1167
1.33k
    case 4:
1168
1.33k
      field.m_type = BeagleWksDBParserInternal::Cell::Picture;
1169
1.33k
      f << "picture,";
1170
1.33k
      break;
1171
818
    case 5:
1172
818
      field.m_type = BeagleWksDBParserInternal::Cell::Formula;
1173
818
      content.m_contentType=MWAWCellContent::C_FORMULA;
1174
818
      f << "formula,";
1175
818
      break;
1176
402
    case 6:
1177
402
      field.m_type = BeagleWksDBParserInternal::Cell::Memo;
1178
402
      content.m_contentType=MWAWCellContent::C_TEXT;
1179
402
      f << "memo,";
1180
402
      break;
1181
1.75k
    default:
1182
1.75k
      f << "#type=" << type << ",";
1183
1.75k
      break;
1184
7.30k
    }
1185
7.30k
    f << "form?=" << std::hex << input->readULong(1) << std::dec << ",";
1186
7.30k
    f << "id2=" << std::hex << input->readULong(4) << std::dec << ",";
1187
7.30k
    val=static_cast<int>(input->readLong(2)); // 0|-1
1188
7.30k
    if (val!=-1) f << "g0=" << val << ",";
1189
7.30k
    f << "g1=" << input->readLong(2) << ",";
1190
7.30k
    database.m_fields.push_back(field);
1191
1192
7.30k
    ascii().addPos(pos);
1193
7.30k
    ascii().addNote(f.str().c_str());
1194
7.30k
    input->seek(endPos, librevenge::RVNG_SEEK_SET);
1195
7.30k
  }
1196
379
  return true;
1197
475
}
1198
1199
////////////////////////////////////////////////////////////
1200
// read the layouts
1201
////////////////////////////////////////////////////////////
1202
bool BeagleWksDBParser::readLayouts()
1203
379
{
1204
379
  MWAWInputStreamPtr &input= getInput();
1205
379
  long pos=input->tell();
1206
379
  if (!input->checkPosition(pos+6)) {
1207
5
    MWAW_DEBUG_MSG(("BeagleWksDBParser::readLayouts: can not find the layout zone\n"));
1208
5
    return false;
1209
5
  }
1210
374
  libmwaw::DebugStream f;
1211
374
  f << "Entries(Layout):";
1212
374
  auto val=static_cast<int>(input->readLong(2));
1213
374
  if (val) f << "f0=" << val << ",";
1214
374
  val=static_cast<int>(input->readLong(2));
1215
374
  if (val!=0x29) // may a type
1216
361
    f << "f1=" << val << ",";
1217
374
  auto numLayouts=static_cast<int>(input->readULong(2));
1218
374
  f << "num[layout]=" << numLayouts << ",";
1219
374
  ascii().addPos(pos);
1220
374
  ascii().addNote(f.str().c_str());
1221
1222
393
  for (int layout=0; layout<numLayouts; ++layout) {
1223
71
    if (!readLayout(layout)) return false;
1224
71
  }
1225
322
  return true;
1226
374
}
1227
1228
bool BeagleWksDBParser::readLayout(int id)
1229
71
{
1230
71
  MWAWInputStreamPtr &input= getInput();
1231
71
  libmwaw::DebugStream f;
1232
71
  f << "Layout-" << id << "[A]:";
1233
1234
71
  long pos=input->tell();
1235
71
  auto readId=static_cast<int>(input->readULong(1));
1236
71
  auto dSz=long(input->readULong(2));
1237
71
  long endPos=pos+1+dSz;
1238
71
  if (dSz<100 || !input->checkPosition(endPos)) {
1239
21
    MWAW_DEBUG_MSG(("BeagleWksDBParser::readLayouts: can find a layout\n"));
1240
21
    f << "###";
1241
21
    ascii().addPos(pos);
1242
21
    ascii().addNote(f.str().c_str());
1243
21
    return false;
1244
21
  }
1245
50
  if (readId!=id) f << "#id=" << readId << ",";
1246
50
  auto val=static_cast<int>(input->readLong(2));
1247
50
  if (val) f << "f0=" << val << ",";
1248
50
  val=static_cast<int>(input->readULong(1));
1249
50
  if (val!=readId) f << "#id1=" << val << ",";
1250
50
  auto sSz=static_cast<int>(input->readULong(1));
1251
50
  if (sSz>30) {
1252
2
    MWAW_DEBUG_MSG(("BeagleWksDBParser::readLayouts: can find layout string\n"));
1253
2
    f << "###sSz=" << sSz << ",";
1254
2
    ascii().addPos(pos);
1255
2
    ascii().addNote(f.str().c_str());
1256
2
    return false;
1257
2
  }
1258
48
  std::string name("");
1259
332
  for (int i=0; i<sSz; ++i) name+=char(input->readULong(1));
1260
48
  f << name << ",";
1261
48
  input->seek(pos+37, librevenge::RVNG_SEEK_SET);
1262
48
  f << "ids=[" << std::hex;
1263
192
  for (int i=0; i<3; ++i) f << input->readULong(4) << ",";
1264
48
  f << std::dec << "],";
1265
48
  val=static_cast<int>(input->readLong(2)); // small number
1266
48
  f << "N=" << val << ",";
1267
336
  for (int i=0; i<6; ++i) { // f4=0|78, f5=0|68
1268
288
    static int const expected[]= {0x100, 0, 0, 0, 0, 0xffff };
1269
288
    val = static_cast<int>(input->readULong(2));
1270
288
    if (val!=expected[i])
1271
141
      f << "f" << i+2 << "=" << std::hex << val << std::dec << ",";
1272
288
  }
1273
48
  f << "g0=" << std::hex << input->readULong(4) << std::dec << ",";
1274
48
  f << "id2s=[" << std::hex;
1275
240
  for (int i=0; i<4; ++i) {
1276
192
    val=static_cast<int>(input->readULong(i==2 ? 2 : 4));
1277
192
    if (val)
1278
166
      f << val << ",";
1279
26
    else
1280
26
      f << "_,";
1281
192
  }
1282
48
  f << std::dec << "],";
1283
48
  ascii().addPos(pos);
1284
48
  ascii().addNote(f.str().c_str());
1285
1286
48
  pos=input->tell();
1287
48
  f.str("");
1288
48
  f << "Layout-" << id << "[B]:";
1289
48
  double margins[4];
1290
48
  f << "margins=[";
1291
192
  for (double &margin : margins) {
1292
192
    margin=double(input->readLong(4))/72.;
1293
192
    f << margin << ",";
1294
192
  }
1295
48
  f << "],";
1296
192
  for (int i=0; i<3; ++i) {
1297
144
    val=static_cast<int>(input->readLong(2));
1298
144
    if (val) f << "f" << i << "=" << val << ",";
1299
144
  }
1300
48
  f << "id=" << std::hex << input->readULong(4) << std::dec << ",";
1301
48
  ascii().addDelimiter(input->tell(),'|');
1302
48
  ascii().addPos(pos);
1303
48
  ascii().addNote(f.str().c_str());
1304
1305
48
  input->seek(endPos, librevenge::RVNG_SEEK_SET);
1306
48
  pos=input->tell();
1307
48
  f.str("");
1308
48
  f << "Layout-" << id << "[C]:";
1309
432
  for (int i=0; i<8; i++) {
1310
384
    val=static_cast<int>(input->readLong(1));
1311
384
    if (val==1) f << "fl" << i << ",";
1312
298
    else if (val) f << "fl" << i << "=" << val << ",";
1313
384
  }
1314
48
  ascii().addPos(pos);
1315
48
  ascii().addNote(f.str().c_str());
1316
  //--- now some big unknown zones
1317
48
  pos=input->tell();
1318
48
  f.str("");
1319
48
  f << "Layout-" << id << "[C0]:";
1320
48
  ascii().addPos(pos);
1321
48
  ascii().addNote(f.str().c_str());
1322
48
  input->seek(pos+244, librevenge::RVNG_SEEK_SET);
1323
1324
48
  pos=input->tell();
1325
48
  f.str("");
1326
48
  f << "Layout-" << id << "[C1]:";
1327
48
  ascii().addPos(pos);
1328
48
  ascii().addNote(f.str().c_str());
1329
48
  input->seek(pos+178, librevenge::RVNG_SEEK_SET);
1330
1331
  /* in some positions there seems be some blocks with size 12
1332
     so let's try this decomposition ( which clearly does not works )..
1333
   */
1334
4.22k
  for (int i=0; i<87; ++i) {
1335
4.17k
    pos=input->tell();
1336
4.17k
    f.str("");
1337
4.17k
    f << "Layout-" << id << "[C2:" << i << "]:";
1338
4.17k
    ascii().addPos(pos);
1339
4.17k
    ascii().addNote(f.str().c_str());
1340
4.17k
    input->seek(pos+12, librevenge::RVNG_SEEK_SET);
1341
4.17k
  }
1342
1343
48
  pos=input->tell();
1344
48
  f.str("");
1345
48
  f << "Layout-" << id << "[C3]:";
1346
48
  ascii().addPos(pos);
1347
48
  ascii().addNote(f.str().c_str());
1348
1349
48
  input->seek(pos+1420, librevenge::RVNG_SEEK_SET);
1350
1351
  //--- end of unknown zone
1352
48
  pos=input->tell();
1353
48
  f.str("");
1354
48
  f << "Layout-" << id << "[D]:";
1355
48
  auto N=static_cast<int>(input->readULong(2));
1356
48
  f << "N=" << N << ",";
1357
48
  if (!input->checkPosition(pos+2+2*N)) {
1358
15
    MWAW_DEBUG_MSG(("BeagleWksDBParser::readLayouts: can find zone D\n"));
1359
15
    f << "###";
1360
15
    ascii().addPos(pos);
1361
15
    ascii().addNote(f.str().c_str());
1362
15
    return false;
1363
15
  }
1364
33
  if (N) {
1365
12
    f << "lists=[";
1366
76.3k
    for (int i=0; i<N; ++i) f << input->readLong(2) << ",";
1367
12
    f << "],";
1368
12
  }
1369
33
  ascii().addPos(pos);
1370
33
  ascii().addNote(f.str().c_str());
1371
1372
33
  pos=input->tell();
1373
33
  f.str("");
1374
33
  f << "Layout-" << id << "[fields]:";
1375
33
  val=static_cast<int>(input->readULong(2));
1376
33
  auto type=static_cast<int>(input->readULong(2));
1377
33
  N=static_cast<int>(input->readULong(2));
1378
33
  f << "N=" << N << ",";
1379
33
  if (type!=0x5a || !input->checkPosition(pos+6+36*N)) {
1380
13
    MWAW_DEBUG_MSG(("BeagleWksDBParser::readLayouts: can find field zone \n"));
1381
13
    f << "###";
1382
13
    ascii().addPos(pos);
1383
13
    ascii().addNote(f.str().c_str());
1384
13
    return false;
1385
13
  }
1386
20
  ascii().addPos(pos);
1387
20
  ascii().addNote(f.str().c_str());
1388
20
  BeagleWksDBParserInternal::Cell field;
1389
100
  for (int i=0; i<N; i++) {
1390
80
    pos=input->tell();
1391
80
    f.str("");
1392
80
    f << "Layout-" << id << "[field" << i << "]:";
1393
80
    id=static_cast<int>(input->readLong(2));
1394
80
    if (id!=i) f << "id[field]=" << val << ",";
1395
80
    val=static_cast<int>(input->readLong(2));
1396
80
    if (val!=0x4b) f << "f0=" << val << ",";
1397
240
    for (int j=0; j<2; ++j) { // j=0: field name, j=1: field content
1398
160
      std::string extra("");
1399
160
      if (!readFormat(field, extra)) {
1400
0
        f << "###";
1401
0
        break;
1402
0
      }
1403
160
      f << "field" << j << "=[" << extra << "],";
1404
160
    }
1405
240
    for (int j=0; j<2; ++j) {
1406
160
      int dim[4];
1407
640
      for (auto &k : dim) k=static_cast<int>(input->readLong(2));
1408
160
      f << "box" << j << "=" << dim[1] << "x" << dim[0] << "<->" << dim[3] << "x" << dim[2] << ",";
1409
160
    }
1410
80
    ascii().addPos(pos);
1411
80
    ascii().addNote(f.str().c_str());
1412
80
    input->seek(pos+36, librevenge::RVNG_SEEK_SET);
1413
80
  }
1414
1415
20
  pos=input->tell();
1416
20
  f.str("");
1417
20
  f << "Layout-" << id << "[list]:";
1418
20
  dSz=static_cast<int>(input->readULong(2));
1419
20
  type=static_cast<int>(input->readLong(2));
1420
20
  N=static_cast<int>(input->readULong(2));
1421
20
  endPos=pos+6+dSz;
1422
20
  if (2*N>dSz || type!=0x75 || !input->checkPosition(endPos)) {
1423
1
    MWAW_DEBUG_MSG(("BeagleWksDBParser::readLayouts: can read zone F\n"));
1424
1
    f << "###";
1425
1
    ascii().addPos(pos);
1426
1
    ascii().addNote(f.str().c_str());
1427
1
    return false;
1428
1
  }
1429
19
  f << "N=" << N << ",";
1430
19
  if (val!=0x75) f << "f0=" << val << ",";
1431
19
  f << "lists=[";
1432
171
  for (int i=0; i<N; ++i) f << input->readLong(2) << ",";
1433
19
  f << "],";
1434
19
  ascii().addPos(pos);
1435
19
  ascii().addNote(f.str().c_str());
1436
19
  input->seek(endPos, librevenge::RVNG_SEEK_SET);
1437
19
  return true;
1438
20
}
1439
1440
////////////////////////////////////////////////////////////
1441
// send data
1442
////////////////////////////////////////////////////////////
1443
bool BeagleWksDBParser::sendPageFrames()
1444
0
{
1445
0
  auto const &frameMap = m_structureManager->getIdFrameMap();
1446
0
  for (auto const &it : frameMap)
1447
0
    sendFrame(it.second);
1448
0
  return true;
1449
0
}
1450
1451
bool BeagleWksDBParser::sendFrame(BeagleWksStructManager::Frame const &frame)
1452
0
{
1453
0
  MWAWPosition fPos(MWAWVec2f(0,0), frame.m_dim, librevenge::RVNG_POINT);
1454
1455
0
  fPos.setPagePos(frame.m_page > 0 ? frame.m_page : 1, frame.m_origin);
1456
0
  fPos.setRelativePosition(MWAWPosition::Page);
1457
0
  fPos.m_wrapping = frame.m_wrap==0 ? MWAWPosition::WNone : MWAWPosition::WDynamic;
1458
1459
0
  auto style=MWAWGraphicStyle::emptyStyle();
1460
0
  style.setBorders(frame.m_bordersSet, frame.m_border);
1461
0
  return sendPicture(frame.m_pictId, fPos, true, style);
1462
0
}
1463
1464
// read/send picture (edtp resource)
1465
bool BeagleWksDBParser::sendPicture
1466
(int pId, MWAWPosition const &pictPos, bool readEDTP, MWAWGraphicStyle const &style)
1467
1
{
1468
1
  MWAWSpreadsheetListenerPtr listener=getSpreadsheetListener();
1469
1
  if (!listener) {
1470
0
    MWAW_DEBUG_MSG(("BeagleWksDBParser::sendPicture: can not find the listener\n"));
1471
0
    return false;
1472
0
  }
1473
1
  auto rsrcParser = getRSRCParser();
1474
1
  if (!rsrcParser) {
1475
1
    static bool first=true;
1476
1
    if (first) {
1477
1
      MWAW_DEBUG_MSG(("BeagleWksDBParser::sendPicture: need access to resource fork to retrieve picture content\n"));
1478
1
      first=false;
1479
1
    }
1480
1
    return true;
1481
1
  }
1482
1483
0
  librevenge::RVNGBinaryData data;
1484
0
  if (!m_structureManager->readPicture(pId, data, readEDTP))
1485
0
    return false;
1486
1487
0
  listener->insertPicture(pictPos, MWAWEmbeddedObject(data, "image/pict"), style);
1488
0
  return true;
1489
0
}
1490
1491
bool BeagleWksDBParser::sendText(MWAWEntry const &entry, bool /*headerFooter*/)
1492
81
{
1493
81
  MWAWSpreadsheetListenerPtr listener=getSpreadsheetListener();
1494
81
  if (!listener) {
1495
0
    MWAW_DEBUG_MSG(("BeagleWksDBParser::sendText: can not find the listener\n"));
1496
0
    return false;
1497
0
  }
1498
81
  if (!entry.valid()) {
1499
0
    MWAW_DEBUG_MSG(("BeagleWksDBParser::sendText: can not find the entry\n"));
1500
0
    return false;
1501
0
  }
1502
1503
81
  MWAWInputStreamPtr &input= getInput();
1504
81
  long endPos=entry.end();
1505
81
  input->seek(entry.begin(), librevenge::RVNG_SEEK_SET);
1506
3.66k
  while (!input->isEnd()) {
1507
3.66k
    long pos=input->tell();
1508
3.66k
    if (pos>=endPos) break;
1509
3.58k
    auto c = static_cast<unsigned char>(input->readULong(1));
1510
3.58k
    switch (c) {
1511
40
    case 0x9:
1512
40
      listener->insertTab();
1513
40
      break;
1514
8
    case 0xd:
1515
8
      listener->insertEOL();
1516
8
      break;
1517
3.53k
    default:
1518
3.53k
      listener->insertCharacter(static_cast<unsigned char>(c));
1519
3.53k
      break;
1520
3.58k
    }
1521
3.58k
  }
1522
81
  return true;
1523
81
}
1524
1525
////////////////////////////////////////////////////////////
1526
////////////////////////////////////////////////////////////
1527
bool BeagleWksDBParser::sendDatabase()
1528
297
{
1529
297
  MWAWSpreadsheetListenerPtr listener=getSpreadsheetListener();
1530
297
  if (!listener) {
1531
0
    MWAW_DEBUG_MSG(("BeagleWksDBParser::sendDatabase: I can not find the listener\n"));
1532
0
    return false;
1533
0
  }
1534
297
  MWAWInputStreamPtr input=getInput();
1535
297
  auto const &database=m_state->m_database;
1536
297
  auto const &fields = database.m_fields;
1537
297
  size_t numFields=fields.size();
1538
297
  auto const &records=database.m_records;
1539
297
  size_t numRecords=records.size();
1540
  // fixme: use first layout colWidth here
1541
297
  listener->openSheet(std::vector<float>(1,76), librevenge::RVNG_POINT, std::vector<int>(1,static_cast<int>(numRecords)), "Sheet0");
1542
6.33k
  for (size_t r=0; r<numRecords; ++r) {
1543
6.04k
    std::vector<MWAWCellContent> const &row=records[r];
1544
6.04k
    listener->openSheetRow(12, librevenge::RVNG_POINT);
1545
71.3k
    for (size_t c=0; c<row.size(); ++c) {
1546
65.2k
      if (c>=numFields) break;
1547
65.2k
      auto field=fields[c];
1548
65.2k
      database.updateWithContent(field, MWAWVec2i(int(c),int(r)), row[c]);
1549
65.2k
      if (field.empty()) continue;
1550
1551
10.9k
      auto const &content=field.m_content;
1552
10.9k
      listener->openSheetCell(field, content);
1553
10.9k
      if (content.m_contentType==MWAWCellContent::C_TEXT && content.m_textEntry.valid()) {
1554
2.09k
        listener->setFont(field.getFont());
1555
2.09k
        input->seek(content.m_textEntry.begin(), librevenge::RVNG_SEEK_SET);
1556
40.0k
        while (!input->isEnd() && input->tell()<content.m_textEntry.end()) {
1557
39.6k
          auto ch=static_cast<unsigned char>(input->readULong(1));
1558
39.6k
          if (ch==0xd)
1559
611
            listener->insertEOL();
1560
39.0k
          else if (ch<30) {
1561
1.64k
            MWAW_DEBUG_MSG(("BeagleWksDBParser::sendDatabase: find some odd character\n"));
1562
1.64k
            break;
1563
1.64k
          }
1564
37.3k
          else
1565
37.3k
            listener->insertCharacter(ch);
1566
39.6k
        }
1567
2.09k
      }
1568
8.88k
      else if (field.m_type==BeagleWksDBParserInternal::Cell::Picture && field.m_pictureId>=0) {
1569
1
        std::string cellName("Sheet0.");
1570
1
        cellName+=MWAWCell::getBasicCellName(field.position()+MWAWVec2i(1,1));
1571
1
        MWAWPosition position(MWAWVec2f(0,0), MWAWVec2f(76,12), librevenge::RVNG_POINT); // changeme
1572
1
        position.setAnchorToCell(librevenge::RVNGString(cellName.c_str()));
1573
1
        sendPicture(field.m_pictureId, position, false);
1574
1
      }
1575
10.9k
      listener->closeSheetCell();
1576
10.9k
    }
1577
6.04k
    listener->closeSheetRow();
1578
6.04k
  }
1579
297
  listener->closeSheet();
1580
297
  return true;
1581
297
}
1582
1583
////////////////////////////////////////////////////////////
1584
//
1585
// Low level
1586
//
1587
////////////////////////////////////////////////////////////
1588
1589
////////////////////////////////////////////////////////////
1590
// read the header
1591
////////////////////////////////////////////////////////////
1592
bool BeagleWksDBParser::checkHeader(MWAWHeader *header, bool strict)
1593
7.56k
{
1594
7.56k
  *m_state = BeagleWksDBParserInternal::State();
1595
7.56k
  MWAWInputStreamPtr input = getInput();
1596
7.56k
  if (!input || !input->hasDataFork() || !input->checkPosition(66))
1597
186
    return false;
1598
1599
7.37k
  libmwaw::DebugStream f;
1600
7.37k
  f << "FileHeader:";
1601
1602
7.37k
  input->seek(0, librevenge::RVNG_SEEK_SET);
1603
7.37k
  if (input->readLong(2)!=0x4257 || input->readLong(2)!=0x6b73 ||
1604
7.31k
      input->readLong(2)!=0x4257 || input->readLong(2)!=0x6462 ||
1605
7.31k
      input->readLong(2)!=0x4257 || input->readLong(2)!=0x6462) {
1606
290
    return false;
1607
290
  }
1608
70.8k
  for (int i=0; i < 9; ++i) { // f2=f6=1 other 0
1609
63.7k
    auto val=static_cast<int>(input->readLong(2));
1610
63.7k
    if (val) f << "f" << i << "=" << val << ",";
1611
63.7k
  }
1612
7.08k
  setVersion(1);
1613
1614
7.08k
  if (header)
1615
5.99k
    header->reset(MWAWDocument::MWAW_T_BEAGLEWORKS, 1, MWAWDocument::MWAW_K_DATABASE);
1616
1617
7.08k
  ascii().addPos(0);
1618
7.08k
  ascii().addNote(f.str().c_str());
1619
1620
7.08k
  long pos=input->tell();
1621
7.08k
  f.str("");
1622
7.08k
  f << "FileHeader-II:";
1623
7.08k
  m_state->m_databaseBegin=input->readLong(4);
1624
7.08k
  if (!input->checkPosition(m_state->m_databaseBegin)) {
1625
1.16k
    MWAW_DEBUG_MSG(("BeagleWksDBParser::checkHeader: can not read the database position\n"));
1626
1.16k
    return false;
1627
1.16k
  }
1628
5.92k
  f << "database[ptr]=" << std::hex << m_state->m_databaseBegin << std::dec << ",";
1629
71.1k
  for (int i=0; i < 11; ++i) { // f2=0x50c|58c|5ac f3=f5=9
1630
65.1k
    long val=input->readLong(2);
1631
65.1k
    if (val) f << "f" << i << "=" << std::hex << val << std::dec << ",";
1632
65.1k
  }
1633
5.92k
  MWAWEntry entry;
1634
5.92k
  entry.setBegin(input->readLong(4));
1635
5.92k
  entry.setLength(input->readLong(4));
1636
5.92k
  entry.setId(static_cast<int>(input->readLong(2))); // in fact nFonts
1637
5.92k
  entry.setType("FontNames");
1638
5.92k
  f << "fontNames[ptr]=" << std::hex << entry.begin() << "<->" << entry.end()
1639
5.92k
    << std::dec << ",nFonts=" << entry.id() << ",";
1640
5.92k
  if (entry.length() && (!entry.valid() || !input->checkPosition(entry.end()))) {
1641
2.94k
    MWAW_DEBUG_MSG(("BeagleWksDBParser::checkHeader: can not read the font names position\n"));
1642
2.94k
    f << "###";
1643
2.94k
    ascii().addPos(pos);
1644
2.94k
    ascii().addNote(f.str().c_str());
1645
2.94k
    return false;
1646
2.94k
  }
1647
1648
2.97k
  m_state->m_typeEntryMap.insert
1649
2.97k
  (std::multimap<std::string, MWAWEntry>::value_type(entry.type(),entry));
1650
2.97k
  ascii().addPos(pos);
1651
2.97k
  ascii().addNote(f.str().c_str());
1652
2.97k
  if (strict && !readPrintInfo())
1653
217
    return false;
1654
2.75k
  ascii().addPos(66);
1655
2.75k
  ascii().addNote("_");
1656
1657
2.75k
  return true;
1658
2.97k
}
1659
1660
// vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab: