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 public PathObject () { 35 base (); 36 path = new Path (); 37 update_region_boundaries (); 38 } 39 40 public PathObject.create_copy (PathObject p) { 41 base.create_copy (p); 42 path = p.path.copy (); 43 } 44 45 public PathObject.for_path (Path path) { 46 base (); 47 this.path = path; 48 } 49 50 public override bool is_over (double x, double y) { 51 return path.is_over_coordinate (x, y); 52 } 53 54 public override void draw_outline (Context cr) { 55 // drawing is handled in Glyph.draw_bird_font_paths 56 } 57 58 public void draw_path (Context cr) { 59 if (path.stroke > 0) { 60 draw_path_list (path.get_completed_stroke (), cr); 61 } else { 62 path.draw_path (cr); 63 } 64 } 65 66 public static void draw_path_list (PathList pl, Context cr) { 67 foreach (Path p in pl.paths) { 68 p.draw_path (cr); 69 } 70 } 71 72 public override void move (double dx, double dy) { 73 path.move (dx, dy); 74 path.reset_stroke (); 75 } 76 77 public Path get_path () { 78 return path; 79 } 80 81 public override void update_region_boundaries () { 82 xmin = Glyph.CANVAS_MAX; 83 xmax = Glyph.CANVAS_MIN; 84 ymin = Glyph.CANVAS_MAX; 85 ymax = Glyph.CANVAS_MIN; 86 87 path.update_region_boundaries (); 88 89 xmin = path.xmin; 90 xmax = path.xmax; 91 ymin = path.ymin; 92 ymax = path.ymax; 93 } 94 95 public override void rotate (double theta, double xc, double yc) { 96 path.rotate (theta, xc, yc); 97 } 98 99 public override bool is_empty () { 100 return path.points.size == 0; 101 } 102 103 public override void resize (double ratio_x, double ratio_y) { 104 path.resize (ratio_x, ratio_y); 105 path.reset_stroke (); 106 } 107 108 public override SvgBird.Object copy () { 109 return new PathObject.create_copy (this); 110 } 111 112 public override string to_string () { 113 return "PathObject"; 114 } 115 116 } 117 118 } 119