1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 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. 14 * 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). 20 * 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. 25 * 26 ************************************************************************/ 27 28 // MARKER(update_precomp.py): autogen include statement, do not remove 29 #include "precompiled_canvas.hxx" 30 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" 36 37 #include <com/sun/star/rendering/XSpriteCanvas.hpp> 38 #include <com/sun/star/rendering/PanoseWeight.hpp> 39 40 using namespace ::com::sun::star; 41 42 namespace dxcanvas 43 { 44 namespace 45 { 46 INT calcFontStyle( const rendering::FontRequest& rFontRequest ) 47 { 48 INT nFontStyle( Gdiplus::FontStyleRegular ); 49 50 if( rFontRequest.FontDescription.FontDescription.Weight > rendering::PanoseWeight::BOOK ) 51 nFontStyle = Gdiplus::FontStyleBold; 52 53 return nFontStyle; 54 } 55 } 56 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 ) 67 { 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]); 72 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) ); 76 77 mpFont.reset( new Gdiplus::Font( mpFontFamily.get(), 78 static_cast<Gdiplus::REAL>(rFontRequest.CellSize), 79 calcFontStyle( rFontRequest ), 80 Gdiplus::UnitWorld )); 81 } 82 83 void SAL_CALL CanvasFont::disposing() 84 { 85 ::osl::MutexGuard aGuard( m_aMutex ); 86 87 mpFont.reset(); 88 mpFontFamily.reset(); 89 mpGdiPlusUser.reset(); 90 } 91 92 uno::Reference< rendering::XTextLayout > SAL_CALL CanvasFont::createTextLayout( const rendering::StringContext& aText, 93 sal_Int8 nDirection, 94 sal_Int64 nRandomSeed ) throw (uno::RuntimeException) 95 { 96 ::osl::MutexGuard aGuard( m_aMutex ); 97 98 return new TextLayout( aText, nDirection, nRandomSeed, ImplRef( this ) ); 99 } 100 101 uno::Sequence< double > SAL_CALL CanvasFont::getAvailableSizes( ) throw (uno::RuntimeException) 102 { 103 ::osl::MutexGuard aGuard( m_aMutex ); 104 105 // TODO 106 return uno::Sequence< double >(); 107 } 108 109 uno::Sequence< beans::PropertyValue > SAL_CALL CanvasFont::getExtraFontProperties( ) throw (uno::RuntimeException) 110 { 111 ::osl::MutexGuard aGuard( m_aMutex ); 112 113 // TODO 114 return uno::Sequence< beans::PropertyValue >(); 115 } 116 117 rendering::FontRequest SAL_CALL CanvasFont::getFontRequest( ) throw (uno::RuntimeException) 118 { 119 ::osl::MutexGuard aGuard( m_aMutex ); 120 121 return maFontRequest; 122 } 123 124 rendering::FontMetrics SAL_CALL CanvasFont::getFontMetrics( ) throw (uno::RuntimeException) 125 { 126 ::osl::MutexGuard aGuard( m_aMutex ); 127 128 // TODO 129 return rendering::FontMetrics(); 130 } 131 132 #define SERVICE_NAME "com.sun.star.rendering.CanvasFont" 133 #define IMPLEMENTATION_NAME "DXCanvas::CanvasFont" 134 135 ::rtl::OUString SAL_CALL CanvasFont::getImplementationName() throw( uno::RuntimeException ) 136 { 137 return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( IMPLEMENTATION_NAME ) ); 138 } 139 140 sal_Bool SAL_CALL CanvasFont::supportsService( const ::rtl::OUString& ServiceName ) throw( uno::RuntimeException ) 141 { 142 return ServiceName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( SERVICE_NAME ) ); 143 } 144 145 uno::Sequence< ::rtl::OUString > SAL_CALL CanvasFont::getSupportedServiceNames() throw( uno::RuntimeException ) 146 { 147 uno::Sequence< ::rtl::OUString > aRet(1); 148 aRet[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM ( SERVICE_NAME ) ); 149 150 return aRet; 151 } 152 153 double CanvasFont::getCellAscent() const 154 { 155 ::osl::MutexGuard aGuard( m_aMutex ); 156 157 return mpFontFamily->GetCellAscent(0); // TODO(F1): rFontRequest.styleName 158 } 159 160 double CanvasFont::getEmHeight() const 161 { 162 ::osl::MutexGuard aGuard( m_aMutex ); 163 164 return mpFontFamily->GetEmHeight(0); // TODO(F1): rFontRequest.styleName 165 } 166 167 FontSharedPtr CanvasFont::getFont() const 168 { 169 ::osl::MutexGuard aGuard( m_aMutex ); 170 171 return mpFont; 172 } 173 174 const ::com::sun::star::geometry::Matrix2D& CanvasFont::getFontMatrix() const 175 { 176 ::osl::MutexGuard aGuard( m_aMutex ); 177 178 return maFontMatrix; 179 } 180 } 181