Commit c8fcf94
Cached font
Changed files (3)
addedlibbirdfont/Renderer/CachedFont.valamodifiedlibbirdfont/Renderer/Text.valamodifiedlibbirdfont/VersionList.vala
Diff
new file mode 100644@@ -0,0 +1,67 @@+/*+ 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 Gee;++namespace BirdFont {+ +public class CachedFont : GLib.Object {+ public Font? font;++ // FIXME: move fallback glyphs in to fond boundaries+ public double top_limit = 84;+ public double base_line = 0;+ public double bottom_limit = -27;+ + FallbackFont fallback_font {+ get {+ if (_fallback_font == null) {+ _fallback_font = new FallbackFont ();+ }+ + return (!) _fallback_font;+ }+ }+ static FallbackFont? _fallback_font = null;++ public CachedFont (Font? font) {+ this.font = font;+ }+ + public Glyph? get_glyph_by_name (string name) {+ Font f = new Font ();+ Glyph? g = null;+ + if (font != null) {+ g = ((!) font).get_glyph_by_name (name);+ }+ + if (g == null && name.char_count () == 1) {+ f = fallback_font.get_single_glyph_font (name.get_char (0));+ g = f.get_glyph_by_name (name);+ + if (g == null) {+ return null;+ }+ + top_limit = f.top_limit;+ base_line = f.base_line;+ bottom_limit = f.bottom_limit; + }+ + return g;+ }+}++}@@ -48,8 +48,6 @@ public class Text : Widget { bool use_cached_glyphs = true; double truncated_width = -1; - static int ntext = 0;- public Text (string text = "", double size = 17, double margin_bottom = 0) { this.margin_bottom = margin_bottom; font_cache = FontCache.get_default_cache ();@@ -57,12 +55,6 @@ public class Text : Widget { set_font_size (size); set_text (text);- - ntext++;- }- - ~Text () {- ntext--; } public void use_cache (bool cache) {@@ -343,6 +335,10 @@ public class Text : Widget { y = py; x = px; + if (unlikely (cached_font.base_line != 0)) {+ warning ("Base line not zero.");+ }+ if (use_cached_glyphs) { iterate ((glyph, kerning, last) => { double end;@@ -390,7 +386,7 @@ public class Text : Widget { lsb = glyph.left_limit; foreach (Path path in glyph.path_list) {- draw_path (cr, path, lsb, x, y, ratio);+ draw_path (cr, glyph, path, lsb, x, y, ratio); } cr.fill ();@@ -426,7 +422,7 @@ public class Text : Widget { cc.new_path (); foreach (Path path in glyph.path_list) {- draw_path (cc, path, lsb, offset_x / 10.0, cc_y + offset_y / 10.0, ratio);+ draw_path (cc, glyph, path, lsb, offset_x / 10.0, cc_y + offset_y / 10.0, ratio); } cc.fill ();@@ -442,12 +438,18 @@ public class Text : Widget { cr.restore (); } - void draw_path (Context cr, Path path, double lsb, double x, double y, double scale) {+ void draw_path (Context cr, Glyph glyph, Path path,+ double lsb, double x, double y, double scale) {+ EditPoint e, prev; double xa, ya, xb, yb, xc, yc, xd, yd; double by;- + if (path.points.size > 0) {+ if (unlikely (path.is_open ())) {+ warning (@"Path is open in $(glyph.get_name ()).");+ }+ path.add_hidden_double_points (); prev = path.points.get (path.points.size - 1);@@ -27,8 +27,6 @@ public class VersionList : GLib.Object { GlyphCollection glyph_collection; public Gee.ArrayList<Glyph> glyphs;- - static int n_lists = 0; public delegate void Selected (MenuAction self); public signal void selected (VersionList self);@@ -74,15 +72,6 @@ public class VersionList : GLib.Object { } set_selected_version (gc.get_current ().version_id, false);- n_lists++;- }- - ~VersionList () {- n_lists--;-- if (menu_visible) {- warning ("menu is visible");- } } private void delete_item (int index) {@@ -92,7 +81,7 @@ public class VersionList : GLib.Object { font.touch (); - index--; // first item is the add new action+ index--; // first item adds new glyphs to the list // delete the entire glyph if the last remaining version is removed if (glyphs.size == 1) {