.
1 /*
2 Copyright (C) 2012, 2013, 2014 Johan Mattsson
3
4 This library is free software; you can redistribute it and/or modify
5 it under the terms of the GNU Lesser General Public License as
6 published by the Free Software Foundation; either version 3 of the
7 License, or (at your option) any later version.
8
9 This library is distributed in the hope that it will be useful, but
10 WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
13 */
14
15 using B;
16
17 namespace BirdFont {
18
19 /** All the things we want to test listed is here. */
20 class TestCases {
21
22 public List<Test> test_cases;
23
24 public TestCases () {
25 add (test_overview, "Overview");
26 add (test_data_reader, "Font data reader");
27 add (test_argument, "Argument list");
28 add (test_glyph_ranges, "Glyph ranges");
29 add (test_hex, "Unicode hex values");
30 add (test_reverse_path, "Reverse path");
31 add (test_reverse_random_triangles, "Reverse random paths");
32 add (test_coordinates, "Coordinates");
33 add (test_drawing, "Pen tool");
34 add (test_delete_points, "Delete edit points");
35 add (test_convert_to_quadratic_bezier_path, "Convert to quadratic path");
36 add (test_over_path, "Over path");
37 add (test_export, "Export");
38 add (test_background_coordinates, "Background coordinates");
39 add (test_spin_button, "Spin button");
40 add (test_inkscape_import, "Inkscape import");
41 add (test_illustrator_import, "Illustrator import");
42 add (test_parse_quadratic_paths, "Quadratic paths");
43 add (test_freetype, "Freetype");
44 add (test_preview, "Preview");
45 add (test_kerning, "Kerning");
46 add (test_boundaries, "Boundaries");
47 add (test_codepages, "Codepages");
48 add (test_double_quadratic, "Double quadratic");
49 add (test_raster_path, "Raster path");
50 add (test_file_path, "File path");
51 add (test_xml, "XML");
52
53 add_bechmark (benchmark_stroke, "Stroke");
54 }
55
56 private void add_bechmark (Callback callback, string name) {
57 test_cases.append (new Test (callback, name, true));
58 }
59
60 private void add (Callback callback, string name) {
61 test_cases.append (new Test (callback, name));
62 }
63
64 public unowned List<Test> get_test_functions () {
65 return test_cases;
66 }
67
68 public static void test_double_quadratic () {
69 Glyph g = MainWindow.get_current_glyph ();
70 Gee.ArrayList<Path> paths = new Gee.ArrayList<Path> ();
71 Path pn;
72
73 foreach (Path p in g.get_all_paths ()) {
74 pn = p.copy ();
75 pn.add_hidden_double_points ();
76 paths.add (pn);
77 }
78
79 foreach (Path p in paths) {
80 g.add_path (p);
81 }
82 }
83
84 public static void test_codepages () {
85 CodePageBits pages = new CodePageBits ();
86 uint32 p0, p1;
87
88 pages.get_bits ('ó', out p0, out p1);
89 if (p0 == 0 && p1 == 0) {
90 warning ("Codepage for Hungarian is not set.");
91 }
92
93 pages.get_bits ('ö', out p0, out p1);
94 if (p0 == 0 && p1 == 0) {
95 warning ("Codepage for Swedish is not set.");
96 }
97
98 pages.get_bits ('ツ', out p0, out p1);
99 if (p0 == 0 && p1 == 0) {
100 warning ("Codepage for Japanese is not set.");
101 }
102
103 pages.get_bits ('马', out p0, out p1);
104 if (p0 == 0 && p1 == 0) {
105 warning ("Codepage for Chinese is not set.");
106 }
107 }
108
109 public static void load_test_font () {
110 string fn = "./fonts/Decibel.bf";
111 Font f = BirdFont.new_font ();
112
113 f.set_read_only (true);
114
115 f.set_file (fn);
116 if (!f.load ()) {
117 warning (@"Failed to load fond $fn");
118 return;
119 }
120
121 if (f.length () == 0) {
122 warning ("No glyphs in font.");
123 }
124 }
125
126 public static void test_kerning () {
127 KerningDisplay k;
128 Font font;
129 Glyph? g;
130
131 load_test_font ();
132
133 k = MainWindow.get_kerning_display ();
134 font = BirdFont.get_current_font ();
135 MenuTab.show_kerning_context ();
136
137 if (font.length () == 0) {
138 warning ("No font loaded.");
139 }
140
141 for (int i = 0; i < 10; i++) {
142 for (int j = 0; j < 10; j++) {
143 g = font.get_glyph_index (Random.int_range (0, (int) font.length () - 1));
144 return_if_fail (g != null);
145 if (Random.int_range (1, 9) % 3 == 0) {
146 k.add_kerning_class (Random.int_range (0, 9));
147 } else {
148 k.add_text (((!)g).get_unichar_string ());
149 }
150
151 GlyphCanvas.redraw ();
152 Tool.yield ();
153 }
154
155 for (int j = 0; j < 10; j++) {
156 k.set_absolute_kerning (Random.int_range (1, 9), Random.int_range (0, 30));
157 GlyphCanvas.redraw ();
158 Tool.yield ();
159 }
160
161 k.new_line ();
162 GlyphCanvas.redraw ();
163 Tool.yield ();
164 }
165 }
166
167 public static void benchmark_stroke () {
168 Glyph glyph;
169 test_open_next_glyph ();
170 test_illustrator_import ();
171
172 glyph = MainWindow.get_current_glyph ();
173 for (int i = 0; i < 5; i++) {
174 foreach (Path p in glyph.get_all_paths ()) {
175 p.stroke = (i / 100.0);
176 glyph.update_view ();
177 Tool.yield ();
178 }
179 }
180 }
181
182 public static void test_freetype () {
183 StringBuilder? data;
184 int error;
185 File f = BirdFont.get_settings_directory ();
186 Font font = BirdFont.get_current_font ();
187
188 font.set_name ("TEST_FONT");
189
190 // draw some test glyphs
191 test_illustrator_import ();
192 test_inkscape_import ();
193
194 Tool.yield ();
195
196 if (!ExportTool.export_ttf_font_path (f)) {
197 warning ("TTF export failed.");
198 }
199
200 f = get_child (f, font.get_name () + ".ttf");
201 if (!f.query_exists ()) {
202 warning ("File does not exist.");
203 }
204
205 data = load_freetype_font ((!) f.get_path (), out error);
206 if (error != 0) {
207 warning ("Failed to load font.");
208 return;
209 }
210
211 if (data == null) {
212 warning ("No bf data.");
213 return;
214 }
215
216 Tool.yield ();
217 font.load ();
218 }
219
220 public static void test_parse_quadratic_paths () {
221 Glyph g;
222 SvgParser parser = new SvgParser ();
223
224 test_open_next_glyph ();
225
226 parser.set_format (SvgFormat.INKSCAPE);
227
228 g = MainWindow.get_current_glyph ();
229 parser.parse_svg_data ("M20,300 Q400,50 600,300 T1000,300Q1200 50 1400 300Q1600 50 1800 600 L 1800 700 L 200 700 z", g);
230 Toolbox.select_tool_by_name ("full_glyph");
231
232 g = MainWindow.get_current_glyph ();
233 parser.parse_svg_data ("M300 400 h-200 l0 1000 h200z", g, true);
234 Toolbox.select_tool_by_name ("full_glyph");
235
236
237 parser.set_format (SvgFormat.ILLUSTRATOR);
238
239 g = MainWindow.get_current_glyph ();
240 parser.parse_svg_data ("M20,300 Q400,50 600,300 T1000,300Q1200 50 1400 300Q1600 50 1800 600 L 1800 700 L 200 700 z", g);
241 Toolbox.select_tool_by_name ("full_glyph");
242
243 g = MainWindow.get_current_glyph ();
244 parser.parse_svg_data ("M300 400 h-200 l0 1000 h200z", g, true);
245 Toolbox.select_tool_by_name ("full_glyph");
246
247 }
248
249 public static void test_illustrator_import () {
250 Glyph g;
251 SvgParser parser = new SvgParser ();
252 string illustrator_data = """<?xml version="1.0" encoding="utf-8"?>
253 <!-- Generator: Adobe Illustrator 15.0.2, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
254 <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
255 <svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
256 width="595.28px" height="841.89px" viewBox="0 0 595.28 841.89" enable-background="new 0 0 595.28 841.89" xml:space="preserve">
257 <path fill="#FFFFFF" stroke="#000000" stroke-miterlimit="10" d="M49.102,263.776"/>
258 <g>
259 <g>
260 <path d="M3.037,3.799c0.006-0.057,0.013-0.114,0.019-0.171c0.111-1.002-1.577-0.438-1.89,0.01c0.007-0.012,0.013-0.024,0.02-0.036
261 C1.49,3.626,1.795,3.651,2.1,3.676C2.061,3.954,2.195,4.022,2.5,3.88c0.346-0.007,0.691-0.009,1.036-0.006
262 C4.45,3.876,5.367,3.971,6.279,4.015c1.569,0.075,3.033-0.056,4.441-0.776c1.18-0.604,0.111-1.501-0.824-1.022
263 c-2.19,1.121-5.157,0.242-7.563,0.39C1.281,2.67,0.104,3.19,0.182,4.371C0.218,4.488,0.29,4.577,0.395,4.639
264 C1.397,5.095,2.39,4.668,2.997,3.797c-0.63,0.003-1.26,0.006-1.89,0.01C1.101,3.864,1.095,3.921,1.088,3.979
265 C0.985,4.903,2.948,4.596,3.037,3.799L3.037,3.799z"/>
266 </g>
267 </g>
268 <g>
269 <g>
270 <path d="M4.668,3.559C4.614,5.102,4.586,6.642,4.63,8.186c0.02,0.679-0.033,1.363-0.054,2.041
271 c-0.017,0.587,0.309,1.136-0.299,1.16c-0.563,0.022-1.708,1.045-0.669,1.263c1.091,0.229,2.12,0.154,3.229,0.118
272 c1.057-0.035,1.522-1.348,0.201-1.305c-0.76,0.025-1.539,0.124-2.293-0.035c-0.223,0.421-0.446,0.842-0.669,1.263
273 c1.091-0.043,2.411-0.278,2.5-1.583c0.173-2.551-0.048-5.164,0.042-7.728C6.65,2.432,4.696,2.761,4.668,3.559L4.668,3.559z"/>
274 </g>
275 </g>
276 <g>
277 <g>
278 <path d="M10.014,7.024C9.189,7.82,8.786,8.42,8.661,9.58c-0.098,0.906-0.05,1.599,0.515,2.346
279 c1.215,1.608,3.572,0.777,5.021,0.102c0.216-0.101,0.627-0.469,0.208-0.612c-0.437-0.149-0.964,0.034-1.358,0.218
280 c-1.281,0.597-2.335-0.241-2.516-1.55C10.356,8.81,10.916,7.8,11.784,6.961c0.336-0.325-0.288-0.434-0.486-0.427
281 C10.843,6.55,10.346,6.704,10.014,7.024L10.014,7.024z"/>
282 </g>
283 </g>
284 <g>
285 <g>
286 <path d="M11.415,7.436c0.267-0.022,0.588-0.066,0.852,0.006c-0.072-0.02-0.12-0.251-0.072-0.044
287 c0.021,0.091-0.01,0.268-0.007,0.372c0.003,0.135,0.007,0.264-0.003,0.399c0.001-0.022,0.038-0.029-0.014-0.024
288 c-0.343,0.036-0.735,0.108-1.079,0.09c-0.478-0.026-1.041,0.124-1.254,0.606c-0.187,0.423,0.169,0.847,0.604,0.87
289 c1.314,0.07,3.575-0.07,3.716-1.796c0.043-0.535,0.063-1.19-0.354-1.581c-0.544-0.511-1.554-0.451-2.239-0.394
290 c-0.441,0.037-1.006,0.31-1.056,0.81C10.459,7.24,11.007,7.47,11.415,7.436L11.415,7.436z"/>
291 </g>
292 </g>
293 <g>
294 <g>
295 <path d="M17.85,6.628c-0.13,0.059-0.265,0.102-0.404,0.131c0.104-0.019,0.122-0.021,0.051-0.008
296 c0.112-0.013,0.218-0.015,0.33-0.013c0.152,0.002,0.394,0.013,0.466,0.17c0.207,0.454,2.073-0.208,1.932-0.518
297 c-0.203-0.445-0.951-0.422-1.354-0.417c-0.719,0.01-1.468,0.13-2.126,0.43c-0.143,0.065-0.675,0.39-0.243,0.477
298 C16.934,6.969,17.461,6.806,17.85,6.628L17.85,6.628z"/>
299 </g>
300 </g>
301 <g>
302 <g>
303 <path d="M16.858,6.049c-1.111,0.292-2.424,1.692-1.018,2.544c1.076,0.653,3.576,0.595,2.513,2.572
304 c-0.206,0.382,0.683,0.367,0.816,0.348c0.419-0.059,0.897-0.228,1.107-0.619c0.548-1.019,0.155-1.903-0.79-2.432
305 c-0.418-0.234-0.906-0.356-1.363-0.491c-0.251-0.075-0.492-0.155-0.732-0.259c-0.302-0.131-0.08-0.863-0.304-0.804
306 c0.242-0.063,0.952-0.313,0.851-0.688C17.838,5.842,17.1,5.985,16.858,6.049L16.858,6.049z"/>
307 </g>
308 </g>
309 <g>
310 <g>
311 <path d="M14.983,10.708c-0.036,0.299-0.137,0.716,0.08,0.972c0.244,0.286,0.663,0.358,1.01,0.435
312 c0.994,0.221,1.846,0.177,2.792-0.243c0.185-0.082,0.844-0.417,0.533-0.711c-0.296-0.28-0.951-0.124-1.269,0.018
313 c-0.317,0.141-0.505,0.035-0.853-0.039c-0.444-0.095-0.42-0.276-0.369-0.702C16.991,9.74,15.055,10.114,14.983,10.708
314 L14.983,10.708z"/>
315 </g>
316 </g>
317 <g>
318 <g>
319 <path d="M21.915,6.956c1.207,0.189,2.389,0.085,3.601,0.082c0.424-0.001,1.009-0.321,1.063-0.784
320 c0.06-0.506-0.514-0.641-0.895-0.639c-1.048,0.003-2.059,0.093-3.103-0.071C21.625,5.394,20.618,6.752,21.915,6.956L21.915,6.956z
321 "/>
322 </g>
323 </g>
324 <g>
325 <g>
326 <path d="M21.948,5.359c-0.002,1.245-0.005,2.491-0.045,3.735c-0.023,0.708-0.252,1.594,0.142,2.241
327 c0.911,1.494,3.401,0.492,4.227-0.546c0.544-0.685-1.407-0.547-1.802-0.051c-0.708,0.891-0.653-1.618-0.634-1.881
328 c0.087-1.235,0.043-2.497,0.045-3.735C23.883,4.302,21.949,4.715,21.948,5.359L21.948,5.359z"/>
329 </g>
330 </g>
331 </svg>""";
332 try {
333 File temp_file;
334 FileIOStream? ios;
335 DataOutputStream d;
336 FileOutputStream? os;
337
338 temp_file = get_child (BirdFont.get_settings_directory (), "illustrator_test.svg");
339
340 if (temp_file.query_exists ()) {
341 temp_file.delete ();
342 }
343
344 ios = temp_file.create_readwrite (FileCreateFlags.PRIVATE);
345 os = ((!) ios).output_stream as FileOutputStream?;
346 d = new DataOutputStream ((!) os);
347
348 d.put_string (illustrator_data);
349 d.close ();
350
351 test_open_next_glyph ();
352 SvgParser.import_svg ((!) temp_file.get_path ());
353
354 temp_file.delete ();
355
356 g = MainWindow.get_current_glyph ();
357
358 parser.set_format (SvgFormat.ILLUSTRATOR);
359 parser.add_path_to_glyph ("M67.4,43.5c0,1.1-0.9,2-2,2c-1.1,0-2-0.9-2-2c0-1.1,0.9-2,2-2C66.5,41.5,67.4,42.4,67.4,43.5z", g);
360
361 Toolbox.select_tool_by_name ("full_glyph");
362 } catch (GLib.Error e) {
363 warning (e.message);
364 }
365 }
366
367 public static void test_inkscape_import () {
368 string inkscape_data = """<?xml version="1.0" encoding="UTF-8" standalone="no"?>
369 <svg
370 xmlns:dc="http://purl.org/dc/elements/1.1/"
371 xmlns:cc="http://creativecommons.org/ns#"
372 xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
373 xmlns:svg="http://www.w3.org/2000/svg"
374 xmlns="http://www.w3.org/2000/svg"
375 xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
376 xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
377 width="56"
378 height="111"
379 id="glyph_A"
380 version="1.1"
381 inkscape:version="0.48.2 r9819"
382 sodipodi:docname="Glyph_template.svg">
383 <metadata
384 id="metadata10">
385 <rdf:RDF>
386 <cc:Work
387 rdf:about="">
388 <dc:format>image/svg+xml</dc:format>
389 <dc:type
390 rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
391 <dc:title></dc:title>
392 </cc:Work>
393 </rdf:RDF>
394 </metadata>
395 <defs
396 id="defs8" />
397 <sodipodi:namedview
398 id="namedview3"
399 showgrid="false"
400 inkscape:zoom="1"
401 inkscape:cx="-27.517479"
402 inkscape:cy="43.414876"
403 inkscape:window-width="721"
404 inkscape:window-height="429"
405 inkscape:window-x="557"
406 inkscape:window-y="24"
407 inkscape:window-maximized="0"
408 inkscape:current-layer="glyph_A"
409 inkscape:object-paths="true">
410 <sodipodi:guide
411 orientation="0,1"
412 position="0,39"
413 id="baseline" />
414 </sodipodi:namedview>
415 <path
416 style="fill:#000000;fill-opacity:1;stroke:none"
417 id="path3142"
418 d="M 2.4461236,18.613363 C 3.4535706,17.30804 4.565697,16.070157 5.7189269,14.889064 9.7698153,10.543221 17.324067,7.5616696 21.327378,5.1981153 25.286661,2.860555 13.350954,9.773823 9.3627418,12.061677 16.280624,7.4352732 19.834614,4.1353939 26.808001,3.7441018 c 1.967367,-0.074299 3.936743,-0.05736 5.905091,-0.051608 1.741423,0.3127973 3.428071,0.6890467 5.085162,1.2943721 1.392556,0.6843074 2.448976,1.7917908 3.622959,2.766069 1.120096,1.0121812 2.001523,2.1988012 2.819774,3.4625798 0.849867,1.417783 1.525325,2.83856 1.899606,4.455126 0.609221,1.591091 0.969893,3.232962 1.176184,4.91949 0.18844,1.961102 0.190368,3.933599 0.19931,5.901817 -0.02338,1.98962 0.05666,3.98236 -0.06167,5.96929 -0.326157,1.726864 -0.640714,3.446402 -0.799219,5.198174 -0.141202,1.943199 -0.145653,3.892792 -0.153936,5.840056 -0.0035,2.000837 7.65e-4,4.001679 0.0028,6.002516 0.0019,2.000867 0.0023,4.001735 0.0026,6.002602 -0.119448,1.837413 0.05012,3.609162 0.411903,5.404108 0.436533,1.339043 1.162712,2.583413 2.144788,3.594149 1.406807,1.142779 3.002396,1.683088 4.761485,1.987684 1.194717,0.02857 2.577648,0.517596 3.736705,0.02255 0.232429,-0.09927 0.843546,-0.555586 0.622914,-0.432299 -4.033997,2.254157 -8.043973,4.551038 -12.065959,6.826557 0.179915,-0.145379 0.359829,-0.290757 0.539744,-0.436135 0,0 13.621702,-5.579012 13.621702,-5.579012 l 0,0 c -0.167578,0.175551 -0.335155,0.351102 -0.502733,0.526654 -8.740107,5.12179 -10.300507,8.97968 -17.955597,7.404265 -1.957383,-0.50948 -3.799128,-1.304798 -5.299977,-2.701355 -1.123481,-1.261267 -2.039019,-2.666586 -2.534331,-4.296084 -0.383149,-1.891076 -0.646571,-3.750061 -0.493931,-5.690321 -1.27e-4,-2.000559 -2.84e-4,-4.001119 -0.0017,-6.001678 -0.0017,-2.002107 -0.0049,-4.004212 -0.0062,-6.00632 0.0014,-1.974097 -0.0026,-3.949232 0.08455,-5.921848 0.102996,-1.775437 0.264342,-3.552014 0.742963,-5.2725 0.434483,-1.889017 0.07193,-3.87962 0.190989,-5.804901 -0.0055,-1.914254 -0.0023,-3.8318 -0.157754,-5.741122 -0.175482,-1.642594 -0.511621,-3.23618 -1.128362,-4.775955 -0.299347,-1.455042 -0.914171,-2.699067 -1.678627,-3.966466 -0.757218,-1.14089 -1.561752,-2.21279 -2.610877,-3.106654 -1.010538,-0.897967 -2.015327,-1.827459 -3.298779,-2.322908 -1.523105,-0.512447 -3.13219,-0.816768 -4.732721,-0.938511 -1.950528,0.0034 -3.90631,-0.0079 -5.849616,0.18331 C 9.3832464,13.223396 1.1561405,19.629883 23.07831,6.7491978 18.671333,9.2959874 14.344902,11.987543 9.8573789,14.389567 5.8103531,16.555807 17.78997,9.7680895 21.756041,7.4569649 c 0.21409,-0.1247553 -0.441297,0.229177 -0.642719,0.3734938 -0.63252,0.4531925 -1.255742,0.879984 -1.87055,1.3612245 -0.990862,1.2263148 -2.173114,2.3052708 -3.210427,3.4772508 0,0 -13.5862214,5.944429 -13.5862214,5.944429 z"
419 inkscape:connector-curvature="0" />
420 <path
421 style="fill:#000000;fill-opacity:1;stroke:none"
422 id="path3150"
423 d="m 44.537632,32.349942 c -5.147586,4.026032 -10.873455,6.771035 -16.655502,10.098737 -0.71409,0.686928 -1.63002,0.452279 -2.474519,0.671405 -0.401059,0.104064 -0.753081,0.349262 -1.144818,0.484244 0.736676,0.02838 -2.473393,1.416554 -1.731752,0.983942 29.062029,-16.9524 1.81009,-0.272962 -1.896399,1.014801 -1.286917,0.200555 -2.275566,1.042375 -3.532153,1.301287 -0.405308,0.554267 -1.065095,0.524248 -1.613699,0.795566 -0.662739,0.327763 -1.122742,0.692276 -1.857371,0.928714 -0.760106,0.785065 -1.819224,0.812321 -2.767366,1.163123 -0.474696,0.175632 -0.902223,0.461763 -1.370835,0.653036 -0.256593,0.07288 -0.525961,0.110449 -0.76978,0.218632 C 8.268551,50.865263 6.9846029,51.632281 7.4154555,51.383232 27.533295,39.754369 22.52409,42.532955 18.240391,45.295266 c -1.165488,0.819073 -2.012315,1.89418 -2.774998,3.081098 -0.845284,1.267918 -1.306169,2.696946 -1.894144,4.085429 -0.709336,1.412367 -0.787279,2.808431 -0.584867,4.335462 0.415146,1.308403 0.866784,2.618592 1.690615,3.729211 0.711541,1.116569 1.843939,1.954136 3.05544,2.471647 1.434799,0.587706 2.820424,1.107721 4.370221,1.331222 1.863012,0.201467 3.740237,0.197001 5.61174,0.204627 1.061154,-0.422861 2.259141,-0.406524 3.338121,-0.726337 0.500528,-0.148359 0.95492,-0.423492 1.442889,-0.609031 0.259577,-0.07197 0.531931,-0.107987 0.778732,-0.215924 0.228316,-0.09985 0.420765,-0.267119 0.631148,-0.400678 0.226794,-0.107396 0.447133,-0.229644 0.680383,-0.322187 0.768356,-0.304847 1.479129,-0.382367 2.210911,-0.783628 0.236171,-0.09699 0.929553,-0.418726 0.708513,-0.290959 -3.986257,2.304163 -8.00314,4.554946 -12.009817,6.823414 -0.211901,0.119973 0.413749,-0.25711 0.625248,-0.37779 4.424854,-2.524796 8.855737,-5.039013 13.283606,-7.55852 0,0 -11.493423,9.1721 -11.493423,9.1721 l 0,0 c 25.632954,-14.826031 4.799005,-2.558131 -2.652451,1.337169 -1.491162,0.456817 -2.849157,1.212206 -4.348056,1.647882 -1.608784,0.520829 -3.334322,0.82218 -5.021523,0.881289 -1.937875,-0.0244 -3.888043,-0.04197 -5.802052,-0.381372 C 8.46504,72.371171 6.9529525,71.749159 5.4402732,71.071006 4.1002399,70.2927 2.824761,69.338054 2,68 1.0937305,66.666625 0.5063194,65.186179 6.26e-5,63.660049 -0.2882245,61.935817 -0.448618,60.290055 0.2235018,58.61527 c 0.1864285,-0.460298 0.454071,-0.886178 0.6246649,-1.352577 0.3555415,-0.972041 0.4430375,-2.039925 1.2194084,-2.823626 0.4742277,-1.223862 1.4594908,-2.851226 2.5303973,-3.615873 0.5972416,-0.654754 0.3607951,-0.495492 1.1169283,-0.93613 5.5407473,-3.22888 9.7725723,-6.443379 15.3177753,-8.545059 1.391905,-0.595239 2.821693,-1.08014 4.148056,-1.823818 1.170505,-0.612883 2.349173,-1.244779 3.589444,-1.688564 1.099136,-0.541341 2.265558,-0.860322 3.384995,-1.366026 5.518505,-3.123477 -15.359314,8.690656 -11.325042,6.562985 4.683757,-2.470209 9.826663,-6.265044 15.072968,-8.467654 1.169288,-0.37991 2.379509,-0.540929 3.409749,-1.289413 -29.666352,17.271684 -10.82022,7.119963 -8.585469,4.48399 0,0 13.810255,-5.403563 13.810255,-5.403563 z"
424 inkscape:connector-curvature="0" />
425 </svg>""";
426 try {
427 File temp_file;
428 FileIOStream? ios;
429 DataOutputStream d;
430 FileOutputStream? os;
431
432 temp_file = get_child (BirdFont.get_settings_directory (), "inkscape_test.svg");
433
434 if (temp_file.query_exists ()) {
435 temp_file.delete ();
436 }
437
438 ios = temp_file.create_readwrite (FileCreateFlags.PRIVATE);
439 os = ((!) ios).output_stream as FileOutputStream?;
440 d = new DataOutputStream ((!) os);
441
442 d.put_string (inkscape_data);
443 d.close ();
444
445 test_open_next_glyph ();
446 SvgParser.import_svg ((!) temp_file.get_path ());
447
448 temp_file.delete ();
449 } catch (GLib.Error e) {
450 warning (e.message);
451 }
452 }
453
454 public static void test_spin_button () {
455 SpinButton s = new SpinButton ();
456 double last;
457 string e = "Wrong value in SpinButton";
458
459 s.set_max (1);
460 s.set_min (0);
461 s.set_value ("0.000");
462
463 if (s.get_display_value () != "0.000") {
464 warning (e);
465 }
466
467 s.increase ();
468
469 if (s.get_display_value () != "0.001") {
470 warning (e);
471 }
472
473 last = s.get_value ();
474 for (int i = 0; i < 100; i++) {
475 s.increase ();
476 if (last > s.get_value ()) {
477 warning (e);
478 }
479 last = s.get_value ();
480 }
481
482 if (s.get_display_value () != "0.101") {
483 warning (e);
484 }
485
486 s.set_value ("1.000");
487
488 if (s.get_display_value () != "1.000") {
489 warning (e);
490 }
491
492 last = s.get_value ();
493 for (int i = 0; i < 100; i++) {
494 s.decrease ();
495 if (last < s.get_value ()) {
496 warning (e);
497 }
498 last = s.get_value ();
499 }
500
501 if (s.get_display_value () != "0.900") {
502 warning (e);
503 }
504 }
505
506 public static void test_background_coordinates () {
507 BackgroundImage bg = new BackgroundImage ("");
508
509 bg.set_position (100, 100);
510 bg.set_img_offset (bg.img_offset_x, bg.img_offset_y);
511 warn_if_fail (bg.img_x == 100 && bg.img_y == 100);
512
513 bg.set_img_offset (100, 100);
514 bg.set_position (bg.img_x, bg.img_y);
515 warn_if_fail (bg.img_offset_x == 100 && bg.img_offset_y == 100);
516 }
517
518 public static void test_export () {
519 Glyph g;
520 Path p = new Path ();
521
522 test_open_next_glyph ();
523 g = MainWindow.get_current_glyph ();
524
525 p.add (-10, -10);
526 p.add (50, 50);
527 p.add (10, -10);
528
529 p.close ();
530 g.add_path (p);
531
532 MenuTab.preview ();
533
534 // TODO: run this many times on big fonts
535 for (int i = 0; i < 10; i++) {
536 MenuTab.export_fonts_in_background ();
537 Tool.yield ();
538 }
539 }
540
541 public static void test_preview () {
542 Glyph g;
543 Path p = new Path ();
544
545 test_open_next_glyph ();
546 g = MainWindow.get_current_glyph ();
547
548 p.add (-10, 10);
549 p.add (10, 10);
550 p.add (10, -10);
551 p.add (-10, -10);
552 p.close ();
553 g.add_path (p);
554
555 MenuTab.preview ();
556
557 // TODO: run this many times on big font
558 for (int i = 0; i < 100; i++) {
559 MainWindow.get_tab_bar ().select_tab_name ("Files");
560 Tool.yield ();
561
562 MainWindow.get_tab_bar ().select_tab_name ("Preview");
563 Tool.yield ();
564 }
565
566 }
567
568 public static void test_over_path () {
569 Glyph g;
570 Path p = new Path ();
571 Tool pen_tool;
572
573 pen_tool = MainWindow.get_toolbox ().get_tool ("pen_tool");
574 test_select_action (pen_tool);
575 test_open_next_glyph ();
576
577 g = MainWindow.get_current_glyph ();
578
579 test_click_action (pen_tool, 3, 10, 10);
580 test_click_action (pen_tool, 3, 10, 10);
581 test_click_action (pen_tool, 3, 100, 10);
582 test_click_action (pen_tool, 3, 100, 100);
583 test_click_action (pen_tool, 3, 10, 100);
584 test_click_action (pen_tool, 2, 0, 0);
585
586 g.close_path ();
587
588 warn_if_fail (g.active_paths.size == 0);
589
590 g.select_path (50, 50);
591
592 warn_if_fail (g.active_paths.size == 1);
593
594 p.add (-10, 10);
595 p.add (10, 10);
596 p.add (10, -10);
597 p.add (-10, -10);
598 p.update_region_boundaries();
599 g.add_path (p);
600 g.close_path ();
601
602 if (!p.is_over_coordinate (0, 0)) {
603 warning ("Coordinate 0, 0 is not in path.");
604 }
605
606 if (!p.is_over_coordinate (-10, 10)) {
607 warning ("Corner corrdinate -10, 10 is not in path.");
608 }
609
610 warn_if_fail (!p.is_over_coordinate (-20, -20));
611
612 for (double x = -10; x <= 10; x += 0.1) {
613 for (double y = 10; y <= 10; y += 0.1) {
614 warn_if_fail (p.is_over_coordinate (x, y));
615 }
616 }
617
618 }
619
620 public static void test_convert_to_quadratic_bezier_path () {
621 Glyph g;
622 Path p, p1;
623 EditPoint e0, e1, e2, e3;
624 List<Path> paths = new List<Path> ();
625
626 // convert the current path
627 g = MainWindow.get_current_glyph ();
628
629 foreach (Path path in g.get_all_paths ()) {
630 paths.append (path.get_quadratic_points ());
631 paths.append (path.copy ());
632 }
633
634 // create a new path and convert it
635 test_open_next_glyph ();
636
637 p = new Path ();
638 p1 = new Path ();
639
640 g = MainWindow.get_current_glyph ();
641
642 p.add (-10, 10);
643 p.add (10, 10);
644 p.add (10, -10);
645 p.add (-10, -10);
646 p.close ();
647 g.add_path (p);
648 g.add_path (p1.get_quadratic_points ());
649
650 e0 = new EditPoint (20, 40);
651 e1 = new EditPoint (40, 40);
652 e2 = new EditPoint (40, 20);
653 e3 = new EditPoint (20, 20);
654
655 p1.add_point (e0);
656 p1.add_point (e1);
657 p1.add_point (e2);
658 p1.add_point (e3);
659 p1.close ();
660
661 e0.set_tie_handle (true);
662 e1.set_tie_handle (true);
663 e2.set_tie_handle (true);
664 e3.set_tie_handle (true);
665
666 e0.process_tied_handle ();
667 e1.process_tied_handle ();
668 e2.process_tied_handle ();
669 e3.process_tied_handle ();
670
671 g.add_path (p1);
672 g.add_path (p1.get_quadratic_points ());
673
674 foreach (Path path in paths) {
675 g.add_path (path);
676 }
677 }
678
679 public static void test_overview () {
680 OverView o = MainWindow.get_overview ();
681
682 warn_if_fail (o.selected_char_is_visible ());
683
684 for (int i = 0; i < 10; i++) {
685 o.key_down ();
686 warn_if_fail (o.selected_char_is_visible ());
687 }
688
689 for (int i = 0; i < 15; i++) {
690 o.key_up ();
691 warn_if_fail (o.selected_char_is_visible ());
692 }
693
694 for (int i = 0; i < 6; i++) {
695 o.key_down ();
696 warn_if_fail (o.selected_char_is_visible ());
697 }
698
699 for (int i = 0; i < 3; i++) {
700 o.key_down ();
701 warn_if_fail (o.selected_char_is_visible ());
702 }
703
704 for (int i = 0; i < 2000; i++) {
705 o.scroll_adjustment (5);
706 }
707
708 for (int i = 0; i < 2000; i++) {
709 o.scroll_adjustment (-5);
710 }
711 }
712
713 public static void test_data_reader () {
714 FontData fd = new FontData ();
715 uint len;
716 int v;
717
718 try {
719 fd.add (7);
720 fd.add_ulong (0x5F0F3CF5);
721 fd.add_ulong (9);
722
723 warn_if_fail (fd.table_data[0] == 7);
724 warn_if_fail (fd.read () == 7);
725 warn_if_fail (fd.read_ulong () == 0x5F0F3CF5);
726 warn_if_fail (fd.read_ulong () == 9);
727
728 fd = new FontData ();
729 for (int16 i = 0; i < 2048; i++) {
730 fd.add_short (i);
731 }
732
733 fd.seek (2 * 80);
734 warn_if_fail (fd.read_short () == 80);
735
736 fd.seek (100);
737 fd.add_short (7);
738 fd.seek (100);
739 warn_if_fail (fd.read_short () == 7);
740
741 fd.seek_end ();
742 len = fd.length ();
743 fd.add (0);
744 warn_if_fail (len + 1 == fd.length ());
745
746 fd.seek_end ();
747 for (int i = -1131; i < 1131; i++) {
748 fd.add_charstring_value (i);
749 }
750
751 for (int i = -1131; i < 1131; i++) {
752 v = fd.read_charstring_value ();
753 if (v != i) {
754 warning (@"expecting $i got $v\n");
755 }
756 }
757
758 } catch (GLib.Error e) {
759 warning (e.message);
760 }
761 }
762
763
764 public static void test_argument () {
765 Argument arg = new Argument ("supplement -t \"Argument list\" --unknown -unknown --help -s");
766
767 return_if_fail (arg.has_argument ("--test"));
768 return_if_fail ((!) arg.get_argument ("--test") == "\"Argument list\"" );
769 return_if_fail (arg.has_argument ("--unknown"));
770 return_if_fail (arg.has_argument ("--help"));
771 return_if_fail (arg.has_argument ("--slow"));
772 return_if_fail (arg.validate () != 0);
773
774 arg = new Argument ("supplement --test \"Argument list\"");
775 return_if_fail ((!) arg.get_argument ("--test") == "\"Argument list\"" );
776 return_if_fail (!arg.has_argument ("--help"));
777 return_if_fail (!arg.has_argument ("--slow"));
778 return_if_fail (arg.validate () == 0);
779
780 }
781
782 public static void test_glyph_ranges () {
783 GlyphRange gr = new GlyphRange ();
784 GlyphRange gr_az = new GlyphRange ();
785
786 gr.add_range ('b', 'c');
787 gr.add_single ('d');
788 gr.add_range ('e', 'h');
789 gr.add_range ('k', 'm');
790 gr.add_range ('o', 'u');
791 gr.add_range ('a', 'd');
792 gr.add_range ('f', 'z');
793 gr.add_range ('b', 'd');
794
795 gr.print_all ();
796
797 return_if_fail (gr.length () == 'z' - 'a' + 1);
798 return_if_fail (gr.get_ranges ().size == 1);
799 return_if_fail (gr.get_ranges ().get (0).length () == 'z' - 'a' + 1);
800
801 for (unichar i = 'a'; i <= 'z'; i++) {
802 uint index = i - 'a';
803 string c = gr.get_char (index);
804 StringBuilder s = new StringBuilder ();
805 s.append_unichar (i);
806
807 if (c != s.str) {
808 warning (@"wrong glyph in glyph range got \"$c\" expected \"$(s.str)\" for index $(index).");
809 }
810 }
811
812 gr = new GlyphRange ();
813 gr.add_single ('a');
814 gr.add_range ('c', 'e');
815 gr.add_single ('◊');
816 return_if_fail (gr.get_char (0) == "a");
817 return_if_fail (gr.get_char (1) == "c");
818 return_if_fail (gr.get_char (2) == "d");
819 return_if_fail (gr.get_char (3) == "e");
820 return_if_fail (gr.get_char (4) == "◊");
821
822 // a-z
823 gr_az.add_range ('a', 'z');
824 if (!gr_az.has_character ("g")) {
825 warning ("Can not g in range a-z ");
826 }
827
828 if (gr_az.has_character ("å")) {
829 warning ("Range a-z has å");
830 }
831
832 // codepage test for Latin 2
833 try {
834 gr = new GlyphRange ();
835 gr.parse_ranges ("- Ç ü-ý é á-â ä Ů-ű ç Ł-ń ë Ő-ő í-î Ä É Ĺ-ĺ ó-ô ö-÷ Ľ-ľ Ö-× Ü-Ý ú Ź-ž Ę-ě «- » ░-▓ │ ┤ Á-Â ╣ ═-║ ╗ ╝ ┐ └ ┴ ┬ ├ ─ ┼ Ă-ć ╚ ╔ ╩ ╦ ╠ ╬ ¤ Č-đ Ë Ň-ň Í-Î ┘ ┌ █ ▄ Ş-ť ▀ Ó-Ô ß Ŕ-ŕ Ú ´ ˝ ˛ ˇ ˘-˙ §-¨ ¸ ° Ř-ś ■ ");
836 if (!gr.has_character ("Ă")) {
837 warning ("Latin 2 range does not have Ă");
838 }
839
840 if (!gr.has_unichar ('Ă')) {
841 warning ("Latin 2 range does not have Ă");
842 }
843
844 if (!gr.has_unichar ('ó')) {
845 warning ("Latin 2 range does not have ó");
846 }
847 } catch (MarkupError e) {
848 warning (e.message);
849 }
850 }
851
852 public static void test_hex () {
853 test_hex_conv ('H', "U+48", 72);
854 test_hex_conv ('1', "U+31", 49);
855 test_hex_conv ('å', "U+e5", 229);
856 test_hex_conv ('◊', "U+25ca", 9674);
857 }
858
859 private static void test_hex_conv (unichar h, string sr, int r) {
860 string s = Font.to_hex (h);
861 unichar t = Font.to_unichar (sr);
862
863 if (s != sr) warning (@"($s != \"$sr\")");
864 if ((int)t != r || t != h) warning (@"$((int)t) != $r || $t != '$h'");
865 }
866
867 // test pen tool
868 /** Draw a test glyph. */
869 public static void test_drawing () {
870 Tool pen_tool = MainWindow.get_toolbox ().get_tool ("pen_tool");
871
872 test_select_action (pen_tool);
873
874 test_open_next_glyph ();
875
876 // paint
877 test_click_action (pen_tool, 1, 30, 30);
878 test_click_action (pen_tool, 1, 60, 30);
879 test_click_action (pen_tool, 1, 60, 60);
880 test_click_action (pen_tool, 1, 30, 60);
881
882 // close
883 test_click_action (pen_tool, 3, 0, 0);
884
885 // reopen
886 test_click_action (pen_tool, 3, 35, 35);
887
888 // move around
889 test_move_action (pen_tool, 100, 200);
890 test_move_action (pen_tool, 20, 300);
891 test_move_action (pen_tool, 0, 0);
892
893 // add to path
894 test_move_action (pen_tool, 70, 50);
895
896 test_click_action (pen_tool, 1, 70, 50);
897 test_click_action (pen_tool, 1, 70, 50);
898 test_click_action (pen_tool, 1, 70, 100);
899 test_click_action (pen_tool, 1, 50, 100);
900 test_click_action (pen_tool, 1, 50, 50);
901
902 // close
903 test_click_action (pen_tool, 3, 0, 0);
904 Tool.yield ();
905 }
906
907 /** Test path coordinates and reverse path coordinates. */
908 public static void test_coordinates () {
909 int x, y, xc, yc;
910 double px, py, mx, my;
911 string n;
912 Tool pen_tool = MainWindow.get_toolbox ().get_tool ("pen_tool");
913
914 test_open_next_glyph ();
915 Glyph g = MainWindow.get_current_glyph ();
916
917 xc = (int) (g.allocation.width / 2.0);
918 yc = (int) (g.allocation.height / 2.0);
919
920 g.default_zoom ();
921
922 x = 10;
923 y = 15;
924
925 px = Glyph.path_coordinate_x (x);
926 py = Glyph.path_coordinate_y (y);
927
928 mx = x * Glyph.ivz () - Glyph.xc () + g.view_offset_x;
929 my = Glyph.yc () - y * Glyph.ivz () - g.view_offset_y;
930
931 if (mx != px || my != py) {
932 warning (@"bad coordinate $mx != $px || $my != $py");
933 }
934
935 test_reverse_coordinate (x, y, px, py, "ten fifteen");
936 test_click_action (pen_tool, 1, x, y);
937
938 // offset no zoom
939 n = "Offset no zoom";
940 g.reset_zoom ();
941
942 px = Glyph.path_coordinate_x (x);
943 py = Glyph.path_coordinate_y (y);
944
945 test_reverse_coordinate (x, y, px, py, n);
946 test_click_action (pen_tool, 1, x, y);
947
948 // close path
949 test_click_action (pen_tool, 3, x, y);
950 }
951
952 private static void test_reverse_coordinate (int x, int y, double px, double py, string n) {
953 if (x != Glyph.reverse_path_coordinate_x (px) || Glyph.reverse_path_coordinate_y (py) != y) {
954 warning (@"Reverse coordinates does not match current point for test case \"$n\".\n $x != $(Glyph.reverse_path_coordinate_x (px)) || $(Glyph.reverse_path_coordinate_y (py)) != $y (x != Glyph.reverse_path_coordinate_x (px) || Glyph.reverse_path_coordinate_y (py) != y)");
955 }
956 }
957
958 private static void test_last_is_clockwise (string name) {
959 bool d = ((!)MainWindow.get_current_glyph ().get_last_path ()).is_clockwise ();
960
961 if (!d) {
962 critical (@"\nPath $name is counter clockwise, in test_last_is_clockwise");
963 }
964
965 }
966
967 private static bool test_reverse_last (string name)
968 requires (MainWindow.get_current_glyph ().get_last_path () != null)
969 {
970 Glyph g = MainWindow.get_current_glyph ();
971 Path p = (!) g.get_last_path ();
972 bool direction = p.is_clockwise ();
973
974 p.reverse ();
975
976 if (direction == p.is_clockwise ()) {
977 critical (@"Direction did not change after reverseing path \"$name\"\n");
978 stderr.printf (@"Path length: $(p.points.size) \n");
979 return false;
980 }
981
982 Tool.yield ();
983 return true;
984 }
985
986 class Point {
987
988 public int x;
989 public int y;
990
991 public Point (int x, int y) {
992 this.x = x;
993 this.y = y;
994 }
995 }
996
997 private static Point p (int x, int y) {
998 return new Point (x, y);
999 }
1000
1001 private static void test_triangle (Point a, Point b, Point c, string name = "") {
1002 Tool pen_tool = MainWindow.get_toolbox ().get_tool ("pen_tool");
1003
1004 Tool.yield ();
1005 MainWindow.get_tab_bar ().select_overview ();
1006
1007 Tool.yield ();
1008 MainWindow.get_overview ().open_current_glyph ();
1009
1010 test_select_action (pen_tool);
1011
1012 test_click_action (pen_tool, 3, a.x, a.y);
1013 test_click_action (pen_tool, 3, b.x, b.y);
1014 test_click_action (pen_tool, 3, c.x, c.y);
1015
1016 test_reverse_last (@"Triangle reverse \"$name\" ($(a.x), $(a.y)), ($(b.x), $(b.y)), ($(c.x), $(c.y)) failed.");
1017
1018 Tool.yield ();
1019 }
1020
1021 private static void test_various_triangles () {
1022 test_triangle (p (287, 261), p (155, 81), p (200, 104), "First");
1023 test_triangle (p (65, 100), p (168, 100), p (196, 177), "Second");
1024 test_triangle (p (132, 68), p (195, 283), p (195, 222), "Third");
1025 test_triangle (p (144, 267), p (147, 27), p (296, 267), "Fourth");
1026 }
1027
1028 public static void test_reverse_path () {
1029 // open a new glyph
1030 Tool pen_tool = MainWindow.get_toolbox ().get_tool ("pen_tool");
1031
1032 Tool.yield ();
1033 MainWindow.get_tab_bar ().select_overview ();
1034
1035 Tool.yield ();
1036 MainWindow.get_overview ().open_current_glyph ();
1037
1038 test_select_action (pen_tool);
1039
1040 // paint
1041 int x_offset = 10;
1042 int y_offset = 10;
1043
1044 test_open_next_glyph ();
1045 test_various_triangles ();
1046
1047 test_open_next_glyph ();
1048 // draw clockwise and check direction
1049
1050 y_offset += 160;
1051 test_click_action (pen_tool, 3, 10 + x_offset, 20 + y_offset);
1052 test_click_action (pen_tool, 3, 17 + x_offset, 17 + y_offset);
1053 test_click_action (pen_tool, 3, 20 + x_offset, 0 + y_offset);
1054 test_click_action (pen_tool, 2, 0, 0);
1055 test_last_is_clockwise ("Clockwise triangle 1.2");
1056
1057 // draw paths clockwise / counter clockwise and reverse them
1058
1059 test_click_action (pen_tool, 3, 115, 137);
1060 test_click_action (pen_tool, 3, 89, 74);
1061 test_click_action (pen_tool, 3, 188, 232);
1062 test_click_action (pen_tool, 2, 0, 0);
1063 test_reverse_last ("Triangle 0");
1064
1065 // draw incomplete paths
1066 y_offset += 20;
1067 test_click_action (pen_tool, 3, 10 + x_offset, 20 + y_offset);
1068 test_reverse_last ("Point");
1069 test_click_action (pen_tool, 2, 0, 0);
1070
1071 y_offset += 20;
1072 test_click_action (pen_tool, 3, 10 + x_offset, 20 + y_offset);
1073 test_click_action (pen_tool, 3, 10 + x_offset, 20 + y_offset);
1074 test_reverse_last ("Double point");
1075 test_click_action (pen_tool, 2, 0, 0);
1076
1077 y_offset += 20;
1078 test_click_action (pen_tool, 3, 10 + x_offset, 30 + y_offset);
1079 test_click_action (pen_tool, 3, 10 + x_offset, 20 + y_offset);
1080 test_reverse_last ("Vertical line");
1081 test_click_action (pen_tool, 2, 0, 0);
1082
1083 y_offset += 20;
1084 test_click_action (pen_tool, 1, 30 + x_offset, 20 + y_offset);
1085 test_click_action (pen_tool, 1, 10 + x_offset, 20 + y_offset);
1086 test_click_action (pen_tool, 3, 0, 0);
1087 test_reverse_last ("Horisontal line");
1088 test_click_action (pen_tool, 2, 0, 0);
1089
1090 // triangle 1
1091 y_offset += 20;
1092 test_click_action (pen_tool, 3, 10 + x_offset, -10 + y_offset);
1093 test_click_action (pen_tool, 3, 20 + x_offset, 20 + y_offset);
1094 test_click_action (pen_tool, 3, 30 + x_offset, 0 + y_offset);
1095 test_reverse_last ("Triangle reverse 1");
1096 test_click_action (pen_tool, 2, 0, 0);
1097
1098 // box
1099 y_offset += 20;
1100 test_click_action (pen_tool, 3, 100 + x_offset, 150 + y_offset);
1101 test_click_action (pen_tool, 3, 150 + x_offset, 150 + y_offset);
1102 test_click_action (pen_tool, 3, 150 + x_offset, 100 + y_offset);
1103 test_click_action (pen_tool, 3, 100 + x_offset, 100 + y_offset);
1104 test_reverse_last ("Box 1");
1105 test_click_action (pen_tool, 2, 0, 0);
1106 }
1107
1108 private static Tool select_pen () {
1109 Tool pen_tool = MainWindow.get_toolbox ().get_tool ("pen_tool");
1110 test_select_action (pen_tool);
1111 return pen_tool;
1112 }
1113
1114 public static void test_delete_points () {
1115 PenTool pen;
1116
1117 test_open_next_glyph ();
1118
1119 pen = (PenTool) select_pen ();
1120
1121 // draw a line with ten points
1122 for (int i = 1; i <= 10; i++) {
1123 test_click_action (pen, 3, 20*i, 20);
1124 }
1125
1126 // TODO: it would be nice to test if points were created here
1127
1128 // delete points
1129 for (int i = 1; i <= 10; i++) {
1130 test_move_action (pen, 20 * i, 20);
1131 test_click_action (pen, 1, 20*i, 20);
1132 PenTool.delete_selected_points ();
1133 }
1134 }
1135
1136 public static void test_reverse_random_triangles () {
1137 Tool pen;
1138
1139 int ax, bx, cx;
1140 int ay, by, cy;
1141
1142 bool r = true;
1143
1144 test_open_next_glyph ();
1145 pen = select_pen ();
1146
1147 for (int i = 0; i < 30; i++) {
1148 Tool.yield ();
1149
1150 ax = Random.int_range (0, 300);
1151 bx = Random.int_range (0, 300);
1152 cx = Random.int_range (0, 300);
1153
1154 ay = Random.int_range (0, 300);
1155 by = Random.int_range (0, 300);
1156 cy = Random.int_range (0, 300);
1157
1158 test_click_action (pen, 3, ax, ay);
1159 test_click_action (pen, 3, bx, by);
1160 test_click_action (pen, 3, cx, cy);
1161 test_click_action (pen, 2, 0, 0);
1162
1163 r = test_reverse_last (@"Random triangle № $(i + 1) ($ax, $ay), ($bx, $by), ($cx, $cy)");
1164 if (!r) {
1165 test_open_next_glyph ();
1166 pen = select_pen ();
1167
1168 test_click_action (pen, 3, ax, ay);
1169 test_click_action (pen, 3, bx, by);
1170 test_click_action (pen, 3, cx, cy);
1171 test_click_action (pen, 2, 0, 0);
1172
1173 return;
1174 }
1175
1176 test_open_next_glyph ();
1177 }
1178
1179 if (r) test_open_next_glyph ();
1180 }
1181
1182
1183 /** Help function to test button press actions. */
1184 public static void test_click_action (Tool t, int b, int x, int y) {
1185 Tool.yield ();
1186 t.press_action (t, b, x, y);
1187
1188 Tool.yield ();
1189 t.release_action (t, b, x, y);
1190 }
1191
1192 /** Help function to test select action for this tool. */
1193 public static void test_select_action (Tool t) {
1194 Toolbox tb = MainWindow.get_toolbox ();
1195 Tool.yield ();
1196 tb.select_tool (t);
1197 }
1198
1199 public static void test_move_action (Tool t, int x, int y) {
1200 Tool.yield ();
1201 t.move_action (t, x, y);
1202 }
1203
1204 public static void test_open_next_glyph () {
1205 OverView o = MainWindow.get_overview ();
1206
1207 MainWindow.get_tab_bar ().select_overview ();
1208 Toolbox.select_tool_by_name ("utf_8");
1209 Tool.yield ();
1210
1211 o.select_next_glyph ();
1212 Tool.yield ();
1213
1214 o.open_current_glyph ();
1215 Tool.yield ();
1216 }
1217
1218 private static void test_boundaries () {
1219 Preferences.draw_boundaries = true;
1220 }
1221
1222 private static void test_raster_path () {
1223 Glyph g = MainWindow.get_current_glyph ();
1224 PathList pl = new PathList ();
1225 Path path;
1226
1227 test_open_next_glyph ();
1228 test_inkscape_import (); // draw somee thing
1229
1230 foreach (Path p in g.get_all_paths ()) {
1231 path = new Path ();
1232 p.all_of_path ((cx, cy, ct) => {
1233 path.add (cx, cy);
1234 return true;
1235 });
1236 pl.add (path);
1237 }
1238
1239 test_open_next_glyph ();
1240
1241 foreach (Path p in pl.paths) {
1242 g.add_path (p);
1243 }
1244 }
1245
1246 private static void test_file_path () {
1247 Font f = new Font ();
1248 File file;
1249 string folder;
1250
1251 f.font_file = "E:\\Typeface.bf";
1252 folder = f.get_folder_path ();
1253 if (folder != "E:") {
1254 warning (@"Wrong folder, $folder");
1255 }
1256
1257 f.font_file = "/home/user/Typeface.bf";
1258 folder = f.get_folder_path ();
1259 if (folder != "/home/user") {
1260 warning (@"Wrong folder, $folder");
1261 }
1262
1263 f.font_file = "./Typeface.bf";
1264 file = File.new_for_path (".");
1265 folder = f.get_folder_path ();
1266 if (((!)file.get_path ()) != folder) {
1267 warning (@"Wrong folder, $folder");
1268 }
1269
1270 f.font_file = "./Typeface.bf";
1271 folder = f.get_folder_path ();
1272 if (!folder.has_prefix ("/")) {
1273 warning (@"Wrong folder, $folder");
1274 }
1275 }
1276
1277 static void test_xml () {
1278 Tag root;
1279 XmlParser parser;
1280
1281 parser = new XmlParser ("""<g><g><g></g><g><g></g></g></g></g>""");
1282
1283 root = parser.get_root_tag ();
1284 print_tags (root);
1285
1286 if (parser.validate ()) {
1287 root = parser.get_root_tag ();
1288 print_tags (root);
1289 } else {
1290 warning ("Invalid XML code.");
1291 }
1292 }
1293
1294 static void print_tags (Tag tag) {
1295 print (tag.get_name ());
1296 print ("\n");
1297 print_attributes (tag);
1298 print (tag.get_content ());
1299
1300 foreach (Tag t in tag) {
1301 print_tags (t);
1302 }
1303 }
1304
1305 static void print_attributes (Tag tag) {
1306 Attributes attributes = tag.get_attributes ();
1307 foreach (Attribute attribute in attributes) {
1308 print ("\t");
1309 print (attribute.get_name ());
1310 print ("\n");
1311 }
1312 }
1313
1314 }
1315
1316 }
1317