use crate::values::generics::NonNegative;
use crate::values::specified::length::AbsoluteLength;
#[derive(
Clone, Copy, Debug, Eq, MallocSizeOf, Parse, PartialEq, SpecifiedValueInfo, ToCss, ToShmem,
)]
#[repr(u8)]
pub enum PaperSize {
A5,
A4,
A3,
B5,
B4,
JisB5,
JisB4,
Letter,
Legal,
Ledger,
}
impl PaperSize {
pub fn long_edge(&self) -> NonNegative<AbsoluteLength> {
NonNegative(match *self {
PaperSize::A5 => AbsoluteLength::Mm(210.0),
PaperSize::A4 => AbsoluteLength::Mm(297.0),
PaperSize::A3 => AbsoluteLength::Mm(420.0),
PaperSize::B5 => AbsoluteLength::Mm(250.0),
PaperSize::B4 => AbsoluteLength::Mm(353.0),
PaperSize::JisB5 => AbsoluteLength::Mm(257.0),
PaperSize::JisB4 => AbsoluteLength::Mm(364.0),
PaperSize::Letter => AbsoluteLength::In(11.0),
PaperSize::Legal => AbsoluteLength::In(14.0),
PaperSize::Ledger => AbsoluteLength::In(17.0),
})
}
pub fn short_edge(&self) -> NonNegative<AbsoluteLength> {
NonNegative(match *self {
PaperSize::A5 => AbsoluteLength::Mm(148.0),
PaperSize::A4 => AbsoluteLength::Mm(210.0),
PaperSize::A3 => AbsoluteLength::Mm(297.0),
PaperSize::B5 => AbsoluteLength::Mm(176.0),
PaperSize::B4 => AbsoluteLength::Mm(250.0),
PaperSize::JisB5 => AbsoluteLength::Mm(182.0),
PaperSize::JisB4 => AbsoluteLength::Mm(257.0),
PaperSize::Letter => AbsoluteLength::In(8.5),
PaperSize::Legal => AbsoluteLength::In(8.5),
PaperSize::Ledger => AbsoluteLength::In(11.0),
})
}
}
#[derive(
Clone,
Copy,
Debug,
Eq,
MallocSizeOf,
Parse,
PartialEq,
SpecifiedValueInfo,
ToComputedValue,
ToCss,
ToResolvedValue,
ToShmem,
)]
#[repr(u8)]
pub enum PageOrientation {
Upright,
RotateLeft,
RotateRight,
}
#[derive(
Clone,
Copy,
Debug,
Eq,
MallocSizeOf,
Parse,
PartialEq,
SpecifiedValueInfo,
ToCss,
ToResolvedValue,
ToShmem,
)]
#[repr(u8)]
pub enum PageSizeOrientation {
Portrait,
Landscape,
}
#[inline]
fn is_portrait(orientation: &PageSizeOrientation) -> bool {
*orientation == PageSizeOrientation::Portrait
}
#[derive(Clone, Copy, Debug, MallocSizeOf, PartialEq, SpecifiedValueInfo, ToCss, ToShmem)]
#[repr(C, u8)]
pub enum GenericPageSize<S> {
Auto,
Size(S),
Orientation(PageSizeOrientation),
PaperSize(
PaperSize,
#[css(skip_if = "is_portrait")] PageSizeOrientation,
),
}
pub use self::GenericPageSize as PageSize;
impl<S> PageSize<S> {
#[inline]
pub fn auto() -> Self {
PageSize::Auto
}
#[inline]
pub fn is_auto(&self) -> bool {
matches!(*self, PageSize::Auto)
}
}