Coverage Report

Created: 2026-03-12 06:42

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libwpd/src/lib/WP1SetTabsGroup.cpp
Line
Count
Source
1
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
2
/* libwpd
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 Fridrich Strba (fridrich.strba@bluewin.ch)
11
  *
12
 * For minor contributions see the git repository.
13
 *
14
 * Alternatively, the contents of this file may be used under the terms
15
 * of the GNU Lesser General Public License Version 2.1 or later
16
 * (LGPLv2.1+), in which case the provisions of the LGPLv2.1+ are
17
 * applicable instead of those above.
18
 *
19
 * For further information visit http://libwpd.sourceforge.net
20
 */
21
22
/* "This product is not manufactured, approved, or supported by
23
 * Corel Corporation or Corel Corporation Limited."
24
 */
25
26
#include "WP1SetTabsGroup.h"
27
#include "libwpd_internal.h"
28
#include <vector>
29
30
WP1SetTabsGroup::WP1SetTabsGroup(librevenge::RVNGInputStream *input, WPXEncryption *encryption, unsigned char group) :
31
5.53k
  WP1VariableLengthGroup(group),
32
5.53k
  m_tabStops(std::vector<WPXTabStop>())
33
5.53k
{
34
5.53k
  _read(input, encryption);
35
5.53k
}
36
37
WP1SetTabsGroup::~WP1SetTabsGroup()
38
5.46k
{
39
5.46k
}
40
41
void WP1SetTabsGroup::_readContents(librevenge::RVNGInputStream *input, WPXEncryption *encryption)
42
5.53k
{
43
  // Skip first the old condensed tab table
44
38.6k
  while (readU8(input, encryption) != 0xff && !input->isEnd())
45
33.1k
    input->seek(2, librevenge::RVNG_SEEK_CUR);
46
47
  // Now read the new condensed tab table
48
5.53k
  signed char tmpTabType = 0;
49
5.53k
  double tmpTabPosition = 0.0;
50
5.53k
  WPXTabStop tmpTabStop = WPXTabStop();
51
52
1.43M
  while (((tmpTabType = (signed char)readU8(input, encryption)) & 0xff) != 0xff)
53
1.43M
  {
54
1.43M
    if (input->isEnd())
55
4
      throw FileException();
56
1.43M
    tmpTabPosition = (double)((double)readU16(input, encryption, true) / 72.0);
57
58
1.43M
    if (tmpTabType < 0)
59
1.20M
    {
60
139M
      for (signed char i = tmpTabType; i < 0; i++)
61
138M
      {
62
138M
        tmpTabStop.m_position += tmpTabPosition;
63
138M
        m_tabStops.push_back(tmpTabStop);
64
138M
      }
65
1.20M
    }
66
227k
    else
67
227k
    {
68
227k
      tmpTabStop.m_position = tmpTabPosition;
69
70
227k
      switch (tmpTabType & 0x03)
71
227k
      {
72
156k
      case 0:
73
156k
        tmpTabStop.m_alignment = LEFT;
74
156k
        break;
75
36.5k
      case 1:
76
36.5k
        tmpTabStop.m_alignment = CENTER;
77
36.5k
        break;
78
20.5k
      case 2:
79
20.5k
        tmpTabStop.m_alignment = RIGHT;
80
20.5k
        break;
81
13.7k
      case 3:
82
13.7k
        tmpTabStop.m_alignment = DECIMAL;
83
13.7k
        break;
84
0
      default:
85
0
        tmpTabStop.m_alignment = LEFT;
86
0
        break;
87
227k
      }
88
89
227k
      if (tmpTabType & 0x04)
90
70.5k
      {
91
70.5k
        tmpTabStop.m_leaderCharacter = '.';
92
70.5k
        tmpTabStop.m_leaderNumSpaces = 0;
93
70.5k
      }
94
156k
      else
95
156k
      {
96
156k
        tmpTabStop.m_leaderCharacter = '\0';
97
156k
        tmpTabStop.m_leaderNumSpaces = 0;
98
156k
      }
99
100
227k
      m_tabStops.push_back(tmpTabStop);
101
227k
    }
102
1.43M
  }
103
5.53k
}
104
105
void WP1SetTabsGroup::parse(WP1Listener *listener)
106
5.46k
{
107
#ifdef DEBUG
108
  WPD_DEBUG_MSG(("Parsing Set Tabs Group (positions: "));
109
  for (std::vector<WPXTabStop>::const_iterator i = m_tabStops.begin(); i != m_tabStops.end(); ++i)
110
  {
111
    WPD_DEBUG_MSG((" %.4f", (*i).m_position));
112
  }
113
  WPD_DEBUG_MSG((")\n"));
114
#endif
115
5.46k
  listener->setTabs(m_tabStops);
116
5.46k
}
117
/* vim:set shiftwidth=4 softtabstop=4 noexpandtab: */