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