incubator-ooo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a..@apache.org
Subject svn commit: r1209140 [5/11] - in /incubator/ooo/branches/alg/svgreplacement/main: ./ basegfx/inc/basegfx/matrix/ basegfx/inc/basegfx/polygon/ basegfx/source/polygon/ cppcanvas/source/mtfrenderer/ drawinglayer/ drawinglayer/inc/drawinglayer/primitive2d/...
Date Thu, 01 Dec 2011 16:26:53 GMT
Added: incubator/ooo/branches/alg/svgreplacement/main/svgio/inc/svgio/svgreader/svgtools.hxx
URL: http://svn.apache.org/viewvc/incubator/ooo/branches/alg/svgreplacement/main/svgio/inc/svgio/svgreader/svgtools.hxx?rev=1209140&view=auto
==============================================================================
--- incubator/ooo/branches/alg/svgreplacement/main/svgio/inc/svgio/svgreader/svgtools.hxx (added)
+++ incubator/ooo/branches/alg/svgreplacement/main/svgio/inc/svgio/svgreader/svgtools.hxx Thu Dec  1 16:25:17 2011
@@ -0,0 +1,210 @@
+/**************************************************************
+ * 
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * 
+ *************************************************************/
+
+#ifndef INCLUDED_SVGIO_SVGREADER_SVGTOOLS_HXX
+#define INCLUDED_SVGIO_SVGREADER_SVGTOOLS_HXX
+
+#include <svgio/svgiodllapi.h>
+#include <drawinglayer/primitive2d/baseprimitive2d.hxx>
+#include <basegfx/color/bcolor.hxx>
+#include <basegfx/polygon/b2dpolypolygon.hxx>
+#include <svgio/svgreader/svgpaint.hxx>
+#include <vector>
+
+//////////////////////////////////////////////////////////////////////////////
+
+namespace svgio
+{
+    namespace svgreader
+    {
+#ifdef DBG_UTIL
+        // error helper
+        void myAssert(const rtl::OUString& rMessage);
+#endif
+
+        enum NumberType
+        {
+            xcoordinate,
+            ycoordinate,
+            length
+        };
+
+        class InfoProvider
+        {
+        public:
+            virtual const basegfx::B2DRange* getCurrentViewPort() const = 0;
+            virtual double getCurrentFontSize() const = 0;
+            virtual double getCurrentXHeight() const = 0;
+        };
+
+        enum SvgUnit
+        {
+            Unit_em = 0,    // relative to current font size
+            Unit_ex,        // relative to current x-height
+            
+            Unit_px,        // 'user unit'
+            Unit_pt,        // points, 1.25 px
+            Unit_pc,        // 15.0 px
+            Unit_cm,        // 35.43307 px
+            Unit_mm,        // 3.543307 px
+            Unit_in,        // 90 px
+            
+            Unit_percent    // relative to range
+        };
+
+        class SvgNumber
+        {
+        private:
+            double      mfNumber;
+            SvgUnit     meUnit;
+
+            /// bitfield
+            bool        mbSet : 1;
+
+        public:
+            SvgNumber()
+            :   mfNumber(0.0),
+                meUnit(Unit_px),
+                mbSet(false)
+            {
+            }
+
+            SvgNumber(double fNum, SvgUnit aSvgUnit = Unit_px, bool bSet = true)
+            :   mfNumber(fNum),
+                meUnit(aSvgUnit),
+                mbSet(bSet)
+            {
+            }
+
+            double getNumber() const
+            {
+                return mfNumber;
+            }
+
+            SvgUnit getUnit() const
+            {
+                return meUnit;
+            }
+
+            bool isSet() const
+            {
+                return mbSet;
+            }
+
+            bool isPositive() const;
+
+            double solve(const InfoProvider& rInfoProvider, NumberType aNumberType = length) const;
+        };
+
+        typedef ::std::vector< SvgNumber > SvgNumberVector;
+
+        enum SvgAlign
+        {
+            Align_none,
+            Align_xMinYMin,
+            Align_xMidYMin,
+            Align_xMaxYMin,
+            Align_xMinYMid,
+            Align_xMidYMid, // default
+            Align_xMaxYMid,
+            Align_xMinYMax,
+            Align_xMidYMax,
+            Align_xMaxYMax
+        };
+
+        class SvgAspectRatio
+        {
+        private:
+            SvgAlign    maSvgAlign;
+
+            /// bitfield
+            bool        mbDefer : 1; // default is false
+            bool        mbMeetOrSlice : 1; // true = meet (default), false = slice
+            bool        mbSet : 1;
+
+        public:
+            SvgAspectRatio()
+            :   maSvgAlign(Align_xMidYMid),
+                mbDefer(false),
+                mbMeetOrSlice(true),
+                mbSet(false)
+            {
+            }
+
+            SvgAspectRatio(SvgAlign aSvgAlign, bool bDefer, bool bMeetOrSlice)
+            :   maSvgAlign(aSvgAlign),
+                mbDefer(bDefer),
+                mbMeetOrSlice(bMeetOrSlice),
+                mbSet(true)
+            {
+            }
+
+            /// data read access
+            SvgAlign getSvgAlign() const { return maSvgAlign; }
+            bool isDefer() const { return mbDefer; }
+            bool isMeetOrSlice() const { return mbMeetOrSlice; }
+            bool isSet() const { return mbSet; }
+
+            /// tooling
+            static basegfx::B2DHomMatrix createLinearMapping(const basegfx::B2DRange& rTarget, const basegfx::B2DRange& rSource);
+            basegfx::B2DHomMatrix createMapping(const basegfx::B2DRange& rTarget, const basegfx::B2DRange& rSource) const;
+        };
+
+        void skip_char(const rtl::OUString& rCandidate, const sal_Unicode& rChar, sal_Int32& nPos, const sal_Int32 nLen);
+        void skip_char(const rtl::OUString& rCandidate, const sal_Unicode& rCharA, const sal_Unicode& rCharB, sal_Int32& nPos, const sal_Int32 nLen);
+        void copySign(const rtl::OUString& rCandidate, sal_Int32& nPos, rtl::OUStringBuffer& rTarget, const sal_Int32 nLen);
+        void copyNumber(const rtl::OUString& rCandidate, sal_Int32& nPos, rtl::OUStringBuffer& rTarget, const sal_Int32 nLen);
+        void copyHex(const rtl::OUString& rCandidate, sal_Int32& nPos, rtl::OUStringBuffer& rTarget, const sal_Int32 nLen);
+        void copyString(const rtl::OUString& rCandidate, sal_Int32& nPos, rtl::OUStringBuffer& rTarget, const sal_Int32 nLen);
+        void copyToLimiter(const rtl::OUString& rCandidate, const sal_Unicode& rLimiter, sal_Int32& nPos, rtl::OUStringBuffer& rTarget, const sal_Int32 nLen);
+        bool readNumber(const rtl::OUString& rCandidate, sal_Int32& nPos, double& fNum, const sal_Int32 nLen);
+        SvgUnit readUnit(const rtl::OUString& rCandidate, sal_Int32& nPos, const sal_Int32 nLen);
+        bool readNumberAndUnit(const rtl::OUString& rCandidate, sal_Int32& nPos, SvgNumber& aNum, const sal_Int32 nLen);
+        bool readAngle(const rtl::OUString& rCandidate, sal_Int32& nPos, double& fAngle, const sal_Int32 nLen);
+        sal_Int32 read_hex(const sal_Unicode& rChar);
+        bool match_colorKeyword(basegfx::BColor& rColor, const rtl::OUString& rName);
+        bool read_color(const rtl::OUString& rCandidate, basegfx::BColor& rColor);
+        basegfx::B2DRange readViewBox(const rtl::OUString& rCandidate, InfoProvider& rInfoProvider);
+        basegfx::B2DHomMatrix readTransform(const rtl::OUString& rCandidate, InfoProvider& rInfoProvider);
+        bool readSingleNumber(const rtl::OUString& rCandidate, SvgNumber& aNum);
+        bool readSvgPaint(const rtl::OUString& rCandidate, SvgPaint& rSvgPaint, rtl::OUString& rURL);
+
+        bool readSvgNumberVector(const rtl::OUString& rCandidate, SvgNumberVector& rSvgNumberVector);
+        ::std::vector< double > solveSvgNumberVector(const SvgNumberVector& rInput, const InfoProvider& rInfoProvider, NumberType aNumberType = length);
+
+        SvgAspectRatio readSvgAspectRatio(const rtl::OUString& rCandidate);
+
+        typedef ::std::vector< rtl::OUString > SvgStringVector;
+        bool readSvgStringVector(const rtl::OUString& rCandidate, SvgStringVector& rSvgStringVector);
+
+        rtl::OUString convert(const rtl::OUString& rCandidate, const sal_Unicode& rPattern, const sal_Unicode& rNew, bool bRemove);
+        rtl::OUString consolidateContiguosSpace(const rtl::OUString& rCandidate);
+        rtl::OUString whiteSpaceHandlingDefault(const rtl::OUString& rCandidate);
+        rtl::OUString whiteSpaceHandlingPreserve(const rtl::OUString& rCandidate);
+
+    } // end of namespace svgreader
+} // end of namespace svgio
+
+//////////////////////////////////////////////////////////////////////////////
+
+#endif //INCLUDED_SVGIO_SVGREADER_SVGTOOLS_HXX
+
+// eof

