def combinedBounds(rects):
    bottomLeft = NSPoint(1000.0, 100.0)
    topRight = NSPoint(0.0, 0.0)
    for thisRect in rects:
        bottomLeft.x = min(thisRect.origin.x, bottomLeft.x)
        bottomLeft.y = min(thisRect.origin.y, bottomLeft.y)
        topRight.x = max(topRight.x, thisRect.origin.x + thisRect.size.width)
        topRight.y = max(topRight.y, thisRect.origin.y + thisRect.size.height)
    combinedRect = NSRect()
    combinedRect.origin = bottomLeft
    combinedRect.size = NSSize(topRight.x - bottomLeft.x,
                               topRight.y - bottomLeft.y)
    return combinedRect
def makeAnchor( thisLayer, anchorName, x, y ):
	thisAnchorPosition   = NSPoint()
	thisAnchorPosition.x = x
	thisAnchorPosition.y = y
	thisAnchorName = anchorName
	
	thisAnchor = GSAnchor( thisAnchorName, thisAnchorPosition )
	thisLayer.addAnchor_( thisAnchor )
	
	print("-- %s (%.1f, %.1f)" % ( thisAnchorName, thisAnchorPosition.x, thisAnchorPosition.y ))
 def setRotateAnchor(self, sender):
     try:
         selectedLayers = Glyphs.currentDocument.selectedLayers()
         myRotationCenter = NSPoint()
         myRotationCenter.x = int(self.w.anchor_x.get())
         myRotationCenter.y = int(self.w.anchor_y.get())
         myRotationAnchor = GSAnchor("rotate", myRotationCenter)
         for thisLayer in selectedLayers:
             # adds 'rotate' if it doesn't exist, resets it if it exists:
             thisLayer.addAnchor_(myRotationAnchor)
     except Exception as e:
         self.logToConsole("setRotateAnchor: %s" % e)
 def insertRotateAnchor(self, sender=None):
     try:
         selectedLayers = Glyphs.currentDocument.selectedLayers()
         myRotationCenter = NSPoint()
         myRotationCenter.x = int(
             Glyphs.defaults["com.mekkablue.rotateAroundAnchor.anchor_x"])
         myRotationCenter.y = int(
             Glyphs.defaults["com.mekkablue.rotateAroundAnchor.anchor_y"])
         myRotationAnchor = GSAnchor("#%s" % rotateAnchorName,
                                     myRotationCenter)
         for thisLayer in selectedLayers:
             # adds '#rotate' if it doesn't exist, resets it if it exists:
             thisLayer.addAnchor_(myRotationAnchor)
     except Exception as e:
         import traceback
         print(traceback.format_exc())