/src/libreoffice/vcl/inc/sallayout.hxx
Line | Count | Source (jump to first uncovered line) |
1 | | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
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 | | * This file incorporates work covered by the following license notice: |
10 | | * |
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 . |
18 | | */ |
19 | | |
20 | | #pragma once |
21 | | |
22 | | #include <sal/config.h> |
23 | | |
24 | | #include <basegfx/point/b2dpoint.hxx> |
25 | | #include <basegfx/polygon/b2dpolypolygon.hxx> |
26 | | |
27 | | #include <vcl/dllapi.h> |
28 | | #include <vcl/vclenum.hxx> // for typedef sal_UCS4 |
29 | | #include <vcl/vcllayout.hxx> |
30 | | |
31 | | #include "justificationdata.hxx" |
32 | | #include "ImplLayoutRuns.hxx" |
33 | | #include "impglyphitem.hxx" |
34 | | |
35 | | #include <com/sun/star/i18n/XBreakIterator.hpp> |
36 | | |
37 | | #include <hb.h> |
38 | | |
39 | | #include <memory> |
40 | | #include <span> |
41 | | #include <vector> |
42 | | |
43 | 108M | #define MAX_FALLBACK 16 |
44 | | |
45 | | class GenericSalLayout; |
46 | | |
47 | | class VCL_DLLPUBLIC MultiSalLayout final : public SalLayout |
48 | | { |
49 | | public: |
50 | | SAL_DLLPRIVATE void DrawText(SalGraphics&) const override; |
51 | | SAL_DLLPRIVATE sal_Int32 GetTextBreak(double nMaxWidth, double nCharExtra, int nFactor) const override; |
52 | | SAL_DLLPRIVATE double GetTextWidth() const final override; |
53 | | SAL_DLLPRIVATE double GetPartialTextWidth(sal_Int32 skipStart, sal_Int32 amt) const override; |
54 | | SAL_DLLPRIVATE double FillDXArray(std::vector<double>* pDXArray, const OUString& rStr) const override; |
55 | | SAL_DLLPRIVATE double FillPartialDXArray(std::vector<double>* pDXArray, const OUString& rStr, |
56 | | sal_Int32 skipStart, sal_Int32 amt) const override; |
57 | | SAL_DLLPRIVATE void GetCaretPositions(std::vector<double>& rCaretPositions, const OUString& rStr) const override; |
58 | | SAL_DLLPRIVATE bool GetNextGlyph(const GlyphItem** pGlyph, basegfx::B2DPoint& rPos, int& nStart, |
59 | | const LogicalFontInstance** ppGlyphFont = nullptr) const override; |
60 | | SAL_DLLPRIVATE bool GetOutline(basegfx::B2DPolyPolygonVector&) const override; |
61 | | SAL_DLLPRIVATE bool HasFontKashidaPositions() const override; |
62 | | SAL_DLLPRIVATE bool IsKashidaPosValid(int nCharPos, int nNextCharPos) const override; |
63 | | SAL_DLLPRIVATE SalLayoutGlyphs GetGlyphs() const final override; |
64 | | |
65 | | // used only by OutputDevice::ImplLayout, TODO: make friend |
66 | | SAL_DLLPRIVATE explicit MultiSalLayout( std::unique_ptr<SalLayout> pBaseLayout ); |
67 | | SAL_DLLPRIVATE void AddFallback(std::unique_ptr<SalLayout> pFallbackLayout, ImplLayoutRuns const &); |
68 | | // give up ownership of the initial pBaseLayout taken by the ctor |
69 | | SAL_DLLPRIVATE std::unique_ptr<SalLayout> ReleaseBaseLayout(); |
70 | | SAL_DLLPRIVATE bool LayoutText(vcl::text::ImplLayoutArgs&, const SalLayoutGlyphsImpl*) override; |
71 | | SAL_DLLPRIVATE void AdjustLayout(vcl::text::ImplLayoutArgs&) override; |
72 | | |
73 | | SAL_DLLPRIVATE void SetIncomplete(bool bIncomplete); |
74 | | |
75 | | SAL_DLLPRIVATE void ImplAdjustMultiLayout(vcl::text::ImplLayoutArgs& rArgs, |
76 | | vcl::text::ImplLayoutArgs& rMultiArgs, |
77 | | const JustificationData& rstJustification); |
78 | | |
79 | 0 | SAL_DLLPRIVATE ImplLayoutRuns* GetFallbackRuns() { return maFallbackRuns; } |
80 | | |
81 | | SAL_DLLPRIVATE virtual ~MultiSalLayout() override; |
82 | | |
83 | | virtual void drawSalLayout(void* /*pSurface*/, const basegfx::BColor& /*rTextColor*/, bool /*bAntiAliased*/) const override; |
84 | | |
85 | | private: |
86 | | MultiSalLayout( const MultiSalLayout& ) = delete; |
87 | | MultiSalLayout& operator=( const MultiSalLayout& ) = delete; |
88 | | |
89 | | std::unique_ptr<GenericSalLayout> mpLayouts[ MAX_FALLBACK ]; |
90 | | ImplLayoutRuns maFallbackRuns[ MAX_FALLBACK ]; |
91 | | int mnLevel; |
92 | | bool mbIncomplete; |
93 | | }; |
94 | | |
95 | | class VCL_DLLPUBLIC GenericSalLayout : public SalLayout |
96 | | { |
97 | | friend void MultiSalLayout::ImplAdjustMultiLayout(vcl::text::ImplLayoutArgs& rArgs, |
98 | | vcl::text::ImplLayoutArgs& rMultiArgs, |
99 | | const JustificationData& rstJustification); |
100 | | |
101 | | public: |
102 | | GenericSalLayout(LogicalFontInstance&); |
103 | | ~GenericSalLayout() override; |
104 | | |
105 | | void AdjustLayout(vcl::text::ImplLayoutArgs&) final override; |
106 | | bool LayoutText(vcl::text::ImplLayoutArgs&, const SalLayoutGlyphsImpl*) final override; |
107 | | void DrawText(SalGraphics&) const final override; |
108 | | SalLayoutGlyphs GetGlyphs() const final override; |
109 | | |
110 | | bool HasFontKashidaPositions() const final override; |
111 | | bool IsKashidaPosValid(int nCharPos, int nNextCharPos) const final override; |
112 | | |
113 | | // used by upper layers |
114 | | double GetTextWidth() const final override; |
115 | | double GetPartialTextWidth(sal_Int32 skipStart, sal_Int32 amt) const final override; |
116 | | double FillDXArray(std::vector<double>* pDXArray, const OUString& rStr) const final override; |
117 | | double FillPartialDXArray(std::vector<double>* pDXArray, const OUString& rStr, |
118 | | sal_Int32 skipStart, sal_Int32 amt) const final override; |
119 | | sal_Int32 GetTextBreak(double nMaxWidth, double nCharExtra, int nFactor) const final override; |
120 | | void GetCaretPositions(std::vector<double>& rCaretPositions, const OUString& rStr) const override; |
121 | | |
122 | | // used by display layers |
123 | | LogicalFontInstance& GetFont() const |
124 | 73.1M | { return *m_GlyphItems.GetFont(); } |
125 | | |
126 | | bool GetNextGlyph(const GlyphItem** pGlyph, basegfx::B2DPoint& rPos, int& nStart, |
127 | | const LogicalFontInstance** ppGlyphFont = nullptr) const override; |
128 | | |
129 | 0 | const SalLayoutGlyphsImpl& GlyphsImpl() const { return m_GlyphItems; } |
130 | | |
131 | | virtual void drawSalLayout(void* /*pSurface*/, const basegfx::BColor& /*rTextColor*/, bool /*bAntiAliased*/) const override; |
132 | | |
133 | | private: |
134 | | // for glyph+font+script fallback |
135 | | SAL_DLLPRIVATE void MoveGlyph(int nStart, double nNewXPos); |
136 | | SAL_DLLPRIVATE void DropGlyph(int nStart); |
137 | | SAL_DLLPRIVATE void Simplify(bool bIsBase); |
138 | | |
139 | | GenericSalLayout( const GenericSalLayout& ) = delete; |
140 | | GenericSalLayout& operator=( const GenericSalLayout& ) = delete; |
141 | | |
142 | | SAL_DLLPRIVATE void ApplyJustificationData(const JustificationData& rstJustification); |
143 | | SAL_DLLPRIVATE void Justify(double nNewWidth); |
144 | | SAL_DLLPRIVATE void ApplyAsianKerning(std::u16string_view rStr); |
145 | | |
146 | | SAL_DLLPRIVATE void GetCharWidths(std::vector<double>& rCharWidths, |
147 | | const OUString& rStr) const; |
148 | | |
149 | | SAL_DLLPRIVATE void SetNeedFallback(vcl::text::ImplLayoutArgs& rArgs, sal_Int32 nCharPos, |
150 | | sal_Int32 nCharEnd, bool bRightToLeft); |
151 | | |
152 | | SAL_DLLPRIVATE bool HasVerticalAlternate(sal_UCS4 aChar, sal_UCS4 aNextChar); |
153 | | |
154 | | SAL_DLLPRIVATE void ParseFeatures(std::u16string_view name); |
155 | | |
156 | | css::uno::Reference<css::i18n::XBreakIterator> mxBreak; |
157 | | |
158 | | SalLayoutGlyphsImpl m_GlyphItems; |
159 | | |
160 | | OString msLanguage; |
161 | | std::vector<hb_feature_t> maFeatures; |
162 | | |
163 | | hb_set_t* mpVertGlyphs; |
164 | | const bool mbFuzzing; |
165 | | bool m_bHasFontKashidaPositions = false; |
166 | | }; |
167 | | |
168 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |