Coverage Report

Created: 2026-10-28 06:34

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libwpg/src/lib/WPGTextDataHandler.cpp
Line
Count
Source
1
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
2
/* libwpg
3
 * Version: MPL 2.0 / LGPLv2.1+
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
 * Major Contributor(s):
10
 * Copyright (C) 2006 Ariya Hidayat (ariya@kde.org)
11
 * Copyright (C) 2004 Marc Oude Kotte (marc@solcon.nl)
12
 * Copyright (C) 2005 Fridrich Strba (fridrich.strba@bluewin.ch)
13
 *
14
 * For minor contributions see the git repository.
15
 *
16
 * Alternatively, the contents of this file may be used under the terms
17
 * of the GNU Lesser General Public License Version 2.1 or later
18
 * (LGPLv2.1+), in which case the provisions of the LGPLv2.1+ are
19
 * applicable instead of those above.
20
 *
21
 * For further information visit http://libwpg.sourceforge.net
22
 */
23
24
/* "This product is not manufactured, approved, or supported by
25
 * Corel Corporation or Corel Corporation Limited."
26
 */
27
28
#include "WPGTextDataHandler.h"
29
30
namespace
31
{
32
33
static void separateTabsAndInsertText(librevenge::RVNGDrawingInterface *iface, const librevenge::RVNGString &text)
34
241k
{
35
241k
  if (!iface || text.empty())
36
0
    return;
37
241k
  librevenge::RVNGString tmpText;
38
241k
  librevenge::RVNGString::Iter i(text);
39
11.1M
  for (i.rewind(); i.next();)
40
10.9M
  {
41
10.9M
    if (*(i()) == '\t')
42
0
    {
43
0
      if (!tmpText.empty())
44
0
      {
45
0
        if (iface)
46
0
          iface->insertText(tmpText);
47
0
        tmpText.clear();
48
0
      }
49
50
0
      if (iface)
51
0
        iface->insertTab();
52
0
    }
53
10.9M
    else if (*(i()) == '\n')
54
0
    {
55
0
      if (!tmpText.empty())
56
0
      {
57
0
        if (iface)
58
0
          iface->insertText(tmpText);
59
0
        tmpText.clear();
60
0
      }
61
62
0
      if (iface)
63
0
        iface->insertLineBreak();
64
0
    }
65
10.9M
    else
66
10.9M
    {
67
10.9M
      tmpText.append(i());
68
10.9M
    }
69
10.9M
  }
70
241k
  if (iface && !tmpText.empty())
71
241k
    iface->insertText(tmpText);
72
241k
}
73
74
static void separateSpacesAndInsertText(librevenge::RVNGDrawingInterface *iface, const librevenge::RVNGString &text)
75
243k
{
76
243k
  if (!iface)
77
0
    return;
78
243k
  if (text.empty())
79
2.13k
  {
80
2.13k
    iface->insertText(text);
81
2.13k
    return;
82
2.13k
  }
83
241k
  librevenge::RVNGString tmpText;
84
241k
  int numConsecutiveSpaces = 0;
85
241k
  librevenge::RVNGString::Iter i(text);
86
11.1M
  for (i.rewind(); i.next();)
87
10.9M
  {
88
10.9M
    if (*(i()) == ' ')
89
48.1k
      numConsecutiveSpaces++;
90
10.8M
    else
91
10.8M
      numConsecutiveSpaces = 0;
92
93
10.9M
    if (numConsecutiveSpaces > 1)
94
0
    {
95
0
      if (!tmpText.empty())
96
0
      {
97
0
        separateTabsAndInsertText(iface, tmpText);
98
0
        tmpText.clear();
99
0
      }
100
101
0
      if (iface)
102
0
        iface->insertSpace();
103
0
    }
104
10.9M
    else
105
10.9M
    {
106
10.9M
      tmpText.append(i());
107
10.9M
    }
108
10.9M
  }
109
241k
  separateTabsAndInsertText(iface, tmpText);
110
241k
}
111
112
} // anonymous namespace
113
114
void WPGTextDataHandler::openParagraph(const librevenge::RVNGPropertyList &propList)
115
674k
{
116
674k
  m_painter->openParagraph(propList);
117
674k
}
118
119
void WPGTextDataHandler::closeParagraph()
120
674k
{
121
674k
  m_painter->closeParagraph();
122
674k
}
123
124
void WPGTextDataHandler::openSpan(const librevenge::RVNGPropertyList &propList)
125
702k
{
126
702k
  m_painter->openSpan(propList);
127
702k
}
128
129
void WPGTextDataHandler::closeSpan()
130
702k
{
131
702k
  m_painter->closeSpan();
132
702k
}
133
134
void WPGTextDataHandler::insertTab()
135
5.44k
{
136
5.44k
  m_painter->insertTab();
137
5.44k
}
138
139
void WPGTextDataHandler::insertSpace()
140
225k
{
141
225k
  m_painter->insertSpace();
142
225k
}
143
144
void WPGTextDataHandler::insertText(const librevenge::RVNGString &text)
145
243k
{
146
243k
  separateSpacesAndInsertText(m_painter, text);
147
243k
}
148
149
void WPGTextDataHandler::insertLineBreak()
150
748
{
151
748
  m_painter->insertLineBreak();
152
748
}
153
154
void WPGTextDataHandler::openListElement(const librevenge::RVNGPropertyList &propList)
155
20.2k
{
156
20.2k
  m_painter->openListElement(propList);
157
20.2k
}
158
159
void WPGTextDataHandler::closeListElement()
160
20.2k
{
161
20.2k
  m_painter->closeListElement();
162
20.2k
}
163
/* vim:set shiftwidth=4 softtabstop=4 noexpandtab: */