forked from 1b-agent/opencadstudio-upstream
feat(text): read unifont and big-font .shx files; pair a style's big font
`shx.rs` only accepted the classic `AutoCAD-86 shapes 1.x` container, so every modern Autodesk font (`txt.shx`, `simplex.shx`, `romans.shx`, … are `unifont 1.0`) and every Asian big font (`chineset.shx`, `hztxt.shx`, `bigfont.shx` — `bigfont 1.0`) was rejected and text fell back to the LFF substitutes and TrueType fallback glyphs. Drawings authored with SHX big fonts (the norm for Chinese / Japanese / Korean sheets) never showed their real glyphs. - Parse all three containers. Unifont glyphs are keyed by Unicode; big-font glyphs by their double-byte code from a sparse hash table of (code, length, offset) entries. Big fonts reference subshapes with a two-byte `7, 0, hi, lo`. - `bigfont_glyph` encodes a character with encoding_rs (Big5 / GBK / Shift_JIS / EUC-KR, most likely first for the file name) and takes the first code the font has. - `Face::WithBig` pairs a style's big font with its primary face: full-width characters come from the big font, everything else from the primary — how a STYLE with a "Big Font" behaves in AutoCAD. `resolve_text_style` resolves `big_font_file` like the primary (next to the drawing, then the user fonts folder) and rides it along in the font name. - The missing-fonts dialog lists unresolvable big fonts too. Unit tests cover a synthetic big font (Big5 lookup, cap-height scaling, no aliasing of unknown codes), a synthetic unifont, and the pairing. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
0b522ceb86
commit
ff4981ffe6
6 files changed
+351
-35
No files matched your search
@@ -77,6 +77,27 @@ pub fn resolve_text_style(style_name: &str, document: &CadDocument) -> ResolvedT
|
||||
}
|
||||
}
|
||||
|
||||
// A style's "Big Font" (`chineset.shx`, `hztxt.shx`, …) supplies the
|
||||
// double-byte characters. Resolve it like the primary font (next to the
|
||||
// drawing, then the per-user fonts folder) and pair it with the face; an
|
||||
// unresolvable big font just leaves those characters to the fallback.
|
||||
if let Some(big) = style
|
||||
.map(|s| s.big_font_file.trim())
|
||||
.filter(|big| !big.is_empty() && big.to_ascii_lowercase().ends_with(".shx"))
|
||||
{
|
||||
let base = document
|
||||
.source_path
|
||||
.as_deref()
|
||||
.map(std::path::Path::new)
|
||||
.and_then(|p| p.parent());
|
||||
let big_path = crate::io::resolve_image_file(big, base).or_else(|| {
|
||||
crate::io::font_repo::local_font_file(big).map(|p| p.to_string_lossy().into_owned())
|
||||
});
|
||||
if let Some(big_path) = big_path {
|
||||
font_name = Face::with_big_font(&font_name, &big_path);
|
||||
}
|
||||
}
|
||||
|
||||
ResolvedTextStyle {
|
||||
font_name,
|
||||
width_factor: style.map(|s| s.width_factor as f32).unwrap_or(1.0),
|
||||
|
||||
Reference in new issue
Block a user