| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #import "ui/ios/NSString+CrStringDrawing.h" | 5 #import "ui/ios/NSString+CrStringDrawing.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "ui/ios/uikit_util.h" | 8 #include "ui/ios/uikit_util.h" |
| 9 | 9 |
| 10 @implementation NSString (CrStringDrawing) | 10 @implementation NSString (CrStringDrawing) |
| 11 | 11 |
| 12 - (CGRect)cr_boundingRectWithSize:(CGSize)size |
| 13 font:(UIFont*)font { |
| 14 NSDictionary* attributes = font ? @{NSFontAttributeName: font} : @{}; |
| 15 return [self boundingRectWithSize:size |
| 16 options:NSStringDrawingUsesLineFragmentOrigin |
| 17 attributes:attributes |
| 18 context:nil]; |
| 19 } |
| 20 |
| 21 - (CGSize)cr_boundingSizeWithSize:(CGSize)size |
| 22 font:(UIFont*)font { |
| 23 return [self cr_boundingRectWithSize:size font:font].size; |
| 24 } |
| 25 |
| 12 - (CGSize)cr_pixelAlignedSizeWithFont:(UIFont*)font { | 26 - (CGSize)cr_pixelAlignedSizeWithFont:(UIFont*)font { |
| 13 DCHECK(font) << "|font| can not be nil; it is used as a NSDictionary value"; | 27 DCHECK(font) << "|font| can not be nil; it is used as a NSDictionary value"; |
| 14 NSDictionary* attributes = @{ NSFontAttributeName : font }; | 28 NSDictionary* attributes = @{ NSFontAttributeName : font }; |
| 15 return ui::AlignSizeToUpperPixel([self sizeWithAttributes:attributes]); | 29 return ui::AlignSizeToUpperPixel([self sizeWithAttributes:attributes]); |
| 16 } | 30 } |
| 17 | 31 |
| 18 - (CGSize)cr_sizeWithFont:(UIFont*)font { | 32 - (CGSize)cr_sizeWithFont:(UIFont*)font { |
| 19 if (!font) | 33 if (!font) |
| 20 return CGSizeZero; | 34 return CGSizeZero; |
| 21 NSDictionary* attributes = @{ NSFontAttributeName : font }; | 35 NSDictionary* attributes = @{ NSFontAttributeName : font }; |
| 22 CGSize size = [self sizeWithAttributes:attributes]; | 36 CGSize size = [self sizeWithAttributes:attributes]; |
| 23 return CGSizeMake(ceil(size.width), ceil(size.height)); | 37 return CGSizeMake(ceil(size.width), ceil(size.height)); |
| 24 } | 38 } |
| 25 | 39 |
| 26 @end | 40 @end |
| OLD | NEW |