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 <sal/config.h>
24 
26 #include <tools/gen.hxx>
27 #include <tools/degree.hxx>
29 
30 #include <vcl/dllapi.h>
31 #include <vcl/devicecoordinate.hxx>
32 #include <vcl/vclenum.hxx> // for typedef sal_UCS4
33 #include <vcl/vcllayout.hxx>
34 
35 #include "ImplLayoutRuns.hxx"
36 #include "impglyphitem.hxx"
37 
38 #include <com/sun/star/i18n/XBreakIterator.hpp>
39 
40 #include <hb.h>
41 
42 #include <iostream>
43 #include <memory>
44 #include <vector>
45 
46 #define MAX_FALLBACK 16
47 
48 class GenericSalLayout;
49 class SalGraphics;
50 enum class SalLayoutFlags;
51 
52 namespace vcl::font {
53  class PhysicalFontFace;
54 }
55 
56 namespace vcl::text {
57  class TextLayoutCache;
58 }
59 
60 class MultiSalLayout final : public SalLayout
61 {
62 public:
63  void DrawText(SalGraphics&) const override;
64  sal_Int32 GetTextBreak(DeviceCoordinate nMaxWidth, DeviceCoordinate nCharExtra, int nFactor) const override;
65  DeviceCoordinate FillDXArray(std::vector<DeviceCoordinate>* pDXArray) const override;
66  void GetCaretPositions(int nArraySize, sal_Int32* pCaretXArray) const override;
67  bool GetNextGlyph(const GlyphItem** pGlyph, DevicePoint& rPos, int& nStart,
68  const LogicalFontInstance** ppGlyphFont = nullptr,
69  const vcl::font::PhysicalFontFace** pFallbackFont = nullptr) const override;
70  bool GetOutline(basegfx::B2DPolyPolygonVector&) const override;
71  bool IsKashidaPosValid(int nCharPos) const override;
72  SalLayoutGlyphs GetGlyphs() const final override;
73 
74  // used only by OutputDevice::ImplLayout, TODO: make friend
75  explicit MultiSalLayout( std::unique_ptr<SalLayout> pBaseLayout );
76  void AddFallback(std::unique_ptr<SalLayout> pFallbackLayout, ImplLayoutRuns const &);
77  // give up ownership of the initial pBaseLayout taken by the ctor
78  std::unique_ptr<SalLayout> ReleaseBaseLayout();
81  void InitFont() const override;
82 
83  void SetIncomplete(bool bIncomplete);
84 
85  template<typename DC>
87  vcl::text::ImplLayoutArgs& rMultiArgs,
88  const DC* pMultiDXArray);
89 
90  virtual ~MultiSalLayout() override;
91 
92 private:
93  MultiSalLayout( const MultiSalLayout& ) = delete;
94  MultiSalLayout& operator=( const MultiSalLayout& ) = delete;
95 
96  std::unique_ptr<GenericSalLayout> mpLayouts[ MAX_FALLBACK ];
98  int mnLevel;
100 };
101 
103 {
104  template<typename DC> friend void MultiSalLayout::ImplAdjustMultiLayout(
106  vcl::text::ImplLayoutArgs& rMultiArgs,
107  const DC* pMultiDXArray);
108 
109 public:
111  ~GenericSalLayout() override;
112 
113  void AdjustLayout(vcl::text::ImplLayoutArgs&) final override;
114  bool LayoutText(vcl::text::ImplLayoutArgs&, const SalLayoutGlyphsImpl*) final override;
115  void DrawText(SalGraphics&) const final override;
116  SalLayoutGlyphs GetGlyphs() const final override;
117 
118  bool IsKashidaPosValid(int nCharPos) const final override;
119 
120  // used by upper layers
121  DeviceCoordinate GetTextWidth() const final override;
122  DeviceCoordinate FillDXArray(std::vector<DeviceCoordinate>* pDXArray) const final override;
123  sal_Int32 GetTextBreak(DeviceCoordinate nMaxWidth, DeviceCoordinate nCharExtra, int nFactor) const final override;
124  void GetCaretPositions(int nArraySize, sal_Int32* pCaretXArray) const final override;
125 
126  // used by display layers
128  { return *m_GlyphItems.GetFont(); }
129 
130  bool GetNextGlyph(const GlyphItem** pGlyph, DevicePoint& rPos, int& nStart,
131  const LogicalFontInstance** ppGlyphFont = nullptr,
132  const vcl::font::PhysicalFontFace** pFallbackFont = nullptr) const override;
133 
134  const SalLayoutGlyphsImpl& GlyphsImpl() const { return m_GlyphItems; }
135 
136 private:
137  // for glyph+font+script fallback
138  void MoveGlyph(int nStart, tools::Long nNewXPos);
139  void DropGlyph(int nStart);
140  void Simplify(bool bIsBase);
141 
142  GenericSalLayout( const GenericSalLayout& ) = delete;
143  GenericSalLayout& operator=( const GenericSalLayout& ) = delete;
144 
145  template<typename DC>
146  void ApplyDXArray(const DC*, SalLayoutFlags nLayoutFlags);
147  void Justify(DeviceCoordinate nNewWidth);
148  void ApplyAsianKerning(const OUString& rStr);
149 
150  void GetCharWidths(std::vector<DeviceCoordinate>& rCharWidths) const;
151 
152  void SetNeedFallback(vcl::text::ImplLayoutArgs&, sal_Int32, bool);
153 
154  bool HasVerticalAlternate(sal_UCS4 aChar, sal_UCS4 aNextChar);
155 
156  void ParseFeatures(std::u16string_view name);
157 
158  css::uno::Reference<css::i18n::XBreakIterator> mxBreak;
159 
161 
162  OString msLanguage;
163  std::vector<hb_feature_t> maFeatures;
164 
165  hb_set_t* mpVertGlyphs;
166  const bool mbFuzzing;
167 };
168 
169 #endif // INCLUDED_VCL_INC_SALLAYOUT_HXX
170 
171 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual sal_Int32 GetTextBreak(DeviceCoordinate nMaxWidth, DeviceCoordinate nCharExtra, int nFactor) const =0
MultiSalLayout & operator=(const MultiSalLayout &)=delete
DeviceCoordinate FillDXArray(std::vector< DeviceCoordinate > *pDXArray) const override
Definition: sallayout.cxx:1066
void GetCaretPositions(int nArraySize, sal_Int32 *pCaretXArray) const override
Definition: sallayout.cxx:1111
void AddFallback(std::unique_ptr< SalLayout > pFallbackLayout, ImplLayoutRuns const &)
Definition: sallayout.cxx:630
hb_set_t * mpVertGlyphs
Definition: sallayout.hxx:165
sal_uInt32 sal_UCS4
Definition: vclenum.hxx:172
virtual bool LayoutText(vcl::text::ImplLayoutArgs &, const SalLayoutGlyphsImpl *)=0
std::unique_ptr< SalLayout > ReleaseBaseLayout()
Definition: sallayout.cxx:615
bool GetOutline(basegfx::B2DPolyPolygonVector &) const override
Definition: sallayout.cxx:1165
std::unique_ptr< GenericSalLayout > mpLayouts[MAX_FALLBACK]
Definition: sallayout.hxx:96
#define VCL_DLLPUBLIC
Definition: dllapi.h:29
#define MAX_FALLBACK
Definition: sallayout.hxx:46
long Long
void InitFont() const override
Definition: sallayout.cxx:1004
virtual DeviceCoordinate GetTextWidth() const
Definition: vcllayout.hxx:93
void ImplAdjustMultiLayout(vcl::text::ImplLayoutArgs &rArgs, vcl::text::ImplLayoutArgs &rMultiArgs, const DC *pMultiDXArray)
Definition: sallayout.cxx:729
bool LayoutText(vcl::text::ImplLayoutArgs &, const SalLayoutGlyphsImpl *) override
Definition: sallayout.cxx:642
sal_Int32 DeviceCoordinate
LogicalFontInstance & GetFont() const
Definition: sallayout.hxx:127
MultiSalLayout(std::unique_ptr< SalLayout > pBaseLayout)
Definition: sallayout.cxx:605
void SetIncomplete(bool bIncomplete)
Definition: sallayout.cxx:620
SalLayout & operator=(const SalLayout &)=delete
bool IsKashidaPosValid(int nCharPos) const override
Definition: sallayout.cxx:1182
bool GetNextGlyph(const GlyphItem **pGlyph, DevicePoint &rPos, int &nStart, const LogicalFontInstance **ppGlyphFont=nullptr, const vcl::font::PhysicalFontFace **pFallbackFont=nullptr) const override
Definition: sallayout.cxx:1135
SalLayoutGlyphsImpl m_GlyphItems
Definition: sallayout.hxx:160
virtual void AdjustLayout(vcl::text::ImplLayoutArgs &)
Definition: sallayout.cxx:145
const SalLayoutGlyphsImpl & GlyphsImpl() const
Definition: sallayout.hxx:134
void AdjustLayout(vcl::text::ImplLayoutArgs &) override
Definition: sallayout.cxx:651
virtual void DrawText(SalGraphics &) const =0
OString msLanguage
Definition: sallayout.hxx:162
A PhysicalFontFaceCollection is created by a PhysicalFontCollection and becomes invalid when original...
virtual ~MultiSalLayout() override
Definition: sallayout.cxx:626
virtual SalLayoutGlyphs GetGlyphs() const
Definition: sallayout.cxx:254
virtual void GetCaretPositions(int nArraySize, sal_Int32 *pCaretXArray) const =0
abstract base class for physical font faces
std::vector< hb_feature_t > maFeatures
Definition: sallayout.hxx:163
const bool mbFuzzing
Definition: sallayout.hxx:166
void DrawText(SalGraphics &) const override
Definition: sallayout.cxx:1010
virtual bool IsKashidaPosValid(int) const
Definition: vcllayout.hxx:95
SalLayoutGlyphs GetGlyphs() const final override
Definition: sallayout.cxx:1205
css::uno::Reference< css::i18n::XBreakIterator > mxBreak
Definition: sallayout.hxx:158
ImplLayoutRuns maFallbackRuns[MAX_FALLBACK]
Definition: sallayout.hxx:97
virtual bool GetNextGlyph(const GlyphItem **pGlyph, DevicePoint &rPos, int &nStart, const LogicalFontInstance **ppGlyphFont=nullptr, const vcl::font::PhysicalFontFace **pFallbackFont=nullptr) const =0
virtual DeviceCoordinate FillDXArray(std::vector< DeviceCoordinate > *pDXArray) const =0
sal_Int32 GetTextBreak(DeviceCoordinate nMaxWidth, DeviceCoordinate nCharExtra, int nFactor) const override
Definition: sallayout.cxx:1025
::std::vector< B2DPolyPolygon > B2DPolyPolygonVector
SalLayoutFlags