Skip to content

[net12] Add Span.TextDecorationColor and TextDecorationThickness (underline / strikethrough color and thickness) - #40260

Open
Redth wants to merge 5 commits into
mainfrom
redth/span-textdecorationcolor
Open

Redth wants to merge 5 commits into
mainfrom
redth/span-textdecorationcolor

Conversation

@Redth

@Redth Redth commented Nov 14, 2026 •

Copy link
Copy Markdown
Member

Note

Are you waiting for the changes in this PR to be merged?
It would be very helpful if you could test the resulting artifacts from this PR and let us know in a comment if this change resolves your issue. Thank you!

Target Branch

This PR is for Initial base
New features, API changes, or .NET 12 work (including .NET 12 fixes) main
.NET 11 servicing fixes net11, for review
Older servicing, release integration, infrastructure, or documentation The branch designated for that work
  • I selected the applicable base branch using the contribution guide. This is a new API, so it targets main.

For .NET 11 fixes, only a maintainer retargets the approved PR to the active
inflight lane and merges it after CI validates that final base. Do not merge
individual fixes directly into net11; agents must not retarget or merge.

Description of Change

Adds Span.TextDecorationColor and Span.TextDecorationThickness, so a span's underline / strikethrough can be drawn in a color other than the text color and at a chosen thickness. A typical use is a term or link inside running text: normal text color, a thin accent-colored underline. Spec: #40259.

public static readonly BindableProperty TextDecorationColorProperty;
public Color TextDecorationColor { get; set; }        // null (default) = text color, as today

public static readonly BindableProperty TextDecorationThicknessProperty;
public double TextDecorationThickness { get; set; }   // device-independent units; <= 0 (default -1) = font's thickness, as today
<Span Text="Stabilizer / CYA" TextDecorations="Underline"
      TextDecorationColor="{StaticResource CyaAccent}" TextDecorationThickness="1" />

