[Libreoffice-commits] core.git: filter/source

Xisco Fauli anistenis at gmail.com
Fri Jan 8 01:35:42 PST 2016


 filter/source/svg/gfxtypes.hxx  |    6 ----
 filter/source/svg/svgreader.cxx |    1 
 filter/source/svg/units.cxx     |   50 +++++++++++++++++++++++++++++++++++-----
 filter/source/svg/units.hxx     |    5 ++--
 4 files changed, 49 insertions(+), 13 deletions(-)

New commits:
commit 0cae9c32ce9884a9809e220ba80b7c4cb4059565
Author: Xisco Fauli <anistenis at gmail.com>
Date:   Thu Dec 3 17:16:55 2015 +0100

    tdf#96046 SVG: Change logic to parse doubles correctly and..
    
    add support for font-size keywords.
    
    My previous commit fa17cfd7e006c73f1360a5a974f38d9875f347c5
    was wrong as doubles like '-10.0' or '5e1' were ignored.
    Change logic to parse the whole string but the units ( 'cm',
    'mm', etc, etc)
    Then, value.toDouble() will try to convert it to double, and
    if it's not possible it will return 0.0.
    
    Besides, add support for font-size keywords described here:
    http://www.w3.org/TR/REC-CSS2/fonts.html#font-size-props
    
    Working on a parse test for this section.
    
    Change-Id: I2b9c89225fcf63f1a0564abf7187097373cbc9a1
    Reviewed-on: https://gerrit.libreoffice.org/20379
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Armin Le Grand <Armin.Le.Grand at cib.de>

diff --git a/filter/source/svg/gfxtypes.hxx b/filter/source/svg/gfxtypes.hxx
index 3d502da..e8041f5 100644
--- a/filter/source/svg/gfxtypes.hxx
+++ b/filter/source/svg/gfxtypes.hxx
@@ -193,13 +193,9 @@ struct State
 
     bool                        mbIsText;
     OUString                    maFontFamily;
-    /** Absolute: xx-small=6.94 | x-small=8.33 | small=10 | medium=12 | large=14.4 | x-large=17.28 | xx-large=20.736
 
-        Relative(to parent): larger (enlarge by 1.2)
-                             smaller (shrink by 1.2)
-
-     */
     double                      mnFontSize;
+    double                      mnParentFontSize;
     OUString                    maFontStyle;
     OUString                    maFontVariant;
     double                      mnFontWeight;
diff --git a/filter/source/svg/svgreader.cxx b/filter/source/svg/svgreader.cxx
index 5ae3281..7e8a769 100644
--- a/filter/source/svg/svgreader.cxx
+++ b/filter/source/svg/svgreader.cxx
@@ -1142,6 +1142,7 @@ struct AnnotatingVisitor
                 maCurrState.maFontFamily=sValue;
                 break;
             case XML_FONT_SIZE:
+                maCurrState.mnParentFontSize=maParentStates.back().mnFontSize;
                 maCurrState.mnFontSize=convLength(sValue,maCurrState,'v');
                 break;
             case XML_FONT_STYLE:
