bump product version to 6.4.0.3
[LibreOffice.git] / vcl / inc / sallayout.hxx
blobbe66bafd87e374df568e8303e4e40cbc3ed607b1
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 <iostream>
24 #include <memory>
25 #include <vector>
27 #include <hb.h>
29 #include <com/sun/star/i18n/XBreakIterator.hpp>
31 #include <basegfx/polygon/b2dpolypolygon.hxx>
32 #include <i18nlangtag/languagetag.hxx>
33 #include <tools/gen.hxx>
34 #include <vcl/dllapi.h>
35 #include <vcl/vclenum.hxx> // for typedef sal_UCS4
36 #include <vcl/devicecoordinate.hxx>
37 #include <vcl/vcllayout.hxx>
39 #include "impglyphitem.hxx"
41 #define MAX_FALLBACK 16
44 class SalGraphics;
45 class PhysicalFontFace;
46 class GenericSalLayout;
47 enum class SalLayoutFlags;
48 namespace vcl {
49 class TextLayoutCache;
52 // used for managing runs e.g. for BiDi, glyph and script fallback
53 class ImplLayoutRuns
55 private:
56 int mnRunIndex;
57 std::vector<int> maRuns;
59 public:
60 ImplLayoutRuns() { mnRunIndex = 0; maRuns.reserve(8); }
62 void Clear() { maRuns.clear(); }
63 void AddPos( int nCharPos, bool bRTL );
64 void AddRun( int nMinRunPos, int nEndRunPos, bool bRTL );
66 bool IsEmpty() const { return maRuns.empty(); }
67 void ResetPos() { mnRunIndex = 0; }
68 void NextRun() { mnRunIndex += 2; }
69 bool GetRun( int* nMinRunPos, int* nEndRunPos, bool* bRTL ) const;
70 bool GetNextPos( int* nCharPos, bool* bRTL );
71 bool PosIsInRun( int nCharPos ) const;
72 bool PosIsInAnyRun( int nCharPos ) const;
75 class VCL_DLLPUBLIC ImplLayoutArgs
77 public:
78 // string related inputs
79 LanguageTag const maLanguageTag;
80 SalLayoutFlags mnFlags;
81 const OUString& mrStr;
82 int const mnMinCharPos;
83 int const mnEndCharPos;
85 // performance hack
86 vcl::TextLayoutCache const* m_pTextLayoutCache;
88 // positioning related inputs
89 const DeviceCoordinate* mpDXArray; // in pixel units
90 DeviceCoordinate mnLayoutWidth; // in pixel units
91 int mnOrientation; // in 0-3600 system
93 // data for bidi and glyph+script fallback
94 ImplLayoutRuns maRuns;
95 ImplLayoutRuns maFallbackRuns;
97 ImplLayoutArgs( const OUString& rStr,
98 int nMinCharPos, int nEndCharPos, SalLayoutFlags nFlags,
99 const LanguageTag& rLanguageTag,
100 vcl::TextLayoutCache const* pLayoutCache);
102 void SetLayoutWidth( DeviceCoordinate nWidth ) { mnLayoutWidth = nWidth; }
103 void SetDXArray( const DeviceCoordinate* pDXArray ) { mpDXArray = pDXArray; }
104 void SetOrientation( int nOrientation ) { mnOrientation = nOrientation; }
106 void ResetPos()
107 { maRuns.ResetPos(); }
108 bool GetNextPos( int* nCharPos, bool* bRTL )
109 { return maRuns.GetNextPos( nCharPos, bRTL ); }
110 bool GetNextRun( int* nMinRunPos, int* nEndRunPos, bool* bRTL );
111 void NeedFallback( int nMinRunPos, int nEndRunPos, bool bRTL )
112 { maFallbackRuns.AddRun( nMinRunPos, nEndRunPos, bRTL ); }
113 // methods used by BiDi and glyph fallback
114 bool NeedFallback() const
115 { return !maFallbackRuns.IsEmpty(); }
116 bool PrepareFallback();
118 private:
119 void AddRun( int nMinCharPos, int nEndCharPos, bool bRTL );
122 // For nice SAL_INFO logging of ImplLayoutArgs values
123 std::ostream &operator <<(std::ostream& s, ImplLayoutArgs const &rArgs);
125 class MultiSalLayout final : public SalLayout
127 public:
128 void DrawText(SalGraphics&) const override;
129 sal_Int32 GetTextBreak(DeviceCoordinate nMaxWidth, DeviceCoordinate nCharExtra, int nFactor) const override;
130 DeviceCoordinate FillDXArray(DeviceCoordinate* pDXArray) const override;
131 void GetCaretPositions(int nArraySize, long* pCaretXArray) const override;
132 bool GetNextGlyph(const GlyphItem** pGlyph, Point& rPos, int& nStart,
133 const PhysicalFontFace** pFallbackFont = nullptr,
134 int* const pFallbackLevel = nullptr) const override;
135 bool GetOutline(basegfx::B2DPolyPolygonVector&) const override;
136 bool IsKashidaPosValid(int nCharPos) const override;
138 // used only by OutputDevice::ImplLayout, TODO: make friend
139 explicit MultiSalLayout( std::unique_ptr<SalLayout> pBaseLayout );
140 void AddFallback(std::unique_ptr<SalLayout> pFallbackLayout, ImplLayoutRuns const &);
141 bool LayoutText(ImplLayoutArgs&, const SalLayoutGlyphs*) override;
142 void AdjustLayout(ImplLayoutArgs&) override;
143 void InitFont() const override;
145 void SetIncomplete(bool bIncomplete);
147 public:
148 virtual ~MultiSalLayout() override;
150 private:
151 MultiSalLayout( const MultiSalLayout& ) = delete;
152 MultiSalLayout& operator=( const MultiSalLayout& ) = delete;
154 std::unique_ptr<GenericSalLayout> mpLayouts[ MAX_FALLBACK ];
155 ImplLayoutRuns maFallbackRuns[ MAX_FALLBACK ];
156 int mnLevel;
157 bool mbIncomplete;
160 class VCL_DLLPUBLIC GenericSalLayout : public SalLayout
162 friend void MultiSalLayout::AdjustLayout(ImplLayoutArgs&);
164 public:
165 GenericSalLayout(LogicalFontInstance&);
166 ~GenericSalLayout() override;
168 void AdjustLayout(ImplLayoutArgs&) final override;
169 bool LayoutText(ImplLayoutArgs&, const SalLayoutGlyphs*) final override;
170 void DrawText(SalGraphics&) const final override;
171 static std::shared_ptr<vcl::TextLayoutCache> CreateTextLayoutCache(OUString const&);
172 const SalLayoutGlyphs* GetGlyphs() const final override;
174 bool IsKashidaPosValid(int nCharPos) const final override;
176 // used by upper layers
177 DeviceCoordinate GetTextWidth() const final override;
178 DeviceCoordinate FillDXArray(DeviceCoordinate* pDXArray) const final override;
179 sal_Int32 GetTextBreak(DeviceCoordinate nMaxWidth, DeviceCoordinate nCharExtra, int nFactor) const final override;
180 void GetCaretPositions(int nArraySize, long* pCaretXArray) const final override;
182 // used by display layers
183 LogicalFontInstance& GetFont() const
184 { return m_GlyphItems.Impl()->GetFont(); }
186 bool GetNextGlyph(const GlyphItem** pGlyph, Point& rPos, int& nStart,
187 const PhysicalFontFace** pFallbackFont = nullptr,
188 int* const pFallbackLevel = nullptr) const override;
190 private:
191 // for glyph+font+script fallback
192 void MoveGlyph(int nStart, long nNewXPos);
193 void DropGlyph(int nStart);
194 void Simplify(bool bIsBase);
196 GenericSalLayout( const GenericSalLayout& ) = delete;
197 GenericSalLayout& operator=( const GenericSalLayout& ) = delete;
199 void ApplyDXArray(const ImplLayoutArgs&);
200 void Justify(DeviceCoordinate nNewWidth);
201 void ApplyAsianKerning(const OUString& rStr);
203 void GetCharWidths(DeviceCoordinate* pCharWidths) const;
205 void SetNeedFallback(ImplLayoutArgs&, sal_Int32, bool);
207 bool HasVerticalAlternate(sal_UCS4 aChar, sal_UCS4 aNextChar);
209 void ParseFeatures(const OUString& name);
211 css::uno::Reference<css::i18n::XBreakIterator> mxBreak;
213 SalLayoutGlyphs m_GlyphItems;
215 OString msLanguage;
216 std::vector<hb_feature_t> maFeatures;
218 hb_set_t* mpVertGlyphs;
219 const bool mbFuzzing;
222 #undef SalGraphics
224 #endif // INCLUDED_VCL_INC_SALLAYOUT_HXX
226 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */