The Birdfont Source Code


All Repositories / birdfont.git / blob – RSS feed

PathList.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
Circle boundaries heads/master
1 /* 2 Copyright (C) 2013 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 SvgBird; 16 17 namespace BirdFont { 18 19 public class PathList : GLib.Object { 20 public Gee.ArrayList<Path> paths; 21 22 public PathList () { 23 paths = new Gee.ArrayList<Path> (); 24 } 25 26 public PathList.for_path (Path p) { 27 paths = new Gee.ArrayList<Path> (); 28 paths.add (p); 29 } 30 31 public void remove (Path p) { 32 paths.remove (p); 33 } 34 35 public void add_unique (Path p) { 36 if (paths.index_of (p) == -1) { 37 paths.add (p); 38 } 39 } 40 41 public void add (Path p) { 42 paths.add (p); 43 } 44 45 public void append (PathList pl) { 46 foreach (Path p in pl.paths) { 47 paths.add (p); 48 } 49 } 50 51 public void clear () { 52 paths.clear (); 53 } 54 55 public Path get_first_path () { 56 if (unlikely (paths.size == 0)) { 57 warning ("No path"); 58 return new Path (); 59 } 60 61 return paths.get (0); 62 } 63 64 public Path merge_all () { 65 Path p = get_first_path (); 66 67 for (int i = 1; i < paths.size; i++) { 68 p.append_path (paths.get (i)); 69 } 70 71 return p; 72 } 73 74 public PathList copy () { 75 PathList pl = new PathList (); 76 77 foreach (Path p in paths) { 78 pl.add (p.copy ()); 79 } 80 81 return pl; 82 } 83 84 public void apply_style (SvgStyle style) { 85 foreach (Path p in paths) { 86 if (style.has_stroke ()) { 87 p.stroke = style.get_stroke_width (); 88 } else { 89 p.stroke = 0; 90 } 91 92 p.line_cap = style.get_line_cap (); 93 p.reset_stroke (); 94 p.update_region_boundaries (); 95 } 96 } 97 } 98 99 } 100