The Birdfont Source Code


All Repositories / birdfont.git / commit – RSS feed

Save stylistic alternatives to bf fonts and make gsub features optional

These changes was commited to the Birdfont repository Sun, 27 Sep 2015 17:24:22 +0000.

Contributing

Send patches or pull requests to johan.mattsson.m@gmail.com.
Clone this repository: git clone https://github.com/johanmattssonm/birdfont.git
author Johan Mattsson <johan.mattsson.m@gmail.com>
Sun, 27 Sep 2015 17:24:22 +0000 (19:24 +0200)
committer Johan Mattsson <johan.mattsson.m@gmail.com>
Sun, 27 Sep 2015 17:24:22 +0000 (19:24 +0200)
commit b324bbf40db8d588b88fbec4071498a626fb8606
tree 8d294328038ad3c7d04a72b42c8e6955bec50573
parent d7653df4d75962a8b0f576d9637f13f0a1096268
Save stylistic alternatives to bf fonts and make gsub features optional

libbirdfont/BirdFontFile.vala
libbirdfont/BirdFontPart.vala
libbirdfont/ExportTool.vala
libbirdfont/Font.vala
libbirdfont/OpenFontFormat/Alternate.vala
libbirdfont/OpenFontFormat/AlternateFeature.vala
libbirdfont/OpenFontFormat/GsubTable.vala
libbirdfont/OverviewTools.vala
--- a/libbirdfont/BirdFontFile.vala +++ b/libbirdfont/BirdFontFile.vala @@ -176,6 +176,7 @@ os.put_string ("\n"); write_spacing_classes (os); + write_alternates (os); write_kerning (os); write_closing_root_tag (os); @@ -187,6 +188,18 @@ } 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 { @@ -683,7 +696,7 @@ 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 (); } @@ -806,10 +819,31 @@ 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) {
--- a/libbirdfont/BirdFontPart.vala +++ b/libbirdfont/BirdFontPart.vala @@ -136,6 +136,12 @@ os = create_file ("ligatures.bfp"); bf.write_root_tag (os); 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 ();
--- a/libbirdfont/ExportTool.vala +++ b/libbirdfont/ExportTool.vala @@ -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 @@ 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 @@ </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>
--- a/libbirdfont/Font.vala +++ b/libbirdfont/Font.vala @@ -186,9 +186,9 @@ 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 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 () {
--- a/libbirdfont/OpenFontFormat/Alternate.vala +++ b/libbirdfont/OpenFontFormat/Alternate.vala @@ -16,22 +16,22 @@ 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++;
--- a/libbirdfont/OpenFontFormat/AlternateFeature.vala +++ b/libbirdfont/OpenFontFormat/AlternateFeature.vala @@ -35,7 +35,7 @@ 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 @@ // 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 @@ // 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 @@ 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)); }
--- a/libbirdfont/OpenFontFormat/GsubTable.vala +++ b/libbirdfont/OpenFontFormat/GsubTable.vala @@ -39,7 +39,7 @@ 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 @@ // 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
--- a/libbirdfont/OverviewTools.vala +++ b/libbirdfont/OverviewTools.vala @@ -166,7 +166,7 @@ font = BirdFont.get_current_font (); - if (alternate_name == "") { + if (alternate_name == "" || gc.is_unassigned ()) { return; }