Date: prev next · Thread: first prev next last
2011 Archives by date, by thread · List index


KUROSAWA, Takeshi wrote:
Here are some patches to improve SVG export filter.

Hi Takeshi,

wow, this is great work! I have only one comment (and a suggestion,
see below):

0003: Make filter export linear and axial gradients as SVG <linearGradient>s.
Use SVG's native gradient instead of polygon fallback.
With this patch, gradient steps of linear and axial gradient are ignored.
In other words, linear and axial gradients are always exported as
"smooth" gradients.
However, as far as I know, the manual steps function is for printing.
So I suppose ignoring gradient steps is safe.

Nope, this is still in use, especially in legacy binary documents
(soon to be axed I guess), and more importantly, for all those svm
metafiles. Could you keep both code paths - i.e. falling back to the
old code, should there be a step count (with 0 meaning smooth
gradient, and maybe you can even cut off at something like 100 or so
steps)?

I have not yet applied the patches, to not interfere with potential
rework on your side.

A bit orthogonal to this great improvement, let me point you to
https://github.com/knobo/OOo-svg-Export.git - this is an early stage
of a slightly different attempt, using the new drawing layer
primitives (that contain more high-level geometry information, like
stroking etc.). I attach two changes I had lying around locally -
maybe you're also interested in looking into that.

Additionally (though not sure it's of help here, as it's designed
for high-level ODF-style gradients) - there's
basegfx/inc/basegfx/tools/gradienttools.hxx, that encapsulates most
of the pain involved in converting gradient types.

To support native gradients, I need to calculate a bounding box of a gradient.
Currently it is done in OutputDevice::ImplDrawLinearGradient and
OutputDevice::ImplDrawComplexGradient.
So I moved that to Gradient class (0002 patch) to use it in filter code.

This is fine.

0004: Make filter export transparencies as SVG <mask>s.
SVG export filter supports only solid transparency of solid fill (i.e.
color) until now.
The patch extends support to support solid and gradient transparency
of all fill styles.
# Some SVG viewers including WebKit don't support <mask> yet :-(.

I'd take that route anyway.

Cheers,

-- Thorsten
From 95ebed72916aeded24043bb7189d97c6c9031946 Mon Sep 17 00:00:00 2001
From: Thorsten Behrens <tbehrens@novell.com>
Date: Tue, 16 Nov 2010 22:59:51 +0100
Subject: [PATCH 1/2] Write header, more compile fixes

---
 exports.map    |    9 ++++++
 makefile.mk    |   68 +++++++++++++++++++++++++++++++++++++++++++
 svgexport2.cxx |   88 +++++++++++++++++++++++++++++++++++++-------------------
 svgexport2.hxx |    6 ++--
 4 files changed, 138 insertions(+), 33 deletions(-)
 create mode 100644 exports.map
 create mode 100644 makefile.mk

diff --git a/exports.map b/exports.map
new file mode 100644
index 0000000..532415a
--- /dev/null
+++ b/exports.map
@@ -0,0 +1,9 @@
+UDK_3_0_0 {
+        global:
+                component_getImplementationEnvironment;
+                component_getFactory;
+                component_writeInfo;
+
+        local:
+                *;
+};
diff --git a/makefile.mk b/makefile.mk
new file mode 100644
index 0000000..f0a23fa
--- /dev/null
+++ b/makefile.mk
@@ -0,0 +1,68 @@
+#*************************************************************************
+#
+# 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=..$/..
+
+PRJNAME=filter
+TARGET=svgexport
+ENABLE_EXCEPTIONS=TRUE
+VISIBILITY_HIDDEN=TRUE
+
+# --- Settings ----------------------------------
+
+.INCLUDE :  settings.mk
+.INCLUDE :     libs.mk
+
+# --- Types -------------------------------------
+
+SLOFILES= $(SLO)$/svgexport2.obj
+
+# --- Library -----------------------------------
+
+SHL1TARGET=$(TARGET)$(DLLPOSTFIX)
+
+SHL1STDLIBS=\
+    $(BASEGFXLIB)              \
+    $(UNOTOOLSLIB)             \
+    $(TOOLSLIB)                        \
+       $(DRAWINGLAYERLIB)  \
+    $(COMPHELPERLIB)   \
+    $(CPPUHELPERLIB)   \
+    $(CPPULIB)                 \
+    $(SALLIB)
+
+SHL1DEPN=
+SHL1IMPLIB=    i$(SHL1TARGET)
+SHL1LIBS=      $(SLB)$/$(TARGET).lib
+SHL1VERSIONMAP=exports.map
+SHL1DEF=       $(MISC)$/$(SHL1TARGET).def
+
+DEF1NAME=$(SHL1TARGET)
+
+# --- Targets ----------------------------------
+
+.INCLUDE : target.mk
diff --git a/svgexport2.cxx b/svgexport2.cxx
index 5dde9d0..d5029e9 100644
--- a/svgexport2.cxx
+++ b/svgexport2.cxx
@@ -35,32 +35,42 @@
 
 #include "svgexport2.hxx"
 
