diff options
| author | Nathan Reiner <nathan@nathanreiner.xyz> | 2023-04-12 23:31:26 +0200 |
|---|---|---|
| committer | Nathan Reiner <nathan@nathanreiner.xyz> | 2023-04-12 23:31:26 +0200 |
| commit | 4ed0d0fe018adea8ef2f7f1308c38e8e9c2873a7 (patch) | |
| tree | 0ab3c9b6e93f5d75e1ea25fc5d0e379f876b176a /drw.c | |
| parent | c7ebccb81d7a31b5bbfabdb533e665eb2ddb929c (diff) | |
add optional boldstrokemode
Diffstat (limited to 'drw.c')
| -rw-r--r-- | drw.c | 33 |
1 files changed, 29 insertions, 4 deletions
@@ -9,6 +9,8 @@ #include "drw.h" #include "util.h" +extern int boldstokemode; + /* static function declarations */ static Color to_color(uint32_t color); static uint32_t to_uint32_t(Color color); @@ -172,7 +174,7 @@ font_cache_generate_box(FontCache *fontcache) { Font *font = get_font_with_charcode(fontcache, 0); FT_Set_Pixel_Sizes(font->face, 0, fontcache->fontsize); - fontcache->box.width = (font->face->size->metrics.max_advance) >> 6; + fontcache->box.width = ((font->face->size->metrics.max_advance) >> 6); fontcache->box.height = (font->face->size->metrics.height) >> 6; } @@ -330,10 +332,21 @@ draw_char(Canvas *canvas, FontCache *fontcache, uint_least32_t charcode, unsigne FT_Bool has_kerning; FT_Vector delta; Font *current_font; + FT_Stroker stroker; current_font = get_font_with_charcode(fontcache, charcode); FT_Set_Pixel_Sizes(current_font->face, 0, fontcache->fontsize); + if (boldstokemode && fontcache->fonttype == FONT_BOLD) { + FT_Stroker_New(current_font->library, &stroker); + FT_Stroker_Set(stroker, fontcache->fontsize * 2, FT_STROKER_LINECAP_ROUND, FT_STROKER_LINEJOIN_ROUND, fontcache->fontsize * 2); + + y -= fontcache->fontsize * 2 / 64 + 1; + } else { + FT_Stroker_New(current_font->library, &stroker); + FT_Stroker_Set(stroker, 0, FT_STROKER_LINECAP_ROUND, FT_STROKER_LINEJOIN_ROUND, 0); + } + slot = current_font->face->glyph; glyph_index = FT_Get_Char_Index(current_font->face, charcode); @@ -343,15 +356,27 @@ draw_char(Canvas *canvas, FontCache *fontcache, uint_least32_t charcode, unsigne x += delta.x >> 6; } - error = FT_Load_Glyph(current_font->face, glyph_index, FT_LOAD_RENDER); + error = FT_Load_Glyph(current_font->face, glyph_index, FT_LOAD_DEFAULT); if (error) { fprintf(stderr, "warning: char not loaded, skipping...\n"); return x; } - draw_bitmap(canvas, &slot->bitmap, x + slot->bitmap_left, y - slot->bitmap_top, color); + FT_Glyph glyph; + FT_Get_Glyph(slot, &glyph); + FT_Glyph_StrokeBorder(&glyph, stroker, 0, 1); + if (error) { + fprintf(stderr, "warning: could not apply stroke\n"); + return x; + } + + FT_Glyph_To_Bitmap(&glyph, FT_RENDER_MODE_NORMAL, 0, 1); + + FT_BitmapGlyph bg = (FT_BitmapGlyph)glyph; + + draw_bitmap(canvas, &bg->bitmap, x + bg->left, y - bg->top, color); - x += slot->advance.x >> 6; + x += fontcache->box.width >> 6; return x; } |