Commit 6bf3e32
A warning message about incompatible format changes
Changed files (3)
modifiedlibbirdfont/BirdFontFile.valamodifiedlibbirdfont/Font.valamodifiedlibbirdfont/LoadCallback.vala
Diff
@@ -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;@@ -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; }@@ -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 () {