From: jpbruyere Date: Sat, 23 May 2015 13:20:53 +0000 (+0200) Subject: Image loading detecting svg with extension, ressource tag (#) for X-Git-Tag: 0.2~95 X-Git-Url: https://git.osiis.dedyn.io/?a=commitdiff_plain;h=70c3f379d422f0bd729c93161bb5d9e28afc9040;p=jp%2Fcrow.git Image loading detecting svg with extension, ressource tag (#) for pathes -svg sub element drawing --- diff --git a/GOLib.csproj b/GOLib.csproj index 3cc7e7e2..b8b0fb24 100644 --- a/GOLib.csproj +++ b/GOLib.csproj @@ -306,11 +306,8 @@ - - go.image.icons.question_mark - - + diff --git a/Images/Icons/IconAlerte.svg b/Images/Icons/IconAlerte.svg new file mode 100755 index 00000000..286dbf3a --- /dev/null +++ b/Images/Icons/IconAlerte.svg @@ -0,0 +1,177 @@ + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Images/Icons/icon_alert.gif b/Images/Icons/icon_alert.gif deleted file mode 100755 index f3d40961..00000000 Binary files a/Images/Icons/icon_alert.gif and /dev/null differ diff --git a/Images/Icons/question_mark.svg b/Images/Icons/question_mark.svg deleted file mode 100644 index 9272381f..00000000 --- a/Images/Icons/question_mark.svg +++ /dev/null @@ -1,105 +0,0 @@ - - - - - - - - - - - - - - - - - - image/svg+xml - - - - - - - ? - - diff --git a/Images/Icons/updown.svg b/Images/Icons/updown.svg index df22a28b..a4d5fcb4 100644 --- a/Images/Icons/updown.svg +++ b/Images/Icons/updown.svg @@ -5,10 +5,47 @@ xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:svg="http://www.w3.org/2000/svg" xmlns="http://www.w3.org/2000/svg" + xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" + xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" viewBox="0 0 65.480012 51.479989" height="51.479988" - width="65.480011"> - + width="65.480011" + id="svg2" + version="1.1" + inkscape:version="0.91 r13725" + sodipodi:docname="updown.svg"> + + + + image/svg+xml + + + + + + + + + - + id="up" + transform="matrix(0.88780545,0,0,0.79362094,4.0529638,4.3893292)"> + transform="matrix(0.88780545,0,0,0.79362094,4.0529638,4.3893292)"> + sodipodi:nodetypes="cccc" /> diff --git a/Tests/Interfaces/test4.goml b/Tests/Interfaces/test4.goml index 4118e075..13d1a9f6 100755 --- a/Tests/Interfaces/test4.goml +++ b/Tests/Interfaces/test4.goml @@ -57,7 +57,7 @@ + + + diff --git a/Tests/image/tetra.png b/Tests/image/tetra.png new file mode 100755 index 00000000..be7edbe7 Binary files /dev/null and b/Tests/image/tetra.png differ diff --git a/src/GraphicObjects/Container.cs b/src/GraphicObjects/Container.cs index 0d0ad5b3..298f1873 100644 --- a/src/GraphicObjects/Container.cs +++ b/src/GraphicObjects/Container.cs @@ -177,8 +177,8 @@ namespace go using (System.Xml.XmlReader subTree = reader.ReadSubtree()) { - subTree.Read(); - subTree.Read(); //move to first child + subTree.Read(); //skip current node + subTree.Read(); //read first child if (!subTree.IsStartElement()) return; diff --git a/src/GraphicObjects/GraphicObject.cs b/src/GraphicObjects/GraphicObject.cs index 683e88f3..094bc453 100644 --- a/src/GraphicObjects/GraphicObject.cs +++ b/src/GraphicObjects/GraphicObject.cs @@ -213,7 +213,7 @@ namespace go registerForGraphicUpdate (); } } - [XmlAttributeAttribute()][DefaultValue(5)] + [XmlAttributeAttribute()][DefaultValue(2)] public virtual double CornerRadius { get { return _cornerRadius; } set { diff --git a/src/GraphicObjects/Image.cs b/src/GraphicObjects/Image.cs index 3858aebc..863c95cc 100755 --- a/src/GraphicObjects/Image.cs +++ b/src/GraphicObjects/Image.cs @@ -5,89 +5,108 @@ using System.Text; using Cairo; using System.IO; using System.Runtime.InteropServices; +using System.Xml.Serialization; +using System.ComponentModel; namespace go { public class Image : GraphicObject { - byte[] image; Rsvg.Handle hSVG; Size imgSize; string _imgPath; - - [System.Xml.Serialization.XmlIgnore] - public System.Drawing.Bitmap Bitmap { - set { - loadImage (value); - } - } + string _svgSub; - [System.Xml.Serialization.XmlAttributeAttribute("Path")] + [XmlAttributeAttribute("Path")] public string ImagePath { get { return _imgPath; } set { _imgPath = value; - loadImage (_imgPath); + LoadImage (_imgPath); } } + [XmlAttributeAttribute()][DefaultValue(null)] + public string SvgSub { + get { return _svgSub; } + set { + _svgSub = value; + registerForGraphicUpdate (); + } + } + + #region CTOR public Image () : base() { } - public Image (string ImagePath, Rectangle _bounds) : base(_bounds) { _imgPath = ImagePath; - loadImage(_imgPath); + LoadImage(_imgPath); } - public Image (string ImagePath) : base() { _imgPath = ImagePath; - loadImage(_imgPath); + LoadImage(_imgPath); } - public Image (System.Drawing.Bitmap _bitmap) : base() { - Bitmap = _bitmap; + LoadImage (_bitmap); } + #endregion - protected override Size measureRawSize () + #region Image Loading + void loadFromRessource(string resId) { - if (image == null && hSVG == null) - loadRessourceSvg ("go.image.icons.question_mark"); + Stream stream = null; - return imgSize + Margin*2; - } - void loadRessourceSvg(string resId) - { - Stream s = System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream(resId); + //first, search for ressource in main executable assembly + stream = System.Reflection.Assembly.GetEntryAssembly().GetManifestResourceStream(resId); + if (stream == null)//try to find ressource in golib assembly + stream = System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream(resId); + if (stream == null) + return; + using (MemoryStream ms = new MemoryStream ()) { - s.CopyTo (ms); - hSVG = new Rsvg.Handle (ms.ToArray ()); - imgSize = new Size (hSVG.Dimensions.Width, hSVG.Dimensions.Height); - _imgPath = resId; + stream.CopyTo (ms); + + if (resId.EndsWith (".svg", true, System.Globalization.CultureInfo.InvariantCulture)) { + hSVG = new Rsvg.Handle (ms.ToArray ()); + imgSize = new Size (hSVG.Dimensions.Width, hSVG.Dimensions.Height); + } else + LoadImage (new System.Drawing.Bitmap (ms)); } } - //load image via System.Drawing.Bitmap, cairo load png only - public void loadImage (string path) + void loadFromFile(string path) { - if (!File.Exists(path)) - return; - - if (path.EndsWith (".svg", true,System.Globalization.CultureInfo.InvariantCulture)) { + if (!File.Exists(path)) + return; + + if (path.EndsWith (".svg", true, System.Globalization.CultureInfo.InvariantCulture)) { hSVG = new Rsvg.Handle (path); imgSize = new Size (hSVG.Dimensions.Width, hSVG.Dimensions.Height); }else - loadImage (new System.Drawing.Bitmap (path)); - _imgPath = path; + LoadImage (new System.Drawing.Bitmap (path)); + } + public void LoadImage (string path) + { + hSVG = null; + image = null; - public void loadImage (System.Drawing.Bitmap bitmap) + if (path.StartsWith ("#")) + loadFromRessource (path.Substring (1)); + else + loadFromFile (path); + + _imgPath = path; + } + //load image via System.Drawing.Bitmap, cairo load png only + public void LoadImage (System.Drawing.Bitmap bitmap) { if (bitmap == null) return; @@ -104,8 +123,18 @@ namespace go image = new byte[bitmapSize]; System.Runtime.InteropServices.Marshal.Copy (data.Scan0, image, 0, bitmapSize); - bitmap.UnlockBits (data); - //bitmap.Dispose(); + bitmap.UnlockBits (data); + } + #endregion + + #region GraphicObject overrides + protected override Size measureRawSize () + { + if (image == null && hSVG == null) { + loadFromRessource ("go.Images.Icons.IconAlerte.svg"); + } + + return imgSize + Margin * 2; } protected override void onDraw (Context gr) { @@ -126,9 +155,13 @@ namespace go } } else { gr.Translate (rImg.X/widthRatio, rImg.Y/heightRatio); - hSVG.RenderCairo (gr); + if (string.IsNullOrEmpty (_svgSub)) + hSVG.RenderCairo (gr); + else + hSVG.RenderCairoSub (gr, "#" + _svgSub); } gr.Restore (); } + #endregion } }