Environment
- ThinkGeo.Core 15.0.0-beta197 (also present in beta191)
- .NET 10, Windows,
PdfGeoCanvaswithMapPrinterLayoutAsyncLayerinMapPrinterDrawingMode.Vector
Summary
We export a print layout to PDF: a page layer, a MapPrinterLayoutAsyncLayer , and our own printer layers drawn afterwards (a frame around the map, scale bar, text). Once the map contains a feature layer with Opacity < 1 , anything drawn after the map layer is clipped to the map’s area. Our frame lies just outside the map area, so it disappears from the PDF entirely. Without such a layer, the frame is drawn correctly.
The PDF content stream shows that the frame stroke is written with the map’s clip still active:
q
6.5866 6.5866 582.10 828.72 re W* n % map clip
/G7 gs
5.6693 5.6693 583.94 830.55 re S % frame stroke, entirely outside the clip
... % everything after it is inside the same clip group
Q % only closed at the end of the page
Cause (as far as we can tell from the beta197 assembly)
-
Layer.DrawwithOpacity != 1renders to an off-screen image and then callscanvas.DrawWorldImageWithoutScaling(image, …, 0f, 0f, 0f, …). -
SkiaGeoCanvas.DrawScreenImageWithoutScalingCorealways callsSave(), but only callsRestore()whenflagis true:
n2.b(); // Save
bool flag = true;
if (rotateAngle % 360f == 0f)
{
...
flag = num5 != 0f || num6 != 0f; // false when xOffset/yOffset are 0
if (flag) n2.A(num5, num6);
}
...
finally
{
...
if (flag) n2.B(); // Restore skipped → one Save leaks
}
-
PdfGeoCanvaswraps each queued command inSave()→ClipRect(ClippingArea)→ command →Restore(). Because of the leaked save, itsRestore()pops the image’s save instead of its own. TheClipRectfromMapPrinterLayoutAsyncLayer.ClippingAreatherefore remains on theSKCanvasuntil the page ends, even thoughClippingAreais set back tonull.
Minimal repro
using var stream = File.Create("clip-leak.pdf");
var canvas = new PdfGeoCanvas { PageWidth = 595, PageHeight = 842 };
canvas.BeginDrawing(stream, new RectangleShape(0, 842, 595, 0), GeographyUnit.Meter);
// What MapPrinterLayoutAsyncLayer does for a layer with Opacity < 1
canvas.ClippingArea = new RectangleShape(100, 742, 495, 100);
using (var image = new GeoImage(50, 50))
canvas.DrawWorldImageWithoutScaling(image, 297.5, 421, DrawingLevel.LevelOne);
canvas.Flush();
canvas.ClippingArea = null;
// Drawn after the clip was reset; lies outside the former clip
canvas.DrawArea(new RectangleShape(20, 822, 575, 20), new GeoPen(GeoColors.Black, 4), DrawingLevel.LevelOne);
canvas.EndDrawing();
- Expected: a black rectangle near the page edge.
-
Actual: the rectangle is missing. Without the
DrawWorldImageWithoutScalingcall, it appears.
Suggested fix: restore unconditionally in DrawScreenImageWithoutScalingCore . Alternatively, have PdfGeoCanvas use int count = canvas.Save(); … canvas.RestoreToCount(count); so that unbalanced saves inside a command can’t leak.
Related: Background on a printer layer fills the entire page
AsyncLayer calls canvas.Clear(new GeoSolidBrush(Background)) when Background is not transparent. GeoCanvas.ClearCore fills CurrentWorldExtent scaled up 100×. On a PdfGeoCanvas , setting MapPrinterLayoutAsyncLayer.Background therefore paints the whole page, including the page layer and the margins, not just the map area. We expected Background to fill only the map frame, as BackgroundMask does. Is that intended for printer layers?
Our workaround: we draw the frame and the map background ourselves before the MapPrinterLayoutAsyncLayer , and leave its Background unset. Elements drawn after the map still get the leaked clip, but ours happen to lie inside the map area.