@@ -480,7 +480,7 @@ impl Font {
480
480
offset_y += 1.0 ;
481
481
}
482
482
let metrics = Metrics {
483
- xmin : as_i32 ( floor ( bounds. xmin ) ) ,
483
+ xmin : as_i32 ( floor ( bounds. xmin + offset ) ) ,
484
484
ymin : as_i32 ( floor ( bounds. ymin ) ) ,
485
485
width : as_i32 ( ceil ( bounds. width + offset_x) ) as usize ,
486
486
height : as_i32 ( ceil ( bounds. height + offset_y) ) as usize ,
@@ -505,7 +505,7 @@ impl Font {
505
505
/// the top left corner of the glyph.
506
506
#[ inline]
507
507
pub fn rasterize_config ( & self , config : GlyphRasterConfig ) -> ( Metrics , Vec < u8 > ) {
508
- self . rasterize_indexed ( config. glyph_index , config. px )
508
+ self . rasterize_indexed ( config. glyph_index , config. px , 0.0 )
509
509
}
510
510
511
511
/// Retrieves the layout metrics and rasterized bitmap for the given character. If the
@@ -516,15 +516,16 @@ impl Font {
516
516
/// * `character` - The character to rasterize.
517
517
/// * `px` - The size to render the character at. Cannot be negative. The units of the scale
518
518
/// are pixels per Em unit.
519
+ /// * `dx` - The sub-pixel x offset in which to render the glyph.
519
520
/// # Returns
520
521
///
521
522
/// * `Metrics` - Sizing and positioning metadata for the rasterized glyph.
522
523
/// * `Vec<u8>` - Coverage vector for the glyph. Coverage is a linear scale where 0 represents
523
524
/// 0% coverage of that pixel by the glyph and 255 represents 100% coverage. The vec starts at
524
525
/// the top left corner of the glyph.
525
526
#[ inline]
526
- pub fn rasterize ( & self , character : char , px : f32 ) -> ( Metrics , Vec < u8 > ) {
527
- self . rasterize_indexed ( self . lookup_glyph_index ( character) , px)
527
+ pub fn rasterize ( & self , character : char , px : f32 , dx : f32 ) -> ( Metrics , Vec < u8 > ) {
528
+ self . rasterize_indexed ( self . lookup_glyph_index ( character) , px, dx )
528
529
}
529
530
530
531
/// Retrieves the layout rasterized bitmap for the given raster config. If the raster config's
@@ -576,19 +577,21 @@ impl Font {
576
577
/// * `index` - The glyph index in the font to rasterize.
577
578
/// * `px` - The size to render the character at. Cannot be negative. The units of the scale
578
579
/// are pixels per Em unit.
580
+ /// * `dx` - The sub-pixel x offset in which to render the glyph.
581
+ /// # Returns
579
582
/// # Returns
580
583
///
581
584
/// * `Metrics` - Sizing and positioning metadata for the rasterized glyph.
582
585
/// * `Vec<u8>` - Coverage vector for the glyph. Coverage is a linear scale where 0 represents
583
586
/// 0% coverage of that pixel by the glyph and 255 represents 100% coverage. The vec starts at
584
587
/// the top left corner of the glyph.
585
- pub fn rasterize_indexed ( & self , index : u16 , px : f32 ) -> ( Metrics , Vec < u8 > ) {
588
+ pub fn rasterize_indexed ( & self , index : u16 , px : f32 , dx : f32 ) -> ( Metrics , Vec < u8 > ) {
586
589
if px <= 0.0 {
587
590
return ( Metrics :: default ( ) , Vec :: new ( ) ) ;
588
591
}
589
592
let glyph = & self . glyphs [ index as usize ] ;
590
593
let scale = self . scale_factor ( px) ;
591
- let ( metrics, offset_x, offset_y) = self . metrics_raw ( scale, glyph, 0.0 ) ;
594
+ let ( metrics, offset_x, offset_y) = self . metrics_raw ( scale, glyph, dx ) ;
592
595
let mut canvas = Raster :: new ( metrics. width , metrics. height ) ;
593
596
canvas. draw ( & glyph, scale, scale, offset_x, offset_y) ;
594
597
( metrics, canvas. get_bitmap ( ) )
0 commit comments