diff options
Diffstat (limited to 'source/blender/blenfont/intern/blf_glyph.c')
-rw-r--r-- | source/blender/blenfont/intern/blf_glyph.c | 55 |
1 files changed, 49 insertions, 6 deletions
diff --git a/source/blender/blenfont/intern/blf_glyph.c b/source/blender/blenfont/intern/blf_glyph.c index 0d694c28b2b..b1cc4ba3084 100644 --- a/source/blender/blenfont/intern/blf_glyph.c +++ b/source/blender/blenfont/intern/blf_glyph.c @@ -1,4 +1,4 @@ -/** +/* * $Id$ * * ***** BEGIN GPL LICENSE BLOCK ***** @@ -36,10 +36,12 @@ #include FT_FREETYPE_H #include FT_GLYPH_H #include FT_OUTLINE_H +#include FT_BITMAP_H #include "MEM_guardedalloc.h" #include "DNA_vec_types.h" +#include "DNA_userdef_types.h" #include "BLI_blenlib.h" @@ -113,6 +115,23 @@ GlyphCacheBLF *blf_glyph_cache_new(FontBLF *font) return(gc); } +void blf_glyph_cache_clear(FontBLF *font) +{ + GlyphCacheBLF *gc; + GlyphBLF *g; + int i; + + for(gc=font->cache.first; gc; gc=gc->next) { + for (i= 0; i < 257; i++) { + while (gc->bucket[i].first) { + g= gc->bucket[i].first; + BLI_remlink(&(gc->bucket[i]), g); + blf_glyph_free(g); + } + } + } +} + void blf_glyph_cache_free(GlyphCacheBLF *gc) { GlyphBLF *g; @@ -185,12 +204,13 @@ GlyphBLF *blf_glyph_search(GlyphCacheBLF *gc, unsigned int c) return(NULL); } -GlyphBLF *blf_glyph_add(FontBLF *font, FT_UInt index, unsigned int c) +GlyphBLF *blf_glyph_add(FontBLF *font, unsigned int index, unsigned int c) { FT_GlyphSlot slot; GlyphBLF *g; FT_Error err; - FT_Bitmap bitmap; + FT_Bitmap bitmap, tempbitmap; + int sharp = (U.text_render & USER_TEXT_DISABLE_AA); FT_BBox bbox; unsigned int key; @@ -198,14 +218,29 @@ GlyphBLF *blf_glyph_add(FontBLF *font, FT_UInt index, unsigned int c) if (g) return(g); - err= FT_Load_Glyph(font->face, index, FT_LOAD_NO_HINTING | FT_LOAD_NO_BITMAP); + if (sharp) + err = FT_Load_Glyph(font->face, (FT_UInt)index, FT_LOAD_TARGET_MONO); + else + err = FT_Load_Glyph(font->face, (FT_UInt)index, FT_LOAD_TARGET_NORMAL | FT_LOAD_NO_HINTING | FT_LOAD_NO_BITMAP); /* Sure about NO_* flags? */ if (err) return(NULL); /* get the glyph. */ slot= font->face->glyph; - err= FT_Render_Glyph(slot, FT_RENDER_MODE_NORMAL); + if (sharp) { + err = FT_Render_Glyph(slot, FT_RENDER_MODE_MONO); + + /* Convert result from 1 bit per pixel to 8 bit per pixel */ + /* Accum errors for later, fine if not interested beyond "ok vs any error" */ + FT_Bitmap_New(&tempbitmap); + err += FT_Bitmap_Convert(font->ft_lib, &slot->bitmap, &tempbitmap, 1); /* Does Blender use Pitch 1 always? It works so far */ + err += FT_Bitmap_Copy(font->ft_lib, &tempbitmap, &slot->bitmap); + err += FT_Bitmap_Done(font->ft_lib, &tempbitmap); + } else { + err = FT_Render_Glyph(slot, FT_RENDER_MODE_NORMAL); + } + if (err || slot->format != FT_GLYPH_FORMAT_BITMAP) return(NULL); @@ -213,7 +248,7 @@ GlyphBLF *blf_glyph_add(FontBLF *font, FT_UInt index, unsigned int c) g->next= NULL; g->prev= NULL; g->c= c; - g->idx= index; + g->idx= (FT_UInt)index; g->tex= 0; g->build_tex= 0; g->bitmap= NULL; @@ -228,6 +263,14 @@ GlyphBLF *blf_glyph_add(FontBLF *font, FT_UInt index, unsigned int c) g->height= bitmap.rows; if (g->width && g->height) { + if (sharp) { + /* Font buffer uses only 0 or 1 values, Blender expects full 0..255 range */ + int i; + for (i=0; i < (g->width * g->height); i++) { + bitmap.buffer[i] = 255 * bitmap.buffer[i]; + } + } + g->bitmap= (unsigned char *)MEM_mallocN(g->width * g->height, "glyph bitmap"); memcpy((void *)g->bitmap, (void *)bitmap.buffer, g->width * g->height); } |