The Birdfont Source Code


All Repositories / birdfont.git / blob – RSS feed

EmbeddedSvg.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/EmbeddedSvg.vala.
Move the SVG parser and the SVG rendering code to libsvgbird
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 using B; 16 using Math; 17 using Cairo; 18 19 namespace BirdFont { 20 21 public class EmbeddedSvg : Object { 22 public string svg_data = ""; 23 public SvgDrawing drawing = new SvgDrawing (); 24 25 public double x { get; set; } 26 public double y { get; set; } 27 28 public override double xmin { 29 get { 30 return x; 31 } 32 33 set { 34 } 35 } 36 37 public override double xmax { 38 get { 39 return x + drawing.width; 40 } 41 42 set { 43 } 44 } 45 46 47 public override double ymin { 48 get { 49 return y - drawing.height; 50 } 51 52 set { 53 } 54 } 55 56 public override double ymax { 57 get { 58 return y; 59 } 60 61 set { 62 } 63 } 64 65 public EmbeddedSvg (SvgDrawing drawing) { 66 this.drawing = drawing; 67 } 68 69 public override void update_region_boundaries () { 70 drawing.update_region_boundaries (); 71 } 72 73 // FIXME: handle this in SVG library instead 74 public override bool is_over (double x, double y) { 75 print (@" $(this.x) <= $(x) <= $(this.x) + $(drawing.width)"); 76 print (@" $(this.y) <= $(y) <= $(this.y) + $(drawing.height)"); 77 78 return (this.x <= x <= this.x + drawing.width) 79 && (this.y - drawing.height <= y <= this.y); 80 } 81 82 public override void draw (Context cr) { 83 cr.save (); 84 cr.translate (Glyph.xc () + x, Glyph.yc () - y); 85 drawing.draw (cr); 86 cr.restore (); 87 } 88 89 public override Object copy () { 90 EmbeddedSvg svg = new EmbeddedSvg (drawing); 91 svg.svg_data = svg_data; 92 return svg; 93 } 94 95 public override void move (double dx, double dy) { 96 x += dx; 97 y += dy; 98 } 99 100 public override void rotate (double theta, double xc, double yc) { 101 drawing.rotate (theta, xc, yc); 102 } 103 104 public override bool is_empty () { 105 return drawing.is_empty (); 106 } 107 108 public override void resize (double ratio_x, double ratio_y) { 109 drawing.resize (ratio_x, ratio_y); 110 } 111 112 } 113 114 } 115