Render Type1 map slant and extension in PDF and SVG

This commit is contained in:
gloamxun committed 2026-11-21 10:04:48 +08:00
1 parent 28dfba5a5e
commit 3caf1eced2
7 files changed
+274 -70

No files matched your search

+15 -11
View File
@@ -1573,7 +1573,11 @@ fn write_native_type1_descriptor(
let x_height = units(metrics.x_height());
let flags =
4 | if font.is_fixed_pitch { 1 } else { 0 } | if font.italic_angle != "0" { 64 } else { 0 };
let angle = &font.italic_angle;
let angle = if font.transform.slant == 0 {
font.italic_angle.clone()
} else {
font.italic_angle.parse::<f64>().unwrap_or(0.).round().to_string()
};
let stem_v = paint.stem_v;
objects.push(format!("<< /Type /FontDescriptor /FontName /{name} /Flags {flags} /FontBBox [{left} {bottom} {right} {top}] /ItalicAngle {angle} /Ascent {ascent} /Descent {descent} /CapHeight {cap} /XHeight {x_height} /StemV {stem_v} /FontFile {program} 0 R >>").into_bytes());
objects.push(objects::stream(
@@ -1587,15 +1591,15 @@ fn write_native_type1_descriptor(
descriptor
}
fn write_native_font(
fn write_native_font<'font>(
objects: &mut Vec<Vec<u8>>,
face: &crate::native_font::NativeFont,
paint: &crate::native_font::NativeFontPaint,
paint: &'font crate::native_font::NativeFontPaint,
used: &BTreeMap<u8, char>,
compression: u8,
options: Option<crate::pdf_unicode::PdfFinalOptions<'_>>,
diagnostics: &mut Vec<String>,
descriptors: &mut HashMap<&crate::resources::ResourceVersion, NativeType1Descriptor<'_>>,
descriptors: &mut HashMap<crate::native_font::Type1ProgramKey<'font>, NativeType1Descriptor<'_>>,
) -> usize {
let font = match &paint.program {
crate::native_font::NativeFontProgram::Type1(font) => font,
@@ -1606,7 +1610,7 @@ fn write_native_font(
let id = objects.len() + 1;
objects.push(Vec::new());
let m = face.metrics();
let descriptor = match paint.type1_resource().and_then(|key| descriptors.get_mut(key)) {
let descriptor = match paint.type1_program_key().and_then(|key| descriptors.get_mut(&key)) {
Some(shared) => *shared.object.get_or_insert_with(|| {
write_native_type1_descriptor(objects, font, paint, shared.metrics, compression)
}),
@@ -1992,9 +1996,9 @@ fn write_pdf(
let entry = native_used.entry(font.id).or_insert_with(|| {
// pdfTeX registers one font object per scalable TFM name
// when used and writes those objects in reverse order.
// The last newly used TFM for a PFB supplies its shared
// The last newly used TFM for an embedded variant supplies its shared
// descriptor, while each font keeps its own encoding.
if let Some(program) = paint.type1_resource() {
if let Some(program) = paint.type1_program_key() {
if type1_names.insert((program, font.name.as_str())) {
type1_descriptors.insert(
program,
@@ -2023,14 +2027,14 @@ fn write_pdf(
}
}
let mut native_font_ids = BTreeMap::new();
for (id, (face, paint, used)) in native_used {
for (&id, (face, paint, used)) in &native_used {
native_font_ids.insert(
id,
write_native_font(
&mut objects,
&face,
&paint,
&used,
face,
paint,
used,
final_compression.unwrap_or(0).max(0).min(9) as u8,
unicode,
diagnostics,