1010
1111BASE_DIR = "C:/Ligatures"
1212nBins = 11
13- minHeight = 710
14- maxHeight = 780
13+ minHeight = 417
14+ maxHeight = 1400
1515shiftX = 200
1616scaling = 4.9 #2048 units per em font assumption, images are 300 dpi
1717DESC_RATE = 0.2 # per x-unit rate at which the bottom heigh descends where there is glyph data (extrapolation)
3232NUM_PIXEL_SCAN = 9 #number of horizontal pixels to scan
3333dXValid = [10 ,20 ,40 ,50 ,100 ] #valid values for dX
3434LookUp = {} #instantiate an empty dictionary
35+ GlyphHeight = []
3536haroofExceptions = ["alef.png" ,"alefwah" ] #define exception haroof here, these will have differnt default extrpolation height
3637animation = "|/-\\ "
3738def 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
0 commit comments