Hi,

Here is a patch to make SVG filter export object's title and
description as alternate content
i.e. title and description element.
http://www.w3.org/TR/SVG/struct.html#DescriptionAndTitleElements

Currently the filter uses fixed texts such as "Drawing" and "Graphic"
as alternate content.
However they doesn't provide meaningful information.
# It is obvious that contents of a SVG file are "Drawing" or "Graphic".

LibreOffice stores title and description for each object, we can use it.
Actually they are stored as "svg:title" and "svg:description" in ODF.

Fixed text  is information about class of a shape. Thus use them as
class attribute.

The patch is under LGPLv3/MPL.

Cheers,
--
Kurosawa Takeshi <taken....@gmail.com>
From 11646f45021f9343bd33f11442306de6ce3e8b07 Mon Sep 17 00:00:00 2001
From: Kurosawa Takeshi <taken....@gmail.com>
Date: Sat, 12 Feb 2011 13:26:35 +0900
Subject: [PATCH] Export object's title and description as alternate content

Actually they are stored as "svg:title" and "svg:description" in ODF.

Fixed text such as "Drawing" and "Graphic" is information about class of a shape. Thus use them as class attribute.
---
 filter/source/svg/svgexport.cxx |   45 +++++++++++++++++++++-----------------
 filter/source/svg/svgfilter.hxx |    2 +-
 2 files changed, 26 insertions(+), 21 deletions(-)

