[Libreoffice-commits] .: 4 commits - filter/source

Thorsten Behrens thorsten at kemper.freedesktop.org
Fri Jan 7 14:49:03 PST 2011


 filter/source/svg/svgfontexport.cxx |   27 +++------
 filter/source/svg/svgwriter.cxx     |  101 +++++++++++++++++++++++++++++++++---
 filter/source/svg/svgwriter.hxx     |    1 
 3 files changed, 105 insertions(+), 24 deletions(-)

New commits:
commit 24e68935fb621eb6d30e30407f7b62deaede28a3
Author: Takeshi Kurosawa <taken.spc at gmail.com>
Date:   Tue Jan 4 13:31:47 2011 +0900

    Export text color
    
    The color selection logic is what flash export filter does.

diff --git a/filter/source/svg/svgwriter.cxx b/filter/source/svg/svgwriter.cxx
index 608f6b5..7765ea5 100644
--- a/filter/source/svg/svgwriter.cxx
+++ b/filter/source/svg/svgwriter.cxx
@@ -809,6 +809,97 @@ void SVGActionWriter::ImplWriteText( const Point& rPos, const String& rText,
                                      const sal_Int32* pDXArray, long nWidth,
                                      const NMSP_RTL::OUString* pStyle )
 {
+    const FontMetric aMetric( mpVDev->GetFontMetric() );
+
+    bool bTextSpecial = aMetric.IsShadow() || aMetric.IsOutline() || (aMetric.GetRelief() != RELIEF_NONE);
+
+    if( !bTextSpecial )
+    {
+        ImplWriteText( rPos, rText, pDXArray, nWidth, pStyle, mpVDev->GetTextColor() );
+    }
+    else
+    {
+        if( aMetric.GetRelief() != RELIEF_NONE )
+        {
+            Color aReliefColor( COL_LIGHTGRAY );
+            Color aTextColor( mpVDev->GetTextColor() );
+
+            if ( aTextColor.GetColor() == COL_BLACK )
+                aTextColor = Color( COL_WHITE );
+
+            if ( aTextColor.GetColor() == COL_WHITE )
+                aReliefColor = Color( COL_BLACK );
+
+
+            Point aPos( rPos );
+            Point aOffset( 6, 6 );
+
+            if ( aMetric.GetRelief() == RELIEF_ENGRAVED )
+            {
+                aPos -= aOffset;
+            }
+            else
+            {
+                aPos += aOffset;
+            }
+
+            ImplWriteText( aPos, rText, pDXArray, nWidth, pStyle, aReliefColor );
+            ImplWriteText( rPos, rText, pDXArray, nWidth, pStyle, aTextColor );
+        }
+        else
+        {
+            if( aMetric.IsShadow() )
+            {
+                long nOff = 1 + ((aMetric.GetLineHeight()-24)/24);
+                if ( aMetric.IsOutline() )
+                    nOff += 6;
+
+                Color aTextColor( mpVDev->GetTextColor() );
+                Color aShadowColor = Color( COL_BLACK );
+
+                if ( (aTextColor.GetColor() == COL_BLACK) || (aTextColor.GetLuminance() < 8) )
+                    aShadowColor = Color( COL_LIGHTGRAY );
+
+                Point aPos( rPos );
+                aPos += Point( nOff, nOff );
+                ImplWriteText( aPos, rText, pDXArray, nWidth, pStyle, aShadowColor );
+
+                if( !aMetric.IsOutline() )
+                {
+                    ImplWriteText( rPos, rText, pDXArray, nWidth, pStyle, aTextColor );
+                }
+            }
+
+            if( aMetric.IsOutline() )
+            {
+                Point aPos = rPos + Point( -6, -6 );
+                ImplWriteText( aPos, rText, pDXArray, nWidth, pStyle, mpVDev->GetTextColor() );
+                aPos = rPos + Point( +6, +6);
+                ImplWriteText( aPos, rText, pDXArray, nWidth, pStyle, mpVDev->GetTextColor() );
+                aPos = rPos + Point( -6, +0);
+                ImplWriteText( aPos, rText, pDXArray, nWidth, pStyle, mpVDev->GetTextColor() );
+                aPos = rPos + Point( -6, +6);
+                ImplWriteText( aPos, rText, pDXArray, nWidth, pStyle, mpVDev->GetTextColor() );
+                aPos = rPos + Point( +0, +6);
+                ImplWriteText( aPos, rText, pDXArray, nWidth, pStyle, mpVDev->GetTextColor() );
+                aPos = rPos + Point( +0, -6);
+                ImplWriteText( aPos, rText, pDXArray, nWidth, pStyle, mpVDev->GetTextColor() );
+                aPos = rPos + Point( +6, -1);
+                ImplWriteText( aPos, rText, pDXArray, nWidth, pStyle, mpVDev->GetTextColor() );
+                aPos = rPos + Point( +6, +0);
+                ImplWriteText( aPos, rText, pDXArray, nWidth, pStyle, mpVDev->GetTextColor() );
+
+                ImplWriteText( rPos, rText, pDXArray, nWidth, pStyle, Color( COL_WHITE ) );
+            }
+        }
+    }
+}
+
+void SVGActionWriter::ImplWriteText( const Point& rPos, const String& rText,
+                                     const sal_Int32* pDXArray, long nWidth,
+                                     const NMSP_RTL::OUString* pStyle,
+                                     Color aTextColor )
+{
     long nLen = rText.Len(), i;
 
     if( nLen )
@@ -864,6 +955,8 @@ void SVGActionWriter::ImplWriteText( const Point& rPos, const String& rText,
             break;
         }
 
+        mpContext->SetPaintAttr( COL_TRANSPARENT, aTextColor );
+
         // get mapped text position
         const Point aPt( ImplMap( aBaseLinePos ) );
 
@@ -1528,7 +1621,6 @@ void SVGActionWriter::ImplWriteActions( const GDIMetaFile& rMtf,
 
                     aFont.SetHeight( ImplMap( Size( 0, aFont.GetHeight() ) ).Height() );
                     mpContext->SetFontAttr( aFont );
-                    mpContext->SetPaintAttr( COL_TRANSPARENT, aFont.GetColor() );
                     ImplWriteText( pA->GetPoint(), String( pA->GetText(), pA->GetIndex(), pA->GetLen() ), NULL, 0, pStyle );
                 }
             }			
