[librsvg: 2/3] gitlab#108 - Support font-size:larger and font-size:smaller



commit 2699eebe91e1e9458877c4a77aab69495107d206
Author: Federico Mena Quintero <federico gnome org>
Date:   Fri Feb 23 21:15:45 2018 -0600

    gitlab#108 - Support font-size:larger and font-size:smaller
    
    https://gitlab.gnome.org/GNOME/librsvg/issues/108

 librsvg/rsvg-css.c                                 |  33 +++++++++---
 rsvg_internals/src/length.rs                       |   5 +-
 .../reftests/bugs/108-font-size-relative-ref.png   | Bin 0 -> 2297 bytes
 .../reftests/bugs/108-font-size-relative.svg       |  60 +++++++++++++++++++++
 4 files changed, 89 insertions(+), 9 deletions(-)
---
diff --git a/librsvg/rsvg-css.c b/librsvg/rsvg-css.c
index 6ca0656b..467fb363 100644
--- a/librsvg/rsvg-css.c
+++ b/librsvg/rsvg-css.c
@@ -61,20 +61,39 @@ normalize_font_size (RsvgState * state, RsvgDrawingCtx * ctx)
     switch (state->font_size.unit) {
     case LENGTH_UNIT_PERCENT:
     case LENGTH_UNIT_FONT_EM:
-    case LENGTH_UNIT_FONT_EX:
+    case LENGTH_UNIT_FONT_EX: {
+        double parent_size;
+
         parent = rsvg_state_parent (state);
         if (parent) {
-            double parent_size;
             parent_size = normalize_font_size (parent, ctx);
-            return state->font_size.length * parent_size;
+        } else {
+            parent_size = 12.0;
         }
-        break;
+        return state->font_size.length * parent_size;
+    }
+
+    case LENGTH_UNIT_RELATIVE_LARGER:
+    case LENGTH_UNIT_RELATIVE_SMALLER: {
+        double parent_size;
+
+        parent = rsvg_state_parent (state);
+        if (parent) {
+            parent_size = normalize_font_size (parent, ctx);
+        } else {
+            parent_size = 12.0;
+        }
+
+        if (state->font_size.unit == LENGTH_UNIT_RELATIVE_LARGER) {
+            return parent_size * 1.2;
+        } else {
+            return parent_size / 1.2;
+        }
+    }
+
     default:
         return rsvg_length_normalize (&state->font_size, ctx);
-        break;
     }
-
-    return 12.;
 }
 
 double
diff --git a/rsvg_internals/src/length.rs b/rsvg_internals/src/length.rs
index 9b2c8e6e..c22f76f2 100644
--- a/rsvg_internals/src/length.rs
+++ b/rsvg_internals/src/length.rs
@@ -173,9 +173,10 @@ impl RsvgLength {
                 }
             },
 
-            // FIXME: these are pending: 
https://www.w3.org/TR/2008/REC-CSS2-20080411/fonts.html#propdef-font-size
             LengthUnit::RelativeLarger |
-            LengthUnit::RelativeSmaller => { 0.0 }
+            LengthUnit::RelativeSmaller => {
+                drawing_ctx::get_normalized_font_size (draw_ctx)
+            },
         }
     }
 
diff --git a/tests/fixtures/reftests/bugs/108-font-size-relative-ref.png 
b/tests/fixtures/reftests/bugs/108-font-size-relative-ref.png
new file mode 100644
index 00000000..93a74989
Binary files /dev/null and b/tests/fixtures/reftests/bugs/108-font-size-relative-ref.png differ
diff --git a/tests/fixtures/reftests/bugs/108-font-size-relative.svg 
b/tests/fixtures/reftests/bugs/108-font-size-relative.svg
new file mode 100644
index 00000000..532c7d2c
--- /dev/null
+++ b/tests/fixtures/reftests/bugs/108-font-size-relative.svg
@@ -0,0 +1,60 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<svg xmlns="http://www.w3.org/2000/svg"; width="100" height="100">
+
+
+<title>Voronoi. Simple poor</title>
+
+
+<style type="text/css">
+<![CDATA[
+
+.line {
+   stroke : black;
+   stroke-width : 1;
+   stroke-linecap : butt;
+}
+
+.circle {
+   stroke : none;
+   stroke-width : 0;
+   fill : black;
+}
+
+.text {
+   stroke-width : 0;
+   stroke : none;
+   fill : black;
+   font-size : 15px;
+   font-style : italic;
+}
+
+.rect {
+   stroke : none;
+   stroke-width : 0;
+}
+
+]]>
+</style>
+
+
+<rect class="rect" x="0" y="0" width="50" height="100" fill="LightBlue"/>
+<rect class="rect" x="50" y="0" width="50" height="100" fill="LightGreen"/><!-- AntiqueWhite LightCyan -->
+<line class="line" x1="25" y1="70" x2="75" y2="70"/>
+<line class="line" x1="50" y1="10" x2="50" y2="90"/>
+<path fill="none" stroke="black" d="M 50,65 l 5,0 l 0,5"/>
+<circle class="circle" cx="25" cy="70" r="2"/>
+<circle class="circle" cx="75" cy="70" r="2"/>
+<text class="text" x="14" y="70">p</text>
+<text class="text" x="80" y="70">q</text>
+<text class="text" x="5" y="20">H<tspan dy="0.2em" style="font-size : smaller">pq</tspan></text>
+<text class="text" x="75" y="20">H<tspan dy="0.2em" style="font-size : smaller">qp</tspan></text>
+
+
+<!--
+Creation timestamp (ISO 8601) 2015-02-06T05:39:42+00:00.
+
+2015-02-06
+   first release
+
+-->
+</svg>
\ No newline at end of file


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]