OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 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 #ifndef IOS_CHROME_BROWSER_UI_UTIL_TEXT_REGION_MAPPER_H_ |
| 6 #define IOS_CHROME_BROWSER_UI_UTIL_TEXT_REGION_MAPPER_H_ |
| 7 |
| 8 #import <UIKit/UIKit.h> |
| 9 |
| 10 // A TextRegionMapper is a utility class that can, given an attributed string |
| 11 // and bounds that the string will be rendered in, return the regions (rects) |
| 12 // that ranges of the string occupy when rendered in the given bounds. |
| 13 |
| 14 // For testing purposes the class interface is defined as a protocol. |
| 15 |
| 16 @protocol TextRegionMapper<NSObject> |
| 17 // Create a new mapper. The mapper can be used repeatedly as long as the |
| 18 // string and its bounds do not change; if they do, another mapper must be |
| 19 // created. |
| 20 - (instancetype)initWithAttributedString:(NSAttributedString*)string |
| 21 bounds:(CGRect)bounds; |
| 22 |
| 23 // Returns an array of (NSValue-boxed) CGRects which enclose the regions inside |
| 24 // |bounds| that the characters of |string|'s substring at |range| occupy. If |
| 25 // the string is spread across several lines, a given range might occupy several |
| 26 // disjoint rects. |
| 27 // Note that the rect encloses only the region occupied by the glyphs, not any |
| 28 // leading or other space padding. |
| 29 // If |range| is partially or wholly outside of the range of |string|, an |
| 30 // empty array is returned. |
| 31 - (NSArray*)rectsForRange:(NSRange)range; |
| 32 |
| 33 @end |
| 34 |
| 35 // The actual class implementation works by typesetting the text using CoreText. |
| 36 @interface CoreTextRegionMapper : NSObject<TextRegionMapper> |
| 37 |
| 38 - (instancetype)initWithAttributedString:(NSAttributedString*)string |
| 39 bounds:(CGRect)bounds |
| 40 NS_DESIGNATED_INITIALIZER; |
| 41 |
| 42 - (instancetype)init NS_UNAVAILABLE; |
| 43 |
| 44 @end |
| 45 |
| 46 #endif // IOS_CHROME_BROWSER_UI_UTIL_TEXT_REGION_MAPPER_H_ |
OLD | NEW |