Search code examples
ioscore-text

What's "optical bounds" of CTLine?


CTLineGetBoundsWithOptions() uses CTLineBoundsOptions. One of the option is kCTLineBoundsUseOpticalBounds whose doc says:

Pass this option to use optical bounds.

But I don't understand the meaning of optical bounds.


Solution

  • The font designer can specify the optical bounds of a glyph separately from its typographic bounds. In a TrueType font, the opbd table, if present, contains optical bounds.

    From WWDC 2012 Session 226: Core Text and Fonts:

    Now, as I advance to the next few slides, I want to call your attention in particular to the left and right sides of this rectangle on screen because I’m going to start passing some different options to this API and it’s going to have an effect on either side.

    typographic bounds

    Let’s go ahead and advance now as I invoke use optical bounds. This is a very slight difference here, but you may have noticed that the edges of the box have been pulled in a little bit here. What’s going on here is that optical bounds are very closely related to the typographic bounds, the regular measurement of the line.

    optical bounds

    But, in this case, the font designer has specified that the way that the font is likely to be perceived by our eyes means that they don’t line up exactly with just the glyph measurements. The optical bounds in this case have been designed to pull in on either of these curly quotes here because the way our eyes see rounded shapes. It’s a bit different than the way we see straight lines, so the font designer has compensated for that by providing us information in the font.

    (Find the full session transcript here.)

    Microsoft describes it this way:

    Aligns glyphs by their apparent left or right extents in horizontal setting, or apparent top or bottom extents in vertical setting, replacing the default behavior of aligning glyphs by their origins. Another name for this behavior would be visual justification. The optical edge of a given glyph is only indirectly related to its advance width or bounding box; this feature provides a means for getting true visual alignment.