KiBuzzard
KiBuzzard copied to clipboard
dialog: Fix text height
I've had issues with the current text height scaling.
The current method renders the label and captures the height, this height is then scaled compared to the requested height.
This results in the following strings being rendered at the same height: test, TEST, a, _a, _b, _.
If we instead use a fixed value, the resulting height is not exactly matching the value entered, but ensures that labels with different height characters end up with matching sizes.
Where does the magic 7.6 come from?
I don't currently know. And I don't like it either.
The scaling that's applied to the text appears to be a combo of the following:
- fonttools (font reports em=1000 units, and scales down based on text.size
- svg text.size currently the default 12? (px?)
- svg has a DEFAULT_DPI=96
- svg export to kicad footprint scales from DPI to mm. (25.4/96)
Travelling down the rabbit hole, I've generated a plain svg file, and used svg2mod to convert it into a kicad footprint. KiBuzzard uses svg2mod under the hood to do the final conversion.
The SVG has: an A as a text object, scaled to be 1mm tall, The same text but as a path object, then a 2x2mm box.
When converted to a kicad_mod file the text object does not match correctly. So this has potentially been the root of the issue.
This pull-request is rebased to be applied after #120
These latest commits produce this:
One commit now fixes the text scaling/positioning in svg2mod
The second commit adjusts the kibuzzard scaling method. I can get scaling to work for "lineHeight", but the goal is to set the height of "Cap height", as this feels more natural and inline with older versions.
To handle differences in fonts it generates a H and scales the label height to match.