Skip to content

Commit b8e81c3

Browse files
committed
handle empty empty stacks in PopState()
1 parent 3b531eb commit b8e81c3

5 files changed

Lines changed: 19 additions & 9 deletions

File tree

81.5 KB
Binary file not shown.
86 KB
Loading

UglyToad.PdfPig.Rendering.Skia.Tests/TestRendering.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -722,14 +722,20 @@ public class TestRendering
722722

723723
new object[]
724724
{
725-
"GWG060_Shading_x1a_1.png", // reference image on the left is wrong
725+
"GWG060_Shading_x1a_1.png",
726726
"GWG060_Shading_x1a.pdf", 1, 2
727727
},
728728
new object[]
729729
{
730730
"GWG061_Shading_x1a_1.png",
731731
"GWG061_Shading_x1a.pdf", 1, 2
732732
},
733+
734+
new object[]
735+
{
736+
"JD5008_2.png",
737+
"JD5008.pdf", 2, 2
738+
},
733739
};
734740

735741
[Theory(Skip = "for debugging purpose.")]

UglyToad.PdfPig.Rendering.Skia.Tests/UglyToad.PdfPig.Rendering.Skia.Tests.csproj

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,9 @@
326326
<None Update="Documents\ICML03-081.pdf">
327327
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
328328
</None>
329+
<None Update="Documents\JD5008.pdf">
330+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
331+
</None>
329332
<None Update="Documents\journal.pone.0196757.pdf">
330333
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
331334
</None>
@@ -698,6 +701,9 @@
698701
<None Update="ExpectedImages\pdfpig_skia\issue-50_2.png">
699702
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
700703
</None>
704+
<None Update="ExpectedImages\pdfpig_skia\JD5008_2.png">
705+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
706+
</None>
701707
<None Update="ExpectedImages\pdfpig_skia\journal.pone.0196757_1.png">
702708
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
703709
</None>

UglyToad.PdfPig.Rendering.Skia/SkiaStreamProcessor.cs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ protected override void ProcessOperations(IReadOnlyList<IGraphicsStateOperation>
184184
{
185185
_token.ThrowIfCancellationRequested();
186186
}
187-
187+
188188
operations[i].Run(this);
189189
}
190190
}
@@ -195,7 +195,7 @@ public override void PopState()
195195
// composited into the still-open offscreen buffer. DstIn keeps only the parts of
196196
// the layer where the mask has alpha; the LumaColor filter converts the source
197197
// colour to luminosity-as-alpha for /Luminosity-subtype masks.
198-
var maskImage = _pendingMasks.Pop();
198+
var maskImage = _pendingMasks.Count > 0 ? _pendingMasks.Pop() : null;
199199
if (maskImage is not null)
200200
{
201201
_canvas.Save();
@@ -204,11 +204,9 @@ public override void PopState()
204204
// covering the same logical bounds as the layer).
205205
_canvas.SetMatrix(SKMatrix.Identity);
206206

207-
using var maskPaint = new SKPaint
208-
{
209-
BlendMode = SKBlendMode.DstIn,
210-
ColorFilter = SKColorFilter.CreateLumaColor()
211-
};
207+
using var maskPaint = new SKPaint();
208+
maskPaint.BlendMode = SKBlendMode.DstIn;
209+
maskPaint.ColorFilter = SKColorFilter.CreateLumaColor();
212210

213211
_canvas.DrawImage(maskImage, SKRect.Create(0, 0, _width, _height), maskPaint);
214212
_canvas.Restore();
@@ -219,7 +217,7 @@ public override void PopState()
219217
_canvas.Restore();
220218

221219
// Dispose layer paint if one was used for this state
222-
var layerPaint = _transparencyLayerPaints.Pop();
220+
var layerPaint = _transparencyLayerPaints.Count > 0 ? _transparencyLayerPaints.Pop() : null;
223221
layerPaint?.Dispose();
224222

225223
EndPath();

0 commit comments

Comments
 (0)