Clone in a terminal:
Commit e45111c
Johan Mattsson - 2014-10-19T03:17:31+00:00
e45111c88fe3eec01f8d23c529327be466ebbee5johan.mattsson.m@gmail.com

Compile the Xml parser (libbirdxml) with posixvala

Changed files (13)

Diff

diff --git a/README b/READMEindex b13e19a..e8ed4a3 100644--- a/README+++ b/README@@ -20,7 +20,6 @@ valac libgee-dev
 libglib2.0-dev 
 libgtk2.0-dev 
-libxml2-dev 
 libwebkitgtk-dev
 unicode-data (unicode character database)
 
diff --git a/configure b/configureindex e9dfbbc..aa63647 100755--- a/configure+++ b/configure@@ -28,7 +28,7 @@ def test_program_version (program, a, b, c): 	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 @@ def test_library_version (lib): 	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 @@ def configure (gtk, libbgee): 				'gio-2.0',  				'glib-2.0',  				'gtk+-3.0',-				'libxml-2.0',  				'webkitgtk-3.0',  				'libsoup-2.4', 				'libnotify'@@ -70,7 +77,6 @@ def configure (gtk, libbgee): 				'gdk-pixbuf-2.0', 				'gio-2.0',  				'glib-2.0', -				'libxml-2.0',  				] 	 @@ -106,6 +112,7 @@ parser.add_option("-d", "--dest", dest="dest", help="Install to this directory", 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,7 +128,9 @@ if options.gtk == "False": 	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.pyindex b94d619..2b60c64 100644--- a/dodo.py+++ b/dodo.py@@ -52,8 +52,13 @@ LIBS = [     '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 ():diff --git a/libbirdfont/Allocation.vala b/libbirdfont/Allocation.valaindex 3327d20..e78d09c 100644--- a/libbirdfont/Allocation.vala+++ b/libbirdfont/Allocation.vala@@ -20,6 +20,16 @@ public class WidgetAllocation : GLib.Object { 	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 (); 		w.x = x;diff --git a/libbirdfont/DrawingTools.vala b/libbirdfont/DrawingTools.valaindex b5cf58b..851ea7b 100644--- a/libbirdfont/DrawingTools.vala+++ b/libbirdfont/DrawingTools.vala@@ -783,6 +783,12 @@ public class DrawingTools : ToolCollection  { 		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 ()) {diff --git a/libbirdfont/KerningDisplay.vala b/libbirdfont/KerningDisplay.valaindex 6ea6c58..4394887 100644--- a/libbirdfont/KerningDisplay.vala+++ b/libbirdfont/KerningDisplay.vala@@ -38,6 +38,8 @@ public class KerningDisplay : FontDisplay { 	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 @@ public class KerningDisplay : FontDisplay { 	} 	 	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 @@ public class KerningDisplay : FontDisplay { 		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 @@ public class KerningDisplay : FontDisplay { 					 					w = glyph.get_width (); 				}-+				 				// handle 				if (first_row && (active_handle == i || selected_handle == i)) { 					x2 = x + kern / 2.0;@@ -290,7 +291,7 @@ public class KerningDisplay : FontDisplay { 		GlyphRange? gr_left, gr_right; 		int row_index = 0; 		-		font = BirdFont.get_current_font ();+		font = current_font;  		font.touch (); @@ -369,7 +370,7 @@ public class KerningDisplay : FontDisplay { 		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 @@ public class KerningDisplay : FontDisplay { 		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 @@ public class KerningDisplay : FontDisplay { 	}  	/** 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 @@ public class KerningDisplay : FontDisplay { 		 		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 @@ public class KerningDisplay : FontDisplay { 		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 class KerningDisplay : FontDisplay { 	} 	 	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 @@ public class KerningDisplay : FontDisplay { 			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 class KerningDisplay : FontDisplay { 	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;diff --git a/libbirdfont/OpenFontFormat/HmtxTable.vala b/libbirdfont/OpenFontFormat/HmtxTable.valaindex d4ca457..2402b07 100644--- a/libbirdfont/OpenFontFormat/HmtxTable.vala+++ b/libbirdfont/OpenFontFormat/HmtxTable.vala@@ -106,9 +106,7 @@ public class HmtxTable : OtfTable { 		int16 right_guide; 		 		double xmin;-		double ymin; 		double xmax;-		double ymax; 		int i; 		 		Glyph g;diff --git a/libbirdxml/Attribute.vala b/libbirdxml/Attribute.valaindex ced801d..e0fac1c 100644--- a/libbirdxml/Attribute.vala+++ b/libbirdxml/Attribute.vala@@ -16,11 +16,15 @@ namespace Bird { /**   * 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;@@ -34,6 +38,21 @@ public class Attribute : GLib.Object { 		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 ();+		}+	}+	 	/**  	 * @return name space part for this attribute. 	 */@@ -54,6 +73,8 @@ public class Attribute : GLib.Object { 	public string get_content () { 		return content; 	}+	+	private extern void free (); }  }diff --git a/libbirdxml/Attributes.vala b/libbirdxml/Attributes.valaindex ea99b83..f711ecf 100644--- a/libbirdxml/Attributes.vala+++ b/libbirdxml/Attributes.vala@@ -16,9 +16,12 @@ namespace Bird { /**   * 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;@@ -27,10 +30,28 @@ public class Attributes : GLib.Object { 	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,14 +70,33 @@ public class Attributes : GLib.Object { 		}  		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 (); }  }diff --git a/libbirdxml/Tag.vala b/libbirdxml/Tag.valaindex d03b89f..2822e86 100644--- a/libbirdxml/Tag.vala+++ b/libbirdxml/Tag.vala@@ -17,24 +17,30 @@ namespace Bird { /**  * 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;@@ -47,6 +53,21 @@ public class Tag : GLib.Object { 		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 ();+		}+	} 	 	/**  	 * Get tag attributes for this tag. @@ -157,7 +178,7 @@ public class Tag : GLib.Object {  				if (separator < 0) { 					error = true;-					warning ("Expecting a separator.");+					warn ("Expecting a separator."); 					return new Tag.empty (); 				} 				@@ -182,7 +203,7 @@ public class Tag : GLib.Object { 					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 @@ public class Tag : GLib.Object { 		} 		 		error = true;-		warning (@"No closing tag for $(name).");+		warn (@"No closing tag for $(name)."); 		return -1; 	} 	@@ -302,7 +323,7 @@ public class Tag : GLib.Object { 			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 @@ public class Tag : GLib.Object { 				} 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 @@ public class Tag : GLib.Object { 				} 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 @@ public class Tag : GLib.Object { 			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 @@ public class Tag : GLib.Object { 		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,13 +417,38 @@ public class Tag : GLib.Object { 		}  		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 (); }  }diff --git a/libbirdxml/Xml.vala b/libbirdxml/Xml.valaindex 0667169..ca62416 100644--- a/libbirdxml/Xml.vala+++ b/libbirdxml/Xml.vala@@ -17,6 +17,10 @@  */ namespace Bird { +/** Log levels */+internal const int NONE = 0;+internal const int WARNINGS = 1;+ /**   * XML parser  * @@ -64,11 +68,13 @@ namespace Bird {  * }}}  *   */-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 class XmlParser : GLib.Object { 	 */ 	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 @@ public class XmlParser : GLib.Object { 	 * @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,6 +193,15 @@ public class XmlParser : GLib.Object { 		 		return -1; 	}++	/** Print a warning message. */+	public static void warning (string message) {+		print ("XML Parser: "); +		print (message);+		print ("\n");+	}+	+	private extern void free (); }  }diff --git a/scripts/bavala.py b/scripts/bavala.pyindex 1328003..05b3592 100644--- a/scripts/bavala.py+++ b/scripts/bavala.py@@ -24,6 +24,7 @@ from os.path import join from doit.action import CmdAction import config import fnmatch+import subprocess  def cmd(name, *args):     """create string for command line"""@@ -129,7 +130,16 @@ class Vala(object):     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 @@ class Vala(object): 			        + ' ' + 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]@@ -203,3 +221,4 @@ class Vala(object):   +diff --git a/scripts/configfile.py b/scripts/configfile.pyindex b4f1003..6330daf 100755--- a/scripts/configfile.py+++ b/scripts/configfile.py@@ -39,10 +39,13 @@ def write_config (prefix):  	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")++	

Contact

Email: johan.mattsson.m@gmail.com
Mastodon: typo.social/@birdfont
GitHub: johanmattssonm
LinkedIn: johan-mattsson-2ab324112