Ejemplo n.º 1
0
 def test_reloadFont(self):
     src = pathlib.Path(
         __file__).resolve().parent / "data" / "MutatorSans.ttf"
     assert src.exists()
     with tempfile.NamedTemporaryFile(suffix=".ttf") as ff:
         ff.write(src.read_bytes())
         firstModTime = os.stat(ff.name).st_mtime
         drawBot.newDrawing()
         drawBot.font(ff.name)
         self.assertEqual(ff.name, drawBot.fontFilePath())
         path = drawBot.BezierPath()
         path.text("E", font=ff.name, fontSize=1000)
         self.assertEqual((60.0, 0.0, 340.0, 700.0), path.bounds())
         ff.seek(0)
         ttf = TTFont(ff)
         ttf["glyf"]["E"].coordinates[0] = (400, 800)
         ff.seek(0)
         ttf.save(ff)
         secondModTime = os.stat(ff.name).st_mtime
         assert firstModTime != secondModTime, (firstModTime, secondModTime)
         drawBot.newDrawing()  # to clear the memoize cache in baseContext
         drawBot.font(ff.name)
         self.assertEqual(ff.name, drawBot.fontFilePath())
         path = drawBot.BezierPath()
         path.text("E", font=ff.name, fontSize=1000)
         self.assertEqual((60.0, 0.0, 400.0, 800.0), path.bounds())
Ejemplo n.º 2
0
 def fontFilePath(self):
     """Return the path to the file of the current font."""
     return drawBot.fontFilePath()
Ejemplo n.º 3
0
import os
import drawBot
drawBot.size(50, 50)
characters = "Aa今"
glyphNames = ["A", "a", "zzz"]
for fontName in ["Helvetica", "../data/MutatorSans.ttf"]:
    print(fontName)
    print(drawBot.font(fontName))
    drawBot.fontSize(50)
    for char in characters:
        print(drawBot.fontContainsCharacters(char))
    for glyphName in glyphNames:
        print(drawBot.fontContainsGlyph(glyphName))
    print(os.path.basename(drawBot.fontFilePath()))
    print(drawBot.listFontGlyphNames()[:6])
    print(drawBot.fontAscender())
    print(drawBot.fontDescender())
    print(drawBot.fontXHeight())
    print(drawBot.fontCapHeight())
    print(drawBot.fontLeading())
    print(drawBot.fontLineHeight())
    print()

for i in range(4):
    print(drawBot.font("../data/MutatorSans.ttc", fontNumber=i))
    print(os.path.basename(drawBot.fontFilePath()),
          drawBot.fontFileFontNumber())
    assert drawBot.fontFileFontNumber() == i

print()
for fontName in ["Courier", "Courier-Bold", "Courier-Oblique"]: