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