Skip to content

Commit 1df8fa9

Browse files
committed
group formation bug removed in stage 3.
Height of the input images should be same for all glyphs
1 parent 9624e16 commit 1df8fa9

18 files changed

Lines changed: 74 additions & 37 deletions

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
launch.json
22
test/test_bench.py
33
test/obj/*
4-
release
4+
release
5+
source/obj
6+
*.pkl

setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
setup(
44
name = 'ligature_kerning',
55
packages = find_packages(),
6-
version = '0.0.1',
6+
version = '0.0.3',
77
license='MIT',
88
description = 'Nasteeq ligatures kerning for OpenType (TruType) Fonts',
99
author = 'Sayed Zeeshan Asghar',
@@ -22,7 +22,7 @@
2222
'opencv-python >= 4.5.2.0'
2323
],
2424
classifiers=[
25-
'Development Status :: 1 - Beta',
25+
'Development Status :: 3 - Beta',
2626
'Intended Audience :: Users',
2727
'Topic :: Fonts :: Kerning',
2828
'License :: MIT License',
-6 Bytes
Binary file not shown.
299 Bytes
Binary file not shown.
186 Bytes
Binary file not shown.
11 Bytes
Binary file not shown.

source/groups.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
nCols = 10
55
nRows = 10
66

7-
shifts = [100, 100, 175, 175, 175, 200, 200, 200, 200, 200]
8-
left_threshold = [100, 100, 100, 100, 100, 100, 50, 50, 50, 100]
9-
right_threshold = [200, 200, 200, 200, 200, 200, 200, 200, 150, 100]
7+
shifts = []
8+
left_threshold = []
9+
right_threshold = []
1010
HeighAdjustment = [0,-200,-100,-100,-50,-20,-20,0,0,-50]; # should always be non-positive
1111
weights = [0.8,0.15,0.05] #must sum up to 1.0
1212
exceptions = {} #needs to be populated first before calling form_groups_from_tables function
@@ -136,16 +136,23 @@ def form_groups_from_tables(Keys,Lookup,LHeightsData,RHeightsData,LCollisionList
136136
indL[j+1,k] = a[0]
137137
for k in range(0,nCols):
138138
indL[nRows,k] = len(LMaster[k])
139+
for j in range(nRows-1,1,-1):
140+
if indL[j,k] == -2:
141+
indL[j,k] = indL[j+1,k]
142+
indL[j+1,k] = -2
139143
indL[0,k] = 0
140144

141145
for j in range(0,nRows-1):
142146
for k in range(0,nCols):
143147
a = np.argwhere(RMaster[k][:,1] < thresh[j,k])
144148
if a.any():
145-
indR[j+1,k] = a[0]
149+
indR[j,k] = a[0]
146150
for k in range(0,nCols):
147151
indR[nRows,k] = len(RMaster[k])
148-
indR[0,k] = 0
152+
for j in range(nRows-1,1,-1):
153+
if indR[j,k] == -2:
154+
indR[j,k] = indR[j+1,k]
155+
indR[j+1,k] = -2
149156

150157
LeftGroups = {}
151158
RightGroups = {}

source/heights.py

Lines changed: 45 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010

1111
BASE_DIR = "C:/Ligatures"
1212
nBins = 11
13-
minHeight = 710
14-
maxHeight = 780
13+
minHeight = 417
14+
maxHeight = 1400
1515
shiftX = 200
1616
scaling = 4.9 #2048 units per em font assumption, images are 300 dpi
1717
DESC_RATE = 0.2 # per x-unit rate at which the bottom heigh descends where there is glyph data (extrapolation)
@@ -32,6 +32,7 @@
3232
NUM_PIXEL_SCAN = 9 #number of horizontal pixels to scan
3333
dXValid = [10,20,40,50,100] #valid values for dX
3434
LookUp = {} #instantiate an empty dictionary
35+
GlyphHeight = []
3536
haroofExceptions = ["alef.png","alefwah"] #define exception haroof here, these will have differnt default extrpolation height
3637
animation = "|/-\\"
3738
def set_base_dir(loc):
@@ -49,26 +50,47 @@ def calc_glyph_heights(baseDir,dX,enableKasheeda):
4950
symbolDir = baseDir+"/Symbols/"
5051
kasheedaDir = baseDir+"/Ligatures_Kashida/"
5152
kasheedaHaroofDir = baseDir+"/Haroof_Kashida/"
52-
numGlyphs += regular_glyphs(ligatureDir,dX)
53-
print("Number of glyphs processed: " + str(numGlyphs))
53+
numGlyphs = regular_glyphs(ligatureDir,dX,GlyphHeight)
54+
if numGlyphs == 0:
55+
print("Please check the input folder. Exiting now ")
56+
return 0
57+
else:
58+
print("Number of glyphs processed: " + str(numGlyphs))
5459
# regular Haroof processing
55-
numGlyphs += haroof_glyphs(haroofDir,dX)
56-
print("Number of glyphs processed: " + str(numGlyphs))
57-
numGlyphs += symbol_glyphs(symbolDir,dX)
58-
print("Number of glyphs processed: " + str(numGlyphs))
59-
if enableKasheeda == 1:
60-
numGlyphs += regular_glyphs(kasheedaDir,dX)
60+
numGlyphs = haroof_glyphs(haroofDir,dX,GlyphHeight)
61+
if numGlyphs == 0:
62+
print("Please check the input folder. Exiting now ")
63+
return 0
64+
else:
65+
print("Number of glyphs processed: " + str(numGlyphs))
66+
numGlyphs = symbol_glyphs(symbolDir,dX,GlyphHeight)
67+
if numGlyphs == 0:
68+
print("Please check the input folder. Exiting now ")
69+
return 0
70+
else:
6171
print("Number of glyphs processed: " + str(numGlyphs))
72+
if enableKasheeda == 1:
73+
numGlyphs = regular_glyphs(kasheedaDir,dX,GlyphHeight)
74+
if numGlyphs == 0:
75+
print("Please check the input folder. Exiting now ")
76+
return 0
77+
else:
78+
print("Number of glyphs processed: " + str(numGlyphs))
6279
# kasheeda Haroof processing
63-
numGlyphs += haroof_glyphs(kasheedaHaroofDir,dX)
64-
print("Number of glyphs processed: " + str(numGlyphs))
80+
numGlyphs = haroof_glyphs(kasheedaHaroofDir,dX,GlyphHeight)
81+
if numGlyphs == 0:
82+
print("Please check the input folder. Exiting now ")
83+
return 0
84+
else:
85+
print("Number of glyphs processed: " + str(numGlyphs))
6586
if numGlyphs == 0:
6687
print("Zero glyphs processed. Please check if the images are placed in correct directories.\n")
88+
return 0
6789
else:
6890
print("All glyphs processed successfully")
6991
return LookUp
7092

71-
def regular_glyphs(dir,dX):
93+
def regular_glyphs(dir,dX,GlyphHeight):
7294
numGlyphs = 0
7395
idx = 0
7496
for filepath in glob.iglob(dir + '**/*.png', recursive=True):
@@ -84,8 +106,10 @@ def regular_glyphs(dir,dX):
84106
return 0
85107

