Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #include <toolkit/awt/vclxfont.hxx>
30 : : #include <toolkit/helper/vclunohelper.hxx>
31 : : #include <toolkit/helper/macros.hxx>
32 : : #include <cppuhelper/typeprovider.hxx>
33 : : #include <rtl/memory.h>
34 : : #include <rtl/uuid.h>
35 : : #include <rtl/ustring.h>
36 : :
37 : : #include <vcl/outdev.hxx>
38 : :
39 : : // ----------------------------------------------------
40 : : // class VCLXFont
41 : : // ----------------------------------------------------
42 [ + - ][ + - ]: 257 : VCLXFont::VCLXFont()
43 : : {
44 : 257 : mpFontMetric = NULL;
45 : 257 : }
46 : :
47 [ + - ][ + - ]: 257 : VCLXFont::~VCLXFont()
[ + - ]
48 : : {
49 [ - + ][ # # ]: 257 : delete mpFontMetric;
50 [ - + ]: 514 : }
51 : :
52 : 257 : void VCLXFont::Init( ::com::sun::star::awt::XDevice& rxDev, const Font& rFont )
53 : : {
54 : 257 : mxDevice = &rxDev;
55 : :
56 [ - + ]: 257 : delete mpFontMetric;
57 : 257 : mpFontMetric = NULL;
58 : :
59 : 257 : maFont = rFont;
60 : 257 : }
61 : :
62 : 0 : sal_Bool VCLXFont::ImplAssertValidFontMetric()
63 : : {
64 [ # # ][ # # ]: 0 : if ( !mpFontMetric && mxDevice.is() )
[ # # ]
65 : : {
66 : 0 : OutputDevice* pOutDev = VCLUnoHelper::GetOutputDevice( mxDevice );
67 [ # # ]: 0 : if ( pOutDev )
68 : : {
69 [ # # ]: 0 : Font aOldFont = pOutDev->GetFont();
70 [ # # ]: 0 : pOutDev->SetFont( maFont );
71 [ # # ][ # # ]: 0 : mpFontMetric = new FontMetric( pOutDev->GetFontMetric() );
72 [ # # ][ # # ]: 0 : pOutDev->SetFont( aOldFont );
73 : : }
74 : : }
75 [ # # ]: 0 : return mpFontMetric ? sal_True : sal_False;
76 : : }
77 : :
78 : :
79 : : // ::com::sun::star::uno::XInterface
80 : 233 : ::com::sun::star::uno::Any VCLXFont::queryInterface( const ::com::sun::star::uno::Type & rType ) throw(::com::sun::star::uno::RuntimeException)
81 : : {
82 : : ::com::sun::star::uno::Any aRet = ::cppu::queryInterface( rType,
83 : : (static_cast< ::com::sun::star::awt::XFont* >(this)),
84 : : (static_cast< ::com::sun::star::awt::XFont2* >(this)),
85 : : (static_cast< ::com::sun::star::lang::XUnoTunnel* >(this)),
86 [ + - ]: 233 : (static_cast< ::com::sun::star::lang::XTypeProvider* >(this)) );
87 [ + + ][ + - ]: 233 : return (aRet.hasValue() ? aRet : OWeakObject::queryInterface( rType ));
88 : : }
89 : :
90 : : // ::com::sun::star::lang::XUnoTunnel
91 [ # # ][ # # ]: 0 : IMPL_XUNOTUNNEL( VCLXFont )
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
92 : :
93 : : // ::com::sun::star::lang::XTypeProvider
94 [ # # ][ # # ]: 0 : IMPL_XTYPEPROVIDER_START( VCLXFont )
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
95 [ # # ]: 0 : getCppuType( ( ::com::sun::star::uno::Reference< ::com::sun::star::awt::XFont2>* ) NULL )
96 [ # # ][ # # ]: 0 : IMPL_XTYPEPROVIDER_END
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
97 : :
98 : :
99 : 0 : ::com::sun::star::awt::FontDescriptor VCLXFont::getFontDescriptor( ) throw(::com::sun::star::uno::RuntimeException)
100 : : {
101 [ # # ]: 0 : ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
102 : :
103 [ # # ][ # # ]: 0 : return VCLUnoHelper::CreateFontDescriptor( maFont );
104 : :
105 : : }
106 : :
107 : 0 : ::com::sun::star::awt::SimpleFontMetric VCLXFont::getFontMetric( ) throw(::com::sun::star::uno::RuntimeException)
108 : : {
109 [ # # ]: 0 : ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
110 : :
111 : 0 : ::com::sun::star::awt::SimpleFontMetric aFM;
112 [ # # ][ # # ]: 0 : if ( ImplAssertValidFontMetric() )
113 [ # # ]: 0 : aFM = VCLUnoHelper::CreateFontMetric( *mpFontMetric );
114 [ # # ]: 0 : return aFM;
115 : : }
116 : :
117 : 264 : sal_Int16 VCLXFont::getCharWidth( sal_Unicode c ) throw(::com::sun::star::uno::RuntimeException)
118 : : {
119 [ + - ]: 264 : ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
120 : :
121 : 264 : sal_Int16 nRet = -1;
122 [ + - ]: 264 : OutputDevice* pOutDev = VCLUnoHelper::GetOutputDevice( mxDevice );
123 [ + - ]: 264 : if ( pOutDev )
124 : : {
125 [ + - ]: 264 : Font aOldFont = pOutDev->GetFont();
126 [ + - ]: 264 : pOutDev->SetFont( maFont );
127 : :
128 : : nRet = sal::static_int_cast< sal_Int16 >(
129 [ + - ][ + - ]: 264 : pOutDev->GetTextWidth( rtl::OUString(c) ));
[ + - ]
130 : :
131 [ + - ][ + - ]: 264 : pOutDev->SetFont( aOldFont );
132 : : }
133 [ + - ]: 264 : return nRet;
134 : : }
135 : :
136 : 0 : ::com::sun::star::uno::Sequence< sal_Int16 > VCLXFont::getCharWidths( sal_Unicode nFirst, sal_Unicode nLast ) throw(::com::sun::star::uno::RuntimeException)
137 : : {
138 [ # # ]: 0 : ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
139 : :
140 [ # # ]: 0 : ::com::sun::star::uno::Sequence<sal_Int16> aSeq;
141 [ # # ]: 0 : OutputDevice* pOutDev = VCLUnoHelper::GetOutputDevice( mxDevice );
142 [ # # ]: 0 : if ( pOutDev )
143 : : {
144 [ # # ]: 0 : Font aOldFont = pOutDev->GetFont();
145 [ # # ]: 0 : pOutDev->SetFont( maFont );
146 : :
147 : 0 : sal_Int16 nCount = nLast-nFirst + 1;
148 [ # # ][ # # ]: 0 : aSeq = ::com::sun::star::uno::Sequence<sal_Int16>( nCount );
[ # # ]
149 [ # # ]: 0 : for ( sal_uInt16 n = 0; n < nCount; n++ )
150 : : {
151 [ # # ]: 0 : aSeq.getArray()[n] = sal::static_int_cast< sal_Int16 >(
152 : : pOutDev->GetTextWidth(
153 [ # # ][ # # ]: 0 : rtl::OUString(static_cast< sal_Unicode >(nFirst+n)) ));
[ # # ]
154 : : }
155 : :
156 [ # # ][ # # ]: 0 : pOutDev->SetFont( aOldFont );
157 : : }
158 [ # # ]: 0 : return aSeq;
159 : : }
160 : :
161 : 0 : sal_Int32 VCLXFont::getStringWidth( const ::rtl::OUString& str ) throw(::com::sun::star::uno::RuntimeException)
162 : : {
163 [ # # ]: 0 : ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
164 : :
165 : 0 : sal_Int32 nRet = -1;
166 [ # # ]: 0 : OutputDevice* pOutDev = VCLUnoHelper::GetOutputDevice( mxDevice );
167 [ # # ]: 0 : if ( pOutDev )
168 : : {
169 [ # # ]: 0 : Font aOldFont = pOutDev->GetFont();
170 [ # # ]: 0 : pOutDev->SetFont( maFont );
171 [ # # ][ # # ]: 0 : nRet = pOutDev->GetTextWidth( str );
[ # # ]
172 [ # # ][ # # ]: 0 : pOutDev->SetFont( aOldFont );
173 : : }
174 [ # # ]: 0 : return nRet;
175 : : }
176 : :
177 : 0 : sal_Int32 VCLXFont::getStringWidthArray( const ::rtl::OUString& str, ::com::sun::star::uno::Sequence< sal_Int32 >& rDXArray ) throw(::com::sun::star::uno::RuntimeException)
178 : : {
179 [ # # ]: 0 : ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
180 : :
181 : 0 : sal_Int32 nRet = -1;
182 [ # # ]: 0 : OutputDevice* pOutDev = VCLUnoHelper::GetOutputDevice( mxDevice );
183 [ # # ]: 0 : if ( pOutDev )
184 : : {
185 [ # # ]: 0 : Font aOldFont = pOutDev->GetFont();
186 [ # # ]: 0 : pOutDev->SetFont( maFont );
187 [ # # ][ # # ]: 0 : rDXArray = ::com::sun::star::uno::Sequence<sal_Int32>( str.getLength() );
[ # # ]
188 [ # # ][ # # ]: 0 : nRet = pOutDev->GetTextArray( str, rDXArray.getArray() );
[ # # ][ # # ]
189 [ # # ][ # # ]: 0 : pOutDev->SetFont( aOldFont );
190 : : }
191 [ # # ]: 0 : return nRet;
192 : : }
193 : :
194 : 0 : void VCLXFont::getKernPairs( ::com::sun::star::uno::Sequence< sal_Unicode >& rnChars1, ::com::sun::star::uno::Sequence< sal_Unicode >& rnChars2, ::com::sun::star::uno::Sequence< sal_Int16 >& rnKerns ) throw(::com::sun::star::uno::RuntimeException)
195 : : {
196 [ # # ]: 0 : ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
197 : :
198 [ # # ]: 0 : OutputDevice* pOutDev = VCLUnoHelper::GetOutputDevice( mxDevice );
199 [ # # ]: 0 : if( pOutDev )
200 : : {
201 [ # # ]: 0 : Font aOldFont = pOutDev->GetFont();
202 [ # # ]: 0 : pOutDev->SetFont( maFont );
203 : :
204 [ # # ]: 0 : sal_uLong nPairs = pOutDev->GetKerningPairCount();
205 [ # # ]: 0 : if ( nPairs )
206 : : {
207 [ # # ]: 0 : KerningPair* pData = new KerningPair[ nPairs ];
208 [ # # ]: 0 : pOutDev->GetKerningPairs( nPairs, pData );
209 : :
210 [ # # ][ # # ]: 0 : rnChars1 = ::com::sun::star::uno::Sequence<sal_Unicode>( nPairs );
[ # # ]
211 [ # # ][ # # ]: 0 : rnChars2 = ::com::sun::star::uno::Sequence<sal_Unicode>( nPairs );
[ # # ]
212 [ # # ][ # # ]: 0 : rnKerns = ::com::sun::star::uno::Sequence<sal_Int16>( nPairs );
[ # # ]
213 : :
214 [ # # ]: 0 : sal_Unicode* pChars1 = rnChars1.getArray();
215 [ # # ]: 0 : sal_Unicode* pChars2 = rnChars2.getArray();
216 [ # # ]: 0 : sal_Int16* pKerns = rnKerns.getArray();
217 : :
218 [ # # ]: 0 : for ( sal_uLong n = 0; n < nPairs; n++ )
219 : : {
220 : 0 : pChars1[n] = pData[n].nChar1;
221 : 0 : pChars2[n] = pData[n].nChar2;
222 : 0 : pKerns[n] = sal::static_int_cast< sal_Int16 >(pData[n].nKern);
223 : : }
224 : :
225 : :
226 [ # # ]: 0 : delete[] pData;
227 : : }
228 [ # # ][ # # ]: 0 : pOutDev->SetFont( aOldFont );
229 [ # # ]: 0 : }
230 : 0 : }
231 : :
232 : : // ::com::sun::star::awt::XFont2
233 : 4437 : sal_Bool VCLXFont::hasGlyphs( const ::rtl::OUString& aText )
234 : : throw(::com::sun::star::uno::RuntimeException)
235 : : {
236 [ + - ]: 4437 : ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
237 : :
238 [ + - ]: 4437 : OutputDevice* pOutDev = VCLUnoHelper::GetOutputDevice( mxDevice );
239 [ + - ]: 4437 : if ( pOutDev )
240 : : {
241 [ + - ]: 4437 : String aStr( aText );
242 [ + - ][ + + ]: 4437 : if ( pOutDev->HasGlyphs( maFont, aStr, 0, aStr.Len() ) == STRING_LEN )
243 : : {
244 : 4437 : return sal_True;
245 [ + - ][ + + ]: 4437 : }
246 : : }
247 : :
248 [ + - ]: 4437 : return sal_False;
249 : : }
250 : :
251 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|