Clone in a terminal:
Commit 6bf3e32
Johan Mattsson - 2015-06-04T06:24:45+00:00
6bf3e32f215fd9a8f92071c1c3b1e1d30d2e7382johan.mattsson.m@gmail.com

A warning message about incompatible format changes

Changed files (3)

Diff

diff --git a/libbirdfont/BirdFontFile.vala b/libbirdfont/BirdFontFile.valaindex a56ac58..aee159d 100644--- a/libbirdfont/BirdFontFile.vala+++ b/libbirdfont/BirdFontFile.vala@@ -22,7 +22,12 @@ namespace BirdFont { class BirdFontFile : GLib.Object { 	 	Font font;+	public static const int FORMAT_MAJOR = 2;+	public static const int FORMAT_MINOR = 0; 	+	public static const int MIN_FORMAT_MAJOR = 0;+	public static const int MIN_FORMAT_MINOR = 0;+		 	public BirdFontFile (Font f) { 		font = f; 	}@@ -241,7 +246,7 @@ class BirdFontFile : GLib.Object { 		os.put_string ("""<?xml version="1.0" encoding="utf-8" standalone="yes"?>"""); 		os.put_string ("\n"); 		os.put_string ("<font>\n");-		os.put_string ("<format>1.0</format>\n");+		os.put_string (@"\t<format>$FORMAT_MAJOR.$FORMAT_MINOR</format>\n"); 	} 	 	public void write_closing_root_tag (DataOutputStream os) throws GLib.Error {@@ -660,7 +665,12 @@ class BirdFontFile : GLib.Object { 			if (t.get_name () == "backup") { 				font.font_file = t.get_content (); 			}-			++			// file format version+			if (t.get_name () == "format") {+				parse_format (t);+			}+						 			// glyph format 			if (t.get_name () == "collection") { 				parse_glyph_collection (t);@@ -747,7 +757,19 @@ class BirdFontFile : GLib.Object { 		 		return true; 	}+	+	public void parse_format (Tag tag) {+		string[] v = tag.get_content ().split ("."); 		+		if (v.length != 2) {+			warning ("Bad format string.");+			return;+		}+		+		font.format_major = int.parse (v[0]);+		font.format_major = int.parse (v[1]);+	}+	 	public void parse_images (Tag tag) { 		BackgroundImage? new_img; 		BackgroundImage img;diff --git a/libbirdfont/Font.vala b/libbirdfont/Font.valaindex fd32475..be8f99e 100644--- a/libbirdfont/Font.vala+++ b/libbirdfont/Font.vala@@ -1,5 +1,5 @@ /*-    Copyright (C) 2012, 2013, 2014 Johan Mattsson+    Copyright (C) 2012 2013 2014 2015 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 @@ -109,6 +109,9 @@ public class Font : GLib.Object { 	 	public static Font empty; 	+	public int format_major = 0;+	public int format_minor = 0;+	 	public Font () { 		KerningClasses kerning_classes; 		@@ -152,6 +155,36 @@ public class Font : GLib.Object { 		font_deleted (); 	} +	public bool has_compatible_format () {+		return !newer_format () && !older_format ();+	}++	public bool older_format () {+		if (format_major < BirdFontFile.MIN_FORMAT_MAJOR) {+			return true;+		}++		if (format_major == BirdFontFile.MIN_FORMAT_MAJOR +			&& format_minor < BirdFontFile.MIN_FORMAT_MINOR) {+			return true;+		}+		+		return false;+	}+		+	public bool newer_format () {+		if (format_major > BirdFontFile.FORMAT_MAJOR) {+			return true;+		}+		+		if (BirdFontFile.FORMAT_MAJOR == format_major +			&& format_minor > BirdFontFile.FORMAT_MINOR) {+			return true;+		}+		+		return false;+	}+ 	public static void set_default_license (string license) { 		default_license = license; 	}diff --git a/libbirdfont/LoadCallback.vala b/libbirdfont/LoadCallback.valaindex db7f96d..3afb93f 100644--- a/libbirdfont/LoadCallback.vala+++ b/libbirdfont/LoadCallback.vala@@ -20,7 +20,22 @@ public class LoadCallback : GLib.Object {  	public signal void file_loaded (); 	-	public LoadCallback () {	+	public LoadCallback () {+		file_loaded.connect (() => {+			Font f = BirdFont.get_current_font ();+			+			if (!f.has_compatible_format ()) {+				if (f.newer_format ()) {+					MainWindow.show_message (t_("This font was made with a newer version of Birdfont.")+						+ " " + t_("You need to upgrade your version of Birdfont."));+				}++				if (f.older_format ()) {+					MainWindow.show_message (t_("This font was made with an old version of Birdfont.")+						+ " " + t_("You need an older version of Birdfont to open it."));+				}+			}+		}); 	}  	public void load () {

Contact

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