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