# HG changeset patch # User sbr # Date 1375532566 -7200 # Sat Aug 03 14:22:46 2013 +0200 # Node ID 14b3911e308ca34288ea204a48dada290ccb219e # Parent 0d610b876a4c36415c0cec32abfcf199982707a3 -Add: RTL shadowing of freetype fonts To fit in the same bounds than LTR shadowed text, the shadow and glyph horizontal positions are swaped to render the RTL shadowing. diff --git a/src/fontcache.cpp b/src/fontcache.cpp --- a/src/fontcache.cpp +++ b/src/fontcache.cpp @@ -497,22 +497,25 @@ const Sprite *FreeTypeFontCache::GetGlyp sprite.y_offs = this->ascender - slot->bitmap_top; /* Draw shadow for medium size */ + byte shadow_offset = 0; // To draw RTL shadow, swap the x position of shadow and glyph used for LTR. if (this->fs == FS_NORMAL && !aa) { + shadow_offset = (_current_text_dir == TD_RTL) ? 0 : 1; // If RTL draw the shadow in place, otherwise draw it one pixel to the right. for (int y = 0; y < slot->bitmap.rows; y++) { for (int x = 0; x < slot->bitmap.width; x++) { if (aa ? (slot->bitmap.buffer[x + y * slot->bitmap.pitch] > 0) : HasBit(slot->bitmap.buffer[(x / 8) + y * slot->bitmap.pitch], 7 - (x % 8))) { - sprite.data[1 + x + (1 + y) * sprite.width].m = SHADOW_COLOUR; - sprite.data[1 + x + (1 + y) * sprite.width].a = aa ? slot->bitmap.buffer[x + y * slot->bitmap.pitch] : 0xFF; + sprite.data[shadow_offset + x + (1 + y) * sprite.width].m = SHADOW_COLOUR; + sprite.data[shadow_offset + x + (1 + y) * sprite.width].a = aa ? slot->bitmap.buffer[x + y * slot->bitmap.pitch] : 0xFF; } } } + shadow_offset = (_current_text_dir == TD_RTL) ? 1 : 0; // If RTL draw the glyph one pixel to the right, otherwise draw it in place. } for (int y = 0; y < slot->bitmap.rows; y++) { for (int x = 0; x < slot->bitmap.width; x++) { if (aa ? (slot->bitmap.buffer[x + y * slot->bitmap.pitch] > 0) : HasBit(slot->bitmap.buffer[(x / 8) + y * slot->bitmap.pitch], 7 - (x % 8))) { - sprite.data[x + y * sprite.width].m = FACE_COLOUR; - sprite.data[x + y * sprite.width].a = aa ? slot->bitmap.buffer[x + y * slot->bitmap.pitch] : 0xFF; + sprite.data[shadow_offset + x + y * sprite.width].m = FACE_COLOUR; + sprite.data[shadow_offset + x + y * sprite.width].a = aa ? slot->bitmap.buffer[x + y * slot->bitmap.pitch] : 0xFF; } } }