344 if (graphemes) graphemes->clear();
353 const char32 kDottedCircleGlyph = 9676;
354 bool bad_glyph =
false;
355 PangoFontMap* font_map = pango_cairo_font_map_get_default();
356 PangoContext* context = pango_context_new();
357 pango_context_set_font_map(context, font_map);
362 layout = pango_layout_new(context);
365 pango_layout_set_font_description(layout, desc_);
367 PangoFontDescription *desc = pango_font_description_from_string(
369 pango_layout_set_font_description(layout, desc);
370 pango_font_description_free(desc);
372 pango_layout_set_text(layout, utf8_word, len);
373 PangoLayoutIter* run_iter = NULL;
376 run_iter = pango_layout_get_iter(layout);
379 PangoLayoutRun* run = pango_layout_iter_get_run_readonly(run_iter);
381 tlog(2,
"Found end of line NULL run marker\n");
384 PangoGlyph dotted_circle_glyph;
385 PangoFont* font = run->item->analysis.font;
387 #ifdef _WIN32 // Fixme! Leaks memory and breaks unittests. 388 PangoGlyphString* glyphs = pango_glyph_string_new();
389 char s[] =
"\xc2\xa7";
390 pango_shape(s,
sizeof(s), &(run->item->analysis), glyphs);
391 dotted_circle_glyph = glyphs->glyphs[0].glyph;
393 dotted_circle_glyph = pango_fc_font_get_glyph(
394 reinterpret_cast<PangoFcFont*>(font), kDottedCircleGlyph);
398 PangoFontDescription* desc = pango_font_describe(font);
399 char* desc_str = pango_font_description_to_string(desc);
400 tlog(2,
"Desc of font in run: %s\n", desc_str);
402 pango_font_description_free(desc);
405 PangoGlyphItemIter cluster_iter;
406 gboolean have_cluster;
407 for (have_cluster = pango_glyph_item_iter_init_start(&cluster_iter,
409 have_cluster && !bad_glyph;
410 have_cluster = pango_glyph_item_iter_next_cluster(&cluster_iter)) {
411 const int start_byte_index = cluster_iter.start_index;
412 const int end_byte_index = cluster_iter.end_index;
413 int start_glyph_index = cluster_iter.start_glyph;
414 int end_glyph_index = cluster_iter.end_glyph;
415 string cluster_text = string(utf8_word + start_byte_index,
416 end_byte_index - start_byte_index);
417 if (graphemes) graphemes->push_back(cluster_text);
419 tlog(2,
"Skipping whitespace\n");
423 printf(
"start_byte=%d end_byte=%d start_glyph=%d end_glyph=%d ",
424 start_byte_index, end_byte_index,
425 start_glyph_index, end_glyph_index);
427 for (
int i = start_glyph_index,
428 step = (end_glyph_index > start_glyph_index) ? 1 : -1;
429 !bad_glyph && i != end_glyph_index; i+= step) {
430 const bool unknown_glyph =
431 (cluster_iter.glyph_item->glyphs->glyphs[i].glyph &
432 PANGO_GLYPH_UNKNOWN_FLAG);
433 const bool illegal_glyph =
434 (cluster_iter.glyph_item->glyphs->glyphs[i].glyph ==
435 dotted_circle_glyph);
436 bad_glyph = unknown_glyph || illegal_glyph;
438 printf(
"(%d=%d)", cluster_iter.glyph_item->glyphs->glyphs[i].glyph,
443 printf(
" '%s'\n", cluster_text.c_str());
446 tlog(1,
"Found illegal glyph!\n");
448 }
while (!bad_glyph && pango_layout_iter_next_run(run_iter));
450 pango_layout_iter_free(run_iter);
451 g_object_unref(context);
452 g_object_unref(layout);
453 if (bad_glyph && graphemes) graphemes->clear();
bool CoversUTF8Text(const char *utf8_text, int byte_length) const
bool IsUTF8Whitespace(const char *text)
#define TLOG_IS_ON(level)
string DescriptionName() const
#define DISABLE_HEAP_LEAK_CHECK