Group Details Private

administrators

  • RE: Using tkinter in DrawBot

    never used tkinter... DrawBot itself is made with `vanilla a pythonic wrapper around pyobjc.

    vanilla has all the dialogs you'll need!

    import vanilla
    
    result = vanilla.dialogs.getFileOrFolder()
    print(result)
    
    import vanilla
    help(vanilla.dialogs)
    
    posted in General Discussion
  • RE: Request: Barcode Generator

    An ImageObject as support to generate barcodes.

    fe: https://drawbot.com/content/image/imageObject.html#drawBot.context.tools.imageObject.ImageObject.code128BarcodeGenerator

    im = ImageObject()
    
    im.code128BarcodeGenerator((170, 32), message=b"hello world", quietSpace=0)
    image(im, (10, 10))
    
    

    Im making an issue to have the size argument optional.

    posted in Tutorials
  • RE: Scale text to fit rectangle?

    scale the canvas based on the dimension of your destination rectangle:

    # set a width height
    w, h = 396, 244
    # create a formattedString
    txt = FormattedString()
    # set a font
    txt.font("Times")
    # add some text
    txt += "kweti"
    
    #move it a bit
    translate(100, 100)
    # draw the black stroked rect
    fill(None)
    stroke(0)
    rect(0, 0, w, h)
    
    # create a path object
    path = BezierPath()
    # draw text into the path
    path.text(txt)
    # get the bounds of the path
    minx, miny, maxx, maxy = path.bounds()
    # get a scale value based on the bounding box
    scaleX = w / (maxx - minx)
    scaleY = h / (maxy - miny)
    # pick the smallest one and shift up to the middle in the other direction
    if scaleX < scaleY:
        scale(scaleX)
        shift = (h / scaleX - (maxy - miny)) / 2
        translate(0, shift)
    else:
        scale(scaleY)
        shift = (w / scaleY - (maxx - minx)) / 2
        translate(shift, 0)
    # translate witht the offset
    translate(-minx, -miny)
    # draw as text
    text(txt, (0, 0))
    
    posted in General Discussion
  • RE: Accessing opsz fontVariation

    frederik at typemytype.com should do it

    posted in Bugs
  • RE: Accessing opsz fontVariation

    mm, strange, could you share your font? (offline only with me or a simplified dummy example)

    thanks

    posted in Bugs
  • RE: Accessing opsz fontVariation

    works also fine on Big Sur (11.4)

    f1def8c5-efb8-42f9-9389-a0a5bd4f9003-image.png

    posted in Bugs
  • RE: Accessing opsz fontVariation

    what is your OS version?

    this simplified example works... on 10.13

    translate(50, 50)
    
    font('SourceSerif4Variable-Roman.ttf')
    fontSize(76)
    fontVariations(opsz=8)
    text("hello world", (0, 0))
    
    fontVariations(opsz=60)
    text("hello world", (0, 80))
    

    e1d61427-8ec7-406d-95a0-5ae9ea5056e0-image.png

    posted in Bugs
  • RE: Accessing opsz fontVariation

    cool hack, Gustavo

    Looking at a way to disable the automatic optical size scaling.

    posted in Bugs
  • RE: Accessing opsz fontVariation

    hello @craig,

    it looks like variable optical sizes are selected automatically based on the point size. you can then use scale() to make text bigger or smaller:

    opsz.png

    ttfPath = 'SourceSerif4Variable-Roman.ttf'
    txt = 'Handgloves'
    
    font(ttfPath)
    translate(20, 100)
    
    with savedState():
        scale(40)
        fontSize(6)
        text(txt, (0, 0))
    
    translate(0, 300)
    with savedState():
        scale(13)
        fontSize(19)
        text(txt, (0, 0))
    
    translate(0, 300)
    with savedState():
        scale(4)
        fontSize(72)
        text(txt, (0, 0))
    

    hope this helps! cheers

    posted in Bugs
  • RE: redrawing the font's contours + adding coordinates for manipulating

    he Szymon!

    a bezierPath object is not made to be editable. One way could be jumpt to a glyph object.

    or do a detour by cutting the path in four quarters and draw them seperatly

    # create a bezierPath
    path = BezierPath()
    # add text to the path with a font and fontSize
    path.text("P", font="Helvetica-Bold", fontSize=778)
    # move the page a bit
    translate(100, 100)
    # get the bounds of the path
    minx, miny, maxx, maxy = path.bounds()
    # calculate the width, height of the bounds
    # we only need half the width, height
    w = (maxx-minx) * .5
    h = (maxy-miny) * .5
    # create a bezierPath and add a quarter
    bottomLeft = BezierPath()
    bottomLeft.rect(minx, miny, w, h)
    # create a bezierPath and add a quarter
    bottomRight = BezierPath()
    bottomRight.rect(minx + w, miny, w, h)
    # create a bezierPath and add a quarter
    topLeft = BezierPath()
    topLeft.rect(minx, miny + h, w, h)
    # create a bezierPath and add a quarter
    topRight = BezierPath()
    topRight.rect(minx + w, miny + h, w, h)
    
    # only keep the path when both of the them are filled
    bottomLeft = bottomLeft & path
    bottomRight = bottomRight & path
    topLeft = topLeft & path
    topRight = topRight & path
    # start drawing
    with savedState():
        translate(w, h)
        skew(-30, 0)
        translate(-w, -h)
        fill(1, 0, 0)
        drawPath(bottomLeft)
        fill(1, 1, 0)
        drawPath(bottomRight)
        
    fill(0, 1, 0)
    drawPath(topLeft)
    fill(0, 1, 1)
    drawPath(topRight)
    

    df81aad8-11f9-4fb7-9b12-9f37a3937c21-image.png

    posted in Code snippets