Clone in a terminal:
Commit 817a340
Johan Mattsson - 2012-10-25T18:05:30+00:00
817a340a3b89bf81d8e65bdefe4b9a88e07e4569johan.mattsson.m@gmail.com

use a new win32 preview hack for all versions of webkit

Changed files (9)

Diff

diff --git a/icon.svg b/icon.svgdeleted file mode 100644index 5edab6d..0000000--- a/icon.svg+++ /dev/null@@ -1,134 +0,0 @@-<?xml version="1.0" encoding="UTF-8" standalone="no"?>-<!-- Created with Inkscape (http://www.inkscape.org/) -->--<svg-   xmlns:dc="http://purl.org/dc/elements/1.1/"-   xmlns:cc="http://creativecommons.org/ns#"-   xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"-   xmlns:svg="http://www.w3.org/2000/svg"-   xmlns="http://www.w3.org/2000/svg"-   xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"-   xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"-   width="48px"-   height="48px"-   id="svg4654"-   version="1.1"-   inkscape:version="0.48.2 r9819"-   sodipodi:docname="icon.svg"-   inkscape:export-filename="/home/johan/supplement/birdfont.png"-   inkscape:export-xdpi="90"-   inkscape:export-ydpi="90">-  <defs-     id="defs4656">-    <filter-       color-interpolation-filters="sRGB"-       inkscape:collect="always"-       id="filter4650"-       x="-0.38097897"-       width="1.7619579"-       y="-0.37840477"-       height="1.7568095">-      <feGaussianBlur-         inkscape:collect="always"-         stdDeviation="9.55137"-         id="feGaussianBlur4652" />-    </filter>-  </defs>-  <sodipodi:namedview-     id="base"-     pagecolor="#ffffff"-     bordercolor="#666666"-     borderopacity="1.0"-     inkscape:pageopacity="0.0"-     inkscape:pageshadow="2"-     inkscape:zoom="3.8425671"-     inkscape:cx="25.859905"-     inkscape:cy="19.394929"-     inkscape:current-layer="layer1"-     showgrid="true"-     inkscape:grid-bbox="true"-     inkscape:document-units="px"-     inkscape:window-width="472"-     inkscape:window-height="415"-     inkscape:window-x="241"-     inkscape:window-y="281"-     inkscape:window-maximized="0" />-  <metadata-     id="metadata4659">-    <rdf:RDF>-      <cc:Work-         rdf:about="">-        <dc:format>image/svg+xml</dc:format>-        <dc:type-           rdf:resource="http://purl.org/dc/dcmitype/StillImage" />-        <dc:title></dc:title>-      </cc:Work>-    </rdf:RDF>-  </metadata>-  <g-     id="layer1"-     inkscape:label="Layer 1"-     inkscape:groupmode="layer">-    <flowRoot-       transform="matrix(0.86335287,0,0,0.86335287,-986.96953,942.5446)"-       style="font-size:40px;font-style:normal;font-weight:normal;line-height:125%;letter-spacing:0px;word-spacing:0px;fill:#87aade;fill-opacity:1;stroke:none;font-family:Sans"-       id="flowRoot3854-6"-       xml:space="preserve"><flowRegion-         id="flowRegion3856-2"><rect-           style="fill:#87aade;fill-opacity:1"-           y="-1088.9211"-           x="1149.3966"-           height="1094.0553"-           width="451.2446"-           id="rect3858-2" /></flowRegion><flowPara-         style="font-style:normal;font-variant:normal;font-weight:500;font-stretch:normal;fill:#87aade;fill-opacity:1;font-family:BetecknaLowerCase;-inkscape-font-specification:BetecknaLowerCase Medium"-         id="flowPara3860-2">B</flowPara></flowRoot>    <text-       sodipodi:linespacing="125%"-       id="text3985"-       y="35.987507"-       x="26.43726"-       style="font-size:34.4835701px;font-style:normal;font-weight:normal;line-height:125%;letter-spacing:0px;word-spacing:0px;fill:#aaccff;fill-opacity:1;stroke:none;font-family:Sans"-       xml:space="preserve"><tspan-         style="font-style:normal;font-variant:normal;font-weight:500;font-stretch:normal;fill:#aaccff;font-family:BetecknaLowerCase;-inkscape-font-specification:BetecknaLowerCase Medium"-         y="35.987507"-         x="26.43726"-         id="tspan3987"-         sodipodi:role="line">T</tspan></text>-    <text-       xml:space="preserve"-       style="font-size:17.96886063px;font-style:normal;font-weight:normal;line-height:125%;letter-spacing:0px;word-spacing:0px;fill:#2c5aa0;fill-opacity:1;stroke:none;font-family:Sans"-       x="19.960161"-       y="24.938908"-       id="text3865-6"-       sodipodi:linespacing="125%"><tspan-         sodipodi:role="line"-         id="tspan3867-9"-         x="19.960161"-         y="24.938908"-         style="font-style:normal;font-variant:normal;font-weight:500;font-stretch:normal;fill:#2c5aa0;font-family:BetecknaLowerCase;-inkscape-font-specification:BetecknaLowerCase Medium">IRD</tspan></text>-    <text-       xml:space="preserve"-       style="font-size:15.01926994px;font-style:normal;font-weight:normal;line-height:125%;letter-spacing:0px;word-spacing:0px;fill:#214478;fill-opacity:1;stroke:none;font-family:Sans"-       x="7.6629086"-       y="35.851002"-       id="text3888-1"-       sodipodi:linespacing="125%"><tspan-         sodipodi:role="line"-         id="tspan3890-6"-         x="7.6629086"-         y="35.851002"-         style="font-style:normal;font-variant:normal;font-weight:500;font-stretch:normal;fill:#214478;font-family:BetecknaLowerCase;-inkscape-font-specification:BetecknaLowerCase Medium">FON</tspan></text>-    <text-       sodipodi:linespacing="125%"-       id="text3989"-       y="35.981796"-       x="37.876553"-       style="font-size:15.01926994px;font-style:normal;font-weight:normal;line-height:125%;letter-spacing:0px;word-spacing:0px;fill:#214478;fill-opacity:1;stroke:none;font-family:Sans"-       xml:space="preserve"><tspan-         style="font-style:normal;font-variant:normal;font-weight:500;font-stretch:normal;fill:#214478;font-family:BetecknaLowerCase;-inkscape-font-specification:BetecknaLowerCase Medium"-         y="35.981796"-         x="37.876553"-         id="tspan3991"-         sodipodi:role="line">!</tspan></text>-  </g>-</svg>diff --git a/src/EotWriter.vala b/src/EotWriter.valaindex 5da1b94..0bc0736 100644--- a/src/EotWriter.vala+++ b/src/EotWriter.vala@@ -163,6 +163,10 @@ class EotWriter { 		for (int i = 0; i < l; i++) { 			os.put_byte (data[i]); 		}+		+		dis.close ();+		os.close ();+		input.close (); 	} 	 }diff --git a/src/ExportTool.vala b/src/ExportTool.valaindex d3eb1a9..9ac4fa6 100644--- a/src/ExportTool.vala+++ b/src/ExportTool.vala@@ -364,6 +364,9 @@ os.put_string ( 			async = false; 		} +		// the font be created before html is loaded into webkit, see the hack in GtkWindow+		async = false;+ 		try { 			// create a copy of current font and use it in a separate  			// export thread@@ -498,7 +501,7 @@ os.put_string ( 		} 		 		void write_eof () {-			EotWriter fo;+/*			EotWriter fo;  			return_if_fail (!is_null (this)); 			return_if_fail (!is_null (ttf));@@ -513,7 +516,7 @@ os.put_string ( 			} catch (Error e) { 				warning ("EOF convertion falied."); 				critical (@"$(e.message)");-			}+			}*/ 		} 	} 	diff --git a/src/GtkWindow.vala b/src/GtkWindow.valaindex 705a4f6..e829ea6 100644--- a/src/GtkWindow.vala+++ b/src/GtkWindow.vala@@ -88,54 +88,73 @@ public class GtkWindow : Gtk.Window, NativeWindow { 					layout_uri = layout_dir.get_child (fd.get_html_file ()); 					uri = fd.path_to_uri ((!) layout_uri.get_path ()); 				}-				+		 				if (fd.get_html () == "") { 					-					// this hack forces webkit to reload the font and ignore cached data-					// it's only required on windows platform and in wine-					//-					// webkit will crash if the loaded font file is updated with export_all-					//-					if (Supplement.win32) {-						html_canvas.load_uri (uri);+					if (fd.get_name () == "Preview") {+						// hack: force webkit to ignore cache in preview+						//ExportTool.export_all ();++						html_canvas.reload_bypass_cache ();+						html_canvas.load_html_string ("<html></html>", "file:///");	+						html_canvas.reload_bypass_cache (); 						-						TimeoutSource loadscreen = new TimeoutSource(300);-						loadscreen.set_callback(() => {-							html_canvas.load_html_string ("<html>Loading ...</html>", "file:///");-							html_canvas.reload_bypass_cache ();+						html_box.set_visible (false);+						glyph_canvas_area.set_visible (true);+												+						try {+							Preview preview = (Preview) fd;+							DataInputStream dis = new DataInputStream (preview.get_html_file ().read ());+							string? line;+							StringBuilder sb = new StringBuilder ();+							uint rid = Random.next_int ();+							Font font = Supplement.get_current_font ();+							+							File preview_directory = Supplement.get_preview_directory ();+							+							File f_ttf = font.get_folder ().get_child (@"$(font.get_name ()).ttf");+							File f_eot = font.get_folder ().get_child (@"$(font.get_name ()).eot");+							File f_svg = font.get_folder ().get_child (@"$(font.get_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_ttf_font ();+							ExportTool.export_svg_font (); 							-							html_box.set_visible (n);-							glyph_canvas_area.set_visible (!n);+							File r_ttf = preview_directory.get_child (@"$(font.get_name ())$rid.ttf");+							//File r_eot = preview_directory.get_child (@"$(font.get_name ())$rid.eot");+							File r_svg = preview_directory.get_child (@"$(font.get_name ())$rid.svg"); 							-							if (fd.get_name () == "Preview") {-								ExportTool.export_all ();+							f_ttf.copy (r_ttf, FileCopyFlags.NONE);+							//f_eot.copy (r_eot, FileCopyFlags.NONE);+							f_svg.copy (r_svg, FileCopyFlags.NONE);++							while ((line = dis.read_line (null)) != null) {+								line = ((!) line).replace (@"$(font.get_name ()).ttf", @"$(FontDisplay.path_to_uri ((!) f_ttf.get_path ()))?$rid");+								line = ((!) line).replace (@"$(font.get_name ()).eot", @"$(FontDisplay.path_to_uri ((!) f_eot.get_path ()))?$rid");+								line = ((!) line).replace (@"$(font.get_name ()).svg", @"$(FontDisplay.path_to_uri ((!) f_svg.get_path ()))?$rid");+								sb.append ((!) line); 							}-						-							return false;-						});-						loadscreen.attach(null);-						-						TimeoutSource update = new TimeoutSource(2000);						-						update.set_callback(() => {-							html_canvas.load_uri (uri);-							html_canvas.reload_bypass_cache ();-							return false;-						});-						update.attach(null);--					} else {--						if (fd.get_name () == "Preview") {-							ExportTool.export_all ();+					+							html_canvas.load_html_string (sb.str, uri);							+						} catch (Error e) {+							warning (e.message);+							warning ("Failed to load html into canvas."); 						}-				-						html_canvas.load_html_string ("<html></html>", "file:///");	-						html_canvas.reload_bypass_cache (); 						+					} else {+						// normal way to load a uri for all other pages 						html_canvas.load_uri (uri);-						html_canvas.reload_bypass_cache ();-						html_canvas.load_uri (uri);+						html_canvas.reload_bypass_cache ();			 					}+						 				} else { 					html_canvas.load_html_string (fd.get_html (), uri); 				}@@ -146,6 +165,7 @@ public class GtkWindow : Gtk.Window, NativeWindow { 				html_box.set_visible (false); 				glyph_canvas_area.set_visible (true); 			}+ 		});  		// Hide this canvas when window is realized and flip canvas diff --git a/src/OpenFontFormatReader.vala b/src/OpenFontFormatReader.valaindex ec4aea2..d7815ed 100644--- a/src/OpenFontFormatReader.vala+++ b/src/OpenFontFormatReader.vala@@ -57,6 +57,10 @@ class OpenFontFormatReader : Object { 		directory_table = new DirectoryTable (); 	} 	+	public void close () {+		dis.close ();+	}+	 	public Glyph? read_glyph (string name) { 		try { 			return directory_table.glyf_table.read_glyph (name);diff --git a/src/OpenFontFormatWriter.vala b/src/OpenFontFormatWriter.valaindex 0f7da48..71e2350 100644--- a/src/OpenFontFormatWriter.vala+++ b/src/OpenFontFormatWriter.vala@@ -102,6 +102,15 @@ class OtfInputStream : Object  { 	public uint8 read_byte () throws Error {
 		return din.read_byte ();
 	}