diff --git a/filter/source/svg/units.cxx b/filter/source/svg/units.cxx
index 34360ac..dd1a31e 100644
--- a/filter/source/svg/units.cxx
+++ b/filter/source/svg/units.cxx
@@ -17,12 +17,12 @@
 namespace svgi
 {
 
-double convLength( double value, SvgUnit unit, const State& rState, char dir )
+double convLength( const OUString& value, SvgUnit unit, const State& rState, char dir )
 {
     // convert svg unit to internal coordinates ("pixel"). Since the
     // OOo drawing layer is still largely integer-based, the initial
     // viewport transformation includes a certain scale factor
-    double fRet(value);
+    double fRet(value.toDouble());
     switch ( unit )
     {
         case SVG_LENGTH_UNIT_CM: fRet *= F_SVG_PIXEL_PER_INCH/2.54; break;
@@ -36,14 +36,38 @@ double convLength( double value, SvgUnit unit, const State& rState, char dir )
         case SVG_LENGTH_UNIT_PX:
             // no unit defaults to PX in svg, assume display to have 90DPI
             break;
+        case SVG_LENGTH_FONT_SIZE:
+        {
+            //In CSS2, the suggested scaling factor between adjacent indexes is 1.2
+            if ( value == "xx-small" )
+                fRet = rState.mnFontSize / 1.728;
+            else if ( value == "x-small" )
+                fRet = rState.mnFontSize / 1.44;
+            else if ( value == "small" )
+                fRet = rState.mnFontSize / 1.2;
+            else if ( value == "smaller" )
+                fRet = rState.mnParentFontSize / 1.2;
+            else if ( value == "initial" || value == "medium" )
+                fRet = rState.mnFontSize;
+            else if ( value == "larger" )
+                fRet = rState.mnParentFontSize * 1.2;
+            else if ( value == "large" )
+                fRet = rState.mnFontSize * 1.2;
+            else if ( value == "x-large" )
+                fRet = rState.mnFontSize * 1.44;
+            else if ( value == "xx-large" )
+                fRet = rState.mnFontSize * 1.728;
+
+            break;
+        }
         case SVG_LENGTH_UNIT_PERCENTAGE:
         {
             double fBoxLen;
             if (rState.maViewBox.isEmpty())
             {
                 basegfx::B2DRange aDefaultBox(0, 0,
-                  convLength(210, SVG_LENGTH_UNIT_MM, rState, 'h'),
-                  convLength(297, SVG_LENGTH_UNIT_MM, rState, 'v'));
+                  convLength("210", SVG_LENGTH_UNIT_MM, rState, 'h'),
+                  convLength("297", SVG_LENGTH_UNIT_MM, rState, 'v'));
                 fBoxLen = (dir=='h' ? aDefaultBox.getWidth() :
                           (dir=='v' ? aDefaultBox.getHeight() :
                            aDefaultBox.getRange().getLength()));
@@ -77,7 +101,21 @@ double convLength( const OUString& sValue, const State& rState, char dir )
     const bool bRes = parse(aUTF8.getStr(),
         //  Begin grammar
         (
-            (*digit_p >> *((str_p(".") | str_p(",")) >> *digit_p))[assign_a(sVal)]
+            //parse font-size keywords (ie: xx-large, medium )
+            ( +(alpha_p) >> !(str_p("-") >> +alpha_p) )[assign_a(sVal)]
+                >> str_p("")[assign_a(eUnit,SVG_LENGTH_FONT_SIZE)] |
+            //take the first part and ignore the units
+            ( +(anychar_p -
+             (str_p("cm") |
+             str_p("em") |
+             str_p("ex") |
+             str_p("in") |
+             str_p("mm") |
+             str_p("pc") |
+             str_p("pt") |
+             str_p("px") |
+             str_p("%")))
+            )[assign_a(sVal)]
             >> (  str_p("cm") [assign_a(eUnit,SVG_LENGTH_UNIT_CM)]
                 | str_p("em") [assign_a(eUnit,SVG_LENGTH_UNIT_EM)]
                 | str_p("ex") [assign_a(eUnit,SVG_LENGTH_UNIT_EX)]
@@ -98,7 +136,7 @@ double convLength( const OUString& sValue, const State& rState, char dir )
 
     OUString oVal = OUString::createFromAscii(sVal.c_str()).replaceAll(",",".");
 
-    return convLength(oVal.toDouble(),eUnit,rState,dir);
+    return convLength(oVal,eUnit,rState,dir);
 }
 
 } // namespace svgi
diff --git a/filter/source/svg/units.hxx b/filter/source/svg/units.hxx
index d348104..06b7217 100644
--- a/filter/source/svg/units.hxx
+++ b/filter/source/svg/units.hxx
@@ -30,7 +30,8 @@ namespace svgi
         SVG_LENGTH_UNIT_PT,
         SVG_LENGTH_UNIT_PX,
         SVG_LENGTH_UNIT_PERCENTAGE,
-        SVG_LENGTH_UNIT_USER
+        SVG_LENGTH_UNIT_USER,
+        SVG_LENGTH_FONT_SIZE
     };
 
     /** return svg_length_t in 100th's of mm
@@ -39,7 +40,7 @@ namespace svgi
          @param rState current state (needed for viewport dimensions etc.)
          @param dir direction - either 'h' or 'v' for horizonal or vertical, resp.
      */
-    double convLength( double fVal, SvgUnit unit, const State& rState, char dir );
+    double convLength( const OUString& sVal, SvgUnit unit, const State& rState, char dir );
 
     /** return svg_length_t in 100th's of mm
          @param sValue value to convert


More information about the Libreoffice-commits mailing list