Skip to content

Commit 2801e11

Browse files
Alexey BakhtinRealCLanger
authored andcommitted
8360147: Better Glyph drawing redux
Reviewed-by: mbalao, andrew Backport-of: f57e6baf3b86a7ef0911223cccb47b96e2af0420
1 parent 2494864 commit 2801e11

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

src/java.desktop/macosx/native/libawt_lwawt/font/CGGlyphImages.m

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -974,23 +974,28 @@ @implementation CGGI_GlyphCanvas
974974
return;
975975
}
976976

977-
// just do one malloc, and carve it up for all the buffers
978-
void *buffer = malloc((sizeof(CGRect) + sizeof(CGSize) + sizeof(CGGlyph) + sizeof(UnicodeScalarValue)) * len);
979-
if (buffer == NULL) {
977+
CGRect *bboxes = (CGRect*)calloc(len, sizeof(CGRect));
978+
CGSize *advances = (CGSize*)calloc(len, sizeof(CGSize));
979+
CGGlyph *glyphs = (CGGlyph*)calloc(len, sizeof(CGGlyph));
980+
UnicodeScalarValue *uniChars = (UnicodeScalarValue*)calloc(len, sizeof(UnicodeScalarValue));
981+
982+
if (bboxes == NULL || advances == NULL || glyphs == NULL || uniChars == NULL) {
983+
free(bboxes);
984+
free(advances);
985+
free(glyphs);
986+
free(uniChars);
980987
[[NSException exceptionWithName:NSMallocException
981988
reason:@"Failed to allocate memory for the temporary glyph strike and measurement buffers." userInfo:nil] raise];
982989
}
983990

984-
CGRect *bboxes = (CGRect *)(buffer);
985-
CGSize *advances = (CGSize *)(bboxes + sizeof(CGRect) * len);
986-
CGGlyph *glyphs = (CGGlyph *)(advances + sizeof(CGGlyph) * len);
987-
UnicodeScalarValue *uniChars = (UnicodeScalarValue *)(glyphs + sizeof(UnicodeScalarValue) * len);
988-
989991
CGGI_CreateGlyphsAndScanForComplexities(glyphInfos, strike, &mode,
990992
rawGlyphCodes, uniChars, glyphs,
991993
advances, bboxes, len);
992994

993-
free(buffer);
995+
free(bboxes);
996+
free(advances);
997+
free(glyphs);
998+
free(uniChars);
994999
}
9951000

9961001
#define TX_FIXED_UNSAFE(v) (isinf(v) || isnan(v) || fabs(v) >= (1<<30))

0 commit comments

Comments
 (0)