nanovg
nanovg copied to clipboard
Truetype font with embedded bitmap font show failed
Truetype font with embedded bitmap font show failed (show some noise point). But when the font size is not the bitmap font size, show is OK.
void fons__tt_renderGlyphBitmap(FONSttFontImpl *font, unsigned char *output, int outWidth, int outHeight, int outStride, float scaleX, float scaleY, int glyph) { FT_GlyphSlot ftGlyph = font->font->glyph; int x, y; FONS_NOTUSED(outWidth); FONS_NOTUSED(outHeight); FONS_NOTUSED(scaleX); FONS_NOTUSED(scaleY); FONS_NOTUSED(glyph); // glyph has already been loaded by fons__tt_buildGlyphBitmap
FT_Bitmap* bitmap= &font->font->glyph->bitmap;
if(bitmap->pixel_mode==FT_PIXEL_MODE_MONO){
int pitch = bitmap->pitch;
FT_Byte a;
for ( y = 0; y < bitmap->rows; y++ ) {
for ( x = 0; x < bitmap->width; x++ ) {
a = bitmap->buffer[y * pitch + x/8];
if(a&(0x80 >> (x % 8)))
output[(y * outStride) + x]=255;
}
}
}else{//(mode==2)
int ftGlyphOffset = 0;
for ( y = 0; y < bitmap->rows; y++ ) {
for ( x = 0; x < bitmap->width; x++ ) {
output[(y * outStride) + x] = bitmap->buffer[ftGlyphOffset++];
}
}
}
}