Track PDF literal transforms in native source maps
This commit is contained in:
1 parent
d46d6d79a8
commit
7f74251c8a
9 files changed
+303
-22
No files matched your search
@@ -11,6 +11,8 @@ use crate::{
|
||||
render::{DisplayItem, DisplayList, DisplayUnits},
|
||||
};
|
||||
use sha2::{Digest, Sha256};
|
||||
mod pdf_projection;
|
||||
use pdf_projection::PdfProjection;
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
|
||||
pub enum SourceKind {
|
||||
@@ -296,8 +298,15 @@ impl SourceMap {
|
||||
};
|
||||
let mut transform = Affine::IDENTITY;
|
||||
let mut graphics_stack = Vec::new();
|
||||
let mut pdf_projection = PdfProjection::for_page(page);
|
||||
for (item_index, item) in page.items.iter().enumerate() {
|
||||
let placement = pdf_projection
|
||||
.as_mut()
|
||||
.map_or(Some(transform), |projection| projection.observe(item));
|
||||
if let DisplayItem::PdfGraphics { x, y, operation } = item {
|
||||
if pdf_projection.is_some() {
|
||||
continue;
|
||||
}
|
||||
match operation {
|
||||
PdfGraphics::Literal { .. } => {}
|
||||
PdfGraphics::Save => graphics_stack.push(transform),
|
||||
@@ -403,16 +412,17 @@ impl SourceMap {
|
||||
page.sources
|
||||
.get(&item_index)
|
||||
.filter(|s| !s.tokens.is_empty()),
|
||||
placement,
|
||||
) {
|
||||
(Some((kind, bounds)), Some(source)) => map.entries.push(MappedPaint {
|
||||
(Some((kind, bounds)), Some(source), Some(transform)) => map.entries.push(MappedPaint {
|
||||
item_index,
|
||||
kind,
|
||||
bounds: bounds.transformed(transform)?,
|
||||
source: source.clone(),
|
||||
}),
|
||||
(geometry, _) => map.unmapped.push(UnmappedPaint {
|
||||
(geometry, _, placement) => map.unmapped.push(UnmappedPaint {
|
||||
item_index,
|
||||
reason: if geometry.is_some() {
|
||||
reason: if geometry.is_some() && placement.is_some() {
|
||||
UnmappedReason::MissingProvenance
|
||||
} else {
|
||||
UnmappedReason::UnsupportedPrimitive
|
||||
|
||||
Reference in new issue
Block a user