Coverage Report

Created: 2026-09-06 07:18

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libwpg/src/lib/WPGXParser.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 "WPGXParser.h"
29
30
WPGXParser::WPGXParser(librevenge::RVNGInputStream *input, librevenge::RVNGDrawingInterface *painter):
31
0
  m_input(input), m_painter(painter), m_colorPalette(std::map<int,libwpg::WPGColor>())
32
0
{
33
0
}
34
35
WPGXParser::WPGXParser(const WPGXParser &parser):
36
0
  m_input(parser.m_input), m_painter(parser.m_painter),
37
0
  m_colorPalette(parser.m_colorPalette)
38
0
{
39
0
}
40
41
unsigned char WPGXParser::readU8()
42
0
{
43
0
  if (!m_input || m_input->isEnd())
44
0
    return (unsigned char)0;
45
0
  unsigned long numBytesRead;
46
0
  unsigned char const *p = m_input->read(1, numBytesRead);
47
48
0
  if (p && numBytesRead == 1)
49
0
    return *(unsigned char const *)(p);
50
0
  return (unsigned char)0;
51
0
}
52
53
unsigned short WPGXParser::readU16()
54
0
{
55
0
  auto p0 = (unsigned short)readU8();
56
0
  auto p1 = (unsigned short)readU8();
57
0
  return (unsigned short)(p0|(p1<<8));
58
0
}
59
60
unsigned int WPGXParser::readU32()
61
0
{
62
0
  auto p0 = (unsigned int)readU8();
63
0
  auto p1 = (unsigned int)readU8();
64
0
  auto p2 = (unsigned int)readU8();
65
0
  auto p3 = (unsigned int)readU8();
66
0
  return (unsigned int)(p0|(p1<<8)|(p2<<16)|(p3<<24));
67
0
}
68
69
short WPGXParser::readS16()
70
0
{
71
0
  return (short)readU16();
72
0
}
73
74
int WPGXParser::readS32()
75
0
{
76
0
  return (int)readU32();
77
0
}
78
79
unsigned int WPGXParser::readVariableLengthInteger()
80
0
{
81
  // read a byte
82
0
  unsigned char value8 = readU8();
83
  // if it's in the range 0-0xFE, then we have a 8-bit value
84
0
  if (value8<=0xFE)
85
0
  {
86
0
    return (unsigned int)value8;
87
0
  }
88
0
  else
89
0
  {
90
    // now read a 16 bit value
91
0
    unsigned short value16 = readU16();
92
    // if the MSB is 1, we have a 32 bit value
93
0
    if (value16>>15)
94
0
    {
95
      // read the next 16 bit value (LSB part, in value16 resides the MSB part)
96
0
      unsigned long lvalue16 = readU16();
97
0
      unsigned long value32 = value16 & 0x7fff;  // mask out the MSB
98
0
      return (unsigned int)((value32<<16)+lvalue16);
99
0
    }
100
0
    else
101
0
    {
102
      // we have a 16 bit value, return it
103
0
      return (unsigned int)value16;
104
0
    }
105
0
  }
106
0
}
107
108
WPGXParser &WPGXParser::operator=(const WPGXParser &parser)
109
0
{
110
0
  if (this != &parser)
111
0
  {
112
0
    m_input = parser.m_input;
113
0
    m_painter = parser.m_painter;
114
0
    m_colorPalette = parser.m_colorPalette;
115
0
  }
116
0
  return *this;
117
0
}
118
119
/* vim:set shiftwidth=4 softtabstop=4 noexpandtab: */