@@ -6,23 +6,23 @@ mod bitmap;
66use std:: sync:: Arc ;
77
88use peniko:: {
9+ color:: { palette, AlphaColor , DynamicColor , Srgb } ,
10+ kurbo:: { Affine , BezPath , Join , Point , Rect , Shape , Stroke , StrokeOpts , Vec2 } ,
911 BlendMode , Blob , Brush , BrushRef , Color , ColorStop , ColorStops , ColorStopsSource , Compose ,
1012 Extend , Fill , Font , Gradient , Image , Mix , StyleRef ,
11- color:: { AlphaColor , DynamicColor , Srgb , palette} ,
12- kurbo:: { Affine , BezPath , Point , Rect , Shape , Stroke , StrokeOpts , Vec2 } ,
1313} ;
1414use png:: { BitDepth , ColorType , Transformations } ;
1515use skrifa:: {
16- GlyphId , MetadataProvider , OutlineGlyphCollection ,
1716 color:: { ColorGlyph , ColorPainter } ,
1817 instance:: LocationRef ,
1918 outline:: { DrawSettings , OutlinePen } ,
2019 prelude:: Size ,
21- raw:: { TableProvider , tables:: cpal:: Cpal } ,
20+ raw:: { tables:: cpal:: Cpal , TableProvider } ,
21+ GlyphId , MetadataProvider , OutlineGlyphCollection ,
2222} ;
2323#[ cfg( feature = "bump_estimate" ) ]
2424use vello_encoding:: BumpAllocatorMemory ;
25- use vello_encoding:: { Encoding , Glyph , GlyphRun , NormalizedCoord , Patch , Transform } ;
25+ use vello_encoding:: { EmboldenStyle , Encoding , Glyph , GlyphRun , NormalizedCoord , Patch , Transform } ;
2626
2727// TODO - Document invariants and edge cases (#470)
2828// - What happens when we pass a transform matrix with NaN values to the Scene?
@@ -361,6 +361,7 @@ impl<'a> DrawGlyphs<'a> {
361361 transform : Transform :: IDENTITY ,
362362 glyph_transform : None ,
363363 font_size : 16.0 ,
364+ embolden_style : EmboldenStyle :: default ( ) ,
364365 hint : false ,
365366 normalized_coords : coords_start..coords_start,
366367 style : Fill :: NonZero . into ( ) ,
@@ -411,6 +412,37 @@ impl<'a> DrawGlyphs<'a> {
411412 self
412413 }
413414
415+ /// Sets the amount of emboldening to apply.
416+ ///
417+ /// The value represents the amount to embolden in em units.
418+ /// A value of 0.0 means no emboldening (the default).
419+ /// Typical values range from 0.01 to 0.1.
420+ ///
421+ /// The default value is 0.0 (no emboldening).
422+ #[ must_use]
423+ pub fn embolden ( mut self , amount : f32 ) -> Self {
424+ self . run . embolden_style . embolden = amount;
425+ self
426+ }
427+
428+ /// Sets the join to use when emboldening.
429+ ///
430+ /// The default value is Miter.
431+ #[ must_use]
432+ pub fn embolden_join ( mut self , join : Join ) -> Self {
433+ self . run . embolden_style . join = join;
434+ self
435+ }
436+
437+ /// Sets the miter limit to use when emboldening with a miter join.
438+ ///
439+ /// The default value is 4.0.
440+ #[ must_use]
441+ pub fn embolden_miter_limit ( mut self , miter_limit : f32 ) -> Self {
442+ self . run . embolden_style . miter_limit = miter_limit;
443+ self
444+ }
445+
414446 /// Sets the normalized design space coordinates for a variable font instance.
415447 #[ must_use]
416448 pub fn normalized_coords ( mut self , coords : & [ NormalizedCoord ] ) -> Self {
@@ -796,15 +828,18 @@ impl ColorPainter for DrawColorGlyphs<'_> {
796828 return ;
797829 } ;
798830
799- let mut path = BezPathOutline ( BezPath :: new ( ) ) ;
800831 let draw_settings = DrawSettings :: unhinted ( Size :: unscaled ( ) , self . location ) ;
801-
802- let Ok ( _) = outline. draw ( draw_settings, & mut path) else {
803- return ;
832+ let path = {
833+ let mut path = BezPathOutline ( BezPath :: new ( ) ) ;
834+ let Ok ( _) = outline. draw ( draw_settings, & mut path) else {
835+ return ;
836+ } ;
837+ path. 0
804838 } ;
839+
805840 self . clip_depth += 1 ;
806841 self . scene
807- . push_layer ( Mix :: Clip , 1.0 , self . last_transform ( ) . to_kurbo ( ) , & path. 0 ) ;
842+ . push_layer ( Mix :: Clip , 1.0 , self . last_transform ( ) . to_kurbo ( ) , & path) ;
808843 }
809844
810845 fn push_clip_box ( & mut self , clip_box : skrifa:: raw:: types:: BoundingBox < f32 > ) {
@@ -878,11 +913,14 @@ impl ColorPainter for DrawColorGlyphs<'_> {
878913 return ;
879914 } ;
880915
881- let mut path = BezPathOutline ( BezPath :: new ( ) ) ;
882916 let draw_settings = DrawSettings :: unhinted ( Size :: unscaled ( ) , self . location ) ;
883917
884- let Ok ( _) = outline. draw ( draw_settings, & mut path) else {
885- return ;
918+ let path = {
919+ let mut path = BezPathOutline ( BezPath :: new ( ) ) ;
920+ let Ok ( _) = outline. draw ( draw_settings, & mut path) else {
921+ return ;
922+ } ;
923+ path. 0
886924 } ;
887925
888926 let transform = self . last_transform ( ) ;
@@ -893,7 +931,7 @@ impl ColorPainter for DrawColorGlyphs<'_> {
893931 brush_transform
894932 . map ( conv_skrifa_transform)
895933 . map ( |it| it. to_kurbo ( ) ) ,
896- & path. 0 ,
934+ & path,
897935 ) ;
898936 }
899937}
0 commit comments