Render and embed OpenType CFF fonts selected by pdfTeX maps
This commit is contained in:
1 parent
46ef76f890
commit
fd5ab59f42
11 files changed
+433
-57
No files matched your search
@@ -12,9 +12,11 @@ use std::{
|
||||
collections::{BTreeMap, VecDeque},
|
||||
sync::{Arc, Mutex, OnceLock},
|
||||
};
|
||||
mod cff;
|
||||
mod map;
|
||||
mod truetype;
|
||||
mod virtual_paint;
|
||||
pub use cff::OpenTypeCffProgram;
|
||||
pub use truetype::TrueTypeProgram;
|
||||
pub use map::PdfFontBindings;
|
||||
use map::{dedicated_space_map, find_map_entry, load_map, selected_outline};
|
||||
@@ -38,6 +40,13 @@ pub struct NativeFontPaint {
|
||||
program_index: Option<usize>,
|
||||
}
|
||||
|
||||
struct MappedOutline {
|
||||
data: Vec<u8>,
|
||||
encoding: Option<Vec<String>>,
|
||||
resources: Vec<ResourceVersion>,
|
||||
program_index: usize,
|
||||
}
|
||||
|
||||
pub(crate) type Type1ProgramKey<'a> = (&'a ResourceVersion, Type1Transform);
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize)]
|
||||
@@ -62,11 +71,15 @@ impl NativeFontPaint {
|
||||
&& self.encoding[32] == "space"
|
||||
&& font.metrics().width(' ') > 65_782
|
||||
}
|
||||
pub(crate) fn encoding_version(&self) -> Option<&ResourceVersion> {
|
||||
self.resources.get(self.program_index? + 1)
|
||||
}
|
||||
|
||||
pub(crate) fn type1_program_key(&self) -> Option<Type1ProgramKey<'_>> {
|
||||
match &self.program {
|
||||
NativeFontProgram::Type1(font) => self.resources.get(self.program_index.unwrap_or(1))
|
||||
.map(|version| (version, font.transform)),
|
||||
NativeFontProgram::Pk(_) | NativeFontProgram::TrueType(_) => None,
|
||||
NativeFontProgram::Pk(_) | NativeFontProgram::TrueType(_) | NativeFontProgram::OpenTypeCff(_) => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -76,6 +89,7 @@ pub enum NativeFontProgram {
|
||||
Type1(crate::type1::Type1Font),
|
||||
Pk(crate::pk_font::PkFontProgram),
|
||||
TrueType(TrueTypeProgram),
|
||||
OpenTypeCff(OpenTypeCffProgram),
|
||||
}
|
||||
impl NativeFontProgram {
|
||||
pub fn name(&self) -> &str {
|
||||
@@ -83,6 +97,7 @@ impl NativeFontProgram {
|
||||
Self::Type1(p) => &p.name,
|
||||
Self::Pk(p) => &p.name,
|
||||
Self::TrueType(p) => &p.name,
|
||||
Self::OpenTypeCff(p) => &p.name,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -508,6 +523,11 @@ fn resolve_physical_fonts(
|
||||
direct_resolved.insert(id, Arc::new(paint));
|
||||
continue;
|
||||
}
|
||||
if let Some(file) = outline.open_type_file() {
|
||||
let paint = cff::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 = (
|
||||
@@ -605,7 +625,9 @@ fn resolve_physical_fonts(
|
||||
{
|
||||
let p = resolved[&font.id].clone();
|
||||
*character = match &p.program {
|
||||
NativeFontProgram::Type1(_) | NativeFontProgram::TrueType(_) => {
|
||||
NativeFontProgram::Type1(_)
|
||||
| NativeFontProgram::TrueType(_)
|
||||
| NativeFontProgram::OpenTypeCff(_) => {
|
||||
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