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

Revisions

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