Commit ee26ed9b9 for imagemagick.org

commit ee26ed9b9cbc992021bb5d4344ec3953a4b40a91
Author: Jiří Meitner <jiri001meitner@users.noreply.github.com>
Date:   Fri Nov 20 18:51:01 2026 +0100

    Parse font family lists with family names that contain spaces (#9129)

    A font family list like "DejaVu Sans, sans-serif", as used by SVG and
    CSS, was split at white space, so "DejaVu" and "Sans" were looked up as
    separate families and the text was rendered with a fallback font. Only
    quoted family names were found.

    Parse the list as in CSS first: split it at commas, trim white space
    and remove single or double quotes around a family name. If none of the
    families is found, the list is split at white space as before, so lists
    like "Courier 'Source Han Sans JP'" still work.

    Co-authored-by: jiri001meitner <1045987+jiri001meitner@users.noreply.github.com>

diff --git a/MagickCore/annotate.c b/MagickCore/annotate.c
index e6d8862fe..7cb18d839 100644
--- a/MagickCore/annotate.c
+++ b/MagickCore/annotate.c
@@ -1033,6 +1033,65 @@ static MagickBooleanType RenderType(Image *image,const DrawInfo *draw_info,
       if (strpbrk(draw_info->family,",'\"") == (char *) NULL)
         type_info=GetTypeInfoByFamily(draw_info->family,draw_info->style,
           draw_info->stretch,draw_info->weight,exception);
+      else
+        {
+          char
+            family[MagickPathExtent];
+
+          const char
+            *p,
+            *q;
+
+          const TypeInfo
+            *list_info;
+
+          size_t
+            length;
+
+          /*
+            Parse a CSS font family list: the families are separated by
+            commas, may be quoted and their names may contain spaces.
+          */
+          p=draw_info->family;
+          while (*p != '\0')
+          {
+            while ((isspace((int) ((unsigned char) *p)) != 0) || (*p == ','))
+              p++;
+            if (*p == '\0')
+              break;
+            if ((*p == '\'') || (*p == '"'))
+              {
+                q=strchr(p+1,*p);
+                if (q == (const char *) NULL)
+                  q=p+strlen(p);
+                length=(size_t) (q-p-1);
+                (void) CopyMagickString(family,p+1,MagickMin(length+1,
+                  MagickPathExtent));
+                p=(*q == '\0') ? q : q+1;
+              }
+            else
+              {
+                q=strchr(p,',');
+                if (q == (const char *) NULL)
+                  q=p+strlen(p);
+                length=(size_t) (q-p);
+                while ((length > 0) &&
+                       (isspace((int) ((unsigned char) p[length-1])) != 0))
+                  length--;
+                (void) CopyMagickString(family,p,MagickMin(length+1,
+                  MagickPathExtent));
+                p=q;
+              }
+            list_info=GetTypeInfoByFamily(family,draw_info->style,
+              draw_info->stretch,draw_info->weight,exception);
+            if ((list_info != (const TypeInfo *) NULL) &&
+                (LocaleCompare(family,list_info->family) == 0))
+              {
+                type_info=list_info;
+                break;
+              }
+          }
+        }
       if (type_info == (const TypeInfo *) NULL)
         {
           char
diff --git a/tests/cli-svg.tap b/tests/cli-svg.tap
index 173f4f24a..4a3ae66cf 100755
--- a/tests/cli-svg.tap
+++ b/tests/cli-svg.tap
@@ -18,7 +18,7 @@
 #
 . ./common.shi
 . ${srcdir}/tests/common.shi
-echo "1..4"
+echo "1..5"

 # gradientTransform should not cause a double-free / SIGABRT (#8582)
 ${MAGICK} ${SRCDIR}/input_svg_gradient_transform.svg null: && echo "ok" || echo "not ok"
@@ -50,4 +50,17 @@ spaced=`${MAGICK} -size 24x24 xc:white -fill none -stroke black \
   -draw "path 'M6 12 h9 a4 4 0 0 1 0 8 H7 a1 1 0 0 1 -1 -1 V5 a1 1 0 0 1 1 -1 h7 a4 4 0 0 1 0 8'" \
   -format '%#' info:- 2>/dev/null`
 [ "X$compact" != "X" ] && [ "X$compact" = "X$spaced" ] && echo "ok" || echo "not ok"
+
+# Font families are separated by commas and their names may contain spaces.
+family=`${MAGICK} -list font | sed -n 's/^ *family: \([A-Za-z0-9]* [A-Za-z0-9 ]*\)$/\1/p' | head -n 1`
+case "$msvg_mode:$family" in
+  *r*:?*)
+    single=`printf '<svg xmlns="http://www.w3.org/2000/svg" width="120" height="40"><text x="5" y="30" font-family="%s" font-size="24">ACME</text></svg>' "$family" |
+      ${MAGICK} MSVG:- -format '%#' info:- 2>/dev/null`
+    list=`printf '<svg xmlns="http://www.w3.org/2000/svg" width="120" height="40"><text x="5" y="30" font-family="%s, serif" font-size="24">ACME</text></svg>' "$family" |
+      ${MAGICK} MSVG:- -format '%#' info:- 2>/dev/null`
+    [ "X$single" != "X" ] && [ "X$single" = "X$list" ] && echo "ok" || echo "not ok"
+    ;;
+  *) echo "ok # SKIP MSVG coder or a font family with a space unavailable" ;;
+esac
 :