jtanadi / checkparalleltool Goto Github PK
View Code? Open in Web Editor NEWSimple tool to check handles in RF
Simple tool to check handles in RF
With this tool installed, pinching no longer works.
I've recently started having issues with the selection marquee stalling on mouseDragged when the cursor is outside of glyph view. I've tracked it down to this extension. See below:
May have something to do with
Occasionally, using Robofont with Check Parallel Tool installed will cause problems with the glyph editor and font overview panels and their relationship to one another. Typically, this means...
Typically the issue takes a while to manifest and it seems to me (from experiencing this several times) that the issue is triggered by opening multiple UFO files, one after the other. Sometimes just having a file open and opening another will trigger the issue.
Uninstalling Check Parallel Tool and restarting Robofont solves the issue. I've attached a screenshot here to show the other extensions I normally have installed.
Ideally, would update with Merz
hope this helps!!
import math
from mojo.events import EditingTool, installTool
import mojo.drawingTools as ctx
def distance(line):
p1, p2 = line
return math.sqrt((p2.x - p1.x)**2 + (p2.y - p1.y)**2)
def isPointInLine(point, line, scale):
p1, p2 = line
d1 = distance((p1, point))
d2 = distance((point, p2))
totalDistance = distance((p1, p2))
return abs(d1 + d2 - totalDistance) < 10 * scale
def areTheyParallel(line1, line2, tolerance=2):
"""
Checks if 2 lines are parallel by comparing their slopes
line1 and line2 should be a tuple of tuples each: ((x0, y0), (x1, y1))
tolerance defaults to 0
"""
p0, p1 = line1
p2, p3 = line2
# atan returns rads, so convert to angle
angle1 = abs(math.degrees(math.atan2((p1.y - p0.y), (p1.x - p0.x))))
angle2 = abs(math.degrees(math.atan2((p3.y - p2.y), (p3.x - p2.x))))
# instead of checking for absolute equality,
# allow for some tolerance
return abs(angle1 - angle2) <= tolerance
class MyTool(EditingTool):
def setup(self):
self._selectedSegments = []
self._selectedSegment = None
def _mouseDown(self, point, clickCount):
scale = self.getNSView().getGlyphViewScale()
self._selectedSegment = None
for p1, h1, h2, p2 in self._selectedSegments:
if isPointInLine(point, (h1, h2), scale):
self._selectedSegment = p1, h1, h2, p2
if not self._selectedSegment:
super()._mouseDown(point, clickCount)
self.extractSelection()
def mouseDragged(self, point, delta):
if self._selectedSegment:
# edit the point here
# but only the segment wich is close to the mouse
# rubberbanding other segments is weird...
pass
def mouseUp(self, point):
self.extractSelection()
def keyUp(self, event):
self.extractSelection()
def canSelectWithMarque(self):
if self._selectedSegments:
return False
return super().canSelectWithMarque()
def dragSelection(self, point, delta):
if not self._selectedSegments:
super().dragSelection(point, delta)
def draw(self, scale):
ctx.save()
ctx.strokeWidth(1 * scale)
for p1, h1, h2, p2 in self._selectedSegments:
ctx.stroke(1, 0, 0)
ctx.line((p1.x, p1.y), (p2.x, p2.y))
if areTheyParallel((p1, p2), (h1, h2)):
ctx.stroke(0, 0, 1)
if self._selectedSegment == (p1, h1, h2, p2):
ctx.strokeWidth(2 * scale)
else:
ctx.strokeWidth(1 * scale)
ctx.line((h1.x, h1.y), (h2.x, h2.y))
ctx.restore()
def extractSelection(self):
selection = []
for contour in self.getGlyph():
segments = contour.segments
for i, segment in enumerate(segments):
if segment.selected and segment.type in ["curve", "qcurve"]:
prev = segments[i - 1].onCurve
h1, h2, onCurve = segment
selection.append((prev, h1, h2, onCurve))
if selection != self._selectedSegments:
self._selectedSegments = selection
self.refreshView()
installTool(MyTool())
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.