Skip to main content

pdfrum_object/
names.rs

1//! The dictionary-key names the specification defines, as constants.
2//!
3//! One declaration site for the whole workspace: a key spelled here is never
4//! spelled again at a use site, so a typo cannot silently produce a lookup
5//! that never matches. Grouped the way ISO 32000-1 groups them; crates add
6//! their keys to the group they belong to as they land.
7//!
8//! ```
9//! use pdfrum_object::{Dict, Object, names};
10//!
11//! let dict = Dict::from_pairs([(names::TYPE.clone(), Object::Name(names::PAGE.clone()))]);
12//! assert_eq!(dict.raw(names::TYPE), Some(&Object::Name(names::PAGE.clone())));
13//! ```
14
15use crate::names;
16
17names! {
18    // ---- Entries common to all stream dictionaries (table 5) ----
19
20    /// Number of bytes of stream data (`/Length`).
21    LENGTH = "Length";
22    /// Filter or filter chain applied to the stream data (`/Filter`).
23    FILTER = "Filter";
24    /// Parameters for the filters (`/DecodeParms`).
25    DECODE_PARMS = "DecodeParms";
26    /// External file holding the data, also an annotation's flag word
27    /// (`/F` — the meaning follows the dictionary, not the key).
28    F = "F";
29
30    // ---- Stream filters and their abbreviations (tables 6 and 92) ----
31
32    /// Deflate compression (`/FlateDecode`).
33    FLATE_DECODE = "FlateDecode";
34    /// Inline-image abbreviation for `/FlateDecode` (`/Fl`).
35    FL = "Fl";
36    /// LZW compression (`/LZWDecode`).
37    LZW_DECODE = "LZWDecode";
38    /// Inline-image abbreviation for `/LZWDecode` (`/LZW`).
39    LZW = "LZW";
40    /// Base-85 text encoding (`/ASCII85Decode`).
41    ASCII85_DECODE = "ASCII85Decode";
42    /// Inline-image abbreviation for `/ASCII85Decode` (`/A85`).
43    A85 = "A85";
44    /// Hexadecimal text encoding (`/ASCIIHexDecode`).
45    ASCII_HEX_DECODE = "ASCIIHexDecode";
46    /// Inline-image abbreviation for `/ASCIIHexDecode` (`/AHx`).
47    AHX = "AHx";
48    /// Byte-oriented run-length compression (`/RunLengthDecode`).
49    RUN_LENGTH_DECODE = "RunLengthDecode";
50    /// Inline-image abbreviation for `/RunLengthDecode` (`/RL`).
51    RL = "RL";
52    /// Group 3/4 fax compression (`/CCITTFaxDecode`).
53    CCITT_FAX_DECODE = "CCITTFaxDecode";
54    /// Inline-image abbreviation for `/CCITTFaxDecode` (`/CCF`).
55    CCF = "CCF";
56    /// Baseline JPEG (`/DCTDecode`).
57    DCT_DECODE = "DCTDecode";
58    /// Inline-image abbreviation for `/DCTDecode` (`/DCT`).
59    DCT = "DCT";
60    /// JPEG 2000 (`/JPXDecode`).
61    JPX_DECODE = "JPXDecode";
62    /// Bi-level JBIG2 compression (`/JBIG2Decode`).
63    JBIG2_DECODE = "JBIG2Decode";
64    /// The crypt filter placeholder (`/Crypt`).
65    CRYPT = "Crypt";
66
67    // ---- Filter parameters (tables 8, 10, 11 and 12) ----
68
69    /// Which predictor was applied before compression (`/Predictor`).
70    PREDICTOR = "Predictor";
71    /// Colour components per sample, for a predictor (`/Colors`).
72    COLORS = "Colors";
73    /// Bits per colour component (`/BitsPerComponent`).
74    BITS_PER_COMPONENT = "BitsPerComponent";
75    /// Samples per row (`/Columns`).
76    COLUMNS = "Columns";
77    /// Whether LZW code lengths grow one code early (`/EarlyChange`).
78    EARLY_CHANGE = "EarlyChange";
79    /// The CCITT encoding scheme selector (`/K`).
80    K = "K";
81    /// Whether CCITT rows are terminated by end-of-line codes (`/EndOfLine`).
82    END_OF_LINE = "EndOfLine";
83    /// Whether each CCITT row starts on a byte boundary (`/EncodedByteAlign`).
84    ENCODED_BYTE_ALIGN = "EncodedByteAlign";
85    /// Number of rows in a CCITT image (`/Rows`).
86    ROWS = "Rows";
87    /// Whether a CCITT 1 bit means black (`/BlackIs1`).
88    BLACK_IS_1 = "BlackIs1";
89
90    // ---- Trailer and cross-reference (tables 15 and 17) ----
91
92    /// The document catalog (`/Root`).
93    ROOT = "Root";
94    /// The document information dictionary (`/Info`).
95    INFO = "Info";
96    /// One past the highest object number (`/Size`).
97    SIZE = "Size";
98    /// Offset of the previous cross-reference section (`/Prev`).
99    PREV = "Prev";
100    /// Offset of a hybrid file's cross-reference stream (`/XRefStm`).
101    XREF_STM = "XRefStm";
102    /// The encryption dictionary (`/Encrypt`).
103    ENCRYPT = "Encrypt";
104    /// The file identifier pair (`/ID`).
105    ID = "ID";
106    /// Subsection object-number ranges of a cross-reference stream (`/Index`).
107    INDEX = "Index";
108    /// Field widths of a cross-reference stream's entries (`/W`).
109    W = "W";
110    /// What kind of dictionary this is (`/Type`).
111    TYPE = "Type";
112    /// A cross-reference stream (`/XRef`).
113    XREF = "XRef";
114    /// An object stream (`/ObjStm`).
115    OBJ_STM = "ObjStm";
116    /// Number of objects in an object stream (`/N`).
117    N = "N";
118    /// Offset of the first object in an object stream (`/First`).
119    FIRST = "First";
120
121    // ---- Document information dictionary (table 317) ----
122
123    /// The document's title (`/Title`).
124    TITLE = "Title";
125    /// Who wrote the document (`/Author`).
126    AUTHOR = "Author";
127    /// What the document is about (`/Subject`).
128    SUBJECT = "Subject";
129    /// Keywords associated with the document (`/Keywords`).
130    KEYWORDS = "Keywords";
131    /// The application that produced the original document (`/Creator`).
132    CREATOR = "Creator";
133    /// The application that converted it to PDF (`/Producer`).
134    PRODUCER = "Producer";
135    /// When the document was created (`/CreationDate`).
136    CREATION_DATE = "CreationDate";
137    /// When the document was last modified (`/ModDate`).
138    MOD_DATE = "ModDate";
139
140    // ---- Catalog and page tree (tables 28 and 29) ----
141
142    /// The root of the page tree (`/Pages`).
143    PAGES = "Pages";
144    /// A leaf of the page tree (`/Page`).
145    PAGE = "Page";
146    /// The page label number tree (`/PageLabels`).
147    PAGE_LABELS = "PageLabels";
148    /// The name dictionary (`/Names`).
149    NAMES = "Names";
150    /// The named-destination dictionary (`/Dests`).
151    DESTS = "Dests";
152    /// The embedded-file name tree (`/EmbeddedFiles`).
153    EMBEDDED_FILES = "EmbeddedFiles";
154    /// The `/Type` of an embedded file stream (`/EmbeddedFile`).
155    EMBEDDED_FILE = "EmbeddedFile";
156    /// The document-level JavaScript name tree (`/JavaScript`).
157    JAVA_SCRIPT = "JavaScript";
158    /// A portable collection, i.e. a portfolio (`/Collection`).
159    COLLECTION = "Collection";
160    /// Viewer preferences (`/ViewerPreferences`).
161    VIEWER_PREFERENCES = "ViewerPreferences";
162    /// The outline (bookmark) tree root (`/Outlines`).
163    OUTLINES = "Outlines";
164    /// The interactive form dictionary (`/AcroForm`).
165    ACRO_FORM = "AcroForm";
166    /// Children of a page-tree node (`/Kids`).
167    KIDS = "Kids";
168    /// Number of leaf pages below a page-tree node (`/Count`).
169    COUNT = "Count";
170    /// The parent node of a page-tree node or form field (`/Parent`).
171    PARENT = "Parent";
172    /// The resources a page or form needs (`/Resources`). Inheritable
173    /// through the page tree.
174    RESOURCES = "Resources";
175    /// The sheet a page is imaged on (`/MediaBox`). Inheritable.
176    MEDIA_BOX = "MediaBox";
177    /// The region of a page a viewer displays (`/CropBox`). Inheritable.
178    CROP_BOX = "CropBox";
179    /// The region clipped to when producing output (`/BleedBox`).
180    BLEED_BOX = "BleedBox";
181    /// The intended finished dimensions after trimming (`/TrimBox`).
182    TRIM_BOX = "TrimBox";
183    /// The extent of the page's meaningful content (`/ArtBox`).
184    ART_BOX = "ArtBox";
185    /// Clockwise display rotation in degrees (`/Rotate`). Inheritable.
186    ROTATE = "Rotate";
187    /// Metadata stream (`/Metadata`).
188    METADATA = "Metadata";
189    /// A more specific type within a `/Type` (`/Subtype`).
190    SUBTYPE = "Subtype";
191    /// An XML metadata stream's subtype (`/XML`).
192    XML = "XML";
193
194    // ---- Resource categories, form and image XObjects (tables 33, 89 and 95) ----
195
196    /// The font resource category, and a font dictionary's own `/Type`
197    /// value (`/Font`).
198    FONT = "Font";
199    /// The external-object resource category — images and forms alike —
200    /// and an external object's own `/Type` value (`/XObject`).
201    XOBJECT = "XObject";
202    /// The graphics-state parameter resource category (`/ExtGState`).
203    EXT_G_STATE = "ExtGState";
204    /// The marked-content property resource category (`/Properties`).
205    PROPERTIES = "Properties";
206    /// The shading resource category (`/Shading`), which the `sh` operator
207    /// names its shading in.
208    SHADING = "Shading";
209    /// A form's, pattern's or shading's coordinate mapping (`/Matrix`).
210    MATRIX = "Matrix";
211    /// A form's or pattern's clipping rectangle (`/BBox`).
212    BBOX = "BBox";
213    /// Image width in samples (`/Width`).
214    WIDTH = "Width";
215    /// Image height in samples (`/Height`).
216    HEIGHT = "Height";
217    /// An image's or shading's colour space (`/ColorSpace`).
218    COLOR_SPACE = "ColorSpace";
219    /// Sample-value remapping (`/Decode`).
220    DECODE = "Decode";
221    /// Whether the image is a stencil mask (`/ImageMask`).
222    IMAGE_MASK = "ImageMask";
223    /// A soft mask, either an image's or an `/ExtGState`'s (`/SMask`).
224    SMASK = "SMask";
225
226    // ---- Encryption (tables 20 through 27) ----
227
228    /// Algorithm version, also a form field's value (`/V`).
229    V = "V";
230    /// Standard security handler revision (`/R`), also an appearance's
231    /// rollover state.
232    R = "R";
233    /// Owner password hash (`/O`), also a linearized file's first page
234    /// object number.
235    O = "O";
236    /// User password hash (`/U`).
237    U = "U";
238    /// Permission flags (`/P`), also an annotation's page reference and a
239    /// linearized file's first-page offset.
240    P = "P";
241    /// Owner encryption key, revision 5 and 6 (`/OE`).
242    OE = "OE";
243    /// User encryption key, revision 5 and 6 (`/UE`).
244    UE = "UE";
245    /// Encrypted permissions, revision 5 and 6 (`/Perms`).
246    PERMS = "Perms";
247    /// Crypt filter used for streams (`/StmF`).
248    STM_F = "StmF";
249    /// Crypt filter used for strings (`/StrF`).
250    STR_F = "StrF";
251    /// Crypt filter used for embedded files (`/EFF`).
252    EFF = "EFF";
253    /// The crypt filter dictionary (`/CF`).
254    CF = "CF";
255    /// A crypt filter's method (`/CFM`).
256    CFM = "CFM";
257    /// When a crypt filter's key is requested (`/AuthEvent`).
258    AUTH_EVENT = "AuthEvent";
259    /// Whether the document metadata is encrypted (`/EncryptMetadata`).
260    ENCRYPT_METADATA = "EncryptMetadata";
261    /// The standard security handler (`/Standard`).
262    STANDARD = "Standard";
263    /// The pass-through crypt filter (`/Identity`).
264    IDENTITY = "Identity";
265
266    // ---- Linearization (annex F) ----
267
268    /// Length of the whole file (`/L`), also a line annotation's endpoints.
269    L = "L";
270    /// Offset and length of the hint stream (`/H`).
271    H = "H";
272    /// Offset of the end of the first page (`/E`).
273    E = "E";
274    /// Offset of the main cross-reference table (`/T`), also a form field's
275    /// partial name.
276    T = "T";
277
278    // ---- Entries common to all annotations (table 168) ----
279
280    /// A page's annotation array (`/Annots`).
281    ANNOTS = "Annots";
282    /// The annotation's rectangle (`/Rect`).
283    RECT = "Rect";
284    /// The intent of a markup or screen annotation (`/IT`).
285    IT = "IT";
286    /// The annotation's text, or a page's content stream (`/Contents`).
287    CONTENTS = "Contents";
288    /// The annotation's name, unique within the page (`/NM`).
289    NM = "NM";
290    /// Last-modified date (`/M`).
291    M = "M";
292    /// The appearance dictionary (`/AP`).
293    AP = "AP";
294    /// The appearance state selecting a sub-appearance (`/AS`).
295    AS = "AS";
296    /// Border characteristics (`/Border`).
297    BORDER = "Border";
298    /// Colour (`/C`).
299    C = "C";
300    /// Optional-content membership (`/OC`).
301    OC = "OC";
302    /// Ink annotation stroke list (`/InkList`).
303    INK_LIST = "InkList";
304
305    // ---- Appearance characteristics (table 189) ----
306
307    /// Background colour (`/BG`), also a widget's background.
308    BG = "BG";
309    /// Border colour (`/BC`), also a soft mask's backdrop.
310    BC = "BC";
311    /// Normal caption (`/CA`), also the non-stroking alpha constant.
312    CA = "CA";
313    /// Normal icon (`/I`), also a transparency group's isolation flag.
314    I = "I";
315    /// Rollover icon (`/RI`).
316    RI = "RI";
317    /// Alternate (down) icon (`/IX`).
318    IX = "IX";
319
320    // ---- Interactive form fields (tables 220 and 228) ----
321
322    /// The field type (`/FT`).
323    FT = "FT";
324    /// The XFA form packet, whose presence makes a form an XFA one (`/XFA`).
325    XFA = "XFA";
326    /// Alternate field name, shown to the user (`/TU`).
327    TU = "TU";
328    /// Field flags (`/Ff`).
329    FF = "Ff";
330    /// Default value (`/DV`).
331    DV = "DV";
332    /// Additional-actions dictionary (`/AA`).
333    AA = "AA";
334    /// Signature field type (`/Sig`).
335    SIG = "Sig";
336    /// Default appearance string (`/DA`).
337    DA = "DA";
338    /// Quadding — the text alignment code (`/Q`).
339    Q = "Q";
340    /// Default style string (`/DS`).
341    DS = "DS";
342
343    // ---- Predefined encodings (annex D) ----
344
345    /// The Mac OS standard encoding (`/MacRomanEncoding`).
346    MAC_ROMAN_ENCODING = "MacRomanEncoding";
347    /// The Windows code page 1252 encoding (`/WinAnsiEncoding`).
348    WIN_ANSI_ENCODING = "WinAnsiEncoding";
349    /// The document-string encoding (`/PDFDocEncoding`).
350    PDF_DOC_ENCODING = "PDFDocEncoding";
351    /// The expert-set encoding (`/MacExpertEncoding`).
352    MAC_EXPERT_ENCODING = "MacExpertEncoding";
353
354    // ---- Transparency: blend modes and groups (tables 136 and 144) ----
355
356    /// The `Normal` blend mode.
357    NORMAL = "Normal";
358    /// The `Multiply` blend mode.
359    MULTIPLY = "Multiply";
360    /// The `Screen` blend mode.
361    SCREEN = "Screen";
362    /// The `Overlay` blend mode.
363    OVERLAY = "Overlay";
364    /// The `Darken` blend mode.
365    DARKEN = "Darken";
366    /// The `Lighten` blend mode.
367    LIGHTEN = "Lighten";
368    /// The `ColorDodge` blend mode.
369    COLOR_DODGE = "ColorDodge";
370    /// The `ColorBurn` blend mode.
371    COLOR_BURN = "ColorBurn";
372    /// The `HardLight` blend mode.
373    HARD_LIGHT = "HardLight";
374    /// The `SoftLight` blend mode.
375    SOFT_LIGHT = "SoftLight";
376    /// The `Difference` blend mode.
377    DIFFERENCE = "Difference";
378    /// The `Exclusion` blend mode.
379    EXCLUSION = "Exclusion";
380    /// The `Hue` blend mode.
381    HUE = "Hue";
382    /// The `Saturation` blend mode.
383    SATURATION = "Saturation";
384    /// The `Color` blend mode.
385    COLOR = "Color";
386    /// The `Luminosity` blend mode.
387    LUMINOSITY = "Luminosity";
388    /// A soft mask's or transparency group's subtype (`/S`).
389    S = "S";
390    /// An alpha soft mask (`/Alpha`).
391    ALPHA = "Alpha";
392    /// The form `XObject` a soft mask draws (`/G`).
393    G = "G";
394    /// A soft mask's transfer function (`/TR`).
395    TR = "TR";
396    /// A group's colour space (`/CS`).
397    CS = "CS";
398
399    // ---- Form and image XObject subtypes (tables 89 and 95) ----
400
401    /// A form external object's `/Subtype` value (`/Form`).
402    FORM = "Form";
403    /// An image external object's `/Subtype` value (`/Image`).
404    IMAGE = "Image";
405    /// A form `XObject`'s generation number, always 1 (`/FormType`).
406    FORM_TYPE = "FormType";
407
408    // ---- Graphics state parameter dictionaries (table 58) ----
409
410    /// Blend mode (`/BM`).
411    BM = "BM";
412    /// Non-stroking alpha (`/ca`); stroking alpha is `/CA`.
413    CA_LOWER = "ca";
414    /// Whether alpha is a shape or an opacity (`/AIS`).
415    AIS = "AIS";
416
417    // ---- Font dictionaries (tables 111, 117, 120, 122) ----
418
419    /// A simple font's encoding or a Type0 font's CMap (`/Encoding`).
420    ENCODING = "Encoding";
421    /// The encoding a `/Differences` array modifies (`/BaseEncoding`).
422    BASE_ENCODING = "BaseEncoding";
423    /// Per-code overrides on the base encoding (`/Differences`).
424    DIFFERENCES = "Differences";
425    /// The PostScript name of a font (`/BaseFont`).
426    BASE_FONT = "BaseFont";
427    /// A font's metrics and embedded program (`/FontDescriptor`).
428    FONT_DESCRIPTOR = "FontDescriptor";
429    /// An embedded Type 1 program (`/FontFile`).
430    FONT_FILE = "FontFile";
431    /// An embedded TrueType program (`/FontFile2`).
432    FONT_FILE2 = "FontFile2";
433    /// An embedded program in some other format, CFF included (`/FontFile3`).
434    FONT_FILE3 = "FontFile3";
435    /// Per-code advance widths of a simple font (`/Widths`).
436    WIDTHS = "Widths";
437    /// First code a simple font's `/Widths` covers (`/FirstChar`).
438    FIRST_CHAR = "FirstChar";
439    /// Last code a simple font's `/Widths` covers (`/LastChar`).
440    LAST_CHAR = "LastChar";
441    /// The character-code-to-Unicode CMap (`/ToUnicode`).
442    TO_UNICODE = "ToUnicode";
443    /// Descriptor flags, and a form-action flag word (`/Flags`).
444    FLAGS = "Flags";
445    /// Glyph extents (`/FontBBox`).
446    FONT_BBOX = "FontBBox";
447    /// Degrees clockwise from vertical (`/ItalicAngle`).
448    ITALIC_ANGLE = "ItalicAngle";
449    /// Vertical stem thickness (`/StemV`).
450    STEM_V = "StemV";
451    /// Maximum height above the baseline (`/Ascent`).
452    ASCENT = "Ascent";
453    /// Maximum depth below the baseline (`/Descent`).
454    DESCENT = "Descent";
455    /// Height of a capital letter (`/CapHeight`).
456    CAP_HEIGHT = "CapHeight";
457    /// The descendant `CIDFont` of a Type 0 font (`/DescendantFonts`).
458    DESCENDANT_FONTS = "DescendantFonts";
459    /// The CID collection this font is keyed to (`/CIDSystemInfo`).
460    CID_SYSTEM_INFO = "CIDSystemInfo";
461    /// Ordering name inside `/CIDSystemInfo` (`/Ordering`).
462    ORDERING = "Ordering";
463    /// Maps a CID to a glyph index (`/CIDToGIDMap`).
464    CID_TO_GID_MAP = "CIDToGIDMap";
465    /// A Type 1 font's `/Subtype` value (`/Type1`).
466    TYPE1 = "Type1";
467    /// A TrueType font's `/Subtype` value (`/TrueType`).
468    TRUE_TYPE = "TrueType";
469
470    // ---- Extra annotation keys (tables 168 and 179) ----
471
472    /// An annotation's interior colour (`/IC`).
473    IC = "IC";
474    /// A text-markup annotation's quadrilaterals (`/QuadPoints`).
475    QUAD_POINTS = "QuadPoints";
476    /// A destination, an appearance's down state, and a dash pattern (`/D`).
477    D = "D";
478}
479
480#[cfg(test)]
481mod tests {
482    use super::{FILTER, LENGTH, PAGE, ROOT, TYPE};
483    use crate::Name;
484
485    #[test]
486    fn constants_carry_the_specification_spelling() {
487        assert_eq!(LENGTH.as_str(), Some("Length"));
488        assert_eq!(FILTER.as_str(), Some("Filter"));
489        assert_eq!(ROOT.as_str(), Some("Root"));
490        assert_eq!(TYPE.as_str(), Some("Type"));
491        assert_eq!(PAGE.as_str(), Some("Page"));
492    }
493
494    #[test]
495    fn constants_equal_names_parsed_from_a_file() {
496        assert_eq!(LENGTH, &Name::decode(b"Length"));
497        assert_eq!(LENGTH, &Name::decode(b"Lengt#68"));
498    }
499}