Text Properties

drawBot.font(fontName, fontSize=None)

Set a font with the name of the font. Optionally a fontSize can be set directly. The default font, also used as fallback font, is ‘LucidaGrande’. The default fontSize is 10pt.

The name of the font relates to the font’s postscript name.

font("Times-Italic")
drawBot.fontSize(fontSize)

Set the font size in points. The default fontSize is 10pt.

fontSize(30)
drawBot.hyphenation(value)

Set hyphenation, True or False.

txt = """Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi. Nam liber tempor cum soluta nobis eleifend option congue nihil imperdiet doming id quod mazim placerat facer possim assum. Typi non habent claritatem insitam; est usus legentis in iis qui facit eorum claritatem. Investigationes demonstraverunt lectores legere me lius quod ii legunt saepius. Claritas est etiam processus dynamicus, qui sequitur mutationem consuetudium lectorum. Mirum est notare quam littera gothica, quam nunc putamus parum claram, anteposuerit litterarum formas humanitatis per seacula quarta decima et quinta decima. Eodem modo typi, qui nunc nobis videntur parum clari, fiant sollemnes in futurum."""

hyphenation(True)
textBox(txt, (10, 10, 200, 200))
drawBot.lineHeight(value)

Set the line height.

lineHeight(20)
textBox("Hello\nWorld", (10, 10, 100, 100))
drawBot.openTypeFeatures(frac=True, case=True, ...)

Enable OpenType features.

Supported OpenType tags:

c2pc, c2sc, calt, case, cpsp, cswh, dlig, frac, liga, lnum, onum, ordn, pnum, rlig, sinf, smcp, ss01, ss02, ss03, ss04, ss05, ss06, ss07, ss08, ss09, ss10, ss11, ss12, ss13, ss14, ss15, ss16, ss17, ss18, ss19, ss20, subs, sups, swsh, titl, tnum
# set a font
font("Hoefler Text")
# set the font size
fontSize(50)
# draw a string
text("aa1465", (100, 200))
# enable some OpenType features
openTypeFeatures(lnum=True, smcp=True)
# draw the same string
text("aa1465", (100, 100))

Font Properties

drawBot.fontDescender()

Returns the current font descender, based on the current font and fontSize.

drawBot.fontAscender()

Returns the current font ascender, based on the current font and fontSize.

drawBot.fontXHeight()

Returns the current font x-height, based on the current font and fontSize.

drawBot.fontCapHeight()

Returns the current font cap height, based on the current font and fontSize.

drawBot.fontLeading()

Returns the current font leading, based on the current font and fontSize.

drawBot.fontLineHeight()

Returns the current line height, based on the current font and fontSize. If a lineHeight is set, this value will be returned.

txt = "Hello World"
x, y = 10, 100

# set a font
font("Helvetica")
# set a font size
fontSize(100)
# draw the text
text(txt, (x, y))

# calculate the size of the text
textWidth, textHeight = textSize(txt)

# set a red stroke color
stroke(1, 0, 0)
# loop over all font metrics
for metric in (0, fontDescender(), fontAscender(), fontXHeight(), fontCapHeight()):
    # draw a red line with the size of the drawn text
    line((x, y+metric), (x+textWidth, y+metric))