Coverage Report

Created: 2026-03-12 06:42

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
197k
{
35
197k
  if (!iface || text.empty())
36
0
    return;
37
197k
  librevenge::RVNGString tmpText;
38
197k
  librevenge::RVNGString::Iter i(text);
39
6.05M
  for (i.rewind(); i.next();)
40
5.86M
  {
41
5.86M
    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
5.86M
    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
5.86M
    else
66
5.86M
    {
67
5.86M
      tmpText.append(i());
68
5.86M
    }
69
5.86M
  }
70
197k
  if (iface && !tmpText.empty())
71
197k
    iface->insertText(tmpText);
72
197k
}
73
74
static void separateSpacesAndInsertText(librevenge::RVNGDrawingInterface *iface, const librevenge::RVNGString &text)
75
200k
{
76
200k
  if (!iface)
77
0
    return;
78
200k
  if (text.empty())
79
3.37k
  {
80
3.37k
    iface->insertText(text);
81
3.37k
    return;
82
3.37k
  }
83
197k
  librevenge::RVNGString tmpText;
84
197k
  int numConsecutiveSpaces = 0;
85
197k
  librevenge::RVNGString::Iter i(text);
86
6.05M
  for (i.rewind(); i.next();)
87
5.86M
  {
88
5.86M
    if (*(i()) == ' ')
89
40.0k
      numConsecutiveSpaces++;
90
5.82M
    else
91
5.82M
      numConsecutiveSpaces = 0;
92
93
5.86M
    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
5.86M
    else
105
5.86M
    {
106
5.86M
      tmpText.append(i());
107
5.86M
    }
108
5.86M
  }
109
197k
  separateTabsAndInsertText(iface, tmpText);
110
197k
}
111
112
} // anonymous namespace
113
114
void WPGTextDataHandler::openParagraph(const librevenge::RVNGPropertyList &propList)
115
359k
{
116
359k
  m_painter->openParagraph(propList);
117
359k
}
118
119
void WPGTextDataHandler::closeParagraph()
120
359k
{
121
359k
  m_painter->closeParagraph();
122
359k
}
123
124
void WPGTextDataHandler::openSpan(const librevenge::RVNGPropertyList &propList)
125
380k
{
126
380k
  m_painter->openSpan(propList);
127
380k
}
128
129
void WPGTextDataHandler::closeSpan()
130
380k
{
131
380k
  m_painter->closeSpan();
132
380k
}
133
134
void WPGTextDataHandler::insertTab()
135
5.22k
{
136
5.22k
  m_painter->insertTab();
137
5.22k
}
138
139
void WPGTextDataHandler::insertSpace()
140
160k
{
141
160k
  m_painter->insertSpace();
142
160k
}
143
144
void WPGTextDataHandler::insertText(const librevenge::RVNGString &text)
145
200k
{
146
200k
  separateSpacesAndInsertText(m_painter, text);
147
200k
}
148
149
void WPGTextDataHandler::insertLineBreak()
150
717
{
151
717
  m_painter->insertLineBreak();
152
717
}
153
154
void WPGTextDataHandler::openListElement(const librevenge::RVNGPropertyList &propList)
155
13.2k
{
156
13.2k
  m_painter->openListElement(propList);
157
13.2k
}
158
159
void WPGTextDataHandler::closeListElement()
160
13.2k
{
161
13.2k
  m_painter->closeListElement();
162
13.2k
}
163
/* vim:set shiftwidth=4 softtabstop=4 noexpandtab: */