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