Added: incubator/ooo/branches/alg/svgreplacement/main/svgio/inc/svgio/svgreader/svgtrefnode.hxx
URL: http://svn.apache.org/viewvc/incubator/ooo/branches/alg/svgreplacement/main/svgio/inc/svgio/svgreader/svgtrefnode.hxx?rev=1209140&view=auto
==============================================================================
--- incubator/ooo/branches/alg/svgreplacement/main/svgio/inc/svgio/svgreader/svgtrefnode.hxx (added)
+++ incubator/ooo/branches/alg/svgreplacement/main/svgio/inc/svgio/svgreader/svgtrefnode.hxx Thu Dec  1 16:25:17 2011
@@ -0,0 +1,69 @@
+/**************************************************************
+ * 
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * 
+ *************************************************************/
+
+#ifndef INCLUDED_SVGIO_SVGREADER_SVGTREFNODE_HXX
+#define INCLUDED_SVGIO_SVGREADER_SVGTREFNODE_HXX
+
+#include <svgio/svgiodllapi.h>
+#include <svgio/svgreader/svgnode.hxx>
+#include <svgio/svgreader/svgstyleattributes.hxx>
+#include <svgio/svgreader/svgtextnode.hxx>
+
+//////////////////////////////////////////////////////////////////////////////
+
+namespace svgio
+{
+    namespace svgreader
+    {
+        class SvgTrefNode : public SvgNode
+        {
+        private:
+            /// use styles
+            SvgStyleAttributes      maSvgStyleAttributes;
+
+            /// link to text content. If maXLink
+            /// is set, the node can be fetched on demand
+            rtl::OUString               maXLink;
+            const SvgTextNode*          mpXLink;
+
+            /// link on demand
+            void tryToFindLink();
+
+        public:
+            SvgTrefNode(
+                SvgDocument& rDocument,
+                SvgNode* pParent);
+            virtual ~SvgTrefNode();
+
+            virtual const SvgStyleAttributes* getSvgStyleAttributes() const;
+            virtual void parseAttribute(const rtl::OUString& rTokenName, SVGToken aSVGToken, const rtl::OUString& aContent);
+
+            /// access to referenced SvgTextNode
+            const SvgTextNode* getReferencedSvgTextNode() const;
+        };
+    } // end of namespace svgreader
+} // end of namespace svgio
+
+//////////////////////////////////////////////////////////////////////////////
+
+#endif //INCLUDED_SVGIO_SVGREADER_SVGTREFNODE_HXX
+
+// eof

Added: incubator/ooo/branches/alg/svgreplacement/main/svgio/inc/svgio/svgreader/svgtspannode.hxx
URL: http://svn.apache.org/viewvc/incubator/ooo/branches/alg/svgreplacement/main/svgio/inc/svgio/svgreader/svgtspannode.hxx?rev=1209140&view=auto
==============================================================================
--- incubator/ooo/branches/alg/svgreplacement/main/svgio/inc/svgio/svgreader/svgtspannode.hxx (added)
+++ incubator/ooo/branches/alg/svgreplacement/main/svgio/inc/svgio/svgreader/svgtspannode.hxx Thu Dec  1 16:25:17 2011
@@ -0,0 +1,64 @@
+/**************************************************************
+ * 
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * 
+ *************************************************************/
+
+#ifndef INCLUDED_SVGIO_SVGREADER_SVGTSPANNODE_HXX
+#define INCLUDED_SVGIO_SVGREADER_SVGTSPANNODE_HXX
+
+#include <svgio/svgiodllapi.h>
+#include <svgio/svgreader/svgcharacternode.hxx>
+#include <svgio/svgreader/svgstyleattributes.hxx>
+#include <svgio/svgreader/svgtools.hxx>
+
+//////////////////////////////////////////////////////////////////////////////
+
+namespace svgio
+{
+    namespace svgreader
+    {
+        class SvgTspanNode : public SvgNode
+        {
+        private:
+            /// use styles
+            SvgStyleAttributes      maSvgStyleAttributes;
+
+            /// variable scan values, dependent of given XAttributeList
+            SvgTextPositions        maSvgTextPositions;
+
+        public:
+            SvgTspanNode(
+                SvgDocument& rDocument,
+                SvgNode* pParent);
+            virtual ~SvgTspanNode();
+
+            virtual const SvgStyleAttributes* getSvgStyleAttributes() const;
+            virtual void parseAttribute(const rtl::OUString& rTokenName, SVGToken aSVGToken, const rtl::OUString& aContent);
+
+            /// access to SvgTextPositions
+            const SvgTextPositions& getSvgTextPositions() const { return maSvgTextPositions; }
+        };
+    } // end of namespace svgreader
+} // end of namespace svgio
+
+//////////////////////////////////////////////////////////////////////////////
+
+#endif //INCLUDED_SVGIO_SVGREADER_SVGTSPANNODE_HXX
+
+// eof

Added: incubator/ooo/branches/alg/svgreplacement/main/svgio/inc/svgio/svgreader/svgusenode.hxx
URL: http://svn.apache.org/viewvc/incubator/ooo/branches/alg/svgreplacement/main/svgio/inc/svgio/svgreader/svgusenode.hxx?rev=1209140&view=auto
==============================================================================
--- incubator/ooo/branches/alg/svgreplacement/main/svgio/inc/svgio/svgreader/svgusenode.hxx (added)
+++ incubator/ooo/branches/alg/svgreplacement/main/svgio/inc/svgio/svgreader/svgusenode.hxx Thu Dec  1 16:25:17 2011
@@ -0,0 +1,93 @@
+/**************************************************************
+ * 
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * 
+ *************************************************************/
+
+#ifndef INCLUDED_SVGIO_SVGREADER_USENODE_HXX
+#define INCLUDED_SVGIO_SVGREADER_USENODE_HXX
+
+#include <svgio/svgiodllapi.h>
+#include <svgio/svgreader/svgnode.hxx>
+#include <svgio/svgreader/svgstyleattributes.hxx>
+
+//////////////////////////////////////////////////////////////////////////////
+
+namespace svgio
+{
+    namespace svgreader
+    {
+        class SvgUseNode : public SvgNode
+        {
+        private:
+            /// use styles
+            SvgStyleAttributes          maSvgStyleAttributes;
+
+            /// variable scan values, dependent of given XAttributeList
+            basegfx::B2DHomMatrix*      mpaTransform;
+            SvgNumber                   maX;
+            SvgNumber                   maY;
+            SvgNumber                   maWidth;
+            SvgNumber                   maHeight;
+
+            /// link to content. If maXLink is set, the node can be fetched
+            // on demand by using tryToFindLink in accessors
+            rtl::OUString               maXLink;
+            const SvgNode*              mpXLink;
+
+            /// link on demand
+            void tryToFindLink();
+
+        public:
+            SvgUseNode(
+                SvgDocument& rDocument,
+                SvgNode* pParent);
+            virtual ~SvgUseNode();
+
+            virtual const SvgStyleAttributes* getSvgStyleAttributes() const;
+            virtual void parseAttribute(const rtl::OUString& rTokenName, SVGToken aSVGToken, const rtl::OUString& aContent);
+            virtual void decomposeSvgNode(drawinglayer::primitive2d::Primitive2DVector& rTarget, bool bReferenced) const;
+
+            /// transform content
+            const basegfx::B2DHomMatrix* getTransform() const { return mpaTransform; }
+            void setTransform(const basegfx::B2DHomMatrix* pMatrix = 0) { if(mpaTransform) delete mpaTransform; mpaTransform = 0; if(pMatrix) mpaTransform = new basegfx::B2DHomMatrix(*pMatrix); }
+
+            /// x content
+            const SvgNumber& getX() const { return maX; }
+            void setX(const SvgNumber& rX = SvgNumber()) { maX = rX; }
+
+            /// y content
+            const SvgNumber& getY() const { return maY; }
+            void setY(const SvgNumber& rY = SvgNumber()) { maY = rY; }
+
+            /// width content
+            const SvgNumber& getWidth() const { return maWidth; }
+            void setWidth(const SvgNumber& rWidth = SvgNumber()) { maWidth = rWidth; }
+
+            /// height content
+            const SvgNumber& getHeight() const { return maHeight; }
+            void setHeight(const SvgNumber& rHeight = SvgNumber()) { maHeight = rHeight; }
+        };
+    } // end of namespace svgreader
+} // end of namespace svgio
+
+//////////////////////////////////////////////////////////////////////////////
+
+#endif //INCLUDED_SVGIO_SVGREADER_USENODE_HXX
+
+// eof

