Skip to content

font: Refactor font list generation on OpenHarmony platform#44061

Merged
jschwe merged 2 commits into
servo:mainfrom
RichardTjokroutomo:ohos_font_list
Apr 9, 2026
Merged

font: Refactor font list generation on OpenHarmony platform#44061
jschwe merged 2 commits into
servo:mainfrom
RichardTjokroutomo:ohos_font_list

Conversation

@RichardTjokroutomo

@RichardTjokroutomo RichardTjokroutomo commented Apr 9, 2026

Copy link
Copy Markdown
Contributor

font: Use read_fonts module to generate font list on OpenHarmony platform. Specifically:

  • Family name is obtained from the font's name table.
  • width & weight is obtained from the font's os2 table.
  • style is obtained from the font's postscript table.

Additionally, I'd like to mention that I plan to add a caching mechanism to store the font list in the near future (as mentioned in the related issue)

Reference: TrueType reference manual
Testing: No behavior changes expected.
Fixes: Part of #43596

Signed-off-by: Richard Tjokroutomo <richard.tjokro2@gmail.com>
@servo-highfive servo-highfive added the S-awaiting-review There is new code that needs to be reviewed. label Apr 9, 2026
@RichardTjokroutomo

RichardTjokroutomo commented Apr 9, 2026

Copy link
Copy Markdown
Contributor Author

latest test run

p.s. I just noticed a while later that I've been running linux tests, so please ignore this and refer to the try run from this PR instead

@RichardTjokroutomo

Copy link
Copy Markdown
Contributor Author

cc @jschwe

