use crate::renderer::render_tree::{BoundingBox, RectangleNode};
use crate::renderer::HWPUNIT_PER_INCH;
pub(super) fn frame(bounds: BoundingBox, rect: &RectangleNode, pixel: f64) -> Option<BoundingBox> {
let width_hu = rect.drawing_border_width_hu?;
if width_hu <= 0
|| !pixel.is_finite()
|| pixel <= 0.0
|| rect.corner_radius != 0.0
|| rect.transform.has_transform()
|| rect.image_frame_owner.is_some()
|| rect.gradient.is_some()
|| rect.style.fill_color.is_none()
|| rect.style.pattern.is_some()
|| rect.style.shadow.is_some()
|| rect.style.opacity != 1.0
|| ![bounds.x, bounds.y, bounds.width, bounds.height]
.into_iter()
.all(f64::is_finite)
|| bounds.width <= 0.0
|| bounds.height <= 0.0
{
return None;
}
let pen = (f64::from(width_hu) * super::metafile::HANCOM_2024_PRINT_DEVICE_DPI
/ HWPUNIT_PER_INCH)
.round();
let overlap = (pen * 0.4).trunc() * pixel;
if overlap <= 0.0 || !overlap.is_finite() {
return None;
}
Some(BoundingBox::new(
bounds.x - overlap,
bounds.y - overlap,
bounds.width + 2.0 * overlap,
bounds.height + 2.0 * overlap,
))
}
pub(super) fn take_fill(rect: &mut RectangleNode) -> RectangleNode {
let mut fill = rect.clone();
fill.style.stroke_color = None;
fill.style.stroke_width = 0.0;
fill.drawing_border_width_hu = None;
rect.style.fill_color = None;
fill
}