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 
24 #include <tools/gen.hxx>
25 #include <tools/degree.hxx>
27 
28 #include <vcl/dllapi.h>
29 #include <vcl/devicecoordinate.hxx>
30 #include <vcl/vclenum.hxx> // for typedef sal_UCS4
31 #include <vcl/vcllayout.hxx>
32 
33 #include "ImplLayoutRuns.hxx"
34 #include "impglyphitem.hxx"
35 
36 #include <com/sun/star/i18n/XBreakIterator.hpp>
37 
38 #include <hb.h>
39 
40 #include <iostream>
41 #include <memory>
42 #include <vector>
43 
44 #define MAX_FALLBACK 16
45 
46 
47 class SalGraphics;
48 class PhysicalFontFace;
49 class GenericSalLayout;
50 enum class SalLayoutFlags;
51 namespace vcl::text {
52  class TextLayoutCache;
53 }
54 
55 class MultiSalLayout final : public SalLayout
56 {
57 public:
58  void DrawText(SalGraphics&) const override;
59  sal_Int32 GetTextBreak(DeviceCoordinate nMaxWidth, DeviceCoordinate nCharExtra, int nFactor) const override;
60  DeviceCoordinate FillDXArray(std::vector<DeviceCoordinate>* pDXArray) const override;
61  void GetCaretPositions(int nArraySize, tools::Long* pCaretXArray) const override;
62  bool GetNextGlyph(const GlyphItem** pGlyph, Point& rPos, int& nStart,
63  const LogicalFontInstance** ppGlyphFont = nullptr,
64  const PhysicalFontFace** pFallbackFont = nullptr) const override;
65  bool GetOutline(basegfx::B2DPolyPolygonVector&) const override;
66  bool IsKashidaPosValid(int nCharPos) const override;
67  SalLayoutGlyphs GetGlyphs() const final override;
68 
69  // used only by OutputDevice::ImplLayout, TODO: make friend
70  explicit MultiSalLayout( std::unique_ptr<SalLayout> pBaseLayout );
71  void AddFallback(std::unique_ptr<SalLayout> pFallbackLayout, ImplLayoutRuns const &);
72  // give up ownership of the initial pBaseLayout taken by the ctor
73  std::unique_ptr<SalLayout> ReleaseBaseLayout();
76  void InitFont() const override;
77 
78  void SetIncomplete(bool bIncomplete);
79 
80 public:
81  virtual ~MultiSalLayout() override;
82 
83 private:
84  MultiSalLayout( const MultiSalLayout& ) = delete;
85  MultiSalLayout& operator=( const MultiSalLayout& ) = delete;
86 
87  std::unique_ptr<GenericSalLayout> mpLayouts[ MAX_FALLBACK ];
89  int mnLevel;
91 };
92 
94 {
96 
97 public:
99  ~GenericSalLayout() override;
100 
101  void AdjustLayout(vcl::text::ImplLayoutArgs&) final override;
102  bool LayoutText(vcl::text::ImplLayoutArgs&, const SalLayoutGlyphsImpl*) final override;
103  void DrawText(SalGraphics&) const final override;
104  static std::shared_ptr<vcl::text::TextLayoutCache> CreateTextLayoutCache(OUString const&);
105  SalLayoutGlyphs GetGlyphs() const final override;
106 
107  bool IsKashidaPosValid(int nCharPos) const final override;
108 
109  // used by upper layers
110  DeviceCoordinate GetTextWidth() const final override;
111  DeviceCoordinate FillDXArray(std::vector<DeviceCoordinate>* pDXArray) const final override;
112  sal_Int32 GetTextBreak(DeviceCoordinate nMaxWidth, DeviceCoordinate nCharExtra, int nFactor) const final override;
113  void GetCaretPositions(int nArraySize, tools::Long* pCaretXArray) const final override;
114 
115  // used by display layers
117  { return *m_GlyphItems.GetFont(); }
118 
119  bool GetNextGlyph(const GlyphItem** pGlyph, Point& rPos, int& nStart,
120  const LogicalFontInstance** ppGlyphFont = nullptr,
121  const PhysicalFontFace** pFallbackFont = nullptr) const override;
122 
123  const SalLayoutGlyphsImpl& GlyphsImpl() const { return m_GlyphItems; }
124 
125 private:
126  // for glyph+font+script fallback
127  void MoveGlyph(int nStart, tools::Long nNewXPos);
128  void DropGlyph(int nStart);
129  void Simplify(bool bIsBase);
130 
131  GenericSalLayout( const GenericSalLayout& ) = delete;
132  GenericSalLayout& operator=( const GenericSalLayout& ) = delete;
133 
134  void ApplyDXArray(const DeviceCoordinate*, SalLayoutFlags nLayoutFlags);
135  void Justify(DeviceCoordinate nNewWidth);
136  void ApplyAsianKerning(const OUString& rStr);
137 
138  void GetCharWidths(std::vector<DeviceCoordinate>& rCharWidths) const;
139 
140  void SetNeedFallback(vcl::text::ImplLayoutArgs&, sal_Int32, bool);
141 
142  bool HasVerticalAlternate(sal_UCS4 aChar, sal_UCS4 aNextChar);
143 
144  void ParseFeatures(const OUString& name);
145 
146  css::uno::Reference<css::i18n::XBreakIterator> mxBreak;
147 
149 
150  OString msLanguage;
151  std::vector<hb_feature_t> maFeatures;
152 
153  hb_set_t* mpVertGlyphs;
154  const bool mbFuzzing;
155 };
156 
157 #undef SalGraphics
158 
159 #endif // INCLUDED_VCL_INC_SALLAYOUT_HXX
160 
161 /* 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:1037
void AddFallback(std::unique_ptr< SalLayout > pFallbackLayout, ImplLayoutRuns const &)
Definition: sallayout.cxx:612
hb_set_t * mpVertGlyphs
Definition: sallayout.hxx:153
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:597
bool GetOutline(basegfx::B2DPolyPolygonVector &) const override
Definition: sallayout.cxx:1136
std::unique_ptr< GenericSalLayout > mpLayouts[MAX_FALLBACK]
Definition: sallayout.hxx:87
#define VCL_DLLPUBLIC
Definition: dllapi.h:29
#define MAX_FALLBACK
Definition: sallayout.hxx:44
long Long
void InitFont() const override
Definition: sallayout.cxx:975
virtual DeviceCoordinate GetTextWidth() const
Definition: vcllayout.hxx:88
bool LayoutText(vcl::text::ImplLayoutArgs &, const SalLayoutGlyphsImpl *) override
Definition: sallayout.cxx:624
LogicalFontInstance & GetFont() const
Definition: sallayout.hxx:116
MultiSalLayout(std::unique_ptr< SalLayout > pBaseLayout)
Definition: sallayout.cxx:587
void GetCaretPositions(int nArraySize, tools::Long *pCaretXArray) const override
Definition: sallayout.cxx:1082
void SetIncomplete(bool bIncomplete)
Definition: sallayout.cxx:602
SalLayout & operator=(const SalLayout &)=delete
bool IsKashidaPosValid(int nCharPos) const override
Definition: sallayout.cxx:1153
SalLayoutGlyphsImpl m_GlyphItems
Definition: sallayout.hxx:148
virtual void AdjustLayout(vcl::text::ImplLayoutArgs &)
Definition: sallayout.cxx:143
abstract base class for physical font faces
const SalLayoutGlyphsImpl & GlyphsImpl() const
Definition: sallayout.hxx:123
void AdjustLayout(vcl::text::ImplLayoutArgs &) override
Definition: sallayout.cxx:633
virtual void DrawText(SalGraphics &) const =0
OString msLanguage
Definition: sallayout.hxx:150
bool GetNextGlyph(const GlyphItem **pGlyph, Point &rPos, int &nStart, const LogicalFontInstance **ppGlyphFont=nullptr, const PhysicalFontFace **pFallbackFont=nullptr) const override
Definition: sallayout.cxx:1106
tools::Long DeviceCoordinate
virtual ~MultiSalLayout() override
Definition: sallayout.cxx:608
virtual void GetCaretPositions(int nArraySize, tools::Long *pCaretXArray) const =0
virtual SalLayoutGlyphs GetGlyphs() const
Definition: sallayout.cxx:242
std::vector< hb_feature_t > maFeatures
Definition: sallayout.hxx:151
const bool mbFuzzing
Definition: sallayout.hxx:154
void DrawText(SalGraphics &) const override
Definition: sallayout.cxx:981
virtual bool GetNextGlyph(const GlyphItem **pGlyph, Point &rPos, int &nStart, const LogicalFontInstance **ppGlyphFont=nullptr, const PhysicalFontFace **pFallbackFont=nullptr) const =0
virtual bool IsKashidaPosValid(int) const
Definition: vcllayout.hxx:90
SalLayoutGlyphs GetGlyphs() const final override
Definition: sallayout.cxx:1176
css::uno::Reference< css::i18n::XBreakIterator > mxBreak
Definition: sallayout.hxx:146
ImplLayoutRuns maFallbackRuns[MAX_FALLBACK]
Definition: sallayout.hxx:88
virtual DeviceCoordinate FillDXArray(std::vector< DeviceCoordinate > *pDXArray) const =0
sal_Int32 GetTextBreak(DeviceCoordinate nMaxWidth, DeviceCoordinate nCharExtra, int nFactor) const override
Definition: sallayout.cxx:996
::std::vector< B2DPolyPolygon > B2DPolyPolygonVector
SalLayoutFlags