The Birdfont Source Code


All Repositories / birdfont.git / blob – RSS feed

TestCases.vala in /libbirdfont

This file is a part of the Birdfont project.

Contributing

Send patches or pull requests to johan.mattsson.m@gmail.com.
Clone this repository: git clone https://github.com/johanmattssonm/birdfont.git
Circle boundaries heads/master
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 using SvgBird; 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_export, "Export"); 37 add (test_background_coordinates, "Background coordinates"); 38 add (test_spin_button, "Spin button"); 39 add (test_inkscape_import, "Inkscape import"); 40 add (test_illustrator_import, "Illustrator import"); 41 add (test_parse_quadratic_paths, "Quadratic paths"); 42 add (test_freetype, "Freetype"); 43 add (test_preview, "Preview"); 44 add (test_kerning, "Kerning"); 45 add (test_boundaries, "Boundaries"); 46 add (test_extrema, "Extrema"); 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_extrema () { 183 Glyph g; 184 SvgParser parser = new SvgParser (); 185 186 test_open_next_glyph (); 187 g = MainWindow.get_current_glyph (); 188 189 parser.set_format (SvgFormat.INKSCAPE); 190 parser.add_path_to_glyph ("m -163.59375,-250.78125 c -42.43208,51.5679 -78.92929,123.30265 -109.59375,216.03125 l 94.9375,31.375 c 27.9767,-84.600883 60.86301,-146.18598 91.875,-183.875 48.545803,-62.79748 104.513616,-52.47212 139.34375,-5.46875 25.619399,35.30837 51.38402,95.22476 69.625,178.625 l 97.6875,-21.375 c -20.20842,-92.39565 -48.64621,-164.00261 -86.375,-216 -88.811818,-115.9163 -218.868232,-92.82539 -297.5,0.6875 z", g); 191 192 Toolbox.select_tool_by_name ("full_glyph"); 193 194 foreach (Path p in g.get_all_paths ()) { 195 p.add_extrema (); 196 } 197 } 198 199 public static void test_freetype () { 200 StringBuilder? data; 201 int error; 202 File f = BirdFont.get_settings_directory (); 203 Font font = BirdFont.get_current_font (); 204 205 font.set_name ("TEST_FONT"); 206 207 // draw some test glyphs 208 test_illustrator_import (); 209 test_inkscape_import (); 210 211 Tool.yield (); 212 213 if (!ExportTool.export_ttf_font_path (f)) { 214 warning ("TTF export failed."); 215 } 216 217 f = get_child (f, font.get_name () + ".ttf"); 218 if (!f.query_exists ()) { 219 warning ("File does not exist."); 220 } 221 222 data = load_freetype_font ((!) f.get_path (), out error); 223 if (error != 0) { 224 warning ("Failed to load font."); 225 return; 226 } 227 228 if (data == null) { 229 warning ("No bf data."); 230 return; 231 } 232 233 Tool.yield (); 234 font.load (); 235 } 236 237 public static void test_parse_quadratic_paths () { 238 Glyph g; 239 SvgParser parser = new SvgParser (); 240 241 test_open_next_glyph (); 242 243 parser.set_format (SvgFormat.INKSCAPE); 244 245 g = MainWindow.get_current_glyph (); 246 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); 247 Toolbox.select_tool_by_name ("full_glyph"); 248 249 g = MainWindow.get_current_glyph (); 250 parser.parse_svg_data ("M300 400 h-200 l0 1000 h200z", g, true); 251 Toolbox.select_tool_by_name ("full_glyph"); 252 253 254 parser.set_format (SvgFormat.ILLUSTRATOR); 255 256 g = MainWindow.get_current_glyph (); 257 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); 258 Toolbox.select_tool_by_name ("full_glyph"); 259 260 g = MainWindow.get_current_glyph (); 261 parser.parse_svg_data ("M300 400 h-200 l0 1000 h200z", g, true); 262 Toolbox.select_tool_by_name ("full_glyph"); 263 264 } 265 266 public static void test_illustrator_import () { 267 Glyph g; 268 SvgParser parser = new SvgParser (); 269 string illustrator_data = """<?xml version="1.0" encoding="utf-8"?> 270 <!-- Generator: Adobe Illustrator 15.0.2, SVG Export Plug-In . SVG Version: 6.00 Build 0) --> 271 <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"> 272 <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" 273 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"> 274 <path fill="#FFFFFF" stroke="#000000" stroke-miterlimit="10" d="M49.102,263.776"/> 275 <g> 276 <g> 277 <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 278 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 279 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 280 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 281 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 282 C0.985,4.903,2.948,4.596,3.037,3.799L3.037,3.799z"/> 283 </g> 284 </g> 285 <g> 286 <g> 287 <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 288 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 289 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 290 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"/> 291 </g> 292 </g> 293 <g> 294 <g> 295 <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 296 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 297 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 298 C10.843,6.55,10.346,6.704,10.014,7.024L10.014,7.024z"/> 299 </g> 300 </g> 301 <g> 302 <g> 303 <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 304 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 305 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 306 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 307 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"/> 308 </g> 309 </g> 310 <g> 311 <g> 312 <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 313 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 314 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 315 C16.934,6.969,17.461,6.806,17.85,6.628L17.85,6.628z"/> 316 </g> 317 </g> 318 <g> 319 <g> 320 <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 321 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 322 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 323 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"/> 324 </g> 325 </g> 326 <g> 327 <g> 328 <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 329 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 330 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 331 L14.983,10.708z"/> 332 </g> 333 </g> 334 <g> 335 <g> 336 <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 337 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 338 "/> 339 </g> 340 </g> 341 <g> 342 <g> 343 <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 344 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 345 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"/> 346 </g> 347 </g> 348 </svg>"""; 349 try { 350 File temp_file; 351 FileIOStream? ios; 352 DataOutputStream d; 353 FileOutputStream? os; 354 355 temp_file = get_child (BirdFont.get_settings_directory (), "illustrator_test.svg"); 356 357 if (temp_file.query_exists ()) { 358 temp_file.delete (); 359 } 360 361 ios = temp_file.create_readwrite (FileCreateFlags.PRIVATE); 362 os = ((!) ios).output_stream as FileOutputStream?; 363 d = new DataOutputStream ((!) os); 364 365 d.put_string (illustrator_data); 366 d.close (); 367 368 test_open_next_glyph (); 369 SvgParser.import_svg ((!) temp_file.get_path ()); 370 371 temp_file.delete (); 372 373 g = MainWindow.get_current_glyph (); 374 375 parser.set_format (SvgFormat.ILLUSTRATOR); 376 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); 377 378 Toolbox.select_tool_by_name ("full_glyph"); 379 } catch (GLib.Error e) { 380 warning (e.message); 381 } 382 } 383 384 public static void test_inkscape_import () { 385 string inkscape_data = """<?xml version="1.0" encoding="UTF-8" standalone="no"?> 386 <svg 387 xmlns:dc="http://purl.org/dc/elements/1.1/" 388 xmlns:cc="http://creativecommons.org/ns#" 389 xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" 390 xmlns:svg="http://www.w3.org/2000/svg" 391 xmlns="http://www.w3.org/2000/svg" 392 xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" 393 xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" 394 width="56" 395 height="111" 396 id="glyph_A" 397 version="1.1" 398 inkscape:version="0.48.2 r9819" 399 sodipodi:docname="Glyph_template.svg"> 400 <metadata 401 id="metadata10"> 402 <rdf:RDF> 403 <cc:Work 404 rdf:about=""> 405 <dc:format>image/svg+xml</dc:format> 406 <dc:type 407 rdf:resource="http://purl.org/dc/dcmitype/StillImage" /> 408 <dc:title></dc:title> 409 </cc:Work> 410 </rdf:RDF> 411 </metadata> 412 <defs 413 id="defs8" /> 414 <sodipodi:namedview 415 id="namedview3" 416 showgrid="false" 417 inkscape:zoom="1" 418 inkscape:cx="-27.517479" 419 inkscape:cy="43.414876" 420 inkscape:window-width="721" 421 inkscape:window-height="429" 422 inkscape:window-x="557" 423 inkscape:window-y="24" 424 inkscape:window-maximized="0" 425 inkscape:current-layer="glyph_A" 426 inkscape:object-paths="true"> 427 <sodipodi:guide 428 orientation="0,1" 429 position="0,39" 430 id="baseline" /> 431 </sodipodi:namedview> 432 <path 433 style="fill:#000000;fill-opacity:1;stroke:none" 434 id="path3142" 435 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" 436 inkscape:connector-curvature="0" /> 437 <path 438 style="fill:#000000;fill-opacity:1;stroke:none" 439 id="path3150" 440 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" 441 inkscape:connector-curvature="0" /> 442 </svg>"""; 443 try { 444 File temp_file; 445 FileIOStream? ios; 446 DataOutputStream d; 447 FileOutputStream? os; 448 449 temp_file = get_child (BirdFont.get_settings_directory (), "inkscape_test.svg"); 450 451 if (temp_file.query_exists ()) { 452 temp_file.delete (); 453 } 454 455 ios = temp_file.create_readwrite (FileCreateFlags.PRIVATE); 456 os = ((!) ios).output_stream as FileOutputStream?; 457 d = new DataOutputStream ((!) os); 458 459 d.put_string (inkscape_data); 460 d.close (); 461 462 test_open_next_glyph (); 463 SvgParser.import_svg ((!) temp_file.get_path ()); 464 465 temp_file.delete (); 466 } catch (GLib.Error e) { 467 warning (e.message); 468 } 469 } 470 471 public static void test_spin_button () { 472 SpinButton s = new SpinButton (); 473 double last; 474 string e = "Wrong value in SpinButton"; 475 476 s.set_max (1); 477 s.set_min (0); 478 s.set_value ("0.000"); 479 480 if (s.get_display_value () != "0.000") { 481 warning (e); 482 } 483 484 s.increase (); 485 486 if (s.get_display_value () != "0.001") { 487 warning (e); 488 } 489 490 last = s.get_value (); 491 for (int i = 0; i < 100; i++) { 492 s.increase (); 493 if (last > s.get_value ()) { 494 warning (e); 495 } 496 last = s.get_value (); 497 } 498 499 if (s.get_display_value () != "0.101") { 500 warning (e); 501 } 502 503 s.set_value ("1.000"); 504 505 if (s.get_display_value () != "1.000") { 506 warning (e); 507 } 508 509 last = s.get_value (); 510 for (int i = 0; i < 100; i++) { 511 s.decrease (); 512 if (last < s.get_value ()) { 513 warning (e); 514 } 515 last = s.get_value (); 516 } 517 518 if (s.get_display_value () != "0.900") { 519 warning (e); 520 } 521 } 522 523 public static void test_background_coordinates () { 524 BackgroundImage bg = new BackgroundImage (""); 525 526 bg.set_position (100, 100); 527 bg.set_img_offset (bg.img_offset_x, bg.img_offset_y); 528 warn_if_fail (bg.img_x == 100 && bg.img_y == 100); 529 530 bg.set_img_offset (100, 100); 531 bg.set_position (bg.img_x, bg.img_y); 532 warn_if_fail (bg.img_offset_x == 100 && bg.img_offset_y == 100); 533 } 534 535 public static void test_export () { 536 Glyph g; 537 Path p = new Path (); 538 539 test_open_next_glyph (); 540 g = MainWindow.get_current_glyph (); 541 542 p.add (-10, -10); 543 p.add (50, 50); 544 p.add (10, -10); 545 546 p.close (); 547 g.add_path (p); 548 549 MenuTab.preview (); 550 551 // TODO: run this many times on big fonts 552 for (int i = 0; i < 10; i++) { 553 MenuTab.export_fonts_in_background (); 554 Tool.yield (); 555 } 556 } 557 558 public static void test_preview () { 559 Glyph g; 560 Path p = new Path (); 561 562 test_open_next_glyph (); 563 g = MainWindow.get_current_glyph (); 564 565 p.add (-10, 10); 566 p.add (10, 10); 567 p.add (10, -10); 568 p.add (-10, -10); 569 p.close (); 570 g.add_path (p); 571 572 MenuTab.preview (); 573 574 // TODO: run this many times on big font 575 for (int i = 0; i < 100; i++) { 576 MainWindow.get_tab_bar ().select_tab_name ("Files"); 577 Tool.yield (); 578 579 MainWindow.get_tab_bar ().select_tab_name ("Preview"); 580 Tool.yield (); 581 } 582 583 } 584 585 public static void test_convert_to_quadratic_bezier_path () { 586 Glyph g; 587 Path p, p1; 588 EditPoint e0, e1, e2, e3; 589 List<Path> paths = new List<Path> (); 590 591 // convert the current path 592 g = MainWindow.get_current_glyph (); 593 594 foreach (Path path in g.get_all_paths ()) { 595 paths.append (path.get_quadratic_points ()); 596 paths.append (path.copy ()); 597 } 598 599 // create a new path and convert it 600 test_open_next_glyph (); 601 602 p = new Path (); 603 p1 = new Path (); 604 605 g = MainWindow.get_current_glyph (); 606 607 p.add (-10, 10); 608 p.add (10, 10); 609 p.add (10, -10); 610 p.add (-10, -10); 611 p.close (); 612 g.add_path (p); 613 g.add_path (p1.get_quadratic_points ()); 614 615 e0 = new EditPoint (20, 40); 616 e1 = new EditPoint (40, 40); 617 e2 = new EditPoint (40, 20); 618 e3 = new EditPoint (20, 20); 619 620 p1.add_point (e0); 621 p1.add_point (e1); 622 p1.add_point (e2); 623 p1.add_point (e3); 624 p1.close (); 625 626 e0.set_tie_handle (true); 627 e1.set_tie_handle (true); 628 e2.set_tie_handle (true); 629 e3.set_tie_handle (true); 630 631 e0.process_tied_handle (); 632 e1.process_tied_handle (); 633 e2.process_tied_handle (); 634 e3.process_tied_handle (); 635 636 g.add_path (p1); 637 g.add_path (p1.get_quadratic_points ()); 638 639 foreach (Path path in paths) { 640 g.add_path (path); 641 } 642 } 643 644 public static void test_overview () { 645 OverView o = MainWindow.get_overview (); 646 647 warn_if_fail (o.selected_char_is_visible ()); 648 649 for (int i = 0; i < 10; i++) { 650 o.key_down (); 651 warn_if_fail (o.selected_char_is_visible ()); 652 } 653 654 for (int i = 0; i < 15; i++) { 655 o.key_up (); 656 warn_if_fail (o.selected_char_is_visible ()); 657 } 658 659 for (int i = 0; i < 6; i++) { 660 o.key_down (); 661 warn_if_fail (o.selected_char_is_visible ()); 662 } 663 664 for (int i = 0; i < 3; i++) { 665 o.key_down (); 666 warn_if_fail (o.selected_char_is_visible ()); 667 } 668 669 for (int i = 0; i < 2000; i++) { 670 o.scroll_adjustment (5); 671 } 672 673 for (int i = 0; i < 2000; i++) { 674 o.scroll_adjustment (-5); 675 } 676 } 677 678 public static void test_data_reader () { 679 FontData fd = new FontData (); 680 uint len; 681 int v; 682 683 try { 684 fd.add (7); 685 fd.add_ulong (0x5F0F3CF5); 686 fd.add_ulong (9); 687 688 warn_if_fail (fd.table_data[0] == 7); 689 warn_if_fail (fd.read () == 7); 690 warn_if_fail (fd.read_ulong () == 0x5F0F3CF5); 691 warn_if_fail (fd.read_ulong () == 9); 692 693 fd = new FontData (); 694 for (int16 i = 0; i < 2048; i++) { 695 fd.add_short (i); 696 } 697 698 fd.seek (2 * 80); 699 warn_if_fail (fd.read_short () == 80); 700 701 fd.seek (100); 702 fd.add_short (7); 703 fd.seek (100); 704 warn_if_fail (fd.read_short () == 7); 705 706 fd.seek_end (); 707 len = fd.length (); 708 fd.add (0); 709 warn_if_fail (len + 1 == fd.length ()); 710 711 fd.seek_end (); 712 for (int i = -1131; i < 1131; i++) { 713 fd.add_charstring_value (i); 714 } 715 716 for (int i = -1131; i < 1131; i++) { 717 v = fd.read_charstring_value (); 718 if (v != i) { 719 warning (@"expecting $i got $v\n"); 720 } 721 } 722 723 } catch (GLib.Error e) { 724 warning (e.message); 725 } 726 } 727 728 729 public static void test_argument () { 730 Argument arg = new Argument ("supplement -t \"Argument list\" --unknown -unknown --help -s"); 731 732 return_if_fail (arg.has_argument ("--test")); 733 return_if_fail ((!) arg.get_argument ("--test") == "\"Argument list\"" ); 734 return_if_fail (arg.has_argument ("--unknown")); 735 return_if_fail (arg.has_argument ("--help")); 736 return_if_fail (arg.has_argument ("--slow")); 737 return_if_fail (arg.validate () != 0); 738 739 arg = new Argument ("supplement --test \"Argument list\""); 740 return_if_fail ((!) arg.get_argument ("--test") == "\"Argument list\"" ); 741 return_if_fail (!arg.has_argument ("--help")); 742 return_if_fail (!arg.has_argument ("--slow")); 743 return_if_fail (arg.validate () == 0); 744 745 } 746 747 public static void test_glyph_ranges () { 748 GlyphRange gr = new GlyphRange (); 749 GlyphRange gr_az = new GlyphRange (); 750 751 gr.add_range ('b', 'c'); 752 gr.add_single ('d'); 753 gr.add_range ('e', 'h'); 754 gr.add_range ('k', 'm'); 755 gr.add_range ('o', 'u'); 756 gr.add_range ('a', 'd'); 757 gr.add_range ('f', 'z'); 758 gr.add_range ('b', 'd'); 759 760 gr.print_all (); 761 762 return_if_fail (gr.length () == 'z' - 'a' + 1); 763 return_if_fail (gr.get_ranges ().size == 1); 764 return_if_fail (gr.get_ranges ().get (0).length () == 'z' - 'a' + 1); 765 766 for (unichar i = 'a'; i <= 'z'; i++) { 767 uint index = i - 'a'; 768 string c = gr.get_char (index); 769 StringBuilder s = new StringBuilder (); 770 s.append_unichar (i); 771 772 if (c != s.str) { 773 warning (@"wrong glyph in glyph range got \"$c\" expected \"$(s.str)\" for index $(index)."); 774 } 775 } 776 777 gr = new GlyphRange (); 778 gr.add_single ('a'); 779 gr.add_range ('c', 'e'); 780 gr.add_single ('◊'); 781 return_if_fail (gr.get_char (0) == "a"); 782 return_if_fail (gr.get_char (1) == "c"); 783 return_if_fail (gr.get_char (2) == "d"); 784 return_if_fail (gr.get_char (3) == "e"); 785 return_if_fail (gr.get_char (4) == "◊"); 786 787 // a-z 788 gr_az.add_range ('a', 'z'); 789 if (!gr_az.has_character ("g")) { 790 warning ("Can not g in range a-z "); 791 } 792 793 if (gr_az.has_character ("å")) { 794 warning ("Range a-z has å"); 795 } 796 797 // codepage test for Latin 2 798 try { 799 gr = new GlyphRange (); 800 gr.parse_ranges ("- Ç ü-ý é á-â ä Ů-ű ç Ł-ń ë Ő-ő í-î Ä É Ĺ-ĺ ó-ô ö-÷ Ľ-ľ Ö-× Ü-Ý ú Ź-ž Ę-ě «-­ » ░-▓ │ ┤ Á-Â ╣ ═-║ ╗ ╝ ┐ └ ┴ ┬ ├ ─ ┼ Ă-ć ╚ ╔ ╩ ╦ ╠ ╬ ¤ Č-đ Ë Ň-ň Í-Î ┘ ┌ █ ▄ Ş-ť ▀ Ó-Ô ß Ŕ-ŕ Ú ´ ˝ ˛ ˇ ˘-˙ §-¨ ¸ ° Ř-ś ■  "); 801 if (!gr.has_character ("Ă")) { 802 warning ("Latin 2 range does not have Ă"); 803 } 804 805 if (!gr.has_unichar ('Ă')) { 806 warning ("Latin 2 range does not have Ă"); 807 } 808 809 if (!gr.has_unichar ('ó')) { 810 warning ("Latin 2 range does not have ó"); 811 } 812 } catch (MarkupError e) { 813 warning (e.message); 814 } 815 } 816 817 public static void test_hex () { 818 test_hex_conv ('H', "U+48", 72); 819 test_hex_conv ('1', "U+31", 49); 820 test_hex_conv ('å', "U+e5", 229); 821 test_hex_conv ('◊', "U+25ca", 9674); 822 } 823 824 private static void test_hex_conv (unichar h, string sr, int r) { 825 string s = Font.to_hex (h); 826 unichar t = Font.to_unichar (sr); 827 828 if (s != sr) warning (@"($s != \"$sr\")"); 829 if ((int)t != r || t != h) warning (@"$((int)t) != $r || $t != '$h'"); 830 } 831 832 // test pen tool 833 /** Draw a test glyph. */ 834 public static void test_drawing () { 835 Tool pen_tool = MainWindow.get_toolbox ().get_tool ("pen_tool"); 836 837 test_select_action (pen_tool); 838 839 test_open_next_glyph (); 840 841 // paint 842 test_click_action (pen_tool, 1, 30, 30); 843 test_click_action (pen_tool, 1, 60, 30); 844 test_click_action (pen_tool, 1, 60, 60); 845 test_click_action (pen_tool, 1, 30, 60); 846 847 // close 848 test_click_action (pen_tool, 3, 0, 0); 849 850 // reopen 851 test_click_action (pen_tool, 3, 35, 35); 852 853 // move around 854 test_move_action (pen_tool, 100, 200); 855 test_move_action (pen_tool, 20, 300); 856 test_move_action (pen_tool, 0, 0); 857 858 // add to path 859 test_move_action (pen_tool, 70, 50); 860 861 test_click_action (pen_tool, 1, 70, 50); 862 test_click_action (pen_tool, 1, 70, 50); 863 test_click_action (pen_tool, 1, 70, 100); 864 test_click_action (pen_tool, 1, 50, 100); 865 test_click_action (pen_tool, 1, 50, 50); 866 867 // close 868 test_click_action (pen_tool, 3, 0, 0); 869 Tool.yield (); 870 } 871 872 /** Test path coordinates and reverse path coordinates. */ 873 public static void test_coordinates () { 874 int x, y, xc, yc; 875 double px, py, mx, my; 876 string n; 877 Tool pen_tool = MainWindow.get_toolbox ().get_tool ("pen_tool"); 878 879 test_open_next_glyph (); 880 Glyph g = MainWindow.get_current_glyph (); 881 882 xc = (int) (g.allocation.width / 2.0); 883 yc = (int) (g.allocation.height / 2.0); 884 885 g.default_zoom (); 886 887 x = 10; 888 y = 15; 889 890 px = Glyph.path_coordinate_x (x); 891 py = Glyph.path_coordinate_y (y); 892 893 mx = x * Glyph.ivz () - Glyph.xc () + g.view_offset_x; 894 my = Glyph.yc () - y * Glyph.ivz () - g.view_offset_y; 895 896 if (mx != px || my != py) { 897 warning (@"bad coordinate $mx != $px || $my != $py"); 898 } 899 900 test_reverse_coordinate (x, y, px, py, "ten fifteen"); 901 test_click_action (pen_tool, 1, x, y); 902 903 // offset no zoom 904 n = "Offset no zoom"; 905 g.reset_zoom (); 906 907 px = Glyph.path_coordinate_x (x); 908 py = Glyph.path_coordinate_y (y); 909 910 test_reverse_coordinate (x, y, px, py, n); 911 test_click_action (pen_tool, 1, x, y); 912 913 // close path 914 test_click_action (pen_tool, 3, x, y); 915 } 916 917 private static void test_reverse_coordinate (int x, int y, double px, double py, string n) { 918 if (x != Glyph.reverse_path_coordinate_x (px) || Glyph.reverse_path_coordinate_y (py) != y) { 919 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)"); 920 } 921 } 922 923 private static void test_last_is_clockwise (string name) { 924 bool d = ((!)MainWindow.get_current_glyph ().get_last_path ()).is_clockwise (); 925 926 if (!d) { 927 critical (@"\nPath $name is counter clockwise, in test_last_is_clockwise"); 928 } 929 930 } 931 932 private static bool test_reverse_last (string name) 933 requires (MainWindow.get_current_glyph ().get_last_path () != null) 934 { 935 Glyph g = MainWindow.get_current_glyph (); 936 Path p = (!) g.get_last_path (); 937 bool direction = p.is_clockwise (); 938 939 p.reverse (); 940 941 if (direction == p.is_clockwise ()) { 942 critical (@"Direction did not change after reverseing path \"$name\"\n"); 943 stderr.printf (@"Path length: $(p.points.size) \n"); 944 return false; 945 } 946 947 Tool.yield (); 948 return true; 949 } 950 951 class Point { 952 953 public int x; 954 public int y; 955 956 public Point (int x, int y) { 957 this.x = x; 958 this.y = y; 959 } 960 } 961 962 private static Point p (int x, int y) { 963 return new Point (x, y); 964 } 965 966 private static void test_triangle (Point a, Point b, Point c, string name = "") { 967 Tool pen_tool = MainWindow.get_toolbox ().get_tool ("pen_tool"); 968 969 Tool.yield (); 970 MainWindow.get_tab_bar ().select_overview (); 971 972 Tool.yield (); 973 MainWindow.get_overview ().open_current_glyph (); 974 975 test_select_action (pen_tool); 976 977 test_click_action (pen_tool, 3, a.x, a.y); 978 test_click_action (pen_tool, 3, b.x, b.y); 979 test_click_action (pen_tool, 3, c.x, c.y); 980 981 test_reverse_last (@"Triangle reverse \"$name\" ($(a.x), $(a.y)), ($(b.x), $(b.y)), ($(c.x), $(c.y)) failed."); 982 983 Tool.yield (); 984 } 985 986 private static void test_various_triangles () { 987 test_triangle (p (287, 261), p (155, 81), p (200, 104), "First"); 988 test_triangle (p (65, 100), p (168, 100), p (196, 177), "Second"); 989 test_triangle (p (132, 68), p (195, 283), p (195, 222), "Third"); 990 test_triangle (p (144, 267), p (147, 27), p (296, 267), "Fourth"); 991 } 992 993 public static void test_reverse_path () { 994 // open a new glyph 995 Tool pen_tool = MainWindow.get_toolbox ().get_tool ("pen_tool"); 996 997 Tool.yield (); 998 MainWindow.get_tab_bar ().select_overview (); 999 1000 Tool.yield (); 1001 MainWindow.get_overview ().open_current_glyph (); 1002 1003 test_select_action (pen_tool); 1004 1005 // paint 1006 int x_offset = 10; 1007 int y_offset = 10; 1008 1009 test_open_next_glyph (); 1010 test_various_triangles (); 1011 1012 test_open_next_glyph (); 1013 // draw clockwise and check direction 1014 1015 y_offset += 160; 1016 test_click_action (pen_tool, 3, 10 + x_offset, 20 + y_offset); 1017 test_click_action (pen_tool, 3, 17 + x_offset, 17 + y_offset); 1018 test_click_action (pen_tool, 3, 20 + x_offset, 0 + y_offset); 1019 test_click_action (pen_tool, 2, 0, 0); 1020 test_last_is_clockwise ("Clockwise triangle 1.2"); 1021 1022 // draw paths clockwise / counter clockwise and reverse them 1023 1024 test_click_action (pen_tool, 3, 115, 137); 1025 test_click_action (pen_tool, 3, 89, 74); 1026 test_click_action (pen_tool, 3, 188, 232); 1027 test_click_action (pen_tool, 2, 0, 0); 1028 test_reverse_last ("Triangle 0"); 1029 1030 // draw incomplete paths 1031 y_offset += 20; 1032 test_click_action (pen_tool, 3, 10 + x_offset, 20 + y_offset); 1033 test_reverse_last ("Point"); 1034 test_click_action (pen_tool, 2, 0, 0); 1035 1036 y_offset += 20; 1037 test_click_action (pen_tool, 3, 10 + x_offset, 20 + y_offset); 1038 test_click_action (pen_tool, 3, 10 + x_offset, 20 + y_offset); 1039 test_reverse_last ("Double point"); 1040 test_click_action (pen_tool, 2, 0, 0); 1041 1042 y_offset += 20; 1043 test_click_action (pen_tool, 3, 10 + x_offset, 30 + y_offset); 1044 test_click_action (pen_tool, 3, 10 + x_offset, 20 + y_offset); 1045 test_reverse_last ("Vertical line"); 1046 test_click_action (pen_tool, 2, 0, 0); 1047 1048 y_offset += 20; 1049 test_click_action (pen_tool, 1, 30 + x_offset, 20 + y_offset); 1050 test_click_action (pen_tool, 1, 10 + x_offset, 20 + y_offset); 1051 test_click_action (pen_tool, 3, 0, 0); 1052 test_reverse_last ("Horisontal line"); 1053 test_click_action (pen_tool, 2, 0, 0); 1054 1055 // triangle 1 1056 y_offset += 20; 1057 test_click_action (pen_tool, 3, 10 + x_offset, -10 + y_offset); 1058 test_click_action (pen_tool, 3, 20 + x_offset, 20 + y_offset); 1059 test_click_action (pen_tool, 3, 30 + x_offset, 0 + y_offset); 1060 test_reverse_last ("Triangle reverse 1"); 1061 test_click_action (pen_tool, 2, 0, 0); 1062 1063 // box 1064 y_offset += 20; 1065 test_click_action (pen_tool, 3, 100 + x_offset, 150 + y_offset); 1066 test_click_action (pen_tool, 3, 150 + x_offset, 150 + y_offset); 1067 test_click_action (pen_tool, 3, 150 + x_offset, 100 + y_offset); 1068 test_click_action (pen_tool, 3, 100 + x_offset, 100 + y_offset); 1069 test_reverse_last ("Box 1"); 1070 test_click_action (pen_tool, 2, 0, 0); 1071 } 1072 1073 private static Tool select_pen () { 1074 Tool pen_tool = MainWindow.get_toolbox ().get_tool ("pen_tool"); 1075 test_select_action (pen_tool); 1076 return pen_tool; 1077 } 1078 1079 public static void test_delete_points () { 1080 PenTool pen; 1081 1082 test_open_next_glyph (); 1083 1084 pen = (PenTool) select_pen (); 1085 1086 // draw a line with ten points 1087 for (int i = 1; i <= 10; i++) { 1088 test_click_action (pen, 3, 20*i, 20); 1089 } 1090 1091 // TODO: it would be nice to test if points were created here 1092 1093 // delete points 1094 for (int i = 1; i <= 10; i++) { 1095 test_move_action (pen, 20 * i, 20); 1096 test_click_action (pen, 1, 20*i, 20); 1097 PenTool.delete_selected_points (); 1098 } 1099 } 1100 1101 public static void test_reverse_random_triangles () { 1102 Tool pen; 1103 1104 int ax, bx, cx; 1105 int ay, by, cy; 1106 1107 bool r = true; 1108 1109 test_open_next_glyph (); 1110 pen = select_pen (); 1111 1112 for (int i = 0; i < 30; i++) { 1113 Tool.yield (); 1114 1115 ax = Random.int_range (0, 300); 1116 bx = Random.int_range (0, 300); 1117 cx = Random.int_range (0, 300); 1118 1119 ay = Random.int_range (0, 300); 1120 by = Random.int_range (0, 300); 1121 cy = Random.int_range (0, 300); 1122 1123 test_click_action (pen, 3, ax, ay); 1124 test_click_action (pen, 3, bx, by); 1125 test_click_action (pen, 3, cx, cy); 1126 test_click_action (pen, 2, 0, 0); 1127 1128 r = test_reverse_last (@"Random triangle № $(i + 1) ($ax, $ay), ($bx, $by), ($cx, $cy)"); 1129 if (!r) { 1130 test_open_next_glyph (); 1131 pen = select_pen (); 1132 1133 test_click_action (pen, 3, ax, ay); 1134 test_click_action (pen, 3, bx, by); 1135 test_click_action (pen, 3, cx, cy); 1136 test_click_action (pen, 2, 0, 0); 1137 1138 return; 1139 } 1140 1141 test_open_next_glyph (); 1142 } 1143 1144 if (r) test_open_next_glyph (); 1145 } 1146 1147 1148 /** Help function to test button press actions. */ 1149 public static void test_click_action (Tool t, int b, int x, int y) { 1150 Tool.yield (); 1151 t.press_action (t, b, x, y); 1152 1153 Tool.yield (); 1154 t.release_action (t, b, x, y); 1155 } 1156 1157 /** Help function to test select action for this tool. */ 1158 public static void test_select_action (Tool t) { 1159 Toolbox tb = MainWindow.get_toolbox (); 1160 Tool.yield (); 1161 tb.select_tool (t); 1162 } 1163 1164 public static void test_move_action (Tool t, int x, int y) { 1165 Tool.yield (); 1166 t.move_action (t, x, y); 1167 } 1168 1169 public static void test_open_next_glyph () { 1170 OverView o = MainWindow.get_overview (); 1171 1172 MainWindow.get_tab_bar ().select_overview (); 1173 Toolbox.select_tool_by_name ("utf_8"); 1174 Tool.yield (); 1175 1176 o.select_next_glyph (); 1177 Tool.yield (); 1178 1179 o.open_current_glyph (); 1180 Tool.yield (); 1181 } 1182 1183 private static void test_boundaries () { 1184 Preferences.draw_boundaries = true; 1185 } 1186 1187 private static void test_raster_path () { 1188 Glyph g = MainWindow.get_current_glyph (); 1189 PathList pl = new PathList (); 1190 Path path; 1191 1192 test_open_next_glyph (); 1193 test_inkscape_import (); // draw somee thing 1194 1195 foreach (Path p in g.get_all_paths ()) { 1196 path = new Path (); 1197 p.all_of_path ((cx, cy, ct) => { 1198 path.add (cx, cy); 1199 return true; 1200 }); 1201 pl.add (path); 1202 } 1203 1204 test_open_next_glyph (); 1205 1206 foreach (Path p in pl.paths) { 1207 g.add_path (p); 1208 } 1209 } 1210 1211 private static void test_file_path () { 1212 Font f = new Font (); 1213 File file; 1214 string folder; 1215 1216 f.font_file = "E:\\Typeface.bf"; 1217 folder = f.get_folder_path (); 1218 if (folder != "E:") { 1219 warning (@"Wrong folder, $folder"); 1220 } 1221 1222 f.font_file = "/home/user/Typeface.bf"; 1223 folder = f.get_folder_path (); 1224 if (folder != "/home/user") { 1225 warning (@"Wrong folder, $folder"); 1226 } 1227 1228 f.font_file = "./Typeface.bf"; 1229 file = File.new_for_path ("."); 1230 folder = f.get_folder_path (); 1231 if (((!)file.get_path ()) != folder) { 1232 warning (@"Wrong folder, $folder"); 1233 } 1234 1235 f.font_file = "./Typeface.bf"; 1236 folder = f.get_folder_path (); 1237 if (!folder.has_prefix ("/")) { 1238 warning (@"Wrong folder, $folder"); 1239 } 1240 } 1241 1242 static void test_xml () { 1243 Tag root; 1244 XmlParser parser; 1245 1246 parser = new XmlParser ("""<g><g><g></g><g><g></g></g></g></g>"""); 1247 1248 root = parser.get_root_tag (); 1249 print_tags (root); 1250 1251 if (parser.validate ()) { 1252 root = parser.get_root_tag (); 1253 print_tags (root); 1254 } else { 1255 warning ("Invalid XML code."); 1256 } 1257 } 1258 1259 static void print_tags (Tag tag) { 1260 print (tag.get_name ()); 1261 print ("\n"); 1262 print_attributes (tag); 1263 print (tag.get_content ()); 1264 1265 foreach (Tag t in tag) { 1266 print_tags (t); 1267 } 1268 } 1269 1270 static void print_attributes (Tag tag) { 1271 Attributes attributes = tag.get_attributes (); 1272 foreach (Attribute attribute in attributes) { 1273 print ("\t"); 1274 print (attribute.get_name ()); 1275 print ("\n"); 1276 } 1277 } 1278 1279 } 1280 1281 } 1282