Support unembedded pdfTeX Type 1 device fonts in export and preview
This commit is contained in:
1 parent
60d67bbb7b
commit
c0970bdbf6
10 files changed
+465
-33
No files matched your search
@@ -13,11 +13,13 @@ use std::{
|
|||||||
sync::{Arc, Mutex, OnceLock},
|
sync::{Arc, Mutex, OnceLock},
|
||||||
};
|
};
|
||||||
mod cff;
|
mod cff;
|
||||||
|
mod device_type1;
|
||||||
mod map;
|
mod map;
|
||||||
mod sfd;
|
mod sfd;
|
||||||
mod truetype;
|
mod truetype;
|
||||||
mod virtual_paint;
|
mod virtual_paint;
|
||||||
pub use cff::OpenTypeCffProgram;
|
pub use cff::OpenTypeCffProgram;
|
||||||
|
pub use device_type1::DeviceType1Program;
|
||||||
pub use truetype::TrueTypeProgram;
|
pub use truetype::TrueTypeProgram;
|
||||||
pub use map::PdfFontBindings;
|
pub use map::PdfFontBindings;
|
||||||
use map::{dedicated_space_map, find_map_entry, load_map, selected_outline};
|
use map::{dedicated_space_map, find_map_entry, load_map, selected_outline};
|
||||||
@@ -67,12 +69,15 @@ impl MappedType1 {
|
|||||||
impl NativeFontPaint {
|
impl NativeFontPaint {
|
||||||
pub(crate) fn has_pdf_space(&self, font: &NativeFont) -> bool {
|
pub(crate) fn has_pdf_space(&self, font: &NativeFont) -> bool {
|
||||||
// pdfTeX requires the space name in an actual map re-encoding.
|
// pdfTeX requires the space name in an actual map re-encoding.
|
||||||
matches!(self.program, NativeFontProgram::Type1(_))
|
self.encoding_version().is_some()
|
||||||
&& self.resources.len() == self.program_index.unwrap_or(1) + 2
|
&& matches!(self.program, NativeFontProgram::Type1(_) | NativeFontProgram::DeviceType1(_))
|
||||||
&& self.encoding[32] == "space"
|
&& self.encoding[32] == "space"
|
||||||
&& font.metrics().width(' ') > 65_782
|
&& font.metrics().width(' ') > 65_782
|
||||||
}
|
}
|
||||||
pub(crate) fn encoding_version(&self) -> Option<&ResourceVersion> {
|
pub(crate) fn encoding_version(&self) -> Option<&ResourceVersion> {
|
||||||
|
if let NativeFontProgram::DeviceType1(program) = &self.program {
|
||||||
|
return if program.reencoded { self.resources.last() } else { None };
|
||||||
|
}
|
||||||
self.resources.get(self.program_index? + 1)
|
self.resources.get(self.program_index? + 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -80,7 +85,8 @@ impl NativeFontPaint {
|
|||||||
match &self.program {
|
match &self.program {
|
||||||
NativeFontProgram::Type1(font) => self.resources.get(self.program_index.unwrap_or(1))
|
NativeFontProgram::Type1(font) => self.resources.get(self.program_index.unwrap_or(1))
|
||||||
.map(|version| (version, font.transform)),
|
.map(|version| (version, font.transform)),
|
||||||
NativeFontProgram::Pk(_) | NativeFontProgram::TrueType(_) | NativeFontProgram::OpenTypeCff(_) => None,
|
NativeFontProgram::Pk(_) | NativeFontProgram::TrueType(_)
|
||||||
|
| NativeFontProgram::OpenTypeCff(_) | NativeFontProgram::DeviceType1(_) => None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -91,6 +97,7 @@ pub enum NativeFontProgram {
|
|||||||
Pk(crate::pk_font::PkFontProgram),
|
Pk(crate::pk_font::PkFontProgram),
|
||||||
TrueType(TrueTypeProgram),
|
TrueType(TrueTypeProgram),
|
||||||
OpenTypeCff(OpenTypeCffProgram),
|
OpenTypeCff(OpenTypeCffProgram),
|
||||||
|
DeviceType1(DeviceType1Program),
|
||||||
}
|
}
|
||||||
impl NativeFontProgram {
|
impl NativeFontProgram {
|
||||||
pub fn name(&self) -> &str {
|
pub fn name(&self) -> &str {
|
||||||
@@ -99,6 +106,7 @@ impl NativeFontProgram {
|
|||||||
Self::Pk(p) => &p.name,
|
Self::Pk(p) => &p.name,
|
||||||
Self::TrueType(p) => &p.name,
|
Self::TrueType(p) => &p.name,
|
||||||
Self::OpenTypeCff(p) => &p.name,
|
Self::OpenTypeCff(p) => &p.name,
|
||||||
|
Self::DeviceType1(p) => &p.name,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -266,7 +274,7 @@ pub struct NativeFontCache {
|
|||||||
}
|
}
|
||||||
|
|
||||||
struct DecodedType1 {
|
struct DecodedType1 {
|
||||||
program: Type1Font,
|
program: Arc<Type1Font>,
|
||||||
outlines: Type1Outlines,
|
outlines: Type1Outlines,
|
||||||
bbox: [i32; 4],
|
bbox: [i32; 4],
|
||||||
stem_v: i32,
|
stem_v: i32,
|
||||||
@@ -286,7 +294,7 @@ impl DecodedType1 {
|
|||||||
(program.bbox, outlines.raw_stem_v())
|
(program.bbox, outlines.raw_stem_v())
|
||||||
};
|
};
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
program,
|
program: Arc::new(program),
|
||||||
outlines,
|
outlines,
|
||||||
bbox,
|
bbox,
|
||||||
stem_v,
|
stem_v,
|
||||||
@@ -517,6 +525,11 @@ fn resolve_physical_fonts(
|
|||||||
);
|
);
|
||||||
continue;
|
continue;
|
||||||
};
|
};
|
||||||
|
if !xdv && let Some(name) = outline.device_type1_name() {
|
||||||
|
let paint = device_type1::resolve(files, font_cache, outline, name, &font, slots)?;
|
||||||
|
direct_resolved.insert(id, Arc::new(paint));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
if let Some(file) = outline.true_type_file() {
|
if let Some(file) = outline.true_type_file() {
|
||||||
let paint = truetype::resolve(files, &mut outlines, outline, file, &font, slots)?;
|
let paint = truetype::resolve(files, &mut outlines, outline, file, &font, slots)?;
|
||||||
direct_resolved.insert(id, Arc::new(paint));
|
direct_resolved.insert(id, Arc::new(paint));
|
||||||
@@ -565,7 +578,7 @@ fn resolve_physical_fonts(
|
|||||||
key.clone(),
|
key.clone(),
|
||||||
(
|
(
|
||||||
NativeFontPaint {
|
NativeFontPaint {
|
||||||
program: NativeFontProgram::Type1(program.clone()),
|
program: NativeFontProgram::Type1(program.as_ref().clone()),
|
||||||
encoding,
|
encoding,
|
||||||
glyph_paths: BTreeMap::new(),
|
glyph_paths: BTreeMap::new(),
|
||||||
bbox: decoded.bbox,
|
bbox: decoded.bbox,
|
||||||
@@ -625,6 +638,7 @@ fn resolve_physical_fonts(
|
|||||||
let p = resolved[&font.id].clone();
|
let p = resolved[&font.id].clone();
|
||||||
*character = match &p.program {
|
*character = match &p.program {
|
||||||
NativeFontProgram::Type1(_)
|
NativeFontProgram::Type1(_)
|
||||||
|
| NativeFontProgram::DeviceType1(_)
|
||||||
| NativeFontProgram::TrueType(_)
|
| NativeFontProgram::TrueType(_)
|
||||||
| NativeFontProgram::OpenTypeCff(_) => {
|
| NativeFontProgram::OpenTypeCff(_) => {
|
||||||
crate::type1::glyph_unicode_text(&p.encoding[*slot as usize])
|
crate::type1::glyph_unicode_text(&p.encoding[*slot as usize])
|
||||||
|
|||||||
@@ -0,0 +1,128 @@
|
|||||||
|
//! Unembedded pdfTeX Type 1 fonts retain a device name and optional local outlines.
|
||||||
|
use super::{
|
||||||
|
NativeFont, NativeFontCache, NativeFontPaint, NativeFontProgram, actual_resource,
|
||||||
|
encoding_vector, map::MapEntry, verify_resource,
|
||||||
|
};
|
||||||
|
use crate::{
|
||||||
|
execution::SourceProvider,
|
||||||
|
resources::ResourceKind,
|
||||||
|
type1::{Type1Font, Type1Transform, standard_encoding},
|
||||||
|
};
|
||||||
|
use std::{
|
||||||
|
collections::{BTreeMap, BTreeSet},
|
||||||
|
sync::Arc,
|
||||||
|
};
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize)]
|
||||||
|
pub struct DeviceType1Program {
|
||||||
|
pub name: String,
|
||||||
|
pub(crate) reencoded: bool,
|
||||||
|
/// This program is used by previews. The device font stays unembedded.
|
||||||
|
pub preview_program: Option<Arc<Type1Font>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl DeviceType1Program {
|
||||||
|
pub(crate) fn standard_flags(&self) -> Option<i32> {
|
||||||
|
standard_flags(&self.name)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn standard_flags(name: &str) -> Option<i32> {
|
||||||
|
Some(match name {
|
||||||
|
"Courier" => 35,
|
||||||
|
"Courier-Bold" => 35 | (1 << 18),
|
||||||
|
"Courier-Oblique" => 35 | 64,
|
||||||
|
"Courier-BoldOblique" => 35 | 64 | (1 << 18),
|
||||||
|
"Helvetica" => 32,
|
||||||
|
"Helvetica-Bold" => 32 | (1 << 18),
|
||||||
|
"Helvetica-Oblique" => 32 | 64,
|
||||||
|
"Helvetica-BoldOblique" => 32 | 64 | (1 << 18),
|
||||||
|
"Times-Roman" => 34,
|
||||||
|
"Times-Bold" => 34 | (1 << 18),
|
||||||
|
"Times-Italic" => 34 | 64,
|
||||||
|
"Times-BoldItalic" => 34 | 64 | (1 << 18),
|
||||||
|
"Symbol" | "ZapfDingbats" => 4,
|
||||||
|
_ => return None,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(super) fn resolve(
|
||||||
|
files: &mut impl SourceProvider,
|
||||||
|
cache: &NativeFontCache,
|
||||||
|
entry: &MapEntry,
|
||||||
|
name: &str,
|
||||||
|
font: &NativeFont,
|
||||||
|
slots: BTreeSet<u8>,
|
||||||
|
) -> Result<NativeFontPaint, String> {
|
||||||
|
let from = entry.from.to_string_lossy();
|
||||||
|
let mut resources: Vec<_> = entry.version.iter().cloned().collect();
|
||||||
|
let mut preview = None;
|
||||||
|
let candidates = [name, font.name.as_str()];
|
||||||
|
for (index, candidate) in candidates.into_iter().enumerate() {
|
||||||
|
if index == 1 && candidate == name {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
for extension in ["pfb", "pfa"] {
|
||||||
|
let file = format!("{candidate}.{extension}");
|
||||||
|
let Some(resource) = files.optional_font_file(ResourceKind::Type1, &file, &from)?
|
||||||
|
else {
|
||||||
|
continue;
|
||||||
|
};
|
||||||
|
let resource = verify_resource(resource, ResourceKind::Type1, &file)?;
|
||||||
|
if let Ok(decoded) = cache.type1(&resource, Type1Transform::default())
|
||||||
|
&& decoded.program.name == name
|
||||||
|
{
|
||||||
|
resources.push(resource.version);
|
||||||
|
preview = Some(decoded);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if preview.is_some() {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
let encoding = if let Some(file) = &entry.encoding {
|
||||||
|
let encoding = actual_resource(files, ResourceKind::Encoding, file, &from)?;
|
||||||
|
let vector = encoding_vector(&encoding.data)?;
|
||||||
|
resources.push(encoding.version);
|
||||||
|
vector
|
||||||
|
} else {
|
||||||
|
let standard_latin = standard_flags(name).is_some_and(|flags| flags & 32 != 0);
|
||||||
|
(0..=255u8)
|
||||||
|
.map(|slot| {
|
||||||
|
match &preview {
|
||||||
|
Some(font) => font.program.name_for_code(slot),
|
||||||
|
None if standard_latin => standard_encoding(slot),
|
||||||
|
None => None,
|
||||||
|
}
|
||||||
|
.unwrap_or(".notdef")
|
||||||
|
.to_owned()
|
||||||
|
})
|
||||||
|
.collect()
|
||||||
|
};
|
||||||
|
let mut glyph_paths = BTreeMap::new();
|
||||||
|
if let Some(preview) = &preview {
|
||||||
|
for slot in slots {
|
||||||
|
let glyph = &encoding[usize::from(slot)];
|
||||||
|
if preview.outlines.has_glyph(glyph) {
|
||||||
|
glyph_paths.insert(slot, preview.outlines.glyph_path(glyph)?);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Ok(NativeFontPaint {
|
||||||
|
program: NativeFontProgram::DeviceType1(DeviceType1Program {
|
||||||
|
name: name.to_owned(),
|
||||||
|
reencoded: entry.encoding.is_some(),
|
||||||
|
preview_program: preview.map(|font| font.program.clone()),
|
||||||
|
}),
|
||||||
|
encoding,
|
||||||
|
glyph_paths,
|
||||||
|
bbox: [0; 4],
|
||||||
|
stem_v: 0,
|
||||||
|
subset: false,
|
||||||
|
descriptor_flags: entry.descriptor_flags,
|
||||||
|
xdv_descriptor: None,
|
||||||
|
resources,
|
||||||
|
program_index: None,
|
||||||
|
})
|
||||||
|
}
|
||||||
@@ -66,6 +66,10 @@ impl MapEntry {
|
|||||||
self.file.is_some() || self.postscript_name
|
self.file.is_some() || self.postscript_name
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub(super) fn device_type1_name(&self) -> Option<&str> {
|
||||||
|
self.ps_name.as_deref().filter(|_| self.file.is_none())
|
||||||
|
}
|
||||||
|
|
||||||
pub(super) fn true_type_file(&self) -> Option<&str> {
|
pub(super) fn true_type_file(&self) -> Option<&str> {
|
||||||
self.outline_file(&["ttf", "ttc"])
|
self.outline_file(&["ttf", "ttc"])
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1528,7 +1528,8 @@ fn native_pdf(
|
|||||||
if paint.encoding.len() != 256
|
if paint.encoding.len() != 256
|
||||||
|| (matches!(paint.program, crate::native_font::NativeFontProgram::Type1(_))
|
|| (matches!(paint.program, crate::native_font::NativeFontProgram::Type1(_))
|
||||||
&& paint.encoding[usize::from(*slot)] == ".notdef")
|
&& paint.encoding[usize::from(*slot)] == ".notdef")
|
||||||
|| !paint.glyph_paths.contains_key(slot)
|
|| (!matches!(paint.program, crate::native_font::NativeFontProgram::DeviceType1(_))
|
||||||
|
&& !paint.glyph_paths.contains_key(slot))
|
||||||
|| !font.has_slot(*slot)
|
|| !font.has_slot(*slot)
|
||||||
{
|
{
|
||||||
return Err(format!("native font {} has no output encoding for slot {slot}",font.name));
|
return Err(format!("native font {} has no output encoding for slot {slot}",font.name));
|
||||||
@@ -1758,6 +1759,31 @@ fn native_type1_parameters(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn write_device_type1_descriptor(
|
||||||
|
objects: &mut Vec<Vec<u8>>,
|
||||||
|
metrics: &crate::tfm::TfmMetrics,
|
||||||
|
name: &str,
|
||||||
|
flags: i32,
|
||||||
|
parameters: Option<&[i32]>,
|
||||||
|
) -> usize {
|
||||||
|
let units = |value: i64| native_font_units(value, native_pdf_font_size(metrics.size_sp()), 1000);
|
||||||
|
let ascent = units(metrics.height('h'));
|
||||||
|
let descent = (-units(metrics.depth('y'))).min(0);
|
||||||
|
let cap = units(metrics.height('H'));
|
||||||
|
let param = |index| parameters.and_then(|p| p.get(index)).copied()
|
||||||
|
.map_or_else(|| metrics.param(index), i64::from);
|
||||||
|
let quad = units(param(5));
|
||||||
|
let top = ascent.max(cap);
|
||||||
|
let angle_sp = -(param(0) as f64 / 65_536.).atan().to_degrees() as i64;
|
||||||
|
let angle = units(angle_sp);
|
||||||
|
let stem = units(metrics.width('.') / 3);
|
||||||
|
let x_height = units(param(4));
|
||||||
|
objects.push(format!(
|
||||||
|
"<< /Type /FontDescriptor /FontName /{name} /Flags {flags} /FontBBox [0 {descent} {quad} {top}] /Ascent {ascent} /CapHeight {cap} /Descent {descent} /ItalicAngle {angle} /StemV {stem} /XHeight {x_height} >>"
|
||||||
|
).into_bytes());
|
||||||
|
objects.len()
|
||||||
|
}
|
||||||
|
|
||||||
fn write_sfnt_descriptor(
|
fn write_sfnt_descriptor(
|
||||||
objects: &mut Vec<Vec<u8>>,
|
objects: &mut Vec<Vec<u8>>,
|
||||||
metrics: &crate::tfm::TfmMetrics,
|
metrics: &crate::tfm::TfmMetrics,
|
||||||
@@ -1809,7 +1835,7 @@ fn write_native_font(
|
|||||||
reference: Option<&type1_fonts::Reference>,
|
reference: Option<&type1_fonts::Reference>,
|
||||||
target: Option<usize>,
|
target: Option<usize>,
|
||||||
subset_tags: &mut BTreeSet<String>,
|
subset_tags: &mut BTreeSet<String>,
|
||||||
cff_encoding: Option<usize>,
|
mapped_encoding: Option<usize>,
|
||||||
) -> Result<usize, String> {
|
) -> Result<usize, String> {
|
||||||
use crate::native_font::NativeFontProgram;
|
use crate::native_font::NativeFontProgram;
|
||||||
if let NativeFontProgram::Pk(pk) = &paint.program {
|
if let NativeFontProgram::Pk(pk) = &paint.program {
|
||||||
@@ -1870,8 +1896,38 @@ fn write_native_font(
|
|||||||
let width_object = objects.len() + 1;
|
let width_object = objects.len() + 1;
|
||||||
objects.push(format!("[{widths}]").into_bytes());
|
objects.push(format!("[{widths}]").into_bytes());
|
||||||
let (descriptor, name) = cff_fonts::write(objects, m, paint, program, compression)?;
|
let (descriptor, name) = cff_fonts::write(objects, m, paint, program, compression)?;
|
||||||
let encoding = cff_encoding.map_or_else(String::new, |id| format!(" /Encoding {id} 0 R"));
|
let encoding = mapped_encoding.map_or_else(String::new, |id| format!(" /Encoding {id} 0 R"));
|
||||||
("Type1", descriptor, name, format!("{width_object} 0 R"), encoding, cff_encoding.is_some())
|
("Type1", descriptor, name, format!("{width_object} 0 R"), encoding, mapped_encoding.is_some())
|
||||||
|
}
|
||||||
|
NativeFontProgram::DeviceType1(program) => {
|
||||||
|
let name = native_pdf_name(&program.name);
|
||||||
|
let standard_flags = program.standard_flags();
|
||||||
|
let flags = paint.descriptor_flags.or(standard_flags).unwrap_or(34);
|
||||||
|
if paint.descriptor_flags.is_none() {
|
||||||
|
diagnostics.push(format!(
|
||||||
|
"No flags specified for non-embedded font '{}' ({}) (I'm using {flags}): fix your map entry.",
|
||||||
|
program.name, face.name
|
||||||
|
));
|
||||||
|
}
|
||||||
|
if standard_flags.is_none() {
|
||||||
|
diagnostics.push(format!(
|
||||||
|
"font '{}' is not a standard font; I suppose it is available to your PDF viewer then",
|
||||||
|
program.name
|
||||||
|
));
|
||||||
|
}
|
||||||
|
let width_object = objects.len() + 1;
|
||||||
|
objects.push(format!("[{widths}]").into_bytes());
|
||||||
|
let parameters = options.and_then(|options| options.fonts.font(face.id).ok())
|
||||||
|
.map(|font| font.parameters());
|
||||||
|
let descriptor = write_device_type1_descriptor(objects, m, &name, flags, parameters);
|
||||||
|
let encoding = mapped_encoding.map_or_else(String::new, |id| format!(" /Encoding {id} 0 R"));
|
||||||
|
if mapped_encoding.is_none() && options.is_some_and(|options|
|
||||||
|
options.generate_unicode > 0
|
||||||
|
&& !options.fonts.pdf_settings(face.id).is_some_and(|settings| settings.omit_builtin_unicode))
|
||||||
|
{
|
||||||
|
return Err("builtin glyph names is empty".into());
|
||||||
|
}
|
||||||
|
("Type1", descriptor, name, format!("{width_object} 0 R"), encoding, mapped_encoding.is_some())
|
||||||
}
|
}
|
||||||
NativeFontProgram::Pk(_) => unreachable!(),
|
NativeFontProgram::Pk(_) => unreachable!(),
|
||||||
};
|
};
|
||||||
@@ -2448,12 +2504,15 @@ fn write_pdf(
|
|||||||
.filter_map(|font| font.name.split_once('+').map(|(tag, _)| tag.to_owned()))
|
.filter_map(|font| font.name.split_once('+').map(|(tag, _)| tag.to_owned()))
|
||||||
.collect();
|
.collect();
|
||||||
let mut native_font_ids = BTreeMap::new();
|
let mut native_font_ids = BTreeMap::new();
|
||||||
let mut cff_encodings = cff_fonts::Encodings::default();
|
let mut mapped_encodings = cff_fonts::Encodings::default();
|
||||||
for (&id, (face, paint, used)) in &native_used {
|
for (&id, (face, paint, used)) in &native_used {
|
||||||
let target = registry.and_then(|objects| objects.font_number(id))
|
let target = registry.and_then(|objects| objects.font_number(id))
|
||||||
.map(|number| device_objects[&number] as usize);
|
.map(|number| device_objects[&number] as usize);
|
||||||
let encoding = if matches!(paint.program, crate::native_font::NativeFontProgram::OpenTypeCff(_)) {
|
let encoding = if matches!(
|
||||||
cff_encodings.mark(&mut objects, paint, used.keys().copied())
|
paint.program,
|
||||||
|
crate::native_font::NativeFontProgram::OpenTypeCff(_) | crate::native_font::NativeFontProgram::DeviceType1(_)
|
||||||
|
) {
|
||||||
|
mapped_encodings.mark(&mut objects, paint, used.keys().copied())
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
};
|
};
|
||||||
@@ -2474,7 +2533,7 @@ fn write_pdf(
|
|||||||
)?,
|
)?,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
cff_encodings.write(&mut objects);
|
mapped_encodings.write(&mut objects);
|
||||||
for (font, owner) in aliases {
|
for (font, owner) in aliases {
|
||||||
let id = native_font_ids[&owner];
|
let id = native_font_ids[&owner];
|
||||||
native_font_ids.insert(font, id);
|
native_font_ids.insert(font, id);
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ struct Encoding<'a> {
|
|||||||
names: BTreeMap<u8, &'a str>,
|
names: BTreeMap<u8, &'a str>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A single encoding read is shared by all mapped CFF fonts that use it.
|
/// Fonts using the same encoding resource share its PDF encoding dictionary.
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
pub(super) struct Encodings<'a>(HashMap<&'a ResourceVersion, Encoding<'a>>);
|
pub(super) struct Encodings<'a>(HashMap<&'a ResourceVersion, Encoding<'a>>);
|
||||||
|
|
||||||
|
|||||||
@@ -193,11 +193,12 @@ impl DisplayItem {
|
|||||||
.glyph_paths
|
.glyph_paths
|
||||||
.get(slot)
|
.get(slot)
|
||||||
.filter(|_| paint.encoding.len() == 256)
|
.filter(|_| paint.encoding.len() == 256)
|
||||||
.ok_or_else(|| {
|
.ok_or_else(|| match &paint.program {
|
||||||
format!(
|
crate::native_font::NativeFontProgram::DeviceType1(program) => format!(
|
||||||
"native SVG outline is not resolved for {} slot {slot}",
|
"native preview needs the actual device font {} with glyph {}",
|
||||||
font.name
|
program.name, paint.encoding.get(usize::from(*slot)).map_or(".notdef", String::as_str)
|
||||||
)
|
),
|
||||||
|
_ => format!("native SVG outline is not resolved for {} slot {slot}", font.name),
|
||||||
})?;
|
})?;
|
||||||
Ok(NativeSvgGlyph {
|
Ok(NativeSvgGlyph {
|
||||||
position: [*x, *y],
|
position: [*x, *y],
|
||||||
|
|||||||
@@ -819,6 +819,37 @@ letterspace-fresh.log 和 device-pdftex-spaced-moved.log。
|
|||||||
[原版字距虚拟字体构造](https://github.com/TeX-Live/texlive-source/blob/fb6158926661cb7a7246b3a94a0cb170a9624d5a/texk/web2c/pdftexdir/pdftex.web#L16400-L16492)
|
[原版字距虚拟字体构造](https://github.com/TeX-Live/texlive-source/blob/fb6158926661cb7a7246b3a94a0cb170a9624d5a/texk/web2c/pdftexdir/pdftex.web#L16400-L16492)
|
||||||
[原版格式所写字体字段](https://github.com/TeX-Live/texlive-source/blob/fb6158926661cb7a7246b3a94a0cb170a9624d5a/texk/web2c/pdftexdir/pdftex.web#L30627-L30696)
|
[原版格式所写字体字段](https://github.com/TeX-Live/texlive-source/blob/fb6158926661cb7a7246b3a94a0cb170a9624d5a/texk/web2c/pdftexdir/pdftex.web#L30627-L30696)
|
||||||
|
|
||||||
|
### pdfTeX 的未嵌入 Type 1 设备字体
|
||||||
|
|
||||||
|
映射中只声明设备字体名时,原生 PDF 写出实际 TFM 字宽和字体描述符,
|
||||||
|
按最终 fontdimen 更新 x-height 和包围盒。按实际编码共享 PDF 字典,
|
||||||
|
并根据字形映射生成 ToUnicode。
|
||||||
|
预览从当前项目资源查找具有相同 PostScript 名的实际 PFB 或 PFA。
|
||||||
|
原生 SVG 直接绘制该轮廓。需要解析完整 PDF 的页面在内存预览副本中
|
||||||
|
使用相同字体程序。缺少真实字体时,仍可生成设备字体 PDF,预览报告
|
||||||
|
缺失资源。[原版度量与字体写出](https://github.com/TeX-Live/texlive-source/blob/fb6158926661cb7a7246b3a94a0cb170a9624d5a/texk/web2c/pdftexdir/writefont.c#L96-L126)
|
||||||
|
[原版设备字体字典](https://github.com/TeX-Live/texlive-source/blob/fb6158926661cb7a7246b3a94a0cb170a9624d5a/texk/web2c/pdftexdir/writefont.c#L580-L637)
|
||||||
|
|
||||||
|
八组原版 pdfTeX 1.40.29 对照的字体名、描述符数值、字宽、编码和
|
||||||
|
ToUnicode 映射一致,八组词框一致。保持原版设备字体输出,没有
|
||||||
|
FontFile。缺失显式编码和开启 ToUnicode 时的缺失内建字形名,两端
|
||||||
|
均失败。三项定向回归涵盖设备字体预览、原 PFA 和共享编码的 CFF。
|
||||||
|
|
||||||
|
四页版本会话更改实际 CMR10 轮廓时,导出 PDF 字节相同,第 2、3 页
|
||||||
|
预览更新。编辑第 2 页新增字形后,共用字体字典改变,复核得到
|
||||||
|
第 3 页 SVG 完全相同并沿用原预览,只交付第 2 页。后两次成功
|
||||||
|
修订各复用 114 步。三次成功修订的 PDF、测量页面、SVG、来源映射
|
||||||
|
和 aux 与同版本独立全量一致。缺字体时编辑器观察器报告错误,
|
||||||
|
此前的已发布预览与 aux 保持可用。
|
||||||
|
|
||||||
|
回执在 target/p3-device-type1。receipt.json 的 SHA-256 为
|
||||||
|
0c21be91673a1da263aed86b28e2748952833ac25f77491b0ef0e8ec46b8f6c1,
|
||||||
|
revision.log 为 3fd97d4ce56afb3197dad9a664af9503ede40bad0574fbd0de5a2ed4a4f537dd。
|
||||||
|
保留修复前的误发页记录。下一处缺口是只在导入 PDF 中使用的设备
|
||||||
|
字体。在 next-imported-device-type1 中,两端 PDF 均保留未嵌入的
|
||||||
|
CMR10,原生需要从导入页的实际字体引用查找已提供的 CMR10.pfb。
|
||||||
|
当前资源清单只记录了图像输入,SVG 中只留下图像的裁剪定义。
|
||||||
|
|
||||||
### pdfTeX 映射的 Type 1 PFA 字体
|
### pdfTeX 映射的 Type 1 PFA 字体
|
||||||
|
|
||||||
原生从实际映射和版本化资源读取 PFA,解码十六进制 eexec,使用
|
原生从实际映射和版本化资源读取 PFA,解码十六进制 eexec,使用
|
||||||
|
|||||||
+42
-13
@@ -4,11 +4,13 @@ use hayro_svg::{
|
|||||||
};
|
};
|
||||||
use std::{
|
use std::{
|
||||||
collections::BTreeMap,
|
collections::BTreeMap,
|
||||||
sync::{Arc, Mutex, OnceLock},
|
sync::{Arc, Mutex, OnceLock, atomic::{AtomicBool, Ordering}},
|
||||||
};
|
};
|
||||||
use texrra_tex_core::render::DisplayList;
|
use texrra_tex_core::render::DisplayList;
|
||||||
|
|
||||||
|
mod device_fonts;
|
||||||
mod pdf_dependencies;
|
mod pdf_dependencies;
|
||||||
|
use device_fonts::PreviewFonts;
|
||||||
use pdf_dependencies::{Fingerprint, PdfDependencies};
|
use pdf_dependencies::{Fingerprint, PdfDependencies};
|
||||||
|
|
||||||
#[derive(Clone, Debug, PartialEq, Eq, serde::Serialize)]
|
#[derive(Clone, Debug, PartialEq, Eq, serde::Serialize)]
|
||||||
@@ -32,7 +34,7 @@ pub struct PreviewUpdate {
|
|||||||
struct CachedPage {
|
struct CachedPage {
|
||||||
svg: Arc<str>,
|
svg: Arc<str>,
|
||||||
pdf_page: Option<Fingerprint>,
|
pdf_page: Option<Fingerprint>,
|
||||||
reused_pdf_page: bool,
|
same_as_previous: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
type PageSvg = OnceLock<Result<CachedPage, String>>;
|
type PageSvg = OnceLock<Result<CachedPage, String>>;
|
||||||
@@ -40,6 +42,7 @@ type PriorPdfPage = (Fingerprint, Arc<str>);
|
|||||||
|
|
||||||
struct PdfPreview<'a> {
|
struct PdfPreview<'a> {
|
||||||
bytes: Option<&'a Arc<[u8]>>,
|
bytes: Option<&'a Arc<[u8]>>,
|
||||||
|
fonts: &'a PreviewFonts,
|
||||||
document: OnceLock<Result<Pdf, String>>,
|
document: OnceLock<Result<Pdf, String>>,
|
||||||
dependencies: PdfDependencies,
|
dependencies: PdfDependencies,
|
||||||
}
|
}
|
||||||
@@ -57,8 +60,12 @@ impl PdfPreview<'_> {
|
|||||||
let bytes = self
|
let bytes = self
|
||||||
.bytes
|
.bytes
|
||||||
.ok_or("embedded PDF preview has no published PDF")?;
|
.ok_or("embedded PDF preview has no published PDF")?;
|
||||||
|
let document = if let Some(data) = self.fonts.attach(bytes)? {
|
||||||
|
Pdf::new(Arc::new(data))
|
||||||
|
} else {
|
||||||
Pdf::new(Arc::new(bytes.clone()))
|
Pdf::new(Arc::new(bytes.clone()))
|
||||||
.map_err(|error| format!("could not read the published preview PDF: {error:?}"))
|
};
|
||||||
|
document.map_err(|error| format!("could not read the published preview PDF: {error:?}"))
|
||||||
})
|
})
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.map_err(Clone::clone)?;
|
.map_err(Clone::clone)?;
|
||||||
@@ -67,22 +74,35 @@ impl PdfPreview<'_> {
|
|||||||
.get(index)
|
.get(index)
|
||||||
.ok_or("preview PDF page is missing")?;
|
.ok_or("preview PDF page is missing")?;
|
||||||
let pdf_page = self.dependencies.page(document, page, unit);
|
let pdf_page = self.dependencies.page(document, page, unit);
|
||||||
if let Some((prior_page, svg)) = previous
|
if let Some((prior_page, svg)) = &previous
|
||||||
&& pdf_page == Some(prior_page)
|
&& pdf_page.as_ref() == Some(prior_page)
|
||||||
{
|
{
|
||||||
return Ok(CachedPage {
|
return Ok(CachedPage {
|
||||||
svg,
|
svg: svg.clone(),
|
||||||
pdf_page,
|
pdf_page,
|
||||||
reused_pdf_page: true,
|
same_as_previous: true,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let mut settings = InterpreterSettings::default();
|
||||||
|
let missing_font = self.fonts.includes_device_fonts().then(|| Arc::new(AtomicBool::new(false)));
|
||||||
|
if let Some(flag) = &missing_font {
|
||||||
|
let flag = flag.clone();
|
||||||
|
settings.warning_sink = Arc::new(move |warning| {
|
||||||
|
if matches!(warning, hayro_svg::hayro_interpret::InterpreterWarning::UnsupportedFont) {
|
||||||
|
flag.store(true, Ordering::Relaxed);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
let svg = hayro_svg::convert(
|
let svg = hayro_svg::convert(
|
||||||
page,
|
page,
|
||||||
&RenderCache::new(),
|
&RenderCache::new(),
|
||||||
&InterpreterSettings::default(),
|
&settings,
|
||||||
&SvgRenderSettings::default(),
|
&SvgRenderSettings::default(),
|
||||||
);
|
);
|
||||||
|
if missing_font.is_some_and(|flag| flag.load(Ordering::Relaxed)) {
|
||||||
|
return Err("native PDF preview needs an actual device font used by this page".into());
|
||||||
|
}
|
||||||
let svg = if unit == 1.0 {
|
let svg = if unit == 1.0 {
|
||||||
Arc::from(svg)
|
Arc::from(svg)
|
||||||
} else {
|
} else {
|
||||||
@@ -92,10 +112,13 @@ impl PdfPreview<'_> {
|
|||||||
"<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"{width}pt\" height=\"{height}pt\" viewBox=\"0 0 {width} {height}\"><g transform=\"scale({unit})\">{svg}</g></svg>"
|
"<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"{width}pt\" height=\"{height}pt\" viewBox=\"0 0 {width} {height}\"><g transform=\"scale({unit})\">{svg}</g></svg>"
|
||||||
))
|
))
|
||||||
};
|
};
|
||||||
|
// A shared PDF object can change without affecting this page's paint.
|
||||||
|
let same = previous.filter(|(_, old)| *old == svg);
|
||||||
|
let same_as_previous = same.is_some();
|
||||||
Ok(CachedPage {
|
Ok(CachedPage {
|
||||||
svg,
|
svg: same.map_or(svg, |(_, old_svg)| old_svg),
|
||||||
pdf_page,
|
pdf_page,
|
||||||
reused_pdf_page: false,
|
same_as_previous,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -105,6 +128,7 @@ pub(crate) struct PreviewState {
|
|||||||
changed: Vec<usize>,
|
changed: Vec<usize>,
|
||||||
slots: Vec<Arc<PageSvg>>,
|
slots: Vec<Arc<PageSvg>>,
|
||||||
prior_pdf: BTreeMap<usize, Mutex<Option<PriorPdfPage>>>,
|
prior_pdf: BTreeMap<usize, Mutex<Option<PriorPdfPage>>>,
|
||||||
|
fonts: PreviewFonts,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PreviewState {
|
impl PreviewState {
|
||||||
@@ -116,10 +140,13 @@ impl PreviewState {
|
|||||||
let mut changed = Vec::new();
|
let mut changed = Vec::new();
|
||||||
let mut slots = Vec::with_capacity(pages.len());
|
let mut slots = Vec::with_capacity(pages.len());
|
||||||
let mut prior_pdf = BTreeMap::new();
|
let mut prior_pdf = BTreeMap::new();
|
||||||
|
let fonts = PreviewFonts::collect(pages);
|
||||||
|
let pdf_inputs_unchanged = pdf_unchanged
|
||||||
|
&& previous.is_some_and(|(_, _, old)| old.fonts == fonts);
|
||||||
for (index, page) in pages.iter().enumerate() {
|
for (index, page) in pages.iter().enumerate() {
|
||||||
let uses_pdf = page.has_embedded_pdf();
|
let uses_pdf = page.has_embedded_pdf();
|
||||||
if let Some((_, old_pages, old)) = previous
|
if let Some((_, old_pages, old)) = previous
|
||||||
&& (pdf_unchanged || !uses_pdf)
|
&& (pdf_inputs_unchanged || !uses_pdf)
|
||||||
&& old_pages
|
&& old_pages
|
||||||
.get(index)
|
.get(index)
|
||||||
.is_some_and(|old_page| old_page.same_svg_paint(page))
|
.is_some_and(|old_page| old_page.same_svg_paint(page))
|
||||||
@@ -142,6 +169,7 @@ impl PreviewState {
|
|||||||
changed,
|
changed,
|
||||||
slots,
|
slots,
|
||||||
prior_pdf,
|
prior_pdf,
|
||||||
|
fonts,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -155,6 +183,7 @@ impl PreviewState {
|
|||||||
) -> Result<PreviewUpdate, String> {
|
) -> Result<PreviewUpdate, String> {
|
||||||
let mut pdf = PdfPreview {
|
let mut pdf = PdfPreview {
|
||||||
bytes: pdf,
|
bytes: pdf,
|
||||||
|
fonts: &self.fonts,
|
||||||
document: OnceLock::new(),
|
document: OnceLock::new(),
|
||||||
dependencies: PdfDependencies::default(),
|
dependencies: PdfDependencies::default(),
|
||||||
};
|
};
|
||||||
@@ -165,7 +194,7 @@ impl PreviewState {
|
|||||||
for &index in &self.changed {
|
for &index in &self.changed {
|
||||||
check()?;
|
check()?;
|
||||||
let cached = self.render_page(index, &pages[index], &mut pdf)?;
|
let cached = self.render_page(index, &pages[index], &mut pdf)?;
|
||||||
if !cached.reused_pdf_page {
|
if !cached.same_as_previous {
|
||||||
rendered.push(PreviewPage {
|
rendered.push(PreviewPage {
|
||||||
index,
|
index,
|
||||||
svg: cached.svg.clone(),
|
svg: cached.svg.clone(),
|
||||||
@@ -213,7 +242,7 @@ impl PreviewState {
|
|||||||
page.try_to_svg().map(|svg| CachedPage {
|
page.try_to_svg().map(|svg| CachedPage {
|
||||||
svg: Arc::from(svg),
|
svg: Arc::from(svg),
|
||||||
pdf_page: None,
|
pdf_page: None,
|
||||||
reused_pdf_page: false,
|
same_as_previous: false,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -0,0 +1,110 @@
|
|||||||
|
use lopdf::{Dictionary, Document, Stream};
|
||||||
|
use std::{collections::BTreeMap, sync::Arc};
|
||||||
|
use texrra_tex_core::{
|
||||||
|
native_font::NativeFontProgram,
|
||||||
|
render::{DisplayItem, DisplayList},
|
||||||
|
type1::Type1Font,
|
||||||
|
};
|
||||||
|
|
||||||
|
#[derive(Default, PartialEq, Eq)]
|
||||||
|
pub(super) struct PreviewFonts {
|
||||||
|
programs: BTreeMap<String, Arc<Type1Font>>,
|
||||||
|
missing: bool,
|
||||||
|
conflict: Option<String>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl PreviewFonts {
|
||||||
|
pub(super) fn collect(pages: &[DisplayList]) -> Self {
|
||||||
|
let mut fonts = Self::default();
|
||||||
|
if pages.iter().any(DisplayList::has_embedded_pdf) {
|
||||||
|
for page in pages {
|
||||||
|
fonts.collect_from(page);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fonts
|
||||||
|
}
|
||||||
|
|
||||||
|
fn collect_from(&mut self, page: &DisplayList) {
|
||||||
|
for item in &page.items {
|
||||||
|
let DisplayItem::NativeGlyph {
|
||||||
|
paint: Some(paint), ..
|
||||||
|
} = item
|
||||||
|
else {
|
||||||
|
continue;
|
||||||
|
};
|
||||||
|
if let NativeFontProgram::DeviceType1(device) = &paint.program {
|
||||||
|
if let Some(program) = &device.preview_program {
|
||||||
|
if let Some(captured) = self.programs.get(&device.name) {
|
||||||
|
if !Arc::ptr_eq(captured, program) && captured != program {
|
||||||
|
self.conflict = Some(device.name.clone());
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
self.programs.insert(device.name.clone(), program.clone());
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
self.missing = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for form in &page.forms {
|
||||||
|
self.collect_from(&form.list);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(super) fn includes_device_fonts(&self) -> bool {
|
||||||
|
self.missing || !self.programs.is_empty()
|
||||||
|
}
|
||||||
|
|
||||||
|
/// For PDF-backed previews, attach the same captured local font programs
|
||||||
|
/// used by the native SVG path to an in-memory copy of the PDF.
|
||||||
|
pub(super) fn attach(&self, pdf: &[u8]) -> Result<Option<Vec<u8>>, String> {
|
||||||
|
if let Some(name) = &self.conflict {
|
||||||
|
return Err(format!(
|
||||||
|
"conflicting actual fonts for PDF preview device name {name}"
|
||||||
|
));
|
||||||
|
}
|
||||||
|
if self.programs.is_empty() {
|
||||||
|
return Ok(None);
|
||||||
|
}
|
||||||
|
let mut document = Document::load_mem(pdf)
|
||||||
|
.map_err(|error| format!("could not read PDF device fonts for preview: {error}"))?;
|
||||||
|
let descriptors: Vec<_> = document
|
||||||
|
.objects
|
||||||
|
.iter()
|
||||||
|
.filter_map(|(&id, object)| {
|
||||||
|
let descriptor = object.as_dict().ok()?;
|
||||||
|
if descriptor.get(b"Type").ok()?.as_name().ok()? != b"FontDescriptor"
|
||||||
|
|| [b"FontFile".as_slice(), b"FontFile2", b"FontFile3"]
|
||||||
|
.into_iter()
|
||||||
|
.any(|key| descriptor.has(key))
|
||||||
|
{
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
let name = descriptor.get(b"FontName").ok()?;
|
||||||
|
let (_, name) = document.dereference(name).ok()?;
|
||||||
|
let name = std::str::from_utf8(name.as_name().ok()?).ok()?;
|
||||||
|
Some((id, self.programs.get(name)?))
|
||||||
|
})
|
||||||
|
.collect();
|
||||||
|
if descriptors.is_empty() {
|
||||||
|
return Ok(None);
|
||||||
|
}
|
||||||
|
let mut streams = BTreeMap::new();
|
||||||
|
for (id, font) in descriptors {
|
||||||
|
let stream = *streams.entry(&font.name).or_insert_with(|| {
|
||||||
|
let mut dictionary = Dictionary::new();
|
||||||
|
dictionary.set("Length1", font.length1 as i64);
|
||||||
|
dictionary.set("Length2", font.length2 as i64);
|
||||||
|
dictionary.set("Length3", font.length3 as i64);
|
||||||
|
document.add_object(Stream::new(dictionary, font.program.clone()))
|
||||||
|
});
|
||||||
|
let descriptor = document.get_object_mut(id).unwrap().as_dict_mut().unwrap();
|
||||||
|
descriptor.set("FontFile", stream);
|
||||||
|
}
|
||||||
|
let mut bytes = Vec::new();
|
||||||
|
document
|
||||||
|
.save_to(&mut bytes)
|
||||||
|
.map_err(|error| format!("could not prepare PDF device fonts for preview: {error}"))?;
|
||||||
|
Ok(Some(bytes))
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1888,6 +1888,62 @@ fn relocated_format_binds_packed_and_new_glyphs_to_the_current_tfm() {
|
|||||||
fs::remove_dir_all(root).unwrap();
|
fs::remove_dir_all(root).unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn mapped_device_type1_uses_actual_preview_font_without_pdf_embedding() {
|
||||||
|
use texrra_tex_core::{native_font::NativeFontProgram, render::DisplayItem};
|
||||||
|
|
||||||
|
let root = directory("mapped-device-type1").canonicalize().unwrap();
|
||||||
|
let outline = root.join("CMR10.pfb");
|
||||||
|
let source = root.join("main.tex");
|
||||||
|
fs::write(&outline, include_bytes!("../assets/fonts/cmr10.pfb")).unwrap();
|
||||||
|
fs::write(root.join("pdftex.map"), b"cmr10 CMR10 4\n").unwrap();
|
||||||
|
let body = r"\catcode123=1 \catcode125=2 \pdfoutput=1 \pdfcompresslevel=0
|
||||||
|
\font\f=cmr10 \shipout\hbox{\f ABC}";
|
||||||
|
fs::write(&source, format!("{body}\\end\n")).unwrap();
|
||||||
|
let mut job = request(&root);
|
||||||
|
for kind in [ResourceKind::Map, ResourceKind::Type1] {
|
||||||
|
job.world.paths.insert(kind, vec![SearchPath::directory(&root, false)]);
|
||||||
|
}
|
||||||
|
let compiler = NativeCompiler::default();
|
||||||
|
let native = compiler.compile(job.clone()).unwrap();
|
||||||
|
let first = native.preview_since(None).unwrap();
|
||||||
|
assert!(first.pages[0].svg.contains("<path"));
|
||||||
|
assert!(native.resources.trace.reads.contains(&file_version(&outline).unwrap().unwrap()));
|
||||||
|
assert!(native.pages[0].items.iter().any(|item| matches!(item,
|
||||||
|
DisplayItem::NativeGlyph { paint: Some(paint), .. }
|
||||||
|
if matches!(&paint.program, NativeFontProgram::DeviceType1(font) if font.name == "CMR10")
|
||||||
|
)));
|
||||||
|
|
||||||
|
fs::write(&source, format!("{body}\\shipout\\hbox{{\\pdfliteral direct {{q Q}}\\f ABC}}\\end\n")).unwrap();
|
||||||
|
let mixed = compiler.compile(job.clone()).unwrap();
|
||||||
|
assert!(mixed.pages[1].has_embedded_pdf());
|
||||||
|
let delta = mixed.preview_since(Some(native.revision())).unwrap();
|
||||||
|
assert_eq!(delta.pages.len(), 1);
|
||||||
|
assert_eq!(delta.pages[0].index, 1);
|
||||||
|
assert!(delta.pages[0].svg.contains("<path"));
|
||||||
|
let pdf = lopdf::Document::load_mem(mixed.pdf.as_deref().unwrap()).unwrap();
|
||||||
|
let descriptor = pdf.objects.values().filter_map(|object| object.as_dict().ok()).find(
|
||||||
|
|dict| dict.get(b"FontName").and_then(|name| name.as_name()).ok() == Some(b"CMR10"),
|
||||||
|
).unwrap();
|
||||||
|
assert!(!descriptor.has(b"FontFile"));
|
||||||
|
|
||||||
|
let updated_body = body.replace("ABC", "ADC");
|
||||||
|
fs::write(
|
||||||
|
&source,
|
||||||
|
format!("{updated_body}\\shipout\\hbox{{\\pdfliteral direct {{q Q}}\\f ABC}}\\end\n"),
|
||||||
|
).unwrap();
|
||||||
|
let edited = compiler.compile(job.clone()).unwrap();
|
||||||
|
let delta = edited.preview_since(Some(mixed.revision())).unwrap();
|
||||||
|
assert_eq!(delta.pages.iter().map(|page| page.index).collect::<Vec<_>>(), [0]);
|
||||||
|
|
||||||
|
fs::remove_file(&outline).unwrap();
|
||||||
|
let missing = compiler.compile(job).unwrap();
|
||||||
|
assert!(missing.pdf.is_some());
|
||||||
|
let error = missing.preview_since(None).unwrap_err();
|
||||||
|
assert!(error.contains("actual device font CMR10"), "{error}");
|
||||||
|
fs::remove_dir_all(root).unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn mapped_type1_pfa_embeds_original_cipher_and_tracks_its_input() {
|
fn mapped_type1_pfa_embeds_original_cipher_and_tracks_its_input() {
|
||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
|
|||||||
Reference in new issue
Block a user