Coverage Report

Created: 2026-11-06 11:29

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/vcl/inc/sallayout.hxx
Line
Count
Source
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
#pragma once
21
22
#include <sal/config.h>
23
24
#include <basegfx/point/b2dpoint.hxx>
25
#include <basegfx/polygon/b2dpolypolygon.hxx>
26
27
#include <vcl/dllapi.h>
28
#include <vcl/vclenum.hxx> // for typedef sal_UCS4
29
#include <vcl/vcllayout.hxx>
30
31
#include "justificationdata.hxx"
32
#include "ImplLayoutRuns.hxx"
33
#include "impglyphitem.hxx"
34
35
#include <com/sun/star/i18n/XBreakIterator.hpp>
36
37
#include <hb.h>
38
39
#include <memory>
40
#include <span>
41
#include <vector>
42
43
77.8M
#define MAX_FALLBACK 16
44
45
class GenericSalLayout;
46
47
class VCL_DLLPUBLIC MultiSalLayout final : public SalLayout
48
{
49
public:
50
    SAL_DLLPRIVATE void            DrawText(SalGraphics&) const override;
51
    SAL_DLLPRIVATE sal_Int32       GetTextBreak(double nMaxWidth, double nCharExtra, int nFactor) const override;
52
    SAL_DLLPRIVATE double          GetTextWidth() const final override;
53
    SAL_DLLPRIVATE double          FillDXArray(std::vector<double>* pDXArray, const OUString& rStr) const override;
54
    SAL_DLLPRIVATE double FillPartialDXArray(std::vector<double>* pDXArray, const OUString& rStr,
55
                                             sal_Int32 skipStart, sal_Int32 amt) const override;
56
    SAL_DLLPRIVATE void            GetCaretPositions(std::vector<double>& rCaretPositions, const OUString& rStr) const override;
57
    SAL_DLLPRIVATE bool            GetNextGlyph(const GlyphItem** pGlyph, basegfx::B2DPoint& rPos, int& nStart,
58
                                 const LogicalFontInstance** ppGlyphFont = nullptr) const override;
59
    SAL_DLLPRIVATE bool            GetOutline(basegfx::B2DPolyPolygonVector&) const override;
60
    SAL_DLLPRIVATE bool HasFontKashidaPositions() const override;
61
    SAL_DLLPRIVATE bool            IsKashidaPosValid(int nCharPos, int nNextCharPos) const override;
62
    SAL_DLLPRIVATE SalLayoutGlyphs GetGlyphs() const final override;
63
64
    // used only by OutputDevice::ImplLayout, TODO: make friend
65
    SAL_DLLPRIVATE explicit        MultiSalLayout( std::unique_ptr<SalLayout> pBaseLayout );
66
    SAL_DLLPRIVATE void            AddFallback(std::unique_ptr<SalLayout> pFallbackLayout, ImplLayoutRuns const &);
67
    // give up ownership of the initial pBaseLayout taken by the ctor
68
    SAL_DLLPRIVATE std::unique_ptr<SalLayout>  ReleaseBaseLayout();
69
    SAL_DLLPRIVATE bool            LayoutText(vcl::text::ImplLayoutArgs&, const SalLayoutGlyphsImpl*) override;
70
    SAL_DLLPRIVATE void            AdjustLayout(vcl::text::ImplLayoutArgs&) override;
71
72
    SAL_DLLPRIVATE void SetIncomplete(bool bIncomplete);
73
74
    SAL_DLLPRIVATE void ImplAdjustMultiLayout(vcl::text::ImplLayoutArgs& rArgs,
75
                                              vcl::text::ImplLayoutArgs& rMultiArgs,
76
                                              const JustificationData& rstJustification);
77
78
0
    SAL_DLLPRIVATE ImplLayoutRuns* GetFallbackRuns() { return maFallbackRuns; }
79
80
    SAL_DLLPRIVATE virtual         ~MultiSalLayout() override;
81
82
    virtual void drawSalLayout(void* /*pSurface*/, const basegfx::BColor& /*rTextColor*/, bool /*bAntiAliased*/) const override;
83
84
private:
85
                    MultiSalLayout( const MultiSalLayout& ) = delete;
86
                    MultiSalLayout& operator=( const MultiSalLayout& ) = delete;
87
88
    std::unique_ptr<GenericSalLayout> mpLayouts[ MAX_FALLBACK ];
89
    ImplLayoutRuns  maFallbackRuns[ MAX_FALLBACK ];
90
    int             mnLevel;
91
    bool            mbIncomplete;
92
};
93
94
class VCL_DLLPUBLIC GenericSalLayout : public SalLayout
95
{
96
    friend void MultiSalLayout::ImplAdjustMultiLayout(vcl::text::ImplLayoutArgs& rArgs,
97
                                                      vcl::text::ImplLayoutArgs& rMultiArgs,
98
                                                      const JustificationData& rstJustification);
99
100
public:
101
                    GenericSalLayout(LogicalFontInstance&);
102
                    ~GenericSalLayout() override;
103
104
    void            AdjustLayout(vcl::text::ImplLayoutArgs&) final override;
105
    bool            LayoutText(vcl::text::ImplLayoutArgs&, const SalLayoutGlyphsImpl*) final override;
106
    void            DrawText(SalGraphics&) const final override;
107
    SalLayoutGlyphs GetGlyphs() const final override;
108
109
    bool HasFontKashidaPositions() const final override;
110
    bool            IsKashidaPosValid(int nCharPos, int nNextCharPos) const final override;
111
112
    // used by upper layers
113
    double          GetTextWidth() const final override;
114
    double          FillDXArray(std::vector<double>* pDXArray, const OUString& rStr) const final override;
115
    double FillPartialDXArray(std::vector<double>* pDXArray, const OUString& rStr,
116
                              sal_Int32 skipStart, sal_Int32 amt) const final override;
117
    sal_Int32       GetTextBreak(double nMaxWidth, double nCharExtra, int nFactor) const final override;
118
    void            GetCaretPositions(std::vector<double>& rCaretPositions, const OUString& rStr) const override;
119
120
    // used by display layers
121
    LogicalFontInstance& GetFont() const
122
27.0M
        { return *m_GlyphItems.GetFont(); }
123
124
    bool            GetNextGlyph(const GlyphItem** pGlyph, basegfx::B2DPoint& rPos, int& nStart,
125
                                 const LogicalFontInstance** ppGlyphFont = nullptr) const override;
126
127
0
    const SalLayoutGlyphsImpl& GlyphsImpl() const { return m_GlyphItems; }
128
129
    virtual void drawSalLayout(void* /*pSurface*/, const basegfx::BColor& /*rTextColor*/, bool /*bAntiAliased*/) const override;
130
131
private:
132
    // for glyph+font+script fallback
133
    SAL_DLLPRIVATE void MoveGlyph(int nStart, double nNewXPos);
134
    SAL_DLLPRIVATE void DropGlyph(int nStart);
135
    SAL_DLLPRIVATE void Simplify(bool bIsBase);
136
137
                    GenericSalLayout( const GenericSalLayout& ) = delete;
138
                    GenericSalLayout& operator=( const GenericSalLayout& ) = delete;
139
140
    SAL_DLLPRIVATE void ApplyJustificationData(const JustificationData& rstJustification);
141
    SAL_DLLPRIVATE void Justify(double nNewWidth);
142
    SAL_DLLPRIVATE void ApplyAsianKerning(std::u16string_view rStr);
143
144
    SAL_DLLPRIVATE void GetCharWidths(std::vector<double>& rCharWidths,
145
                                  const OUString& rStr) const;
146
147
    SAL_DLLPRIVATE void SetNeedFallback(vcl::text::ImplLayoutArgs& rArgs, sal_Int32 nCharPos,
148
                                        sal_Int32 nCharEnd, bool bRightToLeft);
149
150
    SAL_DLLPRIVATE bool HasVerticalAlternate(sal_UCS4 aChar, sal_UCS4 aNextChar);
151
152
    SAL_DLLPRIVATE void ParseFeatures(std::u16string_view name);
153
154
    css::uno::Reference<css::i18n::XBreakIterator> mxBreak;
155
156
    SalLayoutGlyphsImpl m_GlyphItems;
157
158
    OString         msLanguage;
159
    std::vector<hb_feature_t> maFeatures;
160
161
    hb_set_t*       mpVertGlyphs;
162
    const bool      mbFuzzing;
163
    bool m_bHasFontKashidaPositions = false;
164
};
165
166
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */