Allocate dedicated PDF spaces in the native font catalog at shipout
This commit is contained in:
1 parent
4bd7f1e08e
commit
584b708487
11 files changed
+339
-93
No files matched your search
@@ -13,6 +13,7 @@ use std::{
|
||||
sync::{Arc, Mutex},
|
||||
};
|
||||
mod virtual_paint;
|
||||
pub(crate) use virtual_paint::VirtualPaintState;
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize)]
|
||||
pub struct NativeFontPaint {
|
||||
@@ -69,6 +70,8 @@ pub struct NativeFont {
|
||||
pub expansion: i32,
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub letter_spacing: Option<LetterspaceProgram>,
|
||||
#[serde(default, skip_serializing_if = "std::ops::Not::not")]
|
||||
pub(crate) pdf_space_font: bool,
|
||||
}
|
||||
|
||||
/// Virtual character packets use the selected font and an encoded right move.
|
||||
@@ -233,7 +236,6 @@ fn verify_resource(
|
||||
Ok(resource)
|
||||
}
|
||||
|
||||
const SPACE_FONT_ID: u32 = u32::MAX;
|
||||
const MAX_TYPE1_PROGRAMS: usize = 16;
|
||||
const MAX_CACHED_PFB_BYTES: usize = 256 * 1024;
|
||||
|
||||
@@ -301,7 +303,8 @@ impl NativeFontCache {
|
||||
pages: &mut [crate::render::DisplayList],
|
||||
files: &mut impl crate::execution::SourceProvider,
|
||||
) -> Result<(), String> {
|
||||
let expanded = virtual_paint::expand_pages(pages, files)?;
|
||||
let mut virtuals = virtual_paint::VirtualPaintState::default();
|
||||
let expanded = virtual_paint::expand_pages(&mut virtuals, pages, files)?;
|
||||
if expanded.is_none() && !pages.iter().any(|page| page.pdf_text_spaces.is_some()) {
|
||||
return resolve_physical_fonts(pages, files, self);
|
||||
}
|
||||
@@ -316,27 +319,28 @@ impl NativeFontCache {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn space_font(
|
||||
pub(crate) fn resolve_space_probe(
|
||||
&self,
|
||||
request: &crate::pdf_device::text_spaces::SpaceFontRequest,
|
||||
pages: &mut [crate::render::DisplayList],
|
||||
virtuals: &mut VirtualPaintState,
|
||||
files: &mut impl crate::execution::SourceProvider,
|
||||
) -> Result<(), String> {
|
||||
if let Some(expanded) = virtual_paint::expand_pages(virtuals, pages, files)? {
|
||||
for (original, expanded) in pages.iter_mut().zip(expanded) {
|
||||
*original = expanded;
|
||||
}
|
||||
}
|
||||
resolve_physical_fonts(pages, files, self)
|
||||
}
|
||||
|
||||
pub(crate) fn space_font(
|
||||
&self,
|
||||
font: Arc<NativeFont>,
|
||||
device: Option<crate::pdf_device::PdfPageData>,
|
||||
files: &mut impl crate::execution::SourceProvider,
|
||||
) -> Result<crate::pdf_device::text_spaces::ResolvedSpaceFont, String> {
|
||||
use crate::execution::{CommandName, FontCatalog, FontIntegers};
|
||||
use crate::pdf_device::text_spaces::ResolvedSpaceFont;
|
||||
use crate::render::{DisplayItem, DisplayList, DisplayUnits};
|
||||
let mut catalog = FontCatalog::default();
|
||||
let id = catalog.load(
|
||||
files,
|
||||
&request.name,
|
||||
&request.from,
|
||||
crate::tfm::FontSize::Design,
|
||||
CommandName::Control(String::new()),
|
||||
FontIntegers { hyphen: 45, skew: -1 },
|
||||
)?;
|
||||
let mut font = (**catalog.glyph_font(id)?).clone();
|
||||
font.id = FontId::for_device(SPACE_FONT_ID);
|
||||
let font = Arc::new(font);
|
||||
let mut page = DisplayList {
|
||||
units: DisplayUnits::TeX,
|
||||
pdf: device,
|
||||
@@ -406,7 +410,7 @@ fn resolve_physical_fonts(
|
||||
.map(|p| p.file.clone());
|
||||
let mut cache: BTreeMap<_, (NativeFontPaint, Arc<DecodedType1>)> = BTreeMap::new();
|
||||
for (id, (font, slots)) in used {
|
||||
let entry = if id.index() == SPACE_FONT_ID && font.name == "pdftexspace" {
|
||||
let entry = if font.pdf_space_font && font.name == "pdftexspace" {
|
||||
// The pdfTeX device adds its own map entry on first use.
|
||||
Some(MapEntry { file: "pdftexspace.pfb".into(), encoding: None })
|
||||
} else {
|
||||
|
||||
Reference in new issue
Block a user