- if (use_lcd) {
- if (FT_Load_Glyph(*j, glyph_index, FT_LOAD_RENDER | FT_LOAD_TARGET_LCD))
- throw std::runtime_error("Couldn't load glyph");
- } else {
- if (FT_Load_Glyph(*j, glyph_index, FT_LOAD_RENDER))
- throw std::runtime_error("Couldn't load glyph");
+ // Try to shape and render it in each of the fonts in turn.
+ for (std::vector<FT_Face>::const_iterator face_it = fonts.begin(); face_it != fonts.end(); ++face_it) {
+ // The buffer seemingly needs to be created anew for each try.
+ hb_buffer_t *hbuf = hb_buffer_create();
+ hb_buffer_set_unicode_funcs(hbuf, hb_icu_get_unicode_funcs());
+ hb_direction_t dir = PANGO_GRAVITY_IS_VERTICAL(analysis->gravity) ? HB_DIRECTION_TTB : HB_DIRECTION_LTR;
+ if (analysis->level % 2)
+ dir = HB_DIRECTION_REVERSE(dir);
+ if (PANGO_GRAVITY_IS_IMPROPER (analysis->gravity))
+ dir = HB_DIRECTION_REVERSE(dir);
+
+ hb_buffer_set_direction(hbuf, dir);
+ hb_buffer_set_script(hbuf, hb_glib_script_to_script((GUnicodeScript)analysis->script));
+ hb_buffer_set_language(hbuf, hb_language_from_string(pango_language_to_string(analysis->language), -1));
+ hb_buffer_add_utf8(hbuf, utf8str.data(), utf8str.size(), item->offset, item->length);
+
+ // Font-specifics.
+ FT_Face face = *face_it;
+ hb_font_t *font = hb_ft_font_create(face, NULL);
+ hb_shape(font, hbuf, NULL, 0);
+ unsigned glyph_count;
+ hb_glyph_info_t *glyph_info = hb_buffer_get_glyph_infos(hbuf, &glyph_count);
+ hb_glyph_position_t *glyph_pos = hb_buffer_get_glyph_positions(hbuf, &glyph_count);
+
+ bool found_all = true;
+ for (unsigned i = 0; i < glyph_count; ++i) {
+ if (glyph_info[i].codepoint == 0) {
+ found_all = false;
+ }
+ break;