- if (len > 1
- && gstring.glyphs[1].c >= 0x300 && gstring.glyphs[1].c <= 0x36F)
- /* A little bit ad hoc. Perhaps, shaper must get script and
- language information, and select a proper flt for them
- here. */
- flt = mflt_get (msymbol ("combining"));
- for (i = 0; i < 3; i++)
- {
- int result = mflt_run (&gstring, 0, len, &flt_font_ft.flt_font, flt);
- if (result != -2)
- break;
- if (INT_MAX / 2 < gstring.allocated)
- memory_full (SIZE_MAX);
- gstring.glyphs = xnrealloc (gstring.glyphs,
- gstring.allocated, 2 * sizeof (MFLTGlyph));
- gstring.allocated *= 2;
+
+ if (1 < len)
+ {
+ /* A little bit ad hoc. Perhaps, shaper must get script and
+ language information, and select a proper flt for them
+ here. */
+ int c1 = LGLYPH_CHAR (LGSTRING_GLYPH (lgstring, 1));
+ /* For the combining characters in the range U+300..U+36F,
+ "combining" is the sole FLT provided by the m17n-lib. In
+ addition, it is the sole FLT that can handle the other
+ combining characters with non-OTF fonts. */
+ if ((0x300 <= c1 && c1 <= 0x36F)
+ || (! otf && CHAR_HAS_CATEGORY (c1, '^')))
+ flt = mflt_get (msymbol ("combining"));
+ }
+ if (! flt && ! otf)
+ {
+ flt = mflt_find (LGLYPH_CHAR (LGSTRING_GLYPH (lgstring, 0)),
+ &flt_font_ft.flt_font);
+ if (! flt)
+ return make_number (0);
+ }
+
+ MFLTGlyphFT *glyphs = (MFLTGlyphFT *) gstring.glyphs;
+ ptrdiff_t allocated = gstring.allocated;
+ ptrdiff_t incr_min = len - allocated;
+
+ do
+ {
+ if (0 < incr_min)
+ {
+ xfree (glyphs);
+ glyphs = xpalloc (NULL, &allocated, incr_min, INT_MAX, sizeof *glyphs);
+ }
+ incr_min = 1;
+
+ for (i = 0; i < len; i++)
+ {
+ Lisp_Object g = LGSTRING_GLYPH (lgstring, i);
+ memset (&glyphs[i], 0, sizeof glyphs[i]);
+ glyphs[i].g.c = LGLYPH_CHAR (g);
+ if (with_variation_selector)
+ {
+ glyphs[i].g.code = LGLYPH_CODE (g);
+ glyphs[i].g.encoded = 1;
+ }
+ }
+
+ gstring.glyph_size = sizeof *glyphs;
+ gstring.glyphs = (MFLTGlyph *) glyphs;
+ gstring.allocated = allocated;
+ gstring.used = len;
+ gstring.r2l = 0;