Avoid potential negative array index access to cached text.
[LibreOffice.git] / vcl / inc / sallayout.hxx
blobbdbd45189086ffcf3cb48047a7d67d3c523776a6
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 <sal/config.h>
25 #include <basegfx/point/b2dpoint.hxx>
26 #include <basegfx/polygon/b2dpolypolygon.hxx>
28 #include <vcl/dllapi.h>
29 #include <vcl/vclenum.hxx> // for typedef sal_UCS4
30 #include <vcl/vcllayout.hxx>
32 #include "ImplLayoutRuns.hxx"
33 #include "impglyphitem.hxx"
35 #include <com/sun/star/i18n/XBreakIterator.hpp>
37 #include <hb.h>
39 #include <memory>
40 #include <vector>
42 #define MAX_FALLBACK 16
44 class GenericSalLayout;
45 class SalGraphics;
46 enum class SalLayoutFlags;
48 namespace vcl::font {
49 class PhysicalFontFace;
52 namespace vcl::text {
53 class TextLayoutCache;
56 class VCL_DLLPUBLIC MultiSalLayout final : public SalLayout
58 public:
59 void DrawText(SalGraphics&) const override;
60 sal_Int32 GetTextBreak(double nMaxWidth, double nCharExtra, int nFactor) const override;
61 double GetTextWidth() const final override;
62 double FillDXArray(std::vector<double>* pDXArray, const OUString& rStr) const override;
63 void GetCaretPositions(std::vector<double>& rCaretPositions, const OUString& rStr) const override;
64 bool GetNextGlyph(const GlyphItem** pGlyph, basegfx::B2DPoint& rPos, int& nStart,
65 const LogicalFontInstance** ppGlyphFont = nullptr) const override;
66 bool GetOutline(basegfx::B2DPolyPolygonVector&) const override;
67 bool IsKashidaPosValid(int nCharPos, int nNextCharPos) const override;
68 SalLayoutGlyphs GetGlyphs() const final override;
70 // used only by OutputDevice::ImplLayout, TODO: make friend
71 explicit MultiSalLayout( std::unique_ptr<SalLayout> pBaseLayout );
72 void AddFallback(std::unique_ptr<SalLayout> pFallbackLayout, ImplLayoutRuns const &);
73 // give up ownership of the initial pBaseLayout taken by the ctor
74 std::unique_ptr<SalLayout> ReleaseBaseLayout();
75 bool LayoutText(vcl::text::ImplLayoutArgs&, const SalLayoutGlyphsImpl*) override;
76 void AdjustLayout(vcl::text::ImplLayoutArgs&) override;
77 void InitFont() const override;
79 void SetIncomplete(bool bIncomplete);
81 void ImplAdjustMultiLayout(vcl::text::ImplLayoutArgs& rArgs,
82 vcl::text::ImplLayoutArgs& rMultiArgs,
83 const double* pMultiDXArray);
85 SAL_DLLPRIVATE ImplLayoutRuns* GetFallbackRuns() { return maFallbackRuns; }
87 virtual ~MultiSalLayout() override;
89 private:
90 MultiSalLayout( const MultiSalLayout& ) = delete;
91 MultiSalLayout& operator=( const MultiSalLayout& ) = delete;
93 std::unique_ptr<GenericSalLayout> mpLayouts[ MAX_FALLBACK ];
94 ImplLayoutRuns maFallbackRuns[ MAX_FALLBACK ];
95 int mnLevel;
96 bool mbIncomplete;
99 class VCL_DLLPUBLIC GenericSalLayout : public SalLayout
101 friend void MultiSalLayout::ImplAdjustMultiLayout(
102 vcl::text::ImplLayoutArgs& rArgs,
103 vcl::text::ImplLayoutArgs& rMultiArgs,
104 const double* pMultiDXArray);
106 public:
107 GenericSalLayout(LogicalFontInstance&);
108 ~GenericSalLayout() override;
110 void AdjustLayout(vcl::text::ImplLayoutArgs&) final override;
111 bool LayoutText(vcl::text::ImplLayoutArgs&, const SalLayoutGlyphsImpl*) final override;
112 void DrawText(SalGraphics&) const final override;
113 SalLayoutGlyphs GetGlyphs() const final override;
115 bool IsKashidaPosValid(int nCharPos, int nNextCharPos) const final override;
117 // used by upper layers
118 double GetTextWidth() const final override;
119 double FillDXArray(std::vector<double>* pDXArray, const OUString& rStr) const final override;
120 sal_Int32 GetTextBreak(double nMaxWidth, double nCharExtra, int nFactor) const final override;
121 void GetCaretPositions(std::vector<double>& rCaretPositions, const OUString& rStr) const override;
123 // used by display layers
124 LogicalFontInstance& GetFont() const
125 { return *m_GlyphItems.GetFont(); }
127 bool GetNextGlyph(const GlyphItem** pGlyph, basegfx::B2DPoint& rPos, int& nStart,
128 const LogicalFontInstance** ppGlyphFont = nullptr) const override;
130 const SalLayoutGlyphsImpl& GlyphsImpl() const { return m_GlyphItems; }
132 private:
133 // for glyph+font+script fallback
134 void MoveGlyph(int nStart, double nNewXPos);
135 void DropGlyph(int nStart);
136 void Simplify(bool bIsBase);
138 GenericSalLayout( const GenericSalLayout& ) = delete;
139 GenericSalLayout& operator=( const GenericSalLayout& ) = delete;
141 void ApplyDXArray(const double*, const sal_Bool*);
142 void Justify(double nNewWidth);
143 void ApplyAsianKerning(std::u16string_view rStr);
145 void GetCharWidths(std::vector<double>& rCharWidths,
146 const OUString& rStr) const;
148 void SetNeedFallback(vcl::text::ImplLayoutArgs&, sal_Int32, bool);
150 bool HasVerticalAlternate(sal_UCS4 aChar, sal_UCS4 aNextChar);
152 void ParseFeatures(std::u16string_view name);
154 css::uno::Reference<css::i18n::XBreakIterator> mxBreak;
156 SalLayoutGlyphsImpl m_GlyphItems;
158 OString msLanguage;
159 std::vector<hb_feature_t> maFeatures;
161 hb_set_t* mpVertGlyphs;
162 const bool mbFuzzing;
165 #endif // INCLUDED_VCL_INC_SALLAYOUT_HXX
167 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */