YYTextLine.h 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. //
  2. // YYTextLine.h
  3. // YYKit <https://github.com/ibireme/YYKit>
  4. //
  5. // Created by ibireme on 15/3/10.
  6. // Copyright (c) 2015 ibireme.
  7. //
  8. // This source code is licensed under the MIT-style license found in the
  9. // LICENSE file in the root directory of this source tree.
  10. //
  11. #import <UIKit/UIKit.h>
  12. #import <CoreText/CoreText.h>
  13. #if __has_include(<YYKit/YYKit.h>)
  14. #import <YYKit/YYTextAttribute.h>
  15. #else
  16. #import "YYTextAttribute.h"
  17. #endif
  18. @class YYTextRunGlyphRange;
  19. NS_ASSUME_NONNULL_BEGIN
  20. /**
  21. A text line object wrapped `CTLineRef`, see `YYTextLayout` for more.
  22. */
  23. @interface YYTextLine : NSObject
  24. + (instancetype)lineWithCTLine:(CTLineRef)CTLine position:(CGPoint)position vertical:(BOOL)isVertical;
  25. @property (nonatomic) NSUInteger index; ///< line index
  26. @property (nonatomic) NSUInteger row; ///< line row
  27. @property (nullable, nonatomic, strong) NSArray<NSArray<YYTextRunGlyphRange *> *> *verticalRotateRange; ///< Run rotate range
  28. @property (nonatomic, readonly) CTLineRef CTLine; ///< CoreText line
  29. @property (nonatomic, readonly) NSRange range; ///< string range
  30. @property (nonatomic, readonly) BOOL vertical; ///< vertical form
  31. @property (nonatomic, readonly) CGRect bounds; ///< bounds (ascent + descent)
  32. @property (nonatomic, readonly) CGSize size; ///< bounds.size
  33. @property (nonatomic, readonly) CGFloat width; ///< bounds.size.width
  34. @property (nonatomic, readonly) CGFloat height; ///< bounds.size.height
  35. @property (nonatomic, readonly) CGFloat top; ///< bounds.origin.y
  36. @property (nonatomic, readonly) CGFloat bottom; ///< bounds.origin.y + bounds.size.height
  37. @property (nonatomic, readonly) CGFloat left; ///< bounds.origin.x
  38. @property (nonatomic, readonly) CGFloat right; ///< bounds.origin.x + bounds.size.width
  39. @property (nonatomic) CGPoint position; ///< baseline position
  40. @property (nonatomic, readonly) CGFloat ascent; ///< line ascent
  41. @property (nonatomic, readonly) CGFloat descent; ///< line descent
  42. @property (nonatomic, readonly) CGFloat leading; ///< line leading
  43. @property (nonatomic, readonly) CGFloat lineWidth; ///< line width
  44. @property (nonatomic, readonly) CGFloat trailingWhitespaceWidth;
  45. @property (nullable, nonatomic, readonly) NSArray<YYTextAttachment *> *attachments; ///< YYTextAttachment
  46. @property (nullable, nonatomic, readonly) NSArray<NSValue *> *attachmentRanges; ///< NSRange(NSValue)
  47. @property (nullable, nonatomic, readonly) NSArray<NSValue *> *attachmentRects; ///< CGRect(NSValue)
  48. @end
  49. typedef NS_ENUM(NSUInteger, YYTextRunGlyphDrawMode) {
  50. /// No rotate.
  51. YYTextRunGlyphDrawModeHorizontal = 0,
  52. /// Rotate vertical for single glyph.
  53. YYTextRunGlyphDrawModeVerticalRotate = 1,
  54. /// Rotate vertical for single glyph, and move the glyph to a better position,
  55. /// such as fullwidth punctuation.
  56. YYTextRunGlyphDrawModeVerticalRotateMove = 2,
  57. };
  58. /**
  59. A range in CTRun, used for vertical form.
  60. */
  61. @interface YYTextRunGlyphRange : NSObject
  62. @property (nonatomic) NSRange glyphRangeInRun;
  63. @property (nonatomic) YYTextRunGlyphDrawMode drawMode;
  64. + (instancetype)rangeWithRange:(NSRange)range drawMode:(YYTextRunGlyphDrawMode)mode;
  65. @end
  66. NS_ASSUME_NONNULL_END