Commit 45bf6cb
Improved preview This commit adds a tool box for the preview tab with a few tools that let users export fonts and update the Webkit view.
Changed files (13)
modifiedbirdfont/GtkWindow.valamodifiedgraphics/tools_and_buttons.svgdeletedicons/export.pngaddedicons/export_fonts.pngaddedicons/generate_html_document.pngaddedicons/update_webview.pngmodifiedlibbirdfont/DrawingTools.valamodifiedlibbirdfont/FileTab.valamodifiedlibbirdfont/MenuTab.valamodifiedlibbirdfont/Preview.valaaddedlibbirdfont/PreviewTools.valamodifiedlibbirdfont/TabBar.valamodifiedlibbirdfont/Toolbox.vala
Diff
@@ -97,6 +97,7 @@ public class GtkWindow : Gtk.Window, NativeWindow { MainWindow.get_tab_bar ().signal_tab_selected.connect ((f, tab) => { string uri = "";+ string html = ""; FontDisplay fd = tab.get_display (); MainWindow.glyph_canvas.set_current_glyph (fd); @@ -109,57 +110,10 @@ public class GtkWindow : Gtk.Window, NativeWindow { glyph_canvas_area.set_visible (false); } else if (fd.get_name () == "Preview") { uri = Preview.get_uri ();-- // hack: force webkit to ignore cache in preview- html_box.set_visible (false);- glyph_canvas_area.set_visible (true);- - try {- DataInputStream dis = new DataInputStream (Preview.get_html_file ().read ());- string? line;- StringBuilder sb = new StringBuilder ();- uint rid = Random.next_int ();- Font font = BirdFont.get_current_font ();- - File preview_directory = BirdFont.get_preview_directory ();- - File f_ttf = font.get_folder ().get_child (@"$(font.get_full_name ()).ttf");- File f_eot = font.get_folder ().get_child (@"$(font.get_full_name ()).eot");- File f_svg = font.get_folder ().get_child (@"$(font.get_full_name ()).svg");-- if (f_ttf.query_exists ()) {- f_ttf.delete ();- }- - if (f_eot.query_exists ()) {- f_eot.delete ();- }- - if (f_svg.query_exists ()) {- f_svg.delete ();- }- - ExportTool.export_svg_font ();- ExportTool.export_ttf_font_sync (); - - File r_ttf = preview_directory.get_child (@"$(font.get_full_name ())$rid.ttf");- File r_svg = preview_directory.get_child (@"$(font.get_full_name ())$rid.svg");- - if (BirdFont.win32) {- f_ttf.copy (r_ttf, FileCopyFlags.NONE);- }- - f_svg.copy (r_svg, FileCopyFlags.NONE);-- while ((line = dis.read_line (null)) != null) {- line = ((!) line).replace (@"$(font.get_full_name ()).ttf", @"$(FontDisplay.path_to_uri ((!) f_ttf.get_path ()))?$rid");- line = ((!) line).replace (@"$(font.get_full_name ()).eot", @"$(FontDisplay.path_to_uri ((!) f_eot.get_path ()))?$rid");- line = ((!) line).replace (@"$(font.get_full_name ()).svg", @"$(FontDisplay.path_to_uri ((!) f_svg.get_path ()))?$rid");- sb.append ((!) line);- }- - html_canvas.load_html_string (sb.str, uri);+ html = Preview.get_html_with_absolute_paths (); + try { + html_canvas.load_html_string (html, uri); } catch (Error e) { warning (e.message); warning ("Failed to load html into canvas.");@@ -16,7 +16,7 @@ version="1.1" inkscape:version="0.48.4 r9939" sodipodi:docname="tools_and_buttons.svg"- inkscape:export-filename="/home/johan/birdfont/icons/flip_horizontal.png"+ inkscape:export-filename="/home/johan/birdfont/icons/generate_html_document.png" inkscape:export-xdpi="319.88824" inkscape:export-ydpi="319.88824"> <defs@@ -405,6 +405,109 @@ r="30.703518" gradientUnits="userSpaceOnUse" gradientTransform="matrix(1.696811,-0.06964229,0.06038833,1.4713414,-140.70881,2.3661124)" />+ <linearGradient+ inkscape:collect="always"+ xlink:href="#linearGradient3761-1-3-33"+ id="linearGradient4027-3"+ gradientUnits="userSpaceOnUse"+ gradientTransform="matrix(1.1095097,0,0,0.99800197,-656.63464,-283.00582)"+ x1="608.99573"+ y1="316.79437"+ x2="608.64221"+ y2="290.27783" />+ <linearGradient+ id="linearGradient3761-1-3-33">+ <stop+ style="stop-color:#eeeded;stop-opacity:1"+ offset="0"+ id="stop3763-4-4-81" />+ <stop+ style="stop-color:#ffffff;stop-opacity:1;"+ offset="1"+ id="stop3765-1-1-3" />+ </linearGradient>+ <linearGradient+ y2="290.27783"+ x2="608.64221"+ y1="316.79437"+ x1="608.99573"+ gradientTransform="matrix(1.1095097,0,0,0.99800197,-655.33353,116.22305)"+ gradientUnits="userSpaceOnUse"+ id="linearGradient3264"+ xlink:href="#linearGradient3761-1-3-33"+ inkscape:collect="always" />+ <linearGradient+ inkscape:collect="always"+ xlink:href="#linearGradient3761-1-3-4"+ id="linearGradient4027-4"+ gradientUnits="userSpaceOnUse"+ gradientTransform="matrix(1.1095097,0,0,0.99800197,-656.63464,-283.00582)"+ x1="608.99573"+ y1="316.79437"+ x2="608.64221"+ y2="290.27783" />+ <linearGradient+ id="linearGradient3761-1-3-4">+ <stop+ style="stop-color:#eeeded;stop-opacity:1"+ offset="0"+ id="stop3763-4-4-9" />+ <stop+ style="stop-color:#ffffff;stop-opacity:1;"+ offset="1"+ id="stop3765-1-1-38" />+ </linearGradient>+ <linearGradient+ y2="290.27783"+ x2="608.64221"+ y1="316.79437"+ x1="608.99573"+ gradientTransform="matrix(1.1095097,0,0,0.99800197,-660.46502,-288.68482)"+ gradientUnits="userSpaceOnUse"+ id="linearGradient4095"+ xlink:href="#linearGradient3761-1-3-4"+ inkscape:collect="always" />+ <linearGradient+ inkscape:collect="always"+ xlink:href="#linearGradient3761-1-3-4"+ id="linearGradient4131"+ gradientUnits="userSpaceOnUse"+ gradientTransform="matrix(1.1095097,0,0,0.99800197,-622.38631,114.60033)"+ x1="608.99573"+ y1="316.79437"+ x2="608.64221"+ y2="290.27783" />+ <linearGradient+ inkscape:collect="always"+ xlink:href="#linearGradient3761-1-3-0"+ id="linearGradient4027-37"+ gradientUnits="userSpaceOnUse"+ gradientTransform="matrix(1.1095097,0,0,0.99800197,-656.63464,-283.00582)"+ x1="608.99573"+ y1="316.79437"+ x2="608.64221"+ y2="290.27783" />+ <linearGradient+ id="linearGradient3761-1-3-0">+ <stop+ style="stop-color:#eeeded;stop-opacity:1"+ offset="0"+ id="stop3763-4-4-4" />+ <stop+ style="stop-color:#ffffff;stop-opacity:1;"+ offset="1"+ id="stop3765-1-1-58" />+ </linearGradient>+ <linearGradient+ y2="290.27783"+ x2="608.64221"+ y1="316.79437"+ x1="608.99573"+ gradientTransform="matrix(1.1095097,0,0,0.99800197,-581.1328,116.90405)"+ gradientUnits="userSpaceOnUse"+ id="linearGradient4175"+ xlink:href="#linearGradient3761-1-3-0"+ inkscape:collect="always" /> </defs> <sodipodi:namedview id="base"@@ -413,9 +516,9 @@ borderopacity="1.0" inkscape:pageopacity="0.0" inkscape:pageshadow="2"- inkscape:zoom="5.4770642"- inkscape:cx="199"- inkscape:cy="703.5"+ inkscape:zoom="1"+ inkscape:cx="104.43834"+ inkscape:cy="468.78196" inkscape:current-layer="layer1" inkscape:document-units="px" showgrid="false"@@ -1910,5 +2013,97 @@ inkscape:export-filename="/home/johan/birdfont/icons/track.png" inkscape:export-xdpi="319.89001" inkscape:export-ydpi="319.89001" />+ <g+ id="g4075"+ inkscape:export-filename="/home/johan/birdfont/icons/update_webview.png"+ inkscape:export-xdpi="319"+ inkscape:export-ydpi="319">+ <rect+ inkscape:export-ydpi="319"+ inkscape:export-xdpi="319"+ inkscape:export-filename="/home/johan/birdfont/icons/update_webview.png"+ y="412.64969"+ x="9.7045212"+ height="14.306025"+ width="17.010134"+ id="rect4069"+ style="fill:none;" />+ <path+ sodipodi:nodetypes="csssc"+ inkscape:connector-curvature="0"+ id="path3285"+ d="m 13.302974,417.23111 c -0.103718,-3.07049 2.410096,-3.2344 4.43523,-3.24588 2.477269,-0.014 4.861048,0.23803 4.894968,5.42429 0.02793,4.27128 -1.032833,6.09448 -4.442348,6.09448 -2.667991,0 -5.382393,-0.32164 -4.784799,-5.55719"+ style="fill:none;stroke:#858585;stroke-width:1;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none" />+ <path+ sodipodi:nodetypes="ccc"+ inkscape:connector-curvature="0"+ id="path3289"+ d="m 10.941276,422.08208 2.336134,-2.69315 2.432232,2.7018"+ style="fill:none;stroke:#858585;stroke-width:1;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none" />+ </g>+ <g+ id="g4154"+ style="stroke:#858585;stroke-opacity:1"+ transform="translate(0.19863014,2.3835618)"+ inkscape:export-filename="/home/johan/birdfont/icons/export_fonts.png"+ inkscape:export-xdpi="319"+ inkscape:export-ydpi="319">+ <g+ transform="translate(-3.690616,1.451615)"+ id="g4145"+ style="stroke:#858585;stroke-opacity:1">+ <path+ sodipodi:nodetypes="cc"+ style="fill:none;stroke:#858585;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"+ d="m 51.12501,416.09675 12.128285,0"+ id="path4133"+ inkscape:connector-curvature="0" />+ <path+ style="fill:none;stroke:#858585;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"+ d="m 60.897902,412.86775 2.992578,3.56045"+ id="path4139"+ inkscape:connector-curvature="0"+ sodipodi:nodetypes="cc" />+ <path+ style="fill:none;stroke:#858585;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"+ d="m 63.958333,415.90522 -3.078034,3.64394"+ id="path4143"+ inkscape:connector-curvature="0"+ sodipodi:nodetypes="cc" />+ </g>+ </g>+ <g+ id="g4240"+ inkscape:export-filename="/home/johan/birdfont/icons/generate_html_document.png"+ inkscape:export-xdpi="319"+ inkscape:export-ydpi="319">+ <path+ sodipodi:nodetypes="cccccc"+ inkscape:connector-curvature="0"+ id="path4194"+ d="m 89.176159,415.85065 0,10.85224 10.270161,0 0,-14.47262 -7.237895,0 z"+ style="fill:#ffffff;stroke:#858585;stroke-width:0.78642100000000004px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1" />+ <path+ inkscape:connector-curvature="0"+ id="path4233"+ d="m 89.570109,416.4873 3.852514,0"+ style="fill:none;stroke:#e6e6e6;stroke-width:1.10593903px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1" />+ <g+ transform="translate(0.14089431,-0.25163226)"+ id="text4226"+ style="font-size:8.32909298px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;line-height:125%;letter-spacing:0px;word-spacing:0px;fill:#858585;fill-opacity:1;stroke:none;font-family:Big_Bottom_Cartoon_Hungarian;-inkscape-font-specification:Big_Bottom_Cartoon_Hungarian">+ <path+ inkscape:connector-curvature="0"+ id="path4231"+ style="fill:#858585;fill-opacity:1;font-family:BetecknaBirdfont;-inkscape-font-specification:BetecknaBirdfont"+ d="m 92.262767,417.02452 0.821522,0 0,2.48897 2.985134,0 0,-2.48897 0.821522,0 0,6.07195 -0.821522,0 0,-2.8916 -2.985134,0 0,2.8916 -0.821522,0 0,-6.07195" />+ </g>+ <path+ sodipodi:nodetypes="cc"+ inkscape:connector-curvature="0"+ id="path4238"+ d="m 92.92596,416.18009 0.01336,-3.554"+ style="fill:none;stroke:#e6e6e6;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1" />+ </g> </g> </svg>deleted file mode 100644Binary files a/icons/export.png and /dev/null differnew file mode 100644Binary files /dev/null and b/icons/export_fonts.png differnew file mode 100644Binary files /dev/null and b/icons/generate_html_document.png differnew file mode 100644Binary files /dev/null and b/icons/update_webview.png differ@@ -254,7 +254,7 @@ public class DrawingTools : ToolCollection { // Character set tools Tool full_unicode = new Tool ("utf_8", t_("Show full unicode characters set")); full_unicode.select_action.connect ((self) => {- MainWindow.get_tab_bar ().add_unique_tab (new OverView (), 100, false); + MainWindow.get_tab_bar ().add_unique_tab (new OverView ()); OverView o = MainWindow.get_overview (); GlyphRange gr = new GlyphRange (); @@ -520,7 +520,7 @@ public class DrawingTools : ToolCollection { } BackgroundSelection bgs = new BackgroundSelection ();- MainWindow.get_tab_bar ().add_unique_tab (bgs , 120, false);+ MainWindow.get_tab_bar ().add_unique_tab (bgs); tp.show_text (""); });@@ -155,6 +155,11 @@ public class FileTab : FontDisplay { if (i == r) { load_font ((!) font.font_file); open_file ();++ // open_file will close this tab and the list of files + // will be deleted here.++ return; } i++; }@@ -173,6 +178,7 @@ public class FileTab : FontDisplay { } else { load_backup (backup); open_file ();+ return; } } i++;@@ -231,12 +231,12 @@ public class MenuTab : FontDisplay { } public static void show_description () {- MainWindow.get_tab_bar ().add_unique_tab (new DescriptionTab (), 110, false);+ MainWindow.get_tab_bar ().add_unique_tab (new DescriptionTab ()); } public static void show_kerning_context () { KerningDisplay kd = MainWindow.get_kerning_display ();- MainWindow.get_tab_bar ().add_unique_tab (kd, 85, false);+ MainWindow.get_tab_bar ().add_unique_tab (kd); } public static void preview () {@@ -260,7 +260,8 @@ public class MenuTab : FontDisplay { } dialog.overwrite_signal.connect (() => {- tab_bar.add_unique_tab (new Preview ());+ tab_bar.add_unique_tab (new Preview (), true);+ PreviewTools.update_preview (); }); if ((format == FontFormat.SVG || format == FontFormat.FREETYPE) && !OverWriteDialogListener.dont_ask_again) {@@ -293,7 +294,7 @@ public class MenuTab : FontDisplay { } public static void list_all_kerning_pairs () {- MainWindow.get_tab_bar ().add_unique_tab (new KerningList (), 130);+ MainWindow.get_tab_bar ().add_unique_tab (new KerningList ()); } } }@@ -36,7 +36,7 @@ public class Preview : FontDisplay { public static File get_file () { Font font = BirdFont.get_current_font ();- string path = @"$(font.get_full_name ()).html";+ string path = get_html_file_name (); File dir = font.get_folder (); File file = dir.get_child (path); @@ -46,6 +46,39 @@ public class Preview : FontDisplay { return file; }+ + public static bool has_html_document () {+ Font font = BirdFont.get_current_font ();+ string path = get_html_file_name ();+ File dir = font.get_folder ();+ File file = dir.get_child (path);+ return file.query_exists ();+ }+ + public static void generate_html_document () {+ Font font = BirdFont.get_current_font ();+ string path = get_html_file_name ();+ File dir = font.get_folder ();+ File file = dir.get_child (path);+ ExportTool.generate_html_document ((!)file.get_path (), font);+ }++ public static void delete_html_document () {+ Font font = BirdFont.get_current_font ();+ string path = get_html_file_name ();+ File dir = font.get_folder ();+ File file = dir.get_child (path);+ try {+ file.delete ();+ } catch (Error e) {+ warning (e.message);+ }+ }+ + static string get_html_file_name () {+ Font font = BirdFont.get_current_font ();+ return @"$(font.get_full_name ()).html";+ } public static File get_html_file () { return get_file (); @@ -57,7 +90,7 @@ public class Preview : FontDisplay { public static string get_windows_uri () { Font font = BirdFont.get_current_font ();- string html = @"$(font.get_full_name ()).html";+ string html = get_html_file_name (); File dir = font.get_folder (); File file = dir.get_child (html); return "file:///" + (!) file.get_path ();@@ -78,8 +111,7 @@ public class Preview : FontDisplay { File f_svg; File r_ttf; File r_svg;- - + try { dis = new DataInputStream (get_file ().read ()); @@ -106,6 +138,7 @@ public class Preview : FontDisplay { } } catch (Error e) { warning (e.message);+ sb.append (@"Error: $(e.message)<br>\n"); warning ("Failed to copy ttf file."); } @@ -124,6 +157,7 @@ public class Preview : FontDisplay { } catch (Error e) { warning (e.message); warning ("Failed to load html into canvas.");+ sb.append (@"Error: $(e.message)<br>\n"); } return sb.str; }new file mode 100644@@ -0,0 +1,84 @@+/*+ Copyright (C) 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 + 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.+*/++namespace BirdFont {++public class PreviewTools : ToolCollection {+ public List<Expander> expanders;+ public Expander classes;+ + private static bool suppress_event = false;+ + public PreviewTools () {+ Expander webview_tools = new Expander ();+ + Tool update_webview_button = new Tool ("update_webview", t_("Reload webview"));+ update_webview_button.select_action.connect ((self) => {+ update_preview ();+ });+ webview_tools.add_tool (update_webview_button);+ + Tool export_fonts_button = new Tool ("export_fonts", t_("Export fonts"));+ export_fonts_button.select_action.connect ((self) => {+ export_fonts ();+ });+ webview_tools.add_tool (export_fonts_button);++ Tool generate_html_button = new Tool ("generate_html_document", t_("Generate html document"));+ generate_html_button.select_action.connect ((self) => {+ generate_html_document ();+ });+ webview_tools.add_tool (generate_html_button);+ + webview_tools.set_open (true);+ + expanders.append (webview_tools);+ }++ + /** Export fonts and update html canvas. */+ public static void update_preview () {+ Font font = BirdFont.get_current_font ();++ export_fonts ();++ if (!Preview.has_html_document ()) {+ Preview.generate_html_document ();+ }+ + MainWindow.tabs.select_tab_name ("Preview");+ }+ + /** Export TTF, EOT and SVG fonts. */+ public static void export_fonts () {+ if (!suppress_event) {+ suppress_event = true;+ ExportTool.export_ttf_font_sync ();+ ExportTool.export_svg_font ();+ suppress_event = false;+ }+ }++ /** Generate the preview document. */+ public static void generate_html_document () {+ Preview.delete_html_document ();+ Preview.generate_html_document ();+ }+ + public override unowned List<Expander> get_expanders () {+ return expanders;+ }+}++}@@ -308,7 +308,7 @@ public class TabBar : GLib.Object { return selected; } - public void select_tab (int index) {+ public void select_tab (int index, bool signal_selected = true) { Tab t; // always close any pending text input if the user switches tab@@ -349,7 +349,7 @@ public class TabBar : GLib.Object { previous_tab = current_tab; current_tab = t; - scroll_to_tab (selected);+ scroll_to_tab (selected, signal_selected); } private bool has_scroll () {@@ -388,13 +388,16 @@ public class TabBar : GLib.Object { signal_tab_selected (t); } - private void scroll_to_tab (int index) {+ private void scroll_to_tab (int index, bool send_signal_selected = true) { double offset = 19; int i = 0; if (index < first_tab) { first_tab = index;- signal_selected (index);+ + if (send_signal_selected) {+ signal_selected (index);+ } return; } @@ -414,7 +417,11 @@ public class TabBar : GLib.Object { // in view if (i == index) {- signal_selected (index);+ + if (send_signal_selected) { + signal_selected (index);+ }+ return; } @@ -444,7 +451,9 @@ public class TabBar : GLib.Object { } } - public void add_tab (FontDisplay display_item, double tab_width = -1, bool always_open = false) {+ public void add_tab (FontDisplay display_item, bool signal_selected = true) {+ double tab_width = -1;+ bool always_open = false; int s = (tabs.length () == 0) ? 0 : selected + 1; if (tab_width < 0) {@@ -453,15 +462,15 @@ public class TabBar : GLib.Object { } tabs.insert (new Tab (display_item, tab_width, always_open), s);- select_tab (s);+ select_tab (s, signal_selected); } /** Returns true if the new item was added to the bar. */- public bool add_unique_tab (FontDisplay display_item, double tab_width = -1, bool always_open = false) {+ public bool add_unique_tab (FontDisplay display_item, bool signal_selected = true) { bool i = select_tab_name (display_item.get_name ()); if (!i) {- add_tab (display_item, tab_width, always_open);+ add_tab (display_item, signal_selected); return true; } @@ -22,6 +22,7 @@ public class Toolbox : GLib.Object { public DrawingTools drawing_tools; public KerningTools kerning_tools;+ public PreviewTools preview_tools; Tool current_tool; @@ -46,11 +47,16 @@ public class Toolbox : GLib.Object { drawing_tools = new DrawingTools (glyph_canvas); kerning_tools = new KerningTools ();+ preview_tools = new PreviewTools ();+ current_set = drawing_tools; tab_bar.signal_tab_selected.connect ((tab) => {- if (tab.get_display ().get_name () == "Kerning") {+ string tab_name = tab.get_display ().get_name ();+ if (tab_name == "Kerning") { current_set = kerning_tools;+ } else if (tab_name == "Preview") {+ current_set = preview_tools; } else { current_set = drawing_tools; }