1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
// stet-pdf-reader
// Copyright (c) 2026 Scott Bowman
// SPDX-License-Identifier: Apache-2.0 OR MIT
//! PDF Optional Content (layers).
//!
//! Layers — formally Optional Content Groups (OCGs) in ISO 32000-2
//! §8.11 — let a PDF mark slices of its content for selective
//! visibility: CAD layers, watermarks, multilingual annotations,
//! print-only or screen-only overlays, and so on.
//!
//! This module exposes the read-only metadata side of the OCG model:
//!
//! - One [`Layer`] per OCG, carrying the layer's name, intent, lock
//! state, default visibility, full `/Usage` sub-dict, and any
//! `/CreatorInfo` hint.
//!
//! Hierarchy (`/Order`), alternate configurations, runtime visibility
//! overrides, OCMD policies, and `/AS` automatic-state rules land in
//! later phases. Phase 1 is just the per-layer record so consumers can
//! enumerate what a document contains.
//!
//! # Quick reference
//!
//! ```no_run
//! use stet_pdf_reader::PdfDocument;
//!
//! let data = std::fs::read("layered.pdf")?;
//! let doc = PdfDocument::from_bytes(&data)?;
//!
//! for layer in doc.layers() {
//! println!(
//! "{} (id={}, locked={}, default_visible={})",
//! layer.name, layer.ocg_id, layer.locked, layer.default_visible
//! );
//! }
//! # Ok::<(), Box<dyn std::error::Error>>(())
//! ```
pub use ;
pub use ;
// Re-export the underlying renderer types so consumers don't have to
// reach into `stet-graphics` to construct visibility predicates.
pub use ;
pub use LayerSet;
use cratePdfDocument;
/// Which audience a render is for.
///
/// Drives [`PdfDocument::layer_set_for`]: the resulting [`LayerSet`]
/// has every `/AS` automatic-state rule whose `/Event` matches this
/// intent applied on top of the default-configuration starting point.
///
/// PDF authors use this to hide print-only watermarks during
/// interactive viewing, or to surface annotations only for export.
/// Build a [`LayerSet`] that reflects the document's default
/// configuration with every `/AS` automatic-state rule for the given
/// [`RenderIntent`] applied.
///
/// Algorithm:
///
/// 1. Start from [`layer_set_from_document`].
/// 2. For each auto-state rule on the default configuration whose
/// `/Event` matches the requested intent:
/// - For each OCG listed in the rule's `/OCGs`:
/// - For each `/Category` in the rule:
/// - If that category's `/Usage` sub-dict on the OCG
/// carries an explicit ON/OFF state, override that
/// OCG's entry in the LayerSet.
///
/// PDF spec doesn't define precedence when multiple rules touch the
/// same OCG; this implementation is **last-wins** in the order rules
/// appear in `/AS`.
///
/// Layers carrying `/Usage` hints with **no** matching `/AS` rule are
/// untouched — by spec their hints are informational only, not
/// auto-applied. Some viewers heuristically apply them anyway; stet
/// does not.
/// Look up an OCG's `/Usage` sub-dict for the given `/Category` name
/// and return its ON/OFF state, if it carries one. Categories that
/// don't carry a state (Zoom, Language, User, PageElement,
/// CreatorInfo) return `None` and are silently skipped by
/// [`layer_set_for`].
/// Build a [`LayerSet`] populated from a [`PdfDocument`]'s default
/// configuration (`/OCProperties /D`).
///
/// Each layer gets an explicit override matching its `default_visible`
/// flag; the resulting set is therefore equivalent to "what the
/// document looks like with no user toggles applied" but lets a UI
/// toggle individual layers from a known starting point.
/// Build a [`LayerSet`] populated from one of the document's
/// alternate configurations (`/OCProperties /Configs`).
///
/// `index = 0` is the default configuration; `1..N` are the entries
/// of `/Configs`. Returns `None` for an out-of-range index.
///
/// `BaseState::On` starts every layer ON before applying the
/// configuration's `/OFF` overrides; `BaseState::Off` starts every
/// layer OFF before applying `/ON`; `BaseState::Unchanged` carries
/// each layer's metadata-level `default_visible` forward.