The Birdfont Source Code


All Repositories / birdfont.git / commitdiff – RSS feed

Compile the Xml parser (libbirdxml) with posixvala

These changes was commited to the Birdfont repository Sun, 19 Oct 2014 03:16:46 +0000.

Contributing

Send patches or pull requests to johan.mattsson.m@gmail.com.
Clone this repository: git clone https://github.com/johanmattssonm/birdfont.git
[Sun, 19 Oct 2014 03:16:46 +0000]

Updated Files

README
configure
dodo.py
libbirdfont/Allocation.vala
libbirdfont/DrawingTools.vala
libbirdfont/KerningDisplay.vala
libbirdfont/OpenFontFormat/HmtxTable.vala
libbirdxml/Attribute.vala
libbirdxml/Attributes.vala
libbirdxml/Tag.vala
libbirdxml/Xml.vala
scripts/bavala.py
scripts/configfile.py
diff --git a/README b/README
--- a/README +++ b/README @@ -20,7 +20,6 @@ libgee-dev libglib2.0-dev libgtk2.0-dev - libxml2-dev libwebkitgtk-dev unicode-data (unicode character database)
--- a/configure +++ b/configure @@ -28,7 +28,7 @@ if not process.returncode == 0: print (FAIL + "Not found" + ENDC) exit (1) - print ("Found version " + v) + print ("Found " + v) o = v.split (" "); for s in o: @@ -46,7 +46,15 @@ process.communicate()[0] return process.returncode == 0 - def configure (gtk, libbgee): + def has_posixvala (): + posixvala = test_library_version ('posixvala') + if not posixvala: + print (OKGREEN + "Posix profile disable Glib will be used." + ENDC) + return "False" + + return "True" + + def configure (gtk, libbgee, posixvala): global gee if not test_program_version ("valac", 0, 16, 0): @@ -60,7 +68,6 @@ 'gio-2.0', 'glib-2.0', 'gtk+-3.0', - 'libxml-2.0', 'webkitgtk-3.0', 'libsoup-2.4', 'libnotify' @@ -70,7 +77,6 @@ 'gdk-pixbuf-2.0', 'gio-2.0', 'glib-2.0', - 'libxml-2.0', ] @@ -106,6 +112,7 @@ parser.add_option("-c", "--cc", dest="cc", help="C compiler", metavar="CC") parser.add_option("-g", "--gtk", dest="gtk", help="Build Gtk version, default is True", metavar="GTK") parser.add_option("-e", "--gee", dest="gee", help="Version of libgee", metavar="GEE") + parser.add_option("-x", "--posix", dest="posix", help="Use posixvala", metavar="POSIX") (options, args) = parser.parse_args() @@ -121,8 +128,10 @@ options.gtk = False if not options.gee: options.gee = "Any" + if not options.posix: + options.posix = has_posixvala () - configure (options.gtk, options.gee) + configure (options.gtk, options.gee, options.posix) configfile.write_config (options.prefix) - configfile.write_compile_parameters (options.prefix, options.dest, options.cc, gee) + configfile.write_compile_parameters (options.prefix, options.dest, options.cc, gee, options.posix)
diff --git a/dodo.py b/dodo.py
--- a/dodo.py +++ b/dodo.py @@ -52,8 +52,13 @@ 'libnotify' ] - LIBBIRD_XML_LIBS = [ - 'glib-2.0' + if not config.POSIXVALA: + LIBBIRD_XML_LIBS = [ + 'glib-2.0' + ] + else: + LIBBIRD_XML_LIBS = [ + 'posixvala' ] def task_build ():
--- a/libbirdfont/Allocation.vala +++ b/libbirdfont/Allocation.vala @@ -19,6 +19,16 @@ public int height = 0; public int x = 0; public int y = 0; + + public WidgetAllocation () { + } + + public WidgetAllocation.for_area (int x, int y, int width, int height) { + this.x = x; + this.y = y; + this.width = width; + this.height = height; + } public WidgetAllocation copy () { WidgetAllocation w = new WidgetAllocation ();
--- a/libbirdfont/DrawingTools.vala +++ b/libbirdfont/DrawingTools.vala @@ -783,6 +783,12 @@ characterset_tools.add_tool (avalilable_characters); if (BirdFont.has_argument ("--test")) { + Tool text_rendering = new Tool ("text_rendering"); + text_rendering.select_action.connect((self) => { + TextArea.test (); + }); + test_tools.add_tool (text_rendering); + Tool test_case = new Tool ("test_case"); test_case.select_action.connect((self) => { if (self.is_selected ()) {
--- a/libbirdfont/KerningDisplay.vala +++ b/libbirdfont/KerningDisplay.vala @@ -38,6 +38,8 @@ Gee.ArrayList<UndoItem> undo_items; Gee.ArrayList<UndoItem> redo_items; bool first_update = true; + + Font current_font = new Font (); public KerningDisplay () { GlyphSequence w = new GlyphSequence (); @@ -93,10 +95,9 @@ } double get_row_height () { - Font font = BirdFont.get_current_font (); - return font.top_limit - font.bottom_limit; + return current_font.top_limit - current_font.bottom_limit; } - + public void draw_kerning_pairs (WidgetAllocation allocation, Context cr) { Glyph glyph; double x, y, w, kern, alpha; @@ -111,7 +112,7 @@ Font font; double item_size = 1.0 / KerningTools.font_size; - font = BirdFont.get_current_font (); + font = current_font; i = 0; // bg color @@ -173,7 +174,7 @@ w = glyph.get_width (); } - + // handle if (first_row && (active_handle == i || selected_handle == i)) { x2 = x + kern / 2.0; @@ -290,7 +291,7 @@ GlyphRange? gr_left, gr_right; int row_index = 0; - font = BirdFont.get_current_font (); + font = current_font; font.touch (); @@ -369,7 +370,7 @@ Font font; GlyphRange? gr_left, gr_right; - font = BirdFont.get_current_font (); + font = current_font; font.touch (); if (!KerningTools.adjust_side_bearings) { @@ -394,7 +395,7 @@ bool has_kerning; Font font; - font = BirdFont.get_current_font (); + font = current_font; font.touch (); kern = get_kerning_for_pair (a, b, gr_left, gr_right); @@ -434,7 +435,7 @@ } /** Class based gpos kerning. */ - public double get_kerning_for_pair (string a, string b, GlyphRange? gr_left, GlyphRange? gr_right) { + public static double get_kerning_for_pair (string a, string b, GlyphRange? gr_left, GlyphRange? gr_right) { double k; GlyphRange grl, grr; try { @@ -476,12 +477,18 @@ return 0; } + + public void set_current_font (Font f) { + current_font = f; + } + public override void selected_canvas () { Glyph g; GlyphSequence w; StringBuilder s = new StringBuilder (); bool append_char = false; - Font font = BirdFont.get_current_font (); + + current_font = BirdFont.get_current_font (); KeyBindings.set_require_modifier (true); @@ -495,7 +502,7 @@ if (append_char) { w = new GlyphSequence (); row.add (w); - w.glyph.insert (0, font.get_glyph (s.str)); + w.glyph.insert (0, current_font.get_glyph (s.str)); } } @@ -504,7 +511,7 @@ } public void add_range (GlyphRange range) { - Font font = BirdFont.get_current_font (); + Font font = current_font; Glyph? glyph; glyph = font.get_glyph_by_name (range.get_char (0)); @@ -680,7 +687,7 @@ return; } - f = BirdFont.get_current_font (); + f = current_font; if (!is_modifier_key (c) && c.validate ()) { name = f.get_name_for_character (c); @@ -924,7 +931,7 @@ public UndoItem apply_undo (UndoItem ui) { KerningClasses classes = KerningClasses.get_instance (); GlyphRange glyph_range_first, glyph_range_next; - Font font = BirdFont.get_current_font (); + Font font = current_font; string l, r; UndoItem redo_state = new UndoItem ("", "", 0, false); double? k;
--- a/libbirdfont/OpenFontFormat/HmtxTable.vala +++ b/libbirdfont/OpenFontFormat/HmtxTable.vala @@ -106,9 +106,7 @@ int16 right_guide; double xmin; - double ymin; double xmax; - double ymax; int i; Glyph g;
--- a/libbirdxml/Attribute.vala +++ b/libbirdxml/Attribute.vala @@ -16,11 +16,15 @@ /** * Representation of one XML attribute. */ - public class Attribute : GLib.Object { + [Compact] + [CCode (ref_function = "bird_attribute_ref", unref_function = "bird_attribute_unref")] + public class Attribute { public string ns; public string name; public string content; + + public int refcount = 1; internal Attribute (string ns, string name, string content) { this.ns = ns; @@ -32,6 +36,21 @@ this.ns = ""; this.name = ""; this.content = ""; + } + + /** Increment the reference count. + * @return a pointer to this object + */ + public unowned Attribute @ref () { + refcount++; + return this; + } + + /** Decrement the reference count and free the object when zero object are holding references to it.*/ + public void unref () { + if (--refcount == 0) { + this.free (); + } } /** @@ -54,7 +73,9 @@ public string get_content () { return content; } + + private extern void free (); } }
--- a/libbirdxml/Attributes.vala +++ b/libbirdxml/Attributes.vala @@ -16,9 +16,12 @@ /** * Iterator for XML attributes. */ - public class Attributes : GLib.Object { + [Compact] + [CCode (ref_function = "bird_attributes_ref", unref_function = "bird_attributes_unref")] + public class Attributes { - Tag tag; + public Tag tag; + public int refcount = 1; internal Attributes (Tag t) { tag = t; @@ -26,11 +29,29 @@ public Iterator iterator () { return new Iterator (tag); + } + + /** Increment the reference count. + * @return a pointer to this object + */ + public unowned Attributes @ref () { + refcount++; + return this; + } + + /** Decrement the reference count and free the object when zero object are holding references to it.*/ + public void unref () { + if (--refcount == 0) { + this.free (); + } } + [Compact] + [CCode (ref_function = "bird_attributes_iterator_ref", unref_function = "bird_attributes_iterator_unref")] public class Iterator { - Tag tag; - Attribute? next_attribute; + public Tag tag; + public Attribute? next_attribute; + public int iterator_refcount = 1; internal Iterator (Tag t) { tag = t; @@ -49,15 +70,34 @@ } public Attribute get () { - if (unlikely (next_attribute == null)) { - warning ("No attribute is parsed yet."); + if (next_attribute == null) { + XmlParser.warning ("No attribute is parsed yet."); return new Attribute.empty (); } return (!) next_attribute; } + + /** Increment the reference count. + * @return a pointer to this object + */ + public unowned Iterator @ref () { + iterator_refcount++; + return this; + } + + /** Decrement the reference count and free the object when zero object are holding references to it.*/ + public void unref () { + if (--iterator_refcount == 0) { + this.free (); + } + } + + private extern void free (); } + + private extern void free (); } }
--- a/libbirdxml/Tag.vala +++ b/libbirdxml/Tag.vala @@ -17,24 +17,30 @@ /** * Representation of one XML tag. */ - public class Tag : GLib.Object { + [Compact] + [CCode (ref_function = "bird_tag_ref", unref_function = "bird_tag_unref")] + public class Tag { - int tag_index; - int attribute_index; + public int tag_index; + public int attribute_index; - bool has_tags; - bool has_attributes; + public bool has_tags; + public bool has_attributes; - string name; - string data; - string attributes; + public string name; + public string data; + public string attributes; - Tag? next_tag = null; - Attribute? next_attribute = null; + public Tag? next_tag = null; + public Attribute? next_attribute = null; - bool error = false; + public bool error = false; + public int log_level = WARNINGS; - internal Tag (string name, string attributes, string content) { + public int refcount = 1; + + internal Tag (string name, string attributes, string content, int log_level) { + this.log_level = log_level; this.name = name; this.data = content; this.attributes = attributes; @@ -46,6 +52,21 @@ data = ""; attributes = ""; name = ""; + } + + /** Increment the reference count. + * @return a pointer to this object + */ + public unowned Tag @ref () { + refcount++; + return this; + } + + /** Decrement the reference count and free the object when zero object are holding references to it.*/ + public void unref () { + if (--refcount == 0) { + this.free (); + } } /** @@ -157,7 +178,7 @@ if (separator < 0) { error = true; - warning ("Expecting a separator."); + warn ("Expecting a separator."); return new Tag.empty (); } @@ -182,7 +203,7 @@ data.get_next_char (ref end_tag_index, out c); } - return new Tag (name, attributes, content); + return new Tag (name, attributes, content, log_level); } } @@ -241,7 +262,7 @@ } error = true; - warning (@"No closing tag for $(name)."); + warn (@"No closing tag for $(name)."); return -1; } @@ -302,7 +323,7 @@ previous_index = index; if (!attributes.get_next_char (ref index, out c)) { error = true; - warning (@"Unexpected end of attributes in tag $(this.name)"); + warn (@"Unexpected end of attributes in tag $(this.name)"); has_attributes = false; return new Attribute.empty (); } @@ -329,7 +350,7 @@ } else { has_attributes = false; error = true; - warning (@"Expecting equal sign for attribute $(attribute_name)."); + warn (@"Expecting equal sign for attribute $(attribute_name)."); return new Attribute.empty (); } } @@ -342,7 +363,7 @@ } else { has_attributes = false; error = true; - warning (@"Expecting quote for attribute $(attribute_name)."); + warn (@"Expecting quote for attribute $(attribute_name)."); return new Attribute.empty (); } } @@ -355,7 +376,7 @@ if (!attributes.get_next_char (ref index, out c)) { has_attributes = false; error = true; - warning (@"Expecting end quote for attribute $(attribute_name)."); + warn (@"Expecting end quote for attribute $(attribute_name)."); return new Attribute.empty (); } @@ -373,9 +394,12 @@ return new Attribute (ns, attribute_name, content); } + [Compact] + [CCode (ref_function = "bird_tag_iterator_ref", unref_function = "bird_tag_iterator_unref")] public class Iterator { - Tag tag; - Tag? next_tag = null; + public Tag tag; + public Tag? next_tag = null; + public int iterator_efcount = 1; internal Iterator (Tag t) { tag = t; @@ -393,14 +417,39 @@ } public Tag get () { - if (unlikely (next_tag == null)) { - warning ("No tag is parsed yet."); + if (next_tag == null) { + XmlParser.warning ("No tag is parsed yet."); return new Tag.empty (); } return (!) next_tag; } + + /** Increment the reference count. + * @return a pointer to this object + */ + public unowned Tag.Iterator @ref () { + iterator_efcount++; + return this; + } + + /** Decrement the reference count and free the object when zero object are holding references to it.*/ + public void unref () { + if (--iterator_efcount == 0) { + this.free (); + } + } + + private extern void free (); } + + internal void warn (string message) { + if (log_level == WARNINGS) { + XmlParser.warning (message); + } + } + + private extern void free (); } }
--- a/libbirdxml/Xml.vala +++ b/libbirdxml/Xml.vala @@ -16,6 +16,10 @@ * Tools originally written for the BirdFont project. */ namespace Bird { + + /** Log levels */ + internal const int NONE = 0; + internal const int WARNINGS = 1; /** * XML parser @@ -64,11 +68,13 @@ * }}} * */ - public class XmlParser : GLib.Object { - - Tag root; - string data; - bool error; + [Compact] + [CCode (ref_function = "bird_xml_parser_ref", unref_function = "bird_xml_parser_unref")] + public class XmlParser { + public Tag root; + public string data; + public bool error; + public int refcount = 1; /** * Create a new xml parser. @@ -76,24 +82,38 @@ */ public XmlParser (string data) { this.data = data; - reparse (); + reparse (NONE); + } + + /** Increment the reference count. + * @return a pointer to this object + */ + public unowned XmlParser @ref () { + refcount++; + return this; } + /** Decrement the reference count and free the object when zero object are holding references to it.*/ + public void unref () { + if (--refcount == 0) { + this.free (); + } + } + /** * Determine if the document can be parsed. * @return true if the xml document is valid xml. */ public bool validate () { - reparse (); - Tag root = get_root_tag (); - + reparse (NONE); + if (error) { return false; } validate_tags (root); - reparse (); + reparse (NONE); return !error; } @@ -122,26 +142,30 @@ * @return the root tag. */ public Tag get_root_tag () { - reparse (); + reparse (WARNINGS); return root; } /** * Reset the parser and start from the beginning of the XML document. */ - internal void reparse () { + internal void reparse (int log_level) { int root_index; Tag container; + string content; error = false; root_index = find_root_tag (); if (root_index == -1) { - warning ("No root tag found."); + if (log_level == WARNINGS) { + XmlParser.warning ("No root tag found."); + } error = true; root = new Tag.empty (); } else { - container = new Tag ("", "", data.substring (root_index)); + content = data.substring (root_index); + container = new Tag ("", "", content, log_level); root = container.get_next_tag (); } } @@ -169,7 +193,16 @@ return -1; } + + /** Print a warning message. */ + public static void warning (string message) { + print ("XML Parser: "); + print (message); + print ("\n"); + } + + private extern void free (); } }
--- a/scripts/bavala.py +++ b/scripts/bavala.py @@ -24,6 +24,7 @@ from doit.action import CmdAction import config import fnmatch + import subprocess def cmd(name, *args): """create string for command line""" @@ -129,7 +130,16 @@ def gen_o(self, opts): """compile C files to obj `.o` """ def compile_cmd(conf, opts, libs, pos): - flags = [conf[l].strip() for l in libs] + flags = [] + for l in libs: + process = subprocess.Popen ('pkg-config --cflags ' + l, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + cflags = process.stdout.readline() + process.communicate()[0] + if not process.returncode == 0: + print ( "Library not found: " + l) + exit (1) + flags += [cflags.strip ()] + return cmd(config.CC, opts, flags, pos) for cc, obj in zip(self.cc, self.obj): @@ -154,7 +164,15 @@ + ' ' + obj_glob + ' -o ' + self.so ] - flags = [conf[l].strip() for l in libs] + flags = [] + for l in libs: + process = subprocess.Popen ('pkg-config --cflags ' + l, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + cflags = process.stdout.readline() + process.communicate()[0] + if not process.returncode == 0: + print ( "Library not found: " + l) + exit (1) + flags += [cflags.strip ()] if generated_libs: flags += [generated_libs] @@ -200,7 +218,8 @@ 'file_dep': self.cc + [ d.so_link for d in self.vala_deps ], 'targets': [ target ], } +
--- a/scripts/configfile.py +++ b/scripts/configfile.py @@ -39,11 +39,14 @@ f.write("}") - def write_compile_parameters (prefix, dest, cc, gee): + def write_compile_parameters (prefix, dest, cc, gee, posixvala): f = open('./scripts/config.py', 'w+') f.write("#!/usr/bin/python\n") f.write("PREFIX = \"" + prefix + "\"\n") f.write("DEST = \"" + dest + "\"\n") f.write("CC = \"" + cc + "\"\n") f.write("GEE = \"" + gee + "\"\n") + f.write("POSIXVALA = \"" + posixvala + "\"\n") + +