Skip to content

cobalt: Restore Cobalt 25 synthetic bold for fallback fonts - #13714

Merged
andrewsavage1 merged 2 commits into
youtube:mainfrom
andrewsavage1:fix-cjk-synthetic-bold
Nov 2, 2026
Merged

andrewsavage1 merged 2 commits into
youtube:mainfrom
andrewsavage1:fix-cjk-synthetic-bold

Conversation

@andrewsavage1

@andrewsavage1 andrewsavage1 commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

FontCache::PlatformFallbackFontForCharacter on Starboard only enabled synthetic bold when FontDescription::IsSyntheticBold() was set. That flag is not set for an ordinary CSS font-weight: bold, so text that resolves via character fallback to a Regular-only face (e.g. CJK via NotoSansCJK-Regular, weight 400) was never emboldened. This is a regression from Cobalt 25.

This restores the Cobalt 25 rule from cobalt/renderer/rasterizer/skia/text_shaper.cc (ShouldEmbolden):

if (font_provider->style().weight > 500)   // 100-step weight enum
  return typeface->synthesizes_bold();     // !isBold() && !disable_synthetic_bolding
  • Blink (font_cache_starboard.cc): synthesize bold when isFontWeightBold(weight) (Blink's kBoldThreshold = 600, equivalent to C25's > 500 on its 100-step enum) and !typeface->isBold() (same Skia check C25 used).
  • SkTypeface_Cobalt: override onFilterRec to drop kEmbolden_Flag when !synthesizes_bold_, so the disable_synthetic_bolding fonts.xml attribute (NotoColorEmoji, DroidSansFallback) is honored again. It was parsed but unused in Cobalt 27.
  • Italic synthesis is unchanged (C25 did not synthesize italic).

Testing

RDK (evergreen-arm-hardfp-rdk_qa), page rendering the ETC Localization strings at weight 400 vs 700 and comparing inked pixels via canvas:

Locale Before After After, CJK marked disable_synthetic_bolding
zh-TW 開朗 1.000 1.589 1.000
ko 밝음 1.000 1.620 1.000
zh 欢快 1.000 1.633 1.000
zh-HK 樂觀 1.000 1.610 1.000
en Bright 1.479 1.479 1.479

Bug: 577839103
TAG=agy
CONV=aa9a1512-4172-4d51-a830-f0632fee17fa

@andrewsavage1 andrewsavage1 added the cp-27.lts Cherry Pick to the 27.lts branch label Oct 29, 2026
@github-actions

github-actions Bot commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor
Context State Description
CI / All Pass ⏳ PENDING Checks are running
CI / android ✅ PASS Passed
CI / evergreen ✅ PASS Passed
CI / linux ✅ PASS Passed
CI / tvos ⏳ PENDING Checks are running
@github-actions

Copy link
Copy Markdown
Contributor

🤖 Gemini Suggested Commit Message


starboard: Synthesize bold/italic for fallback

Character fallback fonts on Starboard were not applying synthetic bold
or italic styles when requested via CSS font-weight or font-style.
The previous logic only enabled synthesis when specific synthetic
flags were set, causing text that resolved to Regular-only faces to
lack emboldening.

This change updates the fallback logic to compare requested weight and
style against the typeface properties. This ensures synthesis is
triggered when the requested weight exceeds the typeface weight or
when italic is requested for a non-italic face, restoring behavior
from Cobalt 25 and aligning with the Skia font cache.

Bug: 577839103

💡 Pro Tips for a Better Commit Message:

  1. Influence the Result: Want to change the output? You can write custom prompts or instructions directly in the Pull Request description. The model uses that text to generate the message.
  2. Re-run the Generator: Post a comment with: /generate-commit-message

@gemini-code-assist gemini-code-assist 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.

Code Review

This pull request updates the font synthesis logic in font_cache_starboard.cc to mirror the standard Blink behavior, ensuring that synthetic bold and italic styles are applied when fallback typefaces do not meet the requested weight or style. The review feedback correctly identifies an issue where using the > operator instead of >= prevents synthetic bold from being applied when the requested weight is exactly 200 units heavier than the typeface (such as requesting Semi-Bold 600 with a Regular 400 fallback). Updating this operator to >= will resolve this issue.

FontCache::PlatformFallbackFontForCharacter on Starboard only enabled
synthetic bold when FontDescription::IsSyntheticBold() was set, which is
not the case for an ordinary CSS `font-weight: bold`. Text that resolves
via character fallback to a Regular-only face (e.g. CJK via
NotoSansCJK-Regular) was therefore never emboldened, a regression from
Cobalt 25.

Restore the Cobalt 25 rule (text_shaper.cc ShouldEmbolden):
  - Blink: synthesize bold when the requested weight is bold
    (isFontWeightBold(), i.e. >= kBoldThreshold; Cobalt 25 used `> 500`
    on a 100-step weight enum, which is equivalent) and the typeface is
    not bold (SkTypeface::isBold()).
  - SkTypeface_Cobalt: drop SkFont embolden for typefaces that do not
    synthesize bold, so `disable_synthetic_bolding` in fonts.xml (e.g.
    NotoColorEmoji, DroidSansFallback) is honored again. It was parsed
    but unused in Cobalt 27.

Italic synthesis is unchanged (Cobalt 25 did not synthesize italic).

Bug: 577839103
TAG=agy
CONV=aa9a1512-4172-4d51-a830-f0632fee17fa
@andrewsavage1
andrewsavage1 force-pushed the fix-cjk-synthetic-bold branch from 1ee2ae6 to b4ed645 Compare October 29, 2026 14:35
@andrewsavage1 andrewsavage1 changed the title blink: Synthesize bold/italic for Starboard character fallback fonts Oct 29, 2026

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

Nice fix! Just a couple of small comments, otherwise LGTM.

Add SkFontMgr_cobalt unit tests verifying that SkFont::setEmbolden
widens glyphs of a Regular typeface but is ignored for Bold typefaces
and for typefaces marked disable_synthetic_bolding in fonts.xml. Add
FontCache tests for synthetic bold on character fallback. Remove the
now-unused SkTypeface_Cobalt::synthesizes_bold() getter.

Bug: 577839103
@andrewsavage1
andrewsavage1 enabled auto-merge (squash) November 2, 2026 15:18
@andrewsavage1
andrewsavage1 merged commit 2ddebfe into youtube:main Nov 2, 2026
928 of 945 checks passed
cobalt-github-releaser-bot pushed a commit that referenced this pull request Nov 2, 2026
…allback fonts

Refer to original PR: #13714

`FontCache::PlatformFallbackFontForCharacter` on Starboard only enabled
synthetic bold when `FontDescription::IsSyntheticBold()` was set. That
flag is not set for an ordinary CSS `font-weight: bold`, so text that
resolves via character fallback to a Regular-only face (e.g. CJK via
`NotoSansCJK-Regular`, weight 400) was never emboldened. This is a
regression from Cobalt 25.

This restores the Cobalt 25 rule from
`cobalt/renderer/rasterizer/skia/text_shaper.cc` (`ShouldEmbolden`):

```cpp
if (font_provider->style().weight > 500)   // 100-step weight enum
  return typeface->synthesizes_bold();     // !isBold() && !disable_synthetic_bolding
```

- **Blink** (`font_cache_starboard.cc`): synthesize bold when
`isFontWeightBold(weight)` (Blink's `kBoldThreshold` = 600, equivalent
to C25's `> 500` on its 100-step enum) and `!typeface->isBold()` (same
Skia check C25 used).
- **SkTypeface_Cobalt**: override `onFilterRec` to drop `kEmbolden_Flag`
when `!synthesizes_bold_`, so the `disable_synthetic_bolding` fonts.xml
attribute (NotoColorEmoji, DroidSansFallback) is honored again. It was
parsed but unused in Cobalt 27.
- Italic synthesis is unchanged (C25 did not synthesize italic).

### Testing
RDK (`evergreen-arm-hardfp-rdk_qa`), page rendering the ETC Localization
strings at weight 400 vs 700 and comparing inked pixels via canvas:

| Locale | Before | After | After, CJK marked
`disable_synthetic_bolding` |
|---|---|---|---|
| zh-TW 開朗 | 1.000 | 1.589 | 1.000 |
| ko 밝음 | 1.000 | 1.620 | 1.000 |
| zh 欢快 | 1.000 | 1.633 | 1.000 |
| zh-HK 樂觀 | 1.000 | 1.610 | 1.000 |
| en Bright | 1.479 | 1.479 | 1.479 |

Bug: 577839103
TAG=agy
CONV=aa9a1512-4172-4d51-a830-f0632fee17fa

(cherry picked from commit 2ddebfe)
cobalt-github-releaser-bot pushed a commit that referenced this pull request Nov 3, 2026
…allback fonts

Refer to original PR: #13714

`FontCache::PlatformFallbackFontForCharacter` on Starboard only enabled
synthetic bold when `FontDescription::IsSyntheticBold()` was set. That
flag is not set for an ordinary CSS `font-weight: bold`, so text that
resolves via character fallback to a Regular-only face (e.g. CJK via
`NotoSansCJK-Regular`, weight 400) was never emboldened. This is a
regression from Cobalt 25.

This restores the Cobalt 25 rule from
`cobalt/renderer/rasterizer/skia/text_shaper.cc` (`ShouldEmbolden`):

```cpp
if (font_provider->style().weight > 500)   // 100-step weight enum
  return typeface->synthesizes_bold();     // !isBold() && !disable_synthetic_bolding
```

- **Blink** (`font_cache_starboard.cc`): synthesize bold when
`isFontWeightBold(weight)` (Blink's `kBoldThreshold` = 600, equivalent
to C25's `> 500` on its 100-step enum) and `!typeface->isBold()` (same
Skia check C25 used).
- **SkTypeface_Cobalt**: override `onFilterRec` to drop `kEmbolden_Flag`
when `!synthesizes_bold_`, so the `disable_synthetic_bolding` fonts.xml
attribute (NotoColorEmoji, DroidSansFallback) is honored again. It was
parsed but unused in Cobalt 27.
- Italic synthesis is unchanged (C25 did not synthesize italic).

### Testing
RDK (`evergreen-arm-hardfp-rdk_qa`), page rendering the ETC Localization
strings at weight 400 vs 700 and comparing inked pixels via canvas:

| Locale | Before | After | After, CJK marked
`disable_synthetic_bolding` |
|---|---|---|---|
| zh-TW 開朗 | 1.000 | 1.589 | 1.000 |
| ko 밝음 | 1.000 | 1.620 | 1.000 |
| zh 欢快 | 1.000 | 1.633 | 1.000 |
| zh-HK 樂觀 | 1.000 | 1.610 | 1.000 |
| en Bright | 1.479 | 1.479 | 1.479 |

Bug: 577839103
TAG=agy
CONV=aa9a1512-4172-4d51-a830-f0632fee17fa

(cherry picked from commit 2ddebfe)
briantting pushed a commit that referenced this pull request Nov 3, 2026
…allback fonts

Refer to original PR: #13714

`FontCache::PlatformFallbackFontForCharacter` on Starboard only enabled
synthetic bold when `FontDescription::IsSyntheticBold()` was set. That
flag is not set for an ordinary CSS `font-weight: bold`, so text that
resolves via character fallback to a Regular-only face (e.g. CJK via
`NotoSansCJK-Regular`, weight 400) was never emboldened. This is a
regression from Cobalt 25.

This restores the Cobalt 25 rule from
`cobalt/renderer/rasterizer/skia/text_shaper.cc` (`ShouldEmbolden`):

```cpp
if (font_provider->style().weight > 500)   // 100-step weight enum
  return typeface->synthesizes_bold();     // !isBold() && !disable_synthetic_bolding
```

- **Blink** (`font_cache_starboard.cc`): synthesize bold when
`isFontWeightBold(weight)` (Blink's `kBoldThreshold` = 600, equivalent
to C25's `> 500` on its 100-step enum) and `!typeface->isBold()` (same
Skia check C25 used).
- **SkTypeface_Cobalt**: override `onFilterRec` to drop `kEmbolden_Flag`
when `!synthesizes_bold_`, so the `disable_synthetic_bolding` fonts.xml
attribute (NotoColorEmoji, DroidSansFallback) is honored again. It was
parsed but unused in Cobalt 27.
- Italic synthesis is unchanged (C25 did not synthesize italic).

### Testing
RDK (`evergreen-arm-hardfp-rdk_qa`), page rendering the ETC Localization
strings at weight 400 vs 700 and comparing inked pixels via canvas:

| Locale | Before | After | After, CJK marked
`disable_synthetic_bolding` |
|---|---|---|---|
| zh-TW 開朗 | 1.000 | 1.589 | 1.000 |
| ko 밝음 | 1.000 | 1.620 | 1.000 |
| zh 欢快 | 1.000 | 1.633 | 1.000 |
| zh-HK 樂觀 | 1.000 | 1.610 | 1.000 |
| en Bright | 1.479 | 1.479 | 1.479 |

Bug: 577839103
TAG=agy
CONV=aa9a1512-4172-4d51-a830-f0632fee17fa

(cherry picked from commit 2ddebfe)
andrewsavage1 added a commit that referenced this pull request Nov 24, 2026
…allback fonts (#13714) (#14234)

Refer to original PR: #13714

`FontCache::PlatformFallbackFontForCharacter` on Starboard only enabled
synthetic bold when `FontDescription::IsSyntheticBold()` was set. That
flag is not set for an ordinary CSS `font-weight: bold`, so text that
resolves via character fallback to a Regular-only face (e.g. CJK via
`NotoSansCJK-Regular`, weight 400) was never emboldened. This is a
regression from Cobalt 25.

This restores the Cobalt 25 rule from
`cobalt/renderer/rasterizer/skia/text_shaper.cc` (`ShouldEmbolden`):

```cpp
if (font_provider->style().weight > 500)   // 100-step weight enum
  return typeface->synthesizes_bold();     // !isBold() && !disable_synthetic_bolding
```

- **Blink** (`font_cache_starboard.cc`): synthesize bold when
`isFontWeightBold(weight)` (Blink's `kBoldThreshold` = 600, equivalent
to C25's `> 500` on its 100-step enum) and `!typeface->isBold()` (same
Skia check C25 used).
- **SkTypeface_Cobalt**: override `onFilterRec` to drop `kEmbolden_Flag`
when `!synthesizes_bold_`, so the `disable_synthetic_bolding` fonts.xml
attribute (NotoColorEmoji, DroidSansFallback) is honored again. It was
parsed but unused in Cobalt 27.
- Italic synthesis is unchanged (C25 did not synthesize italic).

### Testing
RDK (`evergreen-arm-hardfp-rdk_qa`), page rendering the ETC Localization
strings at weight 400 vs 700 and comparing inked pixels via canvas:

| Locale | Before | After | After, CJK marked
`disable_synthetic_bolding` |
|---|---|---|---|
| zh-TW 開朗 | 1.000 | 1.589 | 1.000 |
| ko 밝음 | 1.000 | 1.620 | 1.000 |
| zh 欢快 | 1.000 | 1.633 | 1.000 |
| zh-HK 樂觀 | 1.000 | 1.610 | 1.000 |
| en Bright | 1.479 | 1.479 | 1.479 |

Bug: 577839103
TAG=agy
CONV=aa9a1512-4172-4d51-a830-f0632fee17fa

(cherry picked from commit 2ddebfe)


---
Manual cherry-pick to staging. The first commit is the bot-style
CONFLICTED cherry-pick, and the second resolves the conflicts against
current staging:

Conflicts in SkTypeface_cobalt.{h,cc} were signature drift only:
staging's
Skia uses the SkSpan-based onCharsToGlyphs. Kept staging's SkSpan
onCharsToGlyphs declaration/definition and added the PR's onFilterRec
override (plus SkScalerContext.h include), and dropped the unused
synthesizes_bold() accessor as the PR does. In
SkFontMgr_cobalt_unittest.cc,
replaced the removed pointer/count SkFont::getBounds overload with the
single-glyph getBounds(glyph, paint) form available on staging.


When squash-merging, keep this description as the commit message so the
'Refer to original PR' and 'cherry picked from' lines stay in staging's
history.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cp-27.lts Cherry Pick to the 27.lts branch

3 participants