379 if (graphemes) graphemes->clear();
388 const char32 kDottedCircleGlyph = 9676;
389 bool bad_glyph =
false;
390 PangoFontMap* font_map = pango_cairo_font_map_get_default();
391 PangoContext* context = pango_context_new();
392 pango_context_set_font_map(context, font_map);
397 layout = pango_layout_new(context);
400 pango_layout_set_font_description(layout, desc_);
402 PangoFontDescription *desc = pango_font_description_from_string(
404 pango_layout_set_font_description(layout, desc);
405 pango_font_description_free(desc);
407 pango_layout_set_text(layout, utf8_word, len);
408 PangoLayoutIter* run_iter =
NULL;
411 run_iter = pango_layout_get_iter(layout);
414 PangoLayoutRun* run = pango_layout_iter_get_run_readonly(run_iter);
416 tlog(2,
"Found end of line NULL run marker\n");
419 PangoGlyph dotted_circle_glyph;
420 PangoFont* font = run->item->analysis.font;
421 dotted_circle_glyph = pango_fc_font_get_glyph(
422 reinterpret_cast<PangoFcFont*>(font), kDottedCircleGlyph);
424 PangoFontDescription* desc = pango_font_describe(font);
425 char* desc_str = pango_font_description_to_string(desc);
426 tlog(2,
"Desc of font in run: %s\n", desc_str);
428 pango_font_description_free(desc);
431 PangoGlyphItemIter cluster_iter;
432 gboolean have_cluster;
433 for (have_cluster = pango_glyph_item_iter_init_start(&cluster_iter,
435 have_cluster && !bad_glyph;
436 have_cluster = pango_glyph_item_iter_next_cluster(&cluster_iter)) {
437 const int start_byte_index = cluster_iter.start_index;
438 const int end_byte_index = cluster_iter.end_index;
439 int start_glyph_index = cluster_iter.start_glyph;
440 int end_glyph_index = cluster_iter.end_glyph;
441 string cluster_text = string(utf8_word + start_byte_index,
442 end_byte_index - start_byte_index);
443 if (graphemes) graphemes->push_back(cluster_text);
445 tlog(2,
"Skipping whitespace\n");
449 printf(
"start_byte=%d end_byte=%d start_glyph=%d end_glyph=%d ",
450 start_byte_index, end_byte_index,
451 start_glyph_index, end_glyph_index);
453 for (
int i = start_glyph_index,
454 step = (end_glyph_index > start_glyph_index) ? 1 : -1;
455 !bad_glyph && i != end_glyph_index; i+= step) {
456 const bool unknown_glyph =
457 (cluster_iter.glyph_item->glyphs->glyphs[i].glyph &
458 PANGO_GLYPH_UNKNOWN_FLAG);
459 const bool illegal_glyph =
460 (cluster_iter.glyph_item->glyphs->glyphs[i].glyph ==
461 dotted_circle_glyph);
462 bad_glyph = unknown_glyph || illegal_glyph;
464 printf(
"(%d=%d)", cluster_iter.glyph_item->glyphs->glyphs[i].glyph,
469 printf(
" '%s'\n", cluster_text.c_str());
472 tlog(1,
"Found illegal glyph!\n");
474 }
while (!bad_glyph && pango_layout_iter_next_run(run_iter));
476 pango_layout_iter_free(run_iter);
477 g_object_unref(context);
478 g_object_unref(layout);
479 if (bad_glyph && graphemes) graphemes->clear();
#define DISABLE_HEAP_LEAK_CHECK
bool CoversUTF8Text(const char *utf8_text, int byte_length) const
bool IsUTF8Whitespace(const char *text)
string DescriptionName() const
#define TLOG_IS_ON(level)