@@ -55,14 +55,31 @@ def run(argv):
5555 # ===========================================================
5656 # argparse command line argument definitions
5757 # ===========================================================
58- # TODO: add support for options to keep individual tables that are removed by default
5958 parser = argparse .ArgumentParser (
6059 description = "A tool for the removal of TrueType instruction sets (hints) in fonts"
6160 )
6261 parser .add_argument (
6362 "--version" , action = "version" , version = "dehinter v{}" .format (__version__ )
6463 )
6564 parser .add_argument ("-o" , "--out" , help = "out file path (dehinted font)" )
65+ parser .add_argument ("--keep-cvt" , help = "keep cvt table" , action = "store_true" )
66+ parser .add_argument ("--keep-fpgm" , help = "keep fpgm table" , action = "store_true" )
67+ parser .add_argument ("--keep-hdmx" , help = "keep hdmx table" , action = "store_true" )
68+ parser .add_argument ("--keep-ltsh" , help = "keep LTSH table" , action = "store_true" )
69+ parser .add_argument ("--keep-prep" , help = "keep prep table" , action = "store_true" )
70+ parser .add_argument ("--keep-ttfa" , help = "keep TTFA table" , action = "store_true" )
71+ parser .add_argument (
72+ "--keep-glyf" , help = "do not modify glyf table" , action = "store_true"
73+ )
74+ parser .add_argument (
75+ "--keep-gasp" , help = "do not modify gasp table" , action = "store_true"
76+ )
77+ parser .add_argument (
78+ "--keep-maxp" , help = "do not modify maxp table" , action = "store_true"
79+ )
80+ parser .add_argument (
81+ "--keep-head" , help = "do not modify head table" , action = "store_true"
82+ )
6683 parser .add_argument ("INFILE" , help = "in file path (hinted font)" )
6784
6885 args = parser .parse_args (argv )
@@ -113,77 +130,87 @@ def run(argv):
113130 )
114131 sys .exit (1 )
115132
116- if has_cvt_table (tt ):
117- remove_cvt_table (tt )
118- if not has_cvt_table (tt ):
119- print ("[-] Removed cvt table" )
120- else :
121- sys .stderr .write ("[!] Error: failed to remove cvt table from font" )
122-
123- if has_fpgm_table (tt ):
124- remove_fpgm_table (tt )
125- if not has_fpgm_table (tt ):
126- print ("[-] Removed fpgm table" )
127- else :
128- sys .stderr .write ("[!] Error: failed to remove fpgm table from font" )
129-
130- if has_hdmx_table (tt ):
131- remove_hdmx_table (tt )
132- if not has_hdmx_table (tt ):
133- print ("[-] Removed hdmx table" )
134- else :
135- sys .stderr .write ("[!] Error: failed to remove hdmx table from font" )
136-
137- if has_ltsh_table (tt ):
138- remove_ltsh_table (tt )
139- if not has_ltsh_table (tt ):
140- print ("[-] Removed LTSH table" )
141- else :
142- sys .stderr .write ("[!] Error: failed to remove LTSH table from font" )
143-
144- if has_prep_table (tt ):
145- remove_prep_table (tt )
146- if not has_prep_table (tt ):
147- print ("[-] Removed prep table" )
148- else :
149- sys .stderr .write ("[!] Error: failed to remove prep table from font" )
150-
151- if has_ttfa_table (tt ):
152- remove_ttfa_table (tt )
153- if not has_ttfa_table (tt ):
154- print ("[-] Removed TTFA table" )
155- else :
156- sys .stderr .write ("[!] Error: failed to remove TTFA table from font" )
133+ if not args .keep_cvt :
134+ if has_cvt_table (tt ):
135+ remove_cvt_table (tt )
136+ if not has_cvt_table (tt ):
137+ print ("[-] Removed cvt table" )
138+ else :
139+ sys .stderr .write ("[!] Error: failed to remove cvt table from font" )
140+
141+ if not args .keep_fpgm :
142+ if has_fpgm_table (tt ):
143+ remove_fpgm_table (tt )
144+ if not has_fpgm_table (tt ):
145+ print ("[-] Removed fpgm table" )
146+ else :
147+ sys .stderr .write ("[!] Error: failed to remove fpgm table from font" )
148+
149+ if not args .keep_hdmx :
150+ if has_hdmx_table (tt ):
151+ remove_hdmx_table (tt )
152+ if not has_hdmx_table (tt ):
153+ print ("[-] Removed hdmx table" )
154+ else :
155+ sys .stderr .write ("[!] Error: failed to remove hdmx table from font" )
156+
157+ if not args .keep_ltsh :
158+ if has_ltsh_table (tt ):
159+ remove_ltsh_table (tt )
160+ if not has_ltsh_table (tt ):
161+ print ("[-] Removed LTSH table" )
162+ else :
163+ sys .stderr .write ("[!] Error: failed to remove LTSH table from font" )
164+
165+ if not args .keep_prep :
166+ if has_prep_table (tt ):
167+ remove_prep_table (tt )
168+ if not has_prep_table (tt ):
169+ print ("[-] Removed prep table" )
170+ else :
171+ sys .stderr .write ("[!] Error: failed to remove prep table from font" )
172+
173+ if not args .keep_ttfa :
174+ if has_ttfa_table (tt ):
175+ remove_ttfa_table (tt )
176+ if not has_ttfa_table (tt ):
177+ print ("[-] Removed TTFA table" )
178+ else :
179+ sys .stderr .write ("[!] Error: failed to remove TTFA table from font" )
157180
158181 # (2) Remove glyf table instruction set bytecode
159- number_glyfs_edited = remove_glyf_instructions (tt )
160- if number_glyfs_edited > 0 :
161- print (
162- "[-] Removed glyf table instruction bytecode from {} glyphs" .format (
163- number_glyfs_edited
182+ if not args .keep_glyf :
183+ number_glyfs_edited = remove_glyf_instructions (tt )
184+ if number_glyfs_edited > 0 :
185+ print (
186+ "[-] Removed glyf table instruction bytecode from {} glyphs" .format (
187+ number_glyfs_edited
188+ )
164189 )
165- )
166190
167191 # (3) Edit gasp table
168- if has_gasp_table (tt ):
169- if update_gasp_table (tt ):
170- print (
171- "[Δ] New gasp table values:{} {}" .format (
172- os .linesep , pp .pformat (tt ["gasp" ].__dict__ )
192+ if not args .keep_gasp :
193+ if has_gasp_table (tt ):
194+ if update_gasp_table (tt ):
195+ print (
196+ "[Δ] New gasp table values:{} {}" .format (
197+ os .linesep , pp .pformat (tt ["gasp" ].__dict__ )
198+ )
173199 )
174- )
175200
176201 # (4) Edit maxp table
177- if update_maxp_table (tt ):
178- print (
179- "[Δ] New maxp table values:{} {}" .format (
180- os .linesep , pp .pformat (tt ["maxp" ].__dict__ )
202+ if not args .keep_maxp :
203+ if update_maxp_table (tt ):
204+ print (
205+ "[Δ] New maxp table values:{} {}" .format (
206+ os .linesep , pp .pformat (tt ["maxp" ].__dict__ )
207+ )
181208 )
182- )
183209
184210 # (5) Edit head table flags to clear bit 4
185- if update_head_table_flags (tt ):
186- print ("[Δ] Cleared bit 4 in head table flags" )
211+ if not args .keep_head :
212+ if update_head_table_flags (tt ):
213+ print ("[Δ] Cleared bit 4 in head table flags" )
187214
188215 # File write
189216 # ----------
0 commit comments