Bind shipped XeLaTeX font maps to native font resources
This commit is contained in:
1 parent
dcc6a3984c
commit
af6466cd98
11 files changed
+482
-25
No files matched your search
@@ -212,6 +212,25 @@ impl Executor {
|
|||||||
bytes: Arc::from(bytes),
|
bytes: Arc::from(bytes),
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
if let Some(body) = body {
|
||||||
|
for (command, map_file) in [(b"mapfile".as_slice(), true), (b"mapline", false)] {
|
||||||
|
if let Some(operands) = xdv_operand(body, command) {
|
||||||
|
let from = self.source_name(special.span);
|
||||||
|
self.reads.insert(Dependency::FontResources);
|
||||||
|
let warnings = Arc::make_mut(&mut self.pdf_virtual_fonts)
|
||||||
|
.update_xdv_font_map(operands, map_file, std::path::Path::new(&from), files)
|
||||||
|
.map_err(|error| self.error(error, special.span))?;
|
||||||
|
self.check_cancellation()?;
|
||||||
|
for warning in warnings {
|
||||||
|
files.observe_diagnostic(
|
||||||
|
WriteDestination::TerminalAndLog,
|
||||||
|
&format!("xdvipdfmx: warning: {warning}\n"),
|
||||||
|
).map_err(|error| self.error(error, special.span))?;
|
||||||
|
}
|
||||||
|
return Ok(None);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
if let Some(dictionary) = body.and_then(|body| xdv_operand(body, b"docinfo")) {
|
if let Some(dictionary) = body.and_then(|body| xdv_operand(body, b"docinfo")) {
|
||||||
use crate::pdf_device::xdv_document::merge_docinfo;
|
use crate::pdf_device::xdv_document::merge_docinfo;
|
||||||
let (entries, warnings) = merge_docinfo(&self.state.pdf_info, dictionary)
|
let (entries, warnings) = merge_docinfo(&self.state.pdf_info, dictionary)
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ pub use cff::OpenTypeCffProgram;
|
|||||||
pub use device_type1::DeviceType1Program;
|
pub use device_type1::DeviceType1Program;
|
||||||
pub use truetype::TrueTypeProgram;
|
pub use truetype::TrueTypeProgram;
|
||||||
pub use map::PdfFontBindings;
|
pub use map::PdfFontBindings;
|
||||||
|
pub(crate) use map::XdvFontMatrix;
|
||||||
use map::{dedicated_space_map, find_map_entry, load_map, selected_outline};
|
use map::{dedicated_space_map, find_map_entry, load_map, selected_outline};
|
||||||
pub(crate) use virtual_paint::{JobVirtualFonts, VirtualGlyphs, VirtualPaintState};
|
pub(crate) use virtual_paint::{JobVirtualFonts, VirtualGlyphs, VirtualPaintState};
|
||||||
|
|
||||||
@@ -40,6 +41,8 @@ pub struct NativeFontPaint {
|
|||||||
pub(crate) xdv_descriptor: Option<XdvDescriptor>,
|
pub(crate) xdv_descriptor: Option<XdvDescriptor>,
|
||||||
#[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
|
#[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
|
||||||
pub(crate) xdv_widths: BTreeMap<u8, i64>,
|
pub(crate) xdv_widths: BTreeMap<u8, i64>,
|
||||||
|
#[serde(default, skip_serializing_if = "XdvFontMatrix::is_identity")]
|
||||||
|
pub(crate) xdv_matrix: XdvFontMatrix,
|
||||||
pub resources: Vec<crate::resources::ResourceVersion>,
|
pub resources: Vec<crate::resources::ResourceVersion>,
|
||||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||||
program_index: Option<usize>,
|
program_index: Option<usize>,
|
||||||
@@ -554,6 +557,7 @@ fn resolve_physical_fonts(
|
|||||||
descriptor_flags: None,
|
descriptor_flags: None,
|
||||||
xdv_descriptor: None,
|
xdv_descriptor: None,
|
||||||
xdv_widths: BTreeMap::new(),
|
xdv_widths: BTreeMap::new(),
|
||||||
|
xdv_matrix: Default::default(),
|
||||||
resources: entry.as_ref().and_then(|entry| entry.version.as_ref())
|
resources: entry.as_ref().and_then(|entry| entry.version.as_ref())
|
||||||
.or(default_version).cloned().into_iter()
|
.or(default_version).cloned().into_iter()
|
||||||
.chain(std::iter::once(resource.version)).collect(),
|
.chain(std::iter::once(resource.version)).collect(),
|
||||||
@@ -567,31 +571,36 @@ fn resolve_physical_fonts(
|
|||||||
direct_resolved.insert(id, Arc::new(paint));
|
direct_resolved.insert(id, Arc::new(paint));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
let matrix = if xdv { outline.xdv_text_matrix() } else { XdvFontMatrix::default() };
|
||||||
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 mut paint = truetype::resolve(files, &mut outlines, outline, file, &font, slots)?;
|
||||||
|
paint.xdv_matrix = matrix;
|
||||||
direct_resolved.insert(id, Arc::new(paint));
|
direct_resolved.insert(id, Arc::new(paint));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if let Some(file) = outline.open_type_file() {
|
if let Some(file) = outline.open_type_file() {
|
||||||
let paint = cff::resolve(files, &mut outlines, outline, file, &font, slots)?;
|
let mut paint = cff::resolve(files, &mut outlines, outline, file, &font, slots)?;
|
||||||
|
paint.xdv_matrix = matrix;
|
||||||
direct_resolved.insert(id, Arc::new(paint));
|
direct_resolved.insert(id, Arc::new(paint));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
let file = outline.type1_file(&font.name)?;
|
let file = outline.type1_file(&font.name)?;
|
||||||
let version = outline.version.as_ref();
|
let version = outline.version.as_ref();
|
||||||
|
let transform = outline.transform;
|
||||||
let key = (
|
let key = (
|
||||||
outline.from.clone(),
|
outline.from.clone(),
|
||||||
version.map(|version| version.sha256.clone()),
|
version.map(|version| version.sha256.clone()),
|
||||||
file.to_owned(),
|
file.to_owned(),
|
||||||
outline.encoding.clone(),
|
outline.encoding.clone(),
|
||||||
outline.transform,
|
transform,
|
||||||
|
matrix,
|
||||||
outline.subset,
|
outline.subset,
|
||||||
outline.descriptor_flags,
|
outline.descriptor_flags,
|
||||||
);
|
);
|
||||||
if !cache.contains_key(&key) {
|
if !cache.contains_key(&key) {
|
||||||
let from = outline.from.to_string_lossy();
|
let from = outline.from.to_string_lossy();
|
||||||
let resource = actual_resource(files, ResourceKind::Type1, file, &from)?;
|
let resource = actual_resource(files, ResourceKind::Type1, file, &from)?;
|
||||||
let decoded = font_cache.type1(&resource, outline.transform)?;
|
let decoded = font_cache.type1(&resource, transform)?;
|
||||||
let program = &decoded.program;
|
let program = &decoded.program;
|
||||||
let mut resources: Vec<_> = version.cloned().into_iter().collect();
|
let mut resources: Vec<_> = version.cloned().into_iter().collect();
|
||||||
let program_index = Some(resources.len());
|
let program_index = Some(resources.len());
|
||||||
@@ -630,6 +639,7 @@ fn resolve_physical_fonts(
|
|||||||
None
|
None
|
||||||
},
|
},
|
||||||
xdv_widths: BTreeMap::new(),
|
xdv_widths: BTreeMap::new(),
|
||||||
|
xdv_matrix: matrix,
|
||||||
resources,
|
resources,
|
||||||
program_index,
|
program_index,
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -133,6 +133,7 @@ pub(super) fn resolve(
|
|||||||
descriptor_flags: outline.descriptor_flags,
|
descriptor_flags: outline.descriptor_flags,
|
||||||
xdv_descriptor: None,
|
xdv_descriptor: None,
|
||||||
xdv_widths: BTreeMap::new(),
|
xdv_widths: BTreeMap::new(),
|
||||||
|
xdv_matrix: Default::default(),
|
||||||
resources,
|
resources,
|
||||||
program_index: Some(program_index),
|
program_index: Some(program_index),
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -140,6 +140,7 @@ pub(super) fn resolve(
|
|||||||
descriptor_flags: entry.descriptor_flags,
|
descriptor_flags: entry.descriptor_flags,
|
||||||
xdv_descriptor: None,
|
xdv_descriptor: None,
|
||||||
xdv_widths: BTreeMap::new(),
|
xdv_widths: BTreeMap::new(),
|
||||||
|
xdv_matrix: Default::default(),
|
||||||
resources,
|
resources,
|
||||||
program_index: None,
|
program_index: None,
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -30,6 +30,27 @@ pub(super) struct MapEntry {
|
|||||||
pub(super) descriptor_flags: Option<i32>,
|
pub(super) descriptor_flags: Option<i32>,
|
||||||
#[serde(default, skip_serializing_if = "Type1Transform::is_identity")]
|
#[serde(default, skip_serializing_if = "Type1Transform::is_identity")]
|
||||||
pub transform: Type1Transform,
|
pub transform: Type1Transform,
|
||||||
|
#[serde(default, skip_serializing_if = "XdvFontMatrix::is_identity")]
|
||||||
|
xdv_matrix: XdvFontMatrix,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash, serde::Serialize, serde::Deserialize)]
|
||||||
|
pub(crate) struct XdvFontMatrix {
|
||||||
|
slant: i32,
|
||||||
|
extend: i32,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl XdvFontMatrix {
|
||||||
|
pub(crate) fn is_identity(&self) -> bool {
|
||||||
|
*self == Self::default()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) fn coefficients(self) -> [f64; 2] {
|
||||||
|
[
|
||||||
|
1.0 + f64::from(self.extend) / 1_000_000.0,
|
||||||
|
f64::from(self.slant) / 1_000_000.0,
|
||||||
|
]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type PostscriptKey = (String, i32, i32);
|
type PostscriptKey = (String, i32, i32);
|
||||||
@@ -59,6 +80,42 @@ impl OutlineFiles {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl MapEntry {
|
impl MapEntry {
|
||||||
|
fn empty(from: &Path, version: Option<&ResourceVersion>) -> Self {
|
||||||
|
Self {
|
||||||
|
from: from.to_owned(),
|
||||||
|
version: version.cloned(),
|
||||||
|
file: None,
|
||||||
|
encoding: None,
|
||||||
|
subfont: None,
|
||||||
|
cmap: None,
|
||||||
|
postscript_name: false,
|
||||||
|
ps_name: None,
|
||||||
|
descriptor_flags: None,
|
||||||
|
transform: Type1Transform::default(),
|
||||||
|
subset: false,
|
||||||
|
xdv_matrix: XdvFontMatrix::default(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(super) fn xdv_text_matrix(&self) -> XdvFontMatrix {
|
||||||
|
self.xdv_matrix
|
||||||
|
}
|
||||||
|
|
||||||
|
fn xdv_matrix(&self) -> XdvFontMatrix {
|
||||||
|
if self.xdv_matrix.is_identity() {
|
||||||
|
XdvFontMatrix {
|
||||||
|
slant: self.transform.slant * 1_000,
|
||||||
|
extend: if self.transform.extend == 0 {
|
||||||
|
0
|
||||||
|
} else {
|
||||||
|
(self.transform.extend - 1_000) * 1_000
|
||||||
|
},
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
self.xdv_matrix
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn postscript_key(&self) -> Option<PostscriptKey> {
|
fn postscript_key(&self) -> Option<PostscriptKey> {
|
||||||
Some((self.ps_name.clone()?, self.transform.slant, self.transform.extend))
|
Some((self.ps_name.clone()?, self.transform.slant, self.transform.extend))
|
||||||
}
|
}
|
||||||
@@ -183,19 +240,7 @@ fn parse_map_line(
|
|||||||
if !current.is_empty() {
|
if !current.is_empty() {
|
||||||
fields.push((false, current));
|
fields.push((false, current));
|
||||||
}
|
}
|
||||||
let mut entry = MapEntry {
|
let mut entry = MapEntry::empty(from, version);
|
||||||
from: from.to_path_buf(),
|
|
||||||
version: version.cloned(),
|
|
||||||
file: None,
|
|
||||||
subset: false,
|
|
||||||
encoding: None,
|
|
||||||
subfont: None,
|
|
||||||
cmap: None,
|
|
||||||
postscript_name: false,
|
|
||||||
ps_name: None,
|
|
||||||
descriptor_flags: None,
|
|
||||||
transform: Type1Transform::default(),
|
|
||||||
};
|
|
||||||
let mut fields = fields.into_iter().skip(1).enumerate();
|
let mut fields = fields.into_iter().skip(1).enumerate();
|
||||||
while let Some((index, (quote, value))) = fields.next() {
|
while let Some((index, (quote, value))) = fields.next() {
|
||||||
if quote {
|
if quote {
|
||||||
@@ -278,6 +323,80 @@ fn parse_map_line(
|
|||||||
Ok(Some((name, entry)))
|
Ok(Some((name, entry)))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Copy, PartialEq, Eq)]
|
||||||
|
enum XdvMapSyntax {
|
||||||
|
Neutral,
|
||||||
|
Dvips,
|
||||||
|
Dvipdfm,
|
||||||
|
}
|
||||||
|
|
||||||
|
fn xdv_map_syntax(line: &str) -> XdvMapSyntax {
|
||||||
|
if line.contains(['"', '<']) {
|
||||||
|
XdvMapSyntax::Dvips
|
||||||
|
} else if line.split_ascii_whitespace().count() == 2
|
||||||
|
&& !line.split_ascii_whitespace().any(|part| part.starts_with('-'))
|
||||||
|
{
|
||||||
|
XdvMapSyntax::Neutral
|
||||||
|
} else {
|
||||||
|
XdvMapSyntax::Dvipdfm
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn parse_xdv_map_line(
|
||||||
|
line: &str,
|
||||||
|
from: &Path,
|
||||||
|
version: Option<&ResourceVersion>,
|
||||||
|
) -> Result<Option<(String, MapEntry)>, String> {
|
||||||
|
let mut words = line.split_ascii_whitespace().peekable();
|
||||||
|
let Some(name) = words.next() else { return Ok(None) };
|
||||||
|
let mut entry = MapEntry::empty(from, version);
|
||||||
|
let mut fields = (0..2).map(|_| {
|
||||||
|
words.next_if(|field| !field.starts_with('-'))
|
||||||
|
.filter(|field| !matches!(*field, "default" | "none"))
|
||||||
|
});
|
||||||
|
if let Some(encoding) = fields.next().flatten() {
|
||||||
|
if encoding == "unicode" || encoding.starts_with("Identity-") {
|
||||||
|
return Err(format!("unsupported XDV composite map encoding {encoding} for {name}"));
|
||||||
|
}
|
||||||
|
entry.encoding = Some(if encoding.ends_with(".enc") {
|
||||||
|
encoding.to_owned()
|
||||||
|
} else {
|
||||||
|
format!("{encoding}.enc")
|
||||||
|
});
|
||||||
|
}
|
||||||
|
let file = fields.next().flatten().unwrap_or(name);
|
||||||
|
if file.contains([':', ',']) || file.starts_with('!') {
|
||||||
|
return Err(format!("unsupported XDV map font options for {name}: {file}"));
|
||||||
|
}
|
||||||
|
entry.file = Some(if Path::new(file).extension().is_none() {
|
||||||
|
format!("{file}.pfb")
|
||||||
|
} else {
|
||||||
|
file.to_owned()
|
||||||
|
});
|
||||||
|
entry.subset = true;
|
||||||
|
while let Some(option) = words.next() {
|
||||||
|
match option {
|
||||||
|
"-r" => {}, // Obsolete remapping option in the reference driver.
|
||||||
|
"-s" | "-e" => {
|
||||||
|
let number = words.next().and_then(|word| word.parse::<f64>().ok())
|
||||||
|
.filter(|value| value.is_finite())
|
||||||
|
.ok_or_else(|| format!("invalid XDV map option {option} for {name}"))?;
|
||||||
|
let fixed = (number * 1_000_000.0).round();
|
||||||
|
if fixed.abs() > f64::from(i32::MAX) || (option == "-e" && fixed <= 0.0) {
|
||||||
|
return Err(format!("XDV map option {option} out of range for {name}"));
|
||||||
|
}
|
||||||
|
if option == "-s" {
|
||||||
|
entry.xdv_matrix.slant = fixed as i32;
|
||||||
|
} else {
|
||||||
|
entry.xdv_matrix.extend = fixed as i32 - 1_000_000;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_ => return Err(format!("unsupported XDV map option {option} for {name}")),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Ok(Some((name.to_owned(), entry)))
|
||||||
|
}
|
||||||
|
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
#[derive(Clone, Debug, Default, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
|
#[derive(Clone, Debug, Default, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
|
||||||
pub struct PdfFontBindings {
|
pub struct PdfFontBindings {
|
||||||
@@ -326,6 +445,9 @@ pub(super) struct JobFontMap {
|
|||||||
used_names: BTreeSet<String>,
|
used_names: BTreeSet<String>,
|
||||||
used_postscript: BTreeSet<PostscriptKey>,
|
used_postscript: BTreeSet<PostscriptKey>,
|
||||||
bindings: Option<Arc<PdfFontBindings>>,
|
bindings: Option<Arc<PdfFontBindings>>,
|
||||||
|
// XDV fixes a scalable PDF font by its device name on first use.
|
||||||
|
// Later sizes can still pick up a new text matrix for that same program.
|
||||||
|
xdv_loaded: Option<BTreeMap<String, Arc<MapEntry>>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl JobFontMap {
|
impl JobFontMap {
|
||||||
@@ -371,7 +493,27 @@ impl JobFontMap {
|
|||||||
if bindings.fonts.contains_key(&id) {
|
if bindings.fonts.contains_key(&id) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let entry = self.tables.entries.get(name).cloned();
|
let mut entry = self.tables.entries.get(name).cloned();
|
||||||
|
if let Some(loaded) = &mut self.xdv_loaded {
|
||||||
|
if let Some(first) = loaded.get(name) {
|
||||||
|
let matrix = entry.as_ref().map_or_else(XdvFontMatrix::default, |entry| entry.xdv_matrix());
|
||||||
|
if matrix == first.xdv_matrix() {
|
||||||
|
entry = Some(first.clone());
|
||||||
|
} else {
|
||||||
|
let mut device = first.as_ref().clone();
|
||||||
|
device.transform = Type1Transform::default();
|
||||||
|
device.xdv_matrix = matrix;
|
||||||
|
entry = Some(Arc::new(device));
|
||||||
|
}
|
||||||
|
} else if let Some(outline) = entry.as_ref().filter(|entry| entry.is_scalable()) {
|
||||||
|
let mut device = outline.as_ref().clone();
|
||||||
|
device.xdv_matrix = device.xdv_matrix();
|
||||||
|
device.transform = Type1Transform::default();
|
||||||
|
let device = Arc::new(device);
|
||||||
|
loaded.insert(name.to_owned(), device.clone());
|
||||||
|
entry = Some(device);
|
||||||
|
}
|
||||||
|
}
|
||||||
if let Some(entry) = &entry {
|
if let Some(entry) = &entry {
|
||||||
self.used_names.insert(name.into());
|
self.used_names.insert(name.into());
|
||||||
if let Some(key) = entry.postscript_key()
|
if let Some(key) = entry.postscript_key()
|
||||||
@@ -460,6 +602,102 @@ impl JobFontMap {
|
|||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub(super) fn xdv_prefers_physical(&self, name: &str) -> bool {
|
||||||
|
self.xdv_loaded.is_some() && self.tables.entries.contains_key(name)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(super) fn xdv_command(
|
||||||
|
&mut self,
|
||||||
|
input: &[u8],
|
||||||
|
map_file: bool,
|
||||||
|
from: &Path,
|
||||||
|
files: &mut impl SourceProvider,
|
||||||
|
) -> Result<Vec<String>, String> {
|
||||||
|
let text = std::str::from_utf8(input).map_err(|_| "XDV font map command is not UTF-8")?;
|
||||||
|
let text = text.trim_ascii_start();
|
||||||
|
if text.is_empty() {
|
||||||
|
return Ok(if map_file { Vec::new() } else { vec!["Empty mapline special?".into()] });
|
||||||
|
}
|
||||||
|
let (mode, item) = match text.as_bytes()[0] {
|
||||||
|
b'+' => (MapMode::Add, &text[1..]),
|
||||||
|
b'-' => (MapMode::Delete, &text[1..]),
|
||||||
|
_ => (MapMode::Replace, text),
|
||||||
|
};
|
||||||
|
self.xdv_loaded.get_or_insert_with(BTreeMap::new);
|
||||||
|
if self.bindings.is_none() {
|
||||||
|
self.initialize(true, from, files)?;
|
||||||
|
}
|
||||||
|
let item = item.trim_ascii_start();
|
||||||
|
let mut warnings = Vec::new();
|
||||||
|
if map_file {
|
||||||
|
let name = if let Some(quoted) = item.strip_prefix('"') {
|
||||||
|
quoted.split_once('"').map(|(name, _)| name)
|
||||||
|
} else {
|
||||||
|
item.split_ascii_whitespace().next()
|
||||||
|
};
|
||||||
|
let Some(name) = name.filter(|name| !name.is_empty()) else {
|
||||||
|
return Ok(vec!["No fontmap file specified.".into()]);
|
||||||
|
};
|
||||||
|
let name = if Path::new(name).extension().is_some() {
|
||||||
|
name.to_owned()
|
||||||
|
} else {
|
||||||
|
format!("{name}.map")
|
||||||
|
};
|
||||||
|
let Some(read) = load_map(files, &name, from)? else {
|
||||||
|
return Ok(vec![format!("Could not open font map file {name:?}.")]);
|
||||||
|
};
|
||||||
|
let body = std::str::from_utf8(&read.data).map_err(|_| "XDV font map is not UTF-8")?;
|
||||||
|
let mut syntax = XdvMapSyntax::Neutral;
|
||||||
|
for (index, line) in body.lines().enumerate() {
|
||||||
|
let line = line.split('%').next().unwrap().trim_ascii();
|
||||||
|
if line.is_empty() || line.starts_with(['#', ';', '*']) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
let shape = xdv_map_syntax(line);
|
||||||
|
if syntax == XdvMapSyntax::Neutral {
|
||||||
|
syntax = shape;
|
||||||
|
} else if shape != XdvMapSyntax::Neutral && syntax != shape {
|
||||||
|
warnings.push(format!("Mismatched fontmap line {} from {name}.", index + 1));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
let result = if syntax == XdvMapSyntax::Dvipdfm {
|
||||||
|
parse_xdv_map_line(line, &read.version.path, Some(&read.version))
|
||||||
|
} else {
|
||||||
|
parse_map_line(line, &read.version.path, Some(&read.version))
|
||||||
|
};
|
||||||
|
match result {
|
||||||
|
Ok(Some((name, entry))) => self.install_line(name, entry, mode, true, &mut warnings, files)?,
|
||||||
|
Ok(None) => {},
|
||||||
|
Err(error) => {
|
||||||
|
warnings.push(error);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if mode == MapMode::Delete {
|
||||||
|
if let Some(name) = item.split_ascii_whitespace().next() {
|
||||||
|
self.install_line(name.to_owned(), MapEntry::empty(from, None), mode, true, &mut warnings, files)?;
|
||||||
|
} else {
|
||||||
|
warnings.push("Invalid fontmap line: Missing TFM name.".into());
|
||||||
|
}
|
||||||
|
} else if item.len() >= 1023 {
|
||||||
|
warnings.push("Invalid fontmap line: Too long a line.".into());
|
||||||
|
} else {
|
||||||
|
let item = item.split('%').next().unwrap().trim_ascii();
|
||||||
|
let result = if xdv_map_syntax(item) == XdvMapSyntax::Dvipdfm {
|
||||||
|
parse_xdv_map_line(item, from, None)
|
||||||
|
} else {
|
||||||
|
parse_map_line(item, from, None)
|
||||||
|
};
|
||||||
|
match result {
|
||||||
|
Ok(Some((name, entry))) => self.install_line(name, entry, mode, true, &mut warnings, files)?,
|
||||||
|
Ok(None) => {},
|
||||||
|
Err(error) => warnings.push(error),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Ok(warnings)
|
||||||
|
}
|
||||||
|
|
||||||
pub(super) fn command(
|
pub(super) fn command(
|
||||||
&mut self,
|
&mut self,
|
||||||
input: &[u8],
|
input: &[u8],
|
||||||
@@ -546,6 +784,18 @@ impl JobFontMap {
|
|||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
self.install_line(name, entry, mode, suppress_duplicates, warnings, files)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn install_line(
|
||||||
|
&mut self,
|
||||||
|
name: String,
|
||||||
|
entry: MapEntry,
|
||||||
|
mode: MapMode,
|
||||||
|
suppress_duplicates: bool,
|
||||||
|
warnings: &mut Vec<String>,
|
||||||
|
files: &mut impl SourceProvider,
|
||||||
|
) -> Result<(), String> {
|
||||||
if let Some((prefix, file)) = sfd::template(&name) {
|
if let Some((prefix, file)) = sfd::template(&name) {
|
||||||
let definition = format!("{file}.sfd");
|
let definition = format!("{file}.sfd");
|
||||||
if let Some(definition) = self.subfonts.get(files, &definition, &entry.from)? {
|
if let Some(definition) = self.subfonts.get(files, &definition, &entry.from)? {
|
||||||
@@ -578,22 +828,33 @@ impl JobFontMap {
|
|||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if self.used_names.contains(&name) {
|
if self.xdv_loaded.is_none() && self.used_names.contains(&name) {
|
||||||
warnings.push(format!(
|
warnings.push(format!(
|
||||||
"fontmap entry for '{name}' has been used, replace/delete not allowed"
|
"fontmap entry for '{name}' has been used, replace/delete not allowed"
|
||||||
));
|
));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if self.xdv_loaded.is_some()
|
||||||
|
&& let Some(key) = self.tables.entries.get(&name).and_then(|old| old.postscript_key())
|
||||||
|
&& self.tables.postscript.get(&key).is_some_and(|(owner, _)| *owner == name)
|
||||||
|
{
|
||||||
|
Arc::make_mut(&mut self.tables.postscript).remove(&key);
|
||||||
|
}
|
||||||
let entry = Arc::new(entry);
|
let entry = Arc::new(entry);
|
||||||
if mode == MapMode::Delete {
|
if mode == MapMode::Delete {
|
||||||
Arc::make_mut(&mut self.tables.entries).remove(&name);
|
Arc::make_mut(&mut self.tables.entries).remove(&name);
|
||||||
} else {
|
} else {
|
||||||
Arc::make_mut(&mut self.tables.entries).insert(name.clone(), entry.clone());
|
Arc::make_mut(&mut self.tables.entries).insert(name.clone(), entry.clone());
|
||||||
}
|
}
|
||||||
|
if self.xdv_loaded.is_some() && mode == MapMode::Delete {
|
||||||
|
return;
|
||||||
|
}
|
||||||
let Some(key) = entry.postscript_key() else { return };
|
let Some(key) = entry.postscript_key() else { return };
|
||||||
if self.tables.postscript.contains_key(&key) {
|
if self.tables.postscript.contains_key(&key) {
|
||||||
if mode == MapMode::Add || self.used_postscript.contains(&key) {
|
if mode == MapMode::Add
|
||||||
|
|| (self.xdv_loaded.is_none() && self.used_postscript.contains(&key))
|
||||||
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Arc::make_mut(&mut self.tables.postscript).remove(&key);
|
Arc::make_mut(&mut self.tables.postscript).remove(&key);
|
||||||
@@ -688,5 +949,6 @@ pub(super) fn dedicated_space_map(font: &NativeFont) -> MapEntry {
|
|||||||
descriptor_flags: None,
|
descriptor_flags: None,
|
||||||
transform: Type1Transform::default(),
|
transform: Type1Transform::default(),
|
||||||
subset: false,
|
subset: false,
|
||||||
|
xdv_matrix: XdvFontMatrix::default(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -225,6 +225,7 @@ pub(super) fn resolve(
|
|||||||
descriptor_flags: outline.descriptor_flags,
|
descriptor_flags: outline.descriptor_flags,
|
||||||
xdv_descriptor: None,
|
xdv_descriptor: None,
|
||||||
xdv_widths: BTreeMap::new(),
|
xdv_widths: BTreeMap::new(),
|
||||||
|
xdv_matrix: Default::default(),
|
||||||
resources,
|
resources,
|
||||||
program_index: Some(program_index),
|
program_index: Some(program_index),
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -406,6 +406,13 @@ impl JobVirtualFonts {
|
|||||||
self.font_map.command(bytes, map_file, from, suppress_duplicates, files)
|
self.font_map.command(bytes, map_file, from, suppress_duplicates, files)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub(crate) fn update_xdv_font_map(
|
||||||
|
&mut self, bytes: &[u8], map_file: bool, from: &std::path::Path,
|
||||||
|
files: &mut impl SourceProvider,
|
||||||
|
) -> Result<Vec<String>, String> {
|
||||||
|
self.font_map.xdv_command(bytes, map_file, from, files)
|
||||||
|
}
|
||||||
|
|
||||||
pub(crate) fn imported_type1_program(
|
pub(crate) fn imported_type1_program(
|
||||||
&mut self, name: &str, from: &std::path::Path, files: &mut impl SourceProvider,
|
&mut self, name: &str, from: &std::path::Path, files: &mut impl SourceProvider,
|
||||||
) -> Result<Option<super::MappedType1>, String> {
|
) -> Result<Option<super::MappedType1>, String> {
|
||||||
@@ -471,6 +478,8 @@ impl JobVirtualFonts {
|
|||||||
}
|
}
|
||||||
} else if let Some(program) = &font.letter_spacing {
|
} else if let Some(program) = &font.letter_spacing {
|
||||||
Some(Program::Letterspace(program.clone()))
|
Some(Program::Letterspace(program.clone()))
|
||||||
|
} else if self.font_map.xdv_prefers_physical(&font.name) {
|
||||||
|
None
|
||||||
} else if let Some(vf) = read_virtual(font, files)? {
|
} else if let Some(vf) = read_virtual(font, files)? {
|
||||||
let mut locals = BTreeMap::new();
|
let mut locals = BTreeMap::new();
|
||||||
for id in &vf.program.local_order {
|
for id in &vf.program.local_order {
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
use super::PageContent;
|
use super::PageContent;
|
||||||
use crate::{
|
use crate::{
|
||||||
execution::FontId,
|
execution::FontId,
|
||||||
native_font::NativeFont,
|
native_font::{NativeFont, XdvFontMatrix},
|
||||||
pdf_device::{
|
pdf_device::{
|
||||||
PdfGraphics, PdfLiteralMode, divide_scaled, print_decimal, print_sp,
|
PdfGraphics, PdfLiteralMode, divide_scaled, print_decimal, print_sp,
|
||||||
text_spaces::{ResolvedSpaceFont, SpaceOperation, SpacePlan, SpaceUse},
|
text_spaces::{ResolvedSpaceFont, SpaceOperation, SpacePlan, SpaceUse},
|
||||||
@@ -17,6 +17,7 @@ pub(super) struct NativeText {
|
|||||||
effective_size: i64,
|
effective_size: i64,
|
||||||
expansion: i32,
|
expansion: i32,
|
||||||
xdv: bool,
|
xdv: bool,
|
||||||
|
xdv_matrix: XdvFontMatrix,
|
||||||
v: i64,
|
v: i64,
|
||||||
start_h: i64,
|
start_h: i64,
|
||||||
delta_h: i64,
|
delta_h: i64,
|
||||||
@@ -41,7 +42,7 @@ impl NativeText {
|
|||||||
let first = text.is_none();
|
let first = text.is_none();
|
||||||
let state = text.get_or_insert_with(|| {
|
let state = text.get_or_insert_with(|| {
|
||||||
out.push_str("BT\n");
|
out.push_str("BT\n");
|
||||||
if let Some(origin) = xdv_origin {
|
if let Some(origin) = xdv_origin.filter(|_| paint.xdv_matrix.is_identity()) {
|
||||||
let [h, v] = out.origin.position();
|
let [h, v] = out.origin.position();
|
||||||
out.push_str(&format!(
|
out.push_str(&format!(
|
||||||
"1 0 0 1 {} {} Tm\n",
|
"1 0 0 1 {} {} Tm\n",
|
||||||
@@ -54,6 +55,7 @@ impl NativeText {
|
|||||||
effective_size: 0,
|
effective_size: 0,
|
||||||
expansion: 0,
|
expansion: 0,
|
||||||
xdv: xdv_origin.is_some(),
|
xdv: xdv_origin.is_some(),
|
||||||
|
xdv_matrix: XdvFontMatrix::default(),
|
||||||
v: xdv_origin.unwrap_or(height),
|
v: xdv_origin.unwrap_or(height),
|
||||||
start_h: xdv_origin.unwrap_or(0),
|
start_h: xdv_origin.unwrap_or(0),
|
||||||
delta_h: 0,
|
delta_h: 0,
|
||||||
@@ -82,20 +84,35 @@ impl NativeText {
|
|||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
let matrix_changed = state.xdv && state.xdv_matrix != paint.xdv_matrix;
|
||||||
|
state.xdv_matrix = paint.xdv_matrix;
|
||||||
let (mut shift, shift_out) = state.horizontal_move(x, state.effective_size);
|
let (mut shift, shift_out) = state.horizontal_move(x, state.effective_size);
|
||||||
let (v, v_out) = state.vertical_move(y, digits);
|
let (v, v_out) = state.vertical_move(y, digits);
|
||||||
let reset_line = if state.xdv {
|
let reset_line = if state.xdv {
|
||||||
let delta = x - state.start_h - state.delta_h;
|
let delta = x - state.start_h - state.delta_h;
|
||||||
!state.opened
|
!state.opened
|
||||||
|| v != 0
|
|| v != 0
|
||||||
|| delta.abs() > 3 * Self::expanded_size(state.effective_size, state.expansion)
|
|| matrix_changed
|
||||||
|
|| delta.abs() as f64 > 3.0 * state.xdv_size(state.effective_size)
|
||||||
} else {
|
} else {
|
||||||
v != 0 || shift.abs() >= 32768 || expansion_changed
|
v != 0 || shift.abs() >= 32768 || expansion_changed
|
||||||
};
|
};
|
||||||
if first || reset_line || space == Some(SpaceUse::Dedicated)
|
if first || reset_line || space == Some(SpaceUse::Dedicated)
|
||||||
{
|
{
|
||||||
state.close_string(out);
|
state.close_string(out);
|
||||||
if !state.xdv && (font.expansion != 0 || state.expansion != 0) {
|
if state.xdv && (matrix_changed || !state.xdv_matrix.is_identity()) {
|
||||||
|
let [extend, slant] = state.xdv_matrix.coefficients();
|
||||||
|
let [h, v] = out.origin.position();
|
||||||
|
if !out.measuring {
|
||||||
|
out.push_str(&format!(
|
||||||
|
"{extend:.5} 0 {slant:.5} 1 {} {} Tm\n",
|
||||||
|
print_sp(x - h, digits),
|
||||||
|
print_sp(height - y - v, digits),
|
||||||
|
));
|
||||||
|
}
|
||||||
|
state.start_h = x;
|
||||||
|
state.v = y;
|
||||||
|
} else if !state.xdv && (font.expansion != 0 || state.expansion != 0) {
|
||||||
let (h, h_out) = divide_scaled(x, 6_578_176, digits + 2);
|
let (h, h_out) = divide_scaled(x, 6_578_176, digits + 2);
|
||||||
let (v, v_out) = divide_scaled(height - y, 6_578_176, digits + 2);
|
let (v, v_out) = divide_scaled(height - y, 6_578_176, digits + 2);
|
||||||
if !out.measuring {
|
if !out.measuring {
|
||||||
@@ -190,6 +207,11 @@ impl NativeText {
|
|||||||
|
|
||||||
fn horizontal_move(&self, x: i64, size: i64) -> (i64, i64) {
|
fn horizontal_move(&self, x: i64, size: i64) -> (i64, i64) {
|
||||||
let delta = x - self.start_h - self.delta_h;
|
let delta = x - self.start_h - self.delta_h;
|
||||||
|
if self.xdv && !self.xdv_matrix.is_identity() {
|
||||||
|
let size = self.xdv_size(size);
|
||||||
|
let units = (delta as f64 * 1_000.0 / size) as i64;
|
||||||
|
return (units, (units as f64 * size / 1_000.0) as i64);
|
||||||
|
}
|
||||||
if self.xdv {
|
if self.xdv {
|
||||||
let size = Self::expanded_size(size, self.expansion);
|
let size = Self::expanded_size(size, self.expansion);
|
||||||
let units = delta * 1000 / size;
|
let units = delta * 1000 / size;
|
||||||
@@ -208,6 +230,10 @@ impl NativeText {
|
|||||||
value.signum() * ((value.abs() * multiplier + denominator / 2) / denominator)
|
value.signum() * ((value.abs() * multiplier + denominator / 2) / denominator)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn xdv_size(&self, size: i64) -> f64 {
|
||||||
|
Self::expanded_size(size, self.expansion) as f64 * self.xdv_matrix.coefficients()[0]
|
||||||
|
}
|
||||||
|
|
||||||
fn expanded_size(size: i64, expansion: i32) -> i64 {
|
fn expanded_size(size: i64, expansion: i32) -> i64 {
|
||||||
if expansion == 0 {
|
if expansion == 0 {
|
||||||
size
|
size
|
||||||
|
|||||||
@@ -164,6 +164,7 @@ struct NativeSvgGlyph<'a> {
|
|||||||
position: [i64; 2],
|
position: [i64; 2],
|
||||||
size: i64,
|
size: i64,
|
||||||
expansion: i32,
|
expansion: i32,
|
||||||
|
xdv_matrix: crate::native_font::XdvFontMatrix,
|
||||||
slot: u8,
|
slot: u8,
|
||||||
font: &'a str,
|
font: &'a str,
|
||||||
glyph: &'a str,
|
glyph: &'a str,
|
||||||
@@ -204,6 +205,7 @@ impl DisplayItem {
|
|||||||
position: [*x, *y],
|
position: [*x, *y],
|
||||||
size: *size,
|
size: *size,
|
||||||
expansion: font.expansion,
|
expansion: font.expansion,
|
||||||
|
xdv_matrix: paint.xdv_matrix,
|
||||||
slot: *slot,
|
slot: *slot,
|
||||||
font: paint.program.name(),
|
font: paint.program.name(),
|
||||||
glyph: &paint.encoding[usize::from(*slot)],
|
glyph: &paint.encoding[usize::from(*slot)],
|
||||||
@@ -549,6 +551,7 @@ impl DisplayList {
|
|||||||
position: [x, y],
|
position: [x, y],
|
||||||
size,
|
size,
|
||||||
expansion,
|
expansion,
|
||||||
|
xdv_matrix,
|
||||||
slot,
|
slot,
|
||||||
font,
|
font,
|
||||||
glyph,
|
glyph,
|
||||||
@@ -571,7 +574,27 @@ impl DisplayList {
|
|||||||
} else {
|
} else {
|
||||||
String::new()
|
String::new()
|
||||||
};
|
};
|
||||||
out.push_str(&format!("<g data-font=\"{}\" data-glyph=\"{}\" data-slot=\"{slot}\" aria-label=\"{}\"><path d=\"{}\" transform=\"translate({x:.5} {y:.5}) scale({horizontal_scale:.8} -{scale:.8})\" fill=\"#{:02x}{:02x}{:02x}\"{fill_opacity}/></g>\n", escape(font), escape(glyph), escape(&label), path, fill[0],fill[1],fill[2]));
|
use std::fmt::Write as _;
|
||||||
|
write!(
|
||||||
|
out,
|
||||||
|
"<g data-font=\"{}\" data-glyph=\"{}\" data-slot=\"{slot}\" aria-label=\"{}\"><path d=\"{}\" transform=\"",
|
||||||
|
escape(font), escape(glyph), escape(&label), path,
|
||||||
|
).unwrap();
|
||||||
|
if xdv_matrix.is_identity() {
|
||||||
|
write!(out, "translate({x:.5} {y:.5}) scale({horizontal_scale:.8} -{scale:.8})").unwrap();
|
||||||
|
} else {
|
||||||
|
let [extend, slant] = xdv_matrix.coefficients();
|
||||||
|
write!(
|
||||||
|
out,
|
||||||
|
"matrix({:.8} 0 {:.8} -{scale:.8} {x:.5} {y:.5})",
|
||||||
|
horizontal_scale * extend,
|
||||||
|
scale * slant,
|
||||||
|
).unwrap();
|
||||||
|
}
|
||||||
|
writeln!(
|
||||||
|
out, "\" fill=\"#{:02x}{:02x}{:02x}\"{fill_opacity}/></g>",
|
||||||
|
fill[0], fill[1], fill[2],
|
||||||
|
).unwrap();
|
||||||
}
|
}
|
||||||
DisplayItem::OpenTypeGlyph { x, y, size, font, glyph, text, .. } => {
|
DisplayItem::OpenTypeGlyph { x, y, size, font, glyph, text, .. } => {
|
||||||
let face = match opentype_faces.entry(font.id) {
|
let face = match opentype_faces.entry(font.id) {
|
||||||
|
|||||||
@@ -1258,3 +1258,74 @@ fn xdv_name_trees_keep_binary_keys_and_share_the_catalog_root() {
|
|||||||
assert_eq!(resolve(&ap[1]).as_dict().unwrap().get(b"Proof").unwrap().as_str().unwrap(), b"shared");
|
assert_eq!(resolve(&ap[1]).as_dict().unwrap().get(b"Proof").unwrap().as_str().unwrap(), b"shared");
|
||||||
assert!(output.diagnostics.iter().any(|message| message.contains("Object @mixed already defined.")));
|
assert!(output.diagnostics.iter().any(|message| message.contains("Object @mixed already defined.")));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn xdv_font_map_changes_apply_at_shipout_and_keep_loaded_programs() {
|
||||||
|
use sha2::{Digest, Sha256};
|
||||||
|
use std::path::PathBuf;
|
||||||
|
use texrra_tex_core::native_font::resolve_native_fonts;
|
||||||
|
use texrra_tex_core::render::DisplayItem;
|
||||||
|
use texrra_tex_core::resources::{LoadedResource, ResourceKind, ResourceVersion};
|
||||||
|
|
||||||
|
fn loaded(path: PathBuf, data: Vec<u8>) -> LoadedResource {
|
||||||
|
let sha256 = format!("{:x}", Sha256::digest(&data));
|
||||||
|
LoadedResource { version: ResourceVersion { path, sha256, bytes: data.len() as u64 }, data }
|
||||||
|
}
|
||||||
|
|
||||||
|
struct Fonts {
|
||||||
|
metric: Vec<u8>,
|
||||||
|
roman: LoadedResource,
|
||||||
|
italic: LoadedResource,
|
||||||
|
}
|
||||||
|
impl SourceProvider for Fonts {
|
||||||
|
fn read(&mut self, name: &str, _: &str) -> Result<SourceFile, String> {
|
||||||
|
Err(format!("unexpected input {name}"))
|
||||||
|
}
|
||||||
|
fn default_pk_resolution(&mut self) -> Result<i32, String> {
|
||||||
|
Ok(600)
|
||||||
|
}
|
||||||
|
fn resource(&mut self, kind: ResourceKind, name: &str, _: &str) -> Result<LoadedResource, String> {
|
||||||
|
match (kind, name) {
|
||||||
|
(ResourceKind::Tfm, "mapped.tfm" | "transformed.tfm" | "later.tfm") => {
|
||||||
|
Ok(loaded(PathBuf::from(name), self.metric.clone()))
|
||||||
|
}
|
||||||
|
(ResourceKind::Type1, "cmr10.pfb") => Ok(LoadedResource { version: self.roman.version.clone(), data: self.roman.data.clone() }),
|
||||||
|
(ResourceKind::Type1, "cmti10.pfb") => Ok(LoadedResource { version: self.italic.version.clone(), data: self.italic.data.clone() }),
|
||||||
|
_ => Err(format!("unexpected font resource {kind:?} {name}")),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fn optional_font_map(&mut self, name: &str, _: &str) -> Result<Option<LoadedResource>, String> {
|
||||||
|
Ok((name == "local.map").then(|| loaded(
|
||||||
|
name.into(), b"mapped CMTI10 <cmti10.pfb\nlater CMTI10 <cmti10.pfb\n".to_vec(),
|
||||||
|
)))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut files = Fonts {
|
||||||
|
metric: include_bytes!("../assets/cmr10.tfm").to_vec(),
|
||||||
|
roman: loaded("cmr10.pfb".into(), include_bytes!("../../../assets/fonts/cmr10.pfb").to_vec()),
|
||||||
|
italic: loaded("cmti10.pfb".into(), include_bytes!("../../../assets/fonts/cmti10.pfb").to_vec()),
|
||||||
|
};
|
||||||
|
let state = State::initex().with_etex().with_input_profile(InputProfile::XeTeX);
|
||||||
|
let execution = Executor::new(state, Limits::default()).with_native_pages().run(
|
||||||
|
source(r"\catcode123=1 \catcode125=2
|
||||||
|
\font\old=mapped at10pt \font\new=mapped at12pt
|
||||||
|
\font\later=later at10pt \font\matrix=transformed at10pt
|
||||||
|
\setbox0=\hbox{\special{pdf:mapline later CMR10 <cmr10.pfb}}
|
||||||
|
\shipout\hbox{\special{pdf:mapline +mapped CMR10 <cmr10.pfb}\old A}
|
||||||
|
\shipout\hbox{\special{pdf:mapfile local.map}\new A\later A}
|
||||||
|
\shipout\hbox{\special{pdf:mapline transformed default cmr10.pfb -s 0.18 -e 1.2}\matrix A}
|
||||||
|
\end"),
|
||||||
|
&mut files,
|
||||||
|
).unwrap();
|
||||||
|
let mut pages = execution.shipout_display_lists().unwrap();
|
||||||
|
resolve_native_fonts(&mut pages, &mut files).unwrap();
|
||||||
|
let programs: Vec<Vec<_>> = pages.iter().map(|page| {
|
||||||
|
page.items.iter().filter_map(|item| match item {
|
||||||
|
DisplayItem::NativeGlyph { paint: Some(paint), .. } => Some(paint.program.name()),
|
||||||
|
_ => None,
|
||||||
|
}).collect()
|
||||||
|
}).collect();
|
||||||
|
assert_eq!(programs, [vec!["CMR10"], vec!["CMR10", "CMTI10"], vec!["CMR10"]]);
|
||||||
|
assert!(pages[2].try_to_svg().unwrap().contains("matrix(0.01200000 0 0.00180000 -0.01000000"));
|
||||||
|
}
|
||||||
@@ -18,6 +18,40 @@
|
|||||||
| W6 会话 | 实施中 | 共享库/CLI 与当前原生文字/数学/规则来源进入公共结果;真实 A4 副本九类/27 revision 与独立干净作业页面/PDF/aux/映射一致,新增数学场景独立参考通过;详细失败/捕获重放及宿主/离线/CLI观察已通过;原子项目版本/已知生成初态及TeX流记录已接通;完整副作用/恢复契约、旧来源和性能仍缺 |
|
| W6 会话 | 实施中 | 共享库/CLI 与当前原生文字/数学/规则来源进入公共结果;真实 A4 副本九类/27 revision 与独立干净作业页面/PDF/aux/映射一致,新增数学场景独立参考通过;详细失败/捕获重放及宿主/离线/CLI观察已通过;原子项目版本/已知生成初态及TeX流记录已接通;完整副作用/恢复契约、旧来源和性能仍缺 |
|
||||||
| W7 总验收 | 未满足 | 原有和新增测试、原样项目、格式与会话门禁全部通过才能结项 |
|
| W7 总验收 | 未满足 | 原有和新增测试、原样项目、格式与会话门禁全部通过才能结项 |
|
||||||
|
|
||||||
|
## 2026-11-28 XeLaTeX 出页字体映射与资源失效
|
||||||
|
|
||||||
|
`pdf:mapfile` 和 `pdf:mapline` 按实际出页顺序追加、替换、删除
|
||||||
|
作业映射。已使用的可缩放字体按设备名称保留其物理程序,后续
|
||||||
|
字号读取当时的文字矩阵。常用 dvips 和 dvipdfm 映射接入真实
|
||||||
|
TFM、轮廓文件和 PDF/SVG。XeLaTeX 映射的倾斜与扩展作用于
|
||||||
|
文字矩阵,pdfTeX 命令沿用其字体程序变换。
|
||||||
|
[参考映射语法](https://raw.githubusercontent.com/TeX-Live/texlive-source/e49735c7ed1aa2ed9c2e68e6632d27f20d42eca7/texk/dvipdfm-x/fontmap.c)
|
||||||
|
[参考字体复用](https://raw.githubusercontent.com/TeX-Live/texlive-source/e49735c7ed1aa2ed9c2e68e6632d27f20d42eca7/texk/dvipdfm-x/pdffont.c)
|
||||||
|
|
||||||
|
两组直接对照合计六页,覆盖跨页绑定、文件与行的删除后追加、
|
||||||
|
替换前后字号以及倾斜与扩展。原版 article.cls、hyperref.sty
|
||||||
|
通过格式提供的 `\pdfmapfile` 嵌入实际 CMR10,两页彩色输出
|
||||||
|
及辅助文件与参考一致。三份 PDF 的字体类型、嵌入和编码一致。八页中七页 144 DPI 彩色逐像素相同。余下一页的 43 个差异
|
||||||
|
像素由上一版同字体复现。参考 XDV 在差异位置多推进 3 sp,跨过一处字距
|
||||||
|
舍入阈值,原始对照继续保留。开发构建、十三项 XDV 与一项
|
||||||
|
旧字体映射定向回归通过。另一个旧子集名断言仍报告失败,
|
||||||
|
同一真实用例的 unicode 与 tex8bit 两个入口分别与上一版
|
||||||
|
PDF 和测量列表逐字节一致。
|
||||||
|
|
||||||
|
三页会话的字体映射、实际 PFB 内容及恢复修订均只更新第 2 页。
|
||||||
|
四个成功修订的 PDF、测量页、SVG、来源映射和 aux 与独立全量
|
||||||
|
相同。映射和字体负载改动分别复用 135 和 1,648 步。字体
|
||||||
|
缺失时继续保留上次发布的结果。
|
||||||
|
|
||||||
|
回执在 `target/p3-xdv-font-maps/receipt.json`,SHA-256 为
|
||||||
|
`0f2875d326f118a8fea6b5ae59e8b8477f0f56968c76cd2ef036abb38ef1fc39`。
|
||||||
|
下一批从实际 CMap 数据入手,合并处理 `pdf:tounicode` 与字体映射
|
||||||
|
的 Unicode 转换、复合编码及资源跟踪。样例与参考位于
|
||||||
|
`target/p3-xdv-unicode-mapping`,原始 90ms-RKSJ-UCS2 映射
|
||||||
|
将文档标题、注释、书签与指定字段转换至 UTF-16,保留私有数据
|
||||||
|
字节。原生当前停在 `pdf:tounicode`。完整两种 profile、原样出版
|
||||||
|
矩阵和 100 ms 可见时延按原门槛统一验收。
|
||||||
|
|
||||||
## 2026-11-28 XeLaTeX PDF 名称树与附件
|
## 2026-11-28 XeLaTeX PDF 名称树与附件
|
||||||
|
|
||||||
`pdf:names` 接入原生出页,支持单个名称和成对数组。二进制键按
|
`pdf:names` 接入原生出页,支持单个名称和成对数组。二进制键按
|
||||||
|
|||||||
Reference in new issue
Block a user