bump product version to 7.6.3.2-android
[LibreOffice.git] / include / vcl / kernarray.hxx
blob576ca1d4b22980db7a415d02d12828d9e99cfbce
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.
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
11 #include <sal/config.h>
12 #include <o3tl/span.hxx>
13 #include <cmath>
14 #include <vector>
16 class KernArraySpan final
18 private:
19 int m_nSubUnitFactor;
20 o3tl::span<const sal_Int32> m_DXArray;
22 public:
23 KernArraySpan()
24 : m_nSubUnitFactor(1)
28 KernArraySpan(o3tl::span<const sal_Int32> DXArray, int nSubUnitFactor = 1)
29 : m_nSubUnitFactor(nSubUnitFactor)
30 , m_DXArray(DXArray)
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
38 return std::round(static_cast<double>(m_DXArray[nIndex]) / m_nSubUnitFactor);
41 int get_factor() const { return m_nSubUnitFactor; }
42 sal_Int32 get_subunit(size_t nIndex) const { return m_DXArray[nIndex]; }
45 class KernArray final
47 private:
48 int m_nSubUnitFactor;
49 std::vector<sal_Int32> m_aDXArray;
51 public:
52 KernArray(int nSubUnitFactor = 1)
53 : m_nSubUnitFactor(nSubUnitFactor)
57 sal_Int32 operator[](size_t nIndex) const { return get(nIndex); }
58 sal_Int32 get(size_t nIndex) const
60 return std::round(static_cast<double>(m_aDXArray[nIndex]) / m_nSubUnitFactor);
63 int get_factor() const { return m_nSubUnitFactor; }
64 sal_Int32 get_subunit(size_t nIndex) const { return m_aDXArray[nIndex]; }
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; }
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(); }
76 void assign(KernArraySpan other)
78 m_nSubUnitFactor = other.get_factor();
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));
85 void resize(size_t nSize) { m_aDXArray.resize(nSize); }
86 void resize(size_t nSize, sal_Int32 nDefault)
88 m_aDXArray.resize(nSize, nDefault * m_nSubUnitFactor);
90 void reserve(size_t nCapacity) { m_aDXArray.reserve(nCapacity); }
92 bool operator==(const KernArray& rOther) const
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;
103 operator KernArraySpan() const { return KernArraySpan(m_aDXArray, m_nSubUnitFactor); }
106 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */