Skip to content

[Android] Don't clip the last character of italic Labels before Android 15 - #40619

Closed
marcelomoresco wants to merge 3 commits into
dotnet:net11from
marcelomoresco:fix/33315-italic-label-clipping-net11
Closed

marcelomoresco wants to merge 3 commits into
dotnet:net11from
marcelomoresco:fix/33315-italic-label-clipping-net11

Conversation

@marcelomoresco

Copy link
Copy Markdown
Contributor

Target Branch

Targets net11: longstanding bug (reported 9.0.120), same code on main.

Description of Change

Before Android 15, TextView measures text by advance width, but an italic last glyph's slant is drawn past that width, so a wrap-content or end-aligned Label clips it. Android 15+ measures glyph bounds instead (useBoundsForWidth).

Below API 35, PlatformAppCompatTextView measures the last glyph of each line and reserves the overhang as extra compound padding during measure/layout only (not drawing), so text stays within the clip bounds. Works for Start/Center/End alignment. LabelHandler uses that compound padding when narrowing multi-line Labels.

Not handled: left overhang on the first glyph, RTL, and italic spans inside a non-italic FormattedString. Cost: one extra measurement for italic Labels below API 35.

Context: the earlier PR #38379 for this issue only added the overhang to the desired width, which doesn't fix End-aligned text.

Verification

MAUI 11 Sandbox, API 31: 7–8px clipped in 6/12 cases before, none after. API 36: identical before/after. The device test's logic (run in the Sandbox) fails without the fix on API 31, passes with it.

Before/after API 31

Not verified: the device test itself didn't run.

Issues Fixed

Fixes #33315

…id 15

Before Android 15 TextView measures text by its advance width, while the slant of an italic last glyph is drawn past it, so a wrap-content or end-aligned Label clips it. Android 15 and later measure the glyph bounds (useBoundsForWidth).

Below API 35, PlatformAppCompatTextView now measures only the last glyph of each line and reserves its overhang as extra compound padding while measuring and laying out, but not while drawing. The text layout is narrower than the clip bounds by that amount, which works for Start, Center and End alignment, where adding padding or only widening the desired size would still clip. LabelHandler narrows multi-line labels using the compound padding so the reserved width is kept.

Not handled: a left overhang on the first glyph, right-to-left lines, and italic spans in FormattedString when the view typeface is not italic.

Fixes dotnet#33315
@github-actions

This comment has been minimized.

@dotnet-policy-service dotnet-policy-service Bot added the community ✨ Community Contribution label Nov 25, 2026
@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Hey there @marcelomoresco! Thank you so much for your PR! Someone from the team will get assigned to your PR shortly and we'll get it reviewed.

@azure-pipelines

This comment has been minimized.

@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 — 5 findings · ⚠️ 1 breaking change

Reviewed commit 3932423.

Warning

Existing apps would look or behave differently without opting in. See the Behavioral Change Disclosure findings at:

See inline comments for details.

Reserving the largest overhang of any line changed how already fitting text wrapped. The space is now reserved only when a glyph would really be drawn past the content width, and it is dropped again if reserving it changes the line breaks or truncates text that was not truncated. When the widest line leaves less room than the overhang, the previous behavior is kept.

The logic moves to ItalicOverhang, shared by PlatformAppCompatTextView and the new PlatformMaterialTextView, so that Material3 labels (MauiMaterialTextView) are fixed too. With head and middle truncation the last retained glyph is measured instead of the ellipsis.

Tests draw the views into a bitmap and compare the rightmost ink with an unclipped drawing, for both view types, gravities, head and middle truncation and a narrowed wrapped label, and check that line breaks match a plain TextView.
@kubaflo

This comment has been minimized.

@github-actions

This comment has been minimized.

@kubaflo

This comment has been minimized.

@github-actions

This comment has been minimized.

