[Libreoffice-commits] .: 2 commits - svx/source xmloff/inc xmloff/source
Fridrich Strba
fridrich at kemper.freedesktop.org
Wed Jun 22 03:55:54 PDT 2011
svx/source/customshapes/EnhancedCustomShapeEngine.cxx | 5
svx/source/inc/unopolyhelper.hxx | 57 -
svx/source/svdraw/svdoashp.cxx | 4
svx/source/unodraw/XPropertyTable.cxx | 7
svx/source/unodraw/unoshap2.cxx | 177 ---
svx/source/unodraw/unoshape.cxx | 6
svx/source/xoutdev/xattr.cxx | 10
xmloff/inc/xexptran.hxx | 12
xmloff/source/draw/xexptran.cxx | 990 ------------------
9 files changed, 73 insertions(+), 1195 deletions(-)
New commits:
commit 3768ced8096af7ff6a50c89b2cae8694684d586c
Author: Fridrich Å trba <fridrich.strba at bluewin.ch>
Date: Tue Jun 21 23:08:11 2011 +0200
Avoid division by zero with paths that are vertical or horizontal lines
diff --git a/xmloff/source/draw/xexptran.cxx b/xmloff/source/draw/xexptran.cxx
index 2147391..4cbccfe 100644
--- a/xmloff/source/draw/xexptran.cxx
+++ b/xmloff/source/draw/xexptran.cxx
@@ -2199,8 +2199,8 @@ SdXMLImExSvgDElement::SdXMLImExSvgDElement(const OUString& rNew,
-mrViewBox.GetY());
if( bScale )
aTransform.scale(
- rObjectSize.Width / mrViewBox.GetWidth(),
- rObjectSize.Height / mrViewBox.GetHeight());
+ (mrViewBox.GetWidth() ? rObjectSize.Width / mrViewBox.GetWidth() : 0),
+ (mrViewBox.GetHeight() ? rObjectSize.Height / mrViewBox.GetHeight() : 0));
aTransform.translate( rObjectPos.X, rObjectPos.Y );
aPoly.transform(aTransform);
commit e91a874a06aefba9771a72584347e8274e4d7ccf
Author: Thorsten Behrens <tbehrens at novell.com>
Date: Tue Jun 21 09:11:28 2011 +0200
Teach LibreOffice proper svg:d support
diff --git a/svx/source/customshapes/EnhancedCustomShapeEngine.cxx b/svx/source/customshapes/EnhancedCustomShapeEngine.cxx
index b8e557e..8b8ee6a 100644
--- a/svx/source/customshapes/EnhancedCustomShapeEngine.cxx
+++ b/svx/source/customshapes/EnhancedCustomShapeEngine.cxx
@@ -49,9 +49,9 @@
#include <svx/svdpage.hxx>
#include <svx/svdmodel.hxx>
#include "svx/svditer.hxx"
-#include "unopolyhelper.hxx"
#include <uno/mapping.hxx>
#include <basegfx/polygon/b2dpolypolygontools.hxx>
+#include <basegfx/tools/unotools.hxx>
#include <com/sun/star/document/XActionLockable.hpp>
// ---------------------------
@@ -446,7 +446,8 @@ com::sun::star::drawing::PolyPolygonBezierCoords SAL_CALL EnhancedCustomShapeEng
SdrObject::Free( pNewObj );
}
SdrObject::Free( pObj );
- SvxConvertB2DPolyPolygonToPolyPolygonBezier( aPolyPolygon, aPolyPolygonBezierCoords );
+ basegfx::unotools::b2DPolyPolygonToPolyPolygonBezier( aPolyPolygon,
+ aPolyPolygonBezierCoords );
}
}
diff --git a/svx/source/inc/unopolyhelper.hxx b/svx/source/inc/unopolyhelper.hxx
deleted file mode 100644
index c682f34..0000000
--- a/svx/source/inc/unopolyhelper.hxx
+++ /dev/null
@@ -1,57 +0,0 @@
-/* -*- 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 _SVX_UNOPOLYHELPER_HXX
-#define _SVX_UNOPOLYHELPER_HXX
-
-#include <com/sun/star/lang/IllegalArgumentException.hpp>
-
-#include <svx/svxdllapi.h>
-
-namespace com { namespace sun { namespace star { namespace drawing {
- struct PolyPolygonBezierCoords;
-} } } }
-
-namespace basegfx {
- class B2DPolyPolygon;
-}
-
-/** convert a drawing::PolyPolygonBezierCoords to a B2DPolyPolygon
-*/
-basegfx::B2DPolyPolygon SvxConvertPolyPolygonBezierToB2DPolyPolygon( const com::sun::star::drawing::PolyPolygonBezierCoords* pSourcePolyPolygon)
- throw( com::sun::star::lang::IllegalArgumentException );
-
-/** convert a B2DPolyPolygon to a drawing::PolyPolygonBezierCoords
-*/
-SVX_DLLPUBLIC void SvxConvertB2DPolyPolygonToPolyPolygonBezier( const basegfx::B2DPolyPolygon& rPolyPoly, com::sun::star::drawing::PolyPolygonBezierCoords& rRetval );
-
-
-#endif
-
-
-/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/svx/source/svdraw/svdoashp.cxx b/svx/source/svdraw/svdoashp.cxx
index 9283eb1..17e7f83 100644
--- a/svx/source/svdraw/svdoashp.cxx
+++ b/svx/source/svdraw/svdoashp.cxx
@@ -42,7 +42,6 @@
#include <com/sun/star/drawing/PolyPolygonBezierCoords.hpp>
#include <com/sun/star/beans/PropertyValue.hpp>
#include <com/sun/star/awt/Rectangle.hpp>
-#include "unopolyhelper.hxx"
#include <comphelper/processfactory.hxx>
#include <svl/urihelper.hxx>
#include <com/sun/star/uno/Sequence.h>
@@ -93,6 +92,7 @@
#include <basegfx/polygon/b2dpolypolygontools.hxx>
#include <basegfx/matrix/b2dhommatrix.hxx>
#include <basegfx/matrix/b2dhommatrixtools.hxx>
+#include <basegfx/tools/unotools.hxx>
inline double ImplTwipsToMM(double fVal) { return (fVal * (127.0 / 72.0)); }
inline double ImplMMToTwips(double fVal) { return (fVal * (72.0 / 127.0)); }
@@ -575,7 +575,7 @@ basegfx::B2DPolyPolygon SdrObjCustomShape::GetLineGeometry( const SdrObjCustomSh
com::sun::star::drawing::PolyPolygonBezierCoords aBezierCoords = xCustomShapeEngine->getLineGeometry();
try
{
- aRetval = SvxConvertPolyPolygonBezierToB2DPolyPolygon( &aBezierCoords );
+ aRetval = basegfx::unotools::polyPolygonBezierToB2DPolyPolygon( aBezierCoords );
if ( !bBezierAllowed && aRetval.areControlPointsUsed())
{
aRetval = basegfx::tools::adaptiveSubdivideByAngle(aRetval);
diff --git a/svx/source/unodraw/XPropertyTable.cxx b/svx/source/unodraw/XPropertyTable.cxx
index 574b45d..e911bc5 100644
--- a/svx/source/unodraw/XPropertyTable.cxx
+++ b/svx/source/unodraw/XPropertyTable.cxx
@@ -40,12 +40,12 @@
#include <vcl/svapp.hxx>
#include <cppuhelper/implbase2.hxx>
-#include "unopolyhelper.hxx"
#include <svx/xdef.hxx>
#include "svx/unoapi.hxx"
#include <editeng/unoprnms.hxx>
#include <basegfx/polygon/b2dpolygon.hxx>
+#include <basegfx/tools/unotools.hxx>
using namespace com::sun::star;
using namespace ::cppu;
@@ -383,7 +383,8 @@ uno::Any SvxUnoXLineEndTable::getAny( const XPropertyEntry* pEntry ) const throw
uno::Any aAny;
drawing::PolyPolygonBezierCoords aBezier;
- SvxConvertB2DPolyPolygonToPolyPolygonBezier( ((XLineEndEntry*)pEntry)->GetLineEnd(), aBezier );
+ basegfx::unotools::b2DPolyPolygonToPolyPolygonBezier( ((XLineEndEntry*)pEntry)->GetLineEnd(),
+ aBezier );
aAny <<= aBezier;
return aAny;
}
@@ -397,7 +398,7 @@ XPropertyEntry* SvxUnoXLineEndTable::getEntry( const OUString& rName, const uno:
basegfx::B2DPolyPolygon aPolyPolygon;
drawing::PolyPolygonBezierCoords* pCoords = (drawing::PolyPolygonBezierCoords*)rAny.getValue();
if( pCoords->Coordinates.getLength() > 0 )
- aPolyPolygon = SvxConvertPolyPolygonBezierToB2DPolyPolygon( pCoords );
+ aPolyPolygon = basegfx::unotools::polyPolygonBezierToB2DPolyPolygon( *pCoords );
// #86265# make sure polygon is closed
aPolyPolygon.setClosed(true);
diff --git a/svx/source/unodraw/unoshap2.cxx b/svx/source/unodraw/unoshap2.cxx
index f838a95..8da6156 100644
--- a/svx/source/unodraw/unoshap2.cxx
+++ b/svx/source/unodraw/unoshap2.cxx
@@ -62,7 +62,6 @@
#include "shapeimpl.hxx"
#include "svx/unoshprp.hxx"
#include <svx/svdoashp.hxx>
-#include "unopolyhelper.hxx"
// #i29181#
#include "svx/svdviter.hxx"
@@ -71,6 +70,7 @@
#include <basegfx/polygon/b2dpolygon.hxx>
#include <basegfx/point/b2dpoint.hxx>
#include <basegfx/polygon/b2dpolygontools.hxx>
+#include <basegfx/tools/unotools.hxx>
#include <comphelper/servicehelper.hxx>
@@ -1331,132 +1331,6 @@ SvxShapePolyPolygonBezier::~SvxShapePolyPolygonBezier() throw()
{
}
-basegfx::B2DPolyPolygon SvxConvertPolyPolygonBezierToB2DPolyPolygon(const drawing::PolyPolygonBezierCoords* pSourcePolyPolygon)
- throw( IllegalArgumentException )
-{
- const sal_Int32 nOuterSequenceCount(pSourcePolyPolygon->Coordinates.getLength());
- basegfx::B2DPolyPolygon aNewPolyPolygon;
-
- if(pSourcePolyPolygon->Flags.getLength() != nOuterSequenceCount)
- {
- throw IllegalArgumentException();
- }
-
- // get pointers to inner sequence
- const drawing::PointSequence* pInnerSequence = pSourcePolyPolygon->Coordinates.getConstArray();
- const drawing::FlagSequence* pInnerSequenceFlags = pSourcePolyPolygon->Flags.getConstArray();
-
- for(sal_Int32 a(0); a < nOuterSequenceCount; a++)
- {
- const sal_Int32 nInnerSequenceCount(pInnerSequence->getLength());
-
- if(pInnerSequenceFlags->getLength() != nInnerSequenceCount)
- {
- throw IllegalArgumentException();
- }
-
- // prepare new polygon
- basegfx::B2DPolygon aNewPolygon;
- const awt::Point* pArray = pInnerSequence->getConstArray();
- const drawing::PolygonFlags* pArrayFlags = pInnerSequenceFlags->getConstArray();
-
- // get first point and flag
- basegfx::B2DPoint aNewCoordinatePair(pArray->X, pArray->Y); pArray++;
- XPolyFlags ePolyFlag((XPolyFlags)((sal_uInt16)*pArrayFlags)); pArrayFlags++;
- basegfx::B2DPoint aControlA;
- basegfx::B2DPoint aControlB;
-
- // first point is not allowed to be a control point
- if(XPOLY_CONTROL == ePolyFlag)
- {
- throw IllegalArgumentException();
- }
-
- // add first point as start point
- aNewPolygon.append(aNewCoordinatePair);
-
- for(sal_Int32 b(1); b < nInnerSequenceCount;)
- {
- // prepare loop
- bool bControlA(false);
- bool bControlB(false);
-
- // get next point and flag
- aNewCoordinatePair = basegfx::B2DPoint(pArray->X, pArray->Y);
- ePolyFlag = XPolyFlags((XPolyFlags)((sal_uInt16)*pArrayFlags));
- pArray++; pArrayFlags++; b++;
-
- if(b < nInnerSequenceCount && XPOLY_CONTROL == ePolyFlag)
- {
- aControlA = aNewCoordinatePair;
- bControlA = true;
-
- // get next point and flag
- aNewCoordinatePair = basegfx::B2DPoint(pArray->X, pArray->Y);
- ePolyFlag = XPolyFlags((XPolyFlags)((sal_uInt16)*pArrayFlags));
- pArray++; pArrayFlags++; b++;
- }
-
- if(b < nInnerSequenceCount && XPOLY_CONTROL == ePolyFlag)
- {
- aControlB = aNewCoordinatePair;
- bControlB = true;
-
- // get next point and flag
- aNewCoordinatePair = basegfx::B2DPoint(pArray->X, pArray->Y);
- ePolyFlag = XPolyFlags((XPolyFlags)((sal_uInt16)*pArrayFlags));
- pArray++; pArrayFlags++; b++;
- }
-
- // two or no control points are consumed, another one would be an error.
- // It's also an error if only one control point was read
- if(XPOLY_CONTROL == ePolyFlag || bControlA != bControlB)
- {
- throw IllegalArgumentException();
- }
-
- // the previous writes used the B2DPolyPoygon -> PolyPolygon converter
- // which did not create minimal PolyPolygons, but created all control points
- // as null vectors (identical points). Because of the former P(CA)(CB)-norm of
- // B2DPolygon and it's unused sign of being the zero-vector and CA and CB being
- // relative to P, an empty edge was exported as P == CA == CB. Luckily, the new
- // export format can be read without errors by the old OOo-versions, so we need only
- // to correct here at read and do not need to export a wrong but compatible version
- // for the future.
- if(bControlA
- && aControlA.equal(aControlB)
- && aControlA.equal(aNewPolygon.getB2DPoint(aNewPolygon.count() - 1)))
- {
- bControlA = bControlB = false;
- }
-
- if(bControlA)
- {
- // add bezier edge
- aNewPolygon.appendBezierSegment(aControlA, aControlB, aNewCoordinatePair);
- }
- else
- {
- // add edge
- aNewPolygon.append(aNewCoordinatePair);
- }
- }
-
- // next sequence
- pInnerSequence++;
- pInnerSequenceFlags++;
-
- // #i72807# API import uses old line start/end-equal definition for closed,
- // so we need to correct this to closed state here
- basegfx::tools::checkClosed(aNewPolygon);
-
- // add new subpolygon
- aNewPolyPolygon.append(aNewPolygon);
- }
-
- return aNewPolyPolygon;
-}
-
//----------------------------------------------------------------------
bool SvxShapePolyPolygonBezier::setPropertyValueImpl( const ::rtl::OUString& rName, const SfxItemPropertySimpleEntry* pProperty, const ::com::sun::star::uno::Any& rValue ) throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::beans::PropertyVetoException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException)
@@ -1467,7 +1341,9 @@ bool SvxShapePolyPolygonBezier::setPropertyValueImpl( const ::rtl::OUString& rNa
{
if( rValue.getValue() && (rValue.getValueType() == ::getCppuType(( const drawing::PolyPolygonBezierCoords*)0) ) )
{
- basegfx::B2DPolyPolygon aNewPolyPolygon(SvxConvertPolyPolygonBezierToB2DPolyPolygon( (drawing::PolyPolygonBezierCoords*)rValue.getValue()));
+ basegfx::B2DPolyPolygon aNewPolyPolygon(
+ basegfx::unotools::polyPolygonBezierToB2DPolyPolygon(
+ *(drawing::PolyPolygonBezierCoords*)rValue.getValue()));
SetPolygon(aNewPolyPolygon);
return true;
}
@@ -1483,7 +1359,8 @@ bool SvxShapePolyPolygonBezier::setPropertyValueImpl( const ::rtl::OUString& rNa
basegfx::B2DHomMatrix aNewHomogenMatrix;
mpObj->TRGetBaseGeometry(aNewHomogenMatrix, aNewPolyPolygon);
- aNewPolyPolygon = SvxConvertPolyPolygonBezierToB2DPolyPolygon((drawing::PolyPolygonBezierCoords*)rValue.getValue());
+ aNewPolyPolygon = basegfx::unotools::polyPolygonBezierToB2DPolyPolygon(
+ *(drawing::PolyPolygonBezierCoords*)rValue.getValue());
mpObj->TRSetBaseGeometry(aNewHomogenMatrix, aNewPolyPolygon);
}
return true;
@@ -1497,44 +1374,6 @@ bool SvxShapePolyPolygonBezier::setPropertyValueImpl( const ::rtl::OUString& rNa
throw IllegalArgumentException();
}
-void SvxConvertB2DPolyPolygonToPolyPolygonBezier( const basegfx::B2DPolyPolygon& rPolyPoly, drawing::PolyPolygonBezierCoords& rRetval )
-{
- // use PolyPolygon converter as base. Since PolyPolygonBezierCoords uses
- // integer coordinates, this is no precision loss at all.
- const PolyPolygon aPolyPoly(rPolyPoly);
-
- // Polygone innerhalb vrobereiten
- rRetval.Coordinates.realloc((sal_Int32)aPolyPoly.Count());
- rRetval.Flags.realloc((sal_Int32)aPolyPoly.Count());
-
- // Zeiger auf aeussere Arrays holen
- drawing::PointSequence* pOuterSequence = rRetval.Coordinates.getArray();
- drawing::FlagSequence* pOuterFlags = rRetval.Flags.getArray();
-
- for(sal_uInt16 a=0;a<aPolyPoly.Count();a++)
- {
- // Einzelpolygon holen
- const Polygon& rPoly = aPolyPoly[a];
-
- // Platz in Arrays schaffen
- pOuterSequence->realloc((sal_Int32)rPoly.GetSize());
- pOuterFlags->realloc((sal_Int32)rPoly.GetSize());
-
- // Pointer auf arrays holen
- awt::Point* pInnerSequence = pOuterSequence->getArray();
- drawing::PolygonFlags* pInnerFlags = pOuterFlags->getArray();
-
- for(sal_uInt16 b=0;b<rPoly.GetSize();b++)
- {
- *pInnerSequence++ = awt::Point( rPoly[b].X(), rPoly[b].Y() );
- *pInnerFlags++ = (drawing::PolygonFlags)((sal_uInt16)rPoly.GetFlags(b));
- }
-
- pOuterSequence++;
- pOuterFlags++;
- }
-}
-
//----------------------------------------------------------------------
bool SvxShapePolyPolygonBezier::getPropertyValueImpl( const ::rtl::OUString& rName, const SfxItemPropertySimpleEntry* pProperty, ::com::sun::star::uno::Any& rValue ) throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException)
@@ -1546,7 +1385,7 @@ bool SvxShapePolyPolygonBezier::getPropertyValueImpl( const ::rtl::OUString& rNa
// PolyPolygon in eine struct PolyPolygon packen
const basegfx::B2DPolyPolygon& rPolyPoly = GetPolygon();
drawing::PolyPolygonBezierCoords aRetval;
- SvxConvertB2DPolyPolygonToPolyPolygonBezier(rPolyPoly, aRetval );
+ basegfx::unotools::b2DPolyPolygonToPolyPolygonBezier(rPolyPoly, aRetval);
rValue <<= aRetval;
break;
@@ -1558,7 +1397,7 @@ bool SvxShapePolyPolygonBezier::getPropertyValueImpl( const ::rtl::OUString& rNa
basegfx::B2DHomMatrix aNewHomogenMatrix;
mpObj.get()->TRGetBaseGeometry(aNewHomogenMatrix, aNewPolyPolygon);
drawing::PolyPolygonBezierCoords aRetval;
- SvxConvertB2DPolyPolygonToPolyPolygonBezier(aNewPolyPolygon, aRetval);
+ basegfx::unotools::b2DPolyPolygonToPolyPolygonBezier(aNewPolyPolygon, aRetval);
rValue <<= aRetval;
break;
diff --git a/svx/source/unodraw/unoshape.cxx b/svx/source/unodraw/unoshape.cxx
index 8f2984f..686736a 100644
--- a/svx/source/unodraw/unoshape.cxx
+++ b/svx/source/unodraw/unoshape.cxx
@@ -97,6 +97,7 @@
#include <editeng/outlobj.hxx>
#include <basegfx/matrix/b2dhommatrix.hxx>
#include <basegfx/matrix/b2dhommatrixtools.hxx>
+#include <basegfx/tools/unotools.hxx>
#include "shapeimpl.hxx"
#include <vector>
@@ -104,7 +105,6 @@
// #i68523#
#include "svx/lathe3d.hxx"
#include "svx/extrud3d.hxx"
-#include "unopolyhelper.hxx"
#include <boost/bind.hpp>
@@ -2365,7 +2365,7 @@ bool SvxShape::setPropertyValueImpl( const ::rtl::OUString&, const SfxItemProper
drawing::PolyPolygonBezierCoords aPolyPoly;
if ( rValue >>= aPolyPoly )
{
- basegfx::B2DPolyPolygon aNewPolyPolygon( SvxConvertPolyPolygonBezierToB2DPolyPolygon( &aPolyPoly ) );
+ basegfx::B2DPolyPolygon aNewPolyPolygon( basegfx::unotools::polyPolygonBezierToB2DPolyPolygon( aPolyPoly ) );
// Reintroduction of fix for issue i59051 (#i108851#)
ForceMetricToItemPoolMetric( aNewPolyPolygon );
if( mpModel->IsWriter() )
@@ -2814,7 +2814,7 @@ bool SvxShape::getPropertyValueImpl( const ::rtl::OUString&, const SfxItemProper
// Reintroduction of fix for issue #i59051# (#i108851#)
ForceMetricTo100th_mm( aPolyPoly );
drawing::PolyPolygonBezierCoords aRetval;
- SvxConvertB2DPolyPolygonToPolyPolygonBezier( aPolyPoly, aRetval);
+ basegfx::unotools::b2DPolyPolygonToPolyPolygonBezier( aPolyPoly, aRetval);
rValue <<= aRetval;
break;
}
diff --git a/svx/source/xoutdev/xattr.cxx b/svx/source/xoutdev/xattr.cxx
index d87f26f..0c31a60 100644
--- a/svx/source/xoutdev/xattr.cxx
+++ b/svx/source/xoutdev/xattr.cxx
@@ -47,7 +47,6 @@
#include "svx/unoapi.hxx"
#include <svl/style.hxx>
-#include "unopolyhelper.hxx"
#include <tools/bigint.hxx>
#include <svl/itemset.hxx>
@@ -63,6 +62,7 @@
#include <basegfx/polygon/b2dpolygon.hxx>
#include <basegfx/point/b2dpoint.hxx>
#include <basegfx/vector/b2dvector.hxx>
+#include <basegfx/tools/unotools.hxx>
#include <stdio.h>
@@ -1763,7 +1763,7 @@ bool XLineStartItem::QueryValue( ::com::sun::star::uno::Any& rVal, sal_uInt8 nMe
else
{
com::sun::star::drawing::PolyPolygonBezierCoords aBezier;
- SvxConvertB2DPolyPolygonToPolyPolygonBezier( maPolyPolygon, aBezier );
+ basegfx::unotools::b2DPolyPolygonToPolyPolygonBezier( maPolyPolygon, aBezier );
rVal <<= aBezier;
}
@@ -1790,7 +1790,7 @@ bool XLineStartItem::PutValue( const ::com::sun::star::uno::Any& rVal, sal_uInt8
com::sun::star::drawing::PolyPolygonBezierCoords* pCoords = (com::sun::star::drawing::PolyPolygonBezierCoords*)rVal.getValue();
if( pCoords->Coordinates.getLength() > 0 )
{
- maPolyPolygon = SvxConvertPolyPolygonBezierToB2DPolyPolygon( pCoords );
+ maPolyPolygon = basegfx::unotools::polyPolygonBezierToB2DPolyPolygon( *pCoords );
// #i72807# close line start/end polygons hard
// maPolyPolygon.setClosed(true);
}
@@ -2421,7 +2421,7 @@ bool XLineEndItem::QueryValue( ::com::sun::star::uno::Any& rVal, sal_uInt8 nMemb
else
{
com::sun::star::drawing::PolyPolygonBezierCoords aBezier;
- SvxConvertB2DPolyPolygonToPolyPolygonBezier( maPolyPolygon, aBezier );
+ basegfx::unotools::b2DPolyPolygonToPolyPolygonBezier( maPolyPolygon, aBezier );
rVal <<= aBezier;
}
return true;
@@ -2447,7 +2447,7 @@ bool XLineEndItem::PutValue( const ::com::sun::star::uno::Any& rVal, sal_uInt8 n
com::sun::star::drawing::PolyPolygonBezierCoords* pCoords = (com::sun::star::drawing::PolyPolygonBezierCoords*)rVal.getValue();
if( pCoords->Coordinates.getLength() > 0 )
{
- maPolyPolygon = SvxConvertPolyPolygonBezierToB2DPolyPolygon( pCoords );
+ maPolyPolygon = basegfx::unotools::polyPolygonBezierToB2DPolyPolygon( *pCoords );
// #i72807# close line start/end polygons hard
// maPolyPolygon.setClosed(true);
}
diff --git a/xmloff/inc/xexptran.hxx b/xmloff/inc/xexptran.hxx
index 1036650..14f27ab 100644
--- a/xmloff/inc/xexptran.hxx
+++ b/xmloff/inc/xexptran.hxx
@@ -30,11 +30,10 @@
#define _XEXPTRANSFORM_HXX
#include <rtl/ustring.hxx>
-#include <com/sun/star/drawing/PointSequenceSequence.hpp>
+#include <com/sun/star/drawing/PolyPolygonBezierCoords.hpp>
#include <com/sun/star/drawing/PointSequence.hpp>
-#include <com/sun/star/awt/Size.hpp>
-#include <com/sun/star/drawing/FlagSequenceSequence.hpp>
#include <com/sun/star/drawing/FlagSequence.hpp>
+#include <com/sun/star/awt/Size.hpp>
#include <com/sun/star/drawing/HomogenMatrix.hpp>
#include <tools/mapunit.hxx>
@@ -173,8 +172,7 @@ class SdXMLImExSvgDElement
sal_Int32 mnLastX;
sal_Int32 mnLastY;
- com::sun::star::drawing::PointSequenceSequence maPoly;
- com::sun::star::drawing::FlagSequenceSequence maFlag;
+ com::sun::star::drawing::PolyPolygonBezierCoords maPoly;
public:
SdXMLImExSvgDElement(const SdXMLImExViewBox& rViewBox);
@@ -194,8 +192,8 @@ public:
const rtl::OUString& GetExportString() const { return msString; }
bool IsClosed() const { return mbIsClosed; }
bool IsCurve() const { return mbIsCurve; }
- const com::sun::star::drawing::PointSequenceSequence& GetPointSequenceSequence() const { return maPoly; }
- const com::sun::star::drawing::FlagSequenceSequence& GetFlagSequenceSequence() const { return maFlag; }
+ const com::sun::star::drawing::PointSequenceSequence& GetPointSequenceSequence() const { return maPoly.Coordinates; }
+ const com::sun::star::drawing::FlagSequenceSequence& GetFlagSequenceSequence() const { return maPoly.Flags; }
};
diff --git a/xmloff/source/draw/xexptran.cxx b/xmloff/source/draw/xexptran.cxx
index 7cd9a04..2147391 100644
--- a/xmloff/source/draw/xexptran.cxx
+++ b/xmloff/source/draw/xexptran.cxx
@@ -37,6 +37,9 @@
#include <basegfx/matrix/b2dhommatrix.hxx>
#include <basegfx/tuple/b3dtuple.hxx>
#include <basegfx/matrix/b3dhommatrix.hxx>
+#include <basegfx/polygon/b2dpolypolygon.hxx>
+#include <basegfx/polygon/b2dpolypolygontools.hxx>
+#include <basegfx/tools/unotools.hxx>
#include <tools/string.hxx>
using ::rtl::OUString;
@@ -53,7 +56,19 @@ using namespace ::com::sun::star;
// Predeclarations
void Imp_SkipDouble(const OUString& rStr, sal_Int32& rPos, const sal_Int32 nLen);
-void Imp_CalcVectorValues(::basegfx::B2DVector& aVec1, ::basegfx::B2DVector& aVec2, bool& bSameLength, bool& bSameDirection);
+void Imp_CalcVectorValues(::basegfx::B2DVector& aVec1, ::basegfx::B2DVector& aVec2, bool& bSameLength, bool& bSameDirection)
+{
+ const sal_Int32 nLen1(FRound(aVec1.getLength()));
+ const sal_Int32 nLen2(FRound(aVec2.getLength()));
+ aVec1.normalize();
+ aVec2.normalize();
+ aVec1 += aVec2;
+ const sal_Int32 nLen3(FRound(aVec1.getLength() * ((nLen1 + nLen2) / 2.0)));
+
+ bSameLength = (abs(nLen1 - nLen2) <= BORDER_INTEGERS_ARE_EQUAL);
+ bSameDirection = (nLen3 <= BORDER_INTEGERS_ARE_EQUAL);
+}
+
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
@@ -1520,8 +1535,7 @@ SdXMLImExSvgDElement::SdXMLImExSvgDElement(const SdXMLImExViewBox& rViewBox)
mbIsCurve( false ),
mnLastX( 0L ),
mnLastY( 0L ),
- maPoly( 0L ),
- maFlag( 0L )
+ maPoly()
{
}
@@ -1583,6 +1597,8 @@ void SdXMLImExSvgDElement::AddPolygon(
const awt::Size& rObjectSize,
bool bClosed, bool bRelative)
{
+ // Leaving the export stuff for the while, should eventually also
+ // consolidated with basegfx svg support
DBG_ASSERT(pPoints, "Empty PointSequence handed over to SdXMLImExSvgDElement(!)");
sal_Int32 nCnt(pPoints->getLength());
@@ -2151,964 +2167,44 @@ void SdXMLImExSvgDElement::AddPolygon(
}
}
-// #100617# Linear double reader
-double Imp_ImportDoubleAndSpaces(
- double fRetval, const OUString& rStr, sal_Int32& rPos,
- const sal_Int32 nLen, const SvXMLUnitConverter& rConv)
-{
- fRetval = Imp_GetDoubleChar(rStr, rPos, nLen, rConv, fRetval);
- Imp_SkipSpacesAndCommas(rStr, rPos, nLen);
- return fRetval;
-}
-
-// #100617# Allow to read doubles, too. This will need to be changed to
-// the usage of Imp_ImportDoubleAndSpaces(...). For now, this is sufficient
-// since the interface cannot transport doubles.
-sal_Int32 Imp_ImportNumberAndSpaces(
- sal_Int32 nRetval, const OUString& rStr, sal_Int32& rPos,
- const sal_Int32 nLen, const SvXMLUnitConverter& rConv)
-{
- nRetval = FRound(Imp_ImportDoubleAndSpaces(double(nRetval), rStr, rPos, nLen, rConv));
- Imp_SkipSpacesAndCommas(rStr, rPos, nLen);
- return nRetval;
-}
-
-void Imp_PrepareCoorImport(sal_Int32& nX, sal_Int32& nY,
- const awt::Point& rObjectPos, const awt::Size& rObjectSize,
- const SdXMLImExViewBox& rViewBox, const bool bScale, const bool bTranslate)
-{
- if(bTranslate)
- {
- nX -= rViewBox.GetX();
- nY -= rViewBox.GetY();
- }
-
- if(bScale && rViewBox.GetWidth() && rViewBox.GetHeight())
- {
- nX = (nX * rObjectSize.Width) / rViewBox.GetWidth();
- nY = (nY * rObjectSize.Height) / rViewBox.GetHeight();
- }
-
- nX += rObjectPos.X;
- nY += rObjectPos.Y;
-}
-
-void Imp_AddExportPoints(sal_Int32 nX, sal_Int32 nY,
- awt::Point* pPoints, drawing::PolygonFlags* pFlags,
- const sal_Int32 nInnerIndex,
- drawing::PolygonFlags eFlag)
-{
- if(pPoints)
- pPoints[nInnerIndex] = awt::Point( nX, nY );
-
- if(pFlags)
- pFlags[nInnerIndex] = eFlag;
-}
-
-void Imp_CalcVectorValues(::basegfx::B2DVector& aVec1, ::basegfx::B2DVector& aVec2, bool& bSameLength, bool& bSameDirection)
-{
- const sal_Int32 nLen1(FRound(aVec1.getLength()));
- const sal_Int32 nLen2(FRound(aVec2.getLength()));
- aVec1.normalize();
- aVec2.normalize();
- aVec1 += aVec2;
- const sal_Int32 nLen3(FRound(aVec1.getLength() * ((nLen1 + nLen2) / 2.0)));
-
- bSameLength = (abs(nLen1 - nLen2) <= BORDER_INTEGERS_ARE_EQUAL);
- bSameDirection = (nLen3 <= BORDER_INTEGERS_ARE_EQUAL);
-}
-
-void Imp_CorrectPolygonFlag(const sal_uInt32 nInnerIndex, const awt::Point* const pInnerSequence,
- drawing::PolygonFlags* const pInnerFlags, const sal_Int32 nX1, const sal_Int32 nY1)
-{
- if(nInnerIndex)
- {
- const awt::Point aPPrev1 = pInnerSequence[nInnerIndex - 1];
-
- if(nInnerIndex > 1)
- {
- const awt::Point aPPrev2 = pInnerSequence[nInnerIndex - 2];
- const drawing::PolygonFlags aFPrev2 = pInnerFlags[nInnerIndex - 2];
- ::basegfx::B2DVector aVec1(aPPrev2.X - aPPrev1.X, aPPrev2.Y - aPPrev1.Y);
- ::basegfx::B2DVector aVec2(nX1 - aPPrev1.X, nY1 - aPPrev1.Y);
- bool bSameLength(false);
- bool bSameDirection(false);
-
- // get vector values
- Imp_CalcVectorValues(aVec1, aVec2, bSameLength, bSameDirection);
-
- if(drawing::PolygonFlags_CONTROL == aFPrev2)
- {
- // point before is a control point
- if(bSameDirection)
- {
- if(bSameLength)
- {
- // set to PolygonFlags_SYMMETRIC
- pInnerFlags[nInnerIndex - 1] = drawing::PolygonFlags_SYMMETRIC;
- }
- else
- {
- // set to PolygonFlags_SMOOTH
- pInnerFlags[nInnerIndex - 1] = drawing::PolygonFlags_SMOOTH;
- }
- }
- else
- {
- // set to PolygonFlags_NORMAL
- pInnerFlags[nInnerIndex - 1] = drawing::PolygonFlags_NORMAL;
- }
- }
- else
- {
- // point before is a simple curve point
- if(bSameDirection)
- {
- // set to PolygonFlags_SMOOTH
- pInnerFlags[nInnerIndex - 1] = drawing::PolygonFlags_SMOOTH;
- }
- else
- {
- // set to PolygonFlags_NORMAL
- pInnerFlags[nInnerIndex - 1] = drawing::PolygonFlags_NORMAL;
- }
- }
- }
- else
- {
- // no point before starpoint, set type to PolygonFlags_NORMAL
- pInnerFlags[nInnerIndex - 1] = drawing::PolygonFlags_NORMAL;
- }
- }
-}
-
SdXMLImExSvgDElement::SdXMLImExSvgDElement(const OUString& rNew,
const SdXMLImExViewBox& rViewBox,
const awt::Point& rObjectPos,
const awt::Size& rObjectSize,
- const SvXMLUnitConverter& rConv)
+ const SvXMLUnitConverter& /*rConv*/)
: msString( rNew ),
mrViewBox( rViewBox ),
mbIsClosed( false ),
mbIsCurve( false ),
mnLastX( 0L ),
mnLastY( 0L ),
- maPoly( 0L ),
- maFlag( 0L )
+ maPoly()
{
// convert string to polygon
- const OUString aStr(msString.getStr(), msString.getLength());
- const sal_Int32 nLen(aStr.getLength());
- sal_Int32 nPos(0);
- sal_Int32 nNumPolys(0L);
- bool bEllipticalArc(false);
-
- // object size and ViewBox size different?
- bool bScale(rObjectSize.Width != mrViewBox.GetWidth()
- || rObjectSize.Height != mrViewBox.GetHeight());
- bool bTranslate(mrViewBox.GetX() != 0L || mrViewBox.GetY() != 0L);
-
- // first loop: count polys and get flags
- Imp_SkipSpaces(aStr, nPos, nLen);
-
- while(nPos < nLen)
- {
- switch(aStr[nPos++])
- {
- case 'Z' :
- case 'z' :
- {
- break;
- }
- case 'M' :
- case 'm' :
- {
- nNumPolys++;
- break;
- }
- case 'S' :
- case 's' :
- case 'C' :
- case 'c' :
- case 'Q' :
- case 'q' :
- case 'T' :
- case 't' :
- {
- mbIsCurve = true;
- break;
- }
- case 'L' :
- case 'l' :
- case 'H' :
- case 'h' :
- case 'V' :
- case 'v' :
- {
- // normal, interpreted values. All okay.
- break;
- }
- case 'A' :
- case 'a' :
- {
- // Not yet interpreted value.
- bEllipticalArc = true;
- break;
- }
- }
- }
-
- DBG_ASSERT(!bEllipticalArc, "XMLIMP: non-interpreted tags in svg:d element!");
- (void)bEllipticalArc;
-
- if(nNumPolys)
- {
- // alloc arrays
- maPoly.realloc(nNumPolys);
- if(IsCurve())
- maFlag.realloc(nNumPolys);
-
- // get outer sequences
- drawing::PointSequence* pOuterSequence = maPoly.getArray();
- drawing::FlagSequence* pOuterFlags = (IsCurve()) ? maFlag.getArray() : 0L;
-
- // prepare new loop, count
- sal_uInt32 nPointCount(0L);
- nPos = 0;
- Imp_SkipSpaces(aStr, nPos, nLen);
+ basegfx::B2DPolyPolygon aPoly;
+ basegfx::tools::importFromSvgD(aPoly,msString);
- // #104076# reset closed flag for next to be started polygon
- mbIsClosed = false;
-
- while(nPos < nLen)
- {
- switch(aStr[nPos])
- {
- case 'z' :
- case 'Z' :
- {
- nPos++;
- Imp_SkipSpaces(aStr, nPos, nLen);
-
- // #104076# remember closed state of current polygon
- mbIsClosed = true;
-
- break;
- }
- case 'm' :
- case 'M' :
- {
- // new poly starts, end-process current poly
- if(nPointCount)
- {
- // #104076# If this partial polygon is closed, use one more point
- // to represent that
- if(mbIsClosed)
- {
- nPointCount++;
- }
-
- pOuterSequence->realloc(nPointCount);
- pOuterSequence++;
-
- if(pOuterFlags)
- {
- pOuterFlags->realloc(nPointCount);
- pOuterFlags++;
- }
-
- // reset point count for next polygon
- nPointCount = 0L;
- }
-
- // #104076# reset closed flag for next to be started polygon
- mbIsClosed = false;
-
- // NO break, continue in next case
- }
- case 'L' :
- case 'l' :
- {
- nPos++;
- Imp_SkipSpaces(aStr, nPos, nLen);
-
- while(nPos < nLen && Imp_IsOnNumberChar(aStr, nPos))
- {
- Imp_SkipDoubleAndSpacesAndCommas(aStr, nPos, nLen);
- Imp_SkipDoubleAndSpacesAndCommas(aStr, nPos, nLen);
- nPointCount++;
- }
- break;
- }
- case 'H' :
- case 'h' :
- case 'V' :
- case 'v' :
- {
- nPos++;
- Imp_SkipSpaces(aStr, nPos, nLen);
-
- while(nPos < nLen && Imp_IsOnNumberChar(aStr, nPos))
- {
- Imp_SkipDoubleAndSpacesAndCommas(aStr, nPos, nLen);
- nPointCount++;
- }
- break;
- }
- case 'S' :
- case 's' :
- {
- nPos++;
- Imp_SkipSpaces(aStr, nPos, nLen);
-
- while(nPos < nLen && Imp_IsOnNumberChar(aStr, nPos))
- {
- Imp_SkipDoubleAndSpacesAndCommas(aStr, nPos, nLen);
- Imp_SkipDoubleAndSpacesAndCommas(aStr, nPos, nLen);
- Imp_SkipDoubleAndSpacesAndCommas(aStr, nPos, nLen);
- Imp_SkipDoubleAndSpacesAndCommas(aStr, nPos, nLen);
- nPointCount += 3;
- }
- break;
- }
- case 'C' :
- case 'c' :
- {
- nPos++;
- Imp_SkipSpaces(aStr, nPos, nLen);
-
- while(nPos < nLen && Imp_IsOnNumberChar(aStr, nPos))
- {
- Imp_SkipDoubleAndSpacesAndCommas(aStr, nPos, nLen);
- Imp_SkipDoubleAndSpacesAndCommas(aStr, nPos, nLen);
- Imp_SkipDoubleAndSpacesAndCommas(aStr, nPos, nLen);
- Imp_SkipDoubleAndSpacesAndCommas(aStr, nPos, nLen);
- Imp_SkipDoubleAndSpacesAndCommas(aStr, nPos, nLen);
- Imp_SkipDoubleAndSpacesAndCommas(aStr, nPos, nLen);
- nPointCount += 3;
- }
- break;
- }
-
- // #100617# quadratic beziers, supported as cubic ones
- case 'Q' :
- case 'q' :
- {
- nPos++;
- Imp_SkipSpaces(aStr, nPos, nLen);
-
- while(nPos < nLen && Imp_IsOnNumberChar(aStr, nPos))
- {
- Imp_SkipDoubleAndSpacesAndCommas(aStr, nPos, nLen);
- Imp_SkipDoubleAndSpacesAndCommas(aStr, nPos, nLen);
- Imp_SkipDoubleAndSpacesAndCommas(aStr, nPos, nLen);
- Imp_SkipDoubleAndSpacesAndCommas(aStr, nPos, nLen);
-
- // use three points since quadratic is imported as cubic
- nPointCount += 3;
- }
- break;
- }
-
- // #100617# relative quadratic beziers, supported as cubic ones
- case 'T' :
- case 't' :
- {
- nPos++;
- Imp_SkipSpaces(aStr, nPos, nLen);
-
- while(nPos < nLen && Imp_IsOnNumberChar(aStr, nPos))
- {
- Imp_SkipDoubleAndSpacesAndCommas(aStr, nPos, nLen);
- Imp_SkipDoubleAndSpacesAndCommas(aStr, nPos, nLen);
-
- // use three points since quadratic is imported as cubic
- nPointCount += 3;
- }
- break;
- }
-
- // #100617# not yet supported: elliptical arc
- case 'A' :
- case 'a' :
- {
- OSL_FAIL("XMLIMP: non-interpreted tags in svg:d element (elliptical arc)!");
- nPos++;
- Imp_SkipSpaces(aStr, nPos, nLen);
-
- while(nPos < nLen && Imp_IsOnNumberChar(aStr, nPos))
- {
- Imp_SkipDoubleAndSpacesAndCommas(aStr, nPos, nLen);
- Imp_SkipDoubleAndSpacesAndCommas(aStr, nPos, nLen);
- Imp_SkipDoubleAndSpacesAndCommas(aStr, nPos, nLen);
- Imp_SkipNumberAndSpacesAndCommas(aStr, nPos, nLen);
- Imp_SkipNumberAndSpacesAndCommas(aStr, nPos, nLen);
- Imp_SkipDoubleAndSpacesAndCommas(aStr, nPos, nLen);
- Imp_SkipDoubleAndSpacesAndCommas(aStr, nPos, nLen);
- }
- break;
- }
-
- default:
- {
- nPos++;
- OSL_FAIL("XMLIMP: non-interpreted tags in svg:d element (unknown)!");
- break;
- }
- }
- }
-
- // alloc last poly (when points used)
- if(nPointCount)
- {
- // #104076# If this partial polygon is closed, use one more point
- // to represent that
- if(mbIsClosed)
- {
- nPointCount++;
- }
-
- pOuterSequence->realloc(nPointCount);
- pOuterSequence++;
-
- if(pOuterFlags)
- {
- pOuterFlags->realloc(nPointCount);
- pOuterFlags++;
- }
- }
-
- // set pointers back
- pOuterSequence = maPoly.getArray();
- pOuterFlags = (IsCurve()) ? maFlag.getArray() : 0L;
- awt::Point* pNotSoInnerSequence = 0L;
- drawing::PolygonFlags* pNotSoInnerFlags = 0L;
- sal_uInt32 nInnerIndex(0L);
-
- // prepare new loop, read points
- nPos = 0;
- Imp_SkipSpaces(aStr, nPos, nLen);
+ mbIsCurve = aPoly.areControlPointsUsed();
+ mbIsClosed = aPoly.isClosed();
- // #104076# reset closed flag for next to be started polygon
- mbIsClosed = false;
-
- while(nPos < nLen)
- {
- bool bRelative(false);
-
- switch(aStr[nPos])
- {
- case 'z' :
- case 'Z' :
- {
- nPos++;
- Imp_SkipSpaces(aStr, nPos, nLen);
-
- // #104076# remember closed state of current polygon
- mbIsClosed = true;
-
- break;
- }
-
- case 'm' :
- {
- bRelative = true;
- }
- case 'M' :
- {
- // #104076# end-process current poly
- if(mbIsClosed)
- {
- if(pNotSoInnerSequence)
- {
- // closed: add first point again
- sal_Int32 nX(pNotSoInnerSequence[0].X);
- sal_Int32 nY(pNotSoInnerSequence[0].Y);
- Imp_AddExportPoints(nX, nY, pNotSoInnerSequence, pNotSoInnerFlags, nInnerIndex++, drawing::PolygonFlags_NORMAL);
- }
-
- // reset closed flag for next to be started polygon
- mbIsClosed = false;
- }
-
- // next poly
- pNotSoInnerSequence = pOuterSequence->getArray();
- pOuterSequence++;
-
- if(pOuterFlags)
- {
- pNotSoInnerFlags = pOuterFlags->getArray();
- pOuterFlags++;
- }
-
- nInnerIndex = 0L;
-
- nPos++;
- Imp_SkipSpaces(aStr, nPos, nLen);
-
- while(nPos < nLen && Imp_IsOnNumberChar(aStr, nPos))
- {
- sal_Int32 nX(Imp_ImportNumberAndSpaces(0, aStr, nPos, nLen, rConv));
- sal_Int32 nY(Imp_ImportNumberAndSpaces(0, aStr, nPos, nLen, rConv));
-
- if(bRelative)
- {
- nX += mnLastX;
- nY += mnLastY;
- }
-
- // set last position
- mnLastX = nX;
- mnLastY = nY;
-
- // calc transform and add point and flag
- Imp_PrepareCoorImport(nX, nY, rObjectPos, rObjectSize, mrViewBox, bScale, bTranslate);
- Imp_AddExportPoints(nX, nY, pNotSoInnerSequence, pNotSoInnerFlags, nInnerIndex++, drawing::PolygonFlags_NORMAL);
- }
- break;
- }
-
- case 'l' :
- {
- bRelative = true;
- }
- case 'L' :
- {
- nPos++;
- Imp_SkipSpaces(aStr, nPos, nLen);
-
- while(nPos < nLen && Imp_IsOnNumberChar(aStr, nPos))
- {
- sal_Int32 nX(Imp_ImportNumberAndSpaces(0, aStr, nPos, nLen, rConv));
- sal_Int32 nY(Imp_ImportNumberAndSpaces(0, aStr, nPos, nLen, rConv));
-
- if(bRelative)
- {
- nX += mnLastX;
- nY += mnLastY;
- }
-
- // set last position
- mnLastX = nX;
- mnLastY = nY;
-
- // calc transform and add point and flag
- Imp_PrepareCoorImport(nX, nY, rObjectPos, rObjectSize, mrViewBox, bScale, bTranslate);
- Imp_AddExportPoints(nX, nY, pNotSoInnerSequence, pNotSoInnerFlags, nInnerIndex++, drawing::PolygonFlags_NORMAL);
- }
- break;
- }
-
- case 'h' :
- {
- bRelative = true;
- }
- case 'H' :
- {
- nPos++;
- Imp_SkipSpaces(aStr, nPos, nLen);
-
- while(nPos < nLen && Imp_IsOnNumberChar(aStr, nPos))
- {
- sal_Int32 nX(Imp_ImportNumberAndSpaces(0, aStr, nPos, nLen, rConv));
- sal_Int32 nY(mnLastY);
-
- if(bRelative)
- nX += mnLastX;
-
- // set last position
- mnLastX = nX;
-
- // calc transform and add point and flag
- Imp_PrepareCoorImport(nX, nY, rObjectPos, rObjectSize, mrViewBox, bScale, bTranslate);
- Imp_AddExportPoints(nX, nY, pNotSoInnerSequence, pNotSoInnerFlags, nInnerIndex++, drawing::PolygonFlags_NORMAL);
- }
- break;
- }
-
- case 'v' :
- {
- bRelative = true;
- }
- case 'V' :
- {
- nPos++;
- Imp_SkipSpaces(aStr, nPos, nLen);
-
- while(nPos < nLen && Imp_IsOnNumberChar(aStr, nPos))
- {
- sal_Int32 nX(mnLastX);
- sal_Int32 nY(Imp_ImportNumberAndSpaces(0, aStr, nPos, nLen, rConv));
-
- if(bRelative)
- nY += mnLastY;
-
- // set last position
- mnLastY = nY;
-
- // calc transform and add point and flag
- Imp_PrepareCoorImport(nX, nY, rObjectPos, rObjectSize, mrViewBox, bScale, bTranslate);
- Imp_AddExportPoints(nX, nY, pNotSoInnerSequence, pNotSoInnerFlags, nInnerIndex++, drawing::PolygonFlags_NORMAL);
- }
- break;
- }
-
- case 's' :
- {
- bRelative = true;
- }
- case 'S' :
- {
- nPos++;
- Imp_SkipSpaces(aStr, nPos, nLen);
-
- while(nPos < nLen && Imp_IsOnNumberChar(aStr, nPos))
- {
- sal_Int32 nX1;
- sal_Int32 nY1;
- sal_Int32 nX2(Imp_ImportNumberAndSpaces(0, aStr, nPos, nLen, rConv));
- sal_Int32 nY2(Imp_ImportNumberAndSpaces(0, aStr, nPos, nLen, rConv));
- sal_Int32 nX(Imp_ImportNumberAndSpaces(0, aStr, nPos, nLen, rConv));
- sal_Int32 nY(Imp_ImportNumberAndSpaces(0, aStr, nPos, nLen, rConv));
-
- if(bRelative)
- {
- nX2 += mnLastX;
- nY2 += mnLastY;
- nX += mnLastX;
- nY += mnLastY;
- }
-
- // set last position
- mnLastX = nX;
- mnLastY = nY;
-
- // calc transform for new points
- Imp_PrepareCoorImport(nX2, nY2, rObjectPos, rObjectSize, mrViewBox, bScale, bTranslate);
- Imp_PrepareCoorImport(nX, nY, rObjectPos, rObjectSize, mrViewBox, bScale, bTranslate);
-
- // one more thing is known: the previous real point is PolygonFlags_SYMMETRIC
- // and the Point X1,Y1 can be constructed by mirroring the point before it.
- nX1 = nX2;
- nY1 = nY2;
- if(nInnerIndex)
- {
- awt::Point aPPrev1 = pNotSoInnerSequence[nInnerIndex - 1];
-
- if(nInnerIndex > 1)
- {
- awt::Point aPPrev2 = pNotSoInnerSequence[nInnerIndex - 2];
- nX1 = aPPrev1.X -(aPPrev2.X - aPPrev1.X);
- nY1 = aPPrev1.Y -(aPPrev2.Y - aPPrev1.Y);
- }
-
- // set curve point to symmetric
- pNotSoInnerFlags[nInnerIndex - 1] = drawing::PolygonFlags_SYMMETRIC;
- }
-
- // add calculated control point
- Imp_AddExportPoints(nX1, nY1, pNotSoInnerSequence, pNotSoInnerFlags, nInnerIndex++, drawing::PolygonFlags_CONTROL);
-
- // add new points and set flags
- Imp_AddExportPoints(nX2, nY2, pNotSoInnerSequence, pNotSoInnerFlags, nInnerIndex++, drawing::PolygonFlags_CONTROL);
- Imp_AddExportPoints(nX, nY, pNotSoInnerSequence, pNotSoInnerFlags, nInnerIndex++, drawing::PolygonFlags_SMOOTH);
- }
- break;
- }
-
- case 'c' :
- {
- bRelative = true;
- }
- case 'C' :
- {
- nPos++;
- Imp_SkipSpaces(aStr, nPos, nLen);
-
- while(nPos < nLen && Imp_IsOnNumberChar(aStr, nPos))
- {
- sal_Int32 nX1(Imp_ImportNumberAndSpaces(0, aStr, nPos, nLen, rConv));
- sal_Int32 nY1(Imp_ImportNumberAndSpaces(0, aStr, nPos, nLen, rConv));
- sal_Int32 nX2(Imp_ImportNumberAndSpaces(0, aStr, nPos, nLen, rConv));
- sal_Int32 nY2(Imp_ImportNumberAndSpaces(0, aStr, nPos, nLen, rConv));
- sal_Int32 nX(Imp_ImportNumberAndSpaces(0, aStr, nPos, nLen, rConv));
- sal_Int32 nY(Imp_ImportNumberAndSpaces(0, aStr, nPos, nLen, rConv));
-
- if(bRelative)
- {
- nX1 += mnLastX;
- nY1 += mnLastY;
- nX2 += mnLastX;
- nY2 += mnLastY;
- nX += mnLastX;
- nY += mnLastY;
- }
-
- // set last position
- mnLastX = nX;
- mnLastY = nY;
-
- // calc transform for new points
- Imp_PrepareCoorImport(nX1, nY1, rObjectPos, rObjectSize, mrViewBox, bScale, bTranslate);
- Imp_PrepareCoorImport(nX2, nY2, rObjectPos, rObjectSize, mrViewBox, bScale, bTranslate);
- Imp_PrepareCoorImport(nX, nY, rObjectPos, rObjectSize, mrViewBox, bScale, bTranslate);
-
- // correct polygon flag for previous point
- Imp_CorrectPolygonFlag(nInnerIndex, pNotSoInnerSequence, pNotSoInnerFlags, nX1, nY1);
-
- // add new points and set flags
- Imp_AddExportPoints(nX1, nY1, pNotSoInnerSequence, pNotSoInnerFlags, nInnerIndex++, drawing::PolygonFlags_CONTROL);
- Imp_AddExportPoints(nX2, nY2, pNotSoInnerSequence, pNotSoInnerFlags, nInnerIndex++, drawing::PolygonFlags_CONTROL);
- Imp_AddExportPoints(nX, nY, pNotSoInnerSequence, pNotSoInnerFlags, nInnerIndex++, drawing::PolygonFlags_SMOOTH);
- }
- break;
- }
-
- // #100617# quadratic beziers are imported as cubic
- case 'q' :
- {
- bRelative = true;
- }
- case 'Q' :
- {
- nPos++;
- Imp_SkipSpaces(aStr, nPos, nLen);
-
- while(nPos < nLen && Imp_IsOnNumberChar(aStr, nPos))
- {
- sal_Int32 nXX(Imp_ImportNumberAndSpaces(0, aStr, nPos, nLen, rConv));
- sal_Int32 nYY(Imp_ImportNumberAndSpaces(0, aStr, nPos, nLen, rConv));
- sal_Int32 nX(Imp_ImportNumberAndSpaces(0, aStr, nPos, nLen, rConv));
- sal_Int32 nY(Imp_ImportNumberAndSpaces(0, aStr, nPos, nLen, rConv));
-
- if(bRelative)
- {
- nXX += mnLastX;
- nYY += mnLastY;
- nX += mnLastX;
- nY += mnLastY;
- }
-
- // set last position
- mnLastX = nX;
- mnLastY = nY;
-
- // calc transform for new points
- Imp_PrepareCoorImport(nXX, nYY, rObjectPos, rObjectSize, mrViewBox, bScale, bTranslate);
- Imp_PrepareCoorImport(nX, nY, rObjectPos, rObjectSize, mrViewBox, bScale, bTranslate);
-
- // calculate X1,X2
- awt::Point aPPrev1 = (nInnerIndex) ? pNotSoInnerSequence[nInnerIndex-1] : pNotSoInnerSequence[0];
- sal_Int32 nX1 = FRound((double)((nXX * 2) + aPPrev1.X) / 3.0);
- sal_Int32 nY1 = FRound((double)((nYY * 2) + aPPrev1.Y) / 3.0);
- sal_Int32 nX2 = FRound((double)((nXX * 2) + nX) / 3.0);
- sal_Int32 nY2 = FRound((double)((nYY * 2) + nY) / 3.0);
-
- // correct polygon flag for previous point
- Imp_CorrectPolygonFlag(nInnerIndex, pNotSoInnerSequence, pNotSoInnerFlags, nX1, nY1);
-
- // add new points and set flags
- Imp_AddExportPoints(nX1, nY1, pNotSoInnerSequence, pNotSoInnerFlags, nInnerIndex++, drawing::PolygonFlags_CONTROL);
- Imp_AddExportPoints(nX2, nY2, pNotSoInnerSequence, pNotSoInnerFlags, nInnerIndex++, drawing::PolygonFlags_CONTROL);
- Imp_AddExportPoints(nX, nY, pNotSoInnerSequence, pNotSoInnerFlags, nInnerIndex++, drawing::PolygonFlags_SMOOTH);
- }
- break;
- }
-
- // #100617# relative quadratic beziers are imported as cubic
- case 't' :
- {
- bRelative = true;
- }
- case 'T' :
- {
- nPos++;
- Imp_SkipSpaces(aStr, nPos, nLen);
-
- while(nPos < nLen && Imp_IsOnNumberChar(aStr, nPos))
- {
- sal_Int32 nXX;
- sal_Int32 nYY;
- sal_Int32 nX(Imp_ImportNumberAndSpaces(0, aStr, nPos, nLen, rConv));
- sal_Int32 nY(Imp_ImportNumberAndSpaces(0, aStr, nPos, nLen, rConv));
-
- if(bRelative)
- {
- nX += mnLastX;
- nY += mnLastY;
- }
-
- // set last position
- mnLastX = nX;
- mnLastY = nY;
-
- // calc transform for new points
- Imp_PrepareCoorImport(nX, nY, rObjectPos, rObjectSize, mrViewBox, bScale, bTranslate);
-
- // one more thing is known: the previous real point is PolygonFlags_SYMMETRIC
- // and the Point X1,Y1 can be constructed by mirroring the point before it.
- nXX = nX;
- nYY = nY;
- awt::Point aPPrev1 = pNotSoInnerSequence[0];
-
- if(nInnerIndex)
- {
- aPPrev1 = pNotSoInnerSequence[nInnerIndex - 1];
-
- if(nInnerIndex > 1)
- {
- awt::Point aPPrev2 = pNotSoInnerSequence[nInnerIndex - 2];
- nXX = aPPrev1.X -(aPPrev2.X - aPPrev1.X);
- nYY = aPPrev1.Y -(aPPrev2.Y - aPPrev1.Y);
- }
-
- // set curve point to smooth here, since length
- // is changed and thus only c1 can be used.
- pNotSoInnerFlags[nInnerIndex - 1] = drawing::PolygonFlags_SMOOTH;
- }
-
- // calculate X1,X2
- sal_Int32 nX1 = FRound((double)((nXX * 2) + aPPrev1.X) / 3.0);
- sal_Int32 nY1 = FRound((double)((nYY * 2) + aPPrev1.Y) / 3.0);
- sal_Int32 nX2 = FRound((double)((nXX * 2) + nX) / 3.0);
- sal_Int32 nY2 = FRound((double)((nYY * 2) + nY) / 3.0);
-
- // correct polygon flag for previous point
- Imp_CorrectPolygonFlag(nInnerIndex, pNotSoInnerSequence, pNotSoInnerFlags, nX1, nY1);
-
- // add new points and set flags
- Imp_AddExportPoints(nX1, nY1, pNotSoInnerSequence, pNotSoInnerFlags, nInnerIndex++, drawing::PolygonFlags_CONTROL);
- Imp_AddExportPoints(nX2, nY2, pNotSoInnerSequence, pNotSoInnerFlags, nInnerIndex++, drawing::PolygonFlags_CONTROL);
- Imp_AddExportPoints(nX, nY, pNotSoInnerSequence, pNotSoInnerFlags, nInnerIndex++, drawing::PolygonFlags_SMOOTH);
- }
- break;
- }
-
- // #100617# not yet supported: elliptical arc
- case 'A' :
- case 'a' :
- {
- OSL_FAIL("XMLIMP: non-interpreted tags in svg:d element (elliptical arc)!");
- nPos++;
- Imp_SkipSpaces(aStr, nPos, nLen);
-
- while(nPos < nLen && Imp_IsOnNumberChar(aStr, nPos))
- {
- Imp_SkipDoubleAndSpacesAndCommas(aStr, nPos, nLen);
- Imp_SkipDoubleAndSpacesAndCommas(aStr, nPos, nLen);
- Imp_SkipDoubleAndSpacesAndCommas(aStr, nPos, nLen);
- Imp_SkipNumberAndSpacesAndCommas(aStr, nPos, nLen);
- Imp_SkipNumberAndSpacesAndCommas(aStr, nPos, nLen);
- Imp_SkipDoubleAndSpacesAndCommas(aStr, nPos, nLen);
- Imp_SkipDoubleAndSpacesAndCommas(aStr, nPos, nLen);
- }
- break;
- }
-
- default:
- {
- nPos++;
- OSL_FAIL("XMLIMP: non-interpreted tags in svg:d element (unknown)!");
- break;
- }
- }
- }
-
- // #104076# end-process closed state of last poly
- if(mbIsClosed)
- {
- if(pNotSoInnerSequence)
- {
- // closed: add first point again
- sal_Int32 nX(pNotSoInnerSequence[0].X);
- sal_Int32 nY(pNotSoInnerSequence[0].Y);
- Imp_AddExportPoints(nX, nY, pNotSoInnerSequence, pNotSoInnerFlags, nInnerIndex++, drawing::PolygonFlags_NORMAL);
- }
- }
-
- // #87202# If it's a curve and it's closed the last point maybe too much
- // and just exported since SVG does not allow special handling of same
- // start and end point, remove this last point.
- // Evtl. correct the last curve flags, too.
- if(IsCurve() && IsClosed())
- {
- // make one more loop over the PolyPolygon
- pOuterSequence = maPoly.getArray();
- pOuterFlags = maFlag.getArray();
- sal_Int32 nOuterCnt(maPoly.getLength());
-
- for(sal_Int32 a(0); a < nOuterCnt; a++)
- {
- // get Polygon pointers
- awt::Point* pInnerSequence = pOuterSequence->getArray();
- drawing::PolygonFlags* pInnerFlags = pOuterFlags->getArray();
- sal_Int32 nInnerCnt(pOuterSequence->getLength());
-
- while( nInnerCnt >= 2
- && ((pInnerSequence + (nInnerCnt - 2))->X == (pInnerSequence + (nInnerCnt - 1))->X)
- && ((pInnerSequence + (nInnerCnt - 2))->Y == (pInnerSequence + (nInnerCnt - 1))->Y)
- && drawing::PolygonFlags_CONTROL != *(pInnerFlags + (nInnerCnt - 2)))
- {
- // remove last point from array
- pOuterSequence->realloc(nInnerCnt - 1);
- pOuterFlags->realloc(nInnerCnt - 1);
-
- // get new pointers
- pInnerSequence = pOuterSequence->getArray();
- pInnerFlags = pOuterFlags->getArray();
- nInnerCnt = pOuterSequence->getLength();
- }
-
- // now evtl. correct the last curve flags
- if(nInnerCnt >= 4)
- {
- if( pInnerSequence->X == (pInnerSequence + (nInnerCnt - 1))->X
- && pInnerSequence->Y == (pInnerSequence + (nInnerCnt - 1))->Y
- && drawing::PolygonFlags_CONTROL == *(pInnerFlags + 1)
- && drawing::PolygonFlags_CONTROL == *(pInnerFlags + (nInnerCnt - 2)))
- {
- awt::Point aPrev = *(pInnerSequence + (nInnerCnt - 2));
- awt::Point aCurr = *pInnerSequence;
- awt::Point aNext = *(pInnerSequence + 1);
- ::basegfx::B2DVector aVec1(aPrev.X - aCurr.X, aPrev.Y - aCurr.Y);
- ::basegfx::B2DVector aVec2(aNext.X - aCurr.X, aNext.Y - aCurr.Y);
- bool bSameLength(false);
- bool bSameDirection(false);
-
- // get vector values
- Imp_CalcVectorValues(aVec1, aVec2, bSameLength, bSameDirection);
-
- // set correct flag value
- if(bSameDirection)
- {
- if(bSameLength)
- {
- // set to PolygonFlags_SYMMETRIC
- *pInnerFlags = drawing::PolygonFlags_SYMMETRIC;
- *(pInnerFlags + (nInnerCnt - 1)) = drawing::PolygonFlags_SYMMETRIC;
- }
- else
- {
- // set to PolygonFlags_SMOOTH
- *pInnerFlags = drawing::PolygonFlags_SMOOTH;
- *(pInnerFlags + (nInnerCnt - 1)) = drawing::PolygonFlags_SMOOTH;
- }
- }
- else
- {
- // set to PolygonFlags_NORMAL
- *pInnerFlags = drawing::PolygonFlags_NORMAL;
- *(pInnerFlags + (nInnerCnt - 1)) = drawing::PolygonFlags_NORMAL;
- }
- }
- }
-
- // switch to next Polygon
- pOuterSequence++;
- pOuterFlags++;
- }
- }
- }
+ // object size and ViewBox size different?
+ basegfx::B2DHomMatrix aTransform;
+ const bool bScale(rObjectSize.Width != mrViewBox.GetWidth()
+ || rObjectSize.Height != mrViewBox.GetHeight());
+ const bool bTranslate(mrViewBox.GetX() != 0L || mrViewBox.GetY() != 0L);
+
+ if( bTranslate )
+ aTransform.translate(
+ -mrViewBox.GetX(),
+ -mrViewBox.GetY());
+ if( bScale )
+ aTransform.scale(
+ rObjectSize.Width / mrViewBox.GetWidth(),
+ rObjectSize.Height / mrViewBox.GetHeight());
+ aTransform.translate( rObjectPos.X, rObjectPos.Y );
+ aPoly.transform(aTransform);
+
+ basegfx::unotools::b2DPolyPolygonToPolyPolygonBezier(aPoly,maPoly);
}
// eof
More information about the Libreoffice-commits
mailing list