1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: cairo_canvasfont.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_canvas.hxx"
34 #include <canvas/debug.hxx>
36 #include <rtl/math.hxx>
37 #include <basegfx/numeric/ftools.hxx>
39 #include <vcl/metric.hxx>
40 #include <i18npool/mslangid.hxx>
42 #include "cairo_canvasfont.hxx"
43 #include "cairo_textlayout.hxx"
45 using namespace ::com::sun::star
;
51 // Little helper to encapsulate locking into policy class
56 aGuard( Application::GetSolarMutex() )
60 /// To be compatible with CanvasBase mutex concept
61 LocalGuard( const ::osl::Mutex
& ) :
62 aGuard( Application::GetSolarMutex() )
71 CanvasFont::CanvasFont( const rendering::FontRequest
& rFontRequest
,
72 const uno::Sequence
< beans::PropertyValue
>& /*rExtraFontProperties*/,
73 const geometry::Matrix2D
& rFontMatrix
,
74 const SurfaceProviderRef
& rDevice
) :
75 CanvasFont_Base( m_aMutex
),
76 maFont( Font( rFontRequest
.FontDescription
.FamilyName
,
77 rFontRequest
.FontDescription
.StyleName
,
78 Size( 0, ::basegfx::fround(rFontRequest
.CellSize
) ) ) ),
79 maFontRequest( rFontRequest
),
80 mpRefDevice( rDevice
)
82 maFont
->SetAlign( ALIGN_BASELINE
);
83 maFont
->SetCharSet( (rFontRequest
.FontDescription
.IsSymbolFont
==com::sun::star::util::TriState_YES
) ? RTL_TEXTENCODING_SYMBOL
: RTL_TEXTENCODING_UNICODE
);
84 maFont
->SetVertical( (rFontRequest
.FontDescription
.IsVertical
==com::sun::star::util::TriState_YES
) ? TRUE
: FALSE
);
86 // TODO(F2): improve panose->vclenum conversion
87 maFont
->SetWeight( static_cast<FontWeight
>(rFontRequest
.FontDescription
.FontDescription
.Weight
) );
88 maFont
->SetItalic( (rFontRequest
.FontDescription
.FontDescription
.Letterform
<=8) ? ITALIC_NONE
: ITALIC_NORMAL
);
90 maFont
->SetLanguage(MsLangId::convertLocaleToLanguage(rFontRequest
.Locale
));
92 // adjust to stretched/shrinked font
93 if( !::rtl::math::approxEqual( rFontMatrix
.m00
, rFontMatrix
.m11
) )
95 OutputDevice
* pOutDev( mpRefDevice
->getOutputDevice() );
99 const bool bOldMapState( pOutDev
->IsMapModeEnabled() );
100 pOutDev
->EnableMapMode(FALSE
);
102 const Size aSize
= pOutDev
->GetFontMetric( *maFont
).GetSize();
104 const double fDividend( rFontMatrix
.m10
+ rFontMatrix
.m11
);
105 double fStretch
= (rFontMatrix
.m00
+ rFontMatrix
.m01
);
107 if( !::basegfx::fTools::equalZero( fDividend
) )
108 fStretch
/= fDividend
;
110 const long nNewWidth
= ::basegfx::fround( aSize
.Width() * fStretch
);
112 maFont
->SetWidth( nNewWidth
);
114 pOutDev
->EnableMapMode(bOldMapState
);
119 void SAL_CALL
CanvasFont::disposing()
126 uno::Reference
< rendering::XTextLayout
> SAL_CALL
CanvasFont::createTextLayout( const rendering::StringContext
& aText
, sal_Int8 nDirection
, sal_Int64 nRandomSeed
) throw (uno::RuntimeException
)
130 if( !mpRefDevice
.is() )
131 return uno::Reference
< rendering::XTextLayout
>(); // we're disposed
133 return new TextLayout( aText
,
140 rendering::FontRequest SAL_CALL
CanvasFont::getFontRequest( ) throw (uno::RuntimeException
)
144 return maFontRequest
;
147 rendering::FontMetrics SAL_CALL
CanvasFont::getFontMetrics( ) throw (uno::RuntimeException
)
152 return rendering::FontMetrics();
155 uno::Sequence
< double > SAL_CALL
CanvasFont::getAvailableSizes( ) throw (uno::RuntimeException
)
160 return uno::Sequence
< double >();
163 uno::Sequence
< beans::PropertyValue
> SAL_CALL
CanvasFont::getExtraFontProperties( ) throw (uno::RuntimeException
)
168 return uno::Sequence
< beans::PropertyValue
>();
171 #define IMPLEMENTATION_NAME "CairoCanvas::CanvasFont"
172 #define SERVICE_NAME "com.sun.star.rendering.CanvasFont"
174 ::rtl::OUString SAL_CALL
CanvasFont::getImplementationName() throw( uno::RuntimeException
)
176 return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( IMPLEMENTATION_NAME
) );
179 sal_Bool SAL_CALL
CanvasFont::supportsService( const ::rtl::OUString
& ServiceName
) throw( uno::RuntimeException
)
181 return ServiceName
.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( SERVICE_NAME
) );
184 uno::Sequence
< ::rtl::OUString
> SAL_CALL
CanvasFont::getSupportedServiceNames() throw( uno::RuntimeException
)
186 uno::Sequence
< ::rtl::OUString
> aRet(1);
187 aRet
[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM ( SERVICE_NAME
) );
192 ::Font
CanvasFont::getVCLFont() const