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