kubaflo added a commit that referenced this pull request Nov 26, 2026
…log refused dispatches (#40631)

### Description of Change

**Crash (from #40627).** Every `/review run-tests` dispatch since #40627
fails before posting its comment:

```
Invoke-RunTests.ps1:380  … -RunTestsStatuses -Repository $Repository -Sha $sha) | Where-Object {
You cannot call a method on a null-valued expression.
```

`Get-RunTestsStatuses` returns its list as a single object (`return ,
@(…)`), so `@(Get-RunTestsStatuses …)` nested it and `$_.context` was
the whole list. The list is now assigned first, and `context` is read as
a string. Seen on #40439 and #40294.

**net11 dispatches refused (diagnostics).** Since #40629 merged into
`net11`, creating the `run-tests/*` / `run-devicetests/*` branch for
`net11` PRs fails with `Resource not accessible by integration (HTTP
403)` (#40619, #40620, #40621). `main` PRs and `net11` dispatches before
that pushed fine. The log doesn't say what GitHub objects to, so when
the branch can't be created the script now logs the dispatch commit, its
parent, the test-merge and its base, and the files the commit changes.
That shows the cause on the next run.

### Testing

- New Pester test: `Get-RunTestsStatuses` returns a flat list, and
`Invoke-RunTests.ps1` no longer wraps it in `@()`. 77 pass; the 2
failures (`Pipeline templates`, `gates the device test pipeline on the
dispatch request`) also fail on `main` without this change.
- Called `Get-RunTestsStatuses` against a real commit (#40611 head): 7
statuses, filtering works.

Co-authored-by: Copilot CI <copilot-ci@microsoft.com>
KarthikRajaKalaimani pushed a commit to KarthikRajaKalaimani/maui that referenced this pull request Nov 26, 2026
…log refused dispatches (dotnet#40631)

### Description of Change

**Crash (from dotnet#40627).** Every `/review run-tests` dispatch since dotnet#40627
fails before posting its comment:

```
Invoke-RunTests.ps1:380  … -RunTestsStatuses -Repository $Repository -Sha $sha) | Where-Object {
You cannot call a method on a null-valued expression.
```

`Get-RunTestsStatuses` returns its list as a single object (`return ,
@(…)`), so `@(Get-RunTestsStatuses …)` nested it and `$_.context` was
the whole list. The list is now assigned first, and `context` is read as
a string. Seen on dotnet#40439 and dotnet#40294.

**net11 dispatches refused (diagnostics).** Since dotnet#40629 merged into
`net11`, creating the `run-tests/*` / `run-devicetests/*` branch for
`net11` PRs fails with `Resource not accessible by integration (HTTP
403)` (dotnet#40619, dotnet#40620, dotnet#40621). `main` PRs and `net11` dispatches before
that pushed fine. The log doesn't say what GitHub objects to, so when
the branch can't be created the script now logs the dispatch commit, its
parent, the test-merge and its base, and the files the commit changes.
That shows the cause on the next run.

### Testing

- New Pester test: `Get-RunTestsStatuses` returns a flat list, and
`Invoke-RunTests.ps1` no longer wraps it in `@()`. 77 pass; the 2
failures (`Pipeline templates`, `gates the device test pipeline on the
dispatch request`) also fail on `main` without this change.
- Called `Get-RunTestsStatuses` against a real commit (dotnet#40611 head): 7
statuses, filtering works.

Co-authored-by: Copilot CI <copilot-ci@microsoft.com>

@kubaflo kubaflo 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.

Related tests failed

At low densities the advances of the last glyph measured alone don't match the outline of the whole line, so the view could still be a fraction of a pixel narrower than the ink (174.39 in a 174 px view on CI).

The reserved space now comes from the path bounds of the displayed line, including the ellipsis, rounded up. Only lines that end within half a text size of the content edge are measured.
@kubaflo

This comment has been minimized.

@github-actions

github-actions Bot commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Selected Tests

@kubaflo — AI-selected UI tests and device tests (GPT-6.2 Sol + MAI Code 2) for commit 1e158508.

Result PASSED Platforms Android Tests 2 UI, 2 device Commit 1e158508


🧪 Test selection — click to expand
Suite Result Selected Build
UI tests ✅ passed 2 of 77 categories maui-pr-uitests #1701004
Device tests ✅ passed 2 of 105 units maui-pr-devicetests #1701015
🧪 UI tests — Label, Material3 on Android

✅ maui-pr-uitests #1701004 passed.

GPT-6.2 Sol: Run Android Label and Material3 UI tests for the italic glyph clipping fix.
MAI Code 2: Android-only italic Label overhang fix; runs Label and Material3 UI coverage on Android.

🧪 Ran — 2 categories on Android

Platform Categories
Android Label, Material3
📊 Results — succeeded: 4 passed, 0 failed of 4 jobs

🔗 All test results · Build logs

Job Result
Android UITests CoreClr Controls (API 30) Label ✅ succeeded
Android UITests Material3 Controls Material3 (API 36) ✅ succeeded
Build UITests CoreCLR Sample App Build Sample App ✅ succeeded
Build UITests Material3 Sample App Build Sample App (Material3) ✅ succeeded
🧪 Device tests — Controls.Label, Core.Label on Android

✅ maui-pr-devicetests #1701015 passed.

GPT-6.2 Sol: Run Android Core.Label and Controls.Label device tests for the italic Label rendering and measurement changes.
MAI Code 2: Android Label handler and native text-view changes; runs Core.Label and Controls.Label device tests on Android.

🧪 Ran — 2 categories on Android

Platform Categories
Android Controls.Label, Core.Label
📊 Results — succeeded: 2 passed, 0 failed of 2 jobs

🔗 All test results · Build logs

Job Result
net11.0 CoreCLR Android Helix Tests Run DeviceTests Android (CoreCLR) ✅ succeeded
net11.0 CoreCLR ios/catalyst/android Helix Tests Build Device Tests (CoreCLR) ✅ succeeded
⏭️ Skipped — what neither suite runs

UI tests — 75 categories, 3 platforms

Platforms not run: iOS, MacCatalyst, Windows

Categories not run: Accessibility, ActionSheet, ActivityIndicator, Animation, AppLinks, Border, BoxView, Brush, Button, CarouselView, CollectionView1, CollectionView2, CollectionView3, CollectionView4, CollectionView5, CollectionView6, CollectionView7, Cells, CheckBox, ContextActions, CustomRenderers, DatePicker, Dispatcher, DisplayAlert, DisplayPrompt, DragAndDrop, Entry, Editor, Effects, Essentials, FlyoutPage, Focus, Fonts, Frame, Gestures, GraphicsView, Image, ImageButton, IndicatorView, InputTransparent, IsEnabled, IsVisible, Layout, Lifecycle, ManualReview, Maps, Navigation, Page, Performance, Picker, ProgressBar, RadioButton, RefreshView, SafeAreaEdges, Shadow, ScrollView, SearchBar, Shape, Slider, SoftInput, Stepper, Switch, SwipeView, Shell1, Shell2, TabbedPage, TableView, TimePicker, TitleView, ToolbarItem, Triggers, ViewBaseTests, VisualStateManager, Window, WebView

Each skipped platform and category is listed as a maui-pr-uitests (skipped) … status on this commit. Use /azp run maui-pr-uitests for the full suite.

Device tests — 103 categories, 3 platforms

Platforms not run: iOS, MacCatalyst, Windows

Categories not run: Controls.Accessibility, Controls.Animations, Controls.Application, Controls.Behavior, Controls.Border, Controls.BoxView, Controls.Button, Controls.CarouselView, Controls.CheckBox, Controls.CollectionView, Controls.Compatibility, Controls.ContentView, Controls.DatePicker, Controls.Dispatcher, Controls.Editor, Controls.Element, Controls.Entry, Controls.FlexLayout, Controls.FlyoutPage, Controls.Frame, Controls.Gesture, Controls.HybridWebView, Controls.Image, Controls.Layout, Controls.Lifecycle, Controls.Map, Controls.Mapper, Controls.Memory, Controls.MenuFlyout, Controls.Modal, Controls.NavigationPage, Controls.Page, Controls.PageTransitions, Controls.Path, Controls.Picker, Controls.RadioButton, Controls.RefreshView, Controls.ScrollView, Controls.SearchBar, Controls.Shape, Controls.Shell, Controls.Slider, Controls.SwipeView, Controls.Switch, Controls.TabbedPage, Controls.TemplatedView, Controls.TextInput, Controls.Toolbar, Controls.View, Controls.VisualElement, Controls.VisualElementTree, Controls.WebView, Controls.Window, Controls.WindowOverlay, Controls.Xaml, Core.ActivityIndicator, Core.Animation, Core.Application, Core.Border, Core.BoxView, Core.Button, Core.CheckBox, Core.ContentView, Core.DatePicker, Core.Dispatcher, Core.Editor, Core.Element, Core.Entry, Core.FlowDirection, Core.FlyoutView, Core.Fonts, Core.Formatting, Core.Graphics, Core.GraphicsView, Core.Image, Core.ImageButton, Core.ImageSource, Core.IndicatorView, Core.Layout, Core.Lifecycle, Core.MauiContext, Core.Memory, Core.NavigationPage, Core.Page, Core.Picker, Core.ProgressBar, Core.RadioButton, Core.RefreshView, Core.ScrollView, Core.SearchBar, Core.ShapeView, Core.Slider, Core.Stepper, Core.SwipeView, Core.Switch, Core.TimePicker, Core.View, Core.WebView, Core.Window, Core.WindowOverlay, Graphics, Essentials, BlazorWebView

Each skipped platform and project is listed as a maui-pr-devicetests (skipped) … status on this commit. Use /azp run maui-pr-devicetests for the full suite.

🤖 Why these tests — AI rationale (GPT-6.2 Sol + MAI Code 2)

UI tests

Each model chose independently; every test that runs was selected by at least one of them.

Platform GPT-6.2 Sol MAI Code 2
Android Label, Material3 Label, Material3
iOS — —
MacCatalyst — —
Windows — —

GPT-6.2 Sol — Run Android Label and Material3 UI tests for the italic glyph clipping fix.

  • LabelHandler.Android.cs and PlatformAppCompatTextView change Android Label measurement and drawing.
  • MauiMaterialTextView uses the new native Material text view, so include Material3.
  • No shared UI code or other platform paths changed.

MAI Code 2 — Android-only italic Label overhang fix; runs Label and Material3 UI coverage on Android.

  • Android native TextView subclasses and LabelHandler.Android.cs change italic glyph measurement and compound padding, mapping to Label on Android.
  • MauiMaterialTextView now derives from the new platform Material text view, so include the dedicated Material3 UI lane.
  • No iOS, MacCatalyst, or Windows selection because the production changes and changed tests are Android-specific.
  • No full UI run is needed because the change is scoped to Label text measurement rather than shared UI infrastructure.

Device tests

Each model chose independently; every test that runs was selected by at least one of them.

Platform GPT-6.2 Sol MAI Code 2
Android Core.Label, Controls.Label Core.Label, Controls.Label
iOS — —
MacCatalyst — —
Windows — —

GPT-6.2 Sol — Run Android Core.Label and Controls.Label device tests for the italic Label rendering and measurement changes.

  • Core.Label covers the new clipping, alignment, truncation, and wrapping regressions in LabelHandlerTests.Android.cs.
  • Controls.Label covers the effect of the handler’s compound padding on real Labels.
  • No other platforms or device test units are affected.

MAI Code 2 — Android Label handler and native text-view changes; runs Core.Label and Controls.Label device tests on Android.

  • LabelHandler.Android.cs and both Android platform TextView implementations change Label handler behavior, mapping to Core.Label and Controls.Label.
  • The changed Android device tests exercise clipping, wrapping, and native text-view measurement directly.
  • Exclude non-Android platforms because all production and test changes are Android-specific.
  • No full device run is needed; the blast radius is limited to Label rendering and measurement.

Generated by /review run-tests. A targeted run is a fast signal, not full-suite certification.

@kubaflo

kubaflo commented Nov 26, 2026

Copy link
Copy Markdown
Contributor

Thanks for investigating and contributing this fix. We're closing this PR because the workaround adds substantial complexity for an issue that does not reproduce on newer Android versions (Android 15 and later).

@kubaflo kubaflo closed this Nov 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

community ✨ Community Contribution

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Android] - the last character clipped in the Label with the "Italic" property

2 participants