Commit 8cc0b75
webkit based layout and settings for exporting different formats
Changed files (8)
modifiedsrc/ContentDisplay.valamodifiedsrc/Font.valamodifiedsrc/FontDisplay.valamodifiedsrc/Icons.valamodifiedsrc/MainWindow.valamodifiedsrc/OverView.valamodifiedsrc/wscriptmodifiedwscript
Diff
@@ -39,6 +39,7 @@ class ContentDisplay : FontDisplay { Tool open_tool; Tool save_tool; Tool browser_tool;+ Tool export_preferences; ExportTool export_tool; @@ -94,7 +95,15 @@ class ContentDisplay : FontDisplay { kerning_context_tool.select_action.connect((self) => { MainWindow.get_tab_bar ().add_unique_tab (new ContextDisplay (), 65, false); });- ++ export_preferences = new Tool ("export_preferences", "Export preferences");+ export_preferences.x = 250;+ export_preferences.y = 25;+ export_preferences.select_action.connect((self) => {+ TabBar t = MainWindow.get_tab_bar ();+ t.add_unique_tab (new ExportPreferences (), 75, false);+ });+ add_new_grid_tool = new Tool ("add_new_grid", "Add new grid"); add_new_grid_tool.x = 15; add_new_grid_tool.y = 95;@@ -108,7 +117,7 @@ class ContentDisplay : FontDisplay { delete_grid_tool.select_action.connect((self) => { MainWindow.get_toolbox ().remove_current_grid (); });- + tools = new List<Tool> (); tools.append (new_file_tool); tools.append (open_tool);@@ -118,6 +127,7 @@ class ContentDisplay : FontDisplay { tools.append (add_new_grid_tool); tools.append (delete_grid_tool); tools.append (export_tool);+ tools.append (export_preferences); name = new StringBuilder (); name.append (Supplement.get_current_font ().get_name ());@@ -348,7 +358,8 @@ class ContentDisplay : FontDisplay { open_tool.draw (allocation, cr); browser_tool.draw (allocation, cr); export_tool.draw (allocation, cr);- + export_preferences.draw (allocation, cr);+ kerning_context_tool.draw (allocation, cr); } @@ -61,6 +61,9 @@ class Font : GLib.Object { private string name = "typeface"; + bool ttf_export = true;+ bool svg_export = true;+ public Font () { // positions in pixels at first zoom level // default x-height should be 60 in 1:1@@ -76,6 +79,22 @@ class Font : GLib.Object { modified = true; } + public bool get_ttf_export () {+ return ttf_export;+ }++ public bool get_svg_export () {+ return svg_export;+ }++ public void set_ttf_export (bool d) {+ ttf_export = d;+ }++ public void set_svg_export (bool d) {+ svg_export = d;+ }+ public File get_backgrounds_folder () { string fn = @"$(get_name ()) backgrounds"; File f = Supplement.get_settings_directory ().get_child (fn);@@ -238,7 +257,7 @@ class Font : GLib.Object { double r = base_line - top_position; return (r > 0) ? r : -r; }- + public void set_name (string name) { this.name = name; }@@ -548,7 +567,13 @@ class Font : GLib.Object { os.put_string ("\n"); os.put_string (@"<name>$(get_name ())</name>\n");- + + os.put_string ("\n");+ os.put_string (@"<ttf-export>$(ttf_export)</ttf-export>\n");++ os.put_string ("\n");+ os.put_string (@"<svg-export>$(svg_export)</svg-export>\n");+ os.put_string ("\n"); os.put_string ("<lines>\n"); @@ -847,6 +872,15 @@ class Font : GLib.Object { if (iter->name == "hkern") { parse_kerning (iter); }++ if (iter->name == "ttf-export") {+ ttf_export = bool.parse (iter->children->content);+ } ++ if (iter->name == "svg-export") {+ svg_export = bool.parse (iter->children->content);+ } + } delete doc;@@ -21,8 +21,60 @@ using Gdk; namespace Supplement { +/** Javascripts in webkit do use this callback. */+public class PropertyFunction {+ public delegate void PropertyCallback (string val);+ public PropertyCallback call;+}+ public abstract class FontDisplay : GLib.Object { + List<string> property = new List<string> ();+ List<PropertyFunction> call = new List<PropertyFunction> ();+ + public void add_html_callback (string prop, PropertyFunction.PropertyCallback cb) {+ PropertyFunction pf = new PropertyFunction ();+ pf.call = cb;+ property.append (prop);+ call.append (pf);+ }+ + public void process_property (string prop) {+ string k, v;+ int i, j;+ PropertyFunction cb;+ + if (prop == "done") {+ return;+ }+ + i = prop.index_of (":");+ + return_if_fail (i > 0);+ + k = prop.substring (0, i);+ v = prop.substring (i + 1);+ + j = 0;+ + foreach (string p in property) {+ if (p == k) {+ break;+ }+ j++;+ }+ + if (j >= property.length ()) {+ warning (@"key $k not found in property list");+ return;+ }+ + cb = call.nth (j).data;+ cb.call (v);+ + print (@"Got $k -> $v\n");+ }+ /** Queue redraw area */ public signal void redraw_area (double x, double y, double w, double h); @@ -31,6 +83,18 @@ public abstract class FontDisplay : GLib.Object { return ""; } + public virtual bool is_html_canvas () {+ return false;+ }++ public virtual string get_html_file () {+ return "";+ }+ + public virtual string get_html () {+ return "";+ }+ public virtual void draw (Allocation allocation, Context cr) { } @@ -90,6 +154,31 @@ public abstract class FontDisplay : GLib.Object { public virtual void undo () { }++ public static File find_layout_dir () {+ File f;+ string name = "layout";++ f = Icons.find_file ("./", name);+ if (likely (f.query_exists ())) return f; ++ f = Icons.find_file ("../", name);+ if (likely (f.query_exists ())) return f;++ f = Icons.find_file (".\\", name);+ if (likely (f.query_exists ())) return f;++ f = Icons.find_file ("", name);+ if (likely (f.query_exists ())) return f;+ + f = Icons.find_file ("/usr/local/share/supplement/", name);+ if (likely (f.query_exists ())) return f;++ f = Icons.find_file ("/usr/share/supplement/", name);+ if (likely (f.query_exists ())) return f;+ + return f;+ } } }@@ -74,7 +74,7 @@ class Icons { return f; } - private static File find_file (string? path, string name) {+ public static File find_file (string? path, string name) { StringBuilder fn = new StringBuilder (); string p = (path == null) ? "" : (!) path; @@ -17,6 +17,7 @@ using Gdk; using Gtk; +using WebKit; namespace Supplement { @@ -24,6 +25,8 @@ public class MainWindow : Gtk.Window { HBox list_box; HBox canvas_box; + WebView html_canvas; + ScrolledWindow html_box; static TabBar tabs; VBox tab_box; @@ -63,20 +66,62 @@ public class MainWindow : Gtk.Window { set_size_and_position (); + html_canvas = new WebView (); + + html_canvas.title_changed.connect ((p, s) => { + print (@"property $s\n"); + FontDisplay fd = get_current_display (); + fd.process_property (s); + }); + + html_box = new ScrolledWindow (null, null); + html_box.set_policy (PolicyType.NEVER, PolicyType.AUTOMATIC); + html_box.add (html_canvas); + tabs.signal_tab_selected.connect ((f, tab) => { + bool n; + File layout_dir; + string uri; FontDisplay fd = tab.get_display (); + glyph_canvas.set_current_glyph (fd); + n = fd.is_html_canvas (); + + if (n) { + layout_dir = FontDisplay.find_layout_dir (); + html_box.set_visible (n); + glyph_canvas.set_visible (!n); + + uri = @"file://$((!) layout_dir.get_path ())/$(fd.get_html_file ())"; + if (fd.get_html_file () != "") { + assert (fd.get_html () == ""); + html_canvas.load_uri (uri); + } else { + html_canvas.load_html_string (fd.get_html (), uri); + } + } else { + html_box.set_visible (false); + glyph_canvas.set_visible (true); + } }); + // Hide this canvas when windown is realized and flip canvas + // visibility in tab selection signal. + html_canvas.expose_event.connect ((t, e) => { + glyph_canvas.set_visible (false); + return false; + }); + over_view = new OverView(); tabs.add_unique_tab (content, 60, true); tabs.add_unique_tab (over_view, 75, false); tabs.select_tab_name ("File"); - + canvas_box = new HBox (false, 0); - canvas_box.pack_start (glyph_canvas, true, true, 0); + canvas_box.child = (glyph_canvas); + canvas_box.pack_start (html_box, true, true, 0); tab_box = new VBox (false, 0); tab_box.pack_start (tabs, false, false, 0); @@ -425,17 +425,12 @@ class OverView : FontDisplay { if (items_per_row == 0) { items_per_row = n_items; first_visible = first_character;+ + key_down ();+ key_up (); } else { items_per_row = n_items; first_visible = first_character;- - while (selected < first_visible) {- scroll (-nail_height);- }- - while (selected < first_visible + rows * n_items) {- scroll (nail_height); - } } } @@ -4,6 +4,7 @@ SUPPLEMENT_MAIN = [ 'BackgroundTool.vala', 'BackgroundSelection.vala', 'ExportTool.vala', + 'ExportPreferences.vala', 'FontDisplay.vala', 'CharDatabase.vala', 'Context.vala', @@ -64,7 +65,7 @@ def build (bld): target = 'supplement', param = '--disable-warnings --enable-experimental --enable-experimental-non-null --vapidir=../../', packages = 'gtk+-2.0 libxml-2.0', - uselib = 'GTK GLIB GIO XML', + uselib = 'GTK GLIB GIO XML WEB', source = SUPPLEMENT_MAIN ) @@ -10,13 +10,14 @@ def options(opt): def configure(conf): conf.load('compiler_c vala') - + conf.check_cfg(package='glib-2.0', uselib_store='GLIB',atleast_version='2.16.0', mandatory=1, args='--cflags --libs') conf.check_cfg(package='gio-2.0', uselib_store='GIO', atleast_version='2.16.0', mandatory=1, args='--cflags --libs') conf.check_cfg(package='gtk+-2.0', uselib_store='GTK', atleast_version='2.16.0', mandatory=1, args='--cflags --libs') conf.check_cfg(package='libxml-2.0', uselib_store='XML', mandatory=1, args='--cflags --libs') + conf.check_cfg(package='webkit-1.0', uselib_store='WEB', mandatory=1, args='--cflags --libs') - conf.env.append_unique('VALAFLAGS', ['--enable-experimental', '--enable-experimental-non-null', '--vapidir=../../']) + conf.env.append_unique('VALAFLAGS', ['--thread', '--pkg', 'webkit-1.0', '--enable-experimental', '--enable-experimental-non-null', '--vapidir=../../']) def build(bld): bld.recurse('src')