351 if (graphemes) graphemes->clear();
360 const char32 kDottedCircleGlyph = 9676;
361 bool bad_glyph =
false;
362 PangoFontMap* font_map = pango_cairo_font_map_get_default();
363 PangoContext* context = pango_context_new();
364 pango_context_set_font_map(context, font_map);
369 layout = pango_layout_new(context);
372 pango_layout_set_font_description(layout, desc_);
374 PangoFontDescription *desc = pango_font_description_from_string(
376 pango_layout_set_font_description(layout, desc);
377 pango_font_description_free(desc);
379 pango_layout_set_text(layout, utf8_word, len);
380 PangoLayoutIter* run_iter =
nullptr;
383 run_iter = pango_layout_get_iter(layout);
386 PangoLayoutRun* run = pango_layout_iter_get_run_readonly(run_iter);
388 tlog(2,
"Found end of line nullptr run marker\n");
391 PangoGlyph dotted_circle_glyph;
392 PangoFont* font = run->item->analysis.font;
394 #ifdef _WIN32 // Fixme! Leaks memory and breaks unittests. 395 PangoGlyphString* glyphs = pango_glyph_string_new();
396 char s[] =
"\xc2\xa7";
397 pango_shape(s,
sizeof(s), &(run->item->analysis), glyphs);
398 dotted_circle_glyph = glyphs->glyphs[0].glyph;
400 dotted_circle_glyph = pango_fc_font_get_glyph(
401 reinterpret_cast<PangoFcFont*>(font), kDottedCircleGlyph);
405 PangoFontDescription* desc = pango_font_describe(font);
406 char* desc_str = pango_font_description_to_string(desc);
407 tlog(2,
"Desc of font in run: %s\n", desc_str);
409 pango_font_description_free(desc);
412 PangoGlyphItemIter cluster_iter;
413 gboolean have_cluster;
414 for (have_cluster = pango_glyph_item_iter_init_start(&cluster_iter,
416 have_cluster && !bad_glyph;
417 have_cluster = pango_glyph_item_iter_next_cluster(&cluster_iter)) {
418 const int start_byte_index = cluster_iter.start_index;
419 const int end_byte_index = cluster_iter.end_index;
420 int start_glyph_index = cluster_iter.start_glyph;
421 int end_glyph_index = cluster_iter.end_glyph;
422 std::string cluster_text = std::string(utf8_word + start_byte_index,
423 end_byte_index - start_byte_index);
424 if (graphemes) graphemes->push_back(cluster_text);
426 tlog(2,
"Skipping whitespace\n");
430 printf(
"start_byte=%d end_byte=%d start_glyph=%d end_glyph=%d ",
431 start_byte_index, end_byte_index,
432 start_glyph_index, end_glyph_index);
434 for (
int i = start_glyph_index,
435 step = (end_glyph_index > start_glyph_index) ? 1 : -1;
436 !bad_glyph && i != end_glyph_index; i+= step) {
437 const bool unknown_glyph =
438 (cluster_iter.glyph_item->glyphs->glyphs[i].glyph &
439 PANGO_GLYPH_UNKNOWN_FLAG);
440 const bool illegal_glyph =
441 (cluster_iter.glyph_item->glyphs->glyphs[i].glyph ==
442 dotted_circle_glyph);
443 bad_glyph = unknown_glyph || illegal_glyph;
445 printf(
"(%d=%d)", cluster_iter.glyph_item->glyphs->glyphs[i].glyph,
450 printf(
" '%s'\n", cluster_text.c_str());
453 tlog(1,
"Found illegal glyph!\n");
455 }
while (!bad_glyph && pango_layout_iter_next_run(run_iter));
457 pango_layout_iter_free(run_iter);
458 g_object_unref(context);
459 g_object_unref(layout);
460 if (bad_glyph && graphemes) graphemes->clear();
#define DISABLE_HEAP_LEAK_CHECK
std::string DescriptionName() const
bool IsUTF8Whitespace(const char *text)
#define TLOG_IS_ON(level)
bool CoversUTF8Text(const char *utf8_text, int byte_length) const