diff options
Diffstat (limited to 'src/SvgPicture.cs')
| -rw-r--r-- | src/SvgPicture.cs | 36 |
1 files changed, 32 insertions, 4 deletions
diff --git a/src/SvgPicture.cs b/src/SvgPicture.cs index 38781a1c..19ace4db 100644 --- a/src/SvgPicture.cs +++ b/src/SvgPicture.cs @@ -41,6 +41,38 @@ namespace Crow Dimensions = new Size (hSVG.Dimensions.Width, hSVG.Dimensions.Height); } } + + #region implemented abstract members of Fill + + public override void SetAsSource (Context ctx, Rectangle bounds = default(Rectangle)) + { + float widthRatio = 1f; + float heightRatio = 1f; + + if (Scaled){ + widthRatio = (float)bounds.Width / Dimensions.Width; + heightRatio = (float)bounds.Height / Dimensions.Height; + } + + if (KeepProportions) { + if (widthRatio < heightRatio) + heightRatio = widthRatio; + else + widthRatio = heightRatio; + } + + using (ImageSurface tmp = new ImageSurface (Format.Argb32, bounds.Width, bounds.Height)) { + using (Cairo.Context gr = new Context (tmp)) { + gr.Translate (bounds.Left, bounds.Top); + gr.Scale (widthRatio, heightRatio); + gr.Translate ((bounds.Width/widthRatio - Dimensions.Width)/2, (bounds.Height/heightRatio - Dimensions.Height)/2); + + hSVG.RenderCairo (gr); + } + ctx.SetSource (tmp); + } + } + #endregion public override void Paint (Cairo.Context gr, Rectangle rect, string subPart = "") { @@ -64,10 +96,6 @@ namespace Crow gr.Scale (widthRatio, heightRatio); gr.Translate (((float)rect.Width/widthRatio - Dimensions.Width)/2f, ((float)rect.Height/heightRatio - Dimensions.Height)/2f); - if (string.IsNullOrEmpty (subPart)) - hSVG.RenderCairo (gr); - else - hSVG.RenderCairoSub (gr, "#" + subPart); gr.Restore (); } } |