diff --git a/AppKit/CPStringDrawing.j b/AppKit/CPStringDrawing.j index 23b27e403..8095e6542 100644 --- a/AppKit/CPStringDrawing.j +++ b/AppKit/CPStringDrawing.j @@ -65,15 +65,11 @@ CPStringSizeCachingEnabled = YES; var cssString = [aFont cssString], cacheKey = self + cssString + aWidth, - size = CPStringSizeWithFontInWidthCache[cacheKey], - fontHeight = CPStringSizeWithFontHeightCache[cssString]; + size = CPStringSizeWithFontInWidthCache[cacheKey]; if (size !== undefined) return CGSizeMakeCopy(size); - if (fontHeight === undefined) - fontHeight = CPStringSizeWithFontHeightCache[cssString] = [aFont defaultLineHeightForFont]; - if (!CPStringSizeMeasuringContext) CPStringSizeMeasuringContext = CGBitmapGraphicsContextCreate(); @@ -92,6 +88,11 @@ CPStringSizeCachingEnabled = YES; if (CPStringSizeMeasuringContext.font !== aFont) CPStringSizeMeasuringContext.font = cssString; + var fontHeight = CPStringSizeWithFontHeightCache[cssString]; + + if (fontHeight === undefined) + fontHeight = CPStringSizeWithFontHeightCache[cssString] = [aFont defaultLineHeightForFont]; + size = CGSizeMake(CPStringSizeMeasuringContext.measureText(self).width, fontHeight); }