Skip to content

Instantly share code, notes, and snippets.

@frankrolf
Created March 16, 2021 13:47
Show Gist options
  • Save frankrolf/841b46a259a1dc424054c33953c99681 to your computer and use it in GitHub Desktop.
Save frankrolf/841b46a259a1dc424054c33953c99681 to your computer and use it in GitHub Desktop.
Robofont: move selection around contour
from importlib import reload
import glyph_move_selection_forward
reload(glyph_move_selection_forward)
g = CurrentGlyph()
glyph_move_selection_forward.move_index(g, -1)
def single_next_index(contour, index, direction):
next_index = (index + direction) % len(contour.points)
if contour.points[next_index].type == 'offcurve':
next_index = single_next_index(contour, next_index, direction)
return next_index
def get_next_index(current_selection_index, direction):
new_selection_index = []
for contour, index in current_selection_index:
if contour.clockwise:
direction = direction * -1
next_index = single_next_index(contour, index, direction)
new_selection_index.append((contour, next_index))
return new_selection_index
def move_index(g, direction=1):
current_selection_index = [
(pt.contour, pt.index) for pt in g.selectedPoints]
g.deselect()
for contour, sel_index in get_next_index(
current_selection_index, direction
):
contour.points[sel_index].selected = True
if __name__ == '__main__':
g = CurrentGlyph()
move_index(g, 1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment