1*25b11142SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*25b11142SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*25b11142SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*25b11142SAndrew Rist * distributed with this work for additional information 6*25b11142SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*25b11142SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*25b11142SAndrew Rist * "License"); you may not use this file except in compliance 9*25b11142SAndrew Rist * with the License. You may obtain a copy of the License at 10*25b11142SAndrew Rist * 11*25b11142SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12*25b11142SAndrew Rist * 13*25b11142SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*25b11142SAndrew Rist * software distributed under the License is distributed on an 15*25b11142SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*25b11142SAndrew Rist * KIND, either express or implied. See the License for the 17*25b11142SAndrew Rist * specific language governing permissions and limitations 18*25b11142SAndrew Rist * under the License. 19*25b11142SAndrew Rist * 20*25b11142SAndrew Rist *************************************************************/ 21*25b11142SAndrew Rist 22*25b11142SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_cppcanvas.hxx" 26cdf0e10cSrcweir 27cdf0e10cSrcweir #include <canvas/debug.hxx> 28cdf0e10cSrcweir #include <tools/diagnose_ex.h> 29cdf0e10cSrcweir #include <canvas/verbosetrace.hxx> 30cdf0e10cSrcweir 31cdf0e10cSrcweir #include <rtl/logfile.hxx> 32cdf0e10cSrcweir 33cdf0e10cSrcweir #include <com/sun/star/rendering/PathCapType.hpp> 34cdf0e10cSrcweir #include <com/sun/star/rendering/PathJoinType.hpp> 35cdf0e10cSrcweir #include <com/sun/star/rendering/XCanvas.hpp> 36cdf0e10cSrcweir #include <com/sun/star/rendering/XCanvasFont.hpp> 37cdf0e10cSrcweir 38cdf0e10cSrcweir #include <basegfx/numeric/ftools.hxx> 39cdf0e10cSrcweir #include <basegfx/matrix/b2dhommatrix.hxx> 40cdf0e10cSrcweir #include <basegfx/range/b2drectangle.hxx> 41cdf0e10cSrcweir #include <basegfx/vector/b2dsize.hxx> 42cdf0e10cSrcweir #include <basegfx/polygon/b2dpolypolygontools.hxx> 43cdf0e10cSrcweir #include <basegfx/polygon/b2dpolygontools.hxx> 44cdf0e10cSrcweir #include <basegfx/matrix/b2dhommatrixtools.hxx> 45cdf0e10cSrcweir 46cdf0e10cSrcweir #include <tools/gen.hxx> 47cdf0e10cSrcweir #include <vcl/canvastools.hxx> 48cdf0e10cSrcweir #include <vcl/virdev.hxx> 49cdf0e10cSrcweir 50cdf0e10cSrcweir #include <basegfx/tools/canvastools.hxx> 51cdf0e10cSrcweir #include <canvas/canvastools.hxx> 52cdf0e10cSrcweir 53cdf0e10cSrcweir #include <boost/scoped_array.hpp> 54cdf0e10cSrcweir #include <boost/bind.hpp> 55cdf0e10cSrcweir #include <boost/utility.hpp> 56cdf0e10cSrcweir 57cdf0e10cSrcweir #include "textaction.hxx" 58cdf0e10cSrcweir #include "outdevstate.hxx" 59cdf0e10cSrcweir #include "mtftools.hxx" 60cdf0e10cSrcweir 61cdf0e10cSrcweir 62cdf0e10cSrcweir using namespace ::com::sun::star; 63cdf0e10cSrcweir 64cdf0e10cSrcweir namespace cppcanvas 65cdf0e10cSrcweir { 66cdf0e10cSrcweir namespace internal 67cdf0e10cSrcweir { 68cdf0e10cSrcweir namespace 69cdf0e10cSrcweir { init(rendering::RenderState & o_rRenderState,const::basegfx::B2DPoint & rStartPoint,const OutDevState & rState,const CanvasSharedPtr & rCanvas)70cdf0e10cSrcweir void init( rendering::RenderState& o_rRenderState, 71cdf0e10cSrcweir const ::basegfx::B2DPoint& rStartPoint, 72cdf0e10cSrcweir const OutDevState& rState, 73cdf0e10cSrcweir const CanvasSharedPtr& rCanvas ) 74cdf0e10cSrcweir { 75cdf0e10cSrcweir tools::initRenderState(o_rRenderState,rState); 76cdf0e10cSrcweir 77cdf0e10cSrcweir // #i36950# Offset clip back to origin (as it's also moved 78cdf0e10cSrcweir // by rStartPoint) 79cdf0e10cSrcweir // #i53964# Also take VCL font rotation into account, 80cdf0e10cSrcweir // since this, opposed to the FontMatrix rotation 81cdf0e10cSrcweir // elsewhere, _does_ get incorporated into the render 82cdf0e10cSrcweir // state transform. 83cdf0e10cSrcweir tools::modifyClip( o_rRenderState, 84cdf0e10cSrcweir rState, 85cdf0e10cSrcweir rCanvas, 86cdf0e10cSrcweir rStartPoint, 87cdf0e10cSrcweir NULL, 88cdf0e10cSrcweir &rState.fontRotation ); 89cdf0e10cSrcweir 90cdf0e10cSrcweir basegfx::B2DHomMatrix aLocalTransformation(basegfx::tools::createRotateB2DHomMatrix(rState.fontRotation)); 91cdf0e10cSrcweir aLocalTransformation.translate( rStartPoint.getX(), 92cdf0e10cSrcweir rStartPoint.getY() ); 93cdf0e10cSrcweir ::canvas::tools::appendToRenderState( o_rRenderState, 94cdf0e10cSrcweir aLocalTransformation ); 95cdf0e10cSrcweir 96cdf0e10cSrcweir o_rRenderState.DeviceColor = rState.textColor; 97cdf0e10cSrcweir } 98cdf0e10cSrcweir init(rendering::RenderState & o_rRenderState,const::basegfx::B2DPoint & rStartPoint,const OutDevState & rState,const CanvasSharedPtr & rCanvas,const::basegfx::B2DHomMatrix & rTextTransform)99cdf0e10cSrcweir void init( rendering::RenderState& o_rRenderState, 100cdf0e10cSrcweir const ::basegfx::B2DPoint& rStartPoint, 101cdf0e10cSrcweir const OutDevState& rState, 102cdf0e10cSrcweir const CanvasSharedPtr& rCanvas, 103cdf0e10cSrcweir const ::basegfx::B2DHomMatrix& rTextTransform ) 104cdf0e10cSrcweir { 105cdf0e10cSrcweir init( o_rRenderState, rStartPoint, rState, rCanvas ); 106cdf0e10cSrcweir 107cdf0e10cSrcweir // TODO(F2): Also inversely-transform clip with 108cdf0e10cSrcweir // rTextTransform (which is actually rather hard, as the 109cdf0e10cSrcweir // text transform is _prepended_ to the render state)! 110cdf0e10cSrcweir 111cdf0e10cSrcweir // prepend extra font transform to render state 112cdf0e10cSrcweir // (prepend it, because it's interpreted in the unit 113cdf0e10cSrcweir // rect coordinate space) 114cdf0e10cSrcweir ::canvas::tools::prependToRenderState( o_rRenderState, 115cdf0e10cSrcweir rTextTransform ); 116cdf0e10cSrcweir } 117cdf0e10cSrcweir init(rendering::RenderState & o_rRenderState,uno::Reference<rendering::XCanvasFont> & o_rFont,const::basegfx::B2DPoint & rStartPoint,const OutDevState & rState,const CanvasSharedPtr & rCanvas)118cdf0e10cSrcweir void init( rendering::RenderState& o_rRenderState, 119cdf0e10cSrcweir uno::Reference< rendering::XCanvasFont >& o_rFont, 120cdf0e10cSrcweir const ::basegfx::B2DPoint& rStartPoint, 121cdf0e10cSrcweir const OutDevState& rState, 122cdf0e10cSrcweir const CanvasSharedPtr& rCanvas ) 123cdf0e10cSrcweir { 124cdf0e10cSrcweir // ensure that o_rFont is valid. It is possible that 125cdf0e10cSrcweir // text actions are generated without previously 126cdf0e10cSrcweir // setting a font. Then, just take a default font 127cdf0e10cSrcweir if( !o_rFont.is() ) 128cdf0e10cSrcweir { 129cdf0e10cSrcweir // Use completely default FontRequest 130cdf0e10cSrcweir const rendering::FontRequest aFontRequest; 131cdf0e10cSrcweir 132cdf0e10cSrcweir geometry::Matrix2D aFontMatrix; 133cdf0e10cSrcweir ::canvas::tools::setIdentityMatrix2D( aFontMatrix ); 134cdf0e10cSrcweir 135cdf0e10cSrcweir o_rFont = rCanvas->getUNOCanvas()->createFont( 136cdf0e10cSrcweir aFontRequest, 137cdf0e10cSrcweir uno::Sequence< beans::PropertyValue >(), 138cdf0e10cSrcweir aFontMatrix ); 139cdf0e10cSrcweir } 140cdf0e10cSrcweir 141cdf0e10cSrcweir init( o_rRenderState, 142cdf0e10cSrcweir rStartPoint, 143cdf0e10cSrcweir rState, 144cdf0e10cSrcweir rCanvas ); 145cdf0e10cSrcweir } 146cdf0e10cSrcweir init(rendering::RenderState & o_rRenderState,uno::Reference<rendering::XCanvasFont> & o_rFont,const::basegfx::B2DPoint & rStartPoint,const OutDevState & rState,const CanvasSharedPtr & rCanvas,const::basegfx::B2DHomMatrix & rTextTransform)147cdf0e10cSrcweir void init( rendering::RenderState& o_rRenderState, 148cdf0e10cSrcweir uno::Reference< rendering::XCanvasFont >& o_rFont, 149cdf0e10cSrcweir const ::basegfx::B2DPoint& rStartPoint, 150cdf0e10cSrcweir const OutDevState& rState, 151cdf0e10cSrcweir const CanvasSharedPtr& rCanvas, 152cdf0e10cSrcweir const ::basegfx::B2DHomMatrix& rTextTransform ) 153cdf0e10cSrcweir { 154cdf0e10cSrcweir init( o_rRenderState, o_rFont, rStartPoint, rState, rCanvas ); 155cdf0e10cSrcweir 156cdf0e10cSrcweir // TODO(F2): Also inversely-transform clip with 157cdf0e10cSrcweir // rTextTransform (which is actually rather hard, as the 158cdf0e10cSrcweir // text transform is _prepended_ to the render state)! 159cdf0e10cSrcweir 160cdf0e10cSrcweir // prepend extra font transform to render state 161cdf0e10cSrcweir // (prepend it, because it's interpreted in the unit 162cdf0e10cSrcweir // rect coordinate space) 163cdf0e10cSrcweir ::canvas::tools::prependToRenderState( o_rRenderState, 164cdf0e10cSrcweir rTextTransform ); 165cdf0e10cSrcweir } 166cdf0e10cSrcweir textLinesFromLogicalOffsets(const uno::Sequence<double> & rOffsets,const tools::TextLineInfo & rTextLineInfo)167cdf0e10cSrcweir ::basegfx::B2DPolyPolygon textLinesFromLogicalOffsets( const uno::Sequence< double >& rOffsets, 168cdf0e10cSrcweir const tools::TextLineInfo& rTextLineInfo ) 169cdf0e10cSrcweir { 170cdf0e10cSrcweir return tools::createTextLinesPolyPolygon( 171cdf0e10cSrcweir 0.0, 172cdf0e10cSrcweir // extract character cell furthest to the right 173cdf0e10cSrcweir *(::std::max_element( 174cdf0e10cSrcweir rOffsets.getConstArray(), 175cdf0e10cSrcweir rOffsets.getConstArray() + rOffsets.getLength() )), 176cdf0e10cSrcweir rTextLineInfo ); 177cdf0e10cSrcweir } 178cdf0e10cSrcweir setupDXArray(const sal_Int32 * pCharWidths,sal_Int32 nLen,const OutDevState & rState)179cdf0e10cSrcweir uno::Sequence< double > setupDXArray( const sal_Int32* pCharWidths, 180cdf0e10cSrcweir sal_Int32 nLen, 181cdf0e10cSrcweir const OutDevState& rState ) 182cdf0e10cSrcweir { 183cdf0e10cSrcweir // convert character widths from logical units 184cdf0e10cSrcweir uno::Sequence< double > aCharWidthSeq( nLen ); 185cdf0e10cSrcweir double* pOutputWidths( aCharWidthSeq.getArray() ); 186cdf0e10cSrcweir 187cdf0e10cSrcweir // #143885# maintain (nearly) full precision of DX 188cdf0e10cSrcweir // array, by circumventing integer-based 189cdf0e10cSrcweir // OutDev-mapping 190cdf0e10cSrcweir const double nScale( rState.mapModeTransform.get(0,0) ); 191cdf0e10cSrcweir for( int i = 0; i < nLen; ++i ) 192cdf0e10cSrcweir { 193cdf0e10cSrcweir // TODO(F2): use correct scale direction 194cdf0e10cSrcweir *pOutputWidths++ = *pCharWidths++ * nScale; 195cdf0e10cSrcweir } 196cdf0e10cSrcweir 197cdf0e10cSrcweir return aCharWidthSeq; 198cdf0e10cSrcweir } 199cdf0e10cSrcweir setupDXArray(const::String & rText,sal_Int32 nStartPos,sal_Int32 nLen,VirtualDevice & rVDev,const OutDevState & rState)200cdf0e10cSrcweir uno::Sequence< double > setupDXArray( const ::String& rText, 201cdf0e10cSrcweir sal_Int32 nStartPos, 202cdf0e10cSrcweir sal_Int32 nLen, 203cdf0e10cSrcweir VirtualDevice& rVDev, 204cdf0e10cSrcweir const OutDevState& rState ) 205cdf0e10cSrcweir { 206cdf0e10cSrcweir // no external DX array given, create one from given 207cdf0e10cSrcweir // string 208cdf0e10cSrcweir ::boost::scoped_array< sal_Int32 > pCharWidths( new sal_Int32[nLen] ); 209cdf0e10cSrcweir 210cdf0e10cSrcweir rVDev.GetTextArray( rText, pCharWidths.get(), 211cdf0e10cSrcweir static_cast<sal_uInt16>(nStartPos), 212cdf0e10cSrcweir static_cast<sal_uInt16>(nLen) ); 213cdf0e10cSrcweir 214cdf0e10cSrcweir return setupDXArray( pCharWidths.get(), nLen, rState ); 215cdf0e10cSrcweir } 216cdf0e10cSrcweir adaptStartPoint(const::basegfx::B2DPoint & rStartPoint,const OutDevState & rState,const uno::Sequence<double> & rOffsets)217cdf0e10cSrcweir ::basegfx::B2DPoint adaptStartPoint( const ::basegfx::B2DPoint& rStartPoint, 218cdf0e10cSrcweir const OutDevState& rState, 219cdf0e10cSrcweir const uno::Sequence< double >& rOffsets ) 220cdf0e10cSrcweir { 221cdf0e10cSrcweir ::basegfx::B2DPoint aLocalPoint( rStartPoint ); 222cdf0e10cSrcweir 223cdf0e10cSrcweir if( rState.textAlignment ) 224cdf0e10cSrcweir { 225cdf0e10cSrcweir // text origin is right, not left. Modify start point 226cdf0e10cSrcweir // accordingly, because XCanvas::drawTextLayout() 227cdf0e10cSrcweir // always aligns left! 228cdf0e10cSrcweir 229cdf0e10cSrcweir const double nOffset( rOffsets[ rOffsets.getLength()-1 ] ); 230cdf0e10cSrcweir 231cdf0e10cSrcweir // correct start point for rotated text: rotate around 232cdf0e10cSrcweir // former start point 233cdf0e10cSrcweir aLocalPoint.setX( aLocalPoint.getX() + cos( rState.fontRotation )*nOffset ); 234cdf0e10cSrcweir aLocalPoint.setY( aLocalPoint.getY() + sin( rState.fontRotation )*nOffset ); 235cdf0e10cSrcweir } 236cdf0e10cSrcweir 237cdf0e10cSrcweir return aLocalPoint; 238cdf0e10cSrcweir } 239cdf0e10cSrcweir 240cdf0e10cSrcweir /** Perform common setup for array text actions 241cdf0e10cSrcweir 242cdf0e10cSrcweir This method creates the XTextLayout object and 243cdf0e10cSrcweir initializes it, e.g. with the logical advancements. 244cdf0e10cSrcweir */ initArrayAction(rendering::RenderState & o_rRenderState,uno::Reference<rendering::XTextLayout> & o_rTextLayout,const::basegfx::B2DPoint & rStartPoint,const::rtl::OUString & rText,sal_Int32 nStartPos,sal_Int32 nLen,const uno::Sequence<double> & rOffsets,const CanvasSharedPtr & rCanvas,const OutDevState & rState,const::basegfx::B2DHomMatrix * pTextTransform)245cdf0e10cSrcweir void initArrayAction( rendering::RenderState& o_rRenderState, 246cdf0e10cSrcweir uno::Reference< rendering::XTextLayout >& o_rTextLayout, 247cdf0e10cSrcweir const ::basegfx::B2DPoint& rStartPoint, 248cdf0e10cSrcweir const ::rtl::OUString& rText, 249cdf0e10cSrcweir sal_Int32 nStartPos, 250cdf0e10cSrcweir sal_Int32 nLen, 251cdf0e10cSrcweir const uno::Sequence< double >& rOffsets, 252cdf0e10cSrcweir const CanvasSharedPtr& rCanvas, 253cdf0e10cSrcweir const OutDevState& rState, 254cdf0e10cSrcweir const ::basegfx::B2DHomMatrix* pTextTransform ) 255cdf0e10cSrcweir { 256cdf0e10cSrcweir ENSURE_OR_THROW( rOffsets.getLength(), 257cdf0e10cSrcweir "::cppcanvas::internal::initArrayAction(): zero-length DX array" ); 258cdf0e10cSrcweir 259cdf0e10cSrcweir const ::basegfx::B2DPoint aLocalStartPoint( 260cdf0e10cSrcweir adaptStartPoint( rStartPoint, rState, rOffsets ) ); 261cdf0e10cSrcweir 262cdf0e10cSrcweir uno::Reference< rendering::XCanvasFont > xFont( rState.xFont ); 263cdf0e10cSrcweir 264cdf0e10cSrcweir if( pTextTransform ) 265cdf0e10cSrcweir init( o_rRenderState, xFont, aLocalStartPoint, rState, rCanvas, *pTextTransform ); 266cdf0e10cSrcweir else 267cdf0e10cSrcweir init( o_rRenderState, xFont, aLocalStartPoint, rState, rCanvas ); 268cdf0e10cSrcweir 269cdf0e10cSrcweir o_rTextLayout = xFont->createTextLayout( 270cdf0e10cSrcweir rendering::StringContext( rText, nStartPos, nLen ), 271cdf0e10cSrcweir rState.textDirection, 272cdf0e10cSrcweir 0 ); 273cdf0e10cSrcweir 274cdf0e10cSrcweir ENSURE_OR_THROW( o_rTextLayout.is(), 275cdf0e10cSrcweir "::cppcanvas::internal::initArrayAction(): Invalid font" ); 276cdf0e10cSrcweir 277cdf0e10cSrcweir o_rTextLayout->applyLogicalAdvancements( rOffsets ); 278cdf0e10cSrcweir } 279cdf0e10cSrcweir getLineWidth(::VirtualDevice & rVDev,const OutDevState & rState,const rendering::StringContext & rStringContext)280cdf0e10cSrcweir double getLineWidth( ::VirtualDevice& rVDev, 281cdf0e10cSrcweir const OutDevState& rState, 282cdf0e10cSrcweir const rendering::StringContext& rStringContext ) 283cdf0e10cSrcweir { 284cdf0e10cSrcweir // TODO(F2): use correct scale direction 285cdf0e10cSrcweir const ::basegfx::B2DSize aSize( rVDev.GetTextWidth( rStringContext.Text, 286cdf0e10cSrcweir static_cast<sal_uInt16>(rStringContext.StartPosition), 287cdf0e10cSrcweir static_cast<sal_uInt16>(rStringContext.Length) ), 288cdf0e10cSrcweir 0 ); 289cdf0e10cSrcweir 290cdf0e10cSrcweir return (rState.mapModeTransform * aSize).getX(); 291cdf0e10cSrcweir } 292cdf0e10cSrcweir 293cdf0e10cSrcweir uno::Sequence< double > calcSubsetOffsets(rendering::RenderState & io_rRenderState,double & o_rMinPos,double & o_rMaxPos,const uno::Reference<rendering::XTextLayout> & rOrigTextLayout,const::cppcanvas::internal::Action::Subset & rSubset)294cdf0e10cSrcweir calcSubsetOffsets( rendering::RenderState& io_rRenderState, 295cdf0e10cSrcweir double& o_rMinPos, 296cdf0e10cSrcweir double& o_rMaxPos, 297cdf0e10cSrcweir const uno::Reference< rendering::XTextLayout >& rOrigTextLayout, 298cdf0e10cSrcweir const ::cppcanvas::internal::Action::Subset& rSubset ) 299cdf0e10cSrcweir { 300cdf0e10cSrcweir ENSURE_OR_THROW( rSubset.mnSubsetEnd > rSubset.mnSubsetBegin, 301cdf0e10cSrcweir "::cppcanvas::internal::calcSubsetOffsets(): invalid subset range range" ); 302cdf0e10cSrcweir 303cdf0e10cSrcweir uno::Sequence< double > aOrigOffsets( rOrigTextLayout->queryLogicalAdvancements() ); 304cdf0e10cSrcweir const double* pOffsets( aOrigOffsets.getConstArray() ); 305cdf0e10cSrcweir 306cdf0e10cSrcweir ENSURE_OR_THROW( aOrigOffsets.getLength() >= rSubset.mnSubsetEnd, 307cdf0e10cSrcweir "::cppcanvas::internal::calcSubsetOffsets(): invalid subset range range" ); 308cdf0e10cSrcweir 309cdf0e10cSrcweir // TODO(F3): It currently seems that for RTL text, the 310cdf0e10cSrcweir // DX offsets are nevertheless increasing in logical 311cdf0e10cSrcweir // text order (I'd expect they are decreasing, 312cdf0e10cSrcweir // mimicking the fact that the text is output 313cdf0e10cSrcweir // right-to-left). This breaks text effects for ALL 314cdf0e10cSrcweir // RTL languages. 315cdf0e10cSrcweir 316cdf0e10cSrcweir // determine leftmost position in given subset range - 317cdf0e10cSrcweir // as the DX array contains the output positions 318cdf0e10cSrcweir // starting with the second character (the first is 319cdf0e10cSrcweir // assumed to have output position 0), correct begin 320cdf0e10cSrcweir // iterator. 321cdf0e10cSrcweir const double nMinPos( rSubset.mnSubsetBegin <= 0 ? 0 : 322cdf0e10cSrcweir *(::std::min_element( pOffsets+rSubset.mnSubsetBegin-1, 323cdf0e10cSrcweir pOffsets+rSubset.mnSubsetEnd )) ); 324cdf0e10cSrcweir 325cdf0e10cSrcweir // determine rightmost position in given subset range 326cdf0e10cSrcweir // - as the DX array contains the output positions 327cdf0e10cSrcweir // starting with the second character (the first is 328cdf0e10cSrcweir // assumed to have output position 0), correct begin 329cdf0e10cSrcweir // iterator. 330cdf0e10cSrcweir const double nMaxPos( 331cdf0e10cSrcweir *(::std::max_element( pOffsets + (rSubset.mnSubsetBegin <= 0 ? 332cdf0e10cSrcweir 0 : rSubset.mnSubsetBegin-1), 333cdf0e10cSrcweir pOffsets + rSubset.mnSubsetEnd )) ); 334cdf0e10cSrcweir 335cdf0e10cSrcweir 336cdf0e10cSrcweir // adapt render state, to move text output to given offset 337cdf0e10cSrcweir // ------------------------------------------------------- 338cdf0e10cSrcweir 339cdf0e10cSrcweir // TODO(F1): Strictly speaking, we also have to adapt 340cdf0e10cSrcweir // the clip here, which normally should _not_ move 341cdf0e10cSrcweir // with the output offset. Neglected for now, as it 342cdf0e10cSrcweir // does not matter for drawing layer output 343cdf0e10cSrcweir 344cdf0e10cSrcweir if( rSubset.mnSubsetBegin > 0 ) 345cdf0e10cSrcweir { 346cdf0e10cSrcweir ::basegfx::B2DHomMatrix aTranslation; 347cdf0e10cSrcweir if( rOrigTextLayout->getFont()->getFontRequest().FontDescription.IsVertical ) 348cdf0e10cSrcweir { 349cdf0e10cSrcweir // vertical text -> offset in y direction 350cdf0e10cSrcweir aTranslation.translate( 0.0, nMinPos ); 351cdf0e10cSrcweir } 352cdf0e10cSrcweir else 353cdf0e10cSrcweir { 354cdf0e10cSrcweir // horizontal text -> offset in x direction 355cdf0e10cSrcweir aTranslation.translate( nMinPos, 0.0 ); 356cdf0e10cSrcweir } 357cdf0e10cSrcweir 358cdf0e10cSrcweir ::canvas::tools::appendToRenderState( io_rRenderState, 359cdf0e10cSrcweir aTranslation ); 360cdf0e10cSrcweir } 361cdf0e10cSrcweir 362cdf0e10cSrcweir 363cdf0e10cSrcweir // reduce DX array to given substring 364cdf0e10cSrcweir // ---------------------------------- 365cdf0e10cSrcweir 366cdf0e10cSrcweir const sal_Int32 nNewElements( rSubset.mnSubsetEnd - rSubset.mnSubsetBegin ); 367cdf0e10cSrcweir uno::Sequence< double > aAdaptedOffsets( nNewElements ); 368cdf0e10cSrcweir double* pAdaptedOffsets( aAdaptedOffsets.getArray() ); 369cdf0e10cSrcweir 370cdf0e10cSrcweir // move to new output position (subtract nMinPos, 371cdf0e10cSrcweir // which is the new '0' position), copy only the range 372cdf0e10cSrcweir // as given by rSubset. 373cdf0e10cSrcweir ::std::transform( pOffsets + rSubset.mnSubsetBegin, 374cdf0e10cSrcweir pOffsets + rSubset.mnSubsetEnd, 375cdf0e10cSrcweir pAdaptedOffsets, 376cdf0e10cSrcweir ::boost::bind( ::std::minus<double>(), 377cdf0e10cSrcweir _1, 378cdf0e10cSrcweir nMinPos ) ); 379cdf0e10cSrcweir 380cdf0e10cSrcweir o_rMinPos = nMinPos; 381cdf0e10cSrcweir o_rMaxPos = nMaxPos; 382cdf0e10cSrcweir 383cdf0e10cSrcweir return aAdaptedOffsets; 384cdf0e10cSrcweir } 385cdf0e10cSrcweir 386cdf0e10cSrcweir uno::Reference< rendering::XTextLayout > createSubsetLayout(const rendering::StringContext & rOrigContext,const::cppcanvas::internal::Action::Subset & rSubset,const uno::Reference<rendering::XTextLayout> & rOrigTextLayout)387cdf0e10cSrcweir createSubsetLayout( const rendering::StringContext& rOrigContext, 388cdf0e10cSrcweir const ::cppcanvas::internal::Action::Subset& rSubset, 389cdf0e10cSrcweir const uno::Reference< rendering::XTextLayout >& rOrigTextLayout ) 390cdf0e10cSrcweir { 391cdf0e10cSrcweir // create temporary new text layout with subset string 392cdf0e10cSrcweir // --------------------------------------------------- 393cdf0e10cSrcweir 394cdf0e10cSrcweir const sal_Int32 nNewStartPos( rOrigContext.StartPosition + ::std::min( 395cdf0e10cSrcweir rSubset.mnSubsetBegin, rOrigContext.Length-1 ) ); 396cdf0e10cSrcweir const sal_Int32 nNewLength( ::std::max( 397cdf0e10cSrcweir ::std::min( 398cdf0e10cSrcweir rSubset.mnSubsetEnd - rSubset.mnSubsetBegin, 399cdf0e10cSrcweir rOrigContext.Length ), 400cdf0e10cSrcweir sal_Int32( 0 ) ) ); 401cdf0e10cSrcweir 402cdf0e10cSrcweir const rendering::StringContext aContext( rOrigContext.Text, 403cdf0e10cSrcweir nNewStartPos, 404cdf0e10cSrcweir nNewLength ); 405cdf0e10cSrcweir 406cdf0e10cSrcweir uno::Reference< rendering::XTextLayout > xTextLayout( 407cdf0e10cSrcweir rOrigTextLayout->getFont()->createTextLayout( aContext, 408cdf0e10cSrcweir rOrigTextLayout->getMainTextDirection(), 409cdf0e10cSrcweir 0 ), 410cdf0e10cSrcweir uno::UNO_QUERY_THROW ); 411cdf0e10cSrcweir 412cdf0e10cSrcweir return xTextLayout; 413cdf0e10cSrcweir } 414cdf0e10cSrcweir 415cdf0e10cSrcweir /** Setup subset text layout 416cdf0e10cSrcweir 417cdf0e10cSrcweir @param io_rTextLayout 418cdf0e10cSrcweir Must contain original (full set) text layout on input, 419cdf0e10cSrcweir will contain subsetted text layout (or empty 420cdf0e10cSrcweir reference, for empty subsets) on output. 421cdf0e10cSrcweir 422cdf0e10cSrcweir @param io_rRenderState 423cdf0e10cSrcweir Must contain original render state on input, will 424cdf0e10cSrcweir contain shifted render state concatenated with 425cdf0e10cSrcweir rTransformation on output. 426cdf0e10cSrcweir 427cdf0e10cSrcweir @param rTransformation 428cdf0e10cSrcweir Additional transformation, to be prepended to render 429cdf0e10cSrcweir state 430cdf0e10cSrcweir 431cdf0e10cSrcweir @param rSubset 432cdf0e10cSrcweir Subset to prepare 433cdf0e10cSrcweir */ createSubsetLayout(uno::Reference<rendering::XTextLayout> & io_rTextLayout,rendering::RenderState & io_rRenderState,double & o_rMinPos,double & o_rMaxPos,const::basegfx::B2DHomMatrix & rTransformation,const Action::Subset & rSubset)434cdf0e10cSrcweir void createSubsetLayout( uno::Reference< rendering::XTextLayout >& io_rTextLayout, 435cdf0e10cSrcweir rendering::RenderState& io_rRenderState, 436cdf0e10cSrcweir double& o_rMinPos, 437cdf0e10cSrcweir double& o_rMaxPos, 438cdf0e10cSrcweir const ::basegfx::B2DHomMatrix& rTransformation, 439cdf0e10cSrcweir const Action::Subset& rSubset ) 440cdf0e10cSrcweir { 441cdf0e10cSrcweir ::canvas::tools::prependToRenderState(io_rRenderState, rTransformation); 442cdf0e10cSrcweir 443cdf0e10cSrcweir if( rSubset.mnSubsetBegin == rSubset.mnSubsetEnd ) 444cdf0e10cSrcweir { 445cdf0e10cSrcweir // empty range, empty layout 446cdf0e10cSrcweir io_rTextLayout.clear(); 447cdf0e10cSrcweir 448cdf0e10cSrcweir return; 449cdf0e10cSrcweir } 450cdf0e10cSrcweir 451cdf0e10cSrcweir ENSURE_OR_THROW( io_rTextLayout.is(), 452cdf0e10cSrcweir "createSubsetLayout(): Invalid input layout" ); 453cdf0e10cSrcweir 454cdf0e10cSrcweir const rendering::StringContext& rOrigContext( io_rTextLayout->getText() ); 455cdf0e10cSrcweir 456cdf0e10cSrcweir if( rSubset.mnSubsetBegin == 0 && 457cdf0e10cSrcweir rSubset.mnSubsetEnd == rOrigContext.Length ) 458cdf0e10cSrcweir { 459cdf0e10cSrcweir // full range, no need for subsetting 460cdf0e10cSrcweir return; 461cdf0e10cSrcweir } 462cdf0e10cSrcweir 463cdf0e10cSrcweir uno::Reference< rendering::XTextLayout > xTextLayout( 464cdf0e10cSrcweir createSubsetLayout( rOrigContext, rSubset, io_rTextLayout ) ); 465cdf0e10cSrcweir 466cdf0e10cSrcweir if( xTextLayout.is() ) 467cdf0e10cSrcweir { 468cdf0e10cSrcweir xTextLayout->applyLogicalAdvancements( 469cdf0e10cSrcweir calcSubsetOffsets( io_rRenderState, 470cdf0e10cSrcweir o_rMinPos, 471cdf0e10cSrcweir o_rMaxPos, 472cdf0e10cSrcweir io_rTextLayout, 473cdf0e10cSrcweir rSubset ) ); 474cdf0e10cSrcweir } 475cdf0e10cSrcweir 476cdf0e10cSrcweir io_rTextLayout = xTextLayout; 477cdf0e10cSrcweir } 478cdf0e10cSrcweir 479cdf0e10cSrcweir 480cdf0e10cSrcweir /** Interface for renderEffectText functor below. 481cdf0e10cSrcweir 482cdf0e10cSrcweir This is interface is used from the renderEffectText() 483cdf0e10cSrcweir method below, to call the client implementation. 484cdf0e10cSrcweir */ 485cdf0e10cSrcweir class TextRenderer 486cdf0e10cSrcweir { 487cdf0e10cSrcweir public: ~TextRenderer()488cdf0e10cSrcweir virtual ~TextRenderer() {} 489cdf0e10cSrcweir 490cdf0e10cSrcweir /// Render text with given RenderState 491cdf0e10cSrcweir virtual bool operator()( const rendering::RenderState& rRenderState ) const = 0; 492cdf0e10cSrcweir }; 493cdf0e10cSrcweir 494cdf0e10cSrcweir /** Render effect text. 495cdf0e10cSrcweir 496cdf0e10cSrcweir @param rRenderer 497cdf0e10cSrcweir Functor object, will be called to render the actual 498cdf0e10cSrcweir part of the text effect (the text itself and the means 499cdf0e10cSrcweir to render it are unknown to this method) 500cdf0e10cSrcweir */ renderEffectText(const TextRenderer & rRenderer,const rendering::RenderState & rRenderState,const rendering::ViewState &,const uno::Reference<rendering::XCanvas> & xCanvas,const::Color & rShadowColor,const::basegfx::B2DSize & rShadowOffset,const::Color & rReliefColor,const::basegfx::B2DSize & rReliefOffset)501cdf0e10cSrcweir bool renderEffectText( const TextRenderer& rRenderer, 502cdf0e10cSrcweir const rendering::RenderState& rRenderState, 503cdf0e10cSrcweir const rendering::ViewState& /*rViewState*/, 504cdf0e10cSrcweir const uno::Reference< rendering::XCanvas >& xCanvas, 505cdf0e10cSrcweir const ::Color& rShadowColor, 506cdf0e10cSrcweir const ::basegfx::B2DSize& rShadowOffset, 507cdf0e10cSrcweir const ::Color& rReliefColor, 508cdf0e10cSrcweir const ::basegfx::B2DSize& rReliefOffset ) 509cdf0e10cSrcweir { 510cdf0e10cSrcweir ::Color aEmptyColor( COL_AUTO ); 511cdf0e10cSrcweir uno::Reference<rendering::XColorSpace> xColorSpace( 512cdf0e10cSrcweir xCanvas->getDevice()->getDeviceColorSpace() ); 513cdf0e10cSrcweir 514cdf0e10cSrcweir // draw shadow text, if enabled 515cdf0e10cSrcweir if( rShadowColor != aEmptyColor ) 516cdf0e10cSrcweir { 517cdf0e10cSrcweir rendering::RenderState aShadowState( rRenderState ); 518cdf0e10cSrcweir ::basegfx::B2DHomMatrix aTranslate; 519cdf0e10cSrcweir 520cdf0e10cSrcweir aTranslate.translate( rShadowOffset.getX(), 521cdf0e10cSrcweir rShadowOffset.getY() ); 522cdf0e10cSrcweir 523cdf0e10cSrcweir ::canvas::tools::appendToRenderState(aShadowState, aTranslate); 524cdf0e10cSrcweir 525cdf0e10cSrcweir aShadowState.DeviceColor = 526cdf0e10cSrcweir ::vcl::unotools::colorToDoubleSequence( rShadowColor, 527cdf0e10cSrcweir xColorSpace ); 528cdf0e10cSrcweir 529cdf0e10cSrcweir rRenderer( aShadowState ); 530cdf0e10cSrcweir } 531cdf0e10cSrcweir 532cdf0e10cSrcweir // draw relief text, if enabled 533cdf0e10cSrcweir if( rReliefColor != aEmptyColor ) 534cdf0e10cSrcweir { 535cdf0e10cSrcweir rendering::RenderState aReliefState( rRenderState ); 536cdf0e10cSrcweir ::basegfx::B2DHomMatrix aTranslate; 537cdf0e10cSrcweir 538cdf0e10cSrcweir aTranslate.translate( rReliefOffset.getX(), 539cdf0e10cSrcweir rReliefOffset.getY() ); 540cdf0e10cSrcweir 541cdf0e10cSrcweir ::canvas::tools::appendToRenderState(aReliefState, aTranslate); 542cdf0e10cSrcweir 543cdf0e10cSrcweir aReliefState.DeviceColor = 544cdf0e10cSrcweir ::vcl::unotools::colorToDoubleSequence( rReliefColor, 545cdf0e10cSrcweir xColorSpace ); 546cdf0e10cSrcweir 547cdf0e10cSrcweir rRenderer( aReliefState ); 548cdf0e10cSrcweir } 549cdf0e10cSrcweir 550cdf0e10cSrcweir // draw normal text 551cdf0e10cSrcweir rRenderer( rRenderState ); 552cdf0e10cSrcweir 553cdf0e10cSrcweir return true; 554cdf0e10cSrcweir } 555cdf0e10cSrcweir 556cdf0e10cSrcweir calcEffectTextBounds(const::basegfx::B2DRange & rTextBounds,const::basegfx::B2DRange & rLineBounds,const::basegfx::B2DSize & rReliefOffset,const::basegfx::B2DSize & rShadowOffset,const rendering::RenderState & rRenderState,const rendering::ViewState & rViewState)557cdf0e10cSrcweir ::basegfx::B2DRange calcEffectTextBounds( const ::basegfx::B2DRange& rTextBounds, 558cdf0e10cSrcweir const ::basegfx::B2DRange& rLineBounds, 559cdf0e10cSrcweir const ::basegfx::B2DSize& rReliefOffset, 560cdf0e10cSrcweir const ::basegfx::B2DSize& rShadowOffset, 561cdf0e10cSrcweir const rendering::RenderState& rRenderState, 562cdf0e10cSrcweir const rendering::ViewState& rViewState ) 563cdf0e10cSrcweir { 564cdf0e10cSrcweir ::basegfx::B2DRange aBounds( rTextBounds ); 565cdf0e10cSrcweir 566cdf0e10cSrcweir // add extends of text lines 567cdf0e10cSrcweir aBounds.expand( rLineBounds ); 568cdf0e10cSrcweir 569cdf0e10cSrcweir // TODO(Q3): Provide this functionality at the B2DRange 570cdf0e10cSrcweir ::basegfx::B2DRange aTotalBounds( aBounds ); 571cdf0e10cSrcweir aTotalBounds.expand( 572cdf0e10cSrcweir ::basegfx::B2DRange( aBounds.getMinX() + rReliefOffset.getX(), 573cdf0e10cSrcweir aBounds.getMinY() + rReliefOffset.getY(), 574cdf0e10cSrcweir aBounds.getMaxX() + rReliefOffset.getX(), 575cdf0e10cSrcweir aBounds.getMaxY() + rReliefOffset.getY() ) ); 576cdf0e10cSrcweir aTotalBounds.expand( 577cdf0e10cSrcweir ::basegfx::B2DRange( aBounds.getMinX() + rShadowOffset.getX(), 578cdf0e10cSrcweir aBounds.getMinY() + rShadowOffset.getY(), 579cdf0e10cSrcweir aBounds.getMaxX() + rShadowOffset.getX(), 580cdf0e10cSrcweir aBounds.getMaxY() + rShadowOffset.getY() ) ); 581cdf0e10cSrcweir 582cdf0e10cSrcweir return tools::calcDevicePixelBounds( aTotalBounds, 583cdf0e10cSrcweir rViewState, 584cdf0e10cSrcweir rRenderState ); 585cdf0e10cSrcweir } 586cdf0e10cSrcweir initEffectLinePolyPolygon(::basegfx::B2DSize & o_rOverallSize,uno::Reference<rendering::XPolyPolygon2D> & o_rTextLines,const CanvasSharedPtr & rCanvas,const uno::Sequence<double> & rOffsets,const tools::TextLineInfo rLineInfo)587cdf0e10cSrcweir void initEffectLinePolyPolygon( ::basegfx::B2DSize& o_rOverallSize, 588cdf0e10cSrcweir uno::Reference< rendering::XPolyPolygon2D >& o_rTextLines, 589cdf0e10cSrcweir const CanvasSharedPtr& rCanvas, 590cdf0e10cSrcweir const uno::Sequence< double >& rOffsets, 591cdf0e10cSrcweir const tools::TextLineInfo rLineInfo ) 592cdf0e10cSrcweir { 593cdf0e10cSrcweir const ::basegfx::B2DPolyPolygon aPoly( 594cdf0e10cSrcweir textLinesFromLogicalOffsets( 595cdf0e10cSrcweir rOffsets, 596cdf0e10cSrcweir rLineInfo ) ); 597cdf0e10cSrcweir 598cdf0e10cSrcweir o_rOverallSize = ::basegfx::tools::getRange( aPoly ).getRange(); 599cdf0e10cSrcweir 600cdf0e10cSrcweir o_rTextLines = ::basegfx::unotools::xPolyPolygonFromB2DPolyPolygon( 601cdf0e10cSrcweir rCanvas->getUNOCanvas()->getDevice(), 602cdf0e10cSrcweir aPoly ); 603cdf0e10cSrcweir } 604cdf0e10cSrcweir initEffectLinePolyPolygon(::basegfx::B2DSize & o_rOverallSize,uno::Reference<rendering::XPolyPolygon2D> & o_rTextLines,const CanvasSharedPtr & rCanvas,double nLineWidth,const tools::TextLineInfo rLineInfo)605cdf0e10cSrcweir void initEffectLinePolyPolygon( ::basegfx::B2DSize& o_rOverallSize, 606cdf0e10cSrcweir uno::Reference< rendering::XPolyPolygon2D >& o_rTextLines, 607cdf0e10cSrcweir const CanvasSharedPtr& rCanvas, 608cdf0e10cSrcweir double nLineWidth, 609cdf0e10cSrcweir const tools::TextLineInfo rLineInfo ) 610cdf0e10cSrcweir { 611cdf0e10cSrcweir const ::basegfx::B2DPolyPolygon aPoly( 612cdf0e10cSrcweir tools::createTextLinesPolyPolygon( 0.0, nLineWidth, 613cdf0e10cSrcweir rLineInfo ) ); 614cdf0e10cSrcweir 615cdf0e10cSrcweir o_rOverallSize = ::basegfx::tools::getRange( aPoly ).getRange(); 616cdf0e10cSrcweir 617cdf0e10cSrcweir o_rTextLines = ::basegfx::unotools::xPolyPolygonFromB2DPolyPolygon( 618cdf0e10cSrcweir rCanvas->getUNOCanvas()->getDevice(), 619cdf0e10cSrcweir aPoly ); 620cdf0e10cSrcweir } 621cdf0e10cSrcweir 622cdf0e10cSrcweir 623cdf0e10cSrcweir // ------------------------------------------------------------------------- 624cdf0e10cSrcweir 625cdf0e10cSrcweir class TextAction : public Action, private ::boost::noncopyable 626cdf0e10cSrcweir { 627cdf0e10cSrcweir public: 628cdf0e10cSrcweir TextAction( const ::basegfx::B2DPoint& rStartPoint, 629cdf0e10cSrcweir const ::rtl::OUString& rString, 630cdf0e10cSrcweir sal_Int32 nStartPos, 631cdf0e10cSrcweir sal_Int32 nLen, 632cdf0e10cSrcweir const CanvasSharedPtr& rCanvas, 633cdf0e10cSrcweir const OutDevState& rState ); 634cdf0e10cSrcweir 635cdf0e10cSrcweir TextAction( const ::basegfx::B2DPoint& rStartPoint, 636cdf0e10cSrcweir const ::rtl::OUString& rString, 637cdf0e10cSrcweir sal_Int32 nStartPos, 638cdf0e10cSrcweir sal_Int32 nLen, 639cdf0e10cSrcweir const CanvasSharedPtr& rCanvas, 640cdf0e10cSrcweir const OutDevState& rState, 641cdf0e10cSrcweir const ::basegfx::B2DHomMatrix& rTextTransform ); 642cdf0e10cSrcweir 643cdf0e10cSrcweir virtual bool render( const ::basegfx::B2DHomMatrix& rTransformation ) const; 644cdf0e10cSrcweir virtual bool render( const ::basegfx::B2DHomMatrix& rTransformation, 645cdf0e10cSrcweir const Subset& rSubset ) const; 646cdf0e10cSrcweir 647cdf0e10cSrcweir virtual ::basegfx::B2DRange getBounds( const ::basegfx::B2DHomMatrix& rTransformation ) const; 648cdf0e10cSrcweir virtual ::basegfx::B2DRange getBounds( const ::basegfx::B2DHomMatrix& rTransformation, 649cdf0e10cSrcweir const Subset& rSubset ) const; 650cdf0e10cSrcweir 651cdf0e10cSrcweir virtual sal_Int32 getActionCount() const; 652cdf0e10cSrcweir 653cdf0e10cSrcweir private: 654cdf0e10cSrcweir // TODO(P2): This is potentially a real mass object 655cdf0e10cSrcweir // (every character might be a separate TextAction), 656cdf0e10cSrcweir // thus, make it as lightweight as possible. For 657cdf0e10cSrcweir // example, share common RenderState among several 658cdf0e10cSrcweir // TextActions, maybe using maOffsets for the 659cdf0e10cSrcweir // translation. 660cdf0e10cSrcweir 661cdf0e10cSrcweir uno::Reference< rendering::XCanvasFont > mxFont; 662cdf0e10cSrcweir const rendering::StringContext maStringContext; 663cdf0e10cSrcweir const CanvasSharedPtr mpCanvas; 664cdf0e10cSrcweir rendering::RenderState maState; 665cdf0e10cSrcweir const sal_Int8 maTextDirection; 666cdf0e10cSrcweir }; 667cdf0e10cSrcweir TextAction(const::basegfx::B2DPoint & rStartPoint,const::rtl::OUString & rString,sal_Int32 nStartPos,sal_Int32 nLen,const CanvasSharedPtr & rCanvas,const OutDevState & rState)668cdf0e10cSrcweir TextAction::TextAction( const ::basegfx::B2DPoint& rStartPoint, 669cdf0e10cSrcweir const ::rtl::OUString& rString, 670cdf0e10cSrcweir sal_Int32 nStartPos, 671cdf0e10cSrcweir sal_Int32 nLen, 672cdf0e10cSrcweir const CanvasSharedPtr& rCanvas, 673cdf0e10cSrcweir const OutDevState& rState ) : 674cdf0e10cSrcweir mxFont( rState.xFont ), 675cdf0e10cSrcweir maStringContext( rString, nStartPos, nLen ), 676cdf0e10cSrcweir mpCanvas( rCanvas ), 677cdf0e10cSrcweir maState(), 678cdf0e10cSrcweir maTextDirection( rState.textDirection ) 679cdf0e10cSrcweir { 680cdf0e10cSrcweir init( maState, mxFont, 681cdf0e10cSrcweir rStartPoint, 682cdf0e10cSrcweir rState, rCanvas ); 683cdf0e10cSrcweir 684cdf0e10cSrcweir ENSURE_OR_THROW( mxFont.is(), 685cdf0e10cSrcweir "::cppcanvas::internal::TextAction(): Invalid font" ); 686cdf0e10cSrcweir } 687cdf0e10cSrcweir TextAction(const::basegfx::B2DPoint & rStartPoint,const::rtl::OUString & rString,sal_Int32 nStartPos,sal_Int32 nLen,const CanvasSharedPtr & rCanvas,const OutDevState & rState,const::basegfx::B2DHomMatrix & rTextTransform)688cdf0e10cSrcweir TextAction::TextAction( const ::basegfx::B2DPoint& rStartPoint, 689cdf0e10cSrcweir const ::rtl::OUString& rString, 690cdf0e10cSrcweir sal_Int32 nStartPos, 691cdf0e10cSrcweir sal_Int32 nLen, 692cdf0e10cSrcweir const CanvasSharedPtr& rCanvas, 693cdf0e10cSrcweir const OutDevState& rState, 694cdf0e10cSrcweir const ::basegfx::B2DHomMatrix& rTextTransform ) : 695cdf0e10cSrcweir mxFont( rState.xFont ), 696cdf0e10cSrcweir maStringContext( rString, nStartPos, nLen ), 697cdf0e10cSrcweir mpCanvas( rCanvas ), 698cdf0e10cSrcweir maState(), 699cdf0e10cSrcweir maTextDirection( rState.textDirection ) 700cdf0e10cSrcweir { 701cdf0e10cSrcweir init( maState, mxFont, 702cdf0e10cSrcweir rStartPoint, 703cdf0e10cSrcweir rState, rCanvas, rTextTransform ); 704cdf0e10cSrcweir 705cdf0e10cSrcweir ENSURE_OR_THROW( mxFont.is(), 706cdf0e10cSrcweir "::cppcanvas::internal::TextAction(): Invalid font" ); 707cdf0e10cSrcweir } 708cdf0e10cSrcweir render(const::basegfx::B2DHomMatrix & rTransformation) const709cdf0e10cSrcweir bool TextAction::render( const ::basegfx::B2DHomMatrix& rTransformation ) const 710cdf0e10cSrcweir { 711cdf0e10cSrcweir RTL_LOGFILE_CONTEXT( aLog, "::cppcanvas::internal::TextAction::render()" ); 712cdf0e10cSrcweir RTL_LOGFILE_CONTEXT_TRACE1( aLog, "::cppcanvas::internal::TextAction: 0x%X", this ); 713cdf0e10cSrcweir 714cdf0e10cSrcweir rendering::RenderState aLocalState( maState ); 715cdf0e10cSrcweir ::canvas::tools::prependToRenderState(aLocalState, rTransformation); 716cdf0e10cSrcweir 717cdf0e10cSrcweir mpCanvas->getUNOCanvas()->drawText( maStringContext, mxFont, 718cdf0e10cSrcweir mpCanvas->getViewState(), aLocalState, maTextDirection ); 719cdf0e10cSrcweir 720cdf0e10cSrcweir return true; 721cdf0e10cSrcweir } 722cdf0e10cSrcweir render(const::basegfx::B2DHomMatrix & rTransformation,const Subset &) const723cdf0e10cSrcweir bool TextAction::render( const ::basegfx::B2DHomMatrix& rTransformation, 724cdf0e10cSrcweir const Subset& /*rSubset*/ ) const 725cdf0e10cSrcweir { 726cdf0e10cSrcweir OSL_ENSURE( false, 727cdf0e10cSrcweir "TextAction::render(): Subset not supported by this object" ); 728cdf0e10cSrcweir 729cdf0e10cSrcweir // TODO(P1): Retrieve necessary font metric info for 730cdf0e10cSrcweir // TextAction from XCanvas. Currently, the 731cdf0e10cSrcweir // TextActionFactory does not generate this object for 732cdf0e10cSrcweir // _subsettable_ text 733cdf0e10cSrcweir return render( rTransformation ); 734cdf0e10cSrcweir } 735cdf0e10cSrcweir getBounds(const::basegfx::B2DHomMatrix & rTransformation) const736cdf0e10cSrcweir ::basegfx::B2DRange TextAction::getBounds( const ::basegfx::B2DHomMatrix& rTransformation ) const 737cdf0e10cSrcweir { 738cdf0e10cSrcweir // create XTextLayout, to have the 739cdf0e10cSrcweir // XTextLayout::queryTextBounds() method available 740cdf0e10cSrcweir uno::Reference< rendering::XTextLayout > xTextLayout( 741cdf0e10cSrcweir mxFont->createTextLayout( 742cdf0e10cSrcweir maStringContext, 743cdf0e10cSrcweir maTextDirection, 744cdf0e10cSrcweir 0 ) ); 745cdf0e10cSrcweir 746cdf0e10cSrcweir rendering::RenderState aLocalState( maState ); 747cdf0e10cSrcweir ::canvas::tools::prependToRenderState(aLocalState, rTransformation); 748cdf0e10cSrcweir 749cdf0e10cSrcweir return tools::calcDevicePixelBounds( ::basegfx::unotools::b2DRectangleFromRealRectangle2D( 750cdf0e10cSrcweir xTextLayout->queryTextBounds() ), 751cdf0e10cSrcweir mpCanvas->getViewState(), 752cdf0e10cSrcweir aLocalState ); 753cdf0e10cSrcweir } 754cdf0e10cSrcweir getBounds(const::basegfx::B2DHomMatrix & rTransformation,const Subset &) const755cdf0e10cSrcweir ::basegfx::B2DRange TextAction::getBounds( const ::basegfx::B2DHomMatrix& rTransformation, 756cdf0e10cSrcweir const Subset& /*rSubset*/ ) const 757cdf0e10cSrcweir { 758cdf0e10cSrcweir OSL_ENSURE( false, 759cdf0e10cSrcweir "TextAction::getBounds(): Subset not supported by this object" ); 760cdf0e10cSrcweir 761cdf0e10cSrcweir // TODO(P1): Retrieve necessary font metric info for 762cdf0e10cSrcweir // TextAction from XCanvas. Currently, the 763cdf0e10cSrcweir // TextActionFactory does not generate this object for 764cdf0e10cSrcweir // _subsettable_ text 765cdf0e10cSrcweir return getBounds( rTransformation ); 766cdf0e10cSrcweir } 767cdf0e10cSrcweir getActionCount() const768cdf0e10cSrcweir sal_Int32 TextAction::getActionCount() const 769cdf0e10cSrcweir { 770cdf0e10cSrcweir // TODO(P1): Retrieve necessary font metric info for 771cdf0e10cSrcweir // TextAction from XCanvas. Currently, the 772cdf0e10cSrcweir // TextActionFactory does not generate this object for 773cdf0e10cSrcweir // _subsettable_ text 774cdf0e10cSrcweir return 1; 775cdf0e10cSrcweir } 776cdf0e10cSrcweir 777cdf0e10cSrcweir 778cdf0e10cSrcweir // ------------------------------------------------------------------------- 779cdf0e10cSrcweir 780cdf0e10cSrcweir class EffectTextAction : 781cdf0e10cSrcweir public Action, 782cdf0e10cSrcweir public TextRenderer, 783cdf0e10cSrcweir private ::boost::noncopyable 784cdf0e10cSrcweir { 785cdf0e10cSrcweir public: 786cdf0e10cSrcweir EffectTextAction( const ::basegfx::B2DPoint& rStartPoint, 787cdf0e10cSrcweir const ::basegfx::B2DSize& rReliefOffset, 788cdf0e10cSrcweir const ::Color& rReliefColor, 789cdf0e10cSrcweir const ::basegfx::B2DSize& rShadowOffset, 790cdf0e10cSrcweir const ::Color& rShadowColor, 791cdf0e10cSrcweir const ::rtl::OUString& rText, 792cdf0e10cSrcweir sal_Int32 nStartPos, 793cdf0e10cSrcweir sal_Int32 nLen, 794cdf0e10cSrcweir VirtualDevice& rVDev, 795cdf0e10cSrcweir const CanvasSharedPtr& rCanvas, 796cdf0e10cSrcweir const OutDevState& rState ); 797cdf0e10cSrcweir 798cdf0e10cSrcweir EffectTextAction( const ::basegfx::B2DPoint& rStartPoint, 799cdf0e10cSrcweir const ::basegfx::B2DSize& rReliefOffset, 800cdf0e10cSrcweir const ::Color& rReliefColor, 801cdf0e10cSrcweir const ::basegfx::B2DSize& rShadowOffset, 802cdf0e10cSrcweir const ::Color& rShadowColor, 803cdf0e10cSrcweir const ::rtl::OUString& rText, 804cdf0e10cSrcweir sal_Int32 nStartPos, 805cdf0e10cSrcweir sal_Int32 nLen, 806cdf0e10cSrcweir VirtualDevice& rVDev, 807cdf0e10cSrcweir const CanvasSharedPtr& rCanvas, 808cdf0e10cSrcweir const OutDevState& rState, 809cdf0e10cSrcweir const ::basegfx::B2DHomMatrix& rTextTransform ); 810cdf0e10cSrcweir 811cdf0e10cSrcweir virtual bool render( const ::basegfx::B2DHomMatrix& rTransformation ) const; 812cdf0e10cSrcweir virtual bool render( const ::basegfx::B2DHomMatrix& rTransformation, 813cdf0e10cSrcweir const Subset& rSubset ) const; 814cdf0e10cSrcweir 815cdf0e10cSrcweir virtual ::basegfx::B2DRange getBounds( const ::basegfx::B2DHomMatrix& rTransformation ) const; 816cdf0e10cSrcweir virtual ::basegfx::B2DRange getBounds( const ::basegfx::B2DHomMatrix& rTransformation, 817cdf0e10cSrcweir const Subset& rSubset ) const; 818cdf0e10cSrcweir 819cdf0e10cSrcweir virtual sal_Int32 getActionCount() const; 820cdf0e10cSrcweir 821cdf0e10cSrcweir private: 822cdf0e10cSrcweir /// Interface TextRenderer 823cdf0e10cSrcweir virtual bool operator()( const rendering::RenderState& rRenderState ) const; 824cdf0e10cSrcweir 825cdf0e10cSrcweir // TODO(P2): This is potentially a real mass object 826cdf0e10cSrcweir // (every character might be a separate TextAction), 827cdf0e10cSrcweir // thus, make it as lightweight as possible. For 828cdf0e10cSrcweir // example, share common RenderState among several 829cdf0e10cSrcweir // TextActions, maybe using maOffsets for the 830cdf0e10cSrcweir // translation. 831cdf0e10cSrcweir 832cdf0e10cSrcweir uno::Reference< rendering::XCanvasFont > mxFont; 833cdf0e10cSrcweir const rendering::StringContext maStringContext; 834cdf0e10cSrcweir const CanvasSharedPtr mpCanvas; 835cdf0e10cSrcweir rendering::RenderState maState; 836cdf0e10cSrcweir const tools::TextLineInfo maTextLineInfo; 837cdf0e10cSrcweir ::basegfx::B2DSize maLinesOverallSize; 838cdf0e10cSrcweir const double mnLineWidth; 839cdf0e10cSrcweir uno::Reference< rendering::XPolyPolygon2D > mxTextLines; 840cdf0e10cSrcweir const ::basegfx::B2DSize maReliefOffset; 841cdf0e10cSrcweir const ::Color maReliefColor; 842cdf0e10cSrcweir const ::basegfx::B2DSize maShadowOffset; 843cdf0e10cSrcweir const ::Color maShadowColor; 844cdf0e10cSrcweir const sal_Int8 maTextDirection; 845cdf0e10cSrcweir }; 846cdf0e10cSrcweir EffectTextAction(const::basegfx::B2DPoint & rStartPoint,const::basegfx::B2DSize & rReliefOffset,const::Color & rReliefColor,const::basegfx::B2DSize & rShadowOffset,const::Color & rShadowColor,const::rtl::OUString & rText,sal_Int32 nStartPos,sal_Int32 nLen,VirtualDevice & rVDev,const CanvasSharedPtr & rCanvas,const OutDevState & rState)847cdf0e10cSrcweir EffectTextAction::EffectTextAction( const ::basegfx::B2DPoint& rStartPoint, 848cdf0e10cSrcweir const ::basegfx::B2DSize& rReliefOffset, 849cdf0e10cSrcweir const ::Color& rReliefColor, 850cdf0e10cSrcweir const ::basegfx::B2DSize& rShadowOffset, 851cdf0e10cSrcweir const ::Color& rShadowColor, 852cdf0e10cSrcweir const ::rtl::OUString& rText, 853cdf0e10cSrcweir sal_Int32 nStartPos, 854cdf0e10cSrcweir sal_Int32 nLen, 855cdf0e10cSrcweir VirtualDevice& rVDev, 856cdf0e10cSrcweir const CanvasSharedPtr& rCanvas, 857cdf0e10cSrcweir const OutDevState& rState ) : 858cdf0e10cSrcweir mxFont( rState.xFont ), 859cdf0e10cSrcweir maStringContext( rText, nStartPos, nLen ), 860cdf0e10cSrcweir mpCanvas( rCanvas ), 861cdf0e10cSrcweir maState(), 862cdf0e10cSrcweir maTextLineInfo( tools::createTextLineInfo( rVDev, rState ) ), 863cdf0e10cSrcweir maLinesOverallSize(), 864cdf0e10cSrcweir mnLineWidth( getLineWidth( rVDev, rState, maStringContext ) ), 865cdf0e10cSrcweir mxTextLines(), 866cdf0e10cSrcweir maReliefOffset( rReliefOffset ), 867cdf0e10cSrcweir maReliefColor( rReliefColor ), 868cdf0e10cSrcweir maShadowOffset( rShadowOffset ), 869cdf0e10cSrcweir maShadowColor( rShadowColor ), 870cdf0e10cSrcweir maTextDirection( rState.textDirection ) 871cdf0e10cSrcweir { 872cdf0e10cSrcweir initEffectLinePolyPolygon( maLinesOverallSize, 873cdf0e10cSrcweir mxTextLines, 874cdf0e10cSrcweir rCanvas, 875cdf0e10cSrcweir mnLineWidth, 876cdf0e10cSrcweir maTextLineInfo ); 877cdf0e10cSrcweir 878cdf0e10cSrcweir init( maState, mxFont, 879cdf0e10cSrcweir rStartPoint, 880cdf0e10cSrcweir rState, rCanvas ); 881cdf0e10cSrcweir 882cdf0e10cSrcweir ENSURE_OR_THROW( mxFont.is() && mxTextLines.is(), 883cdf0e10cSrcweir "::cppcanvas::internal::EffectTextAction(): Invalid font or lines" ); 884cdf0e10cSrcweir } 885cdf0e10cSrcweir EffectTextAction(const::basegfx::B2DPoint & rStartPoint,const::basegfx::B2DSize & rReliefOffset,const::Color & rReliefColor,const::basegfx::B2DSize & rShadowOffset,const::Color & rShadowColor,const::rtl::OUString & rText,sal_Int32 nStartPos,sal_Int32 nLen,VirtualDevice & rVDev,const CanvasSharedPtr & rCanvas,const OutDevState & rState,const::basegfx::B2DHomMatrix & rTextTransform)886cdf0e10cSrcweir EffectTextAction::EffectTextAction( const ::basegfx::B2DPoint& rStartPoint, 887cdf0e10cSrcweir const ::basegfx::B2DSize& rReliefOffset, 888cdf0e10cSrcweir const ::Color& rReliefColor, 889cdf0e10cSrcweir const ::basegfx::B2DSize& rShadowOffset, 890cdf0e10cSrcweir const ::Color& rShadowColor, 891cdf0e10cSrcweir const ::rtl::OUString& rText, 892cdf0e10cSrcweir sal_Int32 nStartPos, 893cdf0e10cSrcweir sal_Int32 nLen, 894cdf0e10cSrcweir VirtualDevice& rVDev, 895cdf0e10cSrcweir const CanvasSharedPtr& rCanvas, 896cdf0e10cSrcweir const OutDevState& rState, 897cdf0e10cSrcweir const ::basegfx::B2DHomMatrix& rTextTransform ) : 898cdf0e10cSrcweir mxFont( rState.xFont ), 899cdf0e10cSrcweir maStringContext( rText, nStartPos, nLen ), 900cdf0e10cSrcweir mpCanvas( rCanvas ), 901cdf0e10cSrcweir maState(), 902cdf0e10cSrcweir maTextLineInfo( tools::createTextLineInfo( rVDev, rState ) ), 903cdf0e10cSrcweir maLinesOverallSize(), 904cdf0e10cSrcweir mnLineWidth( getLineWidth( rVDev, rState, maStringContext ) ), 905cdf0e10cSrcweir mxTextLines(), 906cdf0e10cSrcweir maReliefOffset( rReliefOffset ), 907cdf0e10cSrcweir maReliefColor( rReliefColor ), 908cdf0e10cSrcweir maShadowOffset( rShadowOffset ), 909cdf0e10cSrcweir maShadowColor( rShadowColor ), 910cdf0e10cSrcweir maTextDirection( rState.textDirection ) 911cdf0e10cSrcweir { 912cdf0e10cSrcweir initEffectLinePolyPolygon( maLinesOverallSize, 913cdf0e10cSrcweir mxTextLines, 914cdf0e10cSrcweir rCanvas, 915cdf0e10cSrcweir mnLineWidth, 916cdf0e10cSrcweir maTextLineInfo ); 917cdf0e10cSrcweir 918cdf0e10cSrcweir init( maState, mxFont, 919cdf0e10cSrcweir rStartPoint, 920cdf0e10cSrcweir rState, rCanvas, rTextTransform ); 921cdf0e10cSrcweir 922cdf0e10cSrcweir ENSURE_OR_THROW( mxFont.is() && mxTextLines.is(), 923cdf0e10cSrcweir "::cppcanvas::internal::EffectTextAction(): Invalid font or lines" ); 924cdf0e10cSrcweir } 925cdf0e10cSrcweir operator ()(const rendering::RenderState & rRenderState) const926cdf0e10cSrcweir bool EffectTextAction::operator()( const rendering::RenderState& rRenderState ) const 927cdf0e10cSrcweir { 928cdf0e10cSrcweir const rendering::ViewState& rViewState( mpCanvas->getViewState() ); 929cdf0e10cSrcweir const uno::Reference< rendering::XCanvas >& rCanvas( mpCanvas->getUNOCanvas() ); 930cdf0e10cSrcweir 931cdf0e10cSrcweir rCanvas->fillPolyPolygon( mxTextLines, 932cdf0e10cSrcweir rViewState, 933cdf0e10cSrcweir rRenderState ); 934cdf0e10cSrcweir 935cdf0e10cSrcweir rCanvas->drawText( maStringContext, mxFont, 936cdf0e10cSrcweir rViewState, 937cdf0e10cSrcweir rRenderState, 938cdf0e10cSrcweir maTextDirection ); 939cdf0e10cSrcweir 940cdf0e10cSrcweir return true; 941cdf0e10cSrcweir } 942cdf0e10cSrcweir render(const::basegfx::B2DHomMatrix & rTransformation) const943cdf0e10cSrcweir bool EffectTextAction::render( const ::basegfx::B2DHomMatrix& rTransformation ) const 944cdf0e10cSrcweir { 945cdf0e10cSrcweir RTL_LOGFILE_CONTEXT( aLog, "::cppcanvas::internal::EffectTextAction::render()" ); 946cdf0e10cSrcweir RTL_LOGFILE_CONTEXT_TRACE1( aLog, "::cppcanvas::internal::EffectTextAction: 0x%X", this ); 947cdf0e10cSrcweir 948cdf0e10cSrcweir rendering::RenderState aLocalState( maState ); 949cdf0e10cSrcweir ::canvas::tools::prependToRenderState(aLocalState, rTransformation); 950cdf0e10cSrcweir 951cdf0e10cSrcweir return renderEffectText( *this, 952cdf0e10cSrcweir aLocalState, 953cdf0e10cSrcweir mpCanvas->getViewState(), 954cdf0e10cSrcweir mpCanvas->getUNOCanvas(), 955cdf0e10cSrcweir maShadowColor, 956cdf0e10cSrcweir maShadowOffset, 957cdf0e10cSrcweir maReliefColor, 958cdf0e10cSrcweir maReliefOffset ); 959cdf0e10cSrcweir } 960cdf0e10cSrcweir render(const::basegfx::B2DHomMatrix & rTransformation,const Subset &) const961cdf0e10cSrcweir bool EffectTextAction::render( const ::basegfx::B2DHomMatrix& rTransformation, 962cdf0e10cSrcweir const Subset& /*rSubset*/ ) const 963cdf0e10cSrcweir { 964cdf0e10cSrcweir OSL_ENSURE( false, 965cdf0e10cSrcweir "EffectTextAction::render(): Subset not supported by this object" ); 966cdf0e10cSrcweir 967cdf0e10cSrcweir // TODO(P1): Retrieve necessary font metric info for 968cdf0e10cSrcweir // TextAction from XCanvas. Currently, the 969cdf0e10cSrcweir // TextActionFactory does not generate this object for 970cdf0e10cSrcweir // subsettable text 971cdf0e10cSrcweir return render( rTransformation ); 972cdf0e10cSrcweir } 973cdf0e10cSrcweir getBounds(const::basegfx::B2DHomMatrix & rTransformation) const974cdf0e10cSrcweir ::basegfx::B2DRange EffectTextAction::getBounds( const ::basegfx::B2DHomMatrix& rTransformation ) const 975cdf0e10cSrcweir { 976cdf0e10cSrcweir // create XTextLayout, to have the 977cdf0e10cSrcweir // XTextLayout::queryTextBounds() method available 978cdf0e10cSrcweir uno::Reference< rendering::XTextLayout > xTextLayout( 979cdf0e10cSrcweir mxFont->createTextLayout( 980cdf0e10cSrcweir maStringContext, 981cdf0e10cSrcweir maTextDirection, 982cdf0e10cSrcweir 0 ) ); 983cdf0e10cSrcweir 984cdf0e10cSrcweir rendering::RenderState aLocalState( maState ); 985cdf0e10cSrcweir ::canvas::tools::prependToRenderState(aLocalState, rTransformation); 986cdf0e10cSrcweir 987cdf0e10cSrcweir return calcEffectTextBounds( ::basegfx::unotools::b2DRectangleFromRealRectangle2D( 988cdf0e10cSrcweir xTextLayout->queryTextBounds() ), 989cdf0e10cSrcweir ::basegfx::B2DRange( 0,0, 990cdf0e10cSrcweir maLinesOverallSize.getX(), 991cdf0e10cSrcweir maLinesOverallSize.getY() ), 992cdf0e10cSrcweir maReliefOffset, 993cdf0e10cSrcweir maShadowOffset, 994cdf0e10cSrcweir aLocalState, 995cdf0e10cSrcweir mpCanvas->getViewState() ); 996cdf0e10cSrcweir } 997cdf0e10cSrcweir getBounds(const::basegfx::B2DHomMatrix & rTransformation,const Subset &) const998cdf0e10cSrcweir ::basegfx::B2DRange EffectTextAction::getBounds( const ::basegfx::B2DHomMatrix& rTransformation, 999cdf0e10cSrcweir const Subset& /*rSubset*/ ) const 1000cdf0e10cSrcweir { 1001cdf0e10cSrcweir OSL_ENSURE( false, 1002cdf0e10cSrcweir "EffectTextAction::getBounds(): Subset not supported by this object" ); 1003cdf0e10cSrcweir 1004cdf0e10cSrcweir // TODO(P1): Retrieve necessary font metric info for 1005cdf0e10cSrcweir // TextAction from XCanvas. Currently, the 1006cdf0e10cSrcweir // TextActionFactory does not generate this object for 1007cdf0e10cSrcweir // _subsettable_ text 1008cdf0e10cSrcweir return getBounds( rTransformation ); 1009cdf0e10cSrcweir } 1010cdf0e10cSrcweir getActionCount() const1011cdf0e10cSrcweir sal_Int32 EffectTextAction::getActionCount() const 1012cdf0e10cSrcweir { 1013cdf0e10cSrcweir // TODO(P1): Retrieve necessary font metric info for 1014cdf0e10cSrcweir // TextAction from XCanvas. Currently, the 1015cdf0e10cSrcweir // TextActionFactory does not generate this object for 1016cdf0e10cSrcweir // subsettable text 1017cdf0e10cSrcweir return 1; 1018cdf0e10cSrcweir } 1019cdf0e10cSrcweir 1020cdf0e10cSrcweir 1021cdf0e10cSrcweir // ------------------------------------------------------------------------- 1022cdf0e10cSrcweir 1023cdf0e10cSrcweir class TextArrayAction : public Action, private ::boost::noncopyable 1024cdf0e10cSrcweir { 1025cdf0e10cSrcweir public: 1026cdf0e10cSrcweir TextArrayAction( const ::basegfx::B2DPoint& rStartPoint, 1027cdf0e10cSrcweir const ::rtl::OUString& rString, 1028cdf0e10cSrcweir sal_Int32 nStartPos, 1029cdf0e10cSrcweir sal_Int32 nLen, 1030cdf0e10cSrcweir const uno::Sequence< double >& rOffsets, 1031cdf0e10cSrcweir const CanvasSharedPtr& rCanvas, 1032cdf0e10cSrcweir const OutDevState& rState ); 1033cdf0e10cSrcweir 1034cdf0e10cSrcweir TextArrayAction( const ::basegfx::B2DPoint& rStartPoint, 1035cdf0e10cSrcweir const ::rtl::OUString& rString, 1036cdf0e10cSrcweir sal_Int32 nStartPos, 1037cdf0e10cSrcweir sal_Int32 nLen, 1038cdf0e10cSrcweir const uno::Sequence< double >& rOffsets, 1039cdf0e10cSrcweir const CanvasSharedPtr& rCanvas, 1040cdf0e10cSrcweir const OutDevState& rState, 1041cdf0e10cSrcweir const ::basegfx::B2DHomMatrix& rTextTransform ); 1042cdf0e10cSrcweir 1043cdf0e10cSrcweir virtual bool render( const ::basegfx::B2DHomMatrix& rTransformation ) const; 1044cdf0e10cSrcweir virtual bool render( const ::basegfx::B2DHomMatrix& rTransformation, 1045cdf0e10cSrcweir const Subset& rSubset ) const; 1046cdf0e10cSrcweir 1047cdf0e10cSrcweir virtual ::basegfx::B2DRange getBounds( const ::basegfx::B2DHomMatrix& rTransformation ) const; 1048cdf0e10cSrcweir virtual ::basegfx::B2DRange getBounds( const ::basegfx::B2DHomMatrix& rTransformation, 1049cdf0e10cSrcweir const Subset& rSubset ) const; 1050cdf0e10cSrcweir 1051cdf0e10cSrcweir virtual sal_Int32 getActionCount() const; 1052cdf0e10cSrcweir 1053cdf0e10cSrcweir private: 1054cdf0e10cSrcweir // TODO(P2): This is potentially a real mass object 1055cdf0e10cSrcweir // (every character might be a separate TextAction), 1056cdf0e10cSrcweir // thus, make it as lightweight as possible. For 1057cdf0e10cSrcweir // example, share common RenderState among several 1058cdf0e10cSrcweir // TextActions, maybe using maOffsets for the 1059cdf0e10cSrcweir // translation. 1060cdf0e10cSrcweir 1061cdf0e10cSrcweir uno::Reference< rendering::XTextLayout > mxTextLayout; 1062cdf0e10cSrcweir const CanvasSharedPtr mpCanvas; 1063cdf0e10cSrcweir rendering::RenderState maState; 1064cdf0e10cSrcweir }; 1065cdf0e10cSrcweir TextArrayAction(const::basegfx::B2DPoint & rStartPoint,const::rtl::OUString & rString,sal_Int32 nStartPos,sal_Int32 nLen,const uno::Sequence<double> & rOffsets,const CanvasSharedPtr & rCanvas,const OutDevState & rState)1066cdf0e10cSrcweir TextArrayAction::TextArrayAction( const ::basegfx::B2DPoint& rStartPoint, 1067cdf0e10cSrcweir const ::rtl::OUString& rString, 1068cdf0e10cSrcweir sal_Int32 nStartPos, 1069cdf0e10cSrcweir sal_Int32 nLen, 1070cdf0e10cSrcweir const uno::Sequence< double >& rOffsets, 1071cdf0e10cSrcweir const CanvasSharedPtr& rCanvas, 1072cdf0e10cSrcweir const OutDevState& rState ) : 1073cdf0e10cSrcweir mxTextLayout(), 1074cdf0e10cSrcweir mpCanvas( rCanvas ), 1075cdf0e10cSrcweir maState() 1076cdf0e10cSrcweir { 1077cdf0e10cSrcweir initArrayAction( maState, 1078cdf0e10cSrcweir mxTextLayout, 1079cdf0e10cSrcweir rStartPoint, 1080cdf0e10cSrcweir rString, 1081cdf0e10cSrcweir nStartPos, 1082cdf0e10cSrcweir nLen, 1083cdf0e10cSrcweir rOffsets, 1084cdf0e10cSrcweir rCanvas, 1085cdf0e10cSrcweir rState, NULL ); 1086cdf0e10cSrcweir } 1087cdf0e10cSrcweir TextArrayAction(const::basegfx::B2DPoint & rStartPoint,const::rtl::OUString & rString,sal_Int32 nStartPos,sal_Int32 nLen,const uno::Sequence<double> & rOffsets,const CanvasSharedPtr & rCanvas,const OutDevState & rState,const::basegfx::B2DHomMatrix & rTextTransform)1088cdf0e10cSrcweir TextArrayAction::TextArrayAction( const ::basegfx::B2DPoint& rStartPoint, 1089cdf0e10cSrcweir const ::rtl::OUString& rString, 1090cdf0e10cSrcweir sal_Int32 nStartPos, 1091cdf0e10cSrcweir sal_Int32 nLen, 1092cdf0e10cSrcweir const uno::Sequence< double >& rOffsets, 1093cdf0e10cSrcweir const CanvasSharedPtr& rCanvas, 1094cdf0e10cSrcweir const OutDevState& rState, 1095cdf0e10cSrcweir const ::basegfx::B2DHomMatrix& rTextTransform ) : 1096cdf0e10cSrcweir mxTextLayout(), 1097cdf0e10cSrcweir mpCanvas( rCanvas ), 1098cdf0e10cSrcweir maState() 1099cdf0e10cSrcweir { 1100cdf0e10cSrcweir initArrayAction( maState, 1101cdf0e10cSrcweir mxTextLayout, 1102cdf0e10cSrcweir rStartPoint, 1103cdf0e10cSrcweir rString, 1104cdf0e10cSrcweir nStartPos, 1105cdf0e10cSrcweir nLen, 1106cdf0e10cSrcweir rOffsets, 1107cdf0e10cSrcweir rCanvas, 1108cdf0e10cSrcweir rState, 1109cdf0e10cSrcweir &rTextTransform ); 1110cdf0e10cSrcweir } 1111cdf0e10cSrcweir render(const::basegfx::B2DHomMatrix & rTransformation) const1112cdf0e10cSrcweir bool TextArrayAction::render( const ::basegfx::B2DHomMatrix& rTransformation ) const 1113cdf0e10cSrcweir { 1114cdf0e10cSrcweir RTL_LOGFILE_CONTEXT( aLog, "::cppcanvas::internal::TextArrayAction::render()" ); 1115cdf0e10cSrcweir RTL_LOGFILE_CONTEXT_TRACE1( aLog, "::cppcanvas::internal::TextArrayAction: 0x%X", this ); 1116cdf0e10cSrcweir 1117cdf0e10cSrcweir rendering::RenderState aLocalState( maState ); 1118cdf0e10cSrcweir ::canvas::tools::prependToRenderState(aLocalState, rTransformation); 1119cdf0e10cSrcweir 1120cdf0e10cSrcweir #ifdef SPECIAL_DEBUG 1121cdf0e10cSrcweir aLocalState.Clip.clear(); 1122cdf0e10cSrcweir aLocalState.DeviceColor = 1123cdf0e10cSrcweir ::vcl::unotools::colorToDoubleSequence( mpCanvas->getUNOCanvas()->getDevice(), 1124cdf0e10cSrcweir ::Color( 0x80FF0000 ) ); 1125cdf0e10cSrcweir 1126cdf0e10cSrcweir if( maState.Clip.is() ) 1127cdf0e10cSrcweir mpCanvas->getUNOCanvas()->drawPolyPolygon( maState.Clip, 1128cdf0e10cSrcweir mpCanvas->getViewState(), 1129cdf0e10cSrcweir aLocalState ); 1130cdf0e10cSrcweir 1131cdf0e10cSrcweir aLocalState.DeviceColor = maState.DeviceColor; 1132cdf0e10cSrcweir #endif 1133cdf0e10cSrcweir 1134cdf0e10cSrcweir mpCanvas->getUNOCanvas()->drawTextLayout( mxTextLayout, 1135cdf0e10cSrcweir mpCanvas->getViewState(), 1136cdf0e10cSrcweir aLocalState ); 1137cdf0e10cSrcweir 1138cdf0e10cSrcweir return true; 1139cdf0e10cSrcweir } 1140cdf0e10cSrcweir render(const::basegfx::B2DHomMatrix & rTransformation,const Subset & rSubset) const1141cdf0e10cSrcweir bool TextArrayAction::render( const ::basegfx::B2DHomMatrix& rTransformation, 1142cdf0e10cSrcweir const Subset& rSubset ) const 1143cdf0e10cSrcweir { 1144cdf0e10cSrcweir RTL_LOGFILE_CONTEXT( aLog, "::cppcanvas::internal::TextArrayAction::render( subset )" ); 1145cdf0e10cSrcweir RTL_LOGFILE_CONTEXT_TRACE1( aLog, "::cppcanvas::internal::TextArrayAction: 0x%X", this ); 1146cdf0e10cSrcweir 1147cdf0e10cSrcweir rendering::RenderState aLocalState( maState ); 1148cdf0e10cSrcweir uno::Reference< rendering::XTextLayout > xTextLayout( mxTextLayout ); 1149cdf0e10cSrcweir 1150cdf0e10cSrcweir double nDummy0, nDummy1; 1151cdf0e10cSrcweir createSubsetLayout( xTextLayout, 1152cdf0e10cSrcweir aLocalState, 1153cdf0e10cSrcweir nDummy0, 1154cdf0e10cSrcweir nDummy1, 1155cdf0e10cSrcweir rTransformation, 1156cdf0e10cSrcweir rSubset ); 1157cdf0e10cSrcweir 1158cdf0e10cSrcweir if( !xTextLayout.is() ) 1159cdf0e10cSrcweir return true; // empty layout, render nothing 1160cdf0e10cSrcweir 1161cdf0e10cSrcweir mpCanvas->getUNOCanvas()->drawTextLayout( xTextLayout, 1162cdf0e10cSrcweir mpCanvas->getViewState(), 1163cdf0e10cSrcweir aLocalState ); 1164cdf0e10cSrcweir 1165cdf0e10cSrcweir return true; 1166cdf0e10cSrcweir } 1167cdf0e10cSrcweir getBounds(const::basegfx::B2DHomMatrix & rTransformation) const1168cdf0e10cSrcweir ::basegfx::B2DRange TextArrayAction::getBounds( const ::basegfx::B2DHomMatrix& rTransformation ) const 1169cdf0e10cSrcweir { 1170cdf0e10cSrcweir rendering::RenderState aLocalState( maState ); 1171cdf0e10cSrcweir ::canvas::tools::prependToRenderState(aLocalState, rTransformation); 1172cdf0e10cSrcweir 1173cdf0e10cSrcweir return tools::calcDevicePixelBounds( ::basegfx::unotools::b2DRectangleFromRealRectangle2D( 1174cdf0e10cSrcweir mxTextLayout->queryTextBounds() ), 1175cdf0e10cSrcweir mpCanvas->getViewState(), 1176cdf0e10cSrcweir aLocalState ); 1177cdf0e10cSrcweir } 1178cdf0e10cSrcweir getBounds(const::basegfx::B2DHomMatrix & rTransformation,const Subset & rSubset) const1179cdf0e10cSrcweir ::basegfx::B2DRange TextArrayAction::getBounds( const ::basegfx::B2DHomMatrix& rTransformation, 1180cdf0e10cSrcweir const Subset& rSubset ) const 1181cdf0e10cSrcweir { 1182cdf0e10cSrcweir RTL_LOGFILE_CONTEXT( aLog, "::cppcanvas::internal::TextArrayAction::getBounds( subset )" ); 1183cdf0e10cSrcweir RTL_LOGFILE_CONTEXT_TRACE1( aLog, "::cppcanvas::internal::TextArrayAction: 0x%X", this ); 1184cdf0e10cSrcweir 1185cdf0e10cSrcweir rendering::RenderState aLocalState( maState ); 1186cdf0e10cSrcweir uno::Reference< rendering::XTextLayout > xTextLayout( mxTextLayout ); 1187cdf0e10cSrcweir 1188cdf0e10cSrcweir double nDummy0, nDummy1; 1189cdf0e10cSrcweir createSubsetLayout( xTextLayout, 1190cdf0e10cSrcweir aLocalState, 1191cdf0e10cSrcweir nDummy0, 1192cdf0e10cSrcweir nDummy1, 1193cdf0e10cSrcweir rTransformation, 1194cdf0e10cSrcweir rSubset ); 1195cdf0e10cSrcweir 1196cdf0e10cSrcweir if( !xTextLayout.is() ) 1197cdf0e10cSrcweir return ::basegfx::B2DRange(); // empty layout, empty bounds 1198cdf0e10cSrcweir 1199cdf0e10cSrcweir return tools::calcDevicePixelBounds( ::basegfx::unotools::b2DRectangleFromRealRectangle2D( 1200cdf0e10cSrcweir xTextLayout->queryTextBounds() ), 1201cdf0e10cSrcweir mpCanvas->getViewState(), 1202cdf0e10cSrcweir aLocalState ); 1203cdf0e10cSrcweir } 1204cdf0e10cSrcweir getActionCount() const1205cdf0e10cSrcweir sal_Int32 TextArrayAction::getActionCount() const 1206cdf0e10cSrcweir { 1207cdf0e10cSrcweir const rendering::StringContext& rOrigContext( mxTextLayout->getText() ); 1208cdf0e10cSrcweir 1209cdf0e10cSrcweir return rOrigContext.Length; 1210cdf0e10cSrcweir } 1211cdf0e10cSrcweir 1212cdf0e10cSrcweir 1213cdf0e10cSrcweir // ------------------------------------------------------------------------- 1214cdf0e10cSrcweir 1215cdf0e10cSrcweir class EffectTextArrayAction : 1216cdf0e10cSrcweir public Action, 1217cdf0e10cSrcweir public TextRenderer, 1218cdf0e10cSrcweir private ::boost::noncopyable 1219cdf0e10cSrcweir { 1220cdf0e10cSrcweir public: 1221cdf0e10cSrcweir EffectTextArrayAction( const ::basegfx::B2DPoint& rStartPoint, 1222cdf0e10cSrcweir const ::basegfx::B2DSize& rReliefOffset, 1223cdf0e10cSrcweir const ::Color& rReliefColor, 1224cdf0e10cSrcweir const ::basegfx::B2DSize& rShadowOffset, 1225cdf0e10cSrcweir const ::Color& rShadowColor, 1226cdf0e10cSrcweir const ::rtl::OUString& rText, 1227cdf0e10cSrcweir sal_Int32 nStartPos, 1228cdf0e10cSrcweir sal_Int32 nLen, 1229cdf0e10cSrcweir const uno::Sequence< double >& rOffsets, 1230cdf0e10cSrcweir VirtualDevice& rVDev, 1231cdf0e10cSrcweir const CanvasSharedPtr& rCanvas, 1232cdf0e10cSrcweir const OutDevState& rState ); 1233cdf0e10cSrcweir EffectTextArrayAction( const ::basegfx::B2DPoint& rStartPoint, 1234cdf0e10cSrcweir const ::basegfx::B2DSize& rReliefOffset, 1235cdf0e10cSrcweir const ::Color& rReliefColor, 1236cdf0e10cSrcweir const ::basegfx::B2DSize& rShadowOffset, 1237cdf0e10cSrcweir const ::Color& rShadowColor, 1238cdf0e10cSrcweir const ::rtl::OUString& rText, 1239cdf0e10cSrcweir sal_Int32 nStartPos, 1240cdf0e10cSrcweir sal_Int32 nLen, 1241cdf0e10cSrcweir const uno::Sequence< double >& rOffsets, 1242cdf0e10cSrcweir VirtualDevice& rVDev, 1243cdf0e10cSrcweir const CanvasSharedPtr& rCanvas, 1244cdf0e10cSrcweir const OutDevState& rState, 1245cdf0e10cSrcweir const ::basegfx::B2DHomMatrix& rTextTransform ); 1246cdf0e10cSrcweir 1247cdf0e10cSrcweir virtual bool render( const ::basegfx::B2DHomMatrix& rTransformation ) const; 1248cdf0e10cSrcweir virtual bool render( const ::basegfx::B2DHomMatrix& rTransformation, 1249cdf0e10cSrcweir const Subset& rSubset ) const; 1250cdf0e10cSrcweir 1251cdf0e10cSrcweir virtual ::basegfx::B2DRange getBounds( const ::basegfx::B2DHomMatrix& rTransformation ) const; 1252cdf0e10cSrcweir virtual ::basegfx::B2DRange getBounds( const ::basegfx::B2DHomMatrix& rTransformation, 1253cdf0e10cSrcweir const Subset& rSubset ) const; 1254cdf0e10cSrcweir 1255cdf0e10cSrcweir virtual sal_Int32 getActionCount() const; 1256cdf0e10cSrcweir 1257cdf0e10cSrcweir private: 1258cdf0e10cSrcweir // TextRenderer interface 1259cdf0e10cSrcweir virtual bool operator()( const rendering::RenderState& rRenderState ) const; 1260cdf0e10cSrcweir 1261cdf0e10cSrcweir // TODO(P2): This is potentially a real mass object 1262cdf0e10cSrcweir // (every character might be a separate TextAction), 1263cdf0e10cSrcweir // thus, make it as lightweight as possible. For 1264cdf0e10cSrcweir // example, share common RenderState among several 1265cdf0e10cSrcweir // TextActions, maybe using maOffsets for the 1266cdf0e10cSrcweir // translation. 1267cdf0e10cSrcweir 1268cdf0e10cSrcweir uno::Reference< rendering::XTextLayout > mxTextLayout; 1269cdf0e10cSrcweir const CanvasSharedPtr mpCanvas; 1270cdf0e10cSrcweir rendering::RenderState maState; 1271cdf0e10cSrcweir const tools::TextLineInfo maTextLineInfo; 1272cdf0e10cSrcweir ::basegfx::B2DSize maLinesOverallSize; 1273cdf0e10cSrcweir uno::Reference< rendering::XPolyPolygon2D > mxTextLines; 1274cdf0e10cSrcweir const ::basegfx::B2DSize maReliefOffset; 1275cdf0e10cSrcweir const ::Color maReliefColor; 1276cdf0e10cSrcweir const ::basegfx::B2DSize maShadowOffset; 1277cdf0e10cSrcweir const ::Color maShadowColor; 1278cdf0e10cSrcweir }; 1279cdf0e10cSrcweir EffectTextArrayAction(const::basegfx::B2DPoint & rStartPoint,const::basegfx::B2DSize & rReliefOffset,const::Color & rReliefColor,const::basegfx::B2DSize & rShadowOffset,const::Color & rShadowColor,const::rtl::OUString & rText,sal_Int32 nStartPos,sal_Int32 nLen,const uno::Sequence<double> & rOffsets,VirtualDevice & rVDev,const CanvasSharedPtr & rCanvas,const OutDevState & rState)1280cdf0e10cSrcweir EffectTextArrayAction::EffectTextArrayAction( const ::basegfx::B2DPoint& rStartPoint, 1281cdf0e10cSrcweir const ::basegfx::B2DSize& rReliefOffset, 1282cdf0e10cSrcweir const ::Color& rReliefColor, 1283cdf0e10cSrcweir const ::basegfx::B2DSize& rShadowOffset, 1284cdf0e10cSrcweir const ::Color& rShadowColor, 1285cdf0e10cSrcweir const ::rtl::OUString& rText, 1286cdf0e10cSrcweir sal_Int32 nStartPos, 1287cdf0e10cSrcweir sal_Int32 nLen, 1288cdf0e10cSrcweir const uno::Sequence< double >& rOffsets, 1289cdf0e10cSrcweir VirtualDevice& rVDev, 1290cdf0e10cSrcweir const CanvasSharedPtr& rCanvas, 1291cdf0e10cSrcweir const OutDevState& rState ) : 1292cdf0e10cSrcweir mxTextLayout(), 1293cdf0e10cSrcweir mpCanvas( rCanvas ), 1294cdf0e10cSrcweir maState(), 1295cdf0e10cSrcweir maTextLineInfo( tools::createTextLineInfo( rVDev, rState ) ), 1296cdf0e10cSrcweir maLinesOverallSize(), 1297cdf0e10cSrcweir mxTextLines(), 1298cdf0e10cSrcweir maReliefOffset( rReliefOffset ), 1299cdf0e10cSrcweir maReliefColor( rReliefColor ), 1300cdf0e10cSrcweir maShadowOffset( rShadowOffset ), 1301cdf0e10cSrcweir maShadowColor( rShadowColor ) 1302cdf0e10cSrcweir { 1303cdf0e10cSrcweir initEffectLinePolyPolygon( maLinesOverallSize, 1304cdf0e10cSrcweir mxTextLines, 1305cdf0e10cSrcweir rCanvas, 1306cdf0e10cSrcweir rOffsets, 1307cdf0e10cSrcweir maTextLineInfo ); 1308cdf0e10cSrcweir 1309cdf0e10cSrcweir initArrayAction( maState, 1310cdf0e10cSrcweir mxTextLayout, 1311cdf0e10cSrcweir rStartPoint, 1312cdf0e10cSrcweir rText, 1313cdf0e10cSrcweir nStartPos, 1314cdf0e10cSrcweir nLen, 1315cdf0e10cSrcweir rOffsets, 1316cdf0e10cSrcweir rCanvas, 1317cdf0e10cSrcweir rState, NULL ); 1318cdf0e10cSrcweir } 1319cdf0e10cSrcweir EffectTextArrayAction(const::basegfx::B2DPoint & rStartPoint,const::basegfx::B2DSize & rReliefOffset,const::Color & rReliefColor,const::basegfx::B2DSize & rShadowOffset,const::Color & rShadowColor,const::rtl::OUString & rText,sal_Int32 nStartPos,sal_Int32 nLen,const uno::Sequence<double> & rOffsets,VirtualDevice & rVDev,const CanvasSharedPtr & rCanvas,const OutDevState & rState,const::basegfx::B2DHomMatrix & rTextTransform)1320cdf0e10cSrcweir EffectTextArrayAction::EffectTextArrayAction( const ::basegfx::B2DPoint& rStartPoint, 1321cdf0e10cSrcweir const ::basegfx::B2DSize& rReliefOffset, 1322cdf0e10cSrcweir const ::Color& rReliefColor, 1323cdf0e10cSrcweir const ::basegfx::B2DSize& rShadowOffset, 1324cdf0e10cSrcweir const ::Color& rShadowColor, 1325cdf0e10cSrcweir const ::rtl::OUString& rText, 1326cdf0e10cSrcweir sal_Int32 nStartPos, 1327cdf0e10cSrcweir sal_Int32 nLen, 1328cdf0e10cSrcweir const uno::Sequence< double >& rOffsets, 1329cdf0e10cSrcweir VirtualDevice& rVDev, 1330cdf0e10cSrcweir const CanvasSharedPtr& rCanvas, 1331cdf0e10cSrcweir const OutDevState& rState, 1332cdf0e10cSrcweir const ::basegfx::B2DHomMatrix& rTextTransform ) : 1333cdf0e10cSrcweir mxTextLayout(), 1334cdf0e10cSrcweir mpCanvas( rCanvas ), 1335cdf0e10cSrcweir maState(), 1336cdf0e10cSrcweir maTextLineInfo( tools::createTextLineInfo( rVDev, rState ) ), 1337cdf0e10cSrcweir maLinesOverallSize(), 1338cdf0e10cSrcweir mxTextLines(), 1339cdf0e10cSrcweir maReliefOffset( rReliefOffset ), 1340cdf0e10cSrcweir maReliefColor( rReliefColor ), 1341cdf0e10cSrcweir maShadowOffset( rShadowOffset ), 1342cdf0e10cSrcweir maShadowColor( rShadowColor ) 1343cdf0e10cSrcweir { 1344cdf0e10cSrcweir initEffectLinePolyPolygon( maLinesOverallSize, 1345cdf0e10cSrcweir mxTextLines, 1346cdf0e10cSrcweir rCanvas, 1347cdf0e10cSrcweir rOffsets, 1348cdf0e10cSrcweir maTextLineInfo ); 1349cdf0e10cSrcweir 1350cdf0e10cSrcweir initArrayAction( maState, 1351cdf0e10cSrcweir mxTextLayout, 1352cdf0e10cSrcweir rStartPoint, 1353cdf0e10cSrcweir rText, 1354cdf0e10cSrcweir nStartPos, 1355cdf0e10cSrcweir nLen, 1356cdf0e10cSrcweir rOffsets, 1357cdf0e10cSrcweir rCanvas, 1358cdf0e10cSrcweir rState, 1359cdf0e10cSrcweir &rTextTransform ); 1360cdf0e10cSrcweir } 1361cdf0e10cSrcweir operator ()(const rendering::RenderState & rRenderState) const1362cdf0e10cSrcweir bool EffectTextArrayAction::operator()( const rendering::RenderState& rRenderState ) const 1363cdf0e10cSrcweir { 1364cdf0e10cSrcweir const rendering::ViewState& rViewState( mpCanvas->getViewState() ); 1365cdf0e10cSrcweir const uno::Reference< rendering::XCanvas >& rCanvas( mpCanvas->getUNOCanvas() ); 1366cdf0e10cSrcweir 1367cdf0e10cSrcweir rCanvas->fillPolyPolygon( mxTextLines, 1368cdf0e10cSrcweir rViewState, 1369cdf0e10cSrcweir rRenderState ); 1370cdf0e10cSrcweir 1371cdf0e10cSrcweir rCanvas->drawTextLayout( mxTextLayout, 1372cdf0e10cSrcweir rViewState, 1373cdf0e10cSrcweir rRenderState ); 1374cdf0e10cSrcweir 1375cdf0e10cSrcweir return true; 1376cdf0e10cSrcweir } 1377cdf0e10cSrcweir render(const::basegfx::B2DHomMatrix & rTransformation) const1378cdf0e10cSrcweir bool EffectTextArrayAction::render( const ::basegfx::B2DHomMatrix& rTransformation ) const 1379cdf0e10cSrcweir { 1380cdf0e10cSrcweir RTL_LOGFILE_CONTEXT( aLog, "::cppcanvas::internal::EffectTextArrayAction::render()" ); 1381cdf0e10cSrcweir RTL_LOGFILE_CONTEXT_TRACE1( aLog, "::cppcanvas::internal::EffectTextArrayAction: 0x%X", this ); 1382cdf0e10cSrcweir 1383cdf0e10cSrcweir rendering::RenderState aLocalState( maState ); 1384cdf0e10cSrcweir ::canvas::tools::prependToRenderState(aLocalState, rTransformation); 1385cdf0e10cSrcweir 1386cdf0e10cSrcweir return renderEffectText( *this, 1387cdf0e10cSrcweir aLocalState, 1388cdf0e10cSrcweir mpCanvas->getViewState(), 1389cdf0e10cSrcweir mpCanvas->getUNOCanvas(), 1390cdf0e10cSrcweir maShadowColor, 1391cdf0e10cSrcweir maShadowOffset, 1392cdf0e10cSrcweir maReliefColor, 1393cdf0e10cSrcweir maReliefOffset ); 1394cdf0e10cSrcweir } 1395cdf0e10cSrcweir 1396cdf0e10cSrcweir class EffectTextArrayRenderHelper : public TextRenderer 1397cdf0e10cSrcweir { 1398cdf0e10cSrcweir public: EffectTextArrayRenderHelper(const uno::Reference<rendering::XCanvas> & rCanvas,const uno::Reference<rendering::XTextLayout> & rTextLayout,const uno::Reference<rendering::XPolyPolygon2D> & rLinePolygon,const rendering::ViewState & rViewState)1399cdf0e10cSrcweir EffectTextArrayRenderHelper( const uno::Reference< rendering::XCanvas >& rCanvas, 1400cdf0e10cSrcweir const uno::Reference< rendering::XTextLayout >& rTextLayout, 1401cdf0e10cSrcweir const uno::Reference< rendering::XPolyPolygon2D >& rLinePolygon, 1402cdf0e10cSrcweir const rendering::ViewState& rViewState ) : 1403cdf0e10cSrcweir mrCanvas( rCanvas ), 1404cdf0e10cSrcweir mrTextLayout( rTextLayout ), 1405cdf0e10cSrcweir mrLinePolygon( rLinePolygon ), 1406cdf0e10cSrcweir mrViewState( rViewState ) 1407cdf0e10cSrcweir { 1408cdf0e10cSrcweir } 1409cdf0e10cSrcweir 1410cdf0e10cSrcweir // TextRenderer interface operator ()(const rendering::RenderState & rRenderState) const1411cdf0e10cSrcweir virtual bool operator()( const rendering::RenderState& rRenderState ) const 1412cdf0e10cSrcweir { 1413cdf0e10cSrcweir mrCanvas->fillPolyPolygon( mrLinePolygon, 1414cdf0e10cSrcweir mrViewState, 1415cdf0e10cSrcweir rRenderState ); 1416cdf0e10cSrcweir 1417cdf0e10cSrcweir mrCanvas->drawTextLayout( mrTextLayout, 1418cdf0e10cSrcweir mrViewState, 1419cdf0e10cSrcweir rRenderState ); 1420cdf0e10cSrcweir 1421cdf0e10cSrcweir return true; 1422cdf0e10cSrcweir } 1423cdf0e10cSrcweir 1424cdf0e10cSrcweir private: 1425cdf0e10cSrcweir const uno::Reference< rendering::XCanvas >& mrCanvas; 1426cdf0e10cSrcweir const uno::Reference< rendering::XTextLayout >& mrTextLayout; 1427cdf0e10cSrcweir const uno::Reference< rendering::XPolyPolygon2D >& mrLinePolygon; 1428cdf0e10cSrcweir const rendering::ViewState& mrViewState; 1429cdf0e10cSrcweir }; 1430cdf0e10cSrcweir render(const::basegfx::B2DHomMatrix & rTransformation,const Subset & rSubset) const1431cdf0e10cSrcweir bool EffectTextArrayAction::render( const ::basegfx::B2DHomMatrix& rTransformation, 1432cdf0e10cSrcweir const Subset& rSubset ) const 1433cdf0e10cSrcweir { 1434cdf0e10cSrcweir RTL_LOGFILE_CONTEXT( aLog, "::cppcanvas::internal::EffectTextArrayAction::render( subset )" ); 1435cdf0e10cSrcweir RTL_LOGFILE_CONTEXT_TRACE1( aLog, "::cppcanvas::internal::EffectTextArrayAction: 0x%X", this ); 1436cdf0e10cSrcweir 1437cdf0e10cSrcweir rendering::RenderState aLocalState( maState ); 1438cdf0e10cSrcweir uno::Reference< rendering::XTextLayout > xTextLayout( mxTextLayout ); 1439cdf0e10cSrcweir const geometry::RealRectangle2D aTextBounds( mxTextLayout->queryTextBounds() ); 1440cdf0e10cSrcweir 1441cdf0e10cSrcweir double nMinPos(0.0); 1442cdf0e10cSrcweir double nMaxPos(aTextBounds.X2 - aTextBounds.X1); 1443cdf0e10cSrcweir 1444cdf0e10cSrcweir createSubsetLayout( xTextLayout, 1445cdf0e10cSrcweir aLocalState, 1446cdf0e10cSrcweir nMinPos, 1447cdf0e10cSrcweir nMaxPos, 1448cdf0e10cSrcweir rTransformation, 1449cdf0e10cSrcweir rSubset ); 1450cdf0e10cSrcweir 1451cdf0e10cSrcweir if( !xTextLayout.is() ) 1452cdf0e10cSrcweir return true; // empty layout, render nothing 1453cdf0e10cSrcweir 1454cdf0e10cSrcweir 1455cdf0e10cSrcweir // create and setup local line polygon 1456cdf0e10cSrcweir // =================================== 1457cdf0e10cSrcweir 1458cdf0e10cSrcweir uno::Reference< rendering::XCanvas > xCanvas( mpCanvas->getUNOCanvas() ); 1459cdf0e10cSrcweir const rendering::ViewState& rViewState( mpCanvas->getViewState() ); 1460cdf0e10cSrcweir 1461cdf0e10cSrcweir uno::Reference< rendering::XPolyPolygon2D > xTextLines( 1462cdf0e10cSrcweir ::basegfx::unotools::xPolyPolygonFromB2DPolyPolygon( 1463cdf0e10cSrcweir xCanvas->getDevice(), 1464cdf0e10cSrcweir tools::createTextLinesPolyPolygon( 1465cdf0e10cSrcweir 0.0, nMaxPos - nMinPos, 1466cdf0e10cSrcweir maTextLineInfo ) ) ); 1467cdf0e10cSrcweir 1468cdf0e10cSrcweir 1469cdf0e10cSrcweir // render everything 1470cdf0e10cSrcweir // ================= 1471cdf0e10cSrcweir 1472cdf0e10cSrcweir return renderEffectText( 1473cdf0e10cSrcweir EffectTextArrayRenderHelper( xCanvas, 1474cdf0e10cSrcweir xTextLayout, 1475cdf0e10cSrcweir xTextLines, 1476cdf0e10cSrcweir rViewState ), 1477cdf0e10cSrcweir aLocalState, 1478cdf0e10cSrcweir rViewState, 1479cdf0e10cSrcweir xCanvas, 1480cdf0e10cSrcweir maShadowColor, 1481cdf0e10cSrcweir maShadowOffset, 1482cdf0e10cSrcweir maReliefColor, 1483cdf0e10cSrcweir maReliefOffset ); 1484cdf0e10cSrcweir } 1485cdf0e10cSrcweir getBounds(const::basegfx::B2DHomMatrix & rTransformation) const1486cdf0e10cSrcweir ::basegfx::B2DRange EffectTextArrayAction::getBounds( const ::basegfx::B2DHomMatrix& rTransformation ) const 1487cdf0e10cSrcweir { 1488cdf0e10cSrcweir rendering::RenderState aLocalState( maState ); 1489cdf0e10cSrcweir ::canvas::tools::prependToRenderState(aLocalState, rTransformation); 1490cdf0e10cSrcweir 1491cdf0e10cSrcweir return calcEffectTextBounds( ::basegfx::unotools::b2DRectangleFromRealRectangle2D( 1492cdf0e10cSrcweir mxTextLayout->queryTextBounds() ), 1493cdf0e10cSrcweir ::basegfx::B2DRange( 0,0, 1494cdf0e10cSrcweir maLinesOverallSize.getX(), 1495cdf0e10cSrcweir maLinesOverallSize.getY() ), 1496cdf0e10cSrcweir maReliefOffset, 1497cdf0e10cSrcweir maShadowOffset, 1498cdf0e10cSrcweir aLocalState, 1499cdf0e10cSrcweir mpCanvas->getViewState() ); 1500cdf0e10cSrcweir } 1501cdf0e10cSrcweir getBounds(const::basegfx::B2DHomMatrix & rTransformation,const Subset & rSubset) const1502cdf0e10cSrcweir ::basegfx::B2DRange EffectTextArrayAction::getBounds( const ::basegfx::B2DHomMatrix& rTransformation, 1503cdf0e10cSrcweir const Subset& rSubset ) const 1504cdf0e10cSrcweir { 1505cdf0e10cSrcweir RTL_LOGFILE_CONTEXT( aLog, "::cppcanvas::internal::EffectTextArrayAction::getBounds( subset )" ); 1506cdf0e10cSrcweir RTL_LOGFILE_CONTEXT_TRACE1( aLog, "::cppcanvas::internal::EffectTextArrayAction: 0x%X", this ); 1507cdf0e10cSrcweir 1508cdf0e10cSrcweir rendering::RenderState aLocalState( maState ); 1509cdf0e10cSrcweir uno::Reference< rendering::XTextLayout > xTextLayout( mxTextLayout ); 1510cdf0e10cSrcweir const geometry::RealRectangle2D aTextBounds( mxTextLayout->queryTextBounds() ); 1511cdf0e10cSrcweir 1512cdf0e10cSrcweir double nMinPos(0.0); 1513cdf0e10cSrcweir double nMaxPos(aTextBounds.X2 - aTextBounds.X1); 1514cdf0e10cSrcweir 1515cdf0e10cSrcweir createSubsetLayout( xTextLayout, 1516cdf0e10cSrcweir aLocalState, 1517cdf0e10cSrcweir nMinPos, 1518cdf0e10cSrcweir nMaxPos, 1519cdf0e10cSrcweir rTransformation, 1520cdf0e10cSrcweir rSubset ); 1521cdf0e10cSrcweir 1522cdf0e10cSrcweir if( !xTextLayout.is() ) 1523cdf0e10cSrcweir return ::basegfx::B2DRange(); // empty layout, empty bounds 1524cdf0e10cSrcweir 1525cdf0e10cSrcweir 1526cdf0e10cSrcweir // create and setup local line polygon 1527cdf0e10cSrcweir // =================================== 1528cdf0e10cSrcweir 1529cdf0e10cSrcweir const ::basegfx::B2DPolyPolygon aPoly( 1530cdf0e10cSrcweir tools::createTextLinesPolyPolygon( 1531cdf0e10cSrcweir 0.0, nMaxPos - nMinPos, 1532cdf0e10cSrcweir maTextLineInfo ) ); 1533cdf0e10cSrcweir 1534cdf0e10cSrcweir return calcEffectTextBounds( ::basegfx::unotools::b2DRectangleFromRealRectangle2D( 1535cdf0e10cSrcweir xTextLayout->queryTextBounds() ), 1536cdf0e10cSrcweir ::basegfx::tools::getRange( aPoly ), 1537cdf0e10cSrcweir maReliefOffset, 1538cdf0e10cSrcweir maShadowOffset, 1539cdf0e10cSrcweir aLocalState, 1540cdf0e10cSrcweir mpCanvas->getViewState() ); 1541cdf0e10cSrcweir } 1542cdf0e10cSrcweir getActionCount() const1543cdf0e10cSrcweir sal_Int32 EffectTextArrayAction::getActionCount() const 1544cdf0e10cSrcweir { 1545cdf0e10cSrcweir const rendering::StringContext& rOrigContext( mxTextLayout->getText() ); 1546cdf0e10cSrcweir 1547cdf0e10cSrcweir return rOrigContext.Length; 1548cdf0e10cSrcweir } 1549cdf0e10cSrcweir 1550cdf0e10cSrcweir 1551cdf0e10cSrcweir // ------------------------------------------------------------------------- 1552cdf0e10cSrcweir 1553cdf0e10cSrcweir class OutlineAction : 1554cdf0e10cSrcweir public Action, 1555cdf0e10cSrcweir public TextRenderer, 1556cdf0e10cSrcweir private ::boost::noncopyable 1557cdf0e10cSrcweir { 1558cdf0e10cSrcweir public: 1559cdf0e10cSrcweir OutlineAction( const ::basegfx::B2DPoint& rStartPoint, 1560cdf0e10cSrcweir const ::basegfx::B2DSize& rReliefOffset, 1561cdf0e10cSrcweir const ::Color& rReliefColor, 1562cdf0e10cSrcweir const ::basegfx::B2DSize& rShadowOffset, 1563cdf0e10cSrcweir const ::Color& rShadowColor, 1564cdf0e10cSrcweir const ::basegfx::B2DRectangle& rOutlineBounds, 1565cdf0e10cSrcweir const uno::Reference< rendering::XPolyPolygon2D >& rTextPoly, 1566cdf0e10cSrcweir const ::std::vector< sal_Int32 >& rPolygonGlyphMap, 1567cdf0e10cSrcweir const uno::Sequence< double >& rOffsets, 1568cdf0e10cSrcweir VirtualDevice& rVDev, 1569cdf0e10cSrcweir const CanvasSharedPtr& rCanvas, 1570cdf0e10cSrcweir const OutDevState& rState ); 1571cdf0e10cSrcweir OutlineAction( const ::basegfx::B2DPoint& rStartPoint, 1572cdf0e10cSrcweir const ::basegfx::B2DSize& rReliefOffset, 1573cdf0e10cSrcweir const ::Color& rReliefColor, 1574cdf0e10cSrcweir const ::basegfx::B2DSize& rShadowOffset, 1575cdf0e10cSrcweir const ::Color& rShadowColor, 1576cdf0e10cSrcweir const ::basegfx::B2DRectangle& rOutlineBounds, 1577cdf0e10cSrcweir const uno::Reference< rendering::XPolyPolygon2D >& rTextPoly, 1578cdf0e10cSrcweir const ::std::vector< sal_Int32 >& rPolygonGlyphMap, 1579cdf0e10cSrcweir const uno::Sequence< double >& rOffsets, 1580cdf0e10cSrcweir VirtualDevice& rVDev, 1581cdf0e10cSrcweir const CanvasSharedPtr& rCanvas, 1582cdf0e10cSrcweir const OutDevState& rState, 1583cdf0e10cSrcweir const ::basegfx::B2DHomMatrix& rTextTransform ); 1584cdf0e10cSrcweir 1585cdf0e10cSrcweir virtual bool render( const ::basegfx::B2DHomMatrix& rTransformation ) const; 1586cdf0e10cSrcweir virtual bool render( const ::basegfx::B2DHomMatrix& rTransformation, 1587cdf0e10cSrcweir const Subset& rSubset ) const; 1588cdf0e10cSrcweir 1589cdf0e10cSrcweir virtual ::basegfx::B2DRange getBounds( const ::basegfx::B2DHomMatrix& rTransformation ) const; 1590cdf0e10cSrcweir virtual ::basegfx::B2DRange getBounds( const ::basegfx::B2DHomMatrix& rTransformation, 1591cdf0e10cSrcweir const Subset& rSubset ) const; 1592cdf0e10cSrcweir 1593cdf0e10cSrcweir virtual sal_Int32 getActionCount() const; 1594cdf0e10cSrcweir 1595cdf0e10cSrcweir private: 1596cdf0e10cSrcweir // TextRenderer interface 1597cdf0e10cSrcweir virtual bool operator()( const rendering::RenderState& rRenderState ) const; 1598cdf0e10cSrcweir 1599cdf0e10cSrcweir // TODO(P2): This is potentially a real mass object 1600cdf0e10cSrcweir // (every character might be a separate TextAction), 1601cdf0e10cSrcweir // thus, make it as lightweight as possible. For 1602cdf0e10cSrcweir // example, share common RenderState among several 1603cdf0e10cSrcweir // TextActions, maybe using maOffsets for the 1604cdf0e10cSrcweir // translation. 1605cdf0e10cSrcweir 1606cdf0e10cSrcweir uno::Reference< rendering::XPolyPolygon2D > mxTextPoly; 1607cdf0e10cSrcweir 1608cdf0e10cSrcweir /** This vector denotes the index of the start polygon 1609cdf0e10cSrcweir for the respective glyph sequence. 1610cdf0e10cSrcweir 1611cdf0e10cSrcweir To get a polygon index range for a given character 1612cdf0e10cSrcweir index i, take [ maPolygonGlyphMap[i], 1613cdf0e10cSrcweir maPolygonGlyphMap[i+1] ). Note that this is wrong 1614cdf0e10cSrcweir for BiDi 1615cdf0e10cSrcweir */ 1616cdf0e10cSrcweir const ::std::vector< sal_Int32 > maPolygonGlyphMap; 1617cdf0e10cSrcweir const uno::Sequence< double > maOffsets; 1618cdf0e10cSrcweir const CanvasSharedPtr mpCanvas; 1619cdf0e10cSrcweir rendering::RenderState maState; 1620cdf0e10cSrcweir double mnOutlineWidth; 1621cdf0e10cSrcweir const uno::Sequence< double > maFillColor; 1622cdf0e10cSrcweir const tools::TextLineInfo maTextLineInfo; 1623cdf0e10cSrcweir ::basegfx::B2DSize maLinesOverallSize; 1624cdf0e10cSrcweir const ::basegfx::B2DRectangle maOutlineBounds; 1625cdf0e10cSrcweir uno::Reference< rendering::XPolyPolygon2D > mxTextLines; 1626cdf0e10cSrcweir const ::basegfx::B2DSize maReliefOffset; 1627cdf0e10cSrcweir const ::Color maReliefColor; 1628cdf0e10cSrcweir const ::basegfx::B2DSize maShadowOffset; 1629cdf0e10cSrcweir const ::Color maShadowColor; 1630cdf0e10cSrcweir }; 1631cdf0e10cSrcweir calcOutlineWidth(const OutDevState & rState,VirtualDevice & rVDev)1632cdf0e10cSrcweir double calcOutlineWidth( const OutDevState& rState, 1633cdf0e10cSrcweir VirtualDevice& rVDev ) 1634cdf0e10cSrcweir { 1635cdf0e10cSrcweir const ::basegfx::B2DSize aFontSize( 0, 1636cdf0e10cSrcweir rVDev.GetFont().GetHeight() / 64.0 ); 1637cdf0e10cSrcweir 1638cdf0e10cSrcweir const double nOutlineWidth( 1639cdf0e10cSrcweir (rState.mapModeTransform * aFontSize).getY() ); 1640cdf0e10cSrcweir 1641cdf0e10cSrcweir return nOutlineWidth < 1.0 ? 1.0 : nOutlineWidth; 1642cdf0e10cSrcweir } 1643cdf0e10cSrcweir OutlineAction(const::basegfx::B2DPoint & rStartPoint,const::basegfx::B2DSize & rReliefOffset,const::Color & rReliefColor,const::basegfx::B2DSize & rShadowOffset,const::Color & rShadowColor,const::basegfx::B2DRectangle & rOutlineBounds,const uno::Reference<rendering::XPolyPolygon2D> & rTextPoly,const::std::vector<sal_Int32> & rPolygonGlyphMap,const uno::Sequence<double> & rOffsets,VirtualDevice & rVDev,const CanvasSharedPtr & rCanvas,const OutDevState & rState)1644cdf0e10cSrcweir OutlineAction::OutlineAction( const ::basegfx::B2DPoint& rStartPoint, 1645cdf0e10cSrcweir const ::basegfx::B2DSize& rReliefOffset, 1646cdf0e10cSrcweir const ::Color& rReliefColor, 1647cdf0e10cSrcweir const ::basegfx::B2DSize& rShadowOffset, 1648cdf0e10cSrcweir const ::Color& rShadowColor, 1649cdf0e10cSrcweir const ::basegfx::B2DRectangle& rOutlineBounds, 1650cdf0e10cSrcweir const uno::Reference< rendering::XPolyPolygon2D >& rTextPoly, 1651cdf0e10cSrcweir const ::std::vector< sal_Int32 >& rPolygonGlyphMap, 1652cdf0e10cSrcweir const uno::Sequence< double >& rOffsets, 1653cdf0e10cSrcweir VirtualDevice& rVDev, 1654cdf0e10cSrcweir const CanvasSharedPtr& rCanvas, 1655cdf0e10cSrcweir const OutDevState& rState ) : 1656cdf0e10cSrcweir mxTextPoly( rTextPoly ), 1657cdf0e10cSrcweir maPolygonGlyphMap( rPolygonGlyphMap ), 1658cdf0e10cSrcweir maOffsets( rOffsets ), 1659cdf0e10cSrcweir mpCanvas( rCanvas ), 1660cdf0e10cSrcweir maState(), 1661cdf0e10cSrcweir mnOutlineWidth( calcOutlineWidth(rState,rVDev) ), 1662cdf0e10cSrcweir maFillColor( 1663cdf0e10cSrcweir ::vcl::unotools::colorToDoubleSequence( 1664cdf0e10cSrcweir ::Color( COL_WHITE ), 1665cdf0e10cSrcweir rCanvas->getUNOCanvas()->getDevice()->getDeviceColorSpace() )), 1666cdf0e10cSrcweir maTextLineInfo( tools::createTextLineInfo( rVDev, rState ) ), 1667cdf0e10cSrcweir maLinesOverallSize(), 1668cdf0e10cSrcweir maOutlineBounds( rOutlineBounds ), 1669cdf0e10cSrcweir mxTextLines(), 1670cdf0e10cSrcweir maReliefOffset( rReliefOffset ), 1671cdf0e10cSrcweir maReliefColor( rReliefColor ), 1672cdf0e10cSrcweir maShadowOffset( rShadowOffset ), 1673cdf0e10cSrcweir maShadowColor( rShadowColor ) 1674cdf0e10cSrcweir { 1675cdf0e10cSrcweir initEffectLinePolyPolygon( maLinesOverallSize, 1676cdf0e10cSrcweir mxTextLines, 1677cdf0e10cSrcweir rCanvas, 1678cdf0e10cSrcweir rOffsets, 1679cdf0e10cSrcweir maTextLineInfo ); 1680cdf0e10cSrcweir 1681cdf0e10cSrcweir init( maState, 1682cdf0e10cSrcweir rStartPoint, 1683cdf0e10cSrcweir rState, 1684cdf0e10cSrcweir rCanvas ); 1685cdf0e10cSrcweir } 1686cdf0e10cSrcweir OutlineAction(const::basegfx::B2DPoint & rStartPoint,const::basegfx::B2DSize & rReliefOffset,const::Color & rReliefColor,const::basegfx::B2DSize & rShadowOffset,const::Color & rShadowColor,const::basegfx::B2DRectangle & rOutlineBounds,const uno::Reference<rendering::XPolyPolygon2D> & rTextPoly,const::std::vector<sal_Int32> & rPolygonGlyphMap,const uno::Sequence<double> & rOffsets,VirtualDevice & rVDev,const CanvasSharedPtr & rCanvas,const OutDevState & rState,const::basegfx::B2DHomMatrix & rTextTransform)1687cdf0e10cSrcweir OutlineAction::OutlineAction( const ::basegfx::B2DPoint& rStartPoint, 1688cdf0e10cSrcweir const ::basegfx::B2DSize& rReliefOffset, 1689cdf0e10cSrcweir const ::Color& rReliefColor, 1690cdf0e10cSrcweir const ::basegfx::B2DSize& rShadowOffset, 1691cdf0e10cSrcweir const ::Color& rShadowColor, 1692cdf0e10cSrcweir const ::basegfx::B2DRectangle& rOutlineBounds, 1693cdf0e10cSrcweir const uno::Reference< rendering::XPolyPolygon2D >& rTextPoly, 1694cdf0e10cSrcweir const ::std::vector< sal_Int32 >& rPolygonGlyphMap, 1695cdf0e10cSrcweir const uno::Sequence< double >& rOffsets, 1696cdf0e10cSrcweir VirtualDevice& rVDev, 1697cdf0e10cSrcweir const CanvasSharedPtr& rCanvas, 1698cdf0e10cSrcweir const OutDevState& rState, 1699cdf0e10cSrcweir const ::basegfx::B2DHomMatrix& rTextTransform ) : 1700cdf0e10cSrcweir mxTextPoly( rTextPoly ), 1701cdf0e10cSrcweir maPolygonGlyphMap( rPolygonGlyphMap ), 1702cdf0e10cSrcweir maOffsets( rOffsets ), 1703cdf0e10cSrcweir mpCanvas( rCanvas ), 1704cdf0e10cSrcweir maState(), 1705cdf0e10cSrcweir mnOutlineWidth( calcOutlineWidth(rState,rVDev) ), 1706cdf0e10cSrcweir maFillColor( 1707cdf0e10cSrcweir ::vcl::unotools::colorToDoubleSequence( 1708cdf0e10cSrcweir ::Color( COL_WHITE ), 1709cdf0e10cSrcweir rCanvas->getUNOCanvas()->getDevice()->getDeviceColorSpace() )), 1710cdf0e10cSrcweir maTextLineInfo( tools::createTextLineInfo( rVDev, rState ) ), 1711cdf0e10cSrcweir maLinesOverallSize(), 1712cdf0e10cSrcweir maOutlineBounds( rOutlineBounds ), 1713cdf0e10cSrcweir mxTextLines(), 1714cdf0e10cSrcweir maReliefOffset( rReliefOffset ), 1715cdf0e10cSrcweir maReliefColor( rReliefColor ), 1716cdf0e10cSrcweir maShadowOffset( rShadowOffset ), 1717cdf0e10cSrcweir maShadowColor( rShadowColor ) 1718cdf0e10cSrcweir { 1719cdf0e10cSrcweir initEffectLinePolyPolygon( maLinesOverallSize, 1720cdf0e10cSrcweir mxTextLines, 1721cdf0e10cSrcweir rCanvas, 1722cdf0e10cSrcweir rOffsets, 1723cdf0e10cSrcweir maTextLineInfo ); 1724cdf0e10cSrcweir 1725cdf0e10cSrcweir init( maState, 1726cdf0e10cSrcweir rStartPoint, 1727cdf0e10cSrcweir rState, 1728cdf0e10cSrcweir rCanvas, 1729cdf0e10cSrcweir rTextTransform ); 1730cdf0e10cSrcweir } 1731cdf0e10cSrcweir operator ()(const rendering::RenderState & rRenderState) const1732cdf0e10cSrcweir bool OutlineAction::operator()( const rendering::RenderState& rRenderState ) const 1733cdf0e10cSrcweir { 1734cdf0e10cSrcweir const rendering::ViewState& rViewState( mpCanvas->getViewState() ); 1735cdf0e10cSrcweir const uno::Reference< rendering::XCanvas >& rCanvas( mpCanvas->getUNOCanvas() ); 1736cdf0e10cSrcweir 1737cdf0e10cSrcweir rendering::StrokeAttributes aStrokeAttributes; 1738cdf0e10cSrcweir 1739cdf0e10cSrcweir aStrokeAttributes.StrokeWidth = mnOutlineWidth; 1740cdf0e10cSrcweir aStrokeAttributes.MiterLimit = 1.0; 1741cdf0e10cSrcweir aStrokeAttributes.StartCapType = rendering::PathCapType::BUTT; 1742cdf0e10cSrcweir aStrokeAttributes.EndCapType = rendering::PathCapType::BUTT; 1743cdf0e10cSrcweir aStrokeAttributes.JoinType = rendering::PathJoinType::MITER; 1744cdf0e10cSrcweir 1745cdf0e10cSrcweir rendering::RenderState aLocalState( rRenderState ); 1746cdf0e10cSrcweir aLocalState.DeviceColor = maFillColor; 1747cdf0e10cSrcweir 1748cdf0e10cSrcweir // TODO(P1): implement caching 1749cdf0e10cSrcweir 1750cdf0e10cSrcweir // background of text 1751cdf0e10cSrcweir rCanvas->fillPolyPolygon( mxTextPoly, 1752cdf0e10cSrcweir rViewState, 1753cdf0e10cSrcweir aLocalState ); 1754cdf0e10cSrcweir 1755cdf0e10cSrcweir // border line of text 1756cdf0e10cSrcweir rCanvas->strokePolyPolygon( mxTextPoly, 1757cdf0e10cSrcweir rViewState, 1758cdf0e10cSrcweir rRenderState, 1759cdf0e10cSrcweir aStrokeAttributes ); 1760cdf0e10cSrcweir 1761cdf0e10cSrcweir // underlines/strikethrough - background 1762cdf0e10cSrcweir rCanvas->fillPolyPolygon( mxTextLines, 1763cdf0e10cSrcweir rViewState, 1764cdf0e10cSrcweir aLocalState ); 1765cdf0e10cSrcweir // underlines/strikethrough - border 1766cdf0e10cSrcweir rCanvas->strokePolyPolygon( mxTextLines, 1767cdf0e10cSrcweir rViewState, 1768cdf0e10cSrcweir rRenderState, 1769cdf0e10cSrcweir aStrokeAttributes ); 1770cdf0e10cSrcweir 1771cdf0e10cSrcweir return true; 1772cdf0e10cSrcweir } 1773cdf0e10cSrcweir render(const::basegfx::B2DHomMatrix & rTransformation) const1774cdf0e10cSrcweir bool OutlineAction::render( const ::basegfx::B2DHomMatrix& rTransformation ) const 1775cdf0e10cSrcweir { 1776cdf0e10cSrcweir RTL_LOGFILE_CONTEXT( aLog, "::cppcanvas::internal::EffectTextArrayAction::render()" ); 1777cdf0e10cSrcweir RTL_LOGFILE_CONTEXT_TRACE1( aLog, "::cppcanvas::internal::EffectTextArrayAction: 0x%X", this ); 1778cdf0e10cSrcweir 1779cdf0e10cSrcweir rendering::RenderState aLocalState( maState ); 1780cdf0e10cSrcweir ::canvas::tools::prependToRenderState(aLocalState, rTransformation); 1781cdf0e10cSrcweir 1782cdf0e10cSrcweir return renderEffectText( *this, 1783cdf0e10cSrcweir aLocalState, 1784cdf0e10cSrcweir mpCanvas->getViewState(), 1785cdf0e10cSrcweir mpCanvas->getUNOCanvas(), 1786cdf0e10cSrcweir maShadowColor, 1787cdf0e10cSrcweir maShadowOffset, 1788cdf0e10cSrcweir maReliefColor, 1789cdf0e10cSrcweir maReliefOffset ); 1790cdf0e10cSrcweir } 1791cdf0e10cSrcweir 1792cdf0e10cSrcweir class OutlineTextArrayRenderHelper : public TextRenderer 1793cdf0e10cSrcweir { 1794cdf0e10cSrcweir public: OutlineTextArrayRenderHelper(const uno::Reference<rendering::XCanvas> & rCanvas,const uno::Reference<rendering::XPolyPolygon2D> & rTextPolygon,const uno::Reference<rendering::XPolyPolygon2D> & rLinePolygon,const rendering::ViewState & rViewState,double nOutlineWidth)1795cdf0e10cSrcweir OutlineTextArrayRenderHelper( const uno::Reference< rendering::XCanvas >& rCanvas, 1796cdf0e10cSrcweir const uno::Reference< rendering::XPolyPolygon2D >& rTextPolygon, 1797cdf0e10cSrcweir const uno::Reference< rendering::XPolyPolygon2D >& rLinePolygon, 1798cdf0e10cSrcweir const rendering::ViewState& rViewState, 1799cdf0e10cSrcweir double nOutlineWidth ) : 1800cdf0e10cSrcweir maFillColor( 1801cdf0e10cSrcweir ::vcl::unotools::colorToDoubleSequence( 1802cdf0e10cSrcweir ::Color( COL_WHITE ), 1803cdf0e10cSrcweir rCanvas->getDevice()->getDeviceColorSpace() )), 1804cdf0e10cSrcweir mnOutlineWidth( nOutlineWidth ), 1805cdf0e10cSrcweir mrCanvas( rCanvas ), 1806cdf0e10cSrcweir mrTextPolygon( rTextPolygon ), 1807cdf0e10cSrcweir mrLinePolygon( rLinePolygon ), 1808cdf0e10cSrcweir mrViewState( rViewState ) 1809cdf0e10cSrcweir { 1810cdf0e10cSrcweir } 1811cdf0e10cSrcweir 1812cdf0e10cSrcweir // TextRenderer interface operator ()(const rendering::RenderState & rRenderState) const1813cdf0e10cSrcweir virtual bool operator()( const rendering::RenderState& rRenderState ) const 1814cdf0e10cSrcweir { 1815cdf0e10cSrcweir rendering::StrokeAttributes aStrokeAttributes; 1816cdf0e10cSrcweir 1817cdf0e10cSrcweir aStrokeAttributes.StrokeWidth = mnOutlineWidth; 1818cdf0e10cSrcweir aStrokeAttributes.MiterLimit = 1.0; 1819cdf0e10cSrcweir aStrokeAttributes.StartCapType = rendering::PathCapType::BUTT; 1820cdf0e10cSrcweir aStrokeAttributes.EndCapType = rendering::PathCapType::BUTT; 1821cdf0e10cSrcweir aStrokeAttributes.JoinType = rendering::PathJoinType::MITER; 1822cdf0e10cSrcweir 1823cdf0e10cSrcweir rendering::RenderState aLocalState( rRenderState ); 1824cdf0e10cSrcweir aLocalState.DeviceColor = maFillColor; 1825cdf0e10cSrcweir 1826cdf0e10cSrcweir // TODO(P1): implement caching 1827cdf0e10cSrcweir 1828cdf0e10cSrcweir // background of text 1829cdf0e10cSrcweir mrCanvas->fillPolyPolygon( mrTextPolygon, 1830cdf0e10cSrcweir mrViewState, 1831cdf0e10cSrcweir aLocalState ); 1832cdf0e10cSrcweir 1833cdf0e10cSrcweir // border line of text 1834cdf0e10cSrcweir mrCanvas->strokePolyPolygon( mrTextPolygon, 1835cdf0e10cSrcweir mrViewState, 1836cdf0e10cSrcweir rRenderState, 1837cdf0e10cSrcweir aStrokeAttributes ); 1838cdf0e10cSrcweir 1839cdf0e10cSrcweir // underlines/strikethrough - background 1840cdf0e10cSrcweir mrCanvas->fillPolyPolygon( mrLinePolygon, 1841cdf0e10cSrcweir mrViewState, 1842cdf0e10cSrcweir aLocalState ); 1843cdf0e10cSrcweir // underlines/strikethrough - border 1844cdf0e10cSrcweir mrCanvas->strokePolyPolygon( mrLinePolygon, 1845cdf0e10cSrcweir mrViewState, 1846cdf0e10cSrcweir rRenderState, 1847cdf0e10cSrcweir aStrokeAttributes ); 1848cdf0e10cSrcweir 1849cdf0e10cSrcweir return true; 1850cdf0e10cSrcweir } 1851cdf0e10cSrcweir 1852cdf0e10cSrcweir private: 1853cdf0e10cSrcweir const uno::Sequence< double > maFillColor; 1854cdf0e10cSrcweir double mnOutlineWidth; 1855cdf0e10cSrcweir const uno::Reference< rendering::XCanvas >& mrCanvas; 1856cdf0e10cSrcweir const uno::Reference< rendering::XPolyPolygon2D >& mrTextPolygon; 1857cdf0e10cSrcweir const uno::Reference< rendering::XPolyPolygon2D >& mrLinePolygon; 1858cdf0e10cSrcweir const rendering::ViewState& mrViewState; 1859cdf0e10cSrcweir }; 1860cdf0e10cSrcweir render(const::basegfx::B2DHomMatrix & rTransformation,const Subset & rSubset) const1861cdf0e10cSrcweir bool OutlineAction::render( const ::basegfx::B2DHomMatrix& rTransformation, 1862cdf0e10cSrcweir const Subset& rSubset ) const 1863cdf0e10cSrcweir { 1864cdf0e10cSrcweir RTL_LOGFILE_CONTEXT( aLog, "::cppcanvas::internal::OutlineAction::render( subset )" ); 1865cdf0e10cSrcweir RTL_LOGFILE_CONTEXT_TRACE1( aLog, "::cppcanvas::internal::OutlineAction: 0x%X", this ); 1866cdf0e10cSrcweir 1867cdf0e10cSrcweir if( rSubset.mnSubsetBegin == rSubset.mnSubsetEnd ) 1868cdf0e10cSrcweir return true; // empty range, render nothing 1869cdf0e10cSrcweir 1870cdf0e10cSrcweir #if 1 1871cdf0e10cSrcweir // TODO(F3): Subsetting NYI for outline text! 1872cdf0e10cSrcweir return render( rTransformation ); 1873cdf0e10cSrcweir #else 1874cdf0e10cSrcweir const rendering::StringContext rOrigContext( mxTextLayout->getText() ); 1875cdf0e10cSrcweir 1876cdf0e10cSrcweir if( rSubset.mnSubsetBegin == 0 && 1877cdf0e10cSrcweir rSubset.mnSubsetEnd == rOrigContext.Length ) 1878cdf0e10cSrcweir { 1879cdf0e10cSrcweir // full range, no need for subsetting 1880cdf0e10cSrcweir return render( rTransformation ); 1881cdf0e10cSrcweir } 1882cdf0e10cSrcweir 1883cdf0e10cSrcweir rendering::RenderState aLocalState( maState ); 1884cdf0e10cSrcweir ::canvas::tools::prependToRenderState(aLocalState, rTransformation); 1885cdf0e10cSrcweir 1886cdf0e10cSrcweir 1887cdf0e10cSrcweir // create and setup local Text polygon 1888cdf0e10cSrcweir // =================================== 1889cdf0e10cSrcweir 1890cdf0e10cSrcweir uno::Reference< rendering::XPolyPolygon2D > xTextPolygon(); 1891cdf0e10cSrcweir 1892cdf0e10cSrcweir // TODO(P3): Provide an API method for that! 1893cdf0e10cSrcweir 1894cdf0e10cSrcweir if( !xTextLayout.is() ) 1895cdf0e10cSrcweir return false; 1896cdf0e10cSrcweir 1897cdf0e10cSrcweir // render everything 1898cdf0e10cSrcweir // ================= 1899cdf0e10cSrcweir 1900cdf0e10cSrcweir return renderEffectText( 1901cdf0e10cSrcweir OutlineTextArrayRenderHelper( 1902cdf0e10cSrcweir xCanvas, 1903cdf0e10cSrcweir mnOutlineWidth, 1904cdf0e10cSrcweir xTextLayout, 1905cdf0e10cSrcweir xTextLines, 1906cdf0e10cSrcweir rViewState ), 1907cdf0e10cSrcweir aLocalState, 1908cdf0e10cSrcweir rViewState, 1909cdf0e10cSrcweir xCanvas, 1910cdf0e10cSrcweir maShadowColor, 1911cdf0e10cSrcweir maShadowOffset, 1912cdf0e10cSrcweir maReliefColor, 1913cdf0e10cSrcweir maReliefOffset ); 1914cdf0e10cSrcweir #endif 1915cdf0e10cSrcweir } 1916cdf0e10cSrcweir getBounds(const::basegfx::B2DHomMatrix & rTransformation) const1917cdf0e10cSrcweir ::basegfx::B2DRange OutlineAction::getBounds( const ::basegfx::B2DHomMatrix& rTransformation ) const 1918cdf0e10cSrcweir { 1919cdf0e10cSrcweir rendering::RenderState aLocalState( maState ); 1920cdf0e10cSrcweir ::canvas::tools::prependToRenderState(aLocalState, rTransformation); 1921cdf0e10cSrcweir 1922cdf0e10cSrcweir return calcEffectTextBounds( maOutlineBounds, 1923cdf0e10cSrcweir ::basegfx::B2DRange( 0,0, 1924cdf0e10cSrcweir maLinesOverallSize.getX(), 1925cdf0e10cSrcweir maLinesOverallSize.getY() ), 1926cdf0e10cSrcweir maReliefOffset, 1927cdf0e10cSrcweir maShadowOffset, 1928cdf0e10cSrcweir aLocalState, 1929cdf0e10cSrcweir mpCanvas->getViewState() ); 1930cdf0e10cSrcweir } 1931cdf0e10cSrcweir getBounds(const::basegfx::B2DHomMatrix & rTransformation,const Subset &) const1932cdf0e10cSrcweir ::basegfx::B2DRange OutlineAction::getBounds( const ::basegfx::B2DHomMatrix& rTransformation, 1933cdf0e10cSrcweir const Subset& /*rSubset*/ ) const 1934cdf0e10cSrcweir { 1935cdf0e10cSrcweir OSL_ENSURE( false, 1936cdf0e10cSrcweir "OutlineAction::getBounds(): Subset not yet supported by this object" ); 1937cdf0e10cSrcweir 1938cdf0e10cSrcweir return getBounds( rTransformation ); 1939cdf0e10cSrcweir } 1940cdf0e10cSrcweir getActionCount() const1941cdf0e10cSrcweir sal_Int32 OutlineAction::getActionCount() const 1942cdf0e10cSrcweir { 1943cdf0e10cSrcweir // TODO(F3): Subsetting NYI for outline text! 1944cdf0e10cSrcweir return maOffsets.getLength(); 1945cdf0e10cSrcweir } 1946cdf0e10cSrcweir 1947cdf0e10cSrcweir 1948cdf0e10cSrcweir // ====================================================================== 1949cdf0e10cSrcweir // 1950cdf0e10cSrcweir // Action factory methods 1951cdf0e10cSrcweir // 1952cdf0e10cSrcweir // ====================================================================== 1953cdf0e10cSrcweir 1954cdf0e10cSrcweir /** Create an outline action 1955cdf0e10cSrcweir 1956cdf0e10cSrcweir This method extracts the polygonal outline from the 1957cdf0e10cSrcweir text, and creates a properly setup OutlineAction from 1958cdf0e10cSrcweir it. 1959cdf0e10cSrcweir */ createOutline(const::basegfx::B2DPoint & rStartPoint,const::basegfx::B2DSize & rReliefOffset,const::Color & rReliefColor,const::basegfx::B2DSize & rShadowOffset,const::Color & rShadowColor,const String & rText,sal_Int32 nStartPos,sal_Int32 nLen,const sal_Int32 * pDXArray,VirtualDevice & rVDev,const CanvasSharedPtr & rCanvas,const OutDevState & rState,const Renderer::Parameters & rParms)1960cdf0e10cSrcweir ActionSharedPtr createOutline( const ::basegfx::B2DPoint& rStartPoint, 1961cdf0e10cSrcweir const ::basegfx::B2DSize& rReliefOffset, 1962cdf0e10cSrcweir const ::Color& rReliefColor, 1963cdf0e10cSrcweir const ::basegfx::B2DSize& rShadowOffset, 1964cdf0e10cSrcweir const ::Color& rShadowColor, 1965cdf0e10cSrcweir const String& rText, 1966cdf0e10cSrcweir sal_Int32 nStartPos, 1967cdf0e10cSrcweir sal_Int32 nLen, 1968cdf0e10cSrcweir const sal_Int32* pDXArray, 1969cdf0e10cSrcweir VirtualDevice& rVDev, 1970cdf0e10cSrcweir const CanvasSharedPtr& rCanvas, 1971cdf0e10cSrcweir const OutDevState& rState, 1972cdf0e10cSrcweir const Renderer::Parameters& rParms ) 1973cdf0e10cSrcweir { 1974cdf0e10cSrcweir // operate on raw DX array here (in logical coordinate 1975cdf0e10cSrcweir // system), to have a higher resolution 1976cdf0e10cSrcweir // PolyPolygon. That polygon is then converted to 1977cdf0e10cSrcweir // device coordinate system. 1978cdf0e10cSrcweir 1979cdf0e10cSrcweir // #i68512# Temporarily switch off font rotation 1980cdf0e10cSrcweir // (which is already contained in the render state 1981cdf0e10cSrcweir // transformation matrix - otherwise, glyph polygons 1982cdf0e10cSrcweir // will be rotated twice) 1983cdf0e10cSrcweir const ::Font aOrigFont( rVDev.GetFont() ); 1984cdf0e10cSrcweir ::Font aUnrotatedFont( aOrigFont ); 1985cdf0e10cSrcweir aUnrotatedFont.SetOrientation(0); 1986cdf0e10cSrcweir rVDev.SetFont( aUnrotatedFont ); 1987cdf0e10cSrcweir 1988cdf0e10cSrcweir // TODO(F3): Don't understand parameter semantics of 1989cdf0e10cSrcweir // GetTextOutlines() 1990cdf0e10cSrcweir ::basegfx::B2DPolyPolygon aResultingPolyPolygon; 1991cdf0e10cSrcweir PolyPolyVector aVCLPolyPolyVector; 1992cdf0e10cSrcweir const bool bHaveOutlines( rVDev.GetTextOutlines( aVCLPolyPolyVector, rText, 1993cdf0e10cSrcweir static_cast<sal_uInt16>(nStartPos), 1994cdf0e10cSrcweir static_cast<sal_uInt16>(nStartPos), 1995cdf0e10cSrcweir static_cast<sal_uInt16>(nLen), 1996cdf0e10cSrcweir sal_True, 0, pDXArray ) ); 1997cdf0e10cSrcweir rVDev.SetFont(aOrigFont); 1998cdf0e10cSrcweir 1999cdf0e10cSrcweir if( !bHaveOutlines ) 2000cdf0e10cSrcweir return ActionSharedPtr(); 2001cdf0e10cSrcweir 2002cdf0e10cSrcweir ::std::vector< sal_Int32 > aPolygonGlyphMap; 2003cdf0e10cSrcweir 2004cdf0e10cSrcweir // first glyph starts at polygon index 0 2005cdf0e10cSrcweir aPolygonGlyphMap.push_back( 0 ); 2006cdf0e10cSrcweir 2007cdf0e10cSrcweir // remove offsetting from mapmode transformation 2008cdf0e10cSrcweir // (outline polygons must stay at origin, only need to 2009cdf0e10cSrcweir // be scaled) 2010cdf0e10cSrcweir ::basegfx::B2DHomMatrix aMapModeTransform( 2011cdf0e10cSrcweir rState.mapModeTransform ); 2012cdf0e10cSrcweir aMapModeTransform.set(0,2, 0.0); 2013cdf0e10cSrcweir aMapModeTransform.set(1,2, 0.0); 2014cdf0e10cSrcweir 2015cdf0e10cSrcweir PolyPolyVector::const_iterator aIter( aVCLPolyPolyVector.begin() ); 2016cdf0e10cSrcweir const PolyPolyVector::const_iterator aEnd( aVCLPolyPolyVector.end() ); 2017cdf0e10cSrcweir for( ; aIter!= aEnd; ++aIter ) 2018cdf0e10cSrcweir { 2019cdf0e10cSrcweir ::basegfx::B2DPolyPolygon aPolyPolygon; 2020cdf0e10cSrcweir 2021cdf0e10cSrcweir aPolyPolygon = aIter->getB2DPolyPolygon(); 2022cdf0e10cSrcweir aPolyPolygon.transform( aMapModeTransform ); 2023cdf0e10cSrcweir 2024cdf0e10cSrcweir // append result to collecting polypoly 2025cdf0e10cSrcweir for( sal_uInt32 i=0; i<aPolyPolygon.count(); ++i ) 2026cdf0e10cSrcweir { 2027cdf0e10cSrcweir // #i47795# Ensure closed polygons (since 2028cdf0e10cSrcweir // FreeType returns the glyph outlines 2029cdf0e10cSrcweir // open) 2030cdf0e10cSrcweir const ::basegfx::B2DPolygon& rPoly( aPolyPolygon.getB2DPolygon( i ) ); 2031cdf0e10cSrcweir const sal_uInt32 nCount( rPoly.count() ); 2032cdf0e10cSrcweir if( nCount<3 || 2033cdf0e10cSrcweir rPoly.isClosed() ) 2034cdf0e10cSrcweir { 2035cdf0e10cSrcweir // polygon either degenerate, or 2036cdf0e10cSrcweir // already closed. 2037cdf0e10cSrcweir aResultingPolyPolygon.append( rPoly ); 2038cdf0e10cSrcweir } 2039cdf0e10cSrcweir else 2040cdf0e10cSrcweir { 2041cdf0e10cSrcweir ::basegfx::B2DPolygon aPoly(rPoly); 2042cdf0e10cSrcweir aPoly.setClosed(true); 2043cdf0e10cSrcweir 2044cdf0e10cSrcweir aResultingPolyPolygon.append( aPoly ); 2045cdf0e10cSrcweir } 2046cdf0e10cSrcweir } 2047cdf0e10cSrcweir 2048cdf0e10cSrcweir // TODO(F3): Depending on the semantics of 2049cdf0e10cSrcweir // GetTextOutlines(), this here is wrong! 2050cdf0e10cSrcweir 2051cdf0e10cSrcweir // calc next glyph index 2052cdf0e10cSrcweir aPolygonGlyphMap.push_back( aResultingPolyPolygon.count() ); 2053cdf0e10cSrcweir } 2054cdf0e10cSrcweir 2055cdf0e10cSrcweir const uno::Sequence< double > aCharWidthSeq( 2056cdf0e10cSrcweir pDXArray ? 2057cdf0e10cSrcweir setupDXArray( pDXArray, nLen, rState ) : 2058cdf0e10cSrcweir setupDXArray( rText, 2059cdf0e10cSrcweir nStartPos, 2060cdf0e10cSrcweir nLen, 2061cdf0e10cSrcweir rVDev, 2062cdf0e10cSrcweir rState )); 2063cdf0e10cSrcweir const uno::Reference< rendering::XPolyPolygon2D > xTextPoly( 2064cdf0e10cSrcweir ::basegfx::unotools::xPolyPolygonFromB2DPolyPolygon( 2065cdf0e10cSrcweir rCanvas->getUNOCanvas()->getDevice(), 2066cdf0e10cSrcweir aResultingPolyPolygon ) ); 2067cdf0e10cSrcweir 2068cdf0e10cSrcweir if( rParms.maTextTransformation.is_initialized() ) 2069cdf0e10cSrcweir { 2070cdf0e10cSrcweir return ActionSharedPtr( 2071cdf0e10cSrcweir new OutlineAction( 2072cdf0e10cSrcweir rStartPoint, 2073cdf0e10cSrcweir rReliefOffset, 2074cdf0e10cSrcweir rReliefColor, 2075cdf0e10cSrcweir rShadowOffset, 2076cdf0e10cSrcweir rShadowColor, 2077cdf0e10cSrcweir ::basegfx::tools::getRange(aResultingPolyPolygon), 2078cdf0e10cSrcweir xTextPoly, 2079cdf0e10cSrcweir aPolygonGlyphMap, 2080cdf0e10cSrcweir aCharWidthSeq, 2081cdf0e10cSrcweir rVDev, 2082cdf0e10cSrcweir rCanvas, 2083cdf0e10cSrcweir rState, 2084cdf0e10cSrcweir *rParms.maTextTransformation ) ); 2085cdf0e10cSrcweir } 2086cdf0e10cSrcweir else 2087cdf0e10cSrcweir { 2088cdf0e10cSrcweir return ActionSharedPtr( 2089cdf0e10cSrcweir new OutlineAction( 2090cdf0e10cSrcweir rStartPoint, 2091cdf0e10cSrcweir rReliefOffset, 2092cdf0e10cSrcweir rReliefColor, 2093cdf0e10cSrcweir rShadowOffset, 2094cdf0e10cSrcweir rShadowColor, 2095cdf0e10cSrcweir ::basegfx::tools::getRange(aResultingPolyPolygon), 2096cdf0e10cSrcweir xTextPoly, 2097cdf0e10cSrcweir aPolygonGlyphMap, 2098cdf0e10cSrcweir aCharWidthSeq, 2099cdf0e10cSrcweir rVDev, 2100cdf0e10cSrcweir rCanvas, 2101cdf0e10cSrcweir rState ) ); 2102cdf0e10cSrcweir } 2103cdf0e10cSrcweir } 2104cdf0e10cSrcweir 2105cdf0e10cSrcweir } // namespace 2106cdf0e10cSrcweir 2107cdf0e10cSrcweir 2108cdf0e10cSrcweir // --------------------------------------------------------------------------------- 2109cdf0e10cSrcweir createTextAction(const::Point & rStartPoint,const::Size & rReliefOffset,const::Color & rReliefColor,const::Size & rShadowOffset,const::Color & rShadowColor,const String & rText,sal_Int32 nStartPos,sal_Int32 nLen,const sal_Int32 * pDXArray,VirtualDevice & rVDev,const CanvasSharedPtr & rCanvas,const OutDevState & rState,const Renderer::Parameters & rParms,bool bSubsettable)2110cdf0e10cSrcweir ActionSharedPtr TextActionFactory::createTextAction( const ::Point& rStartPoint, 2111cdf0e10cSrcweir const ::Size& rReliefOffset, 2112cdf0e10cSrcweir const ::Color& rReliefColor, 2113cdf0e10cSrcweir const ::Size& rShadowOffset, 2114cdf0e10cSrcweir const ::Color& rShadowColor, 2115cdf0e10cSrcweir const String& rText, 2116cdf0e10cSrcweir sal_Int32 nStartPos, 2117cdf0e10cSrcweir sal_Int32 nLen, 2118cdf0e10cSrcweir const sal_Int32* pDXArray, 2119cdf0e10cSrcweir VirtualDevice& rVDev, 2120cdf0e10cSrcweir const CanvasSharedPtr& rCanvas, 2121cdf0e10cSrcweir const OutDevState& rState, 2122cdf0e10cSrcweir const Renderer::Parameters& rParms, 2123cdf0e10cSrcweir bool bSubsettable ) 2124cdf0e10cSrcweir { 2125cdf0e10cSrcweir const ::Size aBaselineOffset( tools::getBaselineOffset( rState, 2126cdf0e10cSrcweir rVDev ) ); 2127cdf0e10cSrcweir // #143885# maintain (nearly) full precision positioning, 2128cdf0e10cSrcweir // by circumventing integer-based OutDev-mapping 2129cdf0e10cSrcweir const ::basegfx::B2DPoint aStartPoint( 2130cdf0e10cSrcweir rState.mapModeTransform * 2131cdf0e10cSrcweir ::basegfx::B2DPoint(rStartPoint.X() + aBaselineOffset.Width(), 2132cdf0e10cSrcweir rStartPoint.Y() + aBaselineOffset.Height()) ); 2133cdf0e10cSrcweir 2134cdf0e10cSrcweir const ::basegfx::B2DSize aReliefOffset( 2135cdf0e10cSrcweir rState.mapModeTransform * ::vcl::unotools::b2DSizeFromSize( rReliefOffset ) ); 2136cdf0e10cSrcweir const ::basegfx::B2DSize aShadowOffset( 2137cdf0e10cSrcweir rState.mapModeTransform * ::vcl::unotools::b2DSizeFromSize( rShadowOffset ) ); 2138cdf0e10cSrcweir 2139cdf0e10cSrcweir if( rState.isTextOutlineModeSet ) 2140cdf0e10cSrcweir { 2141cdf0e10cSrcweir return createOutline( 2142cdf0e10cSrcweir aStartPoint, 2143cdf0e10cSrcweir aReliefOffset, 2144cdf0e10cSrcweir rReliefColor, 2145cdf0e10cSrcweir aShadowOffset, 2146cdf0e10cSrcweir rShadowColor, 2147cdf0e10cSrcweir rText, 2148cdf0e10cSrcweir nStartPos, 2149cdf0e10cSrcweir nLen, 2150cdf0e10cSrcweir pDXArray, 2151cdf0e10cSrcweir rVDev, 2152cdf0e10cSrcweir rCanvas, 2153cdf0e10cSrcweir rState, 2154cdf0e10cSrcweir rParms ); 2155cdf0e10cSrcweir } 2156cdf0e10cSrcweir 2157cdf0e10cSrcweir // convert DX array to device coordinate system (and 2158cdf0e10cSrcweir // create it in the first place, if pDXArray is NULL) 2159cdf0e10cSrcweir const uno::Sequence< double > aCharWidths( 2160cdf0e10cSrcweir pDXArray ? 2161cdf0e10cSrcweir setupDXArray( pDXArray, nLen, rState ) : 2162cdf0e10cSrcweir setupDXArray( rText, 2163cdf0e10cSrcweir nStartPos, 2164cdf0e10cSrcweir nLen, 2165cdf0e10cSrcweir rVDev, 2166cdf0e10cSrcweir rState )); 2167cdf0e10cSrcweir 2168cdf0e10cSrcweir // determine type of text action to create 2169cdf0e10cSrcweir // ======================================= 2170cdf0e10cSrcweir 2171cdf0e10cSrcweir const ::Color aEmptyColor( COL_AUTO ); 2172cdf0e10cSrcweir 2173cdf0e10cSrcweir // no DX array, and no need to subset - no need to store 2174cdf0e10cSrcweir // DX array, then. 2175cdf0e10cSrcweir if( !pDXArray && !bSubsettable ) 2176cdf0e10cSrcweir { 2177cdf0e10cSrcweir // effects, or not? 2178cdf0e10cSrcweir if( !rState.textOverlineStyle && 2179cdf0e10cSrcweir !rState.textUnderlineStyle && 2180cdf0e10cSrcweir !rState.textStrikeoutStyle && 2181cdf0e10cSrcweir rReliefColor == aEmptyColor && 2182cdf0e10cSrcweir rShadowColor == aEmptyColor ) 2183cdf0e10cSrcweir { 2184cdf0e10cSrcweir // nope 2185cdf0e10cSrcweir if( rParms.maTextTransformation.is_initialized() ) 2186cdf0e10cSrcweir { 2187cdf0e10cSrcweir return ActionSharedPtr( new TextAction( 2188cdf0e10cSrcweir aStartPoint, 2189cdf0e10cSrcweir rText, 2190cdf0e10cSrcweir nStartPos, 2191cdf0e10cSrcweir nLen, 2192cdf0e10cSrcweir rCanvas, 2193cdf0e10cSrcweir rState, 2194cdf0e10cSrcweir *rParms.maTextTransformation ) ); 2195cdf0e10cSrcweir } 2196cdf0e10cSrcweir else 2197cdf0e10cSrcweir { 2198cdf0e10cSrcweir return ActionSharedPtr( new TextAction( 2199cdf0e10cSrcweir aStartPoint, 2200cdf0e10cSrcweir rText, 2201cdf0e10cSrcweir nStartPos, 2202cdf0e10cSrcweir nLen, 2203cdf0e10cSrcweir rCanvas, 2204cdf0e10cSrcweir rState ) ); 2205cdf0e10cSrcweir } 2206cdf0e10cSrcweir } 2207cdf0e10cSrcweir else 2208cdf0e10cSrcweir { 2209cdf0e10cSrcweir // at least one of the effects requested 2210cdf0e10cSrcweir if( rParms.maTextTransformation.is_initialized() ) 2211cdf0e10cSrcweir return ActionSharedPtr( new EffectTextAction( 2212cdf0e10cSrcweir aStartPoint, 2213cdf0e10cSrcweir aReliefOffset, 2214cdf0e10cSrcweir rReliefColor, 2215cdf0e10cSrcweir aShadowOffset, 2216cdf0e10cSrcweir rShadowColor, 2217cdf0e10cSrcweir rText, 2218cdf0e10cSrcweir nStartPos, 2219cdf0e10cSrcweir nLen, 2220cdf0e10cSrcweir rVDev, 2221cdf0e10cSrcweir rCanvas, 2222cdf0e10cSrcweir rState, 2223cdf0e10cSrcweir *rParms.maTextTransformation ) ); 2224cdf0e10cSrcweir else 2225cdf0e10cSrcweir return ActionSharedPtr( new EffectTextAction( 2226cdf0e10cSrcweir aStartPoint, 2227cdf0e10cSrcweir aReliefOffset, 2228cdf0e10cSrcweir rReliefColor, 2229cdf0e10cSrcweir aShadowOffset, 2230cdf0e10cSrcweir rShadowColor, 2231cdf0e10cSrcweir rText, 2232cdf0e10cSrcweir nStartPos, 2233cdf0e10cSrcweir nLen, 2234cdf0e10cSrcweir rVDev, 2235cdf0e10cSrcweir rCanvas, 2236cdf0e10cSrcweir rState ) ); 2237cdf0e10cSrcweir } 2238cdf0e10cSrcweir } 2239cdf0e10cSrcweir else 2240cdf0e10cSrcweir { 2241cdf0e10cSrcweir // DX array necessary - any effects? 2242cdf0e10cSrcweir if( !rState.textOverlineStyle && 2243cdf0e10cSrcweir !rState.textUnderlineStyle && 2244cdf0e10cSrcweir !rState.textStrikeoutStyle && 2245cdf0e10cSrcweir rReliefColor == aEmptyColor && 2246cdf0e10cSrcweir rShadowColor == aEmptyColor ) 2247cdf0e10cSrcweir { 2248cdf0e10cSrcweir // nope 2249cdf0e10cSrcweir if( rParms.maTextTransformation.is_initialized() ) 2250cdf0e10cSrcweir return ActionSharedPtr( new TextArrayAction( 2251cdf0e10cSrcweir aStartPoint, 2252cdf0e10cSrcweir rText, 2253cdf0e10cSrcweir nStartPos, 2254cdf0e10cSrcweir nLen, 2255cdf0e10cSrcweir aCharWidths, 2256cdf0e10cSrcweir rCanvas, 2257cdf0e10cSrcweir rState, 2258cdf0e10cSrcweir *rParms.maTextTransformation ) ); 2259cdf0e10cSrcweir else 2260cdf0e10cSrcweir return ActionSharedPtr( new TextArrayAction( 2261cdf0e10cSrcweir aStartPoint, 2262cdf0e10cSrcweir rText, 2263cdf0e10cSrcweir nStartPos, 2264cdf0e10cSrcweir nLen, 2265cdf0e10cSrcweir aCharWidths, 2266cdf0e10cSrcweir rCanvas, 2267cdf0e10cSrcweir rState ) ); 2268cdf0e10cSrcweir } 2269cdf0e10cSrcweir else 2270cdf0e10cSrcweir { 2271cdf0e10cSrcweir // at least one of the effects requested 2272cdf0e10cSrcweir if( rParms.maTextTransformation.is_initialized() ) 2273cdf0e10cSrcweir return ActionSharedPtr( new EffectTextArrayAction( 2274cdf0e10cSrcweir aStartPoint, 2275cdf0e10cSrcweir aReliefOffset, 2276cdf0e10cSrcweir rReliefColor, 2277cdf0e10cSrcweir aShadowOffset, 2278cdf0e10cSrcweir rShadowColor, 2279cdf0e10cSrcweir rText, 2280cdf0e10cSrcweir nStartPos, 2281cdf0e10cSrcweir nLen, 2282cdf0e10cSrcweir aCharWidths, 2283cdf0e10cSrcweir rVDev, 2284cdf0e10cSrcweir rCanvas, 2285cdf0e10cSrcweir rState, 2286cdf0e10cSrcweir *rParms.maTextTransformation ) ); 2287cdf0e10cSrcweir else 2288cdf0e10cSrcweir return ActionSharedPtr( new EffectTextArrayAction( 2289cdf0e10cSrcweir aStartPoint, 2290cdf0e10cSrcweir aReliefOffset, 2291cdf0e10cSrcweir rReliefColor, 2292cdf0e10cSrcweir aShadowOffset, 2293cdf0e10cSrcweir rShadowColor, 2294cdf0e10cSrcweir rText, 2295cdf0e10cSrcweir nStartPos, 2296cdf0e10cSrcweir nLen, 2297cdf0e10cSrcweir aCharWidths, 2298cdf0e10cSrcweir rVDev, 2299cdf0e10cSrcweir rCanvas, 2300cdf0e10cSrcweir rState ) ); 2301cdf0e10cSrcweir } 2302cdf0e10cSrcweir } 2303cdf0e10cSrcweir #if defined __GNUC__ 2304cdf0e10cSrcweir #if __GNUC__ == 4 && __GNUC_MINOR__ >= 1 2305cdf0e10cSrcweir // Unreachable; to avoid bogus warning: 2306cdf0e10cSrcweir return ActionSharedPtr(); 2307cdf0e10cSrcweir #endif 2308cdf0e10cSrcweir #endif 2309cdf0e10cSrcweir } 2310cdf0e10cSrcweir } 2311cdf0e10cSrcweir } 2312