From 04974e9ea76a647fb5ded11d048017ad2e469157 Mon Sep 17 00:00:00 2001 From: Han-Wen Nienhuys Date: Sat, 2 Dec 2006 17:14:17 +0100 Subject: [PATCH] put cmap handling into all_fonts too. --- lily/all-font-metrics.cc | 24 ++++++++++++++++++++++++ lily/include/all-font-metrics.hh | 9 ++++++++- lily/include/font-metric.hh | 6 ++++++ lily/include/open-type-font.hh | 5 +---- lily/main.cc | 3 +-- lily/pango-font.cc | 22 ++-------------------- 6 files changed, 42 insertions(+), 27 deletions(-) diff --git a/lily/all-font-metrics.cc b/lily/all-font-metrics.cc index 4d95f9e6c1..bf2aadd4bb 100644 --- a/lily/all-font-metrics.cc +++ b/lily/all-font-metrics.cc @@ -15,6 +15,18 @@ #include "scm-hash.hh" #include "warn.hh" + +Index_to_charcode_map const * +All_font_metrics::get_index_to_charcode_map (string filename, FT_Face face) +{ + if (filename_charcode_maps_map_.find (filename) + == filename_charcode_maps_map_.end ()) + filename_charcode_maps_map_[filename] = make_index_to_charcode_map (face); + + return &filename_charcode_maps_map_[filename]; +} + + All_font_metrics::All_font_metrics (string path) { otf_dict_ = new Scheme_hash_table; @@ -166,6 +178,17 @@ All_font_metrics::find_font (string name) All_font_metrics *all_fonts_global; +LY_DEFINE (ly_reset_all_fonts, "ly:reset-all-fonts", 0, 0, 0, + (), + "Forget all about previously loaded fonts. ") +{ + delete all_fonts_global; + all_fonts_global = new All_font_metrics (global_path.to_string ()); + + return SCM_UNSPECIFIED; +} + + LY_DEFINE (ly_font_load, "ly:font-load", 1, 0, 0, (SCM name), "Load the font @var{name}. ") @@ -177,3 +200,4 @@ LY_DEFINE (ly_font_load, "ly:font-load", 1, 0, 0, return fm->self_scm (); } + diff --git a/lily/include/all-font-metrics.hh b/lily/include/all-font-metrics.hh index c8c0de2f0a..34a05e701f 100644 --- a/lily/include/all-font-metrics.hh +++ b/lily/include/all-font-metrics.hh @@ -18,7 +18,8 @@ #include #endif -/** + +/* Interface to all .afm files living in the filesystem. */ class All_font_metrics @@ -32,8 +33,13 @@ class All_font_metrics int pango_dpi_; #endif + map filename_charcode_maps_map_; + All_font_metrics (All_font_metrics const &); public: + + Index_to_charcode_map const *get_index_to_charcode_map (string filename, FT_Face face); + All_font_metrics (string search_path); ~All_font_metrics (); @@ -49,6 +55,7 @@ public: }; extern All_font_metrics *all_fonts_global; +SCM ly_reset_all_fonts (); #endif /* ALL_FONTS_HH */ diff --git a/lily/include/font-metric.hh b/lily/include/font-metric.hh index dfcd1e8003..1107ba9af8 100644 --- a/lily/include/font-metric.hh +++ b/lily/include/font-metric.hh @@ -13,6 +13,12 @@ #include "lily-proto.hh" #include "smobs.hh" #include "virtual-methods.hh" +#include "freetype.hh" + +#include +using namespace std; + +typedef map Index_to_charcode_map; class Font_metric { diff --git a/lily/include/open-type-font.hh b/lily/include/open-type-font.hh index c0490be6e5..9cd34497ab 100644 --- a/lily/include/open-type-font.hh +++ b/lily/include/open-type-font.hh @@ -9,13 +9,9 @@ #ifndef OPEN_TYPE_FONT_HH #define OPEN_TYPE_FONT_HH -#include -using namespace std; -#include "freetype.hh" #include "font-metric.hh" -typedef map Index_to_charcode_map; Index_to_charcode_map make_index_to_charcode_map (FT_Face face); void get_unicode_name (char*s, FT_ULong code); void get_glyph_index_name (char*s, FT_ULong code); @@ -58,4 +54,5 @@ public: string get_otf_table (FT_Face face, string tag); FT_Face open_ft_face (string str); + #endif /* OPEN_TYPE_FONT_HH */ diff --git a/lily/main.cc b/lily/main.cc index 9a21728eb3..9344a1ec4b 100644 --- a/lily/main.cc +++ b/lily/main.cc @@ -393,8 +393,7 @@ main_with_guile (void *, int, char **) init_fontconfig (); init_freetype (); - - all_fonts_global = new All_font_metrics (global_path.to_string ()); + ly_reset_all_fonts (); if (!init_scheme_variables.empty () || !init_scheme_code_string.empty ()) diff --git a/lily/pango-font.cc b/lily/pango-font.cc index ca08a4b0d2..3d58e0dd0e 100644 --- a/lily/pango-font.cc +++ b/lily/pango-font.cc @@ -15,9 +15,6 @@ /* Ugh. */ #include "pango-font.hh" - -#include "open-type-font.hh" // Index_to_charcode_map - #include "dimensions.hh" #include "file-name.hh" #include "international.hh" @@ -25,6 +22,7 @@ #include "main.hh" #include "string-convert.hh" #include "warn.hh" +#include "all-font-metrics.hh" #if HAVE_PANGO_FT2 #include "stencil.hh" @@ -82,22 +80,6 @@ Pango_font::derived_mark () const } -map filename_charcode_maps_map; -Index_to_charcode_map const *get_index_to_charcode_map (string postscript_name, FT_Face face); - - -Index_to_charcode_map const * -get_index_to_charcode_map (string filename, FT_Face face) -{ - if (filename_charcode_maps_map.find (filename) == filename_charcode_maps_map.end ()) - filename_charcode_maps_map[filename] = make_index_to_charcode_map (face); - - if (filename_charcode_maps_map.find (filename) == filename_charcode_maps_map.end ()) - return 0; - - return &filename_charcode_maps_map[filename]; -} - void get_glyph_index_name (char *s, FT_ULong code) { @@ -165,7 +147,7 @@ Pango_font::pango_item_string_stencil (PangoItem const *item, string str, Index_to_charcode_map const *cmap = 0; bool has_glyph_names = ftface->face_flags & FT_FACE_FLAG_GLYPH_NAMES; if (! has_glyph_names) - cmap = get_index_to_charcode_map (file_name, ftface); + cmap = all_fonts_global->get_index_to_charcode_map (file_name, ftface); bool is_ttf = string (FT_Get_X11_Font_Format (ftface)) == "TrueType"; bool cid_keyed = false; -- 2.39.2