The Birdfont Source Code


All Repositories / birdfont.git / blob – RSS feed

LayerUtils.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/LayerUtils.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 SvgBird; 16 17 namespace BirdFont { 18 19 public class LayerUtils { 20 21 public static PathList get_all_paths (Layer layer) { 22 ObjectGroup objects = layer.get_all_objects (); 23 PathList paths = new PathList (); 24 25 foreach (SvgBird.Object o in objects) { 26 if (o is PathObject) { 27 PathObject p = (PathObject) o; 28 paths.add (p.get_path ()); 29 } 30 } 31 32 return paths; 33 } 34 35 public static PathList get_visible_paths (Layer layer) { 36 ObjectGroup objects = layer.get_visible_objects (); 37 PathList paths = new PathList (); 38 39 foreach (SvgBird.Object o in objects) { 40 if (o is PathObject) { 41 PathObject p = (PathObject) o; 42 paths.add (p.get_path ()); 43 } 44 } 45 46 return paths; 47 } 48 49 public static void add_path (Layer layer, Path path) { 50 PathObject p = new PathObject.for_path (path); 51 layer.add_object (p); 52 } 53 54 public static void append_paths (Layer layer, PathList path_list) { 55 foreach (Path p in path_list.paths) { 56 add_path (layer, p); 57 } 58 } 59 60 private static PathObject? get_object_path (Layer layer, Path path) { 61 foreach (SvgBird.Object o in layer.objects) { 62 if (o is PathObject) { 63 PathObject p = (PathObject) o; 64 if (p.get_path () == path) { 65 return p; 66 } 67 } 68 } 69 70 return null; 71 } 72 73 public static void remove_path (Layer layer, Path path) { 74 PathObject? p = get_object_path (layer, path); 75 76 if (p != null) { 77 layer.objects.remove ((!) p); 78 } 79 80 foreach (SvgBird.Layer sublayer in layer.subgroups) { 81 remove_path (sublayer, path); 82 } 83 } 84 85 public static PathList get_paths_in_layer (Layer layer) { 86 PathList paths = new PathList (); 87 88 foreach (SvgBird.Object object in layer.objects) { 89 if (object is PathObject) { 90 paths.add (((PathObject) object).get_path ()); 91 } 92 } 93 94 return paths; 95 } 96 } 97 98 } 99