| 1 |
use crate::{convert, Unit::*}; |
| 2 |
use ttf_parser::colr::{self, ClipBox, CompositeMode, GradientExtend, Paint, Painter}; |
| 3 |
use ttf_parser::{cpal, GlyphId, RgbaColor}; |
| 4 |
|
| 5 |
#[test] |
| 6 |
fn basic() { |
| 7 |
let cpal_data = convert(&[ |
| 8 |
UInt16(0), // version |
| 9 |
UInt16(3), // number of palette entries |
| 10 |
UInt16(1), // number of palettes |
| 11 |
UInt16(3), // number of colors |
| 12 |
UInt32(14), // offset to colors |
| 13 |
UInt16(0), // index of palette 0's first color |
| 14 |
UInt8(10), UInt8(15), UInt8(20), UInt8(25), // color 0 |
| 15 |
UInt8(30), UInt8(35), UInt8(40), UInt8(45), // color 1 |
| 16 |
UInt8(50), UInt8(55), UInt8(60), UInt8(65), // color 2 |
| 17 |
]); |
| 18 |
|
| 19 |
let colr_data = convert(&[ |
| 20 |
UInt16(0), // version |
| 21 |
UInt16(3), // number of base glyphs |
| 22 |
UInt32(14), // offset to base glyphs |
| 23 |
UInt32(32), // offset to layers |
| 24 |
UInt16(4), // number of layers |
| 25 |
UInt16(2), UInt16(2), UInt16(2), // base glyph 0 (id 2) |
| 26 |
UInt16(3), UInt16(0), UInt16(3), // base glyph 1 (id 3) |
| 27 |
UInt16(7), UInt16(1), UInt16(1), // base glyph 2 (id 7) |
| 28 |
UInt16(10), UInt16(2), // layer 0 |
| 29 |
UInt16(11), UInt16(1), // layer 1 |
| 30 |
UInt16(12), UInt16(2), // layer 2 |
| 31 |
UInt16(13), UInt16(0), // layer 3 |
| 32 |
]); |
| 33 |
|
| 34 |
let cpal = cpal::Table::parse(&cpal_data).unwrap(); |
| 35 |
let colr = colr::Table::parse(cpal, &colr_data).unwrap(); |
| 36 |
let paint = |id| { |
| 37 |
let mut painter = VecPainter(vec![]); |
| 38 |
colr.paint(GlyphId(id), 0, &mut painter, &[], RgbaColor::new(0, 0, 0, 255)).map(|_| painter.0) |
| 39 |
}; |
| 40 |
|
| 41 |
let a = RgbaColor::new(20, 15, 10, 25); |
| 42 |
let b = RgbaColor::new(40, 35, 30, 45); |
| 43 |
let c = RgbaColor::new(60, 55, 50, 65); |
| 44 |
|
| 45 |
assert_eq!(cpal.get(0, 0), Some(a)); |
| 46 |
assert_eq!(cpal.get(0, 1), Some(b)); |
| 47 |
assert_eq!(cpal.get(0, 2), Some(c)); |
| 48 |
assert_eq!(cpal.get(0, 3), None); |
| 49 |
assert_eq!(cpal.get(1, 0), None); |
| 50 |
|
| 51 |
assert!(!colr.contains(GlyphId(1))); |
| 52 |
assert!(colr.contains(GlyphId(2))); |
| 53 |
assert!(colr.contains(GlyphId(3))); |
| 54 |
assert!(!colr.contains(GlyphId(4))); |
| 55 |
assert!(!colr.contains(GlyphId(5))); |
| 56 |
assert!(!colr.contains(GlyphId(6))); |
| 57 |
assert!(colr.contains(GlyphId(7))); |
| 58 |
|
| 59 |
let a = CustomPaint::Solid(a); |
| 60 |
let b = CustomPaint::Solid(b); |
| 61 |
let c = CustomPaint::Solid(c); |
| 62 |
|
| 63 |
assert_eq!(paint(1), None); |
| 64 |
|
| 65 |
assert_eq!( |
| 66 |
paint(2).unwrap(), vec![ |
| 67 |
Command::OutlineGlyph(GlyphId(12)), |
| 68 |
Command::Paint(c.clone()), |
| 69 |
Command::OutlineGlyph(GlyphId(13)), |
| 70 |
Command::Paint(a.clone())] |
| 71 |
); |
| 72 |
|
| 73 |
assert_eq!(paint(3).unwrap(), vec![ |
| 74 |
Command::OutlineGlyph(GlyphId(10)), |
| 75 |
Command::Paint(c.clone()), |
| 76 |
Command::OutlineGlyph(GlyphId(11)), |
| 77 |
Command::Paint(b.clone()), |
| 78 |
Command::OutlineGlyph(GlyphId(12)), |
| 79 |
Command::Paint(c.clone()), |
| 80 |
]); |
| 81 |
|
| 82 |
assert_eq!(paint(7).unwrap(), vec![ |
| 83 |
Command::OutlineGlyph(GlyphId(11)), |
| 84 |
Command::Paint(b.clone()), |
| 85 |
]); |
| 86 |
} |
| 87 |
|
| 88 |
#[derive(Clone, Debug, PartialEq)] |
| 89 |
struct CustomStop(f32, RgbaColor); |
| 90 |
|
| 91 |
#[derive(Clone, Debug, PartialEq)] |
| 92 |
enum CustomPaint { |
| 93 |
Solid(RgbaColor), |
| 94 |
LinearGradient(f32, f32, f32, f32, f32, f32, GradientExtend, Vec<CustomStop>), |
| 95 |
RadialGradient(f32, f32, f32, f32, f32, f32, GradientExtend, Vec<CustomStop>), |
| 96 |
SweepGradient(f32, f32, f32, f32, GradientExtend, Vec<CustomStop>), |
| 97 |
} |
| 98 |
|
| 99 |
#[derive(Clone, Debug, PartialEq)] |
| 100 |
enum Command { |
| 101 |
OutlineGlyph(GlyphId), |
| 102 |
Paint(CustomPaint), |
| 103 |
PushLayer(CompositeMode), |
| 104 |
PopLayer, |
| 105 |
Transform(ttf_parser::Transform), |
| 106 |
PopTransform, |
| 107 |
PushClip, |
| 108 |
PushClipBox(ClipBox), |
| 109 |
PopClip, |
| 110 |
} |
| 111 |
|
| 112 |
struct VecPainter(Vec<Command>); |
| 113 |
|
| 114 |
impl<'a> Painter<'a> for VecPainter { |
| 115 |
fn outline_glyph(&mut self, glyph_id: GlyphId) { |
| 116 |
self.0.push(Command::OutlineGlyph(glyph_id)); |
| 117 |
} |
| 118 |
|
| 119 |
fn paint(&mut self, paint: Paint<'a>) { |
| 120 |
let custom_paint = match paint { |
| 121 |
Paint::Solid(color) => CustomPaint::Solid(color), |
| 122 |
Paint::LinearGradient(lg) => CustomPaint::LinearGradient(lg.x0, lg.y0, |
| 123 |
lg.x1, lg.y1, |
| 124 |
lg.x2, lg.y2, |
| 125 |
lg.extend, lg.stops(0, &[]).map(|stop| CustomStop(stop.stop_offset, stop.color)).collect()), |
| 126 |
Paint::RadialGradient(rg) => CustomPaint::RadialGradient(rg.x0, rg.y0, |
| 127 |
rg.r0, rg.r1, |
| 128 |
rg.x1, rg.y1, |
| 129 |
rg.extend, rg.stops(0, &[]).map(|stop| CustomStop(stop.stop_offset, stop.color)).collect()), |
| 130 |
Paint::SweepGradient(sg) => CustomPaint::SweepGradient(sg.center_x, sg.center_y, |
| 131 |
sg.start_angle, sg.end_angle, |
| 132 |
sg.extend, sg.stops(0, &[]).map(|stop| CustomStop(stop.stop_offset, stop.color)).collect()), |
| 133 |
}; |
| 134 |
|
| 135 |
self.0.push(Command::Paint(custom_paint)); |
| 136 |
} |
| 137 |
|
| 138 |
fn push_layer(&mut self, mode: colr::CompositeMode) { |
| 139 |
self.0.push(Command::PushLayer(mode)); |
| 140 |
} |
| 141 |
|
| 142 |
fn pop_layer(&mut self) { |
| 143 |
self.0.push(Command::PopLayer) |
| 144 |
} |
| 145 |
|
| 146 |
fn push_transform(&mut self, transform: ttf_parser::Transform) { |
| 147 |
self.0.push(Command::Transform(transform)) |
| 148 |
} |
| 149 |
|
| 150 |
fn pop_transform(&mut self) { |
| 151 |
self.0.push(Command::PopTransform) |
| 152 |
} |
| 153 |
|
| 154 |
fn push_clip(&mut self) { |
| 155 |
self.0.push(Command::PushClip) |
| 156 |
} |
| 157 |
|
| 158 |
fn push_clip_box(&mut self, clipbox: ClipBox) { |
| 159 |
self.0.push(Command::PushClipBox(clipbox)) |
| 160 |
} |
| 161 |
|
| 162 |
fn pop_clip(&mut self) { |
| 163 |
self.0.push(Command::PopClip) |
| 164 |
} |
| 165 |
} |
| 166 |
|
| 167 |
// A static and variable COLRv1 test font from Google Fonts: |
| 168 |
// https://github.com/googlefonts/color-fonts |
| 169 |
static COLR1_STATIC: &[u8] = include_bytes!("../fonts/colr_1.ttf"); |
| 170 |
static COLR1_VARIABLE: &[u8] = include_bytes!("../fonts/colr_1_variable.ttf"); |
| 171 |
|
| 172 |
mod colr1_static { |
| 173 |
use ttf_parser::{Face, GlyphId, RgbaColor}; |
| 174 |
use ttf_parser::colr::ClipBox; |
| 175 |
use ttf_parser::colr::CompositeMode::*; |
| 176 |
use ttf_parser::colr::GradientExtend::*; |
| 177 |
use crate::colr::{COLR1_STATIC, Command, CustomStop, VecPainter}; |
| 178 |
use crate::colr::Command::*; |
| 179 |
use crate::colr::CustomPaint::*; |
| 180 |
|
| 181 |
#[test] |
| 182 |
fn linear_gradient() { |
| 183 |
let face = Face::parse(COLR1_STATIC, 0).unwrap(); |
| 184 |
let mut vec_painter = VecPainter(vec![]); |
| 185 |
face.paint_color_glyph(GlyphId(9), 0, RgbaColor::new(0, 0, 0, 255), &mut vec_painter); |
| 186 |
assert_eq!(vec_painter.0, vec![ |
| 187 |
PushClipBox(ClipBox { x_min: 100.0, y_min: 250.0, x_max: 900.0, y_max: 950.0 }), |
| 188 |
OutlineGlyph(GlyphId(9)), |
| 189 |
PushClip, |
| 190 |
Paint(LinearGradient(100.0, 250.0, 900.0, 250.0, 100.0, 300.0, Repeat, vec![ |
| 191 |
CustomStop(0.2000122, RgbaColor { red: 255, green: 0, blue: 0, alpha: 255 }), |
| 192 |
CustomStop(0.7999878, RgbaColor { red: 0, green: 0, blue: 255, alpha: 255 })])), |
| 193 |
PopClip, |
| 194 |
PopClip] |
| 195 |
) |
| 196 |
} |
| 197 |
|
| 198 |
#[test] |
| 199 |
fn sweep_gradient() { |
| 200 |
let face = Face::parse(COLR1_STATIC, 0).unwrap(); |
| 201 |
let mut vec_painter = VecPainter(vec![]); |
| 202 |
face.paint_color_glyph(GlyphId(13), 0, RgbaColor::new(0, 0, 0, 255), &mut vec_painter); |
| 203 |
assert_eq!(vec_painter.0, vec![ |
| 204 |
PushClipBox(ClipBox { x_min: 0.0, y_min: 0.0, x_max: 1000.0, y_max: 1000.0 }), |
| 205 |
OutlineGlyph(GlyphId(176)), |
| 206 |
PushClip, |
| 207 |
Paint(SweepGradient(500.0, 600.0, -0.666687, 0.666687, Pad, vec![ |
| 208 |
CustomStop(0.25, RgbaColor { red: 250, green: 240, blue: 230, alpha: 255 }), |
| 209 |
CustomStop(0.416687, RgbaColor { red: 0, green: 0, blue: 255, alpha: 255 }), |
| 210 |
CustomStop(0.583313, RgbaColor { red: 255, green: 0, blue: 0, alpha: 255 }), |
| 211 |
CustomStop(0.75, RgbaColor { red: 47, green: 79, blue: 79, alpha: 255 })])), |
| 212 |
PopClip, |
| 213 |
PopClip] |
| 214 |
) |
| 215 |
} |
| 216 |
|
| 217 |
#[test] |
| 218 |
fn scale_around_center() { |
| 219 |
let face = Face::parse(COLR1_STATIC, 0).unwrap(); |
| 220 |
let mut vec_painter = VecPainter(vec![]); |
| 221 |
face.paint_color_glyph(GlyphId(84), 0, RgbaColor::new(0, 0, 0, 255), &mut vec_painter); |
| 222 |
assert_eq!(vec_painter.0, vec![ |
| 223 |
PushLayer(SourceOver), |
| 224 |
OutlineGlyph(GlyphId(3)), |
| 225 |
PushClip, |
| 226 |
Paint(Solid(RgbaColor { red: 0, green: 0, blue: 255, alpha: 127 })), |
| 227 |
PopClip, |
| 228 |
PushLayer(DestinationOver), |
| 229 |
Transform(ttf_parser::Transform::new_translate(500.0, 500.0)), |
| 230 |
Transform(ttf_parser::Transform::new_scale(0.5, 1.5)), |
| 231 |
Transform(ttf_parser::Transform::new_translate(-500.0, -500.0)), |
| 232 |
OutlineGlyph( |
| 233 |
GlyphId(3)), |
| 234 |
PushClip, |
| 235 |
Paint(Solid(RgbaColor { red: 255, green: 165, blue: 0, alpha: 178 })), |
| 236 |
PopClip, |
| 237 |
PopTransform, |
| 238 |
PopTransform, |
| 239 |
PopTransform, |
| 240 |
PopLayer, |
| 241 |
PopLayer] |
| 242 |
) |
| 243 |
} |
| 244 |
|
| 245 |
#[test] |
| 246 |
fn scale() { |
| 247 |
let face = Face::parse(COLR1_STATIC, 0).unwrap(); |
| 248 |
let mut vec_painter = VecPainter(vec![]); |
| 249 |
face.paint_color_glyph(GlyphId(86), 0, RgbaColor::new(0, 0, 0, 255), &mut vec_painter); |
| 250 |
assert!(vec_painter.0.contains(&Transform(ttf_parser::Transform::new_scale(0.5, 1.5)))) |
| 251 |
} |
| 252 |
|
| 253 |
#[test] |
| 254 |
fn radial_gradient() { |
| 255 |
let face = Face::parse(COLR1_STATIC, 0).unwrap(); |
| 256 |
let mut vec_painter = VecPainter(vec![]); |
| 257 |
face.paint_color_glyph(GlyphId(93), 0, RgbaColor::new(0, 0, 0, 255), &mut vec_painter); |
| 258 |
assert_eq!(vec_painter.0, vec![ |
| 259 |
PushClipBox(ClipBox { x_min: 0.0, y_min: 0.0, x_max: 1000.0, y_max: 1000.0 }), |
| 260 |
OutlineGlyph(GlyphId(2)), |
| 261 |
PushClip, |
| 262 |
Paint(RadialGradient(166.0, 768.0, 0.0, 256.0, 166.0, 768.0, Pad, vec![ |
| 263 |
CustomStop(0.0, RgbaColor { red: 0, green: 128, blue: 0, alpha: 255 }), |
| 264 |
CustomStop(0.5, RgbaColor { red: 255, green: 255, blue: 255, alpha: 255 }), |
| 265 |
CustomStop(1.0, RgbaColor { red: 255, green: 0, blue: 0, alpha: 255 })])), |
| 266 |
PopClip, |
| 267 |
PopClip] |
| 268 |
) |
| 269 |
} |
| 270 |
|
| 271 |
#[test] |
| 272 |
fn rotate() { |
| 273 |
let face = Face::parse(COLR1_STATIC, 0).unwrap(); |
| 274 |
let mut vec_painter = VecPainter(vec![]); |
| 275 |
face.paint_color_glyph(GlyphId(99), 0, RgbaColor::new(0, 0, 0, 255), &mut vec_painter); |
| 276 |
assert!(vec_painter.0.contains(&Transform(ttf_parser::Transform::new_rotate(0.055541992)))) |
| 277 |
} |
| 278 |
|
| 279 |
#[test] |
| 280 |
fn rotate_around_center() { |
| 281 |
let face = Face::parse(COLR1_STATIC, 0).unwrap(); |
| 282 |
let mut vec_painter = VecPainter(vec![]); |
| 283 |
face.paint_color_glyph(GlyphId(101), 0, RgbaColor::new(0, 0, 0, 255), &mut vec_painter); |
| 284 |
assert_eq!(vec_painter.0, vec![ |
| 285 |
PushLayer(SourceOver), |
| 286 |
OutlineGlyph(GlyphId(3)), |
| 287 |
PushClip, |
| 288 |
Paint(Solid(RgbaColor { red: 0, green: 0, blue: 255, alpha: 127 })), |
| 289 |
PopClip, |
| 290 |
PushLayer(DestinationOver), |
| 291 |
Transform(ttf_parser::Transform::new_translate(500.0, 500.0)), |
| 292 |
Transform(ttf_parser::Transform::new_rotate(0.13891602)), |
| 293 |
Transform(ttf_parser::Transform::new_translate(-500.0, -500.0)), |
| 294 |
OutlineGlyph(GlyphId(3)), |
| 295 |
PushClip, |
| 296 |
Paint(Solid(RgbaColor { red: 255, green: 165, blue: 0, alpha: 178 })), |
| 297 |
PopClip, |
| 298 |
PopTransform, |
| 299 |
PopTransform, |
| 300 |
PopTransform, |
| 301 |
PopLayer, |
| 302 |
PopLayer, |
| 303 |
] |
| 304 |
) |
| 305 |
} |
| 306 |
|
| 307 |
#[test] |
| 308 |
fn skew() { |
| 309 |
let face = Face::parse(COLR1_STATIC, 0).unwrap(); |
| 310 |
let mut vec_painter = VecPainter(vec![]); |
| 311 |
face.paint_color_glyph(GlyphId(103), 0, RgbaColor::new(0, 0, 0, 255), &mut vec_painter); |
| 312 |
assert!(vec_painter.0.contains(&Transform(ttf_parser::Transform::new_skew(0.13891602, 0.0)))); |
| 313 |
} |
| 314 |
|
| 315 |
#[test] |
| 316 |
fn skew_around_center() { |
| 317 |
let face = Face::parse(COLR1_STATIC, 0).unwrap(); |
| 318 |
let mut vec_painter = VecPainter(vec![]); |
| 319 |
face.paint_color_glyph(GlyphId(104), 0, RgbaColor::new(0, 0, 0, 255), &mut vec_painter); |
| 320 |
assert_eq!(vec_painter.0, vec![ |
| 321 |
PushLayer(SourceOver), |
| 322 |
OutlineGlyph(GlyphId(3)), |
| 323 |
PushClip, |
| 324 |
Paint(Solid(RgbaColor { red: 0, green: 0, blue: 255, alpha: 127 })), |
| 325 |
PopClip, |
| 326 |
PushLayer(DestinationOver), |
| 327 |
Transform(ttf_parser::Transform::new_translate(500.0, 500.0)), |
| 328 |
Transform(ttf_parser::Transform::new_skew(0.13891602, 0.0)), |
| 329 |
Transform(ttf_parser::Transform::new_translate(-500.0, -500.0)), |
| 330 |
OutlineGlyph(GlyphId(3)), |
| 331 |
PushClip, |
| 332 |
Paint(Solid(RgbaColor { red: 255, green: 165, blue: 0, alpha: 178 })), |
| 333 |
PopClip, |
| 334 |
PopTransform, |
| 335 |
PopTransform, |
| 336 |
PopTransform, |
| 337 |
PopLayer, |
| 338 |
PopLayer]) |
| 339 |
} |
| 340 |
|
| 341 |
#[test] |
| 342 |
fn transform() { |
| 343 |
let face = Face::parse(COLR1_STATIC, 0).unwrap(); |
| 344 |
let mut vec_painter = VecPainter(vec![]); |
| 345 |
face.paint_color_glyph(GlyphId(109), 0, RgbaColor::new(0, 0, 0, 255), &mut vec_painter); |
| 346 |
|
| 347 |
assert!(vec_painter.0.contains(&Transform(ttf_parser::Transform { |
| 348 |
a: 1.0, |
| 349 |
b: 0.0, |
| 350 |
c: 0.0, |
| 351 |
d: 1.0, |
| 352 |
e: 125.0, |
| 353 |
f: 125.0 |
| 354 |
} |
| 355 |
))); |
| 356 |
} |
| 357 |
|
| 358 |
#[test] |
| 359 |
fn translate() { |
| 360 |
let face = Face::parse(COLR1_STATIC, 0).unwrap(); |
| 361 |
let mut vec_painter = VecPainter(vec![]); |
| 362 |
face.paint_color_glyph(GlyphId(114), 0, RgbaColor::new(0, 0, 0, 255), &mut vec_painter); |
| 363 |
|
| 364 |
assert!(vec_painter.0.contains(&Transform(ttf_parser::Transform::new_translate(0.0, 100.0)))); |
| 365 |
} |
| 366 |
|
| 367 |
#[test] |
| 368 |
fn composite() { |
| 369 |
let face = Face::parse(COLR1_STATIC, 0).unwrap(); |
| 370 |
let mut vec_painter = VecPainter(vec![]); |
| 371 |
face.paint_color_glyph(GlyphId(131), 0, RgbaColor::new(0, 0, 0, 255), &mut vec_painter); |
| 372 |
|
| 373 |
assert!(vec_painter.0.contains(&Command::PushLayer(Xor))); |
| 374 |
} |
| 375 |
|
| 376 |
#[test] |
| 377 |
fn cyclic_dependency() { |
| 378 |
let face = Face::parse(COLR1_STATIC, 0).unwrap(); |
| 379 |
let mut vec_painter = VecPainter(vec![]); |
| 380 |
face.paint_color_glyph(GlyphId(179), 0, RgbaColor::new(0, 0, 0, 255), &mut vec_painter); |
| 381 |
} |
| 382 |
} |
| 383 |
|
| 384 |
|
| 385 |
mod colr1_variable { |
| 386 |
use ttf_parser::{Face, GlyphId, RgbaColor, Tag}; |
| 387 |
use ttf_parser::colr::ClipBox; |
| 388 |
use ttf_parser::colr::GradientExtend::*; |
| 389 |
use crate::colr::{COLR1_STATIC, COLR1_VARIABLE, CustomStop, VecPainter}; |
| 390 |
use crate::colr::Command::*; |
| 391 |
use crate::colr::CustomPaint::*; |
| 392 |
|
| 393 |
#[test] |
| 394 |
fn sweep_gradient() { |
| 395 |
let mut face = Face::parse(COLR1_VARIABLE, 0).unwrap(); |
| 396 |
face.set_variation(Tag::from_bytes(b"SWPS"), 45.0); |
| 397 |
face.set_variation(Tag::from_bytes(b"SWPE"), 58.0); |
| 398 |
let mut vec_painter = VecPainter(vec![]); |
| 399 |
face.paint_color_glyph(GlyphId(13), 0, RgbaColor::new(0, 0, 0, 255), &mut vec_painter); |
| 400 |
assert!(vec_painter.0.contains(&Paint(SweepGradient(500.0, 600.0, -0.416687, 0.9888916, Pad, vec![ |
| 401 |
CustomStop(0.25, RgbaColor { red: 250, green: 240, blue: 230, alpha: 255 }), |
| 402 |
CustomStop(0.416687, RgbaColor { red: 0, green: 0, blue: 255, alpha: 255 }), |
| 403 |
CustomStop(0.583313, RgbaColor { red: 255, green: 0, blue: 0, alpha: 255 }), |
| 404 |
CustomStop(0.75, RgbaColor { red: 47, green: 79, blue: 79, alpha: 255 })])) |
| 405 |
)); |
| 406 |
} |
| 407 |
|
| 408 |
#[test] |
| 409 |
fn scale_around_center() { |
| 410 |
let mut face = Face::parse(COLR1_VARIABLE, 0).unwrap(); |
| 411 |
face.set_variation(Tag::from_bytes(b"SCSX"), 1.1); |
| 412 |
face.set_variation(Tag::from_bytes(b"SCSY"), -0.9); |
| 413 |
let mut vec_painter = VecPainter(vec![]); |
| 414 |
face.paint_color_glyph(GlyphId(84), 0, RgbaColor::new(0, 0, 0, 255), &mut vec_painter); |
| 415 |
assert!(vec_painter.0.contains(&Transform(ttf_parser::Transform::new_scale(1.599942, 0.60009766)))) |
| 416 |
} |
| 417 |
|
| 418 |
#[test] |
| 419 |
fn scale() { |
| 420 |
let mut face = Face::parse(COLR1_VARIABLE, 0).unwrap(); |
| 421 |
face.set_variation(Tag::from_bytes(b"SCSX"), 1.1); |
| 422 |
face.set_variation(Tag::from_bytes(b"SCSY"), -0.9); |
| 423 |
let mut vec_painter = VecPainter(vec![]); |
| 424 |
face.paint_color_glyph(GlyphId(86), 0, RgbaColor::new(0, 0, 0, 255), &mut vec_painter); |
| 425 |
assert!(vec_painter.0.contains(&Transform(ttf_parser::Transform::new_scale(1.599942, 0.60009766)))) |
| 426 |
} |
| 427 |
|
| 428 |
#[test] |
| 429 |
fn radial_gradient() { |
| 430 |
let face = Face::parse(COLR1_STATIC, 0).unwrap(); |
| 431 |
let mut vec_painter = VecPainter(vec![]); |
| 432 |
face.paint_color_glyph(GlyphId(93), 0, RgbaColor::new(0, 0, 0, 255), &mut vec_painter); |
| 433 |
assert_eq!(vec_painter.0, vec![ |
| 434 |
PushClipBox(ClipBox { x_min: 0.0, y_min: 0.0, x_max: 1000.0, y_max: 1000.0 }), |
| 435 |
OutlineGlyph(GlyphId(2)), |
| 436 |
PushClip, |
| 437 |
Paint(RadialGradient(166.0, 768.0, 0.0, 256.0, 166.0, 768.0, Pad, vec![ |
| 438 |
CustomStop(0.0, RgbaColor { red: 0, green: 128, blue: 0, alpha: 255 }), |
| 439 |
CustomStop(0.5, RgbaColor { red: 255, green: 255, blue: 255, alpha: 255 }), |
| 440 |
CustomStop(1.0, RgbaColor { red: 255, green: 0, blue: 0, alpha: 255 })])), |
| 441 |
PopClip, |
| 442 |
PopClip] |
| 443 |
) |
| 444 |
} |
| 445 |
|
| 446 |
#[test] |
| 447 |
fn rotate() { |
| 448 |
let mut face = Face::parse(COLR1_VARIABLE, 0).unwrap(); |
| 449 |
face.set_variation(Tag::from_bytes(b"ROTA"), 150.0); |
| 450 |
let mut vec_painter = VecPainter(vec![]); |
| 451 |
face.paint_color_glyph(GlyphId(99), 0, RgbaColor::new(0, 0, 0, 255), &mut vec_painter); |
| 452 |
assert!(vec_painter.0.contains(&Transform(ttf_parser::Transform::new_rotate(0.87341005)))) |
| 453 |
} |
| 454 |
|
| 455 |
#[test] |
| 456 |
fn rotate_around_center() { |
| 457 |
let mut face = Face::parse(COLR1_VARIABLE, 0).unwrap(); |
| 458 |
face.set_variation(Tag::from_bytes(b"ROTA"), 150.0); |
| 459 |
let mut vec_painter = VecPainter(vec![]); |
| 460 |
face.paint_color_glyph(GlyphId(101), 0, RgbaColor::new(0, 0, 0, 255), &mut vec_painter); |
| 461 |
assert!(vec_painter.0.contains(&Transform(ttf_parser::Transform::new_rotate(0.9336252)))) |
| 462 |
} |
| 463 |
|
| 464 |
#[test] |
| 465 |
fn skew() { |
| 466 |
let mut face = Face::parse(COLR1_VARIABLE, 0).unwrap(); |
| 467 |
face.set_variation(Tag::from_bytes(b"SKXA"), 46.0); |
| 468 |
let mut vec_painter = VecPainter(vec![]); |
| 469 |
face.paint_color_glyph(GlyphId(103), 0, RgbaColor::new(0, 0, 0, 255), &mut vec_painter); |
| 470 |
assert!(vec_painter.0.contains(&Transform(ttf_parser::Transform::new_skew(0.3944702, 0.0)))); |
| 471 |
} |
| 472 |
|
| 473 |
#[test] |
| 474 |
fn skew_around_center() { |
| 475 |
let mut face = Face::parse(COLR1_VARIABLE, 0).unwrap(); |
| 476 |
face.set_variation(Tag::from_bytes(b"SKXA"), 46.0); |
| 477 |
let mut vec_painter = VecPainter(vec![]); |
| 478 |
face.paint_color_glyph(GlyphId(104), 0, RgbaColor::new(0, 0, 0, 255), &mut vec_painter); |
| 479 |
assert!(vec_painter.0.contains(&Transform(ttf_parser::Transform::new_skew(0.3944702, 0.0)))); |
| 480 |
} |
| 481 |
|
| 482 |
#[test] |
| 483 |
fn transform() { |
| 484 |
let mut face = Face::parse(COLR1_VARIABLE, 0).unwrap(); |
| 485 |
face.set_variation(Tag::from_bytes(b"TRDX"), 150.0); |
| 486 |
let mut vec_painter = VecPainter(vec![]); |
| 487 |
face.paint_color_glyph(GlyphId(109), 0, RgbaColor::new(0, 0, 0, 255), &mut vec_painter); |
| 488 |
|
| 489 |
assert!(vec_painter.0.contains(&Transform(ttf_parser::Transform { |
| 490 |
a: 1.0, |
| 491 |
b: 0.0, |
| 492 |
c: 0.0, |
| 493 |
d: 1.0, |
| 494 |
e: 274.9939, |
| 495 |
f: 125.0 |
| 496 |
} |
| 497 |
))); |
| 498 |
} |
| 499 |
|
| 500 |
#[test] |
| 501 |
fn translate() { |
| 502 |
let mut face = Face::parse(COLR1_VARIABLE, 0).unwrap(); |
| 503 |
face.set_variation(Tag::from_bytes(b"TLDX"), 100.0); |
| 504 |
let mut vec_painter = VecPainter(vec![]); |
| 505 |
face.paint_color_glyph(GlyphId(114), 0, RgbaColor::new(0, 0, 0, 255), &mut vec_painter); |
| 506 |
|
| 507 |
assert!(vec_painter.0.contains(&Transform(ttf_parser::Transform::new_translate(99.975586, 100.0)))); |
| 508 |
} |
| 509 |
} |