Share physical Type 1 fonts across PDF page resources

This commit is contained in:
gloamxun committed 2026-11-26 16:28:26 +08:00
1 parent 5edd4ae4ec
commit 38c567623a
11 files changed
+385 -140

No files matched your search

+24
View File
@@ -25,6 +25,10 @@ pub struct NativeFontPaint {
pub glyph_paths: BTreeMap<u8, String>,
pub bbox: [i32; 4],
pub stem_v: i32,
#[serde(default, skip_serializing_if = "std::ops::Not::not")]
pub(crate) subset: bool,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub(crate) descriptor_flags: Option<i32>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub(crate) xdv_descriptor: Option<XdvDescriptor>,
pub resources: Vec<crate::resources::ResourceVersion>,
@@ -34,6 +38,20 @@ pub struct NativeFontPaint {
pub(crate) type Type1ProgramKey<'a> = (&'a ResourceVersion, Type1Transform);
#[derive(Clone, Debug, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize)]
pub(crate) struct MappedType1 {
pub version: ResourceVersion,
pub font: Arc<Type1Font>,
pub flags: i32,
pub subset: bool,
}
impl MappedType1 {
pub(crate) fn key(&self) -> Type1ProgramKey<'_> {
(&self.version, self.font.transform)
}
}
impl NativeFontPaint {
pub(crate) fn has_pdf_space(&self, font: &NativeFont) -> bool {
// pdfTeX requires the space name in an actual map re-encoding.
@@ -440,6 +458,8 @@ fn resolve_physical_fonts(
glyph_paths,
bbox: bbox.unwrap(),
stem_v: 0,
subset: false,
descriptor_flags: None,
xdv_descriptor: None,
resources: entry.as_ref().and_then(|entry| entry.version.as_ref())
.or(default_version).cloned().into_iter()
@@ -457,6 +477,8 @@ fn resolve_physical_fonts(
file.to_owned(),
outline.encoding.clone(),
outline.transform,
outline.subset,
outline.descriptor_flags,
);
if !cache.contains_key(&key) {
let from = outline.from.to_string_lossy();
@@ -490,6 +512,8 @@ fn resolve_physical_fonts(
glyph_paths: BTreeMap::new(),
bbox: decoded.bbox,
stem_v: decoded.stem_v,
subset: outline.subset && !xdv,
descriptor_flags: outline.descriptor_flags,
xdv_descriptor: if xdv {
Some(decoded.xdv_descriptor.get_or_init(|| {
decoded.outlines.xdv_descriptor(program.bbox)