SVGObject.cs 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719
  1. using FastReport.Utils;
  2. using Svg;
  3. using System;
  4. using System.ComponentModel;
  5. using System.Drawing;
  6. using System.Drawing.Design;
  7. using System.Drawing.Drawing2D;
  8. using System.IO;
  9. using System.Net;
  10. using System.Text;
  11. using System.Windows.Forms;
  12. #pragma warning disable
  13. namespace FastReport.SVG
  14. {
  15. /// <summary>
  16. /// SVG object
  17. /// </summary>
  18. public partial class SVGObject : PictureObjectBase, ICloneable
  19. {
  20. private readonly string svgTagPr = "<svg";
  21. #region Private fields
  22. private SvgDocument FSvgDocument;
  23. private SvgDocument FSVGGrayscale;
  24. private DateTime FLastDrawTime;
  25. private readonly TimeSpan FSpan;
  26. private Image FCachedImage;
  27. private Image FCachedGrayscaleImage;
  28. private string FSVGString;
  29. private SvgViewBox FViewBox;
  30. private SvgAspectRatio FAspectRatio;
  31. private float FLastImgWidth;
  32. private float FLastImgHeight;
  33. private float originalWidth;
  34. private float originalHeight;
  35. #endregion
  36. #region Properties
  37. /// <summary>
  38. /// Gets or sets svg document
  39. /// </summary>
  40. [Browsable(false)]
  41. public SvgDocument SvgDocument
  42. {
  43. get { return FSvgDocument; }
  44. }
  45. /// <summary>
  46. /// Gets or sets ViewBox value
  47. /// </summary>
  48. [Browsable(false)]
  49. public SvgViewBox ViewBox
  50. {
  51. get { return FViewBox; }
  52. set { SetViewBox(value); }
  53. }
  54. /// <summary>
  55. /// Gets or sets AspectRatio value
  56. /// </summary>
  57. [Browsable(false)]
  58. public SvgAspectRatio AspectRatio
  59. {
  60. get { return FAspectRatio; }
  61. set { SetAspectRatio(value); }
  62. }
  63. /// <inheritdoc/>
  64. [DefaultValue(PictureBoxSizeMode.Zoom)]
  65. [Category("Behavior")]
  66. public override PictureBoxSizeMode SizeMode
  67. {
  68. get { return base.SizeMode; }
  69. set
  70. {
  71. base.SizeMode = value;
  72. if (SvgDocument != null) // if not PictureObject -> Assign();
  73. {
  74. if (value == PictureBoxSizeMode.StretchImage || value == PictureBoxSizeMode.AutoSize)
  75. AspectRatio = new SvgAspectRatio(SvgPreserveAspectRatio.none);
  76. else
  77. AspectRatio = new SvgAspectRatio(SvgPreserveAspectRatio.xMidYMid);
  78. }
  79. }
  80. }
  81. /// <summary>
  82. /// Gets or sets grayscale svg document
  83. /// </summary>
  84. [Browsable(false)]
  85. public SvgDocument SVGGrayscale
  86. {
  87. get
  88. {
  89. if (FSVGGrayscale == null)
  90. FSVGGrayscale = GetSVGGrayscale();
  91. return FSVGGrayscale;
  92. }
  93. set { FSVGGrayscale = value; }
  94. }
  95. /// <summary>
  96. /// Gets or sets a value indicating that the image should be displayed in grayscale mode.
  97. /// </summary>
  98. [DefaultValue(false)]
  99. [Category("Appearance")]
  100. public override bool Grayscale
  101. {
  102. get { return base.Grayscale; }
  103. set
  104. {
  105. base.Grayscale = value;
  106. if (!Grayscale && FSVGGrayscale != null)
  107. {
  108. FSVGGrayscale = null;
  109. }
  110. if (value == true && (SvgDocument != null)) // if not PictureObject -> Assign();
  111. {
  112. FSVGGrayscale = GetSVGGrayscale();
  113. }
  114. }
  115. }
  116. /// <summary>
  117. /// Returns SVG string
  118. /// </summary>
  119. [EditorAttribute("FastReport.TypeEditors.ExpressionEditor, FastReport", typeof(UITypeEditor))]
  120. public string SVGString
  121. {
  122. get { return FSVGString; }
  123. set
  124. {
  125. if (!string.IsNullOrEmpty(value))
  126. {
  127. FSVGString = value;
  128. FSvgDocument = SvgDocument.FromSvg<SvgDocument>(FSVGString);
  129. if (Grayscale)
  130. {
  131. SVGGrayscale = GetSVGGrayscale();
  132. }
  133. if (FSvgDocument != null)
  134. {
  135. originalWidth = this.Width;
  136. originalHeight = this.Height;
  137. FLastImgHeight = int.MinValue;
  138. FLastImgWidth = int.MinValue;
  139. if (FSvgDocument.Width.Type != SvgUnitType.Percentage)
  140. {
  141. originalWidth = FSvgDocument.Width;
  142. FSvgDocument.Width = new SvgUnit(SvgUnitType.Percentage, 100);
  143. }
  144. if (FSvgDocument.Height.Type != SvgUnitType.Percentage)
  145. {
  146. originalHeight = FSvgDocument.Height;
  147. FSvgDocument.Height = new SvgUnit(SvgUnitType.Percentage, 100);
  148. }
  149. if (FSvgDocument.ViewBox.Width == 0 || FSvgDocument.ViewBox.Height == 0)
  150. {
  151. FSvgDocument.ViewBox = new SvgViewBox(FSvgDocument.ViewBox.MinX,
  152. FSvgDocument.ViewBox.MinY,
  153. FSvgDocument.ViewBox.Width == 0 ? originalWidth : FSvgDocument.ViewBox.Width,
  154. FSvgDocument.ViewBox.Height == 0 ? originalHeight : FSvgDocument.ViewBox.Height);
  155. }
  156. }
  157. }
  158. }
  159. }
  160. protected override float ImageHeight
  161. {
  162. get
  163. {
  164. if (SvgDocument == null) return 0;
  165. if (SizeMode == PictureBoxSizeMode.AutoSize)
  166. return originalHeight;
  167. return SvgDocument.GetDimensions().Height;
  168. }
  169. }
  170. protected override float ImageWidth
  171. {
  172. get
  173. {
  174. if (SvgDocument == null) return 0;
  175. if (SizeMode == PictureBoxSizeMode.AutoSize)
  176. return originalWidth;
  177. return SvgDocument.GetDimensions().Width;
  178. }
  179. }
  180. #endregion
  181. #region Private Methods
  182. private Color GetGrayscaleColor(Color color)
  183. {
  184. int grayscale = (int)((color.R * 0.299f) + (color.G * 0.587f) + (color.B * 0.114f));
  185. return Color.FromArgb(color.A, grayscale, grayscale, grayscale);
  186. }
  187. private void MakeElementGrayScale(SvgElement element)
  188. {
  189. if (element.Fill != null)
  190. {
  191. if (element.Fill is SvgGradientServer)
  192. foreach (SvgGradientStop stop in (element.Fill as SvgGradientServer).Stops)
  193. {
  194. (stop.StopColor as SvgColourServer).Colour =
  195. GetGrayscaleColor((stop.StopColor as SvgColourServer).Colour);
  196. }
  197. else
  198. ((element).Fill as SvgColourServer).Colour = GetGrayscaleColor(((element).Fill as SvgColourServer).Colour);
  199. }
  200. if ((element).Stroke != null)
  201. ((element).Stroke as SvgColourServer).Colour = GetGrayscaleColor(((element).Stroke as SvgColourServer).Colour);
  202. if (element.Children.Count > 0)
  203. {
  204. foreach (var item in element.Children)
  205. {
  206. MakeElementGrayScale(item);
  207. }
  208. }
  209. }
  210. //private byte[] SvgToImgByteArray(SvgDocument svg)
  211. //{
  212. // using (MemoryStream pictStr = new MemoryStream())
  213. // {
  214. // Image img = svg.Draw();
  215. // img.Save(pictStr, ImageFormat.Png);
  216. // return pictStr.ToArray();
  217. // }
  218. //}
  219. private static string LoadURL(string url)
  220. {
  221. if (!String.IsNullOrEmpty(url))
  222. {
  223. System.Net.ServicePointManager.SecurityProtocol = (SecurityProtocolType)(0xc0 | 0x300 | 0xc00);
  224. using (WebClient web = new WebClient())
  225. {
  226. return Encoding.UTF8.GetString(web.DownloadData(url));
  227. }
  228. }
  229. return null;
  230. }
  231. public Image GetImage()
  232. {
  233. if (SvgDocument == null)
  234. return null;
  235. FLastDrawTime = DateTime.MinValue;
  236. Size size = SvgDocument.GetDimensions().ToSize();
  237. return GetImage(Grayscale, size.Width, size.Height);
  238. }
  239. private Image GetImage(bool isGrayscale, int imgWidth, int imgHeight)
  240. {
  241. Image image;
  242. float scaleY = imgHeight / FLastImgHeight;
  243. float scaleX = imgWidth / FLastImgWidth;
  244. const float minScale = 0.71f;
  245. const float maxScale = 1.41f;
  246. if (SystemFake.DateTime.Now - FLastDrawTime > FSpan || scaleY < minScale || scaleY > maxScale || scaleX < minScale || scaleX > maxScale
  247. || isGrayscale && FCachedGrayscaleImage == null || !isGrayscale && FCachedImage == null)
  248. {
  249. image = isGrayscale ? SVGGrayscale.Draw(imgWidth, imgHeight) : SvgDocument.Draw(imgWidth, imgHeight);
  250. FLastDrawTime = SystemFake.DateTime.Now;
  251. if (isGrayscale)
  252. {
  253. if (FCachedGrayscaleImage != null)
  254. FCachedGrayscaleImage.Dispose();
  255. FCachedGrayscaleImage = image;
  256. }
  257. else
  258. {
  259. if (FCachedImage != null)
  260. FCachedImage.Dispose();
  261. FCachedImage = image;
  262. }
  263. FLastImgHeight = imgHeight;
  264. FLastImgWidth = imgWidth;
  265. }
  266. else
  267. {
  268. if (isGrayscale)
  269. image = FCachedGrayscaleImage;
  270. else
  271. image = FCachedImage;
  272. }
  273. return image;
  274. }
  275. private string GetSvgString()
  276. {
  277. using (StringWriter sw = new StringWriter())
  278. {
  279. using (System.Xml.XmlTextWriter writer = new System.Xml.XmlTextWriter(sw))
  280. SvgDocument.Write(writer);
  281. string svgStr = sw.ToString();
  282. sw.Flush();
  283. return svgStr;
  284. }
  285. }
  286. private string GetViewBoxString(out int startVb, out int endVb)
  287. {
  288. if (string.IsNullOrEmpty(SVGString))
  289. throw new ArgumentNullException("SvgString is null");
  290. startVb = SVGString.IndexOf("viewBox");
  291. endVb = -1;
  292. if (startVb != -1)
  293. {
  294. startVb = SVGString.IndexOf("\"", startVb) + 1;
  295. endVb = SVGString.IndexOf("\"", startVb);
  296. string vb = SVGString.Substring(startVb, endVb - startVb);
  297. return vb;
  298. }
  299. else return null;
  300. }
  301. private SvgViewBox GetViewBox()
  302. {
  303. if (string.IsNullOrEmpty(SVGString))
  304. throw new ArgumentNullException("SvgString is null");
  305. SvgViewBox viewBox = new SvgViewBox();
  306. int startVb, endVb;
  307. string vb = GetViewBoxString(out startVb, out endVb);
  308. if (!string.IsNullOrEmpty(vb))
  309. {
  310. string[] vbArray = vb.Split(' ', ',');
  311. float minX;
  312. float minY;
  313. float width;
  314. float height;
  315. if (float.TryParse(vbArray[0], out minX) &&
  316. float.TryParse(vbArray[1], out minY) &&
  317. float.TryParse(vbArray[2], out width) &&
  318. float.TryParse(vbArray[3], out height))
  319. {
  320. viewBox.MinX = minX;
  321. viewBox.MinY = minY;
  322. viewBox.Width = width;
  323. viewBox.Height = height;
  324. }
  325. }
  326. return viewBox;
  327. }
  328. private void SetViewBox(SvgViewBox viewBox)
  329. {
  330. int startVb, endVb;
  331. string oldVb = GetViewBoxString(out startVb, out endVb);
  332. string newVb = viewBox.MinX + " " + viewBox.MinY + " " + viewBox.Width + " " + viewBox.Height;
  333. if (!string.IsNullOrEmpty(oldVb))
  334. {
  335. SVGString = SVGString.Remove(startVb, endVb - startVb);
  336. SVGString = SVGString.Insert(startVb, newVb);
  337. }
  338. else
  339. {
  340. startVb = SVGString.IndexOf(svgTagPr) + svgTagPr.Length;
  341. SVGString = SVGString.Insert(startVb, " " + "viewBox=\"" + newVb + "\"");
  342. }
  343. FViewBox = viewBox;
  344. }
  345. private string GetAspectRatioString(out int startAr, out int endAr)
  346. {
  347. if (string.IsNullOrEmpty(SVGString))
  348. throw new ArgumentNullException("SvgString is null");
  349. startAr = SVGString.IndexOf("preserveAspectRatio");
  350. endAr = -1;
  351. if (startAr != -1)
  352. {
  353. startAr = SVGString.IndexOf("\"", startAr) + 1;
  354. endAr = SVGString.IndexOf("\"", startAr);
  355. string ar = SVGString.Substring(startAr, endAr - startAr);
  356. return ar;
  357. }
  358. else return null;
  359. }
  360. private SvgAspectRatio GetAspectRatio()
  361. {
  362. if (string.IsNullOrEmpty(SVGString))
  363. throw new ArgumentNullException("SvgString is null");
  364. SvgAspectRatio aspectRatio = new SvgAspectRatio();
  365. int startAr, endAr;
  366. string ar = GetAspectRatioString(out startAr, out endAr);
  367. if (!string.IsNullOrEmpty(ar))
  368. {
  369. SvgPreserveAspectRatio align;
  370. Enum.TryParse(ar, out align);
  371. aspectRatio.Align = align;
  372. }
  373. return aspectRatio;
  374. }
  375. private void SetAspectRatio(SvgAspectRatio aspectRatio)
  376. {
  377. int startAr, endAr;
  378. string oldAr = GetAspectRatioString(out startAr, out endAr);
  379. string newAr = aspectRatio.Align.ToString();
  380. if (!string.IsNullOrEmpty(oldAr))
  381. {
  382. SVGString = SVGString.Remove(startAr, endAr - startAr);
  383. SVGString = SVGString.Insert(startAr, newAr);
  384. }
  385. else
  386. {
  387. startAr = SVGString.IndexOf(svgTagPr) + svgTagPr.Length;
  388. SVGString = SVGString.Insert(startAr, " " + "preserveAspectRatio=\"" + newAr + "\"");
  389. }
  390. FAspectRatio = aspectRatio;
  391. }
  392. //private Stream StreamFromString(string s)
  393. //{
  394. // var stream = new MemoryStream();
  395. // var writer = new StreamWriter(stream, Encoding.UTF8);
  396. // writer.Write(s);
  397. // writer.Flush();
  398. // stream.Position = 0;
  399. // return stream;
  400. //}
  401. #endregion
  402. #region Internal Methods
  403. internal static SvgDocument GetSvgDocument(string filePath)
  404. {
  405. SvgDocument document = SvgDocument.Open(filePath);
  406. return document;
  407. }
  408. internal void MakeGrayScale(SvgDocument svg)
  409. {
  410. foreach (var element in svg.Children)
  411. {
  412. MakeElementGrayScale(element);
  413. if (element.Children.Count > 0)
  414. {
  415. foreach (var item in element.Children)
  416. {
  417. MakeElementGrayScale(item);
  418. }
  419. }
  420. }
  421. }
  422. internal SvgDocument GetSVGGrayscale()
  423. {
  424. FSVGGrayscale = SvgDocument.FromSvg<SvgDocument>(FSVGString);
  425. MakeGrayScale(FSVGGrayscale);
  426. //GrayscaleHash = FSVGGrayscale.GetHashCode();
  427. return FSVGGrayscale;
  428. }
  429. #endregion
  430. #region Public Methods
  431. /// <inheritdoc/>
  432. public override void Serialize(FRWriter writer)
  433. {
  434. SVGObject c = writer.DiffObject as SVGObject;
  435. base.Serialize(writer);
  436. if (writer.SerializeTo == SerializeTo.SourcePages ||
  437. writer.SerializeTo == SerializeTo.Preview ||
  438. (String.IsNullOrEmpty(ImageLocation) && String.IsNullOrEmpty(DataColumn)))
  439. {
  440. if (!string.IsNullOrEmpty(SVGString) && SVGString != c.SVGString)
  441. {
  442. writer.WriteValue("SvgData", Convert.ToBase64String(Encoding.UTF8.GetBytes(SVGString)));
  443. }
  444. }
  445. }
  446. /// <inheritdoc/>
  447. public override void Deserialize(FRReader reader)
  448. {
  449. base.Deserialize(reader);
  450. if (reader.HasProperty("SvgData"))
  451. {
  452. SetSVGByContent(Encoding.UTF8.GetString(Convert.FromBase64String(reader.ReadStr("SvgData"))));
  453. }
  454. }
  455. /// <inheritdoc/>
  456. public override void Assign(Base source)
  457. {
  458. base.Assign(source);
  459. SVGObject src = source as SVGObject;
  460. if (src != null)
  461. {
  462. if (src.SVGString != null)
  463. SetSVGByContent(src.SVGString);
  464. }
  465. }
  466. /// <inheritdoc/>
  467. public override void LoadImage()
  468. {
  469. if (!String.IsNullOrEmpty(ImageLocation))
  470. {
  471. try
  472. {
  473. Uri uri = CalculateUri();
  474. if (uri.IsFile)
  475. SetSVGByPath(uri.LocalPath);
  476. else
  477. SetSVGByContent(LoadURL(uri.ToString()));
  478. }
  479. catch
  480. {
  481. SetSVGByContent("");
  482. }
  483. }
  484. }
  485. /// <inheritdoc/>
  486. public override void GetData()
  487. {
  488. base.GetData();
  489. if (!String.IsNullOrEmpty(DataColumn))
  490. {
  491. object data = Report.GetColumnValueNullable(DataColumn);
  492. if (data is byte[])
  493. {
  494. SetSVGByContent(Encoding.UTF8.GetString((byte[])data));
  495. }
  496. if (data is string)
  497. {
  498. try
  499. {
  500. SetSVGByContent(data.ToString());
  501. }
  502. catch
  503. {
  504. ImageLocation = data.ToString();
  505. }
  506. }
  507. }
  508. }
  509. /// <inheritdoc/>
  510. public override void DrawImage(FRPaintEventArgs e)
  511. {
  512. IGraphics g = e.Graphics;
  513. if (SvgDocument == null)
  514. {
  515. DrawErrorImage(g, e);
  516. return;
  517. }
  518. float drawLeft = (AbsLeft + Padding.Left) * e.ScaleX;
  519. float drawTop = (AbsTop + Padding.Top) * e.ScaleY;
  520. float drawWidth = (Width - Padding.Horizontal) * e.ScaleX;
  521. float drawHeight = (Height - Padding.Vertical) * e.ScaleY;
  522. RectangleF drawRect = new RectangleF(
  523. drawLeft,
  524. drawTop,
  525. drawWidth,
  526. drawHeight);
  527. IGraphicsState state = g.Save();
  528. try
  529. {
  530. g.SetClip(drawRect);
  531. Report report = Report;
  532. if (report != null && report.SmoothGraphics)
  533. {
  534. g.InterpolationMode = InterpolationMode.HighQualityBicubic;
  535. g.SmoothingMode = SmoothingMode.AntiAlias;
  536. }
  537. DrawImageInternal(e, drawRect);
  538. }
  539. finally
  540. {
  541. g.Restore(state);
  542. }
  543. }
  544. protected override void DrawImageInternal2(IGraphics graphics, PointF upperLeft, PointF upperRight, PointF lowerLeft)
  545. {
  546. int imgWidth = (int)Math.Sqrt((upperLeft.X - upperRight.X) * (upperLeft.X - upperRight.X) + (upperLeft.Y - upperRight.Y) * (upperLeft.Y - upperRight.Y));
  547. int imgHeight = (int)Math.Sqrt((upperLeft.X - lowerLeft.X) * (upperLeft.X - lowerLeft.X) + (upperLeft.Y - lowerLeft.Y) * (upperLeft.Y - lowerLeft.Y));
  548. Image image = GetImage(Grayscale, imgWidth, imgHeight);
  549. if (image != null)
  550. graphics.DrawImage(image, new PointF[] { upperLeft, upperRight, lowerLeft });
  551. }
  552. ///// <inheritdoc/>
  553. //internal override void DrawImageInternal(FRPaintEventArgs e, RectangleF drawRect)
  554. //{
  555. // if (Image == null || SvgDocument == null)
  556. // return;
  557. // bool rotate = Angle == 90 || Angle == 270;
  558. // float imageWidth = Image.Width;//rotate ? Image.Height : Image.Width;
  559. // float imageHeight = Image.Height;//rotate ? Image.Width : Image.Height;
  560. // PointF upperLeft;
  561. // PointF upperRight;
  562. // PointF lowerLeft;
  563. // System.Drawing.Drawing2D.Matrix matrix = e.Graphics.Transform;
  564. // GetImageAngleTransform(drawRect, imageWidth, imageHeight, e.ScaleX, e.ScaleY, matrix.OffsetX, matrix.OffsetY, out upperLeft, out upperRight, out lowerLeft);
  565. // int imgWidth = (int)Math.Sqrt((upperLeft.X - upperRight.X) * (upperLeft.X - upperRight.X) + (upperLeft.Y - upperRight.Y) * (upperLeft.Y - upperRight.Y));
  566. // int imgHeight = (int)Math.Sqrt((upperLeft.X - lowerLeft.X) * (upperLeft.X - lowerLeft.X) + (upperLeft.Y - lowerLeft.Y) * (upperLeft.Y - lowerLeft.Y));
  567. // Image image;
  568. // if (Grayscale)
  569. // {
  570. // if (FSVGGrayscale == null || GrayscaleHash != FSVGGrayscale.GetHashCode())
  571. // {
  572. // FSVGGrayscale = GetSVGGrayscale();
  573. // }
  574. // image = GetImage(true, imgWidth, imgHeight);
  575. // }
  576. // else
  577. // image = GetImage(false, imgWidth, imgHeight);
  578. // e.Graphics.DrawImage(image, new PointF[] { upperLeft, upperRight, lowerLeft });
  579. //}
  580. /// <summary>
  581. /// Returns clone of this object
  582. /// </summary>
  583. /// <returns></returns>
  584. public object Clone()
  585. {
  586. SVGObject clone = new SVGObject();
  587. clone.Assign(this);
  588. return clone;
  589. }
  590. /// <summary>
  591. /// Sets svg object by SvgDocument
  592. /// </summary>
  593. /// <param name="svg">SVG document</param>
  594. public void SetSVG(SvgDocument svg)
  595. {
  596. SetSVGByContent(svg.GetXML());
  597. }
  598. /// <summary>
  599. /// Sets svg object from specified path
  600. /// </summary>
  601. /// <param name="path">path to SVG file</param>
  602. public void SetSVGByPath(string path)
  603. {
  604. SetSVGByContent(File.ReadAllText(path));
  605. }
  606. /// <summary>
  607. /// Sets svg object from svg string
  608. /// </summary>
  609. /// <param name="content">SVG string</param>
  610. public void SetSVGByContent(string content)
  611. {
  612. SVGString = content;
  613. }
  614. protected override void ResetImageIndex()
  615. {
  616. }
  617. #endregion
  618. protected override void Dispose(bool disposing)
  619. {
  620. if (disposing)
  621. {
  622. if (FCachedImage != null)
  623. {
  624. FCachedImage.Dispose();
  625. FCachedImage = null;
  626. }
  627. if (FCachedGrayscaleImage != null)
  628. {
  629. FCachedGrayscaleImage.Dispose();
  630. FCachedGrayscaleImage = null;
  631. }
  632. }
  633. base.Dispose(disposing);
  634. }
  635. /// <summary>
  636. /// Initializes a new instance of the <see cref="SVGObject"/> class with default settings.
  637. /// </summary>
  638. public SVGObject() : base()
  639. {
  640. FSpan = new TimeSpan(0, 0, 3);
  641. SetFlags(Flags.HasSmartTag, true);
  642. FLastDrawTime = DateTime.MinValue;
  643. }
  644. }
  645. }
  646. #pragma warning restore