pub enum Color {
Transparent,
Gray(f32),
Rgb(f32, f32, f32),
Cmyk(f32, f32, f32, f32),
}Expand description
A colour in whichever device space its component count named.
Variants§
Transparent
No colour: the caller emits no colour operator at all.
Gray(f32)
DeviceGray.
Rgb(f32, f32, f32)
DeviceRGB.
Cmyk(f32, f32, f32, f32)
DeviceCMYK.
Implementations§
Source§impl Color
impl Color
Sourcepub fn from_array(array: &Array) -> Color
pub fn from_array(array: &Array) -> Color
Reads a colour array, dispatching purely on its length.
Components come through the non-resolving numeric accessor, so a
missing or mistyped element reads as 0.0 rather than rejecting the
array.
use pdfrum_doc::color::Color;
use pdfrum_object::Array;
let grey = Array::of([0.5_f32]);
assert_eq!(Color::from_array(&grey), Color::Gray(0.5));
// An empty array says "no colour", not "damaged".
assert_eq!(Color::from_array(&Array::new()), Color::Transparent);Sourcepub fn annot_rgb_bytes(self) -> (u32, u32, u32)
pub fn annot_rgb_bytes(self) -> (u32, u32, u32)
Component-wise equality within 1e-4.
Deliberately not PartialEq: the derived one stays exact so a test
The RGB bytes the --annot dump prints.
CMYK converts multiplicatively (255·(1−c)·(1−k)), which is not
the formula Color::mk_rgb_bytes uses for the same colour in a
widget’s /MK dictionary. Both exist upstream; keeping them named
apart is the only defence against unifying them.
Negative components saturate at zero rather than wrapping, which is
what the C++’s float-to-unsigned conversion does in practice.
use pdfrum_doc::color::Color;
assert_eq!(Color::Rgb(1.0, 0.0, 0.5).annot_rgb_bytes(), (255, 0, 127));
// CMYK converts multiplicatively here, not the way `/MK` colours do.
assert_eq!(Color::Cmyk(0.0, 0.0, 0.0, 0.0).annot_rgb_bytes(), (255, 255, 255));