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/types.h>
12 #include <o3tl/typed_flags_set.hxx>
17 enum class ClusterJustificationFlags
20 KashidaPosition
= 0x0001,
26 struct typed_flags
<ClusterJustificationFlags
> : is_typed_flags
<ClusterJustificationFlags
, 0x0001>
31 class ClusterJustification
34 double m_nTotalAdvance
= 0.0;
35 ClusterJustificationFlags m_nFlags
= ClusterJustificationFlags::NONE
;
38 class JustificationData
41 std::vector
<ClusterJustification
> m_aClusters
;
42 sal_Int32 m_nBaseIndex
= 0;
43 sal_Int32 m_nEndIndex
= 0;
44 bool m_bContainsAdvances
= false;
45 bool m_bContainsKashidaPositions
= false;
47 [[nodiscard
]] inline std::optional
<size_t> GetIndex(sal_Int32 nClusterId
) const
49 auto nIndex
= nClusterId
- m_nBaseIndex
;
50 if (nIndex
>= 0 && nIndex
< static_cast<sal_Int32
>(m_aClusters
.size()))
52 return static_cast<size_t>(nIndex
);
59 JustificationData() = default;
60 JustificationData(sal_Int32 nBaseIndex
, sal_Int32 nSize
)
61 : m_nBaseIndex(nBaseIndex
)
62 , m_nEndIndex(nBaseIndex
+ nSize
)
64 m_aClusters
.resize(nSize
);
67 [[nodiscard
]] bool empty() const { return m_aClusters
.empty(); }
69 [[nodiscard
]] bool ContainsAdvances() const { return m_bContainsAdvances
; }
70 [[nodiscard
]] bool ContainsKashidaPositions() const { return m_bContainsKashidaPositions
; }
72 [[nodiscard
]] double GetTotalAdvance(sal_Int32 nClusterId
) const
74 if (nClusterId
< m_nBaseIndex
|| m_aClusters
.empty())
79 if (nClusterId
< m_nEndIndex
)
81 return m_aClusters
.at(nClusterId
- m_nBaseIndex
).m_nTotalAdvance
;
84 return m_aClusters
.back().m_nTotalAdvance
;
87 [[nodiscard
]] std::optional
<bool> GetPositionHasKashida(sal_Int32 nClusterId
) const
89 if (auto nIndex
= GetIndex(nClusterId
); nIndex
.has_value())
91 return std::optional
<bool>{ m_aClusters
.at(*nIndex
).m_nFlags
92 & ClusterJustificationFlags::KashidaPosition
};
98 void SetTotalAdvance(sal_Int32 nClusterId
, double nValue
)
100 if (auto nIndex
= GetIndex(nClusterId
); nIndex
.has_value())
102 m_aClusters
.at(*nIndex
).m_nTotalAdvance
= nValue
;
103 m_bContainsAdvances
= true;
107 void SetKashidaPosition(sal_Int32 nClusterId
, bool bValue
)
109 if (auto nIndex
= GetIndex(nClusterId
); nIndex
.has_value())
113 m_aClusters
.at(*nIndex
).m_nFlags
|= ClusterJustificationFlags::KashidaPosition
;
117 m_aClusters
.at(*nIndex
).m_nFlags
&= ~ClusterJustificationFlags::KashidaPosition
;
120 m_bContainsKashidaPositions
= true;
125 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */