diff options
| -rw-r--r-- | drw.c | 60 | ||||
| -rw-r--r-- | drw.h | 5 | ||||
| -rw-r--r-- | swt.c | 2 |
3 files changed, 44 insertions, 23 deletions
@@ -14,8 +14,14 @@ extern int boldstokemode; typedef struct { - FT_Glyph glyph; - FT_BitmapGlyph bg; + struct { + FT_Glyph glyph; + FT_BitmapGlyph bg; + } normal; + struct { + FT_Glyph glyph; + FT_BitmapGlyph bg; + } bold; } CacheGlyph; /* static function declarations */ @@ -304,7 +310,8 @@ init_font(Font *font) FT_Stroker_New(font->library, &font->stroke); font->loaded = 1; - memset(font->cache, 0, CACHE_SIZE); + memset(font->cache.normal, 0, CACHE_SIZE); + memset(font->cache.bold, 0, CACHE_SIZE); } @@ -388,19 +395,21 @@ get_font_with_charcode(FontCache *fontcache, uint_least32_t charcode) CacheGlyph load_bitmap(Font *font, uint_least32_t charcode) { - CacheGlyph cglyph = { .bg = 0, .glyph = 0 }; + CacheGlyph cglyph = { 0 }; FT_Bool has_kerning; FT_Vector delta; FT_UInt glyph_index; FT_Error error; FT_GlyphSlot slot; FT_BitmapGlyph bg; + FT_BitmapGlyph bg_bold; FT_Glyph glyph; + FT_Glyph glyph_bold; slot = font->face->glyph; glyph_index = FT_Get_Char_Index(font->face, charcode); - if (glyph_index >= CACHE_SIZE || font->cache[glyph_index] == 0) { + if (glyph_index >= CACHE_SIZE || font->cache.normal[glyph_index] == 0) { has_kerning = FT_HAS_KERNING(font->face); if (has_kerning && glyph_index) { FT_Get_Kerning(font->face, 0, glyph_index, FT_KERNING_DEFAULT, &delta); @@ -413,25 +422,30 @@ load_bitmap(Font *font, uint_least32_t charcode) } FT_Get_Glyph(slot, &glyph); - error = FT_Glyph_StrokeBorder(&glyph, font->stroke, 0, 1); - if (error) { - fprintf(stderr, "warning: could not apply stroke\n"); - return cglyph; - } + FT_Glyph_Copy(glyph, &glyph_bold); + + FT_Outline_Embolden(&((FT_OutlineGlyph)glyph_bold)->outline, (FT_Fixed)(0.5f * (float)(1 << 6))); FT_Glyph_To_Bitmap(&glyph, FT_RENDER_MODE_NORMAL, 0, 1); bg = (FT_BitmapGlyph)glyph; + FT_Glyph_To_Bitmap(&glyph_bold, FT_RENDER_MODE_NORMAL, 0, 1); + bg_bold = (FT_BitmapGlyph)glyph_bold; + if (glyph_index >= CACHE_SIZE) { - cglyph.glyph = glyph; + cglyph.normal.glyph = glyph; + cglyph.bold.glyph = glyph_bold; } else { - font->cache[glyph_index] = bg; + font->cache.normal[glyph_index] = bg; + font->cache.bold[glyph_index] = bg_bold; } } else { - bg = font->cache[glyph_index]; + bg = font->cache.normal[glyph_index]; + bg_bold = font->cache.bold[glyph_index]; } - cglyph.bg = bg; + cglyph.normal.bg = bg; + cglyph.bold.bg = bg_bold; return cglyph; } @@ -447,21 +461,25 @@ draw_char(Canvas *canvas, FontCache *fontcache, uint_least32_t charcode, unsigne FT_Set_Pixel_Sizes(font->face, 0, fontcache->fontsize); if (boldstokemode && fontcache->fonttype == FONT_BOLD) { - stroke_size = fontcache->fontsize * 2; + stroke_size = 0; } else { stroke_size = 0; } - FT_Stroker_Set(font->stroke, stroke_size, FT_STROKER_LINECAP_SQUARE, FT_STROKER_LINEJOIN_BEVEL, 0); - cg = load_bitmap(font, charcode); - if (cg.bg == 0) + if (cg.normal.bg == 0) return; - draw_bitmap(canvas, &cg.bg->bitmap, x + cg.bg->left, y - cg.bg->top, color); + if (boldstokemode && fontcache->fonttype == FONT_BOLD) + draw_bitmap(canvas, &cg.bold.bg->bitmap, x + cg.bold.bg->left, y - cg.bold.bg->top, color); + else + draw_bitmap(canvas, &cg.normal.bg->bitmap, x + cg.normal.bg->left, y - cg.normal.bg->top, color); + + if (cg.normal.glyph) + FT_Done_Glyph(cg.normal.glyph); - if (cg.glyph) - FT_Done_Glyph(cg.glyph); + if (cg.bold.glyph) + FT_Done_Glyph(cg.bold.glyph); } @@ -33,7 +33,10 @@ typedef struct { FT_Library library; FT_Face face; FT_Stroker stroke; - FT_BitmapGlyph cache[CACHE_SIZE]; + struct { + FT_BitmapGlyph normal[CACHE_SIZE]; + FT_BitmapGlyph bold[CACHE_SIZE]; + } cache; } Font; enum FontType { @@ -224,7 +224,7 @@ get_color(uint32_t i, ushort mode) return i; } - if ((mode & ATTR_BOLD)) { + if ((mode & ATTR_BOLD) && i < 8) { if (!BETWEEN(i + 8, 0, sizeof(colors) / sizeof(uint32_t))) { return colors[i]; } |