| 1 |
use std::num::NonZeroU16; |
| 2 |
use ttf_parser::GlyphId; |
| 3 |
use ttf_parser::ankr::{Table, Point}; |
| 4 |
use crate::{convert, Unit::*}; |
| 5 |
|
| 6 |
#[test] |
| 7 |
fn empty() { |
| 8 |
let data = convert(&[ |
| 9 |
UInt16(0), // version |
| 10 |
UInt16(0), // reserved |
| 11 |
UInt32(0), // offset to lookup table |
| 12 |
UInt32(0), // offset to glyphs data |
| 13 |
]); |
| 14 |
|
| 15 |
let _ = Table::parse(NonZeroU16::new(1).unwrap(), &data).unwrap(); |
| 16 |
} |
| 17 |
|
| 18 |
#[test] |
| 19 |
fn single() { |
| 20 |
let data = convert(&[ |
| 21 |
UInt16(0), // version |
| 22 |
UInt16(0), // reserved |
| 23 |
UInt32(12), // offset to lookup table |
| 24 |
UInt32(12 + 16), // offset to glyphs data |
| 25 |
|
| 26 |
// Lookup Table |
| 27 |
UInt16(6), // format |
| 28 |
|
| 29 |
// Binary Search Table |
| 30 |
UInt16(4), // segment size |
| 31 |
UInt16(1), // number of segments |
| 32 |
UInt16(0), // search range: we don't use it |
| 33 |
UInt16(0), // entry selector: we don't use it |
| 34 |
UInt16(0), // range shift: we don't use it |
| 35 |
|
| 36 |
// Segment [0] |
| 37 |
UInt16(0), // glyph |
| 38 |
UInt16(0), // offset |
| 39 |
|
| 40 |
// Glyphs Data |
| 41 |
UInt32(1), // number of points |
| 42 |
// Point [0] |
| 43 |
Int16(-5), // x |
| 44 |
Int16(11), // y |
| 45 |
]); |
| 46 |
|
| 47 |
let table = Table::parse(NonZeroU16::new(1).unwrap(), &data).unwrap(); |
| 48 |
let points = table.points(GlyphId(0)).unwrap(); |
| 49 |
assert_eq!(points.get(0).unwrap(), Point { x: -5, y: 11 }); |
| 50 |
} |
| 51 |
|
| 52 |
#[test] |
| 53 |
fn two_points() { |
| 54 |
let data = convert(&[ |
| 55 |
UInt16(0), // version |
| 56 |
UInt16(0), // reserved |
| 57 |
UInt32(12), // offset to lookup table |
| 58 |
UInt32(12 + 16), // offset to glyphs data |
| 59 |
|
| 60 |
// Lookup Table |
| 61 |
UInt16(6), // format |
| 62 |
|
| 63 |
// Binary Search Table |
| 64 |
UInt16(4), // segment size |
| 65 |
UInt16(1), // number of segments |
| 66 |
UInt16(0), // search range: we don't use it |
| 67 |
UInt16(0), // entry selector: we don't use it |
| 68 |
UInt16(0), // range shift: we don't use it |
| 69 |
|
| 70 |
// Segment [0] |
| 71 |
UInt16(0), // glyph |
| 72 |
UInt16(0), // offset |
| 73 |
|
| 74 |
// Glyphs Data |
| 75 |
// Glyph Data [0] |
| 76 |
UInt32(2), // number of points |
| 77 |
// Point [0] |
| 78 |
Int16(-5), // x |
| 79 |
Int16(11), // y |
| 80 |
// Point [1] |
| 81 |
Int16(10), // x |
| 82 |
Int16(-40), // y |
| 83 |
]); |
| 84 |
|
| 85 |
let table = Table::parse(NonZeroU16::new(1).unwrap(), &data).unwrap(); |
| 86 |
let points = table.points(GlyphId(0)).unwrap(); |
| 87 |
assert_eq!(points.get(0).unwrap(), Point { x: -5, y: 11 }); |
| 88 |
assert_eq!(points.get(1).unwrap(), Point { x: 10, y: -40 }); |
| 89 |
} |
| 90 |
|
| 91 |
#[test] |
| 92 |
fn two_glyphs() { |
| 93 |
let data = convert(&[ |
| 94 |
UInt16(0), // version |
| 95 |
UInt16(0), // reserved |
| 96 |
UInt32(12), // offset to lookup table |
| 97 |
UInt32(12 + 20), // offset to glyphs data |
| 98 |
|
| 99 |
// Lookup Table |
| 100 |
UInt16(6), // format |
| 101 |
|
| 102 |
// Binary Search Table |
| 103 |
UInt16(4), // segment size |
| 104 |
UInt16(2), // number of segments |
| 105 |
UInt16(0), // search range: we don't use it |
| 106 |
UInt16(0), // entry selector: we don't use it |
| 107 |
UInt16(0), // range shift: we don't use it |
| 108 |
|
| 109 |
// Segment [0] |
| 110 |
UInt16(0), // glyph |
| 111 |
UInt16(0), // offset |
| 112 |
// Segment [1] |
| 113 |
UInt16(1), // glyph |
| 114 |
UInt16(8), // offset |
| 115 |
|
| 116 |
// Glyphs Data |
| 117 |
// Glyph Data [0] |
| 118 |
UInt32(1), // number of points |
| 119 |
// Point [0] |
| 120 |
Int16(-5), // x |
| 121 |
Int16(11), // y |
| 122 |
// Glyph Data [1] |
| 123 |
UInt32(1), // number of points |
| 124 |
// Point [0] |
| 125 |
Int16(40), // x |
| 126 |
Int16(10), // y |
| 127 |
]); |
| 128 |
|
| 129 |
let table = Table::parse(NonZeroU16::new(1).unwrap(), &data).unwrap(); |
| 130 |
let points = table.points(GlyphId(0)).unwrap(); |
| 131 |
assert_eq!(points.get(0).unwrap(), Point { x: -5, y: 11 }); |
| 132 |
let points = table.points(GlyphId(1)).unwrap(); |
| 133 |
assert_eq!(points.get(0).unwrap(), Point { x: 40, y: 10 }); |
| 134 |
} |