The Birdfont Source Code


All Repositories / birdfont.git / commitdiff – RSS feed

Customise settings directory

These changes was commited to the Birdfont repository Sun, 07 Sep 2014 13:36:56 +0000.

Contributing

Send patches or pull requests to johan.mattsson.m@gmail.com.
Clone this repository: git clone https://github.com/johanmattssonm/birdfont.git
[Sun, 07 Sep 2014 13:36:56 +0000]

Updated Files

libbirdfont/BirdFont.vala
libbirdfont/DrawingTools.vala
libbirdfont/EditPoint.vala
libbirdfont/EditPointHandle.vala
libbirdfont/Path.vala
libbirdfont/PenTool.vala
libbirdfont/StrokeTool.vala
--- a/libbirdfont/BirdFont.vala +++ b/libbirdfont/BirdFont.vala @@ -1,5 +1,5 @@ /* - Copyright (C) 2012 Johan Mattsson + Copyright (C) 2012 2014 Johan Mattsson This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as @@ -15,6 +15,8 @@ public const string GETTEXT_PACKAGE = "birdfont"; namespace BirdFont { + + public static string? settings_directory = null; static void print_import_help (string[] arg) { stdout.printf (t_("Usage:")); @@ -517,6 +519,10 @@ return current_font; } + public void set_settings_directory (string directory) { + settings_directory = directory; + } + public static File get_preview_directory () { File settings = get_settings_directory (); File backup = settings.get_child ("preview"); @@ -537,7 +543,7 @@ return thumbnails; } - + internal static File get_settings_directory () { string home_path; File home; @@ -551,9 +557,10 @@ printd ("Create settings directory."); DirUtils.create ((!) home.get_path (), 0xFFFFFF); } - #else - home_path = Environment.get_home_dir (); - + #else + home_path = (settings_directory != null) + ? (!) settings_directory : Environment.get_home_dir (); + if (is_null (home_path)) { warning ("No home directory set."); home_path = ".";
--- a/libbirdfont/DrawingTools.vala +++ b/libbirdfont/DrawingTools.vala @@ -517,7 +517,7 @@ PointSelection ep; if (PenTool.selected_points.size > 0) { ep = PenTool.selected_points.get (0); - symmetrical = ep.point.reflective_handles; + symmetrical = ep.point.reflective_point; foreach (PointSelection p in PenTool.selected_points) { p.point.set_reflective_handles (!symmetrical); p.point.process_symmetrical_handles ();
--- a/libbirdfont/EditPoint.vala +++ b/libbirdfont/EditPoint.vala @@ -38,17 +38,90 @@ public unowned EditPoint? prev = null; public unowned EditPoint? next = null; - public bool active = false; - public bool selected = false; - public bool deleted = false; + public static uint NONE = 0; + public static uint ACTIVE = 1; + public static uint SELECTED = 1 << 1; + public static uint DELETED = 1 << 2; + public static uint TIE = 1 << 3; + public static uint REFLECTIVE = 1 << 4; + public static uint CORNER = 1 << 5; + public uint flags = NONE; + + public bool active_point { + get { + return (flags & ACTIVE) > 0; + } + + set { + if (value) { + flags |= ACTIVE; + } else { + flags &= uint.MAX ^ ACTIVE; + } + } + } + + public bool selected_point { + get { + return (flags & SELECTED) > 0; + } + + set { + if (value) { + flags |= SELECTED; + } else { + flags &= uint.MAX ^ SELECTED; + } + } + } + + public bool deleted { + get { + return (flags & DELETED) > 0; + } + + set { + if (value) { + flags |= DELETED; + } else { + flags &= uint.MAX ^ DELETED; + } + } + } + + public bool tie_handles { + get { + return (flags & TIE) > 0; + } + + set { + if (value) { + flags |= TIE; + } else { + flags &= uint.MAX ^ TIE; + } + } + } + + public bool reflective_point { + get { + return (flags & REFLECTIVE) > 0; + } + + set { + if (value) { + flags |= REFLECTIVE; + } else { + flags &= uint.MAX ^ REFLECTIVE; + } + } + } + public int selected_handle = 0; public EditPointHandle right_handle; public EditPointHandle left_handle; - - public bool tie_handles = false; - public bool reflective_handles = false; /** Set new position for control point without moving handles. */ public double independent_x { @@ -81,12 +154,12 @@ x = nx; y = ny; type = nt; - active = false; + active_point = false; set_active (true); if (nt == PointType.FLOATING) { - active = false; + active_point = false; } right_handle = new EditPointHandle (this, 0, 7); @@ -120,7 +193,7 @@ /** Make handles symmetrical. */ public void set_reflective_handles (bool symmetrical) { - reflective_handles = symmetrical; + reflective_point = symmetrical; } /** Flip handles if next point on path is in the other direction. @@ -340,11 +413,8 @@ new_point.y = y; new_point.type = type; - new_point.deleted = deleted; - new_point.selected = selected; - - new_point.tie_handles = tie_handles; - + new_point.flags = flags; + new_point.right_handle.angle = right_handle.angle; new_point.right_handle.length = right_handle.length; new_point.right_handle.type = right_handle.type; @@ -440,18 +510,18 @@ } public bool is_selected () { - return selected; + return selected_point; } public void set_selected (bool s) { - selected = s; + selected_point = s; } public bool set_active (bool active) { - bool update = (this.active != active); + bool update = (this.active_point != active); if (update) { - this.active = active; + this.active_point = active; } return update;
--- a/libbirdfont/EditPointHandle.vala +++ b/libbirdfont/EditPointHandle.vala @@ -192,7 +192,7 @@ tie_handle (); } - if (parent.reflective_handles) { + if (parent.reflective_point) { tie_handle (); process_symmetrical_handle (); }
--- a/libbirdfont/Path.vala +++ b/libbirdfont/Path.vala @@ -238,7 +238,7 @@ if (is_editable ()) { // control points for curvature foreach (EditPoint e in points) { - if (show_all_line_handles || e.selected || e.selected_handle > 0) { + if (show_all_line_handles || e.selected_point || e.selected_handle > 0) { draw_edit_point_handles (e, cr); } } @@ -472,15 +472,15 @@ if (e.type != PointType.HIDDEN) { if (e.type == PointType.CUBIC || e.type == PointType.LINE_CUBIC) { if (e.is_selected ()) { - img = (e.active) ? (!) cubic_active_selected_edit_point_image : (!) cubic_selected_edit_point_image; + img = (e.active_point) ? (!) cubic_active_selected_edit_point_image : (!) cubic_selected_edit_point_image; } else { - img = (e.active) ? (!) cubic_active_edit_point_image : (!) cubic_edit_point_image; + img = (e.active_point) ? (!) cubic_active_edit_point_image : (!) cubic_edit_point_image; } } else { if (e.is_selected ()) { - img = (e.active) ? (!) active_selected_edit_point_image : (!) selected_edit_point_image; + img = (e.active_point) ? (!) active_selected_edit_point_image : (!) selected_edit_point_image; } else { - img = (e.active) ? (!) active_edit_point_image : (!) edit_point_image; + img = (e.active_point) ? (!) active_edit_point_image : (!) edit_point_image; } } draw_image (cr, img, e.x, e.y); @@ -1096,11 +1096,13 @@ return converter.get_quadratic_path (); } - public void insert_new_point_on_path (EditPoint ep, double t = -1) { + public void insert_new_point_on_path (EditPoint ep, double t = -1, bool move_point_to_path = false) { EditPoint start, stop; double x0, x1, y0, y1; double position, min; PointType left, right; + double closest_x = 0; + double closest_y = 0; if (ep.next == null || ep.prev == null) { warning ("missing point"); @@ -1131,10 +1133,17 @@ if (n < min) { min = n; position = t; + closest_x = cx; + closest_y = cy; } return true; }); + + if (move_point_to_path) { + ep.x = closest_x; + ep.y = closest_y; + } } else { position = t; }
--- a/libbirdfont/PenTool.vala +++ b/libbirdfont/PenTool.vala @@ -1521,14 +1521,14 @@ if (left_handle) { if (parent_point.prev != null) { tied_point = parent_point.get_prev (); - if (tied_point.selected) { + if (tied_point.selected_point) { eh = tied_point.get_right_handle (); } } } else { if (parent_point.next != null) { tied_point = parent_point.get_next (); - if (tied_point.selected) { + if (tied_point.selected_point) { eh = tied_point.get_left_handle (); } }
--- a/libbirdfont/StrokeTool.vala +++ b/libbirdfont/StrokeTool.vala @@ -229,7 +229,9 @@ bool bad_segment = false; bool failed = false; int size; - + + //FIXME: DELETE. add_self_intersection_points (new_path); + new_path.remove_points_on_points (); new_path.update_region_boundaries (); @@ -246,9 +248,13 @@ start = new_path.get_first_point (); int it = 0; + foreach (EditPoint e in new_path.points) { + e.flags |= EditPoint.CORNER; + } + // double points are not good for this purpose, convert them to the quadratic form new_path.add_hidden_double_points (); - + // add tangent points to the path segment_start = new_path.get_first_point (); size = new_path.points.size; @@ -269,7 +275,7 @@ segment_stop.prev = split_point; new_path.insert_new_point_on_path (split_point, t); - + return false; }, 2); @@ -415,6 +421,7 @@ } return !new_point; }, 3); + /* // FIXME: add many points // bad segment @@ -507,6 +514,7 @@ } // remove self intersection + EditPoint snext, nnext; double back_ratio = 0; double next_ratio = 0; @@ -515,6 +523,7 @@ nnext = new EditPoint (); print (@"\n"); + /* for (int index = 1; index < stroked.points.size; index++) { np = new_path.points.get (index); sp = stroked.points.get (index); @@ -545,8 +554,9 @@ snext = stroked.points.get (j + 1); } - if (segment_intersects (stroked, sp, snext, out inter_x, out inter_y) - && Path.distance (first_inter_x, inter_x, first_inter_y, inter_y) < 0.1) { + if ((nnext.flags & EditPoint.INTERSECTION) > 0 + || (segment_intersects (stroked, sp, snext, out inter_x, out inter_y) + && Path.distance (first_inter_x, inter_x, first_inter_y, inter_y) < 0.1)) { print (@"done\n"); index = j +1; break; @@ -558,6 +568,20 @@ } else { warning ("Failed to remove self intersection."); } + } + } + */ + + + foreach (EditPoint e in new_path.points) { + if ((e.flags & EditPoint.CORNER) > 0) { + //e.flags |= EditPoint.DELETED; + } + } + + foreach (EditPoint e in stroked.points) { + if ((e.flags & EditPoint.CORNER) > 0) { + //e.flags |= EditPoint.DELETED; } } @@ -643,7 +667,38 @@ return stroked; } - + + /* + static void add_self_intersection_points (Path path) { + Gee.ArrayList<EditPoint> n = new Gee.ArrayList<EditPoint> (); + + path.all_segments ((ep1, ep2) => { + double ix, iy; + EditPoint nep; + + if (segment_intersects (path, ep1, ep2, out ix, out iy)) { + nep = new EditPoint (); + nep.prev = ep1; + nep.next = ep2; + + nep.x = ix; + nep.y = iy; + + n.add (nep); + } + + return true; + }); + + foreach (EditPoint np in n) { + path.insert_new_point_on_path (np, -1, true); + np.type = PointType.QUADRATIC; + np.flags |= EditPoint.INTERSECTION; + } + } + */ + + /* static bool segment_intersects (Path path, EditPoint ep, EditPoint next, out double ix, out double iy) { EditPoint p1, p2; @@ -699,7 +754,8 @@ return false; } + */ } }