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 public:
86  virtual ~MultiSalLayout() override;
87 
88 private:
89  MultiSalLayout( const MultiSalLayout& ) = delete;
90  MultiSalLayout& operator=( const MultiSalLayout& ) = delete;
91 
92  std::unique_ptr<GenericSalLayout> mpLayouts[ MAX_FALLBACK ];
94  int mnLevel;
96 };
97 
99 {
101 
102 public:
104  ~GenericSalLayout() override;
105 
106  void AdjustLayout(vcl::text::ImplLayoutArgs&) final override;
107  bool LayoutText(vcl::text::ImplLayoutArgs&, const SalLayoutGlyphsImpl*) final override;
108  void DrawText(SalGraphics&) const final override;
109  static std::shared_ptr<vcl::text::TextLayoutCache> CreateTextLayoutCache(OUString const&);
110  SalLayoutGlyphs GetGlyphs() const final override;
111 
112  bool IsKashidaPosValid(int nCharPos) const final override;
113 
114  // used by upper layers
115  DeviceCoordinate GetTextWidth() const final override;
116  DeviceCoordinate FillDXArray(std::vector<DeviceCoordinate>* pDXArray) const final override;
117  sal_Int32 GetTextBreak(DeviceCoordinate nMaxWidth, DeviceCoordinate nCharExtra, int nFactor) const final override;
118  void GetCaretPositions(int nArraySize, sal_Int32* pCaretXArray) const final override;
119 
120  // used by display layers
122  { return *m_GlyphItems.GetFont(); }
123 
124  bool GetNextGlyph(const GlyphItem** pGlyph, DevicePoint& rPos, int& nStart,
125  const LogicalFontInstance** ppGlyphFont = nullptr,
126  const vcl::font::PhysicalFontFace** pFallbackFont = nullptr) const override;
127 
128  const SalLayoutGlyphsImpl& GlyphsImpl() const { return m_GlyphItems; }
129 
130 private:
131  // for glyph+font+script fallback
132  void MoveGlyph(int nStart, tools::Long nNewXPos);
133  void DropGlyph(int nStart);
134  void Simplify(bool bIsBase);
135 
136  GenericSalLayout( const GenericSalLayout& ) = delete;
137  GenericSalLayout& operator=( const GenericSalLayout& ) = delete;
138 
139  template<typename DC>
140  void ApplyDXArray(const DC*, SalLayoutFlags nLayoutFlags);
141  void Justify(DeviceCoordinate nNewWidth);
142  void ApplyAsianKerning(const OUString& rStr);
143 
144  void GetCharWidths(std::vector<DeviceCoordinate>& rCharWidths) const;
145 
146  void SetNeedFallback(vcl::text::ImplLayoutArgs&, sal_Int32, bool);
147 
148  bool HasVerticalAlternate(sal_UCS4 aChar, sal_UCS4 aNextChar);
149 
150  void ParseFeatures(const OUString& name);
151 
152  css::uno::Reference<css::i18n::XBreakIterator> mxBreak;
153 
155 
156  OString msLanguage;
157  std::vector<hb_feature_t> maFeatures;
158 
159  hb_set_t* mpVertGlyphs;
160  const bool mbFuzzing;
161 };
162 
163 #undef SalGraphics
164 
165 #endif // INCLUDED_VCL_INC_SALLAYOUT_HXX
166 
167 /* 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:1049
void GetCaretPositions(int nArraySize, sal_Int32 *pCaretXArray) const override
Definition: sallayout.cxx:1094
void AddFallback(std::unique_ptr< SalLayout > pFallbackLayout, ImplLayoutRuns const &)
Definition: sallayout.cxx:624
hb_set_t * mpVertGlyphs
Definition: sallayout.hxx:159
sal_uInt32 sal_UCS4
Definition: vclenum.hxx:192
virtual bool LayoutText(vcl::text::ImplLayoutArgs &, const SalLayoutGlyphsImpl *)=0
std::unique_ptr< SalLayout > ReleaseBaseLayout()
Definition: sallayout.cxx:609
bool GetOutline(basegfx::B2DPolyPolygonVector &) const override
Definition: sallayout.cxx:1148
std::unique_ptr< GenericSalLayout > mpLayouts[MAX_FALLBACK]
Definition: sallayout.hxx:92
#define VCL_DLLPUBLIC
Definition: dllapi.h:29
#define MAX_FALLBACK
Definition: sallayout.hxx:46
long Long
void InitFont() const override
Definition: sallayout.cxx:987
virtual DeviceCoordinate GetTextWidth() const
Definition: vcllayout.hxx:93
bool LayoutText(vcl::text::ImplLayoutArgs &, const SalLayoutGlyphsImpl *) override
Definition: sallayout.cxx:636
sal_Int32 DeviceCoordinate
LogicalFontInstance & GetFont() const
Definition: sallayout.hxx:121
MultiSalLayout(std::unique_ptr< SalLayout > pBaseLayout)
Definition: sallayout.cxx:599
void SetIncomplete(bool bIncomplete)
Definition: sallayout.cxx:614
SalLayout & operator=(const SalLayout &)=delete
bool IsKashidaPosValid(int nCharPos) const override
Definition: sallayout.cxx:1165
bool GetNextGlyph(const GlyphItem **pGlyph, DevicePoint &rPos, int &nStart, const LogicalFontInstance **ppGlyphFont=nullptr, const vcl::font::PhysicalFontFace **pFallbackFont=nullptr) const override
Definition: sallayout.cxx:1118
SalLayoutGlyphsImpl m_GlyphItems
Definition: sallayout.hxx:154
virtual void AdjustLayout(vcl::text::ImplLayoutArgs &)
Definition: sallayout.cxx:145
const SalLayoutGlyphsImpl & GlyphsImpl() const
Definition: sallayout.hxx:128
void AdjustLayout(vcl::text::ImplLayoutArgs &) override
Definition: sallayout.cxx:645
virtual void DrawText(SalGraphics &) const =0
OString msLanguage
Definition: sallayout.hxx:156
A PhysicalFontFaceCollection is created by a PhysicalFontCollection and becomes invalid when original...
virtual ~MultiSalLayout() override
Definition: sallayout.cxx:620
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:157
const bool mbFuzzing
Definition: sallayout.hxx:160
void DrawText(SalGraphics &) const override
Definition: sallayout.cxx:993
virtual bool IsKashidaPosValid(int) const
Definition: vcllayout.hxx:95
SalLayoutGlyphs GetGlyphs() const final override
Definition: sallayout.cxx:1188
css::uno::Reference< css::i18n::XBreakIterator > mxBreak
Definition: sallayout.hxx:152
ImplLayoutRuns maFallbackRuns[MAX_FALLBACK]
Definition: sallayout.hxx:93
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:1008
::std::vector< B2DPolyPolygon > B2DPolyPolygonVector
SalLayoutFlags