Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- mod color {
- #[allow(non_camel_case_types)]
- pub struct pdf_color(PdfColor);
- impl pdf_color {
- pub fn new() -> Self {
- Self(BLACK)
- }
- }
- #[derive(Clone)]
- pub enum PdfColor {
- Gray(f64),
- Spot(String, f64),
- Rgb(f64,f64,f64),
- Cmyk(f64,f64,f64,f64),
- }
- macro_rules! warn(
- ($($arg:tt)*) => {
- println!($($arg)*);
- };
- );
- impl PdfColor {
- pub fn warn(self) -> pdf_color {
- use PdfColor::*;
- match self {
- Gray(g) => {
- if g < 0. || g > 1. {
- warn!("Invalid color value specified: gray={}", g);
- }
- },
- Spot(_, c) => {
- if c < 0. || c > 1. {
- warn!("Invalid color value specified: grade={}", c);
- }
- },
- Rgb(r,g,b) => {
- if r < 0. || r > 1. {
- warn!("Invalid color value specified: red={}", r);
- }
- if g < 0. || g > 1. {
- warn!("Invalid color value specified: green={}", g);
- }
- if b < 0. || b > 1. {
- warn!("Invalid color value specified: blue={}", b);
- }
- },
- Cmyk(c,m,y,k) => {
- if c < 0. || c > 1. {
- warn!("Invalid color value specified: cyan={}", c);
- }
- if m < 0. || m > 1. {
- warn!("Invalid color value specified: magenta={}", m);
- }
- if y < 0. || y > 1. {
- warn!("Invalid color value specified: yellow={}", y);
- }
- if k < 0. || k > 1. {
- warn!("Invalid color value specified: black={}", k);
- }
- }
- }
- pdf_color(self)
- }
- pub fn spot(name: &str, c: f64) -> Self {
- PdfColor::Spot(String::from(name), c)
- }
- }
- // Predefined colors
- const BLACK: PdfColor = PdfColor::Gray(0.);
- }
- fn main() {
- use color::{pdf_color, PdfColor};
- let mut _a = pdf_color::new();
- //a = pdf_color(PdfColor::Rgb(0.5, 12.1, 0.4)); //error::private field
- _a = PdfColor::Rgb(0.5, 12.1, 0.4).warn();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement