<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Sep 12, 2017 at 8:06 PM, Akira TAGOH <span dir="ltr"><<a href="mailto:akira@tagoh.org" target="_blank">akira@tagoh.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Can you add a documentation for FcFreeTypeQueryAll?<br><div class="HOEnZb"><div class="h5"></div></div></blockquote><div><br></div><div>Will do, after I finish my patchset and send for review.</div><div><br></div><div>Or if someone wants to help with that, would be even better! :D</div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="HOEnZb"><div class="h5">
On Wed, Sep 13, 2017 at 6:17 AM, Behdad Esfahbod<br>
<<a href="mailto:behdad@kemper.freedesktop.org">behdad@kemper.freedesktop.org</a><wbr>> wrote:<br>
> fc-query/Makefile.am | 2 -<br>
> fc-query/fc-query.c | 88 ++++++++++++++----------------<wbr>------------------<br>
> fc-scan/fc-scan.c | 4 --<br>
> fontconfig/fontconfig.h | 3 +<br>
> src/fcdir.c | 86 ++++++++++--------------------<wbr>----------------<br>
> src/fcfreetype.c | 64 ++++++++++++++++++++++++++++++<wbr>++++<br>
> 6 files changed, 114 insertions(+), 133 deletions(-)<br>
><br>
> New commits:<br>
> commit 27a6a299e0fefca9c244213784d3c7<wbr>8b34281cd5<br>
> Author: Behdad Esfahbod <<a href="mailto:behdad@behdad.org">behdad@behdad.org</a>><br>
> Date: Tue Sep 12 16:43:33 2017 -0400<br>
><br>
> Add FcFreeTypeQueryAll()<br>
><br>
> Like FcFreeTypeQuery(), but adds patterns for all fonts found, including named<br>
> instances of variable fonts. If id is -1, then all collection faces are queried.<br>
> Returns number of fonts added.<br>
><br>
> This merges the same face loop that was in fc-query. and fcdir.c.<br>
><br>
> Needs documentation update.<br>
><br>
> diff --git a/fc-query/Makefile.am b/fc-query/Makefile.am<br>
> index 6fe357b..73b3f11 100644<br>
> --- a/fc-query/Makefile.am<br>
> +++ b/fc-query/Makefile.am<br>
> @@ -41,7 +41,7 @@ EXTRA_DIST=fc-query.sgml $(BUILT_MANS)<br>
><br>
> CLEANFILES =<br>
><br>
> -fc_query_LDADD = ${top_builddir}/src/<a href="http://libfontconfig.la" rel="noreferrer" target="_blank">libfontcon<wbr>fig.la</a> $(FREETYPE_LIBS)<br>
> +fc_query_LDADD = ${top_builddir}/src/<a href="http://libfontconfig.la" rel="noreferrer" target="_blank">libfontcon<wbr>fig.la</a><br>
><br>
> if USEDOCBOOK<br>
><br>
> diff --git a/fc-query/fc-query.c b/fc-query/fc-query.c<br>
> index 6cd5abd..a5b2cda 100644<br>
> --- a/fc-query/fc-query.c<br>
> +++ b/fc-query/fc-query.c<br>
> @@ -98,12 +98,9 @@ usage (char *program, int error)<br>
> int<br>
> main (int argc, char **argv)<br>
> {<br>
> - FT_Library ftLibrary;<br>
> - int index_set = 0;<br>
> - int set_index = 0;<br>
> - int set_face_num = 0;<br>
> - int set_instance_num = 0;<br>
> + int id = -1;<br>
> int ignore_blanks = 0;<br>
> + FcFontSet *fs;<br>
> FcChar8 *format = NULL;<br>
> FcBlanks *blanks = NULL;<br>
> int err = 0;<br>
> @@ -122,8 +119,7 @@ main (int argc, char **argv)<br>
> ignore_blanks = 1;<br>
> break;<br>
> case 'i':<br>
> - index_set = 1;<br>
> - set_index = atoi (optarg);<br>
> + id = atoi (optarg);<br>
> break;<br>
> case 'f':<br>
> format = (FcChar8 *) strdup (optarg);<br>
> @@ -146,74 +142,42 @@ main (int argc, char **argv)<br>
> if (i == argc)<br>
> usage (argv[0], 1);<br>
><br>
> - if (FT_Init_FreeType (&ftLibrary))<br>
> - return 1;<br>
> -<br>
> + fs = FcFontSetCreate ();<br>
> if (!ignore_blanks)<br>
> blanks = FcConfigGetBlanks (NULL);<br>
> +<br>
> for (; i < argc; i++)<br>
> {<br>
> - FT_Face face;<br>
> - int num_faces = 0;<br>
> - int num_instances = 0;<br>
> - int face_num = 0;<br>
> - int instance_num = 0;<br>
> - int id;<br>
> -<br>
> - if (index_set)<br>
> + if (!FcFreeTypeQueryAll ((FcChar8*) argv[i], id, blanks, NULL, fs))<br>
> {<br>
> - face_num = set_face_num = set_index & 0xFFFF;<br>
> - instance_num = set_instance_num = set_index >> 16;<br>
> + fprintf (stderr, "Can't query face %d of font file %s\n", id, argv[i]);<br>
> + err = 1;<br>
> }<br>
> + }<br>
><br>
> - do {<br>
> - FcPattern *pat;<br>
> -<br>
> - id = ((instance_num << 16) + face_num);<br>
> - if (FT_New_Face (ftLibrary, argv[i], id, &face))<br>
> - break;<br>
> - num_faces = face->num_faces;<br>
> - num_instances = face->style_flags >> 16;<br>
> - pat = FcFreeTypeQueryFace (face, (const FcChar8 *) argv[i], id, blanks);<br>
> - FT_Done_Face (face);<br>
> -<br>
> - if (pat)<br>
> - {<br>
> - if (format)<br>
> - {<br>
> - FcChar8 *s;<br>
> -<br>
> - s = FcPatternFormat (pat, format);<br>
> - if (s)<br>
> - {<br>
> - printf ("%s", s);<br>
> - FcStrFree (s);<br>
> - }<br>
> - }<br>
> - else<br>
> - {<br>
> - FcPatternPrint (pat);<br>
> - }<br>
> + for (i = 0; i < fs->nfont; i++)<br>
> + {<br>
> + FcPattern *pat = fs->fonts[i];<br>
><br>
> - FcPatternDestroy (pat);<br>
> - }<br>
> - else<br>
> - {<br>
> - fprintf (stderr, "Can't query face %d of font file %s\n", id, argv[i]);<br>
> - err = 1;<br>
> - }<br>
> + if (format)<br>
> + {<br>
> + FcChar8 *s;<br>
><br>
> - if (instance_num < num_instances && !set_instance_num)<br>
> - instance_num++;<br>
> - else<br>
> + s = FcPatternFormat (pat, format);<br>
> + if (s)<br>
> {<br>
> - face_num++;<br>
> - instance_num = 0;<br>
> + printf ("%s", s);<br>
> + FcStrFree (s);<br>
> }<br>
> - } while (!err && (!index_set || face_num == set_face_num) && face_num < num_faces);<br>
> + }<br>
> + else<br>
> + {<br>
> + FcPatternPrint (pat);<br>
> + }<br>
> }<br>
><br>
> - FT_Done_FreeType (ftLibrary);<br>
> + FcFontSetDestroy (fs);<br>
> +<br>
> FcFini ();<br>
> return err;<br>
> }<br>
> diff --git a/fc-scan/fc-scan.c b/fc-scan/fc-scan.c<br>
> index 1f18e80..58a0b15 100644<br>
> --- a/fc-scan/fc-scan.c<br>
> +++ b/fc-scan/fc-scan.c<br>
> @@ -150,9 +150,7 @@ main (int argc, char **argv)<br>
><br>
> for (i = 0; i < fs->nfont; i++)<br>
> {<br>
> - FcPattern *pat;<br>
> -<br>
> - pat = fs->fonts[i];<br>
> + FcPattern *pat = fs->fonts[i];<br>
><br>
> if (format)<br>
> {<br>
> diff --git a/fontconfig/fontconfig.h b/fontconfig/fontconfig.h<br>
> index ecc1d90..f085aa0 100644<br>
> --- a/fontconfig/fontconfig.h<br>
> +++ b/fontconfig/fontconfig.h<br>
> @@ -577,6 +577,9 @@ FcDirCacheUnload (FcCache *cache);<br>
> FcPublic FcPattern *<br>
> FcFreeTypeQuery (const FcChar8 *file, int id, FcBlanks *blanks, int *count);<br>
><br>
> +FcPublic unsigned int<br>
> +FcFreeTypeQueryAll(const FcChar8 *file, int id, FcBlanks *blanks, int *count, FcFontSet *set);<br>
> +<br>
> /* fcfs.c */<br>
><br>
> FcPublic FcFontSet *<br>
> diff --git a/src/fcdir.c b/src/fcdir.c<br>
> index b6c0bf0..4f38f4b 100644<br>
> --- a/src/fcdir.c<br>
> +++ b/src/fcdir.c<br>
> @@ -23,9 +23,6 @@<br>
> */<br>
><br>
> #include "fcint.h"<br>
> -#include "fcftint.h"<br>
> -#include <ft2build.h><br>
> -#include FT_FREETYPE_H<br>
> #include <dirent.h><br>
><br>
> FcBool<br>
> @@ -67,47 +64,32 @@ FcFileScanFontConfig (FcFontSet *set,<br>
> const FcChar8 *file,<br>
> FcConfig *config)<br>
> {<br>
> - FT_Library ftLibrary;<br>
> - FT_Face face;<br>
> - FcPattern *font;<br>
> + int i;<br>
> FcBool ret = FcTrue;<br>
> - int num_faces = 0;<br>
> - int num_instances = 0;<br>
> - int face_num = 0;<br>
> - int instance_num = 0;<br>
> - int id;<br>
> + int old_nfont = set->nfont;<br>
> const FcChar8 *sysroot = FcConfigGetSysRoot (config);<br>
><br>
> - if (FT_Init_FreeType (&ftLibrary))<br>
> + if (FcDebug () & FC_DBG_SCAN)<br>
> + {<br>
> + printf ("\tScanning file %s...", file);<br>
> + fflush (stdout);<br>
> + }<br>
> +<br>
> + if (!FcFreeTypeQueryAll (file, -1, NULL, NULL, set))<br>
> return FcFalse;<br>
><br>
> - do<br>
> - {<br>
> - font = 0;<br>
> - /*<br>
> - * Nothing in the cache, scan the file<br>
> - */<br>
> - if (FcDebug () & FC_DBG_SCAN)<br>
> - {<br>
> - printf ("\tScanning file %s...", file);<br>
> - fflush (stdout);<br>
> - }<br>
> + if (FcDebug () & FC_DBG_SCAN)<br>
> + printf ("done\n");<br>
><br>
> - id = ((instance_num << 16) + face_num);<br>
> - if (FT_New_Face (ftLibrary, (char *) file, id, &face))<br>
> - return FcFalse;<br>
> - num_faces = face->num_faces;<br>
> - num_instances = face->style_flags >> 16;<br>
> - font = FcFreeTypeQueryFace (face, file, id, NULL);<br>
> - FT_Done_Face (face);<br>
> + for (i = old_nfont; i < set->nfont; i++)<br>
> + {<br>
> + FcPattern *font = set->fonts[i];<br>
><br>
> - if (FcDebug () & FC_DBG_SCAN)<br>
> - printf ("done\n");<br>
> /*<br>
> * Get rid of sysroot here so that targeting scan rule may contains FC_FILE pattern<br>
> * and they should usually expect without sysroot.<br>
> */<br>
> - if (font && sysroot)<br>
> + if (sysroot)<br>
> {<br>
> size_t len = strlen ((const char *)sysroot);<br>
> FcChar8 *f = NULL;<br>
> @@ -129,43 +111,15 @@ FcFileScanFontConfig (FcFontSet *set,<br>
> /*<br>
> * Edit pattern with user-defined rules<br>
> */<br>
> - if (font && config && !FcConfigSubstitute (config, font, FcMatchScan))<br>
> - {<br>
> - FcPatternDestroy (font);<br>
> - font = NULL;<br>
> + if (config && !FcConfigSubstitute (config, font, FcMatchScan))<br>
> ret = FcFalse;<br>
> - }<br>
><br>
> - /*<br>
> - * Add the font<br>
> - */<br>
> - if (font)<br>
> - {<br>
> - if (FcDebug() & FC_DBG_SCANV)<br>
> - {<br>
> - printf ("Final font pattern:\n");<br>
> - FcPatternPrint (font);<br>
> - }<br>
> - if (!FcFontSetAdd (set, font))<br>
> - {<br>
> - FcPatternDestroy (font);<br>
> - font = NULL;<br>
> - ret = FcFalse;<br>
> - }<br>
> - }<br>
> - else<br>
> - ret = FcFalse;<br>
> -<br>
> - if (instance_num < num_instances)<br>
> - instance_num++;<br>
> - else<br>
> + if (FcDebug() & FC_DBG_SCANV)<br>
> {<br>
> - face_num++;<br>
> - instance_num = 0;<br>
> + printf ("Final font pattern:\n");<br>
> + FcPatternPrint (font);<br>
> }<br>
> - } while (font && ret && face_num < num_faces);<br>
> -<br>
> - FT_Done_FreeType (ftLibrary);<br>
> + }<br>
><br>
> return ret;<br>
> }<br>
> diff --git a/src/fcfreetype.c b/src/fcfreetype.c<br>
> index dbfe291..a6e7058 100644<br>
> --- a/src/fcfreetype.c<br>
> +++ b/src/fcfreetype.c<br>
> @@ -1980,7 +1980,8 @@ FcFreeTypeQuery(const FcChar8 *file,<br>
> if (FT_New_Face (ftLibrary, (char *) file, id, &face))<br>
> goto bail;<br>
><br>
> - *count = face->num_faces;<br>
> + if (count)<br>
> + *count = face->num_faces;<br>
><br>
> pat = FcFreeTypeQueryFace (face, file, id, blanks);<br>
><br>
> @@ -1990,6 +1991,67 @@ bail:<br>
> return pat;<br>
> }<br>
><br>
> +unsigned int<br>
> +FcFreeTypeQueryAll(const FcChar8 *file,<br>
> + int id,<br>
> + FcBlanks *blanks,<br>
> + int *count,<br>
> + FcFontSet *set)<br>
> +{<br>
> + FT_Face face;<br>
> + FT_Library ftLibrary = NULL;<br>
> + int index_set = id != -1;<br>
> + int set_face_num = index_set ? id & 0xFFFF : 0;<br>
> + int set_instance_num = index_set ? id >> 16 : 0;<br>
> + int face_num = set_face_num;<br>
> + int instance_num = set_instance_num;<br>
> + int num_faces = 0;<br>
> + int num_instances = 0;<br>
> + unsigned int ret = 0;<br>
> + int err = 0;<br>
> +<br>
> + if (FT_Init_FreeType (&ftLibrary))<br>
> + return 0;<br>
> +<br>
> + do {<br>
> + FcPattern *pat;<br>
> +<br>
> + id = ((instance_num << 16) + face_num);<br>
> + if (FT_New_Face (ftLibrary, (const char *) file, id, &face))<br>
> + break;<br>
> +<br>
> + num_faces = face->num_faces;<br>
> + num_instances = face->style_flags >> 16;<br>
> + pat = FcFreeTypeQueryFace (face, (const FcChar8 *) file, id, blanks);<br>
> + FT_Done_Face (face);<br>
> +<br>
> + if (pat)<br>
> + {<br>
> + ret++;<br>
> + if (!set || ! FcFontSetAdd (set, pat))<br>
> + FcPatternDestroy (pat);<br>
> + }<br>
> + else<br>
> + err = 1;<br>
> +<br>
> + if (instance_num < num_instances && !set_instance_num)<br>
> + instance_num++;<br>
> + else<br>
> + {<br>
> + face_num++;<br>
> + instance_num = 0;<br>
> + }<br>
> + } while (!err && (!index_set || face_num == set_face_num) && face_num < num_faces);<br>
> +<br>
> + if (count)<br>
> + *count = num_faces;<br>
> +<br>
> + FT_Done_FreeType (ftLibrary);<br>
> +<br>
> + return ret;<br>
> +}<br>
> +<br>
> +<br>
> /*<br>
> * For our purposes, this approximation is sufficient<br>
> */<br>
> ______________________________<wbr>_________________<br>
> Fontconfig mailing list<br>
> <a href="mailto:Fontconfig@lists.freedesktop.org">Fontconfig@lists.freedesktop.<wbr>org</a><br>
> <a href="https://lists.freedesktop.org/mailman/listinfo/fontconfig" rel="noreferrer" target="_blank">https://lists.freedesktop.org/<wbr>mailman/listinfo/fontconfig</a><br>
<br>
<br>
<br>
</div></div><span class="HOEnZb"><font color="#888888">--<br>
Akira TAGOH<br>
</font></span></blockquote></div><br><br clear="all"><br>-- <br><div class="gmail_signature" data-smartmail="gmail_signature">behdad<br><a href="http://behdad.org/" target="_blank">http://behdad.org/</a></div>
</div></div>