diff --git a/src/font.rs b/src/font.rs index 9808c694..fb84d856 100644 --- a/src/font.rs +++ b/src/font.rs @@ -480,7 +480,7 @@ impl Font { offset_y += 1.0; } let metrics = Metrics { - xmin: as_i32(floor(bounds.xmin)), + xmin: as_i32(floor(bounds.xmin + offset)), ymin: as_i32(floor(bounds.ymin)), width: as_i32(ceil(bounds.width + offset_x)) as usize, height: as_i32(ceil(bounds.height + offset_y)) as usize, @@ -505,7 +505,7 @@ impl Font { /// the top left corner of the glyph. #[inline] pub fn rasterize_config(&self, config: GlyphRasterConfig) -> (Metrics, Vec) { - self.rasterize_indexed(config.glyph_index, config.px) + self.rasterize_indexed(config.glyph_index, config.px, 0.0) } /// Retrieves the layout metrics and rasterized bitmap for the given character. If the @@ -516,6 +516,7 @@ impl Font { /// * `character` - The character to rasterize. /// * `px` - The size to render the character at. Cannot be negative. The units of the scale /// are pixels per Em unit. + /// * `dx` - The sub-pixel x offset in which to render the glyph. /// # Returns /// /// * `Metrics` - Sizing and positioning metadata for the rasterized glyph. @@ -523,8 +524,8 @@ impl Font { /// 0% coverage of that pixel by the glyph and 255 represents 100% coverage. The vec starts at /// the top left corner of the glyph. #[inline] - pub fn rasterize(&self, character: char, px: f32) -> (Metrics, Vec) { - self.rasterize_indexed(self.lookup_glyph_index(character), px) + pub fn rasterize(&self, character: char, px: f32, dx: f32) -> (Metrics, Vec) { + self.rasterize_indexed(self.lookup_glyph_index(character), px, dx) } /// Retrieves the layout rasterized bitmap for the given raster config. If the raster config's @@ -576,19 +577,21 @@ impl Font { /// * `index` - The glyph index in the font to rasterize. /// * `px` - The size to render the character at. Cannot be negative. The units of the scale /// are pixels per Em unit. + /// * `dx` - The sub-pixel x offset in which to render the glyph. + /// # Returns /// # Returns /// /// * `Metrics` - Sizing and positioning metadata for the rasterized glyph. /// * `Vec` - Coverage vector for the glyph. Coverage is a linear scale where 0 represents /// 0% coverage of that pixel by the glyph and 255 represents 100% coverage. The vec starts at /// the top left corner of the glyph. - pub fn rasterize_indexed(&self, index: u16, px: f32) -> (Metrics, Vec) { + pub fn rasterize_indexed(&self, index: u16, px: f32, dx: f32) -> (Metrics, Vec) { if px <= 0.0 { return (Metrics::default(), Vec::new()); } let glyph = &self.glyphs[index as usize]; let scale = self.scale_factor(px); - let (metrics, offset_x, offset_y) = self.metrics_raw(scale, glyph, 0.0); + let (metrics, offset_x, offset_y) = self.metrics_raw(scale, glyph, dx); let mut canvas = Raster::new(metrics.width, metrics.height); canvas.draw(&glyph, scale, scale, offset_x, offset_y); (metrics, canvas.get_bitmap())