Write PDF interword spaces with actual device fonts
This commit is contained in:
1 parent
b93d5f55da
commit
514a2d3344
24 files changed
+664
-65
No files matched your search
@@ -69,6 +69,35 @@ impl Executor {
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
pub(super) fn scan_pdf_space(
|
||||
&mut self,
|
||||
command: Primitive,
|
||||
span: Span,
|
||||
files: &mut impl SourceProvider,
|
||||
) -> Result<(), Error> {
|
||||
use crate::pdf_device::text_spaces::{SpaceFontRequest, SpaceOperation};
|
||||
if self.read_parameter(Parameter::Pdfoutput).width() <= 0 {
|
||||
return self.fail("PDF text space operation not allowed in DVI mode");
|
||||
}
|
||||
let operation = match command {
|
||||
Primitive::Pdfspacefont => {
|
||||
let tokens = self.scan_expanded_group(files)?;
|
||||
self.pdf_space_font = Some(SpaceFontRequest {
|
||||
name: self.token_list_text(&tokens),
|
||||
from: self.source_name(span),
|
||||
});
|
||||
return Ok(());
|
||||
}
|
||||
Primitive::Pdfinterwordspaceon => SpaceOperation::Automatic(true),
|
||||
Primitive::Pdfinterwordspaceoff => SpaceOperation::Automatic(false),
|
||||
Primitive::Pdffakespace => SpaceOperation::Explicit,
|
||||
_ => unreachable!(),
|
||||
};
|
||||
self.defer_output(OutputNode {
|
||||
operation: OutputOperation::PdfTextSpace(operation),
|
||||
span,
|
||||
})
|
||||
}
|
||||
pub(super) fn pdf_page_data(
|
||||
&mut self,
|
||||
files: &mut impl SourceProvider,
|
||||
|
||||
@@ -550,6 +550,7 @@ impl Executor {
|
||||
| Closeout | Write | Pdfcolorstack | Pdfsave | Pdfsetmatrix | Pdfrestore | Pdfcatalog | Pdfoutline
|
||||
| Pdfglyphtounicode | Pdffontattr | Pdfnobuiltintounicode
|
||||
| Pdfrunninglinkoff | Pdfrunninglinkon
|
||||
| Pdfinterwordspaceon | Pdfinterwordspaceoff | Pdffakespace | Pdfspacefont
|
||||
| Ignorespaces | Unskip | Unkern | Unpenalty => {
|
||||
return Ok(false);
|
||||
}
|
||||
|
||||
@@ -310,6 +310,10 @@ impl Executor {
|
||||
} else {
|
||||
Vec::new().into_iter()
|
||||
};
|
||||
use crate::pdf_device::text_spaces::{SpaceFontRequest, SpaceOperation, SpaceSettings};
|
||||
let automatic_spaces_at_start = self.pdf_interword_spaces;
|
||||
let mut uses_automatic_spaces = automatic_spaces_at_start;
|
||||
let mut has_space_nodes = false;
|
||||
let mut pdf_objects = Vec::new();
|
||||
for output in outputs {
|
||||
if let OutputOperation::PdfObject(number) = output.operation {
|
||||
@@ -337,6 +341,17 @@ impl Executor {
|
||||
&mut graphics_stack,
|
||||
files,
|
||||
)?);
|
||||
} else if let OutputOperation::PdfTextSpace(operation) = output.operation {
|
||||
self.current = output.span;
|
||||
self.tick()?;
|
||||
if device.pdf.is_none() {
|
||||
return self.fail("cannot ship a PDF text space operation to DVI");
|
||||
}
|
||||
has_space_nodes = true;
|
||||
if let SpaceOperation::Automatic(enabled) = operation {
|
||||
self.pdf_interword_spaces = enabled;
|
||||
uses_automatic_spaces |= enabled;
|
||||
}
|
||||
} else if let OutputOperation::PdfLink(link) = &output.operation {
|
||||
use crate::pdf_device::links::LinkNode;
|
||||
self.current = output.span;
|
||||
@@ -380,6 +395,25 @@ impl Executor {
|
||||
} else {
|
||||
Default::default()
|
||||
};
|
||||
let pdf_text_spaces = (has_space_nodes || automatic_spaces_at_start).then(|| {
|
||||
let parameters = if uses_automatic_spaces {
|
||||
self.reads.insert(Dependency::FontResources);
|
||||
self.state.fonts.fonts().iter().map(|font| {
|
||||
let glue = font.space();
|
||||
(glue.width, glue.shrink.amount)
|
||||
}).collect()
|
||||
} else {
|
||||
Vec::new()
|
||||
};
|
||||
SpaceSettings {
|
||||
automatic_at_start: automatic_spaces_at_start,
|
||||
font: self.pdf_space_font.clone().unwrap_or_else(|| SpaceFontRequest {
|
||||
name: "pdftexspace".into(),
|
||||
from: self.source_name(current),
|
||||
}),
|
||||
parameters,
|
||||
}
|
||||
});
|
||||
self.current = current;
|
||||
self.native_page.as_mut().unwrap().dead_cycles = 0;
|
||||
let before = self.statistics_before_shipout(&b, files)?;
|
||||
@@ -390,6 +424,7 @@ impl Executor {
|
||||
pdf_color_start,
|
||||
pdf_color_steps,
|
||||
pdf_graphics_steps,
|
||||
pdf_text_spaces,
|
||||
pdf_resource_entries,
|
||||
pdf_links,
|
||||
})));
|
||||
|
||||
Reference in new issue
Block a user