Fix --codes option not working when running calibre-debug --subset-font

Also allow specifying codes in U+ or hexadecimal notation.
This commit is contained in:
Kovid Goyal 2015-06-07 08:24:56 +05:30
parent 460b69054c
commit 07239946d7
2 changed files with 12 additions and 6 deletions

View File

@ -31,7 +31,8 @@ Everything after the -- is passed to the script.
''')) '''))
parser.add_option('-c', '--command', help=_('Run python code.')) parser.add_option('-c', '--command', help=_('Run python code.'))
parser.add_option('-e', '--exec-file', help=_('Run the python code in file.')) parser.add_option('-e', '--exec-file', help=_('Run the python code in file.'))
parser.add_option('-f', '--subset-font', help=_('Subset the specified font')) parser.add_option('-f', '--subset-font', action='store_true', default=False,
help=_('Subset the specified font. Use -- after this option to pass option to the font subsetting program.'))
parser.add_option('-d', '--debug-device-driver', default=False, action='store_true', parser.add_option('-d', '--debug-device-driver', default=False, action='store_true',
help=_('Debug device detection')) help=_('Debug device detection'))
parser.add_option('-g', '--gui', default=False, action='store_true', parser.add_option('-g', '--gui', default=False, action='store_true',
@ -258,7 +259,7 @@ def main(args=sys.argv):
shutdown_other() shutdown_other()
elif opts.subset_font: elif opts.subset_font:
from calibre.utils.fonts.sfnt.subset import main from calibre.utils.fonts.sfnt.subset import main
main(['subset-font']+[opts.subset_font]+args[1:]) main(['subset-font'] + args[1:])
elif opts.exec_file: elif opts.exec_file:
run_script(opts.exec_file, args[1:]) run_script(opts.exec_file, args[1:])
elif opts.run_plugin: elif opts.run_plugin:

View File

@ -12,6 +12,7 @@ from collections import OrderedDict
from operator import itemgetter from operator import itemgetter
from functools import partial from functools import partial
from calibre.utils.icu import safe_chr
from calibre.utils.fonts.sfnt.container import Sfnt from calibre.utils.fonts.sfnt.container import Sfnt
from calibre.utils.fonts.sfnt.errors import UnsupportedFont, NoGlyphs from calibre.utils.fonts.sfnt.errors import UnsupportedFont, NoGlyphs
@ -237,6 +238,11 @@ def main(args):
prints(c, 'is not a single character', file=sys.stderr) prints(c, 'is not a single character', file=sys.stderr)
raise SystemExit(1) raise SystemExit(1)
def conv_code(c):
if c.upper()[:2] in ('U+', '0X'):
c = int(c[2:], 16)
return safe_chr(int(c))
for c in chars: for c in chars:
if '-' in c: if '-' in c:
parts = [x.strip() for x in c.split('-')] parts = [x.strip() for x in c.split('-')]
@ -244,12 +250,12 @@ def main(args):
prints('Invalid range:', c, file=sys.stderr) prints('Invalid range:', c, file=sys.stderr)
raise SystemExit(1) raise SystemExit(1)
if opts.codes: if opts.codes:
parts = tuple(map(unichr, map(int, parts))) parts = tuple(map(conv_code, parts))
map(not_single, parts) map(not_single, parts)
ranges.add(tuple(parts)) ranges.add(tuple(parts))
else: else:
if opts.codes: if opts.codes:
c = unichr(int(c)) c = conv_code(c)
not_single(c) not_single(c)
individual.add(c) individual.add(c)
st = time.time() st = time.time()
@ -325,8 +331,7 @@ def all():
print ('Failed!') print ('Failed!')
failed.append((font['full_name'], font['path'], unicode(e))) failed.append((font['full_name'], font['path'], unicode(e)))
else: else:
averages.append(sum(new_stats.itervalues())/sum(old_stats.itervalues()) averages.append(sum(new_stats.itervalues())/sum(old_stats.itervalues()) * 100)
* 100)
print ('Reduced to:', '%.1f'%averages[-1] , '%') print ('Reduced to:', '%.1f'%averages[-1] , '%')
if unsupported: if unsupported:
print ('\n\nUnsupported:') print ('\n\nUnsupported:')