mirror of
https://github.com/storytold/wordcraft.git
synced 2026-11-10 20:29:51 -06:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0fb066f17a | ||
|
|
2922fe566b | ||
|
|
43f94a5dca |
Generated
+37
-22
@@ -4,9 +4,9 @@ version = 4
|
||||
|
||||
[[package]]
|
||||
name = "accesskit"
|
||||
version = "0.25.1"
|
||||
version = "0.25.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ad442f58ee04714aaa0ba0a2768c1ea1935b29507bb22ddece8cbbc76db02932"
|
||||
checksum = "4e883d1d28c5fd5568c79ed2d2bd48d9f2fd3945c8974ed0f53690ceddb051be"
|
||||
dependencies = [
|
||||
"uuid",
|
||||
]
|
||||
@@ -27,9 +27,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "accesskit_consumer"
|
||||
version = "0.39.1"
|
||||
version = "0.39.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8a45e2bb300bea6d5f33a82c3e051c3ddc6f41c209750f68a0acbe991a284344"
|
||||
checksum = "f3da8f27636015191b2264ee1df681503170a632cafd832fdc1edfdd4e3a2fd3"
|
||||
dependencies = [
|
||||
"accesskit",
|
||||
"hashbrown 0.17.1",
|
||||
@@ -118,9 +118,9 @@ checksum = "320119579fcad9c21884f5c4861d16174d0e06250625266f50fe6898340abefa"
|
||||
|
||||
[[package]]
|
||||
name = "aes"
|
||||
version = "0.9.3"
|
||||
version = "0.9.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "35f0f96ce78e38c3dc6d8948aa8163d06385be74000f3c7a95bf1eef35d3ea32"
|
||||
checksum = "fc0fc36d7440d015b45468ba08a21e80e056ebbd014c611c6298bb7503e04bd1"
|
||||
dependencies = [
|
||||
"cipher",
|
||||
"cpubits",
|
||||
@@ -155,13 +155,19 @@ version = "2.0.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cc7bb162ec39d46ab1ca8c77bf72e890535becd1751bb45f64c597edb4c8c6b3"
|
||||
|
||||
[[package]]
|
||||
name = "alloc-no-stdlib"
|
||||
version = "3.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c2fb6cfd47bf496ff64095c20eaba0c201404ee38714d4142fcfa1dc334fcc7a"
|
||||
|
||||
[[package]]
|
||||
name = "alloc-stdlib"
|
||||
version = "0.2.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0e76a019e91224d279006ff972f1e984179a6e9feb050adba6ce8274aef23195"
|
||||
dependencies = [
|
||||
"alloc-no-stdlib",
|
||||
"alloc-no-stdlib 2.0.4",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -614,9 +620,9 @@ version = "8.0.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5cc91aac060a7a1e25823bdccbfb6af1875b88f17c6daac97894eed8207166b3"
|
||||
dependencies = [
|
||||
"alloc-no-stdlib",
|
||||
"alloc-no-stdlib 2.0.4",
|
||||
"alloc-stdlib",
|
||||
"brotli-decompressor",
|
||||
"brotli-decompressor 5.0.3",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -625,10 +631,19 @@ version = "5.0.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3a32acac15fe1967bc3986b2a6347dffc965602354ea6f450ad07e8bfd253583"
|
||||
dependencies = [
|
||||
"alloc-no-stdlib",
|
||||
"alloc-no-stdlib 2.0.4",
|
||||
"alloc-stdlib",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "brotli-decompressor"
|
||||
version = "6.3.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "75c74c9c51b9140663e196b5fb88bc94c334d7a497c8311cb759d8557874747f"
|
||||
dependencies = [
|
||||
"alloc-no-stdlib 3.0.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "bumpalo"
|
||||
version = "3.20.3"
|
||||
@@ -1603,9 +1618,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "encoding_rs"
|
||||
version = "0.8.42"
|
||||
version = "0.8.44"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8e985e0451871ad22fb8d2b6b076e2028a502a0d3950998c2c5c0a4f9b5d9679"
|
||||
checksum = "89253175e704ab869b04f9db224d38630e0211a53841a79181deae0889e169f5"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"core_detect",
|
||||
@@ -3101,9 +3116,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "log"
|
||||
version = "0.4.34"
|
||||
version = "0.4.35"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f9f8bd3e56ce4dfc153cf470fffbfa98c7620958b312ca5c3a4b8d5181fd13c6"
|
||||
checksum = "5d15f86d12da44cd8d4ec3c73984537eb7f4cadcb9776a575a0a8a05ca11005c"
|
||||
|
||||
[[package]]
|
||||
name = "lru-slab"
|
||||
@@ -5828,9 +5843,9 @@ checksum = "7df058c713841ad818f1dc5d3fd88063241cc61f49f5fbea4b951e8cf5a8d71d"
|
||||
|
||||
[[package]]
|
||||
name = "unicode-script"
|
||||
version = "0.5.8"
|
||||
version = "0.5.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "383ad40bb927465ec0ce7720e033cb4ca06912855fc35db31b5755d0de75b1ee"
|
||||
checksum = "aa04c955db05429d464c74d495c1ee677e1866e783a4c3747f9c0cef7756cabf"
|
||||
|
||||
[[package]]
|
||||
name = "unicode-segmentation"
|
||||
@@ -6788,9 +6803,9 @@ checksum = "1ebf944e87a7c253233ad6766e082e3cd714b5d03812acc24c318f549614536e"
|
||||
|
||||
[[package]]
|
||||
name = "wl-clipboard-rs"
|
||||
version = "0.9.4"
|
||||
version = "0.9.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4d7888ccd4896447b2d14d3a9350a85df2aeb6f181e2e7a31349d104ac46cac1"
|
||||
checksum = "959c7ac3b8afde864f7a7448ac16f29b2b83350b7eccbf77fb781c3999aa6848"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"log",
|
||||
@@ -6955,7 +6970,7 @@ dependencies = [
|
||||
name = "wordcraft-fonts"
|
||||
version = "0.15.1"
|
||||
dependencies = [
|
||||
"brotli-decompressor",
|
||||
"brotli-decompressor 5.0.3",
|
||||
"harfrust 0.13.3",
|
||||
"kurbo",
|
||||
"log",
|
||||
@@ -7173,11 +7188,11 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "wuff"
|
||||
version = "0.2.9"
|
||||
version = "0.2.10"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "200a7b806377b65f1ff9a985874332f15357c87e5dd7855f35f06dade95b8b3d"
|
||||
checksum = "f6a992b57b3d1ee972b2e3fd9225e44793104d49818836dd812d5459187712dd"
|
||||
dependencies = [
|
||||
"brotli-decompressor",
|
||||
"brotli-decompressor 6.3.1",
|
||||
"bytes",
|
||||
"flate2",
|
||||
]
|
||||
|
||||
@@ -123,13 +123,15 @@ mod tests {
|
||||
assert_eq!(parse_color("#f00"), Some(Rgb(255, 0, 0)));
|
||||
assert_eq!(parse_color("#f00f"), Some(Rgb(255, 0, 0)));
|
||||
assert_eq!(parse_color("#0080FF"), Some(Rgb(0, 128, 255)));
|
||||
assert_eq!(parse_color("#0080ff80"), Some(Rgb(0, 128, 255)));
|
||||
assert_eq!(parse_color("#0080FFff"), Some(Rgb(0, 128, 255)));
|
||||
// A colour with alpha is composited over the white page it lands on (#0080ff at 50%).
|
||||
assert_eq!(parse_color("#0080ff80"), Some(Rgb(127, 191, 255)));
|
||||
assert_eq!(parse_color("rgb(1, 2, 3)"), Some(Rgb(1, 2, 3)));
|
||||
assert_eq!(parse_color("rgb(1 2 3)"), Some(Rgb(1, 2, 3)));
|
||||
assert_eq!(parse_color("rgb(1 2 3 / 50%)"), Some(Rgb(1, 2, 3)));
|
||||
assert_eq!(parse_color("rgb(1 2 3 / 50%)"), Some(Rgb(128, 129, 129)));
|
||||
assert_eq!(parse_color("hsl(0, 100%, 50%)"), Some(Rgb(255, 0, 0)));
|
||||
assert_eq!(parse_color("hsl(120deg 100% 50%)"), Some(Rgb(0, 255, 0)));
|
||||
assert_eq!(parse_color("hsla(240, 100%, 50%, 0.8)"), Some(Rgb(0, 0, 255)));
|
||||
assert_eq!(parse_color("hsla(240, 100%, 50%, 0.8)"), Some(Rgb(51, 51, 255)));
|
||||
assert_eq!(parse_color("navy"), Some(Rgb(0, 0, 128)));
|
||||
assert_eq!(parse_color("#zz"), None);
|
||||
assert_eq!(parse_color("rgb(1)"), None);
|
||||
|
||||
@@ -34,24 +34,59 @@ fn hsl_to_rgb(h: f64, s: f64, l: f64) -> Rgb {
|
||||
Rgb(r, g, b)
|
||||
}
|
||||
|
||||
/// Composite `rgb` over the white page a paste lands on, at CSS alpha `a` (0..1): `rgba(0, 0, 0,
|
||||
/// 0.45)` reads like the rgb(140, 140, 140) it looks like on the site, instead of solid black.
|
||||
fn over_white(r: u8, g: u8, b: u8, a: f32) -> Rgb {
|
||||
let mix = |c: u8| (c as f32 * a + 255.0 * (1.0 - a)).round().clamp(0.0, 255.0) as u8;
|
||||
Rgb(mix(r), mix(g), mix(b))
|
||||
}
|
||||
|
||||
/// The alpha of a CSS colour's `/ alpha` or 4th-value part, where present: 1.0 (opaque) otherwise.
|
||||
fn css_alpha(after: Option<&str>) -> f32 {
|
||||
let Some(a) = after else { return 1.0 };
|
||||
let a = a.trim();
|
||||
// CSS Colour 4's `none` is a missing component, and a missing alpha is transparent.
|
||||
if a.eq_ignore_ascii_case("none") {
|
||||
return 0.0;
|
||||
}
|
||||
// A value that is not a finite number (`nan`, `inf`) is no alpha at all: clamp would keep
|
||||
// NaN, and `over_white` would turn the colour black.
|
||||
let parse = |t: &str| t.parse::<f32>().ok().filter(|f| f.is_finite());
|
||||
if let Some(p) = a.strip_suffix('%') {
|
||||
return parse(p.trim()).map(|f| f.clamp(0.0, 100.0) / 100.0).unwrap_or(1.0);
|
||||
}
|
||||
parse(a).map(|f| f.clamp(0.0, 1.0)).unwrap_or(1.0)
|
||||
}
|
||||
|
||||
/// Parse a CSS / HTML colour: `#rgb`, `#rgba`, `#rrggbb`, `#rrggbbaa`, `rgb(...)`, `hsl(...)` or a basic name.
|
||||
/// A colour with alpha is composited over white: the model keeps opaque colours, and a paste lands
|
||||
/// on a white page.
|
||||
pub fn parse_color(s: &str) -> Option<Rgb> {
|
||||
let s = s.trim().to_ascii_lowercase();
|
||||
if let Some(h) = s.strip_prefix('#') {
|
||||
if (h.len() == 3 || h.len() == 4) && h.is_ascii() {
|
||||
let d = |i: usize| h.get(i..i + 1).and_then(|x| u8::from_str_radix(x, 16).ok()).map(|v| v * 17);
|
||||
return Some(Rgb(d(0)?, d(1)?, d(2)?));
|
||||
let (r, g, b) = (d(0)?, d(1)?, d(2)?);
|
||||
// A 4th digit is the alpha, composited over the page like `rgba(...)`'s is.
|
||||
let a = if h.len() == 4 { d(3)? as f32 / 255.0 } else { 1.0 };
|
||||
return Some(over_white(r, g, b, a));
|
||||
}
|
||||
if h.len() == 8 && h.bytes().all(|b| b.is_ascii_hexdigit()) {
|
||||
let p = |i: usize| h.get(i..i + 2).and_then(|x| u8::from_str_radix(x, 16).ok());
|
||||
return Some(Rgb(p(0)?, p(2)?, p(4)?));
|
||||
return Some(over_white(p(0)?, p(2)?, p(4)?, p(6)? as f32 / 255.0));
|
||||
}
|
||||
return Rgb::parse(h);
|
||||
}
|
||||
if let Some(inner) = s.strip_prefix("rgb(").or_else(|| s.strip_prefix("rgba(")) {
|
||||
let inner = inner.trim_end_matches(')').trim();
|
||||
let before_slash = inner.split('/').next().unwrap_or(inner);
|
||||
let parts: Vec<&str> = if before_slash.contains(',') { before_slash.split(',').collect() } else { before_slash.split_whitespace().collect() };
|
||||
let (rgb_part, alpha_part) = inner.split_once('/').map_or((inner, None), |(a, b)| (a, Some(b)));
|
||||
// Legacy comma syntax carries the alpha as a 4th value (`rgba(0, 0, 0, 0.45)`).
|
||||
let parts: Vec<&str> = if rgb_part.contains(',') { rgb_part.split(',').collect() } else { rgb_part.split_whitespace().collect() };
|
||||
let alpha = match alpha_part {
|
||||
Some(a) => css_alpha(Some(a)),
|
||||
None if parts.len() >= 4 => css_alpha(Some(parts[3])),
|
||||
_ => 1.0,
|
||||
};
|
||||
let v: Vec<u8> = parts
|
||||
.iter()
|
||||
.take(3)
|
||||
@@ -65,14 +100,19 @@ pub fn parse_color(s: &str) -> Option<Rgb> {
|
||||
})
|
||||
.collect();
|
||||
if let [r, g, b] = v[..] {
|
||||
return Some(Rgb(r, g, b));
|
||||
return Some(over_white(r, g, b, alpha));
|
||||
}
|
||||
return None;
|
||||
}
|
||||
if let Some(inner) = s.strip_prefix("hsl(").or_else(|| s.strip_prefix("hsla(")) {
|
||||
let inner = inner.trim_end_matches(')').trim();
|
||||
let before_slash = inner.split('/').next().unwrap_or(inner);
|
||||
let parts: Vec<&str> = if before_slash.contains(',') { before_slash.split(',').collect() } else { before_slash.split_whitespace().collect() };
|
||||
let (hsl_part, alpha_part) = inner.split_once('/').map_or((inner, None), |(a, b)| (a, Some(b)));
|
||||
let parts: Vec<&str> = if hsl_part.contains(',') { hsl_part.split(',').collect() } else { hsl_part.split_whitespace().collect() };
|
||||
let alpha = match alpha_part {
|
||||
Some(a) => css_alpha(Some(a)),
|
||||
None if parts.len() >= 4 => css_alpha(Some(parts[3])),
|
||||
_ => 1.0,
|
||||
};
|
||||
if parts.len() < 3 {
|
||||
return None;
|
||||
}
|
||||
@@ -96,7 +136,8 @@ pub fn parse_color(s: &str) -> Option<Rgb> {
|
||||
};
|
||||
let s = parse_pct(parts[1])?;
|
||||
let l = parse_pct(parts[2])?;
|
||||
return Some(hsl_to_rgb(h, s, l));
|
||||
let Rgb(r, g, b) = hsl_to_rgb(h, s, l);
|
||||
return Some(over_white(r, g, b, alpha));
|
||||
}
|
||||
Some(match s.as_str() {
|
||||
"black" => Rgb(0, 0, 0),
|
||||
@@ -127,6 +168,29 @@ mod tests {
|
||||
#[test]
|
||||
fn eight_digit_hex_rejects_signs() {
|
||||
assert_eq!(parse_color("#+1+2+3+4"), None);
|
||||
assert_eq!(parse_color("#11223344"), Some(Rgb(0x11, 0x22, 0x33)));
|
||||
// #11223344 is alpha 0x44 over white.
|
||||
assert_eq!(parse_color("#11223344"), Some(Rgb(192, 196, 201)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn colors_with_alpha_composite_over_white() {
|
||||
// The secondary text colour of dark-theme sites: solid black would read as the site's
|
||||
// own emphasis, white is invisible on the page; the composite is what the eye saw.
|
||||
assert_eq!(parse_color("rgba(0, 0, 0, 0.45)"), Some(Rgb(140, 140, 140)));
|
||||
assert_eq!(parse_color("rgb(0 0 0 / 0.45)"), Some(Rgb(140, 140, 140)));
|
||||
assert_eq!(parse_color("rgba(0, 0, 0, 0)"), Some(Rgb(255, 255, 255)));
|
||||
assert_eq!(parse_color("rgba(255, 0, 0, 1)"), Some(Rgb(255, 0, 0)));
|
||||
assert_eq!(parse_color("rgba(255, 0, 0, 45%)"), Some(Rgb(255, 140, 140)));
|
||||
assert_eq!(parse_color("hsla(120, 100%, 50%, 0.5)"), Some(Rgb(128, 255, 128)));
|
||||
// A 4-digit hex's last digit is the alpha, too: #0008 is black at 8/15 over white.
|
||||
assert_eq!(parse_color("#0008"), Some(Rgb(119, 119, 119)));
|
||||
// `none` is a missing alpha, and a missing alpha is transparent, not the opaque default
|
||||
// an omitted alpha takes.
|
||||
assert_eq!(parse_color("rgb(0 0 0 / none)"), Some(Rgb(255, 255, 255)));
|
||||
assert_eq!(parse_color("rgb(0 0 0)"), Some(Rgb(0, 0, 0)));
|
||||
// An alpha that is not a finite number is no alpha: the colour stays opaque, not black.
|
||||
assert_eq!(parse_color("rgba(0, 0, 0, nan)"), Some(Rgb(0, 0, 0)));
|
||||
assert_eq!(parse_color("rgba(0, 0, 0, inf)"), Some(Rgb(0, 0, 0)));
|
||||
assert_eq!(parse_color("rgba(0, 0, 0, nan%)"), Some(Rgb(0, 0, 0)));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -135,7 +135,13 @@ fn parse_full(bytes: &[u8], marks: bool) -> Result<Parsed, String> {
|
||||
}
|
||||
match n {
|
||||
b'\'' => {
|
||||
let h = bytes.get(i + 2..i + 4).and_then(|h| std::str::from_utf8(h).ok()).and_then(|h| u8::from_str_radix(h, 16).ok());
|
||||
// `from_str_radix` takes a leading `+`: a pair that isn't both hex digits
|
||||
// is not an escape at all.
|
||||
let h = bytes
|
||||
.get(i + 2..i + 4)
|
||||
.and_then(|h| std::str::from_utf8(h).ok())
|
||||
.filter(|h| h.bytes().all(|b| b.is_ascii_hexdigit()))
|
||||
.and_then(|h| u8::from_str_radix(h, 16).ok());
|
||||
match h {
|
||||
Some(v) => {
|
||||
if r.st.dest == Dest::Pict {
|
||||
@@ -150,7 +156,17 @@ fn parse_full(bytes: &[u8], marks: bool) -> Result<Parsed, String> {
|
||||
}
|
||||
i += 4;
|
||||
}
|
||||
None => i += 2,
|
||||
// Not two hex digits: the escape is malformed. Consume the escape and
|
||||
// any hex digits of a truncated pair, and leave every other byte,
|
||||
// `}` or a control word's `\`, to be read as the structure it is.
|
||||
None => {
|
||||
i += 2;
|
||||
let mut n = 0;
|
||||
while n < 2 && bytes.get(i).is_some_and(u8::is_ascii_hexdigit) {
|
||||
i += 1;
|
||||
n += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
b'*' => {
|
||||
|
||||
@@ -37,6 +37,73 @@ fn basic_reader() {
|
||||
assert!(matches!(&l.inlines[0], Inline::Text(_, f) if f.link.as_deref() == Some("http://a.b")));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn stylesheet_names_take_unicode_escapes() {
|
||||
// \u116?=t \u105?=i \u116?=t \u108?=l \u101?=e — how Word writes a non-Latin style name.
|
||||
let rtf = br"{\rtf1\ansi{\stylesheet{\s0 Normal;}{\s2 \u116?\u105?\u116?\u108?\u101?;}}\pard\s2 T\par}";
|
||||
let f = parse(rtf).unwrap();
|
||||
assert_eq!(texts(&f)[0], "Title:T");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn stylesheet_names_take_negative_escapes() {
|
||||
// 't' as a signed 16-bit escape: 116 - 65536 = -65420.
|
||||
let rtf = br"{\rtf1\ansi{\stylesheet{\s0 Normal;}{\s2 \u-65420?\u105?\u116?\u108?\u101?;}}\pard\s2 T\par}";
|
||||
let f = parse(rtf).unwrap();
|
||||
assert_eq!(texts(&f)[0], "Title:T");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn stylesheet_names_honour_the_uc_fallback_count() {
|
||||
// \uc2: two fallback bytes follow each \uN? — here a second `?`.
|
||||
let rtf = br"{\rtf1\ansi{\stylesheet{\s0 Normal;}{\s2 \uc2\u116??\u105??\u116??\u108??\u101??;}}\pard\s2 T\par}";
|
||||
let f = parse(rtf).unwrap();
|
||||
assert_eq!(texts(&f)[0], "Title:T");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_malformed_hex_escape_leaves_no_stray_text() {
|
||||
// A `\'` that is not followed by two hex digits is malformed: the escape itself goes, any
|
||||
// hex digits of a truncated pair go with it, and everything else — non-hex bytes, `}` —
|
||||
// is read as what it is. `\'gZ` keeps "gZ" as text; `\'4}` keeps the closing brace.
|
||||
let rtf = br"{\rtf1\ansi \'gZok\par}";
|
||||
let f = parse(rtf).unwrap();
|
||||
assert_eq!(texts(&f)[0], "Normal:gZok");
|
||||
|
||||
// The bytes after a truncated pair must not swallow the group's closing brace or the next
|
||||
// control word: the group and its destination state end where they should. Paragraph text
|
||||
// alone would not show that: `survivor` reads the same inside the bold group, so the run's
|
||||
// formatting is checked too.
|
||||
let rtf = br"{\rtf1\ansi{\b \'4}survivor\par}";
|
||||
let f = parse(rtf).unwrap();
|
||||
assert!(texts(&f).iter().any(|t| t.contains("survivor")), "{:?}", texts(&f));
|
||||
let survivor_bold = f.blocks.iter().find_map(|b| match b {
|
||||
FBlock::Para(p) => p.inlines.iter().find_map(|i| match i {
|
||||
Inline::Text(t, fmt) if t.contains("survivor") => Some(fmt.bold),
|
||||
_ => None,
|
||||
}),
|
||||
FBlock::Table(_) => None,
|
||||
});
|
||||
assert_eq!(survivor_bold, Some(false), "survivor must not be inside the bold group: {:?}", f.blocks);
|
||||
// The truncated pair's hex digit goes with the escape: no stray "4" is left in the text.
|
||||
assert!(!texts(&f).iter().any(|t| t.contains('4')), "{:?}", texts(&f));
|
||||
|
||||
// A leading `+` is not a hex digit: `\'+4` is no escape: it stays text, not the byte 0x04.
|
||||
let rtf = br"{\rtf1\ansi \'+4z\par}";
|
||||
let f = parse(rtf).unwrap();
|
||||
assert_eq!(texts(&f)[0], "Normal:+4z");
|
||||
|
||||
let rtf = br"{\rtf1\ansi{\'}}after\par}";
|
||||
let f = parse(rtf).unwrap();
|
||||
assert!(texts(&f).iter().any(|t| t.contains("after")), "{:?}", texts(&f));
|
||||
|
||||
// A hex digit that starts a valid pair with the byte after it is part of the escape:
|
||||
// \'4} reads '4' as the escape's byte and leaves `}` to close the group.
|
||||
let rtf = br"{\rtf1\ansi\'4}x\par}";
|
||||
let f = parse(rtf).unwrap();
|
||||
assert!(texts(&f).iter().any(|t| t.contains('x') && !t.contains('}')), "{:?}", texts(&f));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn unicode_fallback_uses_the_declared_count() {
|
||||
for (rtf, expected) in [
|
||||
|
||||
@@ -403,7 +403,8 @@ impl Reader {
|
||||
}
|
||||
true
|
||||
}
|
||||
Dest::StyleSheet => {
|
||||
// Style names take Unicode escapes (with fallback skipping) like the body.
|
||||
Dest::StyleSheet if !matches!(word, "u" | "uc") => {
|
||||
let def = &mut self.style_def_cur;
|
||||
match word {
|
||||
"s" | "cs" | "ds" | "ts" => {
|
||||
@@ -420,6 +421,7 @@ impl Reader {
|
||||
}
|
||||
true
|
||||
}
|
||||
Dest::StyleSheet => false,
|
||||
Dest::ListTable => {
|
||||
self.list_table_word(word, value);
|
||||
true
|
||||
|
||||
@@ -63,7 +63,7 @@ egui_kittest = { workspace = true, features = ["wgpu", "snapshot"] }
|
||||
zip = { workspace = true }
|
||||
# #2726's regression test: the consumer the Windows adapter runs, fed with our updates.
|
||||
# Pinned to the version egui already brings into the tree, so nothing is built twice.
|
||||
accesskit_consumer = "=0.39.1"
|
||||
accesskit_consumer = "=0.39.2"
|
||||
|
||||
[build-dependencies]
|
||||
serde_json = { workspace = true }
|
||||
|
||||
Reference in New Issue
Block a user