@@ -1543,7 +1635,6 @@ void SVGActionWriter::ImplWriteActions( const GDIMetaFile& rMtf,
 
                     aFont.SetHeight( ImplMap( Size( 0, aFont.GetHeight() ) ).Height() );
                     mpContext->SetFontAttr( aFont );
-                    mpContext->SetPaintAttr( COL_TRANSPARENT, aFont.GetColor() );
                     ImplWriteText( pA->GetRect().TopLeft(), pA->GetText(), NULL, 0, pStyle );
                 }
             }
@@ -1559,7 +1650,6 @@ void SVGActionWriter::ImplWriteActions( const GDIMetaFile& rMtf,
 
                     aFont.SetHeight( ImplMap( Size( 0, aFont.GetHeight() ) ).Height() );
                     mpContext->SetFontAttr( aFont );
-                    mpContext->SetPaintAttr( COL_TRANSPARENT, aFont.GetColor() );
                     ImplWriteText( pA->GetPoint(), String( pA->GetText(), pA->GetIndex(), pA->GetLen() ), pA->GetDXArray(), 0, pStyle );
                 }
             }
@@ -1574,7 +1664,6 @@ void SVGActionWriter::ImplWriteActions( const GDIMetaFile& rMtf,
 
                     aFont.SetHeight( ImplMap( Size( 0, aFont.GetHeight() ) ).Height() );
                     mpContext->SetFontAttr( aFont );
-                    mpContext->SetPaintAttr( COL_TRANSPARENT, aFont.GetColor() );
                     ImplWriteText( pA->GetPoint(), String( pA->GetText(), pA->GetIndex(), pA->GetLen() ), NULL, pA->GetWidth(), pStyle );
                 }
             }
diff --git a/filter/source/svg/svgwriter.hxx b/filter/source/svg/svgwriter.hxx
index 1bd7867..e1467c3 100644
--- a/filter/source/svg/svgwriter.hxx
+++ b/filter/source/svg/svgwriter.hxx
@@ -187,6 +187,7 @@ private:
     void					ImplWritePolyPolygon( const PolyPolygon& rPolyPoly, sal_Bool bLineOnly, const ::rtl::OUString* pStyle = NULL );
     void					ImplWriteGradientEx( const PolyPolygon& rPolyPoly, const Gradient& rGradient, const ::rtl::OUString* pStyle, sal_uInt32 nWriteFlags );
     void					ImplWriteText( const Point& rPos, const String& rText, const sal_Int32* pDXArray, long nWidth, const ::rtl::OUString* pStyle = NULL );
+    void                ImplWriteText( const Point& rPos, const String& rText, const sal_Int32* pDXArray, long nWidth, const ::rtl::OUString* pStyle, Color aTextColor );
     void					ImplWriteBmp( const BitmapEx& rBmpEx, const Point& rPt, const Size& rSz, const Point& rSrcPt, const Size& rSrcSz, const ::rtl::OUString* pStyle = NULL );
 
     void					ImplCheckFontAttributes();
commit 4bdef1a10b2d2c76519961e1b85e16954f8b66ea
Author: Takeshi Kurosawa <taken.spc at gmail.com>
Date:   Tue Jan 4 13:25:12 2011 +0900

    Remove redundant 'g' element
    
    pTransform is completely redundant.

