]> git.donarmstrong.com Git - lilypond.git/commitdiff
Issue 4997/6: Use Preinit for font metrics
authorDavid Kastrup <dak@gnu.org>
Sat, 4 Jun 2016 17:00:16 +0000 (19:00 +0200)
committerDavid Kastrup <dak@gnu.org>
Fri, 18 Nov 2016 20:49:58 +0000 (21:49 +0100)
lily/include/modified-font-metric.hh
lily/include/open-type-font.hh
lily/include/pango-font.hh
lily/modified-font-metric.cc
lily/open-type-font.cc
lily/pango-font.cc

index c63c532fbde743a0d1e208e4b0702e0f67030520..66996eaf06c226ded5522198767987813055efe0 100644 (file)
@@ -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<Modified_font_metric>,
+                              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_;
index b86a560a73272bc4dc6b963c850a7fcc05f15924..bf66d669813c7917baf23c204034b6c0014bd8f1 100644 (file)
@@ -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<Open_type_font>, 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;
index ff5e6302f061f505347001cce6a34aa3fbfef585..2a3367705b8ee2c4f51008d16b7752e99ac61d56 100644 (file)
@@ -29,7 +29,7 @@
 
 #include "font-metric.hh"
 
-class Pango_font : public Font_metric
+class Pango_font : public Preinit<Pango_font>, 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);
index d1c80b66f056683612aa18259428039e27a27cd1..a93b3f4d97a4a415acc8a469453c1b7baefc9d73 100644 (file)
@@ -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
index f39d924a6852fdcf917c2a91539a4dcc3e27d6f7..73ef069c4fea6816bbbd236cefff664ae9523af0 100644 (file)
@@ -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_));
index b805f34a8541eeb594f51f1aced0633f4c3dcf0e..798d258338787a6497fb180f9c0bf4ea3243eb30 100644 (file)
 #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 ();