1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#pragma once
#include <sal/config.h>
#include <cmath>
#include <span>
#include <vector>
class KernArraySpan final
{
private:
int m_nSubUnitFactor;
std::span<const sal_Int32> m_DXArray;
public:
KernArraySpan()
: m_nSubUnitFactor(1)
{
}
KernArraySpan(std::span<const sal_Int32> DXArray, int nSubUnitFactor = 1)
: m_nSubUnitFactor(nSubUnitFactor)
, m_DXArray(DXArray)
{
}
size_t size() const { return m_DXArray.size(); }
bool empty() const { return m_DXArray.empty(); }
sal_Int32 operator[](size_t nIndex) const { return get(nIndex); }
sal_Int32 get(size_t nIndex) const
{
return std::round(static_cast<double>(m_DXArray[nIndex]) / m_nSubUnitFactor);
}
int get_factor() const { return m_nSubUnitFactor; }
sal_Int32 get_subunit(size_t nIndex) const { return m_DXArray[nIndex]; }
};
class KernArray final
{
private:
int m_nSubUnitFactor;
std::vector<sal_Int32> m_aDXArray;
public:
KernArray(int nSubUnitFactor = 1)
: m_nSubUnitFactor(nSubUnitFactor)
{
}
sal_Int32 operator[](size_t nIndex) const { return get(nIndex); }
sal_Int32 get(size_t nIndex) const
{
return std::round(static_cast<double>(m_aDXArray[nIndex]) / m_nSubUnitFactor);
}
int get_factor() const { return m_nSubUnitFactor; }
sal_Int32 get_subunit(size_t nIndex) const { return m_aDXArray[nIndex]; }
void set_subunit(size_t nIndex, sal_Int32 nValue) { m_aDXArray[nIndex] = nValue; }
std::vector<sal_Int32>& get_subunit_array() { return m_aDXArray; }
void adjust(size_t nIndex, sal_Int32 nDiff) { m_aDXArray[nIndex] += nDiff * m_nSubUnitFactor; }
void set(size_t nIndex, sal_Int32 nValue) { m_aDXArray[nIndex] = nValue * m_nSubUnitFactor; }
void push_back(sal_Int32 nUnit) { m_aDXArray.push_back(nUnit * m_nSubUnitFactor); }
sal_Int32 back() const { return m_aDXArray.back() * m_nSubUnitFactor; }
size_t size() const { return m_aDXArray.size(); }
bool empty() const { return m_aDXArray.empty(); }
void clear() { m_aDXArray.clear(); }
void assign(KernArraySpan other)
{
m_nSubUnitFactor = other.get_factor();
m_aDXArray.clear();
size_t nLen = other.size();
m_aDXArray.reserve(nLen);
for (size_t i = 0; i < nLen; ++i)
m_aDXArray.push_back(other.get_subunit(i));
}
void resize(size_t nSize) { m_aDXArray.resize(nSize); }
void resize(size_t nSize, sal_Int32 nDefault)
{
m_aDXArray.resize(nSize, nDefault * m_nSubUnitFactor);
}
void reserve(size_t nCapacity) { m_aDXArray.reserve(nCapacity); }
bool operator==(const KernArray& rOther) const
{
size_t nSize = size();
if (nSize != rOther.size())
return false;
for (size_t i = 0; i < nSize; ++i)
if (m_aDXArray[i] != rOther.m_aDXArray[i])
return false;
return true;
}
operator KernArraySpan() const { return KernArraySpan(m_aDXArray, m_nSubUnitFactor); }
};
/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
|