Commit b324bbf
Save stylistic alternatives to bf fonts and make gsub features optional
Changed files (8)
modifiedlibbirdfont/BirdFontFile.valamodifiedlibbirdfont/BirdFontPart.valamodifiedlibbirdfont/ExportTool.valamodifiedlibbirdfont/Font.valamodifiedlibbirdfont/OpenFontFormat/Alternate.valamodifiedlibbirdfont/OpenFontFormat/AlternateFeature.valamodifiedlibbirdfont/OpenFontFormat/GsubTable.valamodifiedlibbirdfont/OverviewTools.vala
Diff
@@ -176,6 +176,7 @@ class BirdFontFile : GLib.Object { os.put_string ("\n"); write_spacing_classes (os);+ write_alternates (os); write_kerning (os); write_closing_root_tag (os); @@ -188,6 +189,18 @@ class BirdFontFile : GLib.Object { return true; }++ public void write_alternates (DataOutputStream os) throws GLib.Error {+ foreach (Alternate alternate in font.alternates) {+ string character = @"$(Font.to_hex (alternate.character))";+ + foreach (string alt in alternate.alternates) {+ os.put_string (@"<alternate ");+ os.put_string (@"character=\"$character\" ");+ os.put_string (@"alternate=\"$alt\" />\n");+ }+ }+ } public void write_images (DataOutputStream os) throws GLib.Error { string glyph_name;@@ -683,7 +696,7 @@ class BirdFontFile : GLib.Object { private bool parse_file (Tag tag) { foreach (Tag t in tag) {- // this is a backup file, but path pointing to the original file+ // this is a backup file, but with a path to the original file if (t.get_name () == "backup") { font.font_file = t.get_content (); }@@ -807,11 +820,32 @@ class BirdFontFile : GLib.Object { if (t.get_name () == "images") { parse_images (t); }++ if (t.get_name () == "alternate") {+ parse_alternate (t);+ } } return true; } + public void parse_alternate (Tag tag) {+ unichar character = '\0';+ string alt = "";+ + foreach (Attribute attribute in tag.get_attributes ()) {+ if (attribute.get_name () == "character") {+ character = Font.to_unichar (attribute.get_content ());+ }+ + if (attribute.get_name () == "alternate") {+ alt = unserialize (attribute.get_content ());+ }+ }+ + font.add_alternate (character, alt);+ }+ public void parse_format (Tag tag) { string[] v = tag.get_content ().split ("."); @@ -138,6 +138,12 @@ public class BirdFontPart : GLib.Object{ bf.write_ligatures (os); bf.write_closing_root_tag (os); os.close ();++ os = create_file ("alternates.bfp");+ bf.write_root_tag (os);+ bf.write_alternates (os);+ bf.write_closing_root_tag (os);+ os.close (); font.glyph_cache.for_each ((gc) => { try {@@ -1,5 +1,5 @@ /*- Copyright (C) 2012 2014 Johan Mattsson+ Copyright (C) 2012 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 @@ -331,6 +331,27 @@ os.put_string ( font-size: 12pt; } + span.swashes {+ -moz-font-feature-settings: "swsh";+ -ms-font-feature-settings: "swsh";+ -webkit-font-feature-settings: "swsh";+ font-feature-settings: "swsh"; + }+ + span.alternates { + -moz-font-feature-settings: "salt" 1;+ -ms-font-feature-settings: "salt" 1;+ -webkit-font-feature-settings: "salt" 1;+ font-feature-settings: "salt" 1;+ }+ + span.smallcaps {+ font-variant-caps: small-caps;+ -moz-font-feature-settings: "smcp";+ -ms-font-feature-settings: "smcp";+ -webkit-font-feature-settings: "smcp";+ font-feature-settings: "smcp";+ } </style> """); @@ -350,8 +371,14 @@ os.put_string ( </div> <div>- <h3 class="big">Handgloves & Mittoms</h3>- <p class="big">Bibliography</p>+ <h3 class="big">Optional Features</h3>+ <p class="big">+ <span class="swashes">Like swashes</span>+ <span class="alternates">alternates &</span>+ <span class="smallcaps">small caps</span> can be been added+ to the font.+ </p>+ </p> </div> @@ -186,9 +186,9 @@ public class Font : GLib.Object { font_deleted (); } - public Alternate? get_alternate (GlyphCollection gc) {+ public Alternate? get_alternate (unichar character) { foreach (Alternate a in alternates) {- if (a.glyph == gc) {+ if (a.character == character) { return a; } }@@ -198,19 +198,33 @@ public class Font : GLib.Object { public void add_new_alternate (GlyphCollection glyph, GlyphCollection alternate) {- Alternate a;- Alternate? alt = get_alternate (alternate);+ Alternate? alt = get_alternate (glyph.get_unicode_character ()); if (alt == null) {- a = new Alternate (glyph);+ a = new Alternate (glyph.get_unicode_character ()); alternates.add (a); } else { a = (!) alt; } - a.add (alternate);+ a.add (alternate.get_name ()); glyph_name.insert (alternate.get_name (), alternate);+ glyph_cache.insert (alternate.get_name (), alternate);+ }++ public void add_alternate (unichar character, string alternate) {+ Alternate a;+ Alternate? alt = get_alternate (character);+ + if (alt == null) {+ a = new Alternate (character);+ alternates.add (a);+ } else {+ a = (!) alt;+ }+ + a.add (alternate); } public bool has_compatible_format () {@@ -16,22 +16,22 @@ namespace BirdFont { public class Alternate : GLib.Object { - public GlyphCollection glyph;- public Gee.ArrayList<GlyphCollection> alternates;+ public unichar character;+ public Gee.ArrayList<string> alternates; - public Alternate (GlyphCollection glyph) {- this.glyph = glyph;- this.alternates = new Gee.ArrayList<GlyphCollection> ();+ public Alternate (unichar character) {+ this.character = character;+ this.alternates = new Gee.ArrayList<string> (); } - public void add (GlyphCollection g) {- alternates.add (g);+ public void add (string glyph_name) {+ alternates.add (glyph_name); } public void remove (GlyphCollection g) { int i = 0;- foreach (GlyphCollection a in alternates) {- if (a.get_name () == g.get_name ()) {+ foreach (string a in alternates) {+ if (a == g.get_name ()) { break; } i++;@@ -35,7 +35,7 @@ public class AlternateFeature : GLib.Object { font.alternates.sort ((a, b) => { Alternate alt1 = (Alternate) a; Alternate alt2 = (Alternate) b;- return strcmp (alt1.glyph.get_name (), alt2.glyph.get_name ());+ return strcmp ((!) alt1.character.to_string (), (!) alt2.character.to_string ()); }); fd.add_ushort (1); // format identifier@@ -48,7 +48,7 @@ public class AlternateFeature : GLib.Object { // number of alternate sets fd.add_ushort ((uint16) font.alternates.size); - + int offset = 6 + 2 * font.alternates.size; for (int i = 0; i < font.alternates.size; i++) { // offset to each alternate set@@ -60,9 +60,8 @@ public class AlternateFeature : GLib.Object { // alternates fd.add_ushort ((uint16) font.alternates.size); foreach (Alternate alternate in font.alternates) {- foreach (GlyphCollection g in alternate.alternates) {- string name = g.get_name ();- fd.add_ushort ((uint16) glyf_table.get_gid (name));+ foreach (string alt in alternate.alternates) {+ fd.add_ushort ((uint16) glyf_table.get_gid (alt)); } } @@ -70,7 +69,7 @@ public class AlternateFeature : GLib.Object { fd.add_ushort (1); // format fd.add_ushort ((uint16) font.alternates.size); // coverage array length foreach (Alternate alternate in font.alternates) {- string glyph_name = alternate.glyph.get_name ();+ string glyph_name = (!) alternate.character.to_string (); fd.add_ushort ((uint16) glyf_table.get_gid (glyph_name)); } @@ -39,7 +39,7 @@ public class GsubTable : OtfTable { if (alternate_feature.has_alternates ()) { Lookups aalt_lookup = alternate_feature.get_lookups ();- Feature aalt_feature_lookup = new Feature ("aalt", lookups);+ Feature aalt_feature_lookup = new Feature ("salt", lookups); aalt_feature_lookup.add_feature_lookup (Lookups.ALTERNATES); features.add (aalt_feature_lookup); lookups.append (aalt_lookup);@@ -84,8 +84,8 @@ public class GsubTable : OtfTable { // LangSys table fd.add_ushort (0); // reserved- fd.add_ushort (0); // required features (0xFFFF is none)- fd.add_ushort (1); // number of features+ fd.add_ushort (0xFFFF); // required features (0xFFFF is none)+ fd.add_ushort ((uint16) features.features.size); // number of features fd.add_ushort (0); // feature index // feature lookups with references to the lookup list@@ -166,7 +166,7 @@ public class OverviewTools : ToolCollection { font = BirdFont.get_current_font (); - if (alternate_name == "") {+ if (alternate_name == "" || gc.is_unassigned ()) { return; }