Coverage Report

Created: 2026-07-20 07:04

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libvisio/src/lib/VSDStyles.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 libvisio 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 "VSDStyles.h"
11
12
#include <set>
13
#include <stack>
14
#include "VSDTypes.h"
15
16
namespace libvisio
17
{
18
19
namespace
20
{
21
22
template<typename T>
23
T getOptionalStyle(const std::map<unsigned, unsigned> &styleMasters, const std::map<unsigned, T> &styles, const unsigned styleIndex)
24
808k
{
25
808k
  T style;
26
808k
  if (MINUS_ONE == styleIndex)
27
0
    return style;
28
808k
  std::stack<unsigned> styleIdStack;
29
808k
  std::set<unsigned> foundStyles;
30
808k
  styleIdStack.push(styleIndex);
31
994k
  while (true)
32
994k
  {
33
994k
    auto iter = styleMasters.find(styleIdStack.top());
34
994k
    if (iter != styleMasters.end() && iter->second != MINUS_ONE)
35
238k
    {
36
238k
      if (foundStyles.insert(iter->second).second)
37
186k
        styleIdStack.push(iter->second);
38
51.6k
      else // we already have this style -> stop incoming endless loop
39
51.6k
        break;
40
238k
    }
41
756k
    else
42
756k
      break;
43
994k
  }
44
1.80M
  while (!styleIdStack.empty())
45
994k
  {
46
994k
    auto iter = styles.find(styleIdStack.top());
47
994k
    if (iter != styles.end())
48
153k
      style.override(iter->second);
49
994k
    styleIdStack.pop();
50
994k
  }
51
808k
  return style;
52
808k
}
VSDStyles.cpp:libvisio::VSDOptionalLineStyle libvisio::(anonymous namespace)::getOptionalStyle<libvisio::VSDOptionalLineStyle>(std::__1::map<unsigned int, unsigned int, std::__1::less<unsigned int>, std::__1::allocator<std::__1::pair<unsigned int const, unsigned int> > > const&, std::__1::map<unsigned int, libvisio::VSDOptionalLineStyle, std::__1::less<unsigned int>, std::__1::allocator<std::__1::pair<unsigned int const, libvisio::VSDOptionalLineStyle> > > const&, unsigned int)
Line
Count
Source
24
161k
{
25
161k
  T style;
26
161k
  if (MINUS_ONE == styleIndex)
27
0
    return style;
28
161k
  std::stack<unsigned> styleIdStack;
29
161k
  std::set<unsigned> foundStyles;
30
161k
  styleIdStack.push(styleIndex);
31
199k
  while (true)
32
199k
  {
33
199k
    auto iter = styleMasters.find(styleIdStack.top());
34
199k
    if (iter != styleMasters.end() && iter->second != MINUS_ONE)
35
49.9k
    {
36
49.9k
      if (foundStyles.insert(iter->second).second)
37
38.5k
        styleIdStack.push(iter->second);
38
11.4k
      else // we already have this style -> stop incoming endless loop
39
11.4k
        break;
40
49.9k
    }
41
149k
    else
42
149k
      break;
43
199k
  }
44
361k
  while (!styleIdStack.empty())
45
199k
  {
46
199k
    auto iter = styles.find(styleIdStack.top());
47
199k
    if (iter != styles.end())
48
33.2k
      style.override(iter->second);
49
199k
    styleIdStack.pop();
50
199k
  }
51
161k
  return style;
52
161k
}
VSDStyles.cpp:libvisio::VSDOptionalFillStyle libvisio::(anonymous namespace)::getOptionalStyle<libvisio::VSDOptionalFillStyle>(std::__1::map<unsigned int, unsigned int, std::__1::less<unsigned int>, std::__1::allocator<std::__1::pair<unsigned int const, unsigned int> > > const&, std::__1::map<unsigned int, libvisio::VSDOptionalFillStyle, std::__1::less<unsigned int>, std::__1::allocator<std::__1::pair<unsigned int const, libvisio::VSDOptionalFillStyle> > > const&, unsigned int)
Line
Count
Source
24
161k
{
25
161k
  T style;
26
161k
  if (MINUS_ONE == styleIndex)
27
0
    return style;
28
161k
  std::stack<unsigned> styleIdStack;
29
161k
  std::set<unsigned> foundStyles;
30
161k
  styleIdStack.push(styleIndex);
31
195k
  while (true)
32
195k
  {
33
195k
    auto iter = styleMasters.find(styleIdStack.top());
34
195k
    if (iter != styleMasters.end() && iter->second != MINUS_ONE)
35
42.9k
    {
36
42.9k
      if (foundStyles.insert(iter->second).second)
37
34.8k
        styleIdStack.push(iter->second);
38
8.09k
      else // we already have this style -> stop incoming endless loop
39
8.09k
        break;
40
42.9k
    }
41
152k
    else
42
152k
      break;
43
195k
  }
44
356k
  while (!styleIdStack.empty())
45
195k
  {
46
195k
    auto iter = styles.find(styleIdStack.top());
47
195k
    if (iter != styles.end())
48
29.4k
      style.override(iter->second);
49
195k
    styleIdStack.pop();
50
195k
  }
51
161k
  return style;
52
161k
}
VSDStyles.cpp:libvisio::VSDOptionalTextBlockStyle libvisio::(anonymous namespace)::getOptionalStyle<libvisio::VSDOptionalTextBlockStyle>(std::__1::map<unsigned int, unsigned int, std::__1::less<unsigned int>, std::__1::allocator<std::__1::pair<unsigned int const, unsigned int> > > const&, std::__1::map<unsigned int, libvisio::VSDOptionalTextBlockStyle, std::__1::less<unsigned int>, std::__1::allocator<std::__1::pair<unsigned int const, libvisio::VSDOptionalTextBlockStyle> > > const&, unsigned int)
Line
Count
Source
24
162k
{
25
162k
  T style;
26
162k
  if (MINUS_ONE == styleIndex)
27
0
    return style;
28
162k
  std::stack<unsigned> styleIdStack;
29
162k
  std::set<unsigned> foundStyles;
30
162k
  styleIdStack.push(styleIndex);
31
199k
  while (true)
32
199k
  {
33
199k
    auto iter = styleMasters.find(styleIdStack.top());
34
199k
    if (iter != styleMasters.end() && iter->second != MINUS_ONE)
35
48.4k
    {
36
48.4k
      if (foundStyles.insert(iter->second).second)
37
37.6k
        styleIdStack.push(iter->second);
38
10.7k
      else // we already have this style -> stop incoming endless loop
39
10.7k
        break;
40
48.4k
    }
41
151k
    else
42
151k
      break;
43
199k
  }
44
361k
  while (!styleIdStack.empty())
45
199k
  {
46
199k
    auto iter = styles.find(styleIdStack.top());
47
199k
    if (iter != styles.end())
48
37.0k
      style.override(iter->second);
49
199k
    styleIdStack.pop();
50
199k
  }
51
162k
  return style;
52
162k
}
VSDStyles.cpp:libvisio::VSDOptionalCharStyle libvisio::(anonymous namespace)::getOptionalStyle<libvisio::VSDOptionalCharStyle>(std::__1::map<unsigned int, unsigned int, std::__1::less<unsigned int>, std::__1::allocator<std::__1::pair<unsigned int const, unsigned int> > > const&, std::__1::map<unsigned int, libvisio::VSDOptionalCharStyle, std::__1::less<unsigned int>, std::__1::allocator<std::__1::pair<unsigned int const, libvisio::VSDOptionalCharStyle> > > const&, unsigned int)
Line
Count
Source
24
162k
{
25
162k
  T style;
26
162k
  if (MINUS_ONE == styleIndex)
27
0
    return style;
28
162k
  std::stack<unsigned> styleIdStack;
29
162k
  std::set<unsigned> foundStyles;
30
162k
  styleIdStack.push(styleIndex);
31
199k
  while (true)
32
199k
  {
33
199k
    auto iter = styleMasters.find(styleIdStack.top());
34
199k
    if (iter != styleMasters.end() && iter->second != MINUS_ONE)
35
48.4k
    {
36
48.4k
      if (foundStyles.insert(iter->second).second)
37
37.6k
        styleIdStack.push(iter->second);
38
10.7k
      else // we already have this style -> stop incoming endless loop
39
10.7k
        break;
40
48.4k
    }
41
151k
    else
42
151k
      break;
43
199k
  }
44
361k
  while (!styleIdStack.empty())
45
199k
  {
46
199k
    auto iter = styles.find(styleIdStack.top());
47
199k
    if (iter != styles.end())
48
31.3k
      style.override(iter->second);
49
199k
    styleIdStack.pop();
50
199k
  }
51
162k
  return style;
52
162k
}
VSDStyles.cpp:libvisio::VSDOptionalParaStyle libvisio::(anonymous namespace)::getOptionalStyle<libvisio::VSDOptionalParaStyle>(std::__1::map<unsigned int, unsigned int, std::__1::less<unsigned int>, std::__1::allocator<std::__1::pair<unsigned int const, unsigned int> > > const&, std::__1::map<unsigned int, libvisio::VSDOptionalParaStyle, std::__1::less<unsigned int>, std::__1::allocator<std::__1::pair<unsigned int const, libvisio::VSDOptionalParaStyle> > > const&, unsigned int)
Line
Count
Source
24
162k
{
25
162k
  T style;
26
162k
  if (MINUS_ONE == styleIndex)
27
0
    return style;
28
162k
  std::stack<unsigned> styleIdStack;
29
162k
  std::set<unsigned> foundStyles;
30
162k
  styleIdStack.push(styleIndex);
31
199k
  while (true)
32
199k
  {
33
199k
    auto iter = styleMasters.find(styleIdStack.top());
34
199k
    if (iter != styleMasters.end() && iter->second != MINUS_ONE)
35
48.4k
    {
36
48.4k
      if (foundStyles.insert(iter->second).second)
37
37.6k
        styleIdStack.push(iter->second);
38
10.7k
      else // we already have this style -> stop incoming endless loop
39
10.7k
        break;
40
48.4k
    }
41
151k
    else
42
151k
      break;
43
199k
  }
44
361k
  while (!styleIdStack.empty())
45
199k
  {
46
199k
    auto iter = styles.find(styleIdStack.top());
47
199k
    if (iter != styles.end())
48
22.2k
      style.override(iter->second);
49
199k
    styleIdStack.pop();
50
199k
  }
51
162k
  return style;
52
162k
}
53
54
}
55
56
}
57
58
libvisio::VSDStyles::VSDStyles() :
59
33.9k
  m_lineStyles(), m_fillStyles(), m_textBlockStyles(), m_charStyles(), m_paraStyles(),
