Commit 722fbc2
Merge branch 'master' of github.com:johanmattssonm/birdfont
Changed files (9)
modifiedbirdfont/GtkWindow.valamodifiedbuild.pymodifiedlibbirdfont/Expander.valamodifiedlibbirdfont/NativeWindow.valamodifiedlibbirdfont/OverViewItem.valamodifiedlibbirdfont/Renderer/Text.valamodifiedlibbirdfont/Renderer/TextArea.valaaddedlibbirdfont/Screen.valamodifiedscripts/complete_translations.py
Diff
@@ -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 {@@ -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())@@ -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)); } } @@ -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 ();+ } }@@ -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,21 @@ 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 = ((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 +247,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,9 +283,11 @@ 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.rectangle (0, 0, width - 1, 20 - 1);+ cc.scale(Screen.get_scale(), Screen.get_scale());++ cc.rectangle (0, 0, width, 20 - 1); p = new Cairo.Pattern.linear (0.0, 0, 0.0, 20); Theme.gradient (p, "Overview Item 1", "Overview Item 2"); cc.set_source (p);@@ -296,10 +302,11 @@ 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);+ cc.rectangle (0, 0, width, 20 - 1); Theme.color (cc, "Selected Overview Item"); @@ -313,9 +320,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 +336,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 +378,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 () {@@ -407,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; @@ -431,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 (); }@@ -1198,9 +1198,10 @@ public class TextArea : Widget { ty = paragraph.start_y; if (paragraph.cached_surface == null) { - paragraph.cached_surface = new Surface.similar (cr.get_target (), Cairo.Content.COLOR_ALPHA, (int) width + 2, paragraph.get_height () + (int) font_size + 2);+ paragraph.cached_surface = Screen.create_background_surface ((int) width + 2, paragraph.get_height () + (int) font_size + 2); cc = new Context ((!) paragraph.cached_surface);-+ cc.scale (Screen.get_scale(), Screen.get_scale());+ foreach (Text next_word in paragraph.words) { if (next_word.text != "\n") { next_word.draw_at_top (cc, next_word.widget_x, next_word.widget_y - ty);@@ -1210,8 +1211,10 @@ public class TextArea : Widget { if (likely (paragraph.cached_surface != null)) { // FIXME: subpixel offset in text area- cr.set_source_surface ((!) paragraph.cached_surface, (int) (x + tx), (int) (widget_y + paragraph.start_y - font_size + padding));- cr.paint ();+ Screen.paint_background_surface(cr, + (!) paragraph.cached_surface,+ (int) (x + tx),+ (int) (widget_y + paragraph.start_y - font_size + padding)); } else { warning ("No paragraph image."); }new file mode 100644@@ -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 ();+ }++}+ +}@@ -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)