Files
qbz/crates/vendor/femtovg-0.23.2/tests/transform2D.rs
T
vicrodh 3a1c367d1a fix(text): render CJK glyphs at non-regular weights on macOS
Vendor femtovg 0.23.2 with a targeted patch: the swash raster path can
fail to scale some variable fonts at a non-default variation instance
(the CFF2-based CJK system fonts on modern macOS), and femtovg cached
those glyphs as permanently missing — so track titles and any other
text at medium/semibold/bold weight rendered blank for CJK while
regular weight (empty coords) worked. render_glyph now retries the
glyph at the font's default instance before giving up: worst case the
glyph draws at regular weight instead of not at all. Fonts and
instances that already render are untouched.

Fixes #543

cc
2026-07-05 08:23:17 -06:00

86 lines
2.2 KiB
Rust

use femtovg::Transform2D;
#[test]
fn test_multiplication() {
let a = Transform2D::new(1.0, 2.0, 3.0, 4.0, 5.0, 6.0);
let b = Transform2D::new(7.0, 8.0, 9.0, 10.0, 11.0, 12.0);
let expected = Transform2D::new(25.0, 28.0, 57.0, 64.0, 100.0, 112.0);
let result = a * b;
assert_eq!(result, expected);
}
#[test]
fn test_multiplication_assignment() {
let mut a = Transform2D::new(1.0, 2.0, 3.0, 4.0, 5.0, 6.0);
let b = Transform2D::new(7.0, 8.0, 9.0, 10.0, 11.0, 12.0);
let expected = Transform2D::new(25.0, 28.0, 57.0, 64.0, 100.0, 112.0);
a *= b;
assert_eq!(a, expected);
}
#[test]
fn test_premultiply() {
let a = Transform2D::new(1.0, 2.0, 3.0, 4.0, 5.0, 6.0);
let b = Transform2D::new(7.0, 8.0, 9.0, 10.0, 11.0, 12.0);
let mut premultiplied = a;
premultiplied.premultiply(&b);
assert_eq!(premultiplied, b * a);
}
#[test]
fn test_division() {
let a = Transform2D::new(1.0, 2.0, 3.0, 4.0, 5.0, 6.0);
let b = Transform2D::new(7.0, 8.0, 9.0, 10.0, 11.0, 12.0);
let expected = Transform2D::new(-2.0, 3.0, -3.0, 4.0, -3.0, 3.0);
let result = b / a;
assert_eq!(result, expected);
}
#[test]
fn test_division_assignment() {
let a = Transform2D::new(1.0, 2.0, 3.0, 4.0, 5.0, 6.0);
let mut b = Transform2D::new(7.0, 8.0, 9.0, 10.0, 11.0, 12.0);
let expected = Transform2D::new(-2.0, 3.0, -3.0, 4.0, -3.0, 3.0);
b /= a;
assert_eq!(b, expected);
}
#[test]
fn test_translation() {
let transform = Transform2D::new(1.0, 2.0, 3.0, 4.0, 5.0, 6.0);
let (tx, ty) = (2.0, 5.0);
let mut translated = transform;
translated.translate(tx, ty);
assert_eq!(translated, transform * Transform2D::translation(tx, ty))
}
#[test]
fn test_rotation() {
let transform = Transform2D::new(1.0, 2.0, 3.0, 4.0, 5.0, 6.0);
let a = std::f32::consts::TAU * 0.75;
let mut scaled = transform;
scaled.rotate(a);
assert_eq!(scaled, transform * Transform2D::rotation(a))
}
#[test]
fn test_scaling() {
let transform = Transform2D::new(1.0, 2.0, 3.0, 4.0, 5.0, 6.0);
let (sx, sy) = (2.0, 0.5);
let mut scaled = transform;
scaled.scale(sx, sy);
assert_eq!(scaled, transform * Transform2D::scaling(sx, sy))
}