60
33.9k
  m_lineStyleMasters(), m_fillStyleMasters(), m_textStyleMasters()
61
33.9k
{
62
33.9k
}
63
64
libvisio::VSDStyles::~VSDStyles()
65
96.1k
{
66
96.1k
}
67
68
void libvisio::VSDStyles::addLineStyle(unsigned lineStyleIndex, const VSDOptionalLineStyle &lineStyle)
69
11.0k
{
70
11.0k
  m_lineStyles[lineStyleIndex] = lineStyle;
71
11.0k
}
72
73
void libvisio::VSDStyles::addFillStyle(unsigned fillStyleIndex, const VSDOptionalFillStyle &fillStyle)
74
10.0k
{
75
10.0k
  m_fillStyles[fillStyleIndex] = fillStyle;
76
10.0k
}
77
78
void libvisio::VSDStyles::addTextBlockStyle(unsigned textStyleIndex, const VSDOptionalTextBlockStyle &textBlockStyle)
79
6.56k
{
80
6.56k
  m_textBlockStyles[textStyleIndex] = textBlockStyle;
81
6.56k
}
82
83
void libvisio::VSDStyles::addCharStyle(unsigned textStyleIndex, const VSDOptionalCharStyle &charStyle)
84
9.14k
{
85
9.14k
  m_charStyles[textStyleIndex] = charStyle;
86
9.14k
}
87
88
void libvisio::VSDStyles::addParaStyle(unsigned textStyleIndex, const VSDOptionalParaStyle &paraStyle)
89
3.88k
{
90
3.88k
  m_paraStyles[textStyleIndex] = paraStyle;
91
3.88k
}
92
93
void libvisio::VSDStyles::addLineStyleMaster(unsigned lineStyleIndex, unsigned lineStyleMaster)
94
83.0k
{
95
83.0k
  m_lineStyleMasters[lineStyleIndex] = lineStyleMaster;
96
83.0k
}
97
98
void libvisio::VSDStyles::addFillStyleMaster(unsigned fillStyleIndex, unsigned fillStyleMaster)
99
83.0k
{
100
83.0k
  m_fillStyleMasters[fillStyleIndex] = fillStyleMaster;
101
83.0k
}
102
103
void libvisio::VSDStyles::addTextStyleMaster(unsigned textStyleIndex, unsigned textStyleMaster)
104
83.0k
{
105
83.0k
  m_textStyleMasters[textStyleIndex] = textStyleMaster;
106
83.0k
}
107
108
libvisio::VSDOptionalLineStyle libvisio::VSDStyles::getOptionalLineStyle(unsigned lineStyleIndex) const
109
161k
{
110
161k
  return getOptionalStyle(m_lineStyleMasters, m_lineStyles, lineStyleIndex);
111
161k
}
112
113
libvisio::VSDOptionalFillStyle libvisio::VSDStyles::getOptionalFillStyle(unsigned fillStyleIndex) const
114
161k
{
115
161k
  return getOptionalStyle(m_fillStyleMasters, m_fillStyles, fillStyleIndex);
116
161k
}
117
118
libvisio::VSDFillStyle libvisio::VSDStyles::getFillStyle(unsigned fillStyleIndex, const libvisio::VSDXTheme *theme) const
119
149k
{
120
149k
  VSDFillStyle fillStyle;
121
149k
  fillStyle.override(getOptionalFillStyle(fillStyleIndex), theme);
122
149k
  return fillStyle;
123
149k
}
124
125
libvisio::VSDOptionalTextBlockStyle libvisio::VSDStyles::getOptionalTextBlockStyle(unsigned textStyleIndex) const
126
162k
{
127
162k
  return getOptionalStyle(m_textStyleMasters, m_textBlockStyles, textStyleIndex);
128
162k
}
129
130
libvisio::VSDOptionalCharStyle libvisio::VSDStyles::getOptionalCharStyle(unsigned textStyleIndex) const
131
162k
{
132
162k
  return getOptionalStyle(m_textStyleMasters, m_charStyles, textStyleIndex);
133
162k
}
134
135
libvisio::VSDOptionalParaStyle libvisio::VSDStyles::getOptionalParaStyle(unsigned textStyleIndex) const
136
162k
{
137
162k
  return getOptionalStyle(m_textStyleMasters, m_paraStyles, textStyleIndex);
138
162k
}
139
140
/* vim:set shiftwidth=2 softtabstop=2 expandtab: */