Skip to content

Commit 141d7af

Browse files
Alexey Bakhtingnu-andrew
authored andcommitted
8360147: Better Glyph drawing redux
Reviewed-by: mbalao, andrew Backport-of: f57e6baf3b86a7ef0911223cccb47b96e2af0420
1 parent f31f26a commit 141d7af

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
@@ -893,23 +893,28 @@ @implementation CGGI_GlyphCanvas
893893
return;
894894
}
895895

896-
// just do one malloc, and carve it up for all the buffers
897-
void *buffer = malloc((sizeof(CGRect) + sizeof(CGSize) + sizeof(CGGlyph) + sizeof(UnicodeScalarValue)) * len);
898-
if (buffer == NULL) {
896+
CGRect *bboxes = (CGRect*)calloc(len, sizeof(CGRect));
897+
CGSize *advances = (CGSize*)calloc(len, sizeof(CGSize));
898+
CGGlyph *glyphs = (CGGlyph*)calloc(len, sizeof(CGGlyph));
899+
UnicodeScalarValue *uniChars = (UnicodeScalarValue*)calloc(len, sizeof(UnicodeScalarValue));
900+
901+
if (bboxes == NULL || advances == NULL || glyphs == NULL || uniChars == NULL) {
902+
free(bboxes);
903+
free(advances);
904+
free(glyphs);
905+
free(uniChars);
899906
[[NSException exceptionWithName:NSMallocException
900907
reason:@"Failed to allocate memory for the temporary glyph strike and measurement buffers." userInfo:nil] raise];
901908
}
902909

903-
CGRect *bboxes = (CGRect *)(buffer);
904-
CGSize *advances = (CGSize *)(bboxes + sizeof(CGRect) * len);
905-
CGGlyph *glyphs = (CGGlyph *)(advances + sizeof(CGGlyph) * len);
906-
UnicodeScalarValue *uniChars = (UnicodeScalarValue *)(glyphs + sizeof(UnicodeScalarValue) * len);
907-
908910
CGGI_CreateGlyphsAndScanForComplexities(glyphInfos, strike, &mode,
909911
rawGlyphCodes, uniChars, glyphs,
910912
advances, bboxes, len);
911913

912-
free(buffer);
914+
free(bboxes);
915+
free(advances);
916+
free(glyphs);
917+
free(uniChars);
913918
}
914919

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

0 commit comments

Comments
 (0)