VectorCraft: An open-source, vector art tool written by scratch in pure Rust
Fix #5316: StandardEncoding and ISOLatin1Encoding are Encoding resources
JonRC097b013ea761
diff --git a/crates/eps/src/import/interp.rs b/crates/eps/src/import/interp.rsindex 6126b4b32..98a4a4e77 100644--- a/crates/eps/src/import/interp.rs+++ b/crates/eps/src/import/interp.rs@@ -105,13 +105,18 @@ impl<'a> Interp<'a> {pub fn new(src: &'a [u8], g: GState, out: Out) -> Self {let made = super::obj::track();let system = new_dict();+ // The standard encodings are also instances of the Encoding category, the same arrays+ // (PLRM 3rd ed., `findencoding` and §3.9.2).+ let encodings = new_dict();{let mut d = system.borrow_mut();for (op, name) in Op::ALL {d.insert(Key::name(name), Obj::Op(*op));}for name in ["StandardEncoding", "ISOLatin1Encoding"] {- d.insert(Key::name(name), encoding());+ let e = encoding();+ d.insert(Key::name(name), e.clone());+ encodings.borrow_mut().insert(Key::name(name), e);}// An integer, as interpreters have it (`systemdict /languagelevel get 2 ge`): run, the// name pushes it all the same.@@ -122,6 +127,7 @@ impl<'a> Interp<'a> {CATEGORIES.split_whitespace().map(|c| (Key::name(c), Obj::dict(Dict::from([(Key::name("Category"), Obj::name(c))])))).collect();let resources = new_dict();resources.borrow_mut().insert(Key::name("Category"), Obj::dict(categories));+ resources.borrow_mut().insert(Key::name("Encoding"), Obj::Dict(encodings));let fonts = new_dict();system.borrow_mut().insert(Key::name("FontDirectory"), Obj::Dict(fonts.clone()));for name in ["GlobalFontDirectory", "SharedFontDirectory"] {diff --git a/crates/eps/src/import/tests.rs b/crates/eps/src/import/tests.rsindex aa97f32cb..3f734fef9 100644--- a/crates/eps/src/import/tests.rs+++ b/crates/eps/src/import/tests.rs@@ -892,6 +892,17 @@ fn the_generic_category_defines_new_categories() {check("{ /X 5 /Category defineresource } stopped");}+/// The standard encodings are instances of the Encoding category, the same arrays as the names in+/// `systemdict` (PLRM 3rd ed., `findencoding` and §3.9.2). Ghostscript's `eps2write` finds+/// `StandardEncoding` that way for the fonts it embeds.+#[test]+fn the_standard_encodings_are_encoding_resources() {+ check("/StandardEncoding /Encoding findresource StandardEncoding eq");+ check("/ISOLatin1Encoding /Encoding findresource ISOLatin1Encoding eq");+ check("/StandardEncoding /Encoding resourcestatus { pop pop true } { false } ifelse");+ check("{ /Nope /Encoding findresource } stopped");+}+#[test]fn clipsave_and_cliprestore_bring_the_clip_back() {// #234.