SvgDc.cs 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. namespace WMFConverter.Svg
  7. {
  8. /// <summary>
  9. /// Scalable Vector Graphics - Represents SVG document.
  10. /// </summary>
  11. public class SvgDc : ICloneable
  12. {
  13. #region Local Variables
  14. private SvgGdi _gdi;
  15. private int _dpi = 1440;
  16. // window
  17. private int _wx = 0;
  18. private int _wy = 0;
  19. private int _ww = 0;
  20. private int _wh = 0;
  21. // window offset
  22. private int _wox = 0;
  23. private int _woy = 0;
  24. // window scale
  25. private double _wsx = 1.0;
  26. private double _wsy = 1.0;
  27. // mapping scale
  28. private double _mx = 1.0;
  29. private double _my = 1.0;
  30. // viewport
  31. private int _vx = 0;
  32. private int _vy = 0;
  33. private int _vw = 0;
  34. private int _vh = 0;
  35. // viewport offset
  36. private int _vox = 0;
  37. private int _voy = 0;
  38. // viewport scale
  39. private double _vsx = 1.0;
  40. private double _vsy = 1.0;
  41. // current location
  42. private int _cx = 0;
  43. private int _cy = 0;
  44. // clip offset
  45. private int _cox = 0;
  46. private int _coy = 0;
  47. private int _mapMode = (int)Gdi.GdiEnum.MM_TEXT;
  48. private int _bkColor = 0x00FFFFFF;
  49. private int _bkMode = (int)Gdi.GdiEnum.OPAQUE;
  50. private int _textColor = 0x00000000;
  51. private int _textSpace = 0;
  52. private int _textAlign = (int)Gdi.GdiEnum.TA_TOP | (int)Gdi.GdiEnum.TA_LEFT;
  53. private int _textDx = 0;
  54. private int _polyFillMode = (int)Gdi.GdiEnum.ALTERNATE;
  55. private int _relAbsMode = 0;
  56. private int _rop2Mode = (int)Gdi.GdiEnum.R2_COPYPEN;
  57. private int _stretchBltMode = (int)Gdi.GdiEnum.STRETCH_ANDSCANS;
  58. private long _layout = 0;
  59. private long _mapperFlags = 0;
  60. private SvgBrush _brush = null;
  61. private SvgFont _font = null;
  62. private SvgPen _pen = null;
  63. private System.Xml.XmlElement _mask = null;
  64. #endregion
  65. #region Properties
  66. /// <summary>
  67. /// Background color.
  68. /// </summary>
  69. public int BkColor
  70. {
  71. get
  72. {
  73. return _bkColor;
  74. }
  75. set
  76. {
  77. _bkColor = value;
  78. }
  79. }
  80. /// <summary>
  81. /// Background mode.
  82. /// </summary>
  83. public int BkMode
  84. {
  85. get
  86. {
  87. return _bkMode;
  88. }
  89. set
  90. {
  91. _bkColor = value;
  92. }
  93. }
  94. /// <summary>
  95. /// Text color.
  96. /// </summary>
  97. public int TextColor
  98. {
  99. get
  100. {
  101. return _textColor;
  102. }
  103. set
  104. {
  105. _textColor = value;
  106. }
  107. }
  108. /// <summary>
  109. ///
  110. /// </summary>
  111. public int PolyFillMode
  112. {
  113. get
  114. {
  115. return _polyFillMode;
  116. }
  117. set
  118. {
  119. _polyFillMode = value;
  120. }
  121. }
  122. /// <summary>
  123. ///
  124. /// </summary>
  125. public int RelAbs
  126. {
  127. get
  128. {
  129. return _relAbsMode;
  130. }
  131. set
  132. {
  133. _relAbsMode = value;
  134. }
  135. }
  136. /// <summary>
  137. ///
  138. /// </summary>
  139. public int ROP2
  140. {
  141. get
  142. {
  143. return _rop2Mode;
  144. }
  145. set
  146. {
  147. _rop2Mode = value;
  148. }
  149. }
  150. /// <summary>
  151. ///
  152. /// </summary>
  153. public int StretchBltMode
  154. {
  155. get
  156. {
  157. return _stretchBltMode;
  158. }
  159. set
  160. {
  161. _stretchBltMode = value;
  162. }
  163. }
  164. /// <summary>
  165. ///
  166. /// </summary>
  167. public int TextSpace
  168. {
  169. get
  170. {
  171. return _textSpace;
  172. }
  173. set
  174. {
  175. _textSpace = value;
  176. }
  177. }
  178. /// <summary>
  179. /// Text align.
  180. /// </summary>
  181. public int TextAlign
  182. {
  183. get
  184. {
  185. return _textAlign;
  186. }
  187. set
  188. {
  189. _textAlign = value;
  190. }
  191. }
  192. /// <summary>
  193. ///
  194. /// </summary>
  195. public int TextCharacterExtra
  196. {
  197. get
  198. {
  199. return _textDx;
  200. }
  201. set
  202. {
  203. _textDx = value;
  204. }
  205. }
  206. /// <summary>
  207. ///
  208. /// </summary>
  209. public long Layout
  210. {
  211. get
  212. {
  213. return _layout;
  214. }
  215. set
  216. {
  217. _layout = value;
  218. }
  219. }
  220. /// <summary>
  221. ///
  222. /// </summary>
  223. public long MapperFlags
  224. {
  225. get
  226. {
  227. return _mapperFlags;
  228. }
  229. set
  230. {
  231. _mapperFlags = value;
  232. }
  233. }
  234. /// <summary>
  235. /// Brush instance.
  236. /// </summary>
  237. public SvgBrush Brush
  238. {
  239. get
  240. {
  241. return _brush;
  242. }
  243. set
  244. {
  245. _brush = value;
  246. }
  247. }
  248. /// <summary>
  249. /// Font instance.
  250. /// </summary>
  251. public SvgFont Font
  252. {
  253. get
  254. {
  255. return _font;
  256. }
  257. set
  258. {
  259. _font = value;
  260. }
  261. }
  262. /// <summary>
  263. /// Pen instance.
  264. /// </summary>
  265. public SvgPen Pen
  266. {
  267. get
  268. {
  269. return _pen;
  270. }
  271. set
  272. {
  273. _pen = value;
  274. }
  275. }
  276. /// <summary>
  277. ///
  278. /// </summary>
  279. public System.Xml.XmlElement Mask
  280. {
  281. get
  282. {
  283. return _mask;
  284. }
  285. set
  286. {
  287. _mask = value;
  288. }
  289. }
  290. /// <summary>
  291. /// Current X Point.
  292. /// </summary>
  293. public int CurrentX
  294. {
  295. get
  296. {
  297. return _cx;
  298. }
  299. }
  300. /// <summary>
  301. /// Current Y Point.
  302. /// </summary>
  303. public int CurrentY
  304. {
  305. get
  306. {
  307. return _cy;
  308. }
  309. }
  310. /// <summary>
  311. ///
  312. /// </summary>
  313. public int OffsetClipX
  314. {
  315. get
  316. {
  317. return _cox;
  318. }
  319. }
  320. /// <summary>
  321. ///
  322. /// </summary>
  323. public int OffsetClipY
  324. {
  325. get
  326. {
  327. return _coy;
  328. }
  329. }
  330. /// <summary>
  331. ///
  332. /// </summary>
  333. public int MapMode
  334. {
  335. get
  336. {
  337. return _mapMode;
  338. }
  339. }
  340. /// <summary>
  341. ///
  342. /// </summary>
  343. public int Dpi
  344. {
  345. get
  346. {
  347. return _dpi;
  348. }
  349. }
  350. /// <summary>
  351. ///
  352. /// </summary>
  353. public int WindowX
  354. {
  355. get
  356. {
  357. return _wx;
  358. }
  359. }
  360. /// <summary>
  361. ///
  362. /// </summary>
  363. public int WindowY
  364. {
  365. get
  366. {
  367. return _wy;
  368. }
  369. }
  370. /// <summary>
  371. /// Represents window width.
  372. /// </summary>
  373. public int WindowWidth
  374. {
  375. get
  376. {
  377. return _ww;
  378. }
  379. }
  380. /// <summary>
  381. /// Represents window height.
  382. /// </summary>
  383. public int WindowHeight
  384. {
  385. get
  386. {
  387. return _wh;
  388. }
  389. }
  390. #endregion
  391. #region Constructors
  392. /// <summary>
  393. /// Default Constructor.
  394. /// </summary>
  395. /// <param name="gdi"></param>
  396. public SvgDc(SvgGdi gdi)
  397. {
  398. _gdi = gdi;
  399. }
  400. #endregion
  401. #region Public Methods
  402. /// <summary>
  403. /// Specifies which window point maps to the viewport origin (0,0).
  404. /// </summary>
  405. /// <param name="x"></param>
  406. /// <param name="y"></param>
  407. /// <param name="old"></param>
  408. public void SetWindowOrgEx(int x, int y, WMFConverter.Gdi.Point old)
  409. {
  410. if (old != null)
  411. {
  412. old.X = _wx;
  413. old.Y = _wy;
  414. }
  415. _wx = x;
  416. _wy = y;
  417. }
  418. /// <summary>
  419. /// Sets the horizontal and vertical extents of the window for a device context by using the specified values.
  420. /// </summary>
  421. /// <param name="width"></param>
  422. /// <param name="height"></param>
  423. /// <param name="old"></param>
  424. public void SetWindowExtEx(int width, int height, WMFConverter.Gdi.Size old)
  425. {
  426. if (old != null)
  427. {
  428. old.Width = _ww;
  429. old.Height = _wh;
  430. }
  431. _ww = width;
  432. _wh = height;
  433. }
  434. /// <summary>
  435. /// Modifies the window origin for a device context using the specified horizontal and vertical offsets.
  436. /// </summary>
  437. /// <param name="x"></param>
  438. /// <param name="y"></param>
  439. /// <param name="old"></param>
  440. public void OffSetWindowOrgEx(int x, int y, WMFConverter.Gdi.Point old)
  441. {
  442. if (old != null)
  443. {
  444. old.X = _wox;
  445. old.Y = _woy;
  446. }
  447. _wox += x;
  448. _woy += y;
  449. }
  450. /// <summary>
  451. /// Modifies the window for a device context using the ratios formed by the specified multiplicands and divisors.
  452. /// </summary>
  453. /// <param name="x"></param>
  454. /// <param name="xd"></param>
  455. /// <param name="y"></param>
  456. /// <param name="yd"></param>
  457. /// <param name="old"></param>
  458. public void ScaleWindowExtEx(int x, int xd, int y, int yd, WMFConverter.Gdi.Size old)
  459. {
  460. // TODO
  461. _wsx = (_wsx * x) / xd;
  462. _wsy = (_wsy * y) / yd;
  463. }
  464. /// <summary>
  465. /// Specifies which device point maps to the window origin (0,0).
  466. /// </summary>
  467. /// <param name="x"></param>
  468. /// <param name="y"></param>
  469. /// <param name="old"></param>
  470. public void SetViewportOrgEx(int x, int y, WMFConverter.Gdi.Point old)
  471. {
  472. if (old != null)
  473. {
  474. old.X = _vx;
  475. old.Y = _vy;
  476. }
  477. _vx = x;
  478. _vy = y;
  479. }
  480. /// <summary>
  481. /// Sets the horizontal and vertical extents of the viewport for a device context by using the specified values.
  482. /// </summary>
  483. /// <param name="width"></param>
  484. /// <param name="height"></param>
  485. /// <param name="old"></param>
  486. public void SetViewportExtEx(int width, int height, WMFConverter.Gdi.Size old)
  487. {
  488. if (old != null)
  489. {
  490. old.Width = _vw;
  491. old.Height = _vh;
  492. }
  493. _vw = width;
  494. _vh = height;
  495. }
  496. /// <summary>
  497. /// Modifies the viewport origin for a device context using the specified horizontal and vertical offsets.
  498. /// </summary>
  499. /// <param name="x"></param>
  500. /// <param name="y"></param>
  501. /// <param name="old"></param>
  502. public void OffSetViewportOrgEx(int x, int y, WMFConverter.Gdi.Point old)
  503. {
  504. if (old != null)
  505. {
  506. old.X = _vox;
  507. old.Y = _voy;
  508. }
  509. _vox = x;
  510. _voy = y;
  511. }
  512. /// <summary>
  513. /// Modifies the viewport for a device context using the ratios formed by the specified multiplicands and divisors.
  514. /// </summary>
  515. /// <param name="x"></param>
  516. /// <param name="xd"></param>
  517. /// <param name="y"></param>
  518. /// <param name="yd"></param>
  519. /// <param name="old"></param>
  520. public void ScaleViewportExtEx(int x, int xd, int y, int yd, WMFConverter.Gdi.Size old)
  521. {
  522. // TODO
  523. _vsx = (_vsx * x) / xd;
  524. _vsy = (_vsy * y) / yd;
  525. }
  526. /// <summary>
  527. /// Moves the clipping region of a device context by the specified offsets.
  528. /// </summary>
  529. /// <param name="x"></param>
  530. /// <param name="y"></param>
  531. public void OffSetClipRgn(int x, int y)
  532. {
  533. _cox = x;
  534. _coy = y;
  535. }
  536. /// <summary>
  537. /// Sets the mapping mode of the specified device context.
  538. /// The mapping mode defines the unit of measure used to transform page-space units into device-space units, and also defines the orientation of the device's x and y axes.
  539. /// </summary>
  540. /// <param name="mode"></param>
  541. public void SetMapMode(int mode)
  542. {
  543. _mapMode = mode;
  544. switch (mode)
  545. {
  546. case (int)Gdi.GdiEnum.MM_HIENGLISH:
  547. _mx = 0.09;
  548. _my = -0.09;
  549. break;
  550. case (int)Gdi.GdiEnum.MM_LOENGLISH:
  551. _mx = 0.9;
  552. _my = -0.9;
  553. break;
  554. case (int)Gdi.GdiEnum.MM_HIMETRIC:
  555. _mx = 0.03543307;
  556. _my = -0.03543307;
  557. break;
  558. case (int)Gdi.GdiEnum.MM_LOMETRIC:
  559. _mx = 0.3543307;
  560. _my = -0.3543307;
  561. break;
  562. case (int)Gdi.GdiEnum.MM_TWIPS:
  563. _mx = 0.0625;
  564. _my = -0.0625;
  565. break;
  566. default:
  567. _mx = 1.0;
  568. _my = 1.0;
  569. break;
  570. }
  571. }
  572. /// <summary>
  573. /// Updates the current position to the specified point and optionally returns the previous position.
  574. /// </summary>
  575. /// <param name="x"></param>
  576. /// <param name="y"></param>
  577. /// <param name="old"></param>
  578. public void MoveToEx(int x, int y, WMFConverter.Gdi.Point old)
  579. {
  580. if (old != null)
  581. {
  582. old.X = _cx;
  583. old.Y = _cy;
  584. }
  585. _cx = x;
  586. _cy = y;
  587. }
  588. /// <summary>
  589. /// Return the absolute X position from x point.
  590. /// </summary>
  591. /// <param name="x"></param>
  592. /// <returns></returns>
  593. public double ToAbsoluteX(double x)
  594. {
  595. // TODO Handle Viewport
  596. return ((_ww >= 0) ? 1 : -1) * (_mx * x - (_wx + _wox)) / _wsx;
  597. }
  598. /// <summary>
  599. /// Return the absolute Y position from y point.
  600. /// </summary>
  601. /// <param name="y"></param>
  602. /// <returns></returns>
  603. public double ToAbsoluteY(double y)
  604. {
  605. // TODO Handle Viewport
  606. return ((_wh >= 0) ? 1 : -1) * (_my * y - (_wy + _woy)) / _wsy;
  607. }
  608. /// <summary>
  609. /// Return the relative X position from x point.
  610. /// </summary>
  611. /// <param name="x"></param>
  612. /// <returns></returns>
  613. public double ToRelativeX(double x)
  614. {
  615. // TODO Handle Viewport
  616. return ((_ww >= 0) ? 1 : -1) * (_mx * x) / _wsx;
  617. }
  618. /// <summary>
  619. /// Return the relative Y position from y point.
  620. /// </summary>
  621. /// <param name="y"></param>
  622. /// <returns></returns>
  623. public double ToRelativeY(double y)
  624. {
  625. // TODO Handle Viewport
  626. return ((_wh >= 0) ? 1 : -1) * (_my * y) / _wsy;
  627. }
  628. /// <summary>
  629. /// Define Dpi value
  630. /// </summary>
  631. /// <param name="dpi"></param>
  632. public void SetDpi(int dpi)
  633. {
  634. _dpi = (dpi > 0) ? dpi : 1440;
  635. }
  636. /// <summary>
  637. ///
  638. /// </summary>
  639. /// <param name="rop"></param>
  640. /// <returns></returns>
  641. public string GetRopFilter(long rop)
  642. {
  643. string name = null;
  644. System.Xml.XmlDocument doc = _gdi.Document;
  645. if (rop == (int)Gdi.GdiEnum.BLACKNESS)
  646. {
  647. name = "BLACKNESS_FILTER";
  648. System.Xml.XmlElement filter = doc.GetElementById(name);
  649. if (filter == null)
  650. {
  651. filter = _gdi.Document.CreateElement("filter");
  652. filter.SetAttribute("id", name);
  653. //filter.setIdAttribute("id", true);
  654. System.Xml.XmlElement feColorMatrix = doc.CreateElement("feColorMatrix");
  655. feColorMatrix.SetAttribute("type", "matrix");
  656. feColorMatrix.SetAttribute("in", "SourceGraphic");
  657. feColorMatrix.SetAttribute("values", "0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0");
  658. filter.AppendChild(feColorMatrix);
  659. _gdi.DefsElement.AppendChild(filter);
  660. }
  661. }
  662. else if (rop == (int)Gdi.GdiEnum.NOTSRCERASE)
  663. {
  664. name = "NOTSRCERASE_FILTER";
  665. System.Xml.XmlElement filter = doc.GetElementById(name);
  666. if (filter == null)
  667. {
  668. filter = _gdi.Document.CreateElement("filter");
  669. filter.SetAttribute("id", name);
  670. //filter.setIdAttribute("id", true);
  671. System.Xml.XmlElement feComposite = doc.CreateElement("feComposite");
  672. feComposite.SetAttribute("in", "SourceGraphic");
  673. feComposite.SetAttribute("in2", "BackgroundImage");
  674. feComposite.SetAttribute("operator", "arithmetic");
  675. feComposite.SetAttribute("k1", "1");
  676. feComposite.SetAttribute("result", "result0");
  677. filter.AppendChild(feComposite);
  678. System.Xml.XmlElement feColorMatrix = doc.CreateElement("feColorMatrix");
  679. feColorMatrix.SetAttribute("in", "result0");
  680. feColorMatrix.SetAttribute("values", "-1 0 0 0 1 0 -1 0 0 1 0 0 -1 0 1 0 0 0 1 0");
  681. filter.AppendChild(feColorMatrix);
  682. _gdi.DefsElement.AppendChild(filter);
  683. }
  684. }
  685. else if (rop == (int)Gdi.GdiEnum.NOTSRCCOPY)
  686. {
  687. name = "NOTSRCCOPY_FILTER";
  688. System.Xml.XmlElement filter = doc.GetElementById(name);
  689. if (filter == null)
  690. {
  691. filter = _gdi.Document.CreateElement("filter");
  692. filter.SetAttribute("id", name);
  693. //filter.setIdAttribute("id", true);
  694. System.Xml.XmlElement feColorMatrix = doc.CreateElement("feColorMatrix");
  695. feColorMatrix.SetAttribute("type", "matrix");
  696. feColorMatrix.SetAttribute("in", "SourceGraphic");
  697. feColorMatrix.SetAttribute("values", "-1 0 0 0 1 0 -1 0 0 1 0 0 -1 0 1 0 0 0 1 0");
  698. filter.AppendChild(feColorMatrix);
  699. _gdi.DefsElement.AppendChild(filter);
  700. }
  701. }
  702. else if (rop == (int)Gdi.GdiEnum.SRCERASE)
  703. {
  704. name = "SRCERASE_FILTER";
  705. System.Xml.XmlElement filter = doc.GetElementById(name);
  706. if (filter == null)
  707. {
  708. filter = _gdi.Document.CreateElement("filter");
  709. filter.SetAttribute("id", name);
  710. //filter.setIdAttribute("id", true);
  711. System.Xml.XmlElement feColorMatrix = doc.CreateElement("feColorMatrix");
  712. feColorMatrix.SetAttribute("type", "matrix");
  713. feColorMatrix.SetAttribute("in", "BackgroundImage");
  714. feColorMatrix.SetAttribute("values", "-1 0 0 0 1 0 -1 0 0 1 0 0 -1 0 1 0 0 0 1 0");
  715. feColorMatrix.SetAttribute("result", "result0");
  716. filter.AppendChild(feColorMatrix);
  717. System.Xml.XmlElement feComposite = doc.CreateElement("feComposite");
  718. feComposite.SetAttribute("in", "SourceGraphic");
  719. feComposite.SetAttribute("in2", "result0");
  720. feComposite.SetAttribute("operator", "arithmetic");
  721. feComposite.SetAttribute("k2", "1");
  722. feComposite.SetAttribute("k3", "1");
  723. filter.AppendChild(feComposite);
  724. _gdi.DefsElement.AppendChild(filter);
  725. }
  726. }
  727. else if (rop == (int)Gdi.GdiEnum.PATINVERT)
  728. {
  729. // TODO
  730. }
  731. else if (rop == (int)Gdi.GdiEnum.SRCINVERT)
  732. {
  733. // TODO
  734. }
  735. else if (rop == (int)Gdi.GdiEnum.DSTINVERT)
  736. {
  737. name = "DSTINVERT_FILTER";
  738. System.Xml.XmlElement filter = doc.GetElementById(name);
  739. if (filter == null)
  740. {
  741. filter = _gdi.Document.CreateElement("filter");
  742. filter.SetAttribute("id", name);
  743. //filter.SetIdAttribute("id", true);
  744. System.Xml.XmlElement feColorMatrix = doc.CreateElement("feColorMatrix");
  745. feColorMatrix.SetAttribute("type", "matrix");
  746. feColorMatrix.SetAttribute("in", "BackgroundImage");
  747. feColorMatrix.SetAttribute("values", "-1 0 0 0 1 0 -1 0 0 1 0 0 -1 0 1 0 0 0 1 0");
  748. filter.AppendChild(feColorMatrix);
  749. _gdi.DefsElement.AppendChild(filter);
  750. }
  751. }
  752. else if (rop == (int)Gdi.GdiEnum.SRCAND)
  753. {
  754. name = "SRCAND_FILTER";
  755. System.Xml.XmlElement filter = doc.GetElementById(name);
  756. if (filter == null)
  757. {
  758. filter = _gdi.Document.CreateElement("filter");
  759. filter.SetAttribute("id", name);
  760. //filter.setIdAttribute("id", true);
  761. System.Xml.XmlElement feComposite = doc.CreateElement("feComposite");
  762. feComposite.SetAttribute("in", "SourceGraphic");
  763. feComposite.SetAttribute("in2", "BackgroundImage");
  764. feComposite.SetAttribute("operator", "arithmetic");
  765. feComposite.SetAttribute("k1", "1");
  766. filter.AppendChild(feComposite);
  767. _gdi.DefsElement.AppendChild(filter);
  768. }
  769. }
  770. else if (rop == (int)Gdi.GdiEnum.MERGEPAINT)
  771. {
  772. name = "MERGEPAINT_FILTER";
  773. System.Xml.XmlElement filter = doc.GetElementById(name);
  774. if (filter == null)
  775. {
  776. filter = _gdi.Document.CreateElement("filter");
  777. filter.SetAttribute("id", name);
  778. //filter.setIdAttribute("id", true);
  779. System.Xml.XmlElement feColorMatrix = doc.CreateElement("feColorMatrix");
  780. feColorMatrix.SetAttribute("type", "matrix");
  781. feColorMatrix.SetAttribute("in", "SourceGraphic");
  782. feColorMatrix.SetAttribute("values", "-1 0 0 0 1 0 -1 0 0 1 0 0 -1 0 1 0 0 0 1 0");
  783. feColorMatrix.SetAttribute("result", "result0");
  784. filter.AppendChild(feColorMatrix);
  785. System.Xml.XmlElement feComposite = doc.CreateElement("feComposite");
  786. feComposite.SetAttribute("in", "result0");
  787. feComposite.SetAttribute("in2", "BackgroundImage");
  788. feComposite.SetAttribute("operator", "arithmetic");
  789. feComposite.SetAttribute("k1", "1");
  790. filter.AppendChild(feComposite);
  791. _gdi.DefsElement.AppendChild(filter);
  792. }
  793. }
  794. else if (rop == (int)Gdi.GdiEnum.MERGECOPY)
  795. {
  796. // TODO
  797. }
  798. else if (rop == (int)Gdi.GdiEnum.SRCPAINT)
  799. {
  800. name = "SRCPAINT_FILTER";
  801. System.Xml.XmlElement filter = doc.GetElementById(name);
  802. if (filter == null)
  803. {
  804. filter = _gdi.Document.CreateElement("filter");
  805. filter.SetAttribute("id", name);
  806. //filter.setIdAttribute("id", true);
  807. System.Xml.XmlElement feComposite = doc.CreateElement("feComposite");
  808. feComposite.SetAttribute("in", "SourceGraphic");
  809. feComposite.SetAttribute("in2", "BackgroundImage");
  810. feComposite.SetAttribute("operator", "arithmetic");
  811. feComposite.SetAttribute("k2", "1");
  812. feComposite.SetAttribute("k3", "1");
  813. filter.AppendChild(feComposite);
  814. _gdi.DefsElement.AppendChild(filter);
  815. }
  816. }
  817. else if (rop == (int)Gdi.GdiEnum.PATCOPY)
  818. {
  819. // TODO
  820. }
  821. else if (rop == (int)Gdi.GdiEnum.PATPAINT)
  822. {
  823. // TODO
  824. }
  825. else if (rop == (int)Gdi.GdiEnum.WHITENESS)
  826. {
  827. name = "WHITENESS_FILTER";
  828. System.Xml.XmlElement filter = doc.GetElementById(name);
  829. if (filter == null)
  830. {
  831. filter = _gdi.Document.CreateElement("filter");
  832. filter.SetAttribute("id", name);
  833. //filter.SetIdAttribute("id", true);
  834. System.Xml.XmlElement feColorMatrix = doc.CreateElement("feColorMatrix");
  835. feColorMatrix.SetAttribute("type", "matrix");
  836. feColorMatrix.SetAttribute("in", "SourceGraphic");
  837. feColorMatrix.SetAttribute("values", "1 0 0 0 1 0 1 0 0 1 0 0 1 0 1 0 0 0 1 0");
  838. filter.AppendChild(feColorMatrix);
  839. _gdi.DefsElement.AppendChild(filter);
  840. }
  841. }
  842. if (name != null)
  843. {
  844. if (!doc.DocumentElement.HasAttribute("enable-background"))
  845. {
  846. doc.DocumentElement.SetAttribute("enable-background", "new");
  847. }
  848. return "url(#" + name + ")";
  849. }
  850. return null;
  851. }
  852. /// <summary>
  853. /// Clone this object.
  854. /// </summary>
  855. /// <returns></returns>
  856. public object Clone()
  857. {
  858. return this.Clone();
  859. }
  860. /// <summary>
  861. /// Returns a string that represents the current object.
  862. /// </summary>
  863. /// <returns></returns>
  864. public override string ToString()
  865. {
  866. return "SvgDc [gdi=" + _gdi + ", dpi=" + _dpi + ", wx=" + _wx + ", wy="
  867. + _wy + ", ww=" + _ww + ", wh=" + _wh + ", wox=" + _wox + ", woy="
  868. + _woy + ", wsx=" + _wsx + ", wsy=" + _wsy + ", mx=" + _mx
  869. + ", my=" + _my + ", vx=" + _vx + ", vy=" + _vy + ", vw=" + _vw
  870. + ", vh=" + _vh + ", vox=" + _vox + ", voy=" + _voy + ", vsx="
  871. + _vsx + ", vsy=" + _vsy + ", cx=" + _cx + ", cy=" + _cy
  872. + ", mapMode=" + _mapMode + ", bkColor=" + _bkColor + ", bkMode="
  873. + _bkMode + ", textColor=" + _textColor + ", textSpace="
  874. + _textSpace + ", textAlign=" + _textAlign + ", textDx=" + _textDx
  875. + ", polyFillMode=" + _polyFillMode + ", relAbsMode="
  876. + _relAbsMode + ", rop2Mode=" + _rop2Mode + ", stretchBltMode="
  877. + _stretchBltMode + ", brush=" + _brush + ", font=" + _font
  878. + ", pen=" + _pen + "]";
  879. }
  880. #endregion
  881. }
  882. }