KiBuzzard icon indicating copy to clipboard operation
KiBuzzard copied to clipboard

dialog: Fix text height

Open gregdavill opened this issue 1 year ago • 3 comments
trafficstars

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, _.

Screenshot from 2024-03-02 21-03-57

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.

gregdavill avatar Mar 02 '24 10:03 gregdavill

Where does the magic 7.6 come from?

arturo182 avatar Mar 02 '24 15:03 arturo182

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)

gregdavill avatar Mar 03 '24 04:03 gregdavill

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. Screenshot from 2024-03-06 07-23-38 Screenshot from 2024-03-06 07-24-05

gregdavill avatar Mar 05 '24 21:03 gregdavill

This pull-request is rebased to be applied after #120

These latest commits produce this: image

One commit now fixes the text scaling/positioning in svg2mod image

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. font metrics

gregdavill avatar May 06 '24 12:05 gregdavill