The Birdfont Source Code


All Repositories / birdfont.git / commitdiff – RSS feed

Cached font

These changes was commited to the Birdfont repository Thu, 28 May 2015 12:11:08 +0000.

Contributing

Send patches or pull requests to johan.mattsson.m@gmail.com.
Clone this repository: git clone https://github.com/johanmattssonm/birdfont.git
[Thu, 28 May 2015 12:11:08 +0000]

Updated Files

libbirdfont/Renderer/CachedFont.vala
libbirdfont/Renderer/Text.vala
libbirdfont/VersionList.vala
--- /dev/null +++ b/libbirdfont/Renderer/CachedFont.vala @@ -1,1 +1,68 @@ + /* + 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; + } + } + + }
--- a/libbirdfont/Renderer/Text.vala +++ b/libbirdfont/Renderer/Text.vala @@ -47,8 +47,6 @@ 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; @@ -57,12 +55,6 @@ set_font_size (size); set_text (text); - - ntext++; - } - - ~Text () { - ntext--; } public void use_cache (bool cache) { @@ -342,6 +334,10 @@ y = py; x = px; + + if (unlikely (cached_font.base_line != 0)) { + warning ("Base line not zero."); + } if (use_cached_glyphs) { iterate ((glyph, kerning, last) => { @@ -390,7 +386,7 @@ 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 @@ 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 @@ 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);
--- a/libbirdfont/VersionList.vala +++ b/libbirdfont/VersionList.vala @@ -27,8 +27,6 @@ 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 @@ } 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 @@ 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) {