Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(404)

Side by Side Diff: ui/ios/NSString+CrStringDrawing.mm

Issue 539253002: Add a couple UIKit util functions in src/ui/ios/ (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | ui/ios/ui_ios.gyp » ('j') | ui/ios/ui_ios_tests.gyp » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 8 #include "ui/ios/uikit_util.h"
9 namespace {
10 // Returns the closest pixel-aligned value higher than |value|, taking the scale
11 // factor into account. At a scale of 1, equivalent to ceil().
12 // TODO(lliabraa): Move this method to a common util file (crbug.com/409823).
13 CGFloat alignValueToUpperPixel(CGFloat value) {
14 CGFloat scale = [[UIScreen mainScreen] scale];
15 return ceil(value * scale) / scale;
16 }
17 } // namespace
18 9
19 @implementation NSString (CrStringDrawing) 10 @implementation NSString (CrStringDrawing)
20 11
21 - (CGSize)cr_pixelAlignedSizeWithFont:(UIFont*)font { 12 - (CGSize)cr_pixelAlignedSizeWithFont:(UIFont*)font {
22 DCHECK(font) << "|font| can not be nil; it is used as a NSDictionary value"; 13 DCHECK(font) << "|font| can not be nil; it is used as a NSDictionary value";
23 NSDictionary* attributes = @{ NSFontAttributeName : font }; 14 NSDictionary* attributes = @{ NSFontAttributeName : font };
24 CGSize size = [self sizeWithAttributes:attributes]; 15 return ui::alignSizeToUpperPixel([self sizeWithAttributes:attributes]);
25 return CGSizeMake(alignValueToUpperPixel(size.width),
26 alignValueToUpperPixel(size.height));
27 } 16 }
28 17
29 - (CGSize)cr_sizeWithFont:(UIFont*)font { 18 - (CGSize)cr_sizeWithFont:(UIFont*)font {
30 if (!font) 19 if (!font)
31 return CGSizeZero; 20 return CGSizeZero;
32 NSDictionary* attributes = @{ NSFontAttributeName : font }; 21 NSDictionary* attributes = @{ NSFontAttributeName : font };
33 CGSize size = [self sizeWithAttributes:attributes]; 22 CGSize size = [self sizeWithAttributes:attributes];
34 return CGSizeMake(ceil(size.width), ceil(size.height)); 23 return CGSizeMake(ceil(size.width), ceil(size.height));
35 } 24 }
36 25
37 @end 26 @end
OLDNEW
« no previous file with comments | « no previous file | ui/ios/ui_ios.gyp » ('j') | ui/ios/ui_ios_tests.gyp » ('J')

Powered by Google App Engine
This is Rietveld 408576698