def foregroundInViewCoords(self, sender=None): layer = self.controller.activeLayer() scale = self.getScale() position = self.controller.selectedLayerOrigin windowController = self.controller.view().window().windowController() if windowController: tool = windowController.toolDrawDelegate() if (tool.isKindOfClass_(NSClassFromString("GlyphsToolText")) or tool.isKindOfClass_(NSClassFromString("GlyphsToolHand")) or tool.isKindOfClass_( NSClassFromString("GlyphsToolTrueTypeInstructor"))): return if scale < 0.5: return for path in layer.paths: for node in path.nodes: pt = node.position scaledPoint = NSMakePoint(pt.x * scale + position.x, pt.y * scale + position.y) # phi = degrees(angle(prev_pt, pt)) # if phi > 270 or -90 < phi < 90: # textAlignment = 5 # # top left: 6, top center: 7, top right: 8, center left: 3, center center: 4, center right: 5, bottom left: 0, bottom center: 1, bottom right: 2 # else: # textAlignment = 3 self.drawTextAtPoint(" %g, %g" % (pt.x, pt.y), scaledPoint, 6) for anchor in layer.anchors: pt = anchor.position scaledPoint = NSMakePoint(pt.x * scale + position.x, pt.y * scale + position.y) self.drawTextAtPoint(" %g, %g" % (pt.x, pt.y), scaledPoint, 6)
def foreground(self, layer): if self.should_update_report: #self.logToConsole( "_updateOutlineCheck: %s" % layer) self._updateOutlineCheck(layer) #self.logToConsole( "foreground: Errors: %s" % self.errors ) #self.should_update_report = False try: try: self.mouse_position = self.controller.graphicView( ).getActiveLocation_(Glyphs.currentEvent()) except Exception as e: self.logToConsole("foreground: mouse_position: %s" % str(e)) self.mouse_position = (0, 0) currentController = self.controller.view().window( ).windowController() if currentController: tool = currentController.toolDrawDelegate() # don't activate if on cursor tool, or pan tool if not (tool.isKindOfClass_( NSClassFromString("GlyphsToolText")) or tool.isKindOfClass_( NSClassFromString("GlyphsToolHand")) or tool.isKindOfClass_( NSClassFromString("GlyphsToolTrueTypeInstructor")) ): if len(self.errors) > 0: self._drawArrows() except Exception as e: self.logToConsole("foreground: %s" % str(e))
def background(self, layer): # Check if the drawing should be shown currentController = self.controller.view().window().windowController() if currentController: tool = currentController.toolDrawDelegate() if tool.isKindOfClass_(NSClassFromString("GlyphsToolText")) \ or tool.isKindOfClass_(NSClassFromString("GlyphsToolHand")) \ or tool.isKindOfClass_(NSClassFromString("ScrawlTool")): return # draw pixels data = layer.userData["%s.data" % plugin_id] if data is None: return try: data = NSImage.alloc().initWithData_(data) except: print("Error in image data of layer %s" % layer) return rect = layer.userData["%s.rect" % plugin_id] if rect is None: # The drawing rect was not stored in user data. # Deduce it from the layer/font metrics. font = layer.parent.parent pad = int(round(font.upm / 10)) # find master for image positioning (descender) try: descender = layer.parent.parent.masters[ layer.layerId].descender except KeyError: descender = int(round(font.upm / 5)) rect = NSMakeRect(-pad, descender - pad, 2 * pad + layer.width, 2 * pad + font.upm) else: # Use the rect from user data rect = NSMakeRect(*rect) NSGraphicsContext.saveGraphicsState() NSGraphicsContext.currentContext().setImageInterpolation_( NSImageInterpolationNone) if len(layer.paths) == 0: data.drawInRect_(rect) else: data.drawInRect_fromRect_operation_fraction_( rect, NSZeroRect, NSCompositeSourceOver, 0.2) NSGraphicsContext.restoreGraphicsState()
</div> </div> <!-- Disclaimer --> <p id="helptext" onmouseleave="vanish(this);"> Ctrl-R: Reset Charset. Ctrl-L: Latin1. Ctrl-J: LTR/RTL. Ctrl-C: Center. Ctrl-X: X-Ray. Not working? Please try in a newer macOS or use the <a href="https://www.google.com/chrome/">latest Chrome</a>. Pull mouse across this note to make it disappear. </p> </body> </html> """ % (samsaPlaceholder) # clears macro window log: Glyphs.clearLog() # Query app version: GLYPHSAPPVERSION = NSBundle.bundleForClass_(NSClassFromString( "GSMenu")).infoDictionary().objectForKey_("CFBundleShortVersionString") appVersionHighEnough = not GLYPHSAPPVERSION.startswith("1.") optionKeyFlag = 524288 optionKeyPressed = NSEvent.modifierFlags() & optionKeyFlag == optionKeyFlag shouldCreateSamsa = False if optionKeyPressed: shouldCreateSamsa = True if appVersionHighEnough: firstDoc = Glyphs.orderedDocuments()[0] thisFont = Glyphs.font # frontmost font exportPath = currentOTVarExportPath() # familyName = otVarFamilyName(thisFont) fullName = otVarFullName(thisFont) fileName = otVarFileName(thisFont)
def background(self, layer): # Check if the grid should be drawn currentController = self.controller.view().window().windowController() if currentController: tool = currentController.toolDrawDelegate() if (tool.isKindOfClass_(NSClassFromString("GlyphsToolText")) or tool.isKindOfClass_(NSClassFromString("GlyphsToolHand"))): return try: master = layer.parent.parent.masters[layer.layerId] except KeyError: return if master is None: return gx, gy, grid_type = getGrid(master) if gx == 0 or gy == 0: return if grid_type == "div": upm = layer.parent.parent.upm gx = upm / gx gy = upm / gy NSColor.lightGrayColor().set() NSBezierPath.setDefaultLineWidth_(0.6 / self.getScale()) max_x = int(layer.width // gx + 2) min_y = int(master.descender // gy) max_y = int(master.ascender // gy + 1) max_xx = max_x * gx min_yy = min_y * gy max_yy = max_y * gy for x in range(-1, max_x + 1): xx = gx * x NSBezierPath.strokeLineFromPoint_toPoint_(NSPoint(xx, min_yy), NSPoint(xx, max_yy)) for y in range(min_y, max_y + 1): yy = gy * y NSBezierPath.strokeLineFromPoint_toPoint_(NSPoint(-gx, yy), NSPoint(max_xx, yy)) # NSBezierPath.setDefaultLineWidth_(1.0/self.getScale()) s = int(round(12 / self.getScale())) s2 = s * 0.25 sel = int(round(13 / self.getScale())) for p in layer.paths: for n in p.nodes: if n.type != OFFCURVE: x = n.position.x y = n.position.y if n.selected: s1 = sel else: s1 = s if abs((abs(x) + 1) % gx - 1) < 0.5: NSBezierPath.strokeLineFromPoint_toPoint_( NSPoint(x - s2, y - s1), NSPoint(x - s2, y + s1)) NSBezierPath.strokeLineFromPoint_toPoint_( NSPoint(x + s2, y - s1), NSPoint(x + s2, y + s1)) if abs((abs(y) + 1) % gy - 1) < 0.5: NSBezierPath.strokeLineFromPoint_toPoint_( NSPoint(x - s1, y - s2), NSPoint(x + s1, y - s2)) NSBezierPath.strokeLineFromPoint_toPoint_( NSPoint(x - s1, y + s2), NSPoint(x + s1, y + s2))