incubator-ooo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a..@apache.org
Subject svn commit: r1214899 [2/2] - in /incubator/ooo/branches/alg/svgreplacement/main/svgio: inc/svgio/svgreader/ source/svgreader/ source/svguno/
Date Thu, 15 Dec 2011 18:03:29 GMT
Modified: incubator/ooo/branches/alg/svgreplacement/main/svgio/source/svgreader/svgstyleattributes.cxx
URL: http://svn.apache.org/viewvc/incubator/ooo/branches/alg/svgreplacement/main/svgio/source/svgreader/svgstyleattributes.cxx?rev=1214899&r1=1214898&r2=1214899&view=diff
==============================================================================
--- incubator/ooo/branches/alg/svgreplacement/main/svgio/source/svgreader/svgstyleattributes.cxx
(original)
+++ incubator/ooo/branches/alg/svgreplacement/main/svgio/source/svgreader/svgstyleattributes.cxx
Thu Dec 15 18:03:28 2011
@@ -219,37 +219,6 @@ namespace svgio
             }
         }
 
-        void SvgStyleAttributes::decomposePostProcess(drawinglayer::primitive2d::Primitive2DVector&
rTarget) const
-        {
-            if(rTarget.size())
-            {
-                if(getClipPathXLink().getLength())
-                {
-                    // try to access linked ClipPath
-                    const SvgClipPathNode* mpClip = dynamic_cast< const SvgClipPathNode*
>(mrOwner.getDocument().findSvgNodeById(getClipPathXLink()));
-
-                    if(mpClip)
-                    {
-                        mpClip->apply(rTarget);
-                    }
-                }
-            }
-
-            if(rTarget.size()) // test again, applied clipPath may have lead to empty geometry
-            {
-                if(getMaskXLink().getLength())
-                {
-                    // try to access linked Mask
-                    const SvgMaskNode* mpMask = dynamic_cast< const SvgMaskNode* >(mrOwner.getDocument().findSvgNodeById(getMaskXLink()));
-
-                    if(mpMask)
-                    {
-                        mpMask->apply(rTarget);
-                    }
-                }
-            }
-        }
-
         const SvgStyleAttributes* SvgStyleAttributes::getParentStyle() const 
         { 
             if(mpCssStyleParent)
@@ -266,10 +235,10 @@ namespace svgio
         }
 
         void SvgStyleAttributes::add_text(
-            drawinglayer::primitive2d::Primitive2DVector& rTarget, 
-            drawinglayer::primitive2d::Primitive2DVector& rSource) const
+            drawinglayer::primitive2d::Primitive2DSequence& rTarget, 
+            drawinglayer::primitive2d::Primitive2DSequence& rSource) const
         {
-            if(!rSource.empty())
+            if(rSource.hasElements())
             {
                 // at this point the primitives in rSource are of type TextSimplePortionPrimitive2D
                 // or TextDecoratedPortionPrimitive2D and have the Fill Color (pAttributes->getFill())
@@ -283,9 +252,6 @@ namespace svgio
                 const SvgPatternNode* pStrokePattern = getSvgPatternNodeStroke();
                 basegfx::B2DPolyPolygon aMergedArea;
                 
-                // put primitives into Primitive2DSequence to have clear owner definitions
-                const drawinglayer::primitive2d::Primitive2DSequence aSeq(drawinglayer::primitive2d::Primitive2DVectorToPrimitive2DSequence(rSource));
-
                 if(pFillGradient || pFillPattern || pStroke || pStrokeGradient || pStrokePattern)
                 {
                     // text geometry is needed, create
@@ -294,7 +260,7 @@ namespace svgio
                     drawinglayer::processor2d::TextAsPolygonExtractor2D aExtractor(aViewInformation2D);
 
                     // proccess
-                    aExtractor.process(aSeq);
+                    aExtractor.process(rSource);
 
                     // get results
                     const drawinglayer::processor2d::TextAsPolygonDataNodeVector& rResult
= aExtractor.getTarget();
@@ -332,7 +298,7 @@ namespace svgio
                 else if(pFill)
                 {
                     // add the already prepared primitives for single color fill
-                    rTarget.push_back(new drawinglayer::primitive2d::GroupPrimitive2D(aSeq));
+                    drawinglayer::primitive2d::appendPrimitive2DSequenceToPrimitive2DSequence(rTarget,
rSource);
                 }
 
                 // add stroke
@@ -346,7 +312,7 @@ namespace svgio
 
         void SvgStyleAttributes::add_fillGradient(
             const basegfx::B2DPolyPolygon& rPath, 
-            drawinglayer::primitive2d::Primitive2DVector& rTarget, 
+            drawinglayer::primitive2d::Primitive2DSequence& rTarget, 
             const SvgGradientNode& rFillGradient,
             const basegfx::B2DRange& rGeoRange) const
         {
@@ -404,7 +370,8 @@ namespace svgio
                         aEnd *= aGeoToUnit;
                     }
 
-                    rTarget.push_back(
+                    drawinglayer::primitive2d::appendPrimitive2DReferenceToPrimitive2DSequence(
+                        rTarget,
                         new drawinglayer::primitive2d::SvgLinearGradientPrimitive2D(
                             rPath, 
                             aSvgGradientEntryVector,
@@ -463,7 +430,8 @@ namespace svgio
                         }
                     }
 
-                    rTarget.push_back(
+                    drawinglayer::primitive2d::appendPrimitive2DReferenceToPrimitive2DSequence(
+                        rTarget,
                         new drawinglayer::primitive2d::SvgRadialGradientPrimitive2D(
                             rPath, 
                             aSvgGradientEntryVector,
@@ -477,7 +445,7 @@ namespace svgio
 
         void SvgStyleAttributes::add_fillPatternTransform(
             const basegfx::B2DPolyPolygon& rPath, 
-            drawinglayer::primitive2d::Primitive2DVector& rTarget, 
+            drawinglayer::primitive2d::Primitive2DSequence& rTarget, 
             const SvgPatternNode& rFillPattern,
             const basegfx::B2DRange& rGeoRange) const
         {
@@ -488,20 +456,19 @@ namespace svgio
                 // path and back-transforming the result
                 basegfx::B2DPolyPolygon aPath(rPath);
                 basegfx::B2DHomMatrix aInv(*rFillPattern.getPatternTransform());
-                drawinglayer::primitive2d::Primitive2DVector aNewTarget;
+                drawinglayer::primitive2d::Primitive2DSequence aNewTarget;
 
                 aInv.invert();
                 aPath.transform(aInv);
                 add_fillPattern(aPath, aNewTarget, rFillPattern, aPath.getB2DRange());
 
-                if(aNewTarget.size())
+                if(aNewTarget.hasElements())
                 {
-                    const drawinglayer::primitive2d::Primitive2DSequence aSequence(drawinglayer::primitive2d::Primitive2DVectorToPrimitive2DSequence(aNewTarget));
-
-                    rTarget.push_back(
+                    drawinglayer::primitive2d::appendPrimitive2DReferenceToPrimitive2DSequence(
+                        rTarget,
                         new drawinglayer::primitive2d::TransformPrimitive2D(
                             *rFillPattern.getPatternTransform(),
-                            aSequence));
+                            aNewTarget));
                 }
             }
             else
@@ -513,7 +480,7 @@ namespace svgio
 
         void SvgStyleAttributes::add_fillPattern(
             const basegfx::B2DPolyPolygon& rPath, 
-            drawinglayer::primitive2d::Primitive2DVector& rTarget, 
+            drawinglayer::primitive2d::Primitive2DSequence& rTarget, 
             const SvgPatternNode& rFillPattern,
             const basegfx::B2DRange& rGeoRange) const
         {
@@ -591,7 +558,8 @@ namespace svgio
                         }
 
                         // embed in PatternFillPrimitive2D
-                        rTarget.push_back(
+                        drawinglayer::primitive2d::appendPrimitive2DReferenceToPrimitive2DSequence(
+                            rTarget,
                             new drawinglayer::primitive2d::PatternFillPrimitive2D(
                                 rPath,
                                 aPrimitives,
@@ -603,7 +571,7 @@ namespace svgio
 
         void SvgStyleAttributes::add_fill(
             const basegfx::B2DPolyPolygon& rPath, 
-            drawinglayer::primitive2d::Primitive2DVector& rTarget,
+            drawinglayer::primitive2d::Primitive2DSequence& rTarget,
             const basegfx::B2DRange& rGeoRange) const
         {
             const basegfx::BColor* pFill = getFill();
@@ -616,7 +584,7 @@ namespace svgio
 
                 if(basegfx::fTools::more(fFillOpacity, 0.0))
                 {
-                    drawinglayer::primitive2d::Primitive2DVector aNewFill;
+                    drawinglayer::primitive2d::Primitive2DSequence aNewFill;
 
                     if(pFillGradient)
                     {
@@ -631,26 +599,27 @@ namespace svgio
                     else // if(pFill)
                     {
                         // create fill content
-                        aNewFill.push_back(
-                            new drawinglayer::primitive2d::PolyPolygonColorPrimitive2D(
-                                rPath, 
-                                *pFill));
+                        aNewFill.realloc(1);
+                        aNewFill[0] = new drawinglayer::primitive2d::PolyPolygonColorPrimitive2D(
+                            rPath, 
+                            *pFill);
                     }
 
-                    if(!aNewFill.empty())
+                    if(aNewFill.hasElements())
                     {
                         if(basegfx::fTools::less(fFillOpacity, 1.0))
                         {
                             // embed in UnifiedTransparencePrimitive2D
-                            rTarget.push_back(
+                            drawinglayer::primitive2d::appendPrimitive2DReferenceToPrimitive2DSequence(
+                                rTarget,
                                 new drawinglayer::primitive2d::UnifiedTransparencePrimitive2D(
-                                    drawinglayer::primitive2d::Primitive2DVectorToPrimitive2DSequence(aNewFill),
+                                    aNewFill,
                                     1.0 - fFillOpacity));
                         }
                         else
                         {
                             // append
-                            rTarget.insert(rTarget.end(), aNewFill.begin(), aNewFill.end());
+                            drawinglayer::primitive2d::appendPrimitive2DSequenceToPrimitive2DSequence(rTarget,
aNewFill);
                         }
                     }
                 }
@@ -659,7 +628,7 @@ namespace svgio
 
         void SvgStyleAttributes::add_stroke(
             const basegfx::B2DPolyPolygon& rPath, 
-            drawinglayer::primitive2d::Primitive2DVector& rTarget,
+            drawinglayer::primitive2d::Primitive2DSequence& rTarget,
             const basegfx::B2DRange& rGeoRange) const
         {
             const basegfx::BColor* pStroke = getStroke();
@@ -668,7 +637,7 @@ namespace svgio
 
             if(pStroke || pStrokeGradient || pStrokePattern)
             {
-                drawinglayer::primitive2d::Primitive2DVector aNewStroke;
+                drawinglayer::primitive2d::Primitive2DSequence aNewStroke;
                 const double fStrokeOpacity(getStrokeOpacity().solve(mrOwner, length));
 
                 if(basegfx::fTools::more(fStrokeOpacity, 0.0))
@@ -691,7 +660,7 @@ namespace svgio
                         // todo: Handle getStrokeLinecap()
                         
                         // prepare line attribute
-                        drawinglayer::primitive2d::PolyPolygonStrokePrimitive2D* pNewLinePrimitive
= 0;
+                        drawinglayer::primitive2d::Primitive2DReference aNewLinePrimitive;
                         const drawinglayer::attribute::LineAttribute aLineAttribute(
                             pStroke ? *pStroke : basegfx::BColor(0.0, 0.0, 0.0),
                             fStrokeWidth,
@@ -699,7 +668,7 @@ namespace svgio
 
                         if(aDashArray.empty())
                         {
-                            pNewLinePrimitive = new drawinglayer::primitive2d::PolyPolygonStrokePrimitive2D(
+                            aNewLinePrimitive = new drawinglayer::primitive2d::PolyPolygonStrokePrimitive2D(
                                 rPath, 
                                 aLineAttribute);
                         }
@@ -707,7 +676,7 @@ namespace svgio
                         {
                             const drawinglayer::attribute::StrokeAttribute aStrokeAttribute(aDashArray);
 
-                            pNewLinePrimitive = new drawinglayer::primitive2d::PolyPolygonStrokePrimitive2D(
+                            aNewLinePrimitive = new drawinglayer::primitive2d::PolyPolygonStrokePrimitive2D(
                                 rPath, 
                                 aLineAttribute,
                                 aDashArray);
@@ -716,8 +685,7 @@ namespace svgio
                         if(pStrokeGradient || pStrokePattern)
                         {
                             // put primitive into Primitive2DReference and Primitive2DSequence
-                            const drawinglayer::primitive2d::Primitive2DReference aRef(pNewLinePrimitive);
-                            const drawinglayer::primitive2d::Primitive2DSequence aSeq(&aRef,
1);
+                            const drawinglayer::primitive2d::Primitive2DSequence aSeq(&aNewLinePrimitive,
1);
 
                             // use neutral ViewInformation and create LineGeometryExtractor2D
                             const drawinglayer::geometry::ViewInformation2D aViewInformation2D;
@@ -754,23 +722,24 @@ namespace svgio
                         }
                         else // if(pStroke)
                         {
-                            aNewStroke.push_back(pNewLinePrimitive);
+                            drawinglayer::primitive2d::appendPrimitive2DReferenceToPrimitive2DSequence(aNewStroke,
aNewLinePrimitive);
                         }
 
-                        if(!aNewStroke.empty())
+                        if(aNewStroke.hasElements())
                         {
                             if(basegfx::fTools::less(fStrokeOpacity, 1.0))
                             {
                                 // embed in UnifiedTransparencePrimitive2D
-                                rTarget.push_back(
+                                drawinglayer::primitive2d::appendPrimitive2DReferenceToPrimitive2DSequence(
+                                    rTarget,
                                     new drawinglayer::primitive2d::UnifiedTransparencePrimitive2D(
-                                        drawinglayer::primitive2d::Primitive2DVectorToPrimitive2DSequence(aNewStroke),
+                                        aNewStroke,
                                         1.0 - fStrokeOpacity));
                             }
                             else
                             {
                                 // append
-                                rTarget.insert(rTarget.end(), aNewStroke.begin(), aNewStroke.end());
+                                drawinglayer::primitive2d::appendPrimitive2DSequenceToPrimitive2DSequence(rTarget,
aNewStroke);
                             }
                         }
                     }
@@ -837,6 +806,10 @@ namespace svgio
             basegfx::B2DRange& rClipRange,
             const SvgMarkerNode& rMarker) const
         {
+            // reset return values
+            rMarkerTransform.identity();
+            rClipRange.reset();
+
             // get marker primitive representation
             rMarkerPrimitives = rMarker.getMarkerPrimitives();
 
@@ -874,7 +847,6 @@ namespace svgio
                         const basegfx::B2DRange aTargetRange(0.0, 0.0, fTargetWidth, fTargetHeight);
 
                         // subbstract refX, refY first, it's in marker local coordinates
-                        rMarkerTransform.identity();
                         rMarkerTransform.translate(
                             rMarker.getRefX().isSet() ? -rMarker.getRefX().solve(mrOwner,
xcoordinate) : 0.0,
                             rMarker.getRefY().isSet() ? -rMarker.getRefY().solve(mrOwner,
ycoordinate) : 0.0);
@@ -908,7 +880,7 @@ namespace svgio
         }
 
         void SvgStyleAttributes::add_singleMarker(
-            drawinglayer::primitive2d::Primitive2DVector& rTarget,
+            drawinglayer::primitive2d::Primitive2DSequence& rTarget,
             const drawinglayer::primitive2d::Primitive2DSequence& rMarkerPrimitives,
             const basegfx::B2DHomMatrix& rMarkerTransform,
             const basegfx::B2DRange& rClipRange,
@@ -929,7 +901,8 @@ namespace svgio
                 aCombinedTransform.translate(aPoint.getX(), aPoint.getY());
 
                 // add marker
-                rTarget.push_back(
+                drawinglayer::primitive2d::appendPrimitive2DReferenceToPrimitive2DSequence(
+                    rTarget,
                     new drawinglayer::primitive2d::TransformPrimitive2D(
                         aCombinedTransform,
                         rMarkerPrimitives));
@@ -938,7 +911,7 @@ namespace svgio
 
         void SvgStyleAttributes::add_markers(
             const basegfx::B2DPolyPolygon& rPath,
-            drawinglayer::primitive2d::Primitive2DVector& rTarget) const
+            drawinglayer::primitive2d::Primitive2DSequence& rTarget) const
         {
             // try to access linked markers
             const SvgMarkerNode* pStart = accessMarkerStartXLink();
@@ -999,8 +972,7 @@ namespace svgio
 
         void SvgStyleAttributes::add_path(
             const basegfx::B2DPolyPolygon& rPath, 
-            drawinglayer::primitive2d::Primitive2DVector& rTarget, 
-            const basegfx::B2DHomMatrix* pTransform) const
+            drawinglayer::primitive2d::Primitive2DSequence& rTarget) const
         {
             const bool bIsLine(1 == rPath.count()
                 && !rPath.areControlPointsUsed()
@@ -1032,8 +1004,6 @@ namespace svgio
                 return;
             }
 
-            drawinglayer::primitive2d::Primitive2DVector aNewTarget;
-
             if(!bIsLine)
             {
                 basegfx::B2DPolyPolygon aPath(rPath);
@@ -1047,10 +1017,10 @@ namespace svgio
                     aPath = basegfx::tools::createNonzeroConform(aPath);
                 }
 
-                add_fill(aPath, aNewTarget, aGeoRange);
+                add_fill(aPath, rTarget, aGeoRange);
             }
 
-            add_stroke(rPath, aNewTarget, aGeoRange);
+            add_stroke(rPath, rTarget, aGeoRange);
 
             // Svg supports markers for path, polygon, polyline and line
             if(SVGTokenPath == mrOwner.getType() ||         // path
@@ -1058,38 +1028,78 @@ namespace svgio
                 SVGTokenLine == mrOwner.getType())          // line
             {
                 // try to add markers
-                add_markers(rPath, aNewTarget);
+                add_markers(rPath, rTarget);
             }
+        }
 
-            if(aNewTarget.size())
+        void SvgStyleAttributes::add_postProcess(
+            drawinglayer::primitive2d::Primitive2DSequence& rTarget, 
+            const drawinglayer::primitive2d::Primitive2DSequence& rSource, 
+            const basegfx::B2DHomMatrix* pTransform) const
+        {
+            if(rSource.hasElements())
             {
-                // put content to primitive sequence
-                drawinglayer::primitive2d::Primitive2DSequence aContent(drawinglayer::primitive2d::Primitive2DVectorToPrimitive2DSequence(aNewTarget));
+                const double fOpacity(getOpacity().getNumber());
+
+                if(basegfx::fTools::equalZero(fOpacity))
+                {
+                    return;
+                }
+
+                drawinglayer::primitive2d::Primitive2DSequence aSource(rSource);
 
                 if(basegfx::fTools::less(fOpacity, 1.0))
                 {
                     // embed in UnifiedTransparencePrimitive2D
                     const drawinglayer::primitive2d::Primitive2DReference xRef(
                         new drawinglayer::primitive2d::UnifiedTransparencePrimitive2D(
-                            aContent,
+                            aSource,
                             1.0 - fOpacity));
 
-                    aContent = drawinglayer::primitive2d::Primitive2DSequence(&xRef,
1);
+                    aSource = drawinglayer::primitive2d::Primitive2DSequence(&xRef, 1);
                 }
 
-                if(pTransform)
+                if(getClipPathXLink().getLength())
                 {
-                    // create embedding group element with transformation
-                    const drawinglayer::primitive2d::Primitive2DReference xRef(
-                        new drawinglayer::primitive2d::TransformPrimitive2D(
-                            *pTransform,
-                            aContent));
+                    // try to access linked ClipPath
+                    const SvgClipPathNode* mpClip = dynamic_cast< const SvgClipPathNode*
>(mrOwner.getDocument().findSvgNodeById(getClipPathXLink()));
 
-                    aContent = drawinglayer::primitive2d::Primitive2DSequence(&xRef,
1);
+                    if(mpClip)
+                    {
+                        mpClip->apply(aSource);
+                    }
                 }
 
-                // append to current target
-                rTarget.push_back(new drawinglayer::primitive2d::GroupPrimitive2D(aContent));
+                if(aSource.hasElements()) // test again, applied clipPath may have lead to
empty geometry
+                {
+                    if(getMaskXLink().getLength())
+                    {
+                        // try to access linked Mask
+                        const SvgMaskNode* mpMask = dynamic_cast< const SvgMaskNode* >(mrOwner.getDocument().findSvgNodeById(getMaskXLink()));
+
+                        if(mpMask)
+                        {
+                            mpMask->apply(aSource);
+                        }
+                    }
+
+                    if(aSource.hasElements()) // test again, applied mask may have lead to
empty geometry
+                    {
+                        if(pTransform)
+                        {
+                            // create embedding group element with transformation
+                            const drawinglayer::primitive2d::Primitive2DReference xRef(
+                                new drawinglayer::primitive2d::TransformPrimitive2D(
+                                    *pTransform,
+                                    aSource));
+
+                            aSource = drawinglayer::primitive2d::Primitive2DSequence(&xRef,
1);
+                        }
+
+                        // append to current target
+                        drawinglayer::primitive2d::appendPrimitive2DSequenceToPrimitive2DSequence(rTarget,
aSource);
+                    }
+                }
             }
         }
 

Modified: incubator/ooo/branches/alg/svgreplacement/main/svgio/source/svgreader/svgsvgnode.cxx
URL: http://svn.apache.org/viewvc/incubator/ooo/branches/alg/svgreplacement/main/svgio/source/svgreader/svgsvgnode.cxx?rev=1214899&r1=1214898&r2=1214899&view=diff
==============================================================================
--- incubator/ooo/branches/alg/svgreplacement/main/svgio/source/svgreader/svgsvgnode.cxx (original)
+++ incubator/ooo/branches/alg/svgreplacement/main/svgio/source/svgreader/svgsvgnode.cxx Thu
Dec 15 18:03:28 2011
@@ -156,18 +156,15 @@ namespace svgio
             }
         }
 
-        void SvgSvgNode::decomposeSvgNode(drawinglayer::primitive2d::Primitive2DVector&
rTarget, bool bReferenced) const
+        void SvgSvgNode::decomposeSvgNode(drawinglayer::primitive2d::Primitive2DSequence&
rTarget, bool bReferenced) const
         {
-            drawinglayer::primitive2d::Primitive2DVector aNewTarget;
+            drawinglayer::primitive2d::Primitive2DSequence aSequence;
 
             // decompose childs
-            SvgNode::decomposeSvgNode(aNewTarget, bReferenced);
+            SvgNode::decomposeSvgNode(aSequence, bReferenced);
 
-            if(!aNewTarget.empty())
+            if(aSequence.hasElements())
             {
-                // pack into Primitive2DSequence to ensure ownership
-                const drawinglayer::primitive2d::Primitive2DSequence aSequence(Primitive2DVectorToPrimitive2DSequence(aNewTarget));
-
                 if(getParent())
                 {
                     if(getViewBox())
@@ -186,9 +183,7 @@ namespace svgio
                             if(aTarget.equal(*getViewBox()))
                             {
                                 // no mapping needed, append
-                                rTarget.push_back(
-                                    new drawinglayer::primitive2d::GroupPrimitive2D(
-                                        aSequence));
+                                drawinglayer::primitive2d::appendPrimitive2DSequenceToPrimitive2DSequence(rTarget,
aSequence);
                             }
                             else
                             {
@@ -202,25 +197,25 @@ namespace svgio
                                         rRatio.createMapping(aTarget, *getViewBox()));
 
                                     // prepare embedding in transformation
-                                    drawinglayer::primitive2d::TransformPrimitive2D* pNew
= 
+                                    const drawinglayer::primitive2d::Primitive2DReference
xRef(
                                         new drawinglayer::primitive2d::TransformPrimitive2D(
                                             aEmbeddingTransform,
-                                            aSequence);
+                                            aSequence));
 
                                     if(rRatio.isMeetOrSlice())
                                     {
                                         // embed in transformation
-                                        rTarget.push_back(pNew);
+                                        drawinglayer::primitive2d::appendPrimitive2DReferenceToPrimitive2DSequence(rTarget,
xRef);
                                     }
                                     else
                                     {
                                         // need to embed in MaskPrimitive2D, too
-                                        const drawinglayer::primitive2d::Primitive2DReference
xRef(pNew);
-
-                                        rTarget.push_back(
+                                        const drawinglayer::primitive2d::Primitive2DReference
xMask(
                                             new drawinglayer::primitive2d::MaskPrimitive2D(
                                                 basegfx::B2DPolyPolygon(basegfx::tools::createPolygonFromRect(aTarget)),
                                                 drawinglayer::primitive2d::Primitive2DSequence(&xRef,
1)));
+
+                                        drawinglayer::primitive2d::appendPrimitive2DReferenceToPrimitive2DSequence(rTarget,
xMask);
                                     }
                                 }
                                 else
@@ -231,20 +226,51 @@ namespace svgio
                                             aTarget, *getViewBox()));
                                     
                                     // embed in transformation
-                                    rTarget.push_back(
+                                    const drawinglayer::primitive2d::Primitive2DReference
xTransform(
                                         new drawinglayer::primitive2d::TransformPrimitive2D(
                                             aEmbeddingTransform,
                                             aSequence));
+
+                                    drawinglayer::primitive2d::appendPrimitive2DReferenceToPrimitive2DSequence(rTarget,
xTransform);
                                 }
                             }
                         }
                     }
                     else
                     {
-                        // no viewBox, append
-                        rTarget.push_back(
-                            new drawinglayer::primitive2d::GroupPrimitive2D(
-                                aSequence));
+                        // check if we have a size
+                        const double fW(getWidth().isSet() ? getWidth().solve(*this, xcoordinate)
: 0.0);
+                        const double fH(getHeight().isSet() ? getHeight().solve(*this, ycoordinate)
: 0.0);
+
+                        // Svg defines that a negative value is an error and that 0.0 disables
rendering
+                        if(basegfx::fTools::more(fW, 0.0) && basegfx::fTools::more(fH,
0.0))
+                        {
+                            // check if we have a x,y position
+                            const double fX(getX().isSet() ? getX().solve(*this, xcoordinate)
: 0.0);
+                            const double fY(getY().isSet() ? getY().solve(*this, ycoordinate)
: 0.0);
+
+                            if(!basegfx::fTools::equalZero(fX) || !basegfx::fTools::equalZero(fY))
+                            {
+                                // embed in transform
+                                const drawinglayer::primitive2d::Primitive2DReference xRef(
+                                    new drawinglayer::primitive2d::TransformPrimitive2D(
+                                        basegfx::tools::createTranslateB2DHomMatrix(fX, fY),
+                                        aSequence));
+
+                                aSequence = drawinglayer::primitive2d::Primitive2DSequence(&xRef,
1);
+                            }
+
+                            // embed in MaskPrimitive2D to clip
+                            const drawinglayer::primitive2d::Primitive2DReference xMask(
+                                new drawinglayer::primitive2d::MaskPrimitive2D(
+                                    basegfx::B2DPolyPolygon(
+                                        basegfx::tools::createPolygonFromRect(
+                                            basegfx::B2DRange(fX, fY, fX + fW, fY + fH))),
+                                    aSequence));
+
+                            // append
+                            drawinglayer::primitive2d::appendPrimitive2DReferenceToPrimitive2DSequence(rTarget,
xMask);
+                        }
                     }
                 }
                 else
@@ -259,18 +285,60 @@ namespace svgio
                     // Svg defines that a negative value is an error and that 0.0 disables
rendering
                     if(basegfx::fTools::more(fW, 0.0) && basegfx::fTools::more(fH,
0.0))
                     {
-                        // append embedded in transform primitive to scale to 1/100th mm
-                        // where 1 mm == 3.543307 px
-                        const double fScaleTo100thmm(100.0 / 3.543307);
-                        basegfx::B2DHomMatrix aTransform(
-                            basegfx::tools::createScaleB2DHomMatrix(
-                                fScaleTo100thmm,
-                                fScaleTo100thmm));
-
-                        rTarget.push_back(
-                            new drawinglayer::primitive2d::TransformPrimitive2D(
-                                aTransform,
-                                aSequence));
+                        // to be completely correct in Svg sense it is necessary to clip
+                        // the whole content to the given canvas. I choose here to do this
+                        // initially despite I found various examples of Svg files out there
+                        // which have no correct values for this clipping. It's correct
+                        // due to the Svg spec.
+                        bool bDoCorrectCanvasClipping(true);
+
+                        if(bDoCorrectCanvasClipping)
+                        {
+                            // different from Svg we have the possibility with primitives
to get
+                            // a correct bounding box for the geometry, thhus I will allow
to
+                            // only clip if necessary. This will make Svg images evtl. smaller
+                            // than wanted from Svg (the free space which may be around it
is
+                            // conform to the Svg spec), but avoids an expensive and unneccessary
+                            // clip.
+                            const basegfx::B2DRange aContentRange(
+                                drawinglayer::primitive2d::getB2DRangeFromPrimitive2DSequence(
+                                    aSequence,
+                                    drawinglayer::geometry::ViewInformation2D()));
+                            const basegfx::B2DRange aSvgCanvasRange(0.0, 0.0, fW, fH);
+
+                            if(!aSvgCanvasRange.isInside(aContentRange))
+                            {
+                                const drawinglayer::primitive2d::Primitive2DReference xMask(
+                                    new drawinglayer::primitive2d::MaskPrimitive2D(
+                                        basegfx::B2DPolyPolygon(
+                                            basegfx::tools::createPolygonFromRect(
+                                                aSvgCanvasRange)),
+                                        aSequence));
+
+                                aSequence = drawinglayer::primitive2d::Primitive2DSequence(&xMask,
1);
+                            }
+                        }
+
+                        {
+                            // embed in transform primitive to scale to 1/100th mm
+                            // where 1 mm == 3.543307 px to get from Svg coordinates to
+                            // drawinglayer ones
+                            const double fScaleTo100thmm(100.0 / 3.543307);
+                            const basegfx::B2DHomMatrix aTransform(
+                                basegfx::tools::createScaleB2DHomMatrix(
+                                    fScaleTo100thmm,
+                                    fScaleTo100thmm));
+
+                            const drawinglayer::primitive2d::Primitive2DReference xTransform(
+                                new drawinglayer::primitive2d::TransformPrimitive2D(
+                                    aTransform,
+                                    aSequence));
+
+                            aSequence = drawinglayer::primitive2d::Primitive2DSequence(&xTransform,
1);
+                        }
+
+                        // append
+                        drawinglayer::primitive2d::appendPrimitive2DSequenceToPrimitive2DSequence(rTarget,
aSequence);
                     }
                 }
             }

Modified: incubator/ooo/branches/alg/svgreplacement/main/svgio/source/svgreader/svgtextnode.cxx
URL: http://svn.apache.org/viewvc/incubator/ooo/branches/alg/svgreplacement/main/svgio/source/svgreader/svgtextnode.cxx?rev=1214899&r1=1214898&r2=1214899&view=diff
==============================================================================
--- incubator/ooo/branches/alg/svgreplacement/main/svgio/source/svgreader/svgtextnode.cxx
(original)
+++ incubator/ooo/branches/alg/svgreplacement/main/svgio/source/svgreader/svgtextnode.cxx
Thu Dec 15 18:03:28 2011
@@ -92,9 +92,12 @@ namespace svgio
             }
         }
 
-        void SvgTextNode::addTextPrimitives(const SvgNode& rCandidate, drawinglayer::primitive2d::Primitive2DVector&
rTarget, drawinglayer::primitive2d::Primitive2DVector& rSource) const
+        void SvgTextNode::addTextPrimitives(
+            const SvgNode& rCandidate, 
+            drawinglayer::primitive2d::Primitive2DSequence& rTarget, 
+            drawinglayer::primitive2d::Primitive2DSequence& rSource) const
         {
-            if(!rSource.empty())
+            if(rSource.hasElements())
             {
                 const SvgStyleAttributes* pAttributes = rCandidate.getSvgStyleAttributes();
 
@@ -107,12 +110,12 @@ namespace svgio
                 {
                     // should not happen, every subnode from SvgTextNode will at least
                     // return the attributes from SvgTextNode. Nonetheless, add text
-                    rTarget.insert(rTarget.end(), rSource.begin(), rSource.end());
+                    drawinglayer::primitive2d::appendPrimitive2DSequenceToPrimitive2DSequence(rTarget,
rSource);
                 }
             }
         }
 
-        void SvgTextNode::DecomposeChild(const SvgNode& rCandidate, drawinglayer::primitive2d::Primitive2DVector&
rTarget, SvgTextPosition& rSvgTextPosition) const
+        void SvgTextNode::DecomposeChild(const SvgNode& rCandidate, drawinglayer::primitive2d::Primitive2DSequence&
rTarget, SvgTextPosition& rSvgTextPosition) const
         {
             switch(rCandidate.getType())
             {
@@ -134,7 +137,7 @@ namespace svgio
                     {
                         // remember original TextStart to later detect hor/ver offsets
                         const basegfx::B2DPoint aTextStart(rSvgTextPosition.getPosition());
-                        drawinglayer::primitive2d::Primitive2DVector aNewTarget;
+                        drawinglayer::primitive2d::Primitive2DSequence aNewTarget;
 
                         // decompose to regular TextPrimitives
                         for(sal_uInt32 a(0); a < nCount; a++)
@@ -142,16 +145,16 @@ namespace svgio
                             DecomposeChild(*rChildren[a], aNewTarget, rSvgTextPosition);
                         }
 
-                        if(!aNewTarget.empty())
+                        if(aNewTarget.hasElements())
                         {
-                            const drawinglayer::primitive2d::Primitive2DSequence aPathContent(drawinglayer::primitive2d::Primitive2DVectorToPrimitive2DSequence(aNewTarget));
-                            aNewTarget.clear();
+                            const drawinglayer::primitive2d::Primitive2DSequence aPathContent(aNewTarget);
+                            aNewTarget.realloc(0);
 
                             // dismantle TextPrimitives and map them on curve/path
                             rSvgTextPathNode.decomposePathNode(aPathContent, aNewTarget,
aTextStart);
                         }
 
-                        if(!aNewTarget.empty())
+                        if(aNewTarget.hasElements())
                         {
                             addTextPrimitives(rCandidate, rTarget, aNewTarget);
                         }
@@ -169,7 +172,7 @@ namespace svgio
                     if(nCount)
                     {
                         SvgTextPosition aSvgTextPosition(&rSvgTextPosition, rSvgTspanNode,
rSvgTspanNode.getSvgTextPositions());
-                        drawinglayer::primitive2d::Primitive2DVector aNewTarget;
+                        drawinglayer::primitive2d::Primitive2DSequence aNewTarget;
 
                         for(sal_uInt32 a(0); a < nCount; a++)
                         {
@@ -178,7 +181,7 @@ namespace svgio
 
                         rSvgTextPosition.setPosition(aSvgTextPosition.getPosition());
                         
-                        if(!aNewTarget.empty())
+                        if(aNewTarget.hasElements())
                         {
                             addTextPrimitives(rCandidate, rTarget, aNewTarget);
                         }
@@ -194,7 +197,7 @@ namespace svgio
                     {
                         const SvgNodeVector& rChildren = pRefText->getChildren();
                         const sal_uInt32 nCount(rChildren.size());
-                        drawinglayer::primitive2d::Primitive2DVector aNewTarget;
+                        drawinglayer::primitive2d::Primitive2DSequence aNewTarget;
 
                         if(nCount)
                         {
@@ -207,7 +210,7 @@ namespace svgio
                                 const_cast< SvgNode& >(rChildCandidate).setAlternativeParent(0);
                             }
                             
-                            if(!aNewTarget.empty())
+                            if(aNewTarget.hasElements())
                             {
                                 addTextPrimitives(rCandidate, rTarget, aNewTarget);
                             }
@@ -224,7 +227,7 @@ namespace svgio
             }
         }
 
-        void SvgTextNode::decomposeSvgNode(drawinglayer::primitive2d::Primitive2DVector&
rTarget, bool bReferenced) const
+        void SvgTextNode::decomposeSvgNode(drawinglayer::primitive2d::Primitive2DSequence&
rTarget, bool bReferenced) const
         {
             // text has a group of child nodes, allowed are SVGTokenCharacter, SVGTokenTspan,
             // SVGTokenTref and SVGTokenTextPath. These increase a given current text position
@@ -237,7 +240,7 @@ namespace svgio
                 if(fOpacity > 0.0)
                 {
                     SvgTextPosition aSvgTextPosition(0, *this, getSvgTextPositions());
-                    drawinglayer::primitive2d::Primitive2DVector aNewTarget;
+                    drawinglayer::primitive2d::Primitive2DSequence aNewTarget;
                     const SvgNodeVector& rChildren = getChildren();
                     const sal_uInt32 nCount(rChildren.size());
 
@@ -248,43 +251,17 @@ namespace svgio
                         DecomposeChild(rCandidate, aNewTarget, aSvgTextPosition);
                     }
                 
-                    if(!aNewTarget.empty())
+                    if(aNewTarget.hasElements())
                     {
-                        drawinglayer::primitive2d::Primitive2DVector aNewTarget2;
+                        drawinglayer::primitive2d::Primitive2DSequence aNewTarget2;
 
                         addTextPrimitives(*this, aNewTarget2, aNewTarget);
                         aNewTarget = aNewTarget2;
                     }
 
-                    if(!aNewTarget.empty())
+                    if(aNewTarget.hasElements())
                     {
-                         // put content to primitive sequence
-                        drawinglayer::primitive2d::Primitive2DSequence aContent(drawinglayer::primitive2d::Primitive2DVectorToPrimitive2DSequence(aNewTarget));
-
-                        if(basegfx::fTools::less(fOpacity, 1.0))
-                        {
-                            // embed in UnifiedTransparencePrimitive2D
-                            const drawinglayer::primitive2d::Primitive2DReference xRef(
-                                new drawinglayer::primitive2d::UnifiedTransparencePrimitive2D(
-                                    aContent,
-                                    1.0 - fOpacity));
-
-                            aContent = drawinglayer::primitive2d::Primitive2DSequence(&xRef,
1);
-                        }
-
-                        if(getTransform())
-                        {
-                            // create embedding group element with transformation
-                            const drawinglayer::primitive2d::Primitive2DReference xRef(
-                                new drawinglayer::primitive2d::TransformPrimitive2D(
-                                    *getTransform(),
-                                    aContent));
-
-                            aContent = drawinglayer::primitive2d::Primitive2DSequence(&xRef,
1);
-                        }
-
-                        // append to current target
-                        rTarget.push_back(new drawinglayer::primitive2d::GroupPrimitive2D(aContent));
+                        pStyle->add_postProcess(rTarget, aNewTarget, getTransform());
                     }
                 }
             }

Modified: incubator/ooo/branches/alg/svgreplacement/main/svgio/source/svgreader/svgtextpathnode.cxx
URL: http://svn.apache.org/viewvc/incubator/ooo/branches/alg/svgreplacement/main/svgio/source/svgreader/svgtextpathnode.cxx?rev=1214899&r1=1214898&r2=1214899&view=diff
==============================================================================
--- incubator/ooo/branches/alg/svgreplacement/main/svgio/source/svgreader/svgtextpathnode.cxx
(original)
+++ incubator/ooo/branches/alg/svgreplacement/main/svgio/source/svgreader/svgtextpathnode.cxx
Thu Dec 15 18:03:28 2011
@@ -406,7 +406,7 @@ namespace svgio
 
         void SvgTextPathNode::decomposePathNode(
             const drawinglayer::primitive2d::Primitive2DSequence& rPathContent, 
-            drawinglayer::primitive2d::Primitive2DVector& rTarget, 
+            drawinglayer::primitive2d::Primitive2DSequence& rTarget, 
             const basegfx::B2DPoint& rTextStart) const
         {
             if(rPathContent.hasElements())
@@ -487,7 +487,7 @@ namespace svgio
 
                                         if(aResult.hasElements())
                                         {
-                                            rTarget.push_back(new drawinglayer::primitive2d::GroupPrimitive2D(aResult));
+                                            drawinglayer::primitive2d::appendPrimitive2DSequenceToPrimitive2DSequence(rTarget,
aResult);
                                         }
 
                                         // advance position to consumed

Modified: incubator/ooo/branches/alg/svgreplacement/main/svgio/source/svgreader/svgusenode.cxx
URL: http://svn.apache.org/viewvc/incubator/ooo/branches/alg/svgreplacement/main/svgio/source/svgreader/svgusenode.cxx?rev=1214899&r1=1214898&r2=1214899&view=diff
==============================================================================
--- incubator/ooo/branches/alg/svgreplacement/main/svgio/source/svgreader/svgusenode.cxx (original)
+++ incubator/ooo/branches/alg/svgreplacement/main/svgio/source/svgreader/svgusenode.cxx Thu
Dec 15 18:03:28 2011
@@ -140,7 +140,7 @@ namespace svgio
             }
         }
 
-        void SvgUseNode::decomposeSvgNode(drawinglayer::primitive2d::Primitive2DVector&
rTarget, bool bReferenced) const
+        void SvgUseNode::decomposeSvgNode(drawinglayer::primitive2d::Primitive2DSequence&
rTarget, bool bReferenced) const
         {
             // try to access link to content
             const SvgNode* mpXLink = getDocument().findSvgNodeById(maXLink);
@@ -148,7 +148,7 @@ namespace svgio
             if(mpXLink)
             {
                 // decompose childs
-                drawinglayer::primitive2d::Primitive2DVector aNewTarget;
+                drawinglayer::primitive2d::Primitive2DSequence aNewTarget;
 
                 // todo: in case mpXLink is a SVGTokenSvg or SVGTokenSymbol the
                 // SVG docs want the getWidth() and getHeight() from this node
@@ -157,7 +157,7 @@ namespace svgio
                 mpXLink->decomposeSvgNode(aNewTarget, true);
                 const_cast< SvgNode* >(mpXLink)->setAlternativeParent(0);
 
-                if(!aNewTarget.empty())
+                if(aNewTarget.hasElements())
                 {
                     basegfx::B2DHomMatrix aTransform;
 
@@ -175,14 +175,16 @@ namespace svgio
 
                     if(!aTransform.isIdentity())
                     {
-                        rTarget.push_back(
+                        const drawinglayer::primitive2d::Primitive2DReference xRef(
                             new drawinglayer::primitive2d::TransformPrimitive2D(
                                 aTransform,
-                                drawinglayer::primitive2d::Primitive2DVectorToPrimitive2DSequence(aNewTarget)));
+                                aNewTarget));
+
+                        drawinglayer::primitive2d::appendPrimitive2DReferenceToPrimitive2DSequence(rTarget,
xRef);
                     }
                     else
                     {
-                        rTarget.insert(rTarget.end(), aNewTarget.begin(), aNewTarget.end());
+                        drawinglayer::primitive2d::appendPrimitive2DSequenceToPrimitive2DSequence(rTarget,
aNewTarget);
                     }
                 }
             }

Modified: incubator/ooo/branches/alg/svgreplacement/main/svgio/source/svguno/xsvgparser.cxx
URL: http://svn.apache.org/viewvc/incubator/ooo/branches/alg/svgreplacement/main/svgio/source/svguno/xsvgparser.cxx?rev=1214899&r1=1214898&r2=1214899&view=diff
==============================================================================
--- incubator/ooo/branches/alg/svgreplacement/main/svgio/source/svguno/xsvgparser.cxx (original)
+++ incubator/ooo/branches/alg/svgreplacement/main/svgio/source/svguno/xsvgparser.cxx Thu
Dec 15 18:03:28 2011
@@ -148,17 +148,10 @@ namespace svgio
                 // decompose to primitives
                 const SvgNodeVector& rResults = pSvgDocHdl->getSvgDocument().getSvgNodeVector();
                 const sal_uInt32 nCount(rResults.size());
-                drawinglayer::primitive2d::Primitive2DVector aTarget;
 
                 for(sal_uInt32 a(0); a < nCount; a++)
                 {
-                    rResults[a]->decomposeSvgNode(aTarget, false);
-                }
-
-                if(!aTarget.empty())
-                {
-                    // append created primitives
-                    aRetval = drawinglayer::primitive2d::Primitive2DVectorToPrimitive2DSequence(aTarget);
+                    rResults[a]->decomposeSvgNode(aRetval, false);
                 }
             }
             else



Mime
View raw message