diff options
| author | jpbruyere <jp.bruyere@hotmail.com> | 2016-02-02 23:38:54 +0100 |
|---|---|---|
| committer | jpbruyere <jp.bruyere@hotmail.com> | 2016-02-02 23:38:54 +0100 |
| commit | 67bd044b6e5fe52b8b76cc5d7eb8fd0ce9dc3ee9 (patch) | |
| tree | b94ae5e6ef363eab5f0888b459789ecea9ac5d5d /src/SvgPicture.cs | |
| parent | 2b087282dd73152d21140ea7312a90e046c84f61 (diff) | |
Gradient, Bitmap and Svg Filling
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 (); } } |