mirror of
https://github.com/cappuccino/cappuccino.git
synced 2026-09-13 22:21:29 +00:00
fixed: text sizing was slower than it should be
thanks mrcarlberg for spotting this
This commit is contained in:
@@ -86,18 +86,20 @@ CPStringSizeCachingEnabled = YES;
|
||||
if (!CPStringSizeCachingEnabled)
|
||||
return [CPPlatformString sizeOfString:self withFont:aFont forWidth:aWidth];
|
||||
|
||||
if (CPStringSizeWithFontInWidthCache[self] === undefined)
|
||||
CPStringSizeWithFontInWidthCache[self] = [];
|
||||
var sizeCacheForFont = CPStringSizeWithFontInWidthCache[self];
|
||||
|
||||
if (sizeCacheForFont === undefined)
|
||||
sizeCacheForFont = [];
|
||||
|
||||
var cssString = [aFont cssString],
|
||||
cacheKey = cssString + '_' + aWidth;
|
||||
|
||||
size = CPStringSizeWithFontInWidthCache[self][cacheKey];
|
||||
size = sizeCacheForFont[cacheKey];
|
||||
|
||||
if (CPStringSizeWithFontInWidthCache[self].hasOwnProperty(cacheKey) && size !== undefined)
|
||||
if (size !== undefined && sizeCacheForFont.hasOwnProperty(cacheKey))
|
||||
return CGSizeMakeCopy(size);
|
||||
|
||||
if (!CPStringSizeDidTestCanvasSizingValid)
|
||||
if (CPStringSizeDidTestCanvasSizingValid === undefined)
|
||||
{
|
||||
[self _initializeStringSizing];
|
||||
CPStringSizeDidTestCanvasSizingValid = YES;
|
||||
@@ -118,7 +120,7 @@ CPStringSizeCachingEnabled = YES;
|
||||
size = CGSizeMake(CPStringSizeMeasuringContext.measureText(self).width, fontHeight);
|
||||
}
|
||||
|
||||
CPStringSizeWithFontInWidthCache[self][cacheKey] = size;
|
||||
sizeCacheForFont[cacheKey] = size;
|
||||
#else
|
||||
size = CGSizeMake(0, 0);
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user