Support scoped XeTeX OpenType colors in PDF and SVG
This commit is contained in:
1 parent
5a4271364a
commit
a0922d0105
10 files changed
+183
-16
No files matched your search
@@ -697,6 +697,7 @@ fn page_content(
|
||||
fallback_ids: &[usize; FACE_COUNT],
|
||||
origin: PageOrigin,
|
||||
opentype: &BTreeMap<crate::execution::FontId, opentype_fonts::EmbeddedFont>,
|
||||
font_opacities: &BTreeMap<u8, String>,
|
||||
) -> Vec<u8> {
|
||||
let digits = list.pdf.as_ref().map_or(3, |p| p.file.decimal_digits);
|
||||
let pt = |n: i64| {
|
||||
@@ -863,11 +864,22 @@ fn page_content(
|
||||
Some(text) => opentype_fonts::begin_actual_text(&mut content, text, true),
|
||||
None => content.push_str("EMC\n"),
|
||||
},
|
||||
DisplayItem::OpenTypeColor(color) => {
|
||||
if let Some([r, g, b, alpha]) = color {
|
||||
let [r, g, b] = [*r, *g, *b].map(|channel| f64::from(channel) / 255.);
|
||||
let opacity = &font_opacities[alpha];
|
||||
content.push_str(&format!(
|
||||
"q {r:.3} {g:.3} {b:.3} RG {r:.3} {g:.3} {b:.3} rg /{opacity} gs\n",
|
||||
));
|
||||
} else {
|
||||
content.push_str("Q\n");
|
||||
}
|
||||
}
|
||||
DisplayItem::OpenTypeGlyph { x, y, size, font, glyph, text, .. } => {
|
||||
opentype[&font.id].paint(
|
||||
&mut opentype_text, &mut content, font, *glyph, text,
|
||||
*size, *x - h, height - *y - v, bp_per_unit,
|
||||
[one_inch - h, height - one_inch - v],
|
||||
[one_inch - h, height - one_inch - v], !font_opacities.is_empty(),
|
||||
);
|
||||
}
|
||||
DisplayItem::NativeGlyph {
|
||||
@@ -2299,6 +2311,15 @@ fn write_pdf(
|
||||
font_ids[slot] = write_type0_font(&mut objects, face, slot, &used_chars[slot]);
|
||||
}
|
||||
|
||||
let resources = if resources.is_none() && pages.iter().any(|page| {
|
||||
page.items.iter().any(|item| matches!(item, DisplayItem::OpenTypeColor(Some(_))))
|
||||
}) {
|
||||
Some(crate::pdf_device::page_resources::ResourceOutput::prepare(
|
||||
pages, None, BTreeMap::new(), &[], None, None,
|
||||
)?)
|
||||
} else {
|
||||
resources
|
||||
};
|
||||
let remapped = resources.map(|resources| resources.append(&mut objects, diagnostics));
|
||||
if let Some(resources) = &remapped {
|
||||
for (font, entries) in &resources.fonts {
|
||||
@@ -2522,6 +2543,10 @@ fn write_pdf(
|
||||
for (index, slot) in &used {
|
||||
names.insert(*index, format!("Im{slot}"));
|
||||
}
|
||||
let no_font_opacity = BTreeMap::new();
|
||||
let font_opacities = remapped.as_ref().map_or(
|
||||
&no_font_opacity, |resources| &resources.font_opacities[page_index],
|
||||
);
|
||||
let content = page_content(
|
||||
list,
|
||||
height,
|
||||
@@ -2531,6 +2556,7 @@ fn write_pdf(
|
||||
&fallback_font_ids,
|
||||
origin,
|
||||
&opentype,
|
||||
font_opacities,
|
||||
);
|
||||
objects.push(objects::stream(
|
||||
"",
|
||||
|
||||
Reference in new issue
Block a user