Skip to content

Commit 349da8c

Browse files
author
Mason Chang
committed
Enable subpixel text positioning for dwrite fonts
1 parent 74ad1aa commit 349da8c

File tree

1 file changed

+21
-10
lines changed
  • webrender/src/platform/windows

1 file changed

+21
-10
lines changed

webrender/src/platform/windows/font.rs

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44

55
use app_units::Au;
66
use std::collections::HashMap;
7-
use webrender_traits::{FontKey, ColorU, FontRenderMode, GlyphDimensions, GlyphOptions};
8-
use webrender_traits::{SubpixelOffset};
7+
use webrender_traits::{FontKey, ColorU, FontRenderMode, GlyphDimensions};
8+
use webrender_traits::{GlyphOptions, SubpixelOffset};
99
use gamma_lut::{GammaLut, Color as ColorLut};
1010

1111
use dwrote;
@@ -159,6 +159,8 @@ impl FontContext {
159159
fn create_glyph_analysis(&self, font_key: FontKey,
160160
size: Au, glyph: u32,
161161
render_mode: FontRenderMode,
162+
x_suboffset: SubpixelOffset,
163+
y_suboffset: SubpixelOffset,
162164
options: Option<GlyphOptions>) ->
163165
dwrote::GlyphRunAnalysis {
164166
let face = self.fonts.get(&font_key).unwrap();
@@ -186,9 +188,14 @@ impl FontContext {
186188
dwrite_measure_mode,
187189
options);
188190

189-
// XX use the xform to handle subpixel positioning (what skia does), I believe that keeps
190-
//let xform = dwrote::DWRITE_MATRIX { m11: 1.0, m12: 0.0, m21: 0.0, m22: 1.0, dx: 0.0, dy: 0.0 };
191-
dwrote::GlyphRunAnalysis::create(&glyph_run, 1.0, None,
191+
let x_offset: f32 = Into::<f64>::into(x_suboffset) as f32;
192+
let y_offset: f32 = Into::<f64>::into(y_suboffset) as f32;
193+
let transform = Some(
194+
dwrote::DWRITE_MATRIX { m11: 1.0, m12: 0.0, m21: 0.0, m22: 1.0,
195+
dx: x_offset, dy: y_offset }
196+
);
197+
198+
dwrote::GlyphRunAnalysis::create(&glyph_run, 1.0, transform,
192199
dwrite_render_mode,
193200
dwrite_measure_mode,
194201
0.0, 0.0)
@@ -199,13 +206,14 @@ impl FontContext {
199206
font_key: FontKey,
200207
size: Au,
201208
glyph: u32,
202-
_x_subpixel: SubpixelOffset,
203-
_y_subpixel: SubpixelOffset)
209+
x_suboffset: SubpixelOffset,
210+
y_suboffset: SubpixelOffset)
204211
-> Option<GlyphDimensions> {
205212
// Probably have to default to something else here.
206213
let render_mode = FontRenderMode::Subpixel;
207214
let analysis = self.create_glyph_analysis(font_key, size,
208215
glyph, render_mode,
216+
x_suboffset, y_suboffset,
209217
None);
210218

211219
let texture_type = dwrite_texture_type(render_mode);
@@ -264,12 +272,15 @@ impl FontContext {
264272
color: ColorU,
265273
glyph: u32,
266274
render_mode: FontRenderMode,
267-
_x_suboffset: SubpixelOffset,
268-
_y_suboffset: SubpixelOffset,
275+
x_suboffset: SubpixelOffset,
276+
y_suboffset: SubpixelOffset,
269277
glyph_options: Option<GlyphOptions>)
270278
-> Option<RasterizedGlyph> {
271279
let analysis = self.create_glyph_analysis(font_key, size, glyph,
272-
render_mode, glyph_options);
280+
render_mode,
281+
x_suboffset,
282+
y_suboffset,
283+
glyph_options);
273284
let texture_type = dwrite_texture_type(render_mode);
274285

275286
let bounds = analysis.get_alpha_texture_bounds(texture_type);

0 commit comments

Comments
 (0)