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.
Fix zoom tool on Windows
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 double x, y, w, h; 1081 1082 set_zoom_area (sx, sy, nx, ny); 1083 1084 zoom_area_is_visible = true; 1085 1086 x = Math.fmin (zoom_x1, zoom_x2) - 50; 1087 y = Math.fmin (zoom_y1, zoom_y2) - 50; 1088 1089 w = Math.fabs (zoom_x1 - zoom_x2) + 100; 1090 h = Math.fabs (zoom_y1 - zoom_y2) + 100; 1091 1092 redraw_area ((int)x, (int)y, (int)w, (int)h); 1093 } 1094 1095 public void set_zoom_area (int sx, int sy, int nx, int ny) { 1096 zoom_x1 = sx; 1097 zoom_y1 = sy; 1098 zoom_x2 = nx; 1099 zoom_y2 = ny; 1100 } 1101 1102 public static void validate_zoom () { 1103 Glyph g = MainWindow.get_current_glyph (); 1104 if (unlikely (g.view_zoom == 0)) { 1105 warning ("Zoom is zero."); 1106 g.reset_zoom (); 1107 1108 if (g.view_zoom == 0) { 1109 g.view_zoom = 1; 1110 g.view_offset_x = 0; 1111 g.view_offset_y = 0; 1112 } 1113 } 1114 } 1115 1116 public static double path_coordinate_x (double x) { 1117 Glyph g = MainWindow.get_current_glyph (); 1118 validate_zoom (); 1119 return x * ivz () - xc () + g.view_offset_x; 1120 } 1121 1122 public static int reverse_path_coordinate_x (double x) { 1123 Glyph g = MainWindow.get_current_glyph (); 1124 validate_zoom (); 1125 return (int) Math.rint ((x - g.view_offset_x + xc ()) * g.view_zoom); 1126 } 1127 1128 public static double precise_reverse_path_coordinate_x (double x) { 1129 Glyph g = MainWindow.get_current_glyph (); 1130 validate_zoom (); 1131 return (x - g.view_offset_x + xc ()) * g.view_zoom; 1132 } 1133 1134 public static double path_coordinate_y (double y) { 1135 Glyph g = MainWindow.get_current_glyph (); 1136 validate_zoom (); 1137 return yc () - y * ivz () - g.view_offset_y; 1138 } 1139 1140 public static int reverse_path_coordinate_y (double y) { 1141 Glyph g = MainWindow.get_current_glyph (); 1142 validate_zoom (); 1143 y = Math.rint ((y + g.view_offset_y - yc ()) * g.view_zoom); 1144 return (int) (-y); 1145 } 1146 1147 public static double precise_reverse_path_coordinate_y (double y) { 1148 Glyph g = MainWindow.get_current_glyph (); 1149 validate_zoom (); 1150 y = (y + g.view_offset_y - yc ()) * g.view_zoom; 1151 return -y; 1152 } 1153 1154 public Layer? get_path_at (double x, double y) { 1155 Layer? group = null; 1156 bool found = false; 1157 1158 foreach (Layer layer in get_current_layer ().subgroups) { 1159 foreach (Path pt in layer.paths.paths) { 1160 if (pt.is_over (x, y)) { 1161 found = true; 1162 group = layer; 1163 } 1164 } 1165 } 1166 1167 if (!found) { 1168 foreach (Path pt in get_paths_in_current_layer ()) { 1169 if (pt.is_over (x, y)) { 1170 Layer layer = new Layer (); 1171 layer.is_counter = true; 1172 layer.single_path = true; 1173 layer.add_path (pt); 1174 group = layer; 1175 } 1176 } 1177 } 1178 1179 return group; 1180 } 1181 1182 public bool select_path (double x, double y) { 1183 Path? p = null; 1184 bool found = false; 1185 1186 foreach (Path pt in get_paths_in_current_layer ()) { 1187 if (pt.is_over (x, y)) { 1188 p = pt; 1189 found = true; 1190 } 1191 } 1192 1193 if (!KeyBindings.has_shift ()) { 1194 clear_active_paths (); 1195 } 1196 1197 add_active_path (null, p); 1198 1199 return found; 1200 } 1201 1202 public bool is_over_selected_path (double x, double y) { 1203 foreach (Path pt in active_paths) { 1204 if (pt.is_over (x, y)) { 1205 return true; 1206 } 1207 } 1208 return false; 1209 } 1210 1211 public void queue_redraw_path (Path path) { 1212 redraw_path (path.xmin, path.ymin, path.xmax, path.ymax); 1213 } 1214 1215 private void redraw_path (double xmin, double ymin, double xmax, double ymax) { 1216 int yc = (int)(allocation.height / 2.0); 1217 1218 double yta = yc - ymin - view_offset_y; 1219 double ytb = yc - ymax - view_offset_y; 1220 1221 double xta = -view_offset_x - xmin; 1222 double xtb = -view_offset_x - xmax; 1223 1224 redraw_area ((int)xtb - 10, (int)yta - 10, (int)(xtb - xta) + 10, (int) (yta - ytb) + 10); 1225 } 1226 1227 public Path get_closeset_path (double x, double y) { 1228 double d; 1229 EditPoint ep = new EditPoint (); 1230 1231 Path min_point = new Path (); 1232 double min_distance = double.MAX; 1233 1234 double xt = path_coordinate_x (x); 1235 double yt = path_coordinate_y (y); 1236 var paths = get_visible_paths (); 1237 1238 foreach (Path p in paths) { 1239 if (p.is_over (xt, yt)) { 1240 return p; 1241 } 1242 } 1243 1244 foreach (Path p in paths) { 1245 if (p.points.size == 0) continue; 1246 1247 p.get_closest_point_on_path (ep, xt, yt); 1248 d = Math.pow (ep.x - xt, 2) + Math.pow (ep.y - yt, 2); 1249 1250 if (d < min_distance) { 1251 min_distance = d; 1252 min_point = p; 1253 } 1254 1255 } 1256 1257 // a path without any editpoints 1258 if (paths.size > 0) { 1259 return paths.get (0); 1260 } 1261 1262 if (unlikely (min_distance == double.MAX)) { 1263 warning (@"No path found in path_list."); 1264 } 1265 1266 return min_point; 1267 } 1268 1269 public void move_selected_edit_point_coordinates (EditPoint selected_point, double xt, double yt) { 1270 double x, y; 1271 1272 BirdFont.get_current_font ().touch (); 1273 1274 x = reverse_path_coordinate_x (xt); 1275 y = reverse_path_coordinate_y (yt); 1276 1277 // redraw control point 1278 redraw_area ((int)(x - 4*view_zoom), (int)(y - 4*view_zoom), (int)(x + 3*view_zoom), (int)(y + 3*view_zoom)); 1279 1280 // update position of selected point 1281 selected_point.set_position (xt, yt); 1282 1283 if (view_zoom >= 2) { 1284 redraw_area (0, 0, allocation.width, allocation.height); 1285 } else { 1286 redraw_last_stroke (x, y); 1287 } 1288 } 1289 1290 public void move_selected_edit_point (EditPoint selected_point, double x, double y) { 1291 double xt = path_coordinate_x (x); 1292 double yt = path_coordinate_y (y); 1293 move_selected_edit_point_coordinates (selected_point, xt, yt); 1294 } 1295 1296 public void redraw_segment (EditPoint a, EditPoint b) { 1297 double margin = 10; 1298 double x = Math.fmin (reverse_path_coordinate_x (a.x), reverse_path_coordinate_x (b.x)) - margin; 1299 double y = Math.fmin (reverse_path_coordinate_y (a.y), reverse_path_coordinate_y(b.y)) - margin; 1300 double w = Math.fabs (reverse_path_coordinate_x (a.x) - reverse_path_coordinate_x(b.x)) + 2 * margin; 1301 double h = Math.fabs (reverse_path_coordinate_y (a.y) - reverse_path_coordinate_y (b.y)) + 2 * margin; 1302 1303 redraw_area ((int)x, (int)y, (int)w, (int)h); 1304 } 1305 1306 private void redraw_last_stroke (double x, double y) { 1307 // redraw line, if we have more than one new point on path 1308 double px = 0; 1309 double py = 0; 1310 int tw = 0; 1311 int th = 0; 1312 1313 double xc = (allocation.width / 2.0); 1314 1315 if (active_paths.size == 0) { 1316 return; 1317 } 1318 1319 foreach (Path path in active_paths) { 1320 EditPoint p; 1321 EditPoint pl = path.get_last_point (); 1322 1323 if (pl.prev != null) { 1324 p = pl.get_prev (); 1325 1326 px = p.x + xc; 1327 py = p.y - xc; 1328 1329 tw = (px > x) ? (int) (px - x) : (int) (x - px); 1330 th = (py > y) ? (int) (py - y) : (int) (y - py); 1331 1332 if (px > x) px -= tw + 60; 1333 if (py > y) py -= th + 60; 1334 1335 } else { 1336 px = x - 60; 1337 py = y - 60; 1338 tw = 0; 1339 th = 0; 1340 } 1341 } 1342 1343 redraw_area ((int)px - 20, (int)py - 20, tw + 120, th + 120); 1344 } 1345 1346 public bool has_active_path () { 1347 return active_paths.size > 0; 1348 } 1349 1350 public bool is_open () { 1351 return open; 1352 } 1353 1354 /** Close all editable paths and return false if no path have been closed. */ 1355 public bool close_path () { 1356 bool r = false; 1357 1358 foreach (Path p in get_all_paths ()) { 1359 if (p.is_editable ()) { 1360 r = true; 1361 p.set_editable (false); 1362 } 1363 } 1364 1365 open = false; 1366 clear_active_paths (); 1367 GlyphCanvas.redraw (); 1368 1369 MainWindow.set_cursor (NativeWindow.VISIBLE); 1370 1371 return r; 1372 } 1373 1374 public void open_path () { 1375 foreach (Path p in get_visible_paths ()) { 1376 p.set_editable (true); 1377 p.recalculate_linear_handles (); 1378 1379 if (p.is_open () && p.points.size > 0) { 1380 p.get_first_point ().set_reflective_handles (false); 1381 p.get_first_point ().set_tie_handle (false); 1382 p.get_last_point ().set_reflective_handles (false); 1383 p.get_last_point ().set_tie_handle (false); 1384 } 1385 } 1386 1387 open = true; 1388 redraw_area (0, 0, allocation.width, allocation.height); 1389 } 1390 1391 public void redraw_path_region (Path p) { 1392 int x, y, w, h; 1393 1394 p.update_region_boundaries (); 1395 1396 x = reverse_path_coordinate_x (p.xmin); 1397 y = reverse_path_coordinate_x (p.xmin); 1398 w = reverse_path_coordinate_x (p.xmax) - x; 1399 h = reverse_path_coordinate_x (p.ymax) - y; // FIXME: redraw path 1400 1401 redraw_area (x, y, w, h); 1402 } 1403 1404 public Line get_line (string name) { 1405 foreach (Line line in vertical_help_lines) { 1406 if (likely (line.get_label () == name)) { 1407 return line; 1408 } 1409 } 1410 1411 foreach (Line line in horizontal_help_lines) { 1412 if (likely (line.get_label () == name)) { 1413 return line; 1414 } 1415 } 1416 1417 warning (@"No line with label $name found"); 1418 return new Line ("Err"); 1419 } 1420 1421 public override void zoom_in () { 1422 if (move_canvas) { 1423 return; 1424 } 1425 1426 set_zoom_area (10, 10, allocation.width - 10, allocation.height - 10); 1427 set_zoom_from_area (); 1428 update_view (); 1429 update_zoom_bar (); 1430 } 1431 1432 public override void zoom_out () { 1433 double w = allocation.width; 1434 int n = (int) (10 * ((w - 10) / allocation.width)); 1435 set_zoom_area (-n, -n, allocation.width + n, allocation.height + n); 1436 set_zoom_from_area (); 1437 update_view (); 1438 update_zoom_bar (); 1439 } 1440 1441 public override void zoom_max () { 1442 default_zoom (); 1443 update_zoom_bar (); 1444 } 1445 1446 public override void zoom_min () { 1447 double ax = 1000; 1448 double ay = 1000; 1449 double bx = -1000; 1450 double by = -1000; 1451 1452 int iax, iay, ibx, iby; 1453 1454 reset_zoom (); 1455 1456 foreach (var p in get_visible_paths ()) { 1457 p.update_region_boundaries (); 1458 1459 if (p.points.size > 2) { 1460 if (p.xmin < ax) ax = p.xmin; 1461 if (p.ymin < ay) ay = p.ymin; 1462 if (p.xmax > bx) bx = p.xmax; 1463 if (p.ymax > by) by = p.ymax; 1464 } 1465 } 1466 1467 if (ax == 1000) return; // empty page 1468 1469 iax = (int) ((ax + view_offset_x + allocation.width / 2.0) * view_zoom); 1470 iay = (int) ((-ay + view_offset_y + allocation.height / 2.0) * view_zoom); 1471 ibx = (int) ((bx + view_offset_x + allocation.width / 2.0) * view_zoom); 1472 iby = (int) ((-by + view_offset_y + allocation.height / 2.0) * view_zoom); 1473 1474 show_zoom_area (iax, iay, ibx, iby); // set this later on button release 1475 set_zoom_from_area (); 1476 zoom_out (); // add some margin 1477 1478 redraw_area (0, 0, allocation.width, allocation.height); 1479 update_zoom_bar (); 1480 } 1481 1482 public override void store_current_view () { 1483 ZoomView n; 1484 1485 if (zoom_list_index + 1 < zoom_list.size) { 1486 n = zoom_list.get (zoom_list_index); 1487 while (n != zoom_list.get (zoom_list.size - 1)) { 1488 zoom_list.remove_at (zoom_list.size - 1); 1489 } 1490 } 1491 1492 zoom_list.add (new ZoomView (view_offset_x, view_offset_y, view_zoom, allocation)); 1493 zoom_list_index = (int) zoom_list.size - 1; 1494 1495 if (zoom_list.size > 50) { 1496 zoom_list.remove_at (0); 1497 } 1498 } 1499 1500 public override void restore_last_view () { 1501 if (zoom_list.size == 0 || zoom_list_index - 1 < 0) { 1502 return; 1503 } 1504 1505 zoom_list_index--; 1506 1507 ZoomView z = zoom_list.get (zoom_list_index); 1508 1509 view_offset_x = z.x; 1510 view_offset_y = z.y; 1511 view_zoom = z.zoom; 1512 allocation = z.allocation; 1513 1514 update_zoom_bar (); 1515 } 1516 1517 public override void next_view () { 1518 ZoomView z; 1519 1520 if (zoom_list.size == 0 || zoom_list_index + 1 >= zoom_list.size) { 1521 return; 1522 } 1523 1524 zoom_list_index++; 1525 1526 z = zoom_list.get (zoom_list_index); 1527 1528 view_offset_x = z.x; 1529 view_offset_y = z.y; 1530 view_zoom = z.zoom; 1531 allocation = z.allocation; 1532 1533 update_zoom_bar (); 1534 } 1535 1536 public override void reset_zoom () { 1537 view_offset_x = 0; 1538 view_offset_y = 0; 1539 1540 set_zoom (1); 1541 1542 store_current_view (); 1543 update_zoom_bar (); 1544 } 1545 1546 /** Get x-height or top line. */ 1547 public Line get_upper_line () { 1548 if (has_top_line () || xheight_lines_visible) { 1549 return get_line ("top"); 1550 } 1551 1552 return get_line ("x-height"); 1553 } 1554 1555 /** Get base line. */ 1556 public Line get_lower_line () { 1557 return get_line ("baseline"); 1558 } 1559 1560 /** Set default zoom. See default_zoom. */ 1561 public void set_default_zoom () { 1562 int bottom = 0; 1563 int top = 0; 1564 int left = 0; 1565 int right = 0; 1566 1567 return_if_fail (vertical_help_lines.size != 0); 1568 return_if_fail (horizontal_help_lines.size != 0); 1569 1570 reset_zoom (); 1571 1572 bottom = get_lower_line ().get_position_pixel (); 1573 top = get_upper_line ().get_position_pixel (); 1574 1575 left = vertical_help_lines.get (vertical_help_lines.size - 1).get_position_pixel (); 1576 right = vertical_help_lines.get (0).get_position_pixel (); 1577 1578 set_zoom_area (left + 10, top - 10, right - 10, bottom + 10); 1579 set_zoom_from_area (); 1580 } 1581 1582 /** Set default zoom and redraw canvas. */ 1583 public void default_zoom () { 1584 set_default_zoom (); 1585 update_view (); 1586 } 1587 1588 public bool is_empty () { 1589 foreach (Path p in get_visible_paths ()) { 1590 if (p.points.size > 0) { 1591 return false; 1592 } 1593 } 1594 1595 return true; 1596 } 1597 1598 public void set_zoom (double z) 1599 requires (z > 0) 1600 { 1601 view_zoom = z; 1602 } 1603 1604 public void set_background_visible (bool visibility) { 1605 background_image_visible = visibility; 1606 } 1607 1608 public bool get_background_visible () { 1609 return background_image_visible; 1610 } 1611 1612 public void draw_coordinate (Context cr) { 1613 Theme.color (cr, "Table Border"); 1614 cr.set_font_size (12); 1615 cr.move_to (0, 10); 1616 cr.show_text (@"($motion_x, $motion_y)"); 1617 cr.stroke (); 1618 } 1619 1620 /** Draw filled paths. */ 1621 public void draw_paths (Context cr, Color? c = null) { 1622 PathList stroke; 1623 Color color; 1624 bool open; 1625 1626 cr.save (); 1627 cr.new_path (); 1628 foreach (Path p in get_visible_paths ()) { 1629 if (c != null) { 1630 color = (!) c; 1631 } else if (p.color != null) { 1632 color = (!) p.color; 1633 } else { 1634 color = Color.black (); 1635 } 1636 1637 if (p.stroke > 0) { 1638 stroke = p.get_stroke_fast (); 1639 draw_path_list (stroke, cr, color); 1640 } else { 1641 open = p.is_open (); 1642 1643 if (open) { 1644 p.close (); 1645 p.recalculate_linear_handles (); 1646 } 1647 1648 p.draw_path (cr, this, color); 1649 1650 if (open) { 1651 p.reopen (); 1652 } 1653 } 1654 } 1655 cr.fill (); 1656 cr.restore (); 1657 } 1658 1659 public void draw_path (Context cr) { 1660 PathList stroke; 1661 Color color; 1662 1663 cr.save (); 1664 cr.new_path (); 1665 foreach (Path p in get_visible_paths ()) { 1666 if (p.stroke > 0) { 1667 stroke = p.get_stroke_fast (); 1668 1669 if (p.is_editable ()) { 1670 color = Theme.get_color ("Filled Stroke"); 1671 color.a = 0.8; 1672 } else { 1673 color = Color.black (); 1674 } 1675 1676 draw_path_list (stroke, cr, color); 1677 } 1678 } 1679 cr.fill (); 1680 cr.restore (); 1681 1682 if (!(MainWindow.get_toolbox ().get_current_tool () is PenTool) 1683 && !(MainWindow.get_toolbox ().get_current_tool () is PointTool) 1684 && !(MainWindow.get_toolbox ().get_current_tool () is TrackTool) 1685 && !(MainWindow.get_toolbox ().get_current_tool () is BezierTool)) { 1686 cr.save (); 1687 cr.new_path (); 1688 foreach (Path p in active_paths) { 1689 if (p.stroke > 0) { 1690 stroke = p.get_stroke_fast (); 1691 color = Theme.get_color ("Selected Objects"); 1692 draw_path_list (stroke, cr, color); 1693 } 1694 } 1695 cr.fill (); 1696 cr.restore (); 1697 } 1698 1699 if (is_open () && Path.fill_open_path) { 1700 cr.save (); 1701 cr.new_path (); 1702 foreach (Path p in get_visible_paths ()) { 1703 if (p.stroke == 0) { 1704 color = p.color == null ? get_path_fill_color () : (!) p.color; 1705 p.draw_path (cr, this, color); 1706 } 1707 } 1708 cr.fill (); 1709 cr.restore (); 1710 } 1711 1712 if (is_open ()) { 1713 cr.save (); 1714 cr.new_path (); 1715 foreach (Path p in get_visible_paths ()) { 1716 p.draw_outline (cr); 1717 p.draw_edit_points (cr); 1718 } 1719 cr.restore (); 1720 } 1721 1722 if (!is_open ()) { 1723 // This was good for testing but it is way too slow: 1724 // Svg.draw_svg_path (cr, get_svg_data (), Glyph.xc () + left, Glyph.yc () - baseline); 1725 1726 cr.save (); 1727 cr.new_path (); 1728 foreach (Path p in get_visible_paths ()) { 1729 if (p.stroke == 0) { 1730 color = p.color == null ? Color.black () : (!) p.color; 1731 p.draw_path (cr, this, color); 1732 } 1733 } 1734 cr.close_path (); 1735 cr.fill (); 1736 cr.restore (); 1737 1738 foreach (Path p in active_paths) { 1739 cr.save (); 1740 cr.new_path (); 1741 if (p.stroke == 0) { 1742 p.draw_path (cr, this); 1743 } 1744 cr.close_path (); 1745 cr.fill (); 1746 cr.restore (); 1747 } 1748 } 1749 1750 if (show_orientation_arrow) { 1751 foreach (Path p in get_visible_paths ()) { 1752 if (p.stroke > 0) { 1753 stroke = p.get_stroke_fast (); 1754 foreach (Path ps in stroke.paths) { 1755 ps.draw_orientation_arrow (cr, orientation_arrow_opacity); 1756 } 1757 } else { 1758 p.draw_orientation_arrow (cr, orientation_arrow_opacity); 1759 } 1760 } 1761 } 1762 } 1763 1764 private Color get_path_fill_color () { 1765 return Theme.get_color ("Fill Color"); 1766 } 1767 1768 public void draw_path_list (PathList pl, Context cr, Color? c = null) { 1769 foreach (Path p in pl.paths) { 1770 p.draw_path (cr, this, c); 1771 } 1772 } 1773 1774 public void draw_background_color (Context cr, double opacity) { 1775 if (opacity > 0) { 1776 cr.save (); 1777 cr.rectangle (0, 0, allocation.width, allocation.height); 1778 Theme.color (cr, "Canvas Background"); 1779 cr.fill (); 1780 cr.restore (); 1781 } 1782 } 1783 1784 public void draw_help_lines (Context cr) { 1785 foreach (Line line in get_all_help_lines ()) { 1786 cr.save (); 1787 line.draw (cr, allocation); 1788 cr.restore (); 1789 } 1790 } 1791 1792 public void set_allocation (WidgetAllocation a) { 1793 allocation = a; 1794 } 1795 1796 public override void draw (WidgetAllocation allocation, Context cmp) { 1797 Tool tool; 1798 1799 this.allocation = allocation; 1800 1801 cmp.save (); 1802 draw_background_color (cmp, 1); 1803 cmp.restore (); 1804 1805 if (background_image != null && background_image_visible) { 1806 ((!)background_image).draw (cmp, allocation, view_offset_x, view_offset_y, view_zoom); 1807 } 1808 1809 if (unlikely (Preferences.draw_boundaries)) { 1810 foreach (Path p in get_visible_paths ()) { 1811 p.draw_boundaries (cmp); 1812 } 1813 } 1814 1815 draw_background_glyph (allocation, cmp); 1816 juxtapose (allocation, cmp); 1817 1818 if (BirdFont.show_coordinates) { 1819 draw_coordinate (cmp); 1820 } 1821 1822 if (show_help_lines) { 1823 cmp.save (); 1824 draw_help_lines (cmp); 1825 cmp.restore (); 1826 } 1827 1828 if (!is_empty ()) { 1829 cmp.save (); 1830 cmp.scale (view_zoom, view_zoom); 1831 cmp.translate (-view_offset_x, -view_offset_y); 1832 draw_path (cmp); 1833 cmp.restore (); 1834 } 1835 1836 cmp.save (); 1837 tool = MainWindow.get_toolbox ().get_current_tool (); 1838 tool.draw_action (tool, cmp, this); 1839 cmp.restore (); 1840 } 1841 1842 private void zoom_in_at_point (double x, double y, double amount = 15) { 1843 int n = (int) (-amount); 1844 zoom_at_point (x, y, n); 1845 } 1846 1847 private void zoom_out_at_point (double x, double y, double amount = 15) { 1848 double a = -amount; 1849 int n = (int) (a * ((allocation.width - a) / allocation.width)); 1850 zoom_at_point (x, y, n); 1851 } 1852 1853 public void zoom_tap (double distance) { 1854 int w = (int) (distance); 1855 if (distance != 0) { 1856 show_zoom_area (-w , -w, allocation.width + w, allocation.height + w); 1857 set_zoom_from_area (); 1858 } 1859 } 1860 1861 /** Zoom in @param n pixels. */ 1862 private void zoom_at_point (double x, double y, int n) { 1863 double w = allocation.width; 1864 double h = allocation.height; 1865 1866 double rx = Math.fabs (w / 2 - x) / (w / 2); 1867 double ry = Math.fabs (h / 2 - y) / (h / 2); 1868 1869 int xd = (x < w / 2) ? (int) (n * rx) : (int) (-n * rx); 1870 int yd = (y < h / 2) ? (int) (n * ry) : (int) (-n * ry); 1871 1872 show_zoom_area (-n + xd, -n + yd, allocation.width + n + xd, allocation.height + n + yd); 1873 set_zoom_from_area (); 1874 } 1875 1876 private void move_view_offset (double x, double y) { 1877 view_offset_x = move_offset_x + (pointer_begin_x - x) * (1/view_zoom); 1878 view_offset_y = move_offset_y + (pointer_begin_y - y) * (1/view_zoom); 1879 GlyphCanvas.redraw (); 1880 } 1881 1882 public void store_undo_state (bool clear_redo = false) { 1883 Glyph g = copy (); 1884 undo_list.add (g); 1885 1886 if (clear_redo) { 1887 redo_list.clear (); 1888 } 1889 } 1890 1891 public void store_redo_state () { 1892 Glyph g = copy (); 1893 redo_list.add (g); 1894 } 1895 1896 public Glyph copy () { 1897 Glyph g = new Glyph.no_lines (name, unichar_code); 1898 1899 g.current_layer = current_layer; 1900 1901 g.left_limit = left_limit; 1902 g.right_limit = right_limit; 1903 1904 g.remove_lines (); 1905 1906 foreach (Line line in get_all_help_lines ()) { 1907 g.add_line (line.copy ()); 1908 } 1909 1910 g.layers = layers.copy (); 1911 1912 foreach (Path p in active_paths) { 1913 g.active_paths.add (p); 1914 } 1915 1916 if (background_image != null) { 1917 g.background_image = ((!) background_image).copy (); 1918 } 1919 1920 g.empty = empty; 1921 g.open = open; 1922 g.version_id = version_id; 1923 1924 return g; 1925 } 1926 1927 public void reload () { 1928 Font f = BirdFont.get_current_font (); 1929 1930 if (f.has_glyph (name)) { 1931 set_glyph_data ((!) f.get_glyph (name)); 1932 } 1933 } 1934 1935 public override void undo () { 1936 Glyph g; 1937 Tool tool; 1938 1939 if (undo_list.size == 0) { 1940 return; 1941 } 1942 1943 tool = MainWindow.get_toolbox ().get_current_tool (); 1944 tool.before_undo (); 1945 1946 g = undo_list.get (undo_list.size - 1); 1947 1948 store_redo_state (); 1949 set_glyph_data (g); 1950 1951 undo_list.remove_at (undo_list.size - 1); 1952 1953 DrawingTools.update_layers (); 1954 PenTool.update_selected_points (); 1955 1956 clear_active_paths (); 1957 1958 tool.after_undo (); 1959 } 1960 1961 public override void redo () { 1962 Glyph g; 1963 1964 if (redo_list.size == 0) { 1965 return; 1966 } 1967 1968 g = redo_list.get (redo_list.size - 1); 1969 1970 store_undo_state (false); 1971 set_glyph_data (g); 1972 1973 redo_list.remove_at (redo_list.size - 1); 1974 1975 DrawingTools.update_layers (); 1976 PenTool.update_selected_points (); 1977 1978 clear_active_paths (); 1979 } 1980 1981 void set_glyph_data (Glyph g) { 1982 current_layer = g.current_layer; 1983 layers = g.layers.copy (); 1984 1985 left_limit = g.left_limit; 1986 right_limit = g.right_limit; 1987 1988 remove_lines (); 1989 foreach (Line line in g.get_all_help_lines ()) { 1990 add_line (line.copy ()); 1991 } 1992 1993 add_help_lines (); 1994 1995 if (g.background_image != null) { 1996 background_image = ((!) g.background_image).copy (); 1997 } 1998 1999 clear_active_paths (); 2000 foreach (Path p in g.active_paths) { 2001 add_active_path (null, p); 2002 } 2003 2004 redraw_area (0, 0, allocation.width, allocation.height); 2005 } 2006 2007 /** Split curve in two parts and add a new point in between. 2008 * @return the new point 2009 */ 2010 public void insert_new_point_on_path (double x, double y) { 2011 double min, distance; 2012 Path? p = null; 2013 Path path; 2014 EditPoint? np = null; 2015 EditPoint lep; 2016 2017 double xt; 2018 double yt; 2019 2020 xt = x * ivz () - xc () + view_offset_x; 2021 yt = yc () - y * ivz () - view_offset_y; 2022 2023 min = double.MAX; 2024 2025 foreach (Path pp in get_visible_paths ()) { 2026 lep = new EditPoint (); 2027 pp.get_closest_point_on_path (lep, xt, yt); 2028 distance = Math.sqrt (Math.pow (Math.fabs (xt - lep.x), 2) + Math.pow (Math.fabs (yt - lep.y), 2)); 2029 2030 if (distance < min) { 2031 min = distance; 2032 p = pp; 2033 np = lep; 2034 } 2035 } 2036 2037 if (p == null) { 2038 return; 2039 } 2040 2041 path = (!) p; 2042 2043 lep = new EditPoint (); 2044 path.get_closest_point_on_path (lep, xt, yt); 2045 path.insert_new_point_on_path (lep); 2046 } 2047 2048 static bool in_range (double offset_x, double coordinate_x1, double coordinate_x2) { 2049 return coordinate_x1 <= offset_x <= coordinate_x2; 2050 } 2051 2052 public void juxtapose (WidgetAllocation allocation, Context cr) { 2053 string glyph_sequence = Preferences.get ("glyph_sequence"); 2054 unichar c; 2055 Font font = BirdFont.get_current_font (); 2056 Glyph glyph = MainWindow.get_current_glyph (); 2057 Glyph juxtaposed; 2058 StringBuilder current = new StringBuilder (); 2059 int pos; 2060 string name; 2061 double x, kern; 2062 double left, baseline; 2063 string last_name; 2064 2065 double box_x1, box_x2, box_y1, box_y2; 2066 double marker_x, marker_y; 2067 2068 KerningClasses classes = font.get_kerning_classes (); 2069 2070 x = 0; 2071 2072 box_x1 = path_coordinate_x (0); 2073 box_y1 = path_coordinate_y (0); 2074 box_x2 = path_coordinate_x (allocation.width); 2075 box_y2 = path_coordinate_y (allocation.height); 2076 2077 current.append_unichar (glyph.unichar_code); 2078 pos = glyph_sequence.index_of (current.str); 2079 2080 baseline = font.base_line;; 2081 left = glyph.get_line ("left").pos; 2082 2083 x = glyph.get_width (); 2084 last_name = glyph.name; 2085 for (int i = pos + 1; i < glyph_sequence.char_count (); i++) { 2086 c = glyph_sequence.get_char (i); 2087 name = (!) c.to_string (); 2088 juxtaposed = (font.has_glyph (name)) ? (!) font.get_glyph (name) : font.get_space ().get_current (); 2089 2090 if (font.has_glyph (last_name) && font.has_glyph (name)) { 2091 kern = classes.get_kerning (last_name, name); 2092 } else { 2093 kern = 0; 2094 } 2095 2096 if (!juxtaposed.is_empty () 2097 && (in_range (left + x + kern, box_x1, box_x2) // the letter is visible 2098 || in_range (left + x + kern + juxtaposed.get_width (), box_x1, box_x2))) { 2099 2100 marker_x = Glyph.xc () + left + x + kern - glyph.view_offset_x; 2101 marker_y = Glyph.yc () - baseline - glyph.view_offset_y; 2102 2103 cr.save (); 2104 cr.scale (glyph.view_zoom, glyph.view_zoom); 2105 Theme.color (cr, "Foreground 1"); 2106 2107 Svg.draw_svg_path (cr, juxtaposed.get_svg_data (), marker_x, marker_y); 2108 cr.restore (); 2109 } 2110 2111 x += juxtaposed.get_width () + kern; 2112 2113 last_name = name; 2114 } 2115 2116 x = 0; 2117 last_name = glyph.name; 2118 for (int i = pos - 1; i >= 0; i--) { 2119 c = glyph_sequence.get_char (i); 2120 name = (!) c.to_string (); 2121 juxtaposed = (font.has_glyph (name)) ? (!) font.get_glyph (name) : font.get_space ().get_current (); 2122 2123 if (font.has_glyph (last_name) && font.has_glyph (name)) { 2124 kern = classes.get_kerning (name, last_name); 2125 } else { 2126 kern = 0; 2127 } 2128 2129 x -= juxtaposed.get_width (); 2130 x -= kern; 2131 2132 marker_x = Glyph.xc () + left + x; 2133 marker_y = Glyph.yc () - baseline; 2134 if (!juxtaposed.is_empty () 2135 &&(in_range (left + x, box_x1, box_x2) 2136 || in_range (left + x + juxtaposed.get_width (), box_x1, box_x2))) { 2137 cr.save (); 2138 cr.scale (glyph.view_zoom, glyph.view_zoom); 2139 cr.translate (-glyph.view_offset_x, -glyph.view_offset_y); 2140 Theme.color (cr, "Foreground 1"); 2141 Svg.draw_svg_path (cr, juxtaposed.get_svg_data (), marker_x, marker_y); 2142 cr.restore (); 2143 } 2144 2145 last_name = name; 2146 } 2147 } 2148 2149 /** @return left side bearing */ 2150 public double get_lsb () { 2151 return get_line ("left").pos; 2152 } 2153 2154 /** @return bottom line */ 2155 public double get_baseline () { 2156 Font font = BirdFont.get_current_font (); 2157 return font.base_line; 2158 } 2159 2160 void draw_background_glyph (WidgetAllocation allocation, Context cr) { 2161 double left, baseline, current_left; 2162 Glyph g; 2163 Font font = BirdFont.get_current_font (); 2164 2165 current_left = get_line ("left").pos; 2166 2167 if (background_glyph != null) { 2168 g = (!) background_glyph; 2169 baseline = font.base_line; 2170 left = g.get_line ("left").pos; 2171 cr.save (); 2172 cr.scale (view_zoom, view_zoom); 2173 cr.translate (-view_offset_x, -view_offset_y); 2174 Theme.color (cr, "Background Glyph"); 2175 2176 Svg.draw_svg_path (cr, g.get_svg_data (), 2177 Glyph.xc () + left - (left - current_left) , 2178 Glyph.yc () - baseline); 2179 cr.restore (); 2180 } 2181 2182 } 2183 2184 public string get_hex () { 2185 return Font.to_hex_code (unichar_code); 2186 } 2187 2188 public override void move_view (double x, double y) { 2189 view_offset_x += x / view_zoom; 2190 view_offset_y += y / view_zoom; 2191 GlyphCanvas.redraw (); 2192 } 2193 2194 /** Scroll or zoom from tap events. */ 2195 public void change_view_event (int finger, int x, int y) { 2196 double dx, dy; 2197 double last_distance, new_distance; 2198 2199 dx = 0; 2200 dy = 0; 2201 2202 new_distance = 0; 2203 2204 if (last_tap0_y == -1 || last_tap0_x == -1 || last_tap1_y == -1 || last_tap1_x == -1) { 2205 return; 2206 } 2207 2208 if (finger == 0) { 2209 dx = last_tap0_x - x; 2210 dy = last_tap0_y - y; 2211 new_distance = Path.distance (last_tap1_x, x, last_tap1_y, y); 2212 } 2213 2214 if (finger == 1) { 2215 dx = last_tap1_x - x; 2216 dy = last_tap1_y - y; 2217 new_distance = Path.distance (last_tap0_x, x, last_tap0_y, y); 2218 } 2219 2220 last_distance = Path.distance (last_tap0_x, last_tap1_x, last_tap0_y, last_tap1_y); 2221 2222 if (zoom_distance != 0) { 2223 zoom_tap (zoom_distance - new_distance); 2224 } 2225 2226 if (finger == 1) { 2227 warning (@"dx $dx dy $dy last_tap1_x $last_tap1_x last_tap1_y $last_tap1_y x $x y $y"); 2228 move_view (dx, dy); 2229 } 2230 2231 zoom_distance = new_distance; 2232 } 2233 2234 public override void tap_down (int finger, int x, int y) { 2235 TimeoutSource delay; 2236 2237 if (finger == 0) { 2238 delay = new TimeoutSource (400); // wait for second finger 2239 delay.set_callback(() => { 2240 if (!change_view && !ignore_input) { 2241 button_press (1, x, y); 2242 } 2243 return false; 2244 }); 2245 delay.attach (null); 2246 2247 last_tap0_x = x; 2248 last_tap0_y = y; 2249 } 2250 2251 if (finger == 1) { 2252 change_view = true; 2253 last_tap1_x = x; 2254 last_tap1_y = y; 2255 } 2256 } 2257 2258 public override void tap_up (int finger, int x, int y) { 2259 if (finger == 0) { 2260 button_release (1, x, y); 2261 2262 last_tap0_x = -1; 2263 last_tap0_y = -1; 2264 } 2265 2266 if (finger == 1) { 2267 last_tap1_x = -1; 2268 last_tap1_y = -1; 2269 2270 change_view = false; 2271 zoom_distance = 0; 2272 } 2273 } 2274 2275 public override void tap_move (int finger, int x, int y) { 2276 if (!change_view) { 2277 motion_notify (x, y); 2278 } else { 2279 change_view_event (finger, x, y); 2280 } 2281 2282 if (finger == 0) { 2283 last_tap0_x = x; 2284 last_tap0_y = y; 2285 } 2286 2287 if (finger == 1) { 2288 last_tap1_x = x; 2289 last_tap1_y = y; 2290 } 2291 } 2292 2293 public void update_spacing_class () { 2294 Font font = BirdFont.get_current_font (); 2295 GlyphCollection? g; 2296 GlyphCollection gc; 2297 Glyph glyph; 2298 Gee.ArrayList<string> s; 2299 SpacingData sd; 2300 2301 sd = font.get_spacing (); 2302 s = sd.get_all_connections ((!) unichar_code.to_string ()); 2303 foreach (string l in s) { 2304 if (l != (!) unichar_code.to_string ()) { 2305 g = font.get_glyph_collection (l); 2306 if (g != null) { 2307 gc = (!) g; 2308 glyph = gc.get_current (); 2309 2310 if (glyph.left_limit == glyph.right_limit) { 2311 warning ("Zero width glyph in kerning class."); 2312 } 2313 2314 left_limit = glyph.left_limit; 2315 right_limit = glyph.right_limit; 2316 2317 break; 2318 } 2319 } 2320 } 2321 2322 add_help_lines (); 2323 } 2324 2325 public void update_other_spacing_classes () { 2326 Font font = BirdFont.get_current_font (); 2327 GlyphCollection? g; 2328 GlyphCollection gc; 2329 Glyph glyph; 2330 Gee.ArrayList<string> s; 2331 SpacingData sd; 2332 2333 sd = font.get_spacing (); 2334 s = sd.get_all_connections (get_name ()); 2335 2336 foreach (string l in s) { 2337 if (l != (!) unichar_code.to_string ()) { 2338 g = font.get_glyph_collection (l); 2339 if (g != null) { 2340 gc = (!) g; 2341 glyph = gc.get_current (); 2342 glyph.left_limit = left_limit; 2343 glyph.right_limit = right_limit; 2344 } 2345 } 2346 } 2347 } 2348 2349 public void set_cache (string key, Surface cache) { 2350 glyph_cache.set (key, cache); 2351 } 2352 2353 public bool has_cache (string key) { 2354 return glyph_cache.has_key (key); 2355 } 2356 2357 public Surface get_cache (string key) { 2358 if (unlikely (!has_cache (key))) { 2359 warning ("No cache for glyph."); 2360 return new ImageSurface (Cairo.Format.ARGB32, 1, 1); 2361 } 2362 2363 return glyph_cache.get (key); 2364 } 2365 2366 public void add_custom_guide () { 2367 TextListener listener; 2368 2369 listener = new TextListener (t_("Guide"), "", t_("Add")); 2370 2371 listener.signal_text_input.connect ((text) => { 2372 new_guide_name = text; 2373 }); 2374 2375 listener.signal_submit.connect (() => { 2376 Line guide; 2377 double position; 2378 2379 position = path_coordinate_y (allocation.height / 2.0); 2380 guide = new Line (new_guide_name, new_guide_name, position); 2381 horizontal_help_lines.add (guide); 2382 2383 BirdFont.get_current_font ().custom_guides.add (guide); 2384 2385 TabContent.hide_text_input (); 2386 GlyphCanvas.redraw (); 2387 }); 2388 2389 TabContent.show_text_input (listener); 2390 } 2391 2392 public Path? get_last_path () { 2393 var paths = get_all_paths (); 2394 return_val_if_fail (paths.size > 0, null); 2395 return paths.get (paths.size - 1); 2396 } 2397 2398 public void move_layer_up () { 2399 Layer layer = get_current_layer (); 2400 2401 if (current_layer + 2 <= layers.subgroups.size) { 2402 return_if_fail (0 <= current_layer + 2 <= layers.subgroups.size); 2403 layers.subgroups.insert (current_layer + 2, layer); 2404 2405 return_if_fail (0 <= current_layer + 1 < layers.subgroups.size); 2406 layers.subgroups.remove_at (current_layer); 2407 2408 set_current_layer (layer); 2409 } 2410 } 2411 2412 public void move_layer_down () { 2413 Layer layer = get_current_layer (); 2414 2415 if (current_layer >= 1) { 2416 return_if_fail (0 <= current_layer - 1 < layers.subgroups.size); 2417 layers.subgroups.insert (current_layer - 1, layer); 2418 2419 return_if_fail (0 <= current_layer + 1 < layers.subgroups.size); 2420 layers.subgroups.remove_at (current_layer + 1); 2421 2422 set_current_layer (layer); 2423 } 2424 } 2425 2426 public void fix_curve_orientation () { 2427 int inside_count; 2428 bool inside; 2429 Path outline; 2430 2431 foreach (Path p1 in get_visible_paths ()) { 2432 inside_count = 0; 2433 2434 foreach (Path p2 in get_visible_paths ()) { 2435 if (p1 != p2) { 2436 inside = true; 2437 outline = p2.flatten (); 2438 2439 foreach (EditPoint ep in p1.points) { 2440 if (!SvgParser.is_inside (ep, outline)) { 2441 inside = false; 2442 } 2443 } 2444 2445 if (inside) { 2446 inside_count++; 2447 } 2448 } 2449 } 2450 2451 if (inside_count % 2 == 0) { 2452 p1.force_direction (Direction.CLOCKWISE); 2453 } else { 2454 p1.force_direction (Direction.COUNTER_CLOCKWISE); 2455 } 2456 } 2457 } 2458 2459 public override void magnify (double magnification) { 2460 double x_center = path_coordinate_x (xc ()); 2461 double y_center = path_coordinate_y (yc ()); 2462 2463 view_zoom *= 1 + magnification; 2464 2465 view_offset_x -= path_coordinate_x (xc ()) - x_center; 2466 view_offset_y += path_coordinate_y (yc ()) - y_center; 2467 2468 GlyphCanvas.redraw (); 2469 } 2470 2471 public Glyph self_interpolate (double weight) { 2472 Glyph g1 = copy (); 2473 Glyph g2 = copy (); 2474 2475 g1.fix_curve_orientation (); 2476 g2.layers = new Layer (); // remove all paths 2477 2478 foreach (Path p in g1.get_visible_paths ()) { 2479 bool counter = !p.is_clockwise (); 2480 2481 g2.add_path (p.copy ()); 2482 2483 p.remove_points_on_points (); 2484 Path master = p.get_self_interpolated_master (counter, weight); 2485 p = p.interpolate_estimated_path (master, weight); 2486 p.recalculate_linear_handles (); 2487 2488 g2.add_path (p); 2489 g2.add_path (master); 2490 } 2491 2492 return g2; 2493 } 2494 } 2495 2496 } 2497