@@ -130,23 +130,21 @@ void IGlyphRenderer.EndGlyph()
130130 if ( ! this . usedLayers )
131131 {
132132 IPath path = this . Builder . Build ( ) ;
133- if ( ! path . Bounds . IsEmpty )
133+
134+ this . CurrentPaths . Add ( path ) ;
135+
136+ if ( this . graphemeBuilder is not null )
134137 {
135- this . CurrentPaths . Add ( path ) ;
138+ this . graphemeBuilder . AddPath ( path ) ;
139+ this . graphemeBuilder . AddLayer (
140+ startIndex : this . graphemePathCount ,
141+ count : 1 ,
142+ paint : null ,
143+ fillRule : FillRule . NonZero ,
144+ bounds : path . Bounds ,
145+ kind : GlyphLayerKind . Glyph ) ;
136146
137- if ( this . graphemeBuilder is not null )
138- {
139- this . graphemeBuilder . AddPath ( path ) ;
140- this . graphemeBuilder . AddLayer (
141- startIndex : this . graphemePathCount ,
142- count : 1 ,
143- paint : null ,
144- fillRule : FillRule . NonZero ,
145- bounds : path . Bounds ,
146- kind : GlyphLayerKind . Glyph ) ;
147-
148- this . graphemePathCount ++ ;
149- }
147+ this . graphemePathCount ++ ;
150148 }
151149 }
152150
@@ -212,23 +210,20 @@ void IGlyphRenderer.EndLayer()
212210 }
213211
214212 IPath path = this . Builder . Build ( ) ;
215- if ( ! path . Bounds . IsEmpty )
216- {
217- this . CurrentPaths . Add ( path ) ;
213+ this . CurrentPaths . Add ( path ) ;
218214
219- if ( this . graphemeBuilder is not null )
220- {
221- this . graphemeBuilder . AddPath ( path ) ;
222- this . graphemeBuilder . AddLayer (
223- startIndex : this . layerStartIndex ,
224- count : 1 ,
225- paint : this . activeLayerPaint ,
226- fillRule : this . activeLayerFillRule ,
227- bounds : path . Bounds ,
228- kind : GlyphLayerKind . Painted ) ;
229-
230- this . graphemePathCount ++ ;
231- }
215+ if ( this . graphemeBuilder is not null )
216+ {
217+ this . graphemeBuilder . AddPath ( path ) ;
218+ this . graphemeBuilder . AddLayer (
219+ startIndex : this . layerStartIndex ,
220+ count : 1 ,
221+ paint : this . activeLayerPaint ,
222+ fillRule : this . activeLayerFillRule ,
223+ bounds : path . Bounds ,
224+ kind : GlyphLayerKind . Painted ) ;
225+
226+ this . graphemePathCount ++ ;
232227 }
233228
234229 this . Builder . Clear ( ) ;
@@ -266,21 +261,32 @@ void IGlyphRenderer.SetDecoration(TextDecorations textDecorations, Vector2 start
266261
267262 if ( previous != null )
268263 {
264+ float prevThickness = previous . Value . Thickness ;
265+ Vector2 prevStart = previous . Value . Start ;
266+ Vector2 prevEnd = previous . Value . End ;
267+
268+ // If the previous line is identical to the new one ignore it.
269+ // This can happen when multiple glyph layers are used.
270+ if ( prevStart == start && prevEnd == end )
271+ {
272+ return ;
273+ }
274+
269275 // Align the new line with the previous one if they are close enough.
270276 if ( rotated )
271277 {
272- if ( thickness == previous . Value . Thickness
273- && previous . Value . End . Y + 1 >= start . Y
274- && previous . Value . End . X == start . X )
278+ if ( thickness == prevThickness
279+ && prevEnd . Y + 1 >= start . Y
280+ && prevEnd . X == start . X )
275281 {
276- start = previous . Value . End ;
282+ start = prevEnd ;
277283 }
278284 }
279- else if ( thickness == previous . Value . Thickness
280- && previous . Value . End . Y == start . Y
281- && previous . Value . End . X + 1 >= start . X )
285+ else if ( thickness == prevThickness
286+ && prevEnd . Y == start . Y
287+ && prevEnd . X + 1 >= start . X )
282288 {
283- start = previous . Value . End ;
289+ start = prevEnd ;
284290 }
285291 }
286292
@@ -332,23 +338,28 @@ void IGlyphRenderer.SetDecoration(TextDecorations textDecorations, Vector2 start
332338 renderer . EndFigure ( ) ;
333339
334340 IPath path = this . Builder . Build ( ) ;
335- if ( ! path . Bounds . IsEmpty )
336- {
337- this . CurrentPaths . Add ( path ) ;
338341
339- if ( this . graphemeBuilder is not null )
340- {
341- this . graphemeBuilder . AddPath ( path ) ;
342- this . graphemeBuilder . AddLayer (
343- startIndex : this . layerStartIndex ,
344- count : 1 ,
345- paint : this . activeLayerPaint ,
346- fillRule : FillRule . NonZero ,
347- bounds : path . Bounds ,
348- kind : GlyphLayerKind . Decoration ) ;
342+ // If the path is degenerate (e.g. zero width line) we just skip it
343+ // and return. This might happen when clamping moves the points.
344+ if ( path . Bounds . IsEmpty )
345+ {
346+ this . Builder . Clear ( ) ;
347+ return ;
348+ }
349349
350- this . graphemePathCount ++ ;
351- }
350+ this . CurrentPaths . Add ( path ) ;
351+ if ( this . graphemeBuilder is not null )
352+ {
353+ this . graphemeBuilder . AddPath ( path ) ;
354+ this . graphemeBuilder . AddLayer (
355+ startIndex : this . layerStartIndex ,
356+ count : 1 ,
357+ paint : this . activeLayerPaint ,
358+ fillRule : FillRule . NonZero ,
359+ bounds : path . Bounds ,
360+ kind : GlyphLayerKind . Decoration ) ;
361+
362+ this . graphemePathCount ++ ;
352363 }
353364
354365 this . Builder . Clear ( ) ;
0 commit comments