tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / include / vcl / vcllayout.hxx
blobe6b743f626d5663d79e102a6edf711291a04179b
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 #pragma once
22 #include <basegfx/point/b2dpoint.hxx>
23 #include <basegfx/polygon/b2dpolypolygon.hxx>
24 #include <basegfx/range/b2drectangle.hxx>
25 #include <i18nlangtag/languagetag.hxx>
26 #include <tools/gen.hxx>
27 #include <tools/degree.hxx>
29 #include <vcl/glyphitem.hxx>
30 #include <vcl/dllapi.h>
32 class LogicalFontInstance;
33 namespace vcl::text { class ImplLayoutArgs; }
34 namespace vcl::font { class PhysicalFontFace; }
35 namespace basegfx { class BColor; }
36 class SalGraphics;
37 class GlyphItem;
39 // all positions/widths are in font units
40 // one exception: drawposition is in pixel units
42 // Unfortunately there is little documentation to help implementors of
43 // new classes derived from SalLayout ("layout engines"), and the code
44 // and data structures are far from obvious.
46 // For instance, I *think* the important virtual functions in the
47 // layout engines are called in this order:
49 // * LayoutText()
50 // * AdjustLayout(), any number of times (but presumably
51 // usually not at all or just once)
52 // * Optionally, DrawText()
54 // Functions that just return information like GetTexWidth() and
55 // FillDXArray() are called after LayoutText() and before DrawText().
57 // Another important questions is which parts of an ImplLayoutArgs can
58 // be changed by callers between LayoutText() and AdjustLayout()
59 // calls. It probably makes sense only if one assumes that the "string
60 // related inputs" part are not changed after LayoutText().
62 // But why use the same ImplLayoutArgs structure as parameter for both
63 // LayoutText() and AdjustLayout() in the first place? And why
64 // duplicate some of the fields in both SalLayout and ImplLayoutArgs
65 // (mnMinCharPos, mnEndCharPos, mnLayoutFlags==mnFlags,
66 // mnOrientation)? Lost in history...
68 class VCL_DLLPUBLIC SalLayout
70 public:
71 virtual ~SalLayout();
72 // used by upper layers
73 basegfx::B2DPoint& DrawBase() { return maDrawBase; }
74 const basegfx::B2DPoint& DrawBase() const { return maDrawBase; }
75 basegfx::B2DPoint& DrawOffset() { return maDrawOffset; }
76 const basegfx::B2DPoint& DrawOffset() const { return maDrawOffset; }
77 basegfx::B2DPoint GetDrawPosition( const basegfx::B2DPoint& rRelative = basegfx::B2DPoint(0,0) ) const;
79 virtual bool LayoutText( vcl::text::ImplLayoutArgs&, const SalLayoutGlyphsImpl* ) = 0; // first step of layouting
80 virtual void AdjustLayout( vcl::text::ImplLayoutArgs& ); // adjusting after fallback etc.
81 virtual void DrawText( SalGraphics& ) const = 0;
83 Degree10 GetOrientation() const { return mnOrientation; }
85 void SetSubpixelPositioning(bool bSubpixelPositioning)
87 mbSubpixelPositioning = bSubpixelPositioning;
90 bool GetSubpixelPositioning() const
92 return mbSubpixelPositioning;
95 // methods using string indexing
96 virtual sal_Int32 GetTextBreak(double nMaxWidth, double nCharExtra, int nFactor) const = 0;
97 virtual double FillDXArray( std::vector<double>* pDXArray, const OUString& rStr ) const = 0;
98 virtual double GetTextWidth() const { return FillDXArray( nullptr, {} ); }
100 virtual double FillPartialDXArray(std::vector<double>* pDXArray, const OUString& rStr,
101 sal_Int32 skipStart, sal_Int32 amt) const
102 = 0;
104 virtual double GetPartialTextWidth(sal_Int32 skipStart, sal_Int32 amt) const
106 return FillPartialDXArray(nullptr, {}, skipStart, amt);
109 virtual void GetCaretPositions( std::vector<double>& rCaretPositions, const OUString& rStr ) const = 0;
111 virtual bool HasFontKashidaPositions() const = 0;
112 virtual bool IsKashidaPosValid ( int /*nCharPos*/, int /*nNextCharPos*/ ) const = 0; // i60594
114 // methods using glyph indexing
115 virtual bool GetNextGlyph(const GlyphItem** pGlyph, basegfx::B2DPoint& rPos, int& nStart,
116 const LogicalFontInstance** ppGlyphFont = nullptr) const = 0;
117 virtual bool GetOutline(basegfx::B2DPolyPolygonVector&) const;
118 bool GetBoundRect(basegfx::B2DRectangle&) const;
120 static tools::Rectangle BoundRect2Rectangle(basegfx::B2DRectangle&);
122 virtual SalLayoutGlyphs GetGlyphs() const;
124 virtual void drawSalLayout(void* /*pSurface*/, const basegfx::BColor& /*rTextColor*/, bool /*bAntiAliased*/) const {}
126 protected:
127 // used by layout engines
128 SalLayout();
130 private:
131 SalLayout(const SalLayout&) = delete;
132 SalLayout& operator=(const SalLayout&) = delete;
134 protected:
135 int mnMinCharPos;
136 int mnEndCharPos;
137 LanguageTag maLanguageTag;
139 Degree10 mnOrientation;
141 basegfx::B2DPoint maDrawOffset;
142 basegfx::B2DPoint maDrawBase;
144 bool mbSubpixelPositioning;
147 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */