395 if (graphemes) graphemes->clear();
404 const char32 kDottedCircleGlyph = 9676;
405 bool bad_glyph =
false;
406 PangoFontMap* font_map = pango_cairo_font_map_get_default();
407 PangoContext* context = pango_context_new();
408 pango_context_set_font_map(context, font_map);
413 layout = pango_layout_new(context);
416 pango_layout_set_font_description(layout, desc_);
418 PangoFontDescription *desc = pango_font_description_from_string(
420 pango_layout_set_font_description(layout, desc);
421 pango_font_description_free(desc);
423 pango_layout_set_text(layout, utf8_word, len);
424 PangoLayoutIter* run_iter = NULL;
427 run_iter = pango_layout_get_iter(layout);
430 PangoLayoutRun* run = pango_layout_iter_get_run_readonly(run_iter);
432 tlog(2,
"Found end of line NULL run marker\n");
435 PangoGlyph dotted_circle_glyph;
436 PangoFont* font = run->item->analysis.font;
438 #ifdef _WIN32 // Fixme! Leaks memory and breaks unittests. 439 PangoGlyphString* glyphs = pango_glyph_string_new();
440 char s[] =
"\xc2\xa7";
441 pango_shape(s,
sizeof(s), &(run->item->analysis), glyphs);
442 dotted_circle_glyph = glyphs->glyphs[0].glyph;
444 dotted_circle_glyph = pango_fc_font_get_glyph(
445 reinterpret_cast<PangoFcFont*>(font), kDottedCircleGlyph);
449 PangoFontDescription* desc = pango_font_describe(font);
450 char* desc_str = pango_font_description_to_string(desc);
451 tlog(2,
"Desc of font in run: %s\n", desc_str);
453 pango_font_description_free(desc);
456 PangoGlyphItemIter cluster_iter;
457 gboolean have_cluster;
458 for (have_cluster = pango_glyph_item_iter_init_start(&cluster_iter,
460 have_cluster && !bad_glyph;
461 have_cluster = pango_glyph_item_iter_next_cluster(&cluster_iter)) {
462 const int start_byte_index = cluster_iter.start_index;
463 const int end_byte_index = cluster_iter.end_index;
464 int start_glyph_index = cluster_iter.start_glyph;
465 int end_glyph_index = cluster_iter.end_glyph;
466 string cluster_text = string(utf8_word + start_byte_index,
467 end_byte_index - start_byte_index);
468 if (graphemes) graphemes->push_back(cluster_text);
470 tlog(2,
"Skipping whitespace\n");
474 printf(
"start_byte=%d end_byte=%d start_glyph=%d end_glyph=%d ",
475 start_byte_index, end_byte_index,
476 start_glyph_index, end_glyph_index);
478 for (
int i = start_glyph_index,
479 step = (end_glyph_index > start_glyph_index) ? 1 : -1;
480 !bad_glyph && i != end_glyph_index; i+= step) {
481 const bool unknown_glyph =
482 (cluster_iter.glyph_item->glyphs->glyphs[i].glyph &
483 PANGO_GLYPH_UNKNOWN_FLAG);
484 const bool illegal_glyph =
485 (cluster_iter.glyph_item->glyphs->glyphs[i].glyph ==
486 dotted_circle_glyph);
487 bad_glyph = unknown_glyph || illegal_glyph;
489 printf(
"(%d=%d)", cluster_iter.glyph_item->glyphs->glyphs[i].glyph,
494 printf(
" '%s'\n", cluster_text.c_str());
497 tlog(1,
"Found illegal glyph!\n");
499 }
while (!bad_glyph && pango_layout_iter_next_run(run_iter));
501 pango_layout_iter_free(run_iter);
502 g_object_unref(context);
503 g_object_unref(layout);
504 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