1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 29*cdf0e10cSrcweir #include "precompiled_canvas.hxx" 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir #include <ctype.h> // don't ask. msdev breaks otherwise... 32*cdf0e10cSrcweir #include <canvas/debug.hxx> 33*cdf0e10cSrcweir #include <canvas/verbosetrace.hxx> 34*cdf0e10cSrcweir 35*cdf0e10cSrcweir #include <basegfx/matrix/b2dhommatrix.hxx> 36*cdf0e10cSrcweir #include <basegfx/numeric/ftools.hxx> 37*cdf0e10cSrcweir #include "dx_bitmap.hxx" 38*cdf0e10cSrcweir #include "dx_textlayout.hxx" 39*cdf0e10cSrcweir #include "dx_spritecanvas.hxx" 40*cdf0e10cSrcweir #include "dx_textlayout_drawhelper.hxx" 41*cdf0e10cSrcweir 42*cdf0e10cSrcweir 43*cdf0e10cSrcweir using namespace ::com::sun::star; 44*cdf0e10cSrcweir 45*cdf0e10cSrcweir namespace dxcanvas 46*cdf0e10cSrcweir { 47*cdf0e10cSrcweir TextLayout::TextLayout( const rendering::StringContext& aText, 48*cdf0e10cSrcweir sal_Int8 nDirection, 49*cdf0e10cSrcweir sal_Int64 /*nRandomSeed*/, 50*cdf0e10cSrcweir const CanvasFont::ImplRef& rFont ) : 51*cdf0e10cSrcweir TextLayout_Base( m_aMutex ), 52*cdf0e10cSrcweir maText( aText ), 53*cdf0e10cSrcweir maLogicalAdvancements(), 54*cdf0e10cSrcweir mpFont( rFont ), 55*cdf0e10cSrcweir mnTextDirection( nDirection ) 56*cdf0e10cSrcweir { 57*cdf0e10cSrcweir } 58*cdf0e10cSrcweir 59*cdf0e10cSrcweir TextLayout::~TextLayout() 60*cdf0e10cSrcweir { 61*cdf0e10cSrcweir } 62*cdf0e10cSrcweir 63*cdf0e10cSrcweir void SAL_CALL TextLayout::disposing() 64*cdf0e10cSrcweir { 65*cdf0e10cSrcweir mpFont.reset(); 66*cdf0e10cSrcweir } 67*cdf0e10cSrcweir 68*cdf0e10cSrcweir // XTextLayout 69*cdf0e10cSrcweir uno::Sequence< uno::Reference< rendering::XPolyPolygon2D > > SAL_CALL TextLayout::queryTextShapes( ) throw (uno::RuntimeException) 70*cdf0e10cSrcweir { 71*cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex ); 72*cdf0e10cSrcweir 73*cdf0e10cSrcweir // TODO 74*cdf0e10cSrcweir return uno::Sequence< uno::Reference< rendering::XPolyPolygon2D > >(); 75*cdf0e10cSrcweir } 76*cdf0e10cSrcweir 77*cdf0e10cSrcweir uno::Sequence< geometry::RealRectangle2D > SAL_CALL TextLayout::queryInkMeasures( ) throw (uno::RuntimeException) 78*cdf0e10cSrcweir { 79*cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex ); 80*cdf0e10cSrcweir 81*cdf0e10cSrcweir // TODO 82*cdf0e10cSrcweir return uno::Sequence< geometry::RealRectangle2D >(); 83*cdf0e10cSrcweir } 84*cdf0e10cSrcweir 85*cdf0e10cSrcweir uno::Sequence< geometry::RealRectangle2D > SAL_CALL TextLayout::queryMeasures( ) throw (uno::RuntimeException) 86*cdf0e10cSrcweir { 87*cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex ); 88*cdf0e10cSrcweir 89*cdf0e10cSrcweir // TODO 90*cdf0e10cSrcweir return uno::Sequence< geometry::RealRectangle2D >(); 91*cdf0e10cSrcweir } 92*cdf0e10cSrcweir 93*cdf0e10cSrcweir uno::Sequence< double > SAL_CALL TextLayout::queryLogicalAdvancements( ) throw (uno::RuntimeException) 94*cdf0e10cSrcweir { 95*cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex ); 96*cdf0e10cSrcweir 97*cdf0e10cSrcweir return maLogicalAdvancements; 98*cdf0e10cSrcweir } 99*cdf0e10cSrcweir 100*cdf0e10cSrcweir void SAL_CALL TextLayout::applyLogicalAdvancements( const uno::Sequence< double >& aAdvancements ) throw (lang::IllegalArgumentException, uno::RuntimeException) 101*cdf0e10cSrcweir { 102*cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex ); 103*cdf0e10cSrcweir 104*cdf0e10cSrcweir if( aAdvancements.getLength() != maText.Length ) 105*cdf0e10cSrcweir { 106*cdf0e10cSrcweir OSL_TRACE( "TextLayout::applyLogicalAdvancements(): mismatching number of advancements" ); 107*cdf0e10cSrcweir throw lang::IllegalArgumentException(); 108*cdf0e10cSrcweir } 109*cdf0e10cSrcweir 110*cdf0e10cSrcweir maLogicalAdvancements = aAdvancements; 111*cdf0e10cSrcweir } 112*cdf0e10cSrcweir 113*cdf0e10cSrcweir geometry::RealRectangle2D SAL_CALL TextLayout::queryTextBounds( ) throw (uno::RuntimeException) 114*cdf0e10cSrcweir { 115*cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex ); 116*cdf0e10cSrcweir 117*cdf0e10cSrcweir uno::Reference< rendering::XGraphicDevice > xGraphicDevice; 118*cdf0e10cSrcweir ::dxcanvas::TextLayoutDrawHelper aDrawHelper(xGraphicDevice); 119*cdf0e10cSrcweir 120*cdf0e10cSrcweir // render text 121*cdf0e10cSrcweir const geometry::RealRectangle2D aBounds( 122*cdf0e10cSrcweir aDrawHelper.queryTextBounds( 123*cdf0e10cSrcweir maText, 124*cdf0e10cSrcweir maLogicalAdvancements, 125*cdf0e10cSrcweir mpFont.getRef(), 126*cdf0e10cSrcweir mpFont->getFontMatrix())); 127*cdf0e10cSrcweir 128*cdf0e10cSrcweir return aBounds; 129*cdf0e10cSrcweir } 130*cdf0e10cSrcweir 131*cdf0e10cSrcweir double SAL_CALL TextLayout::justify( double /*nSize*/ ) throw (lang::IllegalArgumentException, uno::RuntimeException) 132*cdf0e10cSrcweir { 133*cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex ); 134*cdf0e10cSrcweir 135*cdf0e10cSrcweir // TODO 136*cdf0e10cSrcweir return 0.0; 137*cdf0e10cSrcweir } 138*cdf0e10cSrcweir 139*cdf0e10cSrcweir double SAL_CALL TextLayout::combinedJustify( const uno::Sequence< uno::Reference< rendering::XTextLayout > >& /*aNextLayouts*/, 140*cdf0e10cSrcweir double /*nSize*/ ) throw (lang::IllegalArgumentException, uno::RuntimeException) 141*cdf0e10cSrcweir { 142*cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex ); 143*cdf0e10cSrcweir 144*cdf0e10cSrcweir // TODO 145*cdf0e10cSrcweir return 0.0; 146*cdf0e10cSrcweir } 147*cdf0e10cSrcweir 148*cdf0e10cSrcweir rendering::TextHit SAL_CALL TextLayout::getTextHit( const geometry::RealPoint2D& /*aHitPoint*/ ) throw (uno::RuntimeException) 149*cdf0e10cSrcweir { 150*cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex ); 151*cdf0e10cSrcweir 152*cdf0e10cSrcweir // TODO 153*cdf0e10cSrcweir return rendering::TextHit(); 154*cdf0e10cSrcweir } 155*cdf0e10cSrcweir 156*cdf0e10cSrcweir rendering::Caret SAL_CALL TextLayout::getCaret( sal_Int32 /*nInsertionIndex*/, 157*cdf0e10cSrcweir sal_Bool /*bExcludeLigatures*/ ) throw (lang::IndexOutOfBoundsException, uno::RuntimeException) 158*cdf0e10cSrcweir { 159*cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex ); 160*cdf0e10cSrcweir 161*cdf0e10cSrcweir // TODO 162*cdf0e10cSrcweir return rendering::Caret(); 163*cdf0e10cSrcweir } 164*cdf0e10cSrcweir 165*cdf0e10cSrcweir sal_Int32 SAL_CALL TextLayout::getNextInsertionIndex( sal_Int32 /*nStartIndex*/, 166*cdf0e10cSrcweir sal_Int32 /*nCaretAdvancement*/, 167*cdf0e10cSrcweir sal_Bool /*bExcludeLigatures*/ ) throw (lang::IndexOutOfBoundsException, uno::RuntimeException) 168*cdf0e10cSrcweir { 169*cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex ); 170*cdf0e10cSrcweir 171*cdf0e10cSrcweir // TODO 172*cdf0e10cSrcweir return 0; 173*cdf0e10cSrcweir } 174*cdf0e10cSrcweir 175*cdf0e10cSrcweir uno::Reference< rendering::XPolyPolygon2D > SAL_CALL TextLayout::queryVisualHighlighting( sal_Int32 /*nStartIndex*/, 176*cdf0e10cSrcweir sal_Int32 /*nEndIndex*/ ) throw (lang::IndexOutOfBoundsException, uno::RuntimeException) 177*cdf0e10cSrcweir { 178*cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex ); 179*cdf0e10cSrcweir 180*cdf0e10cSrcweir // TODO 181*cdf0e10cSrcweir return uno::Reference< rendering::XPolyPolygon2D >(); 182*cdf0e10cSrcweir } 183*cdf0e10cSrcweir 184*cdf0e10cSrcweir uno::Reference< rendering::XPolyPolygon2D > SAL_CALL TextLayout::queryLogicalHighlighting( sal_Int32 /*nStartIndex*/, 185*cdf0e10cSrcweir sal_Int32 /*nEndIndex*/ ) throw (lang::IndexOutOfBoundsException, uno::RuntimeException) 186*cdf0e10cSrcweir { 187*cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex ); 188*cdf0e10cSrcweir 189*cdf0e10cSrcweir // TODO 190*cdf0e10cSrcweir return uno::Reference< rendering::XPolyPolygon2D >(); 191*cdf0e10cSrcweir } 192*cdf0e10cSrcweir 193*cdf0e10cSrcweir double SAL_CALL TextLayout::getBaselineOffset( ) throw (uno::RuntimeException) 194*cdf0e10cSrcweir { 195*cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex ); 196*cdf0e10cSrcweir 197*cdf0e10cSrcweir // TODO 198*cdf0e10cSrcweir return 0.0; 199*cdf0e10cSrcweir } 200*cdf0e10cSrcweir 201*cdf0e10cSrcweir sal_Int8 SAL_CALL TextLayout::getMainTextDirection( ) throw (uno::RuntimeException) 202*cdf0e10cSrcweir { 203*cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex ); 204*cdf0e10cSrcweir 205*cdf0e10cSrcweir return mnTextDirection; 206*cdf0e10cSrcweir } 207*cdf0e10cSrcweir 208*cdf0e10cSrcweir uno::Reference< rendering::XCanvasFont > SAL_CALL TextLayout::getFont( ) throw (uno::RuntimeException) 209*cdf0e10cSrcweir { 210*cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex ); 211*cdf0e10cSrcweir 212*cdf0e10cSrcweir return mpFont.getRef(); 213*cdf0e10cSrcweir } 214*cdf0e10cSrcweir 215*cdf0e10cSrcweir rendering::StringContext SAL_CALL TextLayout::getText( ) throw (uno::RuntimeException) 216*cdf0e10cSrcweir { 217*cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex ); 218*cdf0e10cSrcweir 219*cdf0e10cSrcweir return maText; 220*cdf0e10cSrcweir } 221*cdf0e10cSrcweir 222*cdf0e10cSrcweir namespace 223*cdf0e10cSrcweir { 224*cdf0e10cSrcweir // TODO(P2): Check whether this gets inlined. If not, make functor 225*cdf0e10cSrcweir // out of it 226*cdf0e10cSrcweir inline Gdiplus::PointF gdiPlusPointFromDx( const double& dx ) 227*cdf0e10cSrcweir { 228*cdf0e10cSrcweir return Gdiplus::PointF( static_cast<Gdiplus::REAL>(dx), 229*cdf0e10cSrcweir 0.0f ); 230*cdf0e10cSrcweir } 231*cdf0e10cSrcweir } 232*cdf0e10cSrcweir 233*cdf0e10cSrcweir bool TextLayout::draw( const GraphicsSharedPtr& rGraphics, 234*cdf0e10cSrcweir const rendering::ViewState& rViewState, 235*cdf0e10cSrcweir const rendering::RenderState& rRenderState, 236*cdf0e10cSrcweir const ::basegfx::B2ISize& rOutputOffset, 237*cdf0e10cSrcweir const uno::Reference< rendering::XGraphicDevice >& xGraphicDevice, 238*cdf0e10cSrcweir bool bAlphaSurface ) const 239*cdf0e10cSrcweir { 240*cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex ); 241*cdf0e10cSrcweir 242*cdf0e10cSrcweir ::dxcanvas::TextLayoutDrawHelper aDrawHelper(xGraphicDevice); 243*cdf0e10cSrcweir 244*cdf0e10cSrcweir // render text 245*cdf0e10cSrcweir aDrawHelper.drawText( 246*cdf0e10cSrcweir rGraphics, 247*cdf0e10cSrcweir rViewState, 248*cdf0e10cSrcweir rRenderState, 249*cdf0e10cSrcweir rOutputOffset, 250*cdf0e10cSrcweir maText, 251*cdf0e10cSrcweir maLogicalAdvancements, 252*cdf0e10cSrcweir mpFont.getRef(), 253*cdf0e10cSrcweir mpFont->getFontMatrix(), 254*cdf0e10cSrcweir bAlphaSurface); 255*cdf0e10cSrcweir 256*cdf0e10cSrcweir return true; 257*cdf0e10cSrcweir } 258*cdf0e10cSrcweir 259*cdf0e10cSrcweir 260*cdf0e10cSrcweir #define SERVICE_NAME "com.sun.star.rendering.TextLayout" 261*cdf0e10cSrcweir #define IMPLEMENTATION_NAME "DXCanvas::TextLayout" 262*cdf0e10cSrcweir 263*cdf0e10cSrcweir ::rtl::OUString SAL_CALL TextLayout::getImplementationName() throw( uno::RuntimeException ) 264*cdf0e10cSrcweir { 265*cdf0e10cSrcweir return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( IMPLEMENTATION_NAME ) ); 266*cdf0e10cSrcweir } 267*cdf0e10cSrcweir 268*cdf0e10cSrcweir sal_Bool SAL_CALL TextLayout::supportsService( const ::rtl::OUString& ServiceName ) throw( uno::RuntimeException ) 269*cdf0e10cSrcweir { 270*cdf0e10cSrcweir return ServiceName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( SERVICE_NAME ) ); 271*cdf0e10cSrcweir } 272*cdf0e10cSrcweir 273*cdf0e10cSrcweir uno::Sequence< ::rtl::OUString > SAL_CALL TextLayout::getSupportedServiceNames() throw( uno::RuntimeException ) 274*cdf0e10cSrcweir { 275*cdf0e10cSrcweir uno::Sequence< ::rtl::OUString > aRet(1); 276*cdf0e10cSrcweir aRet[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM ( SERVICE_NAME ) ); 277*cdf0e10cSrcweir 278*cdf0e10cSrcweir return aRet; 279*cdf0e10cSrcweir } 280*cdf0e10cSrcweir } 281