CWS-TOOLING: integrate CWS os146
[LibreOffice.git] / canvas / source / directx / dx_canvasfont.cxx
blobd87079b34c0f98a561ba40fe5f14f0b6971cbadc
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_canvas.hxx"
31 #include <ctype.h> // don't ask. msdev breaks otherwise...
32 #include "dx_winstuff.hxx"
33 #include "dx_spritecanvas.hxx"
34 #include "dx_canvasfont.hxx"
35 #include "dx_textlayout.hxx"
37 #include <com/sun/star/rendering/XSpriteCanvas.hpp>
38 #include <com/sun/star/rendering/PanoseWeight.hpp>
40 using namespace ::com::sun::star;
42 namespace dxcanvas
44 namespace
46 INT calcFontStyle( const rendering::FontRequest& rFontRequest )
48 INT nFontStyle( Gdiplus::FontStyleRegular );
50 if( rFontRequest.FontDescription.FontDescription.Weight > rendering::PanoseWeight::BOOK )
51 nFontStyle = Gdiplus::FontStyleBold;
53 return nFontStyle;
57 CanvasFont::CanvasFont( const rendering::FontRequest& rFontRequest,
58 const uno::Sequence< beans::PropertyValue >& /*extraFontProperties*/,
59 const geometry::Matrix2D& fontMatrix ) :
60 CanvasFont_Base( m_aMutex ),
61 mpGdiPlusUser( GDIPlusUser::createInstance() ),
62 // TODO(F1): extraFontProperties, fontMatrix
63 mpFontFamily(),
64 mpFont(),
65 maFontRequest( rFontRequest ),
66 maFontMatrix( fontMatrix )
68 const sal_Int32 nLen(rFontRequest.FontDescription.FamilyName.getLength());
69 const sal_Unicode* pStr(rFontRequest.FontDescription.FamilyName.getStr());
70 std::vector< sal_Unicode > pStrBuf(nLen+1,0);
71 std::copy(pStr,pStr+nLen,&pStrBuf[0]);
73 mpFontFamily.reset( new Gdiplus::FontFamily(reinterpret_cast<LPCWSTR>(&pStrBuf[0]),NULL) );
74 if( !mpFontFamily->IsAvailable() )
75 mpFontFamily.reset( new Gdiplus::FontFamily(L"Arial",NULL) );
77 mpFont.reset( new Gdiplus::Font( mpFontFamily.get(),
78 static_cast<Gdiplus::REAL>(rFontRequest.CellSize),
79 calcFontStyle( rFontRequest ),
80 Gdiplus::UnitWorld ));
83 void SAL_CALL CanvasFont::disposing()
85 ::osl::MutexGuard aGuard( m_aMutex );
87 mpFont.reset();
88 mpFontFamily.reset();
89 mpGdiPlusUser.reset();
92 uno::Reference< rendering::XTextLayout > SAL_CALL CanvasFont::createTextLayout( const rendering::StringContext& aText,
93 sal_Int8 nDirection,
94 sal_Int64 nRandomSeed ) throw (uno::RuntimeException)
96 ::osl::MutexGuard aGuard( m_aMutex );
98 return new TextLayout( aText, nDirection, nRandomSeed, ImplRef( this ) );
101 uno::Sequence< double > SAL_CALL CanvasFont::getAvailableSizes( ) throw (uno::RuntimeException)
103 ::osl::MutexGuard aGuard( m_aMutex );
105 // TODO
106 return uno::Sequence< double >();
109 uno::Sequence< beans::PropertyValue > SAL_CALL CanvasFont::getExtraFontProperties( ) throw (uno::RuntimeException)
111 ::osl::MutexGuard aGuard( m_aMutex );
113 // TODO
114 return uno::Sequence< beans::PropertyValue >();
117 rendering::FontRequest SAL_CALL CanvasFont::getFontRequest( ) throw (uno::RuntimeException)
119 ::osl::MutexGuard aGuard( m_aMutex );
121 return maFontRequest;
124 rendering::FontMetrics SAL_CALL CanvasFont::getFontMetrics( ) throw (uno::RuntimeException)
126 ::osl::MutexGuard aGuard( m_aMutex );
128 // TODO
129 return rendering::FontMetrics();
132 #define SERVICE_NAME "com.sun.star.rendering.CanvasFont"
133 #define IMPLEMENTATION_NAME "DXCanvas::CanvasFont"
135 ::rtl::OUString SAL_CALL CanvasFont::getImplementationName() throw( uno::RuntimeException )
137 return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( IMPLEMENTATION_NAME ) );
140 sal_Bool SAL_CALL CanvasFont::supportsService( const ::rtl::OUString& ServiceName ) throw( uno::RuntimeException )
142 return ServiceName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( SERVICE_NAME ) );
145 uno::Sequence< ::rtl::OUString > SAL_CALL CanvasFont::getSupportedServiceNames() throw( uno::RuntimeException )
147 uno::Sequence< ::rtl::OUString > aRet(1);
148 aRet[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM ( SERVICE_NAME ) );
150 return aRet;
153 double CanvasFont::getCellAscent() const
155 ::osl::MutexGuard aGuard( m_aMutex );
157 return mpFontFamily->GetCellAscent(0); // TODO(F1): rFontRequest.styleName
160 double CanvasFont::getEmHeight() const
162 ::osl::MutexGuard aGuard( m_aMutex );
164 return mpFontFamily->GetEmHeight(0); // TODO(F1): rFontRequest.styleName
167 FontSharedPtr CanvasFont::getFont() const
169 ::osl::MutexGuard aGuard( m_aMutex );
171 return mpFont;
174 const ::com::sun::star::geometry::Matrix2D& CanvasFont::getFontMatrix() const
176 ::osl::MutexGuard aGuard( m_aMutex );
178 return maFontMatrix;