@@ -37,7 +37,7 @@ protected override void BeforeImageApply()
3737 this . definition . Text . Length ,
3838 this . definition . TextOptions ,
3939 this . definition . Pen ,
40- this . definition . Brush != null ,
40+ this . definition . Brush ,
4141 this . definition . DrawingOptions . Transform )
4242 {
4343 Options = this . definition . DrawingOptions
@@ -149,6 +149,8 @@ private struct DrawingOperation
149149 public Point Location { get ; set ; }
150150
151151 public Color ? Color { get ; set ; }
152+
153+ public IBrush Brush { get ; internal set ; }
152154 }
153155
154156 private class CachingGlyphRenderer : IColorGlyphRenderer , IDisposable
@@ -167,31 +169,22 @@ private class CachingGlyphRenderer : IColorGlyphRenderer, IDisposable
167169 private readonly int offset ;
168170 private PointF currentPoint ;
169171 private Color ? currentColor ;
172+ private IBrush ? currentBrush ;
173+ private IPen ? currentPen ;
170174
171175 private readonly Dictionary < ( GlyphRendererParameters Glyph , PointF SubPixelOffset ) , GlyphRenderData > glyphData = new ( ) ;
172176
173- private readonly bool renderOutline ;
174- private readonly bool renderFill ;
175177 private bool rasterizationRequired ;
176178
177- public CachingGlyphRenderer ( MemoryAllocator memoryAllocator , int size , TextOptions textOptions , IPen pen , bool renderFill , Matrix3x2 transform )
179+ public CachingGlyphRenderer ( MemoryAllocator memoryAllocator , int size , TextDrawingOptions textOptions , IPen pen , IBrush brush , Matrix3x2 transform )
178180 {
179181 this . MemoryAllocator = memoryAllocator ;
180182 this . currentRenderPosition = default ;
181183 this . Pen = pen ;
182- this . renderFill = renderFill ;
183- this . renderOutline = pen != null ;
184+ this . Brush = brush ;
184185 this . offset = ( int ) textOptions . Font . Size ;
185- if ( this . renderFill )
186- {
187- this . FillOperations = new List < DrawingOperation > ( size ) ;
188- }
189-
190- if ( this . renderOutline )
191- {
192- this . OutlineOperations = new List < DrawingOperation > ( size ) ;
193- }
194-
186+ this . FillOperations = new List < DrawingOperation > ( size ) ;
187+ this . OutlineOperations = new List < DrawingOperation > ( size ) ;
195188 this . transform = transform ;
196189 this . builder = new PathBuilder ( ) ;
197190 }
@@ -204,6 +197,8 @@ public CachingGlyphRenderer(MemoryAllocator memoryAllocator, int size, TextOptio
204197
205198 public IPen Pen { get ; internal set ; }
206199
200+ public IBrush Brush { get ; internal set ; }
201+
207202 public DrawingOptions Options { get ; internal set ; }
208203
209204 protected void SetLayerColor ( Color color ) => this . currentColor = color ;
@@ -215,6 +210,18 @@ public CachingGlyphRenderer(MemoryAllocator memoryAllocator, int size, TextOptio
215210 public bool BeginGlyph ( FontRectangle bounds , GlyphRendererParameters parameters )
216211 {
217212 this . currentColor = null ;
213+
214+ if ( parameters . TextRun is TextDrawingRun drawingRun )
215+ {
216+ this . currentBrush = drawingRun . Brush ;
217+ this . currentPen = drawingRun . Pen ;
218+ }
219+ else
220+ {
221+ this . currentBrush = null ;
222+ this . currentPen = null ;
223+ }
224+
218225 RectangleF currentBounds = new RectangularPolygon ( bounds . X , bounds . Y , bounds . Width , bounds . Height )
219226 . Transform ( this . transform )
220227 . Bounds ;
@@ -292,21 +299,23 @@ public void EndGlyph()
292299 // If we are using the fonts color layers we ignore the request to draw an outline only
293300 // cause that wont really work and instead force drawing with fill with the requested color
294301 // if color fonts disabled then this.currentColor will always be null
295- if ( this . renderFill || this . currentColor != null )
302+ var brush = this . Brush ?? this . currentBrush ;
303+ if ( brush != null || this . currentColor != null )
296304 {
297305 renderData . FillMap = this . Render ( path ) ;
298306 renderData . Color = this . currentColor ;
299307 }
300308
301- if ( this . renderOutline && this . currentColor == null )
309+ var pen = this . currentPen ?? this . Pen ;
310+ if ( pen != null && this . currentColor == null )
302311 {
303- if ( this . Pen . StrokePattern . Length == 0 )
312+ if ( pen . StrokePattern . Length == 0 )
304313 {
305- path = path . GenerateOutline ( this . Pen . StrokeWidth ) ;
314+ path = path . GenerateOutline ( pen . StrokeWidth ) ;
306315 }
307316 else
308317 {
309- path = path . GenerateOutline ( this . Pen . StrokeWidth , this . Pen . StrokePattern , this . Pen . JointStyle , this . Pen . EndCapStyle ) ;
318+ path = path . GenerateOutline ( pen . StrokeWidth , pen . StrokePattern , pen . JointStyle , pen . EndCapStyle ) ;
310319 }
311320
312321 renderData . OutlineMap = this . Render ( path ) ;
@@ -325,7 +334,8 @@ public void EndGlyph()
325334 {
326335 Location = this . currentRenderPosition ,
327336 Map = renderData . FillMap ,
328- Color = renderData . Color
337+ Color = this . currentColor ,
338+ Brush = this . currentBrush ,
329339 } ) ;
330340 }
331341
@@ -334,7 +344,8 @@ public void EndGlyph()
334344 this . OutlineOperations . Add ( new DrawingOperation
335345 {
336346 Location = this . currentRenderPosition ,
337- Map = renderData . OutlineMap
347+ Map = renderData . OutlineMap ,
348+ Brush = this . currentPen ? . StrokeFill ,
338349 } ) ;
339350 }
340351 }
0 commit comments