mirror of
https://github.com/libretro/scummvm.git
synced 2025-01-10 11:51:52 +00:00
AGS: Fix font outlines not drawing correctly
This commit is contained in:
parent
e6db9ded56
commit
122acc39b5
@ -65,14 +65,33 @@ size_t alfont_text_height(ALFONT_FONT *font) {
|
||||
return font->_size;
|
||||
}
|
||||
|
||||
void alfont_textout(BITMAP *bmp, ALFONT_FONT *font, const char *text, int x, int y, uint32 color) {
|
||||
void alfont_textout(BITMAP *bmp, ALFONT_FONT *font, ALFONT_FONT *refFont, const char *text, int x, int y, uint32 color) {
|
||||
// Note: the original does not use antialiasing when drawing on 8 bit bmp
|
||||
// if (bitmap_color_depth(bmp) > 8) do not use AA in getFont()...
|
||||
// The original alfont changes the y based on the font height and ascent.
|
||||
y += (font->_size - font->getFont()->getFontAscent());
|
||||
Graphics::ManagedSurface &surf = **bmp;
|
||||
font->getFont()->drawString(&surf, text, x, y, bmp->w - x,
|
||||
(color == surf.getTransparentColor()) ? color - 1 : color);
|
||||
Graphics::Font *fnt = font->getFont();
|
||||
uint32 col = (color == surf.getTransparentColor()) ? color - 1 : color;
|
||||
|
||||
if (!refFont) {
|
||||
// Standard string draw
|
||||
fnt->drawString(&surf, text, x, y, bmp->w - x, col);
|
||||
|
||||
} else {
|
||||
// Drawing an outline prior to standard font drawing on top.
|
||||
// We use the font's character widths to ensure the two match up
|
||||
refFont->_size = font->_size;
|
||||
Graphics::Font *srcFnt = refFont->getFont();
|
||||
|
||||
for (int w = bmp->w - x; *text && w > 0; ++text) {
|
||||
fnt->drawChar(&surf, *text, x, y, col);
|
||||
|
||||
int charWidth = srcFnt->getCharWidth(*text);
|
||||
x += charWidth;
|
||||
w -= charWidth;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void alfont_set_font_size(ALFONT_FONT *font, int size) {
|
||||
|
@ -55,7 +55,7 @@ extern void alfont_destroy_font(ALFONT_FONT *font);
|
||||
|
||||
extern size_t alfont_text_length(ALFONT_FONT *font, const char *text);
|
||||
extern size_t alfont_text_height(ALFONT_FONT *font);
|
||||
extern void alfont_textout(BITMAP *bmp, ALFONT_FONT *font, const char *text, int x, int y, uint32 color);
|
||||
extern void alfont_textout(BITMAP *bmp, ALFONT_FONT *font, ALFONT_FONT *refFont, const char *text, int x, int y, uint32 color);
|
||||
extern const char *alfont_get_name(ALFONT_FONT *font);
|
||||
extern void alfont_set_font_size(ALFONT_FONT *font, int size);
|
||||
|
||||
|
@ -138,6 +138,15 @@ int get_font_outline(size_t font_number) {
|
||||
return _GP(fonts)[font_number].Info.Outline;
|
||||
}
|
||||
|
||||
int get_outline_font(size_t font_number) {
|
||||
for (size_t fontNum = 0; fontNum < _GP(fonts).size(); ++fontNum) {
|
||||
if (_GP(fonts)[fontNum].Info.Outline == (int)font_number)
|
||||
return fontNum;
|
||||
}
|
||||
|
||||
return FONT_OUTLINE_NONE;
|
||||
}
|
||||
|
||||
void set_font_outline(size_t font_number, int outline_type) {
|
||||
if (font_number >= _GP(fonts).size())
|
||||
return;
|
||||
|
@ -84,6 +84,7 @@ int getfontlinespacing(size_t fontNumber);
|
||||
// Get is font is meant to use default line spacing
|
||||
bool use_default_linespacing(size_t fontNumber);
|
||||
int get_font_outline(size_t font_number);
|
||||
int get_outline_font(size_t font_number);
|
||||
void set_font_outline(size_t font_number, int outline_type);
|
||||
// Outputs a single line of text on the defined position on bitmap, using defined font, color and parameters
|
||||
int getfontlinespacing(size_t fontNumber);
|
||||
|
@ -68,8 +68,16 @@ void TTFFontRenderer::RenderText(const char *text, int fontNumber, BITMAP *desti
|
||||
if (y > destination->cb) // optimisation
|
||||
return;
|
||||
|
||||
int srcFontNum = get_outline_font(fontNumber);
|
||||
ALFONT_FONT *srcFont = nullptr;
|
||||
if (srcFontNum != FONT_OUTLINE_NONE) {
|
||||
srcFont = _fontData[srcFontNum].AlFont;
|
||||
assert(srcFont);
|
||||
}
|
||||
|
||||
// Y - 1 because it seems to get drawn down a bit
|
||||
alfont_textout(destination, _fontData[fontNumber].AlFont, text, x, y - 1, colour);
|
||||
alfont_textout(destination, _fontData[fontNumber].AlFont,
|
||||
srcFont, text, x, y - 1, colour);
|
||||
}
|
||||
|
||||
bool TTFFontRenderer::LoadFromDisk(int fontNumber, int fontSize) {
|
||||
|
Loading…
Reference in New Issue
Block a user