[Fontconfig] How to use FcFontMatch to find a font with a given character

Lawrence D'Oliveiro ldo at geek-central.gen.nz
Sun Jul 1 02:00:58 UTC 2018


On Sun, 1 Jul 2018 00:41:01 +0800, Elias Mårtenson wrote:

> I've been testing with U+03C6 GREEK SMALL LETTER PHI, and
> it does exist in DejaVu Sans, Fontconfig correctly finds it when I
> query for fonts that contain this character, but when I use
> FcCharSetFirstPage and FcCharSetNextPage, the resulting bitmaps
> indicates that this character does not exist.

Not sure what you’re doing differently. Here’s a sample Python script I
tried with <https://github.com/ldo/python_fontconfig/>:

    #!/usr/bin/python3

    import sys
    import getopt
    import fontconfig as fc
    from fontconfig import \
        FC

    opts, args = getopt.getopt \
      (
        sys.argv[1:],
        "",
        []
      )

    if len(args) < 2 :
        raise getopt.GetoptError("usage: %s pat prop [prop ...]" % sys.argv[0])
    #end if

    conf = fc.Config.get_current()
    pat = fc.Pattern.name_parse(args[0])
    if True :
        conf.substitute(pat, FC.MatchPattern)
        pat.default_substitute()
    #end if
    props = args[1:]
    sys.stdout.write("matching: %s\n" % pat.name_unparse())

    i = 0
    for f in conf.font_sort(pat, trim = False, want_coverage = False)[0] :
        sys.stdout.write \
          (
                "found[%d]: %s\n"
            %
                (i, "; ".join("%s=%s" % (prop, f.get(prop, 0)) for prop in props))
          )
        i += 1
    #end for
    if i == 0 :
        sys.stdout.write("(none found)\n")
    #end if

invoking it with a command like

    ./font_list dejavu\ sans family charset

and I get output like (abbreviated)

    found[0]: family=('DejaVu Sans', 0); charset=({32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42,
    ... 966, ...
    ... }, 0)

As you can see, the character in question is listed.


More information about the Fontconfig mailing list