fpvwritetest.pas 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. {
  2. FPVectorial example application for writing vectorial images
  3. generated in code to disk. This program will generate the following
  4. vectorial images:
  5. single_line_1 One line from (0, 20) to (30, 30)
  6. single_line_2 One line from (20, 30) to (30, 20)
  7. polyline_1 One line from (0, 0) to (10, 10) to (20, 30) to (30, 20)
  8. polyline_2 One line from (10, 10) to (20, 30) to (30, 20) to (40, 40)
  9. bezier_1 One path starting in (0, 0) lining to (10, 10) then bezier to (20, 10) and then line to (30, 0)
  10. bezier_2 One curve from (10, 10) to (20, 20)
  11. text_ascii One text written at (10, 10)
  12. text_europen One text testing european languages at (20, 20)
  13. text_asian One text testing asian languages at (30, 30)
  14. Author: Felipe Monteiro de Carvalho
  15. License: Public Domain
  16. }
  17. program fpvwritetest;
  18. {$mode objfpc}{$H+}
  19. uses
  20. fpvectorial, svgvectorialwriter, fpvutils;
  21. const
  22. cFormat = vfSVG;
  23. cExtension = '.svg';
  24. var
  25. Vec: TvVectorialDocument;
  26. {$R *.res}
  27. begin
  28. Vec := TvVectorialDocument.Create;
  29. try
  30. // All documents are 10cm x 10cm
  31. Vec.Width := 100;
  32. Vec.Height := 100;
  33. // single_line_1 One line from (0, 20) to (30, 30)
  34. Vec.StartPath(0, 20);
  35. Vec.AddLineToPath(30, 30);
  36. Vec.EndPath();
  37. Vec.WriteToFile('single_line_1' + cExtension, cFormat);
  38. // single_line_2 One line from (20, 30) to (30, 20)
  39. Vec.Clear;
  40. Vec.StartPath(20, 30);
  41. Vec.AddLineToPath(30, 20);
  42. Vec.EndPath();
  43. Vec.WriteToFile('single_line_2' + cExtension, cFormat);
  44. // single_line_3 One line from (0, 20) to (30, 30) + frame
  45. Vec.Clear;
  46. Vec.StartPath(0, 20);
  47. Vec.AddLineToPath(30, 30);
  48. Vec.EndPath();
  49. Vec.StartPath(0, 0);
  50. Vec.AddLineToPath(100, 0);
  51. Vec.AddLineToPath(100, 100);
  52. Vec.AddLineToPath(0, 100);
  53. Vec.AddLineToPath(0, 0);
  54. Vec.EndPath();
  55. Vec.WriteToFile('single_line_3' + cExtension, cFormat);
  56. // polyline_1 One line from (0, 0) to (10, 10) to (20, 30) to (30, 20)
  57. Vec.Clear;
  58. Vec.StartPath(0, 0);
  59. Vec.AddLineToPath(10, 10);
  60. Vec.AddLineToPath(20, 30);
  61. Vec.AddLineToPath(30, 20);
  62. Vec.EndPath();
  63. Vec.WriteToFile('polyline_1' + cExtension, cFormat);
  64. // polyline_2 One line from (10, 10) to (20, 30) to (30, 20) to (40, 40)
  65. Vec.Clear;
  66. Vec.StartPath(10, 10);
  67. Vec.AddLineToPath(20, 30);
  68. Vec.AddLineToPath(30, 20);
  69. Vec.AddLineToPath(40, 40);
  70. Vec.EndPath();
  71. Vec.WriteToFile('polyline_2' + cExtension, cFormat);
  72. // bezier_1 One path starting in (0, 0) lining to (10, 10) then bezier to (20, 10) and then line to (30, 0)
  73. Vec.Clear;
  74. Vec.StartPath(0, 0);
  75. Vec.AddLineToPath(10, 10);
  76. Vec.AddBezierToPath(10, 20, 20, 20, 20, 10);
  77. Vec.AddLineToPath(30, 0);
  78. Vec.EndPath();
  79. Vec.WriteToFile('bezier_1' + cExtension, cFormat);
  80. // bezier_2 One curve from (10, 10) to (20, 20)
  81. Vec.Clear;
  82. Vec.StartPath(10, 10);
  83. Vec.AddBezierToPath(10, 15, 15, 20, 20, 10);
  84. Vec.EndPath();
  85. Vec.WriteToFile('bezier_2' + cExtension, cFormat);
  86. // text_ascii One text written at (10, 10)
  87. Vec.Clear;
  88. Vec.AddText(10, 10, 0, '10,10 Some text in english.');
  89. Vec.WriteToFile('text_ascii' + cExtension, cFormat);
  90. // text_europen One text testing european languages at (20, 20)
  91. Vec.Clear;
  92. Vec.AddText(20, 20, 0, '20, 20 Mówić, cześć, Włosku, Parabéns, Assunção, Correções.');
  93. Vec.WriteToFile('text_europen' + cExtension, cFormat);
  94. // text_asian One text testing asian languages at (30, 30)
  95. Vec.Clear;
  96. Vec.AddText(30, 30, 0, '30, 30 森林,是一个高密度树木的区域');
  97. Vec.WriteToFile('text_asian' + cExtension, cFormat);
  98. // multi_test_1 Combines various elements
  99. Vec.Clear;
  100. Vec.StartPath(0, 20);
  101. Vec.AddLineToPath(30, 30);
  102. Vec.EndPath();
  103. Vec.StartPath(0, 0);
  104. Vec.AddLineToPath(100, 0);
  105. Vec.AddLineToPath(100, 100);
  106. Vec.AddLineToPath(0, 100);
  107. Vec.AddLineToPath(0, 0);
  108. Vec.EndPath();
  109. Vec.StartPath(0, 0);
  110. Vec.AddLineToPath(10, 10);
  111. Vec.AddBezierToPath(10, 20, 20, 20, 20, 10);
  112. Vec.AddLineToPath(30, 0);
  113. Vec.EndPath();
  114. Vec.AddText(10, 10, 0, '10,10 Some text in english.');
  115. Vec.AddText(20, 20, 0, '20, 20 Mówić, cześć, Włosku, Parabéns.');
  116. Vec.AddText(30, 30, 0, '30, 30 森林,是一个高密');
  117. Vec.WriteToFile('multi_test_1' + cExtension, cFormat);
  118. // pen_test_1 Tests the properties of the Pen
  119. Vec.Clear;
  120. Vec.StartPath(0, 20);
  121. Vec.AddLineToPath(30, 30);
  122. Vec.SetPenWidth(10);
  123. Vec.EndPath();
  124. Vec.StartPath(0, 0);
  125. Vec.AddLineToPath(100, 0);
  126. Vec.AddLineToPath(100, 100);
  127. Vec.AddLineToPath(0, 100);
  128. Vec.AddLineToPath(0, 0);
  129. Vec.SetPenWidth(10);
  130. Vec.EndPath();
  131. Vec.StartPath(0, 0);
  132. Vec.AddLineToPath(10, 10);
  133. Vec.AddBezierToPath(10, 20, 20, 20, 20, 10);
  134. Vec.AddLineToPath(30, 0);
  135. Vec.SetPenWidth(10);
  136. Vec.EndPath();
  137. Vec.WriteToFile('pen_test_1' + cExtension, cFormat);
  138. // pen_test_2 Tests the properties of the Pen
  139. Vec.Clear;
  140. Vec.StartPath(0, 20);
  141. Vec.AddLineToPath(30, 30);
  142. Vec.SetPenWidth(10);
  143. Vec.SetPenColor(RGBToVColor(255, 0, 0));
  144. Vec.EndPath();
  145. Vec.StartPath(0, 0);
  146. Vec.AddLineToPath(100, 0);
  147. Vec.AddLineToPath(100, 100);
  148. Vec.AddLineToPath(0, 100);
  149. Vec.AddLineToPath(0, 0);
  150. Vec.SetPenWidth(10);
  151. Vec.SetPenColor(RGBToVColor(0, 255, 0));
  152. Vec.EndPath();
  153. Vec.StartPath(0, 0);
  154. Vec.AddLineToPath(10, 10);
  155. Vec.AddBezierToPath(10, 20, 20, 20, 20, 10);
  156. Vec.AddLineToPath(30, 0);
  157. Vec.SetPenWidth(10);
  158. Vec.SetPenColor(RGBToVColor(0, 0, 255));
  159. Vec.EndPath();
  160. Vec.WriteToFile('pen_test_2' + cExtension, cFormat);
  161. finally
  162. Vec.Free;
  163. end;
  164. end.