コード例 #1
0
    def background(self, layer):
        try:
            NSColor.colorWithDeviceRed_green_blue_alpha_(0.2, 0.2, 0.2,
                                                         0.5).set()
            for a in layer.anchors:
                if a not in layer.selection:
                    continue
                for (l2,
                     otherAnchor) in self.matchingGlyphsAndAnchorsForAnchor(
                         layer, a):
                    if l2.parent.name in self.skipMark:
                        continue
                    anchorAnchorPos = NSPoint(
                        a.position.x - otherAnchor.position.x,
                        a.position.y - otherAnchor.position.y,
                    )
                    bez = NSBezierPath.bezierPath()
                    bez.appendBezierPath_(l2.bezierPath)

                    t = NSAffineTransform.transform()
                    t.translateXBy_yBy_(anchorAnchorPos.x, anchorAnchorPos.y)
                    bez.transformUsingAffineTransform_(t)
                    bez.fill()

        except:
            print("Oops!", sys.exc_info()[0], "occured.")
            traceback.print_exc(file=sys.stdout)
コード例 #2
0
    def drawFriends(self, layer):
        try:
            friends = self.currentWindow.glyphList.get()
        except:
            friends = None

        c = 0

        if friends:
            for friend in friends:
                if friend.get("Visibility", 0):
                    g = friend["layer"]
                    if g.completeBezierPath is not None:
                        bP = g.completeBezierPath.copy()
                        t = NSAffineTransform.transform()

                        if self.alignment == 1:
                            translateX = layer.width / 2.0 - g.width / 2.0 + friend[
                                "Position"]
                        elif self.alignment == 2:
                            translateX = layer.width - g.width + friend[
                                "Position"]
                        else:
                            translateX = int(friend["Position"])

                        t.translateXBy_yBy_(translateX, 0.0)
                        tM = t.transformStruct()
                        bP.applyTransform_(tM)

                        NSColor.colorWithDeviceRed_green_blue_alpha_(
                            1.0, 0.73, c, 0.35).set()
                        bP.fill()

                        c = (c + 0.27) % 1.0
コード例 #3
0
    def __init__(self):
        f = CurrentFont()
        if f is None:
            return
        if f.path is None:
            print("Save this font first!")
            return

        self.designSpaceModel = f.lib.get(self.designSpaceModelLibKey,
                                          "twobytwo")
        #print "self.designSpaceModel", self.designSpaceModel
        if self.designSpaceModel == "twobytwo":
            self.masterNames = [
                'narrow-thin', 'wide-thin', 'narrow-bold', 'wide-bold'
            ]
        elif self.designSpaceModel == "twobyone":
            self.masterNames = ['narrow-thin', 'wide-thin']
        rgbBlack = NSColor.colorWithDeviceRed_green_blue_alpha_(0, 0, 0, 1)
        rgbWhite = NSColor.colorWithDeviceRed_green_blue_alpha_(
            255, 255, 255, 1)
        self.shapeColor = rgbWhite
        self.backgroundColor = rgbBlack
        self.extrapolateMinValue = 0
        self.extrapolateMaxValue = 1
        self.w = vanilla.Window((500, 600),
                                "Responsive Lettering",
                                minSize=(300, 200))
        self.w.preview = HTMLView((0, 0, -0, -140))
        self.w.exportButton = vanilla.Button((-150, -30, -10, 20),
                                             "Export SVG",
                                             callback=self.cbExport)
        columnDescriptions = [
            dict(title="Glyphname", key="name", width=125),
            dict(title="Width", key="width", width=50),
            dict(title="Height", key="height", width=50),
            dict(title="Bounds?", key="bounds", width=75),
            dict(title="Contours", key="contours", width=50),
            dict(title="Points", key="points", width=50),
        ]
        self.w.l = vanilla.List((0, -140, -0, -40),
                                self.wrapGlyphs(),
                                columnDescriptions=columnDescriptions,
                                doubleClickCallback=self.callbackListClick)
        self.w.t = vanilla.TextBox((70, -27, -160, 20),
                                   "FontName",
                                   sizeStyle="small")
        self.w.backgroundColorWell = vanilla.ColorWell(
            (10, -30, 20, 20),
            callback=self.backgroundColorWellCallback,
            color=rgbBlack)
        self.w.shapeColorWell = vanilla.ColorWell(
            (35, -30, 20, 20),
            callback=self.shapeColorWellCallback,
            color=rgbWhite)

        self.w.bind("became main", self.windowBecameMainCallback)
        self.setColorsFromLib()
        self.update()
        self.w.open()
        self.cbMakePreview(None)
コード例 #4
0
ファイル: testAll.py プロジェクト: typesupply/vanilla
 def drawRect_(self, rect):
     if self.inLiveResize():
         self._recalcSize()
     from random import random
     NSColor.redColor().set()
     NSRectFill(self.bounds())
     width, height = self.frame()[1]
     w = width / 5
     h = height / 5
     for xI in range(5):
         for yI in range(5):
             x = xI * w
             y = height - (yI * h) - h
             r = ((x, y), (w, h))
             NSColor.colorWithDeviceRed_green_blue_alpha_(random(), random(), random(), 1.0).set()
             NSRectFill(r)
コード例 #5
0
 def drawRect_(self, rect):
     if self.inLiveResize():
         self._recalcSize()
     from random import random
     NSColor.redColor().set()
     NSRectFill(self.bounds())
     width, height = self.frame()[1]
     w = width / 5
     h = height / 5
     for xI in range(5):
         for yI in range(5):
             x = xI * w
             y = height - (yI * h) - h
             r = ((x, y), (w, h))
             NSColor.colorWithDeviceRed_green_blue_alpha_(random(), random(), random(), 1.0).set()
             NSRectFill(r)
