diff --git a/src/text/ft2.c b/src/text/ft2.c index 17381f9..32e6587 100644 --- a/src/text/ft2.c +++ b/src/text/ft2.c @@ -69,16 +69,13 @@ static int ft2_MwDrawText(MwWidget handle, MwFLFont ttf, MwPoint* point, const c int ox = x + (ttf->face->glyph->metrics.horiBearingX / 64) + cx + ttf->face->glyph->bitmap_left; int oy = y + (ttf->face->height * ttf->px / ttf->face->units_per_EM) - ttf->face->glyph->bitmap_top + cy + (ttf->face->descender * ttf->px / ttf->face->units_per_EM); unsigned char* opx = &px[(oy * tw + ox) * 4]; - - if(opx[3] == 0) { - opx[0] = color->common.red; - opx[1] = color->common.green; - opx[2] = color->common.blue; - opx[3] = bmp->buffer[cy * bmp->pitch + cx]; + opx[0] = color->common.red; + opx[1] = color->common.green; + opx[2] = color->common.blue; + /* overflow check */ + if(opx[3] + bmp->buffer[cy * bmp->pitch + cx] < opx[3]) { + opx[3] = 255; } else { - opx[0] = (opx[0] / color->common.red) / 255; - opx[1] = (opx[1] / color->common.green) / 255; - opx[2] = (opx[2] / color->common.blue) / 255; opx[3] = bmp->buffer[cy * bmp->pitch + cx]; } } diff --git a/src/text/stbtt.c b/src/text/stbtt.c index 5e23f6c..a841907 100644 --- a/src/text/stbtt.c +++ b/src/text/stbtt.c @@ -52,16 +52,13 @@ static int stbtt_MwDrawText(MwWidget handle, MwFLFont ttf, MwPoint* point, const int ox = x + ceil(lsb * ttf->scale) + cx; int oy = y + ceil(ttf->ascent * ttf->scale) + y0 + cy; unsigned char* opx = &px[(oy * tw + ox) * 4]; - - if(opx[3] == 0) { - opx[0] = color->common.red; - opx[1] = color->common.green; - opx[2] = color->common.blue; - opx[3] = out[cy * ow + cx]; + opx[0] = color->common.red; + opx[1] = color->common.green; + opx[2] = color->common.blue; + /* overflow check */ + if(opx[3] + out[cy * ow + cx] < opx[3]) { + opx[3] = 255; } else { - opx[0] = (opx[0] / color->common.red) / 255; - opx[1] = (opx[1] / color->common.green) / 255; - opx[2] = (opx[2] / color->common.blue) / 255; opx[3] = out[cy * ow + cx]; } }