The Birdfont Source Code


All Repositories / birdfont.git / commitdiff – RSS feed

Don't put overview glyphs in cache

These changes was commited to the Birdfont repository Mon, 14 Dec 2015 14:08:12 +0000.

Contributing

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

Updated Files

libbirdfont/CharacterInfo.vala
libbirdfont/OpenFontFormat/Os2Table.vala
libbirdfont/OpenFontFormat/load_font.c
libbirdfont/OverView.vala
libbirdfont/OverViewItem.vala
libbirdfont/Renderer/CachedFont.vala
libbirdfont/Renderer/FallbackFont.vala
libbirdfont/Renderer/Text.vala
libbirdfont/Renderer/fontconfig.c
--- a/libbirdfont/CharacterInfo.vala +++ b/libbirdfont/CharacterInfo.vala @@ -21,6 +21,7 @@ public unichar unicode; + private static Text? info_icon = null; Text icon; double x = 0; double y = 0; @@ -29,13 +30,17 @@ public CharacterInfo (unichar c, GlyphCollection? gc) { unicode = c; - icon = new Text ("info_icon", 22); - icon.load_font ("icons.bf"); + + if (info_icon == null) { + info_icon= new Text ("info_icon", 22); + ((!) info_icon).load_font ("icons.bf"); + } + + icon = (!) info_icon; if (gc != null) { ligature = ((!) gc).is_unassigned (); name = ((!) gc).get_name (); - icon.load_font ("icons.bf"); } }
--- a/libbirdfont/OpenFontFormat/Os2Table.vala +++ b/libbirdfont/OpenFontFormat/Os2Table.vala @@ -61,7 +61,7 @@ uint32 codepage1, codepage2; int16 win_descent; - fd.add_u16 (0x0004); // version + fd.add_u16 (0x0002); // version fd.add_16 (hmtx_table.get_average_width ()); // xAvgCharWidth @@ -104,6 +104,7 @@ fd.add_u32 (0); // ulUnicodeRange3 Bits 64-95 fd.add_u32 (0); // ulUnicodeRange4 Bits 96-127 } else { + warning(@"unicodeRange1: $unicodeRange1 unicodeRange2: $unicodeRange2 unicodeRange3 $unicodeRange3 unicodeRange4: $unicodeRange4"); fd.add_u32 (unicodeRange1); // ulUnicodeRange1 Bits 0-31 fd.add_u32 (unicodeRange2); // ulUnicodeRange2 Bits 32-63 fd.add_u32 (unicodeRange3); // ulUnicodeRange3 Bits 64-95
--- a/libbirdfont/OpenFontFormat/load_font.c +++ b/libbirdfont/OpenFontFormat/load_font.c @@ -1,15 +1,15 @@ /* - Copyright (C) 2013 2014 2015 Johan Mattsson + Copyright (C) 2013 2014 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 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. + 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. */ #include <assert.h>
--- a/libbirdfont/OverView.vala +++ b/libbirdfont/OverView.vala @@ -1455,6 +1455,7 @@ cr.save (); Text character = new Text (); + character.set_use_cache (false); Theme.text_color (character, "Foreground 1"); character.set_text ((!) c.to_string ()); character.set_font_size (height);
--- a/libbirdfont/OverViewItem.vala +++ b/libbirdfont/OverViewItem.vala @@ -233,9 +233,10 @@ c.restore (); } else { c.scale (Screen.get_scale (), Screen.get_scale ()); - + c.save (); Text fallback = new Text (); + fallback.set_use_cache (false); Theme.text_color (fallback, "Overview Glyph"); fallback.set_text ((!) character.to_string ()); double font_size = height * 0.8;
--- a/libbirdfont/Renderer/CachedFont.vala +++ b/libbirdfont/Renderer/CachedFont.vala @@ -33,7 +33,7 @@ double _top_limit = 92.77; // FIXME: load before first glyph double _bottom_limit = -24.4; - FallbackFont fallback_font { + static FallbackFont fallback_font { get { if (_fallback_font == null) { _fallback_font = new FallbackFont ();
--- a/libbirdfont/Renderer/FallbackFont.vala +++ b/libbirdfont/Renderer/FallbackFont.vala @@ -16,17 +16,20 @@ [SimpleType] [CCode (has_type_id = false)] - extern struct FcConfig { + public extern struct FcConfig { } [CCode (cname = "FcInitLoadConfigAndFonts")] - extern FcConfig* FcInitLoadConfigAndFonts (); + public extern FcConfig* FcInitLoadConfigAndFonts (); [CCode (cname = "find_font")] - extern string? find_font (FcConfig* font_config, string characters); + public extern string? find_font (FcConfig* font_config, string characters); + + [CCode (cname = "find_font_family")] + public extern string? find_font_family (FcConfig* font_config, string characters); [CCode (cname = "find_font_file")] - extern string? find_font_file (FcConfig* font_config, string font_name); + public extern string? find_font_file (FcConfig* font_config, string font_name); namespace BirdFont { @@ -35,7 +38,7 @@ Gee.ArrayList<File> font_directories; FontFace* default_font = null; - static FcConfig* font_config = null; + public static FcConfig* font_config = null; static bool font_config_stated = false; string default_font_file_name = "Roboto-Regular.ttf";
--- a/libbirdfont/Renderer/Text.vala +++ b/libbirdfont/Renderer/Text.vala @@ -25,6 +25,8 @@ Surface? cache = null; public string text; + + private bool use_cache = true; GlyphSequence glyph_sequence { get { @@ -58,6 +60,10 @@ set_text (text); set_font_size (size); + } + + public void set_use_cache (bool cache) { + use_cache = cache; } public string get_text () { @@ -432,6 +438,7 @@ double lsb; Surface cache; + Surface cached_glyph; Context cc; string cache_id; double glyph_margin_left = glyph.get_left_side_bearing (); @@ -472,13 +479,19 @@ cc.fill (); cc.restore (); - glyph.set_cache (cache_id, cache); + if (use_cache) { + glyph.set_cache (cache_id, cache); + } + + cached_glyph = cache; + } else { + cached_glyph = glyph.get_cache (cache_id); } cr.save (); cr.set_antialias (Cairo.Antialias.NONE); cr.scale(1 / Screen.get_scale (), 1 / Screen.get_scale ()); - cr.set_source_surface (glyph.get_cache (cache_id), + cr.set_source_surface (cached_glyph, (int) (xp * Screen.get_scale ()), (int) (yp * Screen.get_scale ())); cr.paint ();
--- a/libbirdfont/Renderer/fontconfig.c +++ b/libbirdfont/Renderer/fontconfig.c @@ -1,25 +1,22 @@ /* - Copyright (C) 2015 Johan Mattsson + 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 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. + 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. */ #include <stdio.h> #include <glib.h> #include <fontconfig/fontconfig.h> - /** Find a fallback font for a set of characters. - * @return A path to the font file. - */ - gchar* find_font (FcConfig* fontconfig, const gchar* characters) { + gchar* find_font_with_property (FcConfig* fontconfig, const gchar* characters, const gchar* property) { FcPattern* pattern; FcCharSet* character_set; FcObjectSet* font_properties; @@ -58,12 +55,12 @@ FcPatternAddInteger (pattern, FC_SLANT, FC_SLANT_ROMAN); FcPatternAddBool(pattern, FC_SCALABLE, FcTrue); - font_properties = FcObjectSetBuild (FC_FILE, NULL); + font_properties = FcObjectSetBuild (property, NULL); fonts = FcFontList (fontconfig, pattern, font_properties); if (fonts && fonts->nfont > 0) { font = fonts->fonts[0]; - if (FcPatternGetString(font, FC_FILE, 0, &path) == FcResultMatch) { + if (FcPatternGetString(font, property, 0, &path) == FcResultMatch) { result = g_strdup ((gchar*) path); } } @@ -77,6 +74,20 @@ } return result; + } + + /** Find a fallback font for a set of characters. + * @return A path to the font file. + */ + gchar* find_font (FcConfig* fontconfig, const gchar* characters) { + return find_font_with_property (fontconfig, characters, FC_FILE); + } + + /** Find a fallback font for a set of characters. + * @return Family name of the font. + */ + gchar* find_font_family (FcConfig* fontconfig, const gchar* characters) { + return find_font_with_property (fontconfig, characters, FC_FAMILY); } /** Find a font file from its family name.