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
@@ -210,8 +210,8 @@ impl NativeText {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
pub(super) struct FontHistory {
|
||||
#[derive(Clone, Default)]
|
||||
pub(crate) struct FontHistory {
|
||||
used: BTreeSet<FontId>,
|
||||
first_scalable: BTreeMap<String, FontId>,
|
||||
}
|
||||
@@ -239,11 +239,12 @@ impl FontHistory {
|
||||
}
|
||||
|
||||
/// Determine real font use with the same text moves used by the PDF writer.
|
||||
pub(super) fn plan_spaces(
|
||||
/// A probe returns None as soon as it would first load the dedicated font.
|
||||
pub(crate) fn plan_spaces(
|
||||
page: &DisplayList,
|
||||
fonts: &mut FontHistory,
|
||||
load: impl FnOnce() -> Result<ResolvedSpaceFont, String>,
|
||||
) -> Result<SpacePlan, String> {
|
||||
load: impl FnOnce() -> Result<Option<ResolvedSpaceFont>, String>,
|
||||
) -> Result<Option<SpacePlan>, String> {
|
||||
let Some(settings) = &page.pdf_text_spaces else {
|
||||
for item in &page.items {
|
||||
if let DisplayItem::NativeGlyph {
|
||||
@@ -255,7 +256,7 @@ pub(super) fn plan_spaces(
|
||||
fonts.record(font, paint);
|
||||
}
|
||||
}
|
||||
return Ok(SpacePlan::default());
|
||||
return Ok(Some(SpacePlan::default()));
|
||||
};
|
||||
let digits = page.pdf.as_ref().map_or(3, |pdf| pdf.file.decimal_digits);
|
||||
let mut automatic = settings.automatic_at_start;
|
||||
@@ -277,7 +278,10 @@ pub(super) fn plan_spaces(
|
||||
operation: SpaceOperation::Explicit,
|
||||
} => {
|
||||
if plan.dedicated.is_none() {
|
||||
plan.dedicated = Some(load.take().expect("space font loader used once")()?);
|
||||
let Some(font) = load.take().expect("space font loader used once")()? else {
|
||||
return Ok(None);
|
||||
};
|
||||
plan.dedicated = Some(font);
|
||||
}
|
||||
let dedicated = plan.dedicated.as_ref().unwrap();
|
||||
fonts.record(&dedicated.font, &dedicated.paint);
|
||||
@@ -342,8 +346,10 @@ pub(super) fn plan_spaces(
|
||||
} else {
|
||||
space = Some(SpaceUse::Dedicated);
|
||||
if plan.dedicated.is_none() {
|
||||
plan.dedicated =
|
||||
Some(load.take().expect("space font loader used once")()?);
|
||||
let Some(font) = load.take().expect("space font loader used once")()? else {
|
||||
return Ok(None);
|
||||
};
|
||||
plan.dedicated = Some(font);
|
||||
}
|
||||
let dedicated = plan.dedicated.as_ref().unwrap();
|
||||
fonts.record(&dedicated.font, &dedicated.paint);
|
||||
@@ -380,7 +386,7 @@ pub(super) fn plan_spaces(
|
||||
_ => NativeText::finish(&mut text, &mut out),
|
||||
}
|
||||
}
|
||||
Ok(plan)
|
||||
Ok(Some(plan))
|
||||
}
|
||||
|
||||
pub(super) fn rule(
|
||||
|
||||
Reference in new issue
Block a user