diff --git a/filter/source/svg/svgwriter.cxx b/filter/source/svg/svgwriter.cxx
index af305ac..608f6b5 100644
--- a/filter/source/svg/svgwriter.cxx
+++ b/filter/source/svg/svgwriter.cxx
@@ -848,7 +848,6 @@ void SVGActionWriter::ImplWriteText( const Point& rPos, const String& rText,
         const Font&			rFont = mpVDev->GetFont();
         const FontMetric	aMetric( mpVDev->GetFontMetric() );
         Point				aBaseLinePos( rPos );
-        SvXMLElementExport*	pTransform = NULL;
 
         // always adjust text position to match baseline alignment
         switch( rFont.GetAlign() )
@@ -904,7 +903,6 @@ void SVGActionWriter::ImplWriteText( const Point& rPos, const String& rText,
             aTransform += ')';
 
             mrExport.AddAttribute( XML_NAMESPACE_NONE, aXMLAttrTransform, aTransform );
-            pTransform = new SvXMLElementExport( mrExport, XML_NAMESPACE_NONE, aXMLElemG, TRUE, TRUE );
         }
 
         // add additional style if requested
@@ -989,7 +987,6 @@ void SVGActionWriter::ImplWriteText( const Point& rPos, const String& rText,
 #endif // _SVG_USE_NATIVE_TEXTDECORATION
 
         delete[] pOwnArray;
-        delete pTransform;
     }
 }
 
commit 512dffc1ca71a71361a66d3a013297f16401413d
Author: Takeshi Kurosawa <taken.spc at gmail.com>
Date:   Tue Jan 4 13:22:26 2011 +0900

    Use simple syntax for glyph definition
    
    Opera and Chrome don't support complex syntax for SVG fonts glyph definition (child elements of glyph element).

diff --git a/filter/source/svg/svgfontexport.cxx b/filter/source/svg/svgfontexport.cxx
index 605f878..0c00a06 100644
--- a/filter/source/svg/svgfontexport.cxx
+++ b/filter/source/svg/svgfontexport.cxx
@@ -168,15 +168,11 @@ void SVGFontExport::implEmbedFont( const ::rtl::OUString& rFontName, const ::std
 
             mrExport.AddAttribute( XML_NAMESPACE_NONE, "horiz-adv-x", SVGActionWriter::GetValueString( aSize.Width() ) );
 
+            mrExport.AddAttribute( XML_NAMESPACE_NONE, "style", B2UCONST( "fill:none;stroke:black;stroke-width:33" ) );
+            mrExport.AddAttribute( XML_NAMESPACE_NONE, "d", SVGActionWriter::GetPathString( aMissingGlyphPolyPoly, sal_False ) );
+
             {
                 SvXMLElementExport aExp3( mrExport, XML_NAMESPACE_NONE, "missing-glyph", TRUE, TRUE );
-
-                mrExport.AddAttribute( XML_NAMESPACE_NONE, "style", B2UCONST( "fill:none;stroke:black;stroke-width:33" ) );
-                mrExport.AddAttribute( XML_NAMESPACE_NONE, "d", SVGActionWriter::GetPathString( aMissingGlyphPolyPoly, sal_False ) );
-
-                {
-                    SvXMLElementExport aExp4( mrExport, XML_NAMESPACE_NONE, "path", TRUE, TRUE );
-                }
             }
             
             while( aIter != rGlyphs.end() )
@@ -213,18 +209,15 @@ void SVGFontExport::implEmbedGlyph( OutputDevice& rOut, const ::rtl::OUString& r
         
         mrExport.AddAttribute( XML_NAMESPACE_NONE, "horiz-adv-x", SVGActionWriter::GetValueString( aBoundRect.GetWidth() ) );
 
+        const ::rtl::OUString aPathString( SVGActionWriter::GetPathString( aPolyPoly, sal_False ) );
+
+        if( aPathString.getLength() )
+        {
+            mrExport.AddAttribute( XML_NAMESPACE_NONE, "d", aPathString );
+        }
+
         {
             SvXMLElementExport    aExp( mrExport, XML_NAMESPACE_NONE, "glyph", TRUE, TRUE );
-            const ::rtl::OUString aPathString( SVGActionWriter::GetPathString( aPolyPoly, sal_False ) );
-                  
-            if( aPathString.getLength() )
-            {
-                mrExport.AddAttribute( XML_NAMESPACE_NONE, "d", aPathString );
-    
-                {
-                    SvXMLElementExport aElem( mrExport, XML_NAMESPACE_NONE, B2UCONST( "path" ), TRUE, TRUE );
-                }
-            }
         }
     }
 }
commit d29f9fb0829adb7f63b65443e0f6f80e39764b32
Author: Takeshi Kurosawa <taken.spc at gmail.com>
Date:   Tue Jan 4 13:18:55 2011 +0900

    Add 'px' unit to 'font-size'
    
    Firefox and Opera don't accept unitless font-size values.

diff --git a/filter/source/svg/svgwriter.cxx b/filter/source/svg/svgwriter.cxx
index 8b18650..af305ac 100644
--- a/filter/source/svg/svgwriter.cxx
+++ b/filter/source/svg/svgwriter.cxx
@@ -265,6 +265,7 @@ NMSP_RTL::OUString SVGAttributeWriter::GetFontStyle( const Font& rFont )
     aStyle += B2UCONST( ";" );
     aStyle += B2UCONST( "font-size:" );
     aStyle += SVGActionWriter::GetValueString( rFont.GetHeight() );
+    aStyle += B2UCONST( "px" );
     
     // font style
 /*


More information about the Libreoffice-commits mailing list