@@ -103,6 +103,11 @@ pub struct FontTweak {
103
103
/// A positive value shifts the text downwards.
104
104
/// A negative value shifts it upwards.
105
105
pub baseline_offset_factor : f32 ,
106
+
107
+ /// Override the global font hinting setting for this specific font.
108
+ ///
109
+ /// `None` means use the global setting.
110
+ pub hinting_override : Option < bool > ,
106
111
}
107
112
108
113
impl Default for FontTweak {
@@ -112,6 +117,7 @@ impl Default for FontTweak {
112
117
y_offset_factor : 0.0 ,
113
118
y_offset : 0.0 ,
114
119
baseline_offset_factor : 0.0 ,
120
+ hinting_override : None ,
115
121
}
116
122
}
117
123
}
@@ -345,6 +351,7 @@ pub(super) struct FontsLayoutView<'a> {
345
351
pub texture_atlas : & ' a mut TextureAtlas ,
346
352
pub glyph_atlas : & ' a mut GlyphAtlas ,
347
353
pub font_tweaks : & ' a mut ahash:: HashMap < u64 , FontTweak > ,
354
+ pub hinting_enabled : bool ,
348
355
pub pixels_per_point : f32 ,
349
356
}
350
357
@@ -363,6 +370,7 @@ pub struct FontStore {
363
370
max_texture_side : usize ,
364
371
definitions : FontDefinitions ,
365
372
font_tweaks : ahash:: HashMap < u64 , FontTweak > ,
373
+ hinting_enabled : bool ,
366
374
atlas : TextureAtlas ,
367
375
galley_cache : GalleyCache ,
368
376
@@ -399,6 +407,7 @@ impl FontStore {
399
407
max_texture_side,
400
408
definitions,
401
409
font_tweaks : Default :: default ( ) ,
410
+ hinting_enabled : true ,
402
411
glyph_atlas : GlyphAtlas :: new ( ) ,
403
412
atlas,
404
413
galley_cache : Default :: default ( ) ,
@@ -500,6 +509,15 @@ impl FontStore {
500
509
self . load_fonts_from_definitions ( ) ;
501
510
}
502
511
512
+ pub fn hinting_enabled ( & self ) -> bool {
513
+ self . hinting_enabled
514
+ }
515
+
516
+ pub fn set_hinting_enabled ( & mut self , enabled : bool ) {
517
+ self . hinting_enabled = enabled;
518
+ self . clear_cache ( self . max_texture_side ) ;
519
+ }
520
+
503
521
/// Width of this character in points.
504
522
pub fn glyph_width ( & mut self , font_id : & FontId , c : char ) -> f32 {
505
523
* self . glyph_width_cache . entry ( c) . or_insert_with ( || {
@@ -559,6 +577,7 @@ impl FontStore {
559
577
& mut self . atlas ,
560
578
& run,
561
579
vec2 ( x_offset, 0.0 ) ,
580
+ self . hinting_enabled ,
562
581
pixels_per_point,
563
582
& self . font_tweaks ,
564
583
)
@@ -730,12 +749,19 @@ impl Fonts<'_> {
730
749
self . fonts . definitions ( )
731
750
}
732
751
752
+ #[ inline]
753
+ pub fn hinting_enabled ( & self ) -> bool {
754
+ self . fonts . hinting_enabled ( )
755
+ }
756
+
733
757
/// Width of this character in points.
758
+ #[ inline]
734
759
pub fn glyph_width ( & mut self , font_id : & FontId , c : char ) -> f32 {
735
760
self . fonts . glyph_width ( font_id, c)
736
761
}
737
762
738
763
/// Can we display all the glyphs in this text?
764
+ #[ inline]
739
765
pub fn has_glyphs_for ( & mut self , font_id : & FontId , s : & str ) -> bool {
740
766
self . fonts . has_glyphs_for ( font_id, s)
741
767
}
@@ -746,13 +772,15 @@ impl Fonts<'_> {
746
772
/// Height of one row of text in points.
747
773
///
748
774
/// Returns a value rounded to [`emath::GUI_ROUNDING`].
775
+ #[ inline]
749
776
pub fn row_height ( & mut self , font_id : & FontId ) -> f32 {
750
777
self . fonts
751
778
. row_height ( font_id)
752
779
. round_to_pixels ( self . pixels_per_point )
753
780
}
754
781
755
782
/// Call at the end of each frame (before painting) to get the change to the font texture since last call.
783
+ #[ inline]
756
784
pub fn font_image_delta ( & mut self ) -> Option < crate :: ImageDelta > {
757
785
self . fonts . font_image_delta ( )
758
786
}
@@ -764,21 +792,25 @@ impl Fonts<'_> {
764
792
765
793
/// The font atlas.
766
794
/// Pass this to [`crate::Tessellator`].
795
+ #[ inline]
767
796
pub fn texture_atlas ( & self ) -> & TextureAtlas {
768
797
self . fonts . texture_atlas ( )
769
798
}
770
799
771
800
/// Current size of the font image.
772
801
/// Pass this to [`crate::Tessellator`].
802
+ #[ inline]
773
803
pub fn font_image_size ( & self ) -> [ usize ; 2 ] {
774
804
self . fonts . font_image_size ( )
775
805
}
776
806
777
807
/// List of all loaded font families.
808
+ #[ inline]
778
809
pub fn families ( & mut self ) -> & [ FontFamily ] {
779
810
self . fonts . families ( )
780
811
}
781
812
813
+ #[ inline]
782
814
pub fn num_galleys_in_cache ( & self ) -> usize {
783
815
self . fonts . num_galleys_in_cache ( )
784
816
}
@@ -787,6 +819,7 @@ impl Fonts<'_> {
787
819
///
788
820
/// This increases as new fonts and/or glyphs are used,
789
821
/// but can also decrease in a call to [`Self::begin_pass`].
822
+ #[ inline]
790
823
pub fn font_atlas_fill_ratio ( & self ) -> f32 {
791
824
self . fonts . font_atlas_fill_ratio ( )
792
825
}
@@ -807,6 +840,7 @@ impl Fonts<'_> {
807
840
texture_atlas : & mut self . fonts . atlas ,
808
841
glyph_atlas : & mut self . fonts . glyph_atlas ,
809
842
font_tweaks : & mut self . fonts . font_tweaks ,
843
+ hinting_enabled : self . fonts . hinting_enabled ,
810
844
pixels_per_point : self . pixels_per_point ,
811
845
} ,
812
846
job,
@@ -827,6 +861,7 @@ impl Fonts<'_> {
827
861
texture_atlas : & mut self . fonts . atlas ,
828
862
glyph_atlas : & mut self . fonts . glyph_atlas ,
829
863
font_tweaks : & mut self . fonts . font_tweaks ,
864
+ hinting_enabled : self . fonts . hinting_enabled ,
830
865
pixels_per_point : self . pixels_per_point ,
831
866
} ,
832
867
job,
@@ -836,6 +871,7 @@ impl Fonts<'_> {
836
871
/// Will wrap text at the given width and line break at `\n`.
837
872
///
838
873
/// The implementation uses memoization so repeated calls are cheap.
874
+ #[ inline]
839
875
pub fn layout (
840
876
& mut self ,
841
877
text : String ,
@@ -850,6 +886,7 @@ impl Fonts<'_> {
850
886
/// Will line break at `\n`.
851
887
///
852
888
/// The implementation uses memoization so repeated calls are cheap.
889
+ #[ inline]
853
890
pub fn layout_no_wrap (
854
891
& mut self ,
855
892
text : String ,
@@ -863,6 +900,7 @@ impl Fonts<'_> {
863
900
/// Like [`Self::layout`], made for when you want to pick a color for the text later.
864
901
///
865
902
/// The implementation uses memoization so repeated calls are cheap.
903
+ #[ inline]
866
904
pub fn layout_delayed_color (
867
905
& mut self ,
868
906
text : String ,
0 commit comments