compareInstances.py 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. from AppKit import NSBezierPath
  2. from fontTools.ttLib import TTFont
  3. from fontTools.pens.cocoaPen import CocoaPen
  4. import string
  5. charset = string.uppercase+string.lowercase
  6. label1 = "Roboto-Light"
  7. label2 = "VF Instance"
  8. fontpath1 = "master_ttf_interpolatable/Roboto-Bold.ttf"
  9. fontpath2 = "instances/RobotoB-VF-instanceBold.ttf"
  10. ttfont1 = TTFont(fontpath1)
  11. ttfont2 = TTFont(fontpath2)
  12. pen1 = CocoaPen(ttfont1.getGlyphSet())
  13. pen2 = CocoaPen(ttfont2.getGlyphSet())
  14. color1 = (1, 0, 0, 0.5)
  15. color2 = (0, 0, 1, 0.5)
  16. unequalmetrics = []
  17. for char in charset:
  18. pen1.path = NSBezierPath.bezierPath()
  19. pen2.path = NSBezierPath.bezierPath()
  20. glyph1 = pen1.glyphSet[char]
  21. glyph2 = pen2.glyphSet[char]
  22. glyph1.draw(pen1)
  23. glyph2.draw(pen2)
  24. newPage(2500, 2500)
  25. fill(None)
  26. strokeWidth(2)
  27. offsetX = 500
  28. offsetY = 500
  29. translate(offsetX, offsetY)
  30. # baseline
  31. stroke(0, 0, 0, 0.25)
  32. line((-offsetX, 0), (width()-offsetX, 0))
  33. # glyph 1
  34. stroke(*color1)
  35. drawPath(pen1.path)
  36. line((0, -offsetY), (0, height()-offsetY))
  37. line((glyph1.width, -offsetY), (glyph1.width, 2000))
  38. # glyph 2
  39. stroke(*color2)
  40. drawPath(pen2.path)
  41. line((0, -offsetY), (0, height()-offsetY))
  42. line((glyph2.width, -offsetY), (glyph2.width, 2000))
  43. stroke(None)
  44. fontSize(36)
  45. fill(0, 0, 0, 0.5)
  46. text("width", (-offsetX+50, -100))
  47. fill(*color1)
  48. text(label1, (-offsetX+50, height()-offsetY-100))
  49. text(str(glyph1.width), (-offsetX+50, -150))
  50. fill(*color2)
  51. text(label2, (-offsetX+50, height()-offsetY-150))
  52. text(str(glyph2.width), (-offsetX+50, -200))
  53. metricsdiff = glyph2.width - glyph1.width
  54. if metricsdiff != 0:
  55. unequalmetrics.append((char, metricsdiff))
  56. newPage(2000, 2000)
  57. fs = FormattedString(fontSize=30, font="Menlo")
  58. for c, m in unequalmetrics:
  59. t = "%s %s\n" % (c, m)
  60. fs.append(t)
  61. textBox(fs, (50, 0, width()-100, height()-50))
  62. saveImage(["compareInstances-Bold.pdf"])