incubator-ooo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a..@apache.org
Subject svn commit: r1215102 - in /incubator/ooo/branches/alg/svgreplacement/main: drawinglayer/source/tools/converters.cxx svgio/source/svgreader/svgsvgnode.cxx svx/source/svdraw/svdograf.cxx
Date Fri, 16 Dec 2011 12:01:56 GMT
Author: alg
Date: Fri Dec 16 12:01:56 2011
New Revision: 1215102

URL: http://svn.apache.org/viewvc?rev=1215102&view=rev
Log:
svg: corrected outermost Svg element handling; optimized Svg replacement image creation

Modified:
    incubator/ooo/branches/alg/svgreplacement/main/drawinglayer/source/tools/converters.cxx
    incubator/ooo/branches/alg/svgreplacement/main/svgio/source/svgreader/svgsvgnode.cxx
    incubator/ooo/branches/alg/svgreplacement/main/svx/source/svdraw/svdograf.cxx

Modified: incubator/ooo/branches/alg/svgreplacement/main/drawinglayer/source/tools/converters.cxx
URL: http://svn.apache.org/viewvc/incubator/ooo/branches/alg/svgreplacement/main/drawinglayer/source/tools/converters.cxx?rev=1215102&r1=1215101&r2=1215102&view=diff
==============================================================================
--- incubator/ooo/branches/alg/svgreplacement/main/drawinglayer/source/tools/converters.cxx
(original)
+++ incubator/ooo/branches/alg/svgreplacement/main/drawinglayer/source/tools/converters.cxx
Fri Dec 16 12:01:56 2011
@@ -38,8 +38,8 @@
 
 namespace drawinglayer
 {
-	namespace tools
-	{
+    namespace tools
+    {
         BitmapEx DRAWINGLAYER_DLLPUBLIC convertToBitmapEx(
             const drawinglayer::primitive2d::Primitive2DSequence& rSeq, 
             const geometry::ViewInformation2D& rViewInformation2D,
@@ -53,16 +53,16 @@ namespace drawinglayer
             {
                 // get destination size in pixels
                 const MapMode aMapModePixel(MAP_PIXEL);
-				const sal_uInt32 nViewVisibleArea(nDiscreteWidth * nDiscreteHeight);
-				double fReduceFactor(1.0);
+                const sal_uInt32 nViewVisibleArea(nDiscreteWidth * nDiscreteHeight);
+                double fReduceFactor(1.0);
                 drawinglayer::primitive2d::Primitive2DSequence aSequence(rSeq);
 
-				if(nViewVisibleArea > nMaxQuadratPixels)
-				{
+                if(nViewVisibleArea > nMaxQuadratPixels)
+                {
                     // reduce render size
-					fReduceFactor = sqrt((double)nMaxQuadratPixels / (double)nViewVisibleArea);
-					nDiscreteWidth = basegfx::fround((double)nDiscreteWidth * fReduceFactor);
-					nDiscreteHeight = basegfx::fround((double)nDiscreteHeight * fReduceFactor);
+                    fReduceFactor = sqrt((double)nMaxQuadratPixels / (double)nViewVisibleArea);
+                    nDiscreteWidth = basegfx::fround((double)nDiscreteWidth * fReduceFactor);
+                    nDiscreteHeight = basegfx::fround((double)nDiscreteHeight * fReduceFactor);
 
                     const drawinglayer::primitive2d::Primitive2DReference aEmbed(
                         new drawinglayer::primitive2d::TransformPrimitive2D(
@@ -70,78 +70,70 @@ namespace drawinglayer
                             rSeq));
 
                     aSequence = drawinglayer::primitive2d::Primitive2DSequence(&aEmbed,
1);
-				}
+                }
 
-        		const Point aEmptyPoint;
+                const Point aEmptyPoint;
                 const Size aSizePixel(nDiscreteWidth, nDiscreteHeight);
                 geometry::ViewInformation2D aViewInformation2D(rViewInformation2D);
-		        Bitmap aContent; 
-                AlphaMask aAlphaMask;
-                
-                {
-                    // prepare vdev
-                    VirtualDevice maContent;
+                VirtualDevice maContent;
                     
-                    maContent.SetOutputSizePixel(aSizePixel, false);
-                    maContent.SetMapMode(aMapModePixel);
-                    maContent.SetAntialiasing(true);
-
-                    // render content
-                    processor2d::VclPixelProcessor2D aContentProcessor(aViewInformation2D,
maContent);
-                    aContentProcessor.process(aSequence);
-
-                    // get content pixels
-                    maContent.EnableMapMode(false);
-		            aContent = maContent.GetBitmap(aEmptyPoint, aSizePixel); 
-                }
-
-                {
-                    // prepare vdev
-                    VirtualDevice maAlpha;
-		        
-                    maAlpha.SetOutputSizePixel(aSizePixel, false);
-                    maAlpha.SetMapMode(aMapModePixel);
-                    maAlpha.SetAntialiasing(true);
-
-                    // set alöpha to all white (fully transparent)
-                    maAlpha.SetBackground(Wallpaper(Color(COL_WHITE)));
-					maAlpha.Erase();
-
-                    // embed primitives to paint them black
-                    const primitive2d::Primitive2DReference xRef(
-                        new primitive2d::ModifiedColorPrimitive2D(
-                            aSequence,
-                            basegfx::BColorModifier(
-                                basegfx::BColor(0.0, 0.0, 0.0),
-                                0.5,
-                                basegfx::BCOLORMODIFYMODE_REPLACE)));
-                    const primitive2d::Primitive2DSequence xSeq(&xRef, 1);
-
-                    // render
-                    processor2d::VclPixelProcessor2D aAlphaProcessor(aViewInformation2D,
maAlpha);
-                    aAlphaProcessor.process(xSeq);
-
-                    // get alpha cahannel from vdev
-                    maAlpha.EnableMapMode(false);
-			        aAlphaMask = maAlpha.GetBitmap(aEmptyPoint, aSizePixel);
-                }
+                // prepare vdev
+                maContent.SetOutputSizePixel(aSizePixel, false);
+                maContent.SetMapMode(aMapModePixel);
+                maContent.SetAntialiasing(true);
+
+                // create processor
+                processor2d::VclPixelProcessor2D aContentProcessor(aViewInformation2D, maContent);
+
+                // render content
+                aContentProcessor.process(aSequence);
+
+                // get content
+                maContent.EnableMapMode(false);
+                const Bitmap aContent(maContent.GetBitmap(aEmptyPoint, aSizePixel)); 
+
+                // prepare for mask creation
+                maContent.SetMapMode(aMapModePixel);
+                maContent.SetAntialiasing(true);
+
+                // set alpha to all white (fully transparent)
+                maContent.SetBackground(Wallpaper(Color(COL_WHITE)));
+                maContent.Erase();
+
+                // embed primitives to paint them black
+                const primitive2d::Primitive2DReference xRef(
+                    new primitive2d::ModifiedColorPrimitive2D(
+                        aSequence,
+                        basegfx::BColorModifier(
+                            basegfx::BColor(0.0, 0.0, 0.0),
+                            0.5,
+                            basegfx::BCOLORMODIFYMODE_REPLACE)));
+                const primitive2d::Primitive2DSequence xSeq(&xRef, 1);
+
+                // render
+                aContentProcessor.process(xSeq);
+
+                // get alpha cahannel from vdev
+                maContent.EnableMapMode(false);
+                const AlphaMask aAlphaMask(maContent.GetBitmap(aEmptyPoint, aSizePixel));
 
+                // create BitmapEx result
                 aRetval = BitmapEx(aContent, aAlphaMask);
             }
 
 #ifdef DBG_UTIL
-			static bool bDoSaveForVisualControl(false);
-			if(bDoSaveForVisualControl)
-			{
-				SvFileStream aNew((const String&)String(ByteString( "c:\\test.png" ), RTL_TEXTENCODING_UTF8),
STREAM_WRITE|STREAM_TRUNC);
-				aNew << aRetval;
-			}
+            static bool bDoSaveForVisualControl(false);
+            if(bDoSaveForVisualControl)
+            {
+                SvFileStream aNew((const String&)String(ByteString( "c:\\test.png" ),
RTL_TEXTENCODING_UTF8), STREAM_WRITE|STREAM_TRUNC);
+                aNew << aRetval;
+            }
 #endif
 
             return aRetval;
         }
 
-	} // end of namespace tools
+    } // end of namespace tools
 } // end of namespace drawinglayer
 
 //////////////////////////////////////////////////////////////////////////////

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=1215102&r1=1215101&r2=1215102&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 Fri
Dec 16 12:01:56 2011
@@ -277,14 +277,47 @@ namespace svgio
                 {
                     // Outermost SVG element; create target range homing width and height
as given.
                     // SVG defines that x,y has no meanig for the outermost SVG element.
Use a fallback
-                    // width and height of 8x8 cm (8 * 35.43307px)
-                    const double fFallbackMetric(8.0 * 35.43307);
-                    double fW(getWidth().isSet() ? getWidth().solve(*this, xcoordinate) :
fFallbackMetric);
-                    double fH(getHeight().isSet() ? getHeight().solve(*this, ycoordinate)
: fFallbackMetric);
+                    // width and height of din A 4 (21 x 29,7 cm)
+                    double fW(getWidth().isSet() ? getWidth().solve(*this, xcoordinate) :
(210.0 * 3.543307));
+                    double fH(getHeight().isSet() ? getHeight().solve(*this, ycoordinate)
: (297.0 * 3.543307));
 
                     // 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))
                     {
+                        const basegfx::B2DRange aSvgCanvasRange(0.0, 0.0, fW, fH);
+
+                        if(getViewBox())
+                        {
+                            if(!basegfx::fTools::equalZero(getViewBox()->getWidth()) &&
!basegfx::fTools::equalZero(getViewBox()->getHeight()))
+                            {
+                                // create mapping
+                                const SvgAspectRatio& rRatio = getSvgAspectRatio();
+                                basegfx::B2DHomMatrix aViewBoxMapping;
+
+                                if(rRatio.isSet())
+                                {
+                                    // let mapping be created from SvgAspectRatio
+                                    aViewBoxMapping = rRatio.createMapping(aSvgCanvasRange,
*getViewBox());
+
+                                    // no need to check ratio here for slice, the outermost
Svg will
+                                    // be clipped anyways (see below)
+                                }
+                                else
+                                {
+                                    // choose default mapping
+                                    aViewBoxMapping = rRatio.createLinearMapping(aSvgCanvasRange,
*getViewBox());
+                                }
+
+                                // scale content to viewBox definitions
+                                const drawinglayer::primitive2d::Primitive2DReference xTransform(
+                                    new drawinglayer::primitive2d::TransformPrimitive2D(
+                                        aViewBoxMapping,
+                                        aSequence));
+
+                                aSequence = drawinglayer::primitive2d::Primitive2DSequence(&xTransform,
1);
+                            }
+                        }
+
                         // 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
@@ -304,7 +337,6 @@ namespace svgio
                                 drawinglayer::primitive2d::getB2DRangeFromPrimitive2DSequence(
                                     aSequence,
                                     drawinglayer::geometry::ViewInformation2D()));
-                            const basegfx::B2DRange aSvgCanvasRange(0.0, 0.0, fW, fH);
 
                             if(!aSvgCanvasRange.isInside(aContentRange))
                             {

Modified: incubator/ooo/branches/alg/svgreplacement/main/svx/source/svdraw/svdograf.cxx
URL: http://svn.apache.org/viewvc/incubator/ooo/branches/alg/svgreplacement/main/svx/source/svdraw/svdograf.cxx?rev=1215102&r1=1215101&r2=1215102&view=diff
==============================================================================
--- incubator/ooo/branches/alg/svgreplacement/main/svx/source/svdraw/svdograf.cxx (original)
+++ incubator/ooo/branches/alg/svgreplacement/main/svx/source/svdraw/svdograf.cxx Fri Dec
16 12:01:56 2011
@@ -68,6 +68,8 @@
 #include <basegfx/polygon/b2dpolygontools.hxx>
 #include <osl/thread.hxx>
 #include <vos/mutex.hxx>
+#include <drawinglayer/processor2d/vclmetafileprocessor2d.hxx>
+#include <basegfx/matrix/b2dhommatrixtools.hxx>
 
 using namespace ::com::sun::star::uno;
 using namespace ::com::sun::star::io;
@@ -1091,9 +1093,6 @@ const GDIMetaFile* SdrGrafObj::GetGDIMet
 
 // -----------------------------------------------------------------------------
 
-#include <drawinglayer/processor2d/vclmetafileprocessor2d.hxx>
-#include <basegfx/matrix/b2dhommatrixtools.hxx>
-
 SdrObject* SdrGrafObj::DoConvertToPolyObj(sal_Bool bBezier, bool bAddText) const
 {
 	SdrObject* pRetval = NULL;



Mime
View raw message