]> git.donarmstrong.com Git - lilypond.git/commitdiff
Fix #927.
authorPatrick McCarty <pnorcks@gmail.com>
Sun, 13 Dec 2009 11:17:40 +0000 (03:17 -0800)
committerPatrick McCarty <pnorcks@gmail.com>
Sun, 13 Dec 2009 18:44:11 +0000 (10:44 -0800)
Use the PangoLayout interface for processing text stencils; this way,
the Unicode Bidirectional Algorithm will be applied, if necessary, to
the text.  As a result, all LTR/RTL/bidi issues are now handled
automatically by Pango.

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

index a0e503735d165669a0ce3021e5438b397034a89a..fbd4730c7c97e7f80dadb8b9854687a35b32fee8 100644 (file)
@@ -51,7 +51,7 @@ public:
   void register_font_file (string, string, int);
   Stencil text_stencil (string, bool, bool) const;
 
-  Stencil pango_item_string_stencil (PangoItem const *, string, bool) const;
+  Stencil pango_item_string_stencil (PangoGlyphItem const *, bool) const;
 
   virtual Stencil word_stencil (string, bool) const;
   virtual Stencil text_stencil (string, bool) const;
index ead47963e29c6703850502ecc78f0df7a3f15c90..2e7ea0a6bbd56524199d71b0f34a564ebcacfb05 100644 (file)
@@ -108,17 +108,14 @@ get_unicode_name (char *s,
 }
 
 Stencil
-Pango_font::pango_item_string_stencil (PangoItem const *item,
-                                      string str,
+Pango_font::pango_item_string_stencil (PangoGlyphItem const *glyph_item,
                                       bool tight_bbox) const
 {
   const int GLYPH_NAME_LEN = 256;
   char glyph_name[GLYPH_NAME_LEN];
-  PangoAnalysis const *pa = &(item->analysis);
-  PangoGlyphString *pgs = pango_glyph_string_new ();
 
-  pango_shape (str.c_str () + item->offset,
-              item->length, (PangoAnalysis*) pa, pgs);
+  PangoAnalysis const *pa = &(glyph_item->item->analysis);
+  PangoGlyphString *pgs = glyph_item->glyphs;
 
   PangoRectangle logical_rect;
   PangoRectangle ink_rect;
@@ -316,26 +313,23 @@ Pango_font::text_stencil (string str,
                          bool feta,
                          bool tight) const
 {
-  GList *items
-    = pango_itemize (context_,
-                    str.c_str (),
-                    0, str.length (), attribute_list_,
-                    NULL);
+  /*
+    The text assigned to a PangoLayout is automatically divided
+    into sections and reordered according to the Unicode
+    Bidirectional Algorithm, if necessary.
+  */
+  PangoLayout *layout = pango_layout_new (context_);
+  pango_layout_set_text (layout, str.c_str (), -1);
+  PangoLayoutLine *line = pango_layout_get_line (layout, 0);
+  GSList *layout_runs = line->runs;
 
   Stencil dest;
-
   Real last_x = 0.0;
 
-  /*
-    FIXME: The Unicode Bidirectional Algorithm needs to be
-    implemented here.  Right now, a simplistic approach is taken:
-    a left-to-right ordering of each item in the GList.
-  */
-  for (GList *ptr = items; ptr; ptr = ptr->next)
+  for (GSList *p = layout_runs; p; p = p->next)
     {
-      PangoItem *item = (PangoItem *) ptr->data;
-
-      Stencil item_stencil = pango_item_string_stencil (item, str, tight);
+      PangoGlyphItem *item = (PangoGlyphItem *) p->data;
+      Stencil item_stencil = pango_item_string_stencil (item, tight);
 
       item_stencil.translate_axis (last_x, X_AXIS);
       last_x = item_stencil.extent (X_AXIS)[RIGHT];
@@ -391,8 +385,6 @@ Pango_font::text_stencil (string str,
       return Stencil (b, exp);
     }
 
-  g_list_free (items);
-
   return dest;
 }