Skip to content

Commit aa81aeb

Browse files
author
bors-servo
authored
Auto merge of #1793 - glennw:ahem, r=nical
Support ahem reftests in wrench. <!-- Reviewable:start --> This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/webrender/1793) <!-- Reviewable:end -->
2 parents 21eeb17 + 9578963 commit aa81aeb

File tree

7 files changed

+319
-5
lines changed

7 files changed

+319
-5
lines changed

wrench/reftests/text/Ahem.ttf

21.3 KB
Binary file not shown.

wrench/reftests/text/ahem-ref.yaml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
---
2+
root:
3+
items:
4+
- type: rect
5+
bounds: [ 16, 16, 520, 280 ]
6+
color: 128 128 128 1.0
7+
- type: rect
8+
bounds: [ 56, 56, 440, 200 ]
9+
color: white
10+
- type: rect
11+
bounds: [ 56, 56, 80, 160 ]
12+
color: blue
13+
- type: rect
14+
bounds: [ 56, 216, 120, 40 ]
15+
color: black
16+
- type: rect
17+
bounds: [ 176, 56, 80, 160 ]
18+
color: 255 165 0 1.0000

wrench/reftests/text/ahem.yaml

Lines changed: 246 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,246 @@
1+
---
2+
root:
3+
items:
4+
-
5+
bounds: [0, 0, 0, 0]
6+
"clip-rect": [0, 0, 0, 0]
7+
"clip-and-scroll": 0
8+
"backface-visible": true
9+
-
10+
bounds: [0, 0, 2560, 1294]
11+
"clip-rect": [0, 0, 2560, 1294]
12+
"clip-and-scroll": 0
13+
"backface-visible": true
14+
type: rect
15+
color: white
16+
-
17+
bounds: [0, 0, 2560, 1294]
18+
"clip-rect": [0, 0, 2560, 1294]
19+
"clip-and-scroll": 0
20+
"backface-visible": true
21+
type: clip
22+
id: 1
23+
"content-size": [2560, 1294]
24+
-
25+
"clip-rect": [0, 0, 2560, 1294]
26+
"clip-and-scroll": 1
27+
"backface-visible": true
28+
type: "scroll-frame"
29+
id: 2
30+
"content-size": [2560, 1294]
31+
bounds: [0, 0, 2560, 1294]
32+
-
33+
bounds: [0, 0, 2560, 1294]
34+
"clip-rect": [0, 0, 2560, 1294]
35+
"clip-and-scroll": 2
36+
"backface-visible": true
37+
type: clip
38+
id: 3
39+
"content-size": [2560, 1294]
40+
-
41+
bounds: [0, 0, 2560, 1294]
42+
"clip-rect": [0, 0, 2560, 1294]
43+
"clip-and-scroll": 3
44+
"backface-visible": true
45+
type: rect
46+
color: white
47+
-
48+
bounds: [16, 16, 520, 280]
49+
"clip-rect": [16, 16, 520, 280]
50+
"clip-and-scroll": 3
51+
"backface-visible": true
52+
type: border
53+
width: 40
54+
"border-type": normal
55+
color: 128 128 128 1.0000
56+
style: solid
57+
-
58+
bounds: [56, 216, 80, 40]
59+
"clip-rect": [56, 216, 80, 40]
60+
"clip-and-scroll": 2
61+
"backface-visible": true
62+
type: clip
63+
id: 4
64+
"content-size": [80, 40]
65+
-
66+
bounds: [56, 216, 80, 40]
67+
"clip-rect": [56, 216, 80, 40]
68+
"clip-and-scroll": 4
69+
"backface-visible": true
70+
type: rect
71+
color: black
72+
-
73+
bounds: [54, 55, 124, 42]
74+
"clip-rect": [0, 0, 2560, 1294]
75+
"clip-and-scroll": 3
76+
"backface-visible": true
77+
glyphs: [67, 68]
78+
offsets: [56, 88, 96, 88]
79+
size: 30
80+
color: 0 0 255 1.0000
81+
font: "Ahem.ttf"
82+
-
83+
bounds: [54, 95, 124, 42]
84+
"clip-rect": [0, 0, 2560, 1294]
85+
"clip-and-scroll": 3
86+
"backface-visible": true
87+
glyphs: [69, 70]
88+
offsets: [56, 128, 96, 128]
89+
size: 30
90+
color: 0 0 255 1.0000
91+
font: "Ahem.ttf"
92+
-
93+
bounds: [54, 135, 124, 42]
94+
"clip-rect": [0, 0, 2560, 1294]
95+
"clip-and-scroll": 3
96+
"backface-visible": true
97+
glyphs: [71, 72]
98+
offsets: [56, 168, 96, 168]
99+
size: 30
100+
color: 0 0 255 1.0000
101+
font: "Ahem.ttf"
102+
-
103+
bounds: [54, 175, 124, 42]
104+
"clip-rect": [0, 0, 2560, 1294]
105+
"clip-and-scroll": 3
106+
"backface-visible": true
107+
glyphs: [73, 74]
108+
offsets: [56, 208, 96, 208]
109+
size: 30
110+
color: 0 0 255 1.0000
111+
font: "Ahem.ttf"
112+
-
113+
bounds: [54, 215, 124, 42]
114+
"clip-rect": [0, 0, 2560, 1294]
115+
"clip-and-scroll": 3
116+
"backface-visible": true
117+
glyphs: [19, 20, 21]
118+
offsets: [56, 248, 96, 248, 136, 248]
119+
size: 30
120+
color: black
121+
font: "Ahem.ttf"
122+
-
123+
bounds: [174, 55, 124, 42]
124+
"clip-rect": [0, 0, 2560, 1294]
125+
"clip-and-scroll": 3
126+
"backface-visible": true
127+
glyphs: [75, 76]
128+
offsets: [176, 88, 216, 88]
129+
size: 30
130+
color: 255 165 0 1.0000
131+
font: "Ahem.ttf"
132+
-
133+
bounds: [174, 95, 124, 42]
134+
"clip-rect": [0, 0, 2560, 1294]
135+
"clip-and-scroll": 3
136+
"backface-visible": true
137+
glyphs: [77, 78]
138+
offsets: [176, 128, 216, 128]
139+
size: 30
140+
color: 255 165 0 1.0000
141+
font: "Ahem.ttf"
142+
-
143+
bounds: [174, 135, 124, 42]
144+
"clip-rect": [0, 0, 2560, 1294]
145+
"clip-and-scroll": 3
146+
"backface-visible": true
147+
glyphs: [79, 80]
148+
offsets: [176, 168, 216, 168]
149+
size: 30
150+
color: 255 165 0 1.0000
151+
font: "Ahem.ttf"
152+
-
153+
bounds: [174, 175, 124, 42]
154+
"clip-rect": [0, 0, 2560, 1294]
155+
"clip-and-scroll": 3
156+
"backface-visible": true
157+
glyphs: [81, 83]
158+
offsets: [176, 208, 216, 208]
159+
size: 30
160+
color: 255 165 0 1.0000
161+
font: "Ahem.ttf"
162+
-
163+
bounds: [174, 215, 124, 42]
164+
"clip-rect": [0, 0, 2560, 1294]
165+
"clip-and-scroll": 3
166+
"backface-visible": true
167+
glyphs: [67, 68]
168+
offsets: [176, 248, 216, 248]
169+
size: 30
170+
color: white
171+
font: "Ahem.ttf"
172+
-
173+
bounds: [294, 55, 124, 42]
174+
"clip-rect": [0, 0, 2560, 1294]
175+
"clip-and-scroll": 3
176+
"backface-visible": true
177+
glyphs: [69, 70]
178+
offsets: [296, 88, 336, 88]
179+
size: 30
180+
color: white
181+
font: "Ahem.ttf"
182+
-
183+
bounds: [294, 95, 124, 42]
184+
"clip-rect": [0, 0, 2560, 1294]
185+
"clip-and-scroll": 3
186+
"backface-visible": true
187+
glyphs: [71, 72]
188+
offsets: [296, 128, 336, 128]
189+
size: 30
190+
color: white
191+
font: "Ahem.ttf"
192+
-
193+
bounds: [294, 135, 124, 42]
194+
"clip-rect": [0, 0, 2560, 1294]
195+
"clip-and-scroll": 3
196+
"backface-visible": true
197+
glyphs: [73, 74]
198+
offsets: [296, 168, 336, 168]
199+
size: 30
200+
color: white
201+
font: "Ahem.ttf"
202+
-
203+
bounds: [294, 175, 124, 42]
204+
"clip-rect": [0, 0, 2560, 1294]
205+
"clip-and-scroll": 3
206+
"backface-visible": true
207+
glyphs: [84, 85]
208+
offsets: [296, 208, 336, 208]
209+
size: 30
210+
color: white
211+
font: "Ahem.ttf"
212+
-
213+
bounds: [294, 215, 124, 42]
214+
"clip-rect": [0, 0, 2560, 1294]
215+
"clip-and-scroll": 3
216+
"backface-visible": true
217+
glyphs: [86, 87]
218+
offsets: [296, 248, 336, 248]
219+
size: 30
220+
color: white
221+
font: "Ahem.ttf"
222+
-
223+
bounds: [414, 55, 124, 42]
224+
"clip-rect": [0, 0, 2560, 1294]
225+
"clip-and-scroll": 3
226+
"backface-visible": true
227+
glyphs: [88, 89]
228+
offsets: [416, 88, 456, 88]
229+
size: 30
230+
color: white
231+
font: "Ahem.ttf"
232+
-
233+
bounds: [414, 95, 124, 42]
234+
"clip-rect": [0, 0, 2560, 1294]
235+
"clip-and-scroll": 3
236+
"backface-visible": true
237+
glyphs: [90, 91]
238+
offsets: [416, 128, 456, 128]
239+
size: 30
240+
color: white
241+
font: "Ahem.ttf"
242+
-
243+
bounds: [0, 0, 0, 0]
244+
"clip-rect": [0, 0, 0, 0]
245+
"clip-and-scroll": 0
246+
"backface-visible": true

