The Birdfont Source Code


All Repositories / birdfont.git / blob – RSS feed

CachedFont.vala in libbirdfont/Renderer

This file is a part of the Birdfont project.

Contributing

Send patches or pull requests to johan.mattsson.m@gmail.com.
Clone this repository: git clone https://github.com/johanmattssonm/birdfont.git

Revisions

View the latest version of libbirdfont/Renderer/CachedFont.vala.
Fix text rendering
1 /* 2 Copyright (C) 2015 Johan Mattsson 3 4 This library is free software; you can redistribute it and/or modify 5 it under the terms of the GNU Lesser General Public License as 6 published by the Free Software Foundation; either version 3 of the 7 License, or (at your option) any later version. 8 9 This library is distributed in the hope that it will be useful, but 10 WITHOUT ANY WARRANTY; without even the implied warranty of 11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 Lesser General Public License for more details. 13 */ 14 15 using Gee; 16 17 namespace BirdFont { 18 19 public class CachedFont : GLib.Object { 20 public Font? font; 21 22 // FIXME: move fallback glyphs in to fond boundaries 23 public double top_limit = 84; 24 public double base_line = 0; 25 public double bottom_limit = -27; 26 27 FallbackFont fallback_font { 28 get { 29 if (_fallback_font == null) { 30 _fallback_font = new FallbackFont (); 31 } 32 33 return (!) _fallback_font; 34 } 35 } 36 static FallbackFont? _fallback_font = null; 37 38 public CachedFont (Font? font) { 39 this.font = font; 40 } 41 42 public Glyph? get_glyph_by_name (string name) { 43 Font f = new Font (); 44 Glyph? g = null; 45 46 if (font != null) { 47 g = ((!) font).get_glyph_by_name (name); 48 } 49 50 if (g == null && name.char_count () == 1) { 51 f = fallback_font.get_single_glyph_font (name.get_char (0)); 52 g = f.get_glyph_by_name (name); 53 54 if (g == null) { 55 return null; 56 } 57 58 top_limit = f.top_limit; 59 base_line = f.base_line; 60 bottom_limit = f.bottom_limit; 61 } 62 63 return g; 64 } 65 } 66 67 } 68