Skip to content

Commit 0b7e559

Browse files
Glyph renderer API updates
1 parent 09c1f64 commit 0b7e559

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed

src/ImageSharp.Drawing/Processing/Processors/Text/RichTextGlyphRenderer.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,10 @@ protected override void BeginGlyph(in FontRectangle bounds, in GlyphRendererPara
143143
this.rasterizationRequired = true;
144144
}
145145

146-
protected override void BeginLayer(Paint? paint, FillRule fillRule)
146+
protected override void BeginLayer(Paint? paint, FillRule fillRule, in FontRectangle? clipBounds)
147147
{
148+
// TODO: We may have do some sort of translation based on the delta
149+
// between the bounds and clipbounds.
148150
this.hasLayer = true;
149151
if (TryCreateBrush(paint, this.Builder.Transform, out Brush? brush))
150152
{

src/ImageSharp.Drawing/Shapes/Text/BaseGlyphBuilder.cs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ internal class BaseGlyphBuilder : IGlyphRenderer
3636
private int layerStartIndex;
3737
private Paint? activeLayerPaint;
3838
private FillRule activeLayerFillRule;
39+
private FontRectangle? activeClipBounds;
3940

4041
public BaseGlyphBuilder() => this.Builder = new PathBuilder();
4142

@@ -108,7 +109,7 @@ bool IGlyphRenderer.BeginGlyph(in FontRectangle bounds, in GlyphRendererParamete
108109
this.layerStartIndex = this.graphemePathCount;
109110
this.activeLayerPaint = null;
110111
this.activeLayerFillRule = FillRule.NonZero;
111-
112+
this.activeClipBounds = null;
112113
this.BeginGlyph(in bounds, in parameters);
113114
return true;
114115
}
@@ -153,8 +154,6 @@ void IGlyphRenderer.EndGlyph()
153154
this.inLayer = false;
154155
this.usedLayers = false;
155156
this.layerStartIndex = this.graphemePathCount;
156-
this.activeLayerPaint = null;
157-
this.activeLayerFillRule = FillRule.NonZero;
158157
}
159158

160159
/// <inheritdoc/>
@@ -189,16 +188,17 @@ void IGlyphRenderer.QuadraticBezierTo(Vector2 secondControlPoint, Vector2 point)
189188
}
190189

191190
/// <inheritdoc/>
192-
void IGlyphRenderer.BeginLayer(Paint? paint, FillRule fillRule)
191+
void IGlyphRenderer.BeginLayer(Paint? paint, FillRule fillRule, in FontRectangle? clipBounds)
193192
{
194193
this.usedLayers = true;
195194
this.inLayer = true;
196195
this.layerStartIndex = this.graphemePathCount;
197196
this.activeLayerPaint = paint;
198197
this.activeLayerFillRule = fillRule;
198+
this.activeClipBounds = clipBounds;
199199

200200
this.Builder.Clear();
201-
this.BeginLayer(paint, fillRule);
201+
this.BeginLayer(paint, fillRule, clipBounds);
202202
}
203203

204204
/// <inheritdoc/>
@@ -210,6 +210,8 @@ void IGlyphRenderer.EndLayer()
210210
}
211211

212212
IPath path = this.Builder.Build();
213+
214+
// TODO: We need to clip the path by activeClipBounds if set.
213215
this.CurrentPaths.Add(path);
214216

215217
if (this.graphemeBuilder is not null)
@@ -228,6 +230,9 @@ void IGlyphRenderer.EndLayer()
228230

229231
this.Builder.Clear();
230232
this.inLayer = false;
233+
this.activeLayerPaint = null;
234+
this.activeLayerFillRule = FillRule.NonZero;
235+
this.activeClipBounds = null;
231236
this.EndLayer();
232237
}
233238

@@ -386,8 +391,8 @@ protected virtual void EndText()
386391
{
387392
}
388393

389-
/// <inheritdoc cref="IGlyphRenderer.BeginLayer(Paint?, FillRule)"/>
390-
protected virtual void BeginLayer(Paint? paint, FillRule fillRule)
394+
/// <inheritdoc cref="IGlyphRenderer.BeginLayer(Paint?, FillRule, in FontRectangle?)"/>
395+
protected virtual void BeginLayer(Paint? paint, FillRule fillRule, in FontRectangle? clipBounds)
391396
{
392397
}
393398

0 commit comments

Comments
 (0)