Esempio n. 1
0
#MenuTitle: Remove Nodes and Try to Keep Shape
# -*- coding: utf-8 -*-
from __future__ import division, print_function, unicode_literals
__doc__="""
Delete the selected on-curve nodes, but try to keep the shape of the path. Hold down Shift for balanced handles.
"""

from Foundation import NSEvent

thisFont = Glyphs.font # frontmost font
thisLayer = thisFont.selectedLayers[0] # first of active layers of selected glyphs
thisGlyph = thisLayer.parent # current glyph
selection = thisLayer.selection # node selection in edit mode

# check if Shift is held down:
shiftKeyFlag = 131072
shiftKeyPressed = NSEvent.modifierFlags() & shiftKeyFlag == shiftKeyFlag

if selection:
	selectedNodes = [obj for obj in selection if type(obj)==GSNode and obj.type==GSCURVE]
	if selectedNodes:
		thisGlyph.beginUndo() # begin undo grouping
		thisLayer.selection = None
		for thisNode in selectedNodes:
			thisPath = thisNode.parent
			if not shiftKeyPressed:
				thisPath.removeNodeCheckKeepShape_( thisNode )
			else:
				thisPath.removeNodeCheckKeepShape_normalizeHandles_( thisNode, True )
		thisGlyph.endUndo()   # end undo grouping
Esempio n. 2
0
#MenuTitle: Realign BCPs
# -*- coding: utf-8 -*-
from __future__ import division, print_function, unicode_literals
__doc__ = """
Realigns handles (BCPs) in current layers of selected glyphs. Useful for resetting out-of-sync handles, e.g., after a transform operation, after interpolation or after switching to a different grid. Hold down Option to process ALL layers of the glyph.
"""

from Foundation import NSPoint, NSEvent, NSNumber, NSMutableArray

optionKeyFlag = 524288
optionKeyPressed = NSEvent.modifierFlags() & optionKeyFlag == optionKeyFlag

thisFont = Glyphs.font
moveForward = NSPoint(1, 1)
moveBackward = NSPoint(-1, -1)
noModifier = NSNumber.numberWithUnsignedInteger_(0)
Tool = GlyphsPathPlugin.alloc().init()


def realignLayer(thisLayer):
    countOfHandlesOnLayer = 0
    for thisPath in thisLayer.paths:
        for thisNode in thisPath.nodes:
            if thisNode.type == GSOFFCURVE:
                countOfHandlesOnLayer += 1
                selectedNode = NSMutableArray.arrayWithObject_(thisNode)
                thisLayer.setSelection_(selectedNode)
                Tool.moveSelectionLayer_shadowLayer_withPoint_withModifier_(
                    thisLayer, thisLayer, moveForward, noModifier)
                Tool.moveSelectionLayer_shadowLayer_withPoint_withModifier_(
                    thisLayer, thisLayer, moveBackward, noModifier)
Esempio n. 3
0
    def update(self, sender):
        # check if Option key is pressed or not:
        optionKeyFlag = 524288
        optionKeyPressed = NSEvent.modifierFlags(
        ) & optionKeyFlag == optionKeyFlag

        # some predetermined guesses:
        betterGuesses = {
            "perthousand": "percent",
            "brokenbar": "bar",
            "daggerdbl": "dagger",
            "dollar": "S",
            "cent": "c",
            "Fhook": "florin",
            "endash": "hyphen",
            "emdash": "endash",
            "Eng": "N",
            "eng": "n",
            "thorn": "p",
            "Thorn": "I",
            "ae": "e",
            "oe": "e",
            "AE": "E",
            "OE": "E",
            "germandbls": "f",
            "Germandbls": "F",
        }

        thisFont = Glyphs.font
        if thisFont:
            if thisFont.selectedLayers:
                currentLayer = thisFont.selectedLayers[0]
                currentGlyph = currentLayer.parent

                # do predetermined guesses apply:
                if currentGlyph.name in betterGuesses:
                    glyphName = betterGuesses[currentGlyph.name]
                    self.w.componentName.set(glyphName)
                    self.SavePreferences(sender)
                    return True

                # check for the dot suffix:
                suffix = ""
                if "." in currentGlyph.name:
                    offset = currentGlyph.name.find(".")
                    suffix = currentGlyph.name[offset:]

                # if glyph info has components, take the base letter name:
                thisInfo = currentGlyph.glyphInfo
                if thisInfo and thisInfo.components:
                    firstComponentName = thisInfo.components[0].name
                    if firstComponentName:
                        if not optionKeyPressed:  # hold down OPT to ignore suffix
                            firstComponentName += suffix
                        self.w.componentName.set(firstComponentName)
                        self.SavePreferences(sender)
                        return True

                # no first component found, so try same name without suffix:
                if suffix:
                    self.w.componentName.set(currentGlyph.name[:offset])
                    self.SavePreferences(sender)
                    return True

        return False