+
+ return 0;
+}
+
+int init_glyphs(Font *font, FT_Face face, const Range *range, bool autohinter)
+{
+ unsigned i, j;
+ unsigned size = font->n_glyphs;
+
+ for(i=range->first; i<=range->last; ++i)
+ {
+ unsigned n;
+ FT_Bitmap *bmp = &face->glyph->bitmap;
+ int flags = 0;
+ Glyph *glyph;
+
+ n = FT_Get_Char_Index(face, i);
+ if(!n)
+ continue;
+
+ if(autohinter)
+ flags |= FT_LOAD_FORCE_AUTOHINT;
+ FT_Load_Glyph(face, n, flags);
+ FT_Render_Glyph(face->glyph, FT_RENDER_MODE_NORMAL);
+
+ if(verbose>=2)
+ {
+ printf(" Code point U+%04X", i);
+ if(i>=0x20 && i<0x7F)
+ printf(" (%c)", i);
+ else if(i>=0xA0 && i<=0x10FFFF)
+ {
+ char utf8[5];
+ unsigned bytes;
+
+ for(bytes=2; i>>(1+bytes*5); ++bytes) ;
+ for(j=0; j<bytes; ++j)
+ utf8[j] = 0x80 | ((i>>((bytes-j-1)*6))&0x3F);
+ utf8[0] |= 0xF0<<(4-bytes);
+ utf8[j] = 0;
+
+ printf(" (%s)", utf8);
+ }
+ printf(": glyph %u, size %dx%d\n", n, bmp->width, bmp->rows);
+ }
+
+ if(bmp->pixel_mode!=FT_PIXEL_MODE_GRAY && bmp->pixel_mode!=FT_PIXEL_MODE_MONO)
+ {
+ fprintf(stderr, "Warning: Glyph %u skipped, incompatible pixel mode\n", n);
+ continue;
+ }
+
+ if(font->n_glyphs>=size)
+ {
+ size += 16;
+ font->glyphs = (Glyph *)realloc(font->glyphs, size*sizeof(Glyph));
+ }
+
+ glyph = &font->glyphs[font->n_glyphs++];
+ glyph->index = n;
+ glyph->code = i;
+ glyph->offset_x = face->glyph->bitmap_left;
+ glyph->offset_y = face->glyph->bitmap_top-bmp->rows;
+ glyph->advance = (int)(face->glyph->advance.x+32)/64;
+
+ /* Copy the glyph image since FreeType uses a global buffer, which would
+ be overwritten by the next glyph. Negative pitch means the scanlines
+ start from the bottom. */
+ if(copy_bitmap(bmp, &glyph->image))
+ return -1;
+ }
+
+ return 0;