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