summaryrefslogtreecommitdiff
path: root/sdext/source/pdfimport/tree
diff options
context:
space:
mode:
Diffstat (limited to 'sdext/source/pdfimport/tree')
-rw-r--r--sdext/source/pdfimport/tree/drawtreevisiting.cxx1087
-rw-r--r--sdext/source/pdfimport/tree/drawtreevisiting.hxx132
-rw-r--r--sdext/source/pdfimport/tree/genericelements.cxx496
-rw-r--r--sdext/source/pdfimport/tree/genericelements.hxx326
-rw-r--r--sdext/source/pdfimport/tree/imagecontainer.cxx156
-rw-r--r--sdext/source/pdfimport/tree/imagecontainer.hxx63
-rw-r--r--sdext/source/pdfimport/tree/makefile.mk56
-rw-r--r--sdext/source/pdfimport/tree/pdfiprocessor.cxx1463
-rw-r--r--sdext/source/pdfimport/tree/pdfiprocessor.hxx309
-rw-r--r--sdext/source/pdfimport/tree/style.cxx262
-rw-r--r--sdext/source/pdfimport/tree/style.hxx184
-rw-r--r--sdext/source/pdfimport/tree/treevisiting.hxx83
-rw-r--r--sdext/source/pdfimport/tree/treevisitorfactory.cxx124
-rw-r--r--sdext/source/pdfimport/tree/writertreevisiting.cxx1221
-rw-r--r--sdext/source/pdfimport/tree/writertreevisiting.hxx119
15 files changed, 6081 insertions, 0 deletions
diff --git a/sdext/source/pdfimport/tree/drawtreevisiting.cxx b/sdext/source/pdfimport/tree/drawtreevisiting.cxx
new file mode 100644
index 000000000000..37f9785e1469
--- /dev/null
+++ b/sdext/source/pdfimport/tree/drawtreevisiting.cxx
@@ -0,0 +1,1087 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_sdext.hxx"
+
+#include "pdfiprocessor.hxx"
+#include "xmlemitter.hxx"
+#include "pdfihelper.hxx"
+#include "imagecontainer.hxx"
+#include "style.hxx"
+#include "drawtreevisiting.hxx"
+#include "genericelements.hxx"
+
+#include "basegfx/polygon/b2dpolypolygontools.hxx"
+#include "basegfx/range/b2drange.hxx"
+
+#include "com/sun/star/i18n/XBreakIterator.hpp"
+#include "com/sun/star/lang/XMultiServiceFactory.hpp"
+#include "comphelper/processfactory.hxx"
+#include "com/sun/star/i18n/ScriptType.hpp"
+#include "com/sun/star/i18n/DirectionProperty.hpp"
+
+#include <string.h>
+
+using namespace ::com::sun::star;
+using namespace ::com::sun::star;
+using namespace ::com::sun::star::lang;
+using namespace ::com::sun::star::i18n;
+using namespace ::com::sun::star::uno;
+
+namespace pdfi
+{
+
+const ::com::sun::star::uno::Reference< ::com::sun::star::i18n::XBreakIterator >& DrawXmlOptimizer::GetBreakIterator()
+{
+ if ( !mxBreakIter.is() )
+ {
+ Reference< XComponentContext > xContext( this->m_rProcessor.m_xContext, uno::UNO_SET_THROW );
+ Reference< XMultiComponentFactory > xMSF( xContext->getServiceManager(), uno::UNO_SET_THROW );
+ Reference < XInterface > xInterface = xMSF->createInstanceWithContext(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.i18n.BreakIterator")), xContext);
+
+ mxBreakIter = uno::Reference< i18n::XBreakIterator >( xInterface, uno::UNO_QUERY );
+ }
+ return mxBreakIter;
+}
+
+const ::com::sun::star::uno::Reference< ::com::sun::star::i18n::XBreakIterator >& DrawXmlEmitter::GetBreakIterator()
+{
+ if ( !mxBreakIter.is() )
+ {
+ Reference< XComponentContext > xContext( m_rEmitContext.m_xContext, uno::UNO_SET_THROW );
+ Reference< XMultiComponentFactory > xMSF( xContext->getServiceManager(), uno::UNO_SET_THROW );
+ Reference < XInterface > xInterface = xMSF->createInstanceWithContext(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.i18n.BreakIterator")), xContext);
+ mxBreakIter = uno::Reference< i18n::XBreakIterator >( xInterface, uno::UNO_QUERY );
+ }
+ return mxBreakIter;
+}
+
+const ::com::sun::star::uno::Reference< ::com::sun::star::i18n::XCharacterClassification >& DrawXmlEmitter::GetCharacterClassification()
+{
+ if ( !mxCharClass.is() )
+ {
+ Reference< XComponentContext > xContext( m_rEmitContext.m_xContext, uno::UNO_SET_THROW );
+ Reference< XMultiComponentFactory > xMSF( xContext->getServiceManager(), uno::UNO_SET_THROW );
+ Reference < XInterface > xInterface = xMSF->createInstanceWithContext(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.i18n.CharacterClassification")), xContext);
+ mxCharClass = uno::Reference< i18n::XCharacterClassification >( xInterface, uno::UNO_QUERY );
+ }
+ return mxCharClass;
+}
+
+void DrawXmlEmitter::visit( HyperlinkElement& elem, const std::list< Element* >::const_iterator& )
+{
+ if( elem.Children.empty() )
+ return;
+
+ const char* pType = dynamic_cast<DrawElement*>(elem.Children.front()) ? "draw:a" : "text:a";
+
+ PropertyMap aProps;
+ aProps[ USTR( "xlink:type" ) ] = USTR( "simple" );
+ aProps[ USTR( "xlink:href" ) ] = elem.URI;
+ aProps[ USTR( "office:target-frame-name" ) ] = USTR( "_blank" );
+ aProps[ USTR( "xlink:show" ) ] = USTR( "new" );
+
+ m_rEmitContext.rEmitter.beginTag( pType, aProps );
+ std::list< Element* >::iterator this_it = elem.Children.begin();
+ while( this_it !=elem.Children.end() && *this_it != &elem )
+ {
+ (*this_it)->visitedBy( *this, this_it );
+ ++this_it;
+ }
+ m_rEmitContext.rEmitter.endTag( pType );
+}
+
+void DrawXmlEmitter::visit( TextElement& elem, const std::list< Element* >::const_iterator& )
+{
+ if( ! elem.Text.getLength() )
+ return;
+
+ rtl::OUString strSpace(32);
+ rtl::OUString strNbSpace(160);
+ rtl::OUString tabSpace(0x09);
+ PropertyMap aProps;
+ if( elem.StyleId != -1 )
+ {
+ aProps[ rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "text:style-name" ) ) ] =
+ m_rEmitContext.rStyles.getStyleName( elem.StyleId );
+ }
+
+ rtl::OUString str(elem.Text.getStr());
+
+ // Check for RTL
+ bool isRTL = false;
+ Reference< i18n::XCharacterClassification > xCC( GetCharacterClassification() );
+ if( xCC.is() )
+ {
+ for(int i=1; i< elem.Text.getLength(); i++)
+ {
+ sal_Int16 nType = xCC->getCharacterDirection( str, i );
+ if ( nType == ::com::sun::star::i18n::DirectionProperty_RIGHT_TO_LEFT ||
+ nType == ::com::sun::star::i18n::DirectionProperty_RIGHT_TO_LEFT_ARABIC ||
+ nType == ::com::sun::star::i18n::DirectionProperty_RIGHT_TO_LEFT_EMBEDDING ||
+ nType == ::com::sun::star::i18n::DirectionProperty_RIGHT_TO_LEFT_OVERRIDE
+ )
+ isRTL = true;
+ }
+ }
+
+ if (isRTL) // If so, reverse string
+ str = m_rProcessor.mirrorString( str );
+
+ m_rEmitContext.rEmitter.beginTag( "text:span", aProps );
+
+ for(int i=0; i< elem.Text.getLength(); i++)
+ {
+ rtl::OUString strToken= str.copy(i,1) ;
+ if( strSpace.equals(strToken) || strNbSpace.equals(strToken))
+ {
+ aProps[ USTR( "text:c" ) ] = USTR( "1" );
+ m_rEmitContext.rEmitter.beginTag( "text:s", aProps );
+ m_rEmitContext.rEmitter.endTag( "text:s");
+ }
+ else
+ {
+ if( tabSpace.equals(strToken) )
+ {
+ m_rEmitContext.rEmitter.beginTag( "text:tab", aProps );
+ m_rEmitContext.rEmitter.endTag( "text:tab");
+ }
+ else
+ {
+ m_rEmitContext.rEmitter.write( strToken );
+ }
+ }
+ }
+
+ std::list< Element* >::iterator this_it = elem.Children.begin();
+ while( this_it !=elem.Children.end() && *this_it != &elem )
+ {
+ (*this_it)->visitedBy( *this, this_it );
+ ++this_it;
+ }
+
+ m_rEmitContext.rEmitter.endTag( "text:span" );
+}
+
+void DrawXmlEmitter::visit( ParagraphElement& elem, const std::list< Element* >::const_iterator& )
+{
+ PropertyMap aProps;
+ if( elem.StyleId != -1 )
+ {
+ aProps[ USTR( "text:style-name" ) ] = m_rEmitContext.rStyles.getStyleName( elem.StyleId );
+ }
+ const char* pTagType = "text:p";
+ if( elem.Type == elem.Headline )
+ pTagType = "text:h";
+ m_rEmitContext.rEmitter.beginTag( pTagType, aProps );
+
+ std::list< Element* >::iterator this_it = elem.Children.begin();
+ while( this_it !=elem.Children.end() && *this_it != &elem )
+ {
+ (*this_it)->visitedBy( *this, this_it );
+ ++this_it;
+ }
+
+ m_rEmitContext.rEmitter.endTag( pTagType );
+}
+
+void DrawXmlEmitter::fillFrameProps( DrawElement& rElem,
+ PropertyMap& rProps,
+ const EmitContext& rEmitContext,
+ bool bWasTransformed
+ )
+{
+ double rel_x = rElem.x, rel_y = rElem.y;
+
+ rProps[ USTR( "draw:z-index" ) ] = rtl::OUString::valueOf( rElem.ZOrder );
+ rProps[ USTR( "draw:style-name" )] = rEmitContext.rStyles.getStyleName( rElem.StyleId );
+ rProps[ USTR( "svg:width" ) ] = convertPixelToUnitString( rElem.w );
+ rProps[ USTR( "svg:height" ) ] = convertPixelToUnitString( rElem.h );
+
+ const GraphicsContext& rGC =
+ rEmitContext.rProcessor.getGraphicsContext( rElem.GCId );
+ if( rGC.Transformation.isIdentity() || bWasTransformed )
+ {
+ rProps[ USTR( "svg:x" ) ] = convertPixelToUnitString( rel_x );
+ rProps[ USTR( "svg:y" ) ] = convertPixelToUnitString( rel_y );
+ }
+ else
+ {
+ basegfx::B2DTuple aScale, aTranslation;
+ double fRotate, fShearX;
+
+ rGC.Transformation.decompose( aScale, aTranslation, fRotate, fShearX );
+
+ rtl::OUStringBuffer aBuf( 256 );
+
+ // TODO(F2): general transformation case missing; if implemented, note
+ // that ODF rotation is oriented the other way
+
+ // vertical mirroring is done by horizontally mirroring and rotaing 180 degree
+ // quaint !
+ if( rElem.MirrorVertical )
+ fRotate += M_PI;
+
+ // build transformation string
+ if( fShearX != 0.0 )
+ {
+ aBuf.appendAscii( "skewX( " );
+ aBuf.append( fShearX );
+ aBuf.appendAscii( " )" );
+ }
+ if( fRotate != 0.0 )
+ {
+ if( aBuf.getLength() > 0 )
+ aBuf.append( sal_Unicode(' ') );
+ aBuf.appendAscii( "rotate( " );
+ aBuf.append( -fRotate );
+ aBuf.appendAscii( " )" );
+
+ }
+ if( aBuf.getLength() > 0 )
+ aBuf.append( sal_Unicode(' ') );
+ aBuf.appendAscii( "translate( " );
+ aBuf.append( convertPixelToUnitString( rel_x ) );
+ aBuf.append( sal_Unicode(' ') );
+ aBuf.append( convertPixelToUnitString( rel_y ) );
+ aBuf.appendAscii( " )" );
+
+ rProps[ USTR( "draw:transform" ) ] = aBuf.makeStringAndClear();
+ }
+}
+
+void DrawXmlEmitter::visit( FrameElement& elem, const std::list< Element* >::const_iterator& )
+{
+ if( elem.Children.empty() )
+ return;
+
+ bool bTextBox = (dynamic_cast<ParagraphElement*>(elem.Children.front()) != NULL);
+ PropertyMap aFrameProps;
+ fillFrameProps( elem, aFrameProps, m_rEmitContext );
+ m_rEmitContext.rEmitter.beginTag( "draw:frame", aFrameProps );
+ if( bTextBox )
+ m_rEmitContext.rEmitter.beginTag( "draw:text-box", PropertyMap() );
+
+ std::list< Element* >::iterator this_it = elem.Children.begin();
+ while( this_it !=elem.Children.end() && *this_it != &elem )
+ {
+ (*this_it)->visitedBy( *this, this_it );
+ ++this_it;
+ }
+
+ if( bTextBox )
+ m_rEmitContext.rEmitter.endTag( "draw:text-box" );
+ m_rEmitContext.rEmitter.endTag( "draw:frame" );
+}
+
+void DrawXmlEmitter::visit( PolyPolyElement& elem, const std::list< Element* >::const_iterator& )
+{
+ elem.updateGeometry();
+ /* note:
+ * aw recommends using 100dth of mm in all respects since the xml import
+ * (a) is buggy (see issue 37213)
+ * (b) is optimized for 100dth of mm and does not scale itself then,
+ * this does not gain us speed but makes for smaller rounding errors since
+ * the xml importer coordinates are integer based
+ */
+ for (sal_uInt32 i = 0; i< elem.PolyPoly.count(); i++)
+ {
+ basegfx::B2DPolygon b2dPolygon;
+ b2dPolygon = elem.PolyPoly.getB2DPolygon( i );
+
+ for ( sal_uInt32 j = 0; j< b2dPolygon.count(); j++ )
+ {
+ basegfx::B2DPoint point;
+ basegfx::B2DPoint nextPoint;
+ point = b2dPolygon.getB2DPoint( j );
+
+ basegfx::B2DPoint prevPoint;
+ prevPoint = b2dPolygon.getPrevControlPoint( j ) ;
+
+ point.setX( convPx2mmPrec2( point.getX() )*100.0 );
+ point.setY( convPx2mmPrec2( point.getY() )*100.0 );
+
+ if ( b2dPolygon.isPrevControlPointUsed( j ) )
+ {
+ prevPoint.setX( convPx2mmPrec2( prevPoint.getX() )*100.0 );
+ prevPoint.setY( convPx2mmPrec2( prevPoint.getY() )*100.0 );
+ }
+
+ if ( b2dPolygon.isNextControlPointUsed( j ) )
+ {
+ nextPoint = b2dPolygon.getNextControlPoint( j ) ;
+ nextPoint.setX( convPx2mmPrec2( nextPoint.getX() )*100.0 );
+ nextPoint.setY( convPx2mmPrec2( nextPoint.getY() )*100.0 );
+ }
+
+ b2dPolygon.setB2DPoint( j, point );
+
+ if ( b2dPolygon.isPrevControlPointUsed( j ) )
+ b2dPolygon.setPrevControlPoint( j , prevPoint ) ;
+
+ if ( b2dPolygon.isNextControlPointUsed( j ) )
+ b2dPolygon.setNextControlPoint( j , nextPoint ) ;
+ }
+
+ elem.PolyPoly.setB2DPolygon( i, b2dPolygon );
+ }
+
+ PropertyMap aProps;
+ // PDFIProcessor transforms geometrical objects, not images and text
+ // so we need to tell fillFrameProps here that the transformation for
+ // a PolyPolyElement was already applied (aside form translation)
+ fillFrameProps( elem, aProps, m_rEmitContext, true );
+ rtl::OUStringBuffer aBuf( 64 );
+ aBuf.appendAscii( "0 0 " );
+ aBuf.append( convPx2mmPrec2(elem.w)*100.0 );
+ aBuf.append( sal_Unicode(' ') );
+ aBuf.append( convPx2mmPrec2(elem.h)*100.0 );
+ aProps[ USTR( "svg:viewBox" ) ] = aBuf.makeStringAndClear();
+ aProps[ USTR( "svg:d" ) ] = basegfx::tools::exportToSvgD( elem.PolyPoly );
+
+ m_rEmitContext.rEmitter.beginTag( "draw:path", aProps );
+ m_rEmitContext.rEmitter.endTag( "draw:path" );
+}
+
+void DrawXmlEmitter::visit( ImageElement& elem, const std::list< Element* >::const_iterator& )
+{
+ PropertyMap aImageProps;
+ m_rEmitContext.rEmitter.beginTag( "draw:image", aImageProps );
+ m_rEmitContext.rEmitter.beginTag( "office:binary-data", PropertyMap() );
+ m_rEmitContext.rImages.writeBase64EncodedStream( elem.Image, m_rEmitContext);
+ m_rEmitContext.rEmitter.endTag( "office:binary-data" );
+ m_rEmitContext.rEmitter.endTag( "draw:image" );
+}
+
+void DrawXmlEmitter::visit( PageElement& elem, const std::list< Element* >::const_iterator& )
+{
+ PropertyMap aPageProps;
+ aPageProps[ USTR( "draw:master-page-name" ) ] = m_rEmitContext.rStyles.getStyleName( elem.StyleId );
+
+ m_rEmitContext.rEmitter.beginTag("draw:page", aPageProps);
+
+ if( m_rEmitContext.xStatusIndicator.is() )
+ m_rEmitContext.xStatusIndicator->setValue( elem.PageNumber );
+
+ std::list< Element* >::iterator this_it = elem.Children.begin();
+ while( this_it !=elem.Children.end() && *this_it != &elem )
+ {
+ (*this_it)->visitedBy( *this, this_it );
+ ++this_it;
+ }
+
+ m_rEmitContext.rEmitter.endTag("draw:page");
+}
+
+void DrawXmlEmitter::visit( DocumentElement& elem, const std::list< Element* >::const_iterator&)
+{
+ m_rEmitContext.rEmitter.beginTag( "office:body", PropertyMap() );
+ m_rEmitContext.rEmitter.beginTag( m_bWriteDrawDocument ? "office:drawing" : "office:presentation",
+ PropertyMap() );
+
+ std::list< Element* >::iterator this_it = elem.Children.begin();
+ while( this_it !=elem.Children.end() && *this_it != &elem )
+ {
+ (*this_it)->visitedBy( *this, this_it );
+ ++this_it;
+ }
+
+ m_rEmitContext.rEmitter.endTag( m_bWriteDrawDocument ? "office:drawing" : "office:presentation" );
+ m_rEmitContext.rEmitter.endTag( "office:body" );
+}
+
+/////////////////////////////////////////////////////////////////
+
+void DrawXmlOptimizer::visit( HyperlinkElement&, const std::list< Element* >::const_iterator& )
+{
+}
+
+void DrawXmlOptimizer::visit( TextElement&, const std::list< Element* >::const_iterator&)
+{
+}
+
+void DrawXmlOptimizer::visit( FrameElement& elem, const std::list< Element* >::const_iterator& )
+{
+ elem.applyToChildren(*this);
+}
+
+void DrawXmlOptimizer::visit( ImageElement&, const std::list< Element* >::const_iterator& )
+{
+}
+
+void DrawXmlOptimizer::visit( PolyPolyElement& elem, const std::list< Element* >::const_iterator& )
+{
+ /* note: optimize two consecutive PolyPolyElements that
+ * have the same path but one of which is a stroke while
+ * the other is a fill
+ */
+ if( elem.Parent )
+ {
+ // find following PolyPolyElement in parent's children list
+ std::list< Element* >::iterator this_it = elem.Parent->Children.begin();
+ while( this_it != elem.Parent->Children.end() && *this_it != &elem )
+ ++this_it;
+
+ if( this_it != elem.Parent->Children.end() )
+ {
+ std::list< Element* >::iterator next_it = this_it;
+ if( ++next_it != elem.Parent->Children.end() )
+ {
+ PolyPolyElement* pNext = dynamic_cast<PolyPolyElement*>(*next_it);
+
+ // TODO(F2): this comparison fails for OOo-generated polygons with beziers.
+ if( pNext && pNext->PolyPoly == elem.PolyPoly )
+ {
+ const GraphicsContext& rNextGC =
+ m_rProcessor.getGraphicsContext( pNext->GCId );
+ const GraphicsContext& rThisGC =
+ m_rProcessor.getGraphicsContext( elem.GCId );
+
+ if( rThisGC.BlendMode == rNextGC.BlendMode &&
+ rThisGC.Flatness == rNextGC.Flatness &&
+ rThisGC.Transformation == rNextGC.Transformation &&
+ rThisGC.Clip == rNextGC.Clip &&
+ rThisGC.FillColor.Red == rNextGC.FillColor.Red &&
+ rThisGC.FillColor.Green== rNextGC.FillColor.Green &&
+ rThisGC.FillColor.Blue == rNextGC.FillColor.Blue &&
+ rThisGC.FillColor.Alpha== rNextGC.FillColor.Alpha &&
+ pNext->Action == PATH_STROKE &&
+ (elem.Action == PATH_FILL || elem.Action == PATH_EOFILL) )
+ {
+ GraphicsContext aGC = rThisGC;
+ aGC.LineJoin = rNextGC.LineJoin;
+ aGC.LineCap = rNextGC.LineCap;
+ aGC.LineWidth = rNextGC.LineWidth;
+ aGC.MiterLimit= rNextGC.MiterLimit;
+ aGC.DashArray = rNextGC.DashArray;
+ aGC.LineColor = rNextGC.LineColor;
+ elem.GCId = m_rProcessor.getGCId( aGC );
+
+ elem.Action |= pNext->Action;
+
+ elem.Children.splice( elem.Children.end(), pNext->Children );
+ elem.Parent->Children.erase( next_it );
+ delete pNext;
+ }
+ }
+ }
+ }
+ }
+}
+
+void DrawXmlOptimizer::visit( ParagraphElement& elem, const std::list< Element* >::const_iterator& )
+{
+ optimizeTextElements( elem );
+
+ elem.applyToChildren(*this);
+}
+
+void DrawXmlOptimizer::visit( PageElement& elem, const std::list< Element* >::const_iterator& )
+{
+ if( m_rProcessor.getStatusIndicator().is() )
+ m_rProcessor.getStatusIndicator()->setValue( elem.PageNumber );
+
+ // resolve hyperlinks
+ elem.resolveHyperlinks();
+
+ elem.resolveFontStyles( m_rProcessor ); // underlines and such
+
+ // FIXME: until hyperlinks and font effects are adjusted for
+ // geometrical search handle them before sorting
+ m_rProcessor.sortElements( &elem );
+
+ // find paragraphs in text
+ ParagraphElement* pCurPara = NULL;
+ std::list< Element* >::iterator page_element, next_page_element;
+ next_page_element = elem.Children.begin();
+ double fCurLineHeight = 0.0; // average height of text items in current para
+ int nCurLineElements = 0; // number of line contributing elements in current para
+ double line_left = elem.w, line_right = 0.0;
+ double column_width = elem.w*0.75; // estimate text width
+ // TODO: guess columns
+ while( next_page_element != elem.Children.end() )
+ {
+ page_element = next_page_element++;
+ ParagraphElement* pPagePara = dynamic_cast<ParagraphElement*>(*page_element);
+ if( pPagePara )
+ {
+ pCurPara = pPagePara;
+ // adjust line height and text items
+ fCurLineHeight = 0.0;
+ nCurLineElements = 0;
+ for( std::list< Element* >::iterator it = pCurPara->Children.begin();
+ it != pCurPara->Children.end(); ++it )
+ {
+ TextElement* pTestText = dynamic_cast<TextElement*>(*it);
+ if( pTestText )
+ {
+ fCurLineHeight = (fCurLineHeight*double(nCurLineElements) + pTestText->h)/double(nCurLineElements+1);
+ nCurLineElements++;
+ }
+ }
+ continue;
+ }
+
+ HyperlinkElement* pLink = dynamic_cast<HyperlinkElement*>(*page_element);
+ DrawElement* pDraw = dynamic_cast<DrawElement*>(*page_element);
+ if( ! pDraw && pLink && ! pLink->Children.empty() )
+ pDraw = dynamic_cast<DrawElement*>(pLink->Children.front() );
+ if( pDraw )
+ {
+ // insert small drawing objects as character, else leave them page bound
+
+ bool bInsertToParagraph = false;
+ // first check if this is either inside the paragraph
+ if( pCurPara && pDraw->y < pCurPara->y + pCurPara->h )
+ {
+ if( pDraw->h < fCurLineHeight * 1.5 )
+ {
+ bInsertToParagraph = true;
+ fCurLineHeight = (fCurLineHeight*double(nCurLineElements) + pDraw->h)/double(nCurLineElements+1);
+ nCurLineElements++;
+ // mark draw element as character
+ pDraw->isCharacter = true;
+ }
+ }
+ // or perhaps the draw element begins a new paragraph
+ else if( next_page_element != elem.Children.end() )
+ {
+ TextElement* pText = dynamic_cast<TextElement*>(*next_page_element);
+ if( ! pText )
+ {
+ ParagraphElement* pPara = dynamic_cast<ParagraphElement*>(*next_page_element);
+ if( pPara && ! pPara->Children.empty() )
+ pText = dynamic_cast<TextElement*>(pPara->Children.front());
+ }
+ if( pText && // check there is a text
+ pDraw->h < pText->h*1.5 && // and it is approx the same height
+ // and either upper or lower edge of pDraw is inside text's vertical range
+ ( ( pDraw->y >= pText->y && pDraw->y <= pText->y+pText->h ) ||
+ ( pDraw->y+pDraw->h >= pText->y && pDraw->y+pDraw->h <= pText->y+pText->h )
+ )
+ )
+ {
+ bInsertToParagraph = true;
+ fCurLineHeight = pDraw->h;
+ nCurLineElements = 1;
+ line_left = pDraw->x;
+ line_right = pDraw->x + pDraw->w;
+ // begin a new paragraph
+ pCurPara = NULL;
+ // mark draw element as character
+ pDraw->isCharacter = true;
+ }
+ }
+
+ if( ! bInsertToParagraph )
+ {
+ pCurPara = NULL;
+ continue;
+ }
+ }
+
+ TextElement* pText = dynamic_cast<TextElement*>(*page_element);
+ if( ! pText && pLink && ! pLink->Children.empty() )
+ pText = dynamic_cast<TextElement*>(pLink->Children.front());
+ if( pText )
+ {
+ Element* pGeo = pLink ? static_cast<Element*>(pLink) :
+ static_cast<Element*>(pText);
+ if( pCurPara )
+ {
+ // there was already a text element, check for a new paragraph
+ if( nCurLineElements > 0 )
+ {
+ // if the new text is significantly distant from the paragraph
+ // begin a new paragraph
+ if( pGeo->y > pCurPara->y + pCurPara->h + fCurLineHeight*0.5 )
+ pCurPara = NULL; // insert new paragraph
+ else if( pGeo->y > (pCurPara->y+pCurPara->h - fCurLineHeight*0.05) )
+ {
+ // new paragraph if either the last line of the paragraph
+ // was significantly shorter than the paragraph as a whole
+ if( (line_right - line_left) < pCurPara->w*0.75 )
+ pCurPara = NULL;
+ // or the last line was significantly smaller than the column width
+ else if( (line_right - line_left) < column_width*0.75 )
+ pCurPara = NULL;
+ }
+ }
+
+
+ }
+
+
+ // update line height/width
+ if( pCurPara )
+ {
+ fCurLineHeight = (fCurLineHeight*double(nCurLineElements) + pGeo->h)/double(nCurLineElements+1);
+ nCurLineElements++;
+ if( pGeo->x < line_left )
+ line_left = pGeo->x;
+ if( pGeo->x+pGeo->w > line_right )
+ line_right = pGeo->x+pGeo->w;
+ }
+ else
+ {
+ fCurLineHeight = pGeo->h;
+ nCurLineElements = 1;
+ line_left = pGeo->x;
+ line_right = pGeo->x + pGeo->w;
+ }
+ }
+
+
+ // move element to current paragraph
+ if (! pCurPara ) // new paragraph, insert one
+ {
+ pCurPara = m_rProcessor.getElementFactory()->createParagraphElement( NULL );
+ // set parent
+ pCurPara->Parent = &elem;
+ //insert new paragraph before current element
+ page_element = elem.Children.insert( page_element, pCurPara );
+ // forward iterator to current element again
+ ++ page_element;
+ // update next_element which is now invalid
+ next_page_element = page_element;
+ ++ next_page_element;
+ }
+ Element* pCurEle = *page_element;
+ pCurEle->setParent( page_element, pCurPara );
+ OSL_ENSURE( !pText || pCurEle == pText || pCurEle == pLink, "paragraph child list in disorder" );
+ if( pText || pDraw )
+ pCurPara->updateGeometryWith( pCurEle );
+ }
+
+ // process children
+ elem.applyToChildren(*this);
+}
+
+bool isSpaces(TextElement* pTextElem)
+{
+ rtl::OUString strSpace(32);
+ ::rtl::OUString ouTxt2(pTextElem->Text);
+ for(int i=0; i< pTextElem->Text.getLength(); i++)
+ {
+ rtl::OUString strToken = ouTxt2.copy(i,1) ;
+ if( !strSpace.equals(strToken) )
+ return false;
+ }
+ return true;
+}
+
+bool notTransformed(GraphicsContext GC)
+{
+ return (
+ GC.Transformation.get(0,0) == 100.00 &&
+ GC.Transformation.get(1,0) == 0.00 &&
+ GC.Transformation.get(0,1) == 0.00 &&
+ GC.Transformation.get(1,1) == -100.00
+ );
+}
+
+void DrawXmlOptimizer::optimizeTextElements(Element& rParent)
+{
+ if( rParent.Children.empty() ) // this should not happen
+ {
+ OSL_FAIL( "empty paragraph optimized" );
+ return;
+ }
+
+ // concatenate child elements with same font id
+ std::list< Element* >::iterator next = rParent.Children.begin();
+ std::list< Element* >::iterator it = next++;
+
+ while( next != rParent.Children.end() )
+ {
+ bool bConcat = false;
+ TextElement* pCur = dynamic_cast<TextElement*>(*it);
+
+ if( pCur )
+ {
+ TextElement* pNext = dynamic_cast<TextElement*>(*next);
+ bool isComplex = false;
+ rtl::OUString str(pCur->Text.getStr());
+ for(int i=0; i< str.getLength(); i++)
+ {
+ sal_Int16 nType = GetBreakIterator()->getScriptType( str, i );
+ if (nType == ::com::sun::star::i18n::ScriptType::COMPLEX)
+ isComplex = true;
+ }
+ bool bPara = strspn("ParagraphElement", typeid(rParent).name());
+ ParagraphElement* pPara = dynamic_cast<ParagraphElement*>(&rParent);
+ if (bPara && isComplex)
+ pPara->bRtl = true;
+ if( pNext )
+ {
+ const GraphicsContext& rCurGC = m_rProcessor.getGraphicsContext( pCur->GCId );
+ const GraphicsContext& rNextGC = m_rProcessor.getGraphicsContext( pNext->GCId );
+
+ // line and space optimization; works only in strictly horizontal mode
+
+ // concatenate consecutive text elements unless there is a
+ // font or text color or matrix change, leave a new span in that case
+ if( (pCur->FontId == pNext->FontId || isSpaces(pNext)) &&
+ rCurGC.FillColor.Red == rNextGC.FillColor.Red &&
+ rCurGC.FillColor.Green == rNextGC.FillColor.Green &&
+ rCurGC.FillColor.Blue == rNextGC.FillColor.Blue &&
+ rCurGC.FillColor.Alpha == rNextGC.FillColor.Alpha &&
+ (rCurGC.Transformation == rNextGC.Transformation || notTransformed(rNextGC))
+ )
+ {
+ pCur->updateGeometryWith( pNext );
+ // append text to current element
+ pCur->Text.append( pNext->Text.getStr(), pNext->Text.getLength() );
+
+ str = pCur->Text.getStr();
+ for(int i=0; i< str.getLength(); i++)
+ {
+ sal_Int16 nType = GetBreakIterator()->getScriptType( str, i );
+ if (nType == ::com::sun::star::i18n::ScriptType::COMPLEX)
+ isComplex = true;
+ }
+ if (bPara && isComplex)
+ pPara->bRtl = true;
+ // append eventual children to current element
+ // and clear children (else the children just
+ // appended to pCur would be destroyed)
+ pCur->Children.splice( pCur->Children.end(), pNext->Children );
+ // get rid of the now useless element
+ rParent.Children.erase( next );
+ delete pNext;
+ bConcat = true;
+ }
+ }
+ }
+ else if( dynamic_cast<HyperlinkElement*>(*it) )
+ optimizeTextElements( **it );
+ if ( bConcat )
+ next = it;
+ else
+ ++it;
+ ++next;
+ }
+}
+
+void DrawXmlOptimizer::visit( DocumentElement& elem, const std::list< Element* >::const_iterator&)
+{
+ elem.applyToChildren(*this);
+}
+
+//////////////////////////////////////////////////////////////////////////////////
+
+
+void DrawXmlFinalizer::visit( PolyPolyElement& elem, const std::list< Element* >::const_iterator& )
+{
+ // xxx TODO copied from DrawElement
+ const GraphicsContext& rGC = m_rProcessor.getGraphicsContext(elem.GCId );
+ PropertyMap aProps;
+ aProps[ USTR( "style:family" ) ] = USTR( "graphic" );
+ aProps[ USTR( "style:parent-style-name") ] = USTR( "standard" );
+ // generate standard graphic style if necessary
+ m_rStyleContainer.getStandardStyleId( "graphic" );
+
+ PropertyMap aGCProps;
+
+ // TODO(F3): proper dash emulation
+ if( elem.Action & PATH_STROKE )
+ {
+ aGCProps[ USTR("draw:stroke") ] = rGC.DashArray.empty() ? USTR("solid") : USTR("dash");
+ aGCProps[ USTR("svg:stroke-color") ] = getColorString( rGC.LineColor );
+ if( rGC.LineWidth != 0.0 )
+ {
+ ::basegfx::B2DVector aVec(rGC.LineWidth,0);
+ aVec *= rGC.Transformation;
+
+ aVec.setX ( convPx2mmPrec2( aVec.getX() )*100.0 );
+ aVec.setY ( convPx2mmPrec2( aVec.getY() )*100.0 );
+
+ aGCProps[ USTR("svg:stroke-width") ] = rtl::OUString::valueOf( aVec.getLength() );
+ }
+ }
+ else
+ {
+ aGCProps[ USTR("draw:stroke") ] = USTR("none");
+ }
+
+ // TODO(F1): check whether stuff could be emulated by gradient/bitmap/hatch
+ if( elem.Action & (PATH_FILL | PATH_EOFILL) )
+ {
+ aGCProps[ USTR("draw:fill") ] = USTR("solid");
+ aGCProps[ USTR("draw:fill-color") ] = getColorString( rGC.FillColor );
+ }
+ else
+ {
+ aGCProps[ USTR("draw:fill") ] = USTR("none");
+ }
+
+ StyleContainer::Style aStyle( "style:style", aProps );
+ StyleContainer::Style aSubStyle( "style:graphic-properties", aGCProps );
+ aStyle.SubStyles.push_back( &aSubStyle );
+
+ elem.StyleId = m_rStyleContainer.getStyleId( aStyle );
+}
+
+void DrawXmlFinalizer::visit( HyperlinkElement&, const std::list< Element* >::const_iterator& )
+{
+}
+
+void DrawXmlFinalizer::visit( TextElement& elem, const std::list< Element* >::const_iterator& )
+{
+ const FontAttributes& rFont = m_rProcessor.getFont( elem.FontId );
+ PropertyMap aProps;
+ aProps[ USTR( "style:family" ) ] = USTR( "text" );
+
+ PropertyMap aFontProps;
+
+ // family name
+ aFontProps[ USTR( "fo:font-family" ) ] = rFont.familyName;
+ aFontProps[ USTR( "style:font-family-complex" ) ] = rFont.familyName;
+
+ // bold
+ if( rFont.isBold )
+ {
+ aFontProps[ USTR( "fo:font-weight" ) ] = USTR( "bold" );
+ aFontProps[ USTR( "fo:font-weight-asian" ) ] = USTR( "bold" );
+ aFontProps[ USTR( "style:font-weight-complex" ) ] = USTR( "bold" );
+ }
+ // italic
+ if( rFont.isItalic )
+ {
+ aFontProps[ USTR( "fo:font-style" ) ] = USTR( "italic" );
+ aFontProps[ USTR( "fo:font-style-asian" ) ] = USTR( "italic" );
+ aFontProps[ USTR( "style:font-style-complex" ) ] = USTR( "italic" );
+ }
+ // underline
+ if( rFont.isUnderline )
+ {
+ aFontProps[ USTR( "style:text-underline-style" ) ] = USTR( "solid" );
+ aFontProps[ USTR( "style:text-underline-width" ) ] = USTR( "auto" );
+ aFontProps[ USTR( "style:text-underline-color" ) ] = USTR( "font-color" );
+ }
+ // outline
+ if( rFont.isOutline )
+ {
+ aFontProps[ USTR( "style:text-outline" ) ] = USTR( "true" );
+ }
+ // size
+ rtl::OUStringBuffer aBuf( 32 );
+ aBuf.append( rFont.size*72/PDFI_OUTDEV_RESOLUTION );
+ aBuf.appendAscii( "pt" );
+ rtl::OUString aFSize = aBuf.makeStringAndClear();
+ aFontProps[ USTR( "fo:font-size" ) ] = aFSize;
+ aFontProps[ USTR( "style:font-size-asian" ) ] = aFSize;
+ aFontProps[ USTR( "style:font-size-complex" ) ] = aFSize;
+ // color
+ const GraphicsContext& rGC = m_rProcessor.getGraphicsContext( elem.GCId );
+ aFontProps[ USTR( "fo:color" ) ] = getColorString( rFont.isOutline ? rGC.LineColor : rGC.FillColor );
+
+ StyleContainer::Style aStyle( "style:style", aProps );
+ StyleContainer::Style aSubStyle( "style:text-properties", aFontProps );
+ aStyle.SubStyles.push_back( &aSubStyle );
+ elem.StyleId = m_rStyleContainer.getStyleId( aStyle );
+}
+
+void DrawXmlFinalizer::visit( ParagraphElement& elem, const std::list< Element* >::const_iterator& )
+{
+
+ PropertyMap aProps;
+ aProps[ USTR( "style:family" ) ] = USTR( "paragraph" );
+ // generate standard paragraph style if necessary
+ m_rStyleContainer.getStandardStyleId( "paragraph" );
+
+ PropertyMap aParProps;
+
+ aParProps[ USTR("fo:text-align")] = USTR("start");
+ if (elem.bRtl)
+ aParProps[ USTR("style:writing-mode")] = USTR("rl-tb");
+ else
+ aParProps[ USTR("style:writing-mode")] = USTR("lr-tb");
+
+ StyleContainer::Style aStyle( "style:style", aProps );
+ StyleContainer::Style aSubStyle( "style:paragraph-properties", aParProps );
+ aStyle.SubStyles.push_back( &aSubStyle );
+
+ elem.StyleId = m_rStyleContainer.getStyleId( aStyle );
+
+ elem.applyToChildren(*this);
+}
+
+void DrawXmlFinalizer::visit( FrameElement& elem, const std::list< Element* >::const_iterator&)
+{
+ PropertyMap aProps;
+ aProps[ USTR( "style:family" ) ] = USTR( "graphic" );
+ aProps[ USTR( "style:parent-style-name") ] = USTR( "standard" );
+ // generate standard graphic style if necessary
+ m_rStyleContainer.getStandardStyleId( "graphic" );
+
+ PropertyMap aGCProps;
+
+ aGCProps[ USTR("draw:stroke") ] = USTR("none");
+ aGCProps[ USTR("draw:fill") ] = USTR("none");
+ aGCProps[ USTR("draw:auto-grow-height") ] = USTR("true");
+ aGCProps[ USTR("draw:auto-grow-width") ] = USTR("true");
+ aGCProps[ USTR("draw:textarea-horizontal-align") ] = USTR("left");
+ aGCProps[ USTR("draw:textarea-vertical-align") ] = USTR("top");
+ aGCProps[ USTR("fo:min-height")] = USTR("0cm");
+ aGCProps[ USTR("fo:min-width")] = USTR("0cm");
+ aGCProps[ USTR("fo:padding-top") ] = USTR("0cm");
+ aGCProps[ USTR("fo:padding-left") ] = USTR("0cm");
+ aGCProps[ USTR("fo:padding-right") ] = USTR("0cm");
+ aGCProps[ USTR("fo:padding-bottom") ] = USTR("0cm");
+
+ // remark: vertical mirroring is done in current OOO by
+ // mirroring horzontally and rotating 180 degrees
+ // this is quaint, but unfortunately it seems
+ // mirror=vertical is defined but not implemented in current code
+ if( elem.MirrorVertical )
+ aGCProps[ USTR("style:mirror") ] = USTR("horizontal");
+
+ StyleContainer::Style aStyle( "style:style", aProps );
+ StyleContainer::Style aSubStyle( "style:graphic-properties", aGCProps );
+ aStyle.SubStyles.push_back( &aSubStyle );
+
+ elem.StyleId = m_rStyleContainer.getStyleId( aStyle );
+ elem.applyToChildren(*this);
+}
+
+void DrawXmlFinalizer::visit( ImageElement&, const std::list< Element* >::const_iterator& )
+{
+}
+
+void DrawXmlFinalizer::visit( PageElement& elem, const std::list< Element* >::const_iterator& )
+{
+ if( m_rProcessor.getStatusIndicator().is() )
+ m_rProcessor.getStatusIndicator()->setValue( elem.PageNumber );
+
+ // transform from pixel to mm
+ double page_width = convPx2mm( elem.w ), page_height = convPx2mm( elem.h );
+
+ // calculate page margins out of the relevant children (paragraphs)
+ elem.TopMargin = elem.h, elem.BottomMargin = 0, elem.LeftMargin = elem.w, elem.RightMargin = 0;
+
+ for( std::list< Element* >::const_iterator it = elem.Children.begin(); it != elem.Children.end(); ++it )
+ {
+ if( (*it)->x < elem.LeftMargin )
+ elem.LeftMargin = (*it)->x;
+ if( (*it)->y < elem.TopMargin )
+ elem.TopMargin = (*it)->y;
+ if( (*it)->x + (*it)->w > elem.RightMargin )
+ elem.RightMargin = ((*it)->x + (*it)->w);
+ if( (*it)->y + (*it)->h > elem.BottomMargin )
+ elem.BottomMargin = ((*it)->y + (*it)->h);
+ }
+
+ // transform margins to mm
+ double left_margin = convPx2mm( elem.LeftMargin );
+ double right_margin = convPx2mm( elem.RightMargin );
+ double top_margin = convPx2mm( elem.TopMargin );
+ double bottom_margin = convPx2mm( elem.BottomMargin );
+
+ // round left/top margin to nearest mm
+ left_margin = rtl_math_round( left_margin, 0, rtl_math_RoundingMode_Floor );
+ top_margin = rtl_math_round( top_margin, 0, rtl_math_RoundingMode_Floor );
+ // round (fuzzy) right/bottom margin to nearest cm
+ right_margin = rtl_math_round( right_margin, right_margin >= 10 ? -1 : 0, rtl_math_RoundingMode_Floor );
+ bottom_margin = rtl_math_round( bottom_margin, bottom_margin >= 10 ? -1 : 0, rtl_math_RoundingMode_Floor );
+
+ // set reasonable default in case of way too large margins
+ // e.g. no paragraph case
+ if( left_margin > page_width/2.0 - 10 )
+ left_margin = 10;
+ if( right_margin > page_width/2.0 - 10 )
+ right_margin = 10;
+ if( top_margin > page_height/2.0 - 10 )
+ top_margin = 10;
+ if( bottom_margin > page_height/2.0 - 10 )
+ bottom_margin = 10;
+
+ // catch the weird cases
+ if( left_margin < 0 )
+ left_margin = 0;
+ if( right_margin < 0 )
+ right_margin = 0;
+ if( top_margin < 0 )
+ top_margin = 0;
+ if( bottom_margin < 0 )
+ bottom_margin = 0;
+
+ // widely differing margins are unlikely to be correct
+ if( right_margin > left_margin*1.5 )
+ right_margin = left_margin;
+
+ elem.LeftMargin = convmm2Px( left_margin );
+ elem.RightMargin = convmm2Px( right_margin );
+ elem.TopMargin = convmm2Px( top_margin );
+ elem.BottomMargin = convmm2Px( bottom_margin );
+
+ // get styles for paragraphs
+ PropertyMap aPageProps;
+ PropertyMap aPageLayoutProps;
+ rtl::OUStringBuffer aBuf( 64 );
+ aPageLayoutProps[ USTR( "fo:margin-top" ) ] = unitMMString( top_margin );
+ aPageLayoutProps[ USTR( "fo:margin-bottom" ) ] = unitMMString( bottom_margin );
+ aPageLayoutProps[ USTR( "fo:margin-left" ) ] = unitMMString( left_margin );
+ aPageLayoutProps[ USTR( "fo:margin-right" ) ] = unitMMString( right_margin );
+ aPageLayoutProps[ USTR( "fo:page-width" ) ] = unitMMString( page_width );
+ aPageLayoutProps[ USTR( "fo:page-height" ) ] = unitMMString( page_height );
+ aPageLayoutProps[ USTR( "style:print-orientation" ) ]= elem.w < elem.h ? USTR( "portrait" ) : USTR( "landscape" );
+ aPageLayoutProps[ USTR( "style:writing-mode" ) ]= USTR( "lr-tb" );
+
+ StyleContainer::Style aStyle( "style:page-layout", aPageProps);
+ StyleContainer::Style aSubStyle( "style:page-layout-properties", aPageLayoutProps);
+ aStyle.SubStyles.push_back(&aSubStyle);
+ sal_Int32 nPageStyle = m_rStyleContainer.impl_getStyleId( aStyle, false );
+
+ // create master page
+ rtl::OUString aMasterPageLayoutName = m_rStyleContainer.getStyleName( nPageStyle );
+ aPageProps[ USTR( "style:page-layout-name" ) ] = aMasterPageLayoutName;
+
+ StyleContainer::Style aMPStyle( "style:master-page", aPageProps);
+
+ StyleContainer::Style aHeaderStyle( "style:header", PropertyMap() );
+ StyleContainer::Style aFooterStyle( "style:footer", PropertyMap() );
+
+ elem.StyleId = m_rStyleContainer.impl_getStyleId( aMPStyle,false );
+
+
+ rtl::OUString aMasterPageName = m_rStyleContainer.getStyleName( elem.StyleId );
+
+ // create styles for children
+ elem.applyToChildren(*this);
+}
+
+void DrawXmlFinalizer::visit( DocumentElement& elem, const std::list< Element* >::const_iterator& )
+{
+ elem.applyToChildren(*this);
+}
+
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sdext/source/pdfimport/tree/drawtreevisiting.hxx b/sdext/source/pdfimport/tree/drawtreevisiting.hxx
new file mode 100644
index 000000000000..e957448ded4e
--- /dev/null
+++ b/sdext/source/pdfimport/tree/drawtreevisiting.hxx
@@ -0,0 +1,132 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+#ifndef INCLUDED_PDFI_DRAWTREEVISITING_HXX
+#define INCLUDED_PDFI_DRAWTREEVISITING_HXX
+
+#include "treevisiting.hxx"
+
+#include "com/sun/star/i18n/XBreakIterator.hpp"
+#include "com/sun/star/i18n/XCharacterClassification.hpp"
+#include "com/sun/star/lang/XMultiServiceFactory.hpp"
+#include "com/sun/star/uno/XComponentContext.hpp"
+
+namespace pdfi
+{
+ struct DrawElement;
+
+ class DrawXmlOptimizer : public ElementTreeVisitor
+ {
+ private:
+ PDFIProcessor& m_rProcessor;
+ void optimizeTextElements(Element& rParent);
+
+ public:
+ ::com::sun::star::uno::Reference< ::com::sun::star::i18n::XBreakIterator > mxBreakIter;
+ const ::com::sun::star::uno::Reference< ::com::sun::star::i18n::XBreakIterator >& GetBreakIterator();
+ explicit DrawXmlOptimizer(PDFIProcessor& rProcessor) :
+ m_rProcessor(rProcessor)
+ {}
+
+ virtual void visit( HyperlinkElement&, const std::list< Element* >::const_iterator& );
+ virtual void visit( TextElement&, const std::list< Element* >::const_iterator& );
+ virtual void visit( ParagraphElement&, const std::list< Element* >::const_iterator& );
+ virtual void visit( FrameElement&, const std::list< Element* >::const_iterator& );
+ virtual void visit( PolyPolyElement&, const std::list< Element* >::const_iterator& );
+ virtual void visit( ImageElement&, const std::list< Element* >::const_iterator& );
+ virtual void visit( PageElement&, const std::list< Element* >::const_iterator& );
+ virtual void visit( DocumentElement&, const std::list< Element* >::const_iterator& );
+ };
+
+ class DrawXmlFinalizer : public ElementTreeVisitor
+ {
+ private:
+ StyleContainer& m_rStyleContainer;
+ PDFIProcessor& m_rProcessor;
+
+ public:
+ explicit DrawXmlFinalizer(StyleContainer& rStyleContainer,
+ PDFIProcessor& rProcessor) :
+ m_rStyleContainer(rStyleContainer),
+ m_rProcessor(rProcessor)
+ {}
+
+ virtual void visit( HyperlinkElement&, const std::list< Element* >::const_iterator& );
+ virtual void visit( TextElement&, const std::list< Element* >::const_iterator& );
+ virtual void visit( ParagraphElement&, const std::list< Element* >::const_iterator& );
+ virtual void visit( FrameElement&, const std::list< Element* >::const_iterator& );
+ virtual void visit( PolyPolyElement&, const std::list< Element* >::const_iterator& );
+ virtual void visit( ImageElement&, const std::list< Element* >::const_iterator& );
+ virtual void visit( PageElement&, const std::list< Element* >::const_iterator& );
+ virtual void visit( DocumentElement&, const std::list< Element* >::const_iterator& );
+ };
+
+ class DrawXmlEmitter : public ElementTreeVisitor
+ {
+ private:
+ ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > xFactory;
+ ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > xCtx;
+ ::com::sun::star::uno::Reference< ::com::sun::star::i18n::XBreakIterator > mxBreakIter;
+ ::com::sun::star::uno::Reference< ::com::sun::star::i18n::XCharacterClassification > mxCharClass;
+
+ PDFIProcessor& m_rProcessor;
+
+ EmitContext& m_rEmitContext ;
+ /// writes Impress doc when false
+ const bool m_bWriteDrawDocument;
+
+ void fillFrameProps( DrawElement& rElem,
+ PropertyMap& rProps,
+ const EmitContext& rEmitContext,
+ bool bWasTransformed = false
+ );
+
+ public:
+ const ::com::sun::star::uno::Reference< ::com::sun::star::i18n::XBreakIterator >& GetBreakIterator();
+ const ::com::sun::star::uno::Reference< ::com::sun::star::i18n::XCharacterClassification >& GetCharacterClassification();
+ enum DocType{ DRAW_DOC, IMPRESS_DOC };
+ explicit DrawXmlEmitter(EmitContext& rEmitContext, DocType eDocType, PDFIProcessor& rProc ) :
+ m_rProcessor( rProc ),
+ m_rEmitContext(rEmitContext),
+ m_bWriteDrawDocument(eDocType==DRAW_DOC)
+ {}
+
+ virtual void visit( HyperlinkElement&, const std::list< Element* >::const_iterator& );
+ virtual void visit( TextElement&, const std::list< Element* >::const_iterator& );
+ virtual void visit( ParagraphElement&, const std::list< Element* >::const_iterator& );
+ virtual void visit( FrameElement&, const std::list< Element* >::const_iterator& );
+ virtual void visit( PolyPolyElement&, const std::list< Element* >::const_iterator& );
+ virtual void visit( ImageElement&, const std::list< Element* >::const_iterator& );
+ virtual void visit( PageElement&, const std::list< Element* >::const_iterator& );
+ virtual void visit( DocumentElement&, const std::list< Element* >::const_iterator& );
+ };
+}
+
+#endif
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sdext/source/pdfimport/tree/genericelements.cxx b/sdext/source/pdfimport/tree/genericelements.cxx
new file mode 100644
index 000000000000..e6a50a0331db
--- /dev/null
+++ b/sdext/source/pdfimport/tree/genericelements.cxx
@@ -0,0 +1,496 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_sdext.hxx"
+
+#include "xmlemitter.hxx"
+#include "genericelements.hxx"
+#include "pdfiprocessor.hxx"
+#include "pdfihelper.hxx"
+#include "style.hxx"
+
+
+#include <basegfx/polygon/b2dpolypolygontools.hxx>
+#include <basegfx/range/b2drange.hxx>
+
+namespace pdfi
+{
+
+ElementFactory::~ElementFactory()
+{
+}
+
+Element::~Element()
+{
+ while( !Children.empty() )
+ {
+ Element* pCurr( Children.front() );
+ delete pCurr;
+ Children.pop_front();
+ }
+}
+
+void Element::applyToChildren( ElementTreeVisitor& rVisitor )
+{
+ for( std::list< Element* >::iterator it = Children.begin(); it != Children.end(); ++it )
+ (*it)->visitedBy( rVisitor, it );
+}
+
+void Element::setParent( std::list<Element*>::iterator& el, Element* pNewParent )
+{
+ if( pNewParent )
+ {
+ pNewParent->Children.splice( pNewParent->Children.end(), (*el)->Parent->Children, el );
+ (*el)->Parent = pNewParent;
+ }
+}
+
+void Element::updateGeometryWith( const Element* pMergeFrom )
+{
+ if( w == 0 && h == 0 )
+ {
+ x = pMergeFrom->x;
+ y = pMergeFrom->y;
+ w = pMergeFrom->w;
+ h = pMergeFrom->h;
+ }
+ else
+ {
+ if( pMergeFrom->x < x )
+ {
+ w += x - pMergeFrom->x;
+ x = pMergeFrom->x;
+ }
+ if( pMergeFrom->x+pMergeFrom->w > x+w )
+ w = pMergeFrom->w+pMergeFrom->x - x;
+ if( pMergeFrom->y < y )
+ {
+ h += y - pMergeFrom->y;
+ y = pMergeFrom->y;
+ }
+ if( pMergeFrom->y+pMergeFrom->h > y+h )
+ h = pMergeFrom->h+pMergeFrom->y - y;
+ }
+}
+
+
+#if OSL_DEBUG_LEVEL > 1
+#include <typeinfo>
+void Element::emitStructure( int nLevel)
+{
+ OSL_TRACE( "%*s<%s %p> (%.1f,%.1f)+(%.1fx%.1f)\n",
+ nLevel, "", typeid( *this ).name(), this,
+ x, y, w, h );
+ for( std::list< Element* >::iterator it = Children.begin(); it != Children.end(); ++it )
+ (*it)->emitStructure(nLevel+1 );
+ OSL_TRACE( "%*s</%s>\n", nLevel, "", typeid( *this ).name() );
+}
+#endif
+
+void ListElement::visitedBy( ElementTreeVisitor& visitor, const std::list< Element* >::const_iterator& )
+{
+ // this is only an inner node
+ applyToChildren(visitor);
+}
+
+void HyperlinkElement::visitedBy( ElementTreeVisitor& rVisitor,
+ const std::list< Element* >::const_iterator& rParentIt )
+{
+ rVisitor.visit(*this,rParentIt);
+}
+
+void TextElement::visitedBy( ElementTreeVisitor& rVisitor,
+ const std::list< Element* >::const_iterator& rParentIt )
+{
+ rVisitor.visit(*this,rParentIt);
+}
+
+void FrameElement::visitedBy( ElementTreeVisitor& rVisitor,
+ const std::list< Element* >::const_iterator& rParentIt )
+{
+ rVisitor.visit(*this,rParentIt);
+}
+
+void ImageElement::visitedBy( ElementTreeVisitor& rVisitor,
+ const std::list< Element* >::const_iterator& rParentIt)
+{
+ rVisitor.visit( *this, rParentIt);
+}
+
+PolyPolyElement::PolyPolyElement( Element* pParent,
+ sal_Int32 nGCId,
+ const basegfx::B2DPolyPolygon& rPolyPoly,
+ sal_Int8 nAction )
+ : DrawElement( pParent, nGCId ),
+ PolyPoly( rPolyPoly ),
+ Action( nAction )
+{
+}
+
+void PolyPolyElement::updateGeometry()
+{
+ basegfx::B2DRange aRange;
+ if( PolyPoly.areControlPointsUsed() )
+ aRange = basegfx::tools::getRange( basegfx::tools::adaptiveSubdivideByAngle( PolyPoly ) );
+ else
+ aRange = basegfx::tools::getRange( PolyPoly );
+ x = aRange.getMinX();
+ y = aRange.getMinY();
+ w = aRange.getWidth();
+ h = aRange.getHeight();
+
+ // fdo#32330 - non-closed paths will not show up filled in LibO
+ if( Action & (PATH_FILL | PATH_EOFILL) )
+ PolyPoly.setClosed(true);
+}
+
+void PolyPolyElement::visitedBy( ElementTreeVisitor& rVisitor,
+ const std::list< Element* >::const_iterator& rParentIt)
+{
+ rVisitor.visit( *this, rParentIt);
+}
+
+#if OSL_DEBUG_LEVEL > 1
+void PolyPolyElement::emitStructure( int nLevel)
+{
+ OSL_TRACE( "%*s<%s %p>\n", nLevel, "", typeid( *this ).name(), this );
+ OSL_TRACE( "path=" );
+ int nPoly = PolyPoly.count();
+ for( int i = 0; i < nPoly; i++ )
+ {
+ basegfx::B2DPolygon aPoly = PolyPoly.getB2DPolygon( i );
+ int nPoints = aPoly.count();
+ for( int n = 0; n < nPoints; n++ )
+ {
+ basegfx::B2DPoint aPoint = aPoly.getB2DPoint( n );
+ OSL_TRACE( " (%g,%g)", aPoint.getX(), aPoint.getY() );
+ }
+ OSL_TRACE( "\n" );
+ }
+ for( std::list< Element* >::iterator it = Children.begin(); it != Children.end(); ++it )
+ (*it)->emitStructure( nLevel+1 );
+ OSL_TRACE( "%*s</%s>\n", nLevel, "", typeid( *this ).name() );
+}
+#endif
+
+void ParagraphElement::visitedBy( ElementTreeVisitor& rVisitor,
+ const std::list< Element* >::const_iterator& rParentIt )
+{
+ rVisitor.visit(*this,rParentIt);
+}
+
+bool ParagraphElement::isSingleLined( PDFIProcessor& rProc ) const
+{
+ std::list< Element* >::const_iterator it = Children.begin();
+ TextElement* pText = NULL, *pLastText = NULL;
+ while( it != Children.end() )
+ {
+ // a paragraph containing subparagraphs cannot be single lined
+ if( dynamic_cast< ParagraphElement* >(*it) != NULL )
+ return false;
+
+ pText = dynamic_cast< TextElement* >(*it);
+ if( pText )
+ {
+ const FontAttributes& rFont = rProc.getFont( pText->FontId );
+ if( pText->h > rFont.size*1.5 )
+ return false;
+ if( pLastText )
+ {
+ if( pText->y > pLastText->y+pLastText->h ||
+ pLastText->y > pText->y+pText->h )
+ return false;
+ }
+ else
+ pLastText = pText;
+ }
+ ++it;
+ }
+
+ // a paragraph without a single text is not considered single lined
+ return pLastText != NULL;
+}
+
+double ParagraphElement::getLineHeight( PDFIProcessor& rProc ) const
+{
+ double line_h = 0;
+ for( std::list< Element* >::const_iterator it = Children.begin(); it != Children.end(); ++it )
+ {
+ ParagraphElement* pPara = dynamic_cast< ParagraphElement* >(*it);
+ TextElement* pText = NULL;
+ if( pPara )
+ {
+ double lh = pPara->getLineHeight( rProc );
+ if( lh > line_h )
+ line_h = lh;
+ }
+ else if( (pText = dynamic_cast< TextElement* >( *it )) != NULL )
+ {
+ const FontAttributes& rFont = rProc.getFont( pText->FontId );
+ double lh = pText->h;
+ if( pText->h > rFont.size*1.5 )
+ lh = rFont.size;
+ if( lh > line_h )
+ line_h = lh;
+ }
+ }
+ return line_h;
+}
+
+TextElement* ParagraphElement::getFirstTextChild() const
+{
+ TextElement* pText = NULL;
+ for( std::list< Element* >::const_iterator it = Children.begin();
+ it != Children.end() && ! pText; ++it )
+ {
+ pText = dynamic_cast<TextElement*>(*it);
+ }
+ return pText;
+}
+
+PageElement::~PageElement()
+{
+ if( HeaderElement )
+ delete HeaderElement;
+ if( FooterElement )
+ delete FooterElement;
+}
+
+void PageElement::visitedBy( ElementTreeVisitor& rVisitor,
+ const std::list< Element* >::const_iterator& rParentIt )
+{
+ rVisitor.visit(*this, rParentIt);
+}
+
+void PageElement::updateParagraphGeometry( Element* pEle )
+{
+ // update geometry of children
+ for( std::list< Element* >::iterator it = pEle->Children.begin();
+ it != pEle->Children.end(); ++it )
+ {
+ updateParagraphGeometry( *it );
+ }
+ // if this is a paragraph itself, then update according to children geometry
+ if( dynamic_cast<ParagraphElement*>(pEle) )
+ {
+ for( std::list< Element* >::iterator it = pEle->Children.begin();
+ it != pEle->Children.end(); ++it )
+ {
+ Element* pChild = NULL;
+ TextElement* pText = dynamic_cast<TextElement*>(*it);
+ if( pText )
+ pChild = pText;
+ else
+ {
+ ParagraphElement* pPara = dynamic_cast<ParagraphElement*>(*it);
+ if( pPara )
+ pChild = pPara;
+ }
+ if( pChild )
+ pEle->updateGeometryWith( pChild );
+ }
+ }
+}
+
+bool PageElement::resolveHyperlink( std::list<Element*>::iterator link_it, std::list<Element*>& rElements )
+{
+ HyperlinkElement* pLink = dynamic_cast<HyperlinkElement*>(*link_it);
+ if( ! pLink ) // sanity check
+ return false;
+
+ for( std::list<Element*>::iterator it = rElements.begin(); it != rElements.end(); ++it )
+ {
+ if( (*it)->x >= pLink->x && (*it)->x + (*it)->w <= pLink->x + pLink->w &&
+ (*it)->y >= pLink->y && (*it)->y + (*it)->h <= pLink->y + pLink->h )
+ {
+ TextElement* pText = dynamic_cast<TextElement*>(*it);
+ if( pText )
+ {
+ if( pLink->Children.empty() )
+ {
+ // insert the hyperlink before the frame
+ rElements.splice( it, Hyperlinks.Children, link_it );
+ pLink->Parent = (*it)->Parent;
+ }
+ // move text element into hyperlink
+ std::list<Element*>::iterator next = it;
+ ++next;
+ Element::setParent( it, pLink );
+ it = next;
+ --it;
+ continue;
+ }
+ // a link can contain multiple text elements or a single frame
+ if( ! pLink->Children.empty() )
+ continue;
+ if( dynamic_cast<ParagraphElement*>(*it) )
+ {
+ if( resolveHyperlink( link_it, (*it)->Children ) )
+ break;
+ continue;
+ }
+ FrameElement* pFrame = dynamic_cast<FrameElement*>(*it);
+ if( pFrame )
+ {
+ // insert the hyperlink before the frame
+ rElements.splice( it, Hyperlinks.Children, link_it );
+ pLink->Parent = (*it)->Parent;
+ // move frame into hyperlink
+ Element::setParent( it, pLink );
+ break;
+ }
+ }
+ }
+ return ! pLink->Children.empty();
+}
+
+void PageElement::resolveHyperlinks()
+{
+ while( ! Hyperlinks.Children.empty() )
+ {
+ if( ! resolveHyperlink( Hyperlinks.Children.begin(), Children ) )
+ {
+ delete Hyperlinks.Children.front();
+ Hyperlinks.Children.pop_front();
+ }
+ }
+}
+
+void PageElement::resolveFontStyles( PDFIProcessor& rProc )
+{
+ resolveUnderlines(rProc);
+}
+
+void PageElement::resolveUnderlines( PDFIProcessor& rProc )
+{
+ // FIXME: currently the algorithm used is quadratic
+ // this could be solved by some sorting beforehand
+
+ std::list< Element* >::iterator poly_it = Children.begin();
+ while( poly_it != Children.end() )
+ {
+ PolyPolyElement* pPoly = dynamic_cast< PolyPolyElement* >(*poly_it);
+ if( ! pPoly || ! pPoly->Children.empty() )
+ {
+ ++poly_it;
+ continue;
+ }
+ /* check for: no filling
+ * only two points (FIXME: handle small rectangles, too)
+ * y coordinates of points are equal
+ */
+ if( pPoly->Action != PATH_STROKE )
+ {
+ ++poly_it;
+ continue;
+ }
+ if( pPoly->PolyPoly.count() != 1 )
+ {
+ ++poly_it;
+ continue;
+ }
+
+ bool bRemovePoly = false;
+ basegfx::B2DPolygon aPoly = pPoly->PolyPoly.getB2DPolygon(0);
+ if( aPoly.count() != 2 ||
+ aPoly.getB2DPoint(0).getY() != aPoly.getB2DPoint(1).getY() )
+ {
+ ++poly_it;
+ continue;
+ }
+ double l_x = aPoly.getB2DPoint(0).getX();
+ double r_x = aPoly.getB2DPoint(1).getX();
+ double u_y;
+ if( r_x < l_x )
+ {
+ u_y = r_x; r_x = l_x; l_x = u_y;
+ }
+ u_y = aPoly.getB2DPoint(0).getY();
+ for( std::list< Element*>::iterator it = Children.begin();
+ it != Children.end(); ++it )
+ {
+ Element* pEle = *it;
+ if( pEle->y <= u_y && pEle->y + pEle->h*1.1 >= u_y )
+ {
+ // first: is the element underlined completely ?
+ if( pEle->x + pEle->w*0.1 >= l_x &&
+ pEle->x + pEle->w*0.9 <= r_x )
+ {
+ TextElement* pText = dynamic_cast< TextElement* >(pEle);
+ if( pText )
+ {
+ const GraphicsContext& rTextGC = rProc.getGraphicsContext( pText->GCId );
+ if( ! rTextGC.isRotatedOrSkewed() )
+ {
+ bRemovePoly = true;
+ // retrieve ID for modified font
+ FontAttributes aAttr = rProc.getFont( pText->FontId );
+ aAttr.isUnderline = true;
+ pText->FontId = rProc.getFontId( aAttr );
+ }
+ }
+ else if( dynamic_cast< HyperlinkElement* >(pEle) )
+ bRemovePoly = true;
+ }
+ // second: hyperlinks may be larger than their underline
+ // since they are just arbitrary rectangles in the action definition
+ else if( dynamic_cast< HyperlinkElement* >(pEle) != NULL &&
+ l_x >= pEle->x && r_x <= pEle->x+pEle->w )
+ {
+ bRemovePoly = true;
+ }
+ }
+ }
+ if( bRemovePoly )
+ {
+ std::list< Element* >::iterator next_it = poly_it;
+ ++next_it;
+ Children.erase( poly_it );
+ delete pPoly;
+ poly_it = next_it;
+ }
+ else
+ ++poly_it;
+ }
+}
+
+DocumentElement::~DocumentElement()
+{
+}
+
+void DocumentElement::visitedBy( ElementTreeVisitor& rVisitor,
+ const std::list< Element* >::const_iterator& rParentIt)
+{
+ rVisitor.visit(*this, rParentIt);
+}
+
+
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sdext/source/pdfimport/tree/genericelements.hxx b/sdext/source/pdfimport/tree/genericelements.hxx
new file mode 100644
index 000000000000..b2122a6c7cc2
--- /dev/null
+++ b/sdext/source/pdfimport/tree/genericelements.hxx
@@ -0,0 +1,326 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+#ifndef INCLUDED_PDFI_GENERICELEMENTS_HXX
+#define INCLUDED_PDFI_GENERICELEMENTS_HXX
+
+#include "pdfihelper.hxx"
+#include "treevisiting.hxx"
+
+#include <com/sun/star/task/XStatusIndicator.hpp>
+#include <com/sun/star/uno/XComponentContext.hpp>
+#include <basegfx/polygon/b2dpolypolygon.hxx>
+#include <basegfx/range/b2drange.hxx>
+#include <rtl/ustring.hxx>
+#include <rtl/ustrbuf.hxx>
+
+#include <list>
+
+namespace pdfi
+{
+ class XmlEmitter;
+ class StyleContainer;
+ class ImageContainer;
+ class PDFIProcessor;
+ class ElementFactory;
+
+
+ struct EmitContext
+ {
+ EmitContext(
+ XmlEmitter& _rEmitter,
+ StyleContainer& _rStyles,
+ ImageContainer& _rImages,
+ PDFIProcessor& _rProcessor,
+ const com::sun::star::uno::Reference<
+ com::sun::star::task::XStatusIndicator>& _xStatusIndicator,
+ com::sun::star::uno::Reference< com::sun::star::uno::XComponentContext > xContext)
+ :
+ rEmitter(_rEmitter),
+ rStyles(_rStyles),
+ rImages(_rImages),
+ rProcessor(_rProcessor),
+ xStatusIndicator(_xStatusIndicator),
+ m_xContext(xContext)
+ {}
+
+ XmlEmitter& rEmitter;
+ StyleContainer& rStyles;
+ ImageContainer& rImages;
+ PDFIProcessor& rProcessor;
+ com::sun::star::uno::Reference<
+ com::sun::star::task::XStatusIndicator> xStatusIndicator;
+ com::sun::star::uno::Reference<
+ com::sun::star::uno::XComponentContext > m_xContext;
+ };
+
+ struct Element : public ElementTreeVisitable
+ {
+ protected:
+ Element( Element* pParent )
+ : x( 0 ), y( 0 ), w( 0 ), h( 0 ), StyleId( -1 ), Parent( pParent )
+ {
+ if( pParent )
+ pParent->Children.push_back( this );
+ }
+
+ public:
+ virtual ~Element();
+
+ /// Apply visitor to all children
+ void applyToChildren( ElementTreeVisitor& );
+ /// Union element geometry with given element
+ void updateGeometryWith( const Element* pMergeFrom );
+
+#if OSL_DEBUG_LEVEL > 1
+ // xxx refac TODO: move code to visitor
+ virtual void emitStructure( int nLevel );
+#endif
+ /** el must be a valid dereferencable iterator of el->Parent->Children
+ pNewParent must not be NULL
+ */
+ static void setParent( std::list<Element*>::iterator& el, Element* pNewParent );
+
+ double x, y, w, h;
+ sal_Int32 StyleId;
+ Element* Parent;
+ std::list<Element*> Children;
+ };
+
+ struct ListElement : public Element
+ {
+ ListElement() : Element( NULL ) {}
+ // ElementTreeVisitable
+ virtual void visitedBy( ElementTreeVisitor&, const std::list< Element* >::const_iterator& );
+ };
+
+ struct HyperlinkElement : public Element
+ {
+ friend class ElementFactory;
+ protected:
+ HyperlinkElement( Element* pParent, const rtl::OUString& rURI )
+ : Element( pParent ), URI( rURI ) {}
+ public:
+ // ElementTreeVisitable
+ virtual void visitedBy( ElementTreeVisitor&, const std::list< Element* >::const_iterator& );
+
+ rtl::OUString URI;
+ };
+
+ struct GraphicalElement : public Element
+ {
+ protected:
+ GraphicalElement( Element* pParent, sal_Int32 nGCId )
+ : Element( pParent ), GCId( nGCId ), MirrorVertical( false ) {}
+
+ public:
+ sal_Int32 GCId;
+ bool MirrorVertical;
+ };
+
+ struct DrawElement : public GraphicalElement
+ {
+ protected:
+ DrawElement( Element* pParent, sal_Int32 nGCId )
+ : GraphicalElement( pParent, nGCId ), isCharacter(false), ZOrder(0) {}
+
+ public:
+ bool isCharacter;
+ sal_Int32 ZOrder;
+ };
+
+ struct FrameElement : public DrawElement
+ {
+ friend class ElementFactory;
+ protected:
+ FrameElement( Element* pParent, sal_Int32 nGCId )
+ : DrawElement( pParent, nGCId ) {}
+
+ public:
+ // ElementTreeVisitable
+ virtual void visitedBy( ElementTreeVisitor&, const std::list< Element* >::const_iterator& );
+ };
+
+ struct TextElement : public GraphicalElement
+ {
+ friend class ElementFactory;
+ protected:
+ TextElement( Element* pParent, sal_Int32 nGCId, sal_Int32 nFontId )
+ : GraphicalElement( pParent, nGCId ), FontId( nFontId ) {}
+
+ public:
+ // ElementTreeVisitable
+ virtual void visitedBy( ElementTreeVisitor&, const std::list< Element* >::const_iterator& );
+
+ rtl::OUStringBuffer Text;
+ sal_Int32 FontId;
+ };
+
+ struct ParagraphElement : public Element
+ {
+ friend class ElementFactory;
+ protected:
+ ParagraphElement( Element* pParent ) : Element( pParent ), Type( Normal ), bRtl( false ) {}
+
+ public:
+ // ElementTreeVisitable
+ virtual void visitedBy( ElementTreeVisitor&, const std::list< Element* >::const_iterator& rParentIt );
+
+ // returns true only if only a single line is contained
+ bool isSingleLined( PDFIProcessor& rProc ) const;
+ // returns the highest line height of the contained textelements
+ // line height is font height if the text element is itself multilined
+ double getLineHeight( PDFIProcessor& rProc ) const;
+ // returns the first text element child; does not recurse through subparagraphs
+ TextElement* getFirstTextChild() const;
+
+ enum ParagraphType { Normal, Headline };
+ ParagraphType Type;
+ bool bRtl;
+ };
+
+ struct PolyPolyElement : public DrawElement
+ {
+ friend class ElementFactory;
+ protected:
+ PolyPolyElement( Element* pParent, sal_Int32 nGCId,
+ const basegfx::B2DPolyPolygon& rPolyPoly,
+ sal_Int8 nAction );
+ public:
+ // ElementTreeVisitable
+ virtual void visitedBy( ElementTreeVisitor&, const std::list< Element* >::const_iterator& rParentIt );
+
+ void updateGeometry();
+
+#if OSL_DEBUG_LEVEL > 1
+ virtual void emitStructure( int nLevel );
+#endif
+
+ basegfx::B2DPolyPolygon PolyPoly;
+ sal_Int8 Action;
+ };
+
+ struct ImageElement : public DrawElement
+ {
+ friend class ElementFactory;
+ protected:
+ ImageElement( Element* pParent, sal_Int32 nGCId, ImageId nImage )
+ : DrawElement( pParent, nGCId ), Image( nImage ) {}
+
+ public:
+ // ElementTreeVisitable
+ virtual void visitedBy( ElementTreeVisitor&, const std::list< Element* >::const_iterator& );
+
+ ImageId Image;
+ };
+
+ struct PageElement : public Element
+ {
+ friend class ElementFactory;
+ protected:
+ PageElement( Element* pParent, sal_Int32 nPageNr )
+ : Element( pParent ), PageNumber( nPageNr ), Hyperlinks(),
+ TopMargin( 0.0 ), BottomMargin( 0.0 ), LeftMargin( 0.0 ), RightMargin( 0.0 ),
+ HeaderElement( NULL ), FooterElement( NULL )
+ {}
+ private:
+ // helper method for resolveHyperlinks
+ bool resolveHyperlink( std::list<Element*>::iterator link_it, std::list<Element*>& rElements );
+ public:
+ virtual ~PageElement();
+
+ // ElementTreeVisitable
+ virtual void visitedBy( ElementTreeVisitor&, const std::list< Element* >::const_iterator& rParentIt );
+
+ void emitPageAnchoredElements( EmitContext& rEmitContext );
+ static void updateParagraphGeometry( Element* pEle );
+ void resolveHyperlinks();
+ void resolveFontStyles( PDFIProcessor& rProc );
+ void resolveUnderlines( PDFIProcessor& rProc );
+
+ sal_Int32 PageNumber;
+ ListElement Hyperlinks; // contains not yet realized links on this page
+ double TopMargin;
+ double BottomMargin;
+ double LeftMargin;
+ double RightMargin;
+ Element* HeaderElement;
+ Element* FooterElement;
+ };
+
+ struct DocumentElement : public Element
+ {
+ friend class ElementFactory;
+ protected:
+ DocumentElement() : Element( NULL ) {}
+ public:
+ virtual ~DocumentElement();
+
+ // ElementTreeVisitable
+ virtual void visitedBy( ElementTreeVisitor&, const std::list< Element* >::const_iterator& );
+
+ };
+
+ // this class is the differentiator of document types: it will create
+ // Element objects with an optimize() method suitable for the document type
+ class ElementFactory
+ {
+ public:
+ ElementFactory() {}
+ virtual ~ElementFactory();
+
+ virtual HyperlinkElement* createHyperlinkElement( Element* pParent, const rtl::OUString& rURI )
+ { return new HyperlinkElement( pParent, rURI ); }
+
+ virtual TextElement* createTextElement( Element* pParent, sal_Int32 nGCId, sal_Int32 nFontId )
+ { return new TextElement( pParent, nGCId, nFontId ); }
+ virtual ParagraphElement* createParagraphElement( Element* pParent )
+ { return new ParagraphElement( pParent ); }
+
+ virtual FrameElement* createFrameElement( Element* pParent, sal_Int32 nGCId )
+ { return new FrameElement( pParent, nGCId ); }
+ virtual PolyPolyElement*
+ createPolyPolyElement( Element* pParent,
+ sal_Int32 nGCId,
+ const basegfx::B2DPolyPolygon& rPolyPoly,
+ sal_Int8 nAction)
+ { return new PolyPolyElement( pParent, nGCId, rPolyPoly, nAction ); }
+ virtual ImageElement* createImageElement( Element* pParent, sal_Int32 nGCId, ImageId nImage )
+ { return new ImageElement( pParent, nGCId, nImage ); }
+
+ virtual PageElement* createPageElement( Element* pParent,
+ sal_Int32 nPageNr )
+ { return new PageElement( pParent, nPageNr ); }
+ virtual DocumentElement* createDocumentElement()
+ { return new DocumentElement(); }
+ };
+}
+
+#endif
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sdext/source/pdfimport/tree/imagecontainer.cxx b/sdext/source/pdfimport/tree/imagecontainer.cxx
new file mode 100644
index 000000000000..9be7bb5de0dd
--- /dev/null
+++ b/sdext/source/pdfimport/tree/imagecontainer.cxx
@@ -0,0 +1,156 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_sdext.hxx"
+
+#include "imagecontainer.hxx"
+#include "genericelements.hxx"
+#include "xmlemitter.hxx"
+
+#include <rtl/ustrbuf.hxx>
+#include <osl/file.h>
+#include <rtl/crc.h>
+
+#include <com/sun/star/graphic/XGraphicProvider.hpp>
+#include <com/sun/star/beans/PropertyValue.hpp>
+
+#include <cppuhelper/implbase1.hxx>
+#include <comphelper/stl_types.hxx>
+
+#include <boost/bind.hpp>
+
+using namespace com::sun::star;
+
+namespace pdfi
+{
+
+namespace
+{
+
+static const sal_Char aBase64EncodeTable[] =
+ { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
+ 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
+ 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
+ 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
+ '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '+', '/' };
+
+rtl::OUString encodeBase64( const sal_Int8* i_pBuffer, const sal_uInt32 i_nBufferLength )
+{
+ rtl::OUStringBuffer aBuf( (i_nBufferLength+1) * 4 / 3 );
+ const sal_Int32 nRemain(i_nBufferLength%3);
+ const sal_Int32 nFullTripleLength( i_nBufferLength - (i_nBufferLength%3));
+ sal_Int32 nBufPos( 0 );
+ for( sal_Int32 i = 0; i < nFullTripleLength; i += 3, nBufPos += 4 )
+ {
+ const sal_Int32 nBinary = (((sal_uInt8)i_pBuffer[i + 0]) << 16) +
+ (((sal_uInt8)i_pBuffer[i + 1]) << 8) +
+ ((sal_uInt8)i_pBuffer[i + 2]);
+
+ aBuf.appendAscii("====");
+
+ sal_uInt8 nIndex (static_cast<sal_uInt8>((nBinary & 0xFC0000) >> 18));
+ aBuf.setCharAt(nBufPos, aBase64EncodeTable [nIndex]);
+
+ nIndex = static_cast<sal_uInt8>((nBinary & 0x3F000) >> 12);
+ aBuf.setCharAt(nBufPos+1, aBase64EncodeTable [nIndex]);
+
+ nIndex = static_cast<sal_uInt8>((nBinary & 0xFC0) >> 6);
+ aBuf.setCharAt(nBufPos+2, aBase64EncodeTable [nIndex]);
+
+ nIndex = static_cast<sal_uInt8>((nBinary & 0x3F));
+ aBuf.setCharAt(nBufPos+3, aBase64EncodeTable [nIndex]);
+ }
+ if( nRemain > 0 )
+ {
+ aBuf.appendAscii("====");
+ sal_Int32 nBinary( 0 );
+ const sal_Int32 nStart(i_nBufferLength-nRemain);
+ switch(nRemain)
+ {
+ case 1: nBinary = ((sal_uInt8)i_pBuffer[nStart + 0]) << 16;
+ break;
+ case 2: nBinary = (((sal_uInt8)i_pBuffer[nStart + 0]) << 16) +
+ (((sal_uInt8)i_pBuffer[nStart + 1]) << 8);
+ break;
+ }
+ sal_uInt8 nIndex (static_cast<sal_uInt8>((nBinary & 0xFC0000) >> 18));
+ aBuf.setCharAt(nBufPos, aBase64EncodeTable [nIndex]);
+
+ nIndex = static_cast<sal_uInt8>((nBinary & 0x3F000) >> 12);
+ aBuf.setCharAt(nBufPos+1, aBase64EncodeTable [nIndex]);
+
+ if( nRemain == 2 )
+ {
+ nIndex = static_cast<sal_uInt8>((nBinary & 0xFC0) >> 6);
+ aBuf.setCharAt(nBufPos+2, aBase64EncodeTable [nIndex]);
+ }
+ }
+
+ return aBuf.makeStringAndClear();
+}
+
+} // namespace
+
+ImageContainer::ImageContainer() :
+ m_aImages()
+{}
+
+ImageId ImageContainer::addImage( const uno::Sequence<beans::PropertyValue>& xBitmap )
+{
+ m_aImages.push_back( xBitmap );
+ return m_aImages.size()-1;
+}
+
+void ImageContainer::writeBase64EncodedStream( ImageId nId, EmitContext& rContext )
+{
+ OSL_ASSERT( nId >= 0 && nId < ImageId( m_aImages.size()) );
+
+ const uno::Sequence<beans::PropertyValue>& rEntry( m_aImages[nId] );
+
+ // find "InputSequence" property
+ const beans::PropertyValue* pAry(rEntry.getConstArray());
+ const sal_Int32 nLen(rEntry.getLength());
+ const beans::PropertyValue* pValue(
+ std::find_if(pAry,pAry+nLen,
+ boost::bind(comphelper::TPropertyValueEqualFunctor(),
+ _1,
+ rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("InputSequence")))));
+ OSL_ENSURE( pValue != pAry+nLen,
+ "InputSequence not found" );
+
+ uno::Sequence<sal_Int8> aData;
+ if( !(pValue->Value >>= aData) )
+ OSL_FAIL("Wrong data type");
+
+ rContext.rEmitter.write( encodeBase64( aData.getConstArray(), aData.getLength() ));
+}
+
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sdext/source/pdfimport/tree/imagecontainer.hxx b/sdext/source/pdfimport/tree/imagecontainer.hxx
new file mode 100644
index 000000000000..525c31d570ce
--- /dev/null
+++ b/sdext/source/pdfimport/tree/imagecontainer.hxx
@@ -0,0 +1,63 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+#ifndef INCLUDED_PDFI_IMAGECONTAINER_HXX
+#define INCLUDED_PDFI_IMAGECONTAINER_HXX
+
+#include "pdfihelper.hxx"
+
+#include <rtl/ustring.hxx>
+#include <com/sun/star/uno/Reference.hxx>
+#include <com/sun/star/uno/XComponentContext.hpp>
+#include <com/sun/star/awt/XBitmap.hpp>
+
+#include <vector>
+#include <boost/unordered_map.hpp>
+
+namespace pdfi
+{
+ struct EmitContext;
+
+ class ImageContainer
+ {
+ private:
+ std::vector< ::com::sun::star::uno::Sequence<
+ ::com::sun::star::beans::PropertyValue> > m_aImages;
+
+ public:
+ ImageContainer();
+
+ ImageId addImage( const ::com::sun::star::uno::Sequence<
+ ::com::sun::star::beans::PropertyValue>& xBitmap );
+ void writeBase64EncodedStream( ImageId nImageId, EmitContext& rContext );
+ };
+}
+
+#endif
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sdext/source/pdfimport/tree/makefile.mk b/sdext/source/pdfimport/tree/makefile.mk
new file mode 100644
index 000000000000..827833296f4a
--- /dev/null
+++ b/sdext/source/pdfimport/tree/makefile.mk
@@ -0,0 +1,56 @@
+#*************************************************************************
+#
+# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+#
+# Copyright 2000, 2010 Oracle and/or its affiliates.
+#
+# OpenOffice.org - a multi-platform office productivity suite
+#
+# This file is part of OpenOffice.org.
+#
+# OpenOffice.org is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Lesser General Public License version 3
+# only, as published by the Free Software Foundation.
+#
+# OpenOffice.org is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Lesser General Public License version 3 for more details
+# (a copy is included in the LICENSE file that accompanied this code).
+#
+# You should have received a copy of the GNU Lesser General Public License
+# version 3 along with OpenOffice.org. If not, see
+# <http://www.openoffice.org/license.html>
+# for a copy of the LGPLv3 License.
+#
+#*************************************************************************
+
+PRJ=..$/..$/..
+
+PRJNAME=sdext
+TARGET=pdfparsetree
+ENABLE_EXCEPTIONS=TRUE
+
+# --- Settings -----------------------------------------------------
+
+.INCLUDE: settings.mk
+
+# --- Files --------------------------------------------------------
+
+SLOFILES=\
+ $(SLO)$/genericelements.obj \
+ $(SLO)$/imagecontainer.obj \
+ $(SLO)$/pdfiprocessor.obj \
+ $(SLO)$/writertreevisiting.obj \
+ $(SLO)$/drawtreevisiting.obj \
+ $(SLO)$/treevisitorfactory.obj \
+ $(SLO)$/style.obj
+
+# --- Targets ------------------------------------------------------
+
+.IF "$(ENABLE_PDFIMPORT)" == "NO"
+@all:
+ @echo "PDF Import extension disabled."
+.ENDIF
+
+.INCLUDE: target.mk
diff --git a/sdext/source/pdfimport/tree/pdfiprocessor.cxx b/sdext/source/pdfimport/tree/pdfiprocessor.cxx
new file mode 100644
index 000000000000..62796d37c01a
--- /dev/null
+++ b/sdext/source/pdfimport/tree/pdfiprocessor.cxx
@@ -0,0 +1,1463 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_sdext.hxx"
+
+#include "pdfiprocessor.hxx"
+#include "xmlemitter.hxx"
+#include "pdfihelper.hxx"
+#include "imagecontainer.hxx"
+#include "genericelements.hxx"
+#include "style.hxx"
+#include "treevisiting.hxx"
+
+#include <rtl/string.hxx>
+#include <rtl/strbuf.hxx>
+
+#include <comphelper/sequence.hxx>
+#include <basegfx/polygon/b2dpolypolygontools.hxx>
+#include <basegfx/polygon/b2dpolygonclipper.hxx>
+#include <basegfx/polygon/b2dpolygontools.hxx>
+#include <basegfx/tools/canvastools.hxx>
+#include <basegfx/matrix/b2dhommatrix.hxx>
+#include <basegfx/range/b2irange.hxx>
+#include <basegfx/range/b2drectangle.hxx>
+#include <basegfx/matrix/b2dhommatrixtools.hxx>
+
+#include <com/sun/star/rendering/XVolatileBitmap.hpp>
+#include <com/sun/star/geometry/RealSize2D.hpp>
+#include <com/sun/star/geometry/RealPoint2D.hpp>
+#include <com/sun/star/geometry/RealRectangle2D.hpp>
+
+
+using namespace com::sun::star;
+
+
+namespace pdfi
+{
+
+ PDFIProcessor::PDFIProcessor( const uno::Reference< task::XStatusIndicator >& xStat ,
+ com::sun::star::uno::Reference< com::sun::star::uno::XComponentContext > xContext) :
+
+ m_xContext(xContext),
+ fYPrevTextPosition(-10000.0),
+ fPrevTextHeight(0.0),
+ fXPrevTextPosition(0.0),
+ fPrevTextWidth(0.0),
+ m_pElFactory( new ElementFactory() ),
+ m_pDocument( m_pElFactory->createDocumentElement() ),
+ m_pCurPage(0),
+ m_pCurElement(0),
+ m_nNextFontId( 1 ),
+ m_aIdToFont(),
+ m_aFontToId(),
+ m_aGCStack(),
+ m_nNextGCId( 1 ),
+ m_aIdToGC(),
+ m_aGCToId(),
+ m_aImages(),
+ m_eTextDirection( LrTb ),
+ m_nPages(0),
+ m_nNextZOrder( 1 ),
+ m_fWordSpace(0.0),
+ m_bIsWhiteSpaceInLine( false ),
+ m_xStatusIndicator( xStat ),
+ m_bHaveTextOnDocLevel(false),
+ m_bMirrorMapperTried(false)
+{
+ FontAttributes aDefFont;
+ aDefFont.familyName = USTR("Helvetica");
+ aDefFont.isBold = false;
+ aDefFont.isItalic = false;
+ aDefFont.size = 10*PDFI_OUTDEV_RESOLUTION/72;
+ m_aIdToFont[ 0 ] = aDefFont;
+ m_aFontToId[ aDefFont ] = 0;
+
+ GraphicsContext aDefGC;
+ m_aGCStack.push_back( aDefGC );
+ m_aIdToGC[ 0 ] = aDefGC;
+ m_aGCToId[ aDefGC ] = 0;
+}
+
+void PDFIProcessor::enableToplevelText()
+{
+ m_bHaveTextOnDocLevel = true;
+}
+
+void PDFIProcessor::setPageNum( sal_Int32 nPages )
+{
+ m_nPages = nPages;
+}
+
+
+void PDFIProcessor::pushState()
+{
+ m_aGCStack.push_back( m_aGCStack.back() );
+}
+
+void PDFIProcessor::popState()
+{
+ m_aGCStack.pop_back();
+}
+
+void PDFIProcessor::setFlatness( double value )
+{
+ getCurrentContext().Flatness = value;
+}
+
+void PDFIProcessor::setTransformation( const geometry::AffineMatrix2D& rMatrix )
+{
+ basegfx::unotools::homMatrixFromAffineMatrix(
+ getCurrentContext().Transformation,
+ rMatrix );
+}
+
+void PDFIProcessor::setLineDash( const uno::Sequence<double>& dashes,
+ double /*start*/ )
+{
+ // TODO(F2): factor in start offset
+ GraphicsContext& rContext( getCurrentContext() );
+ comphelper::sequenceToContainer(rContext.DashArray,dashes);
+}
+
+void PDFIProcessor::setLineJoin(sal_Int8 nJoin)
+{
+ getCurrentContext().LineJoin = nJoin;
+}
+
+void PDFIProcessor::setLineCap(sal_Int8 nCap)
+{
+ getCurrentContext().LineCap = nCap;
+}
+
+void PDFIProcessor::setMiterLimit(double)
+{
+ OSL_TRACE("PDFIProcessor::setMiterLimit(): not supported by ODF");
+}
+
+void PDFIProcessor::setLineWidth(double nWidth)
+{
+ getCurrentContext().LineWidth = nWidth;
+}
+
+void PDFIProcessor::setFillColor( const rendering::ARGBColor& rColor )
+{
+ getCurrentContext().FillColor = rColor;
+}
+
+void PDFIProcessor::setStrokeColor( const rendering::ARGBColor& rColor )
+{
+ getCurrentContext().LineColor = rColor;
+}
+
+void PDFIProcessor::setBlendMode(sal_Int8)
+{
+ OSL_TRACE("PDFIProcessor::setBlendMode(): not supported by ODF");
+}
+
+void PDFIProcessor::setFont( const FontAttributes& i_rFont )
+{
+ FontAttributes aChangedFont( i_rFont );
+ GraphicsContext& rGC=getCurrentContext();
+ // for text render modes, please see PDF reference manual
+ aChangedFont.isOutline = ( (rGC.TextRenderMode == 1) || (rGC. TextRenderMode == 2) );
+ FontToIdMap::const_iterator it = m_aFontToId.find( aChangedFont );
+ if( it != m_aFontToId.end() )
+ rGC.FontId = it->second;
+ else
+ {
+ m_aFontToId[ aChangedFont ] = m_nNextFontId;
+ m_aIdToFont[ m_nNextFontId ] = aChangedFont;
+ rGC.FontId = m_nNextFontId;
+ m_nNextFontId++;
+ }
+}
+
+void PDFIProcessor::setTextRenderMode( sal_Int32 i_nMode )
+{
+ GraphicsContext& rGC=getCurrentContext();
+ rGC.TextRenderMode = i_nMode;
+ IdToFontMap::iterator it = m_aIdToFont.find( rGC.FontId );
+ if( it != m_aIdToFont.end() )
+ setFont( it->second );
+}
+
+sal_Int32 PDFIProcessor::getFontId( const FontAttributes& rAttr ) const
+{
+ const sal_Int32 nCurFont = getCurrentContext().FontId;
+ const_cast<PDFIProcessor*>(this)->setFont( rAttr );
+ const sal_Int32 nFont = getCurrentContext().FontId;
+ const_cast<PDFIProcessor*>(this)->getCurrentContext().FontId = nCurFont;
+
+ return nFont;
+}
+
+// line diagnose block - start
+void PDFIProcessor::processGlyphLine()
+{
+ if( m_GlyphsList.empty() )
+ return;
+
+ double fPreAvarageSpaceValue= 0.0;
+ double fAvarageDiffCharSpaceValue= 0.0;
+ double fMinPreSpaceValue= 0.0;
+ double fMaxPreSpaceValue= 0.0;
+ double fNullSpaceBreakerAvaregeSpaceValue = 0.0;
+
+ unsigned int nSpaceCount( 0 );
+ unsigned int nDiffSpaceCount( 0 );
+ unsigned int nNullSpaceBreakerCount=0;
+ bool preSpaceNull(true);
+
+ for ( unsigned int i=0; i<m_GlyphsList.size()-1; i++ ) // i=1 because the first glyph doesn't have a prevGlyphSpace value
+ {
+ if( m_GlyphsList[i].getPrevGlyphsSpace()>0.0 )
+ {
+ if( fMinPreSpaceValue>m_GlyphsList[i].getPrevGlyphsSpace() )
+ fMinPreSpaceValue=m_GlyphsList[i].getPrevGlyphsSpace();
+
+ if( fMaxPreSpaceValue<m_GlyphsList[i].getPrevGlyphsSpace() )
+ fMaxPreSpaceValue=m_GlyphsList[i].getPrevGlyphsSpace();
+
+ fPreAvarageSpaceValue+= m_GlyphsList[i].getPrevGlyphsSpace();
+ nSpaceCount++;
+ }
+ }
+
+ if( nSpaceCount!=0 )
+ fPreAvarageSpaceValue= fPreAvarageSpaceValue/( nSpaceCount );
+
+ for ( unsigned int i=0; i<m_GlyphsList.size()-1; i++ ) // i=1 because the first glyph doesn't have a prevGlyphSpace value
+ {
+ if ( m_GlyphsList[i].getPrevGlyphsSpace()==0.0 )
+ {
+ if (
+ ( m_GlyphsList[i+1].getPrevGlyphsSpace()>0.0)&&
+ ( fPreAvarageSpaceValue>m_GlyphsList[i+1].getPrevGlyphsSpace())
+ )
+ {
+ fNullSpaceBreakerAvaregeSpaceValue+=m_GlyphsList[i+1].getPrevGlyphsSpace();
+ nNullSpaceBreakerCount++;
+ }
+ }
+ }
+
+ if( ( fNullSpaceBreakerAvaregeSpaceValue!= 0.0 )&&
+ ( fNullSpaceBreakerAvaregeSpaceValue < fPreAvarageSpaceValue )
+ )
+ {
+ fPreAvarageSpaceValue = fNullSpaceBreakerAvaregeSpaceValue;
+ }
+
+ for ( unsigned int i=0; i<m_GlyphsList.size()-1; i++ ) // i=1 cose the first Glypth dont have prevGlyphSpace value
+ {
+ if ( ( m_GlyphsList[i].getPrevGlyphsSpace()>0.0 )
+ )
+ {
+ if (
+ ( m_GlyphsList[i].getPrevGlyphsSpace() <= fPreAvarageSpaceValue )&&
+ ( m_GlyphsList[i+1].getPrevGlyphsSpace()<= fPreAvarageSpaceValue )
+ )
+ {
+ double temp= m_GlyphsList[i].getPrevGlyphsSpace()-m_GlyphsList[i+1].getPrevGlyphsSpace();
+
+ if(temp!=0.0)
+ {
+ if( temp< 0.0)
+ temp= temp* -1.0;
+
+ fAvarageDiffCharSpaceValue+=temp;
+ nDiffSpaceCount++;
+ }
+ }
+ }
+
+ }
+
+ if (
+ ( nNullSpaceBreakerCount>0 )
+ )
+ {
+ fNullSpaceBreakerAvaregeSpaceValue=fNullSpaceBreakerAvaregeSpaceValue/nNullSpaceBreakerCount;
+ }
+
+ if (
+ ( nDiffSpaceCount>0 )&&(fAvarageDiffCharSpaceValue>0)
+ )
+ {
+ fAvarageDiffCharSpaceValue= fAvarageDiffCharSpaceValue/ nDiffSpaceCount;
+ }
+
+ ParagraphElement* pPara= NULL ;
+ FrameElement* pFrame= NULL ;
+
+ if(!m_GlyphsList.empty())
+ {
+ pFrame = m_pElFactory->createFrameElement( m_GlyphsList[0].getCurElement(), getGCId( getTransformGlyphContext( m_GlyphsList[0])) );
+ pFrame->ZOrder = m_nNextZOrder++;
+ pPara = m_pElFactory->createParagraphElement( pFrame );
+
+
+
+ processGlyph( 0,
+ m_GlyphsList[0],
+ pPara,
+ pFrame,
+ m_bIsWhiteSpaceInLine );
+
+
+ }
+
+
+ preSpaceNull=false;
+
+ for ( unsigned int i=1; i<m_GlyphsList.size()-1; i++ )
+ {
+ double fPrevDiffCharSpace= m_GlyphsList[i].getPrevGlyphsSpace()-m_GlyphsList[i-1].getPrevGlyphsSpace();
+ double fPostDiffCharSpace= m_GlyphsList[i].getPrevGlyphsSpace()-m_GlyphsList[i+1].getPrevGlyphsSpace();
+
+
+ if(
+ preSpaceNull && (m_GlyphsList[i].getPrevGlyphsSpace()!= 0.0)
+ )
+ {
+ preSpaceNull=false;
+ if( fNullSpaceBreakerAvaregeSpaceValue > m_GlyphsList[i].getPrevGlyphsSpace() )
+ {
+ processGlyph( 0,
+ m_GlyphsList[i],
+ pPara,
+ pFrame,
+ m_bIsWhiteSpaceInLine );
+
+ }
+ else
+ {
+ processGlyph( 1,
+ m_GlyphsList[i],
+ pPara,
+ pFrame,
+ m_bIsWhiteSpaceInLine );
+
+ }
+
+ }
+ else
+ {
+ if (
+ ( ( m_GlyphsList[i].getPrevGlyphsSpace()<= fPreAvarageSpaceValue )&&
+ ( fPrevDiffCharSpace<=fAvarageDiffCharSpaceValue )&&
+ ( fPostDiffCharSpace<=fAvarageDiffCharSpaceValue )
+ ) ||
+ ( m_GlyphsList[i].getPrevGlyphsSpace() == 0.0 )
+ )
+ {
+ preSpaceNull=true;
+
+ processGlyph( 0,
+ m_GlyphsList[i],
+ pPara,
+ pFrame,
+ m_bIsWhiteSpaceInLine );
+
+ }
+ else
+ {
+ processGlyph( 1,
+ m_GlyphsList[i],
+ pPara,
+ pFrame,
+ m_bIsWhiteSpaceInLine );
+
+ }
+
+ }
+
+ }
+
+ if(!m_GlyphsList.empty())
+ processGlyph( 0,
+ m_GlyphsList[m_GlyphsList.size()-1],
+ pPara,
+ pFrame,
+ m_bIsWhiteSpaceInLine );
+
+ m_GlyphsList.clear();
+}
+
+void PDFIProcessor::processGlyph( double fPreAvarageSpaceValue,
+ CharGlyph& aGlyph,
+ ParagraphElement* pPara,
+ FrameElement* pFrame,
+ bool bIsWhiteSpaceInLine
+ )
+{
+ if( !bIsWhiteSpaceInLine )
+ {
+ bool flag=( 0 < fPreAvarageSpaceValue );
+
+ drawCharGlyphs( aGlyph.getGlyph(),
+ aGlyph.getRect(),
+ aGlyph.getFontMatrix(),
+ aGlyph.getGC(),
+ aGlyph.getCurElement(),
+ pPara,
+ pFrame,
+ flag);
+ }
+ else
+ {
+ drawCharGlyphs( aGlyph.getGlyph(),
+ aGlyph.getRect(),
+ aGlyph.getFontMatrix(),
+ aGlyph.getGC(),
+ aGlyph.getCurElement(),
+ pPara,
+ pFrame,
+ false );
+ }
+}
+
+void PDFIProcessor::drawGlyphLine( const rtl::OUString& rGlyphs,
+ const geometry::RealRectangle2D& rRect,
+ const geometry::Matrix2D& rFontMatrix )
+{
+ double isFirstLine= fYPrevTextPosition+ fXPrevTextPosition+ fPrevTextHeight+ fPrevTextWidth ;
+ if(
+ ( ( ( fYPrevTextPosition!= rRect.Y1 ) ) ||
+ ( ( fXPrevTextPosition > rRect.X2 ) ) ||
+ ( ( fXPrevTextPosition+fPrevTextWidth*1.3)<rRect.X1 )
+ ) && ( isFirstLine> 0.0 )
+ )
+ {
+ processGlyphLine();
+ }
+
+ CharGlyph aGlyph;
+
+ aGlyph.setGlyph ( rGlyphs );
+ aGlyph.setRect ( rRect );
+ aGlyph.setFontMatrix ( rFontMatrix );
+ aGlyph.setGraphicsContext ( getCurrentContext() );
+ getGCId(getCurrentContext());
+ aGlyph.setCurElement( m_pCurElement );
+
+ aGlyph.setYPrevGlyphPosition( fYPrevTextPosition );
+ aGlyph.setXPrevGlyphPosition( fXPrevTextPosition );
+ aGlyph.setPrevGlyphHeight ( fPrevTextHeight );
+ aGlyph.setPrevGlyphWidth ( fPrevTextWidth );
+
+ m_GlyphsList.push_back( aGlyph );
+
+ fYPrevTextPosition = rRect.Y1;
+ fXPrevTextPosition = rRect.X2;
+ fPrevTextHeight = rRect.Y2-rRect.Y1;
+ fPrevTextWidth = rRect.X2-rRect.X1;
+
+ if( !m_bIsWhiteSpaceInLine )
+ {
+ static rtl::OUString tempWhiteSpaceStr( 0x20 );
+ static rtl::OUString tempWhiteSpaceNonBreakingStr( 0xa0 );
+ m_bIsWhiteSpaceInLine=(rGlyphs.equals( tempWhiteSpaceStr ) || rGlyphs.equals( tempWhiteSpaceNonBreakingStr ));
+ }
+}
+
+GraphicsContext& PDFIProcessor::getTransformGlyphContext( CharGlyph& rGlyph )
+{
+ geometry::RealRectangle2D rRect = rGlyph.getRect();
+ geometry::Matrix2D rFontMatrix = rGlyph.getFontMatrix();
+
+ rtl::OUString tempStr( 32 );
+ geometry::RealRectangle2D aRect(rRect);
+
+ basegfx::B2DHomMatrix aFontMatrix;
+ basegfx::unotools::homMatrixFromMatrix(
+ aFontMatrix,
+ rFontMatrix );
+
+ FontAttributes aFontAttrs = m_aIdToFont[ rGlyph.getGC().FontId ];
+
+ // add transformation to GC
+ basegfx::B2DHomMatrix aFontTransform(basegfx::tools::createTranslateB2DHomMatrix(-rRect.X1, -rRect.Y1));
+ aFontTransform *= aFontMatrix;
+ aFontTransform.translate( rRect.X1, rRect.Y1 );
+
+
+ rGlyph.getGC().Transformation = rGlyph.getGC().Transformation * aFontTransform;
+ getGCId(rGlyph.getGC());
+
+ return rGlyph.getGC();
+}
+void PDFIProcessor::drawCharGlyphs( rtl::OUString& rGlyphs,
+ geometry::RealRectangle2D& rRect,
+ geometry::Matrix2D& ,
+ GraphicsContext aGC,
+ Element* ,
+ ParagraphElement* pPara,
+ FrameElement* pFrame,
+ bool bSpaceFlag )
+{
+
+
+ rtl::OUString tempStr( 32 );
+ geometry::RealRectangle2D aRect(rRect);
+
+ ::basegfx::B2DRange aRect2;
+ calcTransformedRectBounds( aRect2,
+ ::basegfx::unotools::b2DRectangleFromRealRectangle2D(aRect),
+ aGC.Transformation );
+ // check whether there was a previous draw frame
+
+ TextElement* pText = m_pElFactory->createTextElement( pPara,
+ getGCId(aGC),
+ aGC.FontId );
+ if( bSpaceFlag )
+ pText->Text.append( tempStr );
+
+ pText->Text.append( rGlyphs );
+
+ pText->x = aRect2.getMinX() ;
+ pText->y = aRect2.getMinY() ;
+ pText->w = 0.0; // ToDO P2: 1.1 is a hack for solving of size auto-grow problem
+ pText->h = aRect2.getHeight(); // ToDO P2: 1.1 is a hack for solving of size auto-grow problem
+
+ pPara->updateGeometryWith( pText );
+
+ if( pFrame )
+ pFrame->updateGeometryWith( pPara );
+
+}
+void PDFIProcessor::drawGlyphs( const rtl::OUString& rGlyphs,
+ const geometry::RealRectangle2D& rRect,
+ const geometry::Matrix2D& rFontMatrix )
+{
+ drawGlyphLine( rGlyphs, rRect, rFontMatrix );
+}
+
+void PDFIProcessor::endText()
+{
+ TextElement* pText = dynamic_cast<TextElement*>(m_pCurElement);
+ if( pText )
+ m_pCurElement = pText->Parent;
+}
+
+void PDFIProcessor::setupImage(ImageId nImage)
+{
+ const GraphicsContext& rGC( getCurrentContext() );
+
+ basegfx::B2DHomMatrix aTrans( rGC.Transformation );
+
+ // check for rotation, which is the other way around in ODF
+ basegfx::B2DTuple aScale, aTranslation;
+ double fRotate, fShearX;
+ rGC.Transformation.decompose( aScale, aTranslation, fRotate, fShearX );
+ // TODDO(F4): correcting rotation when fShearX != 0 ?
+ if( fRotate != 0.0 )
+ {
+
+ // try to create a Transformation that corrects for the wrong rotation
+ aTrans.identity();
+ aTrans.scale( aScale.getX(), aScale.getY() );
+ aTrans.rotate( -fRotate );
+
+ basegfx::B2DRange aRect( 0, 0, 1, 1 );
+ aRect.transform( aTrans );
+
+ // TODO(F3) treat translation correctly
+ // the corrections below work for multiples of 90 degree
+ // which is a common case (landscape/portrait/seascape)
+ // we need a general solution here; however this needs to
+ // work in sync with DrawXmlEmitter::fillFrameProps and WriterXmlEmitter::fillFrameProps
+ // admittedly this is a lame workaround and fails for arbitrary rotation
+ double fQuadrant = fmod( fRotate, 2.0*M_PI ) / M_PI_2;
+ int nQuadrant = (int)fQuadrant;
+ if( nQuadrant < 0 )
+ nQuadrant += 4;
+ if( nQuadrant == 1 )
+ {
+ aTranslation.setX( aTranslation.getX() + aRect.getHeight() + aRect.getWidth());
+ aTranslation.setY( aTranslation.getY() + aRect.getHeight() );
+ }
+ if( nQuadrant == 3 )
+ aTranslation.setX( aTranslation.getX() - aRect.getHeight() );
+
+ aTrans.translate( aTranslation.getX(),
+ aTranslation.getY() );
+ }
+
+ bool bMirrorVertical = aScale.getY() > 0;
+
+ // transform unit rect to determine view box
+ basegfx::B2DRange aRect( 0, 0, 1, 1 );
+ aRect.transform( aTrans );
+
+ // TODO(F3): Handle clip
+ const sal_Int32 nGCId = getGCId(rGC);
+ FrameElement* pFrame = m_pElFactory->createFrameElement( m_pCurElement, nGCId );
+ ImageElement* pImageElement = m_pElFactory->createImageElement( pFrame, nGCId, nImage );
+ pFrame->x = pImageElement->x = aRect.getMinX();
+ pFrame->y = pImageElement->y = aRect.getMinY();
+ pFrame->w = pImageElement->w = aRect.getWidth();
+ pFrame->h = pImageElement->h = aRect.getHeight();
+ pFrame->ZOrder = m_nNextZOrder++;
+
+ if( bMirrorVertical )
+ {
+ pFrame->MirrorVertical = pImageElement->MirrorVertical = true;
+ pFrame->x += aRect.getWidth();
+ pImageElement->x += aRect.getWidth();
+ pFrame->y += aRect.getHeight();
+ pImageElement->y += aRect.getHeight();
+ }
+}
+
+void PDFIProcessor::drawMask(const uno::Sequence<beans::PropertyValue>& xBitmap,
+ bool /*bInvert*/ )
+{
+ // TODO(F3): Handle mask and inversion
+ setupImage( m_aImages.addImage(xBitmap) );
+}
+
+void PDFIProcessor::drawImage(const uno::Sequence<beans::PropertyValue>& xBitmap )
+{
+ setupImage( m_aImages.addImage(xBitmap) );
+}
+
+void PDFIProcessor::drawColorMaskedImage(const uno::Sequence<beans::PropertyValue>& xBitmap,
+ const uno::Sequence<uno::Any>& /*xMaskColors*/ )
+{
+ // TODO(F3): Handle mask colors
+ setupImage( m_aImages.addImage(xBitmap) );
+}
+
+void PDFIProcessor::drawMaskedImage(const uno::Sequence<beans::PropertyValue>& xBitmap,
+ const uno::Sequence<beans::PropertyValue>& /*xMask*/,
+ bool /*bInvertMask*/)
+{
+ // TODO(F3): Handle mask and inversion
+ setupImage( m_aImages.addImage(xBitmap) );
+}
+
+void PDFIProcessor::drawAlphaMaskedImage(const uno::Sequence<beans::PropertyValue>& xBitmap,
+ const uno::Sequence<beans::PropertyValue>& /*xMask*/)
+{
+ // TODO(F3): Handle mask
+
+ setupImage( m_aImages.addImage(xBitmap) );
+
+}
+
+void PDFIProcessor::strokePath( const uno::Reference< rendering::XPolyPolygon2D >& rPath )
+{
+ basegfx::B2DPolyPolygon aPoly=basegfx::unotools::b2DPolyPolygonFromXPolyPolygon2D(rPath);
+ aPoly.transform(getCurrentContext().Transformation);
+
+ PolyPolyElement* pPoly = m_pElFactory->createPolyPolyElement(
+ m_pCurElement,
+ getGCId(getCurrentContext()),
+ aPoly,
+ PATH_STROKE );
+ pPoly->updateGeometry();
+ pPoly->ZOrder = m_nNextZOrder++;
+}
+
+void PDFIProcessor::fillPath( const uno::Reference< rendering::XPolyPolygon2D >& rPath )
+{
+ basegfx::B2DPolyPolygon aPoly=basegfx::unotools::b2DPolyPolygonFromXPolyPolygon2D(rPath);
+ aPoly.transform(getCurrentContext().Transformation);
+
+ PolyPolyElement* pPoly = m_pElFactory->createPolyPolyElement(
+ m_pCurElement,
+ getGCId(getCurrentContext()),
+ aPoly,
+ PATH_FILL );
+ pPoly->updateGeometry();
+ pPoly->ZOrder = m_nNextZOrder++;
+}
+
+void PDFIProcessor::eoFillPath( const uno::Reference< rendering::XPolyPolygon2D >& rPath )
+{
+ basegfx::B2DPolyPolygon aPoly=basegfx::unotools::b2DPolyPolygonFromXPolyPolygon2D(rPath);
+ aPoly.transform(getCurrentContext().Transformation);
+
+ PolyPolyElement* pPoly = m_pElFactory->createPolyPolyElement(
+ m_pCurElement,
+ getGCId(getCurrentContext()),
+ aPoly,
+ PATH_EOFILL );
+ pPoly->updateGeometry();
+ pPoly->ZOrder = m_nNextZOrder++;
+}
+
+void PDFIProcessor::intersectClip(const uno::Reference< rendering::XPolyPolygon2D >& rPath)
+{
+ // TODO(F3): interpret fill mode
+ basegfx::B2DPolyPolygon aNewClip = basegfx::unotools::b2DPolyPolygonFromXPolyPolygon2D(rPath);
+ aNewClip.transform(getCurrentContext().Transformation);
+ basegfx::B2DPolyPolygon aCurClip = getCurrentContext().Clip;
+
+ if( aCurClip.count() ) // #i92985# adapted API from (..., false, false) to (..., true, false)
+ aNewClip = basegfx::tools::clipPolyPolygonOnPolyPolygon( aCurClip, aNewClip, true, false );
+
+ getCurrentContext().Clip = aNewClip;
+}
+
+void PDFIProcessor::intersectEoClip(const uno::Reference< rendering::XPolyPolygon2D >& rPath)
+{
+ // TODO(F3): interpret fill mode
+ basegfx::B2DPolyPolygon aNewClip = basegfx::unotools::b2DPolyPolygonFromXPolyPolygon2D(rPath);
+ aNewClip.transform(getCurrentContext().Transformation);
+ basegfx::B2DPolyPolygon aCurClip = getCurrentContext().Clip;
+
+ if( aCurClip.count() ) // #i92985# adapted API from (..., false, false) to (..., true, false)
+ aNewClip = basegfx::tools::clipPolyPolygonOnPolyPolygon( aCurClip, aNewClip, true, false );
+
+ getCurrentContext().Clip = aNewClip;
+}
+
+void PDFIProcessor::hyperLink( const geometry::RealRectangle2D& rBounds,
+ const ::rtl::OUString& rURI )
+{
+ if( rURI.getLength() )
+ {
+ HyperlinkElement* pLink = m_pElFactory->createHyperlinkElement(
+ &m_pCurPage->Hyperlinks,
+ rURI );
+ pLink->x = rBounds.X1;
+ pLink->y = rBounds.Y1;
+ pLink->w = rBounds.X2-rBounds.X1;
+ pLink->h = rBounds.Y2-rBounds.Y1;
+ }
+}
+
+const FontAttributes& PDFIProcessor::getFont( sal_Int32 nFontId ) const
+{
+ IdToFontMap::const_iterator it = m_aIdToFont.find( nFontId );
+ if( it == m_aIdToFont.end() )
+ it = m_aIdToFont.find( 0 );
+ return it->second;
+}
+
+sal_Int32 PDFIProcessor::getGCId( const GraphicsContext& rGC )
+{
+ sal_Int32 nGCId = 0;
+ GCToIdMap::const_iterator it = m_aGCToId.find( rGC );
+ if( it != m_aGCToId.end() )
+ nGCId = it->second;
+ else
+ {
+ m_aGCToId[ rGC ] = m_nNextGCId;
+ m_aIdToGC[ m_nNextGCId ] = rGC;
+ nGCId = m_nNextGCId;
+ m_nNextGCId++;
+ }
+
+ return nGCId;
+}
+
+const GraphicsContext& PDFIProcessor::getGraphicsContext( sal_Int32 nGCId ) const
+{
+ IdToGCMap::const_iterator it = m_aIdToGC.find( nGCId );
+ if( it == m_aIdToGC.end() )
+ it = m_aIdToGC.find( 0 );
+ return it->second;
+}
+
+void PDFIProcessor::endPage()
+{
+ processGlyphLine(); // draw last line
+ if( m_xStatusIndicator.is()
+ && m_pCurPage
+ && m_pCurPage->PageNumber == m_nPages
+ )
+ m_xStatusIndicator->end();
+}
+
+void PDFIProcessor::startPage( const geometry::RealSize2D& rSize )
+{
+ // initial clip is to page bounds
+ getCurrentContext().Clip = basegfx::B2DPolyPolygon(
+ basegfx::tools::createPolygonFromRect(
+ basegfx::B2DRange( 0, 0, rSize.Width, rSize.Height )));
+
+ sal_Int32 nNextPageNr = m_pCurPage ? m_pCurPage->PageNumber+1 : 1;
+ if( m_xStatusIndicator.is() )
+ {
+ if( nNextPageNr == 1 )
+ startIndicator( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( " " ) ) );
+ m_xStatusIndicator->setValue( nNextPageNr );
+ }
+ m_pCurPage = m_pElFactory->createPageElement(m_pDocument.get(), nNextPageNr);
+ m_pCurElement = m_pCurPage;
+ m_pCurPage->w = rSize.Width;
+ m_pCurPage->h = rSize.Height;
+ m_nNextZOrder = 1;
+
+
+}
+
+void PDFIProcessor::emit( XmlEmitter& rEmitter,
+ const TreeVisitorFactory& rVisitorFactory )
+{
+#if OSL_DEBUG_LEVEL > 1
+ m_pDocument->emitStructure( 0 );
+#endif
+
+ ElementTreeVisitorSharedPtr optimizingVisitor(
+ rVisitorFactory.createOptimizingVisitor(*this));
+ // FIXME: localization
+ startIndicator( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( " " ) ) );
+ m_pDocument->visitedBy( *optimizingVisitor, std::list<Element*>::iterator());
+
+#if OSL_DEBUG_LEVEL > 1
+ m_pDocument->emitStructure( 0 );
+#endif
+
+ // get styles
+ StyleContainer aStyles;
+ ElementTreeVisitorSharedPtr finalizingVisitor(
+ rVisitorFactory.createStyleCollectingVisitor(aStyles,*this));
+ // FIXME: localization
+
+ m_pDocument->visitedBy( *finalizingVisitor, std::list<Element*>::iterator() );
+
+ EmitContext aContext( rEmitter, aStyles, m_aImages, *this, m_xStatusIndicator, m_xContext );
+ ElementTreeVisitorSharedPtr aEmittingVisitor(
+ rVisitorFactory.createEmittingVisitor(aContext, *this));
+
+ PropertyMap aProps;
+ // document prolog
+ #define OASIS_STR "urn:oasis:names:tc:opendocument:xmlns:"
+ aProps[ USTR( "xmlns:office" ) ] = USTR( OASIS_STR "office:1.0" );
+ aProps[ USTR( "xmlns:style" ) ] = USTR( OASIS_STR "style:1.0" );
+ aProps[ USTR( "xmlns:text" ) ] = USTR( OASIS_STR "text:1.0" );
+ aProps[ USTR( "xmlns:svg" ) ] = USTR( OASIS_STR "svg-compatible:1.0" );
+ aProps[ USTR( "xmlns:table" ) ] = USTR( OASIS_STR "table:1.0" );
+ aProps[ USTR( "xmlns:draw" ) ] = USTR( OASIS_STR "drawing:1.0" );
+ aProps[ USTR( "xmlns:fo" ) ] = USTR( OASIS_STR "xsl-fo-compatible:1.0" );
+ aProps[ USTR( "xmlns:xlink" )] = USTR( "http://www.w3.org/1999/xlink" );
+ aProps[ USTR( "xmlns:dc" )] = USTR( "http://purl.org/dc/elements/1.1/" );
+ aProps[ USTR( "xmlns:number" )] = USTR( OASIS_STR "datastyle:1.0" );
+ aProps[ USTR( "xmlns:presentation" )] = USTR( OASIS_STR "presentation:1.0" );
+ aProps[ USTR( "xmlns:math" )] = USTR( "http://www.w3.org/1998/Math/MathML" );
+ aProps[ USTR( "xmlns:form" )] = USTR( OASIS_STR "form:1.0" );
+ aProps[ USTR( "xmlns:script" )] = USTR( OASIS_STR "script:1.0" );
+ aProps[ USTR( "xmlns:dom" )] = USTR( "http://www.w3.org/2001/xml-events" );
+ aProps[ USTR( "xmlns:xforms" )] = USTR( "http://www.w3.org/2002/xforms" );
+ aProps[ USTR( "xmlns:xsd" )] = USTR( "http://www.w3.org/2001/XMLSchema" );
+ aProps[ USTR( "xmlns:xsi" )] = USTR( "http://www.w3.org/2001/XMLSchema-instance" );
+ aProps[ USTR( "office:version" ) ] = USTR( "1.0" );
+ aProps[ USTR( "office:version" ) ] = USTR( "1.0" );
+
+ aContext.rEmitter.beginTag( "office:document", aProps );
+
+ // emit style list
+ aStyles.emit( aContext, *aEmittingVisitor );
+
+ m_pDocument->visitedBy( *aEmittingVisitor, std::list<Element*>::iterator() );
+ aContext.rEmitter.endTag( "office:document" );
+ endIndicator();
+}
+
+void PDFIProcessor::startIndicator( const rtl::OUString& rText, sal_Int32 nElements )
+{
+ if( nElements == -1 )
+ nElements = m_nPages;
+ if( m_xStatusIndicator.is() )
+ {
+ sal_Int32 nUnicodes = rText.getLength();
+ rtl::OUStringBuffer aStr( nUnicodes*2 );
+ const sal_Unicode* pText = rText.getStr();
+ for( int i = 0; i < nUnicodes; i++ )
+ {
+ if( nUnicodes-i > 1&&
+ pText[i] == '%' &&
+ pText[i+1] == 'd'
+ )
+ {
+ aStr.append( nElements );
+ i++;
+ }
+ else
+ aStr.append( pText[i] );
+ }
+ m_xStatusIndicator->start( aStr.makeStringAndClear(), nElements );
+ }
+}
+
+void PDFIProcessor::endIndicator()
+{
+ if( m_xStatusIndicator.is() )
+ m_xStatusIndicator->end();
+}
+
+void PDFIProcessor::sortDocument( bool bDeep )
+{
+ for( std::list< Element* >::iterator it = m_pDocument->Children.begin();
+ it != m_pDocument->Children.end(); ++it )
+ {
+ if( dynamic_cast<PageElement*>(*it) != NULL )
+ sortElements( *it, bDeep );
+ }
+}
+
+static bool lr_tb_sort( Element* pLeft, Element* pRight )
+{
+ // first: top-bottom sorting
+
+ // Note: allow for 10% overlap on text lines since text lines are usually
+ // of the same order as font height whereas the real paint area
+ // of text is usually smaller
+ double fudge_factor = 1.0;
+ if( dynamic_cast< TextElement* >(pLeft) || dynamic_cast< TextElement* >(pRight) )
+ fudge_factor = 0.9;
+
+ // if left's lower boundary is above right's upper boundary
+ // then left is smaller
+ if( pLeft->y+pLeft->h*fudge_factor < pRight->y )
+ return true;
+ // if right's lower boundary is above left's upper boundary
+ // then left is definitely not smaller
+ if( pRight->y+pRight->h*fudge_factor < pLeft->y )
+ return false;
+
+ // by now we have established that left and right are inside
+ // a "line", that is they have vertical overlap
+ // second: left-right sorting
+ // if left's right boundary is left to right's left boundary
+ // then left is smaller
+ if( pLeft->x+pLeft->w < pRight->x )
+ return true;
+ // if right's right boundary is left to left's left boundary
+ // then left is definitely not smaller
+ if( pRight->x+pRight->w < pLeft->x )
+ return false;
+
+ // here we have established vertical and horizontal overlap
+ // so sort left first, top second
+ if( pLeft->x < pRight->x )
+ return true;
+ if( pRight->x < pLeft->x )
+ return false;
+ if( pLeft->y < pRight->y )
+ return true;
+
+ return false;
+}
+
+void PDFIProcessor::sortElements( Element* pEle, bool bDeep )
+{
+ if( pEle->Children.empty() )
+ return;
+
+ if( bDeep )
+ {
+ for( std::list< Element* >::iterator it = pEle->Children.begin();
+ it != pEle->Children.end(); ++it )
+ {
+ sortElements( *it, bDeep );
+ }
+ }
+ // HACK: the stable sort member on std::list that takes a
+ // strict weak ordering requires member templates - which we
+ // do not have on all compilers. so we need to use std::stable_sort
+ // here - which does need random access iterators which the
+ // list iterators are not.
+ // so we need to copy the Element* to an array, stable sort that and
+ // copy them back.
+ std::vector<Element*> aChildren;
+ while( ! pEle->Children.empty() )
+ {
+ aChildren.push_back( pEle->Children.front() );
+ pEle->Children.pop_front();
+ }
+ switch( m_eTextDirection )
+ {
+ case LrTb:
+ default:
+ std::stable_sort( aChildren.begin(), aChildren.end(), lr_tb_sort );
+ break;
+ }
+ int nChildren = aChildren.size();
+ for( int i = 0; i < nChildren; i++ )
+ pEle->Children.push_back( aChildren[i] );
+}
+
+
+::basegfx::B2DRange& PDFIProcessor::calcTransformedRectBounds( ::basegfx::B2DRange& outRect,
+ const ::basegfx::B2DRange& inRect,
+ const ::basegfx::B2DHomMatrix& transformation )
+ {
+ outRect.reset();
+
+ if( inRect.isEmpty() )
+ return outRect;
+
+ // transform all four extremal points of the rectangle,
+ // take bounding rect of those.
+
+ // transform left-top point
+ outRect.expand( transformation * inRect.getMinimum() );
+
+ // transform bottom-right point
+ outRect.expand( transformation * inRect.getMaximum() );
+
+ ::basegfx::B2DPoint aPoint;
+
+ // transform top-right point
+ aPoint.setX( inRect.getMaxX() );
+ aPoint.setY( inRect.getMinY() );
+
+ aPoint *= transformation;
+ outRect.expand( aPoint );
+
+ // transform bottom-left point
+ aPoint.setX( inRect.getMinX() );
+ aPoint.setY( inRect.getMaxY() );
+
+ aPoint *= transformation;
+ outRect.expand( aPoint );
+
+ // over and out.
+ return outRect;
+ }
+
+// helper method: get a mirrored string
+rtl::OUString PDFIProcessor::mirrorString( const rtl::OUString& i_rString )
+{
+ if( ! m_xMirrorMapper.is() && ! m_bMirrorMapperTried )
+ {
+ m_bMirrorMapperTried = true;
+ uno::Reference< lang::XMultiComponentFactory > xMSF( m_xContext->getServiceManager(), uno::UNO_SET_THROW );
+ uno::Reference < uno::XInterface > xInterface = xMSF->createInstanceWithContext(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.awt.StringMirror")), m_xContext);
+ m_xMirrorMapper = uno::Reference< util::XStringMapping >( xInterface, uno::UNO_QUERY );
+ #if OSL_DEBUG_LEVEL > 1
+ if( m_xMirrorMapper.is() )
+ fprintf( stderr, "using mirror mapper service\n" );
+ #endif
+ }
+ if( m_xMirrorMapper.is() )
+ {
+ uno::Sequence< rtl::OUString > aSeq( 1 );
+ aSeq.getArray()[0] = i_rString;
+ m_xMirrorMapper->mapStrings( aSeq );
+ return aSeq[0];
+ }
+
+ prepareMirrorMap();
+ sal_Int32 nLen = i_rString.getLength();
+ rtl::OUStringBuffer aRet( nLen );
+ for(int i = nLen - 1; i >= 0; i--)
+ {
+ sal_Unicode cChar = i_rString[ i ];
+ aRet.append( m_aMirrorMap[cChar] );
+ }
+ return aRet.makeStringAndClear();
+}
+
+void PDFIProcessor::prepareMirrorMap()
+{
+ if( m_aMirrorMap.empty() )
+ {
+ #if OSL_DEBUG_LEVEL > 1
+ fprintf( stderr, "falling back to static mirror list\n" );
+ #endif
+
+ m_aMirrorMap.reserve( 0x10000 );
+ for( int i = 0; i < 0x10000; i++ )
+ m_aMirrorMap.push_back( sal_Unicode(i) );
+
+ m_aMirrorMap[ 0x0028 ] = 0x0029; // LEFT PARENTHESIS
+ m_aMirrorMap[ 0x0029 ] = 0x0028; // RIGHT PARENTHESIS
+ m_aMirrorMap[ 0x003C ] = 0x003E; // LESS-THAN SIGN
+ m_aMirrorMap[ 0x003E ] = 0x003C; // GREATER-THAN SIGN
+ m_aMirrorMap[ 0x005B ] = 0x005D; // LEFT SQUARE BRACKET
+ m_aMirrorMap[ 0x005D ] = 0x005B; // RIGHT SQUARE BRACKET
+ m_aMirrorMap[ 0x007B ] = 0x007D; // LEFT CURLY BRACKET
+ m_aMirrorMap[ 0x007D ] = 0x007B; // RIGHT CURLY BRACKET
+ m_aMirrorMap[ 0x00AB ] = 0x00BB; // LEFT-POINTING DOUBLE ANGLE QUOTATION MARK
+ m_aMirrorMap[ 0x00BB ] = 0x00AB; // RIGHT-POINTING DOUBLE ANGLE QUOTATION MARK
+ m_aMirrorMap[ 0x0F3A ] = 0x0F3B; // TIBETAN MARK GUG RTAGS GYON
+ m_aMirrorMap[ 0x0F3B ] = 0x0F3A; // TIBETAN MARK GUG RTAGS GYAS
+ m_aMirrorMap[ 0x0F3C ] = 0x0F3D; // TIBETAN MARK ANG KHANG GYON
+ m_aMirrorMap[ 0x0F3D ] = 0x0F3C; // TIBETAN MARK ANG KHANG GYAS
+ m_aMirrorMap[ 0x169B ] = 0x169C; // OGHAM FEATHER MARK
+ m_aMirrorMap[ 0x169C ] = 0x169B; // OGHAM REVERSED FEATHER MARK
+ m_aMirrorMap[ 0x2039 ] = 0x203A; // SINGLE LEFT-POINTING ANGLE QUOTATION MARK
+ m_aMirrorMap[ 0x203A ] = 0x2039; // SINGLE RIGHT-POINTING ANGLE QUOTATION MARK
+ m_aMirrorMap[ 0x2045 ] = 0x2046; // LEFT SQUARE BRACKET WITH QUILL
+ m_aMirrorMap[ 0x2046 ] = 0x2045; // RIGHT SQUARE BRACKET WITH QUILL
+ m_aMirrorMap[ 0x207D ] = 0x207E; // SUPERSCRIPT LEFT PARENTHESIS
+ m_aMirrorMap[ 0x207E ] = 0x207D; // SUPERSCRIPT RIGHT PARENTHESIS
+ m_aMirrorMap[ 0x208D ] = 0x208E; // SUBSCRIPT LEFT PARENTHESIS
+ m_aMirrorMap[ 0x208E ] = 0x208D; // SUBSCRIPT RIGHT PARENTHESIS
+ m_aMirrorMap[ 0x2208 ] = 0x220B; // ELEMENT OF
+ m_aMirrorMap[ 0x2209 ] = 0x220C; // NOT AN ELEMENT OF
+ m_aMirrorMap[ 0x220A ] = 0x220D; // SMALL ELEMENT OF
+ m_aMirrorMap[ 0x220B ] = 0x2208; // CONTAINS AS MEMBER
+ m_aMirrorMap[ 0x220C ] = 0x2209; // DOES NOT CONTAIN AS MEMBER
+ m_aMirrorMap[ 0x220D ] = 0x220A; // SMALL CONTAINS AS MEMBER
+ m_aMirrorMap[ 0x2215 ] = 0x29F5; // DIVISION SLASH
+ m_aMirrorMap[ 0x223C ] = 0x223D; // TILDE OPERATOR
+ m_aMirrorMap[ 0x223D ] = 0x223C; // REVERSED TILDE
+ m_aMirrorMap[ 0x2243 ] = 0x22CD; // ASYMPTOTICALLY EQUAL TO
+ m_aMirrorMap[ 0x2252 ] = 0x2253; // APPROXIMATELY EQUAL TO OR THE IMAGE OF
+ m_aMirrorMap[ 0x2253 ] = 0x2252; // IMAGE OF OR APPROXIMATELY EQUAL TO
+ m_aMirrorMap[ 0x2254 ] = 0x2255; // COLON EQUALS
+ m_aMirrorMap[ 0x2255 ] = 0x2254; // EQUALS COLON
+ m_aMirrorMap[ 0x2264 ] = 0x2265; // LESS-THAN OR EQUAL TO
+ m_aMirrorMap[ 0x2265 ] = 0x2264; // GREATER-THAN OR EQUAL TO
+ m_aMirrorMap[ 0x2266 ] = 0x2267; // LESS-THAN OVER EQUAL TO
+ m_aMirrorMap[ 0x2267 ] = 0x2266; // GREATER-THAN OVER EQUAL TO
+ m_aMirrorMap[ 0x2268 ] = 0x2269; // [BEST FIT] LESS-THAN BUT NOT EQUAL TO
+ m_aMirrorMap[ 0x2269 ] = 0x2268; // [BEST FIT] GREATER-THAN BUT NOT EQUAL TO
+ m_aMirrorMap[ 0x226A ] = 0x226B; // MUCH LESS-THAN
+ m_aMirrorMap[ 0x226B ] = 0x226A; // MUCH GREATER-THAN
+ m_aMirrorMap[ 0x226E ] = 0x226F; // [BEST FIT] NOT LESS-THAN
+ m_aMirrorMap[ 0x226F ] = 0x226E; // [BEST FIT] NOT GREATER-THAN
+ m_aMirrorMap[ 0x2270 ] = 0x2271; // [BEST FIT] NEITHER LESS-THAN NOR EQUAL TO
+ m_aMirrorMap[ 0x2271 ] = 0x2270; // [BEST FIT] NEITHER GREATER-THAN NOR EQUAL TO
+ m_aMirrorMap[ 0x2272 ] = 0x2273; // [BEST FIT] LESS-THAN OR EQUIVALENT TO
+ m_aMirrorMap[ 0x2273 ] = 0x2272; // [BEST FIT] GREATER-THAN OR EQUIVALENT TO
+ m_aMirrorMap[ 0x2274 ] = 0x2275; // [BEST FIT] NEITHER LESS-THAN NOR EQUIVALENT TO
+ m_aMirrorMap[ 0x2275 ] = 0x2274; // [BEST FIT] NEITHER GREATER-THAN NOR EQUIVALENT TO
+ m_aMirrorMap[ 0x2276 ] = 0x2277; // LESS-THAN OR GREATER-THAN
+ m_aMirrorMap[ 0x2277 ] = 0x2276; // GREATER-THAN OR LESS-THAN
+ m_aMirrorMap[ 0x2278 ] = 0x2279; // [BEST FIT] NEITHER LESS-THAN NOR GREATER-THAN
+ m_aMirrorMap[ 0x2279 ] = 0x2278; // [BEST FIT] NEITHER GREATER-THAN NOR LESS-THAN
+ m_aMirrorMap[ 0x227A ] = 0x227B; // PRECEDES
+ m_aMirrorMap[ 0x227B ] = 0x227A; // SUCCEEDS
+ m_aMirrorMap[ 0x227C ] = 0x227D; // PRECEDES OR EQUAL TO
+ m_aMirrorMap[ 0x227D ] = 0x227C; // SUCCEEDS OR EQUAL TO
+ m_aMirrorMap[ 0x227E ] = 0x227F; // [BEST FIT] PRECEDES OR EQUIVALENT TO
+ m_aMirrorMap[ 0x227F ] = 0x227E; // [BEST FIT] SUCCEEDS OR EQUIVALENT TO
+ m_aMirrorMap[ 0x2280 ] = 0x2281; // [BEST FIT] DOES NOT PRECEDE
+ m_aMirrorMap[ 0x2281 ] = 0x2280; // [BEST FIT] DOES NOT SUCCEED
+ m_aMirrorMap[ 0x2282 ] = 0x2283; // SUBSET OF
+ m_aMirrorMap[ 0x2283 ] = 0x2282; // SUPERSET OF
+ m_aMirrorMap[ 0x2284 ] = 0x2285; // [BEST FIT] NOT A SUBSET OF
+ m_aMirrorMap[ 0x2285 ] = 0x2284; // [BEST FIT] NOT A SUPERSET OF
+ m_aMirrorMap[ 0x2286 ] = 0x2287; // SUBSET OF OR EQUAL TO
+ m_aMirrorMap[ 0x2287 ] = 0x2286; // SUPERSET OF OR EQUAL TO
+ m_aMirrorMap[ 0x2288 ] = 0x2289; // [BEST FIT] NEITHER A SUBSET OF NOR EQUAL TO
+ m_aMirrorMap[ 0x2289 ] = 0x2288; // [BEST FIT] NEITHER A SUPERSET OF NOR EQUAL TO
+ m_aMirrorMap[ 0x228A ] = 0x228B; // [BEST FIT] SUBSET OF WITH NOT EQUAL TO
+ m_aMirrorMap[ 0x228B ] = 0x228A; // [BEST FIT] SUPERSET OF WITH NOT EQUAL TO
+ m_aMirrorMap[ 0x228F ] = 0x2290; // SQUARE IMAGE OF
+ m_aMirrorMap[ 0x2290 ] = 0x228F; // SQUARE ORIGINAL OF
+ m_aMirrorMap[ 0x2291 ] = 0x2292; // SQUARE IMAGE OF OR EQUAL TO
+ m_aMirrorMap[ 0x2292 ] = 0x2291; // SQUARE ORIGINAL OF OR EQUAL TO
+ m_aMirrorMap[ 0x2298 ] = 0x29B8; // CIRCLED DIVISION SLASH
+ m_aMirrorMap[ 0x22A2 ] = 0x22A3; // RIGHT TACK
+ m_aMirrorMap[ 0x22A3 ] = 0x22A2; // LEFT TACK
+ m_aMirrorMap[ 0x22A6 ] = 0x2ADE; // ASSERTION
+ m_aMirrorMap[ 0x22A8 ] = 0x2AE4; // TRUE
+ m_aMirrorMap[ 0x22A9 ] = 0x2AE3; // FORCES
+ m_aMirrorMap[ 0x22AB ] = 0x2AE5; // DOUBLE VERTICAL BAR DOUBLE RIGHT TURNSTILE
+ m_aMirrorMap[ 0x22B0 ] = 0x22B1; // PRECEDES UNDER RELATION
+ m_aMirrorMap[ 0x22B1 ] = 0x22B0; // SUCCEEDS UNDER RELATION
+ m_aMirrorMap[ 0x22B2 ] = 0x22B3; // NORMAL SUBGROUP OF
+ m_aMirrorMap[ 0x22B3 ] = 0x22B2; // CONTAINS AS NORMAL SUBGROUP
+ m_aMirrorMap[ 0x22B4 ] = 0x22B5; // NORMAL SUBGROUP OF OR EQUAL TO
+ m_aMirrorMap[ 0x22B5 ] = 0x22B4; // CONTAINS AS NORMAL SUBGROUP OR EQUAL TO
+ m_aMirrorMap[ 0x22B6 ] = 0x22B7; // ORIGINAL OF
+ m_aMirrorMap[ 0x22B7 ] = 0x22B6; // IMAGE OF
+ m_aMirrorMap[ 0x22C9 ] = 0x22CA; // LEFT NORMAL FACTOR SEMIDIRECT PRODUCT
+ m_aMirrorMap[ 0x22CA ] = 0x22C9; // RIGHT NORMAL FACTOR SEMIDIRECT PRODUCT
+ m_aMirrorMap[ 0x22CB ] = 0x22CC; // LEFT SEMIDIRECT PRODUCT
+ m_aMirrorMap[ 0x22CC ] = 0x22CB; // RIGHT SEMIDIRECT PRODUCT
+ m_aMirrorMap[ 0x22CD ] = 0x2243; // REVERSED TILDE EQUALS
+ m_aMirrorMap[ 0x22D0 ] = 0x22D1; // DOUBLE SUBSET
+ m_aMirrorMap[ 0x22D1 ] = 0x22D0; // DOUBLE SUPERSET
+ m_aMirrorMap[ 0x22D6 ] = 0x22D7; // LESS-THAN WITH DOT
+ m_aMirrorMap[ 0x22D7 ] = 0x22D6; // GREATER-THAN WITH DOT
+ m_aMirrorMap[ 0x22D8 ] = 0x22D9; // VERY MUCH LESS-THAN
+ m_aMirrorMap[ 0x22D9 ] = 0x22D8; // VERY MUCH GREATER-THAN
+ m_aMirrorMap[ 0x22DA ] = 0x22DB; // LESS-THAN EQUAL TO OR GREATER-THAN
+ m_aMirrorMap[ 0x22DB ] = 0x22DA; // GREATER-THAN EQUAL TO OR LESS-THAN
+ m_aMirrorMap[ 0x22DC ] = 0x22DD; // EQUAL TO OR LESS-THAN
+ m_aMirrorMap[ 0x22DD ] = 0x22DC; // EQUAL TO OR GREATER-THAN
+ m_aMirrorMap[ 0x22DE ] = 0x22DF; // EQUAL TO OR PRECEDES
+ m_aMirrorMap[ 0x22DF ] = 0x22DE; // EQUAL TO OR SUCCEEDS
+ m_aMirrorMap[ 0x22E0 ] = 0x22E1; // [BEST FIT] DOES NOT PRECEDE OR EQUAL
+ m_aMirrorMap[ 0x22E1 ] = 0x22E0; // [BEST FIT] DOES NOT SUCCEED OR EQUAL
+ m_aMirrorMap[ 0x22E2 ] = 0x22E3; // [BEST FIT] NOT SQUARE IMAGE OF OR EQUAL TO
+ m_aMirrorMap[ 0x22E3 ] = 0x22E2; // [BEST FIT] NOT SQUARE ORIGINAL OF OR EQUAL TO
+ m_aMirrorMap[ 0x22E4 ] = 0x22E5; // [BEST FIT] SQUARE IMAGE OF OR NOT EQUAL TO
+ m_aMirrorMap[ 0x22E5 ] = 0x22E4; // [BEST FIT] SQUARE ORIGINAL OF OR NOT EQUAL TO
+ m_aMirrorMap[ 0x22E6 ] = 0x22E7; // [BEST FIT] LESS-THAN BUT NOT EQUIVALENT TO
+ m_aMirrorMap[ 0x22E7 ] = 0x22E6; // [BEST FIT] GREATER-THAN BUT NOT EQUIVALENT TO
+ m_aMirrorMap[ 0x22E8 ] = 0x22E9; // [BEST FIT] PRECEDES BUT NOT EQUIVALENT TO
+ m_aMirrorMap[ 0x22E9 ] = 0x22E8; // [BEST FIT] SUCCEEDS BUT NOT EQUIVALENT TO
+ m_aMirrorMap[ 0x22EA ] = 0x22EB; // [BEST FIT] NOT NORMAL SUBGROUP OF
+ m_aMirrorMap[ 0x22EB ] = 0x22EA; // [BEST FIT] DOES NOT CONTAIN AS NORMAL SUBGROUP
+ m_aMirrorMap[ 0x22EC ] = 0x22ED; // [BEST FIT] NOT NORMAL SUBGROUP OF OR EQUAL TO
+ m_aMirrorMap[ 0x22ED ] = 0x22EC; // [BEST FIT] DOES NOT CONTAIN AS NORMAL SUBGROUP OR EQUAL
+ m_aMirrorMap[ 0x22F0 ] = 0x22F1; // UP RIGHT DIAGONAL ELLIPSIS
+ m_aMirrorMap[ 0x22F1 ] = 0x22F0; // DOWN RIGHT DIAGONAL ELLIPSIS
+ m_aMirrorMap[ 0x22F2 ] = 0x22FA; // ELEMENT OF WITH LONG HORIZONTAL STROKE
+ m_aMirrorMap[ 0x22F3 ] = 0x22FB; // ELEMENT OF WITH VERTICAL BAR AT END OF HORIZONTAL STROKE
+ m_aMirrorMap[ 0x22F4 ] = 0x22FC; // SMALL ELEMENT OF WITH VERTICAL BAR AT END OF HORIZONTAL STROKE
+ m_aMirrorMap[ 0x22F6 ] = 0x22FD; // ELEMENT OF WITH OVERBAR
+ m_aMirrorMap[ 0x22F7 ] = 0x22FE; // SMALL ELEMENT OF WITH OVERBAR
+ m_aMirrorMap[ 0x22FA ] = 0x22F2; // CONTAINS WITH LONG HORIZONTAL STROKE
+ m_aMirrorMap[ 0x22FB ] = 0x22F3; // CONTAINS WITH VERTICAL BAR AT END OF HORIZONTAL STROKE
+ m_aMirrorMap[ 0x22FC ] = 0x22F4; // SMALL CONTAINS WITH VERTICAL BAR AT END OF HORIZONTAL STROKE
+ m_aMirrorMap[ 0x22FD ] = 0x22F6; // CONTAINS WITH OVERBAR
+ m_aMirrorMap[ 0x22FE ] = 0x22F7; // SMALL CONTAINS WITH OVERBAR
+ m_aMirrorMap[ 0x2308 ] = 0x2309; // LEFT CEILING
+ m_aMirrorMap[ 0x2309 ] = 0x2308; // RIGHT CEILING
+ m_aMirrorMap[ 0x230A ] = 0x230B; // LEFT FLOOR
+ m_aMirrorMap[ 0x230B ] = 0x230A; // RIGHT FLOOR
+ m_aMirrorMap[ 0x2329 ] = 0x232A; // LEFT-POINTING ANGLE BRACKET
+ m_aMirrorMap[ 0x232A ] = 0x2329; // RIGHT-POINTING ANGLE BRACKET
+ m_aMirrorMap[ 0x2768 ] = 0x2769; // MEDIUM LEFT PARENTHESIS ORNAMENT
+ m_aMirrorMap[ 0x2769 ] = 0x2768; // MEDIUM RIGHT PARENTHESIS ORNAMENT
+ m_aMirrorMap[ 0x276A ] = 0x276B; // MEDIUM FLATTENED LEFT PARENTHESIS ORNAMENT
+ m_aMirrorMap[ 0x276B ] = 0x276A; // MEDIUM FLATTENED RIGHT PARENTHESIS ORNAMENT
+ m_aMirrorMap[ 0x276C ] = 0x276D; // MEDIUM LEFT-POINTING ANGLE BRACKET ORNAMENT
+ m_aMirrorMap[ 0x276D ] = 0x276C; // MEDIUM RIGHT-POINTING ANGLE BRACKET ORNAMENT
+ m_aMirrorMap[ 0x276E ] = 0x276F; // HEAVY LEFT-POINTING ANGLE QUOTATION MARK ORNAMENT
+ m_aMirrorMap[ 0x276F ] = 0x276E; // HEAVY RIGHT-POINTING ANGLE QUOTATION MARK ORNAMENT
+ m_aMirrorMap[ 0x2770 ] = 0x2771; // HEAVY LEFT-POINTING ANGLE BRACKET ORNAMENT
+ m_aMirrorMap[ 0x2771 ] = 0x2770; // HEAVY RIGHT-POINTING ANGLE BRACKET ORNAMENT
+ m_aMirrorMap[ 0x2772 ] = 0x2773; // LIGHT LEFT TORTOISE SHELL BRACKET
+ m_aMirrorMap[ 0x2773 ] = 0x2772; // LIGHT RIGHT TORTOISE SHELL BRACKET
+ m_aMirrorMap[ 0x2774 ] = 0x2775; // MEDIUM LEFT CURLY BRACKET ORNAMENT
+ m_aMirrorMap[ 0x2775 ] = 0x2774; // MEDIUM RIGHT CURLY BRACKET ORNAMENT
+ m_aMirrorMap[ 0x27C3 ] = 0x27C4; // OPEN SUBSET
+ m_aMirrorMap[ 0x27C4 ] = 0x27C3; // OPEN SUPERSET
+ m_aMirrorMap[ 0x27C5 ] = 0x27C6; // LEFT S-SHAPED BAG DELIMITER
+ m_aMirrorMap[ 0x27C6 ] = 0x27C5; // RIGHT S-SHAPED BAG DELIMITER
+ m_aMirrorMap[ 0x27C8 ] = 0x27C9; // REVERSE SOLIDUS PRECEDING SUBSET
+ m_aMirrorMap[ 0x27C9 ] = 0x27C8; // SUPERSET PRECEDING SOLIDUS
+ m_aMirrorMap[ 0x27D5 ] = 0x27D6; // LEFT OUTER JOIN
+ m_aMirrorMap[ 0x27D6 ] = 0x27D5; // RIGHT OUTER JOIN
+ m_aMirrorMap[ 0x27DD ] = 0x27DE; // LONG RIGHT TACK
+ m_aMirrorMap[ 0x27DE ] = 0x27DD; // LONG LEFT TACK
+ m_aMirrorMap[ 0x27E2 ] = 0x27E3; // WHITE CONCAVE-SIDED DIAMOND WITH LEFTWARDS TICK
+ m_aMirrorMap[ 0x27E3 ] = 0x27E2; // WHITE CONCAVE-SIDED DIAMOND WITH RIGHTWARDS TICK
+ m_aMirrorMap[ 0x27E4 ] = 0x27E5; // WHITE SQUARE WITH LEFTWARDS TICK
+ m_aMirrorMap[ 0x27E5 ] = 0x27E4; // WHITE SQUARE WITH RIGHTWARDS TICK
+ m_aMirrorMap[ 0x27E6 ] = 0x27E7; // MATHEMATICAL LEFT WHITE SQUARE BRACKET
+ m_aMirrorMap[ 0x27E7 ] = 0x27E6; // MATHEMATICAL RIGHT WHITE SQUARE BRACKET
+ m_aMirrorMap[ 0x27E8 ] = 0x27E9; // MATHEMATICAL LEFT ANGLE BRACKET
+ m_aMirrorMap[ 0x27E9 ] = 0x27E8; // MATHEMATICAL RIGHT ANGLE BRACKET
+ m_aMirrorMap[ 0x27EA ] = 0x27EB; // MATHEMATICAL LEFT DOUBLE ANGLE BRACKET
+ m_aMirrorMap[ 0x27EB ] = 0x27EA; // MATHEMATICAL RIGHT DOUBLE ANGLE BRACKET
+ m_aMirrorMap[ 0x27EC ] = 0x27ED; // MATHEMATICAL LEFT WHITE TORTOISE SHELL BRACKET
+ m_aMirrorMap[ 0x27ED ] = 0x27EC; // MATHEMATICAL RIGHT WHITE TORTOISE SHELL BRACKET
+ m_aMirrorMap[ 0x27EE ] = 0x27EF; // MATHEMATICAL LEFT FLATTENED PARENTHESIS
+ m_aMirrorMap[ 0x27EF ] = 0x27EE; // MATHEMATICAL RIGHT FLATTENED PARENTHESIS
+ m_aMirrorMap[ 0x2983 ] = 0x2984; // LEFT WHITE CURLY BRACKET
+ m_aMirrorMap[ 0x2984 ] = 0x2983; // RIGHT WHITE CURLY BRACKET
+ m_aMirrorMap[ 0x2985 ] = 0x2986; // LEFT WHITE PARENTHESIS
+ m_aMirrorMap[ 0x2986 ] = 0x2985; // RIGHT WHITE PARENTHESIS
+ m_aMirrorMap[ 0x2987 ] = 0x2988; // Z NOTATION LEFT IMAGE BRACKET
+ m_aMirrorMap[ 0x2988 ] = 0x2987; // Z NOTATION RIGHT IMAGE BRACKET
+ m_aMirrorMap[ 0x2989 ] = 0x298A; // Z NOTATION LEFT BINDING BRACKET
+ m_aMirrorMap[ 0x298A ] = 0x2989; // Z NOTATION RIGHT BINDING BRACKET
+ m_aMirrorMap[ 0x298B ] = 0x298C; // LEFT SQUARE BRACKET WITH UNDERBAR
+ m_aMirrorMap[ 0x298C ] = 0x298B; // RIGHT SQUARE BRACKET WITH UNDERBAR
+ m_aMirrorMap[ 0x298D ] = 0x2990; // LEFT SQUARE BRACKET WITH TICK IN TOP CORNER
+ m_aMirrorMap[ 0x298E ] = 0x298F; // RIGHT SQUARE BRACKET WITH TICK IN BOTTOM CORNER
+ m_aMirrorMap[ 0x298F ] = 0x298E; // LEFT SQUARE BRACKET WITH TICK IN BOTTOM CORNER
+ m_aMirrorMap[ 0x2990 ] = 0x298D; // RIGHT SQUARE BRACKET WITH TICK IN TOP CORNER
+ m_aMirrorMap[ 0x2991 ] = 0x2992; // LEFT ANGLE BRACKET WITH DOT
+ m_aMirrorMap[ 0x2992 ] = 0x2991; // RIGHT ANGLE BRACKET WITH DOT
+ m_aMirrorMap[ 0x2993 ] = 0x2994; // LEFT ARC LESS-THAN BRACKET
+ m_aMirrorMap[ 0x2994 ] = 0x2993; // RIGHT ARC GREATER-THAN BRACKET
+ m_aMirrorMap[ 0x2995 ] = 0x2996; // DOUBLE LEFT ARC GREATER-THAN BRACKET
+ m_aMirrorMap[ 0x2996 ] = 0x2995; // DOUBLE RIGHT ARC LESS-THAN BRACKET
+ m_aMirrorMap[ 0x2997 ] = 0x2998; // LEFT BLACK TORTOISE SHELL BRACKET
+ m_aMirrorMap[ 0x2998 ] = 0x2997; // RIGHT BLACK TORTOISE SHELL BRACKET
+ m_aMirrorMap[ 0x29B8 ] = 0x2298; // CIRCLED REVERSE SOLIDUS
+ m_aMirrorMap[ 0x29C0 ] = 0x29C1; // CIRCLED LESS-THAN
+ m_aMirrorMap[ 0x29C1 ] = 0x29C0; // CIRCLED GREATER-THAN
+ m_aMirrorMap[ 0x29C4 ] = 0x29C5; // SQUARED RISING DIAGONAL SLASH
+ m_aMirrorMap[ 0x29C5 ] = 0x29C4; // SQUARED FALLING DIAGONAL SLASH
+ m_aMirrorMap[ 0x29CF ] = 0x29D0; // LEFT TRIANGLE BESIDE VERTICAL BAR
+ m_aMirrorMap[ 0x29D0 ] = 0x29CF; // VERTICAL BAR BESIDE RIGHT TRIANGLE
+ m_aMirrorMap[ 0x29D1 ] = 0x29D2; // BOWTIE WITH LEFT HALF BLACK
+ m_aMirrorMap[ 0x29D2 ] = 0x29D1; // BOWTIE WITH RIGHT HALF BLACK
+ m_aMirrorMap[ 0x29D4 ] = 0x29D5; // TIMES WITH LEFT HALF BLACK
+ m_aMirrorMap[ 0x29D5 ] = 0x29D4; // TIMES WITH RIGHT HALF BLACK
+ m_aMirrorMap[ 0x29D8 ] = 0x29D9; // LEFT WIGGLY FENCE
+ m_aMirrorMap[ 0x29D9 ] = 0x29D8; // RIGHT WIGGLY FENCE
+ m_aMirrorMap[ 0x29DA ] = 0x29DB; // LEFT DOUBLE WIGGLY FENCE
+ m_aMirrorMap[ 0x29DB ] = 0x29DA; // RIGHT DOUBLE WIGGLY FENCE
+ m_aMirrorMap[ 0x29F5 ] = 0x2215; // REVERSE SOLIDUS OPERATOR
+ m_aMirrorMap[ 0x29F8 ] = 0x29F9; // BIG SOLIDUS
+ m_aMirrorMap[ 0x29F9 ] = 0x29F8; // BIG REVERSE SOLIDUS
+ m_aMirrorMap[ 0x29FC ] = 0x29FD; // LEFT-POINTING CURVED ANGLE BRACKET
+ m_aMirrorMap[ 0x29FD ] = 0x29FC; // RIGHT-POINTING CURVED ANGLE BRACKET
+ m_aMirrorMap[ 0x2A2B ] = 0x2A2C; // MINUS SIGN WITH FALLING DOTS
+ m_aMirrorMap[ 0x2A2C ] = 0x2A2B; // MINUS SIGN WITH RISING DOTS
+ m_aMirrorMap[ 0x2A2D ] = 0x2A2E; // PLUS SIGN IN LEFT HALF CIRCLE
+ m_aMirrorMap[ 0x2A2E ] = 0x2A2D; // PLUS SIGN IN RIGHT HALF CIRCLE
+ m_aMirrorMap[ 0x2A34 ] = 0x2A35; // MULTIPLICATION SIGN IN LEFT HALF CIRCLE
+ m_aMirrorMap[ 0x2A35 ] = 0x2A34; // MULTIPLICATION SIGN IN RIGHT HALF CIRCLE
+ m_aMirrorMap[ 0x2A3C ] = 0x2A3D; // INTERIOR PRODUCT
+ m_aMirrorMap[ 0x2A3D ] = 0x2A3C; // RIGHTHAND INTERIOR PRODUCT
+ m_aMirrorMap[ 0x2A64 ] = 0x2A65; // Z NOTATION DOMAIN ANTIRESTRICTION
+ m_aMirrorMap[ 0x2A65 ] = 0x2A64; // Z NOTATION RANGE ANTIRESTRICTION
+ m_aMirrorMap[ 0x2A79 ] = 0x2A7A; // LESS-THAN WITH CIRCLE INSIDE
+ m_aMirrorMap[ 0x2A7A ] = 0x2A79; // GREATER-THAN WITH CIRCLE INSIDE
+ m_aMirrorMap[ 0x2A7D ] = 0x2A7E; // LESS-THAN OR SLANTED EQUAL TO
+ m_aMirrorMap[ 0x2A7E ] = 0x2A7D; // GREATER-THAN OR SLANTED EQUAL TO
+ m_aMirrorMap[ 0x2A7F ] = 0x2A80; // LESS-THAN OR SLANTED EQUAL TO WITH DOT INSIDE
+ m_aMirrorMap[ 0x2A80 ] = 0x2A7F; // GREATER-THAN OR SLANTED EQUAL TO WITH DOT INSIDE
+ m_aMirrorMap[ 0x2A81 ] = 0x2A82; // LESS-THAN OR SLANTED EQUAL TO WITH DOT ABOVE
+ m_aMirrorMap[ 0x2A82 ] = 0x2A81; // GREATER-THAN OR SLANTED EQUAL TO WITH DOT ABOVE
+ m_aMirrorMap[ 0x2A83 ] = 0x2A84; // LESS-THAN OR SLANTED EQUAL TO WITH DOT ABOVE RIGHT
+ m_aMirrorMap[ 0x2A84 ] = 0x2A83; // GREATER-THAN OR SLANTED EQUAL TO WITH DOT ABOVE LEFT
+ m_aMirrorMap[ 0x2A8B ] = 0x2A8C; // LESS-THAN ABOVE DOUBLE-LINE EQUAL ABOVE GREATER-THAN
+ m_aMirrorMap[ 0x2A8C ] = 0x2A8B; // GREATER-THAN ABOVE DOUBLE-LINE EQUAL ABOVE LESS-THAN
+ m_aMirrorMap[ 0x2A91 ] = 0x2A92; // LESS-THAN ABOVE GREATER-THAN ABOVE DOUBLE-LINE EQUAL
+ m_aMirrorMap[ 0x2A92 ] = 0x2A91; // GREATER-THAN ABOVE LESS-THAN ABOVE DOUBLE-LINE EQUAL
+ m_aMirrorMap[ 0x2A93 ] = 0x2A94; // LESS-THAN ABOVE SLANTED EQUAL ABOVE GREATER-THAN ABOVE SLANTED EQUAL
+ m_aMirrorMap[ 0x2A94 ] = 0x2A93; // GREATER-THAN ABOVE SLANTED EQUAL ABOVE LESS-THAN ABOVE SLANTED EQUAL
+ m_aMirrorMap[ 0x2A95 ] = 0x2A96; // SLANTED EQUAL TO OR LESS-THAN
+ m_aMirrorMap[ 0x2A96 ] = 0x2A95; // SLANTED EQUAL TO OR GREATER-THAN
+ m_aMirrorMap[ 0x2A97 ] = 0x2A98; // SLANTED EQUAL TO OR LESS-THAN WITH DOT INSIDE
+ m_aMirrorMap[ 0x2A98 ] = 0x2A97; // SLANTED EQUAL TO OR GREATER-THAN WITH DOT INSIDE
+ m_aMirrorMap[ 0x2A99 ] = 0x2A9A; // DOUBLE-LINE EQUAL TO OR LESS-THAN
+ m_aMirrorMap[ 0x2A9A ] = 0x2A99; // DOUBLE-LINE EQUAL TO OR GREATER-THAN
+ m_aMirrorMap[ 0x2A9B ] = 0x2A9C; // DOUBLE-LINE SLANTED EQUAL TO OR LESS-THAN
+ m_aMirrorMap[ 0x2A9C ] = 0x2A9B; // DOUBLE-LINE SLANTED EQUAL TO OR GREATER-THAN
+ m_aMirrorMap[ 0x2AA1 ] = 0x2AA2; // DOUBLE NESTED LESS-THAN
+ m_aMirrorMap[ 0x2AA2 ] = 0x2AA1; // DOUBLE NESTED GREATER-THAN
+ m_aMirrorMap[ 0x2AA6 ] = 0x2AA7; // LESS-THAN CLOSED BY CURVE
+ m_aMirrorMap[ 0x2AA7 ] = 0x2AA6; // GREATER-THAN CLOSED BY CURVE
+ m_aMirrorMap[ 0x2AA8 ] = 0x2AA9; // LESS-THAN CLOSED BY CURVE ABOVE SLANTED EQUAL
+ m_aMirrorMap[ 0x2AA9 ] = 0x2AA8; // GREATER-THAN CLOSED BY CURVE ABOVE SLANTED EQUAL
+ m_aMirrorMap[ 0x2AAA ] = 0x2AAB; // SMALLER THAN
+ m_aMirrorMap[ 0x2AAB ] = 0x2AAA; // LARGER THAN
+ m_aMirrorMap[ 0x2AAC ] = 0x2AAD; // SMALLER THAN OR EQUAL TO
+ m_aMirrorMap[ 0x2AAD ] = 0x2AAC; // LARGER THAN OR EQUAL TO
+ m_aMirrorMap[ 0x2AAF ] = 0x2AB0; // PRECEDES ABOVE SINGLE-LINE EQUALS SIGN
+ m_aMirrorMap[ 0x2AB0 ] = 0x2AAF; // SUCCEEDS ABOVE SINGLE-LINE EQUALS SIGN
+ m_aMirrorMap[ 0x2AB3 ] = 0x2AB4; // PRECEDES ABOVE EQUALS SIGN
+ m_aMirrorMap[ 0x2AB4 ] = 0x2AB3; // SUCCEEDS ABOVE EQUALS SIGN
+ m_aMirrorMap[ 0x2ABB ] = 0x2ABC; // DOUBLE PRECEDES
+ m_aMirrorMap[ 0x2ABC ] = 0x2ABB; // DOUBLE SUCCEEDS
+ m_aMirrorMap[ 0x2ABD ] = 0x2ABE; // SUBSET WITH DOT
+ m_aMirrorMap[ 0x2ABE ] = 0x2ABD; // SUPERSET WITH DOT
+ m_aMirrorMap[ 0x2ABF ] = 0x2AC0; // SUBSET WITH PLUS SIGN BELOW
+ m_aMirrorMap[ 0x2AC0 ] = 0x2ABF; // SUPERSET WITH PLUS SIGN BELOW
+ m_aMirrorMap[ 0x2AC1 ] = 0x2AC2; // SUBSET WITH MULTIPLICATION SIGN BELOW
+ m_aMirrorMap[ 0x2AC2 ] = 0x2AC1; // SUPERSET WITH MULTIPLICATION SIGN BELOW
+ m_aMirrorMap[ 0x2AC3 ] = 0x2AC4; // SUBSET OF OR EQUAL TO WITH DOT ABOVE
+ m_aMirrorMap[ 0x2AC4 ] = 0x2AC3; // SUPERSET OF OR EQUAL TO WITH DOT ABOVE
+ m_aMirrorMap[ 0x2AC5 ] = 0x2AC6; // SUBSET OF ABOVE EQUALS SIGN
+ m_aMirrorMap[ 0x2AC6 ] = 0x2AC5; // SUPERSET OF ABOVE EQUALS SIGN
+ m_aMirrorMap[ 0x2ACD ] = 0x2ACE; // SQUARE LEFT OPEN BOX OPERATOR
+ m_aMirrorMap[ 0x2ACE ] = 0x2ACD; // SQUARE RIGHT OPEN BOX OPERATOR
+ m_aMirrorMap[ 0x2ACF ] = 0x2AD0; // CLOSED SUBSET
+ m_aMirrorMap[ 0x2AD0 ] = 0x2ACF; // CLOSED SUPERSET
+ m_aMirrorMap[ 0x2AD1 ] = 0x2AD2; // CLOSED SUBSET OR EQUAL TO
+ m_aMirrorMap[ 0x2AD2 ] = 0x2AD1; // CLOSED SUPERSET OR EQUAL TO
+ m_aMirrorMap[ 0x2AD3 ] = 0x2AD4; // SUBSET ABOVE SUPERSET
+ m_aMirrorMap[ 0x2AD4 ] = 0x2AD3; // SUPERSET ABOVE SUBSET
+ m_aMirrorMap[ 0x2AD5 ] = 0x2AD6; // SUBSET ABOVE SUBSET
+ m_aMirrorMap[ 0x2AD6 ] = 0x2AD5; // SUPERSET ABOVE SUPERSET
+ m_aMirrorMap[ 0x2ADE ] = 0x22A6; // SHORT LEFT TACK
+ m_aMirrorMap[ 0x2AE3 ] = 0x22A9; // DOUBLE VERTICAL BAR LEFT TURNSTILE
+ m_aMirrorMap[ 0x2AE4 ] = 0x22A8; // VERTICAL BAR DOUBLE LEFT TURNSTILE
+ m_aMirrorMap[ 0x2AE5 ] = 0x22AB; // DOUBLE VERTICAL BAR DOUBLE LEFT TURNSTILE
+ m_aMirrorMap[ 0x2AEC ] = 0x2AED; // DOUBLE STROKE NOT SIGN
+ m_aMirrorMap[ 0x2AED ] = 0x2AEC; // REVERSED DOUBLE STROKE NOT SIGN
+ m_aMirrorMap[ 0x2AF7 ] = 0x2AF8; // TRIPLE NESTED LESS-THAN
+ m_aMirrorMap[ 0x2AF8 ] = 0x2AF7; // TRIPLE NESTED GREATER-THAN
+ m_aMirrorMap[ 0x2AF9 ] = 0x2AFA; // DOUBLE-LINE SLANTED LESS-THAN OR EQUAL TO
+ m_aMirrorMap[ 0x2AFA ] = 0x2AF9; // DOUBLE-LINE SLANTED GREATER-THAN OR EQUAL TO
+ m_aMirrorMap[ 0x2E02 ] = 0x2E03; // LEFT SUBSTITUTION BRACKET
+ m_aMirrorMap[ 0x2E03 ] = 0x2E02; // RIGHT SUBSTITUTION BRACKET
+ m_aMirrorMap[ 0x2E04 ] = 0x2E05; // LEFT DOTTED SUBSTITUTION BRACKET
+ m_aMirrorMap[ 0x2E05 ] = 0x2E04; // RIGHT DOTTED SUBSTITUTION BRACKET
+ m_aMirrorMap[ 0x2E09 ] = 0x2E0A; // LEFT TRANSPOSITION BRACKET
+ m_aMirrorMap[ 0x2E0A ] = 0x2E09; // RIGHT TRANSPOSITION BRACKET
+ m_aMirrorMap[ 0x2E0C ] = 0x2E0D; // LEFT RAISED OMISSION BRACKET
+ m_aMirrorMap[ 0x2E0D ] = 0x2E0C; // RIGHT RAISED OMISSION BRACKET
+ m_aMirrorMap[ 0x2E1C ] = 0x2E1D; // LEFT LOW PARAPHRASE BRACKET
+ m_aMirrorMap[ 0x2E1D ] = 0x2E1C; // RIGHT LOW PARAPHRASE BRACKET
+ m_aMirrorMap[ 0x2E20 ] = 0x2E21; // LEFT VERTICAL BAR WITH QUILL
+ m_aMirrorMap[ 0x2E21 ] = 0x2E20; // RIGHT VERTICAL BAR WITH QUILL
+ m_aMirrorMap[ 0x2E22 ] = 0x2E23; // TOP LEFT HALF BRACKET
+ m_aMirrorMap[ 0x2E23 ] = 0x2E22; // TOP RIGHT HALF BRACKET
+ m_aMirrorMap[ 0x2E24 ] = 0x2E25; // BOTTOM LEFT HALF BRACKET
+ m_aMirrorMap[ 0x2E25 ] = 0x2E24; // BOTTOM RIGHT HALF BRACKET
+ m_aMirrorMap[ 0x2E26 ] = 0x2E27; // LEFT SIDEWAYS U BRACKET
+ m_aMirrorMap[ 0x2E27 ] = 0x2E26; // RIGHT SIDEWAYS U BRACKET
+ m_aMirrorMap[ 0x2E28 ] = 0x2E29; // LEFT DOUBLE PARENTHESIS
+ m_aMirrorMap[ 0x2E29 ] = 0x2E28; // RIGHT DOUBLE PARENTHESIS
+ m_aMirrorMap[ 0x3008 ] = 0x3009; // LEFT ANGLE BRACKET
+ m_aMirrorMap[ 0x3009 ] = 0x3008; // RIGHT ANGLE BRACKET
+ m_aMirrorMap[ 0x300A ] = 0x300B; // LEFT DOUBLE ANGLE BRACKET
+ m_aMirrorMap[ 0x300B ] = 0x300A; // RIGHT DOUBLE ANGLE BRACKET
+ m_aMirrorMap[ 0x300C ] = 0x300D; // [BEST FIT] LEFT CORNER BRACKET
+ m_aMirrorMap[ 0x300D ] = 0x300C; // [BEST FIT] RIGHT CORNER BRACKET
+ m_aMirrorMap[ 0x300E ] = 0x300F; // [BEST FIT] LEFT WHITE CORNER BRACKET
+ m_aMirrorMap[ 0x300F ] = 0x300E; // [BEST FIT] RIGHT WHITE CORNER BRACKET
+ m_aMirrorMap[ 0x3010 ] = 0x3011; // LEFT BLACK LENTICULAR BRACKET
+ m_aMirrorMap[ 0x3011 ] = 0x3010; // RIGHT BLACK LENTICULAR BRACKET
+ m_aMirrorMap[ 0x3014 ] = 0x3015; // LEFT TORTOISE SHELL BRACKET
+ m_aMirrorMap[ 0x3015 ] = 0x3014; // RIGHT TORTOISE SHELL BRACKET
+ m_aMirrorMap[ 0x3016 ] = 0x3017; // LEFT WHITE LENTICULAR BRACKET
+ m_aMirrorMap[ 0x3017 ] = 0x3016; // RIGHT WHITE LENTICULAR BRACKET
+ m_aMirrorMap[ 0x3018 ] = 0x3019; // LEFT WHITE TORTOISE SHELL BRACKET
+ m_aMirrorMap[ 0x3019 ] = 0x3018; // RIGHT WHITE TORTOISE SHELL BRACKET
+ m_aMirrorMap[ 0x301A ] = 0x301B; // LEFT WHITE SQUARE BRACKET
+ m_aMirrorMap[ 0x301B ] = 0x301A; // RIGHT WHITE SQUARE BRACKET
+ m_aMirrorMap[ 0xFE59 ] = 0xFE5A; // SMALL LEFT PARENTHESIS
+ m_aMirrorMap[ 0xFE5A ] = 0xFE59; // SMALL RIGHT PARENTHESIS
+ m_aMirrorMap[ 0xFE5B ] = 0xFE5C; // SMALL LEFT CURLY BRACKET
+ m_aMirrorMap[ 0xFE5C ] = 0xFE5B; // SMALL RIGHT CURLY BRACKET
+ m_aMirrorMap[ 0xFE5D ] = 0xFE5E; // SMALL LEFT TORTOISE SHELL BRACKET
+ m_aMirrorMap[ 0xFE5E ] = 0xFE5D; // SMALL RIGHT TORTOISE SHELL BRACKET
+ m_aMirrorMap[ 0xFE64 ] = 0xFE65; // SMALL LESS-THAN SIGN
+ m_aMirrorMap[ 0xFE65 ] = 0xFE64; // SMALL GREATER-THAN SIGN
+ m_aMirrorMap[ 0xFF08 ] = 0xFF09; // FULLWIDTH LEFT PARENTHESIS
+ m_aMirrorMap[ 0xFF09 ] = 0xFF08; // FULLWIDTH RIGHT PARENTHESIS
+ m_aMirrorMap[ 0xFF1C ] = 0xFF1E; // FULLWIDTH LESS-THAN SIGN
+ m_aMirrorMap[ 0xFF1E ] = 0xFF1C; // FULLWIDTH GREATER-THAN SIGN
+ m_aMirrorMap[ 0xFF3B ] = 0xFF3D; // FULLWIDTH LEFT SQUARE BRACKET
+ m_aMirrorMap[ 0xFF3D ] = 0xFF3B; // FULLWIDTH RIGHT SQUARE BRACKET
+ m_aMirrorMap[ 0xFF5B ] = 0xFF5D; // FULLWIDTH LEFT CURLY BRACKET
+ m_aMirrorMap[ 0xFF5D ] = 0xFF5B; // FULLWIDTH RIGHT CURLY BRACKET
+ m_aMirrorMap[ 0xFF5F ] = 0xFF60; // FULLWIDTH LEFT WHITE PARENTHESIS
+ m_aMirrorMap[ 0xFF60 ] = 0xFF5F; // FULLWIDTH RIGHT WHITE PARENTHESIS
+ m_aMirrorMap[ 0xFF62 ] = 0xFF63; // [BEST FIT] HALFWIDTH LEFT CORNER BRACKET
+ m_aMirrorMap[ 0xFF63 ] = 0xFF62; // [BEST FIT] HALFWIDTH RIGHT CORNER BRACKET
+ }
+}
+
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sdext/source/pdfimport/tree/pdfiprocessor.hxx b/sdext/source/pdfimport/tree/pdfiprocessor.hxx
new file mode 100644
index 000000000000..4b66f4c31d54
--- /dev/null
+++ b/sdext/source/pdfimport/tree/pdfiprocessor.hxx
@@ -0,0 +1,309 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+#ifndef INCLUDED_PDFI_PROCESSOR_HXX
+#define INCLUDED_PDFI_PROCESSOR_HXX
+
+#include "pdfihelper.hxx"
+
+#include <com/sun/star/util/XStringMapping.hpp>
+#include <com/sun/star/xml/sax/XDocumentHandler.hpp>
+#include <com/sun/star/task/XStatusIndicator.hpp>
+#include <com/sun/star/rendering/XVolatileBitmap.hpp>
+#include <com/sun/star/geometry/RealSize2D.hpp>
+#include <com/sun/star/geometry/RealPoint2D.hpp>
+#include <com/sun/star/geometry/RealRectangle2D.hpp>
+#include <com/sun/star/geometry/Matrix2D.hpp>
+
+#include <basegfx/polygon/b2dpolypolygon.hxx>
+#include <basegfx/polygon/b2dpolygon.hxx>
+#include <basegfx/matrix/b2dhommatrix.hxx>
+#include <basegfx/range/b2drange.hxx>
+
+#include <rtl/ustring.hxx>
+#include <rtl/ustrbuf.hxx>
+
+#include <boost/shared_ptr.hpp>
+#include <list>
+#include <boost/unordered_map.hpp>
+
+#include "imagecontainer.hxx"
+#include "contentsink.hxx"
+#include "treevisitorfactory.hxx"
+#include "genericelements.hxx"
+
+namespace pdfi
+{
+
+ class PDFIProcessor;
+ struct Element;
+ struct DocumentElement;
+ struct PageElement;
+ class ElementFactory;
+ class XmlEmitter;
+ class CharGlyph;
+
+ /** Main entry from the parser
+
+ Creates the internal DOM tree from the render calls
+ */
+ class PDFIProcessor : public ContentSink
+ {
+ public:
+ com::sun::star::uno::Reference<
+ com::sun::star::uno::XComponentContext > m_xContext;
+ double fYPrevTextPosition;
+ double fPrevTextHeight;
+ double fXPrevTextPosition;
+ double fPrevTextWidth;
+ enum DocumentTextDirecion { LrTb, RlTb, TbLr };
+
+ explicit PDFIProcessor( const com::sun::star::uno::Reference< com::sun::star::task::XStatusIndicator >& xStat,
+ com::sun::star::uno::Reference< com::sun::star::uno::XComponentContext > xContext) ;
+
+ /// TEMP - enable writer-like text:p on doc level
+ void enableToplevelText();
+
+ void emit( XmlEmitter& rEmitter,
+ const TreeVisitorFactory& rVisitorFactory );
+
+ sal_Int32 getGCId( const GraphicsContext& rGC );
+ const GraphicsContext& getGraphicsContext( sal_Int32 nGCId ) const;
+ GraphicsContext& getCurrentContext() { return m_aGCStack.back(); }
+ const GraphicsContext& getCurrentContext() const { return m_aGCStack.back(); }
+
+ ImageContainer& getImages() { return m_aImages; }
+ boost::shared_ptr<ElementFactory> getElementFactory() const { return m_pElFactory; }
+
+ const com::sun::star::uno::Reference< com::sun::star::task::XStatusIndicator >& getStatusIndicator() const
+ { return m_xStatusIndicator; }
+ void setStatusIndicator( const com::sun::star::uno::Reference< com::sun::star::task::XStatusIndicator >& xStatus )
+ { m_xStatusIndicator = xStatus; }
+
+ const FontAttributes& getFont( sal_Int32 nFontId ) const;
+ sal_Int32 getFontId( const FontAttributes& rAttr ) const;
+
+ void sortElements( Element* pElement, bool bDeep = false );
+ void sortDocument( bool bDeep = false );
+
+ rtl::OUString mirrorString( const rtl::OUString& i_rInString );
+
+ private:
+ void prepareMirrorMap();
+ void processGlyphLine();
+ void processGlyph( double fPreAvarageSpaceValue,
+ CharGlyph& rGlyph,
+ ParagraphElement* pPara,
+ FrameElement* pFrame,
+ bool bIsWhiteSpaceInLine );
+
+ void drawGlyphLine( const rtl::OUString& rGlyphs,
+ const ::com::sun::star::geometry::RealRectangle2D& rRect,
+ const ::com::sun::star::geometry::Matrix2D& rFontMatrix );
+
+ void drawCharGlyphs( rtl::OUString& rGlyphs,
+ ::com::sun::star::geometry::RealRectangle2D& rRect,
+ ::com::sun::star::geometry::Matrix2D& rFontMatrix,
+ GraphicsContext aGC,
+ Element* pCurElement,
+ ParagraphElement* pPara,
+ FrameElement* pFrame,
+ bool bSpaceFlag );
+
+ GraphicsContext& getTransformGlyphContext( CharGlyph& rGlyph );
+
+ // ContentSink interface implementation
+
+ virtual void setPageNum( sal_Int32 nNumPages );
+ virtual void startPage( const ::com::sun::star::geometry::RealSize2D& rSize );
+ virtual void endPage();
+
+ virtual void hyperLink( const ::com::sun::star::geometry::RealRectangle2D& rBounds,
+ const ::rtl::OUString& rURI );
+ virtual void pushState();
+ virtual void popState();
+ virtual void setFlatness( double );
+ virtual void setTransformation( const ::com::sun::star::geometry::AffineMatrix2D& rMatrix );
+ virtual void setLineDash( const ::com::sun::star::uno::Sequence<double>& dashes,
+ double start );
+ virtual void setLineJoin(sal_Int8);
+ virtual void setLineCap(sal_Int8);
+ virtual void setMiterLimit(double);
+ virtual void setLineWidth(double);
+ virtual void setFillColor( const ::com::sun::star::rendering::ARGBColor& rColor );
+ virtual void setStrokeColor( const ::com::sun::star::rendering::ARGBColor& rColor );
+ virtual void setBlendMode(sal_Int8);
+ virtual void setFont( const FontAttributes& rFont );
+ virtual void setTextRenderMode( sal_Int32 );
+
+ virtual void strokePath( const ::com::sun::star::uno::Reference<
+ ::com::sun::star::rendering::XPolyPolygon2D >& rPath );
+ virtual void fillPath( const ::com::sun::star::uno::Reference<
+ ::com::sun::star::rendering::XPolyPolygon2D >& rPath );
+ virtual void eoFillPath( const ::com::sun::star::uno::Reference<
+ ::com::sun::star::rendering::XPolyPolygon2D >& rPath );
+
+ virtual void intersectClip(const ::com::sun::star::uno::Reference<
+ ::com::sun::star::rendering::XPolyPolygon2D >& rPath);
+ virtual void intersectEoClip(const ::com::sun::star::uno::Reference<
+ ::com::sun::star::rendering::XPolyPolygon2D >& rPath);
+
+ virtual void drawGlyphs( const rtl::OUString& rGlyphs,
+ const ::com::sun::star::geometry::RealRectangle2D& rRect,
+ const ::com::sun::star::geometry::Matrix2D& rFontMatrix );
+ virtual void endText();
+
+ virtual void drawMask(const ::com::sun::star::uno::Sequence<
+ ::com::sun::star::beans::PropertyValue>& xBitmap,
+ bool bInvert );
+ /// Given image must already be color-mapped and normalized to sRGB.
+ virtual void drawImage(const ::com::sun::star::uno::Sequence<
+ ::com::sun::star::beans::PropertyValue>& xBitmap );
+ /** Given image must already be color-mapped and normalized to sRGB.
+
+ maskColors must contain two sequences of color components
+ */
+ virtual void drawColorMaskedImage(const ::com::sun::star::uno::Sequence<
+ ::com::sun::star::beans::PropertyValue>& xBitmap,
+ const ::com::sun::star::uno::Sequence<
+ ::com::sun::star::uno::Any>& xMaskColors );
+ virtual void drawMaskedImage(const ::com::sun::star::uno::Sequence<
+ ::com::sun::star::beans::PropertyValue>& xBitmap,
+ const ::com::sun::star::uno::Sequence<
+ ::com::sun::star::beans::PropertyValue>& xMask,
+ bool bInvertMask);
+ virtual void drawAlphaMaskedImage(const ::com::sun::star::uno::Sequence<
+ ::com::sun::star::beans::PropertyValue>& xImage,
+ const ::com::sun::star::uno::Sequence<
+ ::com::sun::star::beans::PropertyValue>& xMask);
+
+ /// nElements == -1 means fill in number of pages
+ void startIndicator( const rtl::OUString& rText, sal_Int32 nElements = -1 );
+ void endIndicator();
+
+ void setupImage(ImageId nImage);
+
+ typedef boost::unordered_map<sal_Int32,FontAttributes> IdToFontMap;
+ typedef boost::unordered_map<FontAttributes,sal_Int32,FontAttrHash> FontToIdMap;
+
+ typedef boost::unordered_map<sal_Int32,GraphicsContext> IdToGCMap;
+ typedef boost::unordered_map<GraphicsContext,sal_Int32,GraphicsContextHash> GCToIdMap;
+
+ typedef std::vector<GraphicsContext> GraphicsContextStack;
+
+ ::basegfx::B2DRange& calcTransformedRectBounds( ::basegfx::B2DRange& outRect,
+ const ::basegfx::B2DRange& inRect,
+ const ::basegfx::B2DHomMatrix& transformation );
+ std::vector<CharGlyph> m_GlyphsList;
+
+ boost::shared_ptr<ElementFactory> m_pElFactory;
+ boost::shared_ptr<DocumentElement> m_pDocument;
+ PageElement* m_pCurPage;
+ Element* m_pCurElement;
+ sal_Int32 m_nNextFontId;
+ IdToFontMap m_aIdToFont;
+ FontToIdMap m_aFontToId;
+
+ GraphicsContextStack m_aGCStack;
+ GraphicsContext m_prev_aGC;
+ sal_Int32 m_nNextGCId;
+ IdToGCMap m_aIdToGC;
+ GCToIdMap m_aGCToId;
+
+ ImageContainer m_aImages;
+
+ DocumentTextDirecion m_eTextDirection;
+
+ sal_Int32 m_nPages;
+ sal_Int32 m_nNextZOrder;
+ double m_fWordSpace;
+ bool m_bIsWhiteSpaceInLine;
+ com::sun::star::uno::Reference<
+ com::sun::star::task::XStatusIndicator >
+ m_xStatusIndicator;
+
+ bool m_bHaveTextOnDocLevel;
+ std::vector< sal_Unicode > m_aMirrorMap;
+ com::sun::star::uno::Reference<
+ com::sun::star::util::XStringMapping >
+ m_xMirrorMapper;
+ bool m_bMirrorMapperTried;
+ };
+ class CharGlyph
+ {
+ public:
+ CharGlyph(){};
+ virtual ~CharGlyph(){};
+ rtl::OUString& getGlyph(){ return m_rGlyphs; }
+ com::sun::star::geometry::RealRectangle2D& getRect(){ return m_rRect; }
+ com::sun::star::geometry::Matrix2D& getFontMatrix(){ return m_rFontMatrix; }
+ GraphicsContext& getGC(){ return m_rCurrentContext; }
+ Element* getCurElement(){ return m_pCurElement; }
+
+ void setGlyph (const rtl::OUString& rGlyphs ){ m_rGlyphs=rGlyphs; }
+ void setRect (const ::com::sun::star::geometry::RealRectangle2D& rRect ){ m_rRect=rRect; }
+ void setFontMatrix (const ::com::sun::star::geometry::Matrix2D& rFontMatrix ){ m_rFontMatrix= rFontMatrix; }
+ void setGraphicsContext (GraphicsContext& rCurrentContext ){ m_rCurrentContext= rCurrentContext; }
+ void setCurElement( Element* pCurElement ){ m_pCurElement= pCurElement; }
+
+ double getYPrevGlyphPosition() const { return m_fYPrevGlyphPosition; }
+ double getXPrevGlyphPosition() const { return m_fXPrevGlyphPosition; }
+ double getPrevGlyphHeight() const { return m_fPrevGlyphHeight; }
+ double getPrevGlyphWidth () const { return m_fPrevGlyphWidth; }
+ double getPrevGlyphsSpace() const
+ {
+ if( (m_rRect.X1-m_fXPrevGlyphPosition)<0 )
+ return 0;
+ else
+ return m_rRect.X1-m_fXPrevGlyphPosition;
+ }
+
+ void setYPrevGlyphPosition( double fYPrevTextPosition ){ m_fYPrevGlyphPosition= fYPrevTextPosition; }
+ void setXPrevGlyphPosition( double fXPrevTextPosition ){ m_fXPrevGlyphPosition= fXPrevTextPosition; }
+ void setPrevGlyphHeight ( double fPrevTextHeight ){ m_fPrevGlyphHeight= fPrevTextHeight; }
+ void setPrevGlyphWidth ( double fPrevTextWidth ){ m_fPrevGlyphWidth= fPrevTextWidth; }
+
+ private:
+
+ double m_fYPrevGlyphPosition ;
+ double m_fXPrevGlyphPosition ;
+ double m_fPrevGlyphHeight ;
+ double m_fPrevGlyphWidth ;
+ Element* m_pCurElement ;
+ GraphicsContext m_rCurrentContext ;
+ com::sun::star::geometry::Matrix2D m_rFontMatrix ;
+ com::sun::star::geometry::RealRectangle2D m_rRect ;
+ rtl::OUString m_rGlyphs ;
+ };
+}
+
+#define USTR(x) rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( x ) )
+
+#endif
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sdext/source/pdfimport/tree/style.cxx b/sdext/source/pdfimport/tree/style.cxx
new file mode 100644
index 000000000000..c4068def4307
--- /dev/null
+++ b/sdext/source/pdfimport/tree/style.cxx
@@ -0,0 +1,262 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_sdext.hxx"
+
+#include "style.hxx"
+#include "genericelements.hxx"
+#include "xmlemitter.hxx"
+#include "pdfiprocessor.hxx"
+#include <rtl/ustrbuf.hxx>
+
+#include <algorithm>
+
+using namespace pdfi;
+
+using ::rtl::OUString;
+using ::rtl::OUStringBuffer;
+
+#define USTR(x) rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( x ) )
+
+StyleContainer::StyleContainer() :
+ m_nNextId( 1 )
+{
+}
+
+sal_Int32 StyleContainer::impl_getStyleId( const Style& rStyle, bool bSubStyle )
+{
+ sal_Int32 nRet = -1;
+
+ // construct HashedStyle to find or insert
+ HashedStyle aSearchStyle;
+ aSearchStyle.Name = rStyle.Name;
+ aSearchStyle.Properties = rStyle.Properties;
+ aSearchStyle.Contents = rStyle.Contents;
+ aSearchStyle.ContainedElement = rStyle.ContainedElement;
+ for( unsigned int n = 0; n < rStyle.SubStyles.size(); ++n )
+ aSearchStyle.SubStyles.push_back( impl_getStyleId( *rStyle.SubStyles[n], true ) );
+
+ boost::unordered_map< HashedStyle, sal_Int32, StyleHash >::iterator it =
+ m_aStyleToId.find( aSearchStyle );
+
+ if( it != m_aStyleToId.end() )
+ {
+ nRet = it->second;
+ HashedStyle& rFound = m_aIdToStyle[ nRet ];
+ // increase refcount on this style
+ rFound.RefCount++;
+ if( ! bSubStyle )
+ rFound.IsSubStyle = false;
+ }
+ else
+ {
+ nRet = m_nNextId++;
+ // create new style
+ HashedStyle& rNew = m_aIdToStyle[ nRet ];
+ rNew = aSearchStyle;
+ rNew.RefCount = 1;
+ rNew.IsSubStyle = bSubStyle;
+ // fill the style hash to find the id
+ m_aStyleToId[ rNew ] = nRet;
+ }
+ return nRet;
+}
+
+sal_Int32 StyleContainer::getStandardStyleId( const rtl::OString& rName )
+{
+ PropertyMap aProps;
+ aProps[ USTR( "style:family" ) ] = rtl::OStringToOUString( rName, RTL_TEXTENCODING_UTF8 );
+ aProps[ USTR( "style:name" ) ] = USTR( "standard" );
+
+ Style aStyle( "style:style", aProps );
+ return getStyleId( aStyle );
+}
+
+const PropertyMap* StyleContainer::getProperties( sal_Int32 nStyleId ) const
+{
+ boost::unordered_map< sal_Int32, HashedStyle >::const_iterator it =
+ m_aIdToStyle.find( nStyleId );
+ return it != m_aIdToStyle.end() ? &(it->second.Properties) : NULL;
+}
+
+sal_Int32 StyleContainer::setProperties( sal_Int32 nStyleId, const PropertyMap& rNewProps )
+{
+ sal_Int32 nRet = -1;
+ boost::unordered_map< sal_Int32, HashedStyle >::iterator it =
+ m_aIdToStyle.find( nStyleId );
+ if( it != m_aIdToStyle.end() )
+ {
+ if( it->second.RefCount == 1 )
+ {
+ nRet = it->first;
+ // erase old hash to id mapping
+ m_aStyleToId.erase( it->second );
+ // change properties
+ it->second.Properties = rNewProps;
+ // fill in new hash to id mapping
+ m_aStyleToId[ it->second ] = nRet;
+ }
+ else
+ {
+ // decrease refcound on old instance
+ it->second.RefCount--;
+ // acquire new HashedStyle
+ HashedStyle aSearchStyle;
+ aSearchStyle.Name = it->second.Name;
+ aSearchStyle.Properties = rNewProps;
+ aSearchStyle.Contents = it->second.Contents;
+ aSearchStyle.ContainedElement = it->second.ContainedElement;
+ aSearchStyle.SubStyles = it->second.SubStyles;
+ aSearchStyle.IsSubStyle = it->second.IsSubStyle;
+
+ // find out whether this new style already exists
+ boost::unordered_map< HashedStyle, sal_Int32, StyleHash >::iterator new_it =
+ m_aStyleToId.find( aSearchStyle );
+ if( new_it != m_aStyleToId.end() )
+ {
+ nRet = new_it->second;
+ m_aIdToStyle[ nRet ].RefCount++;
+ }
+ else
+ {
+ nRet = m_nNextId++;
+ // create new style with new id
+ HashedStyle& rNew = m_aIdToStyle[ nRet ];
+ rNew = aSearchStyle;
+ rNew.RefCount = 1;
+ // fill style to id hash
+ m_aStyleToId[ aSearchStyle ] = nRet;
+ }
+ }
+ }
+ return nRet;
+}
+
+OUString StyleContainer::getStyleName( sal_Int32 nStyle ) const
+{
+ OUStringBuffer aRet( 64 );
+
+ boost::unordered_map< sal_Int32, HashedStyle >::const_iterator style_it =
+ m_aIdToStyle.find( nStyle );
+ if( style_it != m_aIdToStyle.end() )
+ {
+ const HashedStyle& rStyle = style_it->second;
+
+ PropertyMap::const_iterator name_it = rStyle.Properties.find( USTR("style:name") );
+ if( name_it != rStyle.Properties.end() )
+ aRet.append( name_it->second );
+ else
+ {
+ PropertyMap::const_iterator fam_it = rStyle.Properties.find( USTR("style:family" ) );
+ OUString aStyleName;
+ if( fam_it != rStyle.Properties.end() )
+ {
+ aStyleName = fam_it->second;
+ }
+ else
+ aStyleName = OStringToOUString( rStyle.Name, RTL_TEXTENCODING_ASCII_US );
+ sal_Int32 nIndex = aStyleName.lastIndexOf( ':' );
+ aRet.append( aStyleName.copy( nIndex+1 ) );
+ aRet.append( nStyle );
+ }
+ }
+ else
+ {
+ aRet.appendAscii( "invalid style id " );
+ aRet.append( nStyle );
+ }
+
+ return aRet.makeStringAndClear();
+}
+
+void StyleContainer::impl_emitStyle( sal_Int32 nStyleId,
+ EmitContext& rContext,
+ ElementTreeVisitor& rContainedElemVisitor )
+{
+ boost::unordered_map< sal_Int32, HashedStyle >::const_iterator it = m_aIdToStyle.find( nStyleId );
+ if( it != m_aIdToStyle.end() )
+ {
+ const HashedStyle& rStyle = it->second;
+ PropertyMap aProps( rStyle.Properties );
+ if( !rStyle.IsSubStyle )
+ aProps[ USTR( "style:name" ) ] = getStyleName( nStyleId );
+ rContext.rEmitter.beginTag( rStyle.Name.getStr(), aProps );
+
+ for( unsigned int n = 0; n < rStyle.SubStyles.size(); ++n )
+ impl_emitStyle( rStyle.SubStyles[n], rContext, rContainedElemVisitor );
+ if( rStyle.Contents.getLength() )
+ rContext.rEmitter.write( rStyle.Contents );
+ if( rStyle.ContainedElement )
+ rStyle.ContainedElement->visitedBy( rContainedElemVisitor,
+ std::list<Element*>::iterator() );
+ rContext.rEmitter.endTag( rStyle.Name.getStr() );
+ }
+}
+
+void StyleContainer::emit( EmitContext& rContext,
+ ElementTreeVisitor& rContainedElemVisitor )
+{
+ std::vector< sal_Int32 > aMasterPageSection, aAutomaticStyleSection, aOfficeStyleSection;
+ for( boost::unordered_map< sal_Int32, HashedStyle >::iterator it = m_aIdToStyle.begin();
+ it != m_aIdToStyle.end(); ++it )
+ {
+ if( ! it->second.IsSubStyle )
+ {
+ if( it->second.Name.equals( "style:master-page" ) )
+ aMasterPageSection.push_back( it->first );
+ else if( getStyleName( it->first ).equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "standard" ) ) )
+ aOfficeStyleSection.push_back( it->first );
+ else
+ aAutomaticStyleSection.push_back( it->first );
+ }
+ }
+
+ if( ! aMasterPageSection.empty() )
+ std::stable_sort( aMasterPageSection.begin(), aMasterPageSection.end(), StyleIdNameSort(&m_aIdToStyle) );
+ if( ! aAutomaticStyleSection.empty() )
+ std::stable_sort( aAutomaticStyleSection.begin(), aAutomaticStyleSection.end(), StyleIdNameSort(&m_aIdToStyle) );
+ if( ! aOfficeStyleSection.empty() )
+ std::stable_sort( aOfficeStyleSection.begin(), aOfficeStyleSection.end(), StyleIdNameSort(&m_aIdToStyle) );
+
+ int n = 0, nElements = 0;
+ rContext.rEmitter.beginTag( "office:styles", PropertyMap() );
+ for( n = 0, nElements = aOfficeStyleSection.size(); n < nElements; n++ )
+ impl_emitStyle( aOfficeStyleSection[n], rContext, rContainedElemVisitor );
+ rContext.rEmitter.endTag( "office:styles" );
+ rContext.rEmitter.beginTag( "office:automatic-styles", PropertyMap() );
+ for( n = 0, nElements = aAutomaticStyleSection.size(); n < nElements; n++ )
+ impl_emitStyle( aAutomaticStyleSection[n], rContext, rContainedElemVisitor );
+ rContext.rEmitter.endTag( "office:automatic-styles" );
+ rContext.rEmitter.beginTag( "office:master-styles", PropertyMap() );
+ for( n = 0, nElements = aMasterPageSection.size(); n < nElements; n++ )
+ impl_emitStyle( aMasterPageSection[n], rContext, rContainedElemVisitor );
+ rContext.rEmitter.endTag( "office:master-styles" );
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sdext/source/pdfimport/tree/style.hxx b/sdext/source/pdfimport/tree/style.hxx
new file mode 100644
index 000000000000..17ee2e210661
--- /dev/null
+++ b/sdext/source/pdfimport/tree/style.hxx
@@ -0,0 +1,184 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+#ifndef INCLUDED_PDFI_STYLE_HXX
+#define INCLUDED_PDFI_STYLE_HXX
+
+#include "pdfihelper.hxx"
+#include <boost/unordered_map.hpp>
+#include <vector>
+#include <rtl/ustring.hxx>
+#include <rtl/string.hxx>
+#include "treevisiting.hxx"
+
+namespace pdfi
+{
+ struct Element;
+ struct EmitContext;
+ struct ElementTreeVisitable;
+
+ class StyleContainer
+ {
+ public:
+ struct Style
+ {
+ rtl::OString Name;
+ PropertyMap Properties;
+ rtl::OUString Contents;
+ Element* ContainedElement;
+ std::vector< Style* > SubStyles;
+
+ Style() : ContainedElement( NULL ) {}
+ Style( const rtl::OString& rName, const PropertyMap& rProps ) :
+ Name( rName ),
+ Properties( rProps ),
+ ContainedElement( NULL )
+ {}
+ };
+
+ private:
+ struct HashedStyle
+ {
+ rtl::OString Name;
+ PropertyMap Properties;
+ rtl::OUString Contents;
+ Element* ContainedElement;
+ std::vector<sal_Int32> SubStyles;
+
+ bool IsSubStyle;
+ sal_Int32 RefCount;
+
+ HashedStyle() : ContainedElement( NULL ), IsSubStyle( true ), RefCount( 0 ) {}
+
+ HashedStyle( const HashedStyle& rRight ) :
+ Name( rRight.Name ),
+ Properties( rRight.Properties ),
+ Contents( rRight.Contents ),
+ ContainedElement( rRight.ContainedElement ),
+ SubStyles( rRight.SubStyles ),
+ IsSubStyle( rRight.IsSubStyle ),
+ RefCount( 0 )
+ {}
+
+ size_t hashCode() const
+ {
+ size_t nRet = size_t(Name.hashCode());
+ for( PropertyMap::const_iterator it = Properties.begin();
+ it != Properties.end(); ++it )
+ {
+ nRet ^= size_t(it->first.hashCode());
+ nRet ^= size_t(it->second.hashCode());
+ }
+ nRet = size_t(Contents.hashCode());
+ nRet ^= size_t(ContainedElement);
+ for( unsigned int n = 0; n < SubStyles.size(); ++n )
+ nRet ^= size_t(SubStyles[n]);
+ return nRet;
+ }
+
+ bool operator==(const HashedStyle& rRight) const
+ {
+ if( Name != rRight.Name ||
+ Properties != rRight.Properties ||
+ Contents != rRight.Contents ||
+ ContainedElement != rRight.ContainedElement ||
+ SubStyles.size() != rRight.SubStyles.size()
+ )
+ return false;
+ for( unsigned int n = 0; n < SubStyles.size(); ++n )
+ {
+ if( SubStyles[n] != rRight.SubStyles[n] )
+ return false;
+ }
+ return true;
+ }
+ };
+
+ struct StyleHash;
+ friend struct StyleHash;
+ struct StyleHash
+ {
+ size_t operator()( const StyleContainer::HashedStyle& rStyle ) const
+ {
+ return rStyle.hashCode();
+ }
+ };
+
+ struct StyleIdNameSort;
+ friend struct StyleIdNameSort;
+ struct StyleIdNameSort
+ {
+ const boost::unordered_map< sal_Int32, HashedStyle >* m_pMap;
+
+ StyleIdNameSort( const boost::unordered_map< sal_Int32, HashedStyle >* pMap ) :
+ m_pMap(pMap)
+ {}
+ bool operator()( sal_Int32 nLeft, sal_Int32 nRight )
+ {
+ const boost::unordered_map< sal_Int32, HashedStyle >::const_iterator left_it =
+ m_pMap->find( nLeft );
+ const boost::unordered_map< sal_Int32, HashedStyle >::const_iterator right_it =
+ m_pMap->find( nRight );
+ if( left_it == m_pMap->end() )
+ return false;
+ else if( right_it == m_pMap->end() )
+ return true;
+ else
+ return left_it->second.Name < right_it->second.Name;
+ }
+ };
+
+ sal_Int32 m_nNextId;
+ boost::unordered_map< sal_Int32, HashedStyle > m_aIdToStyle;
+ boost::unordered_map< HashedStyle, sal_Int32, StyleHash > m_aStyleToId;
+
+ void impl_emitStyle( sal_Int32 nStyleId,
+ EmitContext& rContext,
+ ElementTreeVisitor& rContainedElemVisitor );
+
+ public:
+ StyleContainer();
+
+ void emit( EmitContext& rContext,
+ ElementTreeVisitor& rContainedElemVisitor );
+
+ sal_Int32 impl_getStyleId( const Style& rStyle, bool bSubStyle );
+ sal_Int32 getStyleId( const Style& rStyle )
+ { return impl_getStyleId( rStyle, false ); }
+ sal_Int32 getStandardStyleId( const rtl::OString& rFamily );
+
+ // returns NULL for an invalid style id
+ const PropertyMap* getProperties( sal_Int32 nStyleId ) const;
+ sal_Int32 setProperties( sal_Int32 nStyleId, const PropertyMap &rNewProps );
+ rtl::OUString getStyleName( sal_Int32 nStyle ) const;
+ };
+}
+
+#endif
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sdext/source/pdfimport/tree/treevisiting.hxx b/sdext/source/pdfimport/tree/treevisiting.hxx
new file mode 100644
index 000000000000..b62340a7b9f8
--- /dev/null
+++ b/sdext/source/pdfimport/tree/treevisiting.hxx
@@ -0,0 +1,83 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+#ifndef INCLUDED_PDFI_TREEVISITING_HXX
+#define INCLUDED_PDFI_TREEVISITING_HXX
+
+#include <sal/config.h>
+#include <list>
+
+
+namespace pdfi
+{
+ class PDFIProcessor;
+ class StyleContainer;
+ struct HyperlinkElement;
+ struct TextElement;
+ struct ParagraphElement;
+ struct FrameElement;
+ struct PolyPolyElement;
+ struct ImageElement;
+ struct PageElement;
+ struct DocumentElement;
+ struct EmitContext;
+ struct Element;
+
+ /** To be visited by all tree element types
+
+ Visitor interface from the "visitor pattern". Implementor gets
+ called with actual tree node instances.
+ */
+ struct ElementTreeVisitor
+ {
+ virtual void visit( HyperlinkElement&, const std::list< Element* >::const_iterator& ) = 0;
+ virtual void visit( TextElement&, const std::list< Element* >::const_iterator& ) = 0;
+ virtual void visit( ParagraphElement&, const std::list< Element* >::const_iterator& ) = 0;
+ virtual void visit( FrameElement&, const std::list< Element* >::const_iterator& ) = 0;
+ virtual void visit( PolyPolyElement&, const std::list< Element* >::const_iterator& ) = 0;
+ virtual void visit( ImageElement&, const std::list< Element* >::const_iterator& ) = 0;
+ virtual void visit( PageElement&, const std::list< Element* >::const_iterator& ) = 0;
+ virtual void visit( DocumentElement&, const std::list< Element* >::const_iterator& ) = 0;
+ };
+ typedef boost::shared_ptr<ElementTreeVisitor> ElementTreeVisitorSharedPtr;
+
+ /** Visitee interface
+
+ To be implemented by every tree node that needs to be
+ visitable.
+ */
+ struct ElementTreeVisitable
+ {
+ virtual void visitedBy( ElementTreeVisitor&, const std::list< Element* >::const_iterator& rParentIt ) = 0;
+ };
+ typedef boost::shared_ptr<ElementTreeVisitable> ElementTreeVisitableSharedPtr;
+}
+
+#endif
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sdext/source/pdfimport/tree/treevisitorfactory.cxx b/sdext/source/pdfimport/tree/treevisitorfactory.cxx
new file mode 100644
index 000000000000..e2fc36c5f6b0
--- /dev/null
+++ b/sdext/source/pdfimport/tree/treevisitorfactory.cxx
@@ -0,0 +1,124 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_sdext.hxx"
+
+#include "treevisitorfactory.hxx"
+#include "writertreevisiting.hxx"
+#include "drawtreevisiting.hxx"
+
+namespace pdfi
+{
+ struct WriterTreeVisitorFactory : public TreeVisitorFactory
+ {
+ WriterTreeVisitorFactory() {}
+
+ virtual boost::shared_ptr<ElementTreeVisitor> createOptimizingVisitor(PDFIProcessor& rProc) const
+ {
+ return boost::shared_ptr<ElementTreeVisitor>(new WriterXmlOptimizer(rProc));
+ }
+
+ virtual boost::shared_ptr<ElementTreeVisitor> createStyleCollectingVisitor(
+ StyleContainer& rStyles,
+ PDFIProcessor& rProc ) const
+ {
+ return boost::shared_ptr<ElementTreeVisitor>(new WriterXmlFinalizer(rStyles,rProc));
+ }
+
+ virtual boost::shared_ptr<ElementTreeVisitor> createEmittingVisitor(EmitContext& rEmitContext, PDFIProcessor&) const
+ {
+ return boost::shared_ptr<ElementTreeVisitor>(new WriterXmlEmitter(rEmitContext));
+ }
+ };
+
+ struct ImpressTreeVisitorFactory : public TreeVisitorFactory
+ {
+ ImpressTreeVisitorFactory() {}
+
+ virtual boost::shared_ptr<ElementTreeVisitor> createOptimizingVisitor(PDFIProcessor& rProc) const
+ {
+ return boost::shared_ptr<ElementTreeVisitor>(new DrawXmlOptimizer(rProc));
+ }
+
+ virtual boost::shared_ptr<ElementTreeVisitor> createStyleCollectingVisitor(
+ StyleContainer& rStyles,
+ PDFIProcessor& rProc ) const
+ {
+ return boost::shared_ptr<ElementTreeVisitor>(new DrawXmlFinalizer(rStyles,rProc));
+ }
+
+ virtual boost::shared_ptr<ElementTreeVisitor> createEmittingVisitor(EmitContext& rEmitContext, PDFIProcessor& rProc) const
+ {
+ return boost::shared_ptr<ElementTreeVisitor>(new DrawXmlEmitter(rEmitContext,
+ DrawXmlEmitter::IMPRESS_DOC,
+ rProc
+ ));
+ }
+ };
+
+ struct DrawTreeVisitorFactory : public TreeVisitorFactory
+ {
+ DrawTreeVisitorFactory() {}
+
+ virtual boost::shared_ptr<ElementTreeVisitor> createOptimizingVisitor(PDFIProcessor& rProc) const
+ {
+ return boost::shared_ptr<ElementTreeVisitor>(new DrawXmlOptimizer(rProc));
+ }
+
+ virtual boost::shared_ptr<ElementTreeVisitor> createStyleCollectingVisitor(
+ StyleContainer& rStyles,
+ PDFIProcessor& rProc ) const
+ {
+ return boost::shared_ptr<ElementTreeVisitor>(new DrawXmlFinalizer(rStyles,rProc));
+ }
+
+ virtual boost::shared_ptr<ElementTreeVisitor> createEmittingVisitor(EmitContext& rEmitContext, PDFIProcessor& rProc) const
+ {
+ return boost::shared_ptr<ElementTreeVisitor>(new DrawXmlEmitter(rEmitContext,
+ DrawXmlEmitter::DRAW_DOC,
+ rProc
+ ));
+ }
+ };
+
+ TreeVisitorFactorySharedPtr createWriterTreeVisitorFactory()
+ {
+ return TreeVisitorFactorySharedPtr(new WriterTreeVisitorFactory());
+ }
+ TreeVisitorFactorySharedPtr createImpressTreeVisitorFactory()
+ {
+ return TreeVisitorFactorySharedPtr(new ImpressTreeVisitorFactory());
+ }
+ TreeVisitorFactorySharedPtr createDrawTreeVisitorFactory()
+ {
+ return TreeVisitorFactorySharedPtr(new DrawTreeVisitorFactory());
+ }
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sdext/source/pdfimport/tree/writertreevisiting.cxx b/sdext/source/pdfimport/tree/writertreevisiting.cxx
new file mode 100644
index 000000000000..f01fb959136d
--- /dev/null
+++ b/sdext/source/pdfimport/tree/writertreevisiting.cxx
@@ -0,0 +1,1221 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_sdext.hxx"
+
+#include "pdfiprocessor.hxx"
+#include "xmlemitter.hxx"
+#include "pdfihelper.hxx"
+#include "imagecontainer.hxx"
+#include "style.hxx"
+#include "writertreevisiting.hxx"
+#include "genericelements.hxx"
+
+#include <basegfx/polygon/b2dpolypolygontools.hxx>
+#include <basegfx/range/b2drange.hxx>
+
+
+namespace pdfi
+{
+
+void WriterXmlEmitter::visit( HyperlinkElement& elem, const std::list< Element* >::const_iterator& )
+{
+ if( elem.Children.empty() )
+ return;
+
+ const char* pType = dynamic_cast<DrawElement*>(elem.Children.front()) ? "draw:a" : "text:a";
+
+ PropertyMap aProps;
+ aProps[ USTR( "xlink:type" ) ] = USTR( "simple" );
+ aProps[ USTR( "xlink:href" ) ] = elem.URI;
+ aProps[ USTR( "office:target-frame-name" ) ] = USTR( "_blank" );
+ aProps[ USTR( "xlink:show" ) ] = USTR( "new" );
+
+ m_rEmitContext.rEmitter.beginTag( pType, aProps );
+ std::list< Element* >::iterator this_it = elem.Children.begin();
+ while( this_it !=elem.Children.end() && *this_it != &elem )
+ {
+ (*this_it)->visitedBy( *this, this_it );
+ ++this_it;
+ }
+ m_rEmitContext.rEmitter.endTag( pType );
+}
+
+void WriterXmlEmitter::visit( TextElement& elem, const std::list< Element* >::const_iterator& )
+{
+ if( ! elem.Text.getLength() )
+ return;
+
+ PropertyMap aProps;
+ if( elem.StyleId != -1 )
+ {
+ aProps[ rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "text:style-name" ) ) ] =
+ m_rEmitContext.rStyles.getStyleName( elem.StyleId );
+ }
+
+ m_rEmitContext.rEmitter.beginTag( "text:span", aProps );
+ m_rEmitContext.rEmitter.write( elem.Text.makeStringAndClear() );
+ std::list< Element* >::iterator this_it = elem.Children.begin();
+ while( this_it !=elem.Children.end() && *this_it != &elem )
+ {
+ (*this_it)->visitedBy( *this, this_it );
+ ++this_it;
+ }
+
+ m_rEmitContext.rEmitter.endTag( "text:span" );
+}
+
+void WriterXmlEmitter::visit( ParagraphElement& elem, const std::list< Element* >::const_iterator& )
+{
+ PropertyMap aProps;
+ if( elem.StyleId != -1 )
+ {
+ aProps[ USTR( "text:style-name" ) ] = m_rEmitContext.rStyles.getStyleName( elem.StyleId );
+ }
+ const char* pTagType = "text:p";
+ if( elem.Type == elem.Headline )
+ pTagType = "text:h";
+ m_rEmitContext.rEmitter.beginTag( pTagType, aProps );
+
+ std::list< Element* >::iterator this_it = elem.Children.begin();
+ while( this_it !=elem.Children.end() && *this_it != &elem )
+ {
+ (*this_it)->visitedBy( *this, this_it );
+ ++this_it;
+ }
+
+ m_rEmitContext.rEmitter.endTag( pTagType );
+}
+
+void WriterXmlEmitter::fillFrameProps( DrawElement& rElem,
+ PropertyMap& rProps,
+ const EmitContext& rEmitContext )
+{
+ double rel_x = rElem.x, rel_y = rElem.y;
+
+ // find anchor type by recursing though parents
+ Element* pAnchor = rElem.Parent;
+ while( pAnchor &&
+ ! dynamic_cast<ParagraphElement*>(pAnchor) &&
+ ! dynamic_cast<PageElement*>(pAnchor) )
+ {
+ pAnchor = pAnchor->Parent;
+ }
+ if( pAnchor )
+ {
+ if( dynamic_cast<ParagraphElement*>(pAnchor) )
+ {
+ rProps[ USTR( "text:anchor-type" ) ] =
+ rElem.isCharacter ? USTR( "character" ) : USTR( "paragraph" );
+ }
+ else
+ {
+ PageElement* pPage = dynamic_cast<PageElement*>(pAnchor);
+ rProps[ USTR( "text:anchor-type" ) ] = USTR( "page" );
+ rProps[ USTR( "text:anchor-page-number" ) ] = rtl::OUString::valueOf(pPage->PageNumber);
+ }
+ rel_x -= pAnchor->x;
+ rel_y -= pAnchor->y;
+ }
+
+ rProps[ USTR( "draw:z-index" ) ] = rtl::OUString::valueOf( rElem.ZOrder );
+ rProps[ USTR( "draw:style-name" )] = rEmitContext.rStyles.getStyleName( rElem.StyleId );
+ rProps[ USTR( "svg:width" ) ] = convertPixelToUnitString( rElem.w );
+ rProps[ USTR( "svg:height" ) ] = convertPixelToUnitString( rElem.h );
+
+ const GraphicsContext& rGC =
+ rEmitContext.rProcessor.getGraphicsContext( rElem.GCId );
+ if( rGC.Transformation.isIdentity() )
+ {
+ if( !rElem.isCharacter )
+ {
+ rProps[ USTR( "svg:x" ) ] = convertPixelToUnitString( rel_x );
+ rProps[ USTR( "svg:y" ) ] = convertPixelToUnitString( rel_y );
+ }
+ }
+ else
+ {
+ basegfx::B2DTuple aScale, aTranslation;
+ double fRotate, fShearX;
+
+ rGC.Transformation.decompose( aScale, aTranslation, fRotate, fShearX );
+
+ rtl::OUStringBuffer aBuf( 256 );
+
+ // TODO(F2): general transformation case missing; if implemented, note
+ // that ODF rotation is oriented the other way
+
+ // build transformation string
+ if( fShearX != 0.0 )
+ {
+ aBuf.appendAscii( "skewX( " );
+ aBuf.append( fShearX );
+ aBuf.appendAscii( " )" );
+ }
+ if( fRotate != 0.0 )
+ {
+ if( aBuf.getLength() > 0 )
+ aBuf.append( sal_Unicode(' ') );
+ aBuf.appendAscii( "rotate( " );
+ aBuf.append( -fRotate );
+ aBuf.appendAscii( " )" );
+
+ }
+ if( ! rElem.isCharacter )
+ {
+ if( aBuf.getLength() > 0 )
+ aBuf.append( sal_Unicode(' ') );
+ aBuf.appendAscii( "translate( " );
+ aBuf.append( convertPixelToUnitString( rel_x ) );
+ aBuf.append( sal_Unicode(' ') );
+ aBuf.append( convertPixelToUnitString( rel_y ) );
+ aBuf.appendAscii( " )" );
+ }
+
+ rProps[ USTR( "draw:transform" ) ] = aBuf.makeStringAndClear();
+ }
+}
+
+void WriterXmlEmitter::visit( FrameElement& elem, const std::list< Element* >::const_iterator& )
+{
+ if( elem.Children.empty() )
+ return;
+
+ bool bTextBox = (dynamic_cast<ParagraphElement*>(elem.Children.front()) != NULL);
+ PropertyMap aFrameProps;
+ fillFrameProps( elem, aFrameProps, m_rEmitContext );
+ m_rEmitContext.rEmitter.beginTag( "draw:frame", aFrameProps );
+ if( bTextBox )
+ m_rEmitContext.rEmitter.beginTag( "draw:text-box", PropertyMap() );
+
+ std::list< Element* >::iterator this_it = elem.Children.begin();
+ while( this_it !=elem.Children.end() && *this_it != &elem )
+ {
+ (*this_it)->visitedBy( *this, this_it );
+ ++this_it;
+ }
+
+ if( bTextBox )
+ m_rEmitContext.rEmitter.endTag( "draw:text-box" );
+ m_rEmitContext.rEmitter.endTag( "draw:frame" );
+}
+
+void WriterXmlEmitter::visit( PolyPolyElement& elem, const std::list< Element* >::const_iterator& )
+{
+ elem.updateGeometry();
+ /* note:
+ * aw recommends using 100dth of mm in all respects since the xml import
+ * (a) is buggy (see issue 37213)
+ * (b) is optimized for 100dth of mm and does not scale itself then,
+ * this does not gain us speed but makes for smaller rounding errors since
+ * the xml importer coordinates are integer based
+ */
+ for (sal_uInt32 i = 0; i< elem.PolyPoly.count(); i++)
+ {
+ basegfx::B2DPolygon b2dPolygon;
+ b2dPolygon = elem.PolyPoly.getB2DPolygon( i );
+
+ for ( sal_uInt32 j = 0; j< b2dPolygon.count(); j++ )
+ {
+ basegfx::B2DPoint point;
+ basegfx::B2DPoint nextPoint;
+ point = b2dPolygon.getB2DPoint( j );
+
+ basegfx::B2DPoint prevPoint;
+ prevPoint = b2dPolygon.getPrevControlPoint( j ) ;
+
+ point.setX( convPx2mmPrec2( point.getX() )*100.0 );
+ point.setY( convPx2mmPrec2( point.getY() )*100.0 );
+
+ if ( b2dPolygon.isPrevControlPointUsed( j ) )
+ {
+ prevPoint.setX( convPx2mmPrec2( prevPoint.getX() )*100.0 );
+ prevPoint.setY( convPx2mmPrec2( prevPoint.getY() )*100.0 );
+ }
+
+ if ( b2dPolygon.isNextControlPointUsed( j ) )
+ {
+ nextPoint = b2dPolygon.getNextControlPoint( j ) ;
+ nextPoint.setX( convPx2mmPrec2( nextPoint.getX() )*100.0 );
+ nextPoint.setY( convPx2mmPrec2( nextPoint.getY() )*100.0 );
+ }
+
+ b2dPolygon.setB2DPoint( j, point );
+
+ if ( b2dPolygon.isPrevControlPointUsed( j ) )
+ b2dPolygon.setPrevControlPoint( j , prevPoint ) ;
+
+ if ( b2dPolygon.isNextControlPointUsed( j ) )
+ b2dPolygon.setNextControlPoint( j , nextPoint ) ;
+ }
+
+ elem.PolyPoly.setB2DPolygon( i, b2dPolygon );
+ }
+
+ PropertyMap aProps;
+ fillFrameProps( elem, aProps, m_rEmitContext );
+ rtl::OUStringBuffer aBuf( 64 );
+ aBuf.appendAscii( "0 0 " );
+ aBuf.append( convPx2mmPrec2(elem.w)*100.0 );
+ aBuf.append( sal_Unicode(' ') );
+ aBuf.append( convPx2mmPrec2(elem.h)*100.0 );
+ aProps[ USTR( "svg:viewBox" ) ] = aBuf.makeStringAndClear();
+ aProps[ USTR( "svg:d" ) ] = basegfx::tools::exportToSvgD( elem.PolyPoly );
+
+ m_rEmitContext.rEmitter.beginTag( "draw:path", aProps );
+ m_rEmitContext.rEmitter.endTag( "draw:path" );
+}
+
+void WriterXmlEmitter::visit( ImageElement& elem, const std::list< Element* >::const_iterator& )
+{
+ PropertyMap aImageProps;
+ m_rEmitContext.rEmitter.beginTag( "draw:image", aImageProps );
+ m_rEmitContext.rEmitter.beginTag( "office:binary-data", PropertyMap() );
+ m_rEmitContext.rImages.writeBase64EncodedStream( elem.Image, m_rEmitContext);
+ m_rEmitContext.rEmitter.endTag( "office:binary-data" );
+ m_rEmitContext.rEmitter.endTag( "draw:image" );
+}
+
+void WriterXmlEmitter::visit( PageElement& elem, const std::list< Element* >::const_iterator& )
+{
+ if( m_rEmitContext.xStatusIndicator.is() )
+ m_rEmitContext.xStatusIndicator->setValue( elem.PageNumber );
+
+ std::list< Element* >::iterator this_it = elem.Children.begin();
+ while( this_it !=elem.Children.end() && *this_it != &elem )
+ {
+ (*this_it)->visitedBy( *this, this_it );
+ ++this_it;
+ }
+}
+
+void WriterXmlEmitter::visit( DocumentElement& elem, const std::list< Element* >::const_iterator&)
+{
+ m_rEmitContext.rEmitter.beginTag( "office:body", PropertyMap() );
+ m_rEmitContext.rEmitter.beginTag( "office:text", PropertyMap() );
+
+ for( std::list< Element* >::iterator it = elem.Children.begin(); it != elem.Children.end(); ++it )
+ {
+ PageElement* pPage = dynamic_cast<PageElement*>(*it);
+ if( pPage )
+ {
+ // emit only page anchored objects
+ // currently these are only DrawElement types
+ for( std::list< Element* >::iterator child_it = pPage->Children.begin(); child_it != pPage->Children.end(); ++child_it )
+ {
+ if( dynamic_cast<DrawElement*>(*child_it) != NULL )
+ (*child_it)->visitedBy( *this, child_it );
+ }
+ }
+ }
+
+ // do not emit page anchored objects, they are emitted before
+ // (must precede all pages in writer document) currently these are
+ // only DrawElement types
+ for( std::list< Element* >::iterator it = elem.Children.begin(); it != elem.Children.end(); ++it )
+ {
+ if( dynamic_cast<DrawElement*>(*it) == NULL )
+ (*it)->visitedBy( *this, it );
+ }
+
+ m_rEmitContext.rEmitter.endTag( "office:text" );
+ m_rEmitContext.rEmitter.endTag( "office:body" );
+}
+
+/////////////////////////////////////////////////////////////////
+
+void WriterXmlOptimizer::visit( HyperlinkElement&, const std::list< Element* >::const_iterator& )
+{
+}
+
+void WriterXmlOptimizer::visit( TextElement&, const std::list< Element* >::const_iterator&)
+{
+}
+
+void WriterXmlOptimizer::visit( FrameElement& elem, const std::list< Element* >::const_iterator& )
+{
+ elem.applyToChildren(*this);
+}
+
+void WriterXmlOptimizer::visit( ImageElement&, const std::list< Element* >::const_iterator& )
+{
+}
+
+void WriterXmlOptimizer::visit( PolyPolyElement& elem, const std::list< Element* >::const_iterator& )
+{
+ /* note: optimize two consecutive PolyPolyElements that
+ * have the same path but one of which is a stroke while
+ * the other is a fill
+ */
+ if( elem.Parent )
+ {
+ // find following PolyPolyElement in parent's children list
+ std::list< Element* >::iterator this_it = elem.Parent->Children.begin();
+ while( this_it != elem.Parent->Children.end() && *this_it != &elem )
+ ++this_it;
+
+ if( this_it != elem.Parent->Children.end() )
+ {
+ std::list< Element* >::iterator next_it = this_it;
+ if( ++next_it != elem.Parent->Children.end() )
+ {
+ PolyPolyElement* pNext = dynamic_cast<PolyPolyElement*>(*next_it);
+ if( pNext && pNext->PolyPoly == elem.PolyPoly )
+ {
+ const GraphicsContext& rNextGC =
+ m_rProcessor.getGraphicsContext( pNext->GCId );
+ const GraphicsContext& rThisGC =
+ m_rProcessor.getGraphicsContext( elem.GCId );
+
+ if( rThisGC.BlendMode == rNextGC.BlendMode &&
+ rThisGC.Flatness == rNextGC.Flatness &&
+ rThisGC.Transformation == rNextGC.Transformation &&
+ rThisGC.Clip == rNextGC.Clip &&
+ pNext->Action == PATH_STROKE &&
+ (elem.Action == PATH_FILL || elem.Action == PATH_EOFILL) )
+ {
+ GraphicsContext aGC = rThisGC;
+ aGC.LineJoin = rNextGC.LineJoin;
+ aGC.LineCap = rNextGC.LineCap;
+ aGC.LineWidth = rNextGC.LineWidth;
+ aGC.MiterLimit= rNextGC.MiterLimit;
+ aGC.DashArray = rNextGC.DashArray;
+ aGC.LineColor = rNextGC.LineColor;
+ elem.GCId = m_rProcessor.getGCId( aGC );
+
+ elem.Action |= pNext->Action;
+
+ elem.Children.splice( elem.Children.end(), pNext->Children );
+ elem.Parent->Children.erase( next_it );
+ delete pNext;
+ }
+ }
+ }
+ }
+ }
+}
+
+void WriterXmlOptimizer::visit( ParagraphElement& elem, const std::list< Element* >::const_iterator& rParentIt)
+{
+ optimizeTextElements( elem );
+
+ elem.applyToChildren(*this);
+
+ if( elem.Parent && rParentIt != elem.Parent->Children.end() )
+ {
+ // find if there is a previous paragraph that might be a heading for this one
+ std::list<Element*>::const_iterator prev = rParentIt;
+ ParagraphElement* pPrevPara = NULL;
+ while( prev != elem.Parent->Children.begin() )
+ {
+ --prev;
+ pPrevPara = dynamic_cast< ParagraphElement* >(*prev);
+ if( pPrevPara )
+ {
+ /* What constitutes a heading ? current hints are:
+ * - one line only
+ * - not too far away from this paragraph (two heading height max ?)
+ * - font larger or bold
+ * this is of course incomplete
+ * FIXME: improve hints for heading
+ */
+ // check for single line
+ if( pPrevPara->isSingleLined( m_rProcessor ) )
+ {
+ double head_line_height = pPrevPara->getLineHeight( m_rProcessor );
+ if( pPrevPara->y + pPrevPara->h + 2*head_line_height > elem.y )
+ {
+ // check for larger font
+ if( head_line_height > elem.getLineHeight( m_rProcessor ) )
+ {
+ pPrevPara->Type = elem.Headline;
+ }
+ else
+ {
+ // check whether text of pPrevPara is bold (at least first text element)
+ // and this para is not bold (dito)
+ TextElement* pPrevText = pPrevPara->getFirstTextChild();
+ TextElement* pThisText = elem.getFirstTextChild();
+ if( pPrevText && pThisText )
+ {
+ const FontAttributes& rPrevFont = m_rProcessor.getFont( pPrevText->FontId );
+ const FontAttributes& rThisFont = m_rProcessor.getFont( pThisText->FontId );
+ if( rPrevFont.isBold && ! rThisFont.isBold )
+ pPrevPara->Type = elem.Headline;
+ }
+ }
+ }
+ }
+ break;
+ }
+ }
+ }
+}
+
+void WriterXmlOptimizer::visit( PageElement& elem, const std::list< Element* >::const_iterator& )
+{
+ if( m_rProcessor.getStatusIndicator().is() )
+ m_rProcessor.getStatusIndicator()->setValue( elem.PageNumber );
+
+ // resolve hyperlinks
+ elem.resolveHyperlinks();
+
+ elem.resolveFontStyles( m_rProcessor ); // underlines and such
+
+ // FIXME: until hyperlinks and font effects are adjusted for
+ // geometrical search handle them before sorting
+ m_rProcessor.sortElements( &elem );
+
+ // find paragraphs in text
+ ParagraphElement* pCurPara = NULL;
+ std::list< Element* >::iterator page_element, next_page_element;
+ next_page_element = elem.Children.begin();
+ double fCurLineHeight = 0.0; // average height of text items in current para
+ int nCurLineElements = 0; // number of line contributing elements in current para
+ double line_left = elem.w, line_right = 0.0;
+ double column_width = elem.w*0.75; // estimate text width
+ // TODO: guess columns
+ while( next_page_element != elem.Children.end() )
+ {
+ page_element = next_page_element++;
+ ParagraphElement* pPagePara = dynamic_cast<ParagraphElement*>(*page_element);
+ if( pPagePara )
+ {
+ pCurPara = pPagePara;
+ // adjust line height and text items
+ fCurLineHeight = 0.0;
+ nCurLineElements = 0;
+ for( std::list< Element* >::iterator it = pCurPara->Children.begin();
+ it != pCurPara->Children.end(); ++it )
+ {
+ TextElement* pTestText = dynamic_cast<TextElement*>(*it);
+ if( pTestText )
+ {
+ fCurLineHeight = (fCurLineHeight*double(nCurLineElements) + pTestText->h)/double(nCurLineElements+1);
+ nCurLineElements++;
+ }
+ }
+ continue;
+ }
+
+ HyperlinkElement* pLink = dynamic_cast<HyperlinkElement*>(*page_element);
+ DrawElement* pDraw = dynamic_cast<DrawElement*>(*page_element);
+ if( ! pDraw && pLink && ! pLink->Children.empty() )
+ pDraw = dynamic_cast<DrawElement*>(pLink->Children.front() );
+ if( pDraw )
+ {
+ // insert small drawing objects as character, else leave them page bound
+
+ bool bInsertToParagraph = false;
+ // first check if this is either inside the paragraph
+ if( pCurPara && pDraw->y < pCurPara->y + pCurPara->h )
+ {
+ if( pDraw->h < fCurLineHeight * 1.5 )
+ {
+ bInsertToParagraph = true;
+ fCurLineHeight = (fCurLineHeight*double(nCurLineElements) + pDraw->h)/double(nCurLineElements+1);
+ nCurLineElements++;
+ // mark draw element as character
+ pDraw->isCharacter = true;
+ }
+ }
+ // or perhaps the draw element begins a new paragraph
+ else if( next_page_element != elem.Children.end() )
+ {
+ TextElement* pText = dynamic_cast<TextElement*>(*next_page_element);
+ if( ! pText )
+ {
+ ParagraphElement* pPara = dynamic_cast<ParagraphElement*>(*next_page_element);
+ if( pPara && ! pPara->Children.empty() )
+ pText = dynamic_cast<TextElement*>(pPara->Children.front());
+ }
+ if( pText && // check there is a text
+ pDraw->h < pText->h*1.5 && // and it is approx the same height
+ // and either upper or lower edge of pDraw is inside text's vertical range
+ ( ( pDraw->y >= pText->y && pDraw->y <= pText->y+pText->h ) ||
+ ( pDraw->y+pDraw->h >= pText->y && pDraw->y+pDraw->h <= pText->y+pText->h )
+ )
+ )
+ {
+ bInsertToParagraph = true;
+ fCurLineHeight = pDraw->h;
+ nCurLineElements = 1;
+ line_left = pDraw->x;
+ line_right = pDraw->x + pDraw->w;
+ // begin a new paragraph
+ pCurPara = NULL;
+ // mark draw element as character
+ pDraw->isCharacter = true;
+ }
+ }
+
+ if( ! bInsertToParagraph )
+ {
+ pCurPara = NULL;
+ continue;
+ }
+ }
+
+ TextElement* pText = dynamic_cast<TextElement*>(*page_element);
+ if( ! pText && pLink && ! pLink->Children.empty() )
+ pText = dynamic_cast<TextElement*>(pLink->Children.front());
+ if( pText )
+ {
+ Element* pGeo = pLink ? static_cast<Element*>(pLink) :
+ static_cast<Element*>(pText);
+ if( pCurPara )
+ {
+ // there was already a text element, check for a new paragraph
+ if( nCurLineElements > 0 )
+ {
+ // if the new text is significantly distant from the paragraph
+ // begin a new paragraph
+ if( pGeo->y > pCurPara->y+pCurPara->h + fCurLineHeight*0.5 )
+ pCurPara = NULL; // insert new paragraph
+ else if( pGeo->y > (pCurPara->y+pCurPara->h - fCurLineHeight*0.05) )
+ {
+ // new paragraph if either the last line of the paragraph
+ // was significantly shorter than the paragraph as a whole
+ if( (line_right - line_left) < pCurPara->w*0.75 )
+ pCurPara = NULL;
+ // or the last line was significantly smaller than the column width
+ else if( (line_right - line_left) < column_width*0.75 )
+ pCurPara = NULL;
+ }
+ }
+ }
+ // update line height/width
+ if( pCurPara )
+ {
+ fCurLineHeight = (fCurLineHeight*double(nCurLineElements) + pGeo->h)/double(nCurLineElements+1);
+ nCurLineElements++;
+ if( pGeo->x < line_left )
+ line_left = pGeo->x;
+ if( pGeo->x+pGeo->w > line_right )
+ line_right = pGeo->x+pGeo->w;
+ }
+ else
+ {
+ fCurLineHeight = pGeo->h;
+ nCurLineElements = 1;
+ line_left = pGeo->x;
+ line_right = pGeo->x + pGeo->w;
+ }
+ }
+
+ // move element to current paragraph
+ if( ! pCurPara ) // new paragraph, insert one
+ {
+ pCurPara = m_rProcessor.getElementFactory()->createParagraphElement( NULL );
+ // set parent
+ pCurPara->Parent = &elem;
+ //insert new paragraph before current element
+ page_element = elem.Children.insert( page_element, pCurPara );
+ // forward iterator to current element again
+ ++ page_element;
+ // update next_element which is now invalid
+ next_page_element = page_element;
+ ++ next_page_element;
+ }
+ Element* pCurEle = *page_element;
+ pCurEle->setParent( page_element, pCurPara );
+ OSL_ENSURE( !pText || pCurEle == pText || pCurEle == pLink, "paragraph child list in disorder" );
+ if( pText || pDraw )
+ pCurPara->updateGeometryWith( pCurEle );
+ }
+
+ // process children
+ elem.applyToChildren(*this);
+
+ // find possible header and footer
+ checkHeaderAndFooter( elem );
+}
+
+void WriterXmlOptimizer::checkHeaderAndFooter( PageElement& rElem )
+{
+ /* indicators for a header:
+ * - single line paragrah at top of page ( inside 15% page height)
+ * - at least linheight above the next paragr aph
+ *
+ * indicators for a footer likewise:
+ * - single line paragraph at bottom of page (inside 15% page height)
+ * - at least lineheight below the previous paragraph
+ */
+
+ // detect header
+ // Note: the following assumes that the pages' chiuldren have been
+ // sorted geometrically
+ std::list< Element* >::iterator it = rElem.Children.begin();
+ while( it != rElem.Children.end() )
+ {
+ ParagraphElement* pPara = dynamic_cast<ParagraphElement*>(*it);
+ if( pPara )
+ {
+ if( pPara->y+pPara->h < rElem.h*0.15 && pPara->isSingleLined( m_rProcessor ) )
+ {
+ std::list< Element* >::iterator next_it = it;
+ ParagraphElement* pNextPara = NULL;
+ while( ++next_it != rElem.Children.end() && pNextPara == NULL )
+ {
+ pNextPara = dynamic_cast<ParagraphElement*>(*next_it);
+ }
+ if( pNextPara && pNextPara->y > pPara->y+pPara->h*2 )
+ {
+ rElem.HeaderElement = pPara;
+ pPara->Parent = NULL;
+ rElem.Children.remove( pPara );
+ }
+ }
+ break;
+ }
+ ++it;
+ }
+
+ // detect footer
+ std::list< Element* >::reverse_iterator rit = rElem.Children.rbegin();
+ while( rit != rElem.Children.rend() )
+ {
+ ParagraphElement* pPara = dynamic_cast<ParagraphElement*>(*rit);
+ if( pPara )
+ {
+ if( pPara->y > rElem.h*0.85 && pPara->isSingleLined( m_rProcessor ) )
+ {
+ std::list< Element* >::reverse_iterator next_it = rit;
+ ParagraphElement* pNextPara = NULL;
+ while( ++next_it != rElem.Children.rend() && pNextPara == NULL )
+ {
+ pNextPara = dynamic_cast<ParagraphElement*>(*next_it);
+ }
+ if( pNextPara && pNextPara->y < pPara->y-pPara->h*2 )
+ {
+ rElem.FooterElement = pPara;
+ pPara->Parent = NULL;
+ rElem.Children.remove( pPara );
+ }
+ }
+ break;
+ }
+ ++rit;
+ }
+}
+
+void WriterXmlOptimizer::optimizeTextElements(Element& rParent)
+{
+ if( rParent.Children.empty() ) // this should not happen
+ {
+ OSL_FAIL( "empty paragraph optimized" );
+ return;
+ }
+
+ // concatenate child elements with same font id
+ std::list< Element* >::iterator next = rParent.Children.begin();
+ std::list< Element* >::iterator it = next++;
+ FrameElement* pFrame = dynamic_cast<FrameElement*>(rParent.Parent);
+ bool bRotatedFrame = false;
+ if( pFrame )
+ {
+ const GraphicsContext& rFrameGC = m_rProcessor.getGraphicsContext( pFrame->GCId );
+ if( rFrameGC.isRotatedOrSkewed() )
+ bRotatedFrame = true;
+ }
+ while( next != rParent.Children.end() )
+ {
+ bool bConcat = false;
+ TextElement* pCur = dynamic_cast<TextElement*>(*it);
+ if( pCur )
+ {
+ TextElement* pNext = dynamic_cast<TextElement*>(*next);
+ if( pNext )
+ {
+ const GraphicsContext& rCurGC = m_rProcessor.getGraphicsContext( pCur->GCId );
+ const GraphicsContext& rNextGC = m_rProcessor.getGraphicsContext( pNext->GCId );
+
+ // line and space optimization; works only in strictly horizontal mode
+
+ if( !bRotatedFrame
+ && ! rCurGC.isRotatedOrSkewed()
+ && ! rNextGC.isRotatedOrSkewed()
+ && pNext->Text.charAt( 0 ) != sal_Unicode(' ')
+ && pCur->Text.getLength() > 0
+ && pCur->Text.charAt( pCur->Text.getLength()-1 ) != sal_Unicode(' ')
+ )
+ {
+ // check for new line in paragraph
+ if( pNext->y > pCur->y+pCur->h )
+ {
+ // new line begins
+ // check whether a space would should be inserted or a hyphen removed
+ sal_Unicode aLastCode = pCur->Text.charAt( pCur->Text.getLength()-1 );
+ if( aLastCode == '-'
+ || aLastCode == 0x2010
+ || (aLastCode >= 0x2012 && aLastCode <= 0x2015)
+ || aLastCode == 0xff0d
+ )
+ {
+ // cut a hyphen
+ pCur->Text.setLength( pCur->Text.getLength()-1 );
+ }
+ // append a space unless there is a non breaking hyphen
+ else if( aLastCode != 0x2011 )
+ {
+ pCur->Text.append( sal_Unicode( ' ' ) );
+ }
+ }
+ else // we're continuing the same line
+ {
+ // check whether a space would should be inserted
+ // check for a small horizontal offset
+ if( pCur->x + pCur->w + pNext->h*0.15 < pNext->x )
+ {
+ pCur->Text.append( sal_Unicode(' ') );
+ }
+ }
+ }
+ // concatenate consecutive text elements unless there is a
+ // font or text color or matrix change, leave a new span in that case
+ if( pCur->FontId == pNext->FontId &&
+ rCurGC.FillColor.Red == rNextGC.FillColor.Red &&
+ rCurGC.FillColor.Green == rNextGC.FillColor.Green &&
+ rCurGC.FillColor.Blue == rNextGC.FillColor.Blue &&
+ rCurGC.FillColor.Alpha == rNextGC.FillColor.Alpha &&
+ rCurGC.Transformation == rNextGC.Transformation
+ )
+ {
+ pCur->updateGeometryWith( pNext );
+ // append text to current element
+ pCur->Text.append( pNext->Text.getStr(), pNext->Text.getLength() );
+ // append eventual children to current element
+ // and clear children (else the children just
+ // appended to pCur would be destroyed)
+ pCur->Children.splice( pCur->Children.end(), pNext->Children );
+ // get rid of the now useless element
+ rParent.Children.erase( next );
+ delete pNext;
+ bConcat = true;
+ }
+ }
+ }
+ else if( dynamic_cast<HyperlinkElement*>(*it) )
+ optimizeTextElements( **it );
+ if( bConcat )
+ {
+ next = it;
+ ++next;
+ }
+ else
+ {
+ ++it;
+ ++next;
+ }
+ }
+}
+
+void WriterXmlOptimizer::visit( DocumentElement& elem, const std::list< Element* >::const_iterator&)
+{
+ elem.applyToChildren(*this);
+}
+
+//////////////////////////////////////////////////////////////////////////////////
+
+
+void WriterXmlFinalizer::visit( PolyPolyElement& elem, const std::list< Element* >::const_iterator& )
+{
+ // xxx TODO copied from DrawElement
+ const GraphicsContext& rGC = m_rProcessor.getGraphicsContext(elem.GCId );
+ PropertyMap aProps;
+ aProps[ USTR( "style:family" ) ] = USTR( "graphic" );
+
+ PropertyMap aGCProps;
+
+ // TODO(F3): proper dash emulation
+ if( elem.Action & PATH_STROKE )
+ {
+ aGCProps[ USTR("draw:stroke") ] = rGC.DashArray.empty() ? USTR("solid") : USTR("dash");
+ aGCProps[ USTR("svg:stroke-color") ] = getColorString( rGC.LineColor );
+ if( rGC.LineWidth != 0.0 )
+ {
+ ::basegfx::B2DVector aVec(rGC.LineWidth,0);
+ aVec *= rGC.Transformation;
+
+ aVec.setX ( convPx2mmPrec2( aVec.getX() )*100.0 );
+ aVec.setY ( convPx2mmPrec2( aVec.getY() )*100.0 );
+
+ aGCProps[ USTR("svg:stroke-width") ] = rtl::OUString::valueOf( aVec.getLength() );
+ }
+ }
+ else
+ {
+ aGCProps[ USTR("draw:stroke") ] = USTR("none");
+ }
+
+ // TODO(F1): check whether stuff could be emulated by gradient/bitmap/hatch
+ if( elem.Action & (PATH_FILL | PATH_EOFILL) )
+ {
+ aGCProps[ USTR("draw:fill") ] = USTR("solid");
+ aGCProps[ USTR("draw:fill-color") ] = getColorString( rGC.FillColor );
+ }
+ else
+ {
+ aGCProps[ USTR("draw:fill") ] = USTR("none");
+ }
+
+ StyleContainer::Style aStyle( "style:style", aProps );
+ StyleContainer::Style aSubStyle( "style:graphic-properties", aGCProps );
+ aStyle.SubStyles.push_back( &aSubStyle );
+
+ elem.StyleId = m_rStyleContainer.getStyleId( aStyle );
+}
+
+void WriterXmlFinalizer::visit( HyperlinkElement&, const std::list< Element* >::const_iterator& )
+{
+}
+
+void WriterXmlFinalizer::visit( TextElement& elem, const std::list< Element* >::const_iterator& )
+{
+ const FontAttributes& rFont = m_rProcessor.getFont( elem.FontId );
+ PropertyMap aProps;
+ aProps[ USTR( "style:family" ) ] = USTR( "text" );
+
+ PropertyMap aFontProps;
+
+ // family name
+ aFontProps[ USTR( "fo:font-family" ) ] = rFont.familyName;
+ // bold
+ if( rFont.isBold )
+ {
+ aFontProps[ USTR( "fo:font-weight" ) ] = USTR( "bold" );
+ aFontProps[ USTR( "fo:font-weight-asian" ) ] = USTR( "bold" );
+ aFontProps[ USTR( "fo:font-weight-complex" ) ] = USTR( "bold" );
+ }
+ // italic
+ if( rFont.isItalic )
+ {
+ aFontProps[ USTR( "fo:font-style" ) ] = USTR( "italic" );
+ aFontProps[ USTR( "fo:font-style-asian" ) ] = USTR( "italic" );
+ aFontProps[ USTR( "fo:font-style-complex" ) ] = USTR( "italic" );
+ }
+ // underline
+ if( rFont.isUnderline )
+ {
+ aFontProps[ USTR( "style:text-underline-style" ) ] = USTR( "solid" );
+ aFontProps[ USTR( "style:text-underline-width" ) ] = USTR( "auto" );
+ aFontProps[ USTR( "style:text-underline-color" ) ] = USTR( "font-color" );
+ }
+ // outline
+ if( rFont.isOutline )
+ {
+ aFontProps[ USTR( "style:text-outline" ) ] = USTR( "true" );
+ }
+ // size
+ rtl::OUStringBuffer aBuf( 32 );
+ aBuf.append( rFont.size*72/PDFI_OUTDEV_RESOLUTION );
+ aBuf.appendAscii( "pt" );
+ rtl::OUString aFSize = aBuf.makeStringAndClear();
+ aFontProps[ USTR( "fo:font-size" ) ] = aFSize;
+ aFontProps[ USTR( "style:font-size-asian" ) ] = aFSize;
+ aFontProps[ USTR( "style:font-size-complex" ) ] = aFSize;
+ // color
+ const GraphicsContext& rGC = m_rProcessor.getGraphicsContext( elem.GCId );
+ aFontProps[ USTR( "fo:color" ) ] = getColorString( rFont.isOutline ? rGC.LineColor : rGC.FillColor );
+
+ StyleContainer::Style aStyle( "style:style", aProps );
+ StyleContainer::Style aSubStyle( "style:text-properties", aFontProps );
+ aStyle.SubStyles.push_back( &aSubStyle );
+ elem.StyleId = m_rStyleContainer.getStyleId( aStyle );
+}
+
+void WriterXmlFinalizer::visit( ParagraphElement& elem, const std::list< Element* >::const_iterator& rParentIt )
+{
+ PropertyMap aParaProps;
+
+ if( elem.Parent )
+ {
+ // check for center alignement
+ // criterion: paragraph is small relative to parent and distributed around its center
+ double p_x = elem.Parent->x;
+ double p_y = elem.Parent->y;
+ double p_w = elem.Parent->w;
+ double p_h = elem.Parent->h;
+
+ PageElement* pPage = dynamic_cast<PageElement*>(elem.Parent);
+ if( pPage )
+ {
+ p_x += pPage->LeftMargin;
+ p_y += pPage->TopMargin;
+ p_w -= pPage->LeftMargin+pPage->RightMargin;
+ p_h -= pPage->TopMargin+pPage->BottomMargin;
+ }
+ bool bIsCenter = false;
+ if( elem.w < ( p_w/2) )
+ {
+ double delta = elem.w/4;
+ // allow very small paragraphs to deviate a little more
+ // relative to parent's center
+ if( elem.w < p_w/8 )
+ delta = elem.w;
+ if( fabs( elem.x+elem.w/2 - ( p_x+ p_w/2) ) < delta ||
+ (pPage && fabs( elem.x+elem.w/2 - (pPage->x + pPage->w/2) ) < delta) )
+ {
+ bIsCenter = true;
+ aParaProps[ USTR( "fo:text-align" ) ] = USTR( "center" );
+ }
+ }
+ if( ! bIsCenter && elem.x > p_x + p_w/10 )
+ {
+ // indent
+ rtl::OUStringBuffer aBuf( 32 );
+ aBuf.append( convPx2mm( elem.x - p_x ) );
+ aBuf.appendAscii( "mm" );
+ aParaProps[ USTR( "fo:margin-left" ) ] = aBuf.makeStringAndClear();
+ }
+
+ // check whether to leave some space to next paragraph
+ // find wether there is a next paragraph
+ std::list< Element* >::const_iterator it = rParentIt;
+ const ParagraphElement* pNextPara = NULL;
+ while( ++it != elem.Parent->Children.end() && ! pNextPara )
+ pNextPara = dynamic_cast< const ParagraphElement* >(*it);
+ if( pNextPara )
+ {
+ if( pNextPara->y - (elem.y+elem.h) > convmm2Px( 10 ) )
+ {
+ rtl::OUStringBuffer aBuf( 32 );
+ aBuf.append( convPx2mm( pNextPara->y - (elem.y+elem.h) ) );
+ aBuf.appendAscii( "mm" );
+ aParaProps[ USTR( "fo:margin-bottom" ) ] = aBuf.makeStringAndClear();
+ }
+ }
+ }
+
+ if( ! aParaProps.empty() )
+ {
+ PropertyMap aProps;
+ aProps[ USTR( "style:family" ) ] = USTR( "paragraph" );
+ StyleContainer::Style aStyle( "style:style", aProps );
+ StyleContainer::Style aSubStyle( "style:paragraph-properties", aParaProps );
+ aStyle.SubStyles.push_back( &aSubStyle );
+ elem.StyleId = m_rStyleContainer.getStyleId( aStyle );
+ }
+
+ elem.applyToChildren(*this);
+}
+
+void WriterXmlFinalizer::visit( FrameElement& elem, const std::list< Element* >::const_iterator&)
+{
+ PropertyMap aProps;
+ aProps[ USTR( "style:family" ) ] = USTR( "graphic" );
+
+ PropertyMap aGCProps;
+
+ aGCProps[ USTR("draw:stroke") ] = USTR("none");
+ aGCProps[ USTR("draw:fill") ] = USTR("none");
+
+ StyleContainer::Style aStyle( "style:style", aProps );
+ StyleContainer::Style aSubStyle( "style:graphic-properties", aGCProps );
+ aStyle.SubStyles.push_back( &aSubStyle );
+
+ elem.StyleId = m_rStyleContainer.getStyleId( aStyle );
+ elem.applyToChildren(*this);
+}
+
+void WriterXmlFinalizer::visit( ImageElement&, const std::list< Element* >::const_iterator& )
+{
+}
+
+void WriterXmlFinalizer::setFirstOnPage( ParagraphElement& rElem,
+ StyleContainer& rStyles,
+ const rtl::OUString& rMasterPageName )
+{
+ PropertyMap aProps;
+ if( rElem.StyleId != -1 )
+ {
+ const PropertyMap* pProps = rStyles.getProperties( rElem.StyleId );
+ if( pProps )
+ aProps = *pProps;
+ }
+
+ aProps[ USTR( "style:family" ) ] = USTR( "paragraph" );
+ aProps[ USTR( "style:master-page-name" ) ] = rMasterPageName;
+
+ if( rElem.StyleId != -1 )
+ rElem.StyleId = rStyles.setProperties( rElem.StyleId, aProps );
+ else
+ {
+ StyleContainer::Style aStyle( "style:style", aProps );
+ rElem.StyleId = rStyles.getStyleId( aStyle );
+ }
+}
+
+void WriterXmlFinalizer::visit( PageElement& elem, const std::list< Element* >::const_iterator& )
+{
+ if( m_rProcessor.getStatusIndicator().is() )
+ m_rProcessor.getStatusIndicator()->setValue( elem.PageNumber );
+
+ // transform from pixel to mm
+ double page_width = convPx2mm( elem.w ), page_height = convPx2mm( elem.h );
+
+ // calculate page margins out of the relevant children (paragraphs)
+ elem.TopMargin = elem.h, elem.BottomMargin = 0, elem.LeftMargin = elem.w, elem.RightMargin = 0;
+ // first element should be a paragraphy
+ ParagraphElement* pFirstPara = NULL;
+ for( std::list< Element* >::const_iterator it = elem.Children.begin(); it != elem.Children.end(); ++it )
+ {
+ if( dynamic_cast<ParagraphElement*>( *it ) )
+ {
+ if( (*it)->x < elem.LeftMargin )
+ elem.LeftMargin = (*it)->x;
+ if( (*it)->y < elem.TopMargin )
+ elem.TopMargin = (*it)->y;
+ if( (*it)->x + (*it)->w > elem.w - elem.RightMargin )
+ elem.RightMargin = elem.w - ((*it)->x + (*it)->w);
+ if( (*it)->y + (*it)->h > elem.h - elem.BottomMargin )
+ elem.BottomMargin = elem.h - ((*it)->y + (*it)->h);
+ if( ! pFirstPara )
+ pFirstPara = dynamic_cast<ParagraphElement*>( *it );
+ }
+ }
+ if( elem.HeaderElement && elem.HeaderElement->y < elem.TopMargin )
+ elem.TopMargin = elem.HeaderElement->y;
+ if( elem.FooterElement && elem.FooterElement->y+elem.FooterElement->h > elem.h - elem.BottomMargin )
+ elem.BottomMargin = elem.h - (elem.FooterElement->y + elem.FooterElement->h);
+
+ // transform margins to mm
+ double left_margin = convPx2mm( elem.LeftMargin );
+ double right_margin = convPx2mm( elem.RightMargin );
+ double top_margin = convPx2mm( elem.TopMargin );
+ double bottom_margin = convPx2mm( elem.BottomMargin );
+ if( ! pFirstPara )
+ {
+ // use default page margins
+ left_margin = 10;
+ right_margin = 10;
+ top_margin = 10;
+ bottom_margin = 10;
+ }
+
+ // round left/top margin to nearest mm
+ left_margin = rtl_math_round( left_margin, 0, rtl_math_RoundingMode_Floor );
+ top_margin = rtl_math_round( top_margin, 0, rtl_math_RoundingMode_Floor );
+ // round (fuzzy) right/bottom margin to nearest cm
+ right_margin = rtl_math_round( right_margin, right_margin >= 10 ? -1 : 0, rtl_math_RoundingMode_Floor );
+ bottom_margin = rtl_math_round( bottom_margin, bottom_margin >= 10 ? -1 : 0, rtl_math_RoundingMode_Floor );
+
+ // set reasonable default in case of way too large margins
+ // e.g. no paragraph case
+ if( left_margin > page_width/2.0 - 10 )
+ left_margin = 10;
+ if( right_margin > page_width/2.0 - 10 )
+ right_margin = 10;
+ if( top_margin > page_height/2.0 - 10 )
+ top_margin = 10;
+ if( bottom_margin > page_height/2.0 - 10 )
+ bottom_margin = 10;
+
+ // catch the weird cases
+ if( left_margin < 0 )
+ left_margin = 0;
+ if( right_margin < 0 )
+ right_margin = 0;
+ if( top_margin < 0 )
+ top_margin = 0;
+ if( bottom_margin < 0 )
+ bottom_margin = 0;
+
+ // widely differing margins are unlikely to be correct
+ if( right_margin > left_margin*1.5 )
+ right_margin = left_margin;
+
+ elem.LeftMargin = convmm2Px( left_margin );
+ elem.RightMargin = convmm2Px( right_margin );
+ elem.TopMargin = convmm2Px( top_margin );
+ elem.BottomMargin = convmm2Px( bottom_margin );
+
+ // get styles for paragraphs
+ PropertyMap aPageProps;
+ PropertyMap aPageLayoutProps;
+ rtl::OUStringBuffer aBuf( 64 );
+ aPageLayoutProps[ USTR( "fo:page-width" ) ] = unitMMString( page_width );
+ aPageLayoutProps[ USTR( "fo:page-height" ) ] = unitMMString( page_height );
+ aPageLayoutProps[ USTR( "style:print-orientation" ) ]
+ = elem.w < elem.h ? USTR( "portrait" ) : USTR( "landscape" );
+ aPageLayoutProps[ USTR( "fo:margin-top" ) ] = unitMMString( top_margin );
+ aPageLayoutProps[ USTR( "fo:margin-bottom" ) ] = unitMMString( bottom_margin );
+ aPageLayoutProps[ USTR( "fo:margin-left" ) ] = unitMMString( left_margin );
+ aPageLayoutProps[ USTR( "fo:margin-right" ) ] = unitMMString( right_margin );
+ aPageLayoutProps[ USTR( "style:writing-mode" ) ]= USTR( "lr-tb" );
+
+ StyleContainer::Style aStyle( "style:page-layout", aPageProps);
+ StyleContainer::Style aSubStyle( "style:page-layout-properties", aPageLayoutProps);
+ aStyle.SubStyles.push_back(&aSubStyle);
+ sal_Int32 nPageStyle = m_rStyleContainer.impl_getStyleId( aStyle, false );
+
+ // create master page
+ rtl::OUString aMasterPageLayoutName = m_rStyleContainer.getStyleName( nPageStyle );
+ aPageProps[ USTR( "style:page-layout-name" ) ] = aMasterPageLayoutName;
+ StyleContainer::Style aMPStyle( "style:master-page", aPageProps );
+ StyleContainer::Style aHeaderStyle( "style:header", PropertyMap() );
+ StyleContainer::Style aFooterStyle( "style:footer", PropertyMap() );
+ if( elem.HeaderElement )
+ {
+ elem.HeaderElement->visitedBy( *this, std::list<Element*>::iterator() );
+ aHeaderStyle.ContainedElement = elem.HeaderElement;
+ aMPStyle.SubStyles.push_back( &aHeaderStyle );
+ }
+ if( elem.FooterElement )
+ {
+ elem.FooterElement->visitedBy( *this, std::list<Element*>::iterator() );
+ aFooterStyle.ContainedElement = elem.FooterElement;
+ aMPStyle.SubStyles.push_back( &aFooterStyle );
+ }
+ elem.StyleId = m_rStyleContainer.impl_getStyleId( aMPStyle,false );
+
+
+ rtl::OUString aMasterPageName = m_rStyleContainer.getStyleName( elem.StyleId );
+
+ // create styles for children
+ elem.applyToChildren(*this);
+
+ // no paragraph or other elements before the first paragraph
+ if( ! pFirstPara )
+ {
+ pFirstPara = m_rProcessor.getElementFactory()->createParagraphElement( NULL );
+ pFirstPara->Parent = &elem;
+ elem.Children.push_front( pFirstPara );
+ }
+ setFirstOnPage(*pFirstPara, m_rStyleContainer, aMasterPageName);
+}
+
+void WriterXmlFinalizer::visit( DocumentElement& elem, const std::list< Element* >::const_iterator& )
+{
+ elem.applyToChildren(*this);
+}
+
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sdext/source/pdfimport/tree/writertreevisiting.hxx b/sdext/source/pdfimport/tree/writertreevisiting.hxx
new file mode 100644
index 000000000000..b280b6aa011a
--- /dev/null
+++ b/sdext/source/pdfimport/tree/writertreevisiting.hxx
@@ -0,0 +1,119 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+#ifndef INCLUDED_PDFI_WRITERTREEVISITING_HXX
+#define INCLUDED_PDFI_WRITERTREEVISITING_HXX
+
+#include "treevisiting.hxx"
+
+namespace pdfi
+{
+ struct DrawElement;
+
+ class WriterXmlOptimizer : public ElementTreeVisitor
+ {
+ private:
+ PDFIProcessor& m_rProcessor;
+ void optimizeTextElements(Element& rParent);
+ void checkHeaderAndFooter( PageElement& rElem );
+
+ public:
+ explicit WriterXmlOptimizer(PDFIProcessor& rProcessor) :
+ m_rProcessor(rProcessor)
+ {}
+ virtual ~WriterXmlOptimizer()
+ {}
+
+ virtual void visit( HyperlinkElement&, const std::list< Element* >::const_iterator& );
+ virtual void visit( TextElement&, const std::list< Element* >::const_iterator& );
+ virtual void visit( ParagraphElement&, const std::list< Element* >::const_iterator& );
+ virtual void visit( FrameElement&, const std::list< Element* >::const_iterator& );
+ virtual void visit( PolyPolyElement&, const std::list< Element* >::const_iterator& );
+ virtual void visit( ImageElement&, const std::list< Element* >::const_iterator& );
+ virtual void visit( PageElement&, const std::list< Element* >::const_iterator& );
+ virtual void visit( DocumentElement&, const std::list< Element* >::const_iterator& );
+ };
+
+ class WriterXmlFinalizer : public ElementTreeVisitor
+ {
+ private:
+ StyleContainer& m_rStyleContainer;
+ PDFIProcessor& m_rProcessor;
+
+ void setFirstOnPage( ParagraphElement& rElem,
+ StyleContainer& rStyles,
+ const rtl::OUString& rMasterPageName );
+
+ public:
+ explicit WriterXmlFinalizer(StyleContainer& rStyleContainer,
+ PDFIProcessor& rProcessor) :
+ m_rStyleContainer(rStyleContainer),
+ m_rProcessor(rProcessor)
+ {}
+ virtual ~WriterXmlFinalizer()
+ {}
+
+ virtual void visit( HyperlinkElement&, const std::list< Element* >::const_iterator& );
+ virtual void visit( TextElement&, const std::list< Element* >::const_iterator& );
+ virtual void visit( ParagraphElement&, const std::list< Element* >::const_iterator& );
+ virtual void visit( FrameElement&, const std::list< Element* >::const_iterator& );
+ virtual void visit( PolyPolyElement&, const std::list< Element* >::const_iterator& );
+ virtual void visit( ImageElement&, const std::list< Element* >::const_iterator& );
+ virtual void visit( PageElement&, const std::list< Element* >::const_iterator& );
+ virtual void visit( DocumentElement&, const std::list< Element* >::const_iterator& );
+ };
+
+ class WriterXmlEmitter : public ElementTreeVisitor
+ {
+ private:
+ EmitContext& m_rEmitContext ;
+ void fillFrameProps( DrawElement& rElem,
+ PropertyMap& rProps,
+ const EmitContext& rEmitContext );
+
+ public:
+ explicit WriterXmlEmitter(EmitContext& rEmitContext) :
+ m_rEmitContext(rEmitContext)
+ {}
+ virtual ~WriterXmlEmitter()
+ {}
+
+ virtual void visit( HyperlinkElement&, const std::list< Element* >::const_iterator& );
+ virtual void visit( TextElement&, const std::list< Element* >::const_iterator& );
+ virtual void visit( ParagraphElement&, const std::list< Element* >::const_iterator& );
+ virtual void visit( FrameElement&, const std::list< Element* >::const_iterator& );
+ virtual void visit( PolyPolyElement&, const std::list< Element* >::const_iterator& );
+ virtual void visit( ImageElement&, const std::list< Element* >::const_iterator& );
+ virtual void visit( PageElement&, const std::list< Element* >::const_iterator& );
+ virtual void visit( DocumentElement&, const std::list< Element* >::const_iterator& );
+ };
+}
+
+#endif
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */