Coverage Report

Created: 2026-03-12 06:42

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libetonyek/src/lib/NUM3Parser.cpp
Line
Count
Source
1
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2
/*
3
 * This file is part of the libetonyek project.
4
 *
5
 * This Source Code Form is subject to the terms of the Mozilla Public
6
 * License, v. 2.0. If a copy of the MPL was not distributed with this
7
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8
 */
9
10
#include <algorithm>
11
#include <functional>
12
13
#include "NUM3Parser.h"
14
15
#include "IWAMessage.h"
16
#include "IWAObjectType.h"
17
#include "IWORKTable.h"
18
#include "NUM3ObjectType.h"
19
#include "NUMCollector.h"
20
21
namespace libetonyek
22
{
23
24
NUM3Parser::NUM3Parser(const RVNGInputStreamPtr_t &fragments, const RVNGInputStreamPtr_t &package, NUMCollector &collector)
25
0
  : IWAParser(fragments, package, collector)
26
0
  , m_collector(collector)
27
0
{
28
0
}
29
30
bool NUM3Parser::parseSheet(unsigned id)
31
0
{
32
0
  const ObjectMessage msg(*this, id, NUM3ObjectType::Sheet);
33
0
  if (!msg) return false;
34
  // 1: is the worksheet name
35
  // 2: is the list of table/other drawing in this page
36
0
  boost::optional<std::string> name = get(msg).string(1).optional();
37
0
  m_collector.startWorkSpace(name);
38
0
  const std::deque<unsigned> &tableListRefs = readRefs(get(msg), 2);
39
0
  for (auto cId : tableListRefs)
40
0
    dispatchShape(cId);
41
0
  m_collector.endWorkSpace(m_tableNameMap);
42
43
0
  return true;
44
0
}
45
46
bool NUM3Parser::parseShapePlacement(const IWAMessage &msg, IWORKGeometryPtr_t &geometry, boost::optional<unsigned> &)
47
0
{
48
0
  geometry = std::make_shared<IWORKGeometry>();
49
0
  const boost::optional<IWAMessage> &g = msg.message(1).optional();
50
0
  if (g)
51
0
  {
52
0
    const boost::optional<IWORKPosition> &pos = readPosition(get(g), 1);
53
0
    if (pos)
54
0
      geometry->m_position = get(pos);
55
0
    const boost::optional<IWORKSize> &size = readSize(get(g), 2);
56
0
    if (size)
57
0
      geometry->m_naturalSize = geometry->m_size = get(size);
58
    // CHECKME what means get(g).uint32(3) : 0,3 seems normal ?
59
0
    if (get(g).float_(4))
60
0
      geometry->m_angle = -deg2rad(get(get(g).float_(4)));
61
0
  }
62
0
  geometry->m_aspectRatioLocked = msg.bool_(7).optional();
63
64
0
  return true;
65
0
}
66
67
bool NUM3Parser::parseStickyNote(const IWAMessage &msg)
68
0
{
69
0
  assert(!m_currentText);
70
71
0
  m_collector.startLevel();
72
  // 1: a text box, 2: a comment ref
73
74
  // FIXME: actually, this creates a textbox but the background and
75
  //        padding are bad and we do not retrieve the author, ...
76
0
  auto const &shape=msg.message(1);
77
0
  if (shape)
78
0
    dispatchShapeWithMessage(get(shape),IWAObjectType::DrawableShape);
79
0
  m_collector.endLevel();
80
81
0
  return true;
82
0
}
83
84
bool NUM3Parser::parseDocument()
85
0
{
86
0
  const ObjectMessage msg(*this, 1, NUM3ObjectType::Document);
87
0
  if (!msg) return false;
88
89
0
  m_collector.startDocument();
90
0
  auto info=get(msg).message(8);
91
0
  if (info)
92
0
  {
93
0
    auto customRef=readRef(get(info),12);
94
0
    if (customRef) parseCustomFormat(get(customRef));
95
0
  }
96
  // const optional<IWAMessage> size = get(msg).message(12).optional();
97
  // if (size) define the page size
98
0
  const std::deque<unsigned> &sheetListRefs = readRefs(get(msg), 1);
99
0
  std::for_each(sheetListRefs.begin(), sheetListRefs.end(), std::bind(&NUM3Parser::parseSheet, this, std::placeholders::_1));
100
101
0
  m_collector.endDocument();
102
0
  return true;
103
0
}
104
}
105
106
/* vim:set shiftwidth=2 softtabstop=2 expandtab: */