+/* Concatenate font list FONTS1 and FONTS2. FONTS1 and FONTS2
+ contains NFONTS1 fonts and NFONTS2 fonts respectively. Return a
+ pointer to a newly allocated font list. FONTS1 and FONTS2 are
+ freed. */
+
+static struct font_name *
+concat_font_list (fonts1, nfonts1, fonts2, nfonts2)
+ struct font_name *fonts1, *fonts2;
+ int nfonts1, nfonts2;
+{
+ int new_nfonts = nfonts1 + nfonts2;
+ struct font_name *new_fonts;
+
+ new_fonts = (struct font_name *) xmalloc (sizeof *new_fonts * new_nfonts);
+ bcopy (fonts1, new_fonts, sizeof *new_fonts * nfonts1);
+ bcopy (fonts2, new_fonts + nfonts1, sizeof *new_fonts * nfonts2);
+ xfree (fonts1);
+ xfree (fonts2);
+ return new_fonts;
+}
+
+
+/* Get a sorted list of fonts of family FAMILY on frame F.
+
+ If PATTERN is non-nil list fonts matching that pattern.
+
+ If REGISTRY is non-nil, return fonts with that registry and the
+ alternative registries from Vface_alternative_font_registry_alist.
+
+ If REGISTRY is nil return fonts of any registry.
+
+ Set *FONTS to a vector of font_name structures allocated from the
+ heap containing the fonts found. Value is the number of fonts
+ found. */
+
+static int
+font_list (f, pattern, family, registry, fonts)
+ struct frame *f;
+ Lisp_Object pattern, family, registry;
+ struct font_name **fonts;
+{
+ int nfonts = font_list_1 (f, pattern, family, registry, fonts);
+
+ if (!NILP (registry)
+ && CONSP (Vface_alternative_font_registry_alist))
+ {
+ Lisp_Object alter;
+
+ alter = Fassoc (registry, Vface_alternative_font_registry_alist);
+ if (CONSP (alter))
+ {
+ int reg_prio, i;
+
+ for (alter = XCDR (alter), reg_prio = 1;
+ CONSP (alter);
+ alter = XCDR (alter), reg_prio++)
+ if (STRINGP (XCAR (alter)))
+ {
+ int nfonts2;
+ struct font_name *fonts2;
+
+ nfonts2 = font_list_1 (f, pattern, family, XCAR (alter),
+ &fonts2);
+ for (i = 0; i < nfonts2; i++)
+ fonts2[i].registry_priority = reg_prio;
+ *fonts = (nfonts > 0
+ ? concat_font_list (*fonts, nfonts, fonts2, nfonts2)
+ : fonts2);
+ nfonts += nfonts2;
+ }
+ }
+ }
+
+ return nfonts;
+}
+
+