Render and embed TrueType fonts selected by pdfTeX maps
This commit is contained in:
1 parent
aa780a800b
commit
46ef76f890
9 files changed
+570
-36
No files matched your search
@@ -13,7 +13,9 @@ use std::{
|
||||
sync::{Arc, Mutex, OnceLock},
|
||||
};
|
||||
mod map;
|
||||
mod truetype;
|
||||
mod virtual_paint;
|
||||
pub use truetype::TrueTypeProgram;
|
||||
pub use map::PdfFontBindings;
|
||||
use map::{dedicated_space_map, find_map_entry, load_map, selected_outline};
|
||||
pub(crate) use virtual_paint::{JobVirtualFonts, VirtualGlyphs, VirtualPaintState};
|
||||
@@ -64,7 +66,7 @@ impl NativeFontPaint {
|
||||
match &self.program {
|
||||
NativeFontProgram::Type1(font) => self.resources.get(self.program_index.unwrap_or(1))
|
||||
.map(|version| (version, font.transform)),
|
||||
NativeFontProgram::Pk(_) => None,
|
||||
NativeFontProgram::Pk(_) | NativeFontProgram::TrueType(_) => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -73,12 +75,14 @@ impl NativeFontPaint {
|
||||
pub enum NativeFontProgram {
|
||||
Type1(crate::type1::Type1Font),
|
||||
Pk(crate::pk_font::PkFontProgram),
|
||||
TrueType(TrueTypeProgram),
|
||||
}
|
||||
impl NativeFontProgram {
|
||||
pub fn name(&self) -> &str {
|
||||
match self {
|
||||
Self::Type1(p) => &p.name,
|
||||
Self::Pk(p) => &p.name,
|
||||
Self::TrueType(p) => &p.name,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -373,7 +377,7 @@ impl NativeFontCache {
|
||||
|
||||
/// Resolve only fonts used by actual output lists. TFM-only execution and
|
||||
/// unshipped boxes do not require any font program. Errors leave lists intact.
|
||||
/// SVG executes the requested glyph programs; PDF embeds the same actual PFB.
|
||||
/// SVG draws the requested outlines; PDF embeds the same actual font programs.
|
||||
pub fn resolve_native_fonts(
|
||||
pages: &mut [crate::render::DisplayList],
|
||||
files: &mut impl crate::execution::SourceProvider,
|
||||
@@ -414,7 +418,7 @@ fn resolve_physical_fonts(
|
||||
let default_version = captured.and_then(|bindings| bindings.default_map.as_ref())
|
||||
.or_else(|| default_map.as_ref().map(|map| &map.version));
|
||||
let mut resolved = BTreeMap::new();
|
||||
let mut pk_resolved = BTreeMap::new();
|
||||
let mut direct_resolved = BTreeMap::new();
|
||||
let device = pages.iter().find_map(|page| page.pdf.as_ref());
|
||||
let xdv = device.is_some_and(|pdf| pdf.driver == crate::pdf_device::PdfDriver::Xdv);
|
||||
let device = device.map(|pdf| pdf.file.clone());
|
||||
@@ -480,7 +484,7 @@ fn resolve_physical_fonts(
|
||||
}));
|
||||
glyph_paths.insert(slot, program.glyph_path(slot)?);
|
||||
}
|
||||
pk_resolved.insert(
|
||||
direct_resolved.insert(
|
||||
id,
|
||||
Arc::new(NativeFontPaint {
|
||||
program: NativeFontProgram::Pk(program),
|
||||
@@ -499,6 +503,11 @@ fn resolve_physical_fonts(
|
||||
);
|
||||
continue;
|
||||
};
|
||||
if let Some(file) = outline.true_type_file() {
|
||||
let paint = truetype::resolve(files, outline, file, &font, slots)?;
|
||||
direct_resolved.insert(id, Arc::new(paint));
|
||||
continue;
|
||||
}
|
||||
let file = outline.type1_file(&font.name)?;
|
||||
let version = outline.version.as_ref();
|
||||
let key = (
|
||||
@@ -583,7 +592,7 @@ fn resolve_physical_fonts(
|
||||
.into_iter()
|
||||
.map(|(id, key)| (id, cache[&key].clone()))
|
||||
.collect();
|
||||
resolved.extend(pk_resolved);
|
||||
resolved.extend(direct_resolved);
|
||||
for page in pages {
|
||||
for item in &mut page.items {
|
||||
if let DisplayItem::NativeGlyph {
|
||||
@@ -596,7 +605,7 @@ fn resolve_physical_fonts(
|
||||
{
|
||||
let p = resolved[&font.id].clone();
|
||||
*character = match &p.program {
|
||||
NativeFontProgram::Type1(_) => {
|
||||
NativeFontProgram::Type1(_) | NativeFontProgram::TrueType(_) => {
|
||||
crate::type1::glyph_unicode_text(&p.encoding[*slot as usize])
|
||||
.and_then(|text| text.chars().next())
|
||||
.unwrap_or('�')
|
||||
|
||||
Reference in new issue
Block a user