-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathoptional_content.rs
197 lines (174 loc) · 7.62 KB
/
optional_content.rs
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
197
use crate::objects::Object;
#[derive(Debug, Clone, FromObj)]
pub struct OptionalContent;
#[derive(Debug, FromObj)]
pub struct OptionalContentProperties<'a> {
/// An array of indirect references to all the optional content groups in the
/// document, in any order. Every optional content group shall be included
/// in this array.
#[field("OCGs")]
optional_content_groups: Vec<Object<'a>>,
/// The default viewing optional content configuration dictionary
#[field("D")]
default_config: OptionalContentConfiguration<'a>,
/// An array of alternate optional content configuration dictionaries
#[field("Configs")]
alternate_configs: Option<Vec<OptionalContentConfiguration<'a>>>,
}
#[derive(Debug, FromObj)]
struct OptionalContentConfiguration<'a> {
/// A name for the configuration, suitable for presentation in a user interface.
#[field("Name")]
name: Option<String>,
/// Name of the application or feature that created this configuration dictionary.
#[field("Creator")]
creator: Option<String>,
/// Used to initialize the states of all the optional content groups in a
/// document when this configuration is applied. The value of this entry
/// shall be one of the following names:
///
/// ON The states of all groups shall be turned ON.
/// OFF The states of all groups shall be turned OFF.
/// Unchanged The states of all groups shall be left unchanged.
///
/// After this initialization, the contents of the ON and OFF arrays shall
/// be processed, overriding the state of the groups included in the arrays.
///
/// Default value: ON.
///
/// If BaseState is present in the document’s default configuration dictionary,
/// its value shall be ON.
#[field("BaseState")]
base_state: Option<OptionalContentBaseState>,
/// An array of optional content groups whose state shall be set to ON when
/// this configuration is applied.
///
/// If the BaseState entry is ON, this entry is redundant.
// todo: Vec<OptionalContentGroup>
#[field("ON")]
on: Option<Vec<Object<'a>>>,
/// An array of optional content groups whose state shall be set to OFF when
/// this configuration is applied.
///
/// If the BaseState entry is OFF, this entry is redundant.
// todo: Vec<OptionalContentGroup>
#[field("OFF")]
off: Option<Vec<Object<'a>>>,
/// A single intent name or an array containing any combination of names. It
/// shall be used to determine which optional content groups’ states to consider
/// and which to ignore in calculating the visibility of content
///
/// PDF defines two intent names, View and Design. In addition, the name All
/// shall indicate the set of all intents, including those not yet defined.
///
/// Default value: View.
///
/// The value shall be View for the document’s default configuration.
#[field("Intent")]
intent: Option<Intent>,
/// An array of usage application dictionaries specifying which usage dictionary
/// categories shall be consulted by conforming readers to automatically set
/// the states of optional content groups based on external factors, such as
/// the current system language or viewing magnification, and when they shall
/// be applied.
// todo: Vec<OptionalContentUsageApplication>
#[field("AS")]
applications: Option<Vec<Object<'a>>>,
/// An array specifying the order for presentation of optional content groups
/// in a conforming reader’s user interface. The array elements may include
/// the following objects:
///
/// Optional content group dictionaries, whose Name entry shall be displayed
/// in the user interface by the conforming reader.
///
/// Arrays of optional content groups which may be displayed by a conforming
/// reader in a tree or outline structure. Each nested array may optionally
/// have as its first element a text string to be used as a non-selectable
/// label in a conforming reader’s user interface.
///
/// Text labels in nested arrays shall be used to present collections of related
/// optional content groups, and not to communicate actual nesting of content
/// inside multiple layers of groups. To reflect actual nesting of groups in
/// the content, such as for layers with sublayers, nested arrays of groups
/// without a text label shall be used.
///
/// An empty array [] explicitly specifies that no groups shall be presented.
///
/// In the default configuration dictionary, the default value shall be an
/// empty array; in other configuration dictionaries, the default shall be
/// the Order value from the default configuration dictionary.
///
/// Any groups not listed in this array shall not be presented in any user
/// interface that uses the configuration.
// todo: Vec<OptionalContentGroup>
#[field("Order")]
order: Option<Vec<Object<'a>>>,
/// A name specifying which optional content groups in the Order array shall
/// be displayed to the user.
#[field("ListMode")]
list_mode: Option<ListMode>,
/// An array consisting of one or more arrays, each of which represents a
/// collection of optional content groups whose states shall be intended to
/// follow a radio button paradigm. That is, the state of at most one optional
/// content group in each array shall be ON at a time. If one group is turned
/// ON, all others shall be turned OFF. However, turning a group from ON to
/// OFF does not force any other group to be turned ON.
///
/// An empty array [] explicitly indicates that no such collections exist.
///
/// In the default configuration dictionary, the default value shall be an
/// empty array; in other configuration dictionaries, the default is the
/// RBGroups value from the default configuration dictionary.
// todo: better type
#[field("RBGroups")]
rb_groups: Option<Vec<Object<'a>>>,
/// An array of optional content groups that shall be locked when this
/// configuration is applied. The state of a locked group cannot be changed
/// through the user interface of a conforming reader. Conforming writers
/// can use this entry to prevent the visibility of content that depends on
/// these groups from being changed by users.
///
/// Default value: an empty array.
///
/// A conforming reader may allow the states of optional content groups from
/// being changed by means other than the user interface, such as JavaScript
/// or items in the AS entry of a configuration dictionary.
// todo: Vec<OptionalContentGroup>
#[field("Locked")]
locked: Option<Vec<Object<'a>>>,
}
#[derive(Debug, Clone, FromObj)]
pub struct OptionalContentGroup;
#[derive(Debug)]
struct OptionalContentUsage;
#[derive(Debug)]
struct OptionalContentUsageApplication;
#[pdf_enum]
#[derive(Default)]
enum ListMode {
/// Display all groups in the Order array.
#[default]
AllPages = "AllPages",
/// Display only those groups in the Order array that are referenced by
/// one or more visible pages.
VisiblePages = "VisiblePages",
}
#[pdf_enum]
#[derive(Default)]
enum OptionalContentBaseState {
#[default]
On = "ON",
Off = "OFF",
Unchanged = "Unchanged",
}
#[pdf_enum]
#[derive(Default)]
enum Intent {
/// Used for interactive use by document consumers
#[default]
View = "View",
/// Used to represent a document designer’s structural organization of artwork,
Design = "Design",
/// Indicates the set of all intents, including those not yet defined
All = "All",
}