aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--drw.c60
-rw-r--r--drw.h5
-rw-r--r--swt.c2
3 files changed, 44 insertions, 23 deletions
diff --git a/drw.c b/drw.c
index 5297ab1..ce7b679 100644
--- a/drw.c
+++ b/drw.c
@@ -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);
}
diff --git a/drw.h b/drw.h
index 0885fe2..07dbfa2 100644
--- a/drw.h
+++ b/drw.h
@@ -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 {
diff --git a/swt.c b/swt.c
index 39f50c9..e4aacfd 100644
--- a/swt.c
+++ b/swt.c
@@ -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];
}