Coverage Report

Created: 2026-09-14 06:37

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libetonyek/src/lib/contexts/IWORKWrapElement.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 "IWORKWrapElement.h"
11
12
#include <boost/lexical_cast.hpp>
13
#include <memory>
14
15
#include "libetonyek_xml.h"
16
#include "IWORKBezierElement.h"
17
#include "IWORKDictionary.h"
18
#include "IWORKGeometryElement.h"
19
#include "IWORKPath.h"
20
#include "IWORKToken.h"
21
#include "IWORKTokenizer.h"
22
#include "IWORKXMLParserState.h"
23
24
namespace libetonyek
25
{
26
namespace
27
{
28
29
class PathElement : public IWORKXMLEmptyContextBase
30
{
31
public:
32
  PathElement(IWORKXMLParserState &state, IWORKPathPtr_t &path);
33
34
private:
35
  void attribute(int name, const char *value) override;
36
  IWORKXMLContextPtr_t element(int name) override;
37
private:
38
  IWORKPathPtr_t &m_path;
39
};
40
41
PathElement::PathElement(IWORKXMLParserState &state, IWORKPathPtr_t &path)
42
0
  : IWORKXMLEmptyContextBase(state)
43
0
  , m_path(path)
44
0
{
45
0
}
46
47
void PathElement::attribute(const int name, const char *const value)
48
0
{
49
0
  switch (name)
50
0
  {
51
0
  case +IWORKToken::NS_URI_SFA | IWORKToken::path :
52
0
    try
53
0
    {
54
0
      m_path = std::make_shared<IWORKPath>(value);
55
0
    }
56
0
    catch (const IWORKPath::InvalidException &)
57
0
    {
58
0
      ETONYEK_DEBUG_MSG(("PathElement::attribute[IWORKWrapElement.cpp]: '%s' is not a valid path\n", value));
59
0
    }
60
0
    break;
61
0
  case +IWORKToken::NS_URI_SFA | IWORKToken::ID : // USEME
62
0
    IWORKXMLEmptyContextBase::attribute(name, value);
63
0
    break;
64
0
  case +IWORKToken::NS_URI_SFA | IWORKToken::version :
65
0
    break;
66
0
  default:
67
0
    ETONYEK_DEBUG_MSG(("PathElement::attribute[IWORKWrapElement.cpp]: unexpected attribute\n"));
68
0
    break;
69
0
  }
70
0
}
71
72
IWORKXMLContextPtr_t PathElement::element(const int name)
73
0
{
74
0
  switch (name)
75
0
  {
76
0
  case +IWORKToken::NS_URI_SF | IWORKToken::bezier :
77
0
    return std::make_shared<IWORKBezierElement>(getState(), m_path);
78
0
  default:
79
0
    ETONYEK_DEBUG_MSG(("PathElement::element[IWORKWrapElement.cpp]: find unknown element\n"));
80
0
    break;
81
0
  }
82
83
0
  return IWORKXMLContextPtr_t();
84
0
}
85
}
86
87
IWORKExternalTextWrapElement::IWORKExternalTextWrapElement(IWORKXMLParserState &state, boost::optional<IWORKExternalTextWrap> &wrap)
88
0
  : IWORKXMLElementContextBase(state)
89
0
  , m_wrap(wrap)
90
0
{
91
0
  m_wrap=IWORKExternalTextWrap();
92
0
}
93
94
void IWORKExternalTextWrapElement::attribute(int name, const char *value)
95
0
{
96
0
  try
97
0
  {
98
0
    switch (name)
99
0
    {
100
0
    case +IWORKToken::NS_URI_SFA | IWORKToken::ID :
101
0
      IWORKXMLElementContextBase::attribute(name, value);
102
0
      break;
103
0
    case +IWORKToken::NS_URI_SF | IWORKToken::attachment_wrap_type :
104
0
      switch (getState().getTokenizer().getId(value))
105
0
      {
106
0
      case IWORKToken::aligned:
107
0
        get(m_wrap).m_aligned = true;
108
0
        break;
109
0
      case IWORKToken::unaligned:
110
0
        get(m_wrap).m_aligned = false;
111
0
        break;
112
0
      default:
113
0
        ETONYEK_DEBUG_MSG(("IWORKExternalTextWrapElement::attribute[IWORKWrapElement.cpp]: find unknown attachment type value=%s\n", value));
114
0
        break;
115
0
      }
116
0
      break;
117
0
    case +IWORKToken::NS_URI_SF | IWORKToken::alpha_threshold :
118
0
      get(m_wrap).m_alphaThreshold=double_cast(value);
119
0
      break;
120
0
    case +IWORKToken::NS_URI_SF | IWORKToken::direction :
121
0
      switch (getState().getTokenizer().getId(value))
122
0
      {
123
0
      case IWORKToken::both :
124
0
        get(m_wrap).m_direction=IWORK_WRAP_DIRECTION_BOTH;
125
0
        break;
126
0
      case IWORKToken::left :
127
0
        get(m_wrap).m_direction=IWORK_WRAP_DIRECTION_LEFT;
128
0
        break;
129
0
      case IWORKToken::right :
130
0
        get(m_wrap).m_direction=IWORK_WRAP_DIRECTION_RIGHT;
131
0
        break;
132
0
      default:
133
0
        ETONYEK_DEBUG_MSG(("IWORKExternalTextWrapElement::attribute[IWORKWrapElement.cpp]: find unknown direction value=%s\n", value));
134
0
        break;
135
0
      }
136
0
      break;
137
0
    case +IWORKToken::NS_URI_SF | IWORKToken::floating_wrap_enabled :
138
0
      get(m_wrap).m_floatingWrapEnabled=bool_cast(value);
139
0
      break;
140
0
    case +IWORKToken::NS_URI_SF | IWORKToken::floating_wrap_type :
141
0
      switch (getState().getTokenizer().getId(value))
142
0
      {
143
0
      case IWORKToken::directional:
144
0
        get(m_wrap).m_floatingType = IWORK_WRAP_TYPE_DIRECTIONAL;
145
0
        break;
146
0
      case IWORKToken::largest:
147
0
        get(m_wrap).m_floatingType = IWORK_WRAP_TYPE_LARGEST;
148
0
        break;
149
0
      case IWORKToken::neither:
150
0
        get(m_wrap).m_floatingType = IWORK_WRAP_TYPE_NEITHER;
151
0
        break;
152
0
      default:
153
0
        ETONYEK_DEBUG_MSG(("IWORKExternalTextWrapElement::attribute[IWORKWrapElement.cpp]: find unknown floating type value=%s\n", value));
154
0
        break;
155
0
      }
156
0
      break;
157
0
    case +IWORKToken::NS_URI_SF | IWORKToken::inline_wrap_enabled :
158
0
      get(m_wrap).m_inlineWrapEnabled=bool_cast(value);
159
0
      break;
160
0
    case +IWORKToken::NS_URI_SF | IWORKToken::margin :
161
0
      get(m_wrap).m_margin=double_cast(value);
162
0
      break;
163
0
    case +IWORKToken::NS_URI_SF | IWORKToken::wrap_style :
164
0
      switch (getState().getTokenizer().getId(value))
165
0
      {
166
0
      case IWORKToken::regular :
167
0
        get(m_wrap).m_style=IWORK_WRAP_STYLE_REGULAR;
168
0
        break;
169
0
      case IWORKToken::tight :
170
0
        get(m_wrap).m_style=IWORK_WRAP_STYLE_TIGHT;
171
0
        break;
172
0
      default:
173
0
        ETONYEK_DEBUG_MSG(("IWORKExternalTextWrapElement::attribute[IWORKWrapElement.cpp]: find unknown style value=%s\n", value));
174
0
        break;
175
0
      }
176
0
      break;
177
0
    default:
178
0
      ETONYEK_DEBUG_MSG(("IWORKExternalTextWrapElement::attribute[IWORKWrapElement.cpp]: find unknown attribute\n"));
179
0
      break;
180
0
    }
181
0
  }
182
0
  catch (...)
183
0
  {
184
0
    ETONYEK_DEBUG_MSG(("IWORKExternalTextWrapElement::attribute[IWORKWrapElement.cpp]: catch some exception\n"));
185
0
  }
186
187
0
}
188
189
#ifndef DEBUG
190
IWORKXMLContextPtr_t IWORKExternalTextWrapElement::element(const int)
191
#else
192
IWORKXMLContextPtr_t IWORKExternalTextWrapElement::element(const int name)
193
#endif
194
0
{
195
0
  ETONYEK_DEBUG_MSG(("IWORKExternalTextWrapElement::element[IWORKWrapElement.cpp]: find unknown element %d\n", name));
196
197
0
  return IWORKXMLContextPtr_t();
198
0
}
199
200
void IWORKExternalTextWrapElement::endOfElement()
201
0
{
202
0
  if (getId())
203
0
    getState().getDictionary().m_externalTextWraps[get(getId())]=get(m_wrap);
204
0
}
205
206
IWORKWrapElement::IWORKWrapElement(IWORKXMLParserState &state, boost::optional<IWORKWrap> &wrap)
207
0
  : IWORKXMLElementContextBase(state)
208
0
  , m_wrap(wrap)
209
0
{
210
0
  m_wrap=IWORKWrap();
211
0
}
212
213
void IWORKWrapElement::attribute(const int /*name*/, const char *const /*value*/)
214
0
{
215
0
  ETONYEK_DEBUG_MSG(("IWORKWrapElement::attribute: find unknown attribute\n"));
216
0
}
217
218
IWORKXMLContextPtr_t IWORKWrapElement::element(const int name)
219
0
{
220
0
  switch (name)
221
0
  {
222
0
  case +IWORKToken::NS_URI_SF | IWORKToken::path :
223
0
    return std::make_shared<PathElement>(getState(), get(m_wrap).m_path);
224
0
  case +IWORKToken::NS_URI_SF | IWORKToken::geometry :
225
0
    return std::make_shared<IWORKGeometryElement>(getState(), get(m_wrap).m_geometry);
226
0
  default:
227
0
    ETONYEK_DEBUG_MSG(("IWORKWrapElement::element: find unknown element\n"));
228
0
    break;
229
0
  }
230
231
0
  return IWORKXMLContextPtr_t();
232
0
}
233
234
}
235
236
/* vim:set shiftwidth=2 softtabstop=2 expandtab: */