1*b1cdbd2cSJim Jagielski /************************************************************** 2*b1cdbd2cSJim Jagielski * 3*b1cdbd2cSJim Jagielski * Licensed to the Apache Software Foundation (ASF) under one 4*b1cdbd2cSJim Jagielski * or more contributor license agreements. See the NOTICE file 5*b1cdbd2cSJim Jagielski * distributed with this work for additional information 6*b1cdbd2cSJim Jagielski * regarding copyright ownership. The ASF licenses this file 7*b1cdbd2cSJim Jagielski * to you under the Apache License, Version 2.0 (the 8*b1cdbd2cSJim Jagielski * "License"); you may not use this file except in compliance 9*b1cdbd2cSJim Jagielski * with the License. You may obtain a copy of the License at 10*b1cdbd2cSJim Jagielski * 11*b1cdbd2cSJim Jagielski * http://www.apache.org/licenses/LICENSE-2.0 12*b1cdbd2cSJim Jagielski * 13*b1cdbd2cSJim Jagielski * Unless required by applicable law or agreed to in writing, 14*b1cdbd2cSJim Jagielski * software distributed under the License is distributed on an 15*b1cdbd2cSJim Jagielski * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*b1cdbd2cSJim Jagielski * KIND, either express or implied. See the License for the 17*b1cdbd2cSJim Jagielski * specific language governing permissions and limitations 18*b1cdbd2cSJim Jagielski * under the License. 19*b1cdbd2cSJim Jagielski * 20*b1cdbd2cSJim Jagielski *************************************************************/ 21*b1cdbd2cSJim Jagielski 22*b1cdbd2cSJim Jagielski 23*b1cdbd2cSJim Jagielski 24*b1cdbd2cSJim Jagielski // MARKER(update_precomp.py): autogen include statement, do not remove 25*b1cdbd2cSJim Jagielski #include "precompiled_canvas.hxx" 26*b1cdbd2cSJim Jagielski 27*b1cdbd2cSJim Jagielski #include <ctype.h> // don't ask. msdev breaks otherwise... 28*b1cdbd2cSJim Jagielski #include "dx_winstuff.hxx" 29*b1cdbd2cSJim Jagielski #include "dx_spritecanvas.hxx" 30*b1cdbd2cSJim Jagielski #include "dx_canvasfont.hxx" 31*b1cdbd2cSJim Jagielski #include "dx_textlayout.hxx" 32*b1cdbd2cSJim Jagielski 33*b1cdbd2cSJim Jagielski #include <com/sun/star/rendering/XSpriteCanvas.hpp> 34*b1cdbd2cSJim Jagielski #include <com/sun/star/rendering/PanoseWeight.hpp> 35*b1cdbd2cSJim Jagielski 36*b1cdbd2cSJim Jagielski using namespace ::com::sun::star; 37*b1cdbd2cSJim Jagielski 38*b1cdbd2cSJim Jagielski namespace dxcanvas 39*b1cdbd2cSJim Jagielski { 40*b1cdbd2cSJim Jagielski namespace 41*b1cdbd2cSJim Jagielski { calcFontStyle(const rendering::FontRequest & rFontRequest)42*b1cdbd2cSJim Jagielski INT calcFontStyle( const rendering::FontRequest& rFontRequest ) 43*b1cdbd2cSJim Jagielski { 44*b1cdbd2cSJim Jagielski INT nFontStyle( Gdiplus::FontStyleRegular ); 45*b1cdbd2cSJim Jagielski 46*b1cdbd2cSJim Jagielski if( rFontRequest.FontDescription.FontDescription.Weight > rendering::PanoseWeight::BOOK ) 47*b1cdbd2cSJim Jagielski nFontStyle = Gdiplus::FontStyleBold; 48*b1cdbd2cSJim Jagielski 49*b1cdbd2cSJim Jagielski return nFontStyle; 50*b1cdbd2cSJim Jagielski } 51*b1cdbd2cSJim Jagielski } 52*b1cdbd2cSJim Jagielski CanvasFont(const rendering::FontRequest & rFontRequest,const uno::Sequence<beans::PropertyValue> &,const geometry::Matrix2D & fontMatrix)53*b1cdbd2cSJim Jagielski CanvasFont::CanvasFont( const rendering::FontRequest& rFontRequest, 54*b1cdbd2cSJim Jagielski const uno::Sequence< beans::PropertyValue >& /*extraFontProperties*/, 55*b1cdbd2cSJim Jagielski const geometry::Matrix2D& fontMatrix ) : 56*b1cdbd2cSJim Jagielski CanvasFont_Base( m_aMutex ), 57*b1cdbd2cSJim Jagielski mpGdiPlusUser( GDIPlusUser::createInstance() ), 58*b1cdbd2cSJim Jagielski // TODO(F1): extraFontProperties, fontMatrix 59*b1cdbd2cSJim Jagielski mpFontFamily(), 60*b1cdbd2cSJim Jagielski mpFont(), 61*b1cdbd2cSJim Jagielski maFontRequest( rFontRequest ), 62*b1cdbd2cSJim Jagielski maFontMatrix( fontMatrix ) 63*b1cdbd2cSJim Jagielski { 64*b1cdbd2cSJim Jagielski const sal_Int32 nLen(rFontRequest.FontDescription.FamilyName.getLength()); 65*b1cdbd2cSJim Jagielski const sal_Unicode* pStr(rFontRequest.FontDescription.FamilyName.getStr()); 66*b1cdbd2cSJim Jagielski std::vector< sal_Unicode > pStrBuf(nLen+1,0); 67*b1cdbd2cSJim Jagielski std::copy(pStr,pStr+nLen,&pStrBuf[0]); 68*b1cdbd2cSJim Jagielski 69*b1cdbd2cSJim Jagielski mpFontFamily.reset( new Gdiplus::FontFamily(reinterpret_cast<LPCWSTR>(&pStrBuf[0]),NULL) ); 70*b1cdbd2cSJim Jagielski if( !mpFontFamily->IsAvailable() ) 71*b1cdbd2cSJim Jagielski mpFontFamily.reset( new Gdiplus::FontFamily(L"Arial",NULL) ); 72*b1cdbd2cSJim Jagielski 73*b1cdbd2cSJim Jagielski mpFont.reset( new Gdiplus::Font( mpFontFamily.get(), 74*b1cdbd2cSJim Jagielski static_cast<Gdiplus::REAL>(rFontRequest.CellSize), 75*b1cdbd2cSJim Jagielski calcFontStyle( rFontRequest ), 76*b1cdbd2cSJim Jagielski Gdiplus::UnitWorld )); 77*b1cdbd2cSJim Jagielski } 78*b1cdbd2cSJim Jagielski disposing()79*b1cdbd2cSJim Jagielski void SAL_CALL CanvasFont::disposing() 80*b1cdbd2cSJim Jagielski { 81*b1cdbd2cSJim Jagielski ::osl::MutexGuard aGuard( m_aMutex ); 82*b1cdbd2cSJim Jagielski 83*b1cdbd2cSJim Jagielski mpFont.reset(); 84*b1cdbd2cSJim Jagielski mpFontFamily.reset(); 85*b1cdbd2cSJim Jagielski mpGdiPlusUser.reset(); 86*b1cdbd2cSJim Jagielski } 87*b1cdbd2cSJim Jagielski createTextLayout(const rendering::StringContext & aText,sal_Int8 nDirection,sal_Int64 nRandomSeed)88*b1cdbd2cSJim Jagielski uno::Reference< rendering::XTextLayout > SAL_CALL CanvasFont::createTextLayout( const rendering::StringContext& aText, 89*b1cdbd2cSJim Jagielski sal_Int8 nDirection, 90*b1cdbd2cSJim Jagielski sal_Int64 nRandomSeed ) throw (uno::RuntimeException) 91*b1cdbd2cSJim Jagielski { 92*b1cdbd2cSJim Jagielski ::osl::MutexGuard aGuard( m_aMutex ); 93*b1cdbd2cSJim Jagielski 94*b1cdbd2cSJim Jagielski return new TextLayout( aText, nDirection, nRandomSeed, ImplRef( this ) ); 95*b1cdbd2cSJim Jagielski } 96*b1cdbd2cSJim Jagielski getAvailableSizes()97*b1cdbd2cSJim Jagielski uno::Sequence< double > SAL_CALL CanvasFont::getAvailableSizes( ) throw (uno::RuntimeException) 98*b1cdbd2cSJim Jagielski { 99*b1cdbd2cSJim Jagielski ::osl::MutexGuard aGuard( m_aMutex ); 100*b1cdbd2cSJim Jagielski 101*b1cdbd2cSJim Jagielski // TODO 102*b1cdbd2cSJim Jagielski return uno::Sequence< double >(); 103*b1cdbd2cSJim Jagielski } 104*b1cdbd2cSJim Jagielski getExtraFontProperties()105*b1cdbd2cSJim Jagielski uno::Sequence< beans::PropertyValue > SAL_CALL CanvasFont::getExtraFontProperties( ) throw (uno::RuntimeException) 106*b1cdbd2cSJim Jagielski { 107*b1cdbd2cSJim Jagielski ::osl::MutexGuard aGuard( m_aMutex ); 108*b1cdbd2cSJim Jagielski 109*b1cdbd2cSJim Jagielski // TODO 110*b1cdbd2cSJim Jagielski return uno::Sequence< beans::PropertyValue >(); 111*b1cdbd2cSJim Jagielski } 112*b1cdbd2cSJim Jagielski getFontRequest()113*b1cdbd2cSJim Jagielski rendering::FontRequest SAL_CALL CanvasFont::getFontRequest( ) throw (uno::RuntimeException) 114*b1cdbd2cSJim Jagielski { 115*b1cdbd2cSJim Jagielski ::osl::MutexGuard aGuard( m_aMutex ); 116*b1cdbd2cSJim Jagielski 117*b1cdbd2cSJim Jagielski return maFontRequest; 118*b1cdbd2cSJim Jagielski } 119*b1cdbd2cSJim Jagielski getFontMetrics()120*b1cdbd2cSJim Jagielski rendering::FontMetrics SAL_CALL CanvasFont::getFontMetrics( ) throw (uno::RuntimeException) 121*b1cdbd2cSJim Jagielski { 122*b1cdbd2cSJim Jagielski ::osl::MutexGuard aGuard( m_aMutex ); 123*b1cdbd2cSJim Jagielski 124*b1cdbd2cSJim Jagielski // TODO 125*b1cdbd2cSJim Jagielski return rendering::FontMetrics(); 126*b1cdbd2cSJim Jagielski } 127*b1cdbd2cSJim Jagielski 128*b1cdbd2cSJim Jagielski #define SERVICE_NAME "com.sun.star.rendering.CanvasFont" 129*b1cdbd2cSJim Jagielski #define IMPLEMENTATION_NAME "DXCanvas::CanvasFont" 130*b1cdbd2cSJim Jagielski getImplementationName()131*b1cdbd2cSJim Jagielski ::rtl::OUString SAL_CALL CanvasFont::getImplementationName() throw( uno::RuntimeException ) 132*b1cdbd2cSJim Jagielski { 133*b1cdbd2cSJim Jagielski return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( IMPLEMENTATION_NAME ) ); 134*b1cdbd2cSJim Jagielski } 135*b1cdbd2cSJim Jagielski supportsService(const::rtl::OUString & ServiceName)136*b1cdbd2cSJim Jagielski sal_Bool SAL_CALL CanvasFont::supportsService( const ::rtl::OUString& ServiceName ) throw( uno::RuntimeException ) 137*b1cdbd2cSJim Jagielski { 138*b1cdbd2cSJim Jagielski return ServiceName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( SERVICE_NAME ) ); 139*b1cdbd2cSJim Jagielski } 140*b1cdbd2cSJim Jagielski getSupportedServiceNames()141*b1cdbd2cSJim Jagielski uno::Sequence< ::rtl::OUString > SAL_CALL CanvasFont::getSupportedServiceNames() throw( uno::RuntimeException ) 142*b1cdbd2cSJim Jagielski { 143*b1cdbd2cSJim Jagielski uno::Sequence< ::rtl::OUString > aRet(1); 144*b1cdbd2cSJim Jagielski aRet[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM ( SERVICE_NAME ) ); 145*b1cdbd2cSJim Jagielski 146*b1cdbd2cSJim Jagielski return aRet; 147*b1cdbd2cSJim Jagielski } 148*b1cdbd2cSJim Jagielski getCellAscent() const149*b1cdbd2cSJim Jagielski double CanvasFont::getCellAscent() const 150*b1cdbd2cSJim Jagielski { 151*b1cdbd2cSJim Jagielski ::osl::MutexGuard aGuard( m_aMutex ); 152*b1cdbd2cSJim Jagielski 153*b1cdbd2cSJim Jagielski return mpFontFamily->GetCellAscent(0); // TODO(F1): rFontRequest.styleName 154*b1cdbd2cSJim Jagielski } 155*b1cdbd2cSJim Jagielski getEmHeight() const156*b1cdbd2cSJim Jagielski double CanvasFont::getEmHeight() const 157*b1cdbd2cSJim Jagielski { 158*b1cdbd2cSJim Jagielski ::osl::MutexGuard aGuard( m_aMutex ); 159*b1cdbd2cSJim Jagielski 160*b1cdbd2cSJim Jagielski return mpFontFamily->GetEmHeight(0); // TODO(F1): rFontRequest.styleName 161*b1cdbd2cSJim Jagielski } 162*b1cdbd2cSJim Jagielski getFont() const163*b1cdbd2cSJim Jagielski FontSharedPtr CanvasFont::getFont() const 164*b1cdbd2cSJim Jagielski { 165*b1cdbd2cSJim Jagielski ::osl::MutexGuard aGuard( m_aMutex ); 166*b1cdbd2cSJim Jagielski 167*b1cdbd2cSJim Jagielski return mpFont; 168*b1cdbd2cSJim Jagielski } 169*b1cdbd2cSJim Jagielski getFontMatrix() const170*b1cdbd2cSJim Jagielski const ::com::sun::star::geometry::Matrix2D& CanvasFont::getFontMatrix() const 171*b1cdbd2cSJim Jagielski { 172*b1cdbd2cSJim Jagielski ::osl::MutexGuard aGuard( m_aMutex ); 173*b1cdbd2cSJim Jagielski 174*b1cdbd2cSJim Jagielski return maFontMatrix; 175*b1cdbd2cSJim Jagielski } 176*b1cdbd2cSJim Jagielski } 177