G2: improve editing reliability and Windows rendering fidelity

This commit is contained in:
Dexter
2026-10-06 00:00:31 -05:00
parent b46be83ab4
commit 39e6907b5f
101 changed files with 1727 additions and 351 deletions
+6 -6
View File
@@ -733,7 +733,7 @@ impl T2<'_> {
}
5 => {
let s = self.args();
for c in s.chunks_exact(2) {
for c in s.as_chunks::<2>().0 {
self.line_to(c[0], c[1]);
}
}
@@ -751,7 +751,7 @@ impl T2<'_> {
}
8 => {
let s = self.args();
for c in s.chunks_exact(6) {
for c in s.as_chunks::<6>().0 {
self.curve([c[0], c[1], c[2], c[3], c[4], c[5]]);
}
}
@@ -759,7 +759,7 @@ impl T2<'_> {
// rcurveline
let s = self.args();
let nc = s.len().saturating_sub(2) / 6;
for c in s[..nc * 6].chunks_exact(6) {
for c in s[..nc * 6].as_chunks::<6>().0 {
self.curve([c[0], c[1], c[2], c[3], c[4], c[5]]);
}
if s.len() >= nc * 6 + 2 {
@@ -771,7 +771,7 @@ impl T2<'_> {
let s = self.args();
if s.len() >= 6 {
let nl = (s.len() - 6) / 2;
for c in s[..nl * 2].chunks_exact(2) {
for c in s[..nl * 2].as_chunks::<2>().0 {
self.line_to(c[0], c[1]);
}
let c = &s[nl * 2..];
@@ -785,7 +785,7 @@ impl T2<'_> {
if s.len() % 4 == 1 {
dx1 = s.remove(0);
}
for c in s.chunks_exact(4) {
for c in s.as_chunks::<4>().0 {
self.curve([dx1, c[0], c[1], c[2], 0.0, c[3]]);
dx1 = 0.0;
}
@@ -797,7 +797,7 @@ impl T2<'_> {
if s.len() % 4 == 1 {
dy1 = s.remove(0);
}
for c in s.chunks_exact(4) {
for c in s.as_chunks::<4>().0 {
self.curve([c[0], dy1, c[1], c[2], c[3], 0.0]);
dy1 = 0.0;
}
+1 -1
View File
@@ -560,7 +560,7 @@ impl Func {
/// PDF text string → Rust string (UTF-16BE with a byte-order mark, else PDFDocEncoding ≈ Latin-1).
pub fn text_string(b: &[u8]) -> String {
if b.starts_with(&[0xFE, 0xFF]) {
let u: Vec<u16> = b[2..].chunks_exact(2).map(|c| u16::from_be_bytes([c[0], c[1]])).collect();
let u: Vec<u16> = b[2..].as_chunks::<2>().0.iter().map(|c| u16::from_be_bytes([c[0], c[1]])).collect();
return String::from_utf16_lossy(&u);
}
if let Some(rest) = b.strip_prefix(&[0xEF, 0xBB, 0xBF]) {
+7 -7
View File
@@ -231,21 +231,21 @@ fn parse_cmap(data: &[u8]) -> CMap {
let a = std::mem::take(&mut args);
match mode {
"cs" => {
for p in a.chunks_exact(2) {
for p in a.as_chunks::<2>().0 {
if let (Obj::Str(lo), Obj::Str(hi)) = (&p[0], &p[1]) {
m.codespace.push((lo.len().max(1), be(lo), be(hi)));
}
}
}
"bfchar" => {
for p in a.chunks_exact(2) {
for p in a.as_chunks::<2>().0 {
if let (Obj::Str(src), Obj::Str(dst)) = (&p[0], &p[1]) {
m.unicode.insert(be(src), utf16(dst));
}
}
}
"bfrange" => {
for p in a.chunks_exact(3) {
for p in a.as_chunks::<3>().0 {
let (Obj::Str(lo), Obj::Str(hi)) = (&p[0], &p[1]) else { continue };
let (lo, hi) = (be(lo), be(hi));
if hi < lo || hi - lo > 65535 {
@@ -273,7 +273,7 @@ fn parse_cmap(data: &[u8]) -> CMap {
}
}
"cidchar" => {
for p in a.chunks_exact(2) {
for p in a.as_chunks::<2>().0 {
if let (Obj::Str(src), Some(cid)) = (&p[0], p[1].num()) {
let c = be(src);
m.cids.push((c, c, cid as u32));
@@ -281,7 +281,7 @@ fn parse_cmap(data: &[u8]) -> CMap {
}
}
"cidrange" => {
for p in a.chunks_exact(3) {
for p in a.as_chunks::<3>().0 {
if let (Obj::Str(lo), Obj::Str(hi), Some(cid)) = (&p[0], &p[1], p[2].num()) {
m.cids.push((be(lo), be(hi), cid as u32));
}
@@ -431,7 +431,7 @@ impl Font {
match w.get(i + 1).map(|x| file.resolve(x)) {
Some(Obj::Array(list)) => {
let v: Vec<f64> = list.iter().filter_map(|x| file.resolve(x).num()).collect();
for (k, t) in v.chunks_exact(3).enumerate() {
for (k, t) in v.as_chunks::<3>().0.iter().enumerate() {
f.cid_vmetrics.insert(first + k as u32, (t[0] / 1000.0, t[1] / 1000.0, t[2] / 1000.0));
}
i += 2;
@@ -468,7 +468,7 @@ impl Font {
}
match file.get(&desc_dict, "CIDToGIDMap") {
Some(Obj::Stream(sd, raw)) => {
f.cid_to_gid = decode_stream(file, sd, raw).map(|b| b.chunks_exact(2).map(|c| u16::from_be_bytes([c[0], c[1]])).collect());
f.cid_to_gid = decode_stream(file, sd, raw).map(|b| b.as_chunks::<2>().0.iter().map(|c| u16::from_be_bytes([c[0], c[1]])).collect());
}
_ => f.cid_to_gid = None,
}
+4 -2
View File
@@ -561,7 +561,9 @@ impl Interp {
_ => vec![],
};
let m = self.gs.ctm;
nums.chunks_exact(4)
nums.as_chunks::<4>()
.0
.iter()
.map(|r| {
let mut p = BezPath::new();
p.move_to(m * Point::new(r[0], r[1]));
@@ -656,7 +658,7 @@ impl Interp {
let items = self.st.split_off(self.st.len() - k);
self.st.pop();
let d = new_dict();
for kv in items.chunks_exact(2) {
for kv in items.as_chunks::<2>().0 {
d.borrow_mut().insert(kv[0].key(), kv[1].clone());
}
self.push(V::Dict(d));
+1 -1
View File
@@ -116,7 +116,7 @@ impl Type1 {
let hex = body.iter().take(4).all(u8::is_ascii_hexdigit);
let raw: Vec<u8> = if hex {
let digits: Vec<u8> = body.iter().copied().filter(u8::is_ascii_hexdigit).collect();
digits.chunks_exact(2).map(|p| (hexv(p[0]) << 4) | hexv(p[1])).collect()
digits.as_chunks::<2>().0.iter().map(|p| (hexv(p[0]) << 4) | hexv(p[1])).collect()
} else {
body.to_vec()
};