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.
SVG boundaries for ellipses
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 left { 30 get { 31 return x + drawing.left; 32 } 33 34 set { 35 } 36 } 37 38 public override double right { 39 get { 40 return x + drawing.right; 41 } 42 43 set { 44 } 45 } 46 47 public override double top { 48 get { 49 return drawing.top - y; 50 } 51 52 set { 53 } 54 } 55 56 public override double bottom { 57 get { 58 return drawing.bottom - 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 public override bool is_over (double x, double y) { 74 return (xmin <= x <= xmax) 75 && (ymin <= y <= ymax); 76 } 77 78 public void draw_embedded_svg (Context cr) { 79 cr.save (); 80 cr.translate (Glyph.xc () + x, Glyph.yc () - y); 81 drawing.draw (cr); 82 cr.restore (); 83 } 84 85 public override void draw_outline (Context cr) { 86 } 87 88 public override void move (double dx, double dy) { 89 x += dx; 90 y += dy; 91 } 92 93 public override void rotate (double theta, double xc, double yc) { 94 drawing.rotate (theta, xc, yc); 95 } 96 97 public override bool is_empty () { 98 return drawing.is_empty (); 99 } 100 101 public override void resize (double ratio_x, double ratio_y) { 102 drawing.resize (ratio_x, ratio_y); 103 } 104 105 public override SvgBird.Object copy () { 106 EmbeddedSvg svg = new EmbeddedSvg ((SvgDrawing) drawing.copy ()); 107 SvgBird.Object.copy_attributes (this, svg); 108 svg.svg_data = svg_data; 109 svg.x = x; 110 svg.y = y; 111 return svg; 112 } 113 114 public override string to_string () { 115 return "Embedded SVG"; 116 } 117 } 118 119 } 120