The Birdfont Source Code


All Repositories / birdfont.git / blob – RSS feed

Layer.vala in libsvgbird

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 libsvgbird/Layer.vala.
SVG boundaries for ellipses
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 Cairo; 16 17 namespace SvgBird { 18 19 public class Layer : Object { 20 public ObjectGroup objects; 21 public string name = "Layer"; 22 23 public Layer () { 24 objects = new ObjectGroup (); 25 transforms = new SvgTransforms (); 26 } 27 28 public Layer.with_name (string name) { 29 this.name = name; 30 objects = new ObjectGroup (); 31 transforms = new SvgTransforms (); 32 } 33 34 public void draw (Context cr) { 35 cr.save (); 36 apply_transform (cr); 37 38 if (clip_path != null) { 39 ClipPath clipping = (!) clip_path; 40 clipping.apply (cr); 41 } 42 43 foreach (Object object in objects) { 44 cr.save (); 45 object.apply_transform (cr); 46 47 if (object.clip_path != null) { 48 ClipPath clipping = (!) object.clip_path; 49 clipping.apply (cr); 50 } 51 52 if (object is Layer) { 53 Layer sublayer = (Layer) object; 54 sublayer.draw (cr); 55 } else { 56 object.draw_outline (cr); 57 object.paint (cr); 58 } 59 cr.restore (); 60 } 61 62 cr.restore (); 63 } 64 65 public override void draw_outline (Context cr) { 66 apply_transform (cr); 67 68 foreach (Object object in objects) { 69 cr.save (); 70 object.apply_transform (cr); 71 object.draw_outline (cr); 72 cr.restore (); 73 } 74 75 cr.restore (); 76 } 77 78 public int index_of (Layer sublayer) { 79 return objects.index_of (sublayer); 80 } 81 82 public void add_layer (Layer layer) { 83 objects.add (layer); 84 } 85 86 public void add_object (Object object) { 87 objects.add (object); 88 } 89 90 public void remove (Object o) { 91 objects.remove (o); 92 } 93 94 public void remove_layer (Layer layer) { 95 objects.remove (layer); 96 97 foreach (Object object in objects) { 98 if (object is Layer) { 99 Layer sublayer = (Layer) object; 100 sublayer.remove_layer (layer); 101 } 102 } 103 } 104 105 public static void copy_layer (Layer from, Layer to) { 106 to.name = from.name; 107 to.objects = from.objects.copy (); 108 } 109 110 public override Object copy () { 111 Layer layer = new Layer (); 112 copy_layer (this, layer); 113 Object.copy_attributes (this, layer); 114 return layer; 115 } 116 117 public Gee.ArrayList<Layer> get_sublayers () { 118 Gee.ArrayList<Layer> sublayers = new Gee.ArrayList<Layer> (); 119 120 foreach (Object object in objects) { 121 if (likely (object is Layer)) { 122 Layer sublayer = (Layer) object; 123 sublayers.add (sublayer); 124 } else { 125 warning ("An object in the group " + name + " is not a layer."); 126 } 127 } 128 129 return sublayers; 130 } 131 132 public void print (int indent = 0) { 133 stdout.printf (@"Layer: $(name)"); 134 135 if (!visible) { 136 stdout.printf (" hidden"); 137 } 138 139 stdout.printf (@" $(transforms) $(style)"); 140 stdout.printf (@"\n"); 141 142 foreach (Object object in objects) { 143 stdout.printf (@"$(object.to_string ()) $(object.transforms) $(object.style)"); 144 145 if (!object.visible) { 146 stdout.printf (" hidden"); 147 } 148 149 stdout.printf ("\n"); 150 151 for (int i = 0; i < indent; i++) { 152 stdout.printf ("\t"); 153 } 154 155 if (object is Layer) { 156 Layer sublayer = (Layer) object; 157 sublayer.print (indent + 1); 158 } 159 } 160 } 161 162 public override bool is_over (double x, double y) { 163 return false; 164 } 165 166 public override void move (double dx, double dy) { 167 } 168 169 public override void update_region_boundaries () { 170 } 171 172 public override void rotate (double theta, double xc, double yc) { 173 } 174 175 public override bool is_empty () { 176 return false; 177 } 178 179 public override void resize (double ratio_x, double ratio_y) { 180 } 181 182 public override string to_string () { 183 return "Layer: " + name; 184 } 185 } 186 187 } 188