emacs-diffs
[Top][All Lists]
Advanced

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

master d7bdaa4170c: Handle unknown units provided by the rsvg library (b


From: Pip Cet
Subject: master d7bdaa4170c: Handle unknown units provided by the rsvg library (bug#75712)
Date: Tue, 21 Jan 2025 14:05:29 -0500 (EST)

branch: master
commit d7bdaa4170cd6115a6e3b4d872d8a428397fb2d8
Author: Pip Cet <pipcet@protonmail.com>
Commit: Pip Cet <pipcet@protonmail.com>

    Handle unknown units provided by the rsvg library (bug#75712)
    
    * src/image.c (svg_css_length_to_pixels): Restructure so GCC warns
    about new enum members.  Add case for RSVG_UNIT_CH.  Warn about
    unknown units discovered at runtime.
---
 src/image.c | 52 +++++++++++++++++++++++++++++-----------------------
 1 file changed, 29 insertions(+), 23 deletions(-)

diff --git a/src/image.c b/src/image.c
index b8405d81111..7ab6289bb2a 100644
--- a/src/image.c
+++ b/src/image.c
@@ -11965,34 +11965,27 @@ svg_css_length_to_pixels (RsvgLength length, double 
dpi, int font_size)
     {
     case RSVG_UNIT_PX:
       /* Already a pixel value.  */
-      break;
+      return value;
     case RSVG_UNIT_CM:
       /* 2.54 cm in an inch.  */
-      value = dpi * value / 2.54;
-      break;
+      return dpi * value / 2.54;
     case RSVG_UNIT_MM:
       /* 25.4 mm in an inch.  */
-      value = dpi * value / 25.4;
-      break;
+      return dpi * value / 25.4;
     case RSVG_UNIT_PT:
       /* 72 points in an inch.  */
-      value = dpi * value / 72;
-      break;
+      return dpi * value / 72;
     case RSVG_UNIT_PC:
       /* 6 picas in an inch.  */
-      value = dpi * value / 6;
-      break;
+      return dpi * value / 6;
     case RSVG_UNIT_IN:
-      value *= dpi;
-      break;
+      return value * dpi;
     case RSVG_UNIT_EM:
-      value *= font_size;
-      break;
+      return value * font_size;
     case RSVG_UNIT_EX:
       /* librsvg uses an ex height of half the em height, so we match
         that here.  */
-      value = value * font_size / 2.0;
-      break;
+      return value * font_size / 2.0;
     case RSVG_UNIT_PERCENT:
       /* Percent is a ratio of the containing "viewport".  We don't
         have a viewport, as such, as we try to draw the image to it's
@@ -12006,14 +11999,27 @@ svg_css_length_to_pixels (RsvgLength length, double 
dpi, int font_size)
         spec, this will work out correctly as librsvg will still
         honor the percentage sizes in its final rendering no matter
         what size we make the image.  */
-      value = 0;
-      break;
-    default:
-      /* We should never reach this.  */
-      value = 0;
-    }
-
-  return value;
+      return 0;
+#if LIBRSVG_CHECK_VERSION (2, 58, 0)
+    case RSVG_UNIT_CH:
+      /* FIXME: With CSS 3, "the ch unit falls back to 0.5em in the
+        general case, and to 1em when it would be typeset upright".
+        However, I could not find a way to easily get the relevant CSS
+        attributes using librsvg.  Thus, we simply wrongly assume the
+        general case is always true here.  See Bug#75712.  */
+      return value * font_size / 2.0;
+#endif
+    }
+
+  /* The rsvg header files say that more values may be added to this
+     enum, but there doesn't appear to be a way to get a string
+     representation of the new enum value.  The unfortunate
+     consequence is that the only thing we can do is to report the
+     numeric value.  */
+  image_error ("Unknown RSVG unit, code: %s", make_fixnum ((int) length.unit));
+  /* Return 0; this special value indicates that another method of
+     obtaining the image size must be used.  */
+  return 0;
 }
 #endif
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]