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

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

Issue 704283002: [ui/ios] Add helper methods for getting the bounding size of some text. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix comment Created 6 years, 1 month 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/NSString+CrStringDrawing.mm » ('j') | no next file with comments »
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 #ifndef UI_IOS_NSSTRING_CR_STRING_DRAWING_H_ 5 #ifndef UI_IOS_NSSTRING_CR_STRING_DRAWING_H_
6 #define UI_IOS_NSSTRING_CR_STRING_DRAWING_H_ 6 #define UI_IOS_NSSTRING_CR_STRING_DRAWING_H_
7 7
8 #import <UIKit/UIKit.h> 8 #import <UIKit/UIKit.h>
9 9
10 @interface NSString (CrStringDrawing) 10 @interface NSString (CrStringDrawing)
11 11
12 // Calculates and returns the bounding rect for the receiver drawn using the
13 // given size and font.
14 // This method is implemented as a wrapper around
15 // |boundingRectWithSize:options:attributes:context:| using the following values
16 // for the parameters:
17 // - size: the provided |size|
18 // - options: NSStringDrawingUsesLineFragmentOrigin
19 // - attributes: a NSDictionary with the provided |font|
20 // - context: nil.
21 //
22 // Note that the rect returned may contain fractional values.
23 - (CGRect)cr_boundingRectWithSize:(CGSize)size
24 font:(UIFont*)font;
25
26 // Convenience wrapper to just return the size of |boundingRectWithSize:font:|.
27 //
28 // Note that the size returned may contain fractional values.
29 - (CGSize)cr_boundingSizeWithSize:(CGSize)size
rohitrao (ping after 24h) 2014/11/07 14:21:26 Do we really need this as a convenience method? I
lliabraa 2014/11/07 14:34:50 We never access the origin part of the rect, so if
30 font:(UIFont*)font;
31
12 // Returns the size of the string if it were to be rendered with the specified 32 // Returns the size of the string if it were to be rendered with the specified
13 // font on a single line. The width and height of the CGSize returned are 33 // font on a single line. The width and height of the CGSize returned are
14 // pixel-aligned. 34 // pixel-aligned.
15 // 35 //
16 // This method is a convenience wrapper around sizeWithAttributes: to avoid 36 // This method is a convenience wrapper around sizeWithAttributes: to avoid
17 // boilerplate required to put |font| in a dictionary of attributes. Do not pass 37 // boilerplate required to put |font| in a dictionary of attributes. Do not pass
18 // nil into this method. 38 // nil into this method.
19 - (CGSize)cr_pixelAlignedSizeWithFont:(UIFont*)font; 39 - (CGSize)cr_pixelAlignedSizeWithFont:(UIFont*)font;
20 40
21 // Deprecated: Use cr_pixelAlignedSizeWithFont: or sizeWithAttributes: 41 // Deprecated: Use cr_pixelAlignedSizeWithFont: or sizeWithAttributes:
22 // Provides a drop-in replacement for sizeWithFont:, which was deprecated in iOS 42 // Provides a drop-in replacement for sizeWithFont:, which was deprecated in iOS
23 // 7 in favor of -sizeWithAttributes:. Specifically, this method will return 43 // 7 in favor of -sizeWithAttributes:. Specifically, this method will return
24 // CGSizeZero if |font| is nil, and the width and height returned are rounded up 44 // CGSizeZero if |font| is nil, and the width and height returned are rounded up
25 // to integer values. 45 // to integer values.
26 // TODO(lliabraa): This method was added to ease the transition off of the 46 // TODO(lliabraa): This method was added to ease the transition off of the
27 // deprecated sizeWithFont: method. New call sites should not be added and 47 // deprecated sizeWithFont: method. New call sites should not be added and
28 // existing call sites should be audited to determine the correct behavior for 48 // existing call sites should be audited to determine the correct behavior for
29 // nil |font| and rounding, then replaced with cr_pixelAlignedSizeWithFont: or 49 // nil |font| and rounding, then replaced with cr_pixelAlignedSizeWithFont: or
30 // sizeWithAttributes: (crbug.com/364419). 50 // sizeWithAttributes: (crbug.com/364419).
31 - (CGSize)cr_sizeWithFont:(UIFont*)font; 51 - (CGSize)cr_sizeWithFont:(UIFont*)font;
32 52
33 @end 53 @end
34 54
35 #endif // UI_IOS_NSSTRING_CR_STRING_DRAWING_H_ 55 #endif // UI_IOS_NSSTRING_CR_STRING_DRAWING_H_
OLDNEW
« no previous file with comments | « no previous file | ui/ios/NSString+CrStringDrawing.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698