Skip to content

Preserve synthetic bold for regular-only font fallback#500

Merged
wieslawsoltes merged 2 commits into
masterfrom
fix/issue-462-synthetic-bold
May 9, 2026
Merged

Preserve synthetic bold for regular-only font fallback#500
wieslawsoltes merged 2 commits into
masterfrom
fix/issue-462-synthetic-bold

Conversation

@wieslawsoltes
Copy link
Copy Markdown
Owner

Preserve synthetic bold for regular-only font fallback

Related Issue

Fixes #462.

Problem

SVG text with font-weight="bold" can render too light, and in the reported Fabric.js output it appeared clipped or visually incomplete, when the requested font family only has a regular face available. The reporter narrowed the case to Century BT fonts where no bold TTF is installed.

Svg.Skia already had synthetic bold support in SkiaModel.ApplyTypefaceAdjustments: when a shim SKPaint asks for a heavier typeface than Skia resolves, the native Skia paint enables FakeBoldText.

The issue was that SkiaSvgAssetLoader.FindTypefaces and FindRunTypeface converted the resolved native typeface back into the shim typeface using the resolved face weight. If Skia resolved a regular face for a requested bold font, the retained text command later carried only the regular weight. At render time ApplyTypefaceAdjustments no longer saw a heavier requested weight, so synthetic bold was not enabled.

Changes

  • Preserve the requested font weight when converting resolved native typefaces back to shim typefaces.
  • Only preserve that requested weight when the original paint actually carried a requested typeface.
  • Keep generic or no-typeface fallback behavior tied to the resolved typeface's real weight, so ordinary fallback does not become accidentally emboldened.
  • Apply the same conversion behavior to both fallback paths:
    • FindTypefaces, used for per-span fallback.
    • FindRunTypeface, used for full-run browser-compatible text resolution.

Tests

Added Issue462Tests covering regular-only font resolution with a requested bold shim typeface:

  • FindTypefaces_PreservesRequestedBoldForRegularOnlyResolvedFace
  • FindRunTypeface_PreservesRequestedBoldForRegularOnlyResolvedFace

The tests use the existing SvgUnitTest.GetFontsPath fixture helper with SourceSansPro-Regular.ttf and a custom regular-only typeface provider. They verify that the shim typeface keeps the requested bold weight and that native paint conversion enables FakeBoldText.

Validation

Ran:

dotnet format Svg.Skia.slnx --no-restore --include src/Svg.Skia/SkiaSvgAssetLoader.cs tests/Svg.Skia.UnitTests/Issue462Tests.cs
dotnet test tests/Svg.Skia.UnitTests/Svg.Skia.UnitTests.csproj -f net10.0 -c Release --no-restore --filter "Issue405|Issue462"
dotnet build src/Svg.Skia/Svg.Skia.csproj -c Release --no-restore
git diff --check

Results:

  • Focused Issue405 and Issue462 tests passed: 8 passed.
  • Svg.Skia.csproj Release build passed with 0 warnings and 0 errors.
  • Diff whitespace check passed.

Notes

The full solution build was not used as the final validation boundary because this local checkout was missing restored assets for many unrelated projects and the local SDK environment lacks .NET Framework 4.6.1 reference assemblies. The changed project and focused regression coverage both pass.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bold Font Rendering - Clipped Text

1 participant