@@ -68,12 +68,9 @@ void Draw(IEnumerable<DrawingOperation> operations)
6868 var brushes = new Dictionary < IBrush , BrushApplicator < TPixel > > ( ) ;
6969 foreach ( DrawingOperation operation in operations )
7070 {
71- if ( operation . Brush != null )
71+ if ( ! brushes . TryGetValue ( operation . Brush , out _ ) )
7272 {
73- if ( ! brushes . TryGetValue ( operation . Brush , out _ ) )
74- {
75- brushes [ operation . Brush ] = operation . Brush . CreateApplicator ( this . Configuration , this . textRenderer . Options . GraphicsOptions , source , this . SourceRectangle ) ;
76- }
73+ brushes [ operation . Brush ] = operation . Brush . CreateApplicator ( this . Configuration , this . textRenderer . Options . GraphicsOptions , source , this . SourceRectangle ) ;
7774 }
7875 }
7976
@@ -272,6 +269,42 @@ public void EndGlyph()
272269 {
273270 GlyphRenderData renderData = default ;
274271
272+ // fix up the text runs colors
273+ // only if both brush and pen is null do we fallback to the defualt value
274+ if ( this . currentBrush == null && this . currentPen == null )
275+ {
276+ this . currentBrush = this . Brush ;
277+ this . currentPen = this . Pen ;
278+ }
279+
280+ var renderFill = false ;
281+ var renderOutline = false ;
282+
283+ // If we are using the fonts color layers we ignore the request to draw an outline only
284+ // cause that wont really work and instead force drawing with fill with the requested color
285+ // if color fonts disabled then this.currentColor will always be null
286+ if ( this . currentBrush != null || this . currentColor != null )
287+ {
288+ renderFill = true ;
289+ if ( this . currentColor . HasValue )
290+ {
291+ if ( this . brushLookup . TryGetValue ( this . currentColor . Value , out var brush ) )
292+ {
293+ this . currentBrush = brush ;
294+ }
295+ else
296+ {
297+ this . currentBrush = new SolidBrush ( this . currentColor . Value ) ;
298+ this . brushLookup [ this . currentColor . Value ] = this . currentBrush ;
299+ }
300+ }
301+ }
302+
303+ if ( this . currentPen != null && this . currentColor == null )
304+ {
305+ renderOutline = true ;
306+ }
307+
275308 // Has the glyph been rendered already?
276309 if ( this . rasterizationRequired )
277310 {
@@ -282,48 +315,18 @@ public void EndGlyph()
282315 return ;
283316 }
284317
285- // fix up the text runs colors
286- // only if both brush and pen is null do we fallback to the defualt value
287- if ( this . currentBrush == null && this . currentPen == null )
288- {
289- this . currentBrush = this . Brush ;
290- this . currentPen = this . Pen ;
291- }
292-
293318 // If we are using the fonts color layers we ignore the request to draw an outline only
294319 // cause that wont really work and instead force drawing with fill with the requested color
295320 // if color fonts disabled then this.currentColor will always be null
296- if ( this . currentBrush != null || this . currentColor != null )
321+ if ( renderFill )
297322 {
298323 renderData . FillMap = this . Render ( path ) ;
299-
300- if ( this . currentColor . HasValue )
301- {
302- if ( this . brushLookup . TryGetValue ( this . currentColor . Value , out var brush ) )
303- {
304- this . currentBrush = brush ;
305- }
306- else
307- {
308- this . currentBrush = new SolidBrush ( this . currentColor . Value ) ;
309- this . brushLookup [ this . currentColor . Value ] = this . currentBrush ;
310- }
311- }
312324 }
313325
314- if ( this . currentPen != null && this . currentColor == null )
326+ if ( renderOutline )
315327 {
316- if ( this . currentPen . StrokePattern . Length == 0 )
317- {
318- path = path . GenerateOutline ( this . currentPen . StrokeWidth ) ;
319- }
320- else
321- {
322- path = path . GenerateOutline ( this . currentPen . StrokeWidth , this . currentPen . StrokePattern , this . currentPen . JointStyle , this . currentPen . EndCapStyle ) ;
323- }
324-
328+ path = path . GenerateOutline ( this . currentPen . StrokeWidth , this . currentPen . StrokePattern , this . currentPen . JointStyle , this . currentPen . EndCapStyle ) ;
325329 renderData . OutlineMap = this . Render ( path ) ;
326- this . currentBrush = this . currentPen . StrokeFill ;
327330 }
328331
329332 this . glyphData [ this . currentGlyphRenderParams ] = renderData ;
@@ -350,7 +353,7 @@ public void EndGlyph()
350353 {
351354 Location = this . currentRenderPosition ,
352355 Map = renderData . OutlineMap ,
353- Brush = this . currentBrush ,
356+ Brush = this . currentPen ? . StrokeFill ?? this . currentBrush ,
354357 RenderPass = 2 // render outlines 2nd to ensure they are always ontop of fills
355358 } ) ;
356359 }
0 commit comments