from Hacker News

Adventures in Text Rendering: Kerning and Glyph Atlases

by zachlloyd on 7/27/22, 3:46 PM with 17 comments

  • by deathanatos on 7/27/22, 6:07 PM

    > For monospace fonts, used by Warp for terminal input and output, glyph advance is a constant - a fixed amount of spacing is used between all pairs of glyphs.

    It's more complicated than that, too. (But just about every terminal I've ever used at one point or another has made that buggy assumption!) Emoji and wide CJK characters typically take two terminal cells.

    For example (and HN will corrupt the output of this command, as it will remove the emoji):

      » python3 -c 'print("1234567890\n\N{PILE OF POO}x\u4e09x")'
      1234567890
      x三x
    
    The second "x" should align under the 6. 4 glyphs, 6 cells.

    (I am a bit curious about the subpixel stuff. I've done font atlases, but IME Harfbuzz — the shaping engine I've used — only seems to emit integral advances? (Although I'm now wanting to re-test that assumption.) And I'm not entirely sure I know how to ask FreeType to render a glyph with an offset, either.)

  • by skavi on 7/27/22, 7:24 PM

    Opening this website significantly degrades scrolling performance in Edge (Chromium). This impacts all my open tabs. Scrolling becomes fast again when the Warp tab is closed.

    Doesn't exactly instill confidence in the advertised product.

  • by boywitharupee on 7/27/22, 7:08 PM

    I'm fascinated by text rendering and just scratching the surface to learn more.

    A few questions I have:

    1. Is the pixel grid global to the the screen? or is it specific to application? Can different applications on OS have different pixel grids? Not sure where pixel grids come from

    2. Sounds painful to write your own font rendering system. Why doesn't Warp use OS level libs CoreText, etc?

    3. I know there are many font rendering techniques such as texture, distance and geometry based. The most recent one is pathfinder technique, which is geometry based? Which one does Warp uses?

    4. In which step the font rendering pipeline spends most time? Is it the shaping? rasterization? font file parsing?

  • by pseudosavant on 7/27/22, 6:17 PM

    It is always great to see an excellent post on keming like this.
  • by dubiousconst281 on 7/28/22, 12:09 PM

    I wonder how signed distance fields performs in practice. Seems like it would fix, or at least minimize the scaling/offset issues quite nicely.

    https://github.com/Chlumsky/msdfgen

  • by billconan on 7/27/22, 5:28 PM

    I have a question,

    How to do font fallback? For example, a user uses an English font "Arial", and suddenly she types a Chinese character. the character doesn't present in Arial, so we need to find a fallback font that does.

    Let's say we find one, but the fallback font has different sizing. How to scale the character to match the other font? What about kerning and other positioning issues?

    And also, is your cache ever increasing? Imagine a user zooms in, do you retire those small glyphs?

  • by gumby on 7/27/22, 5:48 PM

    What an excellent introduction.