Skip to main content

has_appearance

Function has_appearance 

Source
pub fn has_appearance<R: Resolve>(dict: &Dict, r: &R) -> bool
Expand description

Whether an annotation already carries a usable normal appearance.

The test is that /AP /N reads as a dictionary — and a stream answers with its own dictionary, so the overwhelmingly common “a stream is there” case suppresses generation just as a multi-state dictionary does. Only a missing /AP, a missing /N, or a scalar /N leaves the door open.

use pdfrum_doc::annot::{ApMode, annot_ap, has_appearance};
use pdfrum_object::{ByteSpan, Dict, Name, NoResolve, Object, Stream};

let normal = Stream::new(Dict::default(), ByteSpan::whole(b"0 0 10 10 re f".as_slice().into()));
let annot = Dict::from_pairs([(
    Name::from("AP"),
    Object::Dict(Dict::from_pairs([(
        Name::from("N"),
        Object::Stream(Box::new(normal)),
    )])),
)]);

assert!(has_appearance(&annot, &NoResolve));
assert!(!has_appearance(&Dict::default(), &NoResolve));