Commit 29358ae
use glyphs as backgrounds
Changed files (6)
modifiedbirdfont/GtkWindow.valamodifiedlibbirdfont/Glyph.valamodifiedlibbirdfont/MenuTab.valamodifiedlibbirdfont/OverView.valamodifiedlibbirdfont/OverViewItem.valamodifiedlibbirdfont/Svg.vala
Diff
@@ -550,7 +550,15 @@ public class GtkWindow : Gtk.Window, NativeWindow { edit_menu.append (glyph_sequence_item); glyph_sequence_item.activate.connect (() => { MainWindow.update_glyph_sequence (); }); glyph_sequence_item.add_accelerator ("activate", accel_group, 'Q', Gdk.ModifierType.CONTROL_MASK, Gtk.AccelFlags.VISIBLE);- ++ Gtk.MenuItem background_glyph_item = new Gtk.MenuItem.with_mnemonic (_("Set Glyph _Background"));+ edit_menu.append (background_glyph_item);+ background_glyph_item.activate.connect (() => { MenuTab.use_current_glyph_as_background (); });++ Gtk.MenuItem reset_background_glyph_item = new Gtk.MenuItem.with_mnemonic (_("Remove Glyph _Background"));+ edit_menu.append (reset_background_glyph_item);+ reset_background_glyph_item.activate.connect (() => { MenuTab.reset_glyph_background (); });+ edit_menu.append (new SeparatorMenuItem ()); Gtk.MenuItem select_point_above = new Gtk.MenuItem.with_mnemonic (" Ctrl+↑ " + _("_Select Point Above"));@@ -85,6 +85,8 @@ public class Glyph : FontDisplay { bool ligature = false; string substitution = ""; + public static Glyph? background_glyph = null;+ public Glyph (string name, unichar unichar_code = 0) { this.name = name; this.unichar_code = unichar_code;@@ -1355,7 +1357,10 @@ public class Glyph : FontDisplay { left = get_line ("left").pos; if (!is_open ()) {+ cr.save ();+ cr.set_source_rgba (0, 0, 0, 1); Svg.draw_svg_path (cr, get_svg_data (), Glyph.xc () + left, Glyph.yc () + baseline);+ cr.restore (); } if (is_open ()) {@@ -1421,6 +1426,7 @@ public class Glyph : FontDisplay { ((!)background_image).draw (cr, allocation, view_offset_x, view_offset_y, view_zoom); } + draw_background_glyph (allocation, cr); juxtapose (allocation, cr); if (BirdFont.show_coordinates) {@@ -1599,8 +1605,10 @@ public class Glyph : FontDisplay { cr = new Context (img); + cr.save ();+ cr.set_source_rgba (0, 0, 0, 1); Svg.draw_svg_path (cr, get_svg_data (), gx, gy); - + cr.restore (); return img; } @@ -1704,7 +1712,7 @@ public class Glyph : FontDisplay { return false; }-+ public void juxtapose (WidgetAllocation allocation, Context cr) { string glyph_sequence = Preferences.get ("glyph_sequence"); unichar c;@@ -1743,6 +1751,7 @@ public class Glyph : FontDisplay { cr.save (); cr.scale (glyph.view_zoom, glyph.view_zoom); cr.translate (-glyph.view_offset_x, -glyph.view_offset_y);+ cr.set_source_rgba (0, 0, 0, 1); Svg.draw_svg_path (cr, juxtaposed.get_svg_data (), Glyph.xc () + left + x + kern, Glyph.yc () + baseline); cr.restore (); }@@ -1771,7 +1780,7 @@ public class Glyph : FontDisplay { cr.save (); cr.scale (glyph.view_zoom, glyph.view_zoom); cr.translate (-glyph.view_offset_x, -glyph.view_offset_y);-+ cr.set_source_rgba (0, 0, 0, 1); Svg.draw_svg_path (cr, juxtaposed.get_svg_data (), Glyph.xc () + left + x, Glyph.yc () + baseline); cr.restore (); }@@ -1779,6 +1788,29 @@ public class Glyph : FontDisplay { last_name = name; } }+ + void draw_background_glyph (WidgetAllocation allocation, Context cr) {+ double left, baseline, current_baseline, current_left;+ Glyph g;+ + current_baseline = get_line ("baseline").pos;+ current_left = get_line ("left").pos;+ + if (background_glyph != null) {+ g = (!) background_glyph;+ baseline = get_line ("baseline").pos;+ left = g.get_line ("left").pos;+ cr.save ();+ cr.scale (view_zoom, view_zoom);+ cr.translate (-view_offset_x, -view_offset_y);+ cr.set_source_rgba (0.2, 0.2, 0.2, 0.5);+ Svg.draw_svg_path (cr, g.get_svg_data (), + Glyph.xc () + left - (left - current_left) , + Glyph.yc () + baseline - (current_baseline - baseline));+ cr.restore ();+ }+ + } } }@@ -512,5 +512,17 @@ c.append (""" public static void select_language () { MainWindow.get_tab_bar ().add_unique_tab (new LanguageSelectionTab (), 120, false); }++ public static void use_current_glyph_as_background () {+ Glyph.background_glyph = MainWindow.get_current_glyph ();+ + if (MainWindow.get_current_display () is OverView) {+ Glyph.background_glyph = MainWindow.get_overview ().get_current_glyph ();+ }+ }+ + public static void reset_glyph_background () {+ Glyph.background_glyph = null;+ } } }@@ -102,6 +102,15 @@ public class OverView : FontDisplay { update_scrollbar (); } + public Glyph? get_current_glyph () + requires (selected > 0 && selected < visible_items.length ()) {+ OverViewItem oi = visible_items.nth (selected).data;+ if (oi.glyphs != null) {+ return ((!) oi.glyphs).get_current ();+ }+ return null;+ }+ private void set_initial_zoom () { Toolbox tools = MainWindow.get_toolbox (); ZoomTool z = (ZoomTool) tools.get_tool ("zoom_tool");@@ -66,7 +66,7 @@ public class OverViewItem : GLib.Object { if (has_icons () && info.is_over_icon (px, py)) { MainWindow.get_overview ().set_character_info (info); }- + return selected; } @@ -234,8 +234,7 @@ class Svg { cr.save (); - cr.set_line_width (1);- cr.set_source_rgba (0, 0, 0, 1);+ cr.set_line_width (0); if (svg == "") { return;