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

Revisions

View the latest version of libsvgbird/SvgDrawing.vala.
SVG M instruction
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 apply_transform (cr); 32 root_layer.update_boundaries (cr); 33 34 left = root_layer.left; 35 right = root_layer.right; 36 top = root_layer.top; 37 bottom = root_layer.bottom; 38 39 return true; 40 } 41 42 public override bool is_over (double x, double y) { 43 return false; 44 } 45 46 void apply_view_box (Context cr) { 47 if (view_box != null) { 48 ViewBox box = (!) view_box; 49 Matrix view_box_matrix = box.get_matrix (width, height); 50 Matrix view_matrix = cr.get_matrix (); 51 view_box_matrix.multiply (view_box_matrix, view_matrix); 52 cr.set_matrix (view_box_matrix); 53 } 54 } 55 56 public override void apply_transform (Context cr) { 57 apply_view_box (cr); 58 base.apply_transform (cr); 59 } 60 61 public void draw (Context cr) { 62 cr.save (); 63 apply_transform (cr); 64 root_layer.draw (cr); 65 cr.restore (); 66 } 67 68 public override void draw_outline (Context cr) { 69 root_layer.draw_outline (cr); 70 } 71 72 public override Object copy () { 73 SvgDrawing drawing = new SvgDrawing (); 74 SvgBird.Object.copy_attributes (this, drawing); 75 drawing.root_layer = (Layer) root_layer.copy (); 76 drawing.defs = defs.copy (); 77 drawing.width = width; 78 drawing.height = height; 79 80 if (view_box != null) { 81 drawing.view_box = ((!) view_box).copy (); 82 } 83 84 return drawing; 85 } 86 87 public override void move (double dx, double dy) { 88 } 89 90 public override bool is_empty () { 91 return false; 92 } 93 94 public override string to_string () { 95 return @"SvgDrawing width: $width, height: $height"; 96 } 97 } 98 99 } 100