Skip to content

Commit

Permalink
Merge pull request #947 from googlefonts/fix_color_layer_unicodes
Browse files Browse the repository at this point in the history
Ensure no unicodes for color layers
  • Loading branch information
anthrotype authored Sep 29, 2023
2 parents 8c0157e + 15fd0c9 commit 217564d
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
3 changes: 3 additions & 0 deletions Lib/glyphsLib/builder/color_layers.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,9 @@ def _to_ufo_color_layers(builder, ufo, master, layerMapping):
ufo_layer = builder.to_ufo_layer(glyph, masterLayer)
ufo_glyph = ufo_layer.newGlyph(layerGlyphName)
builder.to_ufo_glyph(ufo_glyph, layer, glyph, do_color_layers=False)
# Remove Unicode mapping from each color layer to avoid
# duplicate entries.
ufo_glyph.unicodes = []

attributes = layer.paths[0].attributes if layer.paths else {}
if "gradient" in attributes:
Expand Down
49 changes: 49 additions & 0 deletions tests/builder/builder_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1332,6 +1332,55 @@ def test_glyph_color_palette_layers_explode_v3(ufo_module):
assert len(ufo["a.color2"]) == 0


def test_glyph_color_layers_no_unicode_mapping(ufo_module):
font = generate_minimal_font()
glypha = add_glyph(font, "a")

glypha.unicode = "0061"

color0 = GSLayer()
color1 = GSLayer()
color2 = GSLayer()
color0.attributes["color"] = 1
color1.attributes["color"] = 1
color2.attributes["color"] = 1
glypha.layers.append(color0)
glypha.layers.append(color1)
glypha.layers.append(color2)

for i, layer in enumerate(glypha.layers):
path = GSPath()
path.nodes = [
GSNode(position=(i + 0, i + 0), nodetype="line"),
GSNode(position=(i + 100, i + 100), nodetype="line"),
GSNode(position=(i + 200, i + 200), nodetype="line"),
GSNode(position=(i + 300, i + 300), nodetype="line"),
]
if i == 1:
path.attributes["fillColor"] = [255, 124, 0, 225]
elif i == 2:
path.attributes["gradient"] = {
"colors": [[[0, 0, 0, 255], 0], [[185, 0, 0, 255], 1]],
"end": [0.2, 0.3],
"start": [0.4, 0.09],
}
elif i == 3:
path.attributes["gradient"] = {
"colors": [[[185, 0, 0, 255], 0], [[0, 0, 0, 255], 1]],
"end": [0.2, 0.3],
"start": [0.4, 0.09],
"type": "circle",
}
layer.paths.append(path)

ds = to_designspace(font, ufo_module=ufo_module, minimal=True)
ufo = ds.sources[0].font

assert ufo["a"].unicode == 97
assert ufo["a.color0"].unicode is None
assert ufo["a.color1"].unicode is None


def test_glyph_color_layers_explode(ufo_module):
font = generate_minimal_font(format_version=3)
glypha = add_glyph(font, "a")
Expand Down

0 comments on commit 217564d

Please sign in to comment.