The Birdfont Source Code


All Repositories / birdfont.git / blob – RSS feed

Glyph.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/Glyph.vala.
Redraw after switching from rsb to lsb in spacing tab
1 /* 2 Copyright (C) 2012 - 2016 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 Cairo; 16 using Math; 17 using Gee; 18 19 namespace BirdFont { 20 21 public class Glyph : FontDisplay { 22 23 // Background image 24 BackgroundImage? background_image = null; 25 bool background_image_visible = true; 26 27 // Glyph zoom level 28 public double view_zoom = 0.1; 29 30 public double view_offset_x = 0; 31 public double view_offset_y = 0; 32 Gee.ArrayList<ZoomView> zoom_list = new Gee.ArrayList<ZoomView> (); 33 int zoom_list_index = 0; 34 35 // The point where edit event begun 36 double pointer_begin_x = 0; 37 double pointer_begin_y = 0; 38 39 // Tap last tap event position in pixels 40 int last_tap0_y = 0; 41 int last_tap0_x = 0; 42 int last_tap1_y = 0; 43 int last_tap1_x = 0; 44 double zoom_distance = 0; 45 bool change_view; 46 47 bool ignore_input = false; 48 49 // Current pointer position 50 public double motion_x = 0; 51 public double motion_y = 0; 52 53 // Zoom area 54 public double zoom_x1 = 0; 55 public double zoom_y1 = 0; 56 public double zoom_x2 = 0; 57 public double zoom_y2 = 0; 58 public bool zoom_area_is_visible = false; 59 60 bool view_is_moving = false; 61 public double move_offset_x = 0; 62 public double move_offset_y = 0; 63 bool move_canvas = false; 64 65 public WidgetAllocation allocation = new WidgetAllocation (); 66 67 // FIXME: name and unichar should be moved to to glyph collection 68 public unichar unichar_code = 0; 69 public string name; 70 71 public double left_limit { 72 get { 73 return _left_limit; 74 } 75 76 set { 77 ttf_data = null; 78 _left_limit = value; 79 } 80 } 81 82 public double right_limit { 83 get { 84 return _right_limit; 85 } 86 87 set { 88 ttf_data = null; 89 _right_limit = value; 90 } 91 } 92 93 private double _right_limit = 0; 94 private double _left_limit = 0; 95 96 // x-height, lsb, etc. 97 public Gee.ArrayList<Line> vertical_help_lines = new Gee.ArrayList<Line> (); 98 public Gee.ArrayList<Line> horizontal_help_lines = new Gee.ArrayList<Line> (); 99 public bool show_help_lines = true; 100 bool xheight_lines_visible = false; 101 bool margin_boundaries_visible = false; 102 string new_guide_name = ""; 103 104 Gee.ArrayList<Glyph> undo_list = new Gee.ArrayList<Glyph> (); 105 Gee.ArrayList<Glyph> redo_list = new Gee.ArrayList<Glyph> (); 106 107 string glyph_sequence = ""; 108 bool open = true; 109 110 public static Glyph? background_glyph = null; 111 112 bool empty = false; 113 114 /** Id in the version list. */ 115 public int version_id = 0; 116 117 /** Cache quadratic form on export. */ 118 GlyfData? ttf_data = null; 119 120 Line left_line; 121 Line right_line; 122 123 /** Cache for Cairo surface rendering */ 124 HashMap<string, Surface> glyph_cache = new HashMap<string, Surface> (); 125 126 public const double CANVAS_MIN = -10000; 127 public const double CANVAS_MAX = 10000; 128 129 public static bool show_orientation_arrow = false; 130 public static double orientation_arrow_opacity = 1; 131 132 public Layer layers = new Layer (); 133 public int current_layer = 0; 134 public Gee.ArrayList<Path> active_paths = new Gee.ArrayList<Path> (); 135 public Gee.ArrayList<Layer> selected_groups = new Gee.ArrayList<Layer> (); 136 137 // used if this glyph is fetched from a fallback font 138 public double top_limit = 0; 139 public double baseline = 0; 140 public double bottom_limit = 0; 141 142 public Surface? overview_thumbnail = null; 143 144 public Glyph (string name, unichar unichar_code = 0) { 145 this.name = name; 146 this.unichar_code = unichar_code; 147 148 add_help_lines (); 149 150 left_limit = -28; 151 right_limit = 28; 152 } 153 154 public Glyph.no_lines (string name, unichar unichar_code = 0) { 155 this.name = name; 156 this.unichar_code = unichar_code; 157 } 158 159 public Gee.ArrayList<Path> get_active_paths () { 160 return active_paths; 161 } 162 163 public Layer get_current_layer () { 164 return_val_if_fail (0 <= current_layer < layers.subgroups.size, new Layer ()); 165 return layers.subgroups.get (current_layer); 166 } 167 168 public void set_current_layer (Layer layer) { 169 int i = 0; 170 foreach (Layer l in layers.subgroups) { 171 if (likely (l == layer)) { 172 current_layer = i; 173 return; 174 } 175 i++; 176 } 177 178 warning ("Layer is not added to glyph."); 179 } 180 181 public Gee.ArrayList<Path> get_visible_paths () { 182 return layers.get_visible_paths ().paths; 183 } 184 185 public PathList get_visible_path_list () { 186 return layers.get_visible_paths (); 187 } 188 189 public Gee.ArrayList<Path> get_paths_in_current_layer () { 190 return get_current_layer ().get_all_paths ().paths; 191 } 192 193 public Gee.ArrayList<Path> get_all_paths () { 194 return layers.get_all_paths ().paths; 195 } 196 197 public void add_new_layer () { 198 layers.add_layer (new Layer ()); 199 current_layer = layers.subgroups.size - 1; 200 } 201 202 public int get_layer_index (Layer layer) { 203 return layers.index_of (layer); 204 } 205 206 public GlyfData get_ttf_data () { 207 if (ttf_data == null) { 208 209 ttf_data = new GlyfData (this); 210 } 211 212 return (!) ttf_data; 213 } 214 215 public PathList get_quadratic_paths () { 216 PointConverter pc; 217 PathList pl; 218 PathList stroke; 219 220 pl = new PathList (); 221 222 foreach (Path p in get_visible_paths ()) { 223 if (p.stroke > 0) { 224 stroke = p.get_completed_stroke (); 225 foreach (Path stroke_part in stroke.paths) { 226 pc = new PointConverter (stroke_part); 227 pl.add (pc.get_quadratic_path ()); 228 } 229 } else { 230 pc = new PointConverter (p); 231 pl.add (pc.get_quadratic_path ()); 232 } 233 } 234 235 return pl; 236 } 237 238 public override void close () { 239 undo_list.clear (); 240 redo_list.clear (); 241 } 242 243 public void set_empty_ttf (bool e) { 244 empty = e; 245 } 246 247 public bool is_empty_ttf () { 248 return empty; 249 } 250 251 public void clear_active_paths () { 252 selected_groups.clear (); 253 active_paths.clear (); 254 } 255 256 public void add_active_path (Layer? group, Path? p) { 257 Path path; 258 Layer g; 259 260 if (p != null) { 261 path = (!) p; 262 263 if (Toolbox.get_move_tool ().is_selected ()) { 264 if (path.stroke > 0) { 265 Toolbox.set_object_stroke (path.stroke); 266 } 267 } 268 269 if (!active_paths.contains (path)) { 270 active_paths.add (path); 271 } 272 PenTool.active_path = path; 273 } 274 275 if (group != null) { 276 g = (!) group; 277 if (!selected_groups.contains (g)) { 278 selected_groups.add (g); 279 } 280 } 281 } 282 283 public void delete_background () { 284 store_undo_state (); 285 background_image = null; 286 GlyphCanvas.redraw (); 287 } 288 289 public Path? get_active_path () { 290 return_val_if_fail (active_paths.size > 0, null); 291 return active_paths.get (active_paths.size - 1); 292 } 293 294 public bool boundaries (out double x1, out double y1, out double x2, out double y2) { 295 var paths = get_all_paths (); 296 297 if (paths.size == 0) { 298 x1 = 0; 299 y1 = 0; 300 x2 = 0; 301 y2 = 0; 302 return false; 303 } 304 305 x1 = CANVAS_MAX; 306 x2 = CANVAS_MIN; 307 y1 = CANVAS_MAX; 308 y2 = CANVAS_MIN; 309 310 foreach (Path p in paths) { 311 p.update_region_boundaries (); 312 313 if (p.points.size > 1) { 314 if (p.xmin < x1) { 315 x1 = p.xmin; 316 } 317 318 if (p.xmax > x2) { 319 x2 = p.xmax; 320 } 321 322 if (p.ymin < y1) { 323 y1 = p.ymin; 324 } 325 326 if (p.ymax > y2) { 327 y2 = p.ymax; 328 } 329 } 330 } 331 332 return x1 != double.MAX; 333 } 334 335 public void selection_boundaries (out double x, out double y, out double w, out double h) { 336 double px, py, px2, py2; 337 338 px = 10000; 339 py = 10000; 340 px2 = -10000; 341 py2 = -10000; 342 343 foreach (Path p in active_paths) { 344 if (p.xmin < px) { 345 px = p.xmin; 346 } 347 348 if (p.ymin < py) { 349 py = p.ymin; 350 } 351 352 if (p.xmax > px2) { 353 px2 = p.xmax; 354 } 355 356 if (p.ymax > py2) { 357 py2 = p.ymax; 358 } 359 } 360 361 if (px2 == -10000 || px == 10000) { 362 warning (@"No box for selected paths. ($(active_paths.size))"); 363 px = 0; 364 py = 0; 365 px2 = 0; 366 py2 = 0; 367 } 368 369 x = px; 370 y = py2; 371 w = px2 - px; 372 h = py2 - py; 373 } 374 375 /** @return centrum pixel for x coordinates. */ 376 public static double xc () { 377 double c = MainWindow.get_current_glyph ().allocation.width / 2.0; 378 return c; 379 } 380 381 /** @return centrum pixel for y coordinates. */ 382 public static double yc () { 383 double c = MainWindow.get_current_glyph ().allocation.height / 2.0; 384 return c; 385 } 386 387 /** @return 1/view_zoom */ 388 public static double ivz () { 389 return 1 / MainWindow.get_current_glyph ().view_zoom; 390 } 391 392 public void resized (WidgetAllocation alloc) { 393 double a, b, c, d; 394 395 a = Glyph.path_coordinate_x (0); 396 b = Glyph.path_coordinate_y (0); 397 398 this.allocation = alloc; 399 400 c = Glyph.path_coordinate_x (0); 401 d = Glyph.path_coordinate_y (0); 402 403 view_offset_x -= c - a; 404 view_offset_y -= b - d; 405 } 406 407 public void set_background_image (BackgroundImage? b) { 408 BackgroundImage bg; 409 410 if (b == null) { 411 background_image = null; 412 } else { 413 bg = (!) b; 414 background_image = bg; 415 } 416 417 BirdFont.get_current_font ().touch (); 418 } 419 420 public BackgroundImage? get_background_image () { 421 return background_image; 422 } 423 424 public override void scroll_wheel (double x, double y, 425 double pixeldelta_x, double pixeldelta_y) { 426 427 if (KeyBindings.has_alt () || KeyBindings.has_ctrl ()) { 428 if (pixeldelta_y > 0) { 429 zoom_in_at_point (x, y, pixeldelta_y); 430 } else { 431 zoom_out_at_point (x, y, pixeldelta_y); 432 } 433 } else { 434 if (!KeyBindings.has_shift ()) { 435 view_offset_x -= pixeldelta_x / view_zoom; 436 view_offset_y -= pixeldelta_y / view_zoom; 437 } else { 438 // move canvas a long x axis instead of y 439 view_offset_x -= pixeldelta_y / view_zoom; 440 view_offset_y -= pixeldelta_x / view_zoom; 441 } 442 } 443 444 redraw_area (0, 0, allocation.width, allocation.height); 445 } 446 447 public virtual void add_path (Path p) { 448 if (layers.subgroups.size == 0) { 449 layers.add_layer (new Layer ()); 450 } 451 452 get_current_layer ().add_path (p); 453 } 454 455 public override void selected_canvas () { 456 TimeoutSource input_delay; 457 458 ttf_data = null; // recreate quatradic path on export 459 overview_thumbnail = null; 460 461 ignore_input = true; // make sure that tripple clicks in overview are ignored 462 463 input_delay = new TimeoutSource (250); 464 input_delay.set_callback(() => { 465 ignore_input = false; 466 return false; 467 }); 468 input_delay.attach (null); 469 470 add_help_lines (); 471 KeyBindings.set_require_modifier (false); 472 glyph_sequence = Preferences.get ("glyph_sequence"); 473 474 GridTool.update_lines (); 475 476 if (!is_null (MainWindow.native_window)) { 477 MainWindow.native_window.set_scrollbar_size (0); 478 } 479 480 update_zoom_bar (); 481 482 Font font = BirdFont.get_current_font (); 483 string index = font.settings.get_setting (@"Active Layer $(get_name ())"); 484 485 if (index != "") { 486 int i = int.parse (index); 487 488 if (0 <= i < layers.subgroups.size) { 489 current_layer = i; 490 } 491 } 492 493 DrawingTools.update_layers (); 494 MainWindow.get_toolbox ().update_expanders (); 495 } 496 497 void update_zoom_bar () { 498 if (!is_null (Toolbox.drawing_tools) 499 && !is_null (Toolbox.drawing_tools.zoom_bar)) { 500 Toolbox.drawing_tools.zoom_bar.set_zoom ((view_zoom - 1) / 20); 501 } 502 } 503 504 public void remove_lines () { 505 vertical_help_lines.clear (); 506 horizontal_help_lines.clear (); 507 } 508 509 public void add_help_lines () { 510 remove_lines (); 511 512 return_if_fail (!is_null (BirdFont.get_current_font ())); 513 514 double bgt = BirdFont.get_current_font ().top_limit; 515 Line top_margin_line = new Line ("top margin", t_("top margin"), bgt, false); 516 top_margin_line.set_color_theme ("Guide 2"); 517 top_margin_line.position_updated.connect ((pos) => { 518 BirdFont.get_current_font ().top_limit = pos; 519 }); 520 521 double thp = BirdFont.get_current_font ().top_position; 522 Line top_line = new Line ("top", t_("top"), thp, false); 523 top_line.position_updated.connect ((pos) => { 524 Font f = BirdFont.get_current_font (); 525 f.top_position = pos; 526 }); 527 528 double xhp = BirdFont.get_current_font ().xheight_position; 529 Line xheight_line = new Line ("x-height", t_("x-height"), xhp, false); 530 xheight_line.set_color_theme ("Guide 3"); 531 xheight_line.dashed = true; 532 xheight_line.position_updated.connect ((pos) => { 533 Font f = BirdFont.get_current_font (); 534 f.xheight_position = pos; 535 }); 536 537 double xbl = BirdFont.get_current_font ().base_line; 538 Line base_line = new Line ("baseline", t_("baseline"), xbl, false); 539 base_line.position_updated.connect ((pos) => { 540 Font f = BirdFont.get_current_font (); 541 f.base_line = pos; 542 }); 543 544 double bp = BirdFont.get_current_font ().bottom_position; 545 Line bottom_line = new Line ("bottom", t_("bottom"), bp, false); 546 bottom_line.position_updated.connect ((pos) => { 547 BirdFont.get_current_font ().bottom_position = pos; 548 }); 549 550 double bgb = BirdFont.get_current_font ().bottom_limit; 551 Line bottom_margin_line = new Line ("bottom margin", t_("bottom margin"), bgb, false); 552 bottom_margin_line.set_color_theme ("Guide 2"); 553 bottom_margin_line.position_updated.connect ((pos) => { 554 BirdFont.get_current_font ().bottom_limit = pos; 555 }); 556 557 left_line = new Line ("left", t_("left"), left_limit, true); 558 left_line.lsb = true; 559 left_line.position_updated.connect ((pos) => { 560 left_limit = pos; 561 update_other_spacing_classes (); 562 left_line.set_metrics (get_left_side_bearing ()); 563 }); 564 left_line.set_metrics (get_left_side_bearing ()); 565 566 right_line = new Line ("right", t_("right"), right_limit, true); 567 right_line.rsb = true; 568 right_line.position_updated.connect ((pos) => { 569 right_limit = pos; 570 update_other_spacing_classes (); 571 right_line.set_metrics (get_right_side_bearing ()); 572 }); 573 right_line.set_metrics (get_right_side_bearing ()); 574 575 // lists of lines are sorted and lines are added only if 576 // they are relevant for a particular glyph. 577 578 // left to right 579 add_line (left_line); 580 add_line (right_line); 581 582 bool glyph_has_top = has_top_line (); 583 584 // top to bottom 585 add_line (top_margin_line); 586 top_margin_line.set_visible (margin_boundaries_visible); 587 588 add_line (top_line); 589 top_line.set_visible (glyph_has_top || xheight_lines_visible); 590 591 add_line (xheight_line); 592 xheight_line.set_visible (!glyph_has_top || xheight_lines_visible); 593 594 add_line (base_line); 595 596 add_line (bottom_line); 597 bottom_line.set_visible (CharDatabase.has_descender (unichar_code) || xheight_lines_visible); 598 599 add_line (bottom_margin_line); 600 bottom_margin_line.set_visible (margin_boundaries_visible); 601 602 foreach (Line guide in BirdFont.get_current_font ().custom_guides) { 603 add_line (guide); 604 } 605 } 606 607 public double get_left_side_bearing () { 608 double x1, y1, x2, y2; 609 610 if (get_boundaries (out x1, out y1, out x2, out y2)) { 611 return x1 - left_limit; 612 } else { 613 return right_limit - left_limit; 614 } 615 } 616 617 public double get_right_side_bearing () { 618 double x1, y1, x2, y2; 619 620 if (get_boundaries (out x1, out y1, out x2, out y2)) { 621 return right_limit - x2; 622 } else { 623 return right_limit - left_limit; 624 } 625 } 626 627 public bool get_boundaries (out double x1, out double y1, 628 out double x2, out double y2) { 629 630 double max_x, min_x, max_y, min_y; 631 PathList pl; 632 var paths = get_all_paths (); 633 634 if (paths.size == 0) { 635 x1 = 0; 636 y1 = 0; 637 x2 = 0; 638 y2 = 0; 639 return false; 640 } 641 642 max_x = CANVAS_MIN; 643 min_x = CANVAS_MAX; 644 max_y = CANVAS_MIN; 645 min_y = CANVAS_MAX; 646 647 // FIXME: optimize 648 foreach (Path p in paths) { 649 650 if (p.stroke > 0) { 651 pl = p.get_stroke_fast (); 652 653 foreach (Path part in pl.paths) { 654 boundaries_for_path (part, ref min_x, ref max_x, ref min_y, ref max_y); 655 } 656 } else { 657 boundaries_for_path (p, ref min_x, ref max_x, ref min_y, ref max_y); 658 } 659 } 660 661 x1 = min_x; 662 y1 = max_y; 663 x2 = max_x; 664 y2 = min_y; 665 666 return max_x != CANVAS_MIN; 667 } 668 669 void boundaries_for_path (Path p, ref double min_x, ref double max_x, 670 ref double min_y, ref double max_y) { 671 672 double max_x2, max_y2, min_x2, min_y2; 673 674 max_x2 = max_x; 675 min_x2 = min_x; 676 max_y2 = max_y; 677 min_y2 = min_y; 678 679 p.all_of_path ((x, y, t) => { 680 if (x > max_x2) { 681 max_x2 = x; 682 } 683 684 if (y > max_y2) { 685 max_y2 = y; 686 } 687 688 if (x < min_x2) { 689 min_x2 = x; 690 } 691 692 if (y < min_y2) { 693 min_y2 = y; 694 } 695 696 return true; 697 }); 698 699 max_x = max_x2; 700 min_x = min_x2; 701 max_y = max_y2; 702 min_y = min_y2; 703 } 704 705 bool has_top_line () { 706 return !unichar_code.islower () || CharDatabase.has_ascender (unichar_code); 707 } 708 709 public bool get_show_help_lines () { 710 return show_help_lines; 711 } 712 713 /** Show both x-height and top lines. */ 714 public bool get_xheight_lines_visible () { 715 return xheight_lines_visible; 716 } 717 718 /** Show both x-height and top lines. */ 719 public void set_xheight_lines_visible (bool x) { 720 xheight_lines_visible = x; 721 add_help_lines (); 722 } 723 724 public void set_margin_lines_visible (bool m) { 725 margin_boundaries_visible = m; 726 add_help_lines (); 727 } 728 729 public bool get_margin_lines_visible () { 730 return margin_boundaries_visible; 731 } 732 733 public void remove_empty_paths () { 734 foreach (Path p in get_all_paths ()) { 735 if (p.points.size < 2) { 736 delete_path (p); 737 remove_empty_paths (); 738 return; 739 } 740 } 741 } 742 743 public void delete_path (Path p) { 744 layers.remove_path(p); 745 } 746 747 public string get_svg_data () { 748 return Svg.to_svg_glyph (this); 749 } 750 751 public int get_height () { 752 Font f = BirdFont.get_current_font (); 753 return (int) Math.fabs (f.top_limit - f.bottom_limit); 754 } 755 756 public double get_width () { 757 return Math.fabs (right_limit - left_limit); 758 } 759 760 public unichar get_unichar () { 761 return unichar_code; 762 } 763 764 public string get_unichar_string () { 765 string? s = (!)get_unichar ().to_string (); 766 767 if (unlikely (s == null)) { 768 warning ("Invalid character."); 769 return "".dup (); 770 } 771 772 return (!) s; 773 } 774 775 public void redraw_help_lines () { 776 redraw_area (0, 0, allocation.width, allocation.height); 777 } 778 779 public void set_show_help_lines (bool hl) { 780 show_help_lines = hl; 781 } 782 783 private void add_line (Line line) { 784 if (line.is_vertical ()) { 785 vertical_help_lines.add (line); 786 } else { 787 horizontal_help_lines.add (line); 788 } 789 790 sort_help_lines (); 791 792 line.queue_draw_area.connect ((x, y, w, h) => { 793 this.redraw_area (x, y, w, h); 794 }); 795 } 796 797 public void sort_help_lines () { 798 vertical_help_lines.sort ((a, b) => { 799 Line first, next; 800 first = (Line) a; 801 next = (Line) b; 802 return (int) (first.get_pos () - next.get_pos ()); 803 }); 804 805 horizontal_help_lines.sort ((a, b) => { 806 Line first, next; 807 first = (Line) a; 808 next = (Line) b; 809 return (int) (first.get_pos () - next.get_pos ()); 810 }); 811 } 812 813 public override string get_name () { 814 return name; 815 } 816 817 public override string get_label () { 818 return name; 819 } 820 821 private void help_line_event (int x, int y) { 822 bool m = false; 823 824 foreach (Line line in vertical_help_lines) { 825 if (!m && line.event_move_to (x, y, allocation)) { 826 m = true; 827 } 828 } 829 830 foreach (Line line in horizontal_help_lines) { 831 if (!m && line.event_move_to (x, y, allocation)) { 832 m = true; 833 } 834 } 835 } 836 837 public override void key_release (uint keyval) { 838 Tool t; 839 t = MainWindow.get_toolbox ().get_current_tool (); 840 t.key_release_action (t, keyval); 841 842 if (keyval == (uint)' ') { 843 move_canvas = false; 844 } 845 } 846 847 public override void key_press (uint keyval) { 848 Tool t = MainWindow.get_toolbox ().get_current_tool (); 849 t.key_press_action (t, keyval); 850 851 if (keyval == (uint)' ') { 852 move_canvas = true; 853 } 854 855 switch (keyval) { 856 case Key.NUM_PLUS: 857 zoom_in (); 858 break; 859 case Key.NUM_MINUS: 860 zoom_out (); 861 break; 862 } 863 } 864 865 /** Delete edit point from path. 866 * @return false if no points was deleted 867 */ 868 public bool process_deleted () { 869 Gee.ArrayList<Path> deleted_paths = new Gee.ArrayList<Path> (); 870 foreach (Path p in get_all_paths ()) { 871 if (p.points.size > 0) { 872 if (process_deleted_points_in_path (p)) { 873 return true; 874 } 875 } else { 876 deleted_paths.add (p); 877 } 878 } 879 880 foreach (Path p in deleted_paths) { 881 delete_path (p); 882 } 883 884 return false; 885 } 886 887 private bool process_deleted_points_in_path (Path p) { 888 PathList remaining_points; 889 remaining_points = p.process_deleted_points (); 890 foreach (Path path in remaining_points.paths) { 891 add_path (path); 892 path.reopen (); 893 path.create_list (); 894 895 add_active_path (null, path); 896 } 897 898 if (remaining_points.paths.size > 0) { 899 delete_path (p); 900 return true; 901 } 902 903 return false; 904 } 905 906 public override void motion_notify (double x, double y) { 907 Tool t = MainWindow.get_toolbox ().get_current_tool (); 908 909 if (view_is_moving) { 910 move_view_offset (x, y); 911 return; 912 } 913 914 help_line_event ((int) x, (int) y); 915 t.move_action (t, (int) x, (int) y); 916 917 motion_x = x * ivz () - xc () + view_offset_x; 918 motion_y = yc () - y * ivz () - view_offset_y; 919 } 920 921 public override void button_release (int button, double ex, double ey) { 922 bool line_moving = false; 923 view_is_moving = false; 924 925 foreach (Line line in get_all_help_lines ()) { 926 if (!line.set_move (false)) { 927 line_moving = true; 928 } 929 } 930 931 if (!line_moving) { 932 Tool t = MainWindow.get_toolbox ().get_current_tool (); 933 t.release_action (t, (int) button, (int) ex, (int) ey); 934 } 935 936 update_view (); 937 } 938 939 private Gee.ArrayList<Line> get_all_help_lines () { 940 Gee.ArrayList<Line> all_lines = new Gee.ArrayList<Line> (); 941 942 foreach (Line l in vertical_help_lines) { 943 all_lines.add (l); 944 } 945 946 foreach (Line l in horizontal_help_lines) { 947 all_lines.add (l); 948 } 949 950 if (GridTool.is_visible ()) { 951 foreach (Line l in GridTool.get_vertical_lines ()) { 952 all_lines.add (l); 953 } 954 955 foreach (Line l in GridTool.get_horizontal_lines ()) { 956 all_lines.add (l); 957 } 958 } 959 960 return all_lines; 961 } 962 963 public void update_view () { 964 GlyphCanvas.redraw (); 965 } 966 967 public override void double_click (uint button, double ex, double ey) { 968 Tool t = MainWindow.get_toolbox ().get_current_tool (); 969 t.double_click_action (t, (int) button, (int) ex, (int) ey); 970 } 971 972 public override void button_press (uint button, double ex, double ey) { 973 bool moving_lines = false; 974 975 pointer_begin_x = ex; 976 pointer_begin_y = ey; 977 978 foreach (Line line in horizontal_help_lines) { 979 if (!moving_lines && line.is_visible () && line.button_press (button)) { 980 moving_lines = true; 981 } 982 } 983 984 foreach (Line line in vertical_help_lines) { 985 if (!moving_lines && line.is_visible () && line.button_press (button)) { 986 moving_lines = true; 987 } 988 } 989 990 if (moving_lines) { 991 return; 992 } 993 994 if (move_canvas 995 || DrawingTools.move_canvas.is_selected () 996 || (KeyBindings.has_ctrl () && KeyBindings.has_shift ())) { 997 view_is_moving = true; 998 move_offset_x = view_offset_x; 999 move_offset_y = view_offset_y; 1000 } else { 1001 Tool t = MainWindow.get_toolbox ().get_current_tool (); 1002 t.press_action (t, (int) button, (int) ex, (int) ey); 1003 } 1004 } 1005 1006 /** Add new points to this path. */ 1007 public void set_active_path (Path p) { 1008 p.reopen (); 1009 clear_active_paths (); 1010 add_active_path (null, p); 1011 } 1012 1013 /** Move view port centrum to this coordinate. */ 1014 public void set_center (double x, double y) { 1015 x -= allocation.width / 2.0; 1016 y -= allocation.height / 2.0; 1017 1018 view_offset_x += x / view_zoom; 1019 view_offset_y += y / view_zoom; 1020 } 1021 1022 public void set_zoom_from_area () { 1023 double x = Math.fmin (zoom_x1, zoom_x2); 1024 double y = Math.fmin (zoom_y1, zoom_y2); 1025 1026 double w = Math.fabs (zoom_x1 - zoom_x2); 1027 double h = Math.fabs (zoom_y1 - zoom_y2); 1028 1029 double view_zoom_x, view_zoom_y; 1030 double ivz, off; 1031 1032 if (move_canvas) { 1033 return; 1034 } 1035 1036 if (Path.distance (x, x + w, y, y + h) < 7) { 1037 zoom_in (); 1038 } else { 1039 view_offset_x += x / view_zoom; 1040 view_offset_y += y / view_zoom; 1041 1042 if (unlikely (allocation.width == 0 || allocation.height == 0)) { 1043 return; 1044 } 1045 1046 view_zoom_x = allocation.width * view_zoom / w; 1047 view_zoom_y = allocation.height * view_zoom / h; 1048 1049 // TODO: there is a max zoom level 1050 1051 if (view_zoom_x * allocation.width < view_zoom_y * allocation.height) { 1052 view_zoom = view_zoom_x; 1053 ivz = 1 / view_zoom; 1054 1055 off = (view_zoom / view_zoom_y) * allocation.height / view_zoom; 1056 off = allocation.height/view_zoom - off; 1057 off /= 2; 1058 1059 view_offset_y -= off; 1060 1061 } else { 1062 view_zoom = view_zoom_y; 1063 ivz = 1 / view_zoom; 1064 1065 off = (view_zoom / view_zoom_x) * allocation.width / view_zoom; 1066 off = allocation.width / view_zoom - off; 1067 off /= 2; 1068 1069 view_offset_x -= off; 1070 } 1071 1072 zoom_area_is_visible = false; 1073 store_current_view (); 1074 } 1075 1076 update_zoom_bar (); 1077 } 1078 1079 public void show_zoom_area (int sx, int sy, int nx, int ny) { 1080 set_zoom_area (sx, sy, nx, ny); 1081 zoom_area_is_visible = true; 1082 GlyphCanvas.redraw (); 1083 } 1084 1085 public void set_zoom_area (int sx, int sy, int nx, int ny) { 1086 zoom_x1 = sx; 1087 zoom_y1 = sy; 1088 zoom_x2 = nx; 1089 zoom_y2 = ny; 1090 } 1091 1092 public static void validate_zoom () { 1093 Glyph g = MainWindow.get_current_glyph (); 1094 if (unlikely (g.view_zoom == 0)) { 1095 warning ("Zoom is zero."); 1096 g.reset_zoom (); 1097 1098 if (g.view_zoom == 0) { 1099 g.view_zoom = 1; 1100 g.view_offset_x = 0; 1101 g.view_offset_y = 0; 1102 } 1103 } 1104 } 1105 1106 public static double path_coordinate_x (double x) { 1107 Glyph g = MainWindow.get_current_glyph (); 1108 validate_zoom (); 1109 return x * ivz () - xc () + g.view_offset_x; 1110 } 1111 1112 public static int reverse_path_coordinate_x (double x) { 1113 Glyph g = MainWindow.get_current_glyph (); 1114 validate_zoom (); 1115 return (int) Math.rint ((x - g.view_offset_x + xc ()) * g.view_zoom); 1116 } 1117 1118 public static double precise_reverse_path_coordinate_x (double x) { 1119 Glyph g = MainWindow.get_current_glyph (); 1120 validate_zoom (); 1121 return (x - g.view_offset_x + xc ()) * g.view_zoom; 1122 } 1123 1124 public static double path_coordinate_y (double y) { 1125 Glyph g = MainWindow.get_current_glyph (); 1126 validate_zoom (); 1127 return yc () - y * ivz () - g.view_offset_y; 1128 } 1129 1130 public static int reverse_path_coordinate_y (double y) { 1131 Glyph g = MainWindow.get_current_glyph (); 1132 validate_zoom (); 1133 y = Math.rint ((y + g.view_offset_y - yc ()) * g.view_zoom); 1134 return (int) (-y); 1135 } 1136 1137 public static double precise_reverse_path_coordinate_y (double y) { 1138 Glyph g = MainWindow.get_current_glyph (); 1139 validate_zoom (); 1140 y = (y + g.view_offset_y - yc ()) * g.view_zoom; 1141 return -y; 1142 } 1143 1144 public Layer? get_path_at (double x, double y) { 1145 Layer? group = null; 1146 bool found = false; 1147 1148 foreach (Layer layer in get_current_layer ().subgroups) { 1149 foreach (Path pt in layer.paths.paths) { 1150 if (pt.is_over (x, y)) { 1151 found = true; 1152 group = layer; 1153 } 1154 } 1155 } 1156 1157 if (!found) { 1158 foreach (Path pt in get_paths_in_current_layer ()) { 1159 if (pt.is_over (x, y)) { 1160 Layer layer = new Layer (); 1161 layer.is_counter = true; 1162 layer.single_path = true; 1163 layer.add_path (pt); 1164 group = layer; 1165 } 1166 } 1167 } 1168 1169 return group; 1170 } 1171 1172 public bool select_path (double x, double y) { 1173 Path? p = null; 1174 bool found = false; 1175 1176 foreach (Path pt in get_paths_in_current_layer ()) { 1177 if (pt.is_over (x, y)) { 1178 p = pt; 1179 found = true; 1180 } 1181 } 1182 1183 if (!KeyBindings.has_shift ()) { 1184 clear_active_paths (); 1185 } 1186 1187 add_active_path (null, p); 1188 1189 return found; 1190 } 1191 1192 public bool is_over_selected_path (double x, double y) { 1193 foreach (Path pt in active_paths) { 1194 if (pt.is_over (x, y)) { 1195 return true; 1196 } 1197 } 1198 return false; 1199 } 1200 1201 public void queue_redraw_path (Path path) { 1202 redraw_path (path.xmin, path.ymin, path.xmax, path.ymax); 1203 } 1204 1205 private void redraw_path (double xmin, double ymin, double xmax, double ymax) { 1206 int yc = (int)(allocation.height / 2.0); 1207 1208 double yta = yc - ymin - view_offset_y; 1209 double ytb = yc - ymax - view_offset_y; 1210 1211 double xta = -view_offset_x - xmin; 1212 double xtb = -view_offset_x - xmax; 1213 1214 redraw_area ((int)xtb - 10, (int)yta - 10, (int)(xtb - xta) + 10, (int) (yta - ytb) + 10); 1215 } 1216 1217 public Path get_closeset_path (double x, double y) { 1218 double d; 1219 EditPoint ep = new EditPoint (); 1220 1221 Path min_point = new Path (); 1222 double min_distance = double.MAX; 1223 1224 double xt = path_coordinate_x (x); 1225 double yt = path_coordinate_y (y); 1226 var paths = get_visible_paths (); 1227 1228 foreach (Path p in paths) { 1229 if (p.is_over (xt, yt)) { 1230 return p; 1231 } 1232 } 1233 1234 foreach (Path p in paths) { 1235 if (p.points.size == 0) continue; 1236 1237 p.get_closest_point_on_path (ep, xt, yt); 1238 d = Math.pow (ep.x - xt, 2) + Math.pow (ep.y - yt, 2); 1239 1240 if (d < min_distance) { 1241 min_distance = d; 1242 min_point = p; 1243 } 1244 1245 } 1246 1247 // a path without any editpoints 1248 if (paths.size > 0) { 1249 return paths.get (0); 1250 } 1251 1252 if (unlikely (min_distance == double.MAX)) { 1253 warning (@"No path found in path_list."); 1254 } 1255 1256 return min_point; 1257 } 1258 1259 public void move_selected_edit_point_coordinates (EditPoint selected_point, double xt, double yt) { 1260 double x, y; 1261 1262 BirdFont.get_current_font ().touch (); 1263 1264 x = reverse_path_coordinate_x (xt); 1265 y = reverse_path_coordinate_y (yt); 1266 1267 // redraw control point 1268 redraw_area ((int)(x - 4*view_zoom), (int)(y - 4*view_zoom), (int)(x + 3*view_zoom), (int)(y + 3*view_zoom)); 1269 1270 // update position of selected point 1271 selected_point.set_position (xt, yt); 1272 1273 if (view_zoom >= 2) { 1274 redraw_area (0, 0, allocation.width, allocation.height); 1275 } else { 1276 redraw_last_stroke (x, y); 1277 } 1278 } 1279 1280 public void move_selected_edit_point (EditPoint selected_point, double x, double y) { 1281 double xt = path_coordinate_x (x); 1282 double yt = path_coordinate_y (y); 1283 move_selected_edit_point_coordinates (selected_point, xt, yt); 1284 } 1285 1286 public void redraw_segment (EditPoint a, EditPoint b) { 1287 double margin = 10; 1288 double x = Math.fmin (reverse_path_coordinate_x (a.x), reverse_path_coordinate_x (b.x)) - margin; 1289 double y = Math.fmin (reverse_path_coordinate_y (a.y), reverse_path_coordinate_y(b.y)) - margin; 1290 double w = Math.fabs (reverse_path_coordinate_x (a.x) - reverse_path_coordinate_x(b.x)) + 2 * margin; 1291 double h = Math.fabs (reverse_path_coordinate_y (a.y) - reverse_path_coordinate_y (b.y)) + 2 * margin; 1292 1293 redraw_area ((int)x, (int)y, (int)w, (int)h); 1294 } 1295 1296 private void redraw_last_stroke (double x, double y) { 1297 // redraw line, if we have more than one new point on path 1298 double px = 0; 1299 double py = 0; 1300 int tw = 0; 1301 int th = 0; 1302 1303 double xc = (allocation.width / 2.0); 1304 1305 if (active_paths.size == 0) { 1306 return; 1307 } 1308 1309 foreach (Path path in active_paths) { 1310 EditPoint p; 1311 EditPoint pl = path.get_last_point (); 1312 1313 if (pl.prev != null) { 1314 p = pl.get_prev (); 1315 1316 px = p.x + xc; 1317 py = p.y - xc; 1318 1319 tw = (px > x) ? (int) (px - x) : (int) (x - px); 1320 th = (py > y) ? (int) (py - y) : (int) (y - py); 1321 1322 if (px > x) px -= tw + 60; 1323 if (py > y) py -= th + 60; 1324 1325 } else { 1326 px = x - 60; 1327 py = y - 60; 1328 tw = 0; 1329 th = 0; 1330 } 1331 } 1332 1333 redraw_area ((int)px - 20, (int)py - 20, tw + 120, th + 120); 1334 } 1335 1336 public bool has_active_path () { 1337 return active_paths.size > 0; 1338 } 1339 1340 public bool is_open () { 1341 return open; 1342 } 1343 1344 /** Close all editable paths and return false if no path have been closed. */ 1345 public bool close_path () { 1346 bool r = false; 1347 1348 foreach (Path p in get_all_paths ()) { 1349 if (p.is_editable ()) { 1350 r = true; 1351 p.set_editable (false); 1352 } 1353 } 1354 1355 open = false; 1356 clear_active_paths (); 1357 GlyphCanvas.redraw (); 1358 1359 MainWindow.set_cursor (NativeWindow.VISIBLE); 1360 1361 return r; 1362 } 1363 1364 public void open_path () { 1365 foreach (Path p in get_visible_paths ()) { 1366 p.set_editable (true); 1367 p.recalculate_linear_handles (); 1368 1369 if (p.is_open () && p.points.size > 0) { 1370 p.get_first_point ().set_reflective_handles (false); 1371 p.get_first_point ().set_tie_handle (false); 1372 p.get_last_point ().set_reflective_handles (false); 1373 p.get_last_point ().set_tie_handle (false); 1374 } 1375 } 1376 1377 open = true; 1378 redraw_area (0, 0, allocation.width, allocation.height); 1379 } 1380 1381 public void redraw_path_region (Path p) { 1382 int x, y, w, h; 1383 1384 p.update_region_boundaries (); 1385 1386 x = reverse_path_coordinate_x (p.xmin); 1387 y = reverse_path_coordinate_x (p.xmin); 1388 w = reverse_path_coordinate_x (p.xmax) - x; 1389 h = reverse_path_coordinate_x (p.ymax) - y; // FIXME: redraw path 1390 1391 redraw_area (x, y, w, h); 1392 } 1393 1394 public Line get_line (string name) { 1395 foreach (Line line in vertical_help_lines) { 1396 if (likely (line.get_label () == name)) { 1397 return line; 1398 } 1399 } 1400 1401 foreach (Line line in horizontal_help_lines) { 1402 if (likely (line.get_label () == name)) { 1403 return line; 1404 } 1405 } 1406 1407 warning (@"No line with label $name found"); 1408 return new Line ("Err"); 1409 } 1410 1411 public override void zoom_in () { 1412 if (move_canvas) { 1413 return; 1414 } 1415 1416 set_zoom_area (10, 10, allocation.width - 10, allocation.height - 10); 1417 set_zoom_from_area (); 1418 update_view (); 1419 update_zoom_bar (); 1420 } 1421 1422 public override void zoom_out () { 1423 double w = allocation.width; 1424 int n = (int) (10 * ((w - 10) / allocation.width)); 1425 set_zoom_area (-n, -n, allocation.width + n, allocation.height + n); 1426 set_zoom_from_area (); 1427 update_view (); 1428 update_zoom_bar (); 1429 } 1430 1431 public override void zoom_max () { 1432 default_zoom (); 1433 update_zoom_bar (); 1434 } 1435 1436 public override void zoom_min () { 1437 double ax = 1000; 1438 double ay = 1000; 1439 double bx = -1000; 1440 double by = -1000; 1441 1442 int iax, iay, ibx, iby; 1443 1444 reset_zoom (); 1445 1446 foreach (var p in get_visible_paths ()) { 1447 p.update_region_boundaries (); 1448 1449 if (p.points.size > 2) { 1450 if (p.xmin < ax) ax = p.xmin; 1451 if (p.ymin < ay) ay = p.ymin; 1452 if (p.xmax > bx) bx = p.xmax; 1453 if (p.ymax > by) by = p.ymax; 1454 } 1455 } 1456 1457 if (ax == 1000) return; // empty page 1458 1459 iax = (int) ((ax + view_offset_x + allocation.width / 2.0) * view_zoom); 1460 iay = (int) ((-ay + view_offset_y + allocation.height / 2.0) * view_zoom); 1461 ibx = (int) ((bx + view_offset_x + allocation.width / 2.0) * view_zoom); 1462 iby = (int) ((-by + view_offset_y + allocation.height / 2.0) * view_zoom); 1463 1464 show_zoom_area (iax, iay, ibx, iby); // set this later on button release 1465 set_zoom_from_area (); 1466 zoom_out (); // add some margin 1467 1468 redraw_area (0, 0, allocation.width, allocation.height); 1469 update_zoom_bar (); 1470 } 1471 1472 public override void store_current_view () { 1473 ZoomView n; 1474 1475 if (zoom_list_index + 1 < zoom_list.size) { 1476 n = zoom_list.get (zoom_list_index); 1477 while (n != zoom_list.get (zoom_list.size - 1)) { 1478 zoom_list.remove_at (zoom_list.size - 1); 1479 } 1480 } 1481 1482 zoom_list.add (new ZoomView (view_offset_x, view_offset_y, view_zoom, allocation)); 1483 zoom_list_index = (int) zoom_list.size - 1; 1484 1485 if (zoom_list.size > 50) { 1486 zoom_list.remove_at (0); 1487 } 1488 } 1489 1490 public override void restore_last_view () { 1491 if (zoom_list.size == 0 || zoom_list_index - 1 < 0) { 1492 return; 1493 } 1494 1495 zoom_list_index--; 1496 1497 ZoomView z = zoom_list.get (zoom_list_index); 1498 1499 view_offset_x = z.x; 1500 view_offset_y = z.y; 1501 view_zoom = z.zoom; 1502 allocation = z.allocation; 1503 1504 update_zoom_bar (); 1505 } 1506 1507 public override void next_view () { 1508 ZoomView z; 1509 1510 if (zoom_list.size == 0 || zoom_list_index + 1 >= zoom_list.size) { 1511 return; 1512 } 1513 1514 zoom_list_index++; 1515 1516 z = zoom_list.get (zoom_list_index); 1517 1518 view_offset_x = z.x; 1519 view_offset_y = z.y; 1520 view_zoom = z.zoom; 1521 allocation = z.allocation; 1522 1523 update_zoom_bar (); 1524 } 1525 1526 public override void reset_zoom () { 1527 view_offset_x = 0; 1528 view_offset_y = 0; 1529 1530 set_zoom (1); 1531 1532 store_current_view (); 1533 update_zoom_bar (); 1534 } 1535 1536 /** Get x-height or top line. */ 1537 public Line get_upper_line () { 1538 if (has_top_line () || xheight_lines_visible) { 1539 return get_line ("top"); 1540 } 1541 1542 return get_line ("x-height"); 1543 } 1544 1545 /** Get base line. */ 1546 public Line get_lower_line () { 1547 return get_line ("baseline"); 1548 } 1549 1550 /** Set default zoom. See default_zoom. */ 1551 public void set_default_zoom () { 1552 int bottom = 0; 1553 int top = 0; 1554 int left = 0; 1555 int right = 0; 1556 1557 return_if_fail (vertical_help_lines.size != 0); 1558 return_if_fail (horizontal_help_lines.size != 0); 1559 1560 reset_zoom (); 1561 1562 bottom = get_lower_line ().get_position_pixel (); 1563 top = get_upper_line ().get_position_pixel (); 1564 1565 left = vertical_help_lines.get (vertical_help_lines.size - 1).get_position_pixel (); 1566 right = vertical_help_lines.get (0).get_position_pixel (); 1567 1568 set_zoom_area (left + 10, top - 10, right - 10, bottom + 10); 1569 set_zoom_from_area (); 1570 } 1571 1572 /** Set default zoom and redraw canvas. */ 1573 public void default_zoom () { 1574 set_default_zoom (); 1575 update_view (); 1576 } 1577 1578 public bool is_empty () { 1579 foreach (Path p in get_visible_paths ()) { 1580 if (p.points.size > 0) { 1581 return false; 1582 } 1583 } 1584 1585 return true; 1586 } 1587 1588 public void set_zoom (double z) 1589 requires (z > 0) 1590 { 1591 view_zoom = z; 1592 } 1593 1594 public void set_background_visible (bool visibility) { 1595 background_image_visible = visibility; 1596 } 1597 1598 public bool get_background_visible () { 1599 return background_image_visible; 1600 } 1601 1602 public void draw_coordinate (Context cr) { 1603 Theme.color (cr, "Table Border"); 1604 cr.set_font_size (12); 1605 cr.move_to (0, 10); 1606 cr.show_text (@"($motion_x, $motion_y)"); 1607 cr.stroke (); 1608 } 1609 1610 /** Draw filled paths. */ 1611 public void draw_paths (Context cr, Color? c = null) { 1612 PathList stroke; 1613 Color color; 1614 bool open; 1615 1616 cr.save (); 1617 cr.new_path (); 1618 foreach (Path p in get_visible_paths ()) { 1619 if (c != null) { 1620 color = (!) c; 1621 } else if (p.color != null) { 1622 color = (!) p.color; 1623 } else { 1624 color = Color.black (); 1625 } 1626 1627 if (p.stroke > 0) { 1628 stroke = p.get_stroke_fast (); 1629 draw_path_list (stroke, cr, color); 1630 } else { 1631 open = p.is_open (); 1632 1633 if (open) { 1634 p.close (); 1635 p.recalculate_linear_handles (); 1636 } 1637 1638 p.draw_path (cr, this, color); 1639 1640 if (open) { 1641 p.reopen (); 1642 } 1643 } 1644 } 1645 cr.fill (); 1646 cr.restore (); 1647 } 1648 1649 public void draw_path (Context cr) { 1650 PathList stroke; 1651 Color color; 1652 1653 cr.save (); 1654 cr.new_path (); 1655 foreach (Path p in get_visible_paths ()) { 1656 if (p.stroke > 0) { 1657 stroke = p.get_stroke_fast (); 1658 1659 if (p.is_editable ()) { 1660 color = Theme.get_color ("Filled Stroke"); 1661 color.a = 0.8; 1662 } else { 1663 color = Color.black (); 1664 } 1665 1666 draw_path_list (stroke, cr, color); 1667 } 1668 } 1669 cr.fill (); 1670 cr.restore (); 1671 1672 if (!(MainWindow.get_toolbox ().get_current_tool () is PenTool) 1673 && !(MainWindow.get_toolbox ().get_current_tool () is PointTool) 1674 && !(MainWindow.get_toolbox ().get_current_tool () is TrackTool) 1675 && !(MainWindow.get_toolbox ().get_current_tool () is BezierTool)) { 1676 cr.save (); 1677 cr.new_path (); 1678 foreach (Path p in active_paths) { 1679 if (p.stroke > 0) { 1680 stroke = p.get_stroke_fast (); 1681 color = Theme.get_color ("Selected Objects"); 1682 draw_path_list (stroke, cr, color); 1683 } 1684 } 1685 cr.fill (); 1686 cr.restore (); 1687 } 1688 1689 if (is_open () && Path.fill_open_path) { 1690 cr.save (); 1691 cr.new_path (); 1692 foreach (Path p in get_visible_paths ()) { 1693 if (p.stroke == 0) { 1694 color = p.color == null ? get_path_fill_color () : (!) p.color; 1695 p.draw_path (cr, this, color); 1696 } 1697 } 1698 cr.fill (); 1699 cr.restore (); 1700 } 1701 1702 if (is_open ()) { 1703 cr.save (); 1704 cr.new_path (); 1705 foreach (Path p in get_visible_paths ()) { 1706 p.draw_outline (cr); 1707 p.draw_edit_points (cr); 1708 } 1709 cr.restore (); 1710 } 1711 1712 if (!is_open ()) { 1713 // This was good for testing but it is way too slow: 1714 // Svg.draw_svg_path (cr, get_svg_data (), Glyph.xc () + left, Glyph.yc () - baseline); 1715 1716 cr.save (); 1717 cr.new_path (); 1718 foreach (Path p in get_visible_paths ()) { 1719 if (p.stroke == 0) { 1720 color = p.color == null ? Color.black () : (!) p.color; 1721 p.draw_path (cr, this, color); 1722 } 1723 } 1724 cr.close_path (); 1725 cr.fill (); 1726 cr.restore (); 1727 1728 foreach (Path p in active_paths) { 1729 cr.save (); 1730 cr.new_path (); 1731 if (p.stroke == 0) { 1732 p.draw_path (cr, this); 1733 } 1734 cr.close_path (); 1735 cr.fill (); 1736 cr.restore (); 1737 } 1738 } 1739 1740 if (show_orientation_arrow) { 1741 foreach (Path p in get_visible_paths ()) { 1742 if (p.stroke > 0) { 1743 stroke = p.get_stroke_fast (); 1744 foreach (Path ps in stroke.paths) { 1745 ps.draw_orientation_arrow (cr, orientation_arrow_opacity); 1746 } 1747 } else { 1748 p.draw_orientation_arrow (cr, orientation_arrow_opacity); 1749 } 1750 } 1751 } 1752 } 1753 1754 private Color get_path_fill_color () { 1755 return Theme.get_color ("Fill Color"); 1756 } 1757 1758 public void draw_path_list (PathList pl, Context cr, Color? c = null) { 1759 foreach (Path p in pl.paths) { 1760 p.draw_path (cr, this, c); 1761 } 1762 } 1763 1764 public void draw_background_color (Context cr, double opacity) { 1765 if (opacity > 0) { 1766 cr.save (); 1767 cr.rectangle (0, 0, allocation.width, allocation.height); 1768 Theme.color (cr, "Canvas Background"); 1769 cr.fill (); 1770 cr.restore (); 1771 } 1772 } 1773 1774 public void draw_help_lines (Context cr) { 1775 foreach (Line line in get_all_help_lines ()) { 1776 cr.save (); 1777 line.draw (cr, allocation); 1778 cr.restore (); 1779 } 1780 } 1781 1782 public void set_allocation (WidgetAllocation a) { 1783 allocation = a; 1784 } 1785 1786 public override void draw (WidgetAllocation allocation, Context cmp) { 1787 Tool tool; 1788 1789 this.allocation = allocation; 1790 1791 cmp.save (); 1792 draw_background_color (cmp, 1); 1793 cmp.restore (); 1794 1795 if (background_image != null && background_image_visible) { 1796 ((!)background_image).draw (cmp, allocation, view_offset_x, view_offset_y, view_zoom); 1797 } 1798 1799 if (unlikely (Preferences.draw_boundaries)) { 1800 foreach (Path p in get_visible_paths ()) { 1801 p.draw_boundaries (cmp); 1802 } 1803 } 1804 1805 draw_background_glyph (allocation, cmp); 1806 juxtapose (allocation, cmp); 1807 1808 if (BirdFont.show_coordinates) { 1809 draw_coordinate (cmp); 1810 } 1811 1812 if (show_help_lines) { 1813 cmp.save (); 1814 draw_help_lines (cmp); 1815 cmp.restore (); 1816 } 1817 1818 if (!is_empty ()) { 1819 cmp.save (); 1820 cmp.scale (view_zoom, view_zoom); 1821 cmp.translate (-view_offset_x, -view_offset_y); 1822 draw_path (cmp); 1823 cmp.restore (); 1824 } 1825 1826 cmp.save (); 1827 tool = MainWindow.get_toolbox ().get_current_tool (); 1828 tool.draw_action (tool, cmp, this); 1829 cmp.restore (); 1830 } 1831 1832 private void zoom_in_at_point (double x, double y, double amount = 15) { 1833 int n = (int) (-amount); 1834 zoom_at_point (x, y, n); 1835 } 1836 1837 private void zoom_out_at_point (double x, double y, double amount = 15) { 1838 double a = -amount; 1839 int n = (int) (a * ((allocation.width - a) / allocation.width)); 1840 zoom_at_point (x, y, n); 1841 } 1842 1843 public void zoom_tap (double distance) { 1844 int w = (int) (distance); 1845 if (distance != 0) { 1846 show_zoom_area (-w , -w, allocation.width + w, allocation.height + w); 1847 set_zoom_from_area (); 1848 } 1849 } 1850 1851 /** Zoom in @param n pixels. */ 1852 private void zoom_at_point (double x, double y, int n) { 1853 double w = allocation.width; 1854 double h = allocation.height; 1855 1856 double rx = Math.fabs (w / 2 - x) / (w / 2); 1857 double ry = Math.fabs (h / 2 - y) / (h / 2); 1858 1859 int xd = (x < w / 2) ? (int) (n * rx) : (int) (-n * rx); 1860 int yd = (y < h / 2) ? (int) (n * ry) : (int) (-n * ry); 1861 1862 show_zoom_area (-n + xd, -n + yd, allocation.width + n + xd, allocation.height + n + yd); 1863 set_zoom_from_area (); 1864 } 1865 1866 private void move_view_offset (double x, double y) { 1867 view_offset_x = move_offset_x + (pointer_begin_x - x) * (1/view_zoom); 1868 view_offset_y = move_offset_y + (pointer_begin_y - y) * (1/view_zoom); 1869 GlyphCanvas.redraw (); 1870 } 1871 1872 public void store_undo_state (bool clear_redo = false) { 1873 Glyph g = copy (); 1874 undo_list.add (g); 1875 1876 if (clear_redo) { 1877 redo_list.clear (); 1878 } 1879 } 1880 1881 public void store_redo_state () { 1882 Glyph g = copy (); 1883 redo_list.add (g); 1884 } 1885 1886 public Glyph copy () { 1887 Glyph g = new Glyph.no_lines (name, unichar_code); 1888 1889 g.current_layer = current_layer; 1890 1891 g.left_limit = left_limit; 1892 g.right_limit = right_limit; 1893 1894 g.remove_lines (); 1895 1896 foreach (Line line in get_all_help_lines ()) { 1897 g.add_line (line.copy ()); 1898 } 1899 1900 g.layers = layers.copy (); 1901 1902 foreach (Path p in active_paths) { 1903 g.active_paths.add (p); 1904 } 1905 1906 if (background_image != null) { 1907 g.background_image = ((!) background_image).copy (); 1908 } 1909 1910 g.empty = empty; 1911 g.open = open; 1912 g.version_id = version_id; 1913 1914 return g; 1915 } 1916 1917 public void reload () { 1918 Font f = BirdFont.get_current_font (); 1919 1920 if (f.has_glyph (name)) { 1921 set_glyph_data ((!) f.get_glyph (name)); 1922 } 1923 } 1924 1925 public override void undo () { 1926 Glyph g; 1927 Tool tool; 1928 1929 if (undo_list.size == 0) { 1930 return; 1931 } 1932 1933 tool = MainWindow.get_toolbox ().get_current_tool (); 1934 tool.before_undo (); 1935 1936 g = undo_list.get (undo_list.size - 1); 1937 1938 store_redo_state (); 1939 set_glyph_data (g); 1940 1941 undo_list.remove_at (undo_list.size - 1); 1942 1943 DrawingTools.update_layers (); 1944 PenTool.update_selected_points (); 1945 1946 clear_active_paths (); 1947 1948 tool.after_undo (); 1949 } 1950 1951 public override void redo () { 1952 Glyph g; 1953 1954 if (redo_list.size == 0) { 1955 return; 1956 } 1957 1958 g = redo_list.get (redo_list.size - 1); 1959 1960 store_undo_state (false); 1961 set_glyph_data (g); 1962 1963 redo_list.remove_at (redo_list.size - 1); 1964 1965 DrawingTools.update_layers (); 1966 PenTool.update_selected_points (); 1967 1968 clear_active_paths (); 1969 } 1970 1971 void set_glyph_data (Glyph g) { 1972 current_layer = g.current_layer; 1973 layers = g.layers.copy (); 1974 1975 left_limit = g.left_limit; 1976 right_limit = g.right_limit; 1977 1978 remove_lines (); 1979 foreach (Line line in g.get_all_help_lines ()) { 1980 add_line (line.copy ()); 1981 } 1982 1983 add_help_lines (); 1984 1985 if (g.background_image != null) { 1986 background_image = ((!) g.background_image).copy (); 1987 } 1988 1989 clear_active_paths (); 1990 foreach (Path p in g.active_paths) { 1991 add_active_path (null, p); 1992 } 1993 1994 redraw_area (0, 0, allocation.width, allocation.height); 1995 } 1996 1997 /** Split curve in two parts and add a new point in between. 1998 * @return the new point 1999 */ 2000 public void insert_new_point_on_path (double x, double y) { 2001 double min, distance; 2002 Path? p = null; 2003 Path path; 2004 EditPoint? np = null; 2005 EditPoint lep; 2006 2007 double xt; 2008 double yt; 2009 2010 xt = x * ivz () - xc () + view_offset_x; 2011 yt = yc () - y * ivz () - view_offset_y; 2012 2013 min = double.MAX; 2014 2015 foreach (Path pp in get_visible_paths ()) { 2016 lep = new EditPoint (); 2017 pp.get_closest_point_on_path (lep, xt, yt); 2018 distance = Math.sqrt (Math.pow (Math.fabs (xt - lep.x), 2) + Math.pow (Math.fabs (yt - lep.y), 2)); 2019 2020 if (distance < min) { 2021 min = distance; 2022 p = pp; 2023 np = lep; 2024 } 2025 } 2026 2027 if (p == null) { 2028 return; 2029 } 2030 2031 path = (!) p; 2032 2033 lep = new EditPoint (); 2034 path.get_closest_point_on_path (lep, xt, yt); 2035 path.insert_new_point_on_path (lep); 2036 } 2037 2038 static bool in_range (double offset_x, double coordinate_x1, double coordinate_x2) { 2039 return coordinate_x1 <= offset_x <= coordinate_x2; 2040 } 2041 2042 public void juxtapose (WidgetAllocation allocation, Context cr) { 2043 string glyph_sequence = Preferences.get ("glyph_sequence"); 2044 unichar c; 2045 Font font = BirdFont.get_current_font (); 2046 Glyph glyph = MainWindow.get_current_glyph (); 2047 Glyph juxtaposed; 2048 StringBuilder current = new StringBuilder (); 2049 int pos; 2050 string name; 2051 double x, kern; 2052 double left, baseline; 2053 string last_name; 2054 2055 double box_x1, box_x2, box_y1, box_y2; 2056 double marker_x, marker_y; 2057 2058 KerningClasses classes = font.get_kerning_classes (); 2059 2060 x = 0; 2061 2062 box_x1 = path_coordinate_x (0); 2063 box_y1 = path_coordinate_y (0); 2064 box_x2 = path_coordinate_x (allocation.width); 2065 box_y2 = path_coordinate_y (allocation.height); 2066 2067 current.append_unichar (glyph.unichar_code); 2068 pos = glyph_sequence.index_of (current.str); 2069 2070 baseline = font.base_line;; 2071 left = glyph.get_line ("left").pos; 2072 2073 x = glyph.get_width (); 2074 last_name = glyph.name; 2075 for (int i = pos + 1; i < glyph_sequence.char_count (); i++) { 2076 c = glyph_sequence.get_char (i); 2077 name = (!) c.to_string (); 2078 juxtaposed = (font.has_glyph (name)) ? (!) font.get_glyph (name) : font.get_space ().get_current (); 2079 2080 if (font.has_glyph (last_name) && font.has_glyph (name)) { 2081 kern = classes.get_kerning (last_name, name); 2082 } else { 2083 kern = 0; 2084 } 2085 2086 if (!juxtaposed.is_empty () 2087 && (in_range (left + x + kern, box_x1, box_x2) // the letter is visible 2088 || in_range (left + x + kern + juxtaposed.get_width (), box_x1, box_x2))) { 2089 2090 marker_x = Glyph.xc () + left + x + kern - glyph.view_offset_x; 2091 marker_y = Glyph.yc () - baseline - glyph.view_offset_y; 2092 2093 cr.save (); 2094 cr.scale (glyph.view_zoom, glyph.view_zoom); 2095 Theme.color (cr, "Foreground 1"); 2096 2097 Svg.draw_svg_path (cr, juxtaposed.get_svg_data (), marker_x, marker_y); 2098 cr.restore (); 2099 } 2100 2101 x += juxtaposed.get_width () + kern; 2102 2103 last_name = name; 2104 } 2105 2106 x = 0; 2107 last_name = glyph.name; 2108 for (int i = pos - 1; i >= 0; i--) { 2109 c = glyph_sequence.get_char (i); 2110 name = (!) c.to_string (); 2111 juxtaposed = (font.has_glyph (name)) ? (!) font.get_glyph (name) : font.get_space ().get_current (); 2112 2113 if (font.has_glyph (last_name) && font.has_glyph (name)) { 2114 kern = classes.get_kerning (name, last_name); 2115 } else { 2116 kern = 0; 2117 } 2118 2119 x -= juxtaposed.get_width (); 2120 x -= kern; 2121 2122 marker_x = Glyph.xc () + left + x; 2123 marker_y = Glyph.yc () - baseline; 2124 if (!juxtaposed.is_empty () 2125 &&(in_range (left + x, box_x1, box_x2) 2126 || in_range (left + x + juxtaposed.get_width (), box_x1, box_x2))) { 2127 cr.save (); 2128 cr.scale (glyph.view_zoom, glyph.view_zoom); 2129 cr.translate (-glyph.view_offset_x, -glyph.view_offset_y); 2130 Theme.color (cr, "Foreground 1"); 2131 Svg.draw_svg_path (cr, juxtaposed.get_svg_data (), marker_x, marker_y); 2132 cr.restore (); 2133 } 2134 2135 last_name = name; 2136 } 2137 } 2138 2139 /** @return left side bearing */ 2140 public double get_lsb () { 2141 return get_line ("left").pos; 2142 } 2143 2144 /** @return bottom line */ 2145 public double get_baseline () { 2146 Font font = BirdFont.get_current_font (); 2147 return font.base_line; 2148 } 2149 2150 void draw_background_glyph (WidgetAllocation allocation, Context cr) { 2151 double left, baseline, current_left; 2152 Glyph g; 2153 Font font = BirdFont.get_current_font (); 2154 2155 current_left = get_line ("left").pos; 2156 2157 if (background_glyph != null) { 2158 g = (!) background_glyph; 2159 baseline = font.base_line; 2160 left = g.get_line ("left").pos; 2161 cr.save (); 2162 cr.scale (view_zoom, view_zoom); 2163 cr.translate (-view_offset_x, -view_offset_y); 2164 Theme.color (cr, "Background Glyph"); 2165 2166 Svg.draw_svg_path (cr, g.get_svg_data (), 2167 Glyph.xc () + left - (left - current_left) , 2168 Glyph.yc () - baseline); 2169 cr.restore (); 2170 } 2171 2172 } 2173 2174 public string get_hex () { 2175 return Font.to_hex_code (unichar_code); 2176 } 2177 2178 public override void move_view (double x, double y) { 2179 view_offset_x += x / view_zoom; 2180 view_offset_y += y / view_zoom; 2181 GlyphCanvas.redraw (); 2182 } 2183 2184 /** Scroll or zoom from tap events. */ 2185 public void change_view_event (int finger, int x, int y) { 2186 double dx, dy; 2187 double last_distance, new_distance; 2188 2189 dx = 0; 2190 dy = 0; 2191 2192 new_distance = 0; 2193 2194 if (last_tap0_y == -1 || last_tap0_x == -1 || last_tap1_y == -1 || last_tap1_x == -1) { 2195 return; 2196 } 2197 2198 if (finger == 0) { 2199 dx = last_tap0_x - x; 2200 dy = last_tap0_y - y; 2201 new_distance = Path.distance (last_tap1_x, x, last_tap1_y, y); 2202 } 2203 2204 if (finger == 1) { 2205 dx = last_tap1_x - x; 2206 dy = last_tap1_y - y; 2207 new_distance = Path.distance (last_tap0_x, x, last_tap0_y, y); 2208 } 2209 2210 last_distance = Path.distance (last_tap0_x, last_tap1_x, last_tap0_y, last_tap1_y); 2211 2212 if (zoom_distance != 0) { 2213 zoom_tap (zoom_distance - new_distance); 2214 } 2215 2216 if (finger == 1) { 2217 warning (@"dx $dx dy $dy last_tap1_x $last_tap1_x last_tap1_y $last_tap1_y x $x y $y"); 2218 move_view (dx, dy); 2219 } 2220 2221 zoom_distance = new_distance; 2222 } 2223 2224 public override void tap_down (int finger, int x, int y) { 2225 TimeoutSource delay; 2226 2227 if (finger == 0) { 2228 delay = new TimeoutSource (400); // wait for second finger 2229 delay.set_callback(() => { 2230 if (!change_view && !ignore_input) { 2231 button_press (1, x, y); 2232 } 2233 return false; 2234 }); 2235 delay.attach (null); 2236 2237 last_tap0_x = x; 2238 last_tap0_y = y; 2239 } 2240 2241 if (finger == 1) { 2242 change_view = true; 2243 last_tap1_x = x; 2244 last_tap1_y = y; 2245 } 2246 } 2247 2248 public override void tap_up (int finger, int x, int y) { 2249 if (finger == 0) { 2250 button_release (1, x, y); 2251 2252 last_tap0_x = -1; 2253 last_tap0_y = -1; 2254 } 2255 2256 if (finger == 1) { 2257 last_tap1_x = -1; 2258 last_tap1_y = -1; 2259 2260 change_view = false; 2261 zoom_distance = 0; 2262 } 2263 } 2264 2265 public override void tap_move (int finger, int x, int y) { 2266 if (!change_view) { 2267 motion_notify (x, y); 2268 } else { 2269 change_view_event (finger, x, y); 2270 } 2271 2272 if (finger == 0) { 2273 last_tap0_x = x; 2274 last_tap0_y = y; 2275 } 2276 2277 if (finger == 1) { 2278 last_tap1_x = x; 2279 last_tap1_y = y; 2280 } 2281 } 2282 2283 public void update_spacing_class () { 2284 Font font = BirdFont.get_current_font (); 2285 GlyphCollection? g; 2286 GlyphCollection gc; 2287 Glyph glyph; 2288 Gee.ArrayList<string> s; 2289 SpacingData sd; 2290 2291 sd = font.get_spacing (); 2292 s = sd.get_all_connections ((!) unichar_code.to_string ()); 2293 foreach (string l in s) { 2294 if (l != (!) unichar_code.to_string ()) { 2295 g = font.get_glyph_collection (l); 2296 if (g != null) { 2297 gc = (!) g; 2298 glyph = gc.get_current (); 2299 2300 if (glyph.left_limit == glyph.right_limit) { 2301 warning ("Zero width glyph in kerning class."); 2302 } 2303 2304 left_limit = glyph.left_limit; 2305 right_limit = glyph.right_limit; 2306 2307 break; 2308 } 2309 } 2310 } 2311 2312 add_help_lines (); 2313 } 2314 2315 public void update_other_spacing_classes () { 2316 Font font = BirdFont.get_current_font (); 2317 GlyphCollection? g; 2318 GlyphCollection gc; 2319 Glyph glyph; 2320 Gee.ArrayList<string> s; 2321 SpacingData sd; 2322 2323 sd = font.get_spacing (); 2324 s = sd.get_all_connections (get_name ()); 2325 2326 foreach (string l in s) { 2327 if (l != (!) unichar_code.to_string ()) { 2328 g = font.get_glyph_collection (l); 2329 if (g != null) { 2330 gc = (!) g; 2331 glyph = gc.get_current (); 2332 glyph.left_limit = left_limit; 2333 glyph.right_limit = right_limit; 2334 } 2335 } 2336 } 2337 } 2338 2339 public void set_cache (string key, Surface cache) { 2340 glyph_cache.set (key, cache); 2341 } 2342 2343 public bool has_cache (string key) { 2344 return glyph_cache.has_key (key); 2345 } 2346 2347 public Surface get_cache (string key) { 2348 if (unlikely (!has_cache (key))) { 2349 warning ("No cache for glyph."); 2350 return new ImageSurface (Cairo.Format.ARGB32, 1, 1); 2351 } 2352 2353 return glyph_cache.get (key); 2354 } 2355 2356 public void add_custom_guide () { 2357 TextListener listener; 2358 2359 listener = new TextListener (t_("Guide"), "", t_("Add")); 2360 2361 listener.signal_text_input.connect ((text) => { 2362 new_guide_name = text; 2363 }); 2364 2365 listener.signal_submit.connect (() => { 2366 Line guide; 2367 double position; 2368 2369 position = path_coordinate_y (allocation.height / 2.0); 2370 guide = new Line (new_guide_name, new_guide_name, position); 2371 horizontal_help_lines.add (guide); 2372 2373 BirdFont.get_current_font ().custom_guides.add (guide); 2374 2375 TabContent.hide_text_input (); 2376 GlyphCanvas.redraw (); 2377 }); 2378 2379 TabContent.show_text_input (listener); 2380 } 2381 2382 public Path? get_last_path () { 2383 var paths = get_all_paths (); 2384 return_val_if_fail (paths.size > 0, null); 2385 return paths.get (paths.size - 1); 2386 } 2387 2388 public void move_layer_up () { 2389 Layer layer = get_current_layer (); 2390 2391 if (current_layer + 2 <= layers.subgroups.size) { 2392 return_if_fail (0 <= current_layer + 2 <= layers.subgroups.size); 2393 layers.subgroups.insert (current_layer + 2, layer); 2394 2395 return_if_fail (0 <= current_layer + 1 < layers.subgroups.size); 2396 layers.subgroups.remove_at (current_layer); 2397 2398 set_current_layer (layer); 2399 } 2400 } 2401 2402 public void move_layer_down () { 2403 Layer layer = get_current_layer (); 2404 2405 if (current_layer >= 1) { 2406 return_if_fail (0 <= current_layer - 1 < layers.subgroups.size); 2407 layers.subgroups.insert (current_layer - 1, layer); 2408 2409 return_if_fail (0 <= current_layer + 1 < layers.subgroups.size); 2410 layers.subgroups.remove_at (current_layer + 1); 2411 2412 set_current_layer (layer); 2413 } 2414 } 2415 2416 public void fix_curve_orientation () { 2417 int inside_count; 2418 bool inside; 2419 Path outline; 2420 2421 foreach (Path p1 in get_visible_paths ()) { 2422 inside_count = 0; 2423 2424 foreach (Path p2 in get_visible_paths ()) { 2425 if (p1 != p2) { 2426 inside = true; 2427 outline = p2.flatten (); 2428 2429 foreach (EditPoint ep in p1.points) { 2430 if (!SvgParser.is_inside (ep, outline)) { 2431 inside = false; 2432 } 2433 } 2434 2435 if (inside) { 2436 inside_count++; 2437 } 2438 } 2439 } 2440 2441 if (inside_count % 2 == 0) { 2442 p1.force_direction (Direction.CLOCKWISE); 2443 } else { 2444 p1.force_direction (Direction.COUNTER_CLOCKWISE); 2445 } 2446 } 2447 } 2448 2449 public override void magnify (double magnification) { 2450 double x_center = path_coordinate_x (xc ()); 2451 double y_center = path_coordinate_y (yc ()); 2452 2453 view_zoom *= 1 + magnification; 2454 2455 view_offset_x -= path_coordinate_x (xc ()) - x_center; 2456 view_offset_y += path_coordinate_y (yc ()) - y_center; 2457 2458 GlyphCanvas.redraw (); 2459 } 2460 2461 public Glyph self_interpolate (double weight) { 2462 Glyph g1 = copy (); 2463 Glyph g2 = copy (); 2464 2465 g1.fix_curve_orientation (); 2466 g2.layers = new Layer (); // remove all paths 2467 2468 foreach (Path p in g1.get_visible_paths ()) { 2469 bool counter = !p.is_clockwise (); 2470 2471 g2.add_path (p.copy ()); 2472 2473 p.remove_points_on_points (); 2474 Path master = p.get_self_interpolated_master (counter, weight); 2475 p = p.interpolate_estimated_path (master, weight); 2476 p.recalculate_linear_handles (); 2477 2478 g2.add_path (p); 2479 g2.add_path (master); 2480 } 2481 2482 return g2; 2483 } 2484 } 2485 2486 } 2487