The Birdfont Source Code


All Repositories / birdfont.git / blob – RSS feed

Layer.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/Layer.vala.
Use trusty in travis
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 namespace BirdFont { 16 17 public class Layer : GLib.Object { 18 public PathList paths; 19 public Gee.ArrayList<Layer> subgroups; 20 public bool visible = true; 21 public string name = "Layer"; 22 23 public bool is_counter = false; 24 public Gradient? gradient = null; 25 public bool single_path = false; 26 27 public Layer () { 28 paths = new PathList (); 29 subgroups = new Gee.ArrayList<Layer> (); 30 } 31 32 public int index_of (Layer sublayer) { 33 return subgroups.index_of (sublayer); 34 } 35 36 public PathList get_all_paths () { 37 PathList p = new PathList (); 38 39 p.append (paths); 40 41 foreach (Layer sublayer in subgroups) { 42 p.append (sublayer.get_all_paths ()); 43 } 44 45 return p; 46 } 47 48 public PathList get_visible_paths () { 49 PathList p = new PathList (); 50 51 if (visible) { 52 p.append (paths); 53 } 54 55 foreach (Layer sublayer in subgroups) { 56 if (sublayer.visible) { 57 p.append (sublayer.get_all_paths ()); 58 } 59 } 60 61 return p; 62 } 63 64 public void add_layer (Layer layer) { 65 subgroups.add (layer); 66 } 67 68 public void add_path (Path path) { 69 paths.add (path); 70 } 71 72 public void remove_path (Path path) { 73 paths.remove (path); 74 foreach (Layer sublayer in subgroups) { 75 sublayer.remove_path (path); 76 } 77 } 78 79 public void remove_layer (Layer layer) { 80 subgroups.remove (layer); 81 foreach (Layer sublayer in subgroups) { 82 sublayer.remove_layer (layer); 83 } 84 } 85 86 public Layer copy () { 87 Layer layer = new Layer (); 88 89 layer.name = name; 90 layer.paths = paths.copy (); 91 layer.visible = visible; 92 93 foreach (Layer l in subgroups) { 94 layer.subgroups.add (l.copy ()); 95 } 96 97 if (gradient != null) { 98 layer.gradient = ((!) gradient).copy (); 99 } 100 101 layer.single_path = single_path; 102 103 return layer; 104 } 105 106 public void get_boundaries (out double x, out double y, out double w, out double h) { 107 double px, py, px2, py2; 108 109 px = Glyph.CANVAS_MAX; 110 py = Glyph.CANVAS_MAX; 111 px2 = Glyph.CANVAS_MIN; 112 py2 = Glyph.CANVAS_MIN; 113 114 foreach (Path p in get_all_paths ().paths) { 115 if (px > p.xmin) { 116 px = p.xmin; 117 } 118 119 if (py > p.ymin) { 120 py = p.ymin; 121 } 122 123 if (px2 < p.xmax) { 124 px2 = p.xmax; 125 } 126 127 if (py2 < p.ymax) { 128 py2 = p.ymax; 129 } 130 } 131 132 w = px2 - px; 133 h = py2 - py; 134 x = px; 135 y = py2; 136 } 137 138 public void print (int indent = 0) { 139 foreach (Path p in paths.paths) { 140 for (int i = 0; i < indent; i++) { 141 stdout.printf ("\t"); 142 } 143 stdout.printf (@"Path open: $(p.is_open ())"); 144 145 if (p.color != null) { 146 stdout.printf (" %s", ((!) p.color).to_rgb_hex ()); 147 } 148 149 stdout.printf ("\n"); 150 } 151 152 foreach (Layer l in subgroups) { 153 for (int i = 0; i < indent; i++) { 154 stdout.printf ("\t"); 155 } 156 stdout.printf ("%s\n", l.name); 157 l.print (indent + 1); 158 } 159 } 160 } 161 162 } 163