use fop_core::{PropertyId, PropertyList};
use fop_types::Length;
pub use super::types::OverflowBehavior;
pub fn extract_overflow(properties: &PropertyList) -> OverflowBehavior {
properties
.get(PropertyId::Overflow)
.ok()
.map(|v| OverflowBehavior::from_property_value(&v))
.unwrap_or(OverflowBehavior::Visible)
}
pub fn extract_border_radius(properties: &PropertyList) -> Option<[Length; 4]> {
if let Ok(value) = properties.get(PropertyId::XBorderRadius) {
if let Some(len) = value.as_length() {
return Some([len, len, len, len]);
}
}
let top_left = properties
.get(PropertyId::XBorderBeforeStartRadius)
.ok()
.and_then(|v| v.as_length())
.unwrap_or(Length::ZERO);
let top_right = properties
.get(PropertyId::XBorderBeforeEndRadius)
.ok()
.and_then(|v| v.as_length())
.unwrap_or(Length::ZERO);
let bottom_right = properties
.get(PropertyId::XBorderAfterEndRadius)
.ok()
.and_then(|v| v.as_length())
.unwrap_or(Length::ZERO);
let bottom_left = properties
.get(PropertyId::XBorderAfterStartRadius)
.ok()
.and_then(|v| v.as_length())
.unwrap_or(Length::ZERO);
if top_left > Length::ZERO
|| top_right > Length::ZERO
|| bottom_right > Length::ZERO
|| bottom_left > Length::ZERO
{
Some([top_left, top_right, bottom_right, bottom_left])
} else {
None
}
}
pub fn extract_column_count(properties: &PropertyList) -> i32 {
properties
.get(PropertyId::ColumnCount)
.ok()
.and_then(|v| v.as_integer())
.unwrap_or(1) .max(1) }
pub fn extract_column_gap(properties: &PropertyList) -> Length {
properties
.get(PropertyId::ColumnGap)
.ok()
.and_then(|v| v.as_length())
.unwrap_or(Length::from_pt(12.0)) }
pub fn extract_opacity(properties: &PropertyList) -> f64 {
properties
.get(PropertyId::Opacity)
.ok()
.and_then(|v| v.as_number())
.unwrap_or(1.0) .clamp(0.0, 1.0) }
pub fn extract_clear(properties: &PropertyList) -> super::super::engine::ClearSide {
use super::super::engine::ClearSide;
if let Ok(prop) = properties.get(PropertyId::Clear) {
if let Some(enum_val) = prop.as_enum() {
return match enum_val {
66 => ClearSide::Left,
96 => ClearSide::Right,
19 => ClearSide::Both,
104 => ClearSide::Start,
45 => ClearSide::End,
_ => ClearSide::None,
};
}
if let Some(s) = prop.as_string() {
return match s {
"left" => ClearSide::Left,
"right" => ClearSide::Right,
"both" => ClearSide::Both,
"start" => ClearSide::Start,
"end" => ClearSide::End,
_ => ClearSide::None,
};
}
}
ClearSide::None
}