ASTextKitCoreTextAdditions.h 4.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. //
  2. // ASTextKitCoreTextAdditions.h
  3. // AsyncDisplayKit
  4. //
  5. // Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
  6. // This source code is licensed under the BSD-style license found in the
  7. // LICENSE file in the root directory of this source tree. An additional grant
  8. // of patent rights can be found in the PATENTS file in the same directory.
  9. //
  10. #import <Foundation/Foundation.h>
  11. #import <UIKit/UIKit.h>
  12. #import <AsyncDisplayKit/ASBaseDefines.h>
  13. NS_ASSUME_NONNULL_BEGIN
  14. ASDISPLAYNODE_EXTERN_C_BEGIN
  15. /**
  16. @abstract Returns whether a given attribute is an unsupported Core Text attribute.
  17. @param attributeName The name of the attribute
  18. @discussion The following Core Text attributes are not supported on NSAttributedString, and thus will not be preserved during the conversion:
  19. - kCTForegroundColorFromContextAttributeName
  20. - kCTSuperscriptAttributeName
  21. - kCTGlyphInfoAttributeName
  22. - kCTCharacterShapeAttributeName
  23. - kCTLanguageAttributeName
  24. - kCTRunDelegateAttributeName
  25. - kCTBaselineClassAttributeName
  26. - kCTBaselineInfoAttributeName
  27. - kCTBaselineReferenceInfoAttributeName
  28. - kCTWritingDirectionAttributeName
  29. - kCTUnderlineColorAttributeName
  30. @result Whether attributeName is an unsupported Core Text attribute.
  31. */
  32. BOOL ASAttributeWithNameIsUnsupportedCoreTextAttribute(NSString *attributeName);
  33. /**
  34. @abstract Returns an attributes dictionary for use by NSAttributedString, given a dictionary of Core Text attributes.
  35. @param coreTextAttributes An NSDictionary whose keys are CFAttributedStringRef attributes.
  36. @discussion The following Core Text attributes are not supported on NSAttributedString, and thus will not be preserved during the conversion:
  37. - kCTForegroundColorFromContextAttributeName
  38. - kCTSuperscriptAttributeName
  39. - kCTGlyphInfoAttributeName
  40. - kCTCharacterShapeAttributeName
  41. - kCTLanguageAttributeName
  42. - kCTRunDelegateAttributeName
  43. - kCTBaselineClassAttributeName
  44. - kCTBaselineInfoAttributeName
  45. - kCTBaselineReferenceInfoAttributeName
  46. - kCTWritingDirectionAttributeName
  47. - kCTUnderlineColorAttributeName
  48. @result An NSDictionary of attributes for use by NSAttributedString.
  49. */
  50. extern NSDictionary *NSAttributedStringAttributesForCoreTextAttributes(NSDictionary *coreTextAttributes);
  51. /**
  52. @abstract Returns an NSAttributedString whose Core Text attributes have been converted, where possible, to NSAttributedString attributes.
  53. @param dirtyAttributedString An NSAttributedString that may contain Core Text attributes.
  54. @result An NSAttributedString that's preserved as many CFAttributedString attributes as possible.
  55. */
  56. extern NSAttributedString *ASCleanseAttributedStringOfCoreTextAttributes(NSAttributedString *dirtyAttributedString);
  57. ASDISPLAYNODE_EXTERN_C_END
  58. #pragma mark -
  59. #pragma mark -
  60. @interface NSParagraphStyle (ASTextKitCoreTextAdditions)
  61. /**
  62. @abstract Returns an NSParagraphStyle initialized with the paragraph specifiers from the given CTParagraphStyleRef.
  63. @param coreTextParagraphStyle A Core Text paragraph style.
  64. @discussion It is important to note that not all CTParagraphStyle specifiers are supported by NSParagraphStyle, and consequently, this is a lossy conversion. Notably, the following specifiers will not preserved:
  65. - kCTParagraphStyleSpecifierTabStops
  66. - kCTParagraphStyleSpecifierDefaultTabInterval
  67. - kCTParagraphStyleSpecifierMaximumLineSpacing
  68. - kCTParagraphStyleSpecifierMinimumLineSpacing
  69. - kCTParagraphStyleSpecifierLineSpacingAdjustment
  70. - kCTParagraphStyleSpecifierLineBoundsOptions
  71. @result An NSParagraphStyle initialized with as many of the paragraph specifiers from `coreTextParagraphStyle` as possible.
  72. */
  73. + (instancetype)paragraphStyleWithCTParagraphStyle:(CTParagraphStyleRef)coreTextParagraphStyle;
  74. @end
  75. NS_ASSUME_NONNULL_END