Render legacy XeLaTeX composite TrueType fonts
This commit is contained in:
1 parent
7d460e0fa1
commit
bbeeca0317
11 files changed
+687
-55
No files matched your search
@@ -21,6 +21,7 @@ mod virtual_paint;
|
||||
pub use cff::OpenTypeCffProgram;
|
||||
pub use device_type1::DeviceType1Program;
|
||||
pub use truetype::TrueTypeProgram;
|
||||
pub(crate) use truetype::cid_width;
|
||||
pub use map::PdfFontBindings;
|
||||
pub(crate) use map::XdvFontMatrix;
|
||||
use map::{dedicated_space_map, find_map_entry, load_map, selected_outline};
|
||||
@@ -80,6 +81,22 @@ impl MappedType1 {
|
||||
}
|
||||
|
||||
impl NativeFontPaint {
|
||||
pub(crate) fn program_version(&self) -> Option<&ResourceVersion> {
|
||||
self.resources.get(self.program_index?)
|
||||
}
|
||||
|
||||
pub(crate) fn legacy_cid_font(&self) -> Option<&truetype::CompositeTrueType> {
|
||||
match &self.program {
|
||||
NativeFontProgram::TrueType(program) => program.composite.as_ref(),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn mapped_text(&self, slot: u8) -> Option<&str> {
|
||||
self.xdv_unicode.as_ref().and_then(|map| map.texts.get(&slot)).map(String::as_str)
|
||||
.or_else(|| self.legacy_cid_font()?.unicode(slot))
|
||||
}
|
||||
|
||||
pub(crate) fn has_pdf_space(&self, font: &NativeFont) -> bool {
|
||||
// pdfTeX requires the space name in an actual map re-encoding.
|
||||
self.encoding_version().is_some()
|
||||
@@ -464,6 +481,9 @@ fn resolve_xdv_unicode(
|
||||
let mut owners: std::collections::HashMap<_, Option<Arc<XdvFontUnicode>>> = std::collections::HashMap::new();
|
||||
for (id, font_name) in used {
|
||||
let paint = resolved.get_mut(&id).expect("resolved device font");
|
||||
if paint.legacy_cid_font().is_some() {
|
||||
continue;
|
||||
}
|
||||
// The PDF writer shares one Type 1 resource and encoding among all
|
||||
// sizes and aliases of the same physical program.
|
||||
let owner_key = paint.xdv_descriptor.and_then(|_| paint.type1_program_key())
|
||||
@@ -640,6 +660,15 @@ fn resolve_physical_fonts(
|
||||
direct_resolved.insert(id, Arc::new(paint));
|
||||
continue;
|
||||
}
|
||||
if let Some(encoding) = &outline.xdv_encoding
|
||||
&& (outline.encoding.is_none() || files.optional_font_file(
|
||||
ResourceKind::CMap, &encoding.name, &outline.from.to_string_lossy(),
|
||||
)?.is_some())
|
||||
{
|
||||
return Err(format!(
|
||||
"native XDV composite encoding {} requires a TrueType program: {}", encoding.name, font.name,
|
||||
));
|
||||
}
|
||||
if let Some(file) = outline.open_type_file() {
|
||||
let mut paint = cff::resolve(files, &mut outlines, outline, file, &font, slots)?;
|
||||
paint.xdv_matrix = matrix;
|
||||
@@ -754,7 +783,7 @@ fn resolve_physical_fonts(
|
||||
} = item
|
||||
{
|
||||
let p = resolved[&font.id].clone();
|
||||
*character = p.xdv_unicode.as_ref().and_then(|map| map.texts.get(slot))
|
||||
*character = p.mapped_text(*slot)
|
||||
.and_then(|text| text.chars().next()).unwrap_or_else(|| match &p.program {
|
||||
NativeFontProgram::Type1(_)
|
||||
| NativeFontProgram::DeviceType1(_)
|
||||
|
||||
Reference in new issue
Block a user