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