DrawData.cs 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743
  1. using InABox.Core;
  2. using netDxf;
  3. using netDxf.Tables;
  4. using Svg;
  5. using Svg.Transforms;
  6. using Syncfusion.Pdf;
  7. using Syncfusion.Pdf.Graphics;
  8. using Syncfusion.Pdf.Parsing;
  9. using System;
  10. using System.Collections.Generic;
  11. using System.Drawing;
  12. using System.Drawing.Drawing2D;
  13. using System.Linq;
  14. using System.Numerics;
  15. using System.Text;
  16. using System.Threading.Tasks;
  17. using FontStyle = System.Drawing.FontStyle;
  18. using Vector2 = System.Numerics.Vector2;
  19. using Vector3 = System.Numerics.Vector3;
  20. using Vector4 = System.Numerics.Vector4;
  21. using SPdfGraphics = Syncfusion.Pdf.Graphics.PdfGraphics;
  22. using Syncfusion.Pdf.Tables;
  23. using netDxf.Entities;
  24. namespace InABox.Dxf;
  25. public enum TextAlignment
  26. {
  27. Left,
  28. Center,
  29. Right,
  30. Fit,
  31. Justify
  32. }
  33. public enum TextLineAlignment
  34. {
  35. Top,
  36. Center,
  37. Bottom,
  38. Baseline
  39. }
  40. public class TextFormat
  41. {
  42. public TextAlignment Alignment { get; set; } = TextAlignment.Left;
  43. public TextLineAlignment LineAlignment { get; set; } = TextLineAlignment.Top;
  44. }
  45. public class TransformData
  46. {
  47. public DxfData Data { get; set; }
  48. private Stack<Matrix4x4> MatrixStack = new();
  49. public Matrix4x4 Transform { get; private set; } = Matrix4x4.Identity;
  50. public void PushTransform()
  51. {
  52. MatrixStack.Push(Transform);
  53. }
  54. public void TransformBy(Matrix4x4 matrix)
  55. {
  56. Transform = matrix * Transform;
  57. }
  58. protected virtual void UpdateTransform()
  59. {
  60. }
  61. protected Matrix ProjectMatrix(Matrix4x4 matrix)
  62. {
  63. var elMatrix = new Matrix3x2();
  64. elMatrix.M11 = (float)matrix.M11;
  65. elMatrix.M12 = (float)matrix.M12;
  66. elMatrix.M21 = (float)matrix.M21;
  67. elMatrix.M22 = (float)matrix.M22;
  68. elMatrix.M31 = (float)matrix.M41;
  69. elMatrix.M32 = (float)matrix.M42;
  70. var newMatrix = new Matrix();
  71. newMatrix.MatrixElements = elMatrix;
  72. return newMatrix;
  73. }
  74. public void PopTransform()
  75. {
  76. Transform = MatrixStack.Pop();
  77. UpdateTransform();
  78. }
  79. public static Matrix4x4 ArbitraryAxisMatrix(Vector3 zAxis)
  80. {
  81. if (zAxis.Equals(Vector3.UnitZ))
  82. {
  83. return Matrix4x4.Identity;
  84. }
  85. var unitY = Vector3.UnitY;
  86. var unitZ = Vector3.UnitZ;
  87. var v = ((!(Math.Abs(zAxis.X) < 1.0 / 64.0) || !(Math.Abs(zAxis.Y) < 1.0 / 64.0)) ? Vector3.Cross(unitZ, zAxis) : Vector3.Cross(unitY, zAxis));
  88. v = Vector3.Normalize(v);
  89. var vector = Vector3.Cross(zAxis, v);
  90. vector = Vector3.Normalize(vector);
  91. return new Matrix4x4(v.X, vector.X, zAxis.X, 0, v.Y, vector.Y, zAxis.Y, 0, v.Z, vector.Z, zAxis.Z, 0, 0, 0, 0, 1);
  92. }
  93. public void ArbitraryAxis(netDxf.Vector3 zAxis)
  94. {
  95. Transform = ArbitraryAxisMatrix(new((float)zAxis.X, (float)zAxis.Y, (float)zAxis.Z)) * Transform;
  96. UpdateTransform();
  97. }
  98. public void ArbitraryAxis(Vector3 zAxis)
  99. {
  100. Transform = ArbitraryAxisMatrix(zAxis) * Transform;
  101. UpdateTransform();
  102. }
  103. public void Translate(float x, float y)
  104. {
  105. Transform = Transform.Translate(x, y, 0);
  106. UpdateTransform();
  107. }
  108. public void Translate(PointF point)
  109. {
  110. Transform = Transform.Translate(point.X, point.Y, 0);
  111. UpdateTransform();
  112. }
  113. public void Rotate(float angle)
  114. {
  115. Transform = Transform.Rotate(0, 0, 1, angle);
  116. UpdateTransform();
  117. }
  118. public void Scale(float scale)
  119. {
  120. Scale(scale, scale);
  121. }
  122. public void Scale(float scaleX, float scaleY)
  123. {
  124. Transform = Transform.Scale(scaleX, scaleY, 1);
  125. UpdateTransform();
  126. }
  127. public PointF TransformPoint(float x, float y)
  128. {
  129. var nVec = Vector4.Transform(new Vector4(x, y, 0, 1), Transform);
  130. return new(nVec.X, nVec.Y);
  131. }
  132. public PointF TransformPoint(PointF vec)
  133. {
  134. var nVec = Vector4.Transform(new Vector4(vec.X, vec.Y, 0, 1), Transform);
  135. return new(nVec.X, nVec.Y);
  136. }
  137. public PointF TransformPoint(netDxf.Vector2 vec)
  138. {
  139. var nVec = Vector4.Transform(new Vector4((float)vec.X, (float)vec.Y, 0, 1), Transform);
  140. return new(nVec.X, nVec.Y);
  141. }
  142. public PointF TransformPoint(netDxf.Vector3 vec)
  143. {
  144. var nVec = Vector4.Transform(new Vector4((float)vec.X, (float)vec.Y, (float)vec.Z, 1), Transform);
  145. return new(nVec.X, nVec.Y);
  146. }
  147. public PointF TransformVec(PointF vec)
  148. {
  149. var nVec = Vector4.Transform(new Vector4(vec.X, vec.Y, 0, 0), Transform);
  150. return new(nVec.X, nVec.Y);
  151. }
  152. public Vector2 TransformVec(Vector2 vec)
  153. {
  154. var nVec = Vector4.Transform(new Vector4(vec.X, vec.Y, 0, 0), Transform);
  155. return new(nVec.X, nVec.Y);
  156. }
  157. public float ScaleFactor()
  158. {
  159. return (TransformVec(new Vector2(1, 0))).Length();
  160. }
  161. public static PointF ConvertPoint(netDxf.Vector2 vec)
  162. {
  163. return new PointF((float)vec.X, (float)vec.Y);
  164. }
  165. public static PointF ConvertPoint(netDxf.Vector3 vec)
  166. {
  167. return new PointF((float)vec.X, (float)vec.Y);
  168. }
  169. }
  170. public class DrawData : TransformData
  171. {
  172. private IGraphics _graphics;
  173. public IGraphics Graphics
  174. {
  175. get => _graphics;
  176. set
  177. {
  178. _graphics = value;
  179. _graphics.DrawData = this;
  180. }
  181. }
  182. private Stack<Color> _blockColours = new();
  183. public Color BlockColour { get; set; } = Color.Black;
  184. public void PushBlockColour(AciColor colour, EntityObject? obj)
  185. {
  186. _blockColours.Push(BlockColour);
  187. BlockColour = ResolveColour(colour, obj);
  188. }
  189. public void PushBlockColour(Color colour)
  190. {
  191. _blockColours.Push(BlockColour);
  192. BlockColour = colour;
  193. }
  194. public void PopBlockColour()
  195. {
  196. BlockColour = _blockColours.Pop();
  197. }
  198. public Color ResolveColour(AciColor colour, EntityObject? obj)
  199. {
  200. if (colour.IsByBlock)
  201. {
  202. return _blockColours.Count > 0
  203. ? BlockColour
  204. : (obj?.Layer is null ? Color.Black : ResolveColour(obj.Layer.Color, null));
  205. }
  206. else if (colour.IsByLayer)
  207. {
  208. return obj?.Layer is null ? Color.Black : ResolveColour(obj.Layer.Color, null);
  209. }
  210. if(colour.Index == 7)
  211. {
  212. return Color.Black;
  213. }
  214. else
  215. {
  216. return colour.ToColor();
  217. }
  218. }
  219. protected override void UpdateTransform()
  220. {
  221. base.UpdateTransform();
  222. Graphics.SetTransform(ProjectMatrix(Transform));
  223. }
  224. }
  225. public interface IGraphics
  226. {
  227. DrawData DrawData { get; set; }
  228. void SetTransform(Matrix transform);
  229. void DrawLine(Color color, float thickness, params PointF[] points);
  230. void DrawPoint(Color color, float thickness, PointF point);
  231. void FillPolygon(Color color, params PointF[] points);
  232. /// <summary>
  233. /// Set the current font to be the default font at the given <paramref name="fontSize"/>.
  234. /// </summary>
  235. /// <param name="fontSize">Size of the new font.</param>
  236. void SetFont(float fontSize, FontStyle fontStyle = FontStyle.Regular);
  237. void SetFont(string fontName, float fontSize, FontStyle fontStyle = FontStyle.Regular);
  238. void DrawText(string text, Color color, PointF position, float rotation, TextFormat format);
  239. void DrawText(string text, Color color, PointF position, float rotation, float width, PointF scale);
  240. void DrawText(string text, Color color, PointF position, float rotation, SizeF size, PointF scale);
  241. void Clear(Color color);
  242. void Finish();
  243. }
  244. public class GdiGraphics : IGraphics
  245. {
  246. public Graphics Graphics { get; set; }
  247. private Font Font { get; set; }
  248. public DrawData DrawData { get; set; }
  249. public GdiGraphics(Graphics graphics)
  250. {
  251. Graphics = graphics;
  252. }
  253. // public float ConvertThickness(float thickness)
  254. // {
  255. // return thickness == 0 ? 1f / ScaleFactor() : thickness;
  256. // }
  257. public void DrawLine(Color color, float thickness, params PointF[] points)
  258. {
  259. if(points.Length == 2)
  260. {
  261. Graphics.DrawLine(new Pen(color, thickness), points[0], points[1]);
  262. }
  263. else
  264. {
  265. Graphics.DrawLines(new Pen(color, thickness), points);
  266. }
  267. }
  268. public void DrawPoint(Color color, float thickness, PointF point)
  269. {
  270. Graphics.FillEllipse(new SolidBrush(color), point.X - thickness / 2, point.Y - thickness / 2, point.X + thickness / 2, point.Y + thickness / 2);
  271. }
  272. private void TransformTextVertical(string text, Font font, PointF position, float rotation, TextFormat format)
  273. {
  274. DrawData.Translate(position);
  275. DrawData.Rotate(rotation);
  276. DrawData.Scale(1, -1);
  277. var ascentRatio = (float)font.FontFamily.GetCellAscent(font.Style) / font.FontFamily.GetLineSpacing(font.Style);
  278. var size = Graphics.MeasureString(text, font, new PointF(), StringFormat.GenericTypographic);
  279. var scaleFactor = ascentRatio * font.Height / size.Height;
  280. DrawData.Scale(scaleFactor, scaleFactor);
  281. switch (format.LineAlignment)
  282. {
  283. case TextLineAlignment.Center:
  284. DrawData.Translate(new PointF(0, -size.Height / 2));
  285. break;
  286. case TextLineAlignment.Bottom:
  287. DrawData.Translate(new PointF(0, -size.Height));
  288. break;
  289. case TextLineAlignment.Baseline:
  290. var baseline = ascentRatio * font.Height;
  291. DrawData.Translate(new PointF(0, -baseline));
  292. break;
  293. case TextLineAlignment.Top:
  294. baseline = ascentRatio * font.Height;
  295. var lineSpace = font.FontFamily.GetLineSpacing(font.Style);
  296. var ratio = font.GetHeight(Graphics) / lineSpace;
  297. DrawData.Translate(new PointF(0, -baseline + font.FontFamily.GetCellAscent(font.Style) * ratio));
  298. break;
  299. }
  300. }
  301. public void DrawText(string text, Color color, PointF position, float rotation, TextFormat format)
  302. {
  303. if (text.IsNullOrWhiteSpace())
  304. {
  305. return;
  306. }
  307. DrawData.PushTransform();
  308. TransformTextVertical(text, Font, position, rotation, format);
  309. var pos = 0;
  310. foreach(var line in text.Split(new char[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries))
  311. {
  312. DrawData.PushTransform();
  313. DrawData.Translate(0, pos * Font.Height);
  314. var size = Graphics.MeasureString(line, Font);
  315. switch (format.Alignment)
  316. {
  317. case TextAlignment.Left:
  318. break;
  319. case TextAlignment.Center:
  320. DrawData.Translate(new PointF(-(float)size.Width / 2, 0));
  321. break;
  322. case TextAlignment.Right:
  323. DrawData.Translate(new PointF(-(float)size.Width, 0));
  324. break;
  325. }
  326. Graphics.DrawString(line, Font, new SolidBrush(color), new PointF(0, 0), StringFormat.GenericTypographic);
  327. DrawData.PopTransform();
  328. ++pos;
  329. }
  330. DrawData.PopTransform();
  331. }
  332. public void DrawText(string text, Color color, PointF position, float rotation, float width, PointF scale)
  333. {
  334. var size = Graphics.MeasureString(text, Font, new PointF(), StringFormat.GenericTypographic);
  335. DrawText(text, color, position, rotation, new SizeF(width, size.Height * width / size.Width), scale);
  336. }
  337. public void DrawText(string text, Color color, PointF position, float rotation, SizeF size, PointF scale)
  338. {
  339. DrawData.PushTransform();
  340. DrawData.Translate(position);
  341. DrawData.Rotate(rotation);
  342. DrawData.Scale(1, -1);
  343. var (width, height) = (size.Width, size.Height);
  344. DrawData.Translate(width / 2, height / 2);
  345. DrawData.Scale(scale.X, scale.Y);
  346. DrawData.Translate(-width / 2, -height / 2);
  347. DrawData.Scale(width / size.Width, height / size.Height);
  348. Graphics.DrawString(text, Font, new SolidBrush(color), new PointF(0, 0), StringFormat.GenericTypographic);
  349. DrawData.PopTransform();
  350. }
  351. public void FillPolygon(Color color, params PointF[] points)
  352. {
  353. Graphics.FillPolygon(new SolidBrush(color), points);
  354. }
  355. public void SetFont(string fontName, float fontSize, FontStyle fontStyle)
  356. {
  357. var fontFamily = new FontFamily(fontName);
  358. var font = new Font(fontFamily, fontSize, fontStyle);
  359. Font = font;
  360. }
  361. public void SetFont(float fontSize, FontStyle fontStyle)
  362. {
  363. var fontFamily = SystemFonts.DefaultFont.FontFamily;
  364. var font = new Font(fontFamily, fontSize, fontStyle);
  365. Font = font;
  366. }
  367. public void SetTransform(Matrix transform)
  368. {
  369. Graphics.Transform = transform;
  370. }
  371. public void Clear(Color color)
  372. {
  373. Graphics.Clear(color);
  374. }
  375. public void Finish()
  376. {
  377. }
  378. }
  379. public class PdfGraphics : IGraphics
  380. {
  381. public DrawData DrawData { get; set; }
  382. private SPdfGraphics Graphics { get; set; }
  383. private Matrix _transform = new();
  384. private PdfFont _font = new PdfStandardFont(PdfFontFamily.Helvetica, 12, PdfFontStyle.Regular);
  385. private float _ascentRatio = 0;
  386. public PdfGraphics(SPdfGraphics graphics)
  387. {
  388. Graphics = graphics;
  389. }
  390. public void Clear(Color color)
  391. {
  392. }
  393. public void SetTransform(Matrix transform)
  394. {
  395. _transform = transform;
  396. }
  397. public void DrawLine(Color color, float thickness, params PointF[] points)
  398. {
  399. _transform.TransformPoints(points);
  400. var pen = new PdfPen(color, thickness);
  401. for(int i = 0; i < points.Length - 1; ++i)
  402. {
  403. Graphics.DrawLine(pen, points[i], points[i + 1]);
  404. }
  405. }
  406. public void DrawPoint(Color color, float thickness, PointF point)
  407. {
  408. var transformed = _transform.Transform(point);
  409. var brush = new PdfSolidBrush(color);
  410. Graphics.DrawEllipse(brush, transformed.X - thickness / 2, transformed.Y - thickness / 2, transformed.X + thickness / 2, transformed.Y + thickness / 2);
  411. }
  412. public void SetFont(float fontSize, FontStyle fontStyle = FontStyle.Regular)
  413. {
  414. var font = new Font(SystemFonts.DefaultFont.FontFamily, fontSize);
  415. _ascentRatio = (float)font.FontFamily.GetCellAscent(font.Style) / (float)font.FontFamily.GetLineSpacing(font.Style);
  416. _font = new PdfTrueTypeFont(font);
  417. }
  418. public void SetFont(string fontName, float fontSize, FontStyle fontStyle = FontStyle.Regular)
  419. {
  420. var font = new Font(fontName, fontSize);
  421. _ascentRatio = (float)font.FontFamily.GetCellAscent(font.Style) / (float)font.FontFamily.GetLineSpacing(font.Style);
  422. _font = new PdfTrueTypeFont(new Font(fontName, fontSize));
  423. }
  424. public void DrawText(string text, Color color, PointF position, float rotation, TextFormat format)
  425. {
  426. var fmt = new PdfStringFormat();
  427. fmt.Alignment = format.Alignment switch
  428. {
  429. TextAlignment.Center => PdfTextAlignment.Center,
  430. TextAlignment.Right => PdfTextAlignment.Right,
  431. TextAlignment.Justify => PdfTextAlignment.Justify,
  432. _ => PdfTextAlignment.Left,
  433. };
  434. fmt.LineAlignment = format.LineAlignment switch
  435. {
  436. TextLineAlignment.Center => PdfVerticalAlignment.Middle,
  437. TextLineAlignment.Bottom => PdfVerticalAlignment.Bottom,
  438. TextLineAlignment.Baseline => PdfVerticalAlignment.Bottom,
  439. _ => PdfVerticalAlignment.Top
  440. };
  441. if(format.LineAlignment == TextLineAlignment.Baseline)
  442. {
  443. fmt.EnableBaseline = true;
  444. }
  445. Graphics.Save();
  446. var point = _transform.Transform(position);
  447. Graphics.TranslateTransform(point.X, point.Y);
  448. Graphics.RotateTransform(_transform.GetRotation() - rotation);
  449. var scaled = _transform.GetScale();
  450. Graphics.ScaleTransform(scaled / _ascentRatio, scaled / _ascentRatio);
  451. Graphics.DrawString(text, _font, new PdfSolidBrush(color), new PointF(), fmt);
  452. Graphics.Restore();
  453. }
  454. public void DrawText(string text, Color color, PointF position, float rotation, float width, PointF scale)
  455. {
  456. Graphics.Save();
  457. var point = _transform.Transform(position);
  458. Graphics.TranslateTransform(point.X, point.Y);
  459. Graphics.RotateTransform(_transform.GetRotation() - rotation);
  460. var scaleFactor = (_font.Height / _font.Size) * _transform.GetScale();
  461. Graphics.ScaleTransform(scaleFactor, scaleFactor * scale.Y);
  462. if(scale.X != 1)
  463. {
  464. Graphics.TranslateTransform(width / 2, 0);
  465. Graphics.ScaleTransform(scale.X, 1);
  466. Graphics.TranslateTransform(-width / 2, 0);
  467. }
  468. Graphics.DrawString(text, _font, new PdfSolidBrush(color), new RectangleF(0, 0, width, float.MaxValue), new PdfStringFormat
  469. {
  470. Alignment = PdfTextAlignment.Justify,
  471. LineAlignment = PdfVerticalAlignment.Top,
  472. EnableBaseline = true
  473. });
  474. Graphics.Restore();
  475. }
  476. public void DrawText(string text, Color color, PointF position, float rotation, SizeF size, PointF scale)
  477. {
  478. Graphics.Save();
  479. var point = _transform.Transform(position);
  480. Graphics.TranslateTransform(point.X, point.Y);
  481. Graphics.RotateTransform(_transform.GetRotation() - rotation);
  482. var scaleFactor = (_font.Height / _font.Size) * _transform.GetScale();
  483. Graphics.ScaleTransform(scaleFactor, scaleFactor * scale.Y);
  484. if(scale.X != 1 || scale.Y != 1)
  485. {
  486. Graphics.TranslateTransform(size.Width / 2, size.Height / 2);
  487. Graphics.ScaleTransform(scale.X, 1);
  488. Graphics.TranslateTransform(-size.Width / 2, size.Height / 2);
  489. }
  490. Graphics.DrawString(text, _font, new PdfSolidBrush(color), new RectangleF(0, 0, size.Width, size.Height), new PdfStringFormat
  491. {
  492. Alignment = PdfTextAlignment.Justify,
  493. LineAlignment = PdfVerticalAlignment.Top,
  494. EnableBaseline = true
  495. });
  496. Graphics.Restore();
  497. }
  498. public void FillPolygon(Color color, params PointF[] points)
  499. {
  500. _transform.TransformPoints(points);
  501. var brush = new PdfSolidBrush(color);
  502. Graphics.DrawPolygon(brush, points);
  503. }
  504. public void Finish()
  505. {
  506. }
  507. }
  508. public class SvgGraphics : IGraphics
  509. {
  510. public DrawData DrawData { get; set; }
  511. public SvgDocument Document { get; set; }
  512. private SvgMatrix _transform = new(new Matrix().Elements.ToList());
  513. private SvgGroup _group;
  514. private Matrix _groupTransform = new();
  515. private static string[][] _groupProps = new[]
  516. {
  517. new[] { "stroke-width", "style" },
  518. new[] { "vector-effect" }
  519. };
  520. public SvgGraphics(SvgDocument document)
  521. {
  522. Document = document;
  523. _group = new SvgGroup();
  524. Document.Stroke = new SvgColourServer(Color.Black);
  525. }
  526. private void PushGroup()
  527. {
  528. if(_group.Children.Count > 0)
  529. {
  530. Document.Children.Add(_group);
  531. }
  532. }
  533. private void AddChild(SvgElement item)
  534. {
  535. var transMat = _transform.Matrix;
  536. if(!Equals(transMat, _groupTransform))
  537. {
  538. PushGroup();
  539. _group = new();
  540. _group.Transforms = new() { _transform };
  541. _groupTransform = transMat;
  542. }
  543. _group.Children.Add(item);
  544. }
  545. public void SetTransform(Matrix transform)
  546. {
  547. _transform = new(transform.Elements.ToList());
  548. }
  549. public void DrawLine(Color color, float thickness, params PointF[] points)
  550. {
  551. if(points.Length == 2)
  552. {
  553. var line = new SvgLine
  554. {
  555. StartX = points[0].X,
  556. StartY = points[0].Y,
  557. EndX = points[1].X,
  558. EndY = points[1].Y
  559. };
  560. if(color != Color.Black)
  561. {
  562. line.Stroke = new SvgColourServer(color);
  563. }
  564. if(thickness == 0)
  565. {
  566. line.StrokeWidth = 1;
  567. line.CustomAttributes.Add("vector-effect", "non-scaling-stroke");
  568. }
  569. else
  570. {
  571. line.StrokeWidth = thickness;
  572. }
  573. AddChild(line);
  574. }
  575. else
  576. {
  577. var line = new SvgPolyline();
  578. if(color != Color.Black)
  579. {
  580. line.Stroke = new SvgColourServer(color);
  581. }
  582. foreach(var point in points)
  583. {
  584. line.Points.Add(point.X);
  585. line.Points.Add(point.Y);
  586. }
  587. if(thickness == 0)
  588. {
  589. line.StrokeWidth = 1;
  590. line.CustomAttributes.Add("vector-effect", "non-scaling-stroke");
  591. }
  592. else
  593. {
  594. line.StrokeWidth = thickness;
  595. }
  596. AddChild(line);
  597. }
  598. }
  599. public void DrawPoint(Color color, float thickness, PointF point)
  600. {
  601. }
  602. public void FillPolygon(Color color, params PointF[] points)
  603. {
  604. }
  605. public void SetFont(float fontSize, FontStyle fontStyle = FontStyle.Regular)
  606. {
  607. }
  608. public void SetFont(string fontName, float fontSize, FontStyle fontStyle = FontStyle.Regular)
  609. {
  610. }
  611. public void DrawText(string text, Color color, PointF position, float rotation, TextFormat format)
  612. {
  613. }
  614. public void Clear(Color color)
  615. {
  616. }
  617. public void Finish()
  618. {
  619. PushGroup();
  620. }
  621. public void DrawText(string text, Color color, PointF position, float rotation, float width, PointF scale)
  622. {
  623. }
  624. public void DrawText(string text, Color color, PointF position, float rotation, SizeF size, PointF scale)
  625. {
  626. }
  627. }