Closed andrewzwicky closed 1 year ago
Short answer: Use font_family
instead of font
.
Long answer: SVG borrows CSS's definition of font
. According to the CSS specification, font
is
a shorthand property for setting 'font-style', 'font-variant', 'font-weight', 'font-size', 'line-height' and 'font-family'
Before setting any of the specified properties,
All font-related properties are first reset to their initial values,
The initial value for font-size
is the renderer-defined medium
size:
The 'medium' value is the user's preferred font size and is used as the reference middle value.
Putting all that together, in
text("64pt", (10, 50), font="Consolas", font_size="64pt")
font="Consolas"
sets the font family to Consolas and the font size to "medium" (whatever that happens to be). Then, font_size="64pt"
changes the font size to 64 pt. so you get the result you expected. However, in
text("64pt", (10, 100), font_size="64pt", font="Consolas")
font_size="64pt"
first sets the font size to 64 pt. then font="Consolas"
changes the font family to Consolas and the font size to medium. That's why you're seeing the correct font but not in the size you expected.
For what you're trying to achieve you should be using font_family
instead of font
. font_family
changes only the font family, leaving the font size unmodified.
This confused me for quite a while until I was able to figure this out.