Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix otfstemhist bugs #1703

Merged
merged 2 commits into from
Sep 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 14 additions & 8 deletions python/afdko/otfautohint/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,7 @@ def _parse_fontinfo_file(options, fontinfo_path):
options.hCounterGlyphs.update(glyphList)


def add_common_options(parser, term):
def add_common_options(parser, term, name):
parser_fonts = parser.add_argument(
'font_paths',
metavar='FONT',
Expand All @@ -516,9 +516,9 @@ def add_common_options(parser, term):
help='comma-separated sequence of glyphs to %s\n' % term +
'The glyph identifiers may be glyph indexes, glyph names, or '
'glyph CIDs. CID values must be prefixed with a forward slash.\n'
'Examples:\n'
' otfautohint -g A,B,C,69 MyFont.ufo\n'
' otfautohint -g /103,/434,68 MyCIDFont'
'Examples:\n' +
" otf%s -g A,B,C,69 MyFont.ufo\n" % name +
" otf%s -g /103,/434,68 MyCIDFont" % name
)
glyphs_parser.add_argument(
'--glyphs-file',
Expand Down Expand Up @@ -622,12 +622,14 @@ def handle_glyph_lists(options, parsed_args):
elif parsed_args.glyphs_to_hint_file:
options.explicitGlyphs = True
options.glyphList = _process_glyph_list_arg(
_read_txt_file(parsed_args.glyphs_to_hint_file),
_split_comma_sequence(
_read_txt_file(parsed_args.glyphs_to_hint_file)),
options.nameAliases)
elif parsed_args.glyphs_to_not_hint_file:
options.excludeGlyphList = True
options.glyphList = _process_glyph_list_arg(
_read_txt_file(parsed_args.glyphs_to_not_hint_file),
_split_comma_sequence(
_read_txt_file(parsed_args.glyphs_to_not_hint_file)),
options.nameAliases)

if parsed_args.overlaps_to_hint:
Expand All @@ -644,7 +646,7 @@ def get_options(args):
formatter_class=_CustomHelpFormatter,
description=__doc__
)
parser_fonts = add_common_options(parser, 'hint')
parser_fonts = add_common_options(parser, 'hint', 'autohint')
parser.add_argument(
'-o',
'--output',
Expand Down Expand Up @@ -877,7 +879,7 @@ def get_stemhist_options(args):
description='Stem and Alignment zones report for PostScript, '
'OpenType/CFF and UFO fonts.'
)
add_common_options(parser, 'report')
parser_fonts = add_common_options(parser, 'report', 'stemhist')
parser.add_argument(
'-o',
'--output',
Expand Down Expand Up @@ -915,6 +917,10 @@ def get_stemhist_options(args):

logging_conf(parsed_args.verbose, parsed_args.log_path)

if not len(parsed_args.font_paths):
parser.error(
f"the following arguments are required: {parser_fonts.metavar}")

if (parsed_args.output_paths and
len(parsed_args.font_paths) != len(parsed_args.output_paths)):
parser.error("number of input and output fonts differ")
Expand Down
68 changes: 45 additions & 23 deletions python/afdko/otfautohint/autohint.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,32 +92,54 @@ def justReporting(self):


def getGlyphNames(glyphSpec, fontGlyphList, fDesc):
glyphNameList = []
rangeList = glyphSpec.split("-")
try:
prevGID = fontGlyphList.index(rangeList[0])
except ValueError:
if len(rangeList) > 1:
log.warning("glyph ID <%s> in range %s from glyph selection "
"list option is not in font. <%s>.",
rangeList[0], glyphSpec, fDesc)
else:
# If the "range" is actually in the font, just ignore its apparent
# range-ness
if glyphSpec.isnumeric():
GID = int(glyphSpec)
if GID >= len(fontGlyphList):
log.warning("glyph ID <%s> from glyph selection list option "
"is not in font. <%s>.", rangeList[0], fDesc)
"exceeds number of glyphs in font <%s>.",
glyphSpec, fDesc)
return None
return [fontGlyphList[GID]]
elif glyphSpec in fontGlyphList:
return [glyphSpec]

rangeList = glyphSpec.split("-")
if len(rangeList) == 1:
# Not numeric, not name, not range
log.warning("glyph name <%s> from glyph selection list option is "
"not in font <%s>", glyphSpec, fDesc)
return None
elif len(rangeList) > 2:
log.warning("Too many hyphens in glyph selection range <%s>",
glyphSpec)
return None
glyphNameList.append(fontGlyphList[prevGID])

for glyphName2 in rangeList[1:]:
try:
gid = fontGlyphList.index(glyphName2)
except ValueError:
log.warning("glyph ID <%s> in range %s from glyph selection "
"list option is not in font. <%s>.",
glyphName2, glyphSpec, fDesc)
return None
for i in range(prevGID + 1, gid + 1):
glyphNameList.append(fontGlyphList[i])
prevGID = gid
glyphName1, glyphName2 = rangeList
gidList = []

for r in rangeList:
if r.isnumeric():
GID = int(r)
if GID >= len(fontGlyphList):
log.warning("glyph name <%s> in range %s from glyph "
"selection list option is not in font <%s>.",
r, glyphSpec, fDesc)
return None
else:
try:
GID = fontGlyphList.index(r)
except ValueError:
log.warning("glyph name <%s> in range %s from glyph "
"selection list option is not in font <%s>.",
r, glyphSpec, fDesc)
return None
gidList.append(GID)

glyphNameList = []
for i in range(gidList[0], gidList[1] + 1):
glyphNameList.append(fontGlyphList[i])

return glyphNameList

Expand Down
Loading