Implemented correct viewbox scaling and clipping. See #239

This commit is contained in:
Matthew Leibowitz 2017-02-14 22:53:16 +02:00
Родитель 5d97eedb15
Коммит c5cefb2508
1 изменённых файлов: 8 добавлений и 1 удалений

Просмотреть файл

@ -128,8 +128,9 @@ namespace SkiaSharp
using (var recorder = new SKPictureRecorder())
using (var canvas = recorder.BeginRecording(SKRect.Create(CanvasSize)))
{
// if there is no viewbox, then we don't do anything, otherwise
// scale the SVG dimensions to fit inside the user dimensions
if (ViewBox.Width != CanvasSize.Width || ViewBox.Height != CanvasSize.Height)
if (!ViewBox.IsEmpty && (ViewBox.Width != CanvasSize.Width || ViewBox.Height != CanvasSize.Height))
{
if (preserveAspectRatio == "none")
{
@ -148,6 +149,12 @@ namespace SkiaSharp
// translate the canvas by the viewBox origin
canvas.Translate(-ViewBox.Left, -ViewBox.Top);
// if the viewbox was specified, then crop to that
if (!ViewBox.IsEmpty)
{
canvas.ClipRect(ViewBox);
}
LoadElements(svg.Elements(), canvas);
Picture = recorder.EndRecording();