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_CORE_TEXT_UTIL_H_ |
| 6 #define IOS_CHROME_BROWSER_UI_UTIL_CORE_TEXT_UTIL_H_ |
| 7 |
| 8 #import <CoreText/CoreText.h> |
| 9 #import <UIKit/UIKit.h> |
| 10 |
| 11 #import "base/mac/scoped_cftyperef.h" |
| 12 |
| 13 @class ManualTextFramer; |
| 14 |
| 15 namespace core_text_util { |
| 16 |
| 17 // Uses CTFrameSetter to create a CTFrameRef corresponding to |string| drawn |
| 18 // within the path described by |bounds|. |
| 19 base::ScopedCFTypeRef<CTFrameRef> CreateTextFrameForStringInBounds( |
| 20 NSAttributedString* string, |
| 21 CGRect bounds); |
| 22 |
| 23 // The CTFrames returned by CTFameSetter sometimes erroneously frame the same |
| 24 // portion of the original string twice. In addition, these CTFrames may have |
| 25 // innacurate ranges for RTL languages. This function returns true if the |
| 26 // string range for |text_frame| returned by CTFrameGetVisibleStringRange() is |
| 27 // properly framed with no repeats and if the string range length of |
| 28 // |text_frame| matches the string range length of the frame generated by |
| 29 // |manual_framer|, which more accurately handles creating string ranges for RTL |
| 30 // strings. |string| is the attributed string from which |text_frame| and |
| 31 // |manual_framer| were created. |
| 32 bool IsTextFrameValid(CTFrameRef text_frame, |
| 33 ManualTextFramer* manual_framer, |
| 34 NSAttributedString* string); |
| 35 |
| 36 // Returns the width of the typographic bounds for |line|, excluding trailing |
| 37 // whitespace. |
| 38 CGFloat GetTrimmedLineWidth(CTLineRef line); |
| 39 |
| 40 // Returns the width of the typographic bounds for the glyphs in |range| for |
| 41 // |run|. |
| 42 CGFloat GetRunWidthWithRange(CTRunRef run, CFRange range); |
| 43 |
| 44 // Returns the width of the typographic bounds for the glyph in |run| at |
| 45 // |glyph_idx|. |
| 46 CGFloat GetGlyphWidth(CTRunRef run, CFIndex glyph_idx); |
| 47 |
| 48 // Returns the index of the first glyph in the leading direction in |range| for |
| 49 // |run| that corresponds with a character that is a member of |set|. |string| |
| 50 // is the string from which |run| was created, and is used to map from glyphs to |
| 51 // characters. Returns kCFNotFound if no glyphs are found. |
| 52 CFIndex GetGlyphIdxForCharInSet(CTRunRef run, |
| 53 CFRange range, |
| 54 NSAttributedString* string, |
| 55 NSCharacterSet* set); |
| 56 |
| 57 // Returns the index of the character corresponding with the glyph at |
| 58 // |glyph_idx| in |run|. |
| 59 NSUInteger GetStringIdxForGlyphIdx(CTRunRef run, CFIndex glyph_idx); |
| 60 |
| 61 // Returns the string range associated with |run|. |
| 62 NSRange GetStringRangeForRun(CTRunRef run); |
| 63 |
| 64 // Enumerates each attributes dictionary for |range| in |string| and executes |
| 65 // |block| on the dictionary. |
| 66 typedef void (^AttributesBlock)(NSDictionary* attributes); |
| 67 void EnumerateAttributesInString(NSAttributedString* string, |
| 68 NSRange range, |
| 69 AttributesBlock block); |
| 70 |
| 71 // Returns the line height for |range| in |string|. |
| 72 CGFloat GetLineHeight(NSAttributedString* string, NSRange range); |
| 73 |
| 74 // Returns the line spacing for |range| in |string|. |
| 75 CGFloat GetLineSpacing(NSAttributedString* string, NSRange range); |
| 76 |
| 77 // Returns the effective text alignment for |string|. |
| 78 NSTextAlignment GetEffectiveTextAlignment(NSAttributedString* string); |
| 79 |
| 80 // Returns the effective writing direction for |string|. |
| 81 NSWritingDirection GetEffectiveWritingDirection(NSAttributedString* string); |
| 82 |
| 83 } // namespace core_text_util |
| 84 |
| 85 #endif // IOS_CHROME_BROWSER_UI_UTIL_CORE_TEXT_UTIL_H_ |
OLD | NEW |