]> git.donarmstrong.com Git - lilypond.git/commitdiff
(text_stencil): export size as well.
authorHan-Wen Nienhuys <hanwen@xs4all.nl>
Thu, 30 Dec 2004 00:01:21 +0000 (00:01 +0000)
committerHan-Wen Nienhuys <hanwen@xs4all.nl>
Thu, 30 Dec 2004 00:01:21 +0000 (00:01 +0000)
(text_stencil): fix scaling and extents box.

lily/include/pango-font.hh
lily/pango-font.cc

index 36aa04c391a95a1127b29970e355c680d6945726..de98e8194a3638b480ceb4ae6fe3578b2ecaeef3 100644 (file)
@@ -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;
index dd93df8d6abbdda8a2c3c268dddbdb69d65a49b0..52b7dd9bba43cd3802dd9638f08b3ee3b5b86923 100644 (file)
@@ -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;      
     }