Merge pull request #673 from adly-holler/ceil-text-size

Align ASEditableTextNode to pixel boundaries
This commit is contained in:
appleguy
2015-09-20 21:44:53 -07:00
3 changed files with 18 additions and 15 deletions

View File

@@ -149,6 +149,7 @@
{
ASTextKitComponents *displayedComponents = [self isDisplayingPlaceholder] ? _placeholderTextKitComponents : _textKitComponents;
CGSize textSize = [displayedComponents sizeForConstrainedWidth:constrainedSize.width];
textSize = ceilSizeValue(textSize);
return CGSizeMake(constrainedSize.width, fminf(textSize.height, constrainedSize.height));
}

View File

@@ -66,18 +66,6 @@ static NSString *ASTextNodeTruncationTokenAttributeName = @"ASTextNodeTruncation
@end
ASDISPLAYNODE_INLINE CGFloat ceilPixelValueForScale(CGFloat f, CGFloat scale)
{
// Round up to device pixel (.5 on retina)
return ceilf(f * scale) / scale;
}
ASDISPLAYNODE_INLINE CGFloat ceilPixelValue(CGFloat f)
{
return ceilPixelValueForScale(f, [UIScreen mainScreen].scale);
}
@interface ASTextNode () <UIGestureRecognizerDelegate>
@end
@@ -212,9 +200,9 @@ ASDISPLAYNODE_INLINE CGFloat ceilPixelValue(CGFloat f)
CGSize renderSizePlusShadowPadding = UIEdgeInsetsInsetRect(CGRect{CGPointZero, rendererSize}, shadowPadding).size;
ASDisplayNodeAssert(renderSizePlusShadowPadding.width >= 0, @"Calculated width for text with shadow padding (%f) is too narrow", constrainedSizeForText.width);
ASDisplayNodeAssert(renderSizePlusShadowPadding.height >= 0, @"Calculated height for text with shadow padding (%f) is too short", constrainedSizeForText.height);
return CGSizeMake(MIN(ceilPixelValue(renderSizePlusShadowPadding.width), constrainedSize.width),
MIN(ceilPixelValue(renderSizePlusShadowPadding.height), constrainedSize.height));
renderSizePlusShadowPadding = ceilSizeValue(renderSizePlusShadowPadding);
return CGSizeMake(MIN(renderSizePlusShadowPadding.width, constrainedSize.width),
MIN(renderSizePlusShadowPadding.height, constrainedSize.height));
}
- (void)displayDidFinish

View File

@@ -10,7 +10,21 @@
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#import "ASBaseDefines.h"
ASDISPLAYNODE_INLINE CGFloat ceilPixelValueForScale(CGFloat f, CGFloat scale)
{
// Round up to device pixel (.5 on retina)
return ceilf(f * scale) / scale;
}
ASDISPLAYNODE_INLINE CGSize ceilSizeValue(CGSize s)
{
CGFloat screenScale = [UIScreen mainScreen].scale;
s.width = ceilPixelValueForScale(s.width, screenScale);
s.height = ceilPixelValueForScale(s.height, screenScale);
return s;
}
@interface ASTextKitComponents : NSObject