use f_office_paint::Rgb;
use f_office_units::Length;
use f_office_xml::enumeration::{Case, Values, own};
use f_office_xml::{Document, NodeId};
use super::Color;
use super::color::parse_color;
use crate::ns::W;
use crate::params;
use crate::reader::{PartReader, attribute};
use crate::warnings::Feature;
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct Border {
pub width: Length,
pub space: Length,
pub color: Color,
pub parts: BorderParts,
pub dash: Option<DashStyle>,
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct BorderParts {
sizes: [Length; 5],
count: usize,
style: LineStyle,
line: Length,
}
impl BorderParts {
#[must_use]
pub const fn single(width: Length) -> Self {
Self {
sizes: [
width,
Length::ZERO,
Length::ZERO,
Length::ZERO,
Length::ZERO,
],
count: 1,
style: LineStyle::Single,
line: width,
}
}
fn new(style: LineStyle, line: Length, sizes: &[Length]) -> Self {
let mut parts = Self::single(Length::ZERO);
parts.count = sizes.len().min(parts.sizes.len());
for (slot, size) in parts.sizes.iter_mut().zip(sizes) {
*slot = *size;
}
Self {
style,
line,
..parts
}
}
pub(crate) fn sizes(&self) -> &[Length] {
self.sizes.get(..self.count).unwrap_or(&self.sizes)
}
#[must_use]
fn in_whole_twips(self) -> Self {
if self.count == 0 {
return self;
}
let line = self.line.toward_zero_whole(Length::UNITS_PER_TWIP);
border_parts(self.style, line)
}
}
impl Border {
#[must_use]
pub fn new(parts: BorderParts, space: Length, color: Color) -> Self {
Self {
width: parts.sizes().iter().copied().sum(),
space,
color,
parts,
dash: None,
}
}
#[must_use]
pub fn none(space: Length) -> Self {
Self::new(
BorderParts::new(LineStyle::None, Length::ZERO, &[]),
space,
Color::Auto,
)
}
#[must_use]
pub fn in_whole_twips(self) -> Self {
Self {
dash: self.dash,
..Self::new(self.parts.in_whole_twips(), self.space, self.color)
}
}
#[must_use]
pub fn is_none(&self) -> bool {
self.parts.count == 0
}
#[must_use]
pub fn lines(&self) -> Vec<(Length, Length)> {
self.parts
.sizes()
.iter()
.scan(Length::ZERO, |offset, size| {
let start = *offset;
*offset += *size;
Some((start, *size))
})
.step_by(2)
.collect()
}
#[must_use]
pub fn lines_from_end(&self) -> Vec<(Length, Length)> {
let width = self.width;
self.lines()
.into_iter()
.map(|(offset, thickness)| (width - offset - thickness, thickness))
.collect()
}
#[must_use]
pub(crate) const fn touches(&self) -> bool {
matches!(self.parts.style, LineStyle::ThreeD(_))
}
#[must_use]
pub(crate) fn draws_like(&self, other: &Border) -> bool {
self.parts.line == other.parts.line
&& self.parts.style.unturned() == other.parts.style.unturned()
}
pub(crate) fn touching_lines(&self, thick: impl Fn(Length) -> Length) -> Vec<(Length, Length)> {
self.lines()
.into_iter()
.scan(Length::ZERO, |offset, (_, thickness)| {
let (start, drawn) = (*offset, thick(thickness));
*offset += drawn;
Some((start, drawn))
})
.collect()
}
#[must_use]
pub(crate) fn line_colors(&self) -> Vec<Rgb> {
match self.parts.style {
LineStyle::ThreeD(relief) => {
let [light, middle, dark] = relief_shades(self.color);
match relief {
Relief::Emboss => vec![light, middle, dark],
Relief::Engrave => vec![dark, middle, light],
}
}
_ => vec![self.color.drawn(); self.lines().len()],
}
}
#[must_use]
pub(crate) fn as_one_line(self) -> Self {
if self.touches() {
Self {
dash: self.dash,
..Self::new(BorderParts::single(self.parts.line), self.space, self.color)
}
} else {
self
}
}
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub(crate) enum Gap {
Small,
Medium,
Large,
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub(crate) enum LineStyle {
None,
Single,
Double,
Triple,
ThinThick(Gap),
ThickThin(Gap),
ThinThickThin(Gap),
ThreeD(Relief),
}
impl LineStyle {
const fn unturned(self) -> Self {
match self {
Self::ThickThin(gap) => Self::ThinThick(gap),
other => other,
}
}
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub(crate) enum Relief {
Emboss,
Engrave,
}
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub enum DashStyle {
Dotted,
Dashed,
DotDash,
DotDotDash,
}
impl DashStyle {
#[must_use]
pub const fn pattern(self) -> &'static [i64] {
match self {
Self::Dotted => ¶ms::DOTTED_BORDER_DASHES,
Self::Dashed => ¶ms::DASHED_BORDER_DASHES,
Self::DotDash => ¶ms::DOT_DASH_BORDER_DASHES,
Self::DotDotDash => ¶ms::DOT_DOT_DASH_BORDER_DASHES,
}
}
}
const DASHED_LINES: [Case<DashStyle>; 4] = [
own("dotted", DashStyle::Dotted),
own("dashed", DashStyle::Dashed),
own("dotDash", DashStyle::DotDash),
own("dotDotDash", DashStyle::DotDotDash),
];
const BORDER_DASH: &Values<DashStyle> = &Values::new(&DASHED_LINES);
pub(crate) const BORDER_NAMES: &[&str] = &[
"nil",
"none",
"single",
"thick",
"double",
"dotted",
"dashed",
"dotDash",
"dotDotDash",
"triple",
"thinThickSmallGap",
"thickThinSmallGap",
"thinThickThinSmallGap",
"thinThickMediumGap",
"thickThinMediumGap",
"thinThickThinMediumGap",
"thinThickLargeGap",
"thickThinLargeGap",
"thinThickThinLargeGap",
"wave",
"doubleWave",
"dashSmallGap",
"dashDotStroked",
"threeDEmboss",
"threeDEngrave",
"outset",
"inset",
"apples",
"archedScallops",
"babyPacifier",
"babyRattle",
"balloons3Colors",
"balloonsHotAir",
"basicBlackDashes",
"basicBlackDots",
"basicBlackSquares",
"basicThinLines",
"basicWhiteDashes",
"basicWhiteDots",
"basicWhiteSquares",
"basicWideInline",
"basicWideMidline",
"basicWideOutline",
"bats",
"birds",
"birdsFlight",
"cabins",
"cakeSlice",
"candyCorn",
"celticKnotwork",
"certificateBanner",
"chainLink",
"champagneBottle",
"checkedBarBlack",
"checkedBarColor",
"checkered",
"christmasTree",
"circlesLines",
"circlesRectangles",
"classicalWave",
"clocks",
"compass",
"confetti",
"confettiGrays",
"confettiOutline",
"confettiStreamers",
"confettiWhite",
"cornerTriangles",
"couponCutoutDashes",
"couponCutoutDots",
"crazyMaze",
"creaturesButterfly",
"creaturesFish",
"creaturesInsects",
"creaturesLadyBug",
"crossStitch",
"cup",
"decoArch",
"decoArchColor",
"decoBlocks",
"diamondsGray",
"doubleD",
"doubleDiamonds",
"earth1",
"earth2",
"eclipsingSquares1",
"eclipsingSquares2",
"eggsBlack",
"fans",
"film",
"firecrackers",
"flowersBlockPrint",
"flowersDaisies",
"flowersModern1",
"flowersModern2",
"flowersPansy",
"flowersRedRose",
"flowersRoses",
"flowersTeacup",
"flowersTiny",
"gems",
"gingerbreadMan",
"gradient",
"handmade1",
"handmade2",
"heartBalloon",
"heartGray",
"hearts",
"heebieJeebies",
"holly",
"houseFunky",
"hypnotic",
"iceCreamCones",
"lightBulb",
"lightning1",
"lightning2",
"mapPins",
"mapleLeaf",
"mapleMuffins",
"marquee",
"marqueeToothed",
"moons",
"mosaic",
"musicNotes",
"northwest",
"ovals",
"packages",
"palmsBlack",
"palmsColor",
"paperClips",
"papyrus",
"partyFavor",
"partyGlass",
"pencils",
"people",
"peopleWaving",
"peopleHats",
"poinsettias",
"postageStamp",
"pumpkin1",
"pushPinNote2",
"pushPinNote1",
"pyramids",
"pyramidsAbove",
"quadrants",
"rings",
"safari",
"sawtooth",
"sawtoothGray",
"scaredCat",
"seattle",
"shadowedSquares",
"sharksTeeth",
"shorebirdTracks",
"skyrocket",
"snowflakeFancy",
"snowflakes",
"sombrero",
"southwest",
"stars",
"starsTop",
"stars3d",
"starsBlack",
"starsShadowed",
"sun",
"swirligig",
"tornPaper",
"tornPaperBlack",
"trees",
"triangleParty",
"triangles",
"tribal1",
"tribal2",
"tribal3",
"tribal4",
"tribal5",
"tribal6",
"twistedLines1",
"twistedLines2",
"vine",
"waveline",
"weavingAngles",
"weavingBraid",
"weavingRibbon",
"weavingStrips",
"whiteFlowers",
"woodwork",
"xIllusions",
"zanyTriangles",
"zigZag",
"zigZagStitch",
];
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct ArtStyle(u8);
impl ArtStyle {
#[must_use]
pub fn of_name(name: &str) -> Option<Self> {
let index = BORDER_NAMES
.get(params::LINE_STYLE_NAMES..)?
.iter()
.position(|art| *art == name)?;
u8::try_from(index).ok().map(Self)
}
#[must_use]
pub fn name(self) -> &'static str {
BORDER_NAMES
.get(params::LINE_STYLE_NAMES + usize::from(self.0))
.copied()
.unwrap_or_default()
}
}
const DRAWN_LINES: [Case<LineStyle>; 18] = [
own("threeDEmboss", LineStyle::ThreeD(Relief::Emboss)),
own("threeDEngrave", LineStyle::ThreeD(Relief::Engrave)),
own("inset", LineStyle::Single),
own("outset", LineStyle::Single),
own("nil", LineStyle::None),
own("none", LineStyle::None),
own("single", LineStyle::Single),
own("double", LineStyle::Double),
own("triple", LineStyle::Triple),
own("thinThickSmallGap", LineStyle::ThinThick(Gap::Small)),
own("thickThinSmallGap", LineStyle::ThickThin(Gap::Small)),
own(
"thinThickThinSmallGap",
LineStyle::ThinThickThin(Gap::Small),
),
own("thinThickMediumGap", LineStyle::ThinThick(Gap::Medium)),
own("thickThinMediumGap", LineStyle::ThickThin(Gap::Medium)),
own(
"thinThickThinMediumGap",
LineStyle::ThinThickThin(Gap::Medium),
),
own("thinThickLargeGap", LineStyle::ThinThick(Gap::Large)),
own("thickThinLargeGap", LineStyle::ThickThin(Gap::Large)),
own(
"thinThickThinLargeGap",
LineStyle::ThinThickThin(Gap::Large),
),
];
pub(crate) const BORDER_LINE: &Values<LineStyle> =
&Values::with_others(&DRAWN_LINES, BORDER_NAMES, LineStyle::Single);
fn border_parts(style: LineStyle, line: Length) -> BorderParts {
let gap = |gap: Gap| match gap {
Gap::Small => {
let small = eighth_points(params::SMALL_GAP_EIGHTHS);
(small, line, small)
}
Gap::Medium => {
let medium = line.div_toward_zero(params::MEDIUM_GAP_PARTS);
(medium, line, medium)
}
Gap::Large => (
eighth_points(params::LARGE_GAP_THIN_EIGHTHS),
eighth_points(params::LARGE_GAP_THICK_EIGHTHS),
line,
),
};
let compound = |lines: &[Length], gap: Length| {
let sizes: Vec<Length> = lines
.iter()
.rev()
.flat_map(|size| [gap, *size])
.skip(1)
.collect();
BorderParts::new(style, line, &sizes)
};
let repeated = |count: i64| {
BorderParts::new(
style,
line,
&vec![line; usize::try_from(count).unwrap_or(1)],
)
};
match style {
LineStyle::None | LineStyle::Single => BorderParts::new(style, line, &[line]),
LineStyle::Double => repeated(params::DOUBLE_BORDER_PARTS),
LineStyle::Triple => repeated(params::TRIPLE_BORDER_PARTS),
LineStyle::ThinThick(size) => {
let (thin, thick, space) = gap(size);
compound(&[thin, thick], space)
}
LineStyle::ThickThin(size) => {
let (thin, thick, space) = gap(size);
compound(&[thick, thin], space)
}
LineStyle::ThinThickThin(size) => {
let (thin, thick, space) = gap(size);
compound(&[thin, thick, thin], space)
}
LineStyle::ThreeD(_) => {
let [narrow, wide] = params::THREE_D_BAND_EIGHTHS;
let eighths = if line < eighth_points(params::THREE_D_WIDE_LINE_EIGHTHS) {
narrow
} else {
wide
};
let band = eighth_points(eighths);
BorderParts::new(style, line, &[band, Length::ZERO, line, Length::ZERO, band])
}
}
}
fn eighth_points(eighths: i64) -> Length {
Length::from_eighth_points(eighths).unwrap_or(Length::ZERO)
}
fn relief_shades(color: Color) -> [Rgb; 3] {
let rgb = |[r, g, b]: [u8; 3]| Rgb { r, g, b };
let channels = match color {
Color::Auto => return params::THREE_D_BLACK_BANDS.map(rgb),
Color::Rgb(channels) => channels,
};
if channels == [0; 3] {
return params::THREE_D_BLACK_BANDS.map(rgb);
}
if channels == super::color::WHITE {
return params::THREE_D_WHITE_BANDS.map(rgb);
}
let steps = params::THREE_D_LIGHTNESS_STEPS;
let light = lightness(channels);
let light = light
+ params::THREE_D_LIGHTER_STEP
* params::THREE_D_LIGHTER_BELOW
.iter()
.fold(0, |count, &below| count + i64::from(light < below));
let [middle, dark] = params::THREE_D_DARKER.map(|darker| (light - darker).max(0));
[light.min(steps), middle, dark].map(|lightness| rgb(with_lightness(channels, lightness)))
}
fn lightness(channels: [u8; 3]) -> i64 {
let (high, low) = extremes(channels);
f_office_units::div_round(
(high + low) * params::THREE_D_LIGHTNESS_STEPS,
2 * i64::from(u8::MAX),
)
}
fn extremes(channels: [u8; 3]) -> (i64, i64) {
let wide = channels.map(i64::from);
let high = wide.iter().copied().max().unwrap_or(0);
let low = wide.iter().copied().min().unwrap_or(0);
(high, low)
}
fn with_lightness(channels: [u8; 3], lightness: i64) -> [u8; 3] {
let steps = params::THREE_D_LIGHTNESS_STEPS;
let whole = i64::from(u8::MAX);
let (high, low) = extremes(channels);
let full = 2 * whole * steps;
let room = |sum: i64| sum.min(full - sum);
let (old, new) = ((high + low) * steps, lightness * 2 * whole);
let chroma = (high - low) * steps;
let new_chroma = if room(old) == 0 {
0
} else {
chroma * room(new) / room(old)
};
channels.map(|channel| {
let share = if high == low {
0
} else {
(i64::from(channel) - low) * new_chroma / (high - low)
};
let value = f_office_units::div_round(new - new_chroma + 2 * share, 2 * steps);
u8::try_from(value.clamp(0, whole)).unwrap_or(u8::MAX)
})
}
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
pub struct Borders {
pub top: Option<Border>,
pub bottom: Option<Border>,
pub left: Option<Border>,
pub right: Option<Border>,
pub between: Option<Border>,
}
impl Borders {
#[must_use]
pub fn in_whole_twips(self) -> Self {
let cut = |side: Option<Border>| side.map(Border::in_whole_twips);
Self {
top: cut(self.top),
bottom: cut(self.bottom),
left: cut(self.left),
right: cut(self.right),
between: cut(self.between),
}
}
#[must_use]
pub fn as_one_line(self) -> Self {
let one = |side: Option<Border>| side.map(Border::as_one_line);
Self {
top: one(self.top),
bottom: one(self.bottom),
left: one(self.left),
right: one(self.right),
between: one(self.between),
}
}
#[must_use]
pub fn without_none(self) -> Self {
let line = |side: Option<Border>| side.filter(|border| !border.is_none());
Self {
top: line(self.top),
bottom: line(self.bottom),
..self
}
}
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum NamedSide {
Line(Border),
Hidden,
}
impl NamedSide {
#[must_use]
pub fn line(side: Option<Self>) -> Option<Border> {
match side {
Some(Self::Line(border)) => Some(border),
Some(Self::Hidden) | None => None,
}
}
}
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
pub struct NamedSides {
pub top: Option<NamedSide>,
pub bottom: Option<NamedSide>,
pub left: Option<NamedSide>,
pub right: Option<NamedSide>,
pub between: Option<NamedSide>,
}
impl NamedSides {
pub fn apply(&mut self, other: &Self) {
for (side, named) in [
(&mut self.top, other.top),
(&mut self.bottom, other.bottom),
(&mut self.left, other.left),
(&mut self.right, other.right),
(&mut self.between, other.between),
] {
if named.is_some() {
*side = named;
}
}
}
pub fn overlay(sides: &mut Option<Box<Self>>, other: Option<&Self>) {
if let Some(other) = other {
sides.get_or_insert_with(Box::default).apply(other);
}
}
#[must_use]
pub fn borders(self) -> Borders {
Borders {
top: NamedSide::line(self.top),
bottom: NamedSide::line(self.bottom),
left: NamedSide::line(self.left),
right: NamedSide::line(self.right),
between: NamedSide::line(self.between),
}
}
}
pub(super) fn read_borders(reader: &mut PartReader, node: NodeId) -> (Borders, NamedSides) {
let doc = reader.doc;
if doc
.child(node, W, "bar")
.is_some_and(|side| has_line(doc, side))
{
reader.feature_not_supported(Feature::BarBorder);
}
let mut named = |name, edge: bool| {
let side = doc.child(node, W, name)?;
let line = read_border(reader, side).or_else(|| edge.then(|| read_none(reader, side))?);
Some(line.map_or(NamedSide::Hidden, NamedSide::Line))
};
let left = named("left", false);
let left_start = NamedSide::line(left).or_else(|| NamedSide::line(named("start", false)));
let right = named("right", false);
let right_end = NamedSide::line(right).or_else(|| NamedSide::line(named("end", false)));
let sides = NamedSides {
top: named("top", true),
bottom: named("bottom", true),
left,
right,
between: named("between", false),
};
let borders = Borders {
left: left_start,
right: right_end,
..sides.borders()
};
(borders, sides)
}
fn has_line(doc: &Document, side: NodeId) -> bool {
doc.attribute(side, Some(W), "val")
.and_then(|name| BORDER_LINE.find(name))
.is_some_and(|(style, _, _)| !matches!(style, LineStyle::None))
}
fn read_none(reader: &mut PartReader, side: NodeId) -> Option<Border> {
let named = reader.doc.attribute(side, Some(W), "val") == Some("none");
let space = Length::from_points(reader.whole_number(side, "space").unwrap_or(0))?;
(named && space > Length::ZERO).then(|| Border::none(space))
}
pub(crate) fn read_border(reader: &mut PartReader, side: NodeId) -> Option<Border> {
let style = read_line_style(reader, side, BORDER_LINE)?;
read_border_as(reader, side, style)
}
pub(crate) fn read_line_style(
reader: &mut PartReader,
side: NodeId,
table: &'static Values<LineStyle>,
) -> Option<LineStyle> {
let style = reader.enumeration(side, "val", table)?;
let drawn = reader.border_styles().drawn(style);
if drawn != style {
let doc = reader.doc;
if let Some((_, spelling, _)) = doc
.attribute(side, Some(W), "val")
.and_then(|name| table.find(name))
{
reader.not_supported(side, attribute("val"), spelling);
}
}
Some(drawn)
}
pub(crate) fn read_table_border(reader: &mut PartReader, side: NodeId) -> Option<Border> {
let dash = reader
.doc
.attribute(side, Some(W), "val")
.and_then(|name| BORDER_DASH.find(name))
.map(|(dash, _, _)| *dash);
read_border(reader, side).map(|border| Border {
dash,
..border.as_one_line()
})
}
pub(crate) fn read_border_as(
reader: &mut PartReader,
side: NodeId,
style: LineStyle,
) -> Option<Border> {
if style == LineStyle::None {
return None;
}
let doc = reader.doc;
let line = Length::from_eighth_points(reader.whole_number(side, "sz").unwrap_or(0))?;
let space = Length::from_points(reader.whole_number(side, "space").unwrap_or(0))?;
Some(Border::new(
border_parts(style, line),
space,
doc.attribute(side, Some(W), "color")
.map_or(Color::Auto, parse_color),
))
}
#[cfg(test)]
mod tests {
use super::{
Border, BorderParts, Borders, Color, Gap, LineStyle, NamedSide, NamedSides, Relief,
border_parts,
};
use f_office_paint::Rgb;
use f_office_units::Length;
fn relief(relief: Relief, eighths: i64, color: Color) -> Border {
let line = Length::from_eighth_points(eighths).unwrap();
Border::new(
border_parts(LineStyle::ThreeD(relief), line),
Length::ZERO,
color,
)
}
#[test]
fn draws_a_three_d_side_as_a_line_between_two_touching_bands() {
let eighths = |sizes: Vec<(Length, Length)>| -> Vec<(i64, i64)> {
let eighth = Length::from_eighth_points(1).unwrap().units();
sizes
.into_iter()
.map(|(offset, size)| (offset.units() / eighth, size.units() / eighth))
.collect()
};
let narrow = relief(Relief::Emboss, 18, Color::Auto);
assert_eq!(eighths(narrow.lines()), [(0, 6), (6, 18), (24, 6)]);
assert_eq!(narrow.width, Length::from_eighth_points(30).unwrap());
assert_eq!(
eighths(relief(Relief::Engrave, 24, Color::Auto).lines()),
[(0, 12), (12, 24), (36, 12)]
);
assert!(narrow.touches());
assert_eq!(
narrow.as_one_line(),
Border::new(
BorderParts::single(Length::from_eighth_points(18).unwrap()),
Length::ZERO,
Color::Auto
)
);
}
#[test]
fn shades_the_bands_of_a_three_d_side_in_their_order_on_the_page() {
let gray = |v: u8| Rgb { r: v, g: v, b: v };
let colors = |relief_of: Relief, color: Color| relief(relief_of, 18, color).line_colors();
for black in [Color::Auto, Color::Rgb([0; 3])] {
assert_eq!(
colors(Relief::Emboss, black),
[gray(192), gray(96), gray(0)]
);
assert_eq!(
colors(Relief::Engrave, black),
[gray(0), gray(96), gray(192)]
);
}
assert_eq!(
colors(Relief::Emboss, Color::Rgb([255; 3])),
[gray(255), gray(160), gray(128)]
);
let red = |r, g| Rgb { r, g, b: g };
assert_eq!(
colors(Relief::Emboss, Color::Rgb([0xFD, 0, 0])),
[red(255, 83), red(189, 0), red(168, 0)]
);
assert_eq!(
colors(Relief::Emboss, Color::Rgb([0x7D, 0, 0])),
[red(255, 40), red(147, 0), red(125, 0)]
);
}
#[test]
fn named_sides_overlay_side_by_side_and_a_hidden_side_hides_the_one_below() {
let line = |eighths| {
Border::new(
border_parts(
LineStyle::Single,
Length::from_eighth_points(eighths).unwrap(),
),
Length::from_points(1).unwrap(),
Color::Auto,
)
};
let style = NamedSides {
top: Some(NamedSide::Line(line(12))),
bottom: Some(NamedSide::Line(line(12))),
left: Some(NamedSide::Line(line(12))),
right: Some(NamedSide::Line(line(12))),
between: None,
};
let own = NamedSides {
right: Some(NamedSide::Line(line(24))),
bottom: Some(NamedSide::Hidden),
..NamedSides::default()
};
let mut sides = style;
sides.apply(&own);
assert_eq!(
sides.borders(),
Borders {
top: Some(line(12)),
bottom: None,
left: Some(line(12)),
right: Some(line(24)),
between: None,
}
);
sides.apply(&NamedSides::default());
assert_eq!(sides.borders().right, Some(line(24)));
}
#[test]
fn counts_a_thick_and_thin_side_as_drawing_the_lines_of_its_thin_and_thick_turn() {
let side = |style: LineStyle, eighths: i64| {
let line = Length::from_eighth_points(eighths).unwrap();
Border::new(border_parts(style, line), Length::ZERO, Color::Auto)
};
let thin_thick = side(LineStyle::ThinThick(Gap::Small), 24);
assert!(thin_thick.draws_like(&side(LineStyle::ThickThin(Gap::Small), 24)));
assert!(thin_thick.draws_like(&thin_thick));
assert!(!thin_thick.draws_like(&side(LineStyle::ThickThin(Gap::Small), 18)));
assert!(!thin_thick.draws_like(&side(LineStyle::ThickThin(Gap::Medium), 24)));
assert!(!side(LineStyle::Double, 24).draws_like(&side(LineStyle::Triple, 24)));
assert!(
!side(LineStyle::ThinThickThin(Gap::Small), 24)
.draws_like(&side(LineStyle::ThinThick(Gap::Small), 24))
);
}
}