Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show unicode box drawing characters with bitmap fonts #36536

Merged
merged 1 commit into from
Dec 30, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
96 changes: 75 additions & 21 deletions src/sdltiles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -709,8 +709,23 @@ void CachedTTFFont::OutputChar( const std::string &ch, const int x, const int y,

bool BitmapFont::isGlyphProvided( const std::string &ch ) const
{
uint32_t t = UTF8_getch( ch );
return t < 256;
const uint32_t t = UTF8_getch( ch );
switch( t ) {
case LINE_XOXO_UNICODE:
case LINE_OXOX_UNICODE:
case LINE_XXOO_UNICODE:
case LINE_OXXO_UNICODE:
case LINE_OOXX_UNICODE:
case LINE_XOOX_UNICODE:
case LINE_XXXO_UNICODE:
case LINE_XXOX_UNICODE:
case LINE_XOXX_UNICODE:
case LINE_OXXX_UNICODE:
case LINE_XXXX_UNICODE:
return true;
default:
return t < 256;
}
}

void BitmapFont::OutputChar( const std::string &ch, const int x, const int y,
Expand All @@ -723,25 +738,64 @@ void BitmapFont::OutputChar( const std::string &ch, const int x, const int y,
void BitmapFont::OutputChar( const int t, const int x, const int y,
const unsigned char color, const float opacity )
{
if( t > 256 ) {
return;
}
SDL_Rect src;
src.x = ( t % tilewidth ) * fontwidth;
src.y = ( t / tilewidth ) * fontheight;
src.w = fontwidth;
src.h = fontheight;
SDL_Rect rect;
rect.x = x;
rect.y = y;
rect.w = fontwidth;
rect.h = fontheight;
if( opacity != 1.0f ) {
SDL_SetTextureAlphaMod( ascii[color].get(), opacity * 255 );
}
RenderCopy( renderer, ascii[color], &src, &rect );
if( opacity != 1.0f ) {
SDL_SetTextureAlphaMod( ascii[color].get(), 255 );
if( t <= 256 ) {
SDL_Rect src;
src.x = ( t % tilewidth ) * fontwidth;
src.y = ( t / tilewidth ) * fontheight;
src.w = fontwidth;
src.h = fontheight;
SDL_Rect rect;
rect.x = x;
rect.y = y;
rect.w = fontwidth;
rect.h = fontheight;
if( opacity != 1.0f ) {
SDL_SetTextureAlphaMod( ascii[color].get(), opacity * 255 );
}
RenderCopy( renderer, ascii[color], &src, &rect );
if( opacity != 1.0f ) {
SDL_SetTextureAlphaMod( ascii[color].get(), 255 );
}
} else {
unsigned char uc = 0;
switch( t ) {
case LINE_XOXO_UNICODE:
uc = LINE_XOXO_C;
break;
case LINE_OXOX_UNICODE:
uc = LINE_OXOX_C;
break;
case LINE_XXOO_UNICODE:
uc = LINE_XXOO_C;
break;
case LINE_OXXO_UNICODE:
uc = LINE_OXXO_C;
break;
case LINE_OOXX_UNICODE:
uc = LINE_OOXX_C;
break;
case LINE_XOOX_UNICODE:
uc = LINE_XOOX_C;
break;
case LINE_XXXO_UNICODE:
uc = LINE_XXXO_C;
break;
case LINE_XXOX_UNICODE:
uc = LINE_XXOX_C;
break;
case LINE_XOXX_UNICODE:
uc = LINE_XOXX_C;
break;
case LINE_OXXX_UNICODE:
uc = LINE_OXXX_C;
break;
case LINE_XXXX_UNICODE:
uc = LINE_XXXX_C;
break;
default:
return;
}
draw_ascii_lines( uc, x, y, color );
}
}

Expand Down