YYTextDebugOption.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. //
  2. // YYTextDebugOption.h
  3. // YYKit <https://github.com/ibireme/YYKit>
  4. //
  5. // Created by ibireme on 15/4/8.
  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. @class YYTextDebugOption;
  13. NS_ASSUME_NONNULL_BEGIN
  14. /**
  15. The YYTextDebugTarget protocol defines the method a debug target should implement.
  16. A debug target can be add to the global container to receive the shared debug
  17. option changed notification.
  18. */
  19. @protocol YYTextDebugTarget <NSObject>
  20. @required
  21. /**
  22. When the shared debug option changed, this method would be called on main thread.
  23. It should return as quickly as possible. The option's property should not be changed
  24. in this method.
  25. @param option The shared debug option.
  26. */
  27. - (void)setDebugOption:(nullable YYTextDebugOption *)option;
  28. @end
  29. /**
  30. The debug option for YYText.
  31. */
  32. @interface YYTextDebugOption : NSObject <NSCopying>
  33. @property (nullable, nonatomic, strong) UIColor *baselineColor; ///< baseline color
  34. @property (nullable, nonatomic, strong) UIColor *CTFrameBorderColor; ///< CTFrame path border color
  35. @property (nullable, nonatomic, strong) UIColor *CTFrameFillColor; ///< CTFrame path fill color
  36. @property (nullable, nonatomic, strong) UIColor *CTLineBorderColor; ///< CTLine bounds border color
  37. @property (nullable, nonatomic, strong) UIColor *CTLineFillColor; ///< CTLine bounds fill color
  38. @property (nullable, nonatomic, strong) UIColor *CTLineNumberColor; ///< CTLine line number color
  39. @property (nullable, nonatomic, strong) UIColor *CTRunBorderColor; ///< CTRun bounds border color
  40. @property (nullable, nonatomic, strong) UIColor *CTRunFillColor; ///< CTRun bounds fill color
  41. @property (nullable, nonatomic, strong) UIColor *CTRunNumberColor; ///< CTRun number color
  42. @property (nullable, nonatomic, strong) UIColor *CGGlyphBorderColor; ///< CGGlyph bounds border color
  43. @property (nullable, nonatomic, strong) UIColor *CGGlyphFillColor; ///< CGGlyph bounds fill color
  44. - (BOOL)needDrawDebug; ///< `YES`: at least one debug color is visible. `NO`: all debug color is invisible/nil.
  45. - (void)clear; ///< Set all debug color to nil.
  46. /**
  47. Add a debug target.
  48. @discussion When `setSharedDebugOption:` is called, all added debug target will
  49. receive `setDebugOption:` in main thread. It maintains an unsafe_unretained
  50. reference to this target. The target must to removed before dealloc.
  51. @param target A debug target.
  52. */
  53. + (void)addDebugTarget:(id<YYTextDebugTarget>)target;
  54. /**
  55. Remove a debug target which is added by `addDebugTarget:`.
  56. @param target A debug target.
  57. */
  58. + (void)removeDebugTarget:(id<YYTextDebugTarget>)target;
  59. /**
  60. Returns the shared debug option.
  61. @return The shared debug option, default is nil.
  62. */
  63. + (nullable YYTextDebugOption *)sharedDebugOption;
  64. /**
  65. Set a debug option as shared debug option.
  66. This method must be called on main thread.
  67. @discussion When call this method, the new option will set to all debug target
  68. which is added by `addDebugTarget:`.
  69. @param option A new debug option (nil is valid).
  70. */
  71. + (void)setSharedDebugOption:(nullable YYTextDebugOption *)option;
  72. @end
  73. NS_ASSUME_NONNULL_END