Commit 9eeda09
edit filled glyphs
Changed files (5)
modifiedsrc/Glyph.valamodifiedsrc/Line.valamodifiedsrc/Path.valamodifiedsrc/PenTool.valamodifiedsrc/Svg.vala
Diff
@@ -89,8 +89,6 @@ class Glyph : FontDisplay { bool unassigned = false; public unichar unichar_code = 0; - bool editable = true;- List<Glyph> undo_list = new List<Glyph> (); public List<Kerning> kerning = new List<Kerning> ();@@ -1029,10 +1027,6 @@ class Glyph : FontDisplay { return active_paths.length () > 0; } - public bool is_editable () {- return editable;- }- /** Close all editable paths and return false if no path have boon closed. * Paths without area (points and lines) will be deleted. */@@ -1046,8 +1040,6 @@ class Glyph : FontDisplay { } } - editable = false;- clear_active_paths (); new_point_on_path = null; flipping_point_on_path = null;@@ -1060,9 +1052,7 @@ class Glyph : FontDisplay { return r; } - public void open_path () {- editable = true;- + public void open_path () { foreach (var p in path_list) { p.set_editable (true); }@@ -1328,18 +1318,34 @@ class Glyph : FontDisplay { public void draw_path (Context cr) { double left, baseline;+ bool is_open = false; // plot_outline (cr); baseline = get_line ("baseline").pos; left = get_line ("left").pos; - if (!editable) {+ foreach (unowned Path p in path_list) {+ if (p.is_open ()) {+ is_open = true;+ break;+ }+ }+ + if (!is_open) { Svg.draw_svg_path (cr, get_svg_data (), Glyph.xc () + left, Glyph.yc () + baseline, SCALE); } foreach (unowned Path p in path_list) {+ if (is_open) {+ p.draw_outline (cr, allocation, view_zoom);+ }+ p.draw_edit_points (cr, allocation, view_zoom);+ + if (p.is_selected ()) {+ p.fill_path (cr, allocation, view_zoom);+ } } if (new_point_on_path != null) {@@ -87,7 +87,7 @@ class Line : GLib.Object { this.a = a; } - // Valabug: should be public “void set_list_item (unowned List<Line> ll) {”+ // Valabug, it should be: public “void set_list_item (unowned List<Line> ll) {” // Keeping list_item public for now public void set_list_item (void* ll) { // list_item = ll;@@ -89,44 +89,43 @@ class Path { public bool is_selected () { return selected; }- - public void draw_edit_points (Context cr, Allocation allocation, double view_zoom) {++ public void draw_outline (Context cr, Allocation allocation, double view_zoom) { unowned List<EditPoint> ep = points; unowned EditPoint? n = null; unowned EditPoint en; unowned EditPoint em; + if (ep.length () < 2) {+ return;+ }+ cr.new_path (); // draw lines- if (is_editable ()) {- foreach (EditPoint e in ep) {- if (n != null) {- en = (!) n;- draw_next (e, en, cr);- }- - n = e;+ foreach (EditPoint e in ep) {+ if (n != null) {+ en = (!) n;+ draw_next (e, en, cr); }+ + n = e; }- + // close path- if (!is_open () && ep.length () >= 2 && n != null) {+ if (!is_open () && n != null) { en = (!) n; em = ep.first ().data; draw_next (em, en, cr); } - // fill path- if (is_selected ()) { - cr.close_path ();- cr.set_source_rgba (r, g, b, a);- cr.fill ();- }- cr.stroke ();+ }+ + public void draw_edit_points (Context cr, Allocation allocation, double view_zoom) {+ unowned List<EditPoint> ep = points; if (is_editable ()) { // control points for curvature@@ -141,7 +140,40 @@ class Path { } } }- ++ public void fill_path (Context cr, Allocation allocation, double view_zoom) {+ unowned List<EditPoint> ep = points;+ + unowned EditPoint? n = null;+ unowned EditPoint en;+ unowned EditPoint em;+ + cr.new_path ();+ + // draw lines+ foreach (EditPoint e in ep) {+ if (n != null) {+ en = (!) n;+ draw_next (e, en, cr);+ }+ + n = e;+ }+ + // close path+ if (!is_open () && ep.length () >= 2 && n != null) {+ en = (!) n;+ em = ep.first ().data;+ + draw_next (em, en, cr);+ }++ // fill path+ cr.close_path ();+ cr.set_source_rgba (r, g, b, a);+ cr.fill ();+ }+ private void draw_next (EditPoint e, EditPoint en, Context cr) { draw_curve (e, en, cr); }@@ -706,6 +738,11 @@ class Path { return true; } + if (ycoordinates.length () == 0) {+ warning ("No ycoordinates is empty");+ return true;+ }+ ycoordinates.sort ((a, b) => { return (a.y < b.y) ? 1 : -1; });@@ -221,10 +221,7 @@ class PenTool : Tool { } // make path transparent and show edit points- if (!glyph.is_editable ()) {- glyph.open_path ();- return;- }+ glyph.open_path (); if (insert_new_point_on_path_selected ()) { glyph.insert_new_point_on_path (x, y);@@ -220,6 +220,10 @@ class Svg { x /= scale; y /= scale;++ if (d.length == 0) {+ return;+ } cr.save (); @@ -326,9 +330,12 @@ class Svg { } internal static string round (double p) {- string v = @"$p";+ string v = p.to_string ();+ char[] c = new char [501];+ + v = p.format (c, "%3.15f"); - if (v.index_of ("e") != -1) {+ if (v.index_of ("e") != -1) { return "0.0"; }