Skip to content

Commit

Permalink
Haroof fix for Lahori nastaleeq font. Collisons avoided
Browse files Browse the repository at this point in the history
  • Loading branch information
sayedzeeshan committed Sep 9, 2021
1 parent 0dc998a commit 9011e38
Show file tree
Hide file tree
Showing 13 changed files with 29 additions and 19 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ test/obj/*
release
source/obj
*.pkl
*.bak
*.bak
test/test_modules.py
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
setup(
name = 'ligature_kerning',
packages = find_packages(),
version = '0.0.3',
version = '0.0.4',
license='MIT',
description = 'Nasteeq ligatures kerning for OpenType (TruType) Fonts',
author = 'Sayed Zeeshan Asghar',
Expand Down
Binary file modified source/__pycache__/groups.cpython-39.pyc
Binary file not shown.
Binary file modified source/__pycache__/heights.cpython-39.pyc
Binary file not shown.
21 changes: 14 additions & 7 deletions source/groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@
shifts = []
left_threshold = []
right_threshold = []
HeighAdjustment = [0,-200,-100,-100,-50,-20,-20,0,0,-50]; # should always be non-positive
weights = [0.8,0.15,0.05] #must sum up to 1.0
HeighAdjustment = np.ones(shape=(10,),dtype=int)*-15; # should always be non-positive
HeighAdjustment[0] = 0
weights = [0.6,0.25,0.15] #must sum up to 1.0
exceptions = {} #needs to be populated first before calling form_groups_from_tables function

def form_groups_from_tables(Keys,Lookup,LHeightsData,RHeightsData,LCollisionList,RCollisionList,VTGFilePath,VTLFilePath):
lu_len = len(Lookup)
#table sorting
Expand Down Expand Up @@ -101,17 +103,22 @@ def form_groups_from_tables(Keys,Lookup,LHeightsData,RHeightsData,LCollisionList
TLst = np.zeros(shape=(L0,3),dtype=int)
for i in range(0,L0):
TLst[i,0] = RTable[j][i]
TLst[i,1] = RHeightsData[RTable[j][i],j+1]*weights[0] + \
RHeightsData[RTable[j][i],3]*weights[1] + \
RHeightsData[RTable[j][i],4]*weights[2]
if j == 0:
TLst[i,1] = RHeightsData[RTable[j][i],j+1]*0.4 + \
RHeightsData[RTable[j][i],j+2]*0.6
else:
TLst[i,1] = RHeightsData[RTable[j][i],j+1]*weights[0]*0.5+ \
RHeightsData[RTable[j][i],j+2]*weights[0]*0.5 + \
RHeightsData[RTable[j][i],3]*weights[1]+ \
RHeightsData[RTable[j][i],4]*weights[2]
TLst[i,2] = RHeightsData[RTable[j][i],j+2]
RMaster[j]=np.flipud(TLst[TLst[:,1].argsort(),])

cushion = np.zeros(shape=(10,1),dtype=int)
for j in range(0,nCols):
if RMaster[j][:,1].any():
cushion[j] = np.mean(RMaster[j][:,1] - np.mean(RMaster[j][:,2]))

cushion[0:1] = 0
#height thresholds to form vertical groups
thresh = np.zeros(shape=(nRows,nCols),dtype=int)
dT = 0
Expand Down Expand Up @@ -144,7 +151,7 @@ def form_groups_from_tables(Keys,Lookup,LHeightsData,RHeightsData,LCollisionList

for j in range(0,nRows-1):
for k in range(0,nCols):
a = np.argwhere(RMaster[k][:,1] < thresh[j,k])
a = np.argwhere(RMaster[k][:,1] + 0.5*cushion[j] < thresh[j,k])
if a.any():
indR[j,k] = a[0]
for k in range(0,nCols):
Expand Down
Binary file modified source/obj/GlyphHeightsDictionary.pkl
Binary file not shown.
Binary file modified source/obj/LeftList.pkl
Binary file not shown.
Binary file modified source/obj/LeftTable.pkl
Binary file not shown.
Binary file modified source/obj/RightList.pkl
Binary file not shown.
Binary file modified source/obj/RightTable.pkl
Binary file not shown.
10 changes: 5 additions & 5 deletions source/settings.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
# edit this files for directory and kerning control
#any test after # is ignored

GLYPH_DIR_LOC C:/TestKerning #path to ligature directory
GLYPH_DIR_LOC C:/Ligatures_JNN #path to ligature directory

FONT_TYPE KASHEEDA #options: KASHEEDA REGULAR
FONT_TYPE REGULAR #options: KASHEEDA REGULAR

HORIZONTAL_SHIFTS [100, 175,200,200,200,200,200,200,200,200] # amount of shifts in units for each horizontal bin

Expand All @@ -21,12 +21,12 @@ EXCEPTION_STRING r # could be ending string or complete glyph name
EXCEPTION_PROFILE [4000,4000,4000,1500,1800,2000,2500,4000,4000,4000]
#define a height profile at different shift values, at which the glyph specified
#by search string (above) will have to be shorter
EXCEPTION_ADJUSTMENT [-100,-100,-100,-350,-350,-350,-550,-550,-550,-550]
EXCEPTION_ADJUSTMENT [-100,-100,-100,-250,-250,-250,-350,-350,-350,-350]
#once a glyph(s) match the EXCEPTION_STRING and EXCEPTION_PROFILE
#criterion this adjustment will be applied to height of the glyph.
#The values should be negative to apply more kerning and posistive
#if you want to apply less kerning than default.

EXCEPTION_STRING alef
EXCEPTION_PROFILE [4000,4000,4000,1500,1800,2000,2500,4000,4000,4000]
EXCEPTION_ADJUSTMENT [-100,-100,-100,-350,-350,-350,-550,-550,-550,-550]
EXCEPTION_PROFILE [4000,4000,4000,4000,4000,4000,4000,4000,4000,4000]
EXCEPTION_ADJUSTMENT [0,0,-100,-350,-350,-350,-550,-550,-550,-550]
Binary file modified test/__pycache__/test_modules.cpython-39.pyc
Binary file not shown.
12 changes: 7 additions & 5 deletions test/test_modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,17 @@


def haroof_test():
numGlyphs = cgh.haroof_glyphs("C:/Ligatures_JNN/Haroof_Regular/",10,770)
assert numGlyphs == 46
GlyphHeight = []
GlyphHeight.append(1159)
numGlyphs = cgh.haroof_glyphs("C:/TestKerning/Haroof_Regular/",10,GlyphHeight)
#assert numGlyphs == 46
def all_glyphs_test():
LookUp = cgh.calc_glyph_heights("C:/Ligaturess",10,0)
LookUp = cgh.calc_glyph_heights("C:/TestKerning",10,0)
slo.save_obj(LookUp,'GlyphHeightsDictionary')
def plot_test():
LookUp = slo.load_obj('GlyphHeightsDictionary')
cgh.plot_glyph_data(LookUp,"C:/Ligatures/Ligatures_Regular/flsvin.png","flsvin")
cgh.plot_glyph_data(LookUp,"C:/Ligatures/Haroof_Regular/reh.png","reh")
cgh.plot_glyph_data(LookUp,"C:/TestKerning/Ligatures_Regular/mr.png","mr")
cgh.plot_glyph_data(LookUp,"C:/TestKerning/Haroof_Regular/gr.png","gr")
def test_collisions():
start_time = time.time()
LookUp = slo.load_obj('GlyphHeightsDictionary')
Expand Down

0 comments on commit 9011e38

Please sign in to comment.