build: reach lopdf and encoding_rs through printpdf and the codec

#1418 added both as direct dependencies although each was already in the
tree: printpdf's to_lopdf_doc returns the lopdf document whose compress
and save_to are plain methods, and the codec's encoding_from_code_page
hands back the Big5 / GBK / Shift_JIS / EUC-KR encodings by their DXF
code-page names. Cargo.toml keeps its dependency list.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
Hakan SevenandClaude Fable 5.1 committed 2026-09-21 22:55:04 +03:00
1 parent 697ea4984b
commit baba5bccd3
3 files changed
+12 -17

No files matched your search

Generated
-2
View File
@@ -18,7 +18,6 @@ dependencies = [
"console_error_panic_hook",
"cosmic-text 0.15.0",
"dwg-thumbnailer",
"encoding_rs",
"env_logger",
"flate2",
"fluent-syntax",
@@ -38,7 +37,6 @@ dependencies = [
"js-sys",
"libloading",
"log",
"lopdf",
"lyon_tessellation",
"meshopt",
"naga 27.0.3",
-5
View File
@@ -55,9 +55,6 @@ ttf-parser = "0.25"
cosmic-text = "0.15"
unicode-bidi = "0.3"
lyon_tessellation = "1.0.20"
# Big-font (.shx) lookups: encode a char to the font's Big5 / GBK / Shift_JIS
# / EUC-KR double-byte code. Already in the tree through other deps.
encoding_rs = "0.8"
pollster = "0.4"
[dev-dependencies]
@@ -93,8 +90,6 @@ i18n-embed = { version = "0.16", features = ["desktop-requester"] }
rayon = "1"
open = "5"
printpdf = { version = "0.9.1", default-features = false, features = ["images"] }
# The lopdf printpdf builds on: used to Flate-compress the exported PDF streams.
lopdf = { version = "0.39.0", default-features = false, features = ["time"] }
ureq = { version = "3", default-features = false, features = ["rustls", "platform-verifier", "win-system-proxy"] }
[target.'cfg(target_arch = "wasm32")'.dependencies]
+12 -10
View File
@@ -203,25 +203,24 @@ pub fn is_bigfont(path: &str) -> bool {
load_file(path).is_some_and(|f| f.kind == ShxKind::Bigfont)
}
/// The double-byte legacy encodings a big font may be keyed by, most likely
/// first for this file name. The font itself does not say; try them in turn
/// and take the first code the font actually has.
fn bigfont_encodings(path: &str) -> [&'static encoding_rs::Encoding; 4] {
use encoding_rs::{BIG5, EUC_KR, GBK, SHIFT_JIS};
/// The code pages a big font's double-byte codes may be in, most likely
/// first, guessed from the file name. The codec maps a name to its encoding
/// (`ansi_950` Big5, `ansi_936` GBK, `ansi_932` Shift_JIS, `ansi_949` EUC-KR).
fn bigfont_code_pages(path: &str) -> [&'static str; 4] {
let name = path
.rsplit(['/', '\\'])
.next()
.unwrap_or(path)
.to_ascii_lowercase();
if name.contains("gb") || name.contains("hz") || name.contains("china") {
[GBK, BIG5, SHIFT_JIS, EUC_KR]
["ansi_936", "ansi_950", "ansi_932", "ansi_949"]
} else if name.contains("bigfont") || name.contains("extfont") || name.contains("jp") {
[SHIFT_JIS, BIG5, GBK, EUC_KR]
["ansi_932", "ansi_950", "ansi_936", "ansi_949"]
} else if name.contains("whg") || name.contains("kor") || name.contains("han") {
[EUC_KR, BIG5, GBK, SHIFT_JIS]
["ansi_949", "ansi_950", "ansi_936", "ansi_932"]
} else {
// `chineset.shx` and most Taiwanese fonts.
[BIG5, GBK, SHIFT_JIS, EUC_KR]
["ansi_950", "ansi_936", "ansi_932", "ansi_949"]
}
}
@@ -235,7 +234,10 @@ pub fn bigfont_glyph(path: &str, ch: char) -> Option<Arc<crate::scene::text::lff
}
let mut buf = [0u8; 4];
let s = ch.encode_utf8(&mut buf);
for enc in bigfont_encodings(path) {
for page in bigfont_code_pages(path) {
let Some(enc) = acadrust::io::dxf::code_page::encoding_from_code_page(page) else {
continue;
};
let (bytes, _, unmappable) = enc.encode(s);
if unmappable || bytes.len() != 2 {
continue;