From: Han-Wen Nienhuys Date: Thu, 30 Dec 2004 00:01:21 +0000 (+0000) Subject: (text_stencil): export size as well. X-Git-Tag: release/2.5.14~336 X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=6fea800daedae76ba5ac4e4b2c35f4db5e991a1e;p=lilypond.git (text_stencil): export size as well. (text_stencil): fix scaling and extents box. --- diff --git a/lily/include/pango-font.hh b/lily/include/pango-font.hh index 36aa04c391..de98e8194a 100644 --- a/lily/include/pango-font.hh +++ b/lily/include/pango-font.hh @@ -34,6 +34,7 @@ public: SCM font_file_name () const; void register_font_file (String, String); Stencil text_stencil (String) const; + Stencil pango_item_string_stencil (PangoItem*, String) const; virtual SCM sub_fonts () const; virtual void derived_mark () const; diff --git a/lily/pango-font.cc b/lily/pango-font.cc index dd93df8d6a..52b7dd9bba 100644 --- a/lily/pango-font.cc +++ b/lily/pango-font.cc @@ -57,6 +57,70 @@ Pango_font::derived_mark () const scm_gc_mark (subfonts_); } +Stencil +Pango_font::pango_item_string_stencil (PangoItem *item, String str) const +{ + const int GLYPH_NAME_LEN = 256; + char glyph_name[GLYPH_NAME_LEN]; + PangoAnalysis *pa = &(item->analysis); + PangoGlyphString *pgs = pango_glyph_string_new (); + + pango_shape (str.to_str0 () + item->offset, + item->length, pa, pgs); + + PangoRectangle logical_rect; + PangoRectangle ink_rect; + pango_glyph_string_extents (pgs, pa->font, &ink_rect, &logical_rect); + + PangoFcFont *fcfont = G_TYPE_CHECK_INSTANCE_CAST(pa->font, + PANGO_TYPE_FC_FONT, + PangoFcFont); + + FT_Face ftface = pango_fc_font_lock_face (fcfont); + Box b (Interval (PANGO_LBEARING(logical_rect), + PANGO_RBEARING(logical_rect)), + Interval (-PANGO_DESCENT(logical_rect), + PANGO_ASCENT(logical_rect))); + + b.scale (scale_); + + SCM glyph_exprs = SCM_EOL; + SCM *tail = &glyph_exprs; + for (int i = 0; i < pgs->num_glyphs; i++) + { + PangoGlyphInfo *pgi = pgs->glyphs + i; + + PangoGlyph pg = pgi->glyph; + PangoGlyphGeometry ggeo = pgi->geometry; + + FT_Get_Glyph_Name (ftface, pg, glyph_name, GLYPH_NAME_LEN); + *tail = scm_cons (scm_list_3 (scm_from_double (ggeo.x_offset * scale_), + scm_from_double (ggeo.y_offset * scale_), + scm_makfrom0str (glyph_name)), + SCM_EOL); + tail = SCM_CDRLOC (*tail); + } + + PangoFontDescription *descr = pango_font_describe (pa->font); + Real size = pango_font_description_get_size (descr) + / (Real (PANGO_SCALE)) ; + + FcPattern *fcpat = fcfont->font_pattern; + char *filename = 0; + FcPatternGetString(fcpat, FC_FILE, 0, (FcChar8 **) &filename); + char const *ps_name = FT_Get_Postscript_Name (ftface); + ((Pango_font *) this)->register_font_file (filename, ps_name); + pango_fc_font_unlock_face (fcfont); + + SCM expr = scm_list_4 (ly_symbol2scm ("glyph-string"), + scm_makfrom0str (ps_name), + scm_from_double (size), + ly_quote_scm (glyph_exprs)); + + Stencil item_stencil (b, expr); + return item_stencil; +} + Stencil Pango_font::text_stencil (String str) const { @@ -65,74 +129,21 @@ Pango_font::text_stencil (String str) const 0, str.length (), attribute_list_, NULL); - const int GLYPH_NAME_LEN = 256; - char glyph_name[GLYPH_NAME_LEN]; GList *ptr = items; - Stencil dest; + Stencil dest; + Real x = 0.0; while (ptr) { - - // FIXME: factor this out PangoItem *item = (PangoItem*) ptr->data; - PangoAnalysis *pa = &(item->analysis); - PangoGlyphString *pgs = pango_glyph_string_new (); - - pango_shape (str.to_str0 () + item->offset, - item->length, pa, pgs); - PangoRectangle logical_rect; - PangoRectangle ink_rect; - pango_glyph_string_extents (pgs, pa->font, &ink_rect, &logical_rect); - - PangoFcFont *fcfont = G_TYPE_CHECK_INSTANCE_CAST(pa->font, - PANGO_TYPE_FC_FONT, - PangoFcFont); - - FT_Face ftface = pango_fc_font_lock_face (fcfont); - Box b (Interval (PANGO_LBEARING(logical_rect), - PANGO_RBEARING(logical_rect)), - Interval (-PANGO_DESCENT(logical_rect), - PANGO_ASCENT(logical_rect))); - - b.scale (scale_); + Stencil item_stencil = pango_item_string_stencil (item, str); - SCM glyph_exprs = SCM_EOL; - SCM *tail = &glyph_exprs; - for (int i = 0; i < pgs->num_glyphs; i++) - { - PangoGlyphInfo *pgi = pgs->glyphs + i; - - PangoGlyph pg = pgi->glyph; - PangoGlyphGeometry ggeo = pgi->geometry; - - FT_Get_Glyph_Name (ftface, pg, glyph_name, GLYPH_NAME_LEN); - *tail = scm_cons (scm_list_3 (scm_from_double (ggeo.x_offset * scale_), - scm_from_double (ggeo.y_offset * scale_), - scm_makfrom0str (glyph_name)), - SCM_EOL); - tail = SCM_CDRLOC (*tail); - } - PangoFontDescription *descr = pango_font_describe (pa->font); - Real size = pango_font_description_get_size (descr) - / (Real (PANGO_SCALE)) ; + item_stencil.translate_axis (x, X_AXIS); + x += item_stencil.extent (X_AXIS)[RIGHT]; - FcPattern *fcpat = fcfont->font_pattern; - char *filename = 0; - FcPatternGetString(fcpat, FC_FILE, 0, (FcChar8 **) &filename); - char const *ps_name = FT_Get_Postscript_Name (ftface); - ((Pango_font *) this)->register_font_file (filename, ps_name); - - SCM expr = scm_list_4 (ly_symbol2scm ("glyph-string"), - scm_makfrom0str (ps_name), - scm_from_double (size), - ly_quote_scm (glyph_exprs)); - - Stencil item_stencil (b, expr); - dest.add_stencil (item_stencil); - pango_fc_font_unlock_face (fcfont); ptr = ptr->next; }