Update font family in FormattedString



  • I'm hoping to use make an instance of a FormattedString(), set its font size and content, then make multiple pages in which only the font is changed. Ulimately, I'm trying to make a type proof in as simple a way as possible.

    The code below shows my current attempt. I would expect page 1 to have Helvetica, and page 2 to have Times New Roman. However, both have Helvetica. What am I missing?

    import datetime
    timestamp = datetime.datetime.now().strftime("%Y.%m.%d – %H:%M")
    
    W, H = 792, 612
    
    font("Courier")  # caption font
    fontSize = 12    # caption font size
    
    padding = 40
    
    lower = "\
    nnannooaoo nnbnnooboo nncnnoocoo nndnnoodoo nnennooeoo nnfnnoofoo\n\
    nngnnoogoo nnhnnoohoo nninnooioo nnjnnoojoo nnknnookoo nnlnnooloo\n\
    nnmnnoomoo nnpnnoopoo nnqnnooqoo nnrnnooroo nnsnnoosoo nntnnootoo\n\
    nnunnoouoo nnvnnoovoo nnwnnoowoo nnxnnooxoo nnynnooyoo nnznnoozoo\n\
    \n"
    
    upper = "\
    HHAHHOOAOO HHBHHOOBOO HHCHHOOCOO HHDHHOODOO HHEHHOOEOO HHFHHOOFOO\n\
    HHGHHOOGOO HHIHHOOIOO HHJHHOOJOO HHKHHOOKOO HHLHHOOLOO HHMHHOOMOO\n\
    HHNHHOONOO HHPHHOOPOO HHQHHOOQOO HHRHHOOROO HHSHHOOSOO HHTHHOOTOO\n\
    HHUHHOOUOO HHVHHOOVOO HHWHHOOWOO HHXHHOOXOO HHYHHOOYOO HHZHHOOZOO\n\
    \n"
    
    nums = "\
    0080088088 0010088188 0020088288 0030088388 0040088488\n\
    0050088588 0060088688 0070088788 0090088988\n"
    
    
    # ----------------------------------------
    # Setup proof content --------------------
    
    txt = FormattedString()
    txt.fontSize(18)
    
    txt += lower
    txt += upper
    txt.openTypeFeatures(ss01=True)
    txt += lower
    txt += nums
    
    # ----------------------------------------
    # First Page -----------------------------
    
    newPage('LetterLandscape')
    
    txt.font("Helvetica")
    text(txt, (padding, H-padding))
    
    text("Helvetica – " +
         timestamp, padding, padding)
    
    # ----------------------------------------
    # Next Page ------------------------------
    
    newPage('LetterLandscape')
    
    txt.font("Times New Roman")
    text(txt, (padding, H-padding))
    
    text("Times New Roman – " +
         timestamp, padding, padding)
    
    
    # ----------------------------------------
    # Save -----------------------------------
    
    print("saving")
    path = "/Users/stephennixon/type-repos/recursive/src/proofs/drawbot-basic-proof/exports/temp.pdf"
    saveImage(path)
    

  • admin

    Setting a font in a formatted string will only be used for text appended afterwards: txt.font(...) will not alter the font attribute for existing texts in the formatted string.

    For each page you will need to create a fresh formatted string.


Log in to reply