incubator-ooo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a..@apache.org
Subject svn commit: r1211462 - in /incubator/ooo/branches/alg/svgreplacement/main/svgio: Library_svgio.mk inc/svgio/svgreader/svgimagenode.hxx inc/svgio/svgreader/svgtools.hxx source/svgreader/svgimagenode.cxx source/svgreader/svgtools.cxx
Date Wed, 07 Dec 2011 14:54:33 GMT
Author: alg
Date: Wed Dec  7 14:54:33 2011
New Revision: 1211462

URL: http://svn.apache.org/viewvc?rev=1211462&view=rev
Log:
svg: added support for image, base64 embedded; added AspectRatio support for image

Modified:
    incubator/ooo/branches/alg/svgreplacement/main/svgio/Library_svgio.mk
    incubator/ooo/branches/alg/svgreplacement/main/svgio/inc/svgio/svgreader/svgimagenode.hxx
    incubator/ooo/branches/alg/svgreplacement/main/svgio/inc/svgio/svgreader/svgtools.hxx
    incubator/ooo/branches/alg/svgreplacement/main/svgio/source/svgreader/svgimagenode.cxx
    incubator/ooo/branches/alg/svgreplacement/main/svgio/source/svgreader/svgtools.cxx

Modified: incubator/ooo/branches/alg/svgreplacement/main/svgio/Library_svgio.mk
URL: http://svn.apache.org/viewvc/incubator/ooo/branches/alg/svgreplacement/main/svgio/Library_svgio.mk?rev=1211462&r1=1211461&r2=1211462&view=diff
==============================================================================
--- incubator/ooo/branches/alg/svgreplacement/main/svgio/Library_svgio.mk (original)
+++ incubator/ooo/branches/alg/svgreplacement/main/svgio/Library_svgio.mk Wed Dec  7 14:54:33
2011
@@ -49,6 +49,9 @@ $(eval $(call gb_Library_add_linked_libs
     sal \
     stl \
     tl \
+    sax \
+    vcl \
+    svt \
     $(gb_STDLIBS) \
 ))
 

Modified: incubator/ooo/branches/alg/svgreplacement/main/svgio/inc/svgio/svgreader/svgimagenode.hxx
URL: http://svn.apache.org/viewvc/incubator/ooo/branches/alg/svgreplacement/main/svgio/inc/svgio/svgreader/svgimagenode.hxx?rev=1211462&r1=1211461&r2=1211462&view=diff
==============================================================================
--- incubator/ooo/branches/alg/svgreplacement/main/svgio/inc/svgio/svgreader/svgimagenode.hxx
(original)
+++ incubator/ooo/branches/alg/svgreplacement/main/svgio/inc/svgio/svgreader/svgimagenode.hxx
Wed Dec  7 14:54:33 2011
@@ -45,7 +45,12 @@ namespace svgio
             SvgNumber               maY;
             SvgNumber               maWidth;
             SvgNumber               maHeight;
-            rtl::OUString           maXLink;
+
+            rtl::OUString           maXLink;        // internal link
+            rtl::OUString           maUrl;          // external link
+            
+            rtl::OUString           maMimeType;     // mimetype and
+            rtl::OUString           maData;         // base64 data
 
         public:
             SvgImageNode(

Modified: 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=1211462&r1=1211461&r2=1211462&view=diff
==============================================================================
--- incubator/ooo/branches/alg/svgreplacement/main/svgio/inc/svgio/svgreader/svgtools.hxx
(original)
+++ incubator/ooo/branches/alg/svgreplacement/main/svgio/inc/svgio/svgreader/svgtools.hxx
Wed Dec  7 14:54:33 2011
@@ -195,6 +195,8 @@ namespace svgio
         typedef ::std::vector< rtl::OUString > SvgStringVector;
         bool readSvgStringVector(const rtl::OUString& rCandidate, SvgStringVector&
rSvgStringVector);
 
+        void readImageLink(const rtl::OUString& rCandidate, rtl::OUString& rXLink,
rtl::OUString& rUrl, rtl::OUString& rMimeType, rtl::OUString& rData);
+
         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);

Modified: incubator/ooo/branches/alg/svgreplacement/main/svgio/source/svgreader/svgimagenode.cxx
URL: http://svn.apache.org/viewvc/incubator/ooo/branches/alg/svgreplacement/main/svgio/source/svgreader/svgimagenode.cxx?rev=1211462&r1=1211461&r2=1211462&view=diff
==============================================================================
--- incubator/ooo/branches/alg/svgreplacement/main/svgio/source/svgreader/svgimagenode.cxx
(original)
+++ incubator/ooo/branches/alg/svgreplacement/main/svgio/source/svgreader/svgimagenode.cxx
Wed Dec  7 14:54:33 2011
@@ -23,6 +23,17 @@
 #include "precompiled_svgio.hxx"
 
 #include <svgio/svgreader/svgimagenode.hxx>
