The Birdfont Source Code


All Repositories / birdfont.git / blob – RSS feed

Ligature.vala in libbirdfont/OpenFontFormat

This file is a part of the Birdfont project.

Contributing

Send patches or pull requests to johan.mattsson.m@gmail.com.
Clone this repository: git clone https://github.com/johanmattssonm/birdfont.git

Revisions

View the latest version of libbirdfont/OpenFontFormat/Ligature.vala.
Cache overview items
1 /* 2 Copyright (C) 2014 Johan Mattsson 3 4 This library is free software; you can redistribute it and/or modify 5 it under the terms of the GNU Lesser General Public License as 6 published by the Free Software Foundation; either version 3 of the 7 License, or (at your option) any later version. 8 9 This library is distributed in the hope that it will be useful, but 10 WITHOUT ANY WARRANTY; without even the implied warranty of 11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 Lesser General Public License for more details. 13 */ 14 15 namespace BirdFont { 16 17 public class Ligature : GLib.Object { 18 public string ligature = ""; 19 public string substitution = ""; 20 21 public Ligature (string ligature, string substitution = "") { 22 this.ligature = ligature; 23 this.substitution = substitution; 24 } 25 26 public unichar get_first_char () { 27 unichar first; 28 int index = 0; 29 30 get_coverage (substitution).get_next_char (ref index, out first); 31 32 return first; 33 } 34 35 public static string get_coverage (string ligatures) { 36 string[] sp; 37 unichar first; 38 int index = 0; 39 string characters = ligatures; 40 41 if (characters.has_prefix ("U+") || characters.has_prefix ("u+")) { 42 sp = characters.split (" "); 43 return_val_if_fail (sp.length > 0, ""); 44 characters = (!) Font.to_unichar (sp[0]).to_string (); 45 } 46 sp = characters.split (" "); 47 48 if (sp.length == 0) { 49 return ""; 50 } 51 52 if (sp[0] == "space") { 53 sp[0] = " "; 54 } 55 56 sp[0].get_next_char (ref index, out first); 57 58 return (!) first.to_string (); 59 } 60 61 public void set_ligature () { 62 TextListener listener; 63 64 listener = new TextListener (t_("Ligature"), ligature, t_("Set")); 65 66 listener.signal_text_input.connect ((text) => { 67 ligature = text; 68 }); 69 70 listener.signal_submit.connect (() => { 71 TabContent.hide_text_input (); 72 MainWindow.get_ligature_display ().update_rows (); 73 }); 74 75 TabContent.show_text_input (listener); 76 } 77 78 public void set_substitution () { 79 TextListener listener; 80 81 listener = new TextListener (t_("Text"), substitution, t_("Set")); 82 83 listener.signal_text_input.connect ((text) => { 84 Font f = BirdFont.get_current_font (); 85 Ligatures l = f.get_ligatures (); 86 substitution = text; 87 l.sort_ligatures (); 88 }); 89 90 listener.signal_submit.connect (() => { 91 TabContent.hide_text_input (); 92 MainWindow.get_ligature_display ().update_rows (); 93 }); 94 95 TabContent.show_text_input (listener); 96 } 97 } 98 99 } 100