Platforms

  • iOS / Mac Catalyst: FormattedStringExtensions.ToNSAttributedString adds NSUnderlineColorAttributeName / NSStrikethroughColorAttributeName when a color is set. UIKit has no exact decoration thickness, only styles, so a thickness of 1.5 or more uses NSUnderlineStyle.Thick and anything else Single (today's style).
  • Android: FormattedStringExtensions.ToSpannableString uses a new Java PlatformUnderlineSpan (next to PlatformFontSpan / PlatformLineHeightSpan, so drawing stays in Java) when a color and / or thickness is set.
    • On API 29+ it turns off the standard underline and sets the public TextPaint.underlineColor (the text color when no decoration color is set) and underlineThickness (the given thickness multiplied by display density without layout rounding, or the font's own with Android's standard minimum of one native pixel). Explicit positive thicknesses remain fractional, including subpixel values; the one-pixel minimum applies only to the default font-metric fallback. This minimum keeps custom-colored underlines visible when a font reports a zero thickness metric. Below API 29 it draws the usual text-colored underline.
    • Android has no public strikethrough color or thickness, so strikethrough is unchanged.
  • Windows: not supported. TextBlock decorations use the foreground and the font's thickness. Documented in the properties' remarks.

With neither set, nothing changes: UnderlineSpan and the existing attributes are used exactly as before.

Public API: Span.TextDecorationColor{get,set}, Span.TextDecorationColorProperty, Span.TextDecorationThickness{get,set} and Span.TextDecorationThicknessProperty are added to every Controls PublicAPI.Unshipped.txt. The Java span is bound as internal by Transforms/Metadata.xml, so Core's API is unchanged.

Tests

  • Controls.Core.UnitTests: SpanTests.TextDecorationColorDefaultsToNull, TextDecorationThicknessDefaultsToFontThickness, and ChangingTextDecorationColor/ThicknessUpdatesLabelFormattedText (a change re-maps the label's formatted text). All pass locally.
  • Controls.DeviceTests: FormattedStringTests.TextDecorationsApplyNativeColorAndThickness covers 48 combinations: no decoration, underline, strikethrough, or both; with and without a decoration color; and thicknesses -1, 0, 0.25, 1, 1.5, and 2.
    • Android applies the generated underline span to a TextPaint and checks the requested color, fractional density-converted thickness independently against native display metrics, positive default-thickness fallback, cleared standard underline flag, and unchanged text foreground. The test includes assertions for the pre-29 standard underline fallback; that older-API branch was not executed locally.
    • Apple checks native underline and strikethrough colors and styles independently, including combined flags and the Single/Thick boundary, while preserving the text foreground.
    • Undecorated spans receive no underline span on Android and no decoration-color attributes or active decoration styles on Apple, even when custom color and positive thickness are supplied.

What I verified locally (macOS, .NET 11.0.100):

  • Controls.Core builds for all TFMs except Windows: netstandard, net11.0, Android (Gradle compiles and binds the new Java span), iOS and Mac Catalyst. The PublicAPI analyzers are clean.
  • The Controls unit tests above pass (SpanTests: 15/15).
  • Android FormattedStringTests: 50/50 passed on an API 37 emulator, including all 48 decoration combinations. The strengthened independent thickness assertions caught 16 failures before the fractional-conversion correction; all pass with it. At density 2.4375, 0.25 DIP now correctly produces 0.609375 pixels instead of 1. Four default-thickness colored-underline cases also previously failed before the minimum-one-pixel fallback fix.
  • Apple native test source compiles, but the existing device-test host cannot package/run with the local Apple 27 SDK because it lacks the required scene lifecycle setup. These automated Apple cases have not run locally.
  • A separate source-backed demo runs on iOS 27.2, Mac Catalyst, and Android API 37; the screenshots below show the actual platform rendering captured before the final fractional-conversion correction. No screenshot-only demo code is included in this PR.
  • The same native techniques (colour, plus a 1 pt underline: TextPaint.underlineThickness on Android, NSUnderlineStyle.Single vs Thick on iOS) run in a shipping app (Pool Math), on iOS 27 and Android 16, light and dark.

Issues Fixed

Fixes #40259

🤖 Generated with Claude Code

Screenshots

Click a screenshot to view it at full size.

iOS 27.2 Android API 37 Mac Catalyst
iOS: custom underline and strikethrough colors, Single versus Thick styles, combined decorations, and undecorated text Android: custom underline color and exact thickness, unchanged native strikethrough, combined decorations, and undecorated text Mac Catalyst: default and custom underline colors, thin and thick decorations, strikethrough, combined decorations, and undecorated text

Copilot AI balanced review requested due to automatic review settings November 14, 2026 17:57
@Redth
Redth temporarily deployed to copilot-pat-pool November 14, 2026 17:57 — with GitHub Actions Inactive
@github-actions

Copy link
Copy Markdown
Contributor

🚀 Dogfood this PR with:

⚠️ WARNING: Do not do this without first carefully reviewing the code of this PR to satisfy yourself it is safe.

curl -fsSL https://raw.githubusercontent.com/dotnet/maui/main/eng/scripts/get-maui-pr.sh | bash -s -- 40260

Or

  • Run remotely in PowerShell:
iex "& { $(irm https://raw.githubusercontent.com/dotnet/maui/main/eng/scripts/get-maui-pr.ps1) } 40260"

@Redth
Redth temporarily deployed to copilot-pat-pool November 14, 2026 17:58 — with GitHub Actions Inactive
@azure-pipelines

This comment has been minimized.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The Android tests only count spans, leaving underline color, native thickness, flag clearing, and fallback behavior unverified.

1 open issue
What changed in this PR

Adds optional decoration colors to MAUI formatted-text spans, implementing #40259 while preserving text-colored decorations by default.

Changes:

  • Adds Span.TextDecorationColor, public API entries, and documentation of platform limits.
  • Supports colored underlines and strikethroughs on iOS/Mac Catalyst, and colored underlines on Android API 29+.
  • Adds unit and device tests for defaults, change notifications, and native decoration mapping.
File Description
src/​Core/​AndroidNative/​maui/​src/​main/​java/​com/​microsoft/​maui/​PlatformUnderlineColorSpan.java Draws colored Android underlines with an older-API fallback.
src/​Controls/​tests/​DeviceTests/​Elements/​FormattedStringTests.cs Tests native decoration mapping with and without a color.
src/​Controls/​tests/​Core.UnitTests/​SpanTests.cs Tests the null default and formatted-text change notification.
src/​Controls/​src/​Core/​Span.cs Defines the bindable property and documents platform support.
src/​Controls/​src/​Core/​PublicAPI/​netstandard/​PublicAPI.Unshipped.txt Records the new API for .NET Standard.
src/​Controls/​src/​Core/​PublicAPI/​net/​PublicAPI.Unshipped.txt Records the new API for .NET.
src/​Controls/​src/​Core/​PublicAPI/​net-windows/​PublicAPI.Unshipped.txt Records the new API for Windows.
src/​Controls/​src/​Core/​PublicAPI/​net-maccatalyst/​PublicAPI.Unshipped.txt Records the new API for Mac Catalyst.
src/​Controls/​src/​Core/​PublicAPI/​net-ios/​PublicAPI.Unshipped.txt Records the new API for iOS.
src/​Controls/​src/​Core/​PublicAPI/​net-android/​PublicAPI.Unshipped.txt Records the new API for Android.
src/​Controls/​src/​Core/​Platform/​iOS/​Extensions/​FormattedStringExtensions.cs Applies native underline and strikethrough color attributes.
src/​Controls/​src/​Core/​Platform/​Android/​Extensions/​FormattedStringExtensions.cs Selects the colored underline span when a color is specified.

Review effort: Balanced

@kubaflo

This comment has been minimized.

@kubaflo

kubaflo commented Nov 14, 2026

Copy link
Copy Markdown
Contributor

/rebase

@github-actions github-actions Bot added the s/agent-review-in-progress AI review is currently running for this PR label Nov 14, 2026
@github-actions
github-actions Bot force-pushed the redth/span-textdecorationcolor branch from 23ef3f5 to e12535c Compare November 14, 2026 18:47
Copilot AI balanced review requested due to automatic review settings November 14, 2026 18:47
@kubaflo

This comment has been minimized.

@azure-pipelines

This comment has been minimized.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Android tests check only the attached span type, allowing incorrect underline colors, missing underlines, and broken pre-API-29 fallback behavior to go undetected.

2 open issues

Review effort: Balanced

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Expert Review — 3 findings

Reviewed commit e12535c.

See inline comments for details.

@MauiBot

This comment has been minimized.

@MauiBot MauiBot added s/agent-gate-passed AI verified tests catch the bug (fail without fix, pass with fix) and removed s/agent-review-in-progress AI review is currently running for this PR labels Nov 14, 2026
Copilot AI balanced review requested due to automatic review settings November 14, 2026 19:45
@Redth Redth changed the title Add Span.TextDecorationColor (underline / strikethrough in its own color) Add Span.TextDecorationColor and TextDecorationThickness (underline / strikethrough color and thickness) Nov 14, 2026
@kubaflo

This comment has been minimized.

@kubaflo

kubaflo commented Nov 14, 2026

Copy link
Copy Markdown
Contributor

/rebase

@github-actions github-actions Bot added the s/agent-review-in-progress AI review is currently running for this PR label Nov 14, 2026
@azure-pipelines

Copy link
Copy Markdown
No pipelines are associated with this pull request.

Redth and others added 4 commits November 23, 2026 13:14
…lor)

Span.TextDecorationColor draws a span's TextDecorations in a color other than the text color.
Null (the default) keeps today's behavior.

- iOS / Mac Catalyst: NSUnderlineColor / NSStrikethroughColor on the span's attributed string.
- Android: PlatformUnderlineColorSpan (Java) sets TextPaint.underlineColor on API 29+ and falls
  back to a text-colored underline below that. Android has no public strikethrough color, so
  strikethrough stays in the text color.
- Windows: not supported; decorations stay in the text color (documented).

Fixes #40259

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Span.TextDecorationThickness sets the thickness of a span's decorations in device-independent
units. Zero or less (default -1) keeps the font's own thickness.

- Android API 29+: the underline span (renamed PlatformUnderlineSpan, as it now carries a color
  and / or a thickness) sets TextPaint.underlineThickness; without a decoration color the
  underline keeps the text color. Strikethrough has no public thickness API and is unchanged.
- iOS / Mac Catalyst: UIKit only has styles, so underline and strikethrough use the nearer of
  NSUnderlineStyle.Single (about 1) and Thick (about 2).
- Windows: not supported.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Exercise native paint and attributed-string output across decoration flags, color settings, and thickness boundaries. Keep Android custom underlines visible when the font reports a zero thickness metric.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Convert decoration thickness using display density without layout rounding and verify subpixel values against native metrics.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@kubaflo

kubaflo commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

/review expert-review-with-gate

@github-actions github-actions Bot added the s/agent-review-in-progress AI review is currently running for this PR label Nov 23, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Warning

Your /review gate couldn't start due to a transient error triggering the pipeline. The command was left unacknowledged so scheduled recovery can retry it automatically; you can also comment /review gate again in a minute.

@github-actions github-actions Bot removed the s/agent-review-in-progress AI review is currently running for this PR label Nov 23, 2026

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Expert Review — 0 findings

Reviewed commit c83329a.

@Redth
Redth force-pushed the redth/span-textdecorationcolor branch from c83329a to 3fd956e Compare November 23, 2026 20:41
Copilot AI balanced review requested due to automatic review settings November 23, 2026 20:41
@Redth

Redth commented Nov 23, 2026

Copy link
Copy Markdown
Member Author

/azp run maui-pr-devicetests

The authorized rebase is now pushed at 3fd956e; requesting device validation for this head.

🤖 AI-authored reply via Agency Finish PR.

@Redth

Redth commented Nov 23, 2026

Copy link
Copy Markdown
Member Author

/azp run maui-pr-uitests

The authorized rebase is now pushed at 3fd956e; requesting UI validation for this head.

🤖 AI-authored reply via Agency Finish PR.

@azure-pipelines

Copy link
Copy Markdown
No pipelines are associated with this pull request.

1 similar comment
@azure-pipelines

Copy link
Copy Markdown
No pipelines are associated with this pull request.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

The new public APIs rely on native rendering paths that remain untested on Apple devices and Android pre-29, requiring human validation before approval.

No open issues 🎉

Review effort: Balanced

@kubaflo

This comment has been minimized.

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Expert Review — 0 findings

Reviewed commit 3fd956e.

@Redth

Redth commented Nov 23, 2026

Copy link
Copy Markdown
Member Author

The rebased-head build 1695721 completed its compilation, packaging, and integration stages successfully. Its only failing task was Monitor Helix Jobs, which reported zero submitted jobs.

The submission logs actually contain four Helix job IDs (Debug, Release). Direct Helix checks found two jobs still unscheduled and two empty job placeholders, with no completed test work. This is a submission/discovery infrastructure failure, not evidence of a Span assertion failure; the unit tests cannot be called passed.

Azure DevOps accepted one retry of the HelixTests stage, including its submission jobs. Successful build, pack, and integration stages are not being rerun. No source changes, skipped tests, or weakened checks were introduced.

🤖 AI-authored reply via Agency Finish PR.

@kubaflo

This comment has been minimized.

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Expert Review — 0 findings

Reviewed commit 3fd956e.

Preserve the Span decoration APIs alongside newly added APIs from main. All 15 focused Span unit tests pass with the selected branch SDK.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings November 24, 2026 14:49

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

The new public decoration APIs still require API sign-off and native validation because Apple device tests and the Android pre-29 fallback have not been exercised.

No open issues 🎉

Review effort: Balanced

@Redth

Redth commented Nov 24, 2026

Copy link
Copy Markdown
Member Author

Review follow-up: merged current main in f4242b358f solely to resolve six additive PublicAPI list conflicts, preserving both branches’ entries. The feature diff remains 12 files / 334 insertions / 6 deletions.

Validation after the merge:

  • bash eng/common/dotnet.sh build Microsoft.Maui.BuildTasks.slnf -p:IncludeIosTargetFrameworks=false -p:IncludeMacCatalystTargetFrameworks=false -p:IncludeMacOSTargetFrameworks=false -p:IncludeAndroidTargetFrameworks=false -v:q — passed.
  • bash eng/common/dotnet.sh test src/Controls/tests/Core.UnitTests/Controls.Core.UnitTests.csproj --filter FullyQualifiedName~SpanTests -p:IncludeIosTargetFrameworks=false -p:IncludeMacCatalystTargetFrameworks=false -p:IncludeMacOSTargetFrameworks=false -p:IncludeAndroidTargetFrameworks=false --verbosity quiet — 15 passed.
  • Scoped Mac Catalyst device-test attempt via Run-DeviceTests.ps1 -Project Controls -Platform maccatalyst -TestFilter Category=Label -IncludeClasses Microsoft.Maui.DeviceTests.FormattedStringTests -Timeout 00:05:00 — blocked at restore by NETSDK1147: the newly selected repository SDK lacks the iOS workload required by the multi-targeted test graph. No native test results were produced.

The review’s remaining caveats are valid: Apple automated native validation, Android pre-29 fallback validation, and maintainer API sign-off are still outstanding. Existing native captures and the earlier 50/50 Android run do not substitute for those missing checks. No test or approval requirements were removed.

🤖 AI-authored reply via Agency Finish PR.

@kubaflo

kubaflo commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

/review expert-review

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Expert Review — 0 findings

Reviewed commit f4242b3.

Source assessment incomplete (7/8 dimensions); finding count is partial.

This branch was previously deployed

1 inactive (outdated) deployment
copilot-pat-pool — 23ef3f5a Deployed Nov 14, 2026 by Redth via conclusion #2976
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

s/agent-gate-passed AI verified tests catch the bug (fail without fix, pass with fix)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Spec] Span.TextDecorationColor / TextDecorationThickness: underline / strikethrough in its own colour and thickness

4 participants