Commit 209fe0f
list all kerning pairs
Changed files (10)
modifiedbirdfont/GtkWindow.valamodifiedlibbirdfont/BirdFont.valamodifiedlibbirdfont/BirdFontFile.valamodifiedlibbirdfont/KerningClasses.valamodifiedlibbirdfont/KerningDisplay.valaaddedlibbirdfont/KerningList.valamodifiedlibbirdfont/KerningTools.valamodifiedlibbirdfont/MenuTab.valamodifiedlibbirdfont/OverView.valamodifiedlibbirdfont/TestCases.vala
Diff
@@ -713,6 +713,12 @@ public class GtkWindow : Gtk.Window, NativeWindow { }); show_kerning_tab.add_accelerator ("activate", accel_group, 'k', Gdk.ModifierType.CONTROL_MASK, Gtk.AccelFlags.VISIBLE); + Gtk.MenuItem list_all_kerning_pairs = new Gtk.MenuItem.with_mnemonic (_("_List Kerning Pairs"));+ kerning_menu.append (list_all_kerning_pairs);+ list_all_kerning_pairs.activate.connect (() => { + MenuTab.list_all_kerning_pairs ();+ });+ Gtk.MenuItem remove_all_kerning_pairs = new Gtk.MenuItem.with_mnemonic (_("_Remove All Kerning Pairs")); kerning_menu.append (remove_all_kerning_pairs); remove_all_kerning_pairs.activate.connect (() => { @@ -300,8 +300,9 @@ public class BirdFont { assert (!fatal); } - internal static void new_font () {+ internal static Font new_font () { current_font = new Font ();+ return current_font; } public static File get_preview_directory () {@@ -65,8 +65,6 @@ class BirdFontFile { Xml.Doc* doc; Xml.Node* root; - print (xml_data);- Parser.init (); font.font_file = "typeface.bf"; // FIXME@@ -94,7 +92,7 @@ class BirdFontFile { uint num_kerning_pairs; if (file.query_file_type (0) == FileType.DIRECTORY) {- stderr.printf (@"Can not save font. $path is a directory.");+ warning (@"Can not save font. $path is a directory."); return false; } @@ -197,8 +195,8 @@ class BirdFontFile { } } } catch (GLib.Error ef) {- stderr.printf (@"Failed to save $path \n");- stderr.printf (@"$(ef.message) \n");+ warning (@"Failed to save $path \n");+ warning (@"$(ef.message) \n"); } }); @@ -233,15 +231,15 @@ class BirdFontFile { os.put_string (float_point (k)); os.put_string ("\" />\n"); } catch (GLib.Error e) {- stderr.printf (@"$(e.message) \n");+ warning (@"$(e.message) \n"); } }); os.put_string ("</font>"); } catch (GLib.Error e) {- stderr.printf (@"Failed to save $path \n");- stderr.printf (@"$(e.message) \n");+ warning (@"Failed to save $path \n");+ warning (@"$(e.message) \n"); return false; } @@ -559,7 +557,6 @@ class BirdFontFile { if (attr_name == "hadjustment") { hadjustment = double.parse (attr_content);- print (@"$hadjustment"); } } @@ -238,6 +238,14 @@ public class KerningClasses : GLib.Object { print (@"$((!) single_kerning.get (key))\n"); } }++ public void get_classes (KerningIterator kerningIterator) {+ for (int i = 0; i < classes_first.length (); i++) {+ kerningIterator (classes_first.nth (i).data.get_all_ranges (),+ classes_last.nth (i).data.get_all_ranges (),+ classes_kerning.nth (i).data.val);+ }+ } public void get_single_position_pairs (KerningIterator kerningIterator) { double k = 0;@@ -310,6 +318,10 @@ public class KerningClasses : GLib.Object { single_kerning.clear (); }+ + public uint get_number_of_pairs () {+ return single_kerning.keys.size + classes_first.length ();+ } } }@@ -32,6 +32,8 @@ public class KerningDisplay : FontDisplay { double last_handle_x = 0; bool parse_error = false;+ + KerningList kerning_list = new KerningList (); public KerningDisplay () { GlyphSequence w = new GlyphSequence ();@@ -64,6 +66,10 @@ public class KerningDisplay : FontDisplay { } } + private void draw_list (WidgetAllocation allocation, Context cr) {+ kerning_list.draw (allocation, cr);+ }+ public void draw_error_message (WidgetAllocation allocation, Context cr) { string line1 = _("The current kerning class is malformed."); string line2 = _("Add single characters separated by space and ranges on the form A-Z.");@@ -614,7 +620,6 @@ public class KerningDisplay : FontDisplay { last_handle_x = ex; moving = true; }- } }new file mode 100644@@ -0,0 +1,148 @@+/*+ Copyright (C) 2013 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 + published by the Free Software Foundation; either version 3 of the + License, or (at your option) any later version.++ This library is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details.+*/++using Cairo;+using Math;++namespace BirdFont {++public class KerningList : FontDisplay {+ + int scroll = 0;+ int visible_rows = 0;+ WidgetAllocation allocation = new WidgetAllocation ();+ + public KerningList () {+ }++ public override void draw (WidgetAllocation allocation, Context cr) {+ KerningClasses classes = KerningClasses.get_instance ();+ int y = 20;+ int s = 0;+ bool color = (scroll % 2) == 0;+ + this.allocation = allocation;+ + visible_rows = (int) (allocation.height / 18.0);+ + cr.save ();+ cr.set_source_rgba (1, 1, 1, 1);+ cr.rectangle (0, 0, allocation.width, allocation.height);+ cr.fill ();+ cr.restore ();+ + cr.save ();+ cr.set_source_rgba (0.3, 0.3, 0.3, 1);+ cr.set_font_size (12);++ classes.get_classes ((left, right, kerning) => {+ if (s++ >= scroll) {+ draw_row (allocation, cr, left, right, @"$kerning", y, color);+ y += 18;+ color = !color;+ }+ });+ + classes.get_single_position_pairs ((left, right, kerning) => {+ if (s++ >= scroll) {+ draw_row (allocation, cr, left, right, @"$kerning", y, color);+ y += 18;+ color = !color;+ }+ });+ + cr.restore ();+ } ++ private static void draw_row (WidgetAllocation allocation, Context cr,+ string left, string right, string kerning, int y, bool color) {++ if (color) {+ cr.save ();+ cr.set_source_rgba (224/255.0, 224/255.0, 224/255.0, 1);+ cr.rectangle (0, y - 14, allocation.width, 18);+ cr.fill ();+ cr.restore ();+ }+ + cr.move_to (30, y);+ cr.show_text (left);+ cr.move_to (230, y);+ cr.show_text (right);+ cr.move_to (430, y);+ cr.show_text (kerning);+ }++ public override string get_name () {+ _("Kerning Pairs"); // translate later+ return "Kerning Pairs";+ }++ public override bool has_scrollbar () {+ return true;+ }+ + public override void scroll_wheel_down (double x, double y) {+ uint pairs = KerningClasses.get_instance ().get_number_of_pairs ();+ scroll += 3;++ if (scroll > pairs - visible_rows) {+ scroll = (int) (pairs - visible_rows);+ }+ + update_scrollbar ();+ redraw_area (0, 0, allocation.width, allocation.height);+ }+ + public override void scroll_wheel_up (double x, double y) {+ scroll -= 3;+ + if (scroll < 0) {+ scroll = 0;+ }+ + update_scrollbar ();+ redraw_area (0, 0, allocation.width, allocation.height);+ }++ public override void selected_canvas () {+ update_scrollbar ();+ redraw_area (0, 0, allocation.width, allocation.height);+ }+ + public void update_scrollbar () {+ uint rows = KerningClasses.get_instance ().get_number_of_pairs ();++ if (rows == 0 || visible_rows == 0) {+ MainWindow.set_scrollbar_size (0);+ MainWindow.set_scrollbar_position (0);+ } else {+ MainWindow.set_scrollbar_size ((double) visible_rows / rows);+ MainWindow.set_scrollbar_position ((double) scroll / rows);+ }+ }++ public override void scroll_to (double percent) {+ uint pairs = KerningClasses.get_instance ().get_number_of_pairs ();+ scroll = (int) (percent * pairs);+ + if (scroll > pairs - visible_rows) {+ scroll = (int) (pairs - visible_rows);+ }+ + redraw_area (0, 0, allocation.width, allocation.height);+ }+}++}@@ -36,7 +36,7 @@ public class KerningTools : ToolCollection { Toolbox.redraw_tool_box (); }); class_tools.add_tool (new_kerning_class);- + class_tools.set_persistent (false); class_tools.set_unique (false); class_tools.set_open (true);@@ -14,7 +14,7 @@ namespace BirdFont { -public class MenuTab : FontDisplay { +public class MenuTab : FontDisplay { List<Font> recent_fonts = new List<Font> (); @@ -266,7 +266,7 @@ c.append (""" Font f; bool loaded; - f = BirdFont.get_current_font ();+ f = BirdFont.new_font (); f.delete_backup (); MainWindow.clear_glyph_cache ();@@ -448,6 +448,8 @@ c.append (""" if (fn != null) { f.delete_backup (); + f = BirdFont.new_font ();+ MainWindow.clear_glyph_cache (); MainWindow.close_all_tabs (); f.load ((!)fn);@@ -533,5 +535,9 @@ c.append (""" KerningClasses.get_instance ().remove_all_pairs (); KerningTools.update_kerning_classes (); }+ + public static void list_all_kerning_pairs () {+ MainWindow.get_tab_bar ().add_unique_tab (new KerningList (), 130);+ } } }@@ -42,6 +42,8 @@ public class OverView : FontDisplay { /** Show unicode database info. */ CharacterInfo? character_info = null; + double scroll_size = 1;+ public OverView (GlyphRange? range = null) { GlyphRange gr; @@ -147,17 +149,20 @@ public class OverView : FontDisplay { public override void scroll_wheel_up (double x, double y) { key_up ();+ update_scrollbar (); redraw_area (0, 0, allocation.width, allocation.height); } public override void scroll_wheel_down (double x, double y) { key_down ();+ update_scrollbar (); redraw_area (0, 0, allocation.width, allocation.height); } public override void selected_canvas () { redraw_area (0, 0, allocation.width, allocation.height); KeyBindings.singleton.set_require_modifier (true);+ update_scrollbar (); } public override void zoom_min () {@@ -402,10 +407,12 @@ public class OverView : FontDisplay { first_visible = (int) r; } - public override void scroll_to (double percent) requires (items_per_row > 0) {+ public override void scroll_to (double position) requires (items_per_row > 0) { int64 r; double nrows; Font f;++ position = position / (1 - scroll_size); if (all_available) { f = BirdFont.get_current_font ();@@ -414,8 +421,9 @@ public class OverView : FontDisplay { nrows = Math.ceil (glyph_range.length () / items_per_row); } - r = (int64) (Math.ceil (percent * nrows) * items_per_row);+ r = (int64) (Math.ceil (position * nrows) * items_per_row); scroll_to_position (r);+ redraw_area (0, 0, allocation.width, allocation.height); } @@ -446,7 +454,7 @@ public class OverView : FontDisplay { first_visible = 0; } - /** Returns true if the selected glyph is at last row. */+ /** Returns true if the selected glyph is at the last row. */ private bool last_row () { return visible_items.length () - selected <= items_per_row; }@@ -773,16 +781,17 @@ public class OverView : FontDisplay { } else { if (all_available) { f = BirdFont.get_current_font ();- nrows = Math.ceil (f.length () / rows);+ nrows = Math.floor ((f.length ()) / rows); } else {- nrows = Math.ceil (glyph_range.length () / rows);+ nrows = Math.floor ((glyph_range.length ()) / rows); } if (nrows <= 0) { nrows = 1; } - MainWindow.set_scrollbar_size (rows / nrows);+ scroll_size = rows / nrows;+ MainWindow.set_scrollbar_size (scroll_size); MainWindow.set_scrollbar_position ((first_visible / rows) / nrows); } }@@ -1453,7 +1453,6 @@ class TestCases { private static void test_kerning () { MenuTab.show_kerning_context ();- Font font = BirdFont.get_current_font (); KerningDisplay kerning_display = KerningDisplay.get_singleton (); unichar a, b; StringBuilder sb1, sb2;