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

question: how to select all glyphs contain a specific glyph component? #5075

Open
aminabedi68 opened this issue Jul 27, 2022 · 2 comments
Open

Comments

@aminabedi68
Copy link

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:

foreach
   if (check if glyph has that component)
       SelectMoreSingletons(glyph)
endloop
MoveReference(x,y,"glyph")
@skef
Copy link
Contributor

skef commented Jul 27, 2022

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 check you can iterate through that list to see if it contains a tuple with the name of interest.

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.)

@aminabedi68
Copy link
Author

aminabedi68 commented Jul 27, 2022

thank you @skef
i wrote a code based on your guide(modify component matrices):

### 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants