summaryrefslogtreecommitdiffstats
path: root/crawl-ref
diff options
context:
space:
mode:
authorennewalker <ennewalker@c06c8d41-db1a-0410-9941-cceddc491573>2008-10-04 18:12:13 +0000
committerennewalker <ennewalker@c06c8d41-db1a-0410-9941-cceddc491573>2008-10-04 18:12:13 +0000
commit35d09d284050fe0e0bc1cc12d9f327380844f986 (patch)
tree0281a3b17df45b23832a80189ff01d939778b2ac /crawl-ref
parent03777b344e550540fe5883fbec0250ccfaab1cfe (diff)
downloadcrawl-ref-35d09d284050fe0e0bc1cc12d9f327380844f986.tar.gz
crawl-ref-35d09d284050fe0e0bc1cc12d9f327380844f986.zip
Adding better outlines to fonts so that they are more readable.
git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@7131 c06c8d41-db1a-0410-9941-cceddc491573
Diffstat (limited to 'crawl-ref')
-rw-r--r--crawl-ref/source/tilefont.cc74
-rw-r--r--crawl-ref/source/tilefont.h4
-rw-r--r--crawl-ref/source/tilereg.cc5
-rw-r--r--crawl-ref/source/tilesdl.cc17
-rw-r--r--crawl-ref/source/tilesdl.h2
5 files changed, 72 insertions, 30 deletions
diff --git a/crawl-ref/source/tilefont.cc b/crawl-ref/source/tilefont.cc
index 77de04e2a1..4fb4a841ae 100644
--- a/crawl-ref/source/tilefont.cc
+++ b/crawl-ref/source/tilefont.cc
@@ -47,7 +47,7 @@ FTFont::~FTFont()
delete[] m_glyphs;
}
-bool FTFont::load_font(const char *font_name, unsigned int font_size)
+bool FTFont::load_font(const char *font_name, unsigned int font_size, bool outl)
{
FT_Library library;
FT_Face face;
@@ -113,13 +113,23 @@ bool FTFont::load_font(const char *font_name, unsigned int font_size)
m_max_advance.x = std::max(m_max_advance.x, advance);
- max_width = std::max(max_width, bmp->width);
- min_y = std::min(min_y, ascender - face->glyph->bitmap_top);
- max_y = std::max(max_y, ascender + bmp->rows - face->glyph->bitmap_top);
+ int bmp_width = bmp->width;
+ int bmp_top = ascender - face->glyph->bitmap_top;
+ int bmp_bottom = ascender + bmp->rows - face->glyph->bitmap_top;
+ if (outl)
+ {
+ bmp_width += 2;
+ bmp_top -= 1;
+ bmp_bottom += 1;
+ }
+
+ max_width = std::max(max_width, bmp_width);
+ min_y = std::min(min_y, bmp_top);
+ max_y = std::max(max_y, bmp_bottom);
m_glyphs[c].offset = face->glyph->bitmap_left;
m_glyphs[c].advance = advance;
- m_glyphs[c].width = bmp->width;
+ m_glyphs[c].width = bmp_width;
m_min_offset = std::min((char)m_min_offset, m_glyphs[c].offset);
}
@@ -193,17 +203,49 @@ bool FTFont::load_font(const char *font_name, unsigned int font_size)
unsigned int offset_x = (c % 16) * charsz.x;
unsigned int offset_y = (c / 16) * charsz.y + vert_offset;
- for (int x = 0; x < bmp->width; x++)
- for (int y = 0; y < bmp->rows; y++)
- {
- unsigned int idx = offset_x + x + (offset_y + y) * width;
- idx *= 4;
- unsigned char alpha = bmp->buffer[x + bmp->width * y];
- pixels[idx] = 255;
- pixels[idx + 1] = 255;
- pixels[idx + 2] = 255;
- pixels[idx + 3] = alpha;
- }
+ if (outl)
+ {
+ const int charw = bmp->width;
+ for (int x = -1; x <= bmp->width; x++)
+ for (int y = -1; y <= bmp->rows; y++)
+ {
+ bool valid = x >= 0 && y >= 0 &&
+ x < bmp->width && y < bmp->rows;
+ unsigned char orig = valid ? bmp->buffer[x + charw * y] : 0;
+
+ unsigned char edge = 0;
+ if (x > 0)
+ edge = std::max(bmp->buffer[(x-1) + charw * y], edge);
+ if (y > 0)
+ edge = std::max(bmp->buffer[x + charw * (y-1)], edge);
+ if (x < bmp->width - 1)
+ edge = std::max(bmp->buffer[(x+1) + charw * y], edge);
+ if (y < bmp->width - 1)
+ edge = std::max(bmp->buffer[x + charw * (y+1)], edge);
+
+ unsigned int idx = offset_x + x + (offset_y + y) * width;
+ idx *= 4;
+
+ pixels[idx] = orig;
+ pixels[idx + 1] = orig;
+ pixels[idx + 2] = orig;
+ pixels[idx + 3] = std::min(orig + edge, 255);
+ }
+ }
+ else
+ {
+ for (int x = 0; x < bmp->width; x++)
+ for (int y = 0; y < bmp->rows; y++)
+ {
+ unsigned int idx = offset_x + x + (offset_y + y) * width;
+ idx *= 4;
+ unsigned char alpha = bmp->buffer[x + bmp->width * y];
+ pixels[idx] = 255;
+ pixels[idx + 1] = 255;
+ pixels[idx + 2] = 255;
+ pixels[idx + 3] = alpha;
+ }
+ }
}
bool success = m_tex.load_texture(pixels, width, height,
diff --git a/crawl-ref/source/tilefont.h b/crawl-ref/source/tilefont.h
index d87ea6b53b..10d1971391 100644
--- a/crawl-ref/source/tilefont.h
+++ b/crawl-ref/source/tilefont.h
@@ -17,7 +17,7 @@
// TODO enne - Fonts could be made better by:
//
// * handling kerning
-//
+// * using SDL_font (maybe?)
// * the possibility of streaming this class in and out so that Crawl doesn't
// have to link against FreeType2 or be forced do as much processing at
// load time.
@@ -28,7 +28,7 @@ public:
FTFont();
virtual ~FTFont();
- bool load_font(const char *font_name, unsigned int font_size);
+ bool load_font(const char *font_name, unsigned int font_size, bool outline);
// render just text
void render_textblock(unsigned int x, unsigned int y,
diff --git a/crawl-ref/source/tilereg.cc b/crawl-ref/source/tilereg.cc
index 661d721992..0adc45b8b4 100644
--- a/crawl-ref/source/tilereg.cc
+++ b/crawl-ref/source/tilereg.cc
@@ -766,7 +766,7 @@ void DungeonRegion::render()
const coord_def min_pos(sx, sy);
const coord_def max_pos(ex, ey);
m_tag_font->render_string(pc.x, pc.y, m_tags[t][i].tag.c_str(),
- min_pos, max_pos, WHITE, true);
+ min_pos, max_pos, WHITE, false);
}
}
}
@@ -1194,8 +1194,7 @@ void InventoryRegion::render()
m_tag_font->render_string((unsigned int)x, (unsigned int)y,
desc.c_str(),
- min_pos, max_pos, WHITE, true,
- 200, BLACK);
+ min_pos, max_pos, WHITE, false, 200);
}
}
diff --git a/crawl-ref/source/tilesdl.cc b/crawl-ref/source/tilesdl.cc
index af7755005d..bcf1ff92c3 100644
--- a/crawl-ref/source/tilesdl.cc
+++ b/crawl-ref/source/tilesdl.cc
@@ -133,6 +133,7 @@ bool TilesFramework::initialise()
SDL_EnableUNICODE(true);
SDL_WM_SetCaption(CRAWL " " VERSION, CRAWL);
+ // TODO enne - use a different icon on Windows, as this looks bad.
SDL_Surface *icon = IMG_Load("dat/tiles/stone_soup_icon-32x32.png");
if (!icon)
{
@@ -174,15 +175,15 @@ bool TilesFramework::initialise()
return false;
int crt_font = load_font(Options.tile_font_crt_file.c_str(),
- Options.tile_font_crt_size);
+ Options.tile_font_crt_size, true, false);
int msg_font = load_font(Options.tile_font_msg_file.c_str(),
- Options.tile_font_msg_size);
+ Options.tile_font_msg_size, true, false);
int stat_font = load_font(Options.tile_font_stat_file.c_str(),
- Options.tile_font_stat_size);
+ Options.tile_font_stat_size, true, false);
m_tip_font = load_font(Options.tile_font_tip_file.c_str(),
- Options.tile_font_tip_size);
+ Options.tile_font_tip_size, true, false);
int lbl_font = load_font(Options.tile_font_lbl_file.c_str(),
- Options.tile_font_lbl_size);
+ Options.tile_font_lbl_size, true, true);
if (crt_font == -1 || msg_font == -1 || stat_font == -1
|| m_tip_font == -1 || lbl_font == -1)
@@ -221,7 +222,7 @@ bool TilesFramework::initialise()
}
int TilesFramework::load_font(const char *font_file, int font_size,
- bool default_on_fail)
+ bool default_on_fail, bool outline)
{
FTFont *font = new FTFont();
@@ -232,11 +233,11 @@ int TilesFramework::load_font(const char *font_file, int font_size,
return i;
}
- if (!font->load_font(font_file, font_size))
+ if (!font->load_font(font_file, font_size, outline))
{
delete font;
if (default_on_fail)
- return (load_font("VeraMono.ttf", 12, false));
+ return (load_font("VeraMono.ttf", 12, false, outline));
else
return -1;
}
diff --git a/crawl-ref/source/tilesdl.h b/crawl-ref/source/tilesdl.h
index 11016e3b2a..ea4e717284 100644
--- a/crawl-ref/source/tilesdl.h
+++ b/crawl-ref/source/tilesdl.h
@@ -124,7 +124,7 @@ public:
protected:
int load_font(const char *font_file, int font_size,
- bool default_on_fail = true);
+ bool default_on_fail, bool outline);
int handle_mouse(MouseEvent &event);
// screen pixel dimensions