drawbot
drawbot copied to clipboard
FormattedString tracking value – what does it refer to?
It seems to be neither
-
an absolute value based on the em square (InDesign)

-
a percentage (of what?) (Pages)

-
instead:

newPage(200, 100)
fs = FormattedString(
'TESTING',
font='Base900SansOT-Heavy',
fontSize=12,
tracking=10)
textBox(fs, (10, 10, 200, 50))
That's setting NSKernAttributeName which is about kerning. There are subtle but important differences between this and tracking.
It's an absolute number of points to be added in-between the letters.
If you want Adobe-style 1/1000 tracking, calculate based on your point size:
pointSize = 20
trackingUnits = 100
newPage(200, 100)
fs = FormattedString(
'TESTING',
font='Helvetica',
fontSize=pointSize,
tracking=pointSize*trackingUnits/1000)
textBox(fs, (10, 10, 200, 50))
@folengo: kCTTrackingAttributeName has only been available since 10.12. We still support 10.10. It was not us who confused tracking and kerning, but Apple :)
That said, we could have made our public API a bit more sensible.
Thanks @justvanrossum !