* Bake FontVariationSettings into Typeface
Typeface is the value every text property funnels into before font
resolution, so variable-font axis values belong on it - same pattern as
weight and stretch, and the only way a single settings value can flow
from a style through layout to the renderer.
- both ctors take an optional FontVariationSettings; Empty is coerced to
null at construction so equality, hashing and cache keys never
distinguish the two "design defaults" spellings
- equality and hash include the settings (structural, cached hash)
- Normalize() and the FormattedText per-run updaters (SetFontFamily /
SetFontWeight / SetFontStyle) carry the settings over when rebuilding
* Apply Typeface.FontVariations during font resolution
FontManager is the single seam every Typeface passes through on its way
to a GlyphTypeface, so the user-space settings are applied there - once,
at the end, whichever resolution path produced the base typeface.
- the resolution body moves to a private TryResolveGlyphTypeface (the
default-family recursions target it directly); the public method
resolves, then binds the variations via GlyphTypeface.WithVariations
- per-variation instances are cached on the resolved typeface, so
repeated lookups with equal settings return the same instance (pinned
by test against the embedded Inter Variable)
- font fallback carries the variations over: the matched fallback family
renders at the same axis values the primary typeface requested, each
font clamping to its own axes (CSS behavior)
* Expose FontVariations as an inherited text property
TextElement.FontVariationsProperty is the user-facing entry point for
variable-font configuration, following the FontStretch pattern exactly:
an inherited attached property that every typeface bake site folds into
the Typeface it constructs.
- attached property on TextElement (inherits) + CLR accessors and
Get/SetFontVariations statics
- AddOwner on TemplatedControl, ContentPresenter and TextBlock
- baked into the typeface at every control bake site: TextBlock,
SelectableTextBlock, TextPresenter, TextBox line-height layouts, and
Inline run properties
- property changes invalidate like the sibling font properties
(TextBlock/TextPresenter shaping group, TextElement inline host)
- XAML attribute strings ("wght=700, wdth=85") convert through the
static Parse the XAML compiler picks up - no TypeConverter needed
(pinned by a Markup.Xaml test)
* Animate FontVariations with CSS interpolation semantics
FontVariationSettings.Interpolate blends two settings the way CSS
font-variation-settings does: per-axis linear interpolation when both
endpoints set exactly the same axes (easing overshoot extrapolates),
discrete switch at the midpoint otherwise. Discrete is the only sound
fallback because a missing axis means "the font''s default", a value that
is not knowable in user space.
- FontVariationSettingsAnimator registered like the other value
animators, so keyframe Animations on FontVariations work out of the box
- FontVariationSettingsTransition for the Transitions collection,
following the TransformOperationsTransition pattern
- interpolation contract pinned at the value level (lerp, order
independence, overshoot, discrete mismatches, null/Empty endpoints)
and at the transition level through a test clock
* Quantize normalized coordinates to the F2Dot14 grid
An animated axis sweeps through arbitrary float user values; without
quantization every frame produced a fresh normalized position and a
fresh clone in the per-source variation cache, growing it without bound
across repeated sweeps.
Snap each coordinate to 1/16384 after avar correction. That is the
resolution the font binary itself stores - gvar, avar and the item
variation stores speak F2Dot14 - so no representable position is lost,
while a swept axis lands on at most 32769 distinct cache entries and
sub-resolution user values collapse to one clone (pinned by tests at the
position and clone-identity level).
* Add failing tests for shaping varied typefaces
A variation clone shares the source's HarfBuzz font, so shaping places
its glyphs at default-instance hmtx advances while GlyphTypeface reports
HVAR-adjusted advances for the same glyphs.
- Shaped advances of a wght=900 Inter Variable clone must equal the
clone's HVAR advances and differ from the default instance
- The default position keeps the source's shaper typeface
- Disposing a clone must leave the source shaper usable
* Shape variation clones with their own HarfBuzz coordinates
Layout advances come from HarfBuzz, but a varied GlyphTypeface shared the
source's hb_font, so text set through FontVariations was placed at
default-instance advances while its metrics and bounds were varied.
- HarfBuzzTypeface.WithVariation returns an instance owning a sub-font of
the source font with the normalized coordinates set in fvar axis order;
the face stays shared and only the sub-font is released on dispose
- The sub-font installs the OpenType font functions itself, since the
inherited parent functions evaluate HVAR at the parent's coordinates
- Bind hb_font_set_var_coords_normalized, which HarfBuzzSharp exports but
does not wrap, under HarfBuzzSharp's library name; map it to the
embedded framework on iOS, tvOS and Mac Catalyst, and fall back to the
default instance if the entry point cannot be resolved
- Let Avalonia.HarfBuzz see Avalonia.Base internals to implement the
internal ITextShaperTypeface members
* Add failing tests for whitespace absorbed into a fallback run
A fallback run is extended for as long as the fallback font has glyphs
instead of ending where the primary font regains coverage. Practically
every font maps U+0020, so the space that follows fallback text is
pulled into the fallback run and shaped with its space glyph.
- itemization: a Hebrew letter followed by " b" must produce a 1-char
fallback run, not a 2-char one that swallows the space
- measurement: the space after an emoji must have the same advance as
the same space elsewhere in the line
* Merge abutting text bounds within the usual float tolerance
The two edges being compared are reached by summing glyph advances along
different paths, so abutting bounds can land an ULP apart and a single
directional span gets reported as two rectangles. Compare them the way
the rest of layout compares coordinates.
* End a fallback run where the default typeface regains coverage
Whitespace was exempt from the return-to-primary check so that a space
wouldn't split a fallback run. Practically every font maps U+0020, so
the exemption let a fallback run reach past the text the default
typeface couldn't render and shape the following space with the
fallback's own advance - a full em in most emoji fonts, which is the
long space reported after an emoji.
- the check now applies to spacing whitespace (Zs), so a fallback run
ends at the first cluster the default typeface can render; control
and format codepoints stay exempt - many fonts map the
default-ignorable bidi controls, and a default typeface whose cmap
merely has such a mark must not pull it out of the fallback run: the
mark renders nothing either way, and the split cuts the run for no
reason
- a default typeface that cannot shape the run's script is still not a
return target for text, but it does reclaim the spacing whitespace
between the words, which carries no shaping
- a run of pure whitespace no longer becomes the anti-thrashing bias for
the next run, so the words on either side of a space keep resolving to
the same fallback font
Test expectations that encoded the old run structure move with it: a
line of emoji separated by spaces is no longer a single run, glyph
clusters are relative to each run's own text (the affected helpers now
add the run's start), and the spaces of a right-to-left line measure
with the primary font, which widens those lines.
* Add Emoji, Emoji_Presentation and Default_Ignorable Unicode data
Font fallback has to tell content codepoints apart from ones a font is not
expected to draw, and emoji presentation cannot be decided from the general
category alone. None of that data was available.
- Pack Emoji, Emoji_Presentation and Default_Ignorable_Code_Point as single
bits into the spare bits of the GraphemeBreak trie word (it only used 7 of
32); the emoji properties come from the emoji-data.txt the generator already
reads for Extended_Pictographic.
- Expose them as Codepoint.IsEmoji, HasEmojiPresentation and IsDefaultIgnorable.
- Regenerate GraphemeBreak.trie.cs; no other generated file changes.
* Add failing test for default ignorables in cluster coverage
A cluster of base + U+FE0F + combining mark is handed to the primary font even
though it has no glyph for the mark, because every candidate font is required
to cover the variation selector as well and none does. The mark renders as
.notdef.
The fallback font is Noto Sans rather than DejaVu Sans: DejaVu maps U+FE0F and
would hide the defect.
* Ignore default ignorable codepoints when matching cluster coverage
Variation selectors are nonspacing marks by general category, so the cluster
coverage check demanded a glyph for them from every candidate font. Text fonts
do not map U+FE0F, which made any base + U+FE0F + mark cluster look unmatchable:
the fallback search was keyed on the variation selector, found nothing, and the
cluster fell back to the primary font with the mark rendered as .notdef. This is
what made emoji keycap sequences render as a digit followed by a tofu box.
- Skip default ignorables (along with the break/control/format codepoints
already handled) when testing cluster coverage and when picking the codepoint
the fallback search is keyed on.
- A cluster holding only a default ignorable no longer ends a shapeable run;
it renders nothing whichever font it lands on.
* Unify glyph-demand predicate in cluster coverage
Default_Ignorable_Code_Point already covers every invisible format
codepoint, so the blanket Format exclusion in NeedsGlyph only skipped
the deliberately visible ones (prepended concatenation marks like
U+0600, interlinear annotation chars) - those should demand a glyph,
and the base-only pass already did. Dropping Format makes NeedsGlyph
identical to the run-ending condition in TryGetShapeableLength, which
now calls it instead of restating it.
* Add GlyphTypeface.CanShapeScript(Script), backed by a lazy read of the GSUB/GPOS ScriptList via the new ScriptListTable parser.
Add FontFallbackScriptHints.TryGetComplexShapingTags, which maps 17 complex scripts to the OpenType script tag(s) a font must declare to shape them.
Thread a Script shapingScript constraint through FontManager.TryMatchCharacter and FontCollectionBase.TryMatchCharacter as internal overloads, leaving the public signatures untouched.
Rework TextCharacters.CreateShapeableRun into a capability preference: a complex script tries shaping-capable fonts first (tier 0), then cmap-only coverage (tier 1); simple scripts keep the single historical tier.
Replace the NUL placeholder U+200B (ZERO WIDTH SPACE) with U+2060 (WORD JOINER) so the substitution introduces no line-break opportunity.
Suppress previous-run font reuse across a culture change for locale-sensitive scripts, so a zh run's font no longer pins following ja text.
Add 3 subset test fonts and 3 new test files (7 new tests) and fix 2 stale doc-comment crefs.
* Fix comments
* Fix font fallback reusing the wrong cached face from the script bucket
FontCollectionBase.TryMatchCharacter caches a resolved fallback family per
(script, culture) bucket. Two bugs let that bucket hand back a face that does
not match the request:
- A positive bucket entry suppressed the Tier D platform lookup for any later
codepoint, even one the bucket family cannot cover. A CJK run left the
Simplified-only U+534E unmatched (tofu) because the bucket resolved to a
Japanese font that lacks it, while another installed font could place it.
Tier D now treats only a negative (null) entry as "platform already
attempted"; a positive entry no longer blocks the platform, since that
family may not cover this codepoint.
- A cached covering match of a neighbouring FontCollectionKey was reused for a
different requested key. After a Bold run cached a face, a following Normal
run reused it and rendered bold (and the symmetric style and stretch cases).
Tier A, B and C now keep the exact key: when the cached covering match is a
neighbouring key, the exact-key face of the same family is resolved from the
platform via TryMatchCharacterFromPlatform, falling back to the neighbour
only when the platform has no exact face. Collections without a platform are
unchanged.
Add regression tests for both: a bucket whose font lacks a later same-script
codepoint, and weight and style leaks resolved through Tier B (script cache)
and Tier C (the sweep, exercised via a non-locale-sensitive script with no
culture).
* Introduce a universal IGlyphTypeface implementation that does not rely on any platform implementation
* Revert changes
* Fix Android
* Make the test happy
* Fix build
* Update baseline
* Fix naming
* Fix headless
* Move interfaces to dedicated files
Make GlyphTypeface.GlyphCount an integer
* Fix GlyphCount
* Make IGlyphTypeface NotClientImplementable
* Make sure we cache platform typefaces by their desired name, style, weight and stretch
* Update baseline
* Only use IGlyphTypeface
* Fix Android
* Try to clear the buffer before we encode somethimg
* Add needed test font
* Add more unit tests
* Reduce allocations
* Remove Direct2D1 test files
* More tests
* More complete table implementations
* More adjustments
* Use batch APIs
* Handle invalid timestamps
* Update baseline
* Introduce a CharacterToGlyphMap struct for faster access
* Remove AggressiveInlining
* Remove AggressiveInlining
* Make the head table optional for legacy fonts
* Remove Load method. Fix TextBlockTests
* Fix nullables
* Remove redundant folder
* Update Api baseline
* revert diff helper changes
* revert changes
* Use bare minimum font for Headless platform and introduce a test font manager that uses the Inter font for testing.
* Add missing font file for Headless platform
---------
Co-authored-by: Gillibald <stebner@avaloniaui.net>
Co-authored-by: Julien Lebosquain <julien@lebosquain.net>
* Do not treat spacing combining marks as whitespace
* Do not treat combining marks as whitespace
Try to find a matching typeface on a grapheme boundary
* Add embedded font for testing
* Remove using
* Fix naming and remove redundant code
* Apply default until we reach the next base character
* Merge core libraries.
Everything below `Avalonia.Controls` into `Avalonia.Base`.
* Move new files to correct place.
* Removed unused dirs/projects,
* Removed outdated references from theme assemblies.
* Merge unit tests to match new assembly layout.
* Fixup test namespaces.
* Make directory match namespace.
* Move files to match namespace.
* Move files to match namespace.
* Fix up incorrect namespace.
`Avalonia.Visuals.Media.Imaging` -> `Avalonia.Media.Imaging`.
* Fix resource URL.
* Removed outdated dependencies.
* Added missing project reference.
* Update test namespaces.
* Fix merge error.
* Fix merge errors.
* Fix bad merge in WindowsInteropTest.csproj.
* Fix up merge errors in csprojs.
* Remove merged tests from nuke.
* Fix up namespace.
* Fix compile error.
* Fix failing tests.
Now that more unit tests are present in Avalonia.Base.UnitTests, general `AvaloniaObject` properties are getting registered. Ignore those.
Co-authored-by: Jumar Macato <16554748+jmacato@users.noreply.github.com>