Embed hinted Type 1C subsets for XeTeX PDF output

This commit is contained in:
gloamxun committed 2026-11-28 11:07:18 +08:00
1 parent 4ae4275cf3
commit 01c6f1d4bd
9 files changed
+629 -26

No files matched your search

+22 -1
View File
@@ -1881,7 +1881,17 @@ fn write_native_font(
})
.collect::<Result<Vec<_>, String>>()?
.join(" ");
let xdv_type1 = paint.xdv_descriptor.is_some() && matches!(paint.program, NativeFontProgram::Type1(_));
let (subtype, descriptor, name, widths, encoding, has_glyph_unicode) = match &paint.program {
NativeFontProgram::Type1(font) if xdv_type1 => {
let slots = used.keys().map(|&slot| (slot, paint.encoding[usize::from(slot)].as_str())).collect();
let (descriptor, name) = type1_fonts::write_xdv(
objects, font, &native_type1_parameters(font, paint, m), &slots, compression,
subset_tags, options.is_some_and(|options| options.omit_charset),
).map_err(|error| format!("cannot embed XeTeX Type1 font {}: {error}", face.name))?;
let encoding = mapped_encoding.map_or_else(String::new, |id| format!(" /Encoding {id} 0 R"));
("Type1", descriptor, name, format!("[{widths}]"), encoding, true)
}
NativeFontProgram::Type1(font) => {
let descriptor = reference.map_or_else(
|| type1_fonts::write_full(objects, font, &native_type1_parameters(font, paint, m), compression),
@@ -1953,6 +1963,14 @@ fn write_native_font(
let unicode = objects.len() + 1;
let cmap = if !has_glyph_unicode {
None
} else if xdv_type1 {
let names = options.and_then(|options| options.xdv_glyph_names);
// The XDV driver only writes a simple-font cmap when every used
// slot can be recovered from the job's glyph lists or name syntax.
used.keys().map(|&slot| {
opentype_unicode::glyph_text(&paint.encoding[usize::from(slot)], names)
.map(|text| (slot, text))
}).collect::<Option<BTreeMap<_, _>>>().map(|texts| type1_tounicode_texts(&texts))
} else if let Some(options) = options {
if options.fonts.pdf_settings(face.id).is_some_and(|settings| settings.omit_builtin_unicode) {
None
@@ -2500,6 +2518,9 @@ fn write_pdf(
let crate::native_font::NativeFontProgram::Type1(program) = &paint.program else {
continue;
};
if paint.xdv_descriptor.is_some() {
continue;
}
let Some(key) = paint.type1_program_key() else {
continue;
};
@@ -2530,7 +2551,7 @@ fn write_pdf(
let encoding = if matches!(
paint.program,
crate::native_font::NativeFontProgram::OpenTypeCff(_) | crate::native_font::NativeFontProgram::DeviceType1(_)
) {
) || paint.xdv_descriptor.is_some() {
mapped_encodings.mark(&mut objects, paint, used.keys().copied())
} else {
None