mirror of
https://github.com/HackPlan/AsyncDisplayKit.git
synced 2026-04-01 12:23:20 +08:00
Merge pull request #673 from adly-holler/ceil-text-size
Align ASEditableTextNode to pixel boundaries
This commit is contained in:
@@ -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));
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user