diff options
author | RĂ©mi Verschelde <rverschelde@gmail.com> | 2017-09-21 10:37:21 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-09-21 10:37:21 +0200 |
commit | d79ce05b91e0032c6178935c7c0757b9a258becc (patch) | |
tree | 282b0070b40ad29f0a71f4bd34fbaa78509fce49 /scene | |
parent | 791f69419daef09dc1e67ff3b9101437ce945bdd (diff) | |
parent | 2ca82225b78c1fdaac94916ff932067b21d3ff56 (diff) |
Merge pull request #11365 from leezh/freetype_mono
Added support for FT_PIXEL_MODE_MONO in FreeType
Diffstat (limited to 'scene')
-rw-r--r-- | scene/resources/dynamic_font.cpp | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/scene/resources/dynamic_font.cpp b/scene/resources/dynamic_font.cpp index b2d87c8f35..1ee76a4216 100644 --- a/scene/resources/dynamic_font.cpp +++ b/scene/resources/dynamic_font.cpp @@ -560,8 +560,23 @@ void DynamicFontAtSize::_update_char(CharType p_char) { int ofs = ((i + tex_y + rect_margin) * tex.texture_size + j + tex_x + rect_margin) * 2; ERR_FAIL_COND(ofs >= tex.imgdata.size()); - wr[ofs + 0] = 255; //grayscale as 1 - wr[ofs + 1] = slot->bitmap.buffer[i * slot->bitmap.width + j]; + switch (slot->bitmap.pixel_mode) { + case FT_PIXEL_MODE_MONO: { + int byte = i * slot->bitmap.pitch + (j >> 3); + int bit = 1 << (7 - (j % 8)); + wr[ofs + 0] = 255; //grayscale as 1 + wr[ofs + 1] = slot->bitmap.buffer[byte] & bit ? 255 : 0; + } break; + case FT_PIXEL_MODE_GRAY: + wr[ofs + 0] = 255; //grayscale as 1 + wr[ofs + 1] = slot->bitmap.buffer[i * slot->bitmap.pitch + j]; + break; + // TODO: FT_PIXEL_MODE_LCD, FT_PIXEL_MODE_BGRA + default: + ERR_EXPLAIN("Font uses unsupported pixel format: " + itos(slot->bitmap.pixel_mode)); + ERR_FAIL(); + break; + } } } } |