Coverage Report

Created: 2026-04-29 07:28

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libetonyek/src/lib/IWORKTextRecorder.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 "IWORKTextRecorder.h"
11
12
#include <deque>
13
14
#include <boost/variant.hpp>
15
16
#include "libetonyek_utils.h"
17
#include "IWORKText.h"
18
19
namespace libetonyek
20
{
21
22
namespace
23
{
24
25
struct PushBaseLayoutStyle
26
{
27
  explicit PushBaseLayoutStyle(const IWORKStylePtr_t &style)
28
0
    : m_style(style)
29
0
  {
30
0
  }
31
32
  const IWORKStylePtr_t m_style;
33
};
34
35
struct PushBaseParagraphStyle
36
{
37
  explicit PushBaseParagraphStyle(const IWORKStylePtr_t &style)
38
0
    : m_style(style)
39
0
  {
40
0
  }
41
42
  const IWORKStylePtr_t m_style;
43
};
44
45
struct SetLayoutStyle
46
{
47
  explicit SetLayoutStyle(const IWORKStylePtr_t &style)
48
0
    : m_style(style)
49
0
  {
50
0
  }
51
52
  const IWORKStylePtr_t m_style;
53
};
54
55
struct FlushLayout
56
{
57
};
58
59
struct SetListStyle
60
{
61
  explicit SetListStyle(const IWORKStylePtr_t &style)
62
0
    : m_style(style)
63
0
  {
64
0
  }
65
66
  const IWORKStylePtr_t m_style;
67
};
68
69
struct SetListLevel
70
{
71
  explicit SetListLevel(const unsigned level)
72
0
    : m_level(level)
73
0
  {
74
0
  }
75
76
  const unsigned m_level;
77
};
78
79
struct FlushList
80
{
81
};
82
83
struct SetParagraphStyle
84
{
85
  explicit SetParagraphStyle(const IWORKStylePtr_t &style)
86
0
    : m_style(style)
87
0
  {
88
0
  }
89
90
  const IWORKStylePtr_t m_style;
91
};
92
93
struct FlushParagraph
94
{
95
};
96
97
struct SetSpanStyle
98
{
99
  explicit SetSpanStyle(const IWORKStylePtr_t &style)
100
0
    : m_style(style)
101
0
  {
102
0
  }
103
104
  const IWORKStylePtr_t m_style;
105
};
106
107
struct SetLanguage
108
{
109
  explicit SetLanguage(const IWORKStylePtr_t &style)
110
0
    : m_style(style)
111
0
  {
112
0
  }
113
114
  const IWORKStylePtr_t m_style;
115
};
116
117
struct FlushSpan
118
{
119
};
120
121
struct InsertField
122
{
123
  explicit InsertField(IWORKFieldType type)
124
0
    : m_type(type)
125
0
  {
126
0
  }
127
128
  const IWORKFieldType m_type;
129
};
130
131
struct OpenLink
132
{
133
  explicit OpenLink(const std::string &url)
134
0
    : m_url(url)
135
0
  {
136
0
  }
137
138
  const std::string m_url;
139
};
140
141
struct CloseLink
142
{
143
};
144
145
struct InsertText
146
{
147
  explicit InsertText(const std::string &text)
148
0
    : m_text(text)
149
0
  {
150
0
  }
151
152
  const std::string m_text;
153
};
154
155
struct InsertTab
156
{
157
};
158
159
struct InsertSpace
160
{
161
};
162
163
struct InsertBreak
164
{
165
  explicit InsertBreak(IWORKBreakType type)
166
0
    : m_type(type)
167
0
  {
168
0
  }
169
  IWORKBreakType m_type;
170
};
171
172
typedef boost::variant
173
< PushBaseLayoutStyle
174
, PushBaseParagraphStyle
175
, SetLayoutStyle
176
, FlushLayout
177
, SetListStyle
178
, SetListLevel
179
, FlushList
180
, SetParagraphStyle
181
, FlushParagraph
182
, SetSpanStyle
183
, SetLanguage
184
, FlushSpan
185
, InsertField
186
, OpenLink
187
, CloseLink
188
, InsertText
189
, InsertTab
190
, InsertSpace
191
, InsertBreak
192
>
193
Element_t;
194
195
}
196
197
namespace
198
{
199
200
struct Sender : public boost::static_visitor<void>
201
{
202
  explicit Sender(IWORKText &text)
203
0
    : m_text(text)
204
0
  {
205
0
  }
206
207
  void operator()(const PushBaseLayoutStyle &value) const
208
0
  {
209
0
    m_text.pushBaseLayoutStyle(value.m_style);
210
0
  }
211
212
  void operator()(const PushBaseParagraphStyle &value) const
213
0
  {
214
0
    m_text.pushBaseParagraphStyle(value.m_style);
215
0
  }
216
217
  void operator()(const SetLayoutStyle &value) const
218
0
  {
219
0
    m_text.setLayoutStyle(value.m_style);
220
0
  }
221
222
  void operator()(const FlushLayout &) const
223
0
  {
224
0
    m_text.flushLayout();
225
0
  }
226
227
  void operator()(const SetListStyle &value) const
228
0
  {
229
0
    m_text.setListStyle(value.m_style);
230
0
  }
231
232
  void operator()(const SetListLevel &value) const
233
0
  {
234
0
    m_text.setListLevel(value.m_level);
235
0
  }
236
237
  void operator()(const FlushList &) const
238
0
  {
239
0
    m_text.flushList();
240
0
  }
241
242
  void operator()(const SetParagraphStyle &value) const
243
0
  {
244
0
    m_text.setParagraphStyle(value.m_style);
245
0
  }
246
247
  void operator()(const FlushParagraph &) const
248
0
  {
249
0
    m_text.flushParagraph();
250
0
  }
251
252
  void operator()(const SetSpanStyle &value) const
253
0
  {
254
0
    m_text.setSpanStyle(value.m_style);
255
0
  }
256
257
  void operator()(const SetLanguage &value) const
258
0
  {
259
0
    m_text.setLanguage(value.m_style);
260
0
  }
261
262
  void operator()(const FlushSpan &) const
263
0
  {
264
0
    m_text.flushSpan();
265
0
  }
266
267
  void operator()(const InsertField &value) const
268
0
  {
269
0
    m_text.insertField(value.m_type);
270
0
  }
271
272
  void operator()(const OpenLink &value) const
273
0
  {
274
0
    m_text.openLink(value.m_url);
275
0
  }
276
277
  void operator()(const CloseLink &) const
278
0
  {
279
0
    m_text.closeLink();
280
0
  }
281
282
  void operator()(const InsertText &value) const
283
0
  {
284
0
    m_text.insertText(value.m_text);
285
0
  }
286
287
  void operator()(const InsertTab &) const
288
0
  {
289
0
    m_text.insertTab();
290
0
  }
291
292
  void operator()(const InsertSpace &) const
293
0
  {
294
0
    m_text.insertSpace();
295
0
  }
296
297
  void operator()(const InsertBreak &value) const
298
0
  {
299
0
    switch (value.m_type)
300
0
    {
301
0
    case IWORK_BREAK_NONE :
302
0
      break;
303
0
    case IWORK_BREAK_COLUMN:
304
0
      m_text.insertColumnBreak();
305
0
      break;
306
0
    case IWORK_BREAK_LINE :
307
0
      m_text.insertLineBreak();
308
0
      break;
309
0
    case IWORK_BREAK_PAGE:
310
0
      m_text.insertPageBreak();
311
0
      break;
312
0
    default:
313
0
      ETONYEK_DEBUG_MSG(("Sender::operator(InsertBreak)[IWORKTextRecorder.cpp]: unexpected break\n"));
314
0
      break;
315
0
    }
316
0
  }
317
318
private:
319
  IWORKText &m_text;
320
};
321
322
}
323
324
struct IWORKTextRecorder::Impl
325
{
326
  Impl();
327
328
  std::deque<Element_t> m_elements;
329
};
330
331
IWORKTextRecorder::Impl::Impl()
332
0
  : m_elements()
333
0
{
334
0
}
335
336
IWORKTextRecorder::IWORKTextRecorder()
337
0
  : m_impl(new Impl())
338
0
{
339
0
}
340
341
void IWORKTextRecorder::replay(IWORKText &text) const
342
0
{
343
0
  Sender sender(text);
344
0
  for (std::deque<Element_t>::const_iterator it = m_impl->m_elements.begin(); it != m_impl->m_elements.end(); ++it)
345
0
    boost::apply_visitor(sender, *it);
346
0
}
347
348
void IWORKTextRecorder::pushBaseLayoutStyle(const IWORKStylePtr_t &style)
349
0
{
350
0
  m_impl->m_elements.push_back(PushBaseLayoutStyle(style));
351
0
}
352
353
void IWORKTextRecorder::pushBaseParagraphStyle(const IWORKStylePtr_t &style)
354
0
{
355
0
  m_impl->m_elements.push_back(PushBaseParagraphStyle(style));
356
0
}
357
358
void IWORKTextRecorder::setLayoutStyle(const IWORKStylePtr_t &style)
359
0
{
360
0
  m_impl->m_elements.push_back(SetLayoutStyle(style));
361
0
}
362
363
void IWORKTextRecorder::flushLayout()
364
0
{
365
0
  m_impl->m_elements.push_back(FlushLayout());
366
0
}
367
368
void IWORKTextRecorder::setListStyle(const IWORKStylePtr_t &style)
369
0
{
370
0
  m_impl->m_elements.push_back(SetListStyle(style));
371
0
}
372
373
void IWORKTextRecorder::setListLevel(const unsigned level)
374
0
{
375
0
  m_impl->m_elements.push_back(SetListLevel(level));
376
0
}
377
378
void IWORKTextRecorder::flushList()
379
0
{
380
0
  m_impl->m_elements.push_back(FlushList());
381
0
}
382
383
void IWORKTextRecorder::setParagraphStyle(const IWORKStylePtr_t &style)
384
0
{
385
0
  m_impl->m_elements.push_back(SetParagraphStyle(style));
386
0
}
387
388
void IWORKTextRecorder::flushParagraph()
389
0
{
390
0
  m_impl->m_elements.push_back(FlushParagraph());
391
0
}
392
393
void IWORKTextRecorder::setSpanStyle(const IWORKStylePtr_t &style)
394
0
{
395
0
  m_impl->m_elements.push_back(SetSpanStyle(style));
396
0
}
397
398
void IWORKTextRecorder::setLanguage(const IWORKStylePtr_t &style)
399
0
{
400
0
  m_impl->m_elements.push_back(SetLanguage(style));
401
0
}
402
403
void IWORKTextRecorder::flushSpan()
404
0
{
405
0
  m_impl->m_elements.push_back(FlushSpan());
406
0
}
407
408
void IWORKTextRecorder::insertField(IWORKFieldType type)
409
0
{
410
0
  m_impl->m_elements.push_back(InsertField(type));
411
0
}
412
413
void IWORKTextRecorder::openLink(const std::string &url)
414
0
{
415
0
  m_impl->m_elements.push_back(OpenLink(url));
416
0
}
417
418
void IWORKTextRecorder::closeLink()
419
0
{
420
0
  m_impl->m_elements.push_back(CloseLink());
421
0
}
422
423
void IWORKTextRecorder::insertText(const std::string &text)
424
0
{
425
0
  m_impl->m_elements.push_back(InsertText(text));
426
0
}
427
428
void IWORKTextRecorder::insertTab()
429
0
{
430
0
  m_impl->m_elements.push_back(InsertTab());
431
0
}
432
433
void IWORKTextRecorder::insertSpace()
434
0
{
435
0
  m_impl->m_elements.push_back(InsertSpace());
436
0
}
437
438
void IWORKTextRecorder::insertColumnBreak()
439
0
{
440
0
  m_impl->m_elements.push_back(InsertBreak(IWORK_BREAK_COLUMN));
441
0
}
442
443
void IWORKTextRecorder::insertLineBreak()
444
0
{
445
0
  m_impl->m_elements.push_back(InsertBreak(IWORK_BREAK_LINE));
446
0
}
447
448
void IWORKTextRecorder::insertPageBreak()
449
0
{
450
0
  m_impl->m_elements.push_back(InsertBreak(IWORK_BREAK_PAGE));
451
0
}
452
453
}
454
455
/* vim:set shiftwidth=2 softtabstop=2 expandtab: */