LibreOffice Module vcl (master)  1
sallayout.hxx
Go to the documentation of this file.
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 #ifndef INCLUDED_VCL_INC_SALLAYOUT_HXX
21 #define INCLUDED_VCL_INC_SALLAYOUT_HXX
22 
23 #include <iostream>
24 #include <memory>
25 #include <vector>
26 
27 #include <hb.h>
28 
29 #include <com/sun/star/i18n/XBreakIterator.hpp>
30 
33 #include <tools/gen.hxx>
34 #include <tools/degree.hxx>
35 #include <vcl/dllapi.h>
36 #include <vcl/vclenum.hxx> // for typedef sal_UCS4
37 #include <vcl/devicecoordinate.hxx>
38 #include <vcl/vcllayout.hxx>
39 
40 #include "impglyphitem.hxx"
41 
42 #define MAX_FALLBACK 16
43 
44 
45 class SalGraphics;
46 class PhysicalFontFace;
47 class GenericSalLayout;
48 enum class SalLayoutFlags;
49 namespace vcl {
50  class TextLayoutCache;
51 }
52 
53 // used for managing runs e.g. for BiDi, glyph and script fallback
55 {
56 private:
58  std::vector<int> maRuns;
59 
60 public:
61  ImplLayoutRuns() { mnRunIndex = 0; maRuns.reserve(8); }
62 
63  void Clear() { maRuns.clear(); }
64  void AddPos( int nCharPos, bool bRTL );
65  void AddRun( int nMinRunPos, int nEndRunPos, bool bRTL );
66 
67  bool IsEmpty() const { return maRuns.empty(); }
68  void ResetPos() { mnRunIndex = 0; }
69  void NextRun() { mnRunIndex += 2; }
70  bool GetRun( int* nMinRunPos, int* nEndRunPos, bool* bRTL ) const;
71  bool GetNextPos( int* nCharPos, bool* bRTL );
72  bool PosIsInRun( int nCharPos ) const;
73  bool PosIsInAnyRun( int nCharPos ) const;
74 };
75 
77 {
78 public:
79  // string related inputs
82  const OUString& mrStr;
85 
86  // performance hack
88 
89  // positioning related inputs
90  const DeviceCoordinate* mpDXArray; // in pixel units
91  DeviceCoordinate mnLayoutWidth; // in pixel units
92  Degree10 mnOrientation; // in 0-3600 system
93 
94  // data for bidi and glyph+script fallback
97 
98  ImplLayoutArgs( const OUString& rStr,
99  int nMinCharPos, int nEndCharPos, SalLayoutFlags nFlags,
100  const LanguageTag& rLanguageTag,
101  vcl::TextLayoutCache const* pLayoutCache);
102 
103  void SetLayoutWidth( DeviceCoordinate nWidth ) { mnLayoutWidth = nWidth; }
104  void SetDXArray( const DeviceCoordinate* pDXArray ) { mpDXArray = pDXArray; }
105  void SetOrientation( Degree10 nOrientation ) { mnOrientation = nOrientation; }
106 
107  void ResetPos()
108  { maRuns.ResetPos(); }
109  bool GetNextPos( int* nCharPos, bool* bRTL )
110  { return maRuns.GetNextPos( nCharPos, bRTL ); }
111  bool GetNextRun( int* nMinRunPos, int* nEndRunPos, bool* bRTL );
112  void NeedFallback( int nMinRunPos, int nEndRunPos, bool bRTL )
113  { maFallbackRuns.AddRun( nMinRunPos, nEndRunPos, bRTL ); }
114  // methods used by BiDi and glyph fallback
115  bool NeedFallback() const
116  { return !maFallbackRuns.IsEmpty(); }
117  bool PrepareFallback();
118 
119 private:
120  void AddRun( int nMinCharPos, int nEndCharPos, bool bRTL );
121 };
122 
123 // For nice SAL_INFO logging of ImplLayoutArgs values
124 std::ostream &operator <<(std::ostream& s, ImplLayoutArgs const &rArgs);
125 
126 class MultiSalLayout final : public SalLayout
127 {
128 public:
129  void DrawText(SalGraphics&) const override;
130  sal_Int32 GetTextBreak(DeviceCoordinate nMaxWidth, DeviceCoordinate nCharExtra, int nFactor) const override;
131  DeviceCoordinate FillDXArray(DeviceCoordinate* pDXArray) const override;
132  void GetCaretPositions(int nArraySize, tools::Long* pCaretXArray) const override;
133  bool GetNextGlyph(const GlyphItem** pGlyph, Point& rPos, int& nStart,
134  const PhysicalFontFace** pFallbackFont = nullptr) const override;
135  bool GetOutline(basegfx::B2DPolyPolygonVector&) const override;
136  bool IsKashidaPosValid(int nCharPos) const override;
137  SalLayoutGlyphs GetGlyphs() const final override;
138 
139  // used only by OutputDevice::ImplLayout, TODO: make friend
140  explicit MultiSalLayout( std::unique_ptr<SalLayout> pBaseLayout );
141  void AddFallback(std::unique_ptr<SalLayout> pFallbackLayout, ImplLayoutRuns const &);
142  // give up ownership of the initial pBaseLayout taken by the ctor
143  std::unique_ptr<SalLayout> ReleaseBaseLayout();
144  bool LayoutText(ImplLayoutArgs&, const SalLayoutGlyphsImpl*) override;
145  void AdjustLayout(ImplLayoutArgs&) override;
146  void InitFont() const override;
147 
148  void SetIncomplete(bool bIncomplete);
149 
150 public:
151  virtual ~MultiSalLayout() override;
152 
153 private:
154  MultiSalLayout( const MultiSalLayout& ) = delete;
155  MultiSalLayout& operator=( const MultiSalLayout& ) = delete;
156 
157  std::unique_ptr<GenericSalLayout> mpLayouts[ MAX_FALLBACK ];
159  int mnLevel;
161 };
162 
164 {
166 
167 public:
169  ~GenericSalLayout() override;
170 
171  void AdjustLayout(ImplLayoutArgs&) final override;
172  bool LayoutText(ImplLayoutArgs&, const SalLayoutGlyphsImpl*) final override;
173  void DrawText(SalGraphics&) const final override;
174  static std::shared_ptr<vcl::TextLayoutCache> CreateTextLayoutCache(OUString const&);
175  SalLayoutGlyphs GetGlyphs() const final override;
176 
177  bool IsKashidaPosValid(int nCharPos) const final override;
178 
179  // used by upper layers
180  DeviceCoordinate GetTextWidth() const final override;
181  DeviceCoordinate FillDXArray(DeviceCoordinate* pDXArray) const final override;
182  sal_Int32 GetTextBreak(DeviceCoordinate nMaxWidth, DeviceCoordinate nCharExtra, int nFactor) const final override;
183  void GetCaretPositions(int nArraySize, tools::Long* pCaretXArray) const final override;
184 
185  // used by display layers
187  { return *m_GlyphItems.GetFont(); }
188 
189  bool GetNextGlyph(const GlyphItem** pGlyph, Point& rPos, int& nStart,
190  const PhysicalFontFace** pFallbackFont = nullptr) const override;
191 
192  const SalLayoutGlyphsImpl& GlyphsImpl() const { return m_GlyphItems; }
193 
194 private:
195  // for glyph+font+script fallback
196  void MoveGlyph(int nStart, tools::Long nNewXPos);
197  void DropGlyph(int nStart);
198  void Simplify(bool bIsBase);
199 
200  GenericSalLayout( const GenericSalLayout& ) = delete;
201  GenericSalLayout& operator=( const GenericSalLayout& ) = delete;
202 
203  void ApplyDXArray(const ImplLayoutArgs&);
204  void Justify(DeviceCoordinate nNewWidth);
205  void ApplyAsianKerning(const OUString& rStr);
206 
207  void GetCharWidths(DeviceCoordinate* pCharWidths) const;
208 
209  void SetNeedFallback(ImplLayoutArgs&, sal_Int32, bool);
210 
211  bool HasVerticalAlternate(sal_UCS4 aChar, sal_UCS4 aNextChar);
212 
213  void ParseFeatures(const OUString& name);
214 
215  css::uno::Reference<css::i18n::XBreakIterator> mxBreak;
216 
218 
219  OString msLanguage;
220  std::vector<hb_feature_t> maFeatures;
221 
222  hb_set_t* mpVertGlyphs;
223  const bool mbFuzzing;
224 };
225 
226 #undef SalGraphics
227 
228 #endif // INCLUDED_VCL_INC_SALLAYOUT_HXX
229 
230 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual sal_Int32 GetTextBreak(DeviceCoordinate nMaxWidth, DeviceCoordinate nCharExtra, int nFactor) const =0
MultiSalLayout & operator=(const MultiSalLayout &)=delete
void AddFallback(std::unique_ptr< SalLayout > pFallbackLayout, ImplLayoutRuns const &)
Definition: sallayout.cxx:1019
hb_set_t * mpVertGlyphs
Definition: sallayout.hxx:222
sal_uInt32 sal_UCS4
Definition: vclenum.hxx:194
std::unique_ptr< SalLayout > ReleaseBaseLayout()
Definition: sallayout.cxx:1004
bool GetNextPos(int *nCharPos, bool *bRTL)
Definition: sallayout.hxx:109
bool GetOutline(basegfx::B2DPolyPolygonVector &) const override
Definition: sallayout.cxx:1544
std::unique_ptr< GenericSalLayout > mpLayouts[MAX_FALLBACK]
Definition: sallayout.hxx:157
#define VCL_DLLPUBLIC
Definition: dllapi.h:29
#define MAX_FALLBACK
Definition: sallayout.hxx:42
long Long
void InitFont() const override
Definition: sallayout.cxx:1383
virtual DeviceCoordinate GetTextWidth() const
Definition: vcllayout.hxx:87
void SetLayoutWidth(DeviceCoordinate nWidth)
Definition: sallayout.hxx:103
Degree10 mnOrientation
Definition: sallayout.hxx:92
LogicalFontInstance & GetFont() const
Definition: sallayout.hxx:186
MultiSalLayout(std::unique_ptr< SalLayout > pBaseLayout)
Definition: sallayout.cxx:993
void NeedFallback(int nMinRunPos, int nEndRunPos, bool bRTL)
Definition: sallayout.hxx:112
void GetCaretPositions(int nArraySize, tools::Long *pCaretXArray) const override
Definition: sallayout.cxx:1491
std::vector< int > maRuns
Definition: sallayout.hxx:58
void SetIncomplete(bool bIncomplete)
Definition: sallayout.cxx:1009
void AddPos(int nCharPos, bool bRTL)
Definition: sallayout.cxx:231
bool IsEmpty() const
Definition: sallayout.hxx:67
virtual bool LayoutText(ImplLayoutArgs &, const SalLayoutGlyphsImpl *)=0
ImplLayoutRuns maRuns
Definition: sallayout.hxx:95
SalLayout & operator=(const SalLayout &)=delete
bool IsKashidaPosValid(int nCharPos) const override
Definition: sallayout.cxx:1561
virtual void AdjustLayout(ImplLayoutArgs &)
Definition: sallayout.cxx:553
DeviceCoordinate mnLayoutWidth
Definition: sallayout.hxx:91
SalLayoutGlyphsImpl m_GlyphItems
Definition: sallayout.hxx:217
virtual DeviceCoordinate FillDXArray(DeviceCoordinate *pDXArray) const =0
abstract base class for physical font faces
const OUString & mrStr
Definition: sallayout.hxx:82
std::ostream & operator<<(std::ostream &s, ImplLayoutArgs const &rArgs)
Definition: sallayout.cxx:52
const SalLayoutGlyphsImpl & GlyphsImpl() const
Definition: sallayout.hxx:192
virtual void DrawText(SalGraphics &) const =0
bool GetNextGlyph(const GlyphItem **pGlyph, Point &rPos, int &nStart, const PhysicalFontFace **pFallbackFont=nullptr) const override
Definition: sallayout.cxx:1515
OString msLanguage
Definition: sallayout.hxx:219
bool PosIsInRun(int nCharPos) const
Definition: sallayout.cxx:281
tools::Long DeviceCoordinate
virtual ~MultiSalLayout() override
Definition: sallayout.cxx:1015
virtual void GetCaretPositions(int nArraySize, tools::Long *pCaretXArray) const =0
vcl::TextLayoutCache const * m_pTextLayoutCache
Definition: sallayout.hxx:87
virtual SalLayoutGlyphs GetGlyphs() const
Definition: sallayout.cxx:650
bool NeedFallback() const
Definition: sallayout.hxx:115
void SetOrientation(Degree10 nOrientation)
Definition: sallayout.hxx:105
LanguageTag maLanguageTag
Definition: sallayout.hxx:80
bool GetNextPos(int *nCharPos, bool *bRTL)
Definition: sallayout.cxx:323
bool GetRun(int *nMinRunPos, int *nEndRunPos, bool *bRTL) const
Definition: sallayout.cxx:367
void AdjustLayout(ImplLayoutArgs &) override
Definition: sallayout.cxx:1040
SalLayoutFlags
Definition: outdev.hxx:120
std::vector< hb_feature_t > maFeatures
Definition: sallayout.hxx:220
void NextRun()
Definition: sallayout.hxx:69
const bool mbFuzzing
Definition: sallayout.hxx:223
void DrawText(SalGraphics &) const override
Definition: sallayout.cxx:1389
bool LayoutText(ImplLayoutArgs &, const SalLayoutGlyphsImpl *) override
Definition: sallayout.cxx:1031
void SetDXArray(const DeviceCoordinate *pDXArray)
Definition: sallayout.hxx:104
void AddRun(int nMinRunPos, int nEndRunPos, bool bRTL)
Definition: sallayout.cxx:257
virtual bool IsKashidaPosValid(int) const
Definition: vcllayout.hxx:89
void ResetPos()
Definition: sallayout.hxx:68
SalLayoutGlyphs GetGlyphs() const final override
Definition: sallayout.cxx:1584
SalLayoutFlags mnFlags
Definition: sallayout.hxx:81
css::uno::Reference< css::i18n::XBreakIterator > mxBreak
Definition: sallayout.hxx:215
ImplLayoutRuns maFallbackRuns
Definition: sallayout.hxx:96
ImplLayoutRuns maFallbackRuns[MAX_FALLBACK]
Definition: sallayout.hxx:158
virtual bool GetNextGlyph(const GlyphItem **pGlyph, Point &rPos, int &nStart, const PhysicalFontFace **pFallbackFont=nullptr) const =0
bool PosIsInAnyRun(int nCharPos) const
Definition: sallayout.cxx:302
DeviceCoordinate FillDXArray(DeviceCoordinate *pDXArray) const override
Definition: sallayout.cxx:1445
sal_Int32 GetTextBreak(DeviceCoordinate nMaxWidth, DeviceCoordinate nCharExtra, int nFactor) const override
Definition: sallayout.cxx:1404
const DeviceCoordinate * mpDXArray
Definition: sallayout.hxx:90
::std::vector< B2DPolyPolygon > B2DPolyPolygonVector