The Birdfont Source Code


All Repositories / birdfont.git / blob – RSS feed

SvgPath.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/SvgPath.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 using Cairo; 16 17 namespace SvgBird { 18 19 public class SvgPath : Object { 20 public Gee.ArrayList<Points> points = new Gee.ArrayList<Points> (); 21 22 public SvgPath () { 23 } 24 25 public SvgPath.create_copy (SvgPath p) { 26 Object.copy_attributes (p, this); 27 28 foreach (Points point_data in p.points) { 29 points.add (point_data.copy ()); 30 } 31 } 32 33 public override bool is_over (double x, double y) { 34 return false; 35 } 36 37 public override void draw_outline (Context cr) { 38 foreach (Points p in points) { 39 draw_points (cr, p); 40 41 if (p.closed) { 42 cr.close_path (); 43 } 44 } 45 } 46 47 public void draw_points (Context cr, Points path) { 48 PointValue* points = path.point_data.data; 49 int size = path.point_data.size; 50 51 // points are padded up to 8 units 52 return_if_fail (size % 8 == 0); 53 54 for (int i = 0; i < size; i += 8) { 55 switch (points[i].type) { 56 case POINT_ARC: 57 draw_arc (cr, points[i + 1].value, points[i + 2].value, 58 points[i + 3].value, points[i + 4].value, 59 points[i + 5].value, points[i + 6].value, 60 points[i + 7].value); 61 break; 62 case POINT_CUBIC: 63 cr.curve_to (points[i + 1].value, points[i + 2].value, 64 points[i + 3].value, points[i + 4].value, 65 points[i + 5].value, points[i + 6].value); 66 break; 67 case POINT_LINE: 68 cr.line_to (points[i + 1].value, points[i + 2].value); 69 break; 70 } 71 } 72 } 73 74 static void draw_arc (Context cr, 75 double x, double y, 76 double rx, double ry, 77 double angle_start, double angle_extent, 78 double rotation) { 79 80 cr.save (); 81 cr.translate (x, y); 82 cr.rotate (rotation); 83 cr.scale (rx, ry); 84 85 if (angle_extent > 0) { 86 cr.arc_negative (0, 0, 1, -angle_start, -angle_start - angle_extent); 87 } else { 88 cr.arc (0, 0, 1, -angle_start, -angle_start - angle_extent); 89 } 90 91 cr.restore (); 92 } 93 94 public override void move (double dx, double dy) { 95 } 96 97 public override bool is_empty () { 98 return false; 99 } 100 101 public override Object copy () { 102 return new SvgPath.create_copy (this); 103 } 104 105 public override string to_string () { 106 return "SvgPath"; 107 } 108 } 109 110 } 111