X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=lily%2Fpango-font.cc;h=1b90dcfed37be657483adf359f40d8687305b0d2;hb=1a9d44f4edf9c0b3bc12d399491ca7001743b539;hp=b32a77004951573311a4473012f3ebe21af28bbe;hpb=9f113012b3cdfab51066c023e18579e183d1ad94;p=lilypond.git diff --git a/lily/pango-font.cc b/lily/pango-font.cc index b32a770049..1b90dcfed3 100644 --- a/lily/pango-font.cc +++ b/lily/pango-font.cc @@ -1,9 +1,20 @@ /* - pango-font.cc -- implement Pango_font + This file is part of LilyPond, the GNU music typesetter. - source file of the GNU LilyPond music typesetter + Copyright (C) 2004--2009 Han-Wen Nienhuys - (c) 2004--2009 Han-Wen Nienhuys + LilyPond is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + LilyPond is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with LilyPond. If not, see . */ #define PANGO_ENABLE_BACKEND // ugh, why necessary? @@ -97,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; @@ -164,6 +172,13 @@ Pango_font::pango_item_string_stencil (PangoItem const *item, PangoGlyph pg = pgi->glyph; PangoGlyphGeometry ggeo = pgi->geometry; + /* + Zero-width characters are valid Unicode characters, + but glyph lookups need to be skipped. + */ + if (!(pg ^ PANGO_GLYPH_EMPTY)) + continue; + glyph_name[0] = '\0'; if (has_glyph_names) { @@ -301,50 +316,44 @@ 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); + GSList *lines = pango_layout_get_lines (layout); Stencil dest; - Real last_x = 0.0; - Direction text_dir = RIGHT; - for (GList *p = items; p; p = p->next) - { - PangoItem *item = (PangoItem *) p->data; - if (item->analysis.level == PANGO_DIRECTION_RTL) - text_dir = LEFT; - } - - for (GList *ptr = items; ptr; ptr = ptr->next) + for (GSList *l = lines; l; l = l->next) { - PangoItem *item = (PangoItem *) ptr->data; - - Stencil item_stencil = pango_item_string_stencil (item, str, tight); + PangoLayoutLine *line = (PangoLayoutLine *) l->data; + GSList *layout_runs = line->runs; - if (text_dir == RIGHT) + for (GSList *p = layout_runs; p; p = p->next) { + 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]; - } - else if (text_dir == LEFT) - dest.translate_axis (item_stencil.extent (X_AXIS)[RIGHT], X_AXIS); #if 0 // Check extents. - if (!item_stencil.extent_box ()[X_AXIS].is_empty ()) - { - Stencil frame = Lookup::frame (item_stencil.extent_box (), 0.1, 0.1); - Box empty; - empty.set_empty (); - Stencil dimless_frame (empty, frame.expr ()); - dest.add_stencil (frame); - } + if (!item_stencil.extent_box ()[X_AXIS].is_empty ()) + { + Stencil frame = Lookup::frame (item_stencil.extent_box (), 0.1, 0.1); + Box empty; + empty.set_empty (); + Stencil dimless_frame (empty, frame.expr ()); + dest.add_stencil (frame); + } #endif - dest.add_stencil (item_stencil); + dest.add_stencil (item_stencil); + } } string name = get_output_backend_name (); @@ -384,8 +393,6 @@ Pango_font::text_stencil (string str, return Stencil (b, exp); } - g_list_free (items); - return dest; }