+	
+	public void close () {
+		try {
+			fin.close ();
+			din.close ();
+		} catch (GLib.IOError e) {
+			warning (e.message);
+		}
+	}
 }
 
 class FontData : Object {
diff --git a/src/Preview.vala b/src/Preview.valaindex 0345ef5..39f5da8 100644--- a/src/Preview.vala+++ b/src/Preview.vala@@ -19,7 +19,7 @@ using WebKit;  namespace Supplement { -class Preview : FontDisplay {	+public class Preview : FontDisplay {	 	 	public Preview () { 	}@@ -35,7 +35,7 @@ class Preview : FontDisplay { 	public override void selected_canvas () { 	} -	public override string get_uri () {+	public File get_html_file () { 		Font font = Supplement.get_current_font (); 		string path = @"$(font.get_name ()).html"; 		File dir = font.get_folder ();@@ -45,7 +45,11 @@ class Preview : FontDisplay { 			ExportTool.generate_html_document ((!)file.get_path (), font);				 		} 		-		return path_to_uri ((!)file.get_path ());+		return file;	+	}++	public override string get_uri () {+		return path_to_uri ((!) get_html_file ().get_path ()); 	} } }diff --git a/src/Supplement.vala b/src/Supplement.valaindex fd11f99..fe723ff 100644--- a/src/Supplement.vala+++ b/src/Supplement.vala@@ -116,6 +116,17 @@ public class Supplement { 		current_font = new Font ();
 	}
 
+	public static File get_preview_directory () {
+		File settings = get_settings_directory ();
+		File backup = settings.get_child ("preview");
+		
+		if (!backup.query_exists ()) {
+			DirUtils.create ((!) backup.get_path (), 0xFFFFFF);
+		}
+			
+		return backup;
+	}
+
 	internal static File get_thumbnail_directory () {
 		File thumbnails = get_settings_directory ().get_child ("thumbnails");
 		
diff --git a/win32/birdfont.ico b/win32/birdfont.icoindex 0667a1b..7f0549f 100644Binary files a/win32/birdfont.ico and b/win32/birdfont.ico differ

Contact

Email: johan.mattsson.m@gmail.com
Mastodon: typo.social/@birdfont
GitHub: johanmattssonm
LinkedIn: johan-mattsson-2ab324112