diff --git a/filter/source/svg/svgexport.cxx b/filter/source/svg/svgexport.cxx
index bc8bea7..a1e9086 100644
--- a/filter/source/svg/svgexport.cxx
+++ b/filter/source/svg/svgexport.cxx
@@ -510,26 +510,25 @@ sal_Bool SVGFilter::implExportPages( const Reference< XDrawPages >& rxPages,
                 mpSVGExport->AddAttribute( XML_NAMESPACE_NONE, "id", implGetValidIDFromInterface( xShapes ) );
 
                 {
-                    SvXMLElementExport	aExp( *mpSVGExport, XML_NAMESPACE_NONE, "g", TRUE, TRUE );
-                    const Point			aNullPt;
-
                     {
                         Reference< XExtendedDocumentHandler > xExtDocHandler( mpSVGExport->GetDocHandler(), UNO_QUERY );
 
                         if( xExtDocHandler.is() )
                         {
-                            SvXMLElementExport	aExp2( *mpSVGExport, XML_NAMESPACE_NONE, "desc", TRUE, TRUE );
-                            OUString			aDesc;
+                            OUString aDesc;
 
                             if( bMaster )
-                                aDesc = B2UCONST( "Master slide" );
+                                aDesc = B2UCONST( "Master_Slide" );
                             else
                                 aDesc = B2UCONST( "Slide" );
 
-                            xExtDocHandler->unknown( aDesc );
+                            mpSVGExport->AddAttribute( XML_NAMESPACE_NONE, "class", aDesc );
                         }
                     }
 
+                    SvXMLElementExport aExp( *mpSVGExport, XML_NAMESPACE_NONE, "g", TRUE, TRUE );
+                    const Point        aNullPt;
+
                     if( bMaster )
                     {
                         const GDIMetaFile& rMtf = (*mpObjects)[ xDrawPage ].GetRepresentation();
@@ -639,15 +638,9 @@ sal_Bool SVGFilter::implExportShape( const Reference< XShape >& rxShape )
 
                 if( xShapes.is() )
                 {
+                    mpSVGExport->AddAttribute( XML_NAMESPACE_NONE, "class", B2UCONST( "Group" ) );
                     SvXMLElementExport aExp( *mpSVGExport, XML_NAMESPACE_NONE, "g", TRUE, TRUE );
 
-                    {
-                        SvXMLElementExport						aExp2( *mpSVGExport, XML_NAMESPACE_NONE, "desc", TRUE, TRUE );
-                        Reference< XExtendedDocumentHandler >	xExtDocHandler( mpSVGExport->GetDocHandler(), UNO_QUERY );
-
-                        xExtDocHandler->unknown( B2UCONST( "Group" ) );
-                    }
-
                     bRet = implExportShapes( xShapes );
                 }
             }
@@ -663,13 +656,25 @@ sal_Bool SVGFilter::implExportShape( const Reference< XShape >& rxShape )
                 const Size  aSize( aBoundRect.Width, aBoundRect.Height );
 
                 {
+                    mpSVGExport->AddAttribute( XML_NAMESPACE_NONE, "class", implGetClassFromShape( rxShape ) );
                     SvXMLElementExport aExp( *mpSVGExport, XML_NAMESPACE_NONE, "g", TRUE, TRUE );
 
+                    Reference< XExtendedDocumentHandler > xExtDocHandler( mpSVGExport->GetDocHandler(), UNO_QUERY );
+
+                    OUString aTitle;
+                    xShapePropSet->getPropertyValue( B2UCONST( "Title" ) ) >>= aTitle;
+                    if( aTitle.getLength() )
                     {
-                        SvXMLElementExport						aExp2( *mpSVGExport, XML_NAMESPACE_NONE, "desc", TRUE, TRUE );
-                        Reference< XExtendedDocumentHandler >	xExtDocHandler( mpSVGExport->GetDocHandler(), UNO_QUERY );
+                        SvXMLElementExport aExp2( *mpSVGExport, XML_NAMESPACE_NONE, "title", TRUE, TRUE );
+                        xExtDocHandler->characters( aTitle );
+                    }
 
-                        xExtDocHandler->unknown( implGetDescriptionFromShape( rxShape ) );
+                    OUString aDescription;
+                    xShapePropSet->getPropertyValue( B2UCONST( "Description" ) ) >>= aDescription;
+                    if( aDescription.getLength() )
+                    {
+                        SvXMLElementExport aExp2( *mpSVGExport, XML_NAMESPACE_NONE, "desc", TRUE, TRUE );
+                        xExtDocHandler->characters( aDescription );
                     }
 
                     if( rMtf.GetActionCount() )
@@ -868,9 +873,9 @@ sal_Bool SVGFilter::implCreateObjectsFromBackground( const Reference< XDrawPage
 
 // -----------------------------------------------------------------------------
 
-OUString SVGFilter::implGetDescriptionFromShape( const Reference< XShape >& rxShape )
+OUString SVGFilter::implGetClassFromShape( const Reference< XShape >& rxShape )
 {
-    OUString			aRet;
+    OUString            aRet;
     const OUString      aShapeType( rxShape->getShapeType() );
 
     if( aShapeType.lastIndexOf( B2UCONST( "drawing.GroupShape" ) ) != -1 )
@@ -886,7 +891,7 @@ OUString SVGFilter::implGetDescriptionFromShape( const Reference< XShape >& rxSh
     else if( aShapeType.lastIndexOf( B2UCONST( "presentation.DateTimeShape" ) ) != -1 )
         aRet = B2UCONST( "Date/Time" );
     else if( aShapeType.lastIndexOf( B2UCONST( "presentation.SlideNumberShape" ) ) != -1 )
-        aRet = B2UCONST( "Slide Number" );
+        aRet = B2UCONST( "Slide_Number" );
     else
         aRet = B2UCONST( "Drawing" );
         
diff --git a/filter/source/svg/svgfilter.hxx b/filter/source/svg/svgfilter.hxx
index ceda422..ba16cec 100644
--- a/filter/source/svg/svgfilter.hxx
+++ b/filter/source/svg/svgfilter.hxx
@@ -222,7 +222,7 @@ private:
     sal_Bool                            implCreateObjectsFromShape( const Reference< XShape >& rxShape );
     sal_Bool							implCreateObjectsFromBackground( const Reference< XDrawPage >& rxMasterPage );
     
-    ::rtl::OUString						implGetDescriptionFromShape( const Reference< XShape >& rxShape );
+    ::rtl::OUString						implGetClassFromShape( const Reference< XShape >& rxShape );
     ::rtl::OUString						implGetValidIDFromInterface( const Reference< XInterface >& rxIf );
     
                                         DECL_LINK( CalcFieldHdl, EditFieldInfo* );
-- 
1.7.1

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

Reply via email to