Skip to content

Commit aa73c6a

Browse files
author
bors-servo
authored
Auto merge of #3432 - lsalzman:pad-bb, r=kvark
ensure lcd filter padding is applied to cbox when rasterizing glyphs with FreeType This resolves Gecko bug https://bugzilla.mozilla.org/show_bug.cgi?id=1508163 We don't apply the lcd filter padding when querying the cbox to rasterize the glyph, even though we apply the padding when querying the bounds. This causes subpixel AA text to get shifted by the amount of the padding due to the padding not being accounted for in the offset. The solution is to apply the padding in both cases so it properly cancels out. <!-- 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/3432) <!-- Reviewable:end -->
2 parents 9b6c534 + bfaa542 commit aa73c6a

11 files changed

+16
-11
lines changed

webrender/src/platform/unix/font.rs

+16-11
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,20 @@ impl FontContext {
369369
}
370370
}
371371

372+
fn pad_bounding_box(&self, font: &FontInstance, cbox: &mut FT_BBox) {
373+
// Apply extra pixel of padding for subpixel AA, due to the filter.
374+
if font.render_mode == FontRenderMode::Subpixel {
375+
let padding = (self.lcd_extra_pixels * 64) as FT_Pos;
376+
if font.flags.contains(FontInstanceFlags::LCD_VERTICAL) {
377+
cbox.yMin -= padding;
378+
cbox.yMax += padding;
379+
} else {
380+
cbox.xMin -= padding;
381+
cbox.xMax += padding;
382+
}
383+
}
384+
}
385+
372386
// Get the bounding box for a glyph, accounting for sub-pixel positioning.
373387
fn get_bounding_box(
374388
&self,
@@ -389,17 +403,7 @@ impl FontContext {
389403
}
390404
}
391405

392-
// Apply extra pixel of padding for subpixel AA, due to the filter.
393-
if font.render_mode == FontRenderMode::Subpixel {
394-
let padding = (self.lcd_extra_pixels * 64) as FT_Pos;
395-
if font.flags.contains(FontInstanceFlags::LCD_VERTICAL) {
396-
cbox.yMin -= padding;
397-
cbox.yMax += padding;
398-
} else {
399-
cbox.xMin -= padding;
400-
cbox.xMax += padding;
401-
}
402-
}
406+
self.pad_bounding_box(font, &mut cbox);
403407

404408
// Offset the bounding box by subpixel positioning.
405409
// Convert to 26.6 fixed point format for FT.
@@ -572,6 +576,7 @@ impl FontContext {
572576
let outline = &(*slot).outline;
573577
let mut cbox: FT_BBox = mem::uninitialized();
574578
FT_Outline_Get_CBox(outline, &mut cbox);
579+
self.pad_bounding_box(font, &mut cbox);
575580
FT_Outline_Translate(
576581
outline,
577582
dx - ((cbox.xMin + dx) & !63),
Loading
3 Bytes
Loading
4 Bytes
Loading

wrench/reftests/text/colors-subpx.png

55.3 KB
Loading

wrench/reftests/text/raster-space.png

-199 Bytes
Loading
53 Bytes
Loading
-1 Bytes
Loading
0 Bytes
Loading
0 Bytes
Loading
12.5 KB
Loading

0 commit comments

Comments
 (0)