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 3 // found in the LICENSE file. 4 5 #import "ui/ios/NSString+CrStringDrawing.h" 6 7 #include "base/logging.h" 8 #include "ui/ios/uikit_util.h" 9 10 @implementation NSString (CrStringDrawing) 11 12 - (CGSize)cr_pixelAlignedSizeWithFont:(UIFont*)font { 13 DCHECK(font) << "|font| can not be nil; it is used as a NSDictionary value"; 14 NSDictionary* attributes = @{ NSFontAttributeName : font }; 15 return ui::AlignSizeToUpperPixel([self sizeWithAttributes:attributes]); 16 } 17 18 - (CGSize)cr_sizeWithFont:(UIFont*)font { 19 if (!font) 20 return CGSizeZero; 21 NSDictionary* attributes = @{ NSFontAttributeName : font }; 22 CGSize size = [self sizeWithAttributes:attributes]; 23 return CGSizeMake(ceil(size.width), ceil(size.height)); 24 } 25 26 @end 27