The Birdfont Source Code


All Repositories / birdfont.git / blob – RSS feed

PathObject.vala in /libbirdfont

This file is a part of the Birdfont project.

Contributing

Send patches or pull requests to johan.mattsson.m@gmail.com.
Clone this repository: git clone https://github.com/johanmattssonm/birdfont.git
Circle boundaries heads/master
1 /* 2 Copyright (C) 2015 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 SvgBird; 17 18 namespace BirdFont { 19 20 public class PathObject : SvgBird.Object { 21 22 public Path path; 23 24 public override double left { 25 get { 26 return path.xmin; 27 } 28 29 set { 30 } 31 } 32 33 public override double right { 34 get { 35 return path.xmax; 36 } 37 38 set { 39 } 40 } 41 42 public override double top { 43 get { 44 return -path.ymax; 45 } 46 47 set { 48 } 49 } 50 51 public override double bottom { 52 get { 53 return -path.ymin; 54 } 55 56 set { 57 } 58 } 59 60 public double stroke { 61 get { 62 return path.stroke; 63 } 64 65 set { 66 path.stroke = value; 67 } 68 } 69 70 public PathObject () { 71 base (); 72 path = new Path (); 73 } 74 75 public PathObject.create_copy (PathObject p) { 76 base.create_copy (p); 77 path = p.path.copy (); 78 } 79 80 public PathObject.for_path (Path path) { 81 base (); 82 this.path = path; 83 } 84 85 public override bool is_over (double x, double y) { 86 return path.is_over_coordinate (x, y); 87 } 88 89 public override void draw_outline (Context cr) { 90 // drawing is handled in Glyph.draw_bird_font_paths 91 92 if (path.stroke > 0) { 93 //draw_path_list (path.get_completed_stroke (), cr); 94 draw_path_list (path.get_stroke_fast (), cr); 95 } else { 96 path.draw_path (cr); 97 } 98 } 99 100 public void draw_path (Context cr) { 101 cr.save (); 102 apply_transform (cr); 103 104 if (path.stroke > 0) { 105 draw_path_list (path.get_completed_stroke (), cr); 106 } else { 107 path.draw_path (cr); 108 } 109 110 cr.restore (); 111 } 112 113 public static void draw_path_list (PathList pl, Context cr) { 114 foreach (Path p in pl.paths) { 115 p.draw_path (cr); 116 } 117 } 118 119 public override void move (double dx, double dy) { 120 path.move (dx, dy); 121 path.reset_stroke (); 122 } 123 124 public Path get_path () { 125 return path; 126 } 127 128 public override bool update_boundaries (Context cr) { 129 if (path.points.size < 2) { 130 return false; 131 } 132 133 return base.update_boundaries (cr); 134 } 135 136 public override bool is_empty () { 137 return path.points.size == 0; 138 } 139 140 public override SvgBird.Object copy () { 141 return new PathObject.create_copy (this); 142 } 143 144 public override string to_string () { 145 return "PathObject"; 146 } 147 148 } 149 150 } 151