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