Skip to content

Commit 943a5ea

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

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

jdk/src/macosx/native/sun/font/CGGlyphImages.m

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -883,23 +883,28 @@ @implementation CGGI_GlyphCanvas
883883
return;
884884
}
885885

886-
// just do one malloc, and carve it up for all the buffers
887-
void *buffer = malloc((sizeof(CGRect) + sizeof(CGSize) + sizeof(CGGlyph) + sizeof(UniChar)) * len);
888-
if (buffer == NULL) {
886+
CGRect *bboxes = (CGRect*)calloc(len, sizeof(CGRect));
887+
CGSize *advances = (CGSize*)calloc(len, sizeof(CGSize));
888+
CGGlyph *glyphs = (CGGlyph*)calloc(len, sizeof(CGGlyph));
889+
UniChar *uniChars = (UniChar*)calloc(len, sizeof(UniChar));
890+
891+
if (bboxes == NULL || advances == NULL || glyphs == NULL || uniChars == NULL) {
892+
free(bboxes);
893+
free(advances);
894+
free(glyphs);
895+
free(uniChars);
889896
[[NSException exceptionWithName:NSMallocException
890897
reason:@"Failed to allocate memory for the temporary glyph strike and measurement buffers." userInfo:nil] raise];
891898
}
892899

893-
CGRect *bboxes = (CGRect *)(buffer);
894-
CGSize *advances = (CGSize *)(bboxes + sizeof(CGRect) * len);
895-
CGGlyph *glyphs = (CGGlyph *)(advances + sizeof(CGGlyph) * len);
896-
UniChar *uniChars = (UniChar *)(glyphs + sizeof(UniChar) * len);
897-
898900
CGGI_CreateGlyphsAndScanForComplexities(glyphInfos, strike, &mode,
899901
rawGlyphCodes, uniChars, glyphs,
900902
advances, bboxes, len);
901903

902-
free(buffer);
904+
free(bboxes);
905+
free(advances);
906+
free(glyphs);
907+
free(uniChars);
903908
}
904909

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

0 commit comments

Comments
 (0)