[interpolatable] Return master indices in addition to master names (#3346)
[interpolatable] Add master indices to problem reports More solid than using names to refer back to the master index, as needed in interpolatablePlot.
This commit is contained in:
parent
82f44a6b45
commit
51e70f9742
@ -321,10 +321,15 @@ def test_gen(
|
|||||||
allGlyphs = [glyphset[glyph_name] for glyphset in glyphsets]
|
allGlyphs = [glyphset[glyph_name] for glyphset in glyphsets]
|
||||||
if len([1 for glyph in allGlyphs if glyph is not None]) <= 1:
|
if len([1 for glyph in allGlyphs if glyph is not None]) <= 1:
|
||||||
continue
|
continue
|
||||||
for glyph, glyphset, name in zip(allGlyphs, glyphsets, names):
|
for master_idx, (glyph, glyphset, name) in enumerate(
|
||||||
|
zip(allGlyphs, glyphsets, names)
|
||||||
|
):
|
||||||
if glyph is None:
|
if glyph is None:
|
||||||
if not ignore_missing:
|
if not ignore_missing:
|
||||||
yield (glyph_name, {"type": "missing", "master": name})
|
yield (
|
||||||
|
glyph_name,
|
||||||
|
{"type": "missing", "master": name, "master_idx": master_idx},
|
||||||
|
)
|
||||||
allNodeTypes.append(None)
|
allNodeTypes.append(None)
|
||||||
allControlVectors.append(None)
|
allControlVectors.append(None)
|
||||||
allGreenVectors.append(None)
|
allGreenVectors.append(None)
|
||||||
@ -359,7 +364,12 @@ def test_gen(
|
|||||||
except OpenContourError as e:
|
except OpenContourError as e:
|
||||||
yield (
|
yield (
|
||||||
glyph_name,
|
glyph_name,
|
||||||
{"master": name, "contour": ix, "type": "open_path"},
|
{
|
||||||
|
"master": name,
|
||||||
|
"master_idx": master_idx,
|
||||||
|
"contour": ix,
|
||||||
|
"type": "open_path",
|
||||||
|
},
|
||||||
)
|
)
|
||||||
continue
|
continue
|
||||||
contourGreenVectors.append(_contour_vector_from_stats(greenStats))
|
contourGreenVectors.append(_contour_vector_from_stats(greenStats))
|
||||||
@ -405,6 +415,8 @@ def test_gen(
|
|||||||
"type": "path_count",
|
"type": "path_count",
|
||||||
"master_1": names[m0idx],
|
"master_1": names[m0idx],
|
||||||
"master_2": names[m1idx],
|
"master_2": names[m1idx],
|
||||||
|
"master_1_idx": m0idx,
|
||||||
|
"master_2_idx": m1idx,
|
||||||
"value_1": len(m0),
|
"value_1": len(m0),
|
||||||
"value_2": len(m1),
|
"value_2": len(m1),
|
||||||
},
|
},
|
||||||
@ -423,6 +435,8 @@ def test_gen(
|
|||||||
"path": pathIx,
|
"path": pathIx,
|
||||||
"master_1": names[m0idx],
|
"master_1": names[m0idx],
|
||||||
"master_2": names[m1idx],
|
"master_2": names[m1idx],
|
||||||
|
"master_1_idx": m0idx,
|
||||||
|
"master_2_idx": m1idx,
|
||||||
"value_1": len(nodes1),
|
"value_1": len(nodes1),
|
||||||
"value_2": len(nodes2),
|
"value_2": len(nodes2),
|
||||||
},
|
},
|
||||||
@ -438,6 +452,8 @@ def test_gen(
|
|||||||
"node": nodeIx,
|
"node": nodeIx,
|
||||||
"master_1": names[m0idx],
|
"master_1": names[m0idx],
|
||||||
"master_2": names[m1idx],
|
"master_2": names[m1idx],
|
||||||
|
"master_1_idx": m0idx,
|
||||||
|
"master_2_idx": m1idx,
|
||||||
"value_1": n1,
|
"value_1": n1,
|
||||||
"value_2": n2,
|
"value_2": n2,
|
||||||
},
|
},
|
||||||
@ -510,6 +526,8 @@ def test_gen(
|
|||||||
"type": "contour_order",
|
"type": "contour_order",
|
||||||
"master_1": names[m0idx],
|
"master_1": names[m0idx],
|
||||||
"master_2": names[m1idx],
|
"master_2": names[m1idx],
|
||||||
|
"master_1_idx": m0idx,
|
||||||
|
"master_2_idx": m1idx,
|
||||||
"value_1": list(range(len(m0Control))),
|
"value_1": list(range(len(m0Control))),
|
||||||
"value_2": matching,
|
"value_2": matching,
|
||||||
},
|
},
|
||||||
@ -543,6 +561,8 @@ def test_gen(
|
|||||||
"contour": ix,
|
"contour": ix,
|
||||||
"master_1": names[m0idx],
|
"master_1": names[m0idx],
|
||||||
"master_2": names[m1idx],
|
"master_2": names[m1idx],
|
||||||
|
"master_1_idx": m0idx,
|
||||||
|
"master_2_idx": m1idx,
|
||||||
"value_1": 0,
|
"value_1": 0,
|
||||||
"value_2": contour1[min_cost_idx][1],
|
"value_2": contour1[min_cost_idx][1],
|
||||||
"reversed": reverse,
|
"reversed": reverse,
|
||||||
@ -820,14 +840,21 @@ def main(args=None):
|
|||||||
if glyphname != last_glyphname:
|
if glyphname != last_glyphname:
|
||||||
print(f"Glyph {glyphname} was not compatible:", file=f)
|
print(f"Glyph {glyphname} was not compatible:", file=f)
|
||||||
last_glyphname = glyphname
|
last_glyphname = glyphname
|
||||||
last_masters = None
|
last_master_idxs = None
|
||||||
|
|
||||||
masters = (
|
master_idxs = (
|
||||||
(p["master"]) if "master" in p else (p["master_1"], p["master_2"])
|
(p["master_idx"])
|
||||||
|
if "master_idx" in p
|
||||||
|
else (p["master_1_idx"], p["master_2_idx"])
|
||||||
)
|
)
|
||||||
if masters != last_masters:
|
if master_idxs != last_master_idxs:
|
||||||
print(f" Masters: %s:" % ", ".join(masters), file=f)
|
master_names = (
|
||||||
last_masters = masters
|
(p["master"])
|
||||||
|
if "master" in p
|
||||||
|
else (p["master_1"], p["master_2"])
|
||||||
|
)
|
||||||
|
print(f" Masters: %s:" % ", ".join(master_names), file=f)
|
||||||
|
last_master_idxs = master_idxs
|
||||||
|
|
||||||
if p["type"] == "missing":
|
if p["type"] == "missing":
|
||||||
print(" Glyph was missing in master %s" % p["master"], file=f)
|
print(" Glyph was missing in master %s" % p["master"], file=f)
|
||||||
|
@ -148,7 +148,9 @@ class InterpolatablePlot:
|
|||||||
current_glyph_problems = []
|
current_glyph_problems = []
|
||||||
for p in glyph_problems:
|
for p in glyph_problems:
|
||||||
masters = (
|
masters = (
|
||||||
p["master"] if "master" in p else (p["master_1"], p["master_2"])
|
p["master_idx"]
|
||||||
|
if "master_idx" in p
|
||||||
|
else (p["master_1_idx"], p["master_2_idx"])
|
||||||
)
|
)
|
||||||
if masters == last_masters:
|
if masters == last_masters:
|
||||||
current_glyph_problems.append(p)
|
current_glyph_problems.append(p)
|
||||||
@ -176,10 +178,11 @@ class InterpolatablePlot:
|
|||||||
log.info("Drawing %s: %s", glyphname, problem_type)
|
log.info("Drawing %s: %s", glyphname, problem_type)
|
||||||
|
|
||||||
master_keys = (
|
master_keys = (
|
||||||
("master",) if "master" in problems[0] else ("master_1", "master_2")
|
("master_idx",)
|
||||||
|
if "master_idx" in problems[0]
|
||||||
|
else ("master_1_idx", "master_2_idx")
|
||||||
)
|
)
|
||||||
master_names = [problems[0][k] for k in master_keys]
|
master_indices = [problems[0][k] for k in master_keys]
|
||||||
master_indices = [self.names.index(n) for n in master_names]
|
|
||||||
|
|
||||||
if problem_type == "missing":
|
if problem_type == "missing":
|
||||||
sample_glyph = next(
|
sample_glyph = next(
|
||||||
|
@ -47,7 +47,7 @@ class InterpolatableTest(unittest.TestCase):
|
|||||||
for p in all_files:
|
for p in all_files:
|
||||||
if p.startswith(prefix) and p.endswith(suffix):
|
if p.startswith(prefix) and p.endswith(suffix):
|
||||||
file_list.append(os.path.abspath(os.path.join(folder, p)))
|
file_list.append(os.path.abspath(os.path.join(folder, p)))
|
||||||
return file_list
|
return sorted(file_list)
|
||||||
|
|
||||||
def temp_path(self, suffix):
|
def temp_path(self, suffix):
|
||||||
self.temp_dir()
|
self.temp_dir()
|
||||||
@ -136,18 +136,20 @@ class InterpolatableTest(unittest.TestCase):
|
|||||||
# without --ignore-missing
|
# without --ignore-missing
|
||||||
problems = interpolatable_main(["--quiet"] + ttf_paths)
|
problems = interpolatable_main(["--quiet"] + ttf_paths)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
problems["a"], [{"type": "missing", "master": "SparseMasters-Medium"}]
|
problems["a"],
|
||||||
|
[{"type": "missing", "master": "SparseMasters-Medium", "master_idx": 1}],
|
||||||
)
|
)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
problems["s"], [{"type": "missing", "master": "SparseMasters-Medium"}]
|
problems["s"],
|
||||||
|
[{"type": "missing", "master": "SparseMasters-Medium", "master_idx": 1}],
|
||||||
)
|
)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
problems["edotabove"],
|
problems["edotabove"],
|
||||||
[{"type": "missing", "master": "SparseMasters-Medium"}],
|
[{"type": "missing", "master": "SparseMasters-Medium", "master_idx": 1}],
|
||||||
)
|
)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
problems["dotabovecomb"],
|
problems["dotabovecomb"],
|
||||||
[{"type": "missing", "master": "SparseMasters-Medium"}],
|
[{"type": "missing", "master": "SparseMasters-Medium", "master_idx": 1}],
|
||||||
)
|
)
|
||||||
|
|
||||||
# normal order, with --ignore-missing
|
# normal order, with --ignore-missing
|
||||||
@ -172,18 +174,20 @@ class InterpolatableTest(unittest.TestCase):
|
|||||||
# without --ignore-missing
|
# without --ignore-missing
|
||||||
problems = interpolatable_main(["--quiet"] + ufo_paths)
|
problems = interpolatable_main(["--quiet"] + ufo_paths)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
problems["a"], [{"type": "missing", "master": "SparseMasters-Medium"}]
|
problems["a"],
|
||||||
|
[{"type": "missing", "master": "SparseMasters-Medium", "master_idx": 1}],
|
||||||
)
|
)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
problems["s"], [{"type": "missing", "master": "SparseMasters-Medium"}]
|
problems["s"],
|
||||||
|
[{"type": "missing", "master": "SparseMasters-Medium", "master_idx": 1}],
|
||||||
)
|
)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
problems["edotabove"],
|
problems["edotabove"],
|
||||||
[{"type": "missing", "master": "SparseMasters-Medium"}],
|
[{"type": "missing", "master": "SparseMasters-Medium", "master_idx": 1}],
|
||||||
)
|
)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
problems["dotabovecomb"],
|
problems["dotabovecomb"],
|
||||||
[{"type": "missing", "master": "SparseMasters-Medium"}],
|
[{"type": "missing", "master": "SparseMasters-Medium", "master_idx": 1}],
|
||||||
)
|
)
|
||||||
|
|
||||||
# normal order, with --ignore-missing
|
# normal order, with --ignore-missing
|
||||||
@ -206,18 +210,20 @@ class InterpolatableTest(unittest.TestCase):
|
|||||||
|
|
||||||
problems = interpolatable_main(["--quiet", designspace_path])
|
problems = interpolatable_main(["--quiet", designspace_path])
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
problems["a"], [{"type": "missing", "master": "SparseMasters-Medium"}]
|
problems["a"],
|
||||||
|
[{"type": "missing", "master": "SparseMasters-Medium", "master_idx": 1}],
|
||||||
)
|
)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
problems["s"], [{"type": "missing", "master": "SparseMasters-Medium"}]
|
problems["s"],
|
||||||
|
[{"type": "missing", "master": "SparseMasters-Medium", "master_idx": 1}],
|
||||||
)
|
)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
problems["edotabove"],
|
problems["edotabove"],
|
||||||
[{"type": "missing", "master": "SparseMasters-Medium"}],
|
[{"type": "missing", "master": "SparseMasters-Medium", "master_idx": 1}],
|
||||||
)
|
)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
problems["dotabovecomb"],
|
problems["dotabovecomb"],
|
||||||
[{"type": "missing", "master": "SparseMasters-Medium"}],
|
[{"type": "missing", "master": "SparseMasters-Medium", "master_idx": 1}],
|
||||||
)
|
)
|
||||||
|
|
||||||
# normal order, with --ignore-missing
|
# normal order, with --ignore-missing
|
||||||
@ -229,18 +235,20 @@ class InterpolatableTest(unittest.TestCase):
|
|||||||
|
|
||||||
problems = interpolatable_main(["--quiet", glyphsapp_path])
|
problems = interpolatable_main(["--quiet", glyphsapp_path])
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
problems["a"], [{"type": "missing", "master": "Sparse Masters-Medium"}]
|
problems["a"],
|
||||||
|
[{"type": "missing", "master": "Sparse Masters-Medium", "master_idx": 1}],
|
||||||
)
|
)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
problems["s"], [{"type": "missing", "master": "Sparse Masters-Medium"}]
|
problems["s"],
|
||||||
|
[{"type": "missing", "master": "Sparse Masters-Medium", "master_idx": 1}],
|
||||||
)
|
)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
problems["edotabove"],
|
problems["edotabove"],
|
||||||
[{"type": "missing", "master": "Sparse Masters-Medium"}],
|
[{"type": "missing", "master": "Sparse Masters-Medium", "master_idx": 1}],
|
||||||
)
|
)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
problems["dotabovecomb"],
|
problems["dotabovecomb"],
|
||||||
[{"type": "missing", "master": "Sparse Masters-Medium"}],
|
[{"type": "missing", "master": "Sparse Masters-Medium", "master_idx": 1}],
|
||||||
)
|
)
|
||||||
|
|
||||||
# normal order, with --ignore-missing
|
# normal order, with --ignore-missing
|
||||||
|
Loading…
x
Reference in New Issue
Block a user