Fix #5316: StandardEncoding and ISOLatin1Encoding are Encoding resources

The standard encodings were names in systemdict only, and the Encoding
category was empty, so `/StandardEncoding /Encoding findresource`
failed with undefinedresource. The PLRM (3rd ed.) has both as
instances of the Encoding category, the same arrays as the names.
Ghostscript's eps2write prolog takes StandardEncoding that way for a
font whose encoding is a Differences dictionary with no BaseEncoding,
so files with its Type 3 text stopped there.
This commit is contained in:
JonRC
2026-11-03 15:56:58 +07:00
committed by bflatastic
parent 2fec613353
commit 097b013ea7
2 changed files with 18 additions and 1 deletions
+7 -1
View File
@@ -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"] {
+11
View File
@@ -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.