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

Revisions

View the latest version of libbirdfont/PathObject.vala.
Move the SVG parser and the SVG rendering code to libsvgbird
1 /* 2 Copyright (C) 2015 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 17 namespace BirdFont { 18 19 public class PathObject : Object { 20 21 Path path; 22 23 public override double stroke { 24 get { 25 return path.stroke; 26 } 27 28 set { 29 path.stroke = value; 30 } 31 } 32 33 public override double rotation { 34 get { 35 return path.rotation; 36 } 37 38 set { 39 path.rotation = value; 40 } 41 } 42 43 public override LineCap line_cap { 44 get { 45 return path.line_cap; 46 } 47 48 set { 49 path.line_cap = value; 50 } 51 } 52 53 public override bool fill { 54 get { 55 return path.fill; 56 } 57 58 set { 59 path.fill = value; 60 } 61 } 62 63 public override Color? color { 64 get { 65 return path.color; 66 } 67 68 set { 69 path.color = value; 70 } 71 } 72 73 public override Color? stroke_color { 74 get { 75 return path.stroke_color; 76 } 77 78 set { 79 path.stroke_color = value; 80 } 81 } 82 83 public override Gradient? gradient { 84 get { 85 return path.gradient; 86 } 87 88 set { 89 path.gradient = value; 90 } 91 } 92 93 public override double xmin { 94 get { 95 return path.xmin; 96 } 97 98 set { 99 path.xmin = value; 100 } 101 102 default = Glyph.CANVAS_MAX; 103 } 104 105 public override double xmax { 106 get { 107 return path.xmax; 108 } 109 110 set { 111 path.xmax = value; 112 } 113 114 default = Glyph.CANVAS_MIN; 115 } 116 117 public override double ymin { 118 get { 119 return path.ymin; 120 } 121 122 set { 123 path.ymin = value; 124 } 125 126 default = Glyph.CANVAS_MAX; 127 } 128 129 public override double ymax { 130 get { 131 return path.ymax; 132 } 133 134 set { 135 path.ymax = value; 136 } 137 138 default = Glyph.CANVAS_MIN; 139 } 140 141 public PathObject () { 142 path = new Path (); 143 update_region_boundaries (); 144 } 145 146 public PathObject.create_copy (PathObject p) { 147 base.create_copy (p); 148 path = p.path.copy (); 149 } 150 151 public PathObject.for_path (Path path) { 152 this.path = path; 153 } 154 155 public override bool is_over (double x, double y) { 156 return path.is_over_coordinate (x, y); 157 } 158 159 public override void draw (Context cr) { 160 draw_path (cr); 161 } 162 163 public void draw_path (Context cr, Color? c = null) { 164 PathList path_stroke; 165 Color path_color; 166 bool open; 167 168 cr.save (); 169 170 if (c != null) { 171 path_color = (!) c; 172 } else if (color != null) { 173 path_color = (!) color; 174 } else { 175 path_color = Color.black (); 176 } 177 178 if (path.stroke > 0) { 179 path_stroke = path.get_stroke_fast (); 180 draw_path_list (path_stroke, cr, path_color); 181 } else { 182 open = path.is_open (); 183 184 if (open) { 185 path.close (); 186 path.recalculate_linear_handles (); 187 } 188 189 path.draw_path (cr, path_color); 190 191 if (open) { 192 path.reopen (); 193 } 194 } 195 196 cr.restore (); 197 } 198 199 public static void draw_path_list (PathList pl, Context cr, Color? c = null) { 200 foreach (Path p in pl.paths) { 201 p.draw_path (cr, c); 202 } 203 } 204 205 public override void move (double dx, double dy) { 206 path.move (dx, dy); 207 path.reset_stroke (); 208 } 209 210 public Path get_path () { 211 return path; 212 } 213 214 public override void update_region_boundaries () { 215 path.update_region_boundaries (); 216 } 217 218 public override void rotate (double theta, double xc, double yc) { 219 path.rotate (theta, xc, yc); 220 } 221 222 public override bool is_empty () { 223 return path.points.size == 0; 224 } 225 226 public override void resize (double ratio_x, double ratio_y) { 227 path.resize (ratio_x, ratio_y); 228 path.reset_stroke (); 229 } 230 231 public override Object copy () { 232 return new PathObject.create_copy (this); 233 } 234 235 public override string to_string () { 236 return "PathObject"; 237 } 238 239 } 240 241 } 242