memononen / nanovg

Antialiased 2D vector drawing library on top of OpenGL for UI and visualizations.
zlib License
5.16k stars 774 forks source link

Truetype font with embedded bitmap font show failed #499

Open wtjcn opened 6 years ago

wtjcn commented 6 years ago

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.

wtjcn commented 2 years ago

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++];
            }
        }
    }

}