diff --git a/ChangeLog b/ChangeLog index 73db727..fcfebf1 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2020-12-23  Anuj Verma   + + [ftsdf] Fix glyph rendering issue. + + * src/ftsdf.c (draw): Compute the number of + bits per pixel, rather than assuming 24 bits + per pixel. + 2020-08-24 Anuj Verma [ftsdf] Add better usage section. diff --git a/src/ftsdf.c b/src/ftsdf.c index 8d7ef88..568da89 100644 --- a/src/ftsdf.c +++ b/src/ftsdf.c @@ -437,11 +437,16 @@ Vec2 center; FT_Short* buffer; - + FT_Int bytes_per_pixel; if ( !bitmap || !bitmap->buffer ) return FT_Err_Invalid_Argument; + /* compute the number of bytes per pixel of the window surface */ + bytes_per_pixel = display->bitmap->pitch / display->bitmap->width; + bytes_per_pixel = bytes_per_pixel < 0 ? + -bytes_per_pixel : bytes_per_pixel; + /* compute center of display */ center.x = display->bitmap->width / 2; center.y = display->bitmap->rows / 2; @@ -600,10 +605,11 @@ alpha *= 255; /* finally copy the target value to the display buffer */ - display_index *= 3; - display->bitmap->buffer[display_index + 0] = (unsigned char)alpha; - display->bitmap->buffer[display_index + 1] = (unsigned char)alpha; - display->bitmap->buffer[display_index + 2] = (unsigned char)alpha; + display_index *= bytes_per_pixel; + for ( FT_Int pixel = 0; pixel < bytes_per_pixel; pixel++ ) { + display->bitmap->buffer[display_index + pixel] = + (unsigned char)alpha; + } } else { @@ -622,10 +628,11 @@ final_dist *= 255; /* finally copy the target value to the display buffer */ - display_index *= 3; - display->bitmap->buffer[display_index + 0] = (unsigned char)final_dist; - display->bitmap->buffer[display_index + 1] = (unsigned char)final_dist; - display->bitmap->buffer[display_index + 2] = (unsigned char)final_dist; + display_index *= bytes_per_pixel; + for ( FT_Int pixel = 0; pixel < bytes_per_pixel; pixel++ ) { + display->bitmap->buffer[display_index + pixel] = + (unsigned char)final_dist; + } } } }