The Birdfont Source Code


All Repositories / birdfont.git / commit – RSS feed

Add ligatures to the bf file format.

These changes was commited to the Birdfont repository Fri, 03 Oct 2014 20:37:35 +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>
Fri, 03 Oct 2014 20:37:35 +0000 (22:37 +0200)
committer Johan Mattsson <johan.mattsson.m@gmail.com>
Fri, 03 Oct 2014 20:37:35 +0000 (22:37 +0200)
commit 9754e01cc240e24576c9f4f14e640bd1f5ae10ce
tree 3c8b8d39ffaea5525219f99d623d590860ad45f9
parent 57eace320bec900d77ad3ecced856d6e75c3ca72
Add ligatures to the bf file format.

libbirdfont/BirdFontFile.vala
libbirdfont/BirdFontPart.vala
--- a/libbirdfont/BirdFontFile.vala +++ b/libbirdfont/BirdFontFile.vala @@ -137,13 +137,8 @@ os.put_string (@"</images>\n"); os.put_string ("\n"); } - - // FIXME: no need to iterate over all glyphs twise + font.glyph_cache.for_each ((gc) => { - if (is_null (gc)) { - warning ("No glyph collection"); - } - try { write_glyph_collection (gc, os); } catch (GLib.Error e) { @@ -152,6 +147,9 @@ TooltipArea.show_text (t_("Saving")); }); + + os.put_string ("\n"); + write_ligatures (os); font.glyph_cache.for_each ((gc) => { BackgroundImage bg; @@ -663,7 +661,11 @@ if (t.get_name () == "spacing") { parse_spacing_class (t); } - + + if (t.get_name () == "ligature") { + parse_ligature (t); + } + TooltipArea.show_text (t_("Loading XML data.")); } @@ -681,6 +683,12 @@ parse_background_image (child); } } + } + + public static string serialize_attribute (string s) { + string n = s.replace ("\"", "quote"); + n = n.replace ("&", "ampersand"); + return n; } public static string unserialize (string s) { @@ -1347,8 +1355,41 @@ } img.set_position (img.img_x, img.img_y); + } + + public void write_ligatures (DataOutputStream os) { + Ligatures ligatures = font.get_ligatures (); + + try { + ligatures.get_ligatures ((subst, liga) => { + string l = serialize_attribute (liga); + string s = serialize_attribute (subst); + os.put_string ("<ligature sequence=\"$(s)\" replacement=\"$(l)\"/>\n"); + }); + } catch (GLib.Error e) { + warning (e.message); + } + } + + public void parse_ligature (Tag t) { + string sequence = ""; + string ligature = ""; + Ligatures ligatures; + + foreach (Attribute a in t.get_attributes ()) { + if (a.get_name () == "sequence") { + sequence = a.get_content (); + } + + if (a.get_name () == "replacement") { + ligature = a.get_content (); + } + } + + ligatures = font.get_ligatures (); + ligatures.add_ligature (sequence, ligature); } } }
--- a/libbirdfont/BirdFontPart.vala +++ b/libbirdfont/BirdFontPart.vala @@ -199,6 +199,12 @@ bf.write_closing_root_tag (os); os.close (); + os = create_file ("ligatures.bfp"); + bf.write_root_tag (os); + bf.write_ligatures (os); + bf.write_closing_root_tag (os); + os.close (); + font.glyph_cache.for_each ((gc) => { try { string selected_file_name;