nss: upgrade to release 3.73
[LibreOffice.git] / include / drawinglayer / primitive2d / textprimitive2d.hxx
blob516d715c93d653e05c673fa4808a4f1f25dfb727
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 <drawinglayer/drawinglayerdllapi.h>
24 #include <drawinglayer/primitive2d/baseprimitive2d.hxx>
25 #include <drawinglayer/attribute/fontattribute.hxx>
26 #include <basegfx/polygon/b2dpolypolygon.hxx>
27 #include <basegfx/matrix/b2dhommatrix.hxx>
28 #include <rtl/ustring.hxx>
29 #include <tools/color.hxx>
30 #include <tools/long.hxx>
31 #include <basegfx/color/bcolor.hxx>
32 #include <com/sun/star/lang/Locale.hpp>
33 #include <vector>
35 namespace drawinglayer::primitive2d
37 /** TextSimplePortionPrimitive2D class
39 This is the basic primitive for representing a text portion. It contains
40 all needed information. If it is not handled by a renderer, its decomposition
41 will provide the text tools::PolyPolygon outlines as filled polygons, correctly
42 transformed.
44 To get better text quality, it is suggested to handle this primitive directly
45 in a renderer. In that case, e.g. hintings on the system can be supported.
47 @param maTextTransform
48 The text transformation contains the text start position (always baselined)
49 as translation, the FontSize as scale (where width relative to height defines
50 font scaling and width == height means no font scaling) and the font rotation
51 and shear.
52 When shear is used and a renderer does not support it, it may be better to use
53 the decomposition which will do everything correctly. Same is true for mirroring
54 which would be expressed as negative scalings.
56 @param rText
57 The text to be used. Only a part may be used, but a bigger part of the string
58 may be necessary for correct layouting (e.g. international)
60 @param aTextPosition
61 The index to the first character to use from rText
63 @param aTextLength
64 The number of characters to use from rText
66 @param rDXArray
67 The distances between the characters. This parameter may be empty, in that case
68 the renderer is responsible to do something useful. If it is given, it has to be of
69 the size aTextLength. Its values are in logical coordinates and describe the
70 distance for each character to use. This is independent from the font width which
71 is given with maTextTransform. The first value is the offset to use from the start
72 point in FontCoordinateSystem X-Direction (given by maTextTransform) to the start
73 point of the second character
75 @param rFontAttribute
76 The font definition
78 @param rLocale
79 The locale to use
81 @param rFontColor
82 The font color to use
84 @param bFilled
86 @param nWidthToFill
88 @param rTextFillColor
89 Text background color (has nothing to do with bFilled and nWidthToFill)
92 class DRAWINGLAYER_DLLPUBLIC TextSimplePortionPrimitive2D : public BufferedDecompositionPrimitive2D
94 private:
95 /// text transformation (FontCoordinateSystem)
96 basegfx::B2DHomMatrix maTextTransform;
98 /// The text, used from maTextPosition up to maTextPosition + maTextLength
99 OUString maText;
101 /// The index from where on maText is used
102 sal_Int32 mnTextPosition;
104 /// The length for maText usage, starting from maTextPosition
105 sal_Int32 mnTextLength;
107 /// The DX array in logic units
108 std::vector<double> maDXArray;
110 /// The font definition
111 attribute::FontAttribute maFontAttribute;
113 /// The Locale for the text
114 css::lang::Locale maLocale;
116 /// font color
117 basegfx::BColor maFontColor;
119 // Whether to fill a given width with the text
120 bool mbFilled;
122 // the width to fill
123 tools::Long mnWidthToFill;
125 /// The fill color of the text
126 Color maTextFillColor;
128 /// #i96669# internal: add simple range buffering for this primitive
129 basegfx::B2DRange maB2DRange;
131 protected:
132 /// local decomposition.
133 virtual void
134 create2DDecomposition(Primitive2DContainer& rContainer,
135 const geometry::ViewInformation2D& rViewInformation) const override;
137 public:
138 /// constructor
139 TextSimplePortionPrimitive2D(const basegfx::B2DHomMatrix& rNewTransform, const OUString& rText,
140 sal_Int32 nTextPosition, sal_Int32 nTextLength,
141 const ::std::vector<double>& rDXArray,
142 const attribute::FontAttribute& rFontAttribute,
143 const css::lang::Locale& rLocale,
144 const basegfx::BColor& rFontColor, bool bFilled = false,
145 tools::Long nWidthToFill = 0,
146 const Color& rTextFillColor = COL_TRANSPARENT);
148 /** get text outlines as polygons and their according ObjectTransformation. Handles all
149 the necessary VCL outline extractions, scaling adaptations and other stuff.
151 void getTextOutlinesAndTransformation(basegfx::B2DPolyPolygonVector& rTarget,
152 basegfx::B2DHomMatrix& rTransformation) const;
154 /// data read access
155 const basegfx::B2DHomMatrix& getTextTransform() const { return maTextTransform; }
156 const OUString& getText() const { return maText; }
157 sal_Int32 getTextPosition() const { return mnTextPosition; }
158 sal_Int32 getTextLength() const { return mnTextLength; }
159 const ::std::vector<double>& getDXArray() const { return maDXArray; }
160 const attribute::FontAttribute& getFontAttribute() const { return maFontAttribute; }
161 const css::lang::Locale& getLocale() const { return maLocale; }
162 const basegfx::BColor& getFontColor() const { return maFontColor; }
163 const Color& getTextFillColor() const { return maTextFillColor; }
164 bool isFilled() const { return mbFilled; }
165 tools::Long getWidthToFill() const { return mnWidthToFill; }
167 /// compare operator
168 virtual bool operator==(const BasePrimitive2D& rPrimitive) const override;
170 /// get range
171 virtual basegfx::B2DRange
172 getB2DRange(const geometry::ViewInformation2D& rViewInformation) const override;
174 /// provide unique ID
175 virtual sal_uInt32 getPrimitive2DID() const override;
178 /// small helper to have a compare operator for Locale
179 bool DRAWINGLAYER_DLLPUBLIC LocalesAreEqual(const css::lang::Locale& rA,
180 const css::lang::Locale& rB);
182 } // end of namespace drawinglayer::primitive2d
184 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */