Coverage Report

Created: 2026-07-20 07:04

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libetonyek/src/lib/contexts/IWORKPElement.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 "IWORKPElement.h"
11
12
#include "IWORKBrContext.h"
13
#include "IWORKDictionary.h"
14
#include "IWORKFieldElement.h"
15
#include "IWORKLinkElement.h"
16
#include "IWORKProperties.h"
17
#include "IWORKSpanElement.h"
18
#include "IWORKStyle.h"
19
#include "IWORKTabElement.h"
20
#include "IWORKText.h"
21
#include "IWORKToken.h"
22
#include "IWORKXMLParserState.h"
23
#include "libetonyek_xml.h"
24
namespace libetonyek
25
{
26
27
namespace
28
{
29
// cell format ?
30
class GhostTextElement : public IWORKXMLEmptyContextBase
31
{
32
public:
33
  explicit GhostTextElement(IWORKXMLParserState &state);
34
35
private:
36
  void attribute(int name, const char *value) override;
37
  IWORKXMLContextPtr_t element(int name) override;
38
  void text(const char *text) override;
39
};
40
41
GhostTextElement::GhostTextElement(IWORKXMLParserState &state)
42
0
  : IWORKXMLEmptyContextBase(state)
43
0
{
44
0
}
45
46
void GhostTextElement::attribute(const int name, const char *const value)
47
0
{
48
0
  switch (name)
49
0
  {
50
0
  case +IWORKToken::localize | IWORKToken::NS_URI_SF : // a bool
51
0
    break;
52
0
  case +IWORKToken::ID | IWORKToken::NS_URI_SFA :
53
0
  case +IWORKToken::IDREF | IWORKToken::NS_URI_SFA :
54
    /* storeme? */
55
0
    IWORKXMLEmptyContextBase::attribute(name, value);
56
0
    break;
57
0
  default :
58
0
    ETONYEK_DEBUG_MSG(("GhostTextElement::attribute[IWORKPElement.cpp]: find some unknown attribute\n"));
59
0
    IWORKXMLEmptyContextBase::attribute(name, value);
60
0
  }
61
0
}
62
63
IWORKXMLContextPtr_t GhostTextElement::element(const int name)
64
0
{
65
0
  switch (name)
66
0
  {
67
0
  case +IWORKToken::NS_URI_SF | IWORKToken::br : // ok to ignore?
68
0
    return IWORKXMLContextPtr_t();
69
0
  case +IWORKToken::NS_URI_SF | IWORKToken::crbr :
70
0
  case +IWORKToken::NS_URI_SF | IWORKToken::intratopicbr :
71
0
  case +IWORKToken::NS_URI_SF | IWORKToken::lnbr :
72
0
    return std::make_shared<IWORKBrContext>(getState());
73
0
  case +IWORKToken::NS_URI_SF | IWORKToken::pgbr :
74
0
    return IWORKXMLContextPtr_t();
75
0
  case +IWORKToken::NS_URI_SF | IWORKToken::span :
76
0
    return std::make_shared<IWORKSpanElement>(getState());
77
0
  case +IWORKToken::NS_URI_SF | IWORKToken::tab :
78
0
    return std::make_shared<IWORKTabElement>(getState());
79
0
  case +IWORKToken::NS_URI_SF | IWORKToken::link :
80
0
    return std::make_shared<IWORKLinkElement>(getState());
81
0
  case +IWORKToken::NS_URI_SF | IWORKToken::date_time :
82
0
    return std::make_shared<IWORKFieldElement>(getState(),IWORK_FIELD_DATETIME);
83
0
  case +IWORKToken::NS_URI_SF | IWORKToken::filename :
84
0
    return std::make_shared<IWORKFieldElement>(getState(),IWORK_FIELD_FILENAME);
85
0
  case +IWORKToken::NS_URI_SF | IWORKToken::page_count :
86
0
    return std::make_shared<IWORKFieldElement>(getState(),IWORK_FIELD_PAGECOUNT);
87
0
  case +IWORKToken::NS_URI_SF | IWORKToken::page_number :
88
0
    return std::make_shared<IWORKFieldElement>(getState(),IWORK_FIELD_PAGENUMBER);
89
0
  default:
90
0
    ETONYEK_DEBUG_MSG(("GhostTextElement::element[IWORKPElement.cpp]: find unknown element\n"));
91
0
    break;
92
0
  }
93
94
0
  return IWORKXMLContextPtr_t();
95
0
}
96
97
void GhostTextElement::text(const char *const value)
98
0
{
99
0
  if (bool(getState().m_currentText))
100
0
    getState().m_currentText->insertText(value);
101
0
}
102
}
103
}
104
105
namespace libetonyek
106
{
107
108
IWORKPElement::IWORKPElement(IWORKXMLParserState &state)
109
0
  : IWORKXMLMixedContextBase(state)
110
0
  , m_style()
111
0
  , m_opened(false)
112
0
  , m_delayedPageBreak(false)
113
0
  , m_listLevel()
114
0
  , m_restartList()
115
0
{
116
0
}
117
118
void IWORKPElement::attribute(const int name, const char *const value)
119
0
{
120
0
  switch (name)
121
0
  {
122
0
  case +IWORKToken::NS_URI_SF | IWORKToken::list_level :
123
0
    m_listLevel = try_int_cast(value);
124
0
    break;
125
0
  case +IWORKToken::NS_URI_SF | IWORKToken::restart_list :
126
0
    m_restartList = try_bool_cast(value);
127
0
    break;
128
0
  case +IWORKToken::NS_URI_SF | IWORKToken::style :
129
0
    m_style = getState().getStyleByName(value, getState().getDictionary().m_paragraphStyles);
130
0
    break;
131
0
  default:
132
0
    ETONYEK_DEBUG_MSG(("IWORKPElement::attribute: find unknown attributes\n"));
133
0
    break;
134
0
  }
135
0
}
136
137
IWORKXMLContextPtr_t IWORKPElement::element(const int name)
138
0
{
139
0
  ensureOpened();
140
141
0
  switch (name)
142
0
  {
143
0
  case +IWORKToken::NS_URI_SF | IWORKToken::br : // ok to ignore?
144
0
    return IWORKXMLContextPtr_t();
145
0
  case +IWORKToken::NS_URI_SF | IWORKToken::crbr :
146
0
  case +IWORKToken::NS_URI_SF | IWORKToken::intratopicbr :
147
0
  case +IWORKToken::NS_URI_SF | IWORKToken::lnbr :
148
0
    return std::make_shared<IWORKBrContext>(getState());
149
0
  case +IWORKToken::NS_URI_SF | IWORKToken::pgbr :
150
0
    m_delayedPageBreak=true;
151
0
    return IWORKXMLContextPtr_t();
152
0
  case +IWORKToken::NS_URI_SF | IWORKToken::span :
153
0
    return std::make_shared<IWORKSpanElement>(getState());
154
0
  case +IWORKToken::NS_URI_SF | IWORKToken::tab :
155
0
    return std::make_shared<IWORKTabElement>(getState());
156
0
  case +IWORKToken::NS_URI_SF | IWORKToken::link :
157
0
    return std::make_shared<IWORKLinkElement>(getState());
158
0
  case +IWORKToken::NS_URI_SF | IWORKToken::date_time :
159
0
    return std::make_shared<IWORKFieldElement>(getState(),IWORK_FIELD_DATETIME);
160
0
  case +IWORKToken::NS_URI_SF | IWORKToken::filename :
161
0
    return std::make_shared<IWORKFieldElement>(getState(),IWORK_FIELD_FILENAME);
162
0
  case +IWORKToken::NS_URI_SF | IWORKToken::ghost_text :
163
0
  case +IWORKToken::NS_URI_SF | IWORKToken::ghost_text_ref :
164
    /* checkme: sf:ghost-text and sf:ghost-text-ref seems similar, but maybe
165
       sf:ghost-text-ref can also be called without the text data...
166
     */
167
0
    return std::make_shared<GhostTextElement>(getState());
168
0
  case +IWORKToken::NS_URI_SF | IWORKToken::page_count :
169
0
    return std::make_shared<IWORKFieldElement>(getState(),IWORK_FIELD_PAGECOUNT);
170
0
  case +IWORKToken::NS_URI_SF | IWORKToken::page_number :
171
0
    return std::make_shared<IWORKFieldElement>(getState(),IWORK_FIELD_PAGENUMBER);
172
0
  default:
173
0
    ETONYEK_DEBUG_MSG(("IWORKPElement::element: find unknown element\n"));
174
0
    break;
175
0
  }
176
177
0
  return IWORKXMLContextPtr_t();
178
0
}
179
180
void IWORKPElement::text(const char *const value)
181
0
{
182
0
  ensureOpened();
183
0
  if (bool(getState().m_currentText))
184
0
    getState().m_currentText->insertText(value);
185
0
}
186
187
void IWORKPElement::endOfElement()
188
0
{
189
0
  ensureOpened();
190
0
  if (bool(getState().m_currentText))
191
0
  {
192
0
    getState().m_currentText->flushParagraph();
193
0
    if (m_delayedPageBreak)
194
0
      getState().m_currentText->insertPageBreak();
195
0
  }
196
0
}
197
198
void IWORKPElement::ensureOpened()
199
0
{
200
0
  if (!m_opened)
201
0
  {
202
0
    if (bool(getState().m_currentText))
203
0
    {
204
0
      if (m_restartList && get(m_restartList))
205
0
        getState().m_currentText->flushList();
206
0
      getState().m_currentText->setParagraphStyle(m_style);
207
0
      if (m_listLevel)
208
0
        getState().m_currentText->setListLevel(get(m_listLevel));
209
0
      if (m_style && m_style->has<property::ListStyle>())
210
0
        getState().m_currentText->setListStyle(m_style->get<property::ListStyle>());
211
0
      else
212
0
        getState().m_currentText->setListStyle(IWORKStylePtr_t());
213
0
    }
214
0
    m_opened = true;
215
0
  }
216
0
}
217
218
}
219
220
/* vim:set shiftwidth=2 softtabstop=2 expandtab: */