use crate::model::page::{PageBorderBasis, PageBorderFill};
use crate::renderer::{
hwpunit_to_px,
page_layout::{LayoutRect, PageLayoutInfo},
DEFAULT_DPI,
};
pub(crate) fn double_line_parts(declared_width: f64) -> [(f64, f64); 2] {
let grid = DEFAULT_DPI / 600.0;
let stroke = (declared_width / (4.0 * grid)).round().max(1.0) * grid;
let offset = stroke * 1.5;
[(-offset, stroke), (offset, stroke)]
}
pub(crate) fn page_border_rect(
pbf: &PageBorderFill,
layout: &PageLayoutInfo,
dpi: f64,
) -> LayoutRect {
let left = hwpunit_to_px(i32::from(pbf.spacing_left), dpi);
let right = hwpunit_to_px(i32::from(pbf.spacing_right), dpi);
let top = hwpunit_to_px(i32::from(pbf.spacing_top), dpi);
let bottom = hwpunit_to_px(i32::from(pbf.spacing_bottom), dpi);
match pbf.basis {
PageBorderBasis::PaperBased => LayoutRect {
x: left,
y: top,
width: layout.page_width - left - right,
height: layout.page_height - top - bottom,
},
PageBorderBasis::BodyBased => LayoutRect {
x: layout.body_area.x - left,
y: layout.body_area.y - top,
width: layout.body_area.width + left + right,
height: layout.body_area.height + top + bottom,
},
}
}