Discussion:
[fontforge-users] How do setting "match class" of "calt" feature on python script.
michinari.nukazawa
2015-05-07 14:12:09 UTC
Permalink
I need GSUB Conditional Features on python script.( My next product
intend to challenge a script typefece.)

'aalt'/'calt'
(My blog: FontForge version is today(2015/04).
http://blog-en.michinari-nukazawa.com/2015/04/fontforge-conditional-features-caltaalt.html
)

I writing python script is this:

## add 'aalt' feature
font.addLookup("'aalt' Lookup-01", "gsub_alternate",
(), (("DFLT",("dflt")),("latn",("dflt")),))
# font.select("b.high")
# font.addLookupSubtable("'aalt' Lookup-01", "b")
font.addLookupSubtable("'aalt' Lookup-01", "'aalt' Lookup-01
Subtable-01")
font.addPosSub("'aalt' Lookup-01 Subtable-01", "b b.high")

## add 'calt' feature
font.addLookup("'calt' Lookup-01", "gsub_context",
(), (("DFLT",("dflt")),("latn",("dflt")),))
# matching rule
font.addContextualSubtable("'calt' Lookup-01", "'calt' Lookup-01
Subtable-01",
"class",
"high-after | letters @<'aalt' Access All Alternates in Latin
lookup 0> |",)
# add match class
<I need this setting of match class Name:"letter" / Glyphs
in the class:"a b c d" ...>

Thanks.
michinari.nukazawa
2015-06-02 12:32:43 UTC
Permalink
Self helped to half.

A aalt feature can read.
But, calt feature is can't read now.


I have a plans.
plan A: Rewrite a glyph path to a base font already (manual setting)
GSUB setupped.
plan B: I write script. It is generate (or rewrite) a FontForge native
file (.sdf text)
plan C: Add method on python binding.

Now is plan A.
(humm... plan C is hard way for me. I read to fontforge/python.c and
other. )



==== Start script (print GSUB/GPOS feature.)

#!/usr/bin/env fontforge -lang=py -script
# -*- coding: utf-8 -*-
#
# usage : fontforge -lang=py -script {this_script.py} {font_file.otf}
#
# author : MichinariNukazawa / "project daisy bell"
# ***@gmail.com
# https://github.com/MichinariNukazawa/RuneAMN_Pro_Series_Fonts
# license: clause-2 BSD license
#
# Special Thanks
#
http://apt-browse.org/browse/debian/wheezy/main/all/sortsmill-tools/0.4-1/file/usr/share/pyshared/sortsmill/readfeatures.py
#
#
#
import sys
from pprint import pprint

def main():
print("start fontforge script.\n")

if(not (2 == len(sys.argv))):
print("error: args length :{0}\n".format(len(sys.argv)))
sys.exit(-1)

pathFontFile = sys.argv[1]
font = fontforge.open(pathFontFile)

print_lookups_and_subtables(font)

print_getPosSub(font, "*")

font.close()
print ("Exit : "+ pathFontFile)

#
# @param subtable_name or "*" (from glyph.getPosSub())
#
def print_getPosSub(font, subtable_name):
print('=== Search: {0}'.format(subtable_name))
for glyph in font.glyphs():
# pprint(glyph)
posSub = glyph.getPosSub(subtable_name)
if(posSub):
pprint(glyph)
pprint(posSub)
print('=== EndSearch')

def print_lookups_and_subtables(font):
print("gpos")
for lookup in font.gpos_lookups:
print("lookup feature : {0}".format(font.getLookupInfo(lookup)[0]))
subtables = font.getLookupSubtables(lookup)
i = 0
while i < len(subtables) and font.isKerningClass(subtables[i]) :
print("subtable[{0}] : {1}".format(i, subtab))
pprint(subtab)
pprint(font.getPosSub(subtab))
i += 1
for subtab in subtables[i + 1:]:
if not font.isKerningClass(subtab):
print("subtables[{0}] : {1}".format(i, subtables[i]))
print("\n")
print("gsub")
for ixLo, lookup in enumerate(font.gsub_lookups):
print("\n")
print("lookup feature [{0}]:".format(ixLo))
pprint(font.getLookupInfo(lookup))

subtables = font.getLookupSubtables(lookup)
for ixSub, subtable in enumerate(subtables):
# I need:
# print(font.getLookupSubtableInfo(subtable))
#
print("")
print('subtable[{0}]: "{1}"'.format(ixSub, subtable))

print_getPosSub(font, subtable)

anchorClass = font.getLookupSubtableAnchorClasses(subtable)
if(anchorClass):
print('AnchorClass:')
pprint(anchorClass)
else:
print('AnchorClass: Nothing.')
if(font.isKerningClass(subtable)):
print('KerningClass:')
pprint(font.getKerningClass(subtable))
else:
print('KerningClass: Nothing')

#pprint(font.getPosSub(subtable))
print("")

if __name__ == '__main__':
main()


==== End script
Post by michinari.nukazawa
I need GSUB Conditional Features on python script.( My next product
intend to challenge a script typefece.)
'aalt'/'calt'
(My blog: FontForge version is today(2015/04).
http://blog-en.michinari-nukazawa.com/2015/04/fontforge-conditional-features-caltaalt.html
)
## add 'aalt' feature
font.addLookup("'aalt' Lookup-01", "gsub_alternate",
(), (("DFLT",("dflt")),("latn",("dflt")),))
# font.select("b.high")
# font.addLookupSubtable("'aalt' Lookup-01", "b")
font.addLookupSubtable("'aalt' Lookup-01", "'aalt' Lookup-01
Subtable-01")
font.addPosSub("'aalt' Lookup-01 Subtable-01", "b b.high")
## add 'calt' feature
font.addLookup("'calt' Lookup-01", "gsub_context",
(), (("DFLT",("dflt")),("latn",("dflt")),))
# matching rule
font.addContextualSubtable("'calt' Lookup-01", "'calt' Lookup-01
Subtable-01",
"class",
Latin lookup 0> |",)
# add match class
<I need this setting of match class Name:"letter" / Glyphs
in the class:"a b c d" ...>
Thanks.
------------------------------------------------------------------------------
Loading...