Commit b5b2aa0
Merge ../birdfont-2.x
Changed files (18)
modifiedlibbirdfont/BackgroundTools.valamodifiedlibbirdfont/BirdFontFile.valamodifiedlibbirdfont/ClipTool.valamodifiedlibbirdfont/ExportSettings.valamodifiedlibbirdfont/Font.valamodifiedlibbirdfont/Glyph.valamodifiedlibbirdfont/GlyphMaster.valamodifiedlibbirdfont/LoadCallback.valamodifiedlibbirdfont/MainWindow.valamodifiedlibbirdfont/OpenFontFormat/GlyfData.valamodifiedlibbirdfont/OverView.valamodifiedlibbirdfont/Path.valamodifiedlibbirdfont/PointConverter.valamodifiedlibbirdfont/RecentFiles.valamodifiedlibbirdfont/TabBar.valamodifiedlibbirdfont/TestCases.valamodifiedlibbirdfont/Toolbox.valamodifiedlibbirdfont/VersionList.vala
Diff
@@ -182,13 +182,13 @@ public class BackgroundTools : ToolCollection { }); label.has_delete_button = true; parts.add_tool (label, 0);-- parts.redraw ();- parts.clear_cache ();+ parts.redraw (); if (!is_null (MainWindow.get_toolbox ())) {- MainWindow.get_toolbox ().update_expanders ();- Toolbox.redraw_tool_box ();+ MainWindow.get_toolbox ().update_expanders ();+ parts.clear_cache ();+ Toolbox.redraw_tool_box ();+ GlyphCanvas.redraw (); } } @@ -26,7 +26,7 @@ class BirdFontFile : GLib.Object { Font font; public static const int FORMAT_MAJOR = 2;- public static const int FORMAT_MINOR = 2;+ public static const int FORMAT_MINOR = 1; public static const int MIN_FORMAT_MAJOR = 0; public static const int MIN_FORMAT_MINOR = 0;@@ -343,8 +343,7 @@ class BirdFontFile : GLib.Object { os.put_string ("\n"); } - os.put_string (@"<background scale=\"$(font.background_scale)\" />\n");- os.put_string (@"<conversion tolerance=\"$(font.tolerance)\" />\n"); + os.put_string (@"<background scale=\"$(font.background_scale)\" />\n"); } public void write_description (DataOutputStream os) throws GLib.Error {@@ -819,10 +818,6 @@ class BirdFontFile : GLib.Object { parse_background (t); } - if (t.get_name () == "conversion") {- parse_cubic_conversion (t);- }- if (t.get_name () == "postscript_name") { font.postscript_name = XmlParser.decode (t.get_content ()); }@@ -1193,18 +1188,6 @@ class BirdFontFile : GLib.Object { } } - private void parse_cubic_conversion (Tag tag) {- string tolerance = "1";- - foreach (Attribute attr in tag.get_attributes ()) {- if (attr.get_name () == "tolerance") {- tolerance = attr.get_content ();- }- }- - font.tolerance = parse_double (tolerance);- }- private void parse_background_image (Tag tag) { string file = ""; string data = "";@@ -136,7 +136,8 @@ public class ClipTool : Tool { string data; return_if_fail (fd is GlyphTab); - destination = (Glyph) fd;+ GlyphTab glyph_tab = (GlyphTab) fd; + destination = glyph_tab.glyphs.get_current (); ((!)destination).store_undo_state (); ((!)destination).clear_active_paths (); @@ -24,7 +24,6 @@ public class ExportSettings : TableLayout { CheckBox ttf; CheckBox eot; CheckBox svg;- TextArea tolerance; Button export_action; Button name_tab; @@ -131,31 +130,6 @@ public class ExportSettings : TableLayout { svg.margin_bottom = 20 * MainWindow.units; - widgets.add (new Text (t_("Conversion Tolerance"), label_size, label_margin));- - tolerance = new LineTextArea (label_size);- tolerance.margin_bottom = 20 * MainWindow.units;- - tolerance.set_text (@"$(font.tolerance * 100.0)%");- tolerance.text_changed.connect ((t) => {- Font f = BirdFont.get_current_font ();- string tolerance_percent = t.replace ("%", "");- tolerance_percent = t.replace (",", ".");- tolerance_percent = t.replace (" ", "");- double error_tolerance = double.parse (tolerance_percent);- - if (error_tolerance >= 100.0) {- f.tolerance = 1;- } else if (error_tolerance <= 0) {- f.tolerance = 0;- } else {- f.tolerance = error_tolerance / 100.0;- }- });- - widgets.add (tolerance);- focus_ring.add (tolerance);- name_tab = new Button (t_("Name and Description"), margin); name_tab.action.connect ((c) => { MenuTab.show_description ();@@ -125,7 +125,6 @@ public class Font : GLib.Object { public int format_minor = 0; public int units_per_em = 1024;- public double tolerance = 1.0; public Font () { KerningClasses kerning_classes;@@ -231,7 +231,7 @@ public class Glyph : FontDisplay { return (!) ttf_data; } - public PathList get_quadratic_paths (double tolerance) {+ public PathList get_quadratic_paths () { PointConverter pc; PathList pl; PathList stroke;@@ -242,11 +242,11 @@ public class Glyph : FontDisplay { if (p.stroke > 0) { stroke = p.get_completed_stroke (); foreach (Path stroke_part in stroke.paths) {- pc = new PointConverter (stroke_part, tolerance);+ pc = new PointConverter (stroke_part); pl.add (pc.get_quadratic_path ()); } } else {- pc = new PointConverter (p, tolerance);+ pc = new PointConverter (p); pl.add (pc.get_quadratic_path ()); } }@@ -115,7 +115,6 @@ public class GlyphMaster : GLib.Object { foreach (Glyph g in glyphs) { n.glyphs.add (g);- n.glyphs.add (g); } n.selected = selected;@@ -86,8 +86,6 @@ public class LoadCallback : GLib.Object { f = BirdFont.new_font (); - MainWindow.clear_glyph_cache ();- f.set_file ((!) fn); Preferences.add_recent_files ((!) fn); MainWindow.native_window.load ();@@ -222,16 +222,6 @@ public class MainWindow : GLib.Object { public static bool select_tab (Tab t) { return tabs.selected_open_tab (t); } - - public static OverView get_overview () { - foreach (Tab t in tabs.tabs) { - if (t.get_display () is OverView) { - return (OverView) t.get_display (); - } - } - - return overview; - } public static SpacingClassTab get_spacing_class_tab () { return spacing_class_tab; @@ -281,21 +271,6 @@ public class MainWindow : GLib.Object { MainWindow.native_window.set_scrollbar_position (position); } } - - /** Reaload all paths and help lines from disk. */ - public static void clear_glyph_cache () { - Glyph g;- GlyphTab tab; - foreach (Tab t in get_tab_bar ().tabs) { - if (t.get_display () is GlyphTab) {- tab = (GlyphTab) t.get_display (); - g = tab.glyphs.get_current (); - g.add_help_lines (); - } - } - - GlyphCanvas.redraw (); - } public static void close_all_tabs () { get_tab_bar ().close_all_tabs (); @@ -349,6 +324,10 @@ public class MainWindow : GLib.Object { public static void set_toolbox (Toolbox tb) { tools = tb; } ++ public static OverView get_overview () { + return overview; + } } } @@ -58,12 +58,11 @@ public class GlyfData : GLib.Object { public GlyfData (Glyph g) { bool process;- Font font = OpenFontFormatWriter.get_current_font ();- PathList quadratic_path = g.get_quadratic_paths (font.tolerance); + PathList qp = g.get_quadratic_paths (); glyph = g; - foreach (Path p in quadratic_path.paths) {+ foreach (Path p in qp.paths) { if (p.points.size > 0) { if (!is_empty (p)) { // Add points at extrema@@ -77,7 +76,7 @@ public class GlyfData : GLib.Object { while (process) { points.clear (); paths.clear ();- foreach (Path p in quadratic_path.paths) {+ foreach (Path p in qp.paths) { if (!is_empty (p)) { paths.add (p); foreach (EditPoint ep in p.points) {@@ -1,5 +1,5 @@ /*- Copyright (C) 2012 2014 2015 Johan Mattsson+ Copyright (C) 2012 - 2016 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 @@ -96,7 +96,7 @@ public class OverView : FontDisplay { bool selected = tabs.select_char (n); GlyphCanvas canvas; Glyph g = glyph_collection.get_current (); - GlyphTab glyph_tab; + GlyphTab glyph_tab; if (!selected) { glyph_tab = new GlyphTab (glyph_collection);@@ -1045,8 +1045,10 @@ public class OverView : FontDisplay { } store_undo_items (undo_item); - foreach (GlyphCollection gc in selected_items) {- font.delete_glyph (gc);+ foreach (GlyphCollection glyph_collection in selected_items) {+ font.delete_glyph (glyph_collection);+ string name = glyph_collection.get_name ();+ MainWindow.get_tab_bar ().close_background_tab_by_name (name); } update_item_list ();@@ -1096,7 +1098,6 @@ public class OverView : FontDisplay { font.delete_glyph (g); font.add_glyph_collection (g); }- font.alternates = previous_collection.alternate_sets.copy (); redo_items.remove_at (redo_items.size - 1);@@ -1193,12 +1194,12 @@ public class OverView : FontDisplay { if (all_available) { // don't search for glyphs in huge CJK fonts - if (font.length () > 300) {+ if (font.length () > 500) { r = 0; } else { // FIXME: too slow for (r = 0; r < font.length (); r += items_per_row) {- for (i = 0; i < items_per_row; i++) {+ for (i = 0; i < items_per_row && i < font.length (); i++) { glyphs = font.get_glyph_collection_index ((uint32) r + i); return_if_fail (glyphs != null); glyph = ((!) glyphs).get_current ();@@ -1235,6 +1236,7 @@ public class OverView : FontDisplay { if (index > -1) { first_visible = r;+ process_item_list_update (); update_item_list (); select_visible_glyph (ch); }@@ -309,13 +309,16 @@ public class Path : GLib.Object { y = Glyph.yc () - top.y - sin (angle + PI / 2) * 10 * Glyph.ivz (); if (points.size > 0) {- cr.save ();- cr.translate (x, y); double inverted_zoom = Glyph.ivz ();- cr.rotate (-angle);- cr.translate (-x, -y);+ double zoom = 1 / inverted_zoom; cr.scale (inverted_zoom, inverted_zoom);- arrow_icon.draw_at_baseline (cr, x, y);+ + cr.save ();+ cr.translate (x * zoom, y * zoom);+ cr.rotate (-angle);+ cr.translate (-x * zoom, -y * zoom); + + arrow_icon.draw_at_baseline (cr, x * zoom, y * zoom); cr.restore (); } }@@ -1204,9 +1207,9 @@ public class Path : GLib.Object { /** Convert quadratic bezier points to cubic representation of the glyph * for ttf-export. */ - public Path get_quadratic_points (double tolerance) {+ public Path get_quadratic_points () { PointConverter converter;- converter = new PointConverter (this, tolerance);+ converter = new PointConverter (this); return converter.get_quadratic_path (); } @@ -22,11 +22,9 @@ public class PointConverter { Path original_path; Path quadratic_path;- double error_tolerance = 1; - public PointConverter (Path path, double tolerance) { + public PointConverter (Path path) { original_path = path;- error_tolerance = tolerance; } public Path get_quadratic_path () {@@ -111,7 +109,7 @@ public class PointConverter { out distance, out e, out step); } - if (distance > 0.1 + 0.1 * error_tolerance) { // range 0.1 - 0.4,+ if (distance > 0.2) { // range 0.1 - 0.4, quadratic_path.insert_new_point_on_path (e); points_in_segment++; size += 2; // the new point + segment start@@ -240,7 +240,6 @@ public class RecentFiles : Table { f = BirdFont.new_font (); - MainWindow.clear_glyph_cache (); MainWindow.close_all_tabs (); f.set_file (fn);@@ -21,7 +21,7 @@ public class TabBar : GLib.Object { public int width = 0; public int height = 0; - public Gee.ArrayList<Tab> tabs;+ private Gee.ArrayList<Tab> tabs; static const int NO_TAB = -1; static const int NEXT_TAB = -2;@@ -328,9 +328,11 @@ public class TabBar : GLib.Object { public bool close_by_name (string name, bool background_tab = false) { int i = 0; - foreach (var t in tabs) {- if (t.get_display ().get_name () == name) {- return close_tab (i, background_tab);+ foreach (Tab tab in tabs) {+ if (tab.get_display ().get_name () == name) {+ bool closed = close_tab (i, background_tab);+ redraw_tab_bar (0, 0, width, height);+ return closed; } i++;@@ -466,8 +468,7 @@ public class TabBar : GLib.Object { t = tabs.get (index); previous_tab = current_tab; current_tab = t;-- scroll_to_tab (selected, signal_selected);+ scroll_to_tab (selected, signal_selected); } private bool has_scroll () {@@ -579,8 +580,8 @@ public class TabBar : GLib.Object { public void add_tab (FontDisplay display_item, bool signal_selected = true, GlyphCollection? gc = null) { double tab_width = -1; bool always_open = false;- int s = (tabs.size == 0) ? 0 : selected + 1;- Tab t;+ int position = (tabs.size == 0) ? 0 : selected + 1;+ Tab tab; if (MenuTab.has_suppress_event ()) { warn_if_test ("Event suppressed");@@ -592,21 +593,21 @@ public class TabBar : GLib.Object { tab_width += 36; } - t = new Tab (display_item, tab_width, always_open);- tabs.insert (s,t);+ tab = new Tab (display_item, tab_width, always_open); + tabs.insert (position, tab); if (gc != null) {- t.set_glyph_collection ((!) gc);+ tab.set_glyph_collection ((!) gc); } - GlyphCanvas.set_display (t.get_display ());+ GlyphCanvas.set_display (tab.get_display ()); MainWindow.get_glyph_canvas ()- .set_current_glyph_collection (t.get_glyph_collection ());+ .set_current_glyph_collection (tab.get_glyph_collection ()); - select_tab (s, signal_selected);+ select_tab (position, signal_selected); }- + /** Returns true if the new item was added to the bar. */ public bool add_unique_tab (FontDisplay display_item, bool signal_selected = true) { bool i;@@ -592,7 +592,7 @@ class TestCases { g = MainWindow.get_current_glyph (); foreach (Path path in g.get_all_paths ()) {- paths.append (path.get_quadratic_points (1.0));+ paths.append (path.get_quadratic_points ()); paths.append (path.copy ()); } @@ -610,7 +610,7 @@ class TestCases { p.add (-10, -10); p.close (); g.add_path (p);- g.add_path (p1.get_quadratic_points (1.0));+ g.add_path (p1.get_quadratic_points ()); e0 = new EditPoint (20, 40); e1 = new EditPoint (40, 40);@@ -634,7 +634,7 @@ class TestCases { e3.process_tied_handle (); g.add_path (p1);- g.add_path (p1.get_quadratic_points (1.0));+ g.add_path (p1.get_quadratic_points ()); foreach (Path path in paths) { g.add_path (path);@@ -127,6 +127,9 @@ public class Toolbox : GLib.Object { current_set = (ToolCollection) theme_tools; } else if (t != null && ((!) t).get_display () is GlyphTab) { current_set = (ToolCollection) drawing_tools;+ } else if (t != null && ((!) t).get_display () is Glyph) {+ warning ("Expecting GlyphTab instead of Glyph.");+ current_set = (ToolCollection) drawing_tools; } else { current_set = (ToolCollection) file_tools; }@@ -94,6 +94,8 @@ public class VersionList : GLib.Object { if (glyphs.size == 1) { over_view.store_undo_state (glyph_collection.copy ()); font.delete_glyph (glyph_collection);+ string name = glyph_collection.get_name ();+ MainWindow.get_tab_bar ().close_background_tab_by_name (name); return; } @@ -238,7 +240,8 @@ public class VersionList : GLib.Object { continue; } - glyph = (Glyph) tab.get_display ();+ GlyphTab glyph_tab = (GlyphTab) tab.get_display ();+ glyph = glyph_tab.glyphs.get_current (); uni.truncate (0); uni.append_unichar (glyph.unichar_code); ug = font.get_glyph (uni.str);@@ -248,7 +251,7 @@ public class VersionList : GLib.Object { } updated_glyph = (!) ug;- tab.set_display (updated_glyph);+ tab.set_display (glyph_tab); updated_glyph.view_zoom = glyph.view_zoom; updated_glyph.view_offset_x = glyph.view_offset_x; updated_glyph.view_offset_y = glyph.view_offset_y;