xref: /AOO41X/main/drawinglayer/source/primitive2d/textlayoutdevice.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_drawinglayer.hxx"
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir #include <drawinglayer/primitive2d/textlayoutdevice.hxx>
32*cdf0e10cSrcweir #include <vcl/timer.hxx>
33*cdf0e10cSrcweir #include <vcl/virdev.hxx>
34*cdf0e10cSrcweir #include <vcl/font.hxx>
35*cdf0e10cSrcweir #include <vcl/metric.hxx>
36*cdf0e10cSrcweir #include <i18npool/mslangid.hxx>
37*cdf0e10cSrcweir #include <drawinglayer/primitive2d/textprimitive2d.hxx>
38*cdf0e10cSrcweir #include <vcl/svapp.hxx>
39*cdf0e10cSrcweir 
40*cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////
41*cdf0e10cSrcweir // VDev RevDevice provider
42*cdf0e10cSrcweir 
43*cdf0e10cSrcweir namespace
44*cdf0e10cSrcweir {
45*cdf0e10cSrcweir 	class ImpTimedRefDev : public Timer
46*cdf0e10cSrcweir 	{
47*cdf0e10cSrcweir 		ImpTimedRefDev**					mppStaticPointerOnMe;
48*cdf0e10cSrcweir 		VirtualDevice*						mpVirDev;
49*cdf0e10cSrcweir 		sal_uInt32							mnUseCount;
50*cdf0e10cSrcweir 
51*cdf0e10cSrcweir 	public:
52*cdf0e10cSrcweir 		ImpTimedRefDev(ImpTimedRefDev** ppStaticPointerOnMe);
53*cdf0e10cSrcweir 		~ImpTimedRefDev();
54*cdf0e10cSrcweir 	    virtual void Timeout();
55*cdf0e10cSrcweir 
56*cdf0e10cSrcweir 		VirtualDevice& acquireVirtualDevice();
57*cdf0e10cSrcweir 		void releaseVirtualDevice();
58*cdf0e10cSrcweir 	};
59*cdf0e10cSrcweir 
60*cdf0e10cSrcweir 	ImpTimedRefDev::ImpTimedRefDev(ImpTimedRefDev** ppStaticPointerOnMe)
61*cdf0e10cSrcweir 	:	mppStaticPointerOnMe(ppStaticPointerOnMe),
62*cdf0e10cSrcweir 		mpVirDev(0L),
63*cdf0e10cSrcweir 		mnUseCount(0L)
64*cdf0e10cSrcweir 	{
65*cdf0e10cSrcweir 		SetTimeout(3L * 60L * 1000L); // three minutes
66*cdf0e10cSrcweir 		Start();
67*cdf0e10cSrcweir 	}
68*cdf0e10cSrcweir 
69*cdf0e10cSrcweir 	ImpTimedRefDev::~ImpTimedRefDev()
70*cdf0e10cSrcweir 	{
71*cdf0e10cSrcweir 		OSL_ENSURE(0L == mnUseCount, "destruction of a still used ImpTimedRefDev (!)");
72*cdf0e10cSrcweir 
73*cdf0e10cSrcweir 		if(mppStaticPointerOnMe && *mppStaticPointerOnMe)
74*cdf0e10cSrcweir 		{
75*cdf0e10cSrcweir 			*mppStaticPointerOnMe = 0L;
76*cdf0e10cSrcweir 		}
77*cdf0e10cSrcweir 
78*cdf0e10cSrcweir 		if(mpVirDev)
79*cdf0e10cSrcweir 		{
80*cdf0e10cSrcweir 			delete mpVirDev;
81*cdf0e10cSrcweir 		}
82*cdf0e10cSrcweir 	}
83*cdf0e10cSrcweir 
84*cdf0e10cSrcweir 	void ImpTimedRefDev::Timeout()
85*cdf0e10cSrcweir 	{
86*cdf0e10cSrcweir 		// for obvious reasons, do not call anything after this
87*cdf0e10cSrcweir 		delete (this);
88*cdf0e10cSrcweir 	}
89*cdf0e10cSrcweir 
90*cdf0e10cSrcweir 	VirtualDevice& ImpTimedRefDev::acquireVirtualDevice()
91*cdf0e10cSrcweir 	{
92*cdf0e10cSrcweir 		if(!mpVirDev)
93*cdf0e10cSrcweir 		{
94*cdf0e10cSrcweir 			mpVirDev = new VirtualDevice();
95*cdf0e10cSrcweir 			mpVirDev->SetReferenceDevice( VirtualDevice::REFDEV_MODE_MSO1 );
96*cdf0e10cSrcweir 		}
97*cdf0e10cSrcweir 
98*cdf0e10cSrcweir 		if(!mnUseCount)
99*cdf0e10cSrcweir 		{
100*cdf0e10cSrcweir 			Stop();
101*cdf0e10cSrcweir 		}
102*cdf0e10cSrcweir 
103*cdf0e10cSrcweir 		mnUseCount++;
104*cdf0e10cSrcweir 
105*cdf0e10cSrcweir 		return *mpVirDev;
106*cdf0e10cSrcweir 	}
107*cdf0e10cSrcweir 
108*cdf0e10cSrcweir 	void ImpTimedRefDev::releaseVirtualDevice()
109*cdf0e10cSrcweir 	{
110*cdf0e10cSrcweir 		OSL_ENSURE(mnUseCount, "mismatch call number to releaseVirtualDevice() (!)");
111*cdf0e10cSrcweir 		mnUseCount--;
112*cdf0e10cSrcweir 
113*cdf0e10cSrcweir 		if(!mnUseCount)
114*cdf0e10cSrcweir 		{
115*cdf0e10cSrcweir 			Start();
116*cdf0e10cSrcweir 		}
117*cdf0e10cSrcweir 	}
118*cdf0e10cSrcweir } // end of anonymous namespace
119*cdf0e10cSrcweir 
120*cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////
121*cdf0e10cSrcweir // access to one global ImpTimedRefDev incarnation in namespace drawinglayer::primitive
122*cdf0e10cSrcweir 
123*cdf0e10cSrcweir namespace drawinglayer
124*cdf0e10cSrcweir {
125*cdf0e10cSrcweir 	namespace primitive2d
126*cdf0e10cSrcweir 	{
127*cdf0e10cSrcweir 		// static pointer here
128*cdf0e10cSrcweir 		static ImpTimedRefDev* pImpGlobalRefDev = 0L;
129*cdf0e10cSrcweir 
130*cdf0e10cSrcweir 		// static methods here
131*cdf0e10cSrcweir 		VirtualDevice& acquireGlobalVirtualDevice()
132*cdf0e10cSrcweir 		{
133*cdf0e10cSrcweir 			if(!pImpGlobalRefDev)
134*cdf0e10cSrcweir 			{
135*cdf0e10cSrcweir 				pImpGlobalRefDev = new ImpTimedRefDev(&pImpGlobalRefDev);
136*cdf0e10cSrcweir 			}
137*cdf0e10cSrcweir 
138*cdf0e10cSrcweir 			return pImpGlobalRefDev->acquireVirtualDevice();
139*cdf0e10cSrcweir 		}
140*cdf0e10cSrcweir 
141*cdf0e10cSrcweir 		void releaseGlobalVirtualDevice()
142*cdf0e10cSrcweir 		{
143*cdf0e10cSrcweir 			OSL_ENSURE(pImpGlobalRefDev, "releaseGlobalVirtualDevice() without prior acquireGlobalVirtualDevice() call(!)");
144*cdf0e10cSrcweir 			pImpGlobalRefDev->releaseVirtualDevice();
145*cdf0e10cSrcweir 		}
146*cdf0e10cSrcweir 
147*cdf0e10cSrcweir 		TextLayouterDevice::TextLayouterDevice()
148*cdf0e10cSrcweir 		:	mrDevice(acquireGlobalVirtualDevice())
149*cdf0e10cSrcweir 		{
150*cdf0e10cSrcweir 		}
151*cdf0e10cSrcweir 
152*cdf0e10cSrcweir 		TextLayouterDevice::~TextLayouterDevice()
153*cdf0e10cSrcweir 		{
154*cdf0e10cSrcweir 			releaseGlobalVirtualDevice();
155*cdf0e10cSrcweir 		}
156*cdf0e10cSrcweir 
157*cdf0e10cSrcweir 		void TextLayouterDevice::setFont(const Font& rFont)
158*cdf0e10cSrcweir 		{
159*cdf0e10cSrcweir 			mrDevice.SetFont( rFont );
160*cdf0e10cSrcweir 		}
161*cdf0e10cSrcweir 
162*cdf0e10cSrcweir 		void TextLayouterDevice::setFontAttribute(
163*cdf0e10cSrcweir             const attribute::FontAttribute& rFontAttribute,
164*cdf0e10cSrcweir             double fFontScaleX,
165*cdf0e10cSrcweir             double fFontScaleY,
166*cdf0e10cSrcweir             const ::com::sun::star::lang::Locale& rLocale)
167*cdf0e10cSrcweir 		{
168*cdf0e10cSrcweir 			setFont(getVclFontFromFontAttribute(
169*cdf0e10cSrcweir                 rFontAttribute,
170*cdf0e10cSrcweir                 fFontScaleX,
171*cdf0e10cSrcweir                 fFontScaleY,
172*cdf0e10cSrcweir                 0.0,
173*cdf0e10cSrcweir                 rLocale));
174*cdf0e10cSrcweir         }
175*cdf0e10cSrcweir 
176*cdf0e10cSrcweir         double TextLayouterDevice::getOverlineOffset() const
177*cdf0e10cSrcweir         {
178*cdf0e10cSrcweir             const ::FontMetric& rMetric = mrDevice.GetFontMetric();
179*cdf0e10cSrcweir             double fRet = (rMetric.GetIntLeading() / 2.0) - rMetric.GetAscent();
180*cdf0e10cSrcweir             return fRet;
181*cdf0e10cSrcweir         }
182*cdf0e10cSrcweir 
183*cdf0e10cSrcweir 		double TextLayouterDevice::getUnderlineOffset() const
184*cdf0e10cSrcweir 		{
185*cdf0e10cSrcweir 			const ::FontMetric& rMetric = mrDevice.GetFontMetric();
186*cdf0e10cSrcweir 			double fRet = rMetric.GetDescent() / 2.0;
187*cdf0e10cSrcweir 			return fRet;
188*cdf0e10cSrcweir 		}
189*cdf0e10cSrcweir 
190*cdf0e10cSrcweir 		double TextLayouterDevice::getStrikeoutOffset() const
191*cdf0e10cSrcweir 		{
192*cdf0e10cSrcweir 			const ::FontMetric& rMetric = mrDevice.GetFontMetric();
193*cdf0e10cSrcweir 			double fRet = (rMetric.GetAscent() - rMetric.GetIntLeading()) / 3.0;
194*cdf0e10cSrcweir 			return fRet;
195*cdf0e10cSrcweir 		}
196*cdf0e10cSrcweir 
197*cdf0e10cSrcweir         double TextLayouterDevice::getOverlineHeight() const
198*cdf0e10cSrcweir         {
199*cdf0e10cSrcweir             const ::FontMetric& rMetric = mrDevice.GetFontMetric();
200*cdf0e10cSrcweir             double fRet = rMetric.GetIntLeading() / 2.5;
201*cdf0e10cSrcweir             return fRet;
202*cdf0e10cSrcweir         }
203*cdf0e10cSrcweir 
204*cdf0e10cSrcweir 		double TextLayouterDevice::getUnderlineHeight() const
205*cdf0e10cSrcweir 		{
206*cdf0e10cSrcweir 			const ::FontMetric& rMetric = mrDevice.GetFontMetric();
207*cdf0e10cSrcweir 			double fRet = rMetric.GetDescent() / 4.0;
208*cdf0e10cSrcweir 			return fRet;
209*cdf0e10cSrcweir 		}
210*cdf0e10cSrcweir 
211*cdf0e10cSrcweir 		double TextLayouterDevice::getTextHeight() const
212*cdf0e10cSrcweir 		{
213*cdf0e10cSrcweir 			return mrDevice.GetTextHeight();
214*cdf0e10cSrcweir 		}
215*cdf0e10cSrcweir 
216*cdf0e10cSrcweir 		double TextLayouterDevice::getTextWidth(
217*cdf0e10cSrcweir 			const String& rText,
218*cdf0e10cSrcweir 			sal_uInt32 nIndex,
219*cdf0e10cSrcweir 			sal_uInt32 nLength) const
220*cdf0e10cSrcweir 		{
221*cdf0e10cSrcweir 			return mrDevice.GetTextWidth(rText, nIndex, nLength);
222*cdf0e10cSrcweir 		}
223*cdf0e10cSrcweir 
224*cdf0e10cSrcweir 		bool TextLayouterDevice::getTextOutlines(
225*cdf0e10cSrcweir 			basegfx::B2DPolyPolygonVector& rB2DPolyPolyVector,
226*cdf0e10cSrcweir 			const String& rText,
227*cdf0e10cSrcweir 			sal_uInt32 nIndex,
228*cdf0e10cSrcweir 			sal_uInt32 nLength,
229*cdf0e10cSrcweir             const ::std::vector< double >& rDXArray) const
230*cdf0e10cSrcweir 		{
231*cdf0e10cSrcweir             const sal_uInt32 nDXArrayCount(rDXArray.size());
232*cdf0e10cSrcweir 			sal_uInt32 nTextLength(nLength);
233*cdf0e10cSrcweir 			const sal_uInt32 nStringLength(rText.Len());
234*cdf0e10cSrcweir 
235*cdf0e10cSrcweir 			if(nTextLength + nIndex > nStringLength)
236*cdf0e10cSrcweir 			{
237*cdf0e10cSrcweir 				nTextLength = nStringLength - nIndex;
238*cdf0e10cSrcweir 			}
239*cdf0e10cSrcweir 
240*cdf0e10cSrcweir             if(nDXArrayCount)
241*cdf0e10cSrcweir             {
242*cdf0e10cSrcweir                 OSL_ENSURE(nDXArrayCount == nTextLength, "DXArray size does not correspond to text portion size (!)");
243*cdf0e10cSrcweir     		    std::vector< sal_Int32 > aIntegerDXArray(nDXArrayCount);
244*cdf0e10cSrcweir 
245*cdf0e10cSrcweir                 for(sal_uInt32 a(0); a < nDXArrayCount; a++)
246*cdf0e10cSrcweir                 {
247*cdf0e10cSrcweir                     aIntegerDXArray[a] = basegfx::fround(rDXArray[a]);
248*cdf0e10cSrcweir                 }
249*cdf0e10cSrcweir 
250*cdf0e10cSrcweir                 return mrDevice.GetTextOutlines(
251*cdf0e10cSrcweir                     rB2DPolyPolyVector,
252*cdf0e10cSrcweir                     rText,
253*cdf0e10cSrcweir                     nIndex,
254*cdf0e10cSrcweir                     nIndex,
255*cdf0e10cSrcweir                     nLength,
256*cdf0e10cSrcweir                     true,
257*cdf0e10cSrcweir 			        0,
258*cdf0e10cSrcweir                     &(aIntegerDXArray[0]));
259*cdf0e10cSrcweir             }
260*cdf0e10cSrcweir             else
261*cdf0e10cSrcweir             {
262*cdf0e10cSrcweir                 return mrDevice.GetTextOutlines(
263*cdf0e10cSrcweir                     rB2DPolyPolyVector,
264*cdf0e10cSrcweir                     rText,
265*cdf0e10cSrcweir                     nIndex,
266*cdf0e10cSrcweir                     nIndex,
267*cdf0e10cSrcweir                     nLength,
268*cdf0e10cSrcweir                     true,
269*cdf0e10cSrcweir 			        0,
270*cdf0e10cSrcweir                     0);
271*cdf0e10cSrcweir             }
272*cdf0e10cSrcweir 		}
273*cdf0e10cSrcweir 
274*cdf0e10cSrcweir 		basegfx::B2DRange TextLayouterDevice::getTextBoundRect(
275*cdf0e10cSrcweir 			const String& rText,
276*cdf0e10cSrcweir 			sal_uInt32 nIndex,
277*cdf0e10cSrcweir 			sal_uInt32 nLength) const
278*cdf0e10cSrcweir 		{
279*cdf0e10cSrcweir 			sal_uInt32 nTextLength(nLength);
280*cdf0e10cSrcweir 			const sal_uInt32 nStringLength(rText.Len());
281*cdf0e10cSrcweir 
282*cdf0e10cSrcweir 			if(nTextLength + nIndex > nStringLength)
283*cdf0e10cSrcweir 			{
284*cdf0e10cSrcweir 				nTextLength = nStringLength - nIndex;
285*cdf0e10cSrcweir 			}
286*cdf0e10cSrcweir 
287*cdf0e10cSrcweir 			if(nTextLength)
288*cdf0e10cSrcweir 			{
289*cdf0e10cSrcweir 				Rectangle aRect;
290*cdf0e10cSrcweir 
291*cdf0e10cSrcweir 				mrDevice.GetTextBoundRect(
292*cdf0e10cSrcweir                     aRect,
293*cdf0e10cSrcweir                     rText,
294*cdf0e10cSrcweir                     nIndex,
295*cdf0e10cSrcweir                     nIndex,
296*cdf0e10cSrcweir                     nLength);
297*cdf0e10cSrcweir 
298*cdf0e10cSrcweir                 // #i104432#, #i102556# take empty results into account
299*cdf0e10cSrcweir                 if(!aRect.IsEmpty())
300*cdf0e10cSrcweir                 {
301*cdf0e10cSrcweir     				return basegfx::B2DRange(
302*cdf0e10cSrcweir 						aRect.Left(), aRect.Top(),
303*cdf0e10cSrcweir 						aRect.Right(), aRect.Bottom());
304*cdf0e10cSrcweir                 }
305*cdf0e10cSrcweir 			}
306*cdf0e10cSrcweir 
307*cdf0e10cSrcweir             return basegfx::B2DRange();
308*cdf0e10cSrcweir 		}
309*cdf0e10cSrcweir 
310*cdf0e10cSrcweir         double TextLayouterDevice::getFontAscent() const
311*cdf0e10cSrcweir         {
312*cdf0e10cSrcweir             const ::FontMetric& rMetric = mrDevice.GetFontMetric();
313*cdf0e10cSrcweir             return rMetric.GetAscent();
314*cdf0e10cSrcweir         }
315*cdf0e10cSrcweir 
316*cdf0e10cSrcweir         double TextLayouterDevice::getFontDescent() const
317*cdf0e10cSrcweir         {
318*cdf0e10cSrcweir             const ::FontMetric& rMetric = mrDevice.GetFontMetric();
319*cdf0e10cSrcweir             return rMetric.GetDescent();
320*cdf0e10cSrcweir         }
321*cdf0e10cSrcweir 
322*cdf0e10cSrcweir 		void TextLayouterDevice::addTextRectActions(
323*cdf0e10cSrcweir 			const Rectangle& rRectangle,
324*cdf0e10cSrcweir 			const String& rText,
325*cdf0e10cSrcweir 			sal_uInt16 nStyle,
326*cdf0e10cSrcweir 			GDIMetaFile& rGDIMetaFile) const
327*cdf0e10cSrcweir 		{
328*cdf0e10cSrcweir 			mrDevice.AddTextRectActions(
329*cdf0e10cSrcweir 				rRectangle, rText, nStyle, rGDIMetaFile);
330*cdf0e10cSrcweir 		}
331*cdf0e10cSrcweir 
332*cdf0e10cSrcweir 		::std::vector< double > TextLayouterDevice::getTextArray(
333*cdf0e10cSrcweir 			const String& rText,
334*cdf0e10cSrcweir 			sal_uInt32 nIndex,
335*cdf0e10cSrcweir 			sal_uInt32 nLength) const
336*cdf0e10cSrcweir 		{
337*cdf0e10cSrcweir 			::std::vector< double > aRetval;
338*cdf0e10cSrcweir 			sal_uInt32 nTextLength(nLength);
339*cdf0e10cSrcweir 			const sal_uInt32 nStringLength(rText.Len());
340*cdf0e10cSrcweir 
341*cdf0e10cSrcweir 			if(nTextLength + nIndex > nStringLength)
342*cdf0e10cSrcweir 			{
343*cdf0e10cSrcweir 				nTextLength = nStringLength - nIndex;
344*cdf0e10cSrcweir 			}
345*cdf0e10cSrcweir 
346*cdf0e10cSrcweir 			if(nTextLength)
347*cdf0e10cSrcweir 			{
348*cdf0e10cSrcweir 				aRetval.reserve(nTextLength);
349*cdf0e10cSrcweir 				sal_Int32* pArray = new sal_Int32[nTextLength];
350*cdf0e10cSrcweir 				mrDevice.GetTextArray(rText, pArray, nIndex, nLength);
351*cdf0e10cSrcweir 
352*cdf0e10cSrcweir 				for(sal_uInt32 a(0); a < nTextLength; a++)
353*cdf0e10cSrcweir 				{
354*cdf0e10cSrcweir 					aRetval.push_back(pArray[a]);
355*cdf0e10cSrcweir 				}
356*cdf0e10cSrcweir 			}
357*cdf0e10cSrcweir 
358*cdf0e10cSrcweir 			return aRetval;
359*cdf0e10cSrcweir 		}
360*cdf0e10cSrcweir 
361*cdf0e10cSrcweir 	} // end of namespace primitive2d
362*cdf0e10cSrcweir } // end of namespace drawinglayer
363*cdf0e10cSrcweir 
364*cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////
365*cdf0e10cSrcweir // helper methods for vcl font handling
366*cdf0e10cSrcweir 
367*cdf0e10cSrcweir namespace drawinglayer
368*cdf0e10cSrcweir {
369*cdf0e10cSrcweir 	namespace primitive2d
370*cdf0e10cSrcweir 	{
371*cdf0e10cSrcweir 		Font getVclFontFromFontAttribute(
372*cdf0e10cSrcweir             const attribute::FontAttribute& rFontAttribute,
373*cdf0e10cSrcweir             double fFontScaleX,
374*cdf0e10cSrcweir             double fFontScaleY,
375*cdf0e10cSrcweir             double fFontRotation,
376*cdf0e10cSrcweir             const ::com::sun::star::lang::Locale& rLocale)
377*cdf0e10cSrcweir 		{
378*cdf0e10cSrcweir             // detect FontScaling
379*cdf0e10cSrcweir 			const sal_uInt32 nHeight(basegfx::fround(fabs(fFontScaleY)));
380*cdf0e10cSrcweir             const sal_uInt32 nWidth(basegfx::fround(fabs(fFontScaleX)));
381*cdf0e10cSrcweir             const bool bFontIsScaled(nHeight != nWidth);
382*cdf0e10cSrcweir 
383*cdf0e10cSrcweir #ifdef WIN32
384*cdf0e10cSrcweir             // for WIN32 systems, start with creating an unscaled font. If FontScaling
385*cdf0e10cSrcweir             // is wanted, that width needs to be adapted using FontMetric again to get a
386*cdf0e10cSrcweir             // width of the unscaled font
387*cdf0e10cSrcweir 			Font aRetval(
388*cdf0e10cSrcweir 				rFontAttribute.getFamilyName(),
389*cdf0e10cSrcweir 				rFontAttribute.getStyleName(),
390*cdf0e10cSrcweir 				Size(0, nHeight));
391*cdf0e10cSrcweir #else
392*cdf0e10cSrcweir             // for non-WIN32 systems things are easier since these accept a Font creation
393*cdf0e10cSrcweir             // with initially nWidth != nHeight for FontScaling. Despite that, use zero for
394*cdf0e10cSrcweir             // FontWidth when no scaling is used to explicitely have that zero when e.g. the
395*cdf0e10cSrcweir             // Font would be recorded in a MetaFile (The MetaFile FontAction WILL record a
396*cdf0e10cSrcweir             // set FontWidth; import that in a WIN32 system, and trouble is there)
397*cdf0e10cSrcweir 			Font aRetval(
398*cdf0e10cSrcweir 				rFontAttribute.getFamilyName(),
399*cdf0e10cSrcweir 				rFontAttribute.getStyleName(),
400*cdf0e10cSrcweir                 Size(bFontIsScaled ? nWidth : 0, nHeight));
401*cdf0e10cSrcweir #endif
402*cdf0e10cSrcweir             // define various other FontAttribute
403*cdf0e10cSrcweir 			aRetval.SetAlign(ALIGN_BASELINE);
404*cdf0e10cSrcweir 			aRetval.SetCharSet(rFontAttribute.getSymbol() ? RTL_TEXTENCODING_SYMBOL : RTL_TEXTENCODING_UNICODE);
405*cdf0e10cSrcweir 			aRetval.SetVertical(rFontAttribute.getVertical() ? sal_True : sal_False);
406*cdf0e10cSrcweir 			aRetval.SetWeight(static_cast<FontWeight>(rFontAttribute.getWeight()));
407*cdf0e10cSrcweir 			aRetval.SetItalic(rFontAttribute.getItalic() ? ITALIC_NORMAL : ITALIC_NONE);
408*cdf0e10cSrcweir 			aRetval.SetOutline(rFontAttribute.getOutline());
409*cdf0e10cSrcweir             aRetval.SetPitch(rFontAttribute.getMonospaced() ? PITCH_FIXED : PITCH_VARIABLE);
410*cdf0e10cSrcweir             aRetval.SetLanguage(MsLangId::convertLocaleToLanguage(rLocale));
411*cdf0e10cSrcweir 
412*cdf0e10cSrcweir #ifdef WIN32
413*cdf0e10cSrcweir             // for WIN32 systems, correct the FontWidth if FontScaling is used
414*cdf0e10cSrcweir             if(bFontIsScaled && nHeight > 0)
415*cdf0e10cSrcweir             {
416*cdf0e10cSrcweir                 const FontMetric aUnscaledFontMetric(Application::GetDefaultDevice()->GetFontMetric(aRetval));
417*cdf0e10cSrcweir 
418*cdf0e10cSrcweir                 if(aUnscaledFontMetric.GetWidth() > 0)
419*cdf0e10cSrcweir                 {
420*cdf0e10cSrcweir                     const double fScaleFactor((double)nWidth / (double)nHeight);
421*cdf0e10cSrcweir                     const sal_uInt32 nScaledWidth(basegfx::fround((double)aUnscaledFontMetric.GetWidth() * fScaleFactor));
422*cdf0e10cSrcweir                     aRetval.SetWidth(nScaledWidth);
423*cdf0e10cSrcweir                 }
424*cdf0e10cSrcweir             }
425*cdf0e10cSrcweir #endif
426*cdf0e10cSrcweir             // handle FontRotation (if defined)
427*cdf0e10cSrcweir 			if(!basegfx::fTools::equalZero(fFontRotation))
428*cdf0e10cSrcweir 			{
429*cdf0e10cSrcweir 				sal_Int16 aRotate10th((sal_Int16)(fFontRotation * (-1800.0/F_PI)));
430*cdf0e10cSrcweir 				aRetval.SetOrientation(aRotate10th % 3600);
431*cdf0e10cSrcweir 			}
432*cdf0e10cSrcweir 
433*cdf0e10cSrcweir 			return aRetval;
434*cdf0e10cSrcweir 		}
435*cdf0e10cSrcweir 
436*cdf0e10cSrcweir         attribute::FontAttribute getFontAttributeFromVclFont(
437*cdf0e10cSrcweir             basegfx::B2DVector& o_rSize,
438*cdf0e10cSrcweir             const Font& rFont,
439*cdf0e10cSrcweir             bool bRTL,
440*cdf0e10cSrcweir             bool bBiDiStrong)
441*cdf0e10cSrcweir 		{
442*cdf0e10cSrcweir             const attribute::FontAttribute aRetval(
443*cdf0e10cSrcweir 			    rFont.GetName(),
444*cdf0e10cSrcweir 			    rFont.GetStyleName(),
445*cdf0e10cSrcweir 			    static_cast<sal_uInt16>(rFont.GetWeight()),
446*cdf0e10cSrcweir                 RTL_TEXTENCODING_SYMBOL == rFont.GetCharSet(),
447*cdf0e10cSrcweir 			    rFont.IsVertical(),
448*cdf0e10cSrcweir 			    ITALIC_NONE != rFont.GetItalic(),
449*cdf0e10cSrcweir                 PITCH_FIXED == rFont.GetPitch(),
450*cdf0e10cSrcweir 			    rFont.IsOutline(),
451*cdf0e10cSrcweir                 bRTL,
452*cdf0e10cSrcweir                 bBiDiStrong);
453*cdf0e10cSrcweir 			// TODO: eKerning
454*cdf0e10cSrcweir 
455*cdf0e10cSrcweir             // set FontHeight and init to no FontScaling
456*cdf0e10cSrcweir             o_rSize.setY(rFont.GetSize().getHeight() > 0 ? rFont.GetSize().getHeight() : 0);
457*cdf0e10cSrcweir             o_rSize.setX(o_rSize.getY());
458*cdf0e10cSrcweir 
459*cdf0e10cSrcweir #ifdef WIN32
460*cdf0e10cSrcweir             // for WIN32 systems, the FontScaling at the Font is detected by
461*cdf0e10cSrcweir             // checking that FontWidth != 0. When FontScaling is used, WIN32
462*cdf0e10cSrcweir             // needs to do extra stuff to detect the correct width (since it's
463*cdf0e10cSrcweir             // zero and not equal the font height) and it's relationship to
464*cdf0e10cSrcweir             // the height
465*cdf0e10cSrcweir             if(rFont.GetSize().getWidth() > 0)
466*cdf0e10cSrcweir             {
467*cdf0e10cSrcweir                 Font aUnscaledFont(rFont);
468*cdf0e10cSrcweir                 aUnscaledFont.SetWidth(0);
469*cdf0e10cSrcweir                 const FontMetric aUnscaledFontMetric(Application::GetDefaultDevice()->GetFontMetric(aUnscaledFont));
470*cdf0e10cSrcweir 
471*cdf0e10cSrcweir                 if(aUnscaledFontMetric.GetWidth() > 0)
472*cdf0e10cSrcweir                 {
473*cdf0e10cSrcweir                     const double fScaleFactor((double)rFont.GetSize().getWidth() / (double)aUnscaledFontMetric.GetWidth());
474*cdf0e10cSrcweir                     o_rSize.setX(fScaleFactor * o_rSize.getY());
475*cdf0e10cSrcweir                 }
476*cdf0e10cSrcweir             }
477*cdf0e10cSrcweir #else
478*cdf0e10cSrcweir             // For non-WIN32 systems the detection is the same, but the value
479*cdf0e10cSrcweir             // is easier achieved since width == height is interpreted as no
480*cdf0e10cSrcweir             // scaling. Ergo, Width == 0 means width == height, and width != 0
481*cdf0e10cSrcweir             // means the scaling is in the direct relation of width to height
482*cdf0e10cSrcweir             if(rFont.GetSize().getWidth() > 0)
483*cdf0e10cSrcweir             {
484*cdf0e10cSrcweir                 o_rSize.setX((double)rFont.GetSize().getWidth());
485*cdf0e10cSrcweir             }
486*cdf0e10cSrcweir #endif
487*cdf0e10cSrcweir 			return aRetval;
488*cdf0e10cSrcweir 		}
489*cdf0e10cSrcweir 	} // end of namespace primitive2d
490*cdf0e10cSrcweir } // end of namespace drawinglayer
491*cdf0e10cSrcweir 
492*cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////
493*cdf0e10cSrcweir // eof
494