1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
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/.
11 #include <sal/config.h>
12 #include <o3tl/span.hxx>
16 class KernArraySpan final
20 o3tl::span
<const sal_Int32
> m_DXArray
;
28 KernArraySpan(o3tl::span
<const sal_Int32
> DXArray
, int nSubUnitFactor
= 1)
29 : m_nSubUnitFactor(nSubUnitFactor
)
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
]; }
49 std::vector
<sal_Int32
> m_aDXArray
;
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();
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())
97 for (size_t i
= 0; i
< nSize
; ++i
)
98 if (m_aDXArray
[i
] != rOther
.m_aDXArray
[i
])
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: */