Merge pull request #2508 from daboe01/fix-sizing-issue

Fixed: text-sizing by canvas and via DOM sizing differed by 1px
This commit is contained in:
Martin Carlberg authored and GitHub committed 2017-01-16 12:20:06 +01:00
commit 6aea0160df
2 files changed
+11 -3

No files matched your search

+10 -1
View File
@@ -68,7 +68,7 @@ CPStringSizeCachingEnabled = YES;
#endif
}
- (CGSize)sizeWithFont:(CPFont)aFont inWidth:(float)aWidth
- (CGSize)_sizeWithFont:(CPFont)aFont inWidth:(float)aWidth
{
var size;
@@ -81,6 +81,9 @@ CPStringSizeCachingEnabled = YES;
if (sizeCacheForFont === undefined)
sizeCacheForFont = CPStringSizeWithFontInWidthCache[self] = [];
if (!aWidth)
aWidth = '0';
var cssString = [aFont cssString],
cacheKey = cssString + '_' + aWidth;
@@ -111,4 +114,10 @@ CPStringSizeCachingEnabled = YES;
return CGSizeMakeCopy(size);
}
- (CGSize)sizeWithFont:(CPFont)aFont inWidth:(float)aWidth
{
var size = [self _sizeWithFont:aFont inWidth:aWidth];
return CGSizeMake(CEIL(size.width), size.height);
}
@end
+1 -2
View File
@@ -1,4 +1,3 @@
/*
* CPTypesetter.j
* AppKit
@@ -319,7 +318,7 @@ var CPSystemTypesetterFactory,
measuringRange.length++;
var currentCharCode = theString.charCodeAt(glyphIndex), // use pure javascript methods for performance reasons
rangeWidth = [theString.substr(measuringRange.location, measuringRange.length) sizeWithFont:currentFont inWidth:NULL].width + currentAnchor;
rangeWidth = [theString.substr(measuringRange.location, measuringRange.length) _sizeWithFont:currentFont inWidth:NULL].width + currentAnchor;
switch (currentCharCode) // faster than sending actionForControlCharacterAtIndex: called for each char.
{