Is it possible to export to from Space Center to a multi-page or tall-page PDF?



  • Shoot, also: do you know if there a way to use the CurrentFont() as the font in a DrawBot script?

    My hope:

    • Write a RoboFont script that calls DrawBot as a module
    • Within that script, set the font with font(CurrentFont())
    • Get the text and sizing from the CurrentSpaceCenter()
    • Create a drawbot composition with these ingredients
    • Save to PDF

    The closest things I have found so far:

    Is there anything simpler? Either method above would take some level of fuss to make work...


  • admin

    hi @StephenNixon,

    do you know if there a way to use the CurrentFont() as the font in a DrawBot script?

    that’s not possible, because:

    • font() takes a string (font name or path to OpenType font file)
    • CurrentFont() returns an RFont object

    I see now that the SpaceCenter object is missing from the mojo.UI docs, hope to fix it soon. in the meantime, here’s a quick way to access it:

    from mojo.UI import CurrentSpaceCenter
    
    spaceCenter = CurrentSpaceCenter()
    print('glyph names:', spaceCenter.get())
    print('characters:', spaceCenter.getRaw())
    print('fontSize:', spaceCenter.getPointSize())
    print('lineheight:', spaceCenter.getLineHeight())
    print('tracking:', spaceCenter.getTracking())
    print('before:', spaceCenter.getPre())
    print('after:', spaceCenter.getAfter())
    
    # list all attributes & methods
    # print(dir(spaceCenter))
    

    Is there anything simpler?

    things are simple if you use the Space Center to proof on screen, and the DrawBot extension to generate PDFs (from UFOs or OTFs).

    using the Space Center to create multi-page PDFs is a nice idea, but you’ll need to fill in the gaps because the Space Center was not built to generate PDFs. that’s what makes the idea exciting: it takes some level of fun to make it work ;)


  • admin

    while working on the SpaceCenter API docs, I stumbled across the glyphRecords attribute, which returns the computed glyphs (including pre/after contexts, suffix, selected layer, etc). adding a bit of code to fold the glyphs into lines and pages, we can make a simple multi-page PDF exporter:

    '''SpaceCenter to multipage PDF'''
    
    from mojo.UI import CurrentSpaceCenter
    
    # --------
    # settings
    # --------
    
    pageSize = 'A4Landscape'
    margin = 40
    
    # ------------
    # calculations
    # ------------
    
    f = CurrentFont()
    spaceCenter = CurrentSpaceCenter()
    
    size(pageSize)
    
    s = spaceCenter.getPointSize() / f.info.unitsPerEm # scale factor
    L = (f.info.unitsPerEm + f.info.descender) * s # first line shift
    
    w = width()  - margin * 2
    h = height() - margin * 2
    x = margin
    y = height() - margin - L
    
    # ----------
    # make pages
    # ----------
    
    translate(x, y)
    scale(s)
    X, Y = 0, 0 
    
    for gr in spaceCenter.glyphRecords:
    
        # linebreak
        if (X + gr.glyph.width) * s > w:
            X = 0
            Y -= f.info.unitsPerEm * (1 + spaceCenter.getLineHeight() / 800)
    
        # pagebreak
        if (abs(Y * s) + L) > h:
            newPage(pageSize)
            translate(x, y)
            scale(s)
            X, Y = 0, 0 
    
        with savedState():
            translate(X, Y)
            drawGlyph(gr.glyph)
    
        X += gr.glyph.width
    

    Screen Shot 2019-06-27 at 13.16.20.png

    Screen Shot 2019-06-27 at 13.16.26.png

    you could try adding more features: font name, page number, date and time, glyph metrics, vertical metrics…

    I hope this is useful!



  • Hey Gustavo,

    This is amazing; thanks so much for going above and beyond, yet again!

    I definitely agree that it's fun to figure this stuff out; I just like to feel relatively confident that I'm not doing something the slow way if there's something simple that I haven't noticed.

    I'll try this on proofing very soon, and update the thread with my improvements! :)



  • @ThunderNixon I still just use indesign and build proofs manually. Don't worry, you're fine :D



  • @FosterType haha, thanks for letting me know!

    Sometimes, InDesign is definitely the fastest way forward. Other times, though, the siren song of a "one-click" proof is pretty compelling...


  • admin

    it all depends on when the proof is needed in a scope of a design process: is it for you only, for a client, for collaborating typedesigners, your boss...



  • it all depends on when the proof is needed in a scope of a design process

    In this case, I am proofing my own work, plus collaborating with others on UFOs. I want to find the quickest way to look at the glyphs they are drawing and give feedback.

    So far, a handy way to do this has been to export the space center to a PDF, which I draw on with the iPad app, Notability. I can then email/screenshot those proofs. It would take longer to do a TestInstall(), then set up a proof in InDesign to make a PDF, then proof that – especially because the TestInstall might conflict with existing versions of the font I have installed on my computer, in general (unless I change naming, but then that's a whole other set of steps).



  • Question for @gferreira or @frederik

    Having tried Gustavo's excellent starter script, it's a really helpful start! I am now trying to make the text scale so that the PDF width will match the Space Center width, and therefore make it easier to layout basic proofs, right in the Space Center.

    However, I'm not quite sure how to get a value for the Space Center width.

    If I use help(CurrentSpaceCenter()), I see (among other things) what seems to be the answer:

     |  getPosSize(self)
     |      The position and size of the object as a tuple of form *(left, top, width, height)*.
    

    However, if I then use print(CurrentSpaceCenter().getPosSize()), I simply get this:

    (0, 0, 0, 0)
    

    Needless to say, my current Space Center is not 0 in size. It looks like this:

    04d220f9-c31b-4b27-9ed2-8908bfb79c60-image.png

    Am I perhaps missing some way to access this value from VanillaBaseObject?


  • admin

    @StephenNixon this will give you the current width & height of the Space Center window:

    from mojo.UI import CurrentSpaceCenter
    (x, y), (w, h) = CurrentSpaceCenter().getNSView().bounds()
    print(w, h)