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.
Store boundaries in SVG coordinates
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 stroke { 25 get { 26 return path.stroke; 27 } 28 29 set { 30 path.stroke = value; 31 } 32 } 33 34 // FIXME: flip y axis 35 public override double xmin { 36 get { 37 return path.xmin; 38 } 39 40 set { 41 path.xmin = value; 42 } 43 44 default = Glyph.CANVAS_MAX; 45 } 46 47 public override double xmax { 48 get { 49 return path.xmax; 50 } 51 52 set { 53 path.xmax = value; 54 } 55 56 default = Glyph.CANVAS_MIN; 57 } 58 59 public override double ymin { 60 get { 61 return path.ymin; 62 } 63 64 set { 65 path.ymin = value; 66 } 67 68 default = Glyph.CANVAS_MAX; 69 } 70 71 public override double ymax { 72 get { 73 return path.ymax; 74 } 75 76 set { 77 path.ymax = value; 78 } 79 80 default = Glyph.CANVAS_MIN; 81 } 82 83 public PathObject () { 84 base (); 85 path = new Path (); 86 update_region_boundaries (); 87 } 88 89 public PathObject.create_copy (PathObject p) { 90 base.create_copy (p); 91 path = p.path.copy (); 92 } 93 94 public PathObject.for_path (Path path) { 95 base (); 96 this.path = path; 97 } 98 99 public override bool is_over (double x, double y) { 100 return path.is_over_coordinate (x, y); 101 } 102 103 public override void draw_outline (Context cr) { 104 // drawing is handled in Glyph.draw_bird_font_paths 105 } 106 107 public void draw_path (Context cr) { 108 if (path.stroke > 0) { 109 draw_path_list (path.get_completed_stroke (), cr); 110 } else { 111 path.draw_path (cr); 112 } 113 } 114 115 public static void draw_path_list (PathList pl, Context cr) { 116 foreach (Path p in pl.paths) { 117 p.draw_path (cr); 118 } 119 } 120 121 public override void move (double dx, double dy) { 122 path.move (dx, dy); 123 path.reset_stroke (); 124 } 125 126 public Path get_path () { 127 return path; 128 } 129 130 public override void update_region_boundaries () { 131 path.update_region_boundaries (); 132 } 133 134 public override void rotate (double theta, double xc, double yc) { 135 path.rotate (theta, xc, yc); 136 } 137 138 public override bool is_empty () { 139 return path.points.size == 0; 140 } 141 142 public override void resize (double ratio_x, double ratio_y) { 143 path.resize (ratio_x, ratio_y); 144 path.reset_stroke (); 145 } 146 147 public override SvgBird.Object copy () { 148 return new PathObject.create_copy (this); 149 } 150 151 public override string to_string () { 152 return "PathObject"; 153 } 154 155 } 156 157 } 158