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/PAG1StyleContext.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 "PAG1StyleContext.h"
11
12
#include <string>
13
14
#include <boost/optional.hpp>
15
16
#include "libetonyek_xml.h"
17
#include "IWORKProperties.h"
18
#include "IWORKPropertyContext.h"
19
#include "IWORKPropertyMapElement.h"
20
#include "IWORKStyle.h"
21
#include "IWORKToken.h"
22
#include "PAG1ParserState.h"
23
#include "PAG1Token.h"
24
#include "PAGCollector.h"
25
#include "PAGProperties.h"
26
#include "PAGTypes.h"
27
28
namespace libetonyek
29
{
30
31
using boost::optional;
32
33
using std::string;
34
35
namespace
36
{
37
38
class PagemasterElement : public IWORKXMLEmptyContextBase
39
{
40
public:
41
  PagemasterElement(IWORKXMLParserState &state, optional<IWORKPageMaster> &value);
42
43
private:
44
  void attribute(int name, const char *value) override;
45
  void endOfElement() override;
46
47
private:
48
  optional<IWORKPageMaster> &m_value;
49
  optional<string> m_header;
50
  optional<string> m_footer;
51
};
52
53
PagemasterElement::PagemasterElement(IWORKXMLParserState &state, optional<IWORKPageMaster> &value)
54
0
  : IWORKXMLEmptyContextBase(state)
55
0
  , m_value(value)
56
0
  , m_header()
57
0
  , m_footer()
58
0
{
59
0
}
60
61
void PagemasterElement::attribute(const int name, const char *const value)
62
0
{
63
0
  switch (name)
64
0
  {
65
0
  case +PAG1Token::NS_URI_SL | PAG1Token::footer :
66
0
    m_footer = value;
67
0
    break;
68
0
  case +PAG1Token::NS_URI_SL | PAG1Token::header :
69
0
    m_header = value;
70
0
    break;
71
0
  case +IWORKToken::NS_URI_SFA | IWORKToken::ID : // store me?
72
0
    IWORKXMLEmptyContextBase::attribute(name, value);
73
0
    break;
74
0
  default :
75
0
    ETONYEK_DEBUG_MSG(("PagemasterElement::attribute[PAG1StyleContext.cpp]: found unexpected attribute\n"));
76
0
    IWORKXMLEmptyContextBase::attribute(name, value);
77
0
    break;
78
0
  }
79
0
}
80
81
void PagemasterElement::endOfElement()
82
0
{
83
0
  if (m_header || m_footer)
84
0
  {
85
0
    IWORKPageMaster pageMaster;
86
0
    if (m_header)
87
0
      pageMaster.m_header = get(m_header);
88
0
    if (m_footer)
89
0
      pageMaster.m_footer = get(m_footer);
90
0
    m_value = pageMaster;
91
0
  }
92
0
}
93
94
}
95
96
namespace
97
{
98
99
typedef IWORKPropertyContext<property::EvenPageMaster, PagemasterElement, +IWORKToken::NS_URI_SF | IWORKToken::pagemaster> EvenPageMasterElement;
100
typedef IWORKPropertyContext<property::FirstPageMaster, PagemasterElement, +IWORKToken::NS_URI_SF | IWORKToken::pagemaster> FirstPageMasterElement;
101
typedef IWORKPropertyContext<property::OddPageMaster, PagemasterElement, +IWORKToken::NS_URI_SF | IWORKToken::pagemaster> OddPageMasterElement;
102
103
}
104
105
namespace
106
{
107
108
class PropertyMapElement : public PAG1XMLElementContextBase
109
{
110
public:
111
  PropertyMapElement(PAG1ParserState &state, IWORKPropertyMap &propMap);
112
113
private:
114
  IWORKXMLContextPtr_t element(int name) override;
115
116
private:
117
  IWORKPropertyMapElement m_base;
118
  IWORKPropertyMap &m_propMap;
119
};
120
121
PropertyMapElement::PropertyMapElement(PAG1ParserState &state, IWORKPropertyMap &propMap)
122
0
  : PAG1XMLElementContextBase(state)
123
0
  , m_base(state, propMap)
124
0
  , m_propMap(propMap)
125
0
{
126
0
}
127
128
IWORKXMLContextPtr_t PropertyMapElement::element(const int name)
129
0
{
130
0
  switch (name)
131
0
  {
132
0
  case +IWORKToken::NS_URI_SF | IWORKToken::evenPageMaster :
133
0
    return std::make_shared<EvenPageMasterElement>(getState(), m_propMap);
134
0
  case +IWORKToken::NS_URI_SF | IWORKToken::firstPageMaster :
135
0
    return std::make_shared<FirstPageMasterElement>(getState(), m_propMap);
136
0
  case +IWORKToken::NS_URI_SF | IWORKToken::oddPageMaster :
137
0
    return std::make_shared<OddPageMasterElement>(getState(), m_propMap);
138
0
  default:
139
0
    break;
140
0
  }
141
142
0
  return m_base.element(name);
143
0
}
144
145
}
146
147
PAG1StyleContext::PAG1StyleContext(PAG1ParserState &state, IWORKStyleMap_t *const styleMap, const char *const defaultParent, const bool /*nested*/)
148
0
  : PAG1XMLElementContextBase(state)
149
0
  , m_props()
150
0
  , m_base(state, m_props, styleMap, defaultParent/*, nested*/)
151
0
  , m_ident()
152
0
  , m_parentIdent()
153
0
{
154
0
}
155
156
void PAG1StyleContext::attribute(const int name, const char *const value)
157
0
{
158
0
  switch (name)
159
0
  {
160
0
  case +IWORKToken::NS_URI_SF | IWORKToken::ident :
161
0
    m_ident = value;
162
0
    break;
163
0
  case +IWORKToken::NS_URI_SF | IWORKToken::parent_ident :
164
0
    m_parentIdent = value;
165
0
    break;
166
0
  default :
167
0
    PAG1XMLElementContextBase::attribute(name, value);
168
0
    break;
169
0
  }
170
171
0
  m_base.attribute(name, value);
172
0
}
173
174
IWORKXMLContextPtr_t PAG1StyleContext::element(const int name)
175
0
{
176
0
  switch (name)
177
0
  {
178
0
  case +IWORKToken::NS_URI_SF | IWORKToken::property_map :
179
0
    return std::make_shared<PropertyMapElement>(getState(), m_props);
180
0
  default:
181
0
    ETONYEK_DEBUG_MSG(("PAG1StyleContext::element: found unexpected element %d\n", name));
182
0
  }
183
184
0
  return IWORKXMLContextPtr_t();
185
0
}
186
187
void PAG1StyleContext::endOfElement()
188
0
{
189
0
  m_base.endOfElement();
190
0
}
191
192
}
193
194
/* vim:set shiftwidth=2 softtabstop=2 expandtab: */