+#include <cppuhelper/factory.hxx>
+#include <cppuhelper/implementationentry.hxx>
 #include <comphelper/servicedecl.hxx>
 #include <unotools/ucbstreamhelper.hxx>
 #include <unotools/streamwrap.hxx>
-#include <drawinglayer/primitive2d/baseprocesser2d.hxx>
+#include <drawinglayer/processor2d/baseprocessor2d.hxx>
+#include <drawinglayer/primitive2d/drawinglayer_primitivetypes2d.hxx>
+#include <drawinglayer/primitive2d/transformprimitive2d.hxx>
+#include <drawinglayer/primitive2d/polygonprimitive2d.hxx>
 #include <com/sun/star/io/XOutputStream.hpp>
+#include <com/sun/star/frame/XDesktop.hpp>
+#include <com/sun/star/graphic/XPrimitiveFactory2D.hpp>
+#include <com/sun/star/drawing/XDrawView.hpp>
+
+#include <boost/scoped_ptr.hpp>
 
 using namespace ::com::sun::star;
 
 namespace
 {
 
-class SVGRenderer : public drawinglayer::primitive2d::BaseProcesser2D
+class SVGRenderer : public drawinglayer::processor2d::BaseProcessor2D
 {
-    virtual void processBasePrimitive2D(const primitive2d::BasePrimitive2D& rCandidate) 
+    virtual void processBasePrimitive2D(const drawinglayer::primitive2d::BasePrimitive2D& 
rCandidate) 
     {
         switch(rCandidate.getPrimitive2DID())
         {
             case PRIMITIVE2D_ID_TRANSFORMPRIMITIVE2D :
             {
                 // remember current ViewInformation2D
-                const primitive2d::TransformPrimitive2D& rTransformCandidate(
-                    static_cast< const primitive2d::TransformPrimitive2D& >(rCandidate));
-                const geometry::ViewInformation2D aLastViewInformation2D(getViewInformation2D());
+                const drawinglayer::primitive2d::TransformPrimitive2D& rTransformCandidate(
+                    static_cast< const drawinglayer::primitive2d::TransformPrimitive2D& 
(rCandidate));
+                const drawinglayer::geometry::ViewInformation2D 
aLastViewInformation2D(getViewInformation2D());
                  
                 // create new local ViewInformation2D containing transformation
-                const geometry::ViewInformation2D aViewInformation2D(
+                const drawinglayer::geometry::ViewInformation2D aViewInformation2D(
                     getViewInformation2D().getObjectTransformation() * 
rTransformCandidate.getTransformation(), 
                     getViewInformation2D().getViewTransformation(), 
                     getViewInformation2D().getViewport(),
@@ -80,19 +90,16 @@ class SVGRenderer : public drawinglayer::primitive2d::BaseProcesser2D
 
             case PRIMITIVE2D_ID_POLYGONHAIRLINEPRIMITIVE2D :
             {
+#if 0
                 // create hairline in discrete coordinates
-                const primitive2d::PolygonHairlinePrimitive2D& rPolygonCandidate(
-                    static_cast< const primitive2d::PolygonHairlinePrimitive2D& >(rCandidate));
+                const drawinglayer::primitive2d::PolygonHairlinePrimitive2D& rPolygonCandidate(
+                    static_cast< const drawinglayer::primitive2d::PolygonHairlinePrimitive2D& 
(rCandidate));
                 // write PolygonHairlinePrimitive2D as svg
                 // 
+#endif
                 break;
             }
                
-            case PRIMITIVE2D_ID_POLYGONHAIRLINEPRIMITIVE2D :
-            {
-                break;
-            }
-
             // - BitmapPrimitive2D (bitmap data, evtl. with transparence)
             // - PointArrayPrimitive2D (single points)
             // - PolygonHairlinePrimitive2D (hairline curves/polygons)
@@ -114,17 +121,35 @@ class SVGRenderer : public drawinglayer::primitive2d::BaseProcesser2D
     }
 
 public:
-    SVGRenderer(const geometry::ViewInformation2D& rViewInformation) : 
-        drawinglayer::primitive2d::BaseProcesser2D(rViewInformation)
+    SVGRenderer(const drawinglayer::geometry::ViewInformation2D& rViewInformation) : 
+        drawinglayer::processor2d::BaseProcessor2D(rViewInformation)
     {}
 };
 
-void convert_to_svg( const uno::Reference< drawing::XDrawPage >&   xDrawPage, 
-                                        const uno::sequence< graphics::Primitive2D >& xSequence,
-                                        const uno::Reference< io::XOutputStream >&    xOutStream ) 
+void convert_to_svg( const uno::Reference< drawing::XDrawPage >&                   /*xDrawPage*/, 
+                                        const uno::Sequence< uno::Reference<graphic::XPrimitive2D> 
& /*xSequence*/,
+                                        const uno::Reference< io::XOutputStream >&                 
   xOutStream ) 
 {  
-    // Open The file
     // Write svg header
+    const char* sHeader = 
+        "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>"
+        "<!-- Created with LibreOffice (http://www.libreoffice.org/) -->"
+        "<svg"
+        "   xmlns:dc=\"http://purl.org/dc/elements/1.1/\"";
+        "   xmlns:cc=\"http://creativecommons.org/ns#\"";
+        "   xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\"";
+        "   xmlns:svg=\"http://www.w3.org/2000/svg\"";
+        "   xmlns=\"http://www.w3.org/2000/svg\"";
+        "   xmlns:xlink=\"http://www.w3.org/1999/xlink\"";
+        "   width=\"1024\""
+        "   height=\"1024\""
+        "   id=\"svg2\""
+        "   version=\"1.1\">";
+
+    xOutStream->writeBytes(
+        uno::Sequence<sal_Int8>( reinterpret_cast<const sal_Int8*>( sHeader ), 
+                                 sizeof(sHeader)-1 ));
+
     // page properties from XDrawPage
   
     // Iterate through primitives sequence
@@ -132,10 +157,10 @@ void convert_to_svg( const uno::Reference< drawing::XDrawPage >&   xDrawPage,
     // drawinglayer::primitive2d::Primitive2DSequence* pMySequence = 
     // dynamic_cast< drawinglayer::primitive2d::Primitive2DSequence > ( xSequence );
   
-    geometry::ViewInformation2D aViewInformation;
+    drawinglayer::geometry::ViewInformation2D aViewInformation;
     SVGRenderer aRederer(aViewInformation);
 
-    aRender.process(xSequence);
+    //aRender.process(xSequence);
 
        // Two pass
     // Collect hasmap of gradients, colors, etc.
@@ -144,8 +169,9 @@ void convert_to_svg( const uno::Reference< drawing::XDrawPage >&   xDrawPage,
 
 } // anon namespace
 
-SVGFilter::SVGFilter( const uno::Reference< lang::XMultiServiceFactory > &rxMSF ) :
-    mxMSF(rxMSF),
+SVGFilter::SVGFilter( const uno::Reference< uno::XComponentContext > &rxCtx ) :
+    mxMSF( rxCtx->getServiceManager(),
+           uno::UNO_QUERY_THROW ),
        mxSrcDoc()
 {}  
   
@@ -188,29 +214,31 @@ sal_Bool SAL_CALL SVGFilter::filter( const uno::Sequence< 
beans::PropertyValue >
         {
             rtl::OUString aFileName;
             pValue[ i ].Value >>= aFileName;
-            pOStm.set( ::utl::UcbStreamHelper::CreateStream( aFileName, STREAM_WRITE|STREAM_TRUNC 
) );
+            pOStm.reset( ::utl::UcbStreamHelper::CreateStream( aFileName, 
STREAM_WRITE|STREAM_TRUNC ) );
             if( pOStm )
                 xOStm = uno::Reference< io::XOutputStream >( new ::utl::OOutputStreamWrapper( 
*pOStm ));
         }
     }
 
-    uno::Reference< graphic::PrimitiveFactory2D > xPrimitiveFactory2D ( 
+    uno::Reference< graphic::XPrimitiveFactory2D > xPrimitiveFactory2D ( 
         mxMSF->createInstance(
             rtl::OUString( 
                 RTL_CONSTASCII_USTRINGPARAM("com.sun.star.graphic.PrimitiveFactory2D"))),
         uno::UNO_QUERY_THROW);
 
-    uno::Sequence< graphics::Primitive2D > xPagePrimitives = 
+    uno::Sequence< uno::Reference<graphic::XPrimitive2D> > xPagePrimitives = 
         xPrimitiveFactory2D->createPrimitivesFromXDrawPage( 
             xDrawPage, 
             uno::Sequence<beans::PropertyValue>() );
     convert_to_svg(xDrawPage, xPagePrimitives, xOStm);
+
+    return sal_True;
 }
 
-void SAL_CALL SVGFilter::cancel( ) throw (RuntimeException)
+void SAL_CALL SVGFilter::cancel( ) throw (uno::RuntimeException)
 {}
   
-void SAL_CALL SVGFilter::setSourceDocument( const Reference< XComponent >& xDoc ) 
throw(IllegalArgumentException, RuntimeException)
+void SAL_CALL SVGFilter::setSourceDocument( const uno::Reference< lang::XComponent >& xDoc ) 
throw(lang::IllegalArgumentException, uno::RuntimeException)
 {
     mxSrcDoc = xDoc;
 }
@@ -223,4 +251,4 @@ const sdecl::ServiceDecl svgExportDecl(
     "com.sun.star.document.ExportFilter" );
 
 // The C shared lib entry points
-COMPHELPER_SERVICEDECL_EXPORTS(svgExportDecl)
+COMPHELPER_SERVICEDECL_EXPORTS1(svgExportDecl)
diff --git a/svgexport2.hxx b/svgexport2.hxx
index edb2e65..696693e 100644
--- a/svgexport2.hxx
+++ b/svgexport2.hxx
@@ -35,13 +35,13 @@
 #include <com/sun/star/document/XFilter.hpp>
 #include <com/sun/star/document/XExporter.hpp>
 #include <cppuhelper/implbase2.hxx>
-#include <com/sun/star/lang/XMultiServiceFactory.hpp>
+#include <com/sun/star/uno/XComponentContext.hpp>
 
 class SVGFilter : public cppu::WeakImplHelper2< ::com::sun::star::document::XFilter,
                                                 ::com::sun::star::document::XExporter >
 {
     ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > mxMSF;
-    ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent >                      
mxSrcDoc;
+    ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent >           mxSrcDoc;
     
     // XFilter
     virtual ::sal_Bool SAL_CALL filter( const ::com::sun::star::uno::Sequence< 
::com::sun::star::beans::PropertyValue >& aDescriptor ) throw 
(::com::sun::star::uno::RuntimeException);
@@ -51,7 +51,7 @@ class SVGFilter : public cppu::WeakImplHelper2< ::com::sun::star::document::XFil
     virtual void SAL_CALL setSourceDocument( const ::com::sun::star::uno::Reference< 
::com::sun::star::lang::XComponent >& Document ) throw 
(::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException);
   
 public:
-    SVGFilter( const ::com::sun::star::uno::Reference< 
::com::sun::star::lang::XMultiServiceFactory > &rxMSF );
+    SVGFilter( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > 
&rxCxt );
 };
 
 #endif /*INCLUDED_SVGEXPORT_HXX*/
-- 
1.7.1

From 41249aa5c769e01780899e00569e944f4a807b74 Mon Sep 17 00:00:00 2001
From: Thorsten Behrens <tbehrens@novell.com>
Date: Wed, 2 Feb 2011 14:45:32 +0100
Subject: [PATCH 2/2] More tweaks

---
 svgexport2.cxx |   11 +++--------
 1 files changed, 3 insertions(+), 8 deletions(-)

diff --git a/svgexport2.cxx b/svgexport2.cxx
index d5029e9..d5f807a 100644
--- a/svgexport2.cxx
+++ b/svgexport2.cxx
@@ -127,7 +127,7 @@ public:
 };
 
 void convert_to_svg( const uno::Reference< drawing::XDrawPage >&                   /*xDrawPage*/, 
-                                        const uno::Sequence< uno::Reference<graphic::XPrimitive2D> 
& /*xSequence*/,
+                                        const uno::Sequence< uno::Reference<graphic::XPrimitive2D> 
& xSequence,
                                         const uno::Reference< io::XOutputStream >&                 
   xOutStream ) 
 {  
     // Write svg header
@@ -153,14 +153,9 @@ void convert_to_svg( const uno::Reference< drawing::XDrawPage >&
     // page properties from XDrawPage
   
     // Iterate through primitives sequence
-  
-    // drawinglayer::primitive2d::Primitive2DSequence* pMySequence = 
-    // dynamic_cast< drawinglayer::primitive2d::Primitive2DSequence > ( xSequence );
-  
     drawinglayer::geometry::ViewInformation2D aViewInformation;
-    SVGRenderer aRederer(aViewInformation);
-
-    //aRender.process(xSequence);
+    SVGRenderer aRenderer(aViewInformation);
+    aRenderer.process(xSequence);
 
        // Two pass
     // Collect hasmap of gradients, colors, etc.
-- 
1.7.1

Attachment: pgpHm2nTB7Ali.pgp
Description: PGP signature


Context


Privacy Policy | Impressum (Legal Info) | Copyright information: Unless otherwise specified, all text and images on this website are licensed under the Creative Commons Attribution-Share Alike 3.0 License. This does not include the source code of LibreOffice, which is licensed under the Mozilla Public License (MPLv2). "LibreOffice" and "The Document Foundation" are registered trademarks of their corresponding registered owners or are in actual use as trademarks in one or more countries. Their respective logos and icons are also subject to international copyright laws. Use thereof is explained in our trademark policy.