Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

next/font: tolerate missing unused fields in capsize map #50708

Merged
merged 1 commit into from
Jun 2, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,24 +24,18 @@ use crate::{
};

/// An entry in the Google fonts metrics map
#[derive(Deserialize)]
#[derive(Deserialize, Debug)]
#[serde(rename_all = "camelCase")]
pub(super) struct FontMetricsMapEntry {
#[allow(unused)]
family_name: String,
category: String,
#[allow(unused)]
cap_height: i32,
ascent: i32,
descent: i32,
line_gap: u32,
units_per_em: u32,
#[allow(unused)]
x_height: i32,
x_width_avg: f64,
}

#[derive(Deserialize)]
#[derive(Deserialize, Debug)]
pub(super) struct FontMetricsMap(pub HashMap<String, FontMetricsMapEntry>);

#[derive(Debug, PartialEq, Serialize, Deserialize, TraceRawVcs)]
Expand All @@ -61,49 +55,44 @@ pub(super) async fn get_font_fallback(
Some(fallback) => FontFallback::Manual(StringsVc::cell(fallback.clone())).cell(),
None => {
let metrics_json =
load_next_json(context, "/dist/server/capsize-font-metrics.json").await;
match metrics_json {
Ok(metrics_json) => {
let fallback = lookup_fallback(
&options.font_family,
metrics_json,
options.adjust_font_fallback,
);

match fallback {
Ok(fallback) => FontFallback::Automatic(
AutomaticFontFallback {
scoped_font_family: get_scoped_font_family(
FontFamilyType::Fallback.cell(),
options_vc.font_family(),
request_hash,
),
local_font_family: StringVc::cell(fallback.font_family),
adjustment: fallback.adjustment,
}
.cell(),
)
.cell(),
Err(_) => {
NextFontIssue {
path: context,
title: StringVc::cell(format!(
"Failed to find font override values for font `{}`",
&options.font_family,
)),
description: StringVc::cell(
"Skipping generating a fallback font.".to_owned(),
),
severity: IssueSeverity::Warning.cell(),
}
.cell()
.as_issue()
.emit();
FontFallback::Error.cell()
}
load_next_json(context, "/dist/server/capsize-font-metrics.json").await?;
let fallback = lookup_fallback(
&options.font_family,
metrics_json,
options.adjust_font_fallback,
);

match fallback {
Ok(fallback) => FontFallback::Automatic(
AutomaticFontFallback {
scoped_font_family: get_scoped_font_family(
FontFamilyType::Fallback.cell(),
options_vc.font_family(),
request_hash,
),
local_font_family: StringVc::cell(fallback.font_family),
adjustment: fallback.adjustment,
}
.cell(),
)
.cell(),
Err(_) => {
NextFontIssue {
path: context,
title: StringVc::cell(format!(
"Failed to find font override values for font `{}`",
&options.font_family,
)),
description: StringVc::cell(
"Skipping generating a fallback font.".to_owned(),
),
severity: IssueSeverity::Warning.cell(),
}
.cell()
.as_issue()
.emit();
FontFallback::Error.cell()
}
Err(_) => FontFallback::Error.cell(),
}
}
})
Expand Down