1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 29*cdf0e10cSrcweir #include "precompiled_sdext.hxx" 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir #include "pdfiprocessor.hxx" 32*cdf0e10cSrcweir #include "xmlemitter.hxx" 33*cdf0e10cSrcweir #include "pdfihelper.hxx" 34*cdf0e10cSrcweir #include "imagecontainer.hxx" 35*cdf0e10cSrcweir #include "style.hxx" 36*cdf0e10cSrcweir #include "drawtreevisiting.hxx" 37*cdf0e10cSrcweir #include "genericelements.hxx" 38*cdf0e10cSrcweir 39*cdf0e10cSrcweir #include "basegfx/polygon/b2dpolypolygontools.hxx" 40*cdf0e10cSrcweir #include "basegfx/range/b2drange.hxx" 41*cdf0e10cSrcweir 42*cdf0e10cSrcweir #include "com/sun/star/i18n/XBreakIterator.hpp" 43*cdf0e10cSrcweir #include "com/sun/star/lang/XMultiServiceFactory.hpp" 44*cdf0e10cSrcweir #include "comphelper/processfactory.hxx" 45*cdf0e10cSrcweir #include "com/sun/star/i18n/ScriptType.hpp" 46*cdf0e10cSrcweir #include "com/sun/star/i18n/DirectionProperty.hpp" 47*cdf0e10cSrcweir 48*cdf0e10cSrcweir #include <string.h> 49*cdf0e10cSrcweir 50*cdf0e10cSrcweir using namespace ::com::sun::star; 51*cdf0e10cSrcweir using namespace ::com::sun::star; 52*cdf0e10cSrcweir using namespace ::com::sun::star::lang; 53*cdf0e10cSrcweir using namespace ::com::sun::star::i18n; 54*cdf0e10cSrcweir using namespace ::com::sun::star::uno; 55*cdf0e10cSrcweir 56*cdf0e10cSrcweir namespace pdfi 57*cdf0e10cSrcweir { 58*cdf0e10cSrcweir 59*cdf0e10cSrcweir const ::com::sun::star::uno::Reference< ::com::sun::star::i18n::XBreakIterator >& DrawXmlOptimizer::GetBreakIterator() 60*cdf0e10cSrcweir { 61*cdf0e10cSrcweir if ( !mxBreakIter.is() ) 62*cdf0e10cSrcweir { 63*cdf0e10cSrcweir Reference< XComponentContext > xContext( this->m_rProcessor.m_xContext, uno::UNO_SET_THROW ); 64*cdf0e10cSrcweir Reference< XMultiComponentFactory > xMSF( xContext->getServiceManager(), uno::UNO_SET_THROW ); 65*cdf0e10cSrcweir Reference < XInterface > xInterface = xMSF->createInstanceWithContext(::rtl::OUString::createFromAscii("com.sun.star.i18n.BreakIterator"), xContext); 66*cdf0e10cSrcweir 67*cdf0e10cSrcweir mxBreakIter = uno::Reference< i18n::XBreakIterator >( xInterface, uno::UNO_QUERY ); 68*cdf0e10cSrcweir } 69*cdf0e10cSrcweir return mxBreakIter; 70*cdf0e10cSrcweir } 71*cdf0e10cSrcweir 72*cdf0e10cSrcweir const ::com::sun::star::uno::Reference< ::com::sun::star::i18n::XBreakIterator >& DrawXmlEmitter::GetBreakIterator() 73*cdf0e10cSrcweir { 74*cdf0e10cSrcweir if ( !mxBreakIter.is() ) 75*cdf0e10cSrcweir { 76*cdf0e10cSrcweir Reference< XComponentContext > xContext( m_rEmitContext.m_xContext, uno::UNO_SET_THROW ); 77*cdf0e10cSrcweir Reference< XMultiComponentFactory > xMSF( xContext->getServiceManager(), uno::UNO_SET_THROW ); 78*cdf0e10cSrcweir Reference < XInterface > xInterface = xMSF->createInstanceWithContext(::rtl::OUString::createFromAscii("com.sun.star.i18n.BreakIterator"), xContext); 79*cdf0e10cSrcweir mxBreakIter = uno::Reference< i18n::XBreakIterator >( xInterface, uno::UNO_QUERY ); 80*cdf0e10cSrcweir } 81*cdf0e10cSrcweir return mxBreakIter; 82*cdf0e10cSrcweir } 83*cdf0e10cSrcweir 84*cdf0e10cSrcweir const ::com::sun::star::uno::Reference< ::com::sun::star::i18n::XCharacterClassification >& DrawXmlEmitter::GetCharacterClassification() 85*cdf0e10cSrcweir { 86*cdf0e10cSrcweir if ( !mxCharClass.is() ) 87*cdf0e10cSrcweir { 88*cdf0e10cSrcweir Reference< XComponentContext > xContext( m_rEmitContext.m_xContext, uno::UNO_SET_THROW ); 89*cdf0e10cSrcweir Reference< XMultiComponentFactory > xMSF( xContext->getServiceManager(), uno::UNO_SET_THROW ); 90*cdf0e10cSrcweir Reference < XInterface > xInterface = xMSF->createInstanceWithContext(::rtl::OUString::createFromAscii("com.sun.star.i18n.CharacterClassification"), xContext); 91*cdf0e10cSrcweir mxCharClass = uno::Reference< i18n::XCharacterClassification >( xInterface, uno::UNO_QUERY ); 92*cdf0e10cSrcweir } 93*cdf0e10cSrcweir return mxCharClass; 94*cdf0e10cSrcweir } 95*cdf0e10cSrcweir 96*cdf0e10cSrcweir void DrawXmlEmitter::visit( HyperlinkElement& elem, const std::list< Element* >::const_iterator& ) 97*cdf0e10cSrcweir { 98*cdf0e10cSrcweir if( elem.Children.empty() ) 99*cdf0e10cSrcweir return; 100*cdf0e10cSrcweir 101*cdf0e10cSrcweir const char* pType = dynamic_cast<DrawElement*>(elem.Children.front()) ? "draw:a" : "text:a"; 102*cdf0e10cSrcweir 103*cdf0e10cSrcweir PropertyMap aProps; 104*cdf0e10cSrcweir aProps[ USTR( "xlink:type" ) ] = USTR( "simple" ); 105*cdf0e10cSrcweir aProps[ USTR( "xlink:href" ) ] = elem.URI; 106*cdf0e10cSrcweir aProps[ USTR( "office:target-frame-name" ) ] = USTR( "_blank" ); 107*cdf0e10cSrcweir aProps[ USTR( "xlink:show" ) ] = USTR( "new" ); 108*cdf0e10cSrcweir 109*cdf0e10cSrcweir m_rEmitContext.rEmitter.beginTag( pType, aProps ); 110*cdf0e10cSrcweir std::list< Element* >::iterator this_it = elem.Children.begin(); 111*cdf0e10cSrcweir while( this_it !=elem.Children.end() && *this_it != &elem ) 112*cdf0e10cSrcweir { 113*cdf0e10cSrcweir (*this_it)->visitedBy( *this, this_it ); 114*cdf0e10cSrcweir this_it++; 115*cdf0e10cSrcweir } 116*cdf0e10cSrcweir m_rEmitContext.rEmitter.endTag( pType ); 117*cdf0e10cSrcweir } 118*cdf0e10cSrcweir 119*cdf0e10cSrcweir void DrawXmlEmitter::visit( TextElement& elem, const std::list< Element* >::const_iterator& ) 120*cdf0e10cSrcweir { 121*cdf0e10cSrcweir if( ! elem.Text.getLength() ) 122*cdf0e10cSrcweir return; 123*cdf0e10cSrcweir 124*cdf0e10cSrcweir rtl::OUString strSpace(32); 125*cdf0e10cSrcweir rtl::OUString strNbSpace(160); 126*cdf0e10cSrcweir rtl::OUString tabSpace(0x09); 127*cdf0e10cSrcweir PropertyMap aProps; 128*cdf0e10cSrcweir if( elem.StyleId != -1 ) 129*cdf0e10cSrcweir { 130*cdf0e10cSrcweir aProps[ rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "text:style-name" ) ) ] = 131*cdf0e10cSrcweir m_rEmitContext.rStyles.getStyleName( elem.StyleId ); 132*cdf0e10cSrcweir } 133*cdf0e10cSrcweir 134*cdf0e10cSrcweir rtl::OUString str(elem.Text.getStr()); 135*cdf0e10cSrcweir 136*cdf0e10cSrcweir // Check for RTL 137*cdf0e10cSrcweir bool isRTL = false; 138*cdf0e10cSrcweir Reference< i18n::XCharacterClassification > xCC( GetCharacterClassification() ); 139*cdf0e10cSrcweir if( xCC.is() ) 140*cdf0e10cSrcweir { 141*cdf0e10cSrcweir for(int i=1; i< elem.Text.getLength(); i++) 142*cdf0e10cSrcweir { 143*cdf0e10cSrcweir sal_Int16 nType = xCC->getCharacterDirection( str, i ); 144*cdf0e10cSrcweir if ( nType == ::com::sun::star::i18n::DirectionProperty_RIGHT_TO_LEFT || 145*cdf0e10cSrcweir nType == ::com::sun::star::i18n::DirectionProperty_RIGHT_TO_LEFT_ARABIC || 146*cdf0e10cSrcweir nType == ::com::sun::star::i18n::DirectionProperty_RIGHT_TO_LEFT_EMBEDDING || 147*cdf0e10cSrcweir nType == ::com::sun::star::i18n::DirectionProperty_RIGHT_TO_LEFT_OVERRIDE 148*cdf0e10cSrcweir ) 149*cdf0e10cSrcweir isRTL = true; 150*cdf0e10cSrcweir } 151*cdf0e10cSrcweir } 152*cdf0e10cSrcweir 153*cdf0e10cSrcweir if (isRTL) // If so, reverse string 154*cdf0e10cSrcweir str = m_rProcessor.mirrorString( str ); 155*cdf0e10cSrcweir 156*cdf0e10cSrcweir m_rEmitContext.rEmitter.beginTag( "text:span", aProps ); 157*cdf0e10cSrcweir 158*cdf0e10cSrcweir for(int i=0; i< elem.Text.getLength(); i++) 159*cdf0e10cSrcweir { 160*cdf0e10cSrcweir rtl::OUString strToken= str.copy(i,1) ; 161*cdf0e10cSrcweir if( strSpace.equals(strToken) || strNbSpace.equals(strToken)) 162*cdf0e10cSrcweir { 163*cdf0e10cSrcweir aProps[ USTR( "text:c" ) ] = USTR( "1" ); 164*cdf0e10cSrcweir m_rEmitContext.rEmitter.beginTag( "text:s", aProps ); 165*cdf0e10cSrcweir m_rEmitContext.rEmitter.endTag( "text:s"); 166*cdf0e10cSrcweir } 167*cdf0e10cSrcweir else 168*cdf0e10cSrcweir { 169*cdf0e10cSrcweir if( tabSpace.equals(strToken) ) 170*cdf0e10cSrcweir { 171*cdf0e10cSrcweir m_rEmitContext.rEmitter.beginTag( "text:tab", aProps ); 172*cdf0e10cSrcweir m_rEmitContext.rEmitter.endTag( "text:tab"); 173*cdf0e10cSrcweir } 174*cdf0e10cSrcweir else 175*cdf0e10cSrcweir { 176*cdf0e10cSrcweir m_rEmitContext.rEmitter.write( strToken ); 177*cdf0e10cSrcweir } 178*cdf0e10cSrcweir } 179*cdf0e10cSrcweir } 180*cdf0e10cSrcweir 181*cdf0e10cSrcweir std::list< Element* >::iterator this_it = elem.Children.begin(); 182*cdf0e10cSrcweir while( this_it !=elem.Children.end() && *this_it != &elem ) 183*cdf0e10cSrcweir { 184*cdf0e10cSrcweir (*this_it)->visitedBy( *this, this_it ); 185*cdf0e10cSrcweir this_it++; 186*cdf0e10cSrcweir } 187*cdf0e10cSrcweir 188*cdf0e10cSrcweir m_rEmitContext.rEmitter.endTag( "text:span" ); 189*cdf0e10cSrcweir } 190*cdf0e10cSrcweir 191*cdf0e10cSrcweir void DrawXmlEmitter::visit( ParagraphElement& elem, const std::list< Element* >::const_iterator& ) 192*cdf0e10cSrcweir { 193*cdf0e10cSrcweir PropertyMap aProps; 194*cdf0e10cSrcweir if( elem.StyleId != -1 ) 195*cdf0e10cSrcweir { 196*cdf0e10cSrcweir aProps[ USTR( "text:style-name" ) ] = m_rEmitContext.rStyles.getStyleName( elem.StyleId ); 197*cdf0e10cSrcweir } 198*cdf0e10cSrcweir const char* pTagType = "text:p"; 199*cdf0e10cSrcweir if( elem.Type == elem.Headline ) 200*cdf0e10cSrcweir pTagType = "text:h"; 201*cdf0e10cSrcweir m_rEmitContext.rEmitter.beginTag( pTagType, aProps ); 202*cdf0e10cSrcweir 203*cdf0e10cSrcweir std::list< Element* >::iterator this_it = elem.Children.begin(); 204*cdf0e10cSrcweir while( this_it !=elem.Children.end() && *this_it != &elem ) 205*cdf0e10cSrcweir { 206*cdf0e10cSrcweir (*this_it)->visitedBy( *this, this_it ); 207*cdf0e10cSrcweir this_it++; 208*cdf0e10cSrcweir } 209*cdf0e10cSrcweir 210*cdf0e10cSrcweir m_rEmitContext.rEmitter.endTag( pTagType ); 211*cdf0e10cSrcweir } 212*cdf0e10cSrcweir 213*cdf0e10cSrcweir void DrawXmlEmitter::fillFrameProps( DrawElement& rElem, 214*cdf0e10cSrcweir PropertyMap& rProps, 215*cdf0e10cSrcweir const EmitContext& rEmitContext, 216*cdf0e10cSrcweir bool bWasTransformed 217*cdf0e10cSrcweir ) 218*cdf0e10cSrcweir { 219*cdf0e10cSrcweir double rel_x = rElem.x, rel_y = rElem.y; 220*cdf0e10cSrcweir 221*cdf0e10cSrcweir rProps[ USTR( "draw:z-index" ) ] = rtl::OUString::valueOf( rElem.ZOrder ); 222*cdf0e10cSrcweir rProps[ USTR( "draw:style-name" )] = rEmitContext.rStyles.getStyleName( rElem.StyleId ); 223*cdf0e10cSrcweir rProps[ USTR( "svg:width" ) ] = convertPixelToUnitString( rElem.w ); 224*cdf0e10cSrcweir rProps[ USTR( "svg:height" ) ] = convertPixelToUnitString( rElem.h ); 225*cdf0e10cSrcweir 226*cdf0e10cSrcweir const GraphicsContext& rGC = 227*cdf0e10cSrcweir rEmitContext.rProcessor.getGraphicsContext( rElem.GCId ); 228*cdf0e10cSrcweir if( rGC.Transformation.isIdentity() || bWasTransformed ) 229*cdf0e10cSrcweir { 230*cdf0e10cSrcweir rProps[ USTR( "svg:x" ) ] = convertPixelToUnitString( rel_x ); 231*cdf0e10cSrcweir rProps[ USTR( "svg:y" ) ] = convertPixelToUnitString( rel_y ); 232*cdf0e10cSrcweir } 233*cdf0e10cSrcweir else 234*cdf0e10cSrcweir { 235*cdf0e10cSrcweir basegfx::B2DTuple aScale, aTranslation; 236*cdf0e10cSrcweir double fRotate, fShearX; 237*cdf0e10cSrcweir 238*cdf0e10cSrcweir rGC.Transformation.decompose( aScale, aTranslation, fRotate, fShearX ); 239*cdf0e10cSrcweir 240*cdf0e10cSrcweir rtl::OUStringBuffer aBuf( 256 ); 241*cdf0e10cSrcweir 242*cdf0e10cSrcweir // TODO(F2): general transformation case missing; if implemented, note 243*cdf0e10cSrcweir // that ODF rotation is oriented the other way 244*cdf0e10cSrcweir 245*cdf0e10cSrcweir // vertical mirroring is done by horizontally mirroring and rotaing 180 degree 246*cdf0e10cSrcweir // quaint ! 247*cdf0e10cSrcweir if( rElem.MirrorVertical ) 248*cdf0e10cSrcweir fRotate += M_PI; 249*cdf0e10cSrcweir 250*cdf0e10cSrcweir // build transformation string 251*cdf0e10cSrcweir if( fShearX != 0.0 ) 252*cdf0e10cSrcweir { 253*cdf0e10cSrcweir aBuf.appendAscii( "skewX( " ); 254*cdf0e10cSrcweir aBuf.append( fShearX ); 255*cdf0e10cSrcweir aBuf.appendAscii( " )" ); 256*cdf0e10cSrcweir } 257*cdf0e10cSrcweir if( fRotate != 0.0 ) 258*cdf0e10cSrcweir { 259*cdf0e10cSrcweir if( aBuf.getLength() > 0 ) 260*cdf0e10cSrcweir aBuf.append( sal_Unicode(' ') ); 261*cdf0e10cSrcweir aBuf.appendAscii( "rotate( " ); 262*cdf0e10cSrcweir aBuf.append( -fRotate ); 263*cdf0e10cSrcweir aBuf.appendAscii( " )" ); 264*cdf0e10cSrcweir 265*cdf0e10cSrcweir } 266*cdf0e10cSrcweir if( aBuf.getLength() > 0 ) 267*cdf0e10cSrcweir aBuf.append( sal_Unicode(' ') ); 268*cdf0e10cSrcweir aBuf.appendAscii( "translate( " ); 269*cdf0e10cSrcweir aBuf.append( convertPixelToUnitString( rel_x ) ); 270*cdf0e10cSrcweir aBuf.append( sal_Unicode(' ') ); 271*cdf0e10cSrcweir aBuf.append( convertPixelToUnitString( rel_y ) ); 272*cdf0e10cSrcweir aBuf.appendAscii( " )" ); 273*cdf0e10cSrcweir 274*cdf0e10cSrcweir rProps[ USTR( "draw:transform" ) ] = aBuf.makeStringAndClear(); 275*cdf0e10cSrcweir } 276*cdf0e10cSrcweir } 277*cdf0e10cSrcweir 278*cdf0e10cSrcweir void DrawXmlEmitter::visit( FrameElement& elem, const std::list< Element* >::const_iterator& ) 279*cdf0e10cSrcweir { 280*cdf0e10cSrcweir if( elem.Children.empty() ) 281*cdf0e10cSrcweir return; 282*cdf0e10cSrcweir 283*cdf0e10cSrcweir bool bTextBox = (dynamic_cast<ParagraphElement*>(elem.Children.front()) != NULL); 284*cdf0e10cSrcweir PropertyMap aFrameProps; 285*cdf0e10cSrcweir fillFrameProps( elem, aFrameProps, m_rEmitContext ); 286*cdf0e10cSrcweir m_rEmitContext.rEmitter.beginTag( "draw:frame", aFrameProps ); 287*cdf0e10cSrcweir if( bTextBox ) 288*cdf0e10cSrcweir m_rEmitContext.rEmitter.beginTag( "draw:text-box", PropertyMap() ); 289*cdf0e10cSrcweir 290*cdf0e10cSrcweir std::list< Element* >::iterator this_it = elem.Children.begin(); 291*cdf0e10cSrcweir while( this_it !=elem.Children.end() && *this_it != &elem ) 292*cdf0e10cSrcweir { 293*cdf0e10cSrcweir (*this_it)->visitedBy( *this, this_it ); 294*cdf0e10cSrcweir this_it++; 295*cdf0e10cSrcweir } 296*cdf0e10cSrcweir 297*cdf0e10cSrcweir if( bTextBox ) 298*cdf0e10cSrcweir m_rEmitContext.rEmitter.endTag( "draw:text-box" ); 299*cdf0e10cSrcweir m_rEmitContext.rEmitter.endTag( "draw:frame" ); 300*cdf0e10cSrcweir } 301*cdf0e10cSrcweir 302*cdf0e10cSrcweir void DrawXmlEmitter::visit( PolyPolyElement& elem, const std::list< Element* >::const_iterator& ) 303*cdf0e10cSrcweir { 304*cdf0e10cSrcweir elem.updateGeometry(); 305*cdf0e10cSrcweir /* note: 306*cdf0e10cSrcweir * aw recommends using 100dth of mm in all respects since the xml import 307*cdf0e10cSrcweir * (a) is buggy (see issue 37213) 308*cdf0e10cSrcweir * (b) is optimized for 100dth of mm and does not scale itself then, 309*cdf0e10cSrcweir * this does not gain us speed but makes for smaller rounding errors since 310*cdf0e10cSrcweir * the xml importer coordinates are integer based 311*cdf0e10cSrcweir */ 312*cdf0e10cSrcweir for (sal_uInt32 i = 0; i< elem.PolyPoly.count(); i++) 313*cdf0e10cSrcweir { 314*cdf0e10cSrcweir basegfx::B2DPolygon b2dPolygon; 315*cdf0e10cSrcweir b2dPolygon = elem.PolyPoly.getB2DPolygon( i ); 316*cdf0e10cSrcweir 317*cdf0e10cSrcweir for ( sal_uInt32 j = 0; j< b2dPolygon.count(); j++ ) 318*cdf0e10cSrcweir { 319*cdf0e10cSrcweir basegfx::B2DPoint point; 320*cdf0e10cSrcweir basegfx::B2DPoint nextPoint; 321*cdf0e10cSrcweir point = b2dPolygon.getB2DPoint( j ); 322*cdf0e10cSrcweir 323*cdf0e10cSrcweir basegfx::B2DPoint prevPoint; 324*cdf0e10cSrcweir prevPoint = b2dPolygon.getPrevControlPoint( j ) ; 325*cdf0e10cSrcweir 326*cdf0e10cSrcweir point.setX( convPx2mmPrec2( point.getX() )*100.0 ); 327*cdf0e10cSrcweir point.setY( convPx2mmPrec2( point.getY() )*100.0 ); 328*cdf0e10cSrcweir 329*cdf0e10cSrcweir if ( b2dPolygon.isPrevControlPointUsed( j ) ) 330*cdf0e10cSrcweir { 331*cdf0e10cSrcweir prevPoint.setX( convPx2mmPrec2( prevPoint.getX() )*100.0 ); 332*cdf0e10cSrcweir prevPoint.setY( convPx2mmPrec2( prevPoint.getY() )*100.0 ); 333*cdf0e10cSrcweir } 334*cdf0e10cSrcweir 335*cdf0e10cSrcweir if ( b2dPolygon.isNextControlPointUsed( j ) ) 336*cdf0e10cSrcweir { 337*cdf0e10cSrcweir nextPoint = b2dPolygon.getNextControlPoint( j ) ; 338*cdf0e10cSrcweir nextPoint.setX( convPx2mmPrec2( nextPoint.getX() )*100.0 ); 339*cdf0e10cSrcweir nextPoint.setY( convPx2mmPrec2( nextPoint.getY() )*100.0 ); 340*cdf0e10cSrcweir } 341*cdf0e10cSrcweir 342*cdf0e10cSrcweir b2dPolygon.setB2DPoint( j, point ); 343*cdf0e10cSrcweir 344*cdf0e10cSrcweir if ( b2dPolygon.isPrevControlPointUsed( j ) ) 345*cdf0e10cSrcweir b2dPolygon.setPrevControlPoint( j , prevPoint ) ; 346*cdf0e10cSrcweir 347*cdf0e10cSrcweir if ( b2dPolygon.isNextControlPointUsed( j ) ) 348*cdf0e10cSrcweir b2dPolygon.setNextControlPoint( j , nextPoint ) ; 349*cdf0e10cSrcweir } 350*cdf0e10cSrcweir 351*cdf0e10cSrcweir elem.PolyPoly.setB2DPolygon( i, b2dPolygon ); 352*cdf0e10cSrcweir } 353*cdf0e10cSrcweir 354*cdf0e10cSrcweir PropertyMap aProps; 355*cdf0e10cSrcweir // PDFIProcessor transforms geometrical objects, not images and text 356*cdf0e10cSrcweir // so we need to tell fillFrameProps here that the transformation for 357*cdf0e10cSrcweir // a PolyPolyElement was already applied (aside form translation) 358*cdf0e10cSrcweir fillFrameProps( elem, aProps, m_rEmitContext, true ); 359*cdf0e10cSrcweir rtl::OUStringBuffer aBuf( 64 ); 360*cdf0e10cSrcweir aBuf.appendAscii( "0 0 " ); 361*cdf0e10cSrcweir aBuf.append( convPx2mmPrec2(elem.w)*100.0 ); 362*cdf0e10cSrcweir aBuf.append( sal_Unicode(' ') ); 363*cdf0e10cSrcweir aBuf.append( convPx2mmPrec2(elem.h)*100.0 ); 364*cdf0e10cSrcweir aProps[ USTR( "svg:viewBox" ) ] = aBuf.makeStringAndClear(); 365*cdf0e10cSrcweir aProps[ USTR( "svg:d" ) ] = basegfx::tools::exportToSvgD( elem.PolyPoly ); 366*cdf0e10cSrcweir 367*cdf0e10cSrcweir m_rEmitContext.rEmitter.beginTag( "draw:path", aProps ); 368*cdf0e10cSrcweir m_rEmitContext.rEmitter.endTag( "draw:path" ); 369*cdf0e10cSrcweir } 370*cdf0e10cSrcweir 371*cdf0e10cSrcweir void DrawXmlEmitter::visit( ImageElement& elem, const std::list< Element* >::const_iterator& ) 372*cdf0e10cSrcweir { 373*cdf0e10cSrcweir PropertyMap aImageProps; 374*cdf0e10cSrcweir m_rEmitContext.rEmitter.beginTag( "draw:image", aImageProps ); 375*cdf0e10cSrcweir m_rEmitContext.rEmitter.beginTag( "office:binary-data", PropertyMap() ); 376*cdf0e10cSrcweir m_rEmitContext.rImages.writeBase64EncodedStream( elem.Image, m_rEmitContext); 377*cdf0e10cSrcweir m_rEmitContext.rEmitter.endTag( "office:binary-data" ); 378*cdf0e10cSrcweir m_rEmitContext.rEmitter.endTag( "draw:image" ); 379*cdf0e10cSrcweir } 380*cdf0e10cSrcweir 381*cdf0e10cSrcweir void DrawXmlEmitter::visit( PageElement& elem, const std::list< Element* >::const_iterator& ) 382*cdf0e10cSrcweir { 383*cdf0e10cSrcweir PropertyMap aPageProps; 384*cdf0e10cSrcweir aPageProps[ USTR( "draw:master-page-name" ) ] = m_rEmitContext.rStyles.getStyleName( elem.StyleId ); 385*cdf0e10cSrcweir 386*cdf0e10cSrcweir m_rEmitContext.rEmitter.beginTag("draw:page", aPageProps); 387*cdf0e10cSrcweir 388*cdf0e10cSrcweir if( m_rEmitContext.xStatusIndicator.is() ) 389*cdf0e10cSrcweir m_rEmitContext.xStatusIndicator->setValue( elem.PageNumber ); 390*cdf0e10cSrcweir 391*cdf0e10cSrcweir std::list< Element* >::iterator this_it = elem.Children.begin(); 392*cdf0e10cSrcweir while( this_it !=elem.Children.end() && *this_it != &elem ) 393*cdf0e10cSrcweir { 394*cdf0e10cSrcweir (*this_it)->visitedBy( *this, this_it ); 395*cdf0e10cSrcweir this_it++; 396*cdf0e10cSrcweir } 397*cdf0e10cSrcweir 398*cdf0e10cSrcweir m_rEmitContext.rEmitter.endTag("draw:page"); 399*cdf0e10cSrcweir } 400*cdf0e10cSrcweir 401*cdf0e10cSrcweir void DrawXmlEmitter::visit( DocumentElement& elem, const std::list< Element* >::const_iterator&) 402*cdf0e10cSrcweir { 403*cdf0e10cSrcweir m_rEmitContext.rEmitter.beginTag( "office:body", PropertyMap() ); 404*cdf0e10cSrcweir m_rEmitContext.rEmitter.beginTag( m_bWriteDrawDocument ? "office:drawing" : "office:presentation", 405*cdf0e10cSrcweir PropertyMap() ); 406*cdf0e10cSrcweir 407*cdf0e10cSrcweir std::list< Element* >::iterator this_it = elem.Children.begin(); 408*cdf0e10cSrcweir while( this_it !=elem.Children.end() && *this_it != &elem ) 409*cdf0e10cSrcweir { 410*cdf0e10cSrcweir (*this_it)->visitedBy( *this, this_it ); 411*cdf0e10cSrcweir this_it++; 412*cdf0e10cSrcweir } 413*cdf0e10cSrcweir 414*cdf0e10cSrcweir m_rEmitContext.rEmitter.endTag( m_bWriteDrawDocument ? "office:drawing" : "office:presentation" ); 415*cdf0e10cSrcweir m_rEmitContext.rEmitter.endTag( "office:body" ); 416*cdf0e10cSrcweir } 417*cdf0e10cSrcweir 418*cdf0e10cSrcweir ///////////////////////////////////////////////////////////////// 419*cdf0e10cSrcweir 420*cdf0e10cSrcweir void DrawXmlOptimizer::visit( HyperlinkElement&, const std::list< Element* >::const_iterator& ) 421*cdf0e10cSrcweir { 422*cdf0e10cSrcweir } 423*cdf0e10cSrcweir 424*cdf0e10cSrcweir void DrawXmlOptimizer::visit( TextElement&, const std::list< Element* >::const_iterator&) 425*cdf0e10cSrcweir { 426*cdf0e10cSrcweir } 427*cdf0e10cSrcweir 428*cdf0e10cSrcweir void DrawXmlOptimizer::visit( FrameElement& elem, const std::list< Element* >::const_iterator& ) 429*cdf0e10cSrcweir { 430*cdf0e10cSrcweir elem.applyToChildren(*this); 431*cdf0e10cSrcweir } 432*cdf0e10cSrcweir 433*cdf0e10cSrcweir void DrawXmlOptimizer::visit( ImageElement&, const std::list< Element* >::const_iterator& ) 434*cdf0e10cSrcweir { 435*cdf0e10cSrcweir } 436*cdf0e10cSrcweir 437*cdf0e10cSrcweir void DrawXmlOptimizer::visit( PolyPolyElement& elem, const std::list< Element* >::const_iterator& ) 438*cdf0e10cSrcweir { 439*cdf0e10cSrcweir /* note: optimize two consecutive PolyPolyElements that 440*cdf0e10cSrcweir * have the same path but one of which is a stroke while 441*cdf0e10cSrcweir * the other is a fill 442*cdf0e10cSrcweir */ 443*cdf0e10cSrcweir if( elem.Parent ) 444*cdf0e10cSrcweir { 445*cdf0e10cSrcweir // find following PolyPolyElement in parent's children list 446*cdf0e10cSrcweir std::list< Element* >::iterator this_it = elem.Parent->Children.begin(); 447*cdf0e10cSrcweir while( this_it != elem.Parent->Children.end() && *this_it != &elem ) 448*cdf0e10cSrcweir ++this_it; 449*cdf0e10cSrcweir 450*cdf0e10cSrcweir if( this_it != elem.Parent->Children.end() ) 451*cdf0e10cSrcweir { 452*cdf0e10cSrcweir std::list< Element* >::iterator next_it = this_it; 453*cdf0e10cSrcweir if( ++next_it != elem.Parent->Children.end() ) 454*cdf0e10cSrcweir { 455*cdf0e10cSrcweir PolyPolyElement* pNext = dynamic_cast<PolyPolyElement*>(*next_it); 456*cdf0e10cSrcweir 457*cdf0e10cSrcweir // TODO(F2): this comparison fails for OOo-generated polygons with beziers. 458*cdf0e10cSrcweir if( pNext && pNext->PolyPoly == elem.PolyPoly ) 459*cdf0e10cSrcweir { 460*cdf0e10cSrcweir const GraphicsContext& rNextGC = 461*cdf0e10cSrcweir m_rProcessor.getGraphicsContext( pNext->GCId ); 462*cdf0e10cSrcweir const GraphicsContext& rThisGC = 463*cdf0e10cSrcweir m_rProcessor.getGraphicsContext( elem.GCId ); 464*cdf0e10cSrcweir 465*cdf0e10cSrcweir if( rThisGC.BlendMode == rNextGC.BlendMode && 466*cdf0e10cSrcweir rThisGC.Flatness == rNextGC.Flatness && 467*cdf0e10cSrcweir rThisGC.Transformation == rNextGC.Transformation && 468*cdf0e10cSrcweir rThisGC.Clip == rNextGC.Clip && 469*cdf0e10cSrcweir rThisGC.FillColor.Red == rNextGC.FillColor.Red && 470*cdf0e10cSrcweir rThisGC.FillColor.Green== rNextGC.FillColor.Green && 471*cdf0e10cSrcweir rThisGC.FillColor.Blue == rNextGC.FillColor.Blue && 472*cdf0e10cSrcweir rThisGC.FillColor.Alpha== rNextGC.FillColor.Alpha && 473*cdf0e10cSrcweir pNext->Action == PATH_STROKE && 474*cdf0e10cSrcweir (elem.Action == PATH_FILL || elem.Action == PATH_EOFILL) ) 475*cdf0e10cSrcweir { 476*cdf0e10cSrcweir GraphicsContext aGC = rThisGC; 477*cdf0e10cSrcweir aGC.LineJoin = rNextGC.LineJoin; 478*cdf0e10cSrcweir aGC.LineCap = rNextGC.LineCap; 479*cdf0e10cSrcweir aGC.LineWidth = rNextGC.LineWidth; 480*cdf0e10cSrcweir aGC.MiterLimit= rNextGC.MiterLimit; 481*cdf0e10cSrcweir aGC.DashArray = rNextGC.DashArray; 482*cdf0e10cSrcweir aGC.LineColor = rNextGC.LineColor; 483*cdf0e10cSrcweir elem.GCId = m_rProcessor.getGCId( aGC ); 484*cdf0e10cSrcweir 485*cdf0e10cSrcweir elem.Action |= pNext->Action; 486*cdf0e10cSrcweir 487*cdf0e10cSrcweir elem.Children.splice( elem.Children.end(), pNext->Children ); 488*cdf0e10cSrcweir elem.Parent->Children.erase( next_it ); 489*cdf0e10cSrcweir delete pNext; 490*cdf0e10cSrcweir } 491*cdf0e10cSrcweir } 492*cdf0e10cSrcweir } 493*cdf0e10cSrcweir } 494*cdf0e10cSrcweir } 495*cdf0e10cSrcweir } 496*cdf0e10cSrcweir 497*cdf0e10cSrcweir void DrawXmlOptimizer::visit( ParagraphElement& elem, const std::list< Element* >::const_iterator& ) 498*cdf0e10cSrcweir { 499*cdf0e10cSrcweir optimizeTextElements( elem ); 500*cdf0e10cSrcweir 501*cdf0e10cSrcweir elem.applyToChildren(*this); 502*cdf0e10cSrcweir } 503*cdf0e10cSrcweir 504*cdf0e10cSrcweir void DrawXmlOptimizer::visit( PageElement& elem, const std::list< Element* >::const_iterator& ) 505*cdf0e10cSrcweir { 506*cdf0e10cSrcweir if( m_rProcessor.getStatusIndicator().is() ) 507*cdf0e10cSrcweir m_rProcessor.getStatusIndicator()->setValue( elem.PageNumber ); 508*cdf0e10cSrcweir 509*cdf0e10cSrcweir // resolve hyperlinks 510*cdf0e10cSrcweir elem.resolveHyperlinks(); 511*cdf0e10cSrcweir 512*cdf0e10cSrcweir elem.resolveFontStyles( m_rProcessor ); // underlines and such 513*cdf0e10cSrcweir 514*cdf0e10cSrcweir // FIXME: until hyperlinks and font effects are adjusted for 515*cdf0e10cSrcweir // geometrical search handle them before sorting 516*cdf0e10cSrcweir m_rProcessor.sortElements( &elem ); 517*cdf0e10cSrcweir 518*cdf0e10cSrcweir // find paragraphs in text 519*cdf0e10cSrcweir ParagraphElement* pCurPara = NULL; 520*cdf0e10cSrcweir std::list< Element* >::iterator page_element, next_page_element; 521*cdf0e10cSrcweir next_page_element = elem.Children.begin(); 522*cdf0e10cSrcweir double fCurLineHeight = 0.0; // average height of text items in current para 523*cdf0e10cSrcweir int nCurLineElements = 0; // number of line contributing elements in current para 524*cdf0e10cSrcweir double line_left = elem.w, line_right = 0.0; 525*cdf0e10cSrcweir double column_width = elem.w*0.75; // estimate text width 526*cdf0e10cSrcweir // TODO: guess columns 527*cdf0e10cSrcweir while( next_page_element != elem.Children.end() ) 528*cdf0e10cSrcweir { 529*cdf0e10cSrcweir page_element = next_page_element++; 530*cdf0e10cSrcweir ParagraphElement* pPagePara = dynamic_cast<ParagraphElement*>(*page_element); 531*cdf0e10cSrcweir if( pPagePara ) 532*cdf0e10cSrcweir { 533*cdf0e10cSrcweir pCurPara = pPagePara; 534*cdf0e10cSrcweir // adjust line height and text items 535*cdf0e10cSrcweir fCurLineHeight = 0.0; 536*cdf0e10cSrcweir nCurLineElements = 0; 537*cdf0e10cSrcweir for( std::list< Element* >::iterator it = pCurPara->Children.begin(); 538*cdf0e10cSrcweir it != pCurPara->Children.end(); ++it ) 539*cdf0e10cSrcweir { 540*cdf0e10cSrcweir TextElement* pTestText = dynamic_cast<TextElement*>(*it); 541*cdf0e10cSrcweir if( pTestText ) 542*cdf0e10cSrcweir { 543*cdf0e10cSrcweir fCurLineHeight = (fCurLineHeight*double(nCurLineElements) + pTestText->h)/double(nCurLineElements+1); 544*cdf0e10cSrcweir nCurLineElements++; 545*cdf0e10cSrcweir } 546*cdf0e10cSrcweir } 547*cdf0e10cSrcweir continue; 548*cdf0e10cSrcweir } 549*cdf0e10cSrcweir 550*cdf0e10cSrcweir HyperlinkElement* pLink = dynamic_cast<HyperlinkElement*>(*page_element); 551*cdf0e10cSrcweir DrawElement* pDraw = dynamic_cast<DrawElement*>(*page_element); 552*cdf0e10cSrcweir if( ! pDraw && pLink && ! pLink->Children.empty() ) 553*cdf0e10cSrcweir pDraw = dynamic_cast<DrawElement*>(pLink->Children.front() ); 554*cdf0e10cSrcweir if( pDraw ) 555*cdf0e10cSrcweir { 556*cdf0e10cSrcweir // insert small drawing objects as character, else leave them page bound 557*cdf0e10cSrcweir 558*cdf0e10cSrcweir bool bInsertToParagraph = false; 559*cdf0e10cSrcweir // first check if this is either inside the paragraph 560*cdf0e10cSrcweir if( pCurPara && pDraw->y < pCurPara->y + pCurPara->h ) 561*cdf0e10cSrcweir { 562*cdf0e10cSrcweir if( pDraw->h < fCurLineHeight * 1.5 ) 563*cdf0e10cSrcweir { 564*cdf0e10cSrcweir bInsertToParagraph = true; 565*cdf0e10cSrcweir fCurLineHeight = (fCurLineHeight*double(nCurLineElements) + pDraw->h)/double(nCurLineElements+1); 566*cdf0e10cSrcweir nCurLineElements++; 567*cdf0e10cSrcweir // mark draw element as character 568*cdf0e10cSrcweir pDraw->isCharacter = true; 569*cdf0e10cSrcweir } 570*cdf0e10cSrcweir } 571*cdf0e10cSrcweir // or perhaps the draw element begins a new paragraph 572*cdf0e10cSrcweir else if( next_page_element != elem.Children.end() ) 573*cdf0e10cSrcweir { 574*cdf0e10cSrcweir TextElement* pText = dynamic_cast<TextElement*>(*next_page_element); 575*cdf0e10cSrcweir if( ! pText ) 576*cdf0e10cSrcweir { 577*cdf0e10cSrcweir ParagraphElement* pPara = dynamic_cast<ParagraphElement*>(*next_page_element); 578*cdf0e10cSrcweir if( pPara && ! pPara->Children.empty() ) 579*cdf0e10cSrcweir pText = dynamic_cast<TextElement*>(pPara->Children.front()); 580*cdf0e10cSrcweir } 581*cdf0e10cSrcweir if( pText && // check there is a text 582*cdf0e10cSrcweir pDraw->h < pText->h*1.5 && // and it is approx the same height 583*cdf0e10cSrcweir // and either upper or lower edge of pDraw is inside text's vertical range 584*cdf0e10cSrcweir ( ( pDraw->y >= pText->y && pDraw->y <= pText->y+pText->h ) || 585*cdf0e10cSrcweir ( pDraw->y+pDraw->h >= pText->y && pDraw->y+pDraw->h <= pText->y+pText->h ) 586*cdf0e10cSrcweir ) 587*cdf0e10cSrcweir ) 588*cdf0e10cSrcweir { 589*cdf0e10cSrcweir bInsertToParagraph = true; 590*cdf0e10cSrcweir fCurLineHeight = pDraw->h; 591*cdf0e10cSrcweir nCurLineElements = 1; 592*cdf0e10cSrcweir line_left = pDraw->x; 593*cdf0e10cSrcweir line_right = pDraw->x + pDraw->w; 594*cdf0e10cSrcweir // begin a new paragraph 595*cdf0e10cSrcweir pCurPara = NULL; 596*cdf0e10cSrcweir // mark draw element as character 597*cdf0e10cSrcweir pDraw->isCharacter = true; 598*cdf0e10cSrcweir } 599*cdf0e10cSrcweir } 600*cdf0e10cSrcweir 601*cdf0e10cSrcweir if( ! bInsertToParagraph ) 602*cdf0e10cSrcweir { 603*cdf0e10cSrcweir pCurPara = NULL; 604*cdf0e10cSrcweir continue; 605*cdf0e10cSrcweir } 606*cdf0e10cSrcweir } 607*cdf0e10cSrcweir 608*cdf0e10cSrcweir TextElement* pText = dynamic_cast<TextElement*>(*page_element); 609*cdf0e10cSrcweir if( ! pText && pLink && ! pLink->Children.empty() ) 610*cdf0e10cSrcweir pText = dynamic_cast<TextElement*>(pLink->Children.front()); 611*cdf0e10cSrcweir if( pText ) 612*cdf0e10cSrcweir { 613*cdf0e10cSrcweir Element* pGeo = pLink ? static_cast<Element*>(pLink) : 614*cdf0e10cSrcweir static_cast<Element*>(pText); 615*cdf0e10cSrcweir if( pCurPara ) 616*cdf0e10cSrcweir { 617*cdf0e10cSrcweir // there was already a text element, check for a new paragraph 618*cdf0e10cSrcweir if( nCurLineElements > 0 ) 619*cdf0e10cSrcweir { 620*cdf0e10cSrcweir // if the new text is significantly distant from the paragraph 621*cdf0e10cSrcweir // begin a new paragraph 622*cdf0e10cSrcweir if( pGeo->y > pCurPara->y + pCurPara->h + fCurLineHeight*0.5 ) 623*cdf0e10cSrcweir pCurPara = NULL; // insert new paragraph 624*cdf0e10cSrcweir else if( pGeo->y > (pCurPara->y+pCurPara->h - fCurLineHeight*0.05) ) 625*cdf0e10cSrcweir { 626*cdf0e10cSrcweir // new paragraph if either the last line of the paragraph 627*cdf0e10cSrcweir // was significantly shorter than the paragraph as a whole 628*cdf0e10cSrcweir if( (line_right - line_left) < pCurPara->w*0.75 ) 629*cdf0e10cSrcweir pCurPara = NULL; 630*cdf0e10cSrcweir // or the last line was significantly smaller than the column width 631*cdf0e10cSrcweir else if( (line_right - line_left) < column_width*0.75 ) 632*cdf0e10cSrcweir pCurPara = NULL; 633*cdf0e10cSrcweir } 634*cdf0e10cSrcweir } 635*cdf0e10cSrcweir 636*cdf0e10cSrcweir 637*cdf0e10cSrcweir } 638*cdf0e10cSrcweir 639*cdf0e10cSrcweir 640*cdf0e10cSrcweir // update line height/width 641*cdf0e10cSrcweir if( pCurPara ) 642*cdf0e10cSrcweir { 643*cdf0e10cSrcweir fCurLineHeight = (fCurLineHeight*double(nCurLineElements) + pGeo->h)/double(nCurLineElements+1); 644*cdf0e10cSrcweir nCurLineElements++; 645*cdf0e10cSrcweir if( pGeo->x < line_left ) 646*cdf0e10cSrcweir line_left = pGeo->x; 647*cdf0e10cSrcweir if( pGeo->x+pGeo->w > line_right ) 648*cdf0e10cSrcweir line_right = pGeo->x+pGeo->w; 649*cdf0e10cSrcweir } 650*cdf0e10cSrcweir else 651*cdf0e10cSrcweir { 652*cdf0e10cSrcweir fCurLineHeight = pGeo->h; 653*cdf0e10cSrcweir nCurLineElements = 1; 654*cdf0e10cSrcweir line_left = pGeo->x; 655*cdf0e10cSrcweir line_right = pGeo->x + pGeo->w; 656*cdf0e10cSrcweir } 657*cdf0e10cSrcweir } 658*cdf0e10cSrcweir 659*cdf0e10cSrcweir 660*cdf0e10cSrcweir // move element to current paragraph 661*cdf0e10cSrcweir if (! pCurPara ) // new paragraph, insert one 662*cdf0e10cSrcweir { 663*cdf0e10cSrcweir pCurPara = m_rProcessor.getElementFactory()->createParagraphElement( NULL ); 664*cdf0e10cSrcweir // set parent 665*cdf0e10cSrcweir pCurPara->Parent = &elem; 666*cdf0e10cSrcweir //insert new paragraph before current element 667*cdf0e10cSrcweir page_element = elem.Children.insert( page_element, pCurPara ); 668*cdf0e10cSrcweir // forward iterator to current element again 669*cdf0e10cSrcweir ++ page_element; 670*cdf0e10cSrcweir // update next_element which is now invalid 671*cdf0e10cSrcweir next_page_element = page_element; 672*cdf0e10cSrcweir ++ next_page_element; 673*cdf0e10cSrcweir } 674*cdf0e10cSrcweir Element* pCurEle = *page_element; 675*cdf0e10cSrcweir pCurEle->setParent( page_element, pCurPara ); 676*cdf0e10cSrcweir OSL_ENSURE( !pText || pCurEle == pText || pCurEle == pLink, "paragraph child list in disorder" ); 677*cdf0e10cSrcweir if( pText || pDraw ) 678*cdf0e10cSrcweir pCurPara->updateGeometryWith( pCurEle ); 679*cdf0e10cSrcweir } 680*cdf0e10cSrcweir 681*cdf0e10cSrcweir // process children 682*cdf0e10cSrcweir elem.applyToChildren(*this); 683*cdf0e10cSrcweir } 684*cdf0e10cSrcweir 685*cdf0e10cSrcweir bool isSpaces(TextElement* pTextElem) 686*cdf0e10cSrcweir { 687*cdf0e10cSrcweir rtl::OUString strSpace(32); 688*cdf0e10cSrcweir ::rtl::OUString ouTxt2(pTextElem->Text); 689*cdf0e10cSrcweir for(int i=0; i< pTextElem->Text.getLength(); i++) 690*cdf0e10cSrcweir { 691*cdf0e10cSrcweir rtl::OUString strToken = ouTxt2.copy(i,1) ; 692*cdf0e10cSrcweir if( !strSpace.equals(strToken) ) 693*cdf0e10cSrcweir return false; 694*cdf0e10cSrcweir } 695*cdf0e10cSrcweir return true; 696*cdf0e10cSrcweir } 697*cdf0e10cSrcweir 698*cdf0e10cSrcweir bool notTransformed(GraphicsContext GC) 699*cdf0e10cSrcweir { 700*cdf0e10cSrcweir return ( 701*cdf0e10cSrcweir GC.Transformation.get(0,0) == 100.00 && 702*cdf0e10cSrcweir GC.Transformation.get(1,0) == 0.00 && 703*cdf0e10cSrcweir GC.Transformation.get(0,1) == 0.00 && 704*cdf0e10cSrcweir GC.Transformation.get(1,1) == -100.00 705*cdf0e10cSrcweir ); 706*cdf0e10cSrcweir } 707*cdf0e10cSrcweir 708*cdf0e10cSrcweir void DrawXmlOptimizer::optimizeTextElements(Element& rParent) 709*cdf0e10cSrcweir { 710*cdf0e10cSrcweir if( rParent.Children.empty() ) // this should not happen 711*cdf0e10cSrcweir { 712*cdf0e10cSrcweir OSL_ENSURE( 0, "empty paragraph optimized" ); 713*cdf0e10cSrcweir return; 714*cdf0e10cSrcweir } 715*cdf0e10cSrcweir 716*cdf0e10cSrcweir // concatenate child elements with same font id 717*cdf0e10cSrcweir std::list< Element* >::iterator next = rParent.Children.begin(); 718*cdf0e10cSrcweir std::list< Element* >::iterator it = next++; 719*cdf0e10cSrcweir FrameElement* pFrame = dynamic_cast<FrameElement*>(rParent.Parent); 720*cdf0e10cSrcweir bool bRotatedFrame = false; 721*cdf0e10cSrcweir if( pFrame ) 722*cdf0e10cSrcweir { 723*cdf0e10cSrcweir const GraphicsContext& rFrameGC = m_rProcessor.getGraphicsContext( pFrame->GCId ); 724*cdf0e10cSrcweir if( rFrameGC.isRotatedOrSkewed() ) 725*cdf0e10cSrcweir bRotatedFrame = true; 726*cdf0e10cSrcweir } 727*cdf0e10cSrcweir while( next != rParent.Children.end() ) 728*cdf0e10cSrcweir { 729*cdf0e10cSrcweir bool bConcat = false; 730*cdf0e10cSrcweir TextElement* pCur = dynamic_cast<TextElement*>(*it); 731*cdf0e10cSrcweir 732*cdf0e10cSrcweir if( pCur ) 733*cdf0e10cSrcweir { 734*cdf0e10cSrcweir TextElement* pNext = dynamic_cast<TextElement*>(*next); 735*cdf0e10cSrcweir bool isComplex = false; 736*cdf0e10cSrcweir rtl::OUString str(pCur->Text.getStr()); 737*cdf0e10cSrcweir for(int i=0; i< str.getLength(); i++) 738*cdf0e10cSrcweir { 739*cdf0e10cSrcweir sal_Int16 nType = GetBreakIterator()->getScriptType( str, i ); 740*cdf0e10cSrcweir if (nType == ::com::sun::star::i18n::ScriptType::COMPLEX) 741*cdf0e10cSrcweir isComplex = true; 742*cdf0e10cSrcweir } 743*cdf0e10cSrcweir bool bPara = strspn("ParagraphElement", typeid(rParent).name()); 744*cdf0e10cSrcweir ParagraphElement* pPara = dynamic_cast<ParagraphElement*>(&rParent); 745*cdf0e10cSrcweir if (bPara && isComplex) 746*cdf0e10cSrcweir pPara->bRtl = true; 747*cdf0e10cSrcweir if( pNext ) 748*cdf0e10cSrcweir { 749*cdf0e10cSrcweir const GraphicsContext& rCurGC = m_rProcessor.getGraphicsContext( pCur->GCId ); 750*cdf0e10cSrcweir const GraphicsContext& rNextGC = m_rProcessor.getGraphicsContext( pNext->GCId ); 751*cdf0e10cSrcweir 752*cdf0e10cSrcweir // line and space optimization; works only in strictly horizontal mode 753*cdf0e10cSrcweir 754*cdf0e10cSrcweir // concatenate consecutive text elements unless there is a 755*cdf0e10cSrcweir // font or text color or matrix change, leave a new span in that case 756*cdf0e10cSrcweir if( (pCur->FontId == pNext->FontId || isSpaces(pNext)) && 757*cdf0e10cSrcweir rCurGC.FillColor.Red == rNextGC.FillColor.Red && 758*cdf0e10cSrcweir rCurGC.FillColor.Green == rNextGC.FillColor.Green && 759*cdf0e10cSrcweir rCurGC.FillColor.Blue == rNextGC.FillColor.Blue && 760*cdf0e10cSrcweir rCurGC.FillColor.Alpha == rNextGC.FillColor.Alpha && 761*cdf0e10cSrcweir (rCurGC.Transformation == rNextGC.Transformation || notTransformed(rNextGC)) 762*cdf0e10cSrcweir ) 763*cdf0e10cSrcweir { 764*cdf0e10cSrcweir pCur->updateGeometryWith( pNext ); 765*cdf0e10cSrcweir // append text to current element 766*cdf0e10cSrcweir pCur->Text.append( pNext->Text.getStr(), pNext->Text.getLength() ); 767*cdf0e10cSrcweir 768*cdf0e10cSrcweir str = pCur->Text.getStr(); 769*cdf0e10cSrcweir for(int i=0; i< str.getLength(); i++) 770*cdf0e10cSrcweir { 771*cdf0e10cSrcweir sal_Int16 nType = GetBreakIterator()->getScriptType( str, i ); 772*cdf0e10cSrcweir if (nType == ::com::sun::star::i18n::ScriptType::COMPLEX) 773*cdf0e10cSrcweir isComplex = true; 774*cdf0e10cSrcweir } 775*cdf0e10cSrcweir if (bPara && isComplex) 776*cdf0e10cSrcweir pPara->bRtl = true; 777*cdf0e10cSrcweir // append eventual children to current element 778*cdf0e10cSrcweir // and clear children (else the children just 779*cdf0e10cSrcweir // appended to pCur would be destroyed) 780*cdf0e10cSrcweir pCur->Children.splice( pCur->Children.end(), pNext->Children ); 781*cdf0e10cSrcweir // get rid of the now useless element 782*cdf0e10cSrcweir rParent.Children.erase( next ); 783*cdf0e10cSrcweir delete pNext; 784*cdf0e10cSrcweir bConcat = true; 785*cdf0e10cSrcweir } 786*cdf0e10cSrcweir } 787*cdf0e10cSrcweir } 788*cdf0e10cSrcweir else if( dynamic_cast<HyperlinkElement*>(*it) ) 789*cdf0e10cSrcweir optimizeTextElements( **it ); 790*cdf0e10cSrcweir if ( bConcat ) 791*cdf0e10cSrcweir next = it; 792*cdf0e10cSrcweir else 793*cdf0e10cSrcweir ++it; 794*cdf0e10cSrcweir ++next; 795*cdf0e10cSrcweir } 796*cdf0e10cSrcweir } 797*cdf0e10cSrcweir 798*cdf0e10cSrcweir void DrawXmlOptimizer::visit( DocumentElement& elem, const std::list< Element* >::const_iterator&) 799*cdf0e10cSrcweir { 800*cdf0e10cSrcweir elem.applyToChildren(*this); 801*cdf0e10cSrcweir } 802*cdf0e10cSrcweir 803*cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////////////////// 804*cdf0e10cSrcweir 805*cdf0e10cSrcweir 806*cdf0e10cSrcweir void DrawXmlFinalizer::visit( PolyPolyElement& elem, const std::list< Element* >::const_iterator& ) 807*cdf0e10cSrcweir { 808*cdf0e10cSrcweir // xxx TODO copied from DrawElement 809*cdf0e10cSrcweir const GraphicsContext& rGC = m_rProcessor.getGraphicsContext(elem.GCId ); 810*cdf0e10cSrcweir PropertyMap aProps; 811*cdf0e10cSrcweir aProps[ USTR( "style:family" ) ] = USTR( "graphic" ); 812*cdf0e10cSrcweir aProps[ USTR( "style:parent-style-name") ] = USTR( "standard" ); 813*cdf0e10cSrcweir // generate standard graphic style if necessary 814*cdf0e10cSrcweir m_rStyleContainer.getStandardStyleId( "graphic" ); 815*cdf0e10cSrcweir 816*cdf0e10cSrcweir PropertyMap aGCProps; 817*cdf0e10cSrcweir 818*cdf0e10cSrcweir // TODO(F3): proper dash emulation 819*cdf0e10cSrcweir if( elem.Action & PATH_STROKE ) 820*cdf0e10cSrcweir { 821*cdf0e10cSrcweir aGCProps[ USTR("draw:stroke") ] = rGC.DashArray.empty() ? USTR("solid") : USTR("dash"); 822*cdf0e10cSrcweir aGCProps[ USTR("svg:stroke-color") ] = getColorString( rGC.LineColor ); 823*cdf0e10cSrcweir if( rGC.LineWidth != 0.0 ) 824*cdf0e10cSrcweir { 825*cdf0e10cSrcweir ::basegfx::B2DVector aVec(rGC.LineWidth,0); 826*cdf0e10cSrcweir aVec *= rGC.Transformation; 827*cdf0e10cSrcweir 828*cdf0e10cSrcweir aVec.setX ( convPx2mmPrec2( aVec.getX() )*100.0 ); 829*cdf0e10cSrcweir aVec.setY ( convPx2mmPrec2( aVec.getY() )*100.0 ); 830*cdf0e10cSrcweir 831*cdf0e10cSrcweir aGCProps[ USTR("svg:stroke-width") ] = rtl::OUString::valueOf( aVec.getLength() ); 832*cdf0e10cSrcweir } 833*cdf0e10cSrcweir } 834*cdf0e10cSrcweir else 835*cdf0e10cSrcweir { 836*cdf0e10cSrcweir aGCProps[ USTR("draw:stroke") ] = USTR("none"); 837*cdf0e10cSrcweir } 838*cdf0e10cSrcweir 839*cdf0e10cSrcweir // TODO(F1): check whether stuff could be emulated by gradient/bitmap/hatch 840*cdf0e10cSrcweir if( elem.Action & (PATH_FILL | PATH_EOFILL) ) 841*cdf0e10cSrcweir { 842*cdf0e10cSrcweir aGCProps[ USTR("draw:fill") ] = USTR("solid"); 843*cdf0e10cSrcweir aGCProps[ USTR("draw:fill-color") ] = getColorString( rGC.FillColor ); 844*cdf0e10cSrcweir } 845*cdf0e10cSrcweir else 846*cdf0e10cSrcweir { 847*cdf0e10cSrcweir aGCProps[ USTR("draw:fill") ] = USTR("none"); 848*cdf0e10cSrcweir } 849*cdf0e10cSrcweir 850*cdf0e10cSrcweir StyleContainer::Style aStyle( "style:style", aProps ); 851*cdf0e10cSrcweir StyleContainer::Style aSubStyle( "style:graphic-properties", aGCProps ); 852*cdf0e10cSrcweir aStyle.SubStyles.push_back( &aSubStyle ); 853*cdf0e10cSrcweir 854*cdf0e10cSrcweir elem.StyleId = m_rStyleContainer.getStyleId( aStyle ); 855*cdf0e10cSrcweir } 856*cdf0e10cSrcweir 857*cdf0e10cSrcweir void DrawXmlFinalizer::visit( HyperlinkElement&, const std::list< Element* >::const_iterator& ) 858*cdf0e10cSrcweir { 859*cdf0e10cSrcweir } 860*cdf0e10cSrcweir 861*cdf0e10cSrcweir void DrawXmlFinalizer::visit( TextElement& elem, const std::list< Element* >::const_iterator& ) 862*cdf0e10cSrcweir { 863*cdf0e10cSrcweir const FontAttributes& rFont = m_rProcessor.getFont( elem.FontId ); 864*cdf0e10cSrcweir PropertyMap aProps; 865*cdf0e10cSrcweir aProps[ USTR( "style:family" ) ] = USTR( "text" ); 866*cdf0e10cSrcweir 867*cdf0e10cSrcweir PropertyMap aFontProps; 868*cdf0e10cSrcweir 869*cdf0e10cSrcweir // family name 870*cdf0e10cSrcweir aFontProps[ USTR( "fo:font-family" ) ] = rFont.familyName; 871*cdf0e10cSrcweir aFontProps[ USTR( "style:font-family-complex" ) ] = rFont.familyName; 872*cdf0e10cSrcweir 873*cdf0e10cSrcweir // bold 874*cdf0e10cSrcweir if( rFont.isBold ) 875*cdf0e10cSrcweir { 876*cdf0e10cSrcweir aFontProps[ USTR( "fo:font-weight" ) ] = USTR( "bold" ); 877*cdf0e10cSrcweir aFontProps[ USTR( "fo:font-weight-asian" ) ] = USTR( "bold" ); 878*cdf0e10cSrcweir aFontProps[ USTR( "style:font-weight-complex" ) ] = USTR( "bold" ); 879*cdf0e10cSrcweir } 880*cdf0e10cSrcweir // italic 881*cdf0e10cSrcweir if( rFont.isItalic ) 882*cdf0e10cSrcweir { 883*cdf0e10cSrcweir aFontProps[ USTR( "fo:font-style" ) ] = USTR( "italic" ); 884*cdf0e10cSrcweir aFontProps[ USTR( "fo:font-style-asian" ) ] = USTR( "italic" ); 885*cdf0e10cSrcweir aFontProps[ USTR( "style:font-style-complex" ) ] = USTR( "italic" ); 886*cdf0e10cSrcweir } 887*cdf0e10cSrcweir // underline 888*cdf0e10cSrcweir if( rFont.isUnderline ) 889*cdf0e10cSrcweir { 890*cdf0e10cSrcweir aFontProps[ USTR( "style:text-underline-style" ) ] = USTR( "solid" ); 891*cdf0e10cSrcweir aFontProps[ USTR( "style:text-underline-width" ) ] = USTR( "auto" ); 892*cdf0e10cSrcweir aFontProps[ USTR( "style:text-underline-color" ) ] = USTR( "font-color" ); 893*cdf0e10cSrcweir } 894*cdf0e10cSrcweir // outline 895*cdf0e10cSrcweir if( rFont.isOutline ) 896*cdf0e10cSrcweir { 897*cdf0e10cSrcweir aFontProps[ USTR( "style:text-outline" ) ] = USTR( "true" ); 898*cdf0e10cSrcweir } 899*cdf0e10cSrcweir // size 900*cdf0e10cSrcweir rtl::OUStringBuffer aBuf( 32 ); 901*cdf0e10cSrcweir aBuf.append( rFont.size*72/PDFI_OUTDEV_RESOLUTION ); 902*cdf0e10cSrcweir aBuf.appendAscii( "pt" ); 903*cdf0e10cSrcweir rtl::OUString aFSize = aBuf.makeStringAndClear(); 904*cdf0e10cSrcweir aFontProps[ USTR( "fo:font-size" ) ] = aFSize; 905*cdf0e10cSrcweir aFontProps[ USTR( "style:font-size-asian" ) ] = aFSize; 906*cdf0e10cSrcweir aFontProps[ USTR( "style:font-size-complex" ) ] = aFSize; 907*cdf0e10cSrcweir // color 908*cdf0e10cSrcweir const GraphicsContext& rGC = m_rProcessor.getGraphicsContext( elem.GCId ); 909*cdf0e10cSrcweir aFontProps[ USTR( "fo:color" ) ] = getColorString( rFont.isOutline ? rGC.LineColor : rGC.FillColor ); 910*cdf0e10cSrcweir 911*cdf0e10cSrcweir StyleContainer::Style aStyle( "style:style", aProps ); 912*cdf0e10cSrcweir StyleContainer::Style aSubStyle( "style:text-properties", aFontProps ); 913*cdf0e10cSrcweir aStyle.SubStyles.push_back( &aSubStyle ); 914*cdf0e10cSrcweir elem.StyleId = m_rStyleContainer.getStyleId( aStyle ); 915*cdf0e10cSrcweir } 916*cdf0e10cSrcweir 917*cdf0e10cSrcweir void DrawXmlFinalizer::visit( ParagraphElement& elem, const std::list< Element* >::const_iterator& ) 918*cdf0e10cSrcweir { 919*cdf0e10cSrcweir 920*cdf0e10cSrcweir PropertyMap aProps; 921*cdf0e10cSrcweir aProps[ USTR( "style:family" ) ] = USTR( "paragraph" ); 922*cdf0e10cSrcweir // generate standard paragraph style if necessary 923*cdf0e10cSrcweir m_rStyleContainer.getStandardStyleId( "paragraph" ); 924*cdf0e10cSrcweir 925*cdf0e10cSrcweir PropertyMap aParProps; 926*cdf0e10cSrcweir 927*cdf0e10cSrcweir aParProps[ USTR("fo:text-align")] = USTR("start"); 928*cdf0e10cSrcweir if (elem.bRtl) 929*cdf0e10cSrcweir aParProps[ USTR("style:writing-mode")] = USTR("rl-tb"); 930*cdf0e10cSrcweir else 931*cdf0e10cSrcweir aParProps[ USTR("style:writing-mode")] = USTR("lr-tb"); 932*cdf0e10cSrcweir 933*cdf0e10cSrcweir StyleContainer::Style aStyle( "style:style", aProps ); 934*cdf0e10cSrcweir StyleContainer::Style aSubStyle( "style:paragraph-properties", aParProps ); 935*cdf0e10cSrcweir aStyle.SubStyles.push_back( &aSubStyle ); 936*cdf0e10cSrcweir 937*cdf0e10cSrcweir elem.StyleId = m_rStyleContainer.getStyleId( aStyle ); 938*cdf0e10cSrcweir 939*cdf0e10cSrcweir // update page boundaries 940*cdf0e10cSrcweir if( elem.Parent ) 941*cdf0e10cSrcweir { 942*cdf0e10cSrcweir // check for center alignement 943*cdf0e10cSrcweir // criterion: paragraph is small relative to parent and distributed around its center 944*cdf0e10cSrcweir double p_x = elem.Parent->x; 945*cdf0e10cSrcweir double p_y = elem.Parent->y; 946*cdf0e10cSrcweir double p_w = elem.Parent->w; 947*cdf0e10cSrcweir double p_h = elem.Parent->h; 948*cdf0e10cSrcweir 949*cdf0e10cSrcweir PageElement* pPage = dynamic_cast<PageElement*>(elem.Parent); 950*cdf0e10cSrcweir if( pPage ) 951*cdf0e10cSrcweir { 952*cdf0e10cSrcweir p_x += pPage->LeftMargin; 953*cdf0e10cSrcweir p_y += pPage->TopMargin; 954*cdf0e10cSrcweir p_w -= pPage->LeftMargin+pPage->RightMargin; 955*cdf0e10cSrcweir p_h -= pPage->TopMargin+pPage->BottomMargin; 956*cdf0e10cSrcweir } 957*cdf0e10cSrcweir } 958*cdf0e10cSrcweir 959*cdf0e10cSrcweir elem.applyToChildren(*this); 960*cdf0e10cSrcweir } 961*cdf0e10cSrcweir 962*cdf0e10cSrcweir void DrawXmlFinalizer::visit( FrameElement& elem, const std::list< Element* >::const_iterator&) 963*cdf0e10cSrcweir { 964*cdf0e10cSrcweir PropertyMap aProps; 965*cdf0e10cSrcweir aProps[ USTR( "style:family" ) ] = USTR( "graphic" ); 966*cdf0e10cSrcweir aProps[ USTR( "style:parent-style-name") ] = USTR( "standard" ); 967*cdf0e10cSrcweir // generate standard graphic style if necessary 968*cdf0e10cSrcweir m_rStyleContainer.getStandardStyleId( "graphic" ); 969*cdf0e10cSrcweir 970*cdf0e10cSrcweir PropertyMap aGCProps; 971*cdf0e10cSrcweir 972*cdf0e10cSrcweir aGCProps[ USTR("draw:stroke") ] = USTR("none"); 973*cdf0e10cSrcweir aGCProps[ USTR("draw:fill") ] = USTR("none"); 974*cdf0e10cSrcweir aGCProps[ USTR("draw:auto-grow-height") ] = USTR("true"); 975*cdf0e10cSrcweir aGCProps[ USTR("draw:auto-grow-width") ] = USTR("true"); 976*cdf0e10cSrcweir aGCProps[ USTR("draw:textarea-horizontal-align") ] = USTR("left"); 977*cdf0e10cSrcweir aGCProps[ USTR("draw:textarea-vertical-align") ] = USTR("top"); 978*cdf0e10cSrcweir aGCProps[ USTR("fo:min-height")] = USTR("0cm"); 979*cdf0e10cSrcweir aGCProps[ USTR("fo:min-width")] = USTR("0cm"); 980*cdf0e10cSrcweir aGCProps[ USTR("fo:padding-top") ] = USTR("0cm"); 981*cdf0e10cSrcweir aGCProps[ USTR("fo:padding-left") ] = USTR("0cm"); 982*cdf0e10cSrcweir aGCProps[ USTR("fo:padding-right") ] = USTR("0cm"); 983*cdf0e10cSrcweir aGCProps[ USTR("fo:padding-bottom") ] = USTR("0cm"); 984*cdf0e10cSrcweir 985*cdf0e10cSrcweir // remark: vertical mirroring is done in current OOO by 986*cdf0e10cSrcweir // mirroring horzontally and rotating 180 degrees 987*cdf0e10cSrcweir // this is quaint, but unfortunately it seems 988*cdf0e10cSrcweir // mirror=vertical is defined but not implemented in current code 989*cdf0e10cSrcweir if( elem.MirrorVertical ) 990*cdf0e10cSrcweir aGCProps[ USTR("style:mirror") ] = USTR("horizontal"); 991*cdf0e10cSrcweir 992*cdf0e10cSrcweir StyleContainer::Style aStyle( "style:style", aProps ); 993*cdf0e10cSrcweir StyleContainer::Style aSubStyle( "style:graphic-properties", aGCProps ); 994*cdf0e10cSrcweir aStyle.SubStyles.push_back( &aSubStyle ); 995*cdf0e10cSrcweir 996*cdf0e10cSrcweir elem.StyleId = m_rStyleContainer.getStyleId( aStyle ); 997*cdf0e10cSrcweir elem.applyToChildren(*this); 998*cdf0e10cSrcweir } 999*cdf0e10cSrcweir 1000*cdf0e10cSrcweir void DrawXmlFinalizer::visit( ImageElement&, const std::list< Element* >::const_iterator& ) 1001*cdf0e10cSrcweir { 1002*cdf0e10cSrcweir } 1003*cdf0e10cSrcweir 1004*cdf0e10cSrcweir void DrawXmlFinalizer::visit( PageElement& elem, const std::list< Element* >::const_iterator& ) 1005*cdf0e10cSrcweir { 1006*cdf0e10cSrcweir if( m_rProcessor.getStatusIndicator().is() ) 1007*cdf0e10cSrcweir m_rProcessor.getStatusIndicator()->setValue( elem.PageNumber ); 1008*cdf0e10cSrcweir 1009*cdf0e10cSrcweir // transform from pixel to mm 1010*cdf0e10cSrcweir double page_width = convPx2mm( elem.w ), page_height = convPx2mm( elem.h ); 1011*cdf0e10cSrcweir 1012*cdf0e10cSrcweir // calculate page margins out of the relevant children (paragraphs) 1013*cdf0e10cSrcweir elem.TopMargin = elem.h, elem.BottomMargin = 0, elem.LeftMargin = elem.w, elem.RightMargin = 0; 1014*cdf0e10cSrcweir 1015*cdf0e10cSrcweir for( std::list< Element* >::const_iterator it = elem.Children.begin(); it != elem.Children.end(); ++it ) 1016*cdf0e10cSrcweir { 1017*cdf0e10cSrcweir if( (*it)->x < elem.LeftMargin ) 1018*cdf0e10cSrcweir elem.LeftMargin = (*it)->x; 1019*cdf0e10cSrcweir if( (*it)->y < elem.TopMargin ) 1020*cdf0e10cSrcweir elem.TopMargin = (*it)->y; 1021*cdf0e10cSrcweir if( (*it)->x + (*it)->w > elem.RightMargin ) 1022*cdf0e10cSrcweir elem.RightMargin = ((*it)->x + (*it)->w); 1023*cdf0e10cSrcweir if( (*it)->y + (*it)->h > elem.BottomMargin ) 1024*cdf0e10cSrcweir elem.BottomMargin = ((*it)->y + (*it)->h); 1025*cdf0e10cSrcweir } 1026*cdf0e10cSrcweir 1027*cdf0e10cSrcweir // transform margins to mm 1028*cdf0e10cSrcweir double left_margin = convPx2mm( elem.LeftMargin ); 1029*cdf0e10cSrcweir double right_margin = convPx2mm( elem.RightMargin ); 1030*cdf0e10cSrcweir double top_margin = convPx2mm( elem.TopMargin ); 1031*cdf0e10cSrcweir double bottom_margin = convPx2mm( elem.BottomMargin ); 1032*cdf0e10cSrcweir 1033*cdf0e10cSrcweir // round left/top margin to nearest mm 1034*cdf0e10cSrcweir left_margin = rtl_math_round( left_margin, 0, rtl_math_RoundingMode_Floor ); 1035*cdf0e10cSrcweir top_margin = rtl_math_round( top_margin, 0, rtl_math_RoundingMode_Floor ); 1036*cdf0e10cSrcweir // round (fuzzy) right/bottom margin to nearest cm 1037*cdf0e10cSrcweir right_margin = rtl_math_round( right_margin, right_margin >= 10 ? -1 : 0, rtl_math_RoundingMode_Floor ); 1038*cdf0e10cSrcweir bottom_margin = rtl_math_round( bottom_margin, bottom_margin >= 10 ? -1 : 0, rtl_math_RoundingMode_Floor ); 1039*cdf0e10cSrcweir 1040*cdf0e10cSrcweir // set reasonable default in case of way too large margins 1041*cdf0e10cSrcweir // e.g. no paragraph case 1042*cdf0e10cSrcweir if( left_margin > page_width/2.0 - 10 ) 1043*cdf0e10cSrcweir left_margin = 10; 1044*cdf0e10cSrcweir if( right_margin > page_width/2.0 - 10 ) 1045*cdf0e10cSrcweir right_margin = 10; 1046*cdf0e10cSrcweir if( top_margin > page_height/2.0 - 10 ) 1047*cdf0e10cSrcweir top_margin = 10; 1048*cdf0e10cSrcweir if( bottom_margin > page_height/2.0 - 10 ) 1049*cdf0e10cSrcweir bottom_margin = 10; 1050*cdf0e10cSrcweir 1051*cdf0e10cSrcweir // catch the weird cases 1052*cdf0e10cSrcweir if( left_margin < 0 ) 1053*cdf0e10cSrcweir left_margin = 0; 1054*cdf0e10cSrcweir if( right_margin < 0 ) 1055*cdf0e10cSrcweir right_margin = 0; 1056*cdf0e10cSrcweir if( top_margin < 0 ) 1057*cdf0e10cSrcweir top_margin = 0; 1058*cdf0e10cSrcweir if( bottom_margin < 0 ) 1059*cdf0e10cSrcweir bottom_margin = 0; 1060*cdf0e10cSrcweir 1061*cdf0e10cSrcweir // widely differing margins are unlikely to be correct 1062*cdf0e10cSrcweir if( right_margin > left_margin*1.5 ) 1063*cdf0e10cSrcweir right_margin = left_margin; 1064*cdf0e10cSrcweir 1065*cdf0e10cSrcweir elem.LeftMargin = convmm2Px( left_margin ); 1066*cdf0e10cSrcweir elem.RightMargin = convmm2Px( right_margin ); 1067*cdf0e10cSrcweir elem.TopMargin = convmm2Px( top_margin ); 1068*cdf0e10cSrcweir elem.BottomMargin = convmm2Px( bottom_margin ); 1069*cdf0e10cSrcweir 1070*cdf0e10cSrcweir // get styles for paragraphs 1071*cdf0e10cSrcweir PropertyMap aPageProps; 1072*cdf0e10cSrcweir PropertyMap aPageLayoutProps; 1073*cdf0e10cSrcweir rtl::OUStringBuffer aBuf( 64 ); 1074*cdf0e10cSrcweir aPageLayoutProps[ USTR( "fo:margin-top" ) ] = unitMMString( top_margin ); 1075*cdf0e10cSrcweir aPageLayoutProps[ USTR( "fo:margin-bottom" ) ] = unitMMString( bottom_margin ); 1076*cdf0e10cSrcweir aPageLayoutProps[ USTR( "fo:margin-left" ) ] = unitMMString( left_margin ); 1077*cdf0e10cSrcweir aPageLayoutProps[ USTR( "fo:margin-right" ) ] = unitMMString( right_margin ); 1078*cdf0e10cSrcweir aPageLayoutProps[ USTR( "fo:page-width" ) ] = unitMMString( page_width ); 1079*cdf0e10cSrcweir aPageLayoutProps[ USTR( "fo:page-height" ) ] = unitMMString( page_height ); 1080*cdf0e10cSrcweir aPageLayoutProps[ USTR( "style:print-orientation" ) ]= elem.w < elem.h ? USTR( "portrait" ) : USTR( "landscape" ); 1081*cdf0e10cSrcweir aPageLayoutProps[ USTR( "style:writing-mode" ) ]= USTR( "lr-tb" ); 1082*cdf0e10cSrcweir 1083*cdf0e10cSrcweir StyleContainer::Style aStyle( "style:page-layout", aPageProps); 1084*cdf0e10cSrcweir StyleContainer::Style aSubStyle( "style:page-layout-properties", aPageLayoutProps); 1085*cdf0e10cSrcweir aStyle.SubStyles.push_back(&aSubStyle); 1086*cdf0e10cSrcweir sal_Int32 nPageStyle = m_rStyleContainer.impl_getStyleId( aStyle, false ); 1087*cdf0e10cSrcweir 1088*cdf0e10cSrcweir // create master page 1089*cdf0e10cSrcweir rtl::OUString aMasterPageLayoutName = m_rStyleContainer.getStyleName( nPageStyle ); 1090*cdf0e10cSrcweir aPageProps[ USTR( "style:page-layout-name" ) ] = aMasterPageLayoutName; 1091*cdf0e10cSrcweir 1092*cdf0e10cSrcweir StyleContainer::Style aMPStyle( "style:master-page", aPageProps); 1093*cdf0e10cSrcweir 1094*cdf0e10cSrcweir StyleContainer::Style aHeaderStyle( "style:header", PropertyMap() ); 1095*cdf0e10cSrcweir StyleContainer::Style aFooterStyle( "style:footer", PropertyMap() ); 1096*cdf0e10cSrcweir 1097*cdf0e10cSrcweir elem.StyleId = m_rStyleContainer.impl_getStyleId( aMPStyle,false ); 1098*cdf0e10cSrcweir 1099*cdf0e10cSrcweir 1100*cdf0e10cSrcweir rtl::OUString aMasterPageName = m_rStyleContainer.getStyleName( elem.StyleId ); 1101*cdf0e10cSrcweir 1102*cdf0e10cSrcweir // create styles for children 1103*cdf0e10cSrcweir elem.applyToChildren(*this); 1104*cdf0e10cSrcweir } 1105*cdf0e10cSrcweir 1106*cdf0e10cSrcweir void DrawXmlFinalizer::visit( DocumentElement& elem, const std::list< Element* >::const_iterator& ) 1107*cdf0e10cSrcweir { 1108*cdf0e10cSrcweir elem.applyToChildren(*this); 1109*cdf0e10cSrcweir } 1110*cdf0e10cSrcweir 1111*cdf0e10cSrcweir } 1112