-Open_type_font::get_indexed_char (int signed_idx) const
-{
- FT_UInt idx = signed_idx;
- FT_Load_Glyph (face_,
- idx,
- FT_LOAD_NO_SCALE);
-
- FT_Glyph_Metrics m = face_->glyph->metrics;
- int hb = m.horiBearingX;
- int vb = m.horiBearingY;
- Box b (Interval (-hb, m.width - hb),
- Interval (-vb, m.height - vb));
-
+Open_type_font::get_indexed_char_dimensions (size_t signed_idx) const
+{
+ if (SCM_HASHTABLE_P (lily_index_to_bbox_table_))
+ {
+ SCM box = scm_hashq_ref (lily_index_to_bbox_table_,
+ scm_from_unsigned_integer (signed_idx), SCM_BOOL_F);
+ Box *box_ptr = Box::unsmob (box);
+ if (box_ptr)
+ return *box_ptr;
+ }
+
+ if (SCM_HASHTABLE_P (lily_character_table_))
+ {
+ const size_t len = 256;
+ char name[len];
+ FT_Error code = FT_Get_Glyph_Name (face_, FT_UInt (signed_idx),
+ name, FT_UInt (len));
+ if (code)
+ warning (_f ("FT_Get_Glyph_Name () Freetype error: %s",
+ freetype_error_string (code)));
+
+ SCM sym = ly_symbol2scm (name);
+ SCM alist = scm_hashq_ref (lily_character_table_, sym, SCM_BOOL_F);
+
+ if (alist != SCM_BOOL_F)
+ {
+ SCM bbox = scm_cdr (scm_assq (ly_symbol2scm ("bbox"), alist));
+
+ Box b;
+ b[X_AXIS][LEFT] = scm_to_double (scm_car (bbox));
+ bbox = scm_cdr (bbox);
+ b[Y_AXIS][LEFT] = scm_to_double (scm_car (bbox));
+ bbox = scm_cdr (bbox);
+ b[X_AXIS][RIGHT] = scm_to_double (scm_car (bbox));
+ bbox = scm_cdr (bbox);
+ b[Y_AXIS][RIGHT] = scm_to_double (scm_car (bbox));
+ bbox = scm_cdr (bbox);
+
+ b.scale (point_constant);
+
+ scm_hashq_set_x (lily_index_to_bbox_table_,
+ scm_from_unsigned_integer (signed_idx),
+ b.smobbed_copy ());
+ return b;
+ }
+ }
+
+ Box b = get_unscaled_indexed_char_dimensions (signed_idx);
+
+ b.scale (design_size () / Real (face_->units_per_EM));