spakin / SimpInkScr

Simple Inkscape Scripting
https://inkscape.org/~pakin/%E2%98%85simple-inkscape-scripting
GNU General Public License v3.0
320 stars 31 forks source link

Ordering of font arguments causing font size to not apply #64

Closed andrewzwicky closed 1 year ago

andrewzwicky commented 1 year ago
text("64pt", (10,  50), font="Consolas", font_size="64pt")
text("64pt", (10, 100), font_size="64pt", font="Consolas")

image

This confused me for quite a while until I was able to figure this out.

spakin commented 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.