GithubHelp home page GithubHelp logo

checkparalleltool's People

Contributors

jtanadi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

checkparalleltool's Issues

Tool occasionally causes problems with glyph editor and font overview panels

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

  • Selecting things in the glyph editor is either limited or impossible (for instance cmd+a will select all glyphs in the font overview, rather than the contours in the glyph editor) and
  • Copying/pasting will apply not to the content of the glyph editor but rather the currently selected glyph in the font overview.

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.

Screen Shot 2019-11-09 at 10 18 26 PM

make it your self easier :)

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.