The Birdfont Source Code


All Repositories / birdfont.git / commitdiff – RSS feed

Merge branch 'master' of github.com:johanmattssonm/birdfont

These changes was commited to the Birdfont repository Tue, 22 Sep 2015 21:07:52 +0000.

Contributing

Send patches or pull requests to johan.mattsson.m@gmail.com.
Clone this repository: git clone https://github.com/johanmattssonm/birdfont.git
[Tue, 22 Sep 2015 21:07:52 +0000]

Updated Files

birdfont/GtkWindow.vala
build.py
libbirdfont/Expander.vala
libbirdfont/NativeWindow.vala
libbirdfont/OverViewItem.vala
libbirdfont/Renderer/Text.vala
libbirdfont/Renderer/TextArea.vala
libbirdfont/Screen.vala
scripts/complete_translations.py
--- a/birdfont/GtkWindow.vala +++ b/birdfont/GtkWindow.vala @@ -598,6 +598,10 @@ } else { get_window ().set_cursor (new Cursor (CursorType.ARROW)); } + } + + public double get_screen_scale () { + return 1; } }
diff --git a/build.py b/build.py
--- a/build.py +++ b/build.py @@ -6,13 +6,20 @@ 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())
--- a/libbirdfont/Expander.vala +++ b/libbirdfont/Expander.vala @@ -273,8 +273,9 @@ 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 @@ 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)); } }
--- a/libbirdfont/NativeWindow.vala +++ b/libbirdfont/NativeWindow.vala @@ -68,7 +68,13 @@ /** 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 (); + } }
--- a/libbirdfont/OverViewItem.vala +++ b/libbirdfont/OverViewItem.vala @@ -204,9 +204,9 @@ 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 @@ 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 @@ } 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 () {
--- a/libbirdfont/Renderer/Text.vala +++ b/libbirdfont/Renderer/Text.vala @@ -407,11 +407,15 @@ 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 @@ 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 (); }
--- a/libbirdfont/Renderer/TextArea.vala +++ b/libbirdfont/Renderer/TextArea.vala @@ -1198,9 +1198,10 @@ 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 @@ 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."); }
diff --git libbirdfont/Screen.vala(new)
--- /dev/null +++ b/libbirdfont/Screen.vala @@ -1,1 +1,42 @@ + /* + 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 (); + } + + } + + }
--- a/scripts/complete_translations.py +++ b/scripts/complete_translations.py @@ -71,7 +71,7 @@ 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)