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
Circle boundaries heads/master
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 Gee.ArrayList<SvgBird.Object> get_visible_objects (Layer layer) { 22 ObjectGroup group = new ObjectGroup (); 23 add_visible_objects (layer, group); 24 return group.objects; 25 } 26 27 public static void add_visible_objects (Layer layer, ObjectGroup objects) { 28 foreach (SvgBird.Object o in layer.objects) { 29 if (o is Layer) { 30 Layer sublayer = (Layer) o; 31 32 if (sublayer.visible) { 33 add_visible_objects (sublayer, objects); 34 } 35 } else { 36 if (o.visible) { 37 objects.add (o); 38 } 39 } 40 } 41 } 42 43 public static PathList get_all_paths (Layer layer) { 44 PathList paths = new PathList (); 45 add_paths_to_group (layer, paths); 46 return paths; 47 } 48 49 public static void add_paths_to_group (Layer layer, PathList paths) { 50 foreach (SvgBird.Object o in layer.objects) { 51 if (o is PathObject) { 52 PathObject p = (PathObject) o; 53 paths.add (p.get_path ()); 54 } else if (o is Layer) { 55 add_visible_paths_to_group ((Layer) o, paths); 56 } 57 } 58 } 59 60 public static PathList get_visible_paths (Layer layer) { 61 PathList paths = new PathList (); 62 add_visible_paths_to_group (layer, paths); 63 return paths; 64 } 65 66 public static void add_visible_paths_to_group (Layer layer, PathList paths) { 67 foreach (SvgBird.Object o in layer.objects) { 68 if (o.visible) { 69 if (o is PathObject) { 70 PathObject p = (PathObject) o; 71 paths.add (p.get_path ()); 72 } else if (o is Layer) { 73 add_visible_paths_to_group ((Layer) o, paths); 74 } 75 } 76 } 77 } 78 79 public static void add_path (Layer layer, Path path) { 80 PathObject p = new PathObject.for_path (path); 81 layer.add_object (p); 82 } 83 84 public static void append_paths (Layer layer, PathList path_list) { 85 foreach (Path p in path_list.paths) { 86 add_path (layer, p); 87 } 88 } 89 90 private static PathObject? get_object_path (Layer layer, Path path) { 91 foreach (SvgBird.Object o in layer.objects) { 92 if (o is PathObject) { 93 PathObject p = (PathObject) o; 94 if (p.get_path () == path) { 95 return p; 96 } 97 } 98 } 99 100 return null; 101 } 102 103 public static void remove_path (Layer layer, Path path) { 104 PathObject? p = get_object_path (layer, path); 105 106 if (p != null) { 107 layer.objects.remove ((!) p); 108 } 109 110 foreach (SvgBird.Layer sublayer in layer.get_sublayers ()) { 111 remove_path (sublayer, path); 112 } 113 } 114 115 public static PathList get_paths_in_layer (Layer layer) { 116 PathList paths = new PathList (); 117 118 foreach (SvgBird.Object object in layer.objects) { 119 if (object is PathObject) { 120 paths.add (((PathObject) object).get_path ()); 121 } 122 } 123 124 return paths; 125 } 126 } 127 128 } 129