86108
H, W = im.shape
87-
if H < minHeight or H > maxHeight:
88-
print("Image height should be between "+str(minHeight)+" pixels and "+str(maxHeight)+" pixels.")
109+
if len(GlyphHeight) == 0:
110+
GlyphHeight.append(H)
111+
if H < minHeight or H > maxHeight or H != GlyphHeight[0]:
112+
print("Image height should be between "+str(minHeight)+" pixels and "+str(maxHeight)+" pixels. All images should have the exact same height")
89113
print("Program exiting now")
90114
return 0
91115
numGlyphs += 1
@@ -163,7 +187,7 @@ def regular_glyphs(dir,dX):
163187
LookUp[filename[0:-4]] = extents
164188
return numGlyphs
165189

166-
def haroof_glyphs(dir,dX):
190+
def haroof_glyphs(dir,dX,GlyphHeight):
167191
numGlyphs = 0
168192
for filepath in glob.iglob(dir + '**/*.png', recursive=True):
169193
exceptionFlag = 0
@@ -175,8 +199,8 @@ def haroof_glyphs(dir,dX):
175199
print("Unsuccessful in reading image (check if glyph directory is not empty)\n exiting now\n")
176200
return 0
177201
H, W = im.shape
178-
if H < minHeight or H > maxHeight:
179-
print("Image height should be between "+str(minHeight)+" pixels and "+str(maxHeight)+" pixels.")
202+
if H < minHeight or H > maxHeight or H != GlyphHeight[0]:
203+
print("Image height should be between "+str(minHeight)+" pixels and "+str(maxHeight)+" pixels. All images should have the exact same height")
180204
print("Program exiting now")
181205
return 0
182206
numGlyphs += 1
@@ -251,7 +275,7 @@ def haroof_glyphs(dir,dX):
251275
LookUp[filename[0:-4]] = extents
252276
return numGlyphs
253277

254-
def symbol_glyphs(dir,dX):
278+
def symbol_glyphs(dir,dX,GlyphHeight):
255279
numGlyphs = 0
256280
for filepath in glob.iglob(dir + '**/*.png', recursive=True):
257281
filename = os.path.basename(filepath)
@@ -262,8 +286,8 @@ def symbol_glyphs(dir,dX):
262286
print("Unsuccessful in reading image (check if glyph directory is not empty)\n exiting now\n")
263287
return 0
264288
H, W = im.shape
265-
if H < minHeight or H > maxHeight:
266-
print("Image height should be between "+str(minHeight)+" pixels and "+str(maxHeight)+" pixels.")
289+
if H < minHeight or H > maxHeight or H != GlyphHeight[0]:
290+
print("Image height should be between "+str(minHeight)+" pixels and "+str(maxHeight)+" pixels. All images should have the exact same height")
267291
print("Program exiting now")
268292
return 0
269293
numGlyphs += 1

source/ligature_kerning.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
def process_stage_1():
99
if ps.parse_settings_file("settings.txt") == 1:
10-
LookUp = cgh.calc_glyph_heights(ps.base_dir[0],10,0)
10+
LookUp = cgh.calc_glyph_heights(ps.base_dir[0],10,ps.kasheeda)
1111
if len(LookUp) > 0:
1212
slo.save_obj(LookUp,'GlyphHeightsDictionary')
1313
return 1
@@ -37,6 +37,10 @@ def process_stage_3():
3737
if ps.parse_settings_file("settings.txt") == 1:
3838
for count, str in enumerate(ps.exstr):
3939
gp.add_exception(str,ps.prof[count],ps.adj[count])
40+
for i in range(0,len(ps.shft[0])):
41+
gp.shifts.append(ps.shft[0][i])
42+
gp.left_threshold.append(ps.lt_th[0][i])
43+
gp.right_threshold.append(ps.rt_th[0][i])
4044
LeftTable = slo.load_obj('LeftTable')
4145
RightTable =slo.load_obj('RightTable')
4246
LeftList=slo.load_obj('LeftList')
34.8 KB
Binary file not shown.

0 commit comments

Comments
 (0)