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
//! Watermarking options.
/// Page rotation in 90-degree increments.
///
/// All rotations are **clockwise** relative to the upright page orientation,
/// matching ISO 32000-2 §14.11 (`/Rotate` entry).
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[non_exhaustive]
pub enum Rotation {
/// 90° clockwise.
Clockwise90,
/// 180°.
Clockwise180,
/// 270° clockwise (= 90° counter-clockwise).
Clockwise270,
}
/// Layer — whether the watermark goes in front of or behind content.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Layer {
/// Behind existing content.
Background,
/// In front of existing content.
Foreground,
}
/// Position of a watermark on the page.
#[derive(Debug, Clone, Copy, PartialEq)]
pub enum Position {
/// Centred.
Center,
/// Top-left with offset from the corner.
TopLeft(f32, f32),
/// Top-right with offset.
TopRight(f32, f32),
/// Bottom-left with offset.
BottomLeft(f32, f32),
/// Bottom-right with offset.
BottomRight(f32, f32),
/// Exact position in PDF points from bottom-left.
Exact(f32, f32),
}
/// Options for a text watermark.
///
/// Image-watermark support ships in Epic 2 #1225 via the unified
/// `PageDecoration` builder.
#[derive(Debug, Clone)]
#[non_exhaustive]
pub struct WatermarkOptions {
// Captured at construction; read by the `PdfDocument::add_watermark`
// body when wired in Epic 2 #1223 (and later consolidated via
// `PageDecoration` in #1225). Marked with an explicit allow so the
// scaffold phase does not fail `-D warnings`.
#[allow(dead_code)]
pub(crate) position: Position,
pub(crate) rotation_degrees: f32,
pub(crate) opacity: f32,
pub(crate) layer: Layer,
pub(crate) font_size: f32,
pub(crate) color_rgb: (f32, f32, f32),
}
impl Default for WatermarkOptions {
fn default() -> Self {
Self {
position: Position::Center,
rotation_degrees: 0.0,
opacity: 0.5,
layer: Layer::Foreground,
font_size: 48.0,
color_rgb: (0.6, 0.6, 0.6),
}
}
}
impl WatermarkOptions {
/// A centred watermark with default styling.
pub fn centered() -> Self {
Self::default()
}
/// Rotate the watermark by the given angle in degrees.
pub fn rotated(mut self, degrees: f32) -> Self {
self.rotation_degrees = degrees;
self
}
/// Set opacity in `[0.0, 1.0]`.
pub fn opacity(mut self, alpha: f32) -> Self {
self.opacity = alpha;
self
}
/// Choose foreground or background placement.
pub fn layer(mut self, layer: Layer) -> Self {
self.layer = layer;
self
}
/// Set font size.
pub fn font_size(mut self, pt: f32) -> Self {
self.font_size = pt;
self
}
/// Set text colour.
pub fn color(mut self, r: f32, g: f32, b: f32) -> Self {
self.color_rgb = (r, g, b);
self
}
}