Skip to content

The design language that makes your AI harness better at design.

JavaScript

Make the on-screen sliver and CJK line-length cases font-independent

Paul Bakaus9645ce2ebad1
diff --git a/crates/browser/tests/text_geometry.rs b/crates/browser/tests/text_geometry.rs
index 35271e5c5..1afc4114e 100644
--- a/crates/browser/tests/text_geometry.rs
+++ b/crates/browser/tests/text_geometry.rs
@@ -67,6 +67,19 @@ fn engine() -> Option<BrowserEngine> {
Some(BrowserEngine::new(env))
}
+/// Whether the browser has a Japanese face to set CJK text in. macOS and
+/// Windows ship one; on Linux it is whatever fontconfig lists.
+fn has_cjk_font() -> bool {
+ if !cfg!(target_os = "linux") {
+ return true;
+ }
+ std::process::Command::new("fc-list")
+ .args([":lang=ja", "family"])
+ .output()
+ .map(|out| !String::from_utf8_lossy(&out.stdout).trim().is_empty())
+ .unwrap_or(false)
+}
+
/// `(snippet, selector)` for each finding of `rule` on one fixture.
fn findings(engine: &BrowserEngine, port: u16, fixture: &str, rule: &str) -> Vec<(String, String)> {
let url = format!("http://127.0.0.1:{port}/{fixture}");
@@ -108,16 +121,24 @@ fn the_text_geometry_rules_measure_the_text() {
let mut lines = findings(&engine, port, "line-length.html", "line-length");
lines.sort_by(|a, b| a.1.cmp(&b.1));
let selectors: Vec<&str> = lines.iter().map(|(_, sel)| sel.as_str()).collect();
+ // The 12px CJK column is measured in a CJK face; a machine with none
+ // (a stock Ubuntu runner) sets it in fallback boxes of another width.
+ let cjk: &[&str] = if has_cjk_font() {
+ &["p.copy.cjk-wide"]
+ } else {
+ eprintln!("no CJK font installed: the CJK column is not asserted");
+ &[]
+ };
assert_eq!(
selectors,
- vec![
- "p.copy.cjk-wide",
+ [cjk, &[
"p.copy.flag-large-span",
"p.copy.flag-mono",
"p.copy.wide:nth-of-type(1)",
"p.copy.wide:nth-of-type(2)",
"p.copy.wide:nth-of-type(3)",
- ],
+ ]]
+ .concat(),
"the wide column, its inline-prose twin, its 2.4 line-height twin, the 12px CJK column, the \
24px span across 1,200px and the monospace column; the 16px paragraph set in a 24px span \
and the 680px monospace column hold under 85 characters a line: {lines:?}"
diff --git a/tests/fixtures/antipatterns/on-screen.html b/tests/fixtures/antipatterns/on-screen.html
index 2f98c0485..338a3494d 100644
--- a/tests/fixtures/antipatterns/on-screen.html
+++ b/tests/fixtures/antipatterns/on-screen.html
@@ -51,7 +51,12 @@
.word { display: inline-block; font-size: 20px; line-height: 40px; color: #8a8f98; white-space: nowrap; }
.word-clip { position: absolute; left: 240px; top: 0; width: 300px; height: 40px; overflow: hidden; }
.word-track { position: absolute; top: 0; white-space: nowrap; }
- .sliver-word { display: inline-block; font-size: 20px; line-height: 40px; color: #b0a3a8; white-space: nowrap; }
+ /* Monospace, so the sliver is a sliver whatever font a platform maps the
+ family to: 18 characters at 20px run 198px (Consolas) to 217px (Menlo,
+ DejaVu Sans Mono), and the track parks all but 8 to 27px of them. In a
+ proportional face the word ran 170px on macOS and 210px on Linux, a
+ third of it in view there. */
+ .sliver-word { display: inline-block; font: 20px/40px monospace; color: #b0a3a8; white-space: nowrap; }
.truncate { position: absolute; left: 20px; top: 0; width: 150px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.trunc-word { font-size: 16px; color: #9a8f7f; }
@@ -110,7 +115,7 @@
<p class="label">A word with a sliver inside its clip</p>
<div class="row">
<div class="word-clip">
- <div class="word-track" style="left: -140px;"><span id="pass-sliver-copy" class="sliver-word">Archive of seasons</span></div>
+ <div class="word-track" style="left: -190px;"><span id="pass-sliver-copy" class="sliver-word">Archive of seasons</span></div>
</div>
</div>