sw a11y: clang-format SidebarWinAccessible code
[LibreOffice.git] / vcl / inc / sallayout.hxx
bloba8c0de8438c2c4efbba5b03e723d73b49de31732
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #ifndef INCLUDED_VCL_INC_SALLAYOUT_HXX
21 #define INCLUDED_VCL_INC_SALLAYOUT_HXX
23 #include <sal/config.h>
25 #include <basegfx/point/b2dpoint.hxx>
26 #include <basegfx/polygon/b2dpolypolygon.hxx>
28 #include <vcl/dllapi.h>
29 #include <vcl/vclenum.hxx> // for typedef sal_UCS4
30 #include <vcl/vcllayout.hxx>
32 #include "justificationdata.hxx"
33 #include "ImplLayoutRuns.hxx"
34 #include "impglyphitem.hxx"
36 #include <com/sun/star/i18n/XBreakIterator.hpp>
38 #include <hb.h>
40 #include <memory>
41 #include <span>
42 #include <vector>
44 #define MAX_FALLBACK 16
46 class GenericSalLayout;
47 class SalGraphics;
48 enum class SalLayoutFlags;
50 namespace vcl::font {
51 class PhysicalFontFace;
54 namespace vcl::text {
55 class TextLayoutCache;
58 class VCL_DLLPUBLIC MultiSalLayout final : public SalLayout
60 public:
61 SAL_DLLPRIVATE void DrawText(SalGraphics&) const override;
62 SAL_DLLPRIVATE sal_Int32 GetTextBreak(double nMaxWidth, double nCharExtra, int nFactor) const override;
63 SAL_DLLPRIVATE double GetTextWidth() const final override;
64 SAL_DLLPRIVATE double GetPartialTextWidth(sal_Int32 skipStart, sal_Int32 amt) const override;
65 SAL_DLLPRIVATE double FillDXArray(std::vector<double>* pDXArray, const OUString& rStr) const override;
66 SAL_DLLPRIVATE double FillPartialDXArray(std::vector<double>* pDXArray, const OUString& rStr,
67 sal_Int32 skipStart, sal_Int32 amt) const override;
68 SAL_DLLPRIVATE void GetCaretPositions(std::vector<double>& rCaretPositions, const OUString& rStr) const override;
69 SAL_DLLPRIVATE bool GetNextGlyph(const GlyphItem** pGlyph, basegfx::B2DPoint& rPos, int& nStart,
70 const LogicalFontInstance** ppGlyphFont = nullptr) const override;
71 SAL_DLLPRIVATE bool GetOutline(basegfx::B2DPolyPolygonVector&) const override;
72 SAL_DLLPRIVATE bool HasFontKashidaPositions() const override;
73 SAL_DLLPRIVATE bool IsKashidaPosValid(int nCharPos, int nNextCharPos) const override;
74 SAL_DLLPRIVATE SalLayoutGlyphs GetGlyphs() const final override;
76 // used only by OutputDevice::ImplLayout, TODO: make friend
77 SAL_DLLPRIVATE explicit MultiSalLayout( std::unique_ptr<SalLayout> pBaseLayout );
78 SAL_DLLPRIVATE void AddFallback(std::unique_ptr<SalLayout> pFallbackLayout, ImplLayoutRuns const &);
79 // give up ownership of the initial pBaseLayout taken by the ctor
80 SAL_DLLPRIVATE std::unique_ptr<SalLayout> ReleaseBaseLayout();
81 SAL_DLLPRIVATE bool LayoutText(vcl::text::ImplLayoutArgs&, const SalLayoutGlyphsImpl*) override;
82 SAL_DLLPRIVATE void AdjustLayout(vcl::text::ImplLayoutArgs&) override;
84 SAL_DLLPRIVATE void SetIncomplete(bool bIncomplete);
86 SAL_DLLPRIVATE void ImplAdjustMultiLayout(vcl::text::ImplLayoutArgs& rArgs,
87 vcl::text::ImplLayoutArgs& rMultiArgs,
88 const JustificationData& rstJustification);
90 SAL_DLLPRIVATE ImplLayoutRuns* GetFallbackRuns() { return maFallbackRuns; }
92 SAL_DLLPRIVATE virtual ~MultiSalLayout() override;
94 virtual void drawSalLayout(void* /*pSurface*/, const basegfx::BColor& /*rTextColor*/, bool /*bAntiAliased*/) const override;
96 private:
97 MultiSalLayout( const MultiSalLayout& ) = delete;
98 MultiSalLayout& operator=( const MultiSalLayout& ) = delete;
100 std::unique_ptr<GenericSalLayout> mpLayouts[ MAX_FALLBACK ];
101 ImplLayoutRuns maFallbackRuns[ MAX_FALLBACK ];
102 int mnLevel;
103 bool mbIncomplete;
106 class VCL_DLLPUBLIC GenericSalLayout : public SalLayout
108 friend void MultiSalLayout::ImplAdjustMultiLayout(vcl::text::ImplLayoutArgs& rArgs,
109 vcl::text::ImplLayoutArgs& rMultiArgs,
110 const JustificationData& rstJustification);
112 public:
113 GenericSalLayout(LogicalFontInstance&);
114 ~GenericSalLayout() override;
116 void AdjustLayout(vcl::text::ImplLayoutArgs&) final override;
117 bool LayoutText(vcl::text::ImplLayoutArgs&, const SalLayoutGlyphsImpl*) final override;
118 void DrawText(SalGraphics&) const final override;
119 SalLayoutGlyphs GetGlyphs() const final override;
121 bool HasFontKashidaPositions() const final override;
122 bool IsKashidaPosValid(int nCharPos, int nNextCharPos) const final override;
124 // used by upper layers
125 double GetTextWidth() const final override;
126 double GetPartialTextWidth(sal_Int32 skipStart, sal_Int32 amt) const final override;
127 double FillDXArray(std::vector<double>* pDXArray, const OUString& rStr) const final override;
128 double FillPartialDXArray(std::vector<double>* pDXArray, const OUString& rStr,
129 sal_Int32 skipStart, sal_Int32 amt) const final override;
130 sal_Int32 GetTextBreak(double nMaxWidth, double nCharExtra, int nFactor) const final override;
131 void GetCaretPositions(std::vector<double>& rCaretPositions, const OUString& rStr) const override;
133 // used by display layers
134 LogicalFontInstance& GetFont() const
135 { return *m_GlyphItems.GetFont(); }
137 bool GetNextGlyph(const GlyphItem** pGlyph, basegfx::B2DPoint& rPos, int& nStart,
138 const LogicalFontInstance** ppGlyphFont = nullptr) const override;
140 const SalLayoutGlyphsImpl& GlyphsImpl() const { return m_GlyphItems; }
142 virtual void drawSalLayout(void* /*pSurface*/, const basegfx::BColor& /*rTextColor*/, bool /*bAntiAliased*/) const override;
144 private:
145 // for glyph+font+script fallback
146 SAL_DLLPRIVATE void MoveGlyph(int nStart, double nNewXPos);
147 SAL_DLLPRIVATE void DropGlyph(int nStart);
148 SAL_DLLPRIVATE void Simplify(bool bIsBase);
150 GenericSalLayout( const GenericSalLayout& ) = delete;
151 GenericSalLayout& operator=( const GenericSalLayout& ) = delete;
153 SAL_DLLPRIVATE void ApplyJustificationData(const JustificationData& rstJustification);
154 SAL_DLLPRIVATE void Justify(double nNewWidth);
155 SAL_DLLPRIVATE void ApplyAsianKerning(std::u16string_view rStr);
157 SAL_DLLPRIVATE void GetCharWidths(std::vector<double>& rCharWidths,
158 const OUString& rStr) const;
160 SAL_DLLPRIVATE void SetNeedFallback(vcl::text::ImplLayoutArgs& rArgs, sal_Int32 nCharPos,
161 sal_Int32 nCharEnd, bool bRightToLeft);
163 SAL_DLLPRIVATE bool HasVerticalAlternate(sal_UCS4 aChar, sal_UCS4 aNextChar);
165 SAL_DLLPRIVATE void ParseFeatures(std::u16string_view name);
167 css::uno::Reference<css::i18n::XBreakIterator> mxBreak;
169 SalLayoutGlyphsImpl m_GlyphItems;
171 OString msLanguage;
172 std::vector<hb_feature_t> maFeatures;
174 hb_set_t* mpVertGlyphs;
175 const bool mbFuzzing;
176 bool m_bHasFontKashidaPositions = false;
179 #endif // INCLUDED_VCL_INC_SALLAYOUT_HXX
181 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */