Skip to content

fonts: Use OS/2 table to determine if font face is already bold when synthesizing bold face for FreeType platform#39681

Merged
mrobinson merged 7 commits intoservo:mainfrom
minghuaw:fix/face-is-bold-ft
Oct 7, 2025
Merged

fonts: Use OS/2 table to determine if font face is already bold when synthesizing bold face for FreeType platform#39681
mrobinson merged 7 commits intoservo:mainfrom
minghuaw:fix/face-is-bold-ft

Conversation

@minghuaw
Copy link
Copy Markdown
Contributor

@minghuaw minghuaw commented Oct 6, 2025

The previous implementation in #39519 mistakenly used the FontTemplateDescriptor to determine whether the font face itself is already bold. This PR fixes that by using the usWeightClass in the OS/2 table of the font face to determine if the font face is bold already.

Testing: A new testcase /tests/wpt/mozilla/tests/css/font_synthesis_weight_static_bold.html is getting added in #39633. This test checks whether a bold font face gets "double emboldened"
Depends on: #39633

@minghuaw minghuaw requested a review from nicoburns as a code owner October 6, 2025 08:09
@servo-highfive servo-highfive added the S-awaiting-review There is new code that needs to be reviewed. label Oct 6, 2025
@minghuaw minghuaw mentioned this pull request Oct 6, 2025
8 tasks
Signed-off-by: Minghua Wu <[email protected]>
Comment on lines +134 to +143
let face_is_bold = unsafe {
let ptr = FT_Get_Sfnt_Table(face.as_ptr(), ft_sfnt_os2);
let os2_table: *mut TT_OS2 = std::mem::transmute(ptr);
if os2_table.is_null() {
false
} else {
(*os2_table).usWeightClass >= BOLD_THRESHOLD
}
};

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.

Isn't it possible to use fontations here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Interesting. I haven't thought about that. Let me give it a shot

Copy link
Copy Markdown
Contributor Author

@minghuaw minghuaw Oct 6, 2025

Choose a reason for hiding this comment

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

Tried to use fontations here in commit 2db1142 and 82f9f6a

@minghuaw minghuaw requested a review from mrobinson October 6, 2025 18:50
@minghuaw minghuaw changed the title fonts: Use TT_OS2 table to determine if font face is already bold when synthesizing bold face for FreeType platform fonts: Use OS/2 table to determine if font face is already bold when synthesizing bold face for FreeType platform Oct 6, 2025
Signed-off-by: Minghua Wu <[email protected]>
Copy link
Copy Markdown
Member

@mrobinson mrobinson left a comment

Choose a reason for hiding this comment

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

Does this also need to happen for web fonts?

@servo-highfive servo-highfive removed the S-awaiting-review There is new code that needs to be reviewed. label Oct 7, 2025
Co-authored-by: Martin Robinson <[email protected]>
Signed-off-by: minghuaw <[email protected]>
@servo-highfive servo-highfive added the S-awaiting-review There is new code that needs to be reviewed. label Oct 7, 2025
minghuaw and others added 2 commits October 7, 2025 15:17
Co-authored-by: Martin Robinson <[email protected]>
Signed-off-by: minghuaw <[email protected]>
Signed-off-by: Minghua Wu <[email protected]>
@mrobinson mrobinson enabled auto-merge October 7, 2025 08:01
@minghuaw
Copy link
Copy Markdown
Contributor Author

minghuaw commented Oct 7, 2025

Does this also need to happen for web fonts?

Yeah, it should. I thought this would be already handled by PlatformFontMethods::new_from_data, but I'm not quite sure about how webfonts are handled yet. Let me take a look

@mrobinson mrobinson added this pull request to the merge queue Oct 7, 2025
@servo-highfive servo-highfive added the S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. label Oct 7, 2025
Merged via the queue into servo:main with commit 81cd587 Oct 7, 2025
25 checks passed
@servo-highfive servo-highfive removed the S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. label Oct 7, 2025
@minghuaw minghuaw deleted the fix/face-is-bold-ft branch October 7, 2025 09:56
@minghuaw
Copy link
Copy Markdown
Contributor Author

minghuaw commented Oct 8, 2025

Does this also need to happen for web fonts?

@mrobinson I just realized that I forgot to implement this for new_from_data. I'll open a new PR for that

Edit: I've openend a new PR for the webfont #39713

github-merge-queue bot pushed a commit that referenced this pull request Oct 9, 2025
…t on FreeType platform (#39713)

This is to fix my oversight in the previous PR #39681 where the use of
OS/2 table to determine a synthetic bold face should be applied is not
applied to web font.

Testing: Added a new test
`tests/wpt/mozilla/tests/css/font_synthesis_weight_webfont_bold.html`
that checks if an already-bold webfont is "double emboldened"
Part of #39637

---------

Signed-off-by: Minghua Wu <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-awaiting-review There is new code that needs to be reviewed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants