Clone in a terminal:
Commit c5daea0
Johan Mattsson - 2018-11-05T14:07:34+00:00
c5daea0a7e72a8ef333e0d8368d83203717218d4johan.mattsson.m@gmail.com

Prevew template

Changed files (2)

Diff

diff --git a/libbirdfont/BirdFont.vala b/libbirdfont/BirdFont.valaindex 979e0a5..c4cce11 100644--- a/libbirdfont/BirdFont.vala+++ b/libbirdfont/BirdFont.vala@@ -258,7 +258,9 @@ public class BirdFont { 		if (has_argument ("--codepages")) { 			codepage_bits = new CodePageBits (); 			codepage_bits.generate_codepage_database ();-		}		+		}+		+		ExportTool.generate_html_template (); 	}  	public static bool has_logging () {diff --git a/libbirdfont/ExportTool.vala b/libbirdfont/ExportTool.valaindex c473d52..d9ba7a8 100644--- a/libbirdfont/ExportTool.vala+++ b/libbirdfont/ExportTool.vala@@ -232,17 +232,18 @@ public class ExportTool : GLib.Object { 		fc.add_extension ("svg"); 		MainWindow.file_chooser (t_("Save"), fc, FileChooser.SAVE); 	}-	-	public static void generate_html_document (string html_file, Font font) {-		File file = File.new_for_path (html_file);-		DataOutputStream os;-		string name; -#if MAC -		name = ExportSettings.get_file_name_mac (font);-#else-		name = ExportSettings.get_file_name (font);-#endif+	public static void generate_html_template () {+		File config_dir = BirdFont.get_settings_directory ();+		File file = get_child (config_dir, "preview.html");+		string name = "_NAME_";+		DataOutputStream os;+		+		if (file.query_exists ()) {+			printd("Preview template exists.\n");+			return;+		}+		 		try { 			os = new DataOutputStream (file.create(FileCreateFlags.REPLACE_DESTINATION)); @@ -273,6 +274,13 @@ os.put_string (  	os.put_string (""" 		@font-face {+			font-family: '"""); os.put_string (@"$(name)");              os.put_string ("""OTF';+			src: url('""");     os.put_string (@"$(name).otf"); os.put_string ("""') format('opentype');+		} +		""");+		+	os.put_string ("""+		@font-face { 			font-family: '"""); os.put_string (@"$(name)");              os.put_string ("""TTF'; 			src: url('""");     os.put_string (@"$(name).ttf"); os.put_string ("""') format('truetype'); 		} @@ -329,6 +337,10 @@ os.put_string (  			os.put_string (", '"); 			os.put_string (@"$(name)");+			os.put_string ("OTF'");+			+			os.put_string (", '");+			os.put_string (@"$(name)"); 			os.put_string ("TTF'"); 			 			os.put_string (", '");@@ -424,15 +436,8 @@ os.put_string ( </div>  <div>-	<h3 class="big"></h3>-	<p class="big">OTF features, like swashes alternates &amp; </span> small caps, can be added -		to the font.</span>-	</p>-</div>--<div> 	<h4 class="smaller">Headline 16pt</h4>-	<p class="smaller">Ett litet stycke svalhjärta.</p>	+	<p class="smaller">The quick brown fox jumps over the lazy dog</p>	 </div>  <div>@@ -448,8 +453,42 @@ os.put_string (  		} catch (GLib.Error e) { 			warning (e.message);+		}		+	}+	+	public static void generate_html_document (string html_file, Font font) {+		File config_dir = BirdFont.get_settings_directory ();+		File template = get_child (config_dir, "preview.html");+	+		if (!template.query_exists ()) {+			generate_html_template ();+			get_child (config_dir, "preview.html");+		}+		+		if (!template.query_exists ()) {+			warning ("Preview template does not exists.");+			return;+		}+		+		string html_data;+		FileUtils.get_contents ((!) template.get_path (), out html_data);+		+		string name;+#if MAC +		name = ExportSettings.get_file_name_mac (font);+#else+		name = ExportSettings.get_file_name (font);+#endif++		html_data = html_data.replace ("_NAME_", name);++		try {+			FileUtils.set_contents (html_file, html_data);+		} catch (FileError e) {+			warning (e.message); 		} 	}+	  	public static string get_export_folder () { 		Font font = BirdFont.get_current_font ();

Contact

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