aboutsummaryrefslogtreecommitdiff
path: root/drw.c
diff options
context:
space:
mode:
Diffstat (limited to 'drw.c')
-rw-r--r--drw.c74
1 files changed, 17 insertions, 57 deletions
diff --git a/drw.c b/drw.c
index b906eb9..ff30811 100644
--- a/drw.c
+++ b/drw.c
@@ -241,6 +241,8 @@ init_font(Font *font)
error = FT_Select_Charmap(font->face, ft_encoding_unicode);
if (error)
die("cannot set unicode");
+
+ FT_Stroker_New(font->library, &font->stroke);
}
@@ -331,92 +333,50 @@ draw_char(Canvas *canvas, FontCache *fontcache, uint_least32_t charcode, unsigne
FT_UInt previous = 0;
FT_Bool has_kerning;
FT_Vector delta;
- Font *current_font;
- FT_Stroker stroker;
+ Font *font;
+ FT_BitmapGlyph bg;
+ FT_Glyph glyph;
- current_font = get_font_with_charcode(fontcache, charcode);
- FT_Set_Pixel_Sizes(current_font->face, 0, fontcache->fontsize);
+ font = get_font_with_charcode(fontcache, charcode);
+ FT_Set_Pixel_Sizes(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);
+ FT_Stroker_Set(font->stroke, 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);
+ FT_Stroker_Set(font->stroke, 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);
+ slot = font->face->glyph;
+ glyph_index = FT_Get_Char_Index(font->face, charcode);
- has_kerning = FT_HAS_KERNING(current_font->face);
+ has_kerning = FT_HAS_KERNING(font->face);
if (has_kerning && previous && glyph_index) {
- FT_Get_Kerning(current_font->face, previous, glyph_index, FT_KERNING_DEFAULT, &delta);
+ FT_Get_Kerning(font->face, previous, glyph_index, FT_KERNING_DEFAULT, &delta);
x += delta.x >> 6;
}
- error = FT_Load_Glyph(current_font->face, glyph_index, FT_LOAD_DEFAULT);
+ error = FT_Load_Glyph(font->face, glyph_index, FT_LOAD_DEFAULT);
if (error) {
fprintf(stderr, "warning: char not loaded, skipping...\n");
return x;
}
- FT_Glyph glyph;
FT_Get_Glyph(slot, &glyph);
- FT_Glyph_StrokeBorder(&glyph, stroker, 0, 1);
+ FT_Glyph_StrokeBorder(&glyph, font->stroke, 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;
-
+ bg = (FT_BitmapGlyph)glyph;
draw_bitmap(canvas, &bg->bitmap, x + bg->left, y - bg->top, color);
+ FT_Done_Glyph(glyph);
x += fontcache->box.width >> 6;
return x;
}
-unsigned
-font_width(FontCache *fontcache, const char *text)
-{
- FT_GlyphSlot slot;
- FT_Error error;
- FT_UInt glyph_index;
- FT_UInt previous = 0;
- uint_least32_t charcode;
- FT_Bool has_kerning;
- FT_Vector delta;
- unsigned x = 0;
- Font *current_font;
-
- for (; *text;) {
- text += grapheme_decode_utf8(text, sizeof(uint_least32_t), &charcode);
-
- current_font = get_font_with_charcode(fontcache, charcode);
- FT_Set_Pixel_Sizes(current_font->face, 0, fontcache->fontsize);
-
- slot = current_font->face->glyph;
- glyph_index = FT_Get_Char_Index(current_font->face, charcode);
-
- has_kerning = FT_HAS_KERNING(current_font->face);
- if (has_kerning && previous && glyph_index) {
- FT_Get_Kerning(current_font->face, previous, glyph_index, FT_KERNING_DEFAULT, &delta);
- x += delta.x >> 6;
- }
-
- error = FT_Load_Glyph(current_font->face, glyph_index, FT_LOAD_RENDER);
- if (error) {
- fprintf(stderr, "warning: char not loaded, skipping...\n");
- continue;
- }
-
- x += slot->advance.x >> 6;
- }
-
- return x;
-}