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.
5 #import "ui/ios/NSString+CrStringDrawing.h"
7 #include "base/logging.h"
8 #include "ui/ios/uikit_util.h"
10 @implementation NSString (CrStringDrawing)
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]);
18 - (CGSize)cr_sizeWithFont:(UIFont*)font {
21 NSDictionary* attributes = @{ NSFontAttributeName : font };
22 CGSize size = [self sizeWithAttributes:attributes];
23 return CGSizeMake(ceil(size.width), ceil(size.height));