* 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
CreateTextLayoutCore measured the inline embedded controls whenever the
layout was built. The compositor renders dirty visuals under hidden
ancestors too, and layout never measures those, so a TextBlock in a
hidden subtree built its layout from RenderCore and measured its
InlineUIContainer children there. A child measured for the first time
applies its template, attaching visuals inside the render pass, and
CompositingRenderer.AddDirty throws "Visual was invalidated during the
render pass".
- Only measure the embedded controls from CreateTextLayoutCore when the
block's own measure is valid. An invalid block has a measure pass
pending, and MeasureOverride measures the children once the block is
reachable.
- Cover a block hidden at first render, an embedded control shown while
its page is hidden, and a page hidden after it was shown.
Fixes#22380
* Fix showing ellipsis when word wrap and limited by height or MaxLines.
* Simplify fix based on comment
* Align height clip behavior with WPF/HTML when last visible line fits in the available width
No ellipsis is shown in this case so I guess it makes sense for Avalonia to behave the same.
* Clarify truncation comments and cover them at the TextLayout level
- Reword the MaxHeight and MaxLines truncation comments: the two limits
differ on purpose (a height cut only ellipsizes a soft-wrapped line, a
line-count cut ellipsizes after a hard break too, like CSS line-clamp).
- Add TextLayout tests with the real shaper for MaxLines at a hard break,
MaxHeight at a hard break and MaxHeight at a wrapped line, so the
behavior is guarded below the TextBlock layer.
---------
Co-authored-by: Benedikt Stebner <Gillibald@users.noreply.github.com>
* Keep TextBlock text runs in sync with its inlines
_textRuns is built from Inlines, but OnMeasureInvalidated discarded it on
any measure invalidation while Inlines still held the content. Between
that point and the next measure pass, CreateTextLayout read a null
_textRuns as "no inlines" and shaped Text instead, which is null whenever
the content lives in Inlines. That empty result went into the
TextRunCache, keyed by text source index, so every later layout reused it
and the control rendered nothing until something invalidated the cache.
- Discard _textRuns in InvalidateTextLayout, next to the run cache, so
the runs and the cache are dropped by the same event and cannot
disagree about the content.
- Build the runs on demand in EnsureTextRuns, and pick the text source by
HasComplexContent rather than by _textRuns being set.
- Split the constraint-dependent work out of run building. Runs answer to
the content alone; only an embedded control answers to the available
width, so Inline.MeasureEmbeddedControls measures it and
EmbeddedControlRun reports the child's DesiredSize live. Runs now
survive a constraint change instead of being rebuilt every measure.
SelectableTextBlock never hands the run cache to its layout, but it
shared the same fallback and kept the wrong layout on _textLayout.
Fixes#21902
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
* Invalidate the layout when LineSpacing changes
LineSpacing had no case in the property change switch and is not one of
the properties registered with AffectsRender, so changing it left the
measured size and the rendered text untouched even though CreateTextLayout
feeds it into the paragraph properties. It changes line placement rather
than shaping, so it belongs with LineHeight and the other properties that
keep the run cache.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
* Drop the text layout whenever the content is invalidated
InvalidateMeasure only raises OnMeasureInvalidated while the measure is
still valid, so a second content change before the next measure pass left
_textLayout holding the layout the first change had already replaced.
MeasureOverride keeps that layout when the constraint has not moved, so
the block measured and rendered the superseded content.
Clear the layout in InvalidateTextLayout and InvalidateTextLayoutKeepCache
rather than relying on OnMeasureInvalidated to run, which is what
TextPresenter already does.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
* Drop the text layout when an embedded control resizes
A line snapshots its metrics when it is formatted, so a layout built
before a child was measured again keeps reporting the width and height
that child used to have. MeasureOverride reuses the layout whenever the
constraint has not moved, so a control that resizes while the block is
already measure invalid never reaches the measured size.
- MeasureEmbeddedControls reports whether any child came back a different
size, and the layout is dropped only then rather than on every pass.
- Route the remaining layout resets through DisposeTextLayout so every
reset goes through one place.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
* test(textblock): cover fractional layout rounding
A wrapped TextBlock with a fractional line height must retain every line when its desired height lands exactly on a fractional-scale pixel boundary.
* fix(text): preserve lines at rounded fractional heights
TextLayout treated a floating-point accumulation error as a MaxHeight overflow. Use the established tolerant comparison so a line that exactly fits its rounded layout bounds is retained.
---------
Co-authored-by: Julien Lebosquain <julien@lebosquain.net>
* 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>
* Limit InlineUIContainer to available width
* Unit test for InlineUIContainer maximum width
* Invalidate InlineUIContainer's host
* Better InlineUIContainer visual children management
* OnInlineHostChanged also handled by InlineUIContainer
---------
Co-authored-by: Jan Kučera <miloush@users.noreply.github.com>
Co-authored-by: Benedikt Stebner <Gillibald@users.noreply.github.com>
* Don't round size when UselayoutRounding is false for TextBlock. Fixes#18423
* Added back size rounding
* Removed rounding again for the text size and fixed padding rounding in RenderCore
* Fix issue with MinTextWidth (Fixes#18372)
* Make sure that MeasureOverride for TextPresenter and TextBlock are using same textWidth
* Revert #16601 that is introducing an invalid calculation for the OverhangLeading
Add tests for OverhangLeading and OverhangTrailing
* Revert MinTextWidth
* Fix tests to not rely on fixed values
* Fix remaining issues
* Fix comment in Direct2D1 GlyphRunImpl.cs
* Fix Direct2D1 rendering
* Fix gold images
* Restore TextLineImpl
* Update gold image
* Restore Math.Max on OverhangLeading and Trailing
* Adopt similar behavior to WPF: don't use OverhangLeading/Trailing for measuring and remove clip by default.
But it requires further support with NeedsClipBounds
* Remove MinTextWidth
Keep ClipToBounds=true default for TextBlock
* Revert change
---------
Co-authored-by: Benedikt Stebner <Gillibald@users.noreply.github.com>
* Add failing test for TextBlock
* Fix TextBlock re-measure in infinite container
* Fix outdated test
---------
Co-authored-by: Max Katz <maxkatz6@outlook.com>
* Always measure TextBlock with infinite width
* Make sure the constraint is always fulfilled
* Add some tests
* Adjust tests because we no longer retain the TextLayout in the arrange pass
* Rework how TextBlock skips redundant measure and arrange calls
Add some tests
* Adjust tests
* Try this
* Make sure the TextBlock is arranged after it has been measured with a different availableSize
* Make it more clear that we are resetting and recreating the TextLayout
* Capture textLayout after inlines have been processed
* Make sure to clean up VisualChildren and created text runs when the TextLayout is invalidate
* Remove localized comment
---------
Co-authored-by: Tim <47110241+timunie@users.noreply.github.com>