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
question: how to select all glyphs contain a specific glyph component? #5075
Comments
Each glyph has a references list, which may be empty: https://fontforge.org/docs/scripting/python/fontforge.html#fontforge.glyph.references . If it isn't empty it contains a tuple where the first element is the referenced glyph name. So in your If you're using a recent version of FontForge each tuple has the selection status of the reference as its third element. So if you read out the list, copy the existing tuple elements into new tuples with the desired selection status, and assign everything back, you can modify the selection of those references. (Of course, since the transformation matrix is there you can also move them directly by changing the x and y displacements in those matrices.) |
thank you @skef ### move a referenced glyph(component) in all glyphs of a font by given font name, component_glyph_name, Δx and Δy
### usage:
### fontforge -script font_name component_glyph_name Δx Δy
### example:
### fontforge -script Arial circumflex -124 513
import os
import sys
import fontforge
font_name = sys.argv[1]
component_glyph_name = str(sys.argv[2])
delta_x = int(sys.argv[3])
delta_y = int(sys.argv[4])
font = fontforge.open(font_name + ".sfd")
for glyph in font.glyphs():
for glyph_data in glyph.references:
for i in range(len(glyph_data)):
if str(glyph_data[i]) == component_glyph_name:
glyph_references_list = list(glyph.references)
reference_matrix_list = list(glyph_data[i+1])
reference_matrix_list[4] += delta_x
reference_matrix_list[5] += delta_y
reference_matrix_tuple = tuple(reference_matrix_list)
glyph_references_list[i] = ((component_glyph_name, reference_matrix_tuple))
# print(glyph_references_list[i])
glyph.references = tuple(glyph_references_list)
font.save() it's working with a bit buggy result, for example i ran a test to move circumflex and realized not working as intended for letter E(like in Ê or Ế or any glyphs containing both circumflex and E). please take a look and do some test, there might be some unconsidered aspects. thank you. |
Hi
i need to select and move all components of a few specific glyphs, but it's hard to find and select theme manually, is there a way to select them by ff scripting?
something like this:
The text was updated successfully, but these errors were encountered: