mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-30 10:15:00 +01:00
* feat(ps): add craft-ps with an EPS reader (read feature) The reading half of craft-ps (#115): a clean-room PostScript interpreter that runs an EPS and returns what it paints as a one-page vector PDF of its bounding box, colours kept, so apps can draw and export EPS as a placed PDF. Moved from DesignCraft (storytold/designcraft, where it was written for placed EPS), with its app-specific names made neutral. Written from the PostScript Language Reference (3rd ed.), the EPS specification, the Type 1 Font Format and Adobe TN 5012/5176/5177. Covers the language, paths, clipping, strokepath, device/Separation/ DeviceN/Indexed/ICCBased/Lab colour, images with lazily decoded filters, shadings 1-7 and patterns, and Type 1/3/42/CFF/CID text through CMaps, horizontal and vertical. Bounded: each operator charges work proportional to its operands against the step limit as it goes, every byte read or decoded counts, copies count against the memory cap; defaults 50 M steps / 1 GiB, and 20 M / 256 MiB on wasm32. No panics (deny lints, fuzzed in debug builds). 34 tests, the Type 42 one on a TrueType font built in the test. No new external crates: pdf-writer, miniz_oxide, weezl, skrifa and kurbo are already locked at these versions. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * clippy(ps): document stateful decoder complexity * fix(ps): bound huge arc angle normalization * fix(ps): preserve EffectCraft EPS text and limits parity * fix(ps): address interpreter review findings * fix(ps): preserve composite glyph paint order * fix(ps): address interpreter review findings * fix(ps): bound filter buffers and preserve file aliases * fix(ps): make predictor allocation fallible --------- Co-authored-by: markus.doebele <markus.doebele@top21.sh> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
253 lines
4.0 KiB
Rust
253 lines
4.0 KiB
Rust
//! CFF standard strings (Technical Note 5176, Appendix A): SIDs below 391 name these.
|
||
|
||
/// SIDs 0–228: the Standard and ISO Latin glyph names.
|
||
const NAMES: [&str; 229] = [
|
||
".notdef",
|
||
"space",
|
||
"exclam",
|
||
"quotedbl",
|
||
"numbersign",
|
||
"dollar",
|
||
"percent",
|
||
"ampersand",
|
||
"quoteright",
|
||
"parenleft",
|
||
"parenright",
|
||
"asterisk",
|
||
"plus",
|
||
"comma",
|
||
"hyphen",
|
||
"period",
|
||
"slash",
|
||
"zero",
|
||
"one",
|
||
"two",
|
||
"three",
|
||
"four",
|
||
"five",
|
||
"six",
|
||
"seven",
|
||
"eight",
|
||
"nine",
|
||
"colon",
|
||
"semicolon",
|
||
"less",
|
||
"equal",
|
||
"greater",
|
||
"question",
|
||
"at",
|
||
"A",
|
||
"B",
|
||
"C",
|
||
"D",
|
||
"E",
|
||
"F",
|
||
"G",
|
||
"H",
|
||
"I",
|
||
"J",
|
||
"K",
|
||
"L",
|
||
"M",
|
||
"N",
|
||
"O",
|
||
"P",
|
||
"Q",
|
||
"R",
|
||
"S",
|
||
"T",
|
||
"U",
|
||
"V",
|
||
"W",
|
||
"X",
|
||
"Y",
|
||
"Z",
|
||
"bracketleft",
|
||
"backslash",
|
||
"bracketright",
|
||
"asciicircum",
|
||
"underscore",
|
||
"quoteleft",
|
||
"a",
|
||
"b",
|
||
"c",
|
||
"d",
|
||
"e",
|
||
"f",
|
||
"g",
|
||
"h",
|
||
"i",
|
||
"j",
|
||
"k",
|
||
"l",
|
||
"m",
|
||
"n",
|
||
"o",
|
||
"p",
|
||
"q",
|
||
"r",
|
||
"s",
|
||
"t",
|
||
"u",
|
||
"v",
|
||
"w",
|
||
"x",
|
||
"y",
|
||
"z",
|
||
"braceleft",
|
||
"bar",
|
||
"braceright",
|
||
"asciitilde",
|
||
"exclamdown",
|
||
"cent",
|
||
"sterling",
|
||
"fraction",
|
||
"yen",
|
||
"florin",
|
||
"section",
|
||
"currency",
|
||
"quotesingle",
|
||
"quotedblleft",
|
||
"guillemotleft",
|
||
"guilsinglleft",
|
||
"guilsinglright",
|
||
"fi",
|
||
"fl",
|
||
"endash",
|
||
"dagger",
|
||
"daggerdbl",
|
||
"periodcentered",
|
||
"paragraph",
|
||
"bullet",
|
||
"quotesinglbase",
|
||
"quotedblbase",
|
||
"quotedblright",
|
||
"guillemotright",
|
||
"ellipsis",
|
||
"perthousand",
|
||
"questiondown",
|
||
"grave",
|
||
"acute",
|
||
"circumflex",
|
||
"tilde",
|
||
"macron",
|
||
"breve",
|
||
"dotaccent",
|
||
"dieresis",
|
||
"ring",
|
||
"cedilla",
|
||
"hungarumlaut",
|
||
"ogonek",
|
||
"caron",
|
||
"emdash",
|
||
"AE",
|
||
"ordfeminine",
|
||
"Lslash",
|
||
"Oslash",
|
||
"OE",
|
||
"ordmasculine",
|
||
"ae",
|
||
"dotlessi",
|
||
"lslash",
|
||
"oslash",
|
||
"oe",
|
||
"germandbls",
|
||
"onesuperior",
|
||
"logicalnot",
|
||
"mu",
|
||
"trademark",
|
||
"Eth",
|
||
"onehalf",
|
||
"plusminus",
|
||
"Thorn",
|
||
"onequarter",
|
||
"divide",
|
||
"brokenbar",
|
||
"degree",
|
||
"thorn",
|
||
"threequarters",
|
||
"twosuperior",
|
||
"registered",
|
||
"minus",
|
||
"eth",
|
||
"multiply",
|
||
"threesuperior",
|
||
"copyright",
|
||
"Aacute",
|
||
"Acircumflex",
|
||
"Adieresis",
|
||
"Agrave",
|
||
"Aring",
|
||
"Atilde",
|
||
"Ccedilla",
|
||
"Eacute",
|
||
"Ecircumflex",
|
||
"Edieresis",
|
||
"Egrave",
|
||
"Iacute",
|
||
"Icircumflex",
|
||
"Idieresis",
|
||
"Igrave",
|
||
"Ntilde",
|
||
"Oacute",
|
||
"Ocircumflex",
|
||
"Odieresis",
|
||
"Ograve",
|
||
"Otilde",
|
||
"Scaron",
|
||
"Uacute",
|
||
"Ucircumflex",
|
||
"Udieresis",
|
||
"Ugrave",
|
||
"Yacute",
|
||
"Ydieresis",
|
||
"Zcaron",
|
||
"aacute",
|
||
"acircumflex",
|
||
"adieresis",
|
||
"agrave",
|
||
"aring",
|
||
"atilde",
|
||
"ccedilla",
|
||
"eacute",
|
||
"ecircumflex",
|
||
"edieresis",
|
||
"egrave",
|
||
"iacute",
|
||
"icircumflex",
|
||
"idieresis",
|
||
"igrave",
|
||
"ntilde",
|
||
"oacute",
|
||
"ocircumflex",
|
||
"odieresis",
|
||
"ograve",
|
||
"otilde",
|
||
"scaron",
|
||
"uacute",
|
||
"ucircumflex",
|
||
"udieresis",
|
||
"ugrave",
|
||
"yacute",
|
||
"ydieresis",
|
||
"zcaron",
|
||
];
|
||
|
||
/// SIDs 379–390.
|
||
const TAIL: [&str; 12] = ["001.000", "001.001", "001.002", "001.003", "Black", "Bold", "Book", "Light", "Medium", "Regular", "Roman", "Semibold"];
|
||
|
||
/// The number of standard strings.
|
||
pub const COUNT: usize = 391;
|
||
|
||
/// The glyph name a standard SID stands for. The expert-set names (229–378) are given as
|
||
/// `sid<n>`, which only has to be consistent within one font (they are its own glyph names).
|
||
pub fn standard(sid: usize) -> Option<String> {
|
||
if let Some(n) = NAMES.get(sid) {
|
||
return Some((*n).to_string());
|
||
}
|
||
if let Some(n) = sid.checked_sub(379).and_then(|i| TAIL.get(i)) {
|
||
return Some((*n).to_string());
|
||
}
|
||
(sid < COUNT).then(|| format!("sid{sid}"))
|
||
}
|