+#include <sax/tools/converter.hxx>
+#include <tools/stream.hxx>
+#include <vcl/bitmapex.hxx>
+#include <svtools/filter.hxx>
+#include <basegfx/matrix/b2dhommatrixtools.hxx>
+#include <drawinglayer/primitive2d/bitmapprimitive2d.hxx>
+#include <drawinglayer/primitive2d/groupprimitive2d.hxx>
+#include <drawinglayer/primitive2d/transformprimitive2d.hxx>
+#include <drawinglayer/primitive2d/maskprimitive2d.hxx>
+#include <basegfx/polygon/b2dpolygontools.hxx>
+#include <basegfx/polygon/b2dpolygon.hxx>
 
 //////////////////////////////////////////////////////////////////////////////
 
@@ -41,7 +52,10 @@ namespace svgio
             maY(0),
             maWidth(0),
             maHeight(0),
-            maXLink()
+            maXLink(),
+            maUrl(),
+            maMimeType(),
+            maData()
         {
         }
 
@@ -139,9 +153,9 @@ namespace svgio
                 {
                     const sal_Int32 nLen(aContent.getLength());
 
-                    if(nLen && sal_Unicode('#') == aContent[0])
+                    if(nLen)
                     {
-                        maXLink = aContent.copy(1);
+                        readImageLink(aContent, maXLink, maUrl, maMimeType, maData);
                     }
                     break;
                 }
@@ -160,13 +174,132 @@ namespace svgio
 
                 if(fWidth > 0.0 && fHeight > 0.0)
                 {
+                    BitmapEx aBitmapEx;
+                    drawinglayer::primitive2d::Primitive2DVector aNewTarget;
+                    drawinglayer::primitive2d::Primitive2DSequence aEmbedded;
+
+                    // prepare Target and ViewBox for evtl. AspectRatio mappings
                     const double fX(getX().isSet() ? getX().solve(*this, xcoordinate) : 0.0);
                     const double fY(getY().isSet() ? getY().solve(*this, ycoordinate) : 0.0);
-                    const basegfx::B2DRange aRange(fX, fY, fX + fWidth, fY + fHeight);
+                    const basegfx::B2DRange aTarget(fX, fY, fX + fWidth, fY + fHeight);
+                    basegfx::B2DRange aViewBox(aTarget);
 
+                    if(maMimeType.getLength() && maData.getLength())
+                    {
+                        // use embedded base64 encoded data
+                        ::com::sun::star::uno::Sequence< sal_Int8 > aPass;
+                        ::sax::Converter::decodeBase64(aPass, maData);
 
+                        if(aPass.hasElements())
+                        {
+                            SvMemoryStream aStream(aPass.getArray(), aPass.getLength(), STREAM_READ);
+                            Graphic aGraphic;
 
+                            if(GRFILTER_OK == GraphicFilter::GetGraphicFilter()->ImportGraphic(
+                                aGraphic, 
+                                String(), 
+                                aStream))
+                            {
+                                if(GRAPHIC_BITMAP == aGraphic.GetType())
+                                {
+                                    if(aGraphic.getSvgData().get())
+                                    {
+                                        // embedded Svg
+                                        aEmbedded = aGraphic.getSvgData()->getPrimitive2DSequence();
+
+                                        // fill aViewBox
+                                        aViewBox = aGraphic.getSvgData()->getRange();
+                                    }
+                                    else
+                                    {
+                                        // get bitmap
+                                        aBitmapEx = aGraphic.GetBitmapEx();
+                                    }
+                                }
+                                else
+                                {
+                                    // evtl. convert to bitmap
+                                    aBitmapEx = aGraphic.GetBitmapEx();
+                                }
+                            }
+                        }
+                    }
 
+                    if(!aBitmapEx.IsEmpty())
+                    {
+                        // create content from bitmap
+                        aNewTarget.push_back(
+                            new drawinglayer::primitive2d::BitmapPrimitive2D(
+                                aBitmapEx,
+                                basegfx::B2DHomMatrix()));
+
+                        // fill aViewBox. No size set yet, use unit size
+                        aViewBox = basegfx::B2DRange(0.0, 0.0, 1.0, 1.0);
+                    }
+                    else if(aEmbedded.hasElements())
+                    {
+                        // add to aNewTarget as Group
+                        aNewTarget.push_back(
+                            new drawinglayer::primitive2d::GroupPrimitive2D(
+                                aEmbedded));
+                    }
+
+                    if(aNewTarget.size())
+                    {
+                        if(aTarget.equal(aViewBox))
+                        {
+                            // just add to rTarget
+                            rTarget.insert(rTarget.end(), aNewTarget.begin(), aNewTarget.end());
+                        }
+                        else
+                        {
+                            // create mapping
+                            const SvgAspectRatio& rRatio = getSvgAspectRatio();
+                            const drawinglayer::primitive2d::Primitive2DSequence aSequence(Primitive2DVectorToPrimitive2DSequence(aNewTarget));
+
+                            if(rRatio.isSet())
+                            {
+                                // let mapping be created from SvgAspectRatio
+                                const basegfx::B2DHomMatrix aEmbeddingTransform(
+                                    rRatio.createMapping(aTarget, aViewBox));
+
+                                // prepare embedding in transformation
+                                drawinglayer::primitive2d::TransformPrimitive2D* pNew = 
+                                    new drawinglayer::primitive2d::TransformPrimitive2D(
+                                        aEmbeddingTransform,
+                                        aSequence);
+
+                                if(rRatio.isMeetOrSlice())
+                                {
+                                    // embed in transformation
+                                    rTarget.push_back(pNew);
+                                }
+                                else
+                                {
+                                    // need to embed in MaskPrimitive2D, too
+                                    const drawinglayer::primitive2d::Primitive2DReference
xRef(pNew);
+
+                                    rTarget.push_back(
+                                        new drawinglayer::primitive2d::MaskPrimitive2D(
+                                            basegfx::B2DPolyPolygon(basegfx::tools::createPolygonFromRect(aTarget)),
+                                            drawinglayer::primitive2d::Primitive2DSequence(&xRef,
1)));
+                                }
+                            }
+                            else
+                            {
+                                // choose default mapping
+                                const basegfx::B2DHomMatrix aEmbeddingTransform(
+                                    rRatio.createLinearMapping(
+                                        aTarget, aViewBox));
+                                    
+                                // embed in transformation
+                                rTarget.push_back(
+                                    new drawinglayer::primitive2d::TransformPrimitive2D(
+                                        aEmbeddingTransform,
+                                        aSequence));
+                            }
+                        }
+                    }
                 }
             }
         }

