Skip to content

Commit

Permalink
8238942: Rendering artifacts with LCD text and fractional metrics
Browse files Browse the repository at this point in the history
Reviewed-by: serb, jdv
  • Loading branch information
prrace committed Feb 14, 2020
1 parent 5705a55 commit e6915ff
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions src/java.desktop/share/native/libfontmanager/freetypeScaler.c
Original file line number Diff line number Diff line change
Expand Up @@ -836,8 +836,9 @@ static jlong
jlong pScalerContext, jlong pScaler, jint glyphCode,
jboolean renderImage) {

static int PADBYTES = 3;
int error, imageSize;
UInt16 width, height;
UInt16 width, height, rowBytes;
GlyphInfo *glyphInfo;
int renderFlags = FT_LOAD_DEFAULT, target;
FT_GlyphSlot ftglyph;
Expand Down Expand Up @@ -923,35 +924,42 @@ static jlong

if (renderImage) {
width = (UInt16) ftglyph->bitmap.width;
rowBytes = width;
if (ftglyph->bitmap.pixel_mode == FT_PIXEL_MODE_LCD) {
rowBytes = PADBYTES + width + PADBYTES;
}
height = (UInt16) ftglyph->bitmap.rows;
if (width > MAX_GLYPH_DIM || height > MAX_GLYPH_DIM) {
glyphInfo = getNullGlyphImage();
return ptr_to_jlong(glyphInfo);
}
} else {
width = 0;
rowBytes = 0;
height = 0;
}


imageSize = width*height;
glyphInfo = (GlyphInfo*) malloc(sizeof(GlyphInfo) + imageSize);
imageSize = rowBytes*height;
glyphInfo = (GlyphInfo*) calloc(sizeof(GlyphInfo) + imageSize, 1);
if (glyphInfo == NULL) {
glyphInfo = getNullGlyphImage();
return ptr_to_jlong(glyphInfo);
}
glyphInfo->cellInfo = NULL;
glyphInfo->managed = UNMANAGED_GLYPH;
glyphInfo->rowBytes = width;
glyphInfo->rowBytes = rowBytes;
glyphInfo->width = width;
glyphInfo->height = height;

if (renderImage) {
glyphInfo->topLeftX = (float) ftglyph->bitmap_left;
glyphInfo->topLeftY = (float) -ftglyph->bitmap_top;

if (ftglyph->bitmap.pixel_mode == FT_PIXEL_MODE_LCD) {
if (ftglyph->bitmap.pixel_mode == FT_PIXEL_MODE_LCD && width > 0) {
glyphInfo->width = width/3;
glyphInfo->topLeftX -= 1;
glyphInfo->width += 1;
} else if (ftglyph->bitmap.pixel_mode == FT_PIXEL_MODE_LCD_V) {
glyphInfo->height = glyphInfo->height/3;
}
Expand Down Expand Up @@ -1008,8 +1016,8 @@ static jlong
/* 3 bytes per pixel to 3 bytes per pixel */
CopyFTSubpixelToSubpixel(ftglyph->bitmap.buffer,
ftglyph->bitmap.pitch,
(void *) glyphInfo->image,
width,
(void *) (glyphInfo->image+PADBYTES),
rowBytes,
width,
height);
} else if (ftglyph->bitmap.pixel_mode == FT_PIXEL_MODE_LCD_V) {
Expand Down

0 comments on commit e6915ff

Please sign in to comment.