The Birdfont Source Code


All Repositories / birdfont.git / blob – RSS feed

SvgDrawing.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
Circle boundaries heads/master
1 /* 2 Copyright (C) 2016 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 16 using B; 17 using Cairo; 18 using Math; 19 20 namespace SvgBird { 21 22 public class SvgDrawing : Object { 23 public Layer root_layer = new Layer (); 24 public Defs defs = new Defs (); 25 public ViewBox? view_box = null; 26 27 public double width = 0; 28 public double height = 0; 29 30 public override bool update_boundaries (Context cr) { 31 parent_matrix = copy_matrix (cr.get_matrix ()); 32 base.apply_transform (cr); 33 apply_view_box (cr); 34 view_matrix = copy_matrix (cr.get_matrix ()); 35 36 root_layer.update_boundaries (cr); 37 38 left = root_layer.left; 39 right = root_layer.right; 40 top = root_layer.top; 41 bottom = root_layer.bottom; 42 43 return root_layer.right - root_layer.left > 0; 44 } 45 46 public override bool is_over (double x, double y) { 47 return false; 48 } 49 50 void apply_view_box (Context cr) { 51 if (view_box != null) { 52 ViewBox box = (!) view_box; 53 Matrix view_box_matrix = box.get_matrix (width, height); 54 Matrix object_matrix = cr.get_matrix (); 55 view_box_matrix.multiply (view_box_matrix, object_matrix); 56 cr.set_matrix (view_box_matrix); 57 } 58 } 59 60 public override void apply_transform (Context cr) { 61 Matrix view_matrix = cr.get_matrix (); 62 Matrix object_matrix = transforms.get_matrix (); 63 object_matrix.multiply (object_matrix, view_matrix); 64 cr.set_matrix (object_matrix); 65 66 apply_view_box (cr); 67 } 68 69 public void draw (Context cr) { 70 cr.save (); 71 base.apply_transform (cr); 72 apply_view_box (cr); 73 root_layer.draw (cr); 74 cr.restore (); 75 } 76 77 public override void draw_outline (Context cr) { 78 root_layer.draw_outline (cr); 79 } 80 81 public override Object copy () { 82 SvgDrawing drawing = new SvgDrawing (); 83 SvgBird.Object.copy_attributes (this, drawing); 84 drawing.root_layer = (Layer) root_layer.copy (); 85 drawing.defs = defs.copy (); 86 drawing.width = width; 87 drawing.height = height; 88 89 if (view_box != null) { 90 drawing.view_box = ((!) view_box).copy (); 91 } 92 93 return drawing; 94 } 95 96 public override bool is_empty () { 97 return false; 98 } 99 100 public override string to_string () { 101 return @"SvgDrawing width: $width, height: $height"; 102 } 103 } 104 105 } 106