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.
Bounding box for SVG rectangles
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 override 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 93 public void draw_path (Context cr) { 94 if (path.stroke > 0) { 95 draw_path_list (path.get_completed_stroke (), cr); 96 } else { 97 path.draw_path (cr); 98 } 99 } 100 101 public static void draw_path_list (PathList pl, Context cr) { 102 foreach (Path p in pl.paths) { 103 p.draw_path (cr); 104 } 105 } 106 107 public override void move (double dx, double dy) { 108 path.move (dx, dy); 109 path.reset_stroke (); 110 } 111 112 public Path get_path () { 113 return path; 114 } 115 116 public override void update_boundaries (Matrix matrix) { 117 xmin = Glyph.CANVAS_MAX; 118 xmax = Glyph.CANVAS_MIN; 119 ymin = Glyph.CANVAS_MAX; 120 ymax = Glyph.CANVAS_MIN; 121 122 path.update_region_boundaries (); 123 124 xmin = path.xmin; 125 xmax = path.xmax; 126 ymin = path.ymin; 127 ymax = path.ymax; 128 } 129 130 public override void rotate (double theta, double xc, double yc) { 131 path.rotate (theta, xc, yc); 132 } 133 134 public override bool is_empty () { 135 return path.points.size == 0; 136 } 137 138 public override void resize (double ratio_x, double ratio_y) { 139 path.resize (ratio_x, ratio_y); 140 path.reset_stroke (); 141 } 142 143 public override SvgBird.Object copy () { 144 return new PathObject.create_copy (this); 145 } 146 147 public override string to_string () { 148 return "PathObject"; 149 } 150 151 } 152 153 } 154