Added: incubator/ooo/branches/alg/svgreplacement/main/svgio/prj/build.lst
URL: http://svn.apache.org/viewvc/incubator/ooo/branches/alg/svgreplacement/main/svgio/prj/build.lst?rev=1209140&view=auto
==============================================================================
--- incubator/ooo/branches/alg/svgreplacement/main/svgio/prj/build.lst (added)
+++ incubator/ooo/branches/alg/svgreplacement/main/svgio/prj/build.lst Thu Dec  1 16:25:17 2011
@@ -0,0 +1,2 @@
+dl  svgio : sal basegfx drawinglayer cppuhelper cppu svtools NULL
+dl  svgio\prj nmake - all svgio_prj NULL

Added: incubator/ooo/branches/alg/svgreplacement/main/svgio/prj/d.lst
URL: http://svn.apache.org/viewvc/incubator/ooo/branches/alg/svgreplacement/main/svgio/prj/d.lst?rev=1209140&view=auto
==============================================================================
    (empty)

Propchange: incubator/ooo/branches/alg/svgreplacement/main/svgio/prj/d.lst
------------------------------------------------------------------------------
    svn:executable = *

Added: incubator/ooo/branches/alg/svgreplacement/main/svgio/prj/makefile.mk
URL: http://svn.apache.org/viewvc/incubator/ooo/branches/alg/svgreplacement/main/svgio/prj/makefile.mk?rev=1209140&view=auto
==============================================================================
--- incubator/ooo/branches/alg/svgreplacement/main/svgio/prj/makefile.mk (added)
+++ incubator/ooo/branches/alg/svgreplacement/main/svgio/prj/makefile.mk Thu Dec  1 16:25:17 2011
@@ -0,0 +1,40 @@
+#*************************************************************************
+#
+# 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=..
+TARGET=prj
+
+.INCLUDE : settings.mk
+
+.IF "$(VERBOSE)"!=""
+VERBOSEFLAG :=
+.ELSE
+VERBOSEFLAG := -s
+.ENDIF
+
+all:
+    cd $(PRJ) && $(GNUMAKE) $(VERBOSEFLAG) -r -j$(MAXPROCESS) $(gb_MAKETARGET) && $(GNUMAKE) $(VERBOSEFLAG) -r deliverlog

