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_TEXTLAYOUTDEVICE_HXX
25 #define INCLUDED_DRAWINGLAYER_TEXTLAYOUTDEVICE_HXX
26 
27 #include <drawinglayer/drawinglayerdllapi.h>
28 #include <tools/solar.h>
29 #include <tools/poly.hxx>
30 #include <basegfx/range/b2drange.hxx>
31 #include <vector>
32 #include <com/sun/star/lang/Locale.hpp>
33 #include <basegfx/polygon/b2dpolypolygon.hxx>
34 
35 //////////////////////////////////////////////////////////////////////////////
36 // predefines
37 class VirtualDevice;
38 class Font;
39 class String;
40 class OutputDevice;
41 class GDIMetaFile;
42 
43 namespace drawinglayer { namespace attribute {
44 	class FontAttribute;
45 }}
46 
47 //////////////////////////////////////////////////////////////////////////////
48 // access to one global impTimedRefDev incarnation in namespace drawinglayer::primitive
49 
50 namespace drawinglayer
51 {
52 	namespace primitive2d
53 	{
54         /** TextLayouterDevice class
55 
56             This helper class exists to isolate all accesses to VCL
57             text formatting/handling functionality for primitive implementations.
58             When in the future FontHandling may move to an own library independent
59             from VCL, primitives will be prepared.
60          */
61 		class DRAWINGLAYER_DLLPUBLIC TextLayouterDevice
62 		{
63 			/// internally used VirtualDevice
64 			VirtualDevice&					mrDevice;
65 
66 		public:
67             /// constructor/destructor
68 			TextLayouterDevice();
69 			~TextLayouterDevice();
70 
71             /// tooling methods
72 			void setFont(const Font& rFont);
73 			void setFontAttribute(
74                 const attribute::FontAttribute& rFontAttribute,
75                 double fFontScaleX,
76                 double fFontScaleY,
77                 const ::com::sun::star::lang::Locale & rLocale);
78 
79 			double getTextHeight() const;
80             double getOverlineHeight() const;
81             double getOverlineOffset() const;
82             double getUnderlineHeight() const;
83 			double getUnderlineOffset() const;
84 			double getStrikeoutOffset() const;
85 
86             double getTextWidth(
87 				const String& rText,
88 				sal_uInt32 nIndex,
89 				sal_uInt32 nLength) const;
90 
91 			bool getTextOutlines(
92 				basegfx::B2DPolyPolygonVector&,
93 			    const String& rText,
94 				sal_uInt32 nIndex,
95 				sal_uInt32 nLength,
96                 const ::std::vector< double >& rDXArray) const;
97 
98 			basegfx::B2DRange getTextBoundRect(
99 				const String& rText,
100 				sal_uInt32 nIndex,
101 				sal_uInt32 nLength) const;
102 
103             double getFontAscent() const;
104 	        double getFontDescent() const;
105 
106 			void addTextRectActions(
107 				const Rectangle& rRectangle,
108 				const String& rText,
109 				sal_uInt16 nStyle,
110 				GDIMetaFile& rGDIMetaFile) const;
111 
112 			::std::vector< double > getTextArray(
113 				const String& rText,
114 				sal_uInt32 nIndex,
115 				sal_uInt32 nLength) const;
116 		};
117 	} // end of namespace primitive2d
118 } // end of namespace drawinglayer
119 
120 //////////////////////////////////////////////////////////////////////////////
121 // helper methods for vcl font handling
122 
123 namespace drawinglayer
124 {
125 	namespace primitive2d
126 	{
127         /** Create a VCL-Font based on the definitions in FontAttribute
128             and the given FontScaling. The FontScaling defines the FontHeight
129             (fFontScaleY) and the FontWidth (fFontScaleX). The combination of
130             both defines FontStretching, where no stretching happens at
131             fFontScaleY == fFontScaleX
132          */
133 		Font DRAWINGLAYER_DLLPUBLIC getVclFontFromFontAttribute(
134             const attribute::FontAttribute& rFontAttribute,
135             double fFontScaleX,
136             double fFontScaleY,
137             double fFontRotation,
138             const ::com::sun::star::lang::Locale & rLocale);
139 
140         /** Generate FontAttribute DataSet derived from the given VCL-Font.
141             The FontScaling with fFontScaleY, fFontScaleX relationship (see
142             above) will be set in return parameter o_rSize to allow further
143             processing
144          */
145         attribute::FontAttribute DRAWINGLAYER_DLLPUBLIC getFontAttributeFromVclFont(
146             basegfx::B2DVector& o_rSize,
147             const Font& rFont,
148             bool bRTL,
149             bool bBiDiStrong);
150 
151 	} // end of namespace primitive2d
152 } // end of namespace drawinglayer
153 
154 //////////////////////////////////////////////////////////////////////////////
155 
156 #endif //_DRAWINGLAYER_TEXTLAYOUTDEVICE_HXX
157