[util] If no text is provided, simply call cairo_show_glyphs()

This commit is contained in:
Behdad Esfahbod 2011-09-19 15:45:52 -04:00
parent 5c29934311
commit f6496663c2
1 changed files with 50 additions and 40 deletions

View File

@ -94,6 +94,8 @@ view_cairo_t::consume_line (hb_buffer_t *buffer,
hb_glyph_info_t *hb_glyph = hb_buffer_get_glyph_infos (buffer, NULL);
hb_glyph_position_t *hb_position = hb_buffer_get_glyph_positions (buffer, NULL);
l.glyphs = cairo_glyph_allocate (l.num_glyphs + 1);
if (text) {
l.utf8 = g_strndup (text, text_len);
l.utf8_len = text_len;
l.num_clusters = l.num_glyphs ? 1 : 0;
@ -101,6 +103,10 @@ view_cairo_t::consume_line (hb_buffer_t *buffer,
if (hb_glyph[i].cluster != hb_glyph[i-1].cluster)
l.num_clusters++;
l.clusters = cairo_text_cluster_allocate (l.num_clusters);
} else {
l.utf8_len = 0;
l.num_clusters = 0;
}
if ((l.num_glyphs && !l.glyphs) ||
(l.utf8_len && !l.utf8) ||
@ -126,6 +132,7 @@ view_cairo_t::consume_line (hb_buffer_t *buffer,
l.glyphs[i].x = x;
l.glyphs[i].y = y;
if (l.num_clusters) {
memset ((void *) l.clusters, 0, l.num_clusters * sizeof (l.clusters[0]));
bool backward = HB_DIRECTION_IS_BACKWARD (hb_buffer_get_direction (buffer));
l.cluster_flags = backward ? CAIRO_TEXT_CLUSTER_FLAG_BACKWARD : (cairo_text_cluster_flags_t) 0;
@ -154,6 +161,7 @@ view_cairo_t::consume_line (hb_buffer_t *buffer,
}
l.clusters[cluster].num_bytes += text_len - hb_glyph[i - 1].cluster;
}
}
done:
g_array_append_val (lines, l);
@ -476,12 +484,14 @@ view_cairo_t::draw (cairo_t *cr)
/* cairo_show_glyphs() doesn't support subpixel positioning */
cairo_glyph_path (cr, l.glyphs, l.num_glyphs);
cairo_fill (cr);
} else
} else if (l.num_clusters)
cairo_show_text_glyphs (cr,
l.utf8, l.utf8_len,
l.glyphs, l.num_glyphs,
l.clusters, l.num_clusters,
l.cluster_flags);
else
cairo_show_glyphs (cr, l.glyphs, l.num_glyphs);
cairo_translate (cr, 0, font_extents.height - font_extents.ascent);
}