diff options
| author | Jean-Philippe Bruyère <jp_bruyere@hotmail.com> | 2018-02-03 06:12:57 +0100 |
|---|---|---|
| committer | Jean-Philippe Bruyère <jp_bruyere@hotmail.com> | 2018-02-03 06:19:51 +0100 |
| commit | 726fe4f0acdee5bce7371c8db6b835668d95df17 (patch) | |
| tree | 445dfca91f3adac0aa549d4b8a6fdfc6676e6006 /src/SvgPicture.cs | |
| parent | d5c135d4a8ae66f5c0160c089e9e853a0929e839 (diff) | |
share Picture resource data among widgets
Diffstat (limited to 'src/SvgPicture.cs')
| -rw-r--r-- | src/SvgPicture.cs | 42 |
1 files changed, 36 insertions, 6 deletions
diff --git a/src/SvgPicture.cs b/src/SvgPicture.cs index b398d523..b4026852 100644 --- a/src/SvgPicture.cs +++ b/src/SvgPicture.cs @@ -30,22 +30,45 @@ using Cairo; namespace Crow { + /// <summary> + /// Derived from FILL for loading and drawing SVG images in the interface + /// </summary> public class SvgPicture : Picture { Rsvg.Handle hSVG; + #region CTOR + /// <summary> + /// Initializes a new instance of SvgPicture. + /// </summary> public SvgPicture () {} + /// <summary> + /// Initializes a new instance of SvgPicture by loading the SVG file pointed by the path argument + /// </summary> + /// <param name="path">image path, may be embedded</param> public SvgPicture (string path) : base(path) {} - protected override void loadFromStream (Stream stream) + #endregion + + public override void Load (string path) { - using (MemoryStream ms = new MemoryStream ()) { - stream.CopyTo (ms); + Path = path; + if (sharedResources.ContainsKey (path)) { + sharedPicture sp = sharedResources [path]; + hSVG = (Rsvg.Handle)sp.Data; + Dimensions = sp.Dims; + return; + } + using (Stream stream = Interface.GetStreamFromPath (path)) { + using (MemoryStream ms = new MemoryStream ()) { + stream.CopyTo (ms); - hSVG = new Rsvg.Handle (ms.ToArray ()); - Dimensions = new Size (hSVG.Dimensions.Width, hSVG.Dimensions.Height); + hSVG = new Rsvg.Handle (ms.ToArray ()); + Dimensions = new Size (hSVG.Dimensions.Width, hSVG.Dimensions.Height); + } } + sharedResources [path] = new sharedPicture (hSVG, Dimensions); } #region implemented abstract members of Fill @@ -79,7 +102,14 @@ namespace Crow } } #endregion - + + /// <summary> + /// paint the image in the rectangle given in arguments according + /// to the Scale and keepProportion parameters. + /// </summary> + /// <param name="gr">drawing Backend context</param> + /// <param name="rect">bounds of the target surface to paint</param> + /// <param name="subPart">limit rendering to svg part named 'subPart'</param> public override void Paint (Cairo.Context gr, Rectangle rect, string subPart = "") { float widthRatio = 1f; |