use super::*;
fn points(value: i64) -> Length {
Length::from_points(value).unwrap()
}
fn billionths(share: i128) -> i128 {
div_round_i128(share * 1_000_000_000, ONE)
}
#[test]
fn takes_the_whole_length_at_the_reference_size_and_less_below_it() {
assert_eq!(share(TEXT_SHADOW_SIZE), ONE);
for (size, expected) in [
(36, 615_572_207),
(18, 378_929_142),
(144, 1_624_504_793),
(11, 268_436_849),
] {
assert_eq!(billionths(share(points(size))), expected, "{size} pt");
}
assert_eq!(share(Length::ZERO), 0);
assert_eq!(share(Length::from_units(-1)), 0);
}
#[test]
fn gives_the_room_of_the_blur_less_and_plus_the_offset_down() {
let shadow = |blur, distance, direction| TextShadow {
blur: points(blur),
distance: points(distance),
direction,
color: None,
transparency: 0,
};
let room = room(shadow(4, 3, 5_400_000), TEXT_SHADOW_SIZE);
assert_eq!(room.above, points(1));
assert_eq!(room.below, points(7));
let up = super::room(shadow(4, 3, 16_200_000), TEXT_SHADOW_SIZE);
assert_eq!((up.above, up.below), (points(7), points(1)));
let right = super::room(shadow(4, 3, 0), TEXT_SHADOW_SIZE);
assert_eq!((right.above, right.below), (points(4), points(4)));
let sharp = super::room(shadow(0, 3, 5_400_000), TEXT_SHADOW_SIZE);
assert_eq!((sharp.above, sharp.below), (Length::ZERO, points(3)));
let small = super::room(shadow(4, 3, 5_400_000), points(18));
assert_eq!(small.above, Length::from_units(9_625));
assert_eq!(small.below, Length::from_units(67_373));
}
#[test]
fn draws_a_sharp_opaque_shadow_as_paths_or_picture_for_an_outline() {
let sharp = TextShadow {
distance: points(3),
direction: 0,
color: Some([0x44, 0x72, 0xC4]),
..TextShadow::default()
};
let shadow = drawn(sharp, None, false, TEXT_SHADOW_SIZE).unwrap();
assert_eq!((shadow.across, shadow.down), (points(3), Length::ZERO));
assert_eq!(
shadow.color,
Rgb {
r: 0x44,
g: 0x72,
b: 0xC4
}
);
assert_eq!(shadow.form, ShadowForm::Paths);
let outline = Outline {
width: points(1),
color: Rgb::BLACK,
join: f_office_paint::Join::Round,
};
let outlined = drawn(sharp, Some(outline), false, TEXT_SHADOW_SIZE).unwrap();
assert_eq!(
outlined.form,
ShadowForm::Picture {
blur: Length::ZERO,
opacity: Opacity::FULL,
outline_width: points(1),
}
);
}
#[test]
fn draws_blurred_and_translucent_text_shadows_as_pictures() {
let sharp = TextShadow {
distance: points(3),
direction: 0,
color: Some([0, 0, 0]),
..TextShadow::default()
};
let blurred = drawn(
TextShadow {
blur: points(4),
transparency: 60_000,
..sharp
},
None,
false,
TEXT_SHADOW_SIZE,
)
.unwrap();
assert_eq!(
blurred.form,
ShadowForm::Picture {
blur: points(4),
opacity: Opacity::clamped(40_000),
outline_width: Length::ZERO,
}
);
}
#[test]
fn leaves_unknown_clear_and_scaled_text_shadows_undrawn() {
let sharp = TextShadow {
distance: points(3),
direction: 0,
color: Some([0x44, 0x72, 0xC4]),
..TextShadow::default()
};
let outline = Outline {
width: points(1),
color: Rgb::BLACK,
join: f_office_paint::Join::Round,
};
assert_eq!(
drawn(
TextShadow {
transparency: DRAWING_WHOLE,
..sharp
},
None,
false,
TEXT_SHADOW_SIZE
),
None
);
assert_eq!(
drawn(
TextShadow {
color: None,
..sharp
},
None,
false,
TEXT_SHADOW_SIZE
),
None
);
assert_eq!(drawn(sharp, None, true, TEXT_SHADOW_SIZE), None);
assert_eq!(drawn(sharp, Some(outline), true, TEXT_SHADOW_SIZE), None);
}
#[test]
fn takes_a_non_default_scale_as_scaled_run() {
let mut props = RunProps::default();
assert!(!scaled_run(&props));
props.scale = Some(PERCENT);
assert!(!scaled_run(&props));
props.scale = Some(150);
assert!(scaled_run(&props));
}