randomPoison / text-edit

1 stars 0 forks source link

Investigate point vs. pixel font sizes #4

Open randomPoison opened 7 years ago

randomPoison commented 7 years ago

Right now we have a semi-magical constant being used when rendering fonts:

const PIXEL_TO_POINT: f32 = 0.75;

This value is used to adjust the font scale passed to rusttype when laying out the font, i.e. if pass a font size of 14px to webrender, we have rusttype layout the font with a size of 14 * PIXELS_TO_POINT. In theory this discrepancy comes from the rusttype measuring font size in pixels while the system font renderer used by webrender measures it in points (or vice versa), but on Windows DirectWrite uses pixels to measure font size yet the scaling constant is still needed. My suspicion is that there's some fundamental difference in the units being used to measure the font size, and that may differ between platforms (e.g. Windows uses DIPs, OS X uses points). It's also possible that rusttype is using some fundamentally different algorithm than the system font renderers, in which case we'll have to determine how to get the two systems to agree on glyph size and layout.

For testing this, there's a DEBUG_GLYPHS flag in src/main.rs that will render the bounding boxes of the glyphs as determined by rusttype. Once we fix this issue they should line up better with the text as rendered by webrender.