Clone in a terminal:
Commit d89f026
Johan Mattsson - 2012-09-09T14:55:54+00:00
d89f0267cfa7db0409faed1f1dcb42b517c79dc8johan.mattsson.m@gmail.com

set image position in cartesian coordinate system

Changed files (5)

Diff

diff --git a/src/Font.vala b/src/Font.valaindex 2a71ab3..4eafbbf 100644--- a/src/Font.vala+++ b/src/Font.vala@@ -675,15 +675,15 @@ class Font : GLib.Object { 		if (bg != null) { 			GlyphBackgroundImage background_image = (!) bg; -			double off_x = background_image.img_offset_x;-			double off_y = background_image.img_offset_y;+			double pos_x = background_image.img_x;+			double pos_y = background_image.img_y; 			 			double scale_x = background_image.img_scale_x; 			double scale_y = background_image.img_scale_y; 			 			double rotation = background_image.img_rotation; 			-			os.put_string (@"\t<background sha1=\"$(background_image.get_sha1 ())\" offset_x=\"$off_x\" offset_y=\"$off_y\" scale_x=\"$scale_x\" scale_y=\"$scale_y\" rotation=\"$rotation\"/>\n");+			os.put_string (@"\t<background sha1=\"$(background_image.get_sha1 ())\" x=\"$pos_x\" y=\"$pos_y\" scale_x=\"$scale_x\" scale_y=\"$scale_y\" rotation=\"$rotation\"/>\n"); 		} 		 		os.put_string ("</glyph>\n\n"); @@ -1220,27 +1220,28 @@ class Font : GLib.Object { 			attr_name = prop->name; 			attr_content = prop->children->content; 							-			if (attr_name == "offset_x") {-				img.img_offset_x = double.parse (attr_content);-			}--			if (attr_name == "offset_y") {-				img.img_offset_y = double.parse (attr_content);+			if (attr_name == "x") {+				img.img_x = double.parse (attr_content); 			} 			+			if (attr_name == "y") {+				img.img_y = double.parse (attr_content);+			}	+ 			if (attr_name == "scale_x") { 				img.img_scale_x = double.parse (attr_content); 			}-			+ 			if (attr_name == "scale_y") { 				img.img_scale_y = double.parse (attr_content);-			}	-			+			}+						 			if (attr_name == "rotation") { 				img.img_rotation = double.parse (attr_content); 			} 		}-				+		+		img.set_position(img.img_x, img.img_y);	 	} 	 	private void parse_point (Path p, Xml.Node* iter) {diff --git a/src/Glyph.vala b/src/Glyph.valaindex 364e648..09f4c1a 100644--- a/src/Glyph.vala+++ b/src/Glyph.vala@@ -206,12 +206,14 @@ class Glyph : FontDisplay { 	 	/** @return centrum pixel for x coordinates. */ 	public static double xc () {-		return MainWindow.get_current_glyph ().allocation.width / 2.0;+		double c = MainWindow.get_current_glyph ().allocation.width / 2.0;+		return c;	 	}  	/** @return centrum pixel for y coordinates. */ 	public static double yc () {-		return MainWindow.get_current_glyph ().allocation.height / 2.0;+		double c = MainWindow.get_current_glyph ().allocation.height / 2.0;+		return c; 	}  	/** @return 1/view_zoom */@@ -219,7 +221,6 @@ class Glyph : FontDisplay { 		return 1 / MainWindow.get_current_glyph ().view_zoom; 	} - 	public void resized (Allocation o, Allocation n) { 		double a, b, c, d; 		@@ -1407,12 +1408,6 @@ class Glyph : FontDisplay { 			((!)background_image).draw (cr, allocation, view_offset_x, view_offset_y, view_zoom); 			cmp.restore (); 		}--		cmp.save ();-		cmp.scale (view_zoom, view_zoom);-		cmp.translate (-view_offset_x, -view_offset_y);-		draw_path (cmp); // This does mess up scale (sometimes) for unknown reasons	-		cmp.restore (); 		 		cmp.save ();  		tool = MainWindow.get_toolbox ().get_current_tool ();@@ -1424,7 +1419,13 @@ class Glyph : FontDisplay { 			draw_zoom_area (cmp); 			cmp.restore (); 		}-		++		cmp.save ();+		cmp.scale (view_zoom, view_zoom);+		cmp.translate (-view_offset_x, -view_offset_y);+		draw_path (cmp); // Fixa: This does mess up scale (sometimes) for unknown reasons	+		cmp.restore ();+				 		cr.save (); 		cr.set_source_surface (ps, 0, 0); 		cr.paint ();diff --git a/src/GlyphBackgroundImage.vala b/src/GlyphBackgroundImage.valaindex dc88e7c..7356cdb 100644--- a/src/GlyphBackgroundImage.vala+++ b/src/GlyphBackgroundImage.vala@@ -22,9 +22,11 @@ using Math;  namespace Supplement { 	-class GlyphBackgroundImage {	-	public double img_offset_x = 0;-	public double img_offset_y = 0;+class GlyphBackgroundImage {+	+	public double img_x = 0;+	public double img_y = 0;+	 	public double img_scale_x = 1; 	public double img_scale_y = 1; 	public double img_rotation = 0;@@ -51,9 +53,32 @@ class GlyphBackgroundImage { 	 	public GlyphBackgroundImage (string fn) { 		path = fn;-		size_margin = (int) (Math.sqrt (Math.pow (get_img ().get_height (), 2) + Math.pow (get_img ().get_width (), 2)) + 0.5);+		+		if (fn != "") {+			size_margin = (int) (Math.sqrt (Math.pow (get_img ().get_height (), 2) + Math.pow (get_img ().get_width (), 2)) + 0.5);+		} 	}-	++	public double img_offset_x {+		get { return img_x + Glyph.xc (); }+		set { img_x = value - Glyph.xc (); }+	}++	public double img_offset_y {+		get { return Glyph.yc () - img_y; }+		set { img_y = Glyph.yc () - value; }+	}++	public void set_img_offset (double x, double y) {+		img_offset_x = x;+		img_offset_y = y;+	}++	public void set_position (double coordinate_x, double coordinate_y) {+		img_x = coordinate_x;+		img_y = coordinate_y;+	}+			 	public ImageSurface get_img () { 		if (path.index_of (".png") == -1) { 			create_png ();@@ -204,11 +229,6 @@ class GlyphBackgroundImage { 		img_scale_y = ys; 	} -	public void set_img_offset (double x, double y) {-		img_offset_x = x;-		img_offset_y = y;-	}- 	public string get_path () { 		return path; 	}diff --git a/src/GlyphCanvas.vala b/src/GlyphCanvas.valaindex 919dc6b..3b10351 100644--- a/src/GlyphCanvas.vala+++ b/src/GlyphCanvas.vala@@ -135,6 +135,9 @@ class GlyphCanvas : DrawingArea  { 			g.allocation = allocation;
 			
 			Supplement.current_glyph = g;
+			Supplement.current_glyph.resized (alloc, allocation);
+			
+			warn_if_fail (g.allocation.width != 0 && g.allocation.height != 0);
 		}
 		
 		current_display = fd;
diff --git a/src/TestCases.vala b/src/TestCases.valaindex bc6f01b..1bfae4b 100644--- a/src/TestCases.vala+++ b/src/TestCases.vala@@ -42,6 +42,19 @@ class TestCases { 		add (test_over_path, "Over path"); 		add (test_preview, "Preview"); 		add (test_export, "Export");+		add (test_background_coordinates, "Background coordinates");+	}++	public static void test_background_coordinates () {+		GlyphBackgroundImage bg = new GlyphBackgroundImage ("");+		+		bg.set_position (100, 100);+		bg.set_img_offset (bg.img_offset_x, bg.img_offset_y);+		warn_if_fail (bg.img_x == 100 && bg.img_y == 100);++		bg.set_img_offset (100, 100);+		bg.set_position (bg.img_x, bg.img_y);+		warn_if_fail (bg.img_offset_x == 100 && bg.img_offset_y == 100); 	}  	public static void test_export () {

Contact

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