1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 #ifndef INCLUDED_DRAWINGLAYER_PRIMITIVE2D_TEXTPRIMITIVE2D_HXX 25 #define INCLUDED_DRAWINGLAYER_PRIMITIVE2D_TEXTPRIMITIVE2D_HXX 26 27 #include <drawinglayer/drawinglayerdllapi.h> 28 #include <drawinglayer/primitive2d/baseprimitive2d.hxx> 29 #include <basegfx/matrix/b2dhommatrix.hxx> 30 #include <tools/string.hxx> 31 #include <vcl/font.hxx> 32 #include <basegfx/color/bcolor.hxx> 33 #include <vector> 34 #include <com/sun/star/lang/Locale.hpp> 35 #include <drawinglayer/attribute/fontattribute.hxx> 36 #include <basegfx/polygon/b2dpolypolygon.hxx> 37 38 ////////////////////////////////////////////////////////////////////////////// 39 // predefines 40 41 class OutputDevice; 42 43 ////////////////////////////////////////////////////////////////////////////// 44 45 namespace drawinglayer 46 { 47 namespace primitive2d 48 { 49 /** TextSimplePortionPrimitive2D class 50 51 This is the basic primitive for representing a text portion. It contains 52 all needed information. If it is not handled by a renderer, it's decomposition 53 will provide the text PolyPolygon outlines as filled polygons, correctly 54 transformed. 55 56 To get better text quality, it is suggested to handle tis primitive directly 57 in a renderer. In that case, e.g. hintings on the system can be supported. 58 59 @param maTextTransform 60 The text transformation contains the text start position (always baselined) 61 as translation, the FontSize as scale (where width relative to height defines 62 font scaling and width == height means no font scaling) and the font rotation 63 and shear. 64 When shear is used and a renderer does not support it, it may be better to use 65 the decomposition which will do everything correctly. Same is true for mirroring 66 which would be expressed as negative scalings. 67 68 @param rText 69 The text to be used. Only a part may be used, but a bigger part of the string 70 may be necessary for correct layouting (e.g. international) 71 72 @param aTextPosition 73 The index to the first character to use from rText 74 75 @param aTextLength 76 The number of characters to use from rText 77 78 @param rDXArray 79 The distances between the characters. This parameter may be empty, in that case 80 the renderer is responsible to do something useful. If it is given, it has to be of 81 the size aTextLength. Its values are in logical coordinates and describe the 82 distance for each character to use. This is independent from the font width which 83 is given with maTextTransform. The first value is the offset to use from the start 84 point in FontCoordinateSystem X-Direction (given by maTextTransform) to the start 85 point of the second character 86 87 @param rFontAttribute 88 The font definition 89 90 @param rLocale 91 The locale to use 92 93 @param rFontColor 94 The font color to use 95 */ 96 class DRAWINGLAYER_DLLPUBLIC TextSimplePortionPrimitive2D : public BufferedDecompositionPrimitive2D 97 { 98 private: 99 /// text transformation (FontCoordinateSystem) 100 basegfx::B2DHomMatrix maTextTransform; 101 102 /// The text, used from maTextPosition up to maTextPosition + maTextLength 103 String maText; 104 105 /// The index from where on maText is used 106 xub_StrLen maTextPosition; 107 108 /// The length for maText usage, starting from maTextPosition 109 xub_StrLen maTextLength; 110 111 /// The DX array in logic units 112 ::std::vector< double > maDXArray; 113 114 /// The font definition 115 attribute::FontAttribute maFontAttribute; 116 117 /// The Locale for the text 118 ::com::sun::star::lang::Locale maLocale; 119 120 /// font color 121 basegfx::BColor maFontColor; 122 123 /// #i96669# internal: add simple range buffering for this primitive 124 basegfx::B2DRange maB2DRange; 125 126 protected: 127 /// local decomposition. 128 virtual Primitive2DSequence create2DDecomposition(const geometry::ViewInformation2D& rViewInformation) const; 129 130 public: 131 /// constructor 132 TextSimplePortionPrimitive2D( 133 const basegfx::B2DHomMatrix& rNewTransform, 134 const String& rText, 135 xub_StrLen aTextPosition, 136 xub_StrLen aTextLength, 137 const ::std::vector< double >& rDXArray, 138 const attribute::FontAttribute& rFontAttribute, 139 const ::com::sun::star::lang::Locale& rLocale, 140 const basegfx::BColor& rFontColor); 141 142 /// helpers 143 /** get text outlines as polygons and their according ObjectTransformation. Handles all 144 the necessary VCL outline extractins, scaling adaptions and other stuff. 145 */ 146 void getTextOutlinesAndTransformation(basegfx::B2DPolyPolygonVector& rTarget, basegfx::B2DHomMatrix& rTransformation) const; 147 148 /// data read access getTextTransform() const149 const basegfx::B2DHomMatrix& getTextTransform() const { return maTextTransform; } getText() const150 const String& getText() const { return maText; } getTextPosition() const151 xub_StrLen getTextPosition() const { return maTextPosition; } getTextLength() const152 xub_StrLen getTextLength() const { return maTextLength; } getDXArray() const153 const ::std::vector< double >& getDXArray() const { return maDXArray; } getFontAttribute() const154 const attribute::FontAttribute& getFontAttribute() const { return maFontAttribute; } getLocale() const155 const ::com::sun::star::lang::Locale& getLocale() const { return maLocale; } getFontColor() const156 const basegfx::BColor& getFontColor() const { return maFontColor; } 157 158 /// compare operator 159 virtual bool operator==( const BasePrimitive2D& rPrimitive ) const; 160 161 /// get range 162 virtual basegfx::B2DRange getB2DRange(const geometry::ViewInformation2D& rViewInformation) const; 163 164 /// provide unique ID 165 DeclPrimitrive2DIDBlock() 166 }; 167 168 /// small helper to have a compare operator for Locale 169 bool LocalesAreEqual(const ::com::sun::star::lang::Locale& rA, const ::com::sun::star::lang::Locale& rB); 170 171 } // end of namespace primitive2d 172 } // end of namespace drawinglayer 173 174 ////////////////////////////////////////////////////////////////////////////// 175 176 #endif //INCLUDED_DRAWINGLAYER_PRIMITIVE2D_TEXTPRIMITIVE2D_HXX 177 178 ////////////////////////////////////////////////////////////////////////////// 179 // eof 180