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 <canvas/debug.hxx> 32 #include <tools/diagnose_ex.h> 33 #include <canvas/verbosetrace.hxx> 34 35 #include <basegfx/matrix/b2dhommatrix.hxx> 36 #include <basegfx/numeric/ftools.hxx> 37 38 #include "null_textlayout.hxx" 39 #include "null_spritecanvas.hxx" 40 41 42 using namespace ::com::sun::star; 43 44 namespace nullcanvas 45 { 46 TextLayout::TextLayout( const rendering::StringContext& aText, 47 sal_Int8 nDirection, 48 sal_Int64 /*nRandomSeed*/, 49 const CanvasFont::ImplRef& rFont ) : 50 TextLayout_Base( m_aMutex ), 51 maText( aText ), 52 maLogicalAdvancements(), 53 mpFont( rFont ), 54 mnTextDirection( nDirection ) 55 { 56 } 57 58 TextLayout::~TextLayout() 59 { 60 } 61 62 void SAL_CALL TextLayout::disposing() 63 { 64 mpFont.reset(); 65 } 66 67 // XTextLayout 68 uno::Sequence< uno::Reference< rendering::XPolyPolygon2D > > SAL_CALL TextLayout::queryTextShapes( ) throw (uno::RuntimeException) 69 { 70 ::osl::MutexGuard aGuard( m_aMutex ); 71 72 // TODO 73 return uno::Sequence< uno::Reference< rendering::XPolyPolygon2D > >(); 74 } 75 76 uno::Sequence< geometry::RealRectangle2D > SAL_CALL TextLayout::queryInkMeasures( ) throw (uno::RuntimeException) 77 { 78 ::osl::MutexGuard aGuard( m_aMutex ); 79 80 // TODO 81 return uno::Sequence< geometry::RealRectangle2D >(); 82 } 83 84 uno::Sequence< geometry::RealRectangle2D > SAL_CALL TextLayout::queryMeasures( ) throw (uno::RuntimeException) 85 { 86 ::osl::MutexGuard aGuard( m_aMutex ); 87 88 // TODO 89 return uno::Sequence< geometry::RealRectangle2D >(); 90 } 91 92 uno::Sequence< double > SAL_CALL TextLayout::queryLogicalAdvancements( ) throw (uno::RuntimeException) 93 { 94 ::osl::MutexGuard aGuard( m_aMutex ); 95 96 return maLogicalAdvancements; 97 } 98 99 void SAL_CALL TextLayout::applyLogicalAdvancements( const uno::Sequence< double >& aAdvancements ) throw (lang::IllegalArgumentException, uno::RuntimeException) 100 { 101 ::osl::MutexGuard aGuard( m_aMutex ); 102 103 if( aAdvancements.getLength() != maText.Length ) 104 { 105 OSL_TRACE( "TextLayout::applyLogicalAdvancements(): mismatching number of advancements" ); 106 throw lang::IllegalArgumentException(); 107 } 108 109 maLogicalAdvancements = aAdvancements; 110 } 111 112 geometry::RealRectangle2D SAL_CALL TextLayout::queryTextBounds( ) throw (uno::RuntimeException) 113 { 114 ::osl::MutexGuard aGuard( m_aMutex ); 115 116 ENSURE_OR_THROW( mpFont.get(), 117 "TextLayout::queryTextBounds(): invalid font" ); 118 119 // fake text bounds by either taking the advancement values, 120 // or assuming square glyph boxes (width similar to height) 121 const rendering::FontRequest& rFontRequest( mpFont->getFontRequest() ); 122 const double nFontSize( ::std::max( rFontRequest.CellSize, 123 rFontRequest.ReferenceAdvancement ) ); 124 if( maLogicalAdvancements.getLength() ) 125 { 126 return geometry::RealRectangle2D( 0, -nFontSize/2, 127 maLogicalAdvancements[ maLogicalAdvancements.getLength()-1 ], 128 nFontSize/2 ); 129 } 130 else 131 { 132 return geometry::RealRectangle2D( 0, -nFontSize/2, 133 nFontSize * maText.Length, 134 nFontSize/2 ); 135 } 136 } 137 138 double SAL_CALL TextLayout::justify( double /*nSize*/ ) throw (lang::IllegalArgumentException, uno::RuntimeException) 139 { 140 ::osl::MutexGuard aGuard( m_aMutex ); 141 142 // TODO 143 return 0.0; 144 } 145 146 double SAL_CALL TextLayout::combinedJustify( const uno::Sequence< uno::Reference< rendering::XTextLayout > >& /*aNextLayouts*/, 147 double /*nSize*/ ) throw (lang::IllegalArgumentException, uno::RuntimeException) 148 { 149 ::osl::MutexGuard aGuard( m_aMutex ); 150 151 // TODO 152 return 0.0; 153 } 154 155 rendering::TextHit SAL_CALL TextLayout::getTextHit( const geometry::RealPoint2D& /*aHitPoint*/ ) throw (uno::RuntimeException) 156 { 157 ::osl::MutexGuard aGuard( m_aMutex ); 158 159 // TODO 160 return rendering::TextHit(); 161 } 162 163 rendering::Caret SAL_CALL TextLayout::getCaret( sal_Int32 /*nInsertionIndex*/, 164 sal_Bool /*bExcludeLigatures*/ ) throw (lang::IndexOutOfBoundsException, uno::RuntimeException) 165 { 166 ::osl::MutexGuard aGuard( m_aMutex ); 167 168 // TODO 169 return rendering::Caret(); 170 } 171 172 sal_Int32 SAL_CALL TextLayout::getNextInsertionIndex( sal_Int32 /*nStartIndex*/, 173 sal_Int32 /*nCaretAdvancement*/, 174 sal_Bool /*bExcludeLigatures*/ ) throw (lang::IndexOutOfBoundsException, uno::RuntimeException) 175 { 176 ::osl::MutexGuard aGuard( m_aMutex ); 177 178 // TODO 179 return 0; 180 } 181 182 uno::Reference< rendering::XPolyPolygon2D > SAL_CALL TextLayout::queryVisualHighlighting( sal_Int32 /*nStartIndex*/, 183 sal_Int32 /*nEndIndex*/ ) throw (lang::IndexOutOfBoundsException, uno::RuntimeException) 184 { 185 ::osl::MutexGuard aGuard( m_aMutex ); 186 187 // TODO 188 return uno::Reference< rendering::XPolyPolygon2D >(); 189 } 190 191 uno::Reference< rendering::XPolyPolygon2D > SAL_CALL TextLayout::queryLogicalHighlighting( sal_Int32 /*nStartIndex*/, 192 sal_Int32 /*nEndIndex*/ ) throw (lang::IndexOutOfBoundsException, uno::RuntimeException) 193 { 194 ::osl::MutexGuard aGuard( m_aMutex ); 195 196 // TODO 197 return uno::Reference< rendering::XPolyPolygon2D >(); 198 } 199 200 double SAL_CALL TextLayout::getBaselineOffset( ) throw (uno::RuntimeException) 201 { 202 ::osl::MutexGuard aGuard( m_aMutex ); 203 204 // TODO 205 return 0.0; 206 } 207 208 sal_Int8 SAL_CALL TextLayout::getMainTextDirection( ) throw (uno::RuntimeException) 209 { 210 ::osl::MutexGuard aGuard( m_aMutex ); 211 212 return mnTextDirection; 213 } 214 215 uno::Reference< rendering::XCanvasFont > SAL_CALL TextLayout::getFont( ) throw (uno::RuntimeException) 216 { 217 ::osl::MutexGuard aGuard( m_aMutex ); 218 219 return mpFont.getRef(); 220 } 221 222 rendering::StringContext SAL_CALL TextLayout::getText( ) throw (uno::RuntimeException) 223 { 224 ::osl::MutexGuard aGuard( m_aMutex ); 225 226 return maText; 227 } 228 229 bool TextLayout::draw( const rendering::ViewState& /*rViewState*/, 230 const rendering::RenderState& /*rRenderState*/, 231 const uno::Reference< rendering::XGraphicDevice >& /*xGraphicDevice*/ ) const 232 { 233 ::osl::MutexGuard aGuard( m_aMutex ); 234 235 // TODO 236 237 return true; 238 } 239 240 241 #define SERVICE_NAME "com.sun.star.rendering.TextLayout" 242 #define IMPLEMENTATION_NAME "NullCanvas::TextLayout" 243 244 ::rtl::OUString SAL_CALL TextLayout::getImplementationName() throw( uno::RuntimeException ) 245 { 246 return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( IMPLEMENTATION_NAME ) ); 247 } 248 249 sal_Bool SAL_CALL TextLayout::supportsService( const ::rtl::OUString& ServiceName ) throw( uno::RuntimeException ) 250 { 251 return ServiceName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( SERVICE_NAME ) ); 252 } 253 254 uno::Sequence< ::rtl::OUString > SAL_CALL TextLayout::getSupportedServiceNames() throw( uno::RuntimeException ) 255 { 256 uno::Sequence< ::rtl::OUString > aRet(1); 257 aRet[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM ( SERVICE_NAME ) ); 258 259 return aRet; 260 } 261 } 262