Skip to content

Faux italic when the font does not support it#542

Merged
JimBobSquarePants merged 1 commit into
SixLabors:mainfrom
christianrondeau:faux-italic
Jul 10, 2026
Merged

Faux italic when the font does not support it#542
JimBobSquarePants merged 1 commit into
SixLabors:mainfrom
christianrondeau:faux-italic

Conversation

@christianrondeau

Copy link
Copy Markdown
Contributor

Prerequisites

  • I have written a descriptive pull-request title
  • I have verified that there are no overlapping pull-requests open
  • I have verified that I am following matches the existing coding patterns and practice as demonstrated in the repository. These follow strict Stylecop rules 👮.
  • I have provided test coverage for my change (where applicable)

Description

Some fonts may not provide native italic, and most text rendering engines will fallback to faux-italic (simply slant the text). ImageSharp does not provide that function, which means italic text is simply rendered upright. The italic slant specifications are vague, but the default seems to be 14 degrees (https://www.w3.org/TR/css-fonts-4/).

Disclaimer: this code was written using AI (Copilot with Claude Opus 4.8), and reviewed by me.

image

This solves the italic part of SixLabors/ImageSharp.Drawing#408 - the weight (bold) may be a bit more complex and will be provided as a separate PR.

@codecov

codecov Bot commented Jul 10, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 84%. Comparing base (18925d5) to head (e162989).

Additional details and impacted files
@@          Coverage Diff          @@
##            main    #542   +/-   ##
=====================================
  Coverage     84%     84%           
=====================================
  Files        332     332           
  Lines      24684   24708   +24     
  Branches    3612    3618    +6     
=====================================
+ Hits       20785   20813   +28     
+ Misses      3011    3009    -2     
+ Partials     888     886    -2     
Flag Coverage Δ
unittests 84% <100%> (+<1%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@JimBobSquarePants JimBobSquarePants left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for this. I’m going to accept this PR with a caveat.
The approach is directionally correct: synthetic italic belongs in Fonts rather than in individual renderers, and the chosen skew is close to browser/Skia behavior. Chromium/Skia use a 1/4 skew for synthetic italic, which is approximately a 14 degree slant, and synthetic italic should not change advance width.
I’ll likely need to adjust this after merging into my local branch because the rendering path has changed there, but the behavior this PR is aiming for is the behavior I want.

@JimBobSquarePants JimBobSquarePants merged commit 38b3e5a into SixLabors:main Jul 10, 2026
10 checks passed
@christianrondeau

Copy link
Copy Markdown
Contributor Author

Thank you, looking forward to seeing the new rendering branch (ImageSharp has among the best code I've seen, so I'm always keen to learn from it!)

@christianrondeau christianrondeau deleted the faux-italic branch July 10, 2026 15:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants