Clone in a terminal:
Commit caa3353
Johan Mattsson - 2015-09-22T20:41:58+00:00
caa33531f79c7f41311759c6911e0a6fd360bf4ejohan.mattsson.m@gmail.com

High resolution rendering of text and graphics This commit fixes retina display issues.

Changed files (8)

Diff

diff --git a/birdfont/GtkWindow.vala b/birdfont/GtkWindow.valaindex d3f154f..54512cb 100644--- a/birdfont/GtkWindow.vala+++ b/birdfont/GtkWindow.vala@@ -599,6 +599,10 @@ public class GtkWindow : Gtk.Window, NativeWindow { 			get_window ().set_cursor (new Cursor (CursorType.ARROW)); 		} 	}+	+	public double get_screen_scale () {+		return 1;+	} }  class TabbarCanvas : DrawingArea {diff --git a/build.py b/build.pyindex 38750df..2d3f20f 100755--- a/build.py+++ b/build.py@@ -6,13 +6,20 @@ from sys import platform from scripts.builder import process_tasks from scripts import config from scripts.translations import compile_translations+from scripts import version -if not platform == "msys":-	process_tasks(dodo.task_libbirdgems())-	process_tasks(dodo.task_libbirdfont())-else:+if platform == 'msys': 	process_tasks(dodo.make_libbirdgems('libbirdgems.dll', [])) 	process_tasks(dodo.make_libbirdfont('libbirdfont.dll', ['libbirdgems.dll']))+elif platform == 'darwin':+	gems = "libbirdgems." + str(version.LIBBIRDGEMS_SO_VERSION) + '.dylib'+	bird = "libbirdfont." + str(version.SO_VERSION) + '.dylib';+	process_tasks(dodo.make_libbirdgems(gems, []))+	process_tasks(dodo.make_libbirdfont(bird, [gems]))+	process_tasks(dodo.task_man())+else:+	process_tasks(dodo.task_libbirdgems())+	process_tasks(dodo.task_libbirdfont())  if config.GTK: 	process_tasks(dodo.task_birdfont())diff --git a/libbirdfont/Expander.vala b/libbirdfont/Expander.valaindex a2ad17c..5662ab0 100644--- a/libbirdfont/Expander.vala+++ b/libbirdfont/Expander.vala@@ -273,8 +273,9 @@ public class Expander : GLib.Object { 			double text_height = 17 * Toolbox.get_scale (); 			double offset_y = 0; 			-			cache = new Surface.similar (cr.get_target (), Cairo.Content.COLOR_ALPHA, Toolbox.allocation_width, (int) (h + content_height));+			cache = Screen.create_background_surface (Toolbox.allocation_width, (int) (h + content_height)); 			cc = new Context (cache);+			cc.scale(Screen.get_scale(), Screen.get_scale()); 		 			if (tool.size > 0 && headline != null) { 				Theme.text_color (title, "Text Tool Box");@@ -289,12 +290,7 @@ public class Expander : GLib.Object { 		 		if (cached != null) { 			cache = (!) cached;-			cr.save ();-			cr.set_antialias (Cairo.Antialias.NONE);-			-			cr.set_source_surface (cache, 0, (int) (y + scroll));-			cr.paint ();-			cr.restore ();+			Screen.paint_background_surface (cr, cache, 0, (int) (y + scroll)); 		} 	} 		diff --git a/libbirdfont/NativeWindow.vala b/libbirdfont/NativeWindow.valaindex c690814..8e11db9 100644--- a/libbirdfont/NativeWindow.vala+++ b/libbirdfont/NativeWindow.vala@@ -68,6 +68,12 @@ public interface NativeWindow : GLib.Object {  	/** Set cursor visibility */ 	public abstract void set_cursor (int visible);++	/** Scale all offscreen buffers by this factor in order to +	 * support high resolution screens.+	 */+	public abstract double get_screen_scale ();+ }  }diff --git a/libbirdfont/OverViewItem.vala b/libbirdfont/OverViewItem.valaindex f40511d..2b44c73 100644--- a/libbirdfont/OverViewItem.vala+++ b/libbirdfont/OverViewItem.vala@@ -204,9 +204,9 @@ public class OverViewItem : GLib.Object { 		 		scale_box = width / DEFAULT_WIDTH; -		s = new Surface.similar (cr.get_target (), Content.COLOR_ALPHA, (int) w, (int) h - 20);+		s = Screen.create_background_surface ((int) width, (int) height - 20); 		c = new Context (s);-			+		 		if (gl != null) { 			font = BirdFont.get_current_font (); 			g = ((!) gl).get_current ();@@ -217,19 +217,22 @@ public class OverViewItem : GLib.Object { 			glyph_width = x2 - x1; 			glyph_height = y2 - y1; 			-			gx = ((w / glyph_scale) - glyph_width) / 2;-			gy = (h / glyph_scale) - 25 / glyph_scale;- 			c.save ();-			c.scale (glyph_scale, glyph_scale);	+			c.scale (glyph_scale * Screen.get_scale (), glyph_scale * Screen.get_scale ());  			g.add_help_lines (); 			-			c.translate (gx - g.get_lsb () - Glyph.xc (), g.get_baseline () + gy - Glyph.yc ());+			gx = 0;+			gx = ((w / glyph_scale) - glyph_width) / 2 - g.get_left_side_bearing ();+			gy = (h / glyph_scale) - 25 / glyph_scale;+			+			c.translate (gx - Glyph.xc () - g.get_lsb (), g.get_baseline () + gy - Glyph.yc ()); 						 			g.draw_paths (c, color); 			c.restore (); 		} else {+			c.scale (Screen.get_scale (), Screen.get_scale ());+ 			c.save (); 			Text fallback = new Text (); 			Theme.text_color (fallback, "Overview Glyph");@@ -245,7 +248,9 @@ public class OverViewItem : GLib.Object { 		} 		 		cr.save ();-		cr.set_source_surface (s, x, y - h);+		cr.set_antialias (Cairo.Antialias.NONE);+		cr.scale (1 / Screen.get_scale (), 1 / Screen.get_scale ());	+		cr.set_source_surface (s, (int) (x * Screen.get_scale ()), (int) ((y - h)) * Screen.get_scale ()); 		cr.paint (); 		cr.restore (); 	}@@ -279,8 +284,10 @@ public class OverViewItem : GLib.Object { 		Surface cache; 			 		// unselected item-		cache = new Surface.similar (cr.get_target (), Cairo.Content.COLOR_ALPHA, (int) width, 20);+		cache = Screen.create_background_surface ((int) width, 20); 		cc = new Context (cache);+		cc.scale(Screen.get_scale(), Screen.get_scale());+ 		cc.rectangle (0, 0, width - 1, 20 - 1); 		p = new Cairo.Pattern.linear (0.0, 0, 0.0, 20); 		Theme.gradient (p, "Overview Item 1", "Overview Item 2");@@ -296,8 +303,9 @@ public class OverViewItem : GLib.Object { 		label_background = (!) cache;	  		// selected item-		cache = new Surface.similar (cr.get_target (), Cairo.Content.COLOR_ALPHA, (int) width, 20);+		cache = Screen.create_background_surface ((int) width, 20); 		cc = new Context (cache);+		cc.scale(Screen.get_scale(), Screen.get_scale());  		cc.rectangle (0, 0, width - 1, 20 - 1); @@ -313,9 +321,9 @@ public class OverViewItem : GLib.Object { 		selected_label_background = (!) cache;	 	 		// unselected item without menu icon-		cache = new Surface.similar (cr.get_target (), Cairo.Content.COLOR_ALPHA, (int) width, 20);+		cache = Screen.create_background_surface ((int) width, 20); 		cc = new Context (cache);-+		cc.scale(Screen.get_scale(), Screen.get_scale()); 		cc.rectangle (0, 0, width - 1, 20 - 1); 		p = new Cairo.Pattern.linear (0.0, 0, 0.0, 20); 		Theme.gradient (p, "Overview Item 1", "Overview Item 2");@@ -329,8 +337,9 @@ public class OverViewItem : GLib.Object { 		label_background_no_menu = (!) cache;  		// selected item-		cache = new Surface.similar (cr.get_target (), Cairo.Content.COLOR_ALPHA, (int) width, 20);+		cache = Screen.create_background_surface ((int) width, 20); 		cc = new Context (cache);+		cc.scale(Screen.get_scale(), Screen.get_scale()); 		cc.rectangle (0, 0, width - 1, 20 - 1); 		Theme.color (cc, "Selected Overview Item"); 		cc.fill ();@@ -370,16 +379,12 @@ public class OverViewItem : GLib.Object { 				cache = (!) label_background_no_menu; 			} 			-			cr.save ();-			cr.set_antialias (Cairo.Antialias.NONE);-			cr.set_source_surface (cache, (int) (x + 1), (int) (y + height - 19));-			cr.paint ();-			cr.restore ();+			Screen.paint_background_surface (cr, cache, (int) x, (int) (y + height - 19)); 		} 	} 	 	private void draw_character_info_icon (Context cr) {-		info.draw_icon (cr, selected, width - 17, -2.5);+		info.draw_icon (cr, selected, width - 17, -1.5); 	} 	 	public void hide_menu () {diff --git a/libbirdfont/Renderer/Text.vala b/libbirdfont/Renderer/Text.valaindex f63cf24..a68dd6b 100644--- a/libbirdfont/Renderer/Text.vala+++ b/libbirdfont/Renderer/Text.vala@@ -207,7 +207,6 @@ public class Text : Widget {  	public double get_sidebearing_extent () { 		double x ;-		double ratio; 		 		if (likely (sidebearing_extent > 0)) { 			return sidebearing_extent;@@ -408,11 +407,15 @@ public class Text : Widget { 		offset_x = (int) (10 * (xp - (int) xp)); 		offset_y = (int) (10 * (yp - (int) yp)); 		-		cache_id = (cacheid == "") ? get_cache_id (offset_x, offset_y) : cacheid;		+		cache_id = (cacheid == "") ? get_cache_id (offset_x, offset_y) : cacheid; 				 		if (unlikely (!glyph.has_cache (cache_id))) {-			cache = new Surface.similar (cr.get_target (), Cairo.Content.COLOR_ALPHA, (int) (glyph.get_width () * ratio) + 2, (int) font_size + 2);+			int w = (int) (glyph.get_width () * ratio) + 2;+			int h = (int) font_size + 2;+			cache = Screen.create_background_surface (w, h); 			cc = new Context (cache);++			cc.scale(Screen.get_scale (), Screen.get_scale ()); 			 			lsb = glyph.left_limit; @@ -432,7 +435,10 @@ public class Text : Widget {  		cr.save (); 		cr.set_antialias (Cairo.Antialias.NONE);-		cr.set_source_surface (glyph.get_cache (cache_id), (int) xp, (int) yp);		+		cr.scale(1 / Screen.get_scale (), 1 / Screen.get_scale ());+		cr.set_source_surface (glyph.get_cache (cache_id),+			(int) (xp * Screen.get_scale ()),+			(int) (yp * Screen.get_scale ())); 		cr.paint (); 		cr.restore (); 	}diff --git a/libbirdfont/Screen.vala b/libbirdfont/Screen.valanew file mode 100644index 0000000..6593e35--- /dev/null+++ b/libbirdfont/Screen.vala@@ -0,0 +1,41 @@+/*+    Copyright (C) 2015 Johan Mattsson++    This library is free software; you can redistribute it and/or modify +    it under the terms of the GNU Lesser General Public License as +    published by the Free Software Foundation; either version 3 of the +    License, or (at your option) any later version.++    This library is distributed in the hope that it will be useful, but +    WITHOUT ANY WARRANTY; without even the implied warranty of +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +    Lesser General Public License for more details.+*/++using Cairo;++namespace BirdFont {++class Screen {+	public static double get_scale () {+		return MainWindow.native_window.get_screen_scale ();+	}+	+	public static ImageSurface create_background_surface (int w, int h) {+		int width = (int) (get_scale () * w);+		int height = (int) (get_scale () * h);+		return new ImageSurface(Cairo.Format.ARGB32, width, height);+	}+	+	public static void paint_background_surface(Context cr, Surface s, int x, int y) {+		cr.save ();+		cr.set_antialias (Cairo.Antialias.NONE);+		cr.scale (1 / get_scale (), 1 / get_scale ());	+		cr.set_source_surface (s, (int) (x * Screen.get_scale ()), (int) (y * Screen.get_scale ()));+		cr.paint ();+		cr.restore ();+	}++}+	+}diff --git a/scripts/complete_translations.py b/scripts/complete_translations.pyindex 0a9c11f..868ad03 100755--- a/scripts/complete_translations.py+++ b/scripts/complete_translations.py@@ -71,7 +71,7 @@ elif options.compiled:         else:             print ("Removing incomplete translation " + podir)             run ("mkdir -p build/incomplete")-            run ("mv build/locale/" + podir + " build/incomplete/") +            run ("rm -r build/locale/" + podir)  elif options.incomplete:     for pofile in glob.glob('po/*.po'):         completed = completeness (pofile)

Contact

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