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: 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>
38 #include <i18npool/mslangid.hxx>
39 #include <vcl/metric.hxx>
41 #include "canvasfont.hxx"
42 #include "textlayout.hxx"
44 using namespace ::com::sun::star
;
49 CanvasFont::CanvasFont( const rendering::FontRequest
& rFontRequest
,
50 const uno::Sequence
< beans::PropertyValue
>& ,
51 const geometry::Matrix2D
& rFontMatrix
,
52 rendering::XGraphicDevice
& rDevice
,
53 const OutDevProviderSharedPtr
& rOutDevProvider
) :
54 CanvasFont_Base( m_aMutex
),
55 maFont( Font( rFontRequest
.FontDescription
.FamilyName
,
56 rFontRequest
.FontDescription
.StyleName
,
57 Size( 0, ::basegfx::fround(rFontRequest
.CellSize
) ) ) ),
58 maFontRequest( rFontRequest
),
59 mpRefDevice( &rDevice
),
60 mpOutDevProvider( rOutDevProvider
)
62 maFont
->SetAlign( ALIGN_BASELINE
);
63 maFont
->SetCharSet( (rFontRequest
.FontDescription
.IsSymbolFont
==com::sun::star::util::TriState_YES
) ? RTL_TEXTENCODING_SYMBOL
: RTL_TEXTENCODING_UNICODE
);
64 maFont
->SetVertical( (rFontRequest
.FontDescription
.IsVertical
==com::sun::star::util::TriState_YES
) ? TRUE
: FALSE
);
66 // TODO(F2): improve panose->vclenum conversion
67 maFont
->SetWeight( static_cast<FontWeight
>(rFontRequest
.FontDescription
.FontDescription
.Weight
) );
68 maFont
->SetItalic( (rFontRequest
.FontDescription
.FontDescription
.Letterform
<=8) ? ITALIC_NONE
: ITALIC_NORMAL
);
70 maFont
->SetLanguage(MsLangId::convertLocaleToLanguage(rFontRequest
.Locale
));
72 // adjust to stretched/shrinked font
73 if( !::rtl::math::approxEqual( rFontMatrix
.m00
, rFontMatrix
.m11
) )
75 OutputDevice
& rOutDev( rOutDevProvider
->getOutDev() );
77 const bool bOldMapState( rOutDev
.IsMapModeEnabled() );
78 rOutDev
.EnableMapMode(FALSE
);
80 const Size aSize
= rOutDev
.GetFontMetric( *maFont
).GetSize();
82 const double fDividend( rFontMatrix
.m10
+ rFontMatrix
.m11
);
83 double fStretch
= (rFontMatrix
.m00
+ rFontMatrix
.m01
);
85 if( !::basegfx::fTools::equalZero( fDividend
) )
86 fStretch
/= fDividend
;
88 const long nNewWidth
= ::basegfx::fround( aSize
.Width() * fStretch
);
90 maFont
->SetWidth( nNewWidth
);
92 rOutDev
.EnableMapMode(bOldMapState
);
96 void SAL_CALL
CanvasFont::disposing()
98 tools::LocalGuard aGuard
;
100 mpOutDevProvider
.reset();
104 uno::Reference
< rendering::XTextLayout
> SAL_CALL
CanvasFont::createTextLayout( const rendering::StringContext
& aText
, sal_Int8 nDirection
, sal_Int64 nRandomSeed
) throw (uno::RuntimeException
)
106 tools::LocalGuard aGuard
;
108 if( !mpRefDevice
.is() )
109 return uno::Reference
< rendering::XTextLayout
>(); // we're disposed
111 return new TextLayout( aText
,
119 rendering::FontRequest SAL_CALL
CanvasFont::getFontRequest( ) throw (uno::RuntimeException
)
121 tools::LocalGuard aGuard
;
123 return maFontRequest
;
126 rendering::FontMetrics SAL_CALL
CanvasFont::getFontMetrics( ) throw (uno::RuntimeException
)
128 tools::LocalGuard aGuard
;
131 return rendering::FontMetrics();
134 uno::Sequence
< double > SAL_CALL
CanvasFont::getAvailableSizes( ) throw (uno::RuntimeException
)
136 tools::LocalGuard aGuard
;
139 return uno::Sequence
< double >();
142 uno::Sequence
< beans::PropertyValue
> SAL_CALL
CanvasFont::getExtraFontProperties( ) throw (uno::RuntimeException
)
144 tools::LocalGuard aGuard
;
147 return uno::Sequence
< beans::PropertyValue
>();
150 #define IMPLEMENTATION_NAME "VCLCanvas::CanvasFont"
151 #define SERVICE_NAME "com.sun.star.rendering.CanvasFont"
153 ::rtl::OUString SAL_CALL
CanvasFont::getImplementationName() throw( uno::RuntimeException
)
155 return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( IMPLEMENTATION_NAME
) );
158 sal_Bool SAL_CALL
CanvasFont::supportsService( const ::rtl::OUString
& ServiceName
) throw( uno::RuntimeException
)
160 return ServiceName
.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( SERVICE_NAME
) );
163 uno::Sequence
< ::rtl::OUString
> SAL_CALL
CanvasFont::getSupportedServiceNames() throw( uno::RuntimeException
)
165 uno::Sequence
< ::rtl::OUString
> aRet(1);
166 aRet
[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM ( SERVICE_NAME
) );
171 ::Font
CanvasFont::getVCLFont() const