Skip to main content

overlay_except

Function overlay_except 

Source
pub fn overlay_except<R: Resolve>(
    page: &mut Page,
    page_dict: &Dict,
    catalog: &Dict,
    r: &R,
    ctx: &mut BuildContext,
    limits: &Limits,
    diags: &mut Diagnostics,
    omit: &[ObjRef],
)
Expand description

The same pass as overlay, leaving the named annotation objects out.

A viewer that edits an existing annotation draws it itself while it is being edited, and needs the page without it underneath. omit lists the annotation objects not to draw; an entry of /Annots is matched when it is an indirect reference to one of them. An annotation written inline in the array has no reference to name and so cannot be left out.

An omitted annotation is skipped whole: no appearance, no generated appearance, and none of the widget highlight that would follow it. An empty omit is exactly overlay, down to the operators emitted.

use pdfrum_common::{Diagnostics, Limits};
use pdfrum_doc::annot_render::{overlay, overlay_except};
use pdfrum_object::{Array, Dict, Name, Object};
use pdfrum_page::{BuildContext, Page};

let nums = |v: &[i64]| Object::Array(Array::from_iter(v.iter().map(|&n| Object::Int(n))));
let square = Dict::from_pairs([
    (Name::from("Subtype"), Object::Name(Name::from("Square"))),
    (Name::from("Rect"), nums(&[10, 10, 90, 60])),
    (Name::from("C"), nums(&[1, 0, 0])),
]);
let store = Store(HashMap::from([(5, Arc::new(Object::Dict(square)))]));
let annot = ObjRef::new(5, 0);
let page_dict = Dict::from_pairs([(
    Name::from("Annots"),
    Object::Array(Array::from_iter([Object::Ref(annot)])),
)]);
let draw = |omit: &[ObjRef]| {
    let mut page = Page::empty();
    let (mut ctx, mut diags) = (BuildContext::new(), Diagnostics::default());
    let catalog = Dict::default();
    let limits = Limits::default();
    if omit.is_empty() {
        overlay(&mut page, &page_dict, &catalog, &store, &mut ctx, &limits, &mut diags);
    } else {
        overlay_except(&mut page, &page_dict, &catalog, &store, &mut ctx, &limits, &mut diags, omit);
    }
    page.objects.len()
};
// The square is drawn, and left out when it is named.
assert!(draw(&[]) > 0);
assert_eq!(draw(&[annot]), 0);