UnicodeBlock::HangulSyllables => {
families.push("Noto Sans CJK");
families.push("Noto Serif CJK");
families.push("Noto Sans CJK KR");

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.

NotoSansCJK-Regular.ttc contains many fonts, such as Noto Sans CJK KR, Noto Sans CJK SC, etc.

Previously, since the font list creates the family name from the filename itself, the family name created from this specific font file is Noto Sans CJK. However, now that we obtain the family name from the font's name table, we need to change these into more specific family names, such as Noto Sans CJK KR.

Comment thread components/fonts/platform/freetype/ohos/font_list.rs Outdated
Comment thread components/fonts/platform/freetype/ohos/font_list.rs Outdated
Comment on lines 148 to 153
@@ -188,12 +151,6 @@ fn split_noto_font_name(name: &str) -> Vec<String> {
/// `fontconfig.json` fails for some reason. Beta 1 of OH 5.0 still has a bug in the fontconfig.json
/// though, so the "normal path" is currently unimplemented.
fn parse_font_filenames(font_files: Vec<PathBuf>) -> Vec<FontFamily> {

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.

Perhaps the function name and documentation should be updated.

@jschwe jschwe added the T-ohos Do a try run on OpenHarmony label Apr 9, 2026
@github-actions github-actions Bot removed the T-ohos Do a try run on OpenHarmony label Apr 9, 2026
@github-actions

github-actions Bot commented Apr 9, 2026

Copy link
Copy Markdown

🔨 Triggering try run (#24184326332) for OpenHarmony

@github-actions

github-actions Bot commented Apr 9, 2026

Copy link
Copy Markdown

🐰 Bencher Report

Branch44061/PR
TestbedHUAWEI Mate 80 Pro

⚠️ WARNING: Truncated view!

The full continuous benchmarking report exceeds the maximum length allowed on this platform.

⚠️ WARNING: No Threshold found!

Without a Threshold, no Alerts will ever be generated.

🐰 View full continuous benchmarking report in Bencher

@github-actions

github-actions Bot commented Apr 9, 2026

Copy link
Copy Markdown

✨ Try run (#24184326332) succeeded.

@RichardTjokroutomo

Copy link
Copy Markdown
Contributor Author

latest test run

I just realized I ran the test on linux...

@RichardTjokroutomo

Copy link
Copy Markdown
Contributor Author

@jschwe Thanks for the review! I've pushed the suggested changes & removed some redundant tests as well

Comment on lines 150 to 152
/// Note: For OH 5.0+ this function is intended to only be a fallback path, if parsing the
/// `fontconfig.json` fails for some reason. Beta 1 of OH 5.0 still has a bug in the fontconfig.json
/// though, so the "normal path" is currently unimplemented.

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.

I think this comment is also outdated now though, right?

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.

huh, forgot to update it. my bad..

let style_modifiers = ["Italic"];
let width_modifiers = ["Condensed"];

fn get_system_font_families(font_files: Vec<PathBuf>) -> Vec<FontFamily> {

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.

Maybe we should also instrument this function with #[servo_tracing::instrument(skip_all)] so we can track how long it takes.

@RichardTjokroutomo RichardTjokroutomo Apr 9, 2026

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.

Sure.

BTW, I only mention adding caching mechanism in the near future in the related issue, let me update the PR description as well

let mut families = enumerate_font_files()
.inspect_err(|e| error!("Failed to enumerate font files due to `{e:?}`"))
.map(parse_font_filenames)
.map(get_system_font_families)

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.

If this takes long, we might want to cache this, although that could / should be a followup PR.

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

Looks fine to me, except the nit about the outdated documentation comment, please adjust that

@servo-highfive servo-highfive removed the S-awaiting-review There is new code that needs to be reviewed. label Apr 9, 2026
@servo-highfive servo-highfive added the S-awaiting-review There is new code that needs to be reviewed. label Apr 9, 2026
Signed-off-by: Richard Tjokroutomo <richard.tjokro2@gmail.com>
}
},
Collection(font_collection) => {
// Process all the font files within the collection one by one.

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.

Depending on how long this takes, we could consider using a par_iter here via rayon, to make the first-start faster. (but also future PR stuff)

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.

There could be many fonts within one collection; for your reference, there are 10 fonts in NotoSansCJK-Regular.ttc. But there aren't many .ttc files in the first place (at least in Huawei Mate60).

But yeah; parallelizing it sounds like a cool idea :)

@servo-highfive servo-highfive removed the S-awaiting-review There is new code that needs to be reviewed. label Apr 9, 2026
@jschwe jschwe added the T-ohos Do a try run on OpenHarmony label Apr 9, 2026
@github-actions github-actions Bot removed the T-ohos Do a try run on OpenHarmony label Apr 9, 2026
@github-actions

github-actions Bot commented Apr 9, 2026

Copy link
Copy Markdown

🔨 Triggering try run (#24199200755) for OpenHarmony

@github-actions

github-actions Bot commented Apr 9, 2026

Copy link
Copy Markdown

🐰 Bencher Report

Branch44061/PR
TestbedHUAWEI Mate 60 Pro

⚠️ WARNING: Truncated view!

The full continuous benchmarking report exceeds the maximum length allowed on this platform.

⚠️ WARNING: No Threshold found!

Without a Threshold, no Alerts will ever be generated.

🐰 View full continuous benchmarking report in Bencher

@github-actions

github-actions Bot commented Apr 9, 2026

Copy link
Copy Markdown

✨ Try run (#24199200755) succeeded.

@jschwe jschwe added this pull request to the merge queue Apr 9, 2026
@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 Apr 9, 2026
Merged via the queue into servo:main with commit f56c108 Apr 9, 2026
46 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 Apr 9, 2026
@RichardTjokroutomo RichardTjokroutomo deleted the ohos_font_list branch April 10, 2026 16:44
pull Bot pushed a commit to Patreos998/servo that referenced this pull request Jun 2, 2026
Removed `hardcoded_font_families()`, which is previously used to create
`FontFamily` for HarmonyOS emoji fonts (`HMOS Color Emoji` & `HMOS Color
Emoji Flags`). This function is no longer needed since
[servo#44061](servo#44061) because we're now
using OHOS API to generate `FontList`, which can detect all available
system fonts, including the emoji ones.

Testing: Manually tested.
Fixes: N/A

Signed-off-by: Richard Tjokroutomo <richard.tjokro2@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants