YYTextRubyAnnotation.h 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. //
  2. // YYTextRubyAnnotation.h
  3. // YYKit <https://github.com/ibireme/YYKit>
  4. //
  5. // Created by ibireme on 15/4/24.
  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. NS_ASSUME_NONNULL_BEGIN
  14. /**
  15. Wrapper for CTRubyAnnotationRef.
  16. Example:
  17. YYTextRubyAnnotation *ruby = [YYTextRubyAnnotation new];
  18. ruby.textBefore = @"zhù yīn";
  19. CTRubyAnnotationRef ctRuby = ruby.CTRubyAnnotation;
  20. if (ctRuby) {
  21. /// add to attributed string
  22. CFRelease(ctRuby);
  23. }
  24. */
  25. @interface YYTextRubyAnnotation : NSObject <NSCopying, NSCoding>
  26. /// Specifies how the ruby text and the base text should be aligned relative to each other.
  27. @property (nonatomic) CTRubyAlignment alignment;
  28. /// Specifies how the ruby text can overhang adjacent characters.
  29. @property (nonatomic) CTRubyOverhang overhang;
  30. /// Specifies the size of the annotation text as a percent of the size of the base text.
  31. @property (nonatomic) CGFloat sizeFactor;
  32. /// The ruby text is positioned before the base text;
  33. /// i.e. above horizontal text and to the right of vertical text.
  34. @property (nullable, nonatomic, copy) NSString *textBefore;
  35. /// The ruby text is positioned after the base text;
  36. /// i.e. below horizontal text and to the left of vertical text.
  37. @property (nullable, nonatomic, copy) NSString *textAfter;
  38. /// The ruby text is positioned to the right of the base text whether it is horizontal or vertical.
  39. /// This is the way that Bopomofo annotations are attached to Chinese text in Taiwan.
  40. @property (nullable, nonatomic, copy) NSString *textInterCharacter;
  41. /// The ruby text follows the base text with no special styling.
  42. @property (nullable, nonatomic, copy) NSString *textInline;
  43. /**
  44. Create a ruby object from CTRuby object.
  45. @param ctRuby A CTRuby object.
  46. @return A ruby object, or nil when an error occurs.
  47. */
  48. + (instancetype)rubyWithCTRubyRef:(CTRubyAnnotationRef)ctRuby NS_AVAILABLE_IOS(8_0);
  49. /**
  50. Create a CTRuby object from the instance.
  51. @return A new CTRuby object, or NULL when an error occurs.
  52. The returned value should be release after used.
  53. */
  54. - (nullable CTRubyAnnotationRef)CTRubyAnnotation CF_RETURNS_RETAINED NS_AVAILABLE_IOS(8_0);
  55. @end
  56. NS_ASSUME_NONNULL_END