Skip to content

feat: Add SkiaFontRegistrar to fix CJK/icon-font garbling on Android#8

Merged
michaelstonis merged 3 commits into
mainfrom
copilot/fix-japanese-text-garbled-android
May 5, 2026
Merged

feat: Add SkiaFontRegistrar to fix CJK/icon-font garbling on Android#8
michaelstonis merged 3 commits into
mainfrom
copilot/fix-japanese-text-garbled-android

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 5, 2026

On Android, SKFontManager.Default does not expose CJK or icon-font typefaces. SkiaDrawingContext was falling through to SKTypeface.FromFamilyName() which silently returned the default Latin typeface, rendering Japanese headers as garbled boxes (see screenshot above).

Core fix — KumikoUI.SkiaSharp

New SkiaFontRegistrar static class — a thread-safe registry that bypasses the system font manager entirely for named families:

Method Ownership
RegisterTypeface(family, typeface) Caller retains
RegisterTypefaceFromStream(family, stream) Registrar owns; disposed on Clear()
TryGetTypeface / IsRegistered / Clear Internal + lifecycle

SkiaDrawingContext changes:

  • GetOrCreateTypeface() checks SkiaFontRegistrar first before SKTypeface.FromFamilyName()
  • Dispose() skips registered typefaces (externally owned — must not be disposed per-frame)

Sample app

  • NotoSansJP-Regular.ttf and MaterialIcons-Regular.ttf added to Resources/Raw/
  • MauiProgram.cs registers both at startup via a safe blocking load (pre-message-loop)
  • New Custom Fonts tab (CustomFontsPage) demonstrates Japanese column headers and a Material Icons icon-font cell renderer

Usage

// MauiProgram.cs
using var stream = FileSystem.OpenAppPackageFileAsync("NotoSansJP-Regular.ttf")
    .GetAwaiter().GetResult(); // safe — no sync-context before MAUI message loop starts
SkiaFontRegistrar.RegisterTypefaceFromStream("NotoSansJP", stream);

// DataGridStyle
style.HeaderFont = new GridFont("NotoSansJP", 14, bold: true);
style.CellFont   = new GridFont("NotoSansJP", 13);

Icon fonts work identically — set GridFont.Family to the registered name and use Unicode code-point strings as cell values.

…on-font garbling on Android)

Agent-Logs-Url: https://github.com/TheEightBot/KumikoUI/sessions/aae0dae4-a66d-4053-9c89-362b4641aeed

Co-authored-by: michaelstonis <120685+michaelstonis@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix garbled Japanese text in DataGridColumn.Header on Android feat: Add SkiaFontRegistrar to fix CJK/icon-font garbling on Android May 5, 2026
Copilot AI requested a review from michaelstonis May 5, 2026 02:49
…ellRenderer

Update the property reference to SelectionTextColor to ensure the correct style is applied when a cell is selected.
@michaelstonis michaelstonis marked this pull request as ready for review May 5, 2026 16:39
@michaelstonis michaelstonis merged commit 4e36008 into main May 5, 2026
2 checks passed
@michaelstonis michaelstonis deleted the copilot/fix-japanese-text-garbled-android branch May 5, 2026 16:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

Japanese text in DataGridColumn.Header becomes garbled on Android (font fallback issue)

2 participants