]> git.eshelyaron.com Git - emacs.git/commitdiff
Handle unknown units provided by the rsvg library (bug#75712)
authorPip Cet <pipcet@protonmail.com>
Tue, 21 Jan 2025 18:55:01 +0000 (18:55 +0000)
committerEshel Yaron <me@eshelyaron.com>
Thu, 23 Jan 2025 10:24:49 +0000 (11:24 +0100)
* 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.

(cherry picked from commit d7bdaa4170cd6115a6e3b4d872d8a428397fb2d8)

src/image.c

index b8405d811118bdc362c2952a03534b1b7c8b892f..7ab6289bb2a6efb0c73965c1403c3168a35c3878 100644 (file)
@@ -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