fonts: cut over encodings, Std14, and font wire builders to craft-pdf (#778) (#7940)

This commit is contained in:
Dylan M. Taylor
2026-11-20 07:17:06 -05:00
committed by GitHub
parent 3f3b3e634a
commit 2c0280eb11
14 changed files with 31 additions and 1133 deletions
+1 -2
View File
@@ -4,7 +4,7 @@
Every asset PdfCraft includes, bundles or uses to build its published material, with its author, source and licence. The policy is in [AGENTS.md](AGENTS.md) §1. The machine-readable list, with the SHA-256 of every asset, is [ATTRIBUTION.toml](ATTRIBUTION.toml). Licence texts are kept beside the assets and summarised in [NOTICE](NOTICE).
## In this repository (241)
## In this repository (240)
| Asset | Title | Author | Licence | Source | Used for |
|---|---|---|---|---|---|
@@ -188,7 +188,6 @@ Every asset PdfCraft includes, bundles or uses to build its published material,
| `assets/fonts/Inter-Medium.ttf` | Inter Medium | The Inter Project Authors (Rasmus Andersson) | OFL-1.1 | https://github.com/rsms/inter | UI font, embedded in the app; demo PDF labels |
| `assets/fonts/Inter-SemiBold.ttf` | Inter SemiBold | The Inter Project Authors (Rasmus Andersson) | OFL-1.1 | https://github.com/rsms/inter | UI font, embedded in the app; demo PDF labels |
| `assets/fonts/JetBrainsMono-Regular.ttf` | JetBrains Mono Regular | The JetBrains Mono Project Authors | OFL-1.1 | https://github.com/JetBrains/JetBrainsMono | UI monospace font; demo PDF code |
| `crates/fonts/src/std14_metrics.rs` | Standard-14 font advance widths and encodings (as Rust tables) | Adobe (Core14 AFM metrics, PDF specification encodings); tables generated by the PdfCraft contributors | MIT OR Apache-2.0 | ISO 32000-2 Annex D and the Adobe Core14 AFM metrics. Generated by joining the published WinAnsi, Symbol and ZapfDingbats encodings (code to glyph name) with the per-glyph advance widths, then spot-checked against the specification by hand in the tests of crates/fonts/src/std14.rs. Data only: the code that reads these tables lives in std14.rs, so that ordinary edits do not churn this file's hash. | Advance widths for the fourteen standard fonts, which a PDF may name without embedding. Non-visual data, not a typeface: the item AGENTS.md 1.1 permits, held first-party so generated appearance streams and the renderer agree. |
| `docs/brand/artcraft-logo-white.png` | ArtCraft brand: artcraft-logo-white | ArtCraft Team | LicenseRef-Storyteller-Trademark | ArtCraft Team brand assets (provided by the project owner, 2026-10-01; identical copies in storytold/photocraft) | ArtCraft branding next to the community links (About dialog, Help menu, home screen) and in docs. ArtCraft Team trademark, not open source; may be used only unmodified within PdfCraft; forks and modified versions must remove it. |
| `docs/brand/artcraft-logo-white.svg` | ArtCraft brand: artcraft-logo-white | ArtCraft Team | LicenseRef-Storyteller-Trademark | ArtCraft Team brand assets (provided by the project owner, 2026-10-01; identical copies in storytold/photocraft) | ArtCraft branding next to the community links (About dialog, Help menu, home screen) and in docs. ArtCraft Team trademark, not open source; may be used only unmodified within PdfCraft; forks and modified versions must remove it. |
| `docs/brand/artcraft-logo.png` | ArtCraft brand: artcraft-logo | ArtCraft Team | LicenseRef-Storyteller-Trademark | ArtCraft Team brand assets (provided by the project owner, 2026-10-01; identical copies in storytold/photocraft) | ArtCraft branding next to the community links (About dialog, Help menu, home screen) and in docs. ArtCraft Team trademark, not open source; may be used only unmodified within PdfCraft; forks and modified versions must remove it. |
-12
View File
@@ -2170,18 +2170,6 @@ kind = "data"
usage = "Default CMYK colour conversion (shared hayro-interpret, pinned by Cargo.lock)"
sha256 = "73e1ba37d2bad5bab2a964f40a9eed96209666efc067c3322626214bbef234a0"
[[asset]]
path = "crates/fonts/src/std14_metrics.rs"
title = "Standard-14 font advance widths and encodings (as Rust tables)"
author = "Adobe (Core14 AFM metrics, PDF specification encodings); tables generated by the PdfCraft contributors"
source = "ISO 32000-2 Annex D and the Adobe Core14 AFM metrics. Generated by joining the published WinAnsi, Symbol and ZapfDingbats encodings (code to glyph name) with the per-glyph advance widths, then spot-checked against the specification by hand in the tests of crates/fonts/src/std14.rs. Data only: the code that reads these tables lives in std14.rs, so that ordinary edits do not churn this file's hash."
licence = "MIT OR Apache-2.0"
licence_file = "LICENSE-MIT"
kind = "data"
adobe_data = true
usage = "Advance widths for the fourteen standard fonts, which a PDF may name without embedding. Non-visual data, not a typeface: the item AGENTS.md 1.1 permits, held first-party so generated appearance streams and the renderer agree."
sha256 = "f225e0b044875b8fa6375b6b5ad935f0d99fcc1ad03ecf9f0baae2cedbfca4d2"
[[bundled]]
crate = "craft-prc"
version = "0.1.0"
Generated
+8 -7
View File
@@ -1579,7 +1579,7 @@ dependencies = [
[[package]]
name = "craft-pdf"
version = "0.1.0"
source = "git+https://github.com/storytold/craft-libs?rev=c470ed170dcb7aaaad7ce6172ca4e9b68dd1a7cd#c470ed170dcb7aaaad7ce6172ca4e9b68dd1a7cd"
source = "git+https://github.com/storytold/craft-libs?rev=a6e9a7e6c596982f3aaee1abf9a391383fb0a99e#a6e9a7e6c596982f3aaee1abf9a391383fb0a99e"
dependencies = [
"aes",
"bytemuck",
@@ -1695,7 +1695,7 @@ dependencies = [
[[package]]
name = "craft-stream-codecs"
version = "0.1.0"
source = "git+https://github.com/storytold/craft-libs?rev=c470ed170dcb7aaaad7ce6172ca4e9b68dd1a7cd#c470ed170dcb7aaaad7ce6172ca4e9b68dd1a7cd"
source = "git+https://github.com/storytold/craft-libs?rev=a6e9a7e6c596982f3aaee1abf9a391383fb0a99e#a6e9a7e6c596982f3aaee1abf9a391383fb0a99e"
dependencies = [
"fax",
"hayro-ccitt",
@@ -3319,7 +3319,7 @@ dependencies = [
[[package]]
name = "hayro"
version = "0.7.1"
source = "git+https://github.com/storytold/craft-libs?rev=c470ed170dcb7aaaad7ce6172ca4e9b68dd1a7cd#c470ed170dcb7aaaad7ce6172ca4e9b68dd1a7cd"
source = "git+https://github.com/storytold/craft-libs?rev=a6e9a7e6c596982f3aaee1abf9a391383fb0a99e#a6e9a7e6c596982f3aaee1abf9a391383fb0a99e"
dependencies = [
"bytemuck",
"hayro-interpret",
@@ -3339,7 +3339,7 @@ checksum = "9f4d0e94ddd48749f06bbe4e5389fb9799a0c45bcaf00495042076ef05e3241a"
[[package]]
name = "hayro-cmap"
version = "0.1.0"
source = "git+https://github.com/storytold/craft-libs?rev=c470ed170dcb7aaaad7ce6172ca4e9b68dd1a7cd#c470ed170dcb7aaaad7ce6172ca4e9b68dd1a7cd"
source = "git+https://github.com/storytold/craft-libs?rev=a6e9a7e6c596982f3aaee1abf9a391383fb0a99e#a6e9a7e6c596982f3aaee1abf9a391383fb0a99e"
dependencies = [
"brotli",
"hayro-postscript",
@@ -3348,7 +3348,7 @@ dependencies = [
[[package]]
name = "hayro-interpret"
version = "0.7.0"
source = "git+https://github.com/storytold/craft-libs?rev=c470ed170dcb7aaaad7ce6172ca4e9b68dd1a7cd#c470ed170dcb7aaaad7ce6172ca4e9b68dd1a7cd"
source = "git+https://github.com/storytold/craft-libs?rev=a6e9a7e6c596982f3aaee1abf9a391383fb0a99e#a6e9a7e6c596982f3aaee1abf9a391383fb0a99e"
dependencies = [
"bitflags 2.13.2",
"hayro-cmap",
@@ -3366,7 +3366,7 @@ dependencies = [
[[package]]
name = "hayro-jbig2"
version = "0.3.0"
source = "git+https://github.com/storytold/craft-libs?rev=c470ed170dcb7aaaad7ce6172ca4e9b68dd1a7cd#c470ed170dcb7aaaad7ce6172ca4e9b68dd1a7cd"
source = "git+https://github.com/storytold/craft-libs?rev=a6e9a7e6c596982f3aaee1abf9a391383fb0a99e#a6e9a7e6c596982f3aaee1abf9a391383fb0a99e"
dependencies = [
"fearless_simd",
"hayro-ccitt",
@@ -3389,7 +3389,7 @@ source = "git+https://github.com/storytold/craft-libs?rev=e7873217287876f76a0455
[[package]]
name = "hayro-syntax"
version = "0.7.2"
source = "git+https://github.com/storytold/craft-libs?rev=c470ed170dcb7aaaad7ce6172ca4e9b68dd1a7cd#c470ed170dcb7aaaad7ce6172ca4e9b68dd1a7cd"
source = "git+https://github.com/storytold/craft-libs?rev=a6e9a7e6c596982f3aaee1abf9a391383fb0a99e#a6e9a7e6c596982f3aaee1abf9a391383fb0a99e"
dependencies = [
"flate2",
"hayro-ccitt",
@@ -5177,6 +5177,7 @@ dependencies = [
name = "pdfcraft-fonts"
version = "0.21.1"
dependencies = [
"craft-pdf",
"harfrust",
"pdfcraft-cos",
"skrifa 0.44.0",
+6 -6
View File
@@ -35,7 +35,7 @@ craft-zip = { git = "https://github.com/storytold/craft-libs", version = "0.1.0"
craft-docpath = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "e2dc681a3" }
# craft-update: app-specific pretend versions apply to startup and manual checks.
craft-update = { git = "https://github.com/storytold/craft-libs", version = "=0.1.0", rev = "e2dc681a3", features = ["egui"] }
craft-pdf = { git = "https://github.com/storytold/craft-libs", version = "0.1.0", rev = "c470ed170dcb7aaaad7ce6172ca4e9b68dd1a7cd", features = ["cos", "crypt", "filters"] }
craft-pdf = { git = "https://github.com/storytold/craft-libs", version = "0.1.0", rev = "a6e9a7e6c596982f3aaee1abf9a391383fb0a99e", features = ["cos", "crypt", "filters", "fonts"] }
# The writers the Word and RTF exports map onto (storytold/craft-libs#793). craft-rtf, craft-wordmodel and
# craft-docx move together: craft_rtf::doc::export takes its own revision's Document.
craft-rtf = { git = "https://github.com/storytold/craft-libs", version = "0.1.0", rev = "b8eaa8e2f3561f9fa27fcf3b7f67ce915e93caa3" }
@@ -166,12 +166,12 @@ codegen-units = 1
# Vendored, patched third-party crates (see vendor/README.md). Each patch is meant to go upstream.
[patch.crates-io]
hayro-interpret = { git = "https://github.com/storytold/craft-libs", rev = "c470ed170dcb7aaaad7ce6172ca4e9b68dd1a7cd" }
hayro = { git = "https://github.com/storytold/craft-libs", rev = "c470ed170dcb7aaaad7ce6172ca4e9b68dd1a7cd" }
hayro-syntax = { git = "https://github.com/storytold/craft-libs", rev = "c470ed170dcb7aaaad7ce6172ca4e9b68dd1a7cd" }
hayro-cmap = { git = "https://github.com/storytold/craft-libs", rev = "c470ed170dcb7aaaad7ce6172ca4e9b68dd1a7cd" }
hayro-interpret = { git = "https://github.com/storytold/craft-libs", rev = "a6e9a7e6c596982f3aaee1abf9a391383fb0a99e" }
hayro = { git = "https://github.com/storytold/craft-libs", rev = "a6e9a7e6c596982f3aaee1abf9a391383fb0a99e" }
hayro-syntax = { git = "https://github.com/storytold/craft-libs", rev = "a6e9a7e6c596982f3aaee1abf9a391383fb0a99e" }
hayro-cmap = { git = "https://github.com/storytold/craft-libs", rev = "a6e9a7e6c596982f3aaee1abf9a391383fb0a99e" }
hayro-postscript = { git = "https://github.com/storytold/craft-libs", rev = "e7873217287876f76a045550369c90a541693c33" }
hayro-jbig2 = { git = "https://github.com/storytold/craft-libs", rev = "c470ed170dcb7aaaad7ce6172ca4e9b68dd1a7cd" }
hayro-jbig2 = { git = "https://github.com/storytold/craft-libs", rev = "a6e9a7e6c596982f3aaee1abf9a391383fb0a99e" }
lopdf = { path = "vendor/lopdf" }
vello_common = { path = "vendor/vello_common" }
vello_cpu = { path = "vendor/vello_cpu" }
+1
View File
@@ -9,6 +9,7 @@ license.workspace = true
workspace = true
[dependencies]
craft-pdf = { workspace = true }
pdfcraft-cos = { workspace = true }
# Glyph outlines of the bundled script font (typed signatures); already in the tree via egui.
skrifa = "0.44"
+1 -1
View File
@@ -10,7 +10,7 @@ use skrifa::{
raw::TableProvider,
};
use crate::wire::{
use craft_pdf::fonts::wire::{
CidMapping, FontDescriptorSpec, build_cid_encoding_cmap, build_cid_font_dict, build_font_descriptor, build_to_unicode_cmap,
build_type0_font_dict, font_program_stream,
};
-275
View File
@@ -1,275 +0,0 @@
//! Single-byte encodings (ISO 32000-2 Annex D) as code → Unicode tables (0 = undefined).
pub(crate) static WIN_ANSI: [u32; 256] = [
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43,
44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79,
80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112,
113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 0, 8364, 0, 8218, 402, 8222, 8230, 8224, 8225, 710, 8240, 352, 8249, 338,
// 0xA0 is `space` and 0xAD is `hyphen`, not U+00A0 and U+00AD: WinAnsiEncoding's table
// (Annex D.2) gives those codes the same glyph names as 0x20 and 0x2D, so the bytes a Windows
// codepage calls a non-breaking space and a soft hyphen draw, and extract as, an ordinary
// space and hyphen. Emitting the formatting characters instead hides them from search and
// from redaction's pattern matching: a soft hyphen is invisible and matches nothing, and a
// non-breaking space does not match the space a reader typed.
0, 381, 0, 0, 8216, 8217, 8220, 8221, 8226, 8211, 8212, 732, 8482, 353, 8250, 339, 0, 382, 376, 32, 161, 162, 163, 164, 165, 166, 167, 168, 169,
170, 171, 172, 45, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198,
199, 200, 201, 202, 203, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220, 221, 222, 223, 224, 225, 226, 227,
228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239, 240, 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, 255,
];
pub(crate) static MAC_ROMAN: [u32; 256] = [
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43,
44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79,
80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112,
113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 0, 196, 197, 199, 201, 209, 214, 220, 225, 224, 226, 228, 227, 229, 231,
233, 232, 234, 235, 237, 236, 238, 239, 241, 243, 242, 244, 246, 245, 250, 249, 251, 252, 8224, 176, 162, 163, 167, 8226, 182, 223, 174, 169,
8482, 180, 168, 8800, 198, 216, 8734, 177, 8804, 8805, 165, 181, 8706, 8721, 8719, 960, 8747, 170, 186, 937, 230, 248, 191, 161, 172, 8730, 402,
// 0xCA is `space`, the same glyph name Annex D.2 gives 0x20, for the reason WinAnsi 0xA0 is.
8776, 8710, 171, 187, 8230, 32, 192, 195, 213, 338, 339, 8211, 8212, 8220, 8221, 8216, 8217, 247, 9674, 255, 376, 8260, 8364, 8249, 8250, 64257,
64258, 8225, 183, 8218, 8222, 8240, 194, 202, 193, 203, 200, 205, 206, 207, 204, 211, 212, 63743, 210, 218, 219, 217, 305, 710, 732, 175, 728,
729, 730, 184, 733, 731, 711,
];
pub(crate) static STANDARD: [u32; 256] = [
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 32, 33, 34, 35, 36, 37, 38, 8217, 40, 41, 42, 43,
44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79,
80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 8216, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111,
112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 161, 162, 163, 8260, 165, 402, 167, 164, 39, 8220, 171, 8249, 8250, 64257, 64258, 0, 8211, 8224, 8225, 183, 0,
182, 8226, 8218, 8222, 8221, 187, 8230, 8240, 0, 191, 0, 96, 180, 710, 732, 175, 728, 729, 168, 0, 730, 184, 0, 733, 731, 711, 8212, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 198, 0, 170, 0, 0, 0, 0, 321, 216, 338, 186, 0, 0, 0, 0, 0, 230, 0, 0, 0, 305, 0, 0, 322, 248, 339, 223, 0,
0, 0, 0,
];
/// Glyph names of the Latin character set (Annex D) → Unicode.
pub(crate) static NAMES: &[(&str, u32)] = &[
("A", 0x41),
("AE", 0xc6),
("Aacute", 0xc1),
("Acircumflex", 0xc2),
("Adieresis", 0xc4),
("Agrave", 0xc0),
("Aring", 0xc5),
("Atilde", 0xc3),
("B", 0x42),
("C", 0x43),
("Ccedilla", 0xc7),
("D", 0x44),
("E", 0x45),
("Eacute", 0xc9),
("Ecircumflex", 0xca),
("Edieresis", 0xcb),
("Egrave", 0xc8),
("Eth", 0xd0),
("Euro", 0x20ac),
("F", 0x46),
("G", 0x47),
("H", 0x48),
("I", 0x49),
("Iacute", 0xcd),
("Icircumflex", 0xce),
("Idieresis", 0xcf),
("Igrave", 0xcc),
("J", 0x4a),
("K", 0x4b),
("L", 0x4c),
("Lslash", 0x141),
("M", 0x4d),
("N", 0x4e),
("Ntilde", 0xd1),
("O", 0x4f),
("OE", 0x152),
("Oacute", 0xd3),
("Ocircumflex", 0xd4),
("Odieresis", 0xd6),
("Ograve", 0xd2),
("Oslash", 0xd8),
("Otilde", 0xd5),
("P", 0x50),
("Q", 0x51),
("R", 0x52),
("S", 0x53),
("Scaron", 0x160),
("T", 0x54),
("Thorn", 0xde),
("U", 0x55),
("Uacute", 0xda),
("Ucircumflex", 0xdb),
("Udieresis", 0xdc),
("Ugrave", 0xd9),
("V", 0x56),
("W", 0x57),
("X", 0x58),
("Y", 0x59),
("Yacute", 0xdd),
("Ydieresis", 0x178),
("Z", 0x5a),
("Zcaron", 0x17d),
("a", 0x61),
("aacute", 0xe1),
("acircumflex", 0xe2),
("acute", 0xb4),
("adieresis", 0xe4),
("ae", 0xe6),
("agrave", 0xe0),
("ampersand", 0x26),
("aring", 0xe5),
("asciicircum", 0x5e),
("asciitilde", 0x7e),
("asterisk", 0x2a),
("at", 0x40),
("atilde", 0xe3),
("b", 0x62),
("backslash", 0x5c),
("bar", 0x7c),
("braceleft", 0x7b),
("braceright", 0x7d),
("bracketleft", 0x5b),
("bracketright", 0x5d),
("breve", 0x2d8),
("brokenbar", 0xa6),
("bullet", 0x2022),
("c", 0x63),
("caron", 0x2c7),
("ccedilla", 0xe7),
("cedilla", 0xb8),
("cent", 0xa2),
("circumflex", 0x2c6),
("colon", 0x3a),
("comma", 0x2c),
("copyright", 0xa9),
("currency", 0xa4),
("d", 0x64),
("dagger", 0x2020),
("daggerdbl", 0x2021),
("degree", 0xb0),
("dieresis", 0xa8),
("divide", 0xf7),
("dollar", 0x24),
("dotaccent", 0x2d9),
("dotlessi", 0x131),
("e", 0x65),
("eacute", 0xe9),
("ecircumflex", 0xea),
("edieresis", 0xeb),
("egrave", 0xe8),
("eight", 0x38),
("ellipsis", 0x2026),
("emdash", 0x2014),
("endash", 0x2013),
("equal", 0x3d),
("eth", 0xf0),
("exclam", 0x21),
("exclamdown", 0xa1),
("f", 0x66),
("fi", 0xfb01),
("five", 0x35),
("fl", 0xfb02),
("florin", 0x192),
("four", 0x34),
("fraction", 0x2044),
("g", 0x67),
("germandbls", 0xdf),
("grave", 0x60),
("greater", 0x3e),
("guillemotleft", 0xab),
("guillemotright", 0xbb),
("guilsinglleft", 0x2039),
("guilsinglright", 0x203a),
("h", 0x68),
("hungarumlaut", 0x2dd),
("hyphen", 0x2d),
("i", 0x69),
("iacute", 0xed),
("icircumflex", 0xee),
("idieresis", 0xef),
("igrave", 0xec),
("j", 0x6a),
("k", 0x6b),
("l", 0x6c),
("less", 0x3c),
("logicalnot", 0xac),
("lslash", 0x142),
("m", 0x6d),
("macron", 0xaf),
("minus", 0x2212),
("mu", 0xb5),
("multiply", 0xd7),
("n", 0x6e),
("nbspace", 0xa0),
("nine", 0x39),
("ntilde", 0xf1),
("numbersign", 0x23),
("o", 0x6f),
("oacute", 0xf3),
("ocircumflex", 0xf4),
("odieresis", 0xf6),
("oe", 0x153),
("ogonek", 0x2db),
("ograve", 0xf2),
("one", 0x31),
("onehalf", 0xbd),
("onequarter", 0xbc),
("onesuperior", 0xb9),
("ordfeminine", 0xaa),
("ordmasculine", 0xba),
("oslash", 0xf8),
("otilde", 0xf5),
("p", 0x70),
("paragraph", 0xb6),
("parenleft", 0x28),
("parenright", 0x29),
("percent", 0x25),
("period", 0x2e),
("periodcentered", 0xb7),
("perthousand", 0x2030),
("plus", 0x2b),
("plusminus", 0xb1),
("q", 0x71),
("question", 0x3f),
("questiondown", 0xbf),
("quotedbl", 0x22),
("quotedblbase", 0x201e),
("quotedblleft", 0x201c),
("quotedblright", 0x201d),
("quoteleft", 0x2018),
("quoteright", 0x2019),
("quotesinglbase", 0x201a),
("quotesingle", 0x27),
("r", 0x72),
("registered", 0xae),
("ring", 0x2da),
("s", 0x73),
("scaron", 0x161),
("section", 0xa7),
("semicolon", 0x3b),
("seven", 0x37),
("sfthyphen", 0xad),
("six", 0x36),
("slash", 0x2f),
("space", 0x20),
("sterling", 0xa3),
("t", 0x74),
("thorn", 0xfe),
("three", 0x33),
("threequarters", 0xbe),
("threesuperior", 0xb3),
("tilde", 0x2dc),
("trademark", 0x2122),
("two", 0x32),
("twosuperior", 0xb2),
("u", 0x75),
("uacute", 0xfa),
("ucircumflex", 0xfb),
("udieresis", 0xfc),
("ugrave", 0xf9),
("underscore", 0x5f),
("v", 0x76),
("w", 0x77),
("x", 0x78),
("y", 0x79),
("yacute", 0xfd),
("ydieresis", 0xff),
("yen", 0xa5),
("z", 0x7a),
("zcaron", 0x17e),
("zero", 0x30),
];
+2 -2
View File
@@ -172,8 +172,8 @@ pub fn substitute(req: &Request<'_>) -> Substitution {
}
if let Some((f, how)) = Std14::recognise(req.base_font) {
return match how {
crate::std14::Match::Alias => at(Face::Standard14(f), Why::NamedStandard14),
crate::std14::Match::FamilyHint => at(Face::Standard14(f), Why::NameHintedStandard14),
crate::Std14Match::Alias => at(Face::Standard14(f), Why::NamedStandard14),
crate::Std14Match::FamilyHint => at(Face::Standard14(f), Why::NameHintedStandard14),
};
}
if let Some(f) = crate::embedding::matching_faces(req.base_font).first() {
+3 -109
View File
@@ -11,7 +11,6 @@
mod cjk_scripts;
mod craft;
pub mod embedding;
mod encodings;
pub mod fallback;
pub mod pdf;
pub mod plan;
@@ -19,14 +18,14 @@ mod script;
pub mod shaped_text;
mod shaping;
pub mod source_shaping;
mod std14;
mod std14_metrics;
mod wire;
pub use craft::{
CRAFT_FONTS, CraftFont, SHIPPORI_MINCHO, document_arabic_font, document_devanagari_font, document_hebrew_font, document_japanese_font,
document_japanese_font_for_style, document_japanese_fonts_for_style, document_latin_fonts, document_thai_font, ui_arabic_fonts, ui_chinese_fonts,
ui_cjk_fonts, ui_devanagari_fonts, ui_hebrew_fonts, ui_japanese_fonts, ui_telugu_fonts, ui_thai_fonts,
};
pub use craft_pdf::fonts::{
Std14, Std14Match, UnicodeCMap, encodings, first_non_win_ansi, fits_win_ansi, win_ansi, win_ansi_byte, win_ansi_char, win_ansi_encodable,
};
pub use plan::{MAX_PLAN_GLYPHS, MAX_TYPE3_GLYPHS, PlannedType3, TextPlan};
pub use script::{
GlyphError, GlyphOutline, INTER_REGULAR, MAX_SIGNATURE_CHARS, ScriptOutline, craft_glyph, face_has, japanese_glyph, japanese_glyph_from,
@@ -36,7 +35,6 @@ pub use shaping::{
ShapedCluster, ShapedScript, arabic_glyph, arabic_has, face_glyph, hebrew_has, latin_has, shape_arabic, shape_hebrew, shape_latin, shape_thai,
shaped_glyph, thai_has,
};
pub use std14::{Match as Std14Match, Std14};
/// Advance of `s` in Helvetica at `size` points, using the exact standard-14 metrics.
///
@@ -153,100 +151,6 @@ pub fn wrap_with(text: &str, size: f64, width: f64, measure: impl Fn(&str, f64)
lines
}
/// The WinAnsiEncoding (ISO 32000-2 Annex D) code for `c`, if the encoding has one.
///
/// Codes 0x80–0x9F come from the same table the text extractor decodes with, so encoding and
/// decoding agree (Š š Ž ž Œ œ Ÿ ƒ † ‡ ˆ ˜ ‰ ‹ › as well as quotes, dashes, € and ™).
pub fn win_ansi_byte(c: char) -> Option<u8> {
match c {
'\u{20}'..='\u{7e}' | '\u{a0}'..='\u{ff}' => u8::try_from(u32::from(c)).ok(),
_ => {
let high = encodings::WIN_ANSI.get(0x80..0xa0)?;
let i = high.iter().position(|&u| u != 0 && u == u32::from(c))?;
u8::try_from(0x80 + i).ok()
}
}
}
/// Encode text in WinAnsiEncoding (ISO 32000-2 Annex D); tabs become spaces and unmappable
/// characters become `?`.
pub fn win_ansi(s: &str) -> Vec<u8> {
s.chars().map(|c| if c == '\t' { b' ' } else { win_ansi_byte(c).unwrap_or(b'?') }).collect()
}
/// The character encoding of a predefined Unicode CMap (`UniJIS-UTF16-H`, `UniGB-UCS2-H`, …;
/// ISO 32000-2 §9.7.5.2), which maps Unicode text straight to codes.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum UnicodeCMap {
Ucs2,
Utf16,
Utf8,
Utf32,
}
impl UnicodeCMap {
/// The encoding of the predefined CMap `name`, if it is a horizontal Unicode one. Vertical
/// (`-V`) CMaps are refused: field appearances are laid out horizontally, so their glyphs
/// would be drawn stacked down the field instead of across it.
pub fn from_name(name: &[u8]) -> Option<Self> {
let name = std::str::from_utf8(name).ok()?;
if !name.starts_with("Uni") || !name.ends_with("-H") {
return None;
}
name.split('-').find_map(|part| match part {
"UCS2" => Some(Self::Ucs2),
"UTF16" => Some(Self::Utf16),
"UTF8" => Some(Self::Utf8),
"UTF32" => Some(Self::Utf32),
_ => None,
})
}
/// The first character of `s` this encoding can't hold, which [`Self::encode`] would write as
/// `?`: a character beyond U+FFFF in UCS-2 (`𠀋`). UTF-16, UTF-8 and UTF-32 hold every one.
pub fn first_unencodable(self, s: &str) -> Option<char> {
match self {
Self::Ucs2 => s.chars().find(|c| u16::try_from(u32::from(*c)).is_err()),
Self::Utf16 | Self::Utf8 | Self::Utf32 => None,
}
}
/// Encode `s`; tabs become spaces, and characters UCS-2 can't hold become `?` (check them
/// first with [`Self::first_unencodable`]: PdfCraft refuses such text rather than write `?`).
pub fn encode(self, s: &str) -> Vec<u8> {
let mut out = Vec::with_capacity(s.len().saturating_mul(2));
let mut units = [0u16; 2];
let mut buf = [0u8; 4];
for c in s.chars() {
let c = if c == '\t' { ' ' } else { c };
match self {
Self::Ucs2 => {
let unit = u16::try_from(u32::from(c)).unwrap_or(u16::from(b'?'));
out.extend_from_slice(&unit.to_be_bytes());
}
Self::Utf16 => {
for unit in c.encode_utf16(&mut units) {
out.extend_from_slice(&unit.to_be_bytes());
}
}
Self::Utf8 => out.extend_from_slice(c.encode_utf8(&mut buf).as_bytes()),
Self::Utf32 => out.extend_from_slice(&u32::from(c).to_be_bytes()),
}
}
out
}
}
/// Whether [`win_ansi`] keeps `c` rather than writing `?` (a tab becomes a space).
pub fn win_ansi_encodable(c: char) -> bool {
c == '\t' || win_ansi_byte(c).is_some()
}
/// The first character of `s` that [`win_ansi`] can't encode and would write as `?`.
pub fn first_non_win_ansi(s: &str) -> Option<char> {
s.chars().find(|c| !win_ansi_encodable(*c))
}
/// The first character of `s` the standard fonts (Helvetica and the rest of the standard 14, in
/// WinAnsiEncoding) can't draw, so that a generated appearance would show it as `?`. Line breaks
/// don't count: appearances lay lines out themselves. PdfCraft refuses such text with
@@ -288,16 +192,6 @@ pub fn set_undrawn_mark(d: &mut pdfcraft_cos::Dict, c: Option<char>) {
}
}
/// The byte used by Unicode text plans, from the shared WinAnsi table (tabs become spaces).
pub fn win_ansi_char(c: char) -> Option<u8> {
if c == '\t' { Some(b' ') } else { win_ansi_byte(c) }
}
/// Whether every character can be represented without substitution in WinAnsi.
pub fn fits_win_ansi(s: &str) -> bool {
s.chars().all(win_ansi_encodable)
}
/// Bytes as a PDF literal string, `(` … `)`, with delimiters escaped.
pub fn literal(bytes: &[u8]) -> Vec<u8> {
let mut out = Vec::with_capacity(bytes.len() + 2);
-260
View File
@@ -1,260 +0,0 @@
//! Standard-14 font metrics (ISO 32000-2 Annex D; the Adobe Core14 AFM metrics), as advance
//! widths in glyph space — thousandths of an em.
//!
//! A PDF may name any of the fourteen standard fonts without embedding a program, and the viewer
//! has to supply the metrics. These are those metrics, exactly, replacing the character-class
//! estimate that generated appearances used before: that estimate had Times at 0.9 x Helvetica,
//! which makes a capital A 600 where the specification says 722.
//!
//! **Generated.** The tables are data, not typefaces, and are the item clean-room.md permits as
//! Adobe-authored non-visual technical data; `ATTRIBUTION.toml` carries the entry with
//! `adobe_data = true`. Each row is indexed by character **code**, not by Unicode: the twelve text
//! fonts are indexed by WinAnsiEncoding, which is what PdfCraft writes into the appearance streams
//! it generates, and Symbol and ZapfDingbats by their own built-in encodings. A zero means the
//! encoding leaves that code undefined.
/// One of the fourteen standard fonts (ISO 32000-2 §9.6.2.2).
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub enum Std14 {
Helvetica,
HelveticaBold,
HelveticaOblique,
HelveticaBoldOblique,
TimesRoman,
TimesBold,
TimesItalic,
TimesBoldItalic,
Courier,
CourierBold,
CourierOblique,
CourierBoldOblique,
Symbol,
ZapfDingbats,
}
/// How [`Std14::recognise`] matched a `/BaseFont` name.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum Match {
/// A standard-14 face or a well-known alias of one (Arial for Helvetica, CourierNew for
/// Courier). The document is asking for this face.
Alias,
/// Only a family hint matched -- "Serif", "Roman" or "Mono" in an otherwise unknown name.
/// The face is a guess from the name, not the one the document asked for.
FamilyHint,
}
impl Std14 {
/// The font a `/BaseFont` name selects, by the spec's names and the common aliases viewers
/// accept (`Arial` for `Helvetica`, `TimesNewRoman` for `Times`, `CourierNew` for `Courier`).
/// A subset prefix such as `ABCDEF+Helvetica` is ignored.
pub fn from_base_font(base: &str) -> Option<Self> {
Self::recognise(base).map(|(face, _)| face)
}
/// [`Std14::from_base_font`], also saying *how* the name matched.
///
/// Reporting needs the difference. "Arial" really is a request for Helvetica, but
/// "SomeHouseSerif" is a house font whose name merely contains "Serif"; choosing Times for it
/// is a reasonable guess from the name, not the face the document asked for, and a substitution
/// report that called it a standard-14 name would be telling the reader something untrue.
pub fn recognise(base: &str) -> Option<(Self, Match)> {
let base = base.rsplit('+').next().unwrap_or(base);
let flat: String = base.chars().filter(char::is_ascii_alphanumeric).map(|c| c.to_ascii_lowercase()).collect();
let has = |w: &str| flat.contains(w);
let (bold, italic) = (has("bold"), has("italic") || has("oblique"));
// Two bools index a four-element array, so the subscript is provably 0..=3.
let styled = |faces: [Self; 4]| faces[usize::from(bold) | usize::from(italic) << 1];
let courier = || styled([Self::Courier, Self::CourierBold, Self::CourierOblique, Self::CourierBoldOblique]);
let times = || styled([Self::TimesRoman, Self::TimesBold, Self::TimesItalic, Self::TimesBoldItalic]);
if has("symbol") {
return Some((Self::Symbol, Match::Alias));
}
if has("zapf") || has("dingbat") {
return Some((Self::ZapfDingbats, Match::Alias));
}
if has("courier") {
return Some((courier(), Match::Alias));
}
if has("mono") {
return Some((courier(), Match::FamilyHint));
}
if has("times") {
return Some((times(), Match::Alias));
}
if (has("serif") && !has("sans")) || has("roman") {
return Some((times(), Match::FamilyHint));
}
if has("helvetica") || has("arial") {
return Some((styled([Self::Helvetica, Self::HelveticaBold, Self::HelveticaOblique, Self::HelveticaBoldOblique]), Match::Alias));
}
None
}
/// The advance of one character `code`, in thousandths of an em. Zero where the font's
/// encoding leaves the code undefined.
pub fn width(self, code: u8) -> f64 {
f64::from(crate::std14_metrics::WIDTHS[self as usize][code as usize])
}
/// The advance of `code` at `size` points.
pub fn advance(self, code: u8, size: f64) -> f64 {
self.width(code) * size / 1000.0
}
/// The advance of `text` at `size` points, encoded as the twelve text fonts are written:
/// WinAnsiEncoding, with characters it cannot represent replaced as `win_ansi` replaces them.
///
/// Symbol and ZapfDingbats have their own built-in encodings and are not WinAnsi, so this
/// measures them as if they were; pass codes to [`Std14::width`] for those.
pub fn text_width(self, text: &str, size: f64) -> f64 {
crate::win_ansi(text).iter().map(|&c| self.width(c)).sum::<f64>() * size / 1000.0
}
/// Courier is the only fixed-pitch family of the fourteen.
pub fn is_fixed_pitch(self) -> bool {
matches!(self, Self::Courier | Self::CourierBold | Self::CourierOblique | Self::CourierBoldOblique)
}
/// The `/BaseFont` name for this font, as it is written into a PDF.
pub fn base_font(self) -> &'static str {
crate::std14_metrics::BASE_FONTS[self as usize]
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn sans_serif_names_are_not_mapped_to_times() {
assert!(!matches!(Std14::recognise("SansSerif"), Some((Std14::TimesRoman, _))));
assert_eq!(Std14::recognise("Arial-SansSerif"), Some((Std14::Helvetica, Match::Alias)));
}
/// Widths from the published Core14 metrics, typed in here by hand so the table is checked
/// against the specification rather than against whatever produced it.
#[test]
fn widths_match_the_published_metrics() {
let cases: &[(Std14, char, u16)] = &[
// Helvetica
(Std14::Helvetica, ' ', 278),
(Std14::Helvetica, 'A', 667),
(Std14::Helvetica, 'W', 944),
(Std14::Helvetica, 'i', 222),
(Std14::Helvetica, 'm', 833),
(Std14::Helvetica, '0', 556),
(Std14::Helvetica, '@', 1015),
(Std14::HelveticaBold, 'A', 722),
(Std14::HelveticaBold, 'i', 278),
// Times: not Helvetica scaled by 0.9, which is what the old estimate assumed.
(Std14::TimesRoman, ' ', 250),
(Std14::TimesRoman, 'A', 722),
(Std14::TimesRoman, 'W', 944),
(Std14::TimesRoman, 'i', 278),
(Std14::TimesRoman, 'm', 778),
(Std14::TimesBold, 'A', 722),
(Std14::TimesItalic, 'A', 611),
// Courier is fixed pitch at 600 for every glyph.
(Std14::Courier, ' ', 600),
(Std14::Courier, 'A', 600),
(Std14::Courier, 'm', 600),
(Std14::CourierBoldOblique, 'W', 600),
];
for &(font, ch, want) in cases {
let code = crate::win_ansi(&ch.to_string());
assert_eq!(code.len(), 1, "{ch:?} is one WinAnsi byte");
assert_eq!(font.width(code[0]) as u16, want, "{font:?} {ch:?}");
}
}
#[test]
fn courier_is_fixed_pitch_everywhere_it_is_defined() {
for font in [Std14::Courier, Std14::CourierBold, Std14::CourierOblique, Std14::CourierBoldOblique] {
assert!(font.is_fixed_pitch());
for code in 0..=255u8 {
let w = font.width(code);
assert!(w == 0.0 || w == 600.0, "{font:?} code {code} has width {w}");
}
}
assert!(!Std14::Helvetica.is_fixed_pitch());
}
#[test]
fn every_text_font_covers_printable_ascii_and_latin1() {
for font in [Std14::Helvetica, Std14::TimesRoman, Std14::Courier, Std14::TimesBoldItalic] {
for code in 0x20..=0x7Eu8 {
assert!(font.width(code) > 0.0, "{font:?} has no width for ASCII {code}");
}
for code in 0xA0..=0xFFu8 {
assert!(font.width(code) > 0.0, "{font:?} has no width for Latin-1 {code}");
}
}
}
#[test]
fn symbol_and_dingbats_have_their_own_encodings() {
// Symbol's code 0x61 is alpha, not 'a'; ZapfDingbats' is a scissors glyph.
assert!(Std14::Symbol.width(0x61) > 0.0);
assert!(Std14::ZapfDingbats.width(0x61) > 0.0);
// Neither defines the Latin-1 upper half the text fonts do.
assert_eq!(Std14::Symbol.width(0xFF), 0.0);
}
#[test]
fn base_font_names_round_trip() {
for i in 0..14usize {
let font = [
Std14::Helvetica,
Std14::HelveticaBold,
Std14::HelveticaOblique,
Std14::HelveticaBoldOblique,
Std14::TimesRoman,
Std14::TimesBold,
Std14::TimesItalic,
Std14::TimesBoldItalic,
Std14::Courier,
Std14::CourierBold,
Std14::CourierOblique,
Std14::CourierBoldOblique,
Std14::Symbol,
Std14::ZapfDingbats,
][i];
assert_eq!(Std14::from_base_font(font.base_font()), Some(font), "{}", font.base_font());
}
}
#[test]
fn base_font_aliases_and_subset_prefixes_resolve() {
assert_eq!(Std14::from_base_font("ABCDEF+Helvetica-Bold"), Some(Std14::HelveticaBold));
assert_eq!(Std14::from_base_font("Arial"), Some(Std14::Helvetica));
assert_eq!(Std14::from_base_font("Arial,BoldItalic"), Some(Std14::HelveticaBoldOblique));
assert_eq!(Std14::from_base_font("TimesNewRoman,Bold"), Some(Std14::TimesBold));
assert_eq!(Std14::from_base_font("CourierNew-Oblique"), Some(Std14::CourierOblique));
assert_eq!(Std14::from_base_font("ZapfDingbats"), Some(Std14::ZapfDingbats));
assert_eq!(Std14::from_base_font("Wingdings"), None);
assert_eq!(Std14::from_base_font(""), None);
}
#[test]
fn text_width_sums_the_glyphs_and_scales_with_size() {
let h = Std14::Helvetica;
// "AW" = 667 + 944 = 1611 thousandths of an em.
assert!((h.text_width("AW", 1000.0) - 1611.0).abs() < 1e-9);
assert!((h.text_width("AW", 12.0) - 1611.0 * 12.0 / 1000.0).abs() < 1e-9);
assert_eq!(h.text_width("", 12.0), 0.0);
// Courier: every character is 600, so the width is purely a count.
assert!((Std14::Courier.text_width("hello", 10.0) - 5.0 * 6.0).abs() < 1e-9);
}
#[test]
fn hostile_text_does_not_panic_and_stays_finite() {
for font in [Std14::Helvetica, Std14::Symbol, Std14::Courier] {
for s in ["", "\0", "\u{202E}", "💥", &"a".repeat(10_000), "\u{FFFD}"] {
let w = font.text_width(s, 12.0);
assert!(w.is_finite() && w >= 0.0, "{font:?} {s:?} -> {w}");
}
assert!(font.advance(0, 12.0).is_finite());
assert!(font.advance(255, 0.0).is_finite());
}
}
}
-300
View File
@@ -1,300 +0,0 @@
//! The generated standard-14 tables: the fourteen base font names and their per-code advance
//! widths. **Data only, no logic** -- see `std14.rs` for everything that interprets it.
//!
//! This file is the closed-list item in AGENTS.md 1.1 and carries a SHA-256 in `ATTRIBUTION.toml`,
//! so `cargo xtask assets` fails until a change to it is re-attested. It is kept separate from the
//! code that reads it for exactly that reason: if ordinary edits churned the hash, re-attesting
//! would become reflexive and the check would stop meaning anything.
//!
//! Widths are in thousandths of an em, indexed by character code in each face's own encoding --
//! WinAnsi for the twelve text faces, and their built-in encodings for Symbol and ZapfDingbats.
//! A zero means the encoding leaves that code undefined. Verified against the published
//! specification by the tests in `std14.rs`, which type the expected values in by hand.
pub(crate) static BASE_FONTS: [&str; 14] = [
"Helvetica",
"Helvetica-Bold",
"Helvetica-Oblique",
"Helvetica-BoldOblique",
"Times-Roman",
"Times-Bold",
"Times-Italic",
"Times-BoldItalic",
"Courier",
"Courier-Bold",
"Courier-Oblique",
"Courier-BoldOblique",
"Symbol",
"ZapfDingbats",
];
/// Advance widths by code, one row per [`Std14`] variant in declaration order.
#[rustfmt::skip]
pub(crate) static WIDTHS: [[u16; 256]; 14] = [
// Helvetica
[
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
278, 278, 355, 556, 556, 889, 667, 191, 333, 333, 389, 584, 278, 333, 278, 278,
556, 556, 556, 556, 556, 556, 556, 556, 556, 556, 278, 278, 584, 584, 584, 556,
1015, 667, 667, 722, 722, 667, 611, 778, 722, 278, 500, 667, 556, 833, 722, 778,
667, 778, 722, 667, 611, 722, 667, 944, 667, 667, 611, 278, 278, 278, 469, 556,
333, 556, 556, 500, 556, 556, 278, 556, 556, 222, 222, 500, 222, 833, 556, 556,
556, 556, 333, 500, 278, 556, 500, 722, 500, 500, 500, 334, 260, 334, 584, 0,
556, 0, 222, 556, 333, 1000, 556, 556, 333, 1000, 667, 333, 1000, 0, 611, 0,
0, 222, 222, 333, 333, 350, 556, 1000, 333, 1000, 500, 333, 944, 0, 500, 667,
278, 333, 556, 556, 556, 556, 260, 556, 333, 737, 370, 556, 584, 333, 737, 333,
400, 584, 333, 333, 333, 556, 537, 278, 333, 333, 365, 556, 834, 834, 834, 611,
667, 667, 667, 667, 667, 667, 1000, 722, 667, 667, 667, 667, 278, 278, 278, 278,
722, 722, 778, 778, 778, 778, 778, 584, 778, 722, 722, 722, 722, 667, 667, 611,
556, 556, 556, 556, 556, 556, 889, 500, 556, 556, 556, 556, 278, 278, 278, 278,
556, 556, 556, 556, 556, 556, 556, 584, 611, 556, 556, 556, 556, 500, 556, 500,
],
// HelveticaBold
[
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
278, 333, 474, 556, 556, 889, 722, 238, 333, 333, 389, 584, 278, 333, 278, 278,
556, 556, 556, 556, 556, 556, 556, 556, 556, 556, 333, 333, 584, 584, 584, 611,
975, 722, 722, 722, 722, 667, 611, 778, 722, 278, 556, 722, 611, 833, 722, 778,
667, 778, 722, 667, 611, 722, 667, 944, 667, 667, 611, 333, 278, 333, 584, 556,
333, 556, 611, 556, 611, 556, 333, 611, 611, 278, 278, 556, 278, 889, 611, 611,
611, 611, 389, 556, 333, 611, 556, 778, 556, 556, 500, 389, 280, 389, 584, 0,
556, 0, 278, 556, 500, 1000, 556, 556, 333, 1000, 667, 333, 1000, 0, 611, 0,
0, 278, 278, 500, 500, 350, 556, 1000, 333, 1000, 556, 333, 944, 0, 500, 667,
278, 333, 556, 556, 556, 556, 280, 556, 333, 737, 370, 556, 584, 333, 737, 333,
400, 584, 333, 333, 333, 611, 556, 278, 333, 333, 365, 556, 834, 834, 834, 611,
722, 722, 722, 722, 722, 722, 1000, 722, 667, 667, 667, 667, 278, 278, 278, 278,
722, 722, 778, 778, 778, 778, 778, 584, 778, 722, 722, 722, 722, 667, 667, 611,
556, 556, 556, 556, 556, 556, 889, 556, 556, 556, 556, 556, 278, 278, 278, 278,
611, 611, 611, 611, 611, 611, 611, 584, 611, 611, 611, 611, 611, 556, 611, 556,
],
// HelveticaOblique
[
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
278, 278, 355, 556, 556, 889, 667, 191, 333, 333, 389, 584, 278, 333, 278, 278,
556, 556, 556, 556, 556, 556, 556, 556, 556, 556, 278, 278, 584, 584, 584, 556,
1015, 667, 667, 722, 722, 667, 611, 778, 722, 278, 500, 667, 556, 833, 722, 778,
667, 778, 722, 667, 611, 722, 667, 944, 667, 667, 611, 278, 278, 278, 469, 556,
333, 556, 556, 500, 556, 556, 278, 556, 556, 222, 222, 500, 222, 833, 556, 556,
556, 556, 333, 500, 278, 556, 500, 722, 500, 500, 500, 334, 260, 334, 584, 0,
556, 0, 222, 556, 333, 1000, 556, 556, 333, 1000, 667, 333, 1000, 0, 611, 0,
0, 222, 222, 333, 333, 350, 556, 1000, 333, 1000, 500, 333, 944, 0, 500, 667,
278, 333, 556, 556, 556, 556, 260, 556, 333, 737, 370, 556, 584, 333, 737, 333,
400, 584, 333, 333, 333, 556, 537, 278, 333, 333, 365, 556, 834, 834, 834, 611,
667, 667, 667, 667, 667, 667, 1000, 722, 667, 667, 667, 667, 278, 278, 278, 278,
722, 722, 778, 778, 778, 778, 778, 584, 778, 722, 722, 722, 722, 667, 667, 611,
556, 556, 556, 556, 556, 556, 889, 500, 556, 556, 556, 556, 278, 278, 278, 278,
556, 556, 556, 556, 556, 556, 556, 584, 611, 556, 556, 556, 556, 500, 556, 500,
],
// HelveticaBoldOblique
[
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
278, 333, 474, 556, 556, 889, 722, 238, 333, 333, 389, 584, 278, 333, 278, 278,
556, 556, 556, 556, 556, 556, 556, 556, 556, 556, 333, 333, 584, 584, 584, 611,
975, 722, 722, 722, 722, 667, 611, 778, 722, 278, 556, 722, 611, 833, 722, 778,
667, 778, 722, 667, 611, 722, 667, 944, 667, 667, 611, 333, 278, 333, 584, 556,
333, 556, 611, 556, 611, 556, 333, 611, 611, 278, 278, 556, 278, 889, 611, 611,
611, 611, 389, 556, 333, 611, 556, 778, 556, 556, 500, 389, 280, 389, 584, 0,
556, 0, 278, 556, 500, 1000, 556, 556, 333, 1000, 667, 333, 1000, 0, 611, 0,
0, 278, 278, 500, 500, 350, 556, 1000, 333, 1000, 556, 333, 944, 0, 500, 667,
278, 333, 556, 556, 556, 556, 280, 556, 333, 737, 370, 556, 584, 333, 737, 333,
400, 584, 333, 333, 333, 611, 556, 278, 333, 333, 365, 556, 834, 834, 834, 611,
722, 722, 722, 722, 722, 722, 1000, 722, 667, 667, 667, 667, 278, 278, 278, 278,
722, 722, 778, 778, 778, 778, 778, 584, 778, 722, 722, 722, 722, 667, 667, 611,
556, 556, 556, 556, 556, 556, 889, 556, 556, 556, 556, 556, 278, 278, 278, 278,
611, 611, 611, 611, 611, 611, 611, 584, 611, 611, 611, 611, 611, 556, 611, 556,
],
// TimesRoman
[
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
250, 333, 408, 500, 500, 833, 778, 180, 333, 333, 500, 564, 250, 333, 250, 278,
500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 278, 278, 564, 564, 564, 444,
921, 722, 667, 667, 722, 611, 556, 722, 722, 333, 389, 722, 611, 889, 722, 722,
556, 722, 667, 556, 611, 722, 722, 944, 722, 722, 611, 333, 278, 333, 469, 500,
333, 444, 500, 444, 500, 444, 333, 500, 500, 278, 278, 500, 278, 778, 500, 500,
500, 500, 333, 389, 278, 500, 500, 722, 500, 500, 444, 480, 200, 480, 541, 0,
500, 0, 333, 500, 444, 1000, 500, 500, 333, 1000, 556, 333, 889, 0, 611, 0,
0, 333, 333, 444, 444, 350, 500, 1000, 333, 980, 389, 333, 722, 0, 444, 722,
250, 333, 500, 500, 500, 500, 200, 500, 333, 760, 276, 500, 564, 333, 760, 333,
400, 564, 300, 300, 333, 500, 453, 250, 333, 300, 310, 500, 750, 750, 750, 444,
722, 722, 722, 722, 722, 722, 889, 667, 611, 611, 611, 611, 333, 333, 333, 333,
722, 722, 722, 722, 722, 722, 722, 564, 722, 722, 722, 722, 722, 722, 556, 500,
444, 444, 444, 444, 444, 444, 667, 444, 444, 444, 444, 444, 278, 278, 278, 278,
500, 500, 500, 500, 500, 500, 500, 564, 500, 500, 500, 500, 500, 500, 500, 500,
],
// TimesBold
[
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
250, 333, 555, 500, 500, 1000, 833, 278, 333, 333, 500, 570, 250, 333, 250, 278,
500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 333, 333, 570, 570, 570, 500,
930, 722, 667, 722, 722, 667, 611, 778, 778, 389, 500, 778, 667, 944, 722, 778,
611, 778, 722, 556, 667, 722, 722, 1000, 722, 722, 667, 333, 278, 333, 581, 500,
333, 500, 556, 444, 556, 444, 333, 500, 556, 278, 333, 556, 278, 833, 556, 500,
556, 556, 444, 389, 333, 556, 500, 722, 500, 500, 444, 394, 220, 394, 520, 0,
500, 0, 333, 500, 500, 1000, 500, 500, 333, 1000, 556, 333, 1000, 0, 667, 0,
0, 333, 333, 500, 500, 350, 500, 1000, 333, 1000, 389, 333, 722, 0, 444, 722,
250, 333, 500, 500, 500, 500, 220, 500, 333, 747, 300, 500, 570, 333, 747, 333,
400, 570, 300, 300, 333, 556, 540, 250, 333, 300, 330, 500, 750, 750, 750, 500,
722, 722, 722, 722, 722, 722, 1000, 722, 667, 667, 667, 667, 389, 389, 389, 389,
722, 722, 778, 778, 778, 778, 778, 570, 778, 722, 722, 722, 722, 722, 611, 556,
500, 500, 500, 500, 500, 500, 722, 444, 444, 444, 444, 444, 278, 278, 278, 278,
500, 556, 500, 500, 500, 500, 500, 570, 500, 556, 556, 556, 556, 500, 556, 500,
],
// TimesItalic
[
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
250, 333, 420, 500, 500, 833, 778, 214, 333, 333, 500, 675, 250, 333, 250, 278,
500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 333, 333, 675, 675, 675, 500,
920, 611, 611, 667, 722, 611, 611, 722, 722, 333, 444, 667, 556, 833, 667, 722,
611, 722, 611, 500, 556, 722, 611, 833, 611, 556, 556, 389, 278, 389, 422, 500,
333, 500, 500, 444, 500, 444, 278, 500, 500, 278, 278, 444, 278, 722, 500, 500,
500, 500, 389, 389, 278, 500, 444, 667, 444, 444, 389, 400, 275, 400, 541, 0,
500, 0, 333, 500, 556, 889, 500, 500, 333, 1000, 500, 333, 944, 0, 556, 0,
0, 333, 333, 556, 556, 350, 500, 889, 333, 980, 389, 333, 667, 0, 389, 556,
250, 389, 500, 500, 500, 500, 275, 500, 333, 760, 276, 500, 675, 333, 760, 333,
400, 675, 300, 300, 333, 500, 523, 250, 333, 300, 310, 500, 750, 750, 750, 500,
611, 611, 611, 611, 611, 611, 889, 667, 611, 611, 611, 611, 333, 333, 333, 333,
722, 667, 722, 722, 722, 722, 722, 675, 722, 722, 722, 722, 722, 556, 611, 500,
500, 500, 500, 500, 500, 500, 667, 444, 444, 444, 444, 444, 278, 278, 278, 278,
500, 500, 500, 500, 500, 500, 500, 675, 500, 500, 500, 500, 500, 444, 500, 444,
],
// TimesBoldItalic
[
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
250, 389, 555, 500, 500, 833, 778, 278, 333, 333, 500, 570, 250, 333, 250, 278,
500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 333, 333, 570, 570, 570, 500,
832, 667, 667, 667, 722, 667, 667, 722, 778, 389, 500, 667, 611, 889, 722, 722,
611, 722, 667, 556, 611, 722, 667, 889, 667, 611, 611, 333, 278, 333, 570, 500,
333, 500, 500, 444, 500, 444, 333, 500, 556, 278, 278, 500, 278, 778, 556, 500,
500, 500, 389, 389, 278, 556, 444, 667, 500, 444, 389, 348, 220, 348, 570, 0,
500, 0, 333, 500, 500, 1000, 500, 500, 333, 1000, 556, 333, 944, 0, 611, 0,
0, 333, 333, 500, 500, 350, 500, 1000, 333, 1000, 389, 333, 722, 0, 389, 611,
250, 389, 500, 500, 500, 500, 220, 500, 333, 747, 266, 500, 606, 333, 747, 333,
400, 570, 300, 300, 333, 576, 500, 250, 333, 300, 300, 500, 750, 750, 750, 500,
667, 667, 667, 667, 667, 667, 944, 667, 667, 667, 667, 667, 389, 389, 389, 389,
722, 722, 722, 722, 722, 722, 722, 570, 722, 722, 722, 722, 722, 611, 611, 500,
500, 500, 500, 500, 500, 500, 722, 444, 444, 444, 444, 444, 278, 278, 278, 278,
500, 556, 500, 500, 500, 500, 500, 570, 500, 556, 556, 556, 556, 444, 500, 444,
],
// Courier
[
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600,
600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600,
600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600,
600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600,
600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600,
600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 0,
600, 0, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 0, 600, 0,
0, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 0, 600, 600,
600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600,
600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600,
600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600,
600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600,
600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600,
600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600,
],
// CourierBold
[
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600,
600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600,
600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600,
600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600,
600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600,
600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 0,
600, 0, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 0, 600, 0,
0, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 0, 600, 600,
600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600,
600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600,
600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600,
600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600,
600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600,
600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600,
],
// CourierOblique
[
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600,
600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600,
600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600,
600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600,
600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600,
600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 0,
600, 0, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 0, 600, 0,
0, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 0, 600, 600,
600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600,
600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600,
600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600,
600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600,
600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600,
600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600,
],
// CourierBoldOblique
[
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600,
600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600,
600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600,
600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600,
600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600,
600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 0,
600, 0, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 0, 600, 0,
0, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 0, 600, 600,
600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600,
600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600,
600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600,
600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600,
600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600,
600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600,
],
// Symbol
[
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
250, 333, 713, 500, 549, 833, 778, 439, 333, 333, 500, 549, 250, 549, 250, 278,
500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 278, 278, 549, 549, 549, 444,
549, 722, 667, 722, 612, 611, 763, 603, 722, 333, 631, 722, 686, 889, 722, 722,
768, 741, 556, 592, 611, 690, 439, 768, 645, 795, 611, 333, 863, 333, 658, 500,
500, 631, 549, 549, 494, 439, 521, 411, 603, 329, 603, 549, 549, 576, 521, 549,
549, 521, 549, 603, 439, 576, 713, 686, 493, 686, 494, 480, 200, 480, 549, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
750, 620, 247, 549, 167, 713, 500, 753, 753, 753, 753, 1042, 987, 603, 987, 603,
400, 549, 411, 549, 549, 713, 494, 460, 549, 549, 549, 549, 1000, 603, 1000, 658,
823, 686, 795, 987, 768, 768, 823, 768, 768, 713, 713, 713, 713, 713, 713, 713,
768, 713, 790, 790, 890, 823, 549, 250, 713, 603, 603, 1042, 987, 603, 987, 603,
494, 329, 790, 790, 786, 713, 384, 384, 384, 384, 384, 384, 494, 494, 494, 494,
0, 329, 274, 686, 686, 686, 384, 384, 384, 384, 384, 384, 494, 494, 494, 0,
],
// ZapfDingbats
[
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
278, 974, 961, 974, 980, 719, 789, 790, 791, 690, 960, 939, 549, 855, 911, 933,
911, 945, 974, 755, 846, 762, 761, 571, 677, 763, 760, 759, 754, 494, 552, 537,
577, 692, 786, 788, 788, 790, 793, 794, 816, 823, 789, 841, 823, 833, 816, 831,
923, 744, 723, 749, 790, 792, 695, 776, 768, 792, 759, 707, 708, 682, 701, 826,
815, 789, 789, 707, 687, 696, 689, 786, 787, 713, 791, 785, 791, 873, 761, 762,
762, 759, 759, 892, 892, 788, 784, 438, 138, 277, 415, 392, 392, 668, 668, 0,
390, 390, 317, 317, 276, 276, 509, 509, 410, 410, 234, 234, 334, 334, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 732, 544, 544, 910, 667, 760, 760, 776, 595, 694, 626, 788, 788, 788, 788,
788, 788, 788, 788, 788, 788, 788, 788, 788, 788, 788, 788, 788, 788, 788, 788,
788, 788, 788, 788, 788, 788, 788, 788, 788, 788, 788, 788, 788, 788, 788, 788,
788, 788, 788, 788, 894, 838, 1016, 458, 748, 924, 748, 918, 927, 928, 928, 834,
873, 828, 924, 924, 917, 930, 931, 463, 883, 836, 836, 867, 867, 696, 696, 874,
0, 874, 760, 946, 771, 865, 771, 888, 967, 888, 831, 873, 927, 970, 918, 0,
],
];
-148
View File
@@ -1,148 +0,0 @@
//! Pure COS wire builders for embedded Type0 / CIDFontType0 / CIDFontType2 fonts,
//! FontDescriptors, ToUnicode CMaps, and CID-to-GID CMap streams.
//!
//! No font-file parser (`skrifa`) or application asset policy lives here; callers supply
//! pre-validated metrics, glyph mappings, and program bytes.
use std::collections::BTreeMap;
use std::fmt::Write as _;
use pdfcraft_cos::{Dict, Document, Object, PdfString, Stream};
/// One mapped character/cluster in an embedded Type0 font.
pub(crate) struct CidMapping<'a> {
pub cid: u16,
pub glyph: u16,
#[allow(dead_code)]
pub width: f64,
pub unicode: &'a str,
}
/// Scaled metrics and metadata for a PDF `/FontDescriptor` dictionary.
pub(crate) struct FontDescriptorSpec<'a> {
pub font_name: &'a str,
pub family: &'a str,
pub italic_angle: f64,
pub ascent: f64,
pub descent: f64,
pub cap_height: f64,
pub bbox: [f64; 4],
pub cff: bool,
pub program: Object,
}
/// Add an uncompressed raw COS stream to `doc` and return its indirect reference.
pub(crate) fn raw_stream(doc: &mut Document, bytes: Vec<u8>) -> Object {
Object::Ref(doc.add(Object::Stream(Stream::from_raw(Dict::new(), bytes))))
}
/// Build a compressed full font program stream (`FontFile2` or `FontFile3` for CFF/OpenType).
pub(crate) fn font_program_stream(doc: &mut Document, bytes: &[u8], cff: bool) -> Object {
let mut d = Dict::new();
d.set(b"Length1".to_vec(), Object::Int(bytes.len() as i64));
if cff {
d.set(b"Subtype".to_vec(), Object::name("OpenType"));
}
d.set(b"PCFullFont".to_vec(), Object::Bool(true));
Object::Ref(doc.add(Object::Stream(Stream::flate(d, bytes))))
}
/// Build the `/ToUnicode` CMap stream (`PCUnicode`) mapping 2-byte CIDs to UTF-16BE hex strings.
pub(crate) fn build_to_unicode_cmap(mappings: &[CidMapping<'_>]) -> String {
let mut cmap = String::from(
"/CIDInit /ProcSet findresource begin\n12 dict begin\nbegincmap\n/CMapName /PCUnicode def\n/CMapType 2 def\n1 begincodespacerange\n<0000> <FFFF>\nendcodespacerange\n",
);
for chunk in mappings.chunks(100) {
let _ = writeln!(cmap, "{} beginbfchar", chunk.len());
for m in chunk {
let hex: String = m.unicode.encode_utf16().map(|u| format!("{u:04X}")).collect();
let _ = writeln!(cmap, "<{:04X}> <{hex}>", m.cid);
}
cmap.push_str("endbfchar\n");
}
cmap.push_str("endcmap\nCMapName currentdict /CMap defineresource pop\nend\nend\n");
cmap
}
/// Build the `/Encoding` CMap stream (`PCGlyphs`) mapping 2-byte CIDs to CFF glyph IDs.
pub(crate) fn build_cid_encoding_cmap(mappings: &[CidMapping<'_>]) -> String {
let mut cid_encoding = String::from(
"/CIDInit /ProcSet findresource begin\n12 dict begin\nbegincmap\n/CMapName /PCGlyphs def\n/CMapType 1 def\n1 begincodespacerange\n<0000> <FFFF>\nendcodespacerange\n",
);
for chunk in mappings.chunks(100) {
let _ = writeln!(cid_encoding, "{} begincidchar", chunk.len());
for m in chunk {
let _ = writeln!(cid_encoding, "<{:04X}> {}", m.cid, m.glyph);
}
cid_encoding.push_str("endcidchar\n");
}
cid_encoding.push_str("endcmap\nCMapName currentdict /CMap defineresource pop\nend\nend\n");
cid_encoding
}
/// Build a PDF `/FontDescriptor` dictionary.
pub(crate) fn build_font_descriptor(spec: &FontDescriptorSpec<'_>) -> Dict {
let mut descriptor = Dict::new();
descriptor.set(b"Type".to_vec(), Object::name("FontDescriptor"));
descriptor.set(b"FontName".to_vec(), Object::name(spec.font_name));
descriptor.set(b"FontFamily".to_vec(), Object::String(PdfString::literal(spec.family.as_bytes().to_vec())));
descriptor.set(b"Flags".to_vec(), Object::Int(4));
descriptor.set(b"ItalicAngle".to_vec(), Object::Real(spec.italic_angle));
descriptor.set(b"Ascent".to_vec(), Object::Real(spec.ascent));
descriptor.set(b"Descent".to_vec(), Object::Real(spec.descent));
descriptor.set(b"CapHeight".to_vec(), Object::Real(spec.cap_height));
descriptor.set(b"StemV".to_vec(), Object::Int(80));
descriptor.set(b"FontBBox".to_vec(), Object::Array(spec.bbox.map(Object::Real).to_vec()));
descriptor.set(if spec.cff { b"FontFile3".to_vec() } else { b"FontFile2".to_vec() }, spec.program.clone());
descriptor
}
/// Build a descendant `CIDFontType0` or `CIDFontType2` dictionary.
pub(crate) fn build_cid_font_dict(
doc: &mut Document,
name: &str,
descriptor: Object,
cff: bool,
cff_widths: BTreeMap<u16, f64>,
gids: Vec<u8>,
widths: Vec<Object>,
) -> Dict {
let mut system = Dict::new();
system.set(b"Registry".to_vec(), Object::String(PdfString::literal(b"Adobe".to_vec())));
system.set(b"Ordering".to_vec(), Object::String(PdfString::literal(b"Identity".to_vec())));
system.set(b"Supplement".to_vec(), Object::Int(0));
let mut cid = Dict::new();
cid.set(b"Type".to_vec(), Object::name("Font"));
cid.set(b"Subtype".to_vec(), Object::name(if cff { "CIDFontType0" } else { "CIDFontType2" }));
cid.set(b"BaseFont".to_vec(), Object::name(name));
cid.set(b"CIDSystemInfo".to_vec(), Object::Dict(system));
cid.set(b"FontDescriptor".to_vec(), descriptor);
if cff {
cid.set(
b"W".to_vec(),
Object::Array(cff_widths.into_iter().flat_map(|(gid, w)| [Object::Int(i64::from(gid)), Object::Array(vec![Object::Real(w)])]).collect()),
);
} else {
cid.set(b"CIDToGIDMap".to_vec(), raw_stream(doc, gids));
cid.set(b"W".to_vec(), Object::Array(vec![Object::Int(1), Object::Array(widths)]));
}
cid
}
/// Build the top-level `Type0` font dictionary.
pub(crate) fn build_type0_font_dict(doc: &mut Document, name: &str, descendant: Object, cid_encoding: Option<Vec<u8>>, to_unicode: Vec<u8>) -> Dict {
let mut top = Dict::new();
top.set(b"Type".to_vec(), Object::name("Font"));
top.set(b"Subtype".to_vec(), Object::name("Type0"));
top.set(b"BaseFont".to_vec(), Object::name(name));
top.set(
b"Encoding".to_vec(),
match cid_encoding {
Some(bytes) => raw_stream(doc, bytes),
None => Object::name("Identity-H"),
},
);
top.set(b"DescendantFonts".to_vec(), Object::Array(vec![descendant]));
top.set(b"ToUnicode".to_vec(), raw_stream(doc, to_unicode));
top
}
+8 -10
View File
@@ -48,7 +48,7 @@ pub const ADOBE_DATA_ALLOWED: &[(&str, &str)] = &[("hayro-cmap", "assets/cmaps.b
/// technical data we hold ourselves rather than through a dependency. Each still needs an
/// `[[asset]]` entry with `adobe_data = true`, so its SHA-256 is checked and any change to the
/// table has to be re-attested deliberately.
pub const ADOBE_DATA_FILES: &[&str] = &["crates/fonts/src/std14_metrics.rs"];
pub const ADOBE_DATA_FILES: &[&str] = &[];
/// File extensions that count as assets wherever they appear in the repository.
const ASSET_EXTENSIONS: &[&str] = &[
@@ -594,23 +594,21 @@ mod tests {
#[test]
fn first_party_adobe_data_only_on_the_closed_list() {
let l = lock(&[]);
// The generated standard-14 table is on the list, as `kind = "data"`.
let mut ok = asset("crates/fonts/src/std14_metrics.rs", "Adobe (Core14 AFM metrics); tables by the PdfCraft contributors", "data", "MIT");
ok.adobe_data = true;
let m = Manifest { asset: vec![ok], ..Default::default() };
assert!(check(&root(), &m, &[], &l).is_empty(), "{:?}", check(&root(), &m, &[], &l));
assert!(ADOBE_DATA_FILES.is_empty());
// Any other first-party file claiming it is refused.
// Any first-party file claiming adobe_data is refused now that the closed list is empty.
let mut sneaky = asset("Cargo.toml", "Adobe", "data", "MIT");
sneaky.adobe_data = true;
let m = Manifest { asset: vec![sneaky], ..Default::default() };
assert!(check(&root(), &m, &[], &l).iter().any(|p| p.contains("closed list")));
// Even on the list, it may only be data — never a typeface.
let mut wrong_kind = asset("crates/fonts/src/std14_metrics.rs", "Adobe", "font", "MIT");
// A visual asset from Adobe is also forbidden.
let mut wrong_kind = asset("Cargo.toml", "Adobe", "font", "MIT");
wrong_kind.adobe_data = true;
let m = Manifest { asset: vec![wrong_kind], ..Default::default() };
assert!(!check(&root(), &m, &[], &l).is_empty());
let problems = check(&root(), &m, &[], &l);
assert!(problems.iter().any(|p| p.contains("forbidden")));
assert!(problems.iter().any(|p| p.contains("closed list")));
}
#[test]
+1 -1
View File
@@ -6,7 +6,7 @@ use std::process::Command;
use serde_json::Value;
const SHARED_REV: &str = "c470ed170dcb7aaaad7ce6172ca4e9b68dd1a7cd";
const SHARED_REV: &str = "a6e9a7e6c596982f3aaee1abf9a391383fb0a99e";
const PACKAGES: &[(&str, &str)] = &[
("craft-pdf", "0.1.0"),
("hayro", "0.7.1"),