wrench/reftests/text/reftest.list

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,4 @@ fuzzy(1,160) == shadow-grey.yaml shadow-grey-ref.yaml
2222
== subtle-shadow.yaml subtle-shadow-ref.yaml
2323
# enable when synthetic-italics implemented on mac
2424
platform(linux) != synthetic-italics.yaml synthetic-italics-ref.yaml
25+
options(disable-subpixel) == ahem.yaml ahem-ref.yaml

wrench/src/reftest.rs

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ const PLATFORM: &str = "mac";
2828
#[cfg(not(any(target_os = "linux", target_os = "macos", target_os = "windows")))]
2929
const PLATFORM: &str = "other";
3030

31+
const OPTION_DISABLE_SUBPX: &str = "disable-subpixel";
32+
3133
pub struct ReftestOptions {
3234
// These override values that are lower.
3335
pub allow_max_difference: usize,
@@ -65,6 +67,7 @@ pub struct Reftest {
6567
op: ReftestOp,
6668
test: PathBuf,
6769
reference: PathBuf,
70+
font_render_mode: Option<FontRenderMode>,
6871
max_difference: usize,
6972
num_differences: usize,
7073
}
@@ -179,6 +182,7 @@ impl ReftestManifest {
179182
let mut max_difference = 0;
180183
let mut max_count = 0;
181184
let mut op = ReftestOp::Equal;
185+
let mut font_render_mode = None;
182186

183187
for (i, token) in tokens.iter().enumerate() {
184188
match *token {
@@ -204,6 +208,12 @@ impl ReftestManifest {
204208
max_difference = args[0].parse().unwrap();
205209
max_count = args[1].parse().unwrap();
206210
}
211+
options if options.starts_with("options") => {
212+
let (_, args, _) = parse_function(options);
213+
if args.iter().any(|arg| arg == &OPTION_DISABLE_SUBPX) {
214+
font_render_mode = Some(FontRenderMode::Alpha);
215+
}
216+
}
207217
"==" => {
208218
op = ReftestOp::Equal;
209219
}
@@ -215,6 +225,7 @@ impl ReftestManifest {
215225
op,
216226
test: dir.join(tokens[i + 0]),
217227
reference: dir.join(tokens[i + 1]),
228+
font_render_mode,
218229
max_difference: cmp::max(max_difference, options.allow_max_difference),
219230
num_differences: cmp::max(max_count, options.allow_num_differences),
220231
});
@@ -304,13 +315,13 @@ impl<'a> ReftestHarness<'a> {
304315
self.window.get_inner_size_pixels().1,
305316
);
306317
let reference = match t.reference.extension().unwrap().to_str().unwrap() {
307-
"yaml" => self.render_yaml(t.reference.as_path(), window_size),
318+
"yaml" => self.render_yaml(t.reference.as_path(), window_size, t.font_render_mode),
308319
"png" => self.load_image(t.reference.as_path(), ImageFormat::PNG),
309320
other => panic!("Unknown reftest extension: {}", other),
310321
};
311322
// the reference can be smaller than the window size,
312323
// in which case we only compare the intersection
313-
let test = self.render_yaml(t.test.as_path(), reference.size);
324+
let test = self.render_yaml(t.test.as_path(), reference.size, t.font_render_mode);
314325
let comparison = test.compare(&reference);
315326

316327
match (&t.op, comparison) {
@@ -363,8 +374,14 @@ impl<'a> ReftestHarness<'a> {
363374
}
364375
}
365376

366-
fn render_yaml(&mut self, filename: &Path, size: DeviceUintSize) -> ReftestImage {
377+
fn render_yaml(
378+
&mut self,
379+
filename: &Path,
380+
size: DeviceUintSize,
381+
font_render_mode: Option<FontRenderMode>,
382+
) -> ReftestImage {
367383
let mut reader = YamlFrameReader::new(filename);
384+
reader.set_font_render_mode(font_render_mode);
368385
reader.do_frame(self.wrench);
369386

370387
// wait for the frame
@@ -385,6 +402,8 @@ impl<'a> ReftestHarness<'a> {
385402
save_flipped(debug_path, &pixels, size);
386403
}
387404

405+
reader.deinit(self.wrench);
406+
388407
ReftestImage { data: pixels, size }
389408
}
390409
}

wrench/src/wrench.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -371,11 +371,12 @@ impl Wrench {
371371
font_key: FontKey,
372372
size: Au,
373373
synthetic_italics: bool,
374+
render_mode: Option<FontRenderMode>,
374375
) -> FontInstanceKey {
375376
let key = self.api.generate_font_instance_key();
376377
let mut update = ResourceUpdates::new();
377378
let options = FontInstanceOptions {
378-
render_mode: None,
379+
render_mode,
379380
synthetic_italics,
380381
};
381382
update.add_font_instance(key, font_key, size, Some(options), None, Vec::new());

0 commit comments

Comments
 (0)