コード例 #6
0
ファイル: drawingTools.py プロジェクト: pobivan/GlyphsSDK
def stroke(r=None, g=None, b=None, a=1):
	# Set the stroke color as RGB value.
	global currentStrokeColor
	if r is None:
		currentStrokeColor = None
	elif g is None:
		currentStrokeColor = NSColor.colorWithDeviceWhite_alpha_(r, a)
	else:
		currentStrokeColor = NSColor.colorWithDeviceRed_green_blue_alpha_(r, g, b, a)
コード例 #7
0
def stroke(r=None, g=None, b=None, a=1):
    # Set the stroke color as RGB value.
    global currentStrokeColor
    if r is None:
        currentStrokeColor = None
    elif g is None:
        currentStrokeColor = NSColor.colorWithDeviceWhite_alpha_(r, a)
    else:
        currentStrokeColor = NSColor.colorWithDeviceRed_green_blue_alpha_(
            r, g, b, a)
コード例 #8
0
ファイル: drawingTools.py プロジェクト: pobivan/GlyphsSDK
def fill(r=None, g=None, b=None, a=1):
	# Set the fill color as RGB value.
	global currentFillColor
	global currentGradient
	if r is None:
		currentFillColor = None
	elif g is None:
		currentFillColor = NSColor.colorWithDeviceWhite_alpha_(r, a)
		currentGradient = None
	else:
		currentFillColor = NSColor.colorWithDeviceRed_green_blue_alpha_(r, g, b, a)
		currentGradient = None
コード例 #9
0
def fill(r=None, g=None, b=None, a=1):
    # Set the fill color as RGB value.
    global currentFillColor
    global currentGradient
    if r is None:
        currentFillColor = None
    elif g is None:
        currentFillColor = NSColor.colorWithDeviceWhite_alpha_(r, a)
        currentGradient = None
    else:
        currentFillColor = NSColor.colorWithDeviceRed_green_blue_alpha_(
            r, g, b, a)
        currentGradient = None
コード例 #10
0
ファイル: overprinter.py プロジェクト: LettError/typeMedia
def drawOverprintLetter(items, fontSize, unitsPerEm):
    """ Let's put all the drawable items in a dict so that we can stack more than 2 if we want to. 
    
    This needs the new Drawbot to work. :)
    """
    maxGlyphWidth = None
    glyphHeight = fontSize
    for item in items:
        w = item['font'][item['glyphName']].width
        if maxGlyphWidth is None:
            maxGlyphWidth = w
        maxGlyphWidth = max(maxGlyphWidth, w)
    imageSize = (maxGlyphWidth*fontSize, unitsPerEm)
    overprintImage = NSImage.alloc().initWithSize_(imageSize)
    overprintImage.lockFocus()
    fontScale = float(fontSize) / unitsPerEm
    aT = NSAffineTransform.transform()
    aT.scaleBy_(fontScale)
    aT.concat()

    #gc = NSGraphicsContext.currentContext()
    #gp = gc.graphicsPort()
    #CGContextSetBlendMode(gp, kCGBlendModeMultiply)
    for item in items:
        save()
        f = item['font']
        color = item['color']
        #fill(color[0], color[1], color[2], color[3])
        nsc = NSColor.colorWithDeviceRed_green_blue_alpha_(color[0],color[1],color[2],color[3])
        nsc.set()
        c = CocoaPen(f)
        f[item["glyphName"]].draw(c)
        c.path.fill()
        #drawPath(c.path)
        restore()
    overprintImage.unlockFocus()
    # get drawbot to draw the image.
    image(overprintImage, (0,0))
コード例 #11
0
for glyph in Font.glyphs:
    for layer in glyph.layers:
        rgba = layer.userData.get(
            "com.typemytype.robofont.mark",  # Actually also used by vfb2ufo
            None,
        )
        if rgba is None:
            if set_colors:
                layer.color = 9223372036854775807
        else:
            r, g, b, a = rgba
            if set_colors:
                color = color_map.get((r, g, b, a), None)
                if color is None:
                    layer.colorObject = NSColor.colorWithDeviceRed_green_blue_alpha_(
                        r, g, b, a)
                    if (r, g, b, a) not in used_colors:
                        print(
                            "INFO: Unknown color (%g, %g, %g, %g) was applied directly, you may want to add a mapping for it in the script."
                            % (r, g, b, a))
                else:
                    layer.color = color
            used_colors |= set([(r, g, b, a)])
            if unset_userdata_colors:
                del layer.userData["com.typemytype.robofont.mark"]

        # print(glyph.name, layer, r, g, b, a)

print("Colors used in font:", list(used_colors))
コード例 #12
0
 def setBackgroundColor(self, color):
     r, g, b, a = color
     self.backgroundColor = color
     self.w.backgroundColorWell.set(NSColor.colorWithDeviceRed_green_blue_alpha_(r, g, b, a))
コード例 #13
0
 def setShapeColor(self, color):
     r, g, b, a = color
     self.shapeColor = color
     self.w.shapeColorWell.set(NSColor.colorWithDeviceRed_green_blue_alpha_(r, g, b, a))
コード例 #14
0
 def setBackgroundColor(self, color):
     r, g, b, a = color
     self.backgroundColor = color
     self.w.backgroundColorWell.set(
         NSColor.colorWithDeviceRed_green_blue_alpha_(r, g, b, a))
コード例 #15
0
 def setShapeColor(self, color):
     r, g, b, a = color
     self.shapeColor = color
     self.w.shapeColorWell.set(
         NSColor.colorWithDeviceRed_green_blue_alpha_(r, g, b, a))