From 3cdc909d8cea64c8faef90d3a6a391f32a424ba2 Mon Sep 17 00:00:00 2001 From: David Kastrup Date: Sat, 4 Jun 2016 19:00:16 +0200 Subject: [PATCH] Issue 4997/6: Use Preinit for font metrics --- lily/include/modified-font-metric.hh | 4 +++- lily/include/open-type-font.hh | 3 ++- lily/include/pango-font.hh | 3 ++- lily/modified-font-metric.cc | 7 +++++++ lily/open-type-font.cc | 9 +++++++-- lily/pango-font.cc | 10 ++++++---- 6 files changed, 27 insertions(+), 9 deletions(-) diff --git a/lily/include/modified-font-metric.hh b/lily/include/modified-font-metric.hh index c63c532fbd..66996eaf06 100644 --- a/lily/include/modified-font-metric.hh +++ b/lily/include/modified-font-metric.hh @@ -23,7 +23,8 @@ #include "font-metric.hh" /* Perhaps junk this, and move this to layout_def as interface? */ -struct Modified_font_metric : public Font_metric +struct Modified_font_metric : public Preinit, + public Font_metric { public: Stencil text_stencil (Output_def *output_state, const string&, bool) const; @@ -36,6 +37,7 @@ public: size_t name_to_index (string) const; size_t index_to_charcode (size_t) const; Font_metric *original_font () const; + void pre_init (); protected: Font_metric *orig_; diff --git a/lily/include/open-type-font.hh b/lily/include/open-type-font.hh index b86a560a73..bf66d66981 100644 --- a/lily/include/open-type-font.hh +++ b/lily/include/open-type-font.hh @@ -26,7 +26,7 @@ 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); -class Open_type_font : public Font_metric +class Open_type_font : public Preinit, public Font_metric { /* handle to face object */ FT_Face face_; @@ -42,6 +42,7 @@ class Open_type_font : public Font_metric DECLARE_CLASSNAME (Open_type_font); public: + void pre_init (); Real get_units_per_EM () const; SCM get_subfonts () const; SCM get_global_table () const; diff --git a/lily/include/pango-font.hh b/lily/include/pango-font.hh index ff5e6302f0..2a3367705b 100644 --- a/lily/include/pango-font.hh +++ b/lily/include/pango-font.hh @@ -29,7 +29,7 @@ #include "font-metric.hh" -class Pango_font : public Font_metric +class Pango_font : public Preinit, public Font_metric { PangoContext *context_; PangoFontDescription *pango_description_; @@ -41,6 +41,7 @@ class Pango_font : public Font_metric public: SCM physical_font_tab () const; + void pre_init (); Pango_font (PangoFT2FontMap *, PangoFontDescription const *, Real); diff --git a/lily/modified-font-metric.cc b/lily/modified-font-metric.cc index d1c80b66f0..a93b3f4d97 100644 --- a/lily/modified-font-metric.cc +++ b/lily/modified-font-metric.cc @@ -26,6 +26,11 @@ using namespace std; #include "main.hh" #include "program-option.hh" +void Modified_font_metric::pre_init () +{ + orig_ = 0; +} + Modified_font_metric::Modified_font_metric (Font_metric *fm, Real magnification) { @@ -102,6 +107,8 @@ Modified_font_metric::index_to_charcode (vsize i) const void Modified_font_metric::derived_mark () const { + if (orig_) + scm_gc_mark (orig_->self_scm ()); } Stencil diff --git a/lily/open-type-font.cc b/lily/open-type-font.cc index f39d924a68..73ef069c4f 100644 --- a/lily/open-type-font.cc +++ b/lily/open-type-font.cc @@ -251,13 +251,18 @@ Open_type_font::make_otf (const string &str) return otf->self_scm (); } -Open_type_font::Open_type_font (FT_Face face) +void +Open_type_font::pre_init () { - face_ = face; lily_character_table_ = SCM_EOL; lily_global_table_ = SCM_EOL; lily_subfonts_ = SCM_EOL; lily_index_to_bbox_table_ = SCM_EOL; +} + +Open_type_font::Open_type_font (FT_Face face) +{ + face_ = face; lily_character_table_ = alist_to_hashq (load_scheme_table ("LILC", face_)); lily_global_table_ = alist_to_hashq (load_scheme_table ("LILY", face_)); diff --git a/lily/pango-font.cc b/lily/pango-font.cc index b805f34a85..798d258338 100644 --- a/lily/pango-font.cc +++ b/lily/pango-font.cc @@ -46,14 +46,16 @@ #if HAVE_PANGO_FT2 #include "stencil.hh" +void +Pango_font::pre_init () +{ + physical_font_tab_ = SCM_EOL; +} + Pango_font::Pango_font (PangoFT2FontMap *fontmap, PangoFontDescription const *description, Real output_scale) { - // This line looks stupid, but if we don't initialize physical_font_tab_ before - // we allocate memory in scm_c_make_hash_table, then that could trigger a garbage - // collection. - physical_font_tab_ = SCM_EOL; physical_font_tab_ = scm_c_make_hash_table (11); PangoDirection pango_dir = PANGO_DIRECTION_LTR; context_ = pango_context_new (); -- 2.39.2