Modified: incubator/ooo/branches/alg/svgreplacement/main/svgio/source/svgreader/svgtools.cxx
URL: http://svn.apache.org/viewvc/incubator/ooo/branches/alg/svgreplacement/main/svgio/source/svgreader/svgtools.cxx?rev=1211462&r1=1211461&r2=1211462&view=diff
==============================================================================
--- incubator/ooo/branches/alg/svgreplacement/main/svgio/source/svgreader/svgtools.cxx (original)
+++ incubator/ooo/branches/alg/svgreplacement/main/svgio/source/svgreader/svgtools.cxx Wed
Dec  7 14:54:33 2011
@@ -1335,6 +1335,66 @@ namespace svgio
             return !rSvgStringVector.empty();
         }
 
+        void readImageLink(const rtl::OUString& rCandidate, rtl::OUString& rXLink,
rtl::OUString& rUrl, rtl::OUString& rMimeType, rtl::OUString& rData)
+        {
+            rXLink = rUrl = rMimeType = rData = rtl::OUString();
+
+            if(sal_Unicode('#') == rCandidate[0])
+            {
+                // local link
+                rXLink = rCandidate.copy(1);
+            }
+            else
+            {
+                static rtl::OUString aStrData(rtl::OUString::createFromAscii("data:"));
+
+                if(rCandidate.match(aStrData, 0))
+                {
+                    // embedded data
+                    sal_Int32 nPos(aStrData.getLength());
+                    sal_Int32 nLen(rCandidate.getLength());
+                    rtl::OUStringBuffer aBuffer;
+
+                    // read mime type
+                    skip_char(rCandidate, sal_Unicode(' '), nPos, nLen);
+                    copyToLimiter(rCandidate, sal_Unicode(';'), nPos, aBuffer, nLen);
+                    skip_char(rCandidate, sal_Unicode(' '), sal_Unicode(';'), nPos, nLen);
+                    rMimeType = aBuffer.makeStringAndClear();
+
+                    if(rMimeType.getLength() && nPos < nLen)
+                    {
+                        static rtl::OUString aStrImage(rtl::OUString::createFromAscii("image"));
+
+                        if(rMimeType.match(aStrImage, 0))
+                        {
+                            // image data
+                            rtl::OUString aData(rCandidate.copy(nPos));
+                            static rtl::OUString aStrBase64(rtl::OUString::createFromAscii("base64"));
+                                    
+                            if(aData.match(aStrBase64, 0))
+                            {
+                                // base64 encoded
+                                nPos = aStrBase64.getLength();
+                                nLen = aData.getLength();
+                                            
+                                skip_char(aData, sal_Unicode(' '), sal_Unicode(','), nPos,
nLen);
+
+                                if(nPos < nLen)
+                                {
+                                    rData = aData.copy(nPos);
+                                }
+                            }
+                        }
+                    }
+                }
+                else
+                {
+                    // Url (path and filename)
+                    rUrl = rCandidate;
+                }
+            }
+        }
+
         rtl::OUString convert(const rtl::OUString& rCandidate, const sal_Unicode&
rPattern, const sal_Unicode& rNew, bool bRemove)
         {
             const sal_Int32 nLen(rCandidate.getLength());



Mime
View raw message