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: dx_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 <ctype.h> // don't ask. msdev breaks otherwise...
35 #include "dx_winstuff.hxx"
36 #include "dx_spritecanvas.hxx"
37 #include "dx_canvasfont.hxx"
38 #include "dx_textlayout.hxx"
40 #include <com/sun/star/rendering/XSpriteCanvas.hpp>
41 #include <com/sun/star/rendering/PanoseWeight.hpp>
43 using namespace ::com::sun::star
;
49 INT
calcFontStyle( const rendering::FontRequest
& rFontRequest
)
51 INT
nFontStyle( Gdiplus::FontStyleRegular
);
53 if( rFontRequest
.FontDescription
.FontDescription
.Weight
> rendering::PanoseWeight::BOOK
)
54 nFontStyle
= Gdiplus::FontStyleBold
;
60 CanvasFont::CanvasFont( const rendering::FontRequest
& rFontRequest
,
61 const uno::Sequence
< beans::PropertyValue
>& /*extraFontProperties*/,
62 const geometry::Matrix2D
& fontMatrix
) :
63 CanvasFont_Base( m_aMutex
),
64 mpGdiPlusUser( GDIPlusUser::createInstance() ),
65 // TODO(F1): extraFontProperties, fontMatrix
68 maFontRequest( rFontRequest
),
69 maFontMatrix( fontMatrix
)
71 const sal_Int32
nLen(rFontRequest
.FontDescription
.FamilyName
.getLength());
72 const sal_Unicode
* pStr(rFontRequest
.FontDescription
.FamilyName
.getStr());
73 std::vector
< sal_Unicode
> pStrBuf(nLen
+1,0);
74 std::copy(pStr
,pStr
+nLen
,&pStrBuf
[0]);
76 mpFontFamily
.reset( new Gdiplus::FontFamily(reinterpret_cast<LPCWSTR
>(&pStrBuf
[0]),NULL
) );
77 if( !mpFontFamily
->IsAvailable() )
78 mpFontFamily
.reset( new Gdiplus::FontFamily(L
"Arial",NULL
) );
80 mpFont
.reset( new Gdiplus::Font( mpFontFamily
.get(),
81 static_cast<Gdiplus::REAL
>(rFontRequest
.CellSize
),
82 calcFontStyle( rFontRequest
),
83 Gdiplus::UnitWorld
));
86 void SAL_CALL
CanvasFont::disposing()
88 ::osl::MutexGuard
aGuard( m_aMutex
);
92 mpGdiPlusUser
.reset();
95 uno::Reference
< rendering::XTextLayout
> SAL_CALL
CanvasFont::createTextLayout( const rendering::StringContext
& aText
,
97 sal_Int64 nRandomSeed
) throw (uno::RuntimeException
)
99 ::osl::MutexGuard
aGuard( m_aMutex
);
101 return new TextLayout( aText
, nDirection
, nRandomSeed
, ImplRef( this ) );
104 uno::Sequence
< double > SAL_CALL
CanvasFont::getAvailableSizes( ) throw (uno::RuntimeException
)
106 ::osl::MutexGuard
aGuard( m_aMutex
);
109 return uno::Sequence
< double >();
112 uno::Sequence
< beans::PropertyValue
> SAL_CALL
CanvasFont::getExtraFontProperties( ) throw (uno::RuntimeException
)
114 ::osl::MutexGuard
aGuard( m_aMutex
);
117 return uno::Sequence
< beans::PropertyValue
>();
120 rendering::FontRequest SAL_CALL
CanvasFont::getFontRequest( ) throw (uno::RuntimeException
)
122 ::osl::MutexGuard
aGuard( m_aMutex
);
124 return maFontRequest
;
127 rendering::FontMetrics SAL_CALL
CanvasFont::getFontMetrics( ) throw (uno::RuntimeException
)
129 ::osl::MutexGuard
aGuard( m_aMutex
);
132 return rendering::FontMetrics();
135 #define SERVICE_NAME "com.sun.star.rendering.CanvasFont"
136 #define IMPLEMENTATION_NAME "DXCanvas::CanvasFont"
138 ::rtl::OUString SAL_CALL
CanvasFont::getImplementationName() throw( uno::RuntimeException
)
140 return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( IMPLEMENTATION_NAME
) );
143 sal_Bool SAL_CALL
CanvasFont::supportsService( const ::rtl::OUString
& ServiceName
) throw( uno::RuntimeException
)
145 return ServiceName
.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( SERVICE_NAME
) );
148 uno::Sequence
< ::rtl::OUString
> SAL_CALL
CanvasFont::getSupportedServiceNames() throw( uno::RuntimeException
)
150 uno::Sequence
< ::rtl::OUString
> aRet(1);
151 aRet
[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM ( SERVICE_NAME
) );
156 double CanvasFont::getCellAscent() const
158 ::osl::MutexGuard
aGuard( m_aMutex
);
160 return mpFontFamily
->GetCellAscent(0); // TODO(F1): rFontRequest.styleName
163 double CanvasFont::getEmHeight() const
165 ::osl::MutexGuard
aGuard( m_aMutex
);
167 return mpFontFamily
->GetEmHeight(0); // TODO(F1): rFontRequest.styleName
170 FontSharedPtr
CanvasFont::getFont() const
172 ::osl::MutexGuard
aGuard( m_aMutex
);
177 const ::com::sun::star::geometry::Matrix2D
& CanvasFont::getFontMatrix() const
179 ::osl::MutexGuard
aGuard( m_aMutex
);