aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPip Cet2025-01-21 18:55:01 +0000
committerPip Cet2025-01-21 19:04:11 +0000
commitd7bdaa4170cd6115a6e3b4d872d8a428397fb2d8 (patch)
treeddc1e27fe5cec4b2ea55d2e38c1a2d0406e391de /src
parent0fd5b2d146e3578820446aa69b30d93958d9b1a5 (diff)
downloademacs-d7bdaa4170cd6115a6e3b4d872d8a428397fb2d8.tar.gz
emacs-d7bdaa4170cd6115a6e3b4d872d8a428397fb2d8.zip
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.
Diffstat (limited to 'src')
-rw-r--r--src/image.c52
1 files 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)
11965 { 11965 {
11966 case RSVG_UNIT_PX: 11966 case RSVG_UNIT_PX:
11967 /* Already a pixel value. */ 11967 /* Already a pixel value. */
11968 break; 11968 return value;
11969 case RSVG_UNIT_CM: 11969 case RSVG_UNIT_CM:
11970 /* 2.54 cm in an inch. */ 11970 /* 2.54 cm in an inch. */
11971 value = dpi * value / 2.54; 11971 return dpi * value / 2.54;
11972 break;
11973 case RSVG_UNIT_MM: 11972 case RSVG_UNIT_MM:
11974 /* 25.4 mm in an inch. */ 11973 /* 25.4 mm in an inch. */
11975 value = dpi * value / 25.4; 11974 return dpi * value / 25.4;
11976 break;
11977 case RSVG_UNIT_PT: 11975 case RSVG_UNIT_PT:
11978 /* 72 points in an inch. */ 11976 /* 72 points in an inch. */
11979 value = dpi * value / 72; 11977 return dpi * value / 72;
11980 break;
11981 case RSVG_UNIT_PC: 11978 case RSVG_UNIT_PC:
11982 /* 6 picas in an inch. */ 11979 /* 6 picas in an inch. */
11983 value = dpi * value / 6; 11980 return dpi * value / 6;
11984 break;
11985 case RSVG_UNIT_IN: 11981 case RSVG_UNIT_IN:
11986 value *= dpi; 11982 return value * dpi;
11987 break;
11988 case RSVG_UNIT_EM: 11983 case RSVG_UNIT_EM:
11989 value *= font_size; 11984 return value * font_size;
11990 break;
11991 case RSVG_UNIT_EX: 11985 case RSVG_UNIT_EX:
11992 /* librsvg uses an ex height of half the em height, so we match 11986 /* librsvg uses an ex height of half the em height, so we match
11993 that here. */ 11987 that here. */
11994 value = value * font_size / 2.0; 11988 return value * font_size / 2.0;
11995 break;
11996 case RSVG_UNIT_PERCENT: 11989 case RSVG_UNIT_PERCENT:
11997 /* Percent is a ratio of the containing "viewport". We don't 11990 /* Percent is a ratio of the containing "viewport". We don't
11998 have a viewport, as such, as we try to draw the image to it's 11991 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)
12006 spec, this will work out correctly as librsvg will still 11999 spec, this will work out correctly as librsvg will still
12007 honor the percentage sizes in its final rendering no matter 12000 honor the percentage sizes in its final rendering no matter
12008 what size we make the image. */ 12001 what size we make the image. */
12009 value = 0; 12002 return 0;
12010 break; 12003#if LIBRSVG_CHECK_VERSION (2, 58, 0)
12011 default: 12004 case RSVG_UNIT_CH:
12012 /* We should never reach this. */ 12005 /* FIXME: With CSS 3, "the ch unit falls back to 0.5em in the
12013 value = 0; 12006 general case, and to 1em when it would be typeset upright".
12014 } 12007 However, I could not find a way to easily get the relevant CSS
12015 12008 attributes using librsvg. Thus, we simply wrongly assume the
12016 return value; 12009 general case is always true here. See Bug#75712. */
12010 return value * font_size / 2.0;
12011#endif
12012 }
12013
12014 /* The rsvg header files say that more values may be added to this
12015 enum, but there doesn't appear to be a way to get a string
12016 representation of the new enum value. The unfortunate
12017 consequence is that the only thing we can do is to report the
12018 numeric value. */
12019 image_error ("Unknown RSVG unit, code: %s", make_fixnum ((int) length.unit));
12020 /* Return 0; this special value indicates that another method of
12021 obtaining the image size must be used. */
12022 return 0;
12017} 12023}
12018#endif 12024#endif
12019 12025