Hi all,

Here are some tiny patches to fix bugs in SVG import.

0001: Check opacity for == operator
Sometimes, LilbreOffice doesn't handle opacity value.
Example:
http://gnome-colors.googlecode.com/svn/trunk/gnome-colors/gnome-colors-common/scalable/actions/document-properties.svg
The patch fixes this problem.

0002: Fix color serialization
Sometimes, LibreOffice fails to import fill or stroke colors (when
using File -> Open)
Example:
http://gnome-colors.googlecode.com/svn/trunk/gnome-colors/gnome-colors-common/scalable/actions/edit-redo.svg
Treat color value as hex.

0003:Relax paint url parsing (fix fdo#34205)
LibreOffice doesn't allow ' or " between "url(" and "#". As a result,
gradients using url('#foo') syntax aren't imported.
Bug 34205 – SVG import: transparency gradients incorrect
https://bugs.freedesktop.org/show_bug.cgi?id=34205

0004: Ensure writing styles for text
Currently, when a text element doesn't have presentation attributes or
styles, style information is not written (when using File -> Open).
So the text has zero width and is wrapped wrongly.
This patch ensures that filter writes style information if a text has no styles.
See attached text3.svg. Black text ("Hello") will be wrapped wrongly.

All patches are under LGPLv3 / MPL.

cheers,
--
Kurosawa Takeshi <taken....@gmail.com>
From 7264908a3058c34b5a72e8ce274c1c8e7ccbad02 Mon Sep 17 00:00:00 2001
From: Takeshi Kurosawa <taken....@gmail.com>
Date: Mon, 14 Feb 2011 15:21:41 +0900
Subject: [PATCH 1/4] Check opacity for == operator

Or opacity is ignored.
---
 filter/source/svg/gfxtypes.hxx |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)

diff --git a/filter/source/svg/gfxtypes.hxx b/filter/source/svg/gfxtypes.hxx
index 60e6a6c..0a07094 100644
--- a/filter/source/svg/gfxtypes.hxx
+++ b/filter/source/svg/gfxtypes.hxx
@@ -275,6 +275,7 @@ inline bool operator==(const State& rLHS, const State& rRHS )
         rLHS.mbVisibility==rRHS.mbVisibility &&
         rLHS.meFillType==rRHS.meFillType &&
         rLHS.mnFillOpacity==rRHS.mnFillOpacity &&
+        rLHS.mnOpacity==rRHS.mnOpacity &&
         rLHS.meStrokeType==rRHS.meStrokeType &&
         rLHS.mnStrokeOpacity==rRHS.mnStrokeOpacity &&
         rLHS.meViewportFillType==rRHS.meViewportFillType &&
@@ -319,6 +320,7 @@ struct StateHash
             ^  size_t(rState.mbVisibility)
             ^  size_t(rState.meFillType)
             ^  size_t(rState.mnFillOpacity)
+            ^  size_t(rState.mnOpacity)
             ^  size_t(rState.meStrokeType)
             ^  size_t(rState.mnStrokeOpacity)
             ^  size_t(rState.meViewportFillType)
-- 
1.7.1

From 38fe5587d887efc468393b4df4caed1f7604f63c Mon Sep 17 00:00:00 2001
From: Takeshi Kurosawa <taken....@gmail.com>
Date: Mon, 14 Feb 2011 15:23:20 +0900
Subject: [PATCH 2/4] Fix color serialization

The are hex values.
---
 filter/source/svg/svgreader.cxx |    6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/filter/source/svg/svgreader.cxx b/filter/source/svg/svgreader.cxx
index 9ccd3b7..44fa416 100644
--- a/filter/source/svg/svgreader.cxx
+++ b/filter/source/svg/svgreader.cxx
@@ -410,13 +410,13 @@ struct AnnotatingVisitor
         const sal_uInt8 nGreen( toByteColor(rColor.g) );
         const sal_uInt8 nBlue ( toByteColor(rColor.b)  );
         aBuf.append( sal_Unicode('#') );
-        if( nRed < 10 )
+        if( nRed < 0x10 )
             aBuf.append( sal_Unicode('0') );
         aBuf.append( sal_Int32(nRed), 16 );
-        if( nGreen < 10 )
+        if( nGreen < 0x10 )
             aBuf.append( sal_Unicode('0') );
         aBuf.append( sal_Int32(nGreen), 16 );
-        if( nBlue < 10 )
+        if( nBlue < 0x10 )
             aBuf.append( sal_Unicode('0') );
         aBuf.append( sal_Int32(nBlue), 16 );
 
-- 
1.7.1

From cf0c6d64bb3190743ce7237c75197c8f691aafbe Mon Sep 17 00:00:00 2001
From: Takeshi Kurosawa <taken....@gmail.com>
Date: Mon, 14 Feb 2011 15:24:11 +0900
Subject: [PATCH 3/4] Relax paint url parsing (fix fdo#34205)

Allow ' and " around parens.
---
 filter/source/svg/parserfragments.cxx |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/filter/source/svg/parserfragments.cxx b/filter/source/svg/parserfragments.cxx
index c515e85..95811d4 100644
--- a/filter/source/svg/parserfragments.cxx
+++ b/filter/source/svg/parserfragments.cxx
@@ -560,9 +560,9 @@ bool parsePaintUri( std::pair<const char*,const char*>& o_rPaintUri,
     const bool bRes = parse(sPaintUri,
         //  Begin grammar
         (
-            str_p("url(#") >>
+            str_p("url(") >> !( str_p("'") | str_p("\"") ) >> ("#") >>
             (+alnum_p)[assign_a(o_rPaintUri)] >>
-            str_p(")") >>
+            !( str_p("'") | str_p("\"") ) >> str_p(")") >>
             *( str_p("none")[assign_a(io_rColor.second,false)] |
                str_p("currentColor")[assign_a(io_rColor.second,true)] |
                ColorGrammar(io_rColor.first)
-- 
1.7.1

<<attachment: text3.svg>>

From b6fdd34b092bae64afc52f519ffa120f2e99ea2b Mon Sep 17 00:00:00 2001
From: Takeshi Kurosawa <taken....@gmail.com>
Date: Mon, 14 Feb 2011 15:26:21 +0900
Subject: [PATCH 4/4] Ensure writing styles for text

When a text element doesn't have presentation attributes or styles,
style information is not written. As a result the text has zero width.
---
 filter/source/svg/gfxtypes.hxx  |    2 +-
 filter/source/svg/svgreader.cxx |    9 +++++++++
 2 files changed, 10 insertions(+), 1 deletions(-)

diff --git a/filter/source/svg/gfxtypes.hxx b/filter/source/svg/gfxtypes.hxx
index 0a07094..24c4cbd 100644
--- a/filter/source/svg/gfxtypes.hxx
+++ b/filter/source/svg/gfxtypes.hxx
@@ -174,7 +174,7 @@ struct State
         maViewport(),
         maViewBox(),
         maFontFamily(), // app-default
-        mnFontSize(12.0),
+        mnFontSize(0),
         maFontStyle(RTL_CONSTASCII_USTRINGPARAM("normal")),
         maFontVariant(RTL_CONSTASCII_USTRINGPARAM("normal")),
         mnFontWeight(400.0),
diff --git a/filter/source/svg/svgreader.cxx b/filter/source/svg/svgreader.cxx
index 44fa416..b909155 100644
--- a/filter/source/svg/svgreader.cxx
+++ b/filter/source/svg/svgreader.cxx
@@ -147,6 +147,7 @@ struct AnnotatingVisitor
                       StateMap&                                         rStateMap,
                       const State&                                       rInitialState,
                       const uno::Reference<xml::sax::XDocumentHandler>& xDocumentHandler) :
+        mbSeenText(false),
         mnCurrStateId(0),
         maCurrState(),
         maParentStates(),
@@ -266,6 +267,13 @@ struct AnnotatingVisitor
                 maCurrState.maTransform.identity();
                 maCurrState.maViewBox.reset();
 
+                // set default font size here to ensure writing styles for text
+                if( !mbSeenText && XML_TEXT == nTagId )
+                {
+                    maCurrState.mnFontSize = 12.0;
+                    mbSeenText = true;
+                }
+
                 // scan for style info
                 const sal_Int32 nNumAttrs( xAttributes->getLength() );
                 rtl::OUString sAttributeValue;
@@ -1161,6 +1169,7 @@ struct AnnotatingVisitor
         }
     }
 
+    bool                                       mbSeenText;
     sal_Int32                                  mnCurrStateId;
     State                                      maCurrState;
     std::vector<State>                         maParentStates;
-- 
1.7.1

_______________________________________________
LibreOffice mailing list
LibreOffice@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/libreoffice

Reply via email to