Implement baseline anchoring and visible bounds culling for text - #549
Merged
Conversation
Introduces configurable text/glyph baseline anchoring via new `TextBaseline` options and wires it through layout, rendering, and metrics. Adds OpenType `BASE` table loading plus OS/2 x-height/cap-height support so hanging/ideographic and related baselines can use font-provided coordinates with metric fallbacks. Rendering now supports visible-region culling for text blocks, one-shot text rendering, and glyph runs (including early line-break stop when safe). Measurement behavior was aligned with rendering semantics (zero-based logical advance, positioned renderable bounds), and comprehensive tests/reference outputs were added, including new baseline browser comparison fixtures and a Noto Sans SC baseline subset font.
Introduces `BaselineOffset` on `TextOptions` (and `GlyphOptions`) and propagates it through layout, rendering, measuring, and line metrics so baseline shift composes with baseline anchoring consistently. The offset is treated as pixel units, applies correctly for horizontal and vertical modes, and keeps logical advance unchanged. Added/updated baseline tests and layout test utilities to cover render/measure parity, vertical behavior, and DPI independence.
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #549 +/- ##
======================================
Coverage 80% 80%
======================================
Files 348 349 +1
Lines 26860 27165 +305
Branches 4002 4059 +57
======================================
+ Hits 21491 21784 +293
- Misses 4394 4396 +2
- Partials 975 985 +10
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Prerequisites
Description
This pull request introduces several enhancements to font metrics and text rendering, focusing on improved baseline and bounding box handling, as well as adding support for additional font metrics such as x-height and cap height. These changes improve the library's ability to accurately render and layout text, especially with respect to advanced typographic features and culling of invisible glyphs.
Font Metrics Enhancements:
XHeightandCapHeightproperties toFontMetricsand implementing them in all relevant subclasses (StreamFontMetrics,FileFontMetrics,MemoryFontMetrics). [1] [2] [3] [4] [5] [6]TryGetBaselineCoordinate) toFontMetricsand its subclasses, enabling more precise baseline alignment using the font's BASE table when available. [1] [2] [3] [4]Font Table and Data Handling:
Text Rendering and Layout Improvements:
GlyphOptionsandTextRendererto support visible bounds culling (VisibleBounds), baseline alignment (TextBaseline), and baseline offset (BaselineOffset) for glyph rendering, allowing for more precise and efficient text rendering. [1] [2]Internal Data Structure Updates:
OS2Tableto use 32-bit integers instead of 16-bit, for improved compatibility with font specifications.