diff options
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; |