Added: incubator/ooo/branches/alg/svgreplacement/main/svgio/source/svgreader/svgcharacternode.cxx
URL: http://svn.apache.org/viewvc/incubator/ooo/branches/alg/svgreplacement/main/svgio/source/svgreader/svgcharacternode.cxx?rev=1209140&view=auto
==============================================================================
--- incubator/ooo/branches/alg/svgreplacement/main/svgio/source/svgreader/svgcharacternode.cxx (added)
+++ incubator/ooo/branches/alg/svgreplacement/main/svgio/source/svgreader/svgcharacternode.cxx Thu Dec  1 16:25:17 2011
@@ -0,0 +1,724 @@
+/**************************************************************
+ * 
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * 
+ *************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_svgio.hxx"
+
+#include <svgio/svgreader/svgcharacternode.hxx>
+#include <svgio/svgreader/svgstyleattributes.hxx>
+#include <drawinglayer/attribute/fontattribute.hxx>
+#include <drawinglayer/primitive2d/textprimitive2d.hxx>
+#include <drawinglayer/primitive2d/textlayoutdevice.hxx>
+#include <drawinglayer/primitive2d/textbreakuphelper.hxx>
+#include <drawinglayer/primitive2d/groupprimitive2d.hxx>
+#include <drawinglayer/primitive2d/textdecoratedprimitive2d.hxx>
+
+//////////////////////////////////////////////////////////////////////////////
+
+namespace svgio
+{
+    namespace svgreader
+    {
+        SvgTextPositions::SvgTextPositions()
+        :   maX(),
+            maY(),
+            maDx(),
+            maDy(),
+            maRotate(),
+            maTextLength(),
+            mbLengthAdjust(true)
+        {
+        }
+
+        void SvgTextPositions::parseTextPositionAttributes(const rtl::OUString& rTokenName, SVGToken aSVGToken, const rtl::OUString& aContent)
+        {
+            // parse own
+            switch(aSVGToken)
+            {
+                case SVGTokenX:
+                {
+                    if(aContent.getLength())
+                    {
+                        SvgNumberVector aVector;
+
+                        if(readSvgNumberVector(aContent, aVector))
+                        {
+                            setX(aVector);
+                        }
+                    }
+                    break;
+                }
+                case SVGTokenY:
+                {
+                    if(aContent.getLength())
+                    {
+                        SvgNumberVector aVector;
+
+                        if(readSvgNumberVector(aContent, aVector))
+                        {
+                            setY(aVector);
+                        }
+                    }
+                    break;
+                }
+                case SVGTokenDx:
+                {
+                    if(aContent.getLength())
+                    {
+                        SvgNumberVector aVector;
+
+                        if(readSvgNumberVector(aContent, aVector))
+                        {
+                            setDx(aVector);
+                        }
+                    }
+                    break;
+                }
+                case SVGTokenDy:
+                {
+                    if(aContent.getLength())
+                    {
+                        SvgNumberVector aVector;
+
+                        if(readSvgNumberVector(aContent, aVector))
+                        {
+                            setDy(aVector);
+                        }
+                    }
+                    break;
+                }
+                case SVGTokenRotate:
+                {
+                    if(aContent.getLength())
+                    {
+                        SvgNumberVector aVector;
+
+                        if(readSvgNumberVector(aContent, aVector))
+                        {
+                            setRotate(aVector);
+                        }
+                    }
+                    break;
+                }
+                case SVGTokenTextLength:
+                {
+                    SvgNumber aNum;
+
+                    if(readSingleNumber(aContent, aNum))
+                    {
+                        if(aNum.isPositive())
+                        {
+                            setTextLength(aNum);
+                        }
+                    }
+                    break;
+                }
+                case SVGTokenLengthAdjust:
+                {
+                    if(aContent.getLength())
+                    {
+                        static rtl::OUString aStrSpacing(rtl::OUString::createFromAscii("spacing"));
+                        static rtl::OUString aStrSpacingAndGlyphs(rtl::OUString::createFromAscii("spacingAndGlyphs"));
+
+                        if(aContent.match(aStrSpacing))
+                        {
+                            setLengthAdjust(true);
+                        }
+                        else if(aContent.match(aStrSpacingAndGlyphs))
+                        {
+                            setLengthAdjust(false);
+                        }
+                    }
+                    break;
+                }
+            }
+        }
+
+    } // end of namespace svgreader
+} // end of namespace svgio
+
+//////////////////////////////////////////////////////////////////////////////
+
+namespace svgio
+{
+    namespace svgreader
+    {
+        class localTextBreakupHelper : public drawinglayer::primitive2d::TextBreakupHelper
+        {
+        private:
+            SvgTextPosition&                    mrSvgTextPosition;
+
+        protected:
+            /// allow user callback to allow changes to the new TextTransformation. Default
+            /// does nothing.
+            virtual bool allowChange(sal_uInt32 nCount, basegfx::B2DHomMatrix& rNewTransform, sal_uInt32 nIndex, sal_uInt32 nLength);
+
+        public:
+            localTextBreakupHelper(
+                const drawinglayer::primitive2d::Primitive2DReference& rxSource, 
+                SvgTextPosition& rSvgTextPosition)
+            :   drawinglayer::primitive2d::TextBreakupHelper(rxSource),
+                mrSvgTextPosition(rSvgTextPosition)
+            {
+            }
+        };
+
+        bool localTextBreakupHelper::allowChange(sal_uInt32 nCount, basegfx::B2DHomMatrix& rNewTransform, sal_uInt32 nIndex, sal_uInt32 nLength)
+        {
+            const double fRotation(mrSvgTextPosition.consumeRotation());
+
+            if(0.0 != fRotation)
+            {
+                const basegfx::B2DPoint aBasePoint(rNewTransform * basegfx::B2DPoint(0.0, 0.0));
+
+                rNewTransform.translate(-aBasePoint.getX(), -aBasePoint.getY());
+                rNewTransform.rotate(fRotation);
+                rNewTransform.translate(aBasePoint.getX(), aBasePoint.getY());
+            }
+
+            return true;
+        }
+
+    } // end of namespace svgreader
+} // end of namespace svgio
+
+//////////////////////////////////////////////////////////////////////////////
+
+namespace svgio
+{
+    namespace svgreader
+    {
+        SvgCharacterNode::SvgCharacterNode(
+            SvgDocument& rDocument,
+            SvgNode* pParent,
+            const rtl::OUString& rText)
+        :   SvgNode(SVGTokenCharacter, rDocument, pParent),
+            maText(rText)
+        {
+        }
+
+        SvgCharacterNode::~SvgCharacterNode()
+        {
+        }
+
+        const SvgStyleAttributes* SvgCharacterNode::getSvgStyleAttributes() const
+        {
+            // no own style, use parent's
+            if(getParent())
+            {
+                return getParent()->getSvgStyleAttributes();
+            }
+            else
+            {
+                return 0;
+            }
+        }
+
+        drawinglayer::primitive2d::TextSimplePortionPrimitive2D* SvgCharacterNode::createSimpleTextPrimitive(
+            SvgTextPosition& rSvgTextPosition,
+            const SvgStyleAttributes& rSvgStyleAttributes) const
+        {
+            // prepare retval, index and length
+            drawinglayer::primitive2d::TextSimplePortionPrimitive2D* pRetval = 0;
+            sal_uInt32 nIndex(0);
+            sal_uInt32 nLength(getText().getLength());
+
+            if(nLength)
+            {
+                // prepare FontAttribute
+                const rtl::OUString aFontFamily = rSvgStyleAttributes.getFontFamily().empty() ?
+                    rtl::OUString(rtl::OUString::createFromAscii("Times New Roman")) :
+                    rSvgStyleAttributes.getFontFamily()[0];
+                const ::FontWeight nFontWeight(getVclFontWeight(rSvgStyleAttributes.getFontWeight()));
+                bool bSymbol(false);
+                bool bVertical(false);
+                bool bItalic(FontStyle_italic == rSvgStyleAttributes.getFontStyle() || FontStyle_oblique == rSvgStyleAttributes.getFontStyle());
+                bool bMonospaced(false);
+                bool bOutline(false);
+                bool bRTL(false);
+                bool bBiDiStrong(false);
+                
+                const drawinglayer::attribute::FontAttribute aFontAttribute(
+                    aFontFamily,
+                    rtl::OUString(),
+                    nFontWeight,
+                    bSymbol,
+                    bVertical,
+                    bItalic,
+                    bMonospaced,
+                    bOutline,
+                    bRTL,
+                    bBiDiStrong);
+
+                // prepare FontSize
+                double fFontWidth(rSvgStyleAttributes.getFontSize().solve(*this, length));
+                double fFontHeight(fFontWidth);
+
+                // prepare locale
+                ::com::sun::star::lang::Locale aLocale;
+
+                // prepare TextLayouterDevice
+                drawinglayer::primitive2d::TextLayouterDevice aTextLayouterDevice;
+                aTextLayouterDevice.setFontAttribute(aFontAttribute, fFontWidth, fFontHeight, aLocale);
+
+                // prepare TextArray
+                ::std::vector< double > aTextArray(rSvgTextPosition.getX());
+
+                if(!aTextArray.empty() && aTextArray.size() < nLength)
+                {
+                    const sal_uInt32 nArray(aTextArray.size());
+
+                    if(nArray < nLength)
+                    {
+                        double fStartX(0.0);
+
+                        if(rSvgTextPosition.getParent() && rSvgTextPosition.getParent()->getAbsoluteX())
+                        {
+                            fStartX = rSvgTextPosition.getParent()->getPosition().getX();
+                        }
+                        else
+                        {
+                            fStartX = aTextArray[nArray - 1];
+                        }
+
+                        ::std::vector< double > aExtendArray(aTextLayouterDevice.getTextArray(getText(), nArray, nLength - nArray));
+                        aTextArray.reserve(nLength);
+
+                        for(sal_uInt32 a(0); a < aExtendArray.size(); a++)
+                        {
+                            aTextArray.push_back(aExtendArray[a] + fStartX);
+                        }
+                    }
+                }
+
+                // get current TextPosition and TextWidth in units
+                basegfx::B2DPoint aPosition(rSvgTextPosition.getPosition());
+                double fTextWidth(aTextLayouterDevice.getTextWidth(getText(), nIndex, nLength));
+
+                // check for user-given TextLength
+                if(0.0 != rSvgTextPosition.getTextLength() 
+                    && !basegfx::fTools::equal(fTextWidth, rSvgTextPosition.getTextLength()))
+                {
+                    const double fFactor(rSvgTextPosition.getTextLength() / fTextWidth);
+
+                    if(rSvgTextPosition.getLengthAdjust())
+                    {
+                        // spacing, need to create and expand TextArray
+                        if(aTextArray.empty())
+                        {
+                            aTextArray = aTextLayouterDevice.getTextArray(getText(), nIndex, nLength);
+                        }
+
+                        for(sal_uInt32 a(0); a < aTextArray.size(); a++)
+                        {
+                            aTextArray[a] *= fFactor;
+                        }
+                    }
+                    else
+                    {
+                        // spacing and glyphs, just apply to FontWidth
+                        fFontWidth *= fFactor;
+                    }
+
+                    fTextWidth = rSvgTextPosition.getTextLength();
+                }
+
+                // get TextAlign
+                TextAlign aTextAlign(rSvgStyleAttributes.getTextAlign());
+
+                // map TextAnchor to TextAlign, there seems not to be a difference
+                if(TextAnchor_notset != rSvgStyleAttributes.getTextAnchor())
+                {
+                    switch(rSvgStyleAttributes.getTextAnchor())
+                    {
+                        case TextAnchor_start:
+                        {
+                            aTextAlign = TextAlign_left;
+                            break;
+                        }
+                        case TextAnchor_middle:
+                        {
+                            aTextAlign = TextAlign_center;
+                            break;
+                        }
+                        case TextAnchor_end:
+                        {
+                            aTextAlign = TextAlign_right;
+                            break;
+                        }
+                    }
+                }
+
+                // apply TextAlign
+                switch(aTextAlign)
+                {
+                    case TextAlign_right:
+                    {
+                        aPosition.setX(aPosition.getX() - fTextWidth);
+                        break;
+                    }
+                    case TextAlign_center:
+                    {
+                        aPosition.setX(aPosition.getX() - (fTextWidth * 0.5));
+                        break;
+                    }
+                    case TextAlign_notset:
+                    case TextAlign_left:
+                    case TextAlign_justify:
+                    {
+                        // TextAlign_notset, TextAlign_left: nothing to do
+                        // TextAlign_justify is not clear currently; handle as TextAlign_left
+                        break;
+                    }
+                }
+
+                // get fill color
+                const basegfx::BColor aFill(rSvgStyleAttributes.getFill() 
+                    ? *rSvgStyleAttributes.getFill() 
+                    : basegfx::BColor(0.0, 0.0, 0.0));
+
+                // prepare TextTransformation
+                basegfx::B2DHomMatrix aTextTransform;
+
+                aTextTransform.scale(fFontWidth, fFontHeight);
+                aTextTransform.translate(aPosition.getX(), aPosition.getY());
+
+                // check TextDecoration and if TextDecoratedPortionPrimitive2D is needed
+                const TextDecoration aDeco(rSvgStyleAttributes.getTextDecoration());
+
+                if(TextDecoration_underline == aDeco 
+                    || TextDecoration_overline == aDeco 
+                    || TextDecoration_line_through == aDeco)
+                {
+                    // get the fill for decroation as described by SVG. We cannot
+                    // have different stroke colors/definitions for those, though
+                    const SvgStyleAttributes* pDecoDef = rSvgStyleAttributes.getTextDecorationDefiningSvgStyleAttributes();
+                    const basegfx::BColor aDecoColor(pDecoDef && pDecoDef->getFill() ? *pDecoDef->getFill() : aFill);
+
+                    // create decorated text primitive
+                    pRetval = new drawinglayer::primitive2d::TextDecoratedPortionPrimitive2D(
+                        aTextTransform,
+                        getText(),
+                        nIndex,
+                        nLength,
+                        aTextArray,
+                        aFontAttribute,
+                        aLocale,
+                        aFill,
+
+                        // extra props for decorated
+                        aDecoColor,
+                        aDecoColor,
+                        TextDecoration_overline == aDeco ? drawinglayer::primitive2d::TEXT_LINE_SINGLE : drawinglayer::primitive2d::TEXT_LINE_NONE,
+                        TextDecoration_underline == aDeco ? drawinglayer::primitive2d::TEXT_LINE_SINGLE : drawinglayer::primitive2d::TEXT_LINE_NONE,
+                        false,
+                        TextDecoration_line_through == aDeco ? drawinglayer::primitive2d::TEXT_STRIKEOUT_SINGLE : drawinglayer::primitive2d::TEXT_STRIKEOUT_NONE,
+                        false,
+                        drawinglayer::primitive2d::TEXT_EMPHASISMARK_NONE,
+                        true,
+                        false,
+                        drawinglayer::primitive2d::TEXT_RELIEF_NONE,
+                        false);
+                }
+                else
+                {
+                    // create text primitive
+                    pRetval = new drawinglayer::primitive2d::TextSimplePortionPrimitive2D(
+                        aTextTransform,
+                        getText(),
+                        nIndex,
+                        nLength,
+                        aTextArray,
+                        aFontAttribute,
+                        aLocale,
+                        aFill);
+                }
+
+                // advance current TextPosition
+                rSvgTextPosition.setPosition(rSvgTextPosition.getPosition() + basegfx::B2DVector(fTextWidth, 0.0));
+            }
+
+            return pRetval;
+        }
+
+        void SvgCharacterNode::decomposeTextWithStyle(
+            drawinglayer::primitive2d::Primitive2DVector& rTarget, 
+            SvgTextPosition& rSvgTextPosition,
+            const SvgStyleAttributes& rSvgStyleAttributes) const
+        {
+            drawinglayer::primitive2d::TextSimplePortionPrimitive2D* pNew = createSimpleTextPrimitive(
+                rSvgTextPosition, rSvgStyleAttributes);
+
+            if(pNew)
+            {
+                if(!rSvgTextPosition.isRotated())
+                {
+                    rTarget.push_back(pNew);
+                }
+                else
+                {
+                    // need to apply rotations to each character as given
+                    const drawinglayer::primitive2d::Primitive2DReference xRef(pNew);
+                    localTextBreakupHelper alocalTextBreakupHelper(xRef, rSvgTextPosition);
+                    const drawinglayer::primitive2d::Primitive2DSequence aResult(
+                        alocalTextBreakupHelper.getResult(drawinglayer::primitive2d::BreakupUnit_character));
+
+                    if(aResult.hasElements())
+                    {
+                        rTarget.push_back(new drawinglayer::primitive2d::GroupPrimitive2D(aResult));
+                    }
+
+                    // also consume for the implied single space
+                    rSvgTextPosition.consumeRotation();
+                }
+            }
+        }
+
+        void SvgCharacterNode::whiteSpaceHandling()
+        {
+            if(XmlSpace_default == getXmlSpace())
+            {
+                maText = whiteSpaceHandlingDefault(maText);
+            }
+            else
+            {
+                maText = whiteSpaceHandlingPreserve(maText);
+            }
+        }
+
+        void SvgCharacterNode::addGap()
+        {
+            maText += rtl::OUString(sal_Unicode(' '));
+        }
+
+        void SvgCharacterNode::concatenate(const rtl::OUString& rText)
+        {
+            maText += rText;
+        }
+
+        void SvgCharacterNode::decomposeText(drawinglayer::primitive2d::Primitive2DVector& rTarget, SvgTextPosition& rSvgTextPosition) const
+        {
+            if(getText().getLength())
+            {
+                const SvgStyleAttributes* pSvgStyleAttributes = getSvgStyleAttributes();
+
+                if(pSvgStyleAttributes)
+                {
+                    decomposeTextWithStyle(rTarget, rSvgTextPosition, *pSvgStyleAttributes);
+                }
+            }
+        }
+
+    } // end of namespace svgreader
+} // end of namespace svgio
+
+//////////////////////////////////////////////////////////////////////////////
+
+namespace svgio
+{
+    namespace svgreader
+    {
+        SvgTextPosition::SvgTextPosition(
+            SvgTextPosition* pParent,
+            const InfoProvider& rInfoProvider,
+            const SvgTextPositions& rSvgTextPositions)
+        :   mpParent(pParent),
+            maX(), // computed below
+            maY(), // computed below
+            maRotate(solveSvgNumberVector(rSvgTextPositions.getRotate(), rInfoProvider, length)),
+            mfTextLength(0.0),
+            maPosition(), // computed below
+            mnRotationIndex(0),
+            mbLengthAdjust(rSvgTextPositions.getLengthAdjust()),
+            mbAbsoluteX(false),
+            mbAbsoluteY(false)
+        {
+            // get TextLength if provided
+            if(rSvgTextPositions.getTextLength().isSet())
+            {
+                mfTextLength = rSvgTextPositions.getTextLength().solve(rInfoProvider, length);
+            }
+
+            // SVG does not really define in which units a ‘rotate’ for Text/TSpan is given,
+            // but it seems to be degrees. Convert here to radians
+            if(!maRotate.empty())
+            {
+                const double fFactor(F_PI / 180.0);
+
+                for(sal_uInt32 a(0); a < maRotate.size(); a++)
+                {
+                    maRotate[a] *= fFactor;
+                }
+            }
+
+            // get text positions X
+            const sal_uInt32 nSizeX(rSvgTextPositions.getX().size());
+
+            if(nSizeX)
+            {
+                // we have absolute positions, get first one as current text position X
+                maPosition.setX(rSvgTextPositions.getX()[0].solve(rInfoProvider, xcoordinate));
+                mbAbsoluteX = true;
+
+                if(nSizeX > 1)
+                {
+                    // fill deltas to maX
+                    maX.reserve(nSizeX);
+
+                    for(sal_uInt32 a(1); a < nSizeX; a++)
+                    {
+                        maX.push_back(rSvgTextPositions.getX()[a].solve(rInfoProvider, xcoordinate) - maPosition.getX());
+                    }
+                }
+            }
+            else
+            {
+                // no absolute position, get from parent
+                if(pParent)
+                {
+                    maPosition.setX(pParent->getPosition().getX());
+                }
+
+                const sal_uInt32 nSizeDx(rSvgTextPositions.getDx().size());
+
+                if(nSizeDx)
+                {
+                    // relative positions given, translate position derived from parent
+                    maPosition.setX(maPosition.getX() + rSvgTextPositions.getDx()[0].solve(rInfoProvider, xcoordinate));
+
+                    if(nSizeDx > 1)
+                    {
+                        // fill deltas to maX
+                        maX.reserve(nSizeDx);
+
+                        for(sal_uInt32 a(1); a < nSizeDx; a++)
+                        {
+                            maX.push_back(rSvgTextPositions.getDx()[a].solve(rInfoProvider, xcoordinate));
+                        }
+                    }
+                }
+            }
+
+            // get text positions Y
+            const sal_uInt32 nSizeY(rSvgTextPositions.getY().size());
+
+            if(nSizeY)
+            {
+                // we have absolute positions, get first one as current text position Y
+                maPosition.setY(rSvgTextPositions.getY()[0].solve(rInfoProvider, ycoordinate));
+                mbAbsoluteX = true;
+
+                if(nSizeY > 1)
+                {
+                    // fill deltas to maY
+                    maY.reserve(nSizeY);
+
+                    for(sal_uInt32 a(1); a < nSizeY; a++)
+                    {
+                        maY.push_back(rSvgTextPositions.getY()[a].solve(rInfoProvider, ycoordinate) - maPosition.getY());
+                    }
+                }
+            }
+            else
+            {
+                // no absolute position, get from parent
+                if(pParent)
+                {
+                    maPosition.setY(pParent->getPosition().getY());
+                }
+
+                const sal_uInt32 nSizeDy(rSvgTextPositions.getDy().size());
+
+                if(nSizeDy)
+                {
+                    // relative positions given, translate position derived from parent
+                    maPosition.setY(maPosition.getY() + rSvgTextPositions.getDy()[0].solve(rInfoProvider, ycoordinate));
+
+                    if(nSizeDy > 1)
+                    {
+                        // fill deltas to maY
+                        maY.reserve(nSizeDy);
+
+                        for(sal_uInt32 a(1); a < nSizeDy; a++)
+                        {
+                            maY.push_back(rSvgTextPositions.getDy()[a].solve(rInfoProvider, ycoordinate));
+                        }
+                    }
+                }
+            }
+        }
+
+        bool SvgTextPosition::isRotated() const
+        {
+            if(maRotate.empty())
+            {
+                if(getParent())
+                {
+                    return getParent()->isRotated();
+                }
+                else
+                {
+                    return false;
+                }
+            }
+            else
+            {
+                return true;
+            }
+        }
+
+        double SvgTextPosition::consumeRotation()
+        {
+            double fRetval(0.0);
+
+            if(maRotate.empty())
+            {
+                if(getParent())
+                {
+                    fRetval = mpParent->consumeRotation();
+                }
+                else
+                {
+                    fRetval = 0.0;
+                }
+            }
+            else
+            {
+                const sal_uInt32 nSize(maRotate.size());
+
+                if(mnRotationIndex < nSize)
+                {
+                    fRetval = maRotate[mnRotationIndex++];
+                }
+                else
+                {
+                    fRetval = maRotate[nSize - 1];
+                }
+            }
+
+            return fRetval;
+        }
+
+    } // end of namespace svgreader
+} // end of namespace svgio
+
+//////////////////////////////////////////////////////////////////////////////
+// eof

Added: incubator/ooo/branches/alg/svgreplacement/main/svgio/source/svgreader/svgcirclenode.cxx
URL: http://svn.apache.org/viewvc/incubator/ooo/branches/alg/svgreplacement/main/svgio/source/svgreader/svgcirclenode.cxx?rev=1209140&view=auto
==============================================================================
--- incubator/ooo/branches/alg/svgreplacement/main/svgio/source/svgreader/svgcirclenode.cxx (added)
+++ incubator/ooo/branches/alg/svgreplacement/main/svgio/source/svgreader/svgcirclenode.cxx Thu Dec  1 16:25:17 2011
@@ -0,0 +1,147 @@
+/**************************************************************
+ * 
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * 
+ *************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_svgio.hxx"
+
+#include <svgio/svgreader/svgcirclenode.hxx>
+#include <basegfx/polygon/b2dpolygon.hxx>
+#include <basegfx/polygon/b2dpolygontools.hxx>
+
+//////////////////////////////////////////////////////////////////////////////
+
+namespace svgio
+{
+    namespace svgreader
+    {
+        SvgCircleNode::SvgCircleNode(
+            SvgDocument& rDocument,
+            SvgNode* pParent)
+        :   SvgNode(SVGTokenCircle, rDocument, pParent),
+            maSvgStyleAttributes(*this),
+            maCx(0),
+            maCy(0),
+            maR(0),
+            mpaTransform(0)
+        {
+        }
+
+        SvgCircleNode::~SvgCircleNode()
+        {
+            if(mpaTransform) delete mpaTransform;
+        }
+
+        const SvgStyleAttributes* SvgCircleNode::getSvgStyleAttributes() const
+        {
+            static rtl::OUString aClassStr(rtl::OUString::createFromAscii("circle"));
+            maSvgStyleAttributes.checkForCssStyle(aClassStr);
+
+            return &maSvgStyleAttributes;
+        }
+
+        void SvgCircleNode::parseAttribute(const rtl::OUString& rTokenName, SVGToken aSVGToken, const rtl::OUString& aContent)
+        {
+            // call parent
+            SvgNode::parseAttribute(rTokenName, aSVGToken, aContent);
+
+            // read style attributes
+            maSvgStyleAttributes.parseStyleAttribute(rTokenName, aSVGToken, aContent);
+
+            // parse own
+            switch(aSVGToken)
+            {
+                case SVGTokenStyle:
+                {
+                    maSvgStyleAttributes.readStyle(aContent);
+                    break;
+                }
+                case SVGTokenCx:
+                {
+                    SvgNumber aNum;
+
+                    if(readSingleNumber(aContent, aNum))
+                    {
+                        setCx(aNum);
+                    }
+                    break;
+                }
+                case SVGTokenCy:
+                {
+                    SvgNumber aNum;
+
+                    if(readSingleNumber(aContent, aNum))
+                    {
+                        setCy(aNum);
+                    }
+                    break;
+                }
+                case SVGTokenR:
+                {
+                    SvgNumber aNum;
+
+                    if(readSingleNumber(aContent, aNum))
+                    {
+                        if(aNum.isPositive())
+                        {
+                            setR(aNum);
+                        }
+                    }
+                    break;
+                }
+                case SVGTokenTransform:
+                {
+                    const basegfx::B2DHomMatrix aMatrix(readTransform(aContent, *this));
+
+                    if(!aMatrix.isIdentity())
+                    {
+                        setTransform(&aMatrix);
+                    }
+                    break;
+                }
+            }
+        }
+
+        void SvgCircleNode::decomposeSvgNode(drawinglayer::primitive2d::Primitive2DVector& rTarget, bool bReferenced) const
+        {
+            const SvgStyleAttributes* pStyle = getSvgStyleAttributes();
+
+            if(pStyle && getR().isSet())
+            {
+                const double fR(getR().solve(*this, xcoordinate));
+
+                if(fR > 0.0)
+                {
+                    const basegfx::B2DPolygon aPath(
+                        basegfx::tools::createPolygonFromCircle(
+                            basegfx::B2DPoint(
+                                getCx().isSet() ? getCx().solve(*this, xcoordinate) : 0.0,
+                                getCy().isSet() ? getCy().solve(*this, ycoordinate) : 0.0),
+                            fR));
+
+                    pStyle->add_path(basegfx::B2DPolyPolygon(aPath), rTarget, getTransform());
+                }
+            }
+        }
+    } // end of namespace svgreader
+} // end of namespace svgio
+
+//////////////////////////////////////////////////////////////////////////////
+// eof

Added: incubator/ooo/branches/alg/svgreplacement/main/svgio/source/svgreader/svgdocument.cxx
URL: http://svn.apache.org/viewvc/incubator/ooo/branches/alg/svgreplacement/main/svgio/source/svgreader/svgdocument.cxx?rev=1209140&view=auto
==============================================================================
--- incubator/ooo/branches/alg/svgreplacement/main/svgio/source/svgreader/svgdocument.cxx (added)
+++ incubator/ooo/branches/alg/svgreplacement/main/svgio/source/svgreader/svgdocument.cxx Thu Dec  1 16:25:17 2011
@@ -0,0 +1,120 @@
+/**************************************************************
+ * 
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * 
+ *************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_svgio.hxx"
+
+#include <svgio/svgreader/svgdocument.hxx>
+
+//////////////////////////////////////////////////////////////////////////////
+
+namespace svgio
+{
+    namespace svgreader
+    {
+        SvgDocument::SvgDocument()
+        :   maNodes(),
+            maIdTokenMapperList(),
+            maIdStyleTokenMapperList()
+        {
+        }
+
+        SvgDocument::~SvgDocument()
+        {
+            while(!maNodes.empty())
+            {
+                SvgNode* pCandidate = maNodes[maNodes.size() - 1];
+                delete pCandidate;
+                maNodes.pop_back();
+            }
+        }
+
+        void SvgDocument::appendNode(SvgNode* pNode)
+        {
+            OSL_ENSURE(pNode, "OOps, empty node added (!)");
+            maNodes.push_back(pNode);
+        }
+
+        void SvgDocument::addSvgNodeToMapper(const rtl::OUString& rStr, const SvgNode& rNode)
+        {
+            if(rStr.getLength())
+            {
+                maIdTokenMapperList.insert(IdTokenValueType(rStr, &rNode));
+            }
+        }
+
+        void SvgDocument::removeSvgNodeFromMapper(const rtl::OUString& rStr)
+        {
+            if(rStr.getLength())
+            {
+                maIdTokenMapperList.erase(rStr);
+            }
+        }
+
+        const SvgNode* SvgDocument::findSvgNodeById(const rtl::OUString& rStr) const
+        {
+            const IdTokenMapper::const_iterator aResult(maIdTokenMapperList.find(rStr));
+
+            if(aResult == maIdTokenMapperList.end())
+            {
+                return 0;
+            }
+            else
+            {
+                return aResult->second;
+            }
+        }
+
+        void SvgDocument::addSvgStyleAttributesToMapper(const rtl::OUString& rStr, const SvgStyleAttributes& rSvgStyleAttributes)
+        {
+            if(rStr.getLength())
+            {
+                maIdStyleTokenMapperList.insert(IdStyleTokenValueType(rStr, &rSvgStyleAttributes));
+            }
+        }
+
+        void SvgDocument::removeSvgStyleAttributesFromMapper(const rtl::OUString& rStr)
+        {
+            if(rStr.getLength())
+            {
+                maIdStyleTokenMapperList.erase(rStr);
+            }
+        }
+
+        const SvgStyleAttributes* SvgDocument::findSvgStyleAttributesById(const rtl::OUString& rStr) const
+        {
+            const IdStyleTokenMapper::const_iterator aResult(maIdStyleTokenMapperList.find(rStr));
+
+            if(aResult == maIdStyleTokenMapperList.end())
+            {
+                return 0;
+            }
+            else
+            {
+                return aResult->second;
+            }
+        }
+
+    } // end of namespace svgreader
+} // end of namespace svgio
+
+//////////////////////////////////////////////////////////////////////////////
+// eof

Added: incubator/ooo/branches/alg/svgreplacement/main/svgio/source/svgreader/svgdocumenthandler.cxx
URL: http://svn.apache.org/viewvc/incubator/ooo/branches/alg/svgreplacement/main/svgio/source/svgreader/svgdocumenthandler.cxx?rev=1209140&view=auto
==============================================================================
--- incubator/ooo/branches/alg/svgreplacement/main/svgio/source/svgreader/svgdocumenthandler.cxx (added)
+++ incubator/ooo/branches/alg/svgreplacement/main/svgio/source/svgreader/svgdocumenthandler.cxx Thu Dec  1 16:25:17 2011
@@ -0,0 +1,469 @@
+/**************************************************************
+ * 
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * 
+ *************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_svgio.hxx"
+
+#include <svgio/svgreader/svgdocumenthandler.hxx>
+#include <svgio/svgreader/svgtoken.hxx>
+#include <svgio/svgreader/svgsvgnode.hxx>
+#include <svgio/svgreader/svggnode.hxx>
+#include <svgio/svgreader/svgnode.hxx>
+#include <svgio/svgreader/svgpathnode.hxx>
+#include <svgio/svgreader/svgrectnode.hxx>
+#include <svgio/svgreader/svggradientnode.hxx>
+#include <svgio/svgreader/svggradientstopnode.hxx>
+#include <svgio/svgreader/svgsymbolnode.hxx>
+#include <svgio/svgreader/svgusenode.hxx>
+#include <svgio/svgreader/svgcirclenode.hxx>
+#include <svgio/svgreader/svgellipsenode.hxx>
+#include <svgio/svgreader/svglinenode.hxx>
+#include <svgio/svgreader/svgpolynode.hxx>
+#include <svgio/svgreader/svgsymbolnode.hxx>
+#include <svgio/svgreader/svgtextnode.hxx>
+#include <svgio/svgreader/svgcharacternode.hxx>
+#include <svgio/svgreader/svgtspannode.hxx>
+#include <svgio/svgreader/svgtrefnode.hxx>
+#include <svgio/svgreader/svgtextpathnode.hxx>
+#include <svgio/svgreader/svgstylenode.hxx>
+#include <svgio/svgreader/svgimagenode.hxx>
+
+//////////////////////////////////////////////////////////////////////////////
+
+using namespace com::sun::star;
+
+//////////////////////////////////////////////////////////////////////////////
+
+namespace
+{
+    svgio::svgreader::SvgCharacterNode* whiteSpaceHandling(svgio::svgreader::SvgNode* pNode, svgio::svgreader::SvgCharacterNode* pLast)
+    {
+        if(pNode)
+        {
+            const svgio::svgreader::SvgNodeVector& rChilds = pNode->getChildren();
+            const sal_uInt32 nCount(rChilds.size());
+
+            for(sal_uInt32 a(0); a < nCount; a++)
+            {
+                svgio::svgreader::SvgNode* pCandidate = rChilds[a];
+
+                if(pCandidate)
+                {
+                    switch(pCandidate->getType())
+                    {
+                        case svgio::svgreader::SVGTokenCharacter:
+                        {
+                            // clean whitespace in text span
+                            svgio::svgreader::SvgCharacterNode* pCharNode = static_cast< svgio::svgreader::SvgCharacterNode* >(pCandidate);
+                            pCharNode->whiteSpaceHandling();
+
+                            // pCharNode may have lost all text. If that's the case, ignore
+                            // as invalid character node
+                            if(pCharNode->getText().getLength())
+                            {
+                                if(pLast)
+                                {
+                                    // add in-between whitespace (single space) to last
+                                    // known character node
+                                    pLast->addGap();
+                                }
+
+                                // remember new last corected character node
+                                pLast = pCharNode;
+                            }
+                            break;
+                        }
+                        case svgio::svgreader::SVGTokenTspan:
+                        case svgio::svgreader::SVGTokenTextPath:
+                        case svgio::svgreader::SVGTokenTref:
+                        {
+                            // recursively clean whitespaces in subhierarchy
+                            pLast = whiteSpaceHandling(pCandidate, pLast);
+                            break;
+                        }
+                        default:
+                        {
+                            OSL_ENSURE(false, "Unexpected token inside SVGTokenText (!)");
+                            break;
+                        }
+                    }
+                }
+            }
+        }
+
+        return pLast;
+    }
+}
+
+//////////////////////////////////////////////////////////////////////////////
+
+namespace svgio
+{
+    namespace svgreader
+    {
+        SvgDocHdl::SvgDocHdl()
+        :   maDocument(),
+            mpTarget(0)
+        {
+        }
+
+        SvgDocHdl::~SvgDocHdl()
+        {
+#ifdef DBG_UTIL
+            if(mpTarget)
+            {
+                OSL_ENSURE(false, "SvgDocHdl destructed with active target (!)");
+                delete mpTarget;
+            }
+#endif
+        }
+
+        void SvgDocHdl::startDocument(  ) throw (xml::sax::SAXException, uno::RuntimeException)
+        {
+            OSL_ENSURE(!mpTarget, "Already a target at document start (!)");
+        }
+
+        void SvgDocHdl::endDocument(  ) throw (xml::sax::SAXException, uno::RuntimeException)
+        {
+            OSL_ENSURE(!mpTarget, "Still a target at document end (!)");
+        }
+
+        void SvgDocHdl::startElement( const ::rtl::OUString& aName, const uno::Reference< xml::sax::XAttributeList >& xAttribs ) throw (xml::sax::SAXException, uno::RuntimeException)
+        {
+            if(aName.getLength())
+            {
+                const SVGToken aSVGToken(StrToSVGToken(aName));
+
+                switch(aSVGToken)
+                {
+                    /// structural elements
+                    case SVGTokenSymbol:
+                    {
+                        /// new basic node for Symbol. Content gets scanned, but
+                        /// will not be decomposed (see SvgNode::decomposeSvgNode and bReferenced)
+                        mpTarget = new SvgSymbolNode(maDocument, mpTarget);
+                        mpTarget->parseAttributes(xAttribs);
+                        break;
+                    }
+                    case SVGTokenDefs:
+                    case SVGTokenG:
+                    {
+                        /// new node for Defs/G
+                        mpTarget = new SvgGNode(aSVGToken, maDocument, mpTarget);
+                        mpTarget->parseAttributes(xAttribs);
+                        break;
+                    }
+                    case SVGTokenSvg:
+                    {
+                        /// new node for Svg
+                        mpTarget = new SvgSvgNode(maDocument, mpTarget);
+                        mpTarget->parseAttributes(xAttribs);
+                        break;
+                    }
+                    case SVGTokenUse:
+                    {
+                        /// new node for Use
+                        mpTarget = new SvgUseNode(maDocument, mpTarget);
+                        mpTarget->parseAttributes(xAttribs);
+                        break;
+                    }
+
+                    /// shape elements
+                    case SVGTokenCircle:
+                    {
+                        /// new node for Circle
+                        mpTarget = new SvgCircleNode(maDocument, mpTarget);
+                        mpTarget->parseAttributes(xAttribs);
+                        break;
+                    }
+                    case SVGTokenEllipse:
+                    {
+                        /// new node for Ellipse
+                        mpTarget = new SvgEllipseNode(maDocument, mpTarget);
+                        mpTarget->parseAttributes(xAttribs);
+                        break;
+                    }
+                    case SVGTokenLine:
+                    {
+                        /// new node for Line
+                        mpTarget = new SvgLineNode(maDocument, mpTarget);
+                        mpTarget->parseAttributes(xAttribs);
+                        break;
+                    }
+                    case SVGTokenPath:
+                    {
+                        /// new node for Path
+                        mpTarget = new SvgPathNode(maDocument, mpTarget);
+                        mpTarget->parseAttributes(xAttribs);
+                        break;
+                    }
+                    case SVGTokenPolygon:
+                    {
+                        /// new node for Polygon
+                        mpTarget = new SvgPolyNode(maDocument, mpTarget, false);
+                        mpTarget->parseAttributes(xAttribs);
+                        break;
+                    }
+                    case SVGTokenPolyline:
+                    {
+                        /// new node for Polyline
+                        mpTarget = new SvgPolyNode(maDocument, mpTarget, true);
+                        mpTarget->parseAttributes(xAttribs);
+                        break;
+                    }
+                    case SVGTokenRect:
+                    {
+                        /// new node for Rect
+                        mpTarget = new SvgRectNode(maDocument, mpTarget);
+                        mpTarget->parseAttributes(xAttribs);
+                        break;
+                    }
+                    case SVGTokenImage:
+                    {
+                        /// new node for Image
+                        mpTarget = new SvgImageNode(maDocument, mpTarget);
+                        mpTarget->parseAttributes(xAttribs);
+                        break;
+                    }
+
+                    /// gradients
+                    case SVGTokenLinearGradient:
+                    case SVGTokenRadialGradient:
+                    {
+                        mpTarget = new SvgGradientNode(aSVGToken, maDocument, mpTarget);
+                        mpTarget->parseAttributes(xAttribs);
+                        break;
+                    }
+
+                    /// gradient stops
+                    case SVGTokenStop:
+                    {
+                        mpTarget = new SvgGradientStopNode(maDocument, mpTarget);
+                        mpTarget->parseAttributes(xAttribs);
+                        break;
+                    }
+
+                    /// text
+                    case SVGTokenText:
+                    {
+                        mpTarget = new SvgTextNode(maDocument, mpTarget);
+                        mpTarget->parseAttributes(xAttribs);
+                        break;
+                    }
+                    case SVGTokenTspan:
+                    {
+                        mpTarget = new SvgTspanNode(maDocument, mpTarget);
+                        mpTarget->parseAttributes(xAttribs);
+                        break;
+                    }
+                    case SVGTokenTref:
+                    {
+                        mpTarget = new SvgTrefNode(maDocument, mpTarget);
+                        mpTarget->parseAttributes(xAttribs);
+                        break;
+                    }
+                    case SVGTokenTextPath:
+                    {
+                        mpTarget = new SvgTextPathNode(maDocument, mpTarget);
+                        mpTarget->parseAttributes(xAttribs);
+                        break;
+                    }
+                    
+                    /// styles (as stylesheets)
+                    case SVGTokenStyle:
+                    {
+                        mpTarget = new SvgStyleNode(maDocument, mpTarget);
+                        mpTarget->parseAttributes(xAttribs);
+                        break;
+                    }
+
+                    default:
+                    {
+                        /// invalid token, ignore
+#ifdef DBG_UTIL
+                        myAssert(
+                            rtl::OUString::createFromAscii("Unknown Base SvgToken <") + 
+                            aName + 
+                            rtl::OUString::createFromAscii("> (!)"));
+#endif
+                        break;
+                    }
+                }
+            }
+        }
+
+        void SvgDocHdl::endElement( const ::rtl::OUString& aName ) throw (xml::sax::SAXException, uno::RuntimeException)
+        {
+            if(aName.getLength())
+            {
+                const SVGToken aSVGToken(StrToSVGToken(aName));
+                SvgNode* pWhitespaceCheck(SVGTokenText == aSVGToken ? mpTarget : 0);
+
+                switch(aSVGToken)
+                {
+                    /// valid tokens for which a new one was created
+                    
+                    /// structural elements
+                    case SVGTokenDefs:
+                    case SVGTokenG:
+                    case SVGTokenSvg:
+                    case SVGTokenSymbol:
+                    case SVGTokenUse:
+
+                    /// shape elements
+                    case SVGTokenCircle:
+                    case SVGTokenEllipse:
+                    case SVGTokenLine:
+                    case SVGTokenPath:
+                    case SVGTokenPolygon:
+                    case SVGTokenPolyline:
+                    case SVGTokenRect:
+                    case SVGTokenImage:
+                    
+                    /// gradients
+                    case SVGTokenLinearGradient:
+                    case SVGTokenRadialGradient:
+
+                    /// gradient stops
+                    case SVGTokenStop:
+
+                    /// text
+                    case SVGTokenText:
+                    case SVGTokenTspan:
+                    case SVGTokenTextPath:
+                    case SVGTokenTref:
+                    
+                    /// styles (as stylesheets)
+                    case SVGTokenStyle:
+
+                    /// content handling after parsing
+                    {
+                        if(mpTarget)
+                        {
+                            if(!mpTarget->getParent())
+                            {
+                                // last element closing, save this tree
+                                maDocument.appendNode(mpTarget);
+                            }
+
+                            mpTarget = const_cast< SvgNode* >(mpTarget->getParent());
+                        }
+                        else
+                        {
+                            OSL_ENSURE(false, "Closing token, but no context (!)");
+                        }
+                        break;
+                    }
+                    default:
+                    {
+                        /// invalid token, ignore
+                    }
+                }
+
+                if(pWhitespaceCheck)
+                {
+                    // cleanup read strings
+                    whiteSpaceHandling(pWhitespaceCheck, 0);
+                }
+            }
+        }
+
+        void SvgDocHdl::characters( const ::rtl::OUString& aChars ) throw (xml::sax::SAXException, uno::RuntimeException)
+        {
+            if(mpTarget)
+            {
+                const sal_uInt32 nLength(aChars.getLength());
+
+                if(nLength &&
+                    (SVGTokenText == mpTarget->getType() || 
+                    SVGTokenTspan == mpTarget->getType() || 
+                    SVGTokenTextPath == mpTarget->getType() ||
+                    SVGTokenStyle == mpTarget->getType()))
+                {
+                    switch(mpTarget->getType())
+                    {
+                        case SVGTokenText:
+                        case SVGTokenTspan:
+                        case SVGTokenTextPath:
+                        {
+                            const SvgNodeVector& rChilds = mpTarget->getChildren();
+                            SvgCharacterNode* pTarget = 0;
+
+                            if(rChilds.size())
+                            {
+                                pTarget = dynamic_cast< SvgCharacterNode* >(rChilds[rChilds.size() - 1]);
+                            }
+
+                            if(pTarget)
+                            {
+                                // concatenate to current character span
+                                pTarget->concatenate(aChars);
+                            }
+                            else
+                            {
+                                // add character span as simplified tspan (no arguments)
+                                // as direct child of SvgTextNode/SvgTspanNode/SvgTextPathNode
+                                new SvgCharacterNode(maDocument, mpTarget, aChars);
+                            }
+                            break;
+                        }
+                        case SVGTokenStyle:
+                        {
+                            SvgStyleNode& rSvgStyleNode = static_cast< SvgStyleNode& >(*mpTarget);
+
+                            if(rSvgStyleNode.isTextCss())
+                            {
+                                // need to interpret css styles and remember them as StyleSheets
+                                const ::rtl::OUString aTrimmedChars(aChars.trim());
+                                
+                                if(aTrimmedChars.getLength())
+                                {
+                                    rSvgStyleNode.addCssStyleSheet(aTrimmedChars);
+                                }
+                            }
+                            break;
+                        }
+                        default:
+                        {
+                            // characters not used by a known node
+                            break;
+                        }
+                    }
+                }
+            }
+        }
+
+        void SvgDocHdl::ignorableWhitespace( const ::rtl::OUString& aWhitespaces ) throw (xml::sax::SAXException, uno::RuntimeException)
+        {
+        }
+
+        void SvgDocHdl::processingInstruction( const ::rtl::OUString& aTarget, const ::rtl::OUString& aData ) throw (xml::sax::SAXException, uno::RuntimeException)
+        {
+        }
+
+        void SvgDocHdl::setDocumentLocator( const uno::Reference< xml::sax::XLocator >& xLocator ) throw (xml::sax::SAXException, uno::RuntimeException)
+        {
+        }
+    } // end of namespace svgreader
+} // end of namespace svgio
+
+//////////////////////////////////////////////////////////////////////////////
+// eof

Added: incubator/ooo/branches/alg/svgreplacement/main/svgio/source/svgreader/svgellipsenode.cxx
URL: http://svn.apache.org/viewvc/incubator/ooo/branches/alg/svgreplacement/main/svgio/source/svgreader/svgellipsenode.cxx?rev=1209140&view=auto
==============================================================================
--- incubator/ooo/branches/alg/svgreplacement/main/svgio/source/svgreader/svgellipsenode.cxx (added)
+++ incubator/ooo/branches/alg/svgreplacement/main/svgio/source/svgreader/svgellipsenode.cxx Thu Dec  1 16:25:17 2011
@@ -0,0 +1,162 @@
+/**************************************************************
+ * 
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * 
+ *************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_svgio.hxx"
+
+#include <svgio/svgreader/svgellipsenode.hxx>
+#include <basegfx/polygon/b2dpolygon.hxx>
+#include <basegfx/polygon/b2dpolygontools.hxx>
+
+//////////////////////////////////////////////////////////////////////////////
+
+namespace svgio
+{
+    namespace svgreader
+    {
+        SvgEllipseNode::SvgEllipseNode(
+            SvgDocument& rDocument,
+            SvgNode* pParent)
+        :   SvgNode(SVGTokenEllipse, rDocument, pParent),
+            maSvgStyleAttributes(*this),
+            maCx(0),
+            maCy(0),
+            maRx(0),
+            maRy(0),
+            mpaTransform(0)
+        {
+        }
+
+        SvgEllipseNode::~SvgEllipseNode()
+        {
+            if(mpaTransform) delete mpaTransform;
+        }
+
+        const SvgStyleAttributes* SvgEllipseNode::getSvgStyleAttributes() const
+        {
+            static rtl::OUString aClassStr(rtl::OUString::createFromAscii("ellipse"));
+            maSvgStyleAttributes.checkForCssStyle(aClassStr);
+
+            return &maSvgStyleAttributes;
+        }
+
+        void SvgEllipseNode::parseAttribute(const rtl::OUString& rTokenName, SVGToken aSVGToken, const rtl::OUString& aContent)
+        {
+            // call parent
+            SvgNode::parseAttribute(rTokenName, aSVGToken, aContent);
+
+            // read style attributes
+            maSvgStyleAttributes.parseStyleAttribute(rTokenName, aSVGToken, aContent);
+
+            // parse own
+            switch(aSVGToken)
+            {
+                case SVGTokenStyle:
+                {
+                    maSvgStyleAttributes.readStyle(aContent);
+                    break;
+                }
+                case SVGTokenCx:
+                {
+                    SvgNumber aNum;
+
+                    if(readSingleNumber(aContent, aNum))
+                    {
+                        setCx(aNum);
+                    }
+                    break;
+                }
+                case SVGTokenCy:
+                {
+                    SvgNumber aNum;
+
+                    if(readSingleNumber(aContent, aNum))
+                    {
+                        setCy(aNum);
+                    }
+                    break;
+                }
+                case SVGTokenRx:
+                {
+                    SvgNumber aNum;
+
+                    if(readSingleNumber(aContent, aNum))
+                    {
+                        if(aNum.isPositive())
+                        {
+                            setRx(aNum);
+                        }
+                    }
+                    break;
+                }
+                case SVGTokenRy:
+                {
+                    SvgNumber aNum;
+
+                    if(readSingleNumber(aContent, aNum))
+                    {
+                        if(aNum.isPositive())
+                        {
+                            setRy(aNum);
+                        }
+                    }
+                    break;
+                }
+                case SVGTokenTransform:
+                {
+                    const basegfx::B2DHomMatrix aMatrix(readTransform(aContent, *this));
+
+                    if(!aMatrix.isIdentity())
+                    {
+                        setTransform(&aMatrix);
+                    }
+                    break;
+                }
+            }
+        }
+
+        void SvgEllipseNode::decomposeSvgNode(drawinglayer::primitive2d::Primitive2DVector& rTarget, bool bReferenced) const
+        {
+            const SvgStyleAttributes* pStyle = getSvgStyleAttributes();
+
+            if(pStyle && getRx().isSet() && getRy().isSet())
+            {
+                const double fRx(getRx().solve(*this, xcoordinate));
+                const double fRy(getRy().solve(*this, ycoordinate));
+
+                if(fRx > 0.0 && fRy > 0.0)
+                {
+                    const basegfx::B2DPolygon aPath(
+                        basegfx::tools::createPolygonFromEllipse(
+                            basegfx::B2DPoint(
+                                getCx().isSet() ? getCx().solve(*this, xcoordinate) : 0.0,
+                                getCy().isSet() ? getCy().solve(*this, ycoordinate) : 0.0),
+                            fRx, fRy));
+
+                    pStyle->add_path(basegfx::B2DPolyPolygon(aPath), rTarget, getTransform());
+                }
+            }
+        }
+    } // end of namespace svgreader
+} // end of namespace svgio
+
+//////////////////////////////////////////////////////////////////////////////
+// eof



Mime
View raw message