<div dir="ltr"><div dir="ltr"><div class="gmail_default" style="font-family:arial,helvetica,sans-serif"><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, 25 Jan 2019 at 09:35, Lawrence D'Oliveiro <<a href="mailto:ldo@geek-central.gen.nz">ldo@geek-central.gen.nz</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">On Thu, 24 Jan 2019 12:37:31 +0530, Jay Aurabind wrote:<br>
<br>
> This begs the question, are there any FreeType Supported font formats<br>
> that can actually do granular weight rendering if requested by<br>
> fontconfig?<br>
<br>
As I understand it, what you really want to do is get a list of all the<br>
weights available for a particular family, and choose the next higher<br>
one from a given one?<br>
<br>
Fontconfig has no API for directly returning this, but it is easy<br>
enough to implement the function for yourself.<br>
<br>
Following is an example Python script that, given a font spec, finds<br>
all weights available for the best matching font family. For example,<br>
on my current system setup,<br>
<br>
family_weights palatino<br>
<br>
returns<br>
<br>
family 'P052' members [{'weight': 80, 'file': '/usr/share/fonts/type1/urw-base35/P052-Italic.t1'}, {'weight': 100, 'file': '/usr/share/fonts/type1/urw-base35/P052-Roman.t1'}, {'weight': 200, 'file': '/usr/share/fonts/type1/urw-base35/P052-Bold.t1'}, {'weight': 200, 'file': '/usr/share/fonts/type1/urw-base35/P052-BoldItalic.t1'}]<br>
<br>
Adapt as appropriate.<br></blockquote><div><br></div><div style="font-family:arial,helvetica,sans-serif" class="gmail_default">Thank you very much for sharing this. <br></div><div style="font-family:arial,helvetica,sans-serif" class="gmail_default"></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
----<br>
#!/usr/bin/python3<br>
#+<br>
# Find all weights for a given family. Invoke this script as follows:<br>
#<br>
# family_weights «font-spec»<br>
#<br>
# and it will return a list of all fonts with a common family name<br>
# matching «font-spec», in order of increasing weight.<br>
#-<br>
<br>
import sys<br>
import getopt<br>
import freetype2 as ft # <<a href="https://github.com/ldo/python_freetype" rel="noreferrer" target="_blank">https://github.com/ldo/python_freetype</a>><br>
import fontconfig as fc # <<a href="https://github.com/ldo/python_fontconfig" rel="noreferrer" target="_blank">https://github.com/ldo/python_fontconfig</a>><br>
from fontconfig import \<br>
FC<br>
<br>
if len(sys.argv) != 2 :<br>
raise getopt.GetoptError("need exactly one arg, the Fontconfig pattern to match")<br>
#end if<br>
<br>
conf = fc.Config.get_current()<br>
pat = fc.Pattern.name_parse(sys.argv[1])<br>
conf.substitute(pat, FC.MatchPattern)<br>
pat.default_substitute()<br>
family_name = None<br>
found = []<br>
for entry in conf.font_sort(pat, trim = False, want_coverage = False)[0] :<br>
this_family = entry.get(FC.FAMILY, 0)[0]<br>
if family_name == None or this_family == family_name :<br>
if family_name == None :<br>
family_name = this_family<br>
#end if<br>
found.append({"weight" : entry.get(FC.WEIGHT, 0)[0], "file" : entry.get(FC.FILE, 0)[0]})<br>
#end if<br>
#end for<br>
found = sorted(found, key = lambda x : x["weight"])<br>
sys.stdout.write("family %s members %s\n" % (repr(family_name), repr(found)))<br>
_______________________________________________<br>
Fontconfig mailing list<br>
<a href="mailto:Fontconfig@lists.freedesktop.org" target="_blank">Fontconfig@lists.freedesktop.org</a><br>
<a href="https://lists.freedesktop.org/mailman/listinfo/fontconfig" rel="noreferrer" target="_blank">https://lists.freedesktop.org/mailman/listinfo/fontconfig</a><br>
</blockquote></div><br clear="all"><br>-- <br><div dir="ltr" class="gmail_signature"><div dir="ltr"><br><div><font face="trebuchet ms, sans-serif" color="#073763">Thanks and Regards,</font></div><div><font face="trebuchet ms, sans-serif" color="#073763"><b>Aurabindo J</b></font></div></div></div></div>