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 using SvgBird; 17 18 namespace BirdFont { 19 20 public class PathObject : SvgBird.Object { 21 22 Path path; 23 24 // FIXME: flip y axis 25 public override double xmin { 26 get { 27 return path.xmin; 28 } 29 30 set { 31 path.xmin = value; 32 } 33 34 default = Glyph.CANVAS_MAX; 35 } 36 37 public override double xmax { 38 get { 39 return path.xmax; 40 } 41 42 set { 43 path.xmax = value; 44 } 45 46 default = Glyph.CANVAS_MIN; 47 } 48 49 public override double ymin { 50 get { 51 return path.ymin; 52 } 53 54 set { 55 path.ymin = value; 56 } 57 58 default = Glyph.CANVAS_MAX; 59 } 60 61 public override double ymax { 62 get { 63 return path.ymax; 64 } 65 66 set { 67 path.ymax = value; 68 } 69 70 default = Glyph.CANVAS_MIN; 71 } 72 73 public PathObject () { 74 path = new Path (); 75 update_region_boundaries (); 76 } 77 78 public PathObject.create_copy (PathObject p) { 79 base.create_copy (p); 80 path = p.path.copy (); 81 } 82 83 public PathObject.for_path (Path path) { 84 this.path = path; 85 } 86 87 public override bool is_over (double x, double y) { 88 return path.is_over_coordinate (x, y); 89 } 90 91 public override void draw (Context cr) { 92 draw_path (cr); 93 } 94 95 public void draw_path (Context cr, Color? c = null) { 96 PathList path_stroke; 97 Color path_color; 98 bool open; 99 100 cr.save (); 101 102 if (c != null) { 103 path_color = (!) c; 104 } else if (color != null) { 105 path_color = new Color.create_copy ((!) color); 106 } else { 107 path_color = Color.black (); 108 } 109 110 if (path.stroke > 0) { 111 path_stroke = path.get_stroke_fast (); 112 draw_path_list (path_stroke, cr, path_color); 113 } else { 114 open = path.is_open (); 115 116 if (open) { 117 path.close (); 118 path.recalculate_linear_handles (); 119 } 120 121 path.draw_path (cr, path_color); 122 123 if (open) { 124 path.reopen (); 125 } 126 } 127 128 cr.restore (); 129 } 130 131 public static void draw_path_list (PathList pl, Context cr, Color? c = null) { 132 foreach (Path p in pl.paths) { 133 p.draw_path (cr, c); 134 } 135 } 136 137 public override void move (double dx, double dy) { 138 path.move (dx, dy); 139 path.reset_stroke (); 140 } 141 142 public Path get_path () { 143 return path; 144 } 145 146 public override void update_region_boundaries () { 147 path.update_region_boundaries (); 148 } 149 150 public override void rotate (double theta, double xc, double yc) { 151 path.rotate (theta, xc, yc); 152 } 153 154 public override bool is_empty () { 155 return path.points.size == 0; 156 } 157 158 public override void resize (double ratio_x, double ratio_y) { 159 path.resize (ratio_x, ratio_y); 160 path.reset_stroke (); 161 } 162 163 public override SvgBird.Object copy () { 164 return new PathObject.create_copy (this); 165 } 166 167 public override string to_string () { 168 return "PathObject"; 169 } 170 171 } 172 173 } 174