ASTextKitFontSizeAdjuster.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. //
  2. // ASTextKitFontSizeAdjuster.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 <UIKit/UIKit.h>
  11. #import <AsyncDisplayKit/ASTextKitAttributes.h>
  12. #import <AsyncDisplayKit/ASBaseDefines.h>
  13. NS_ASSUME_NONNULL_BEGIN
  14. @class ASTextKitContext;
  15. AS_SUBCLASSING_RESTRICTED
  16. @interface ASTextKitFontSizeAdjuster : NSObject
  17. @property (nonatomic, assign) CGSize constrainedSize;
  18. /**
  19. * Creates a class that will return a scale factor the will make a string fit inside the constrained size.
  20. *
  21. * "Fitting" means that both the longest word in the string will fit without breaking in the constrained
  22. * size's width AND that the entire string will try to fit within attribute's maximumLineCount. The amount
  23. * that the string will scale is based upon the attribute's pointSizeScaleFactors. If the string cannot fit
  24. * in the given width/number of lines, the smallest scale factor will be returned.
  25. *
  26. * @param context The text kit context
  27. * @param constrainedSize The constrained size to render into
  28. * @param textComponentAttributes The renderer's text attributes
  29. */
  30. - (instancetype)initWithContext:(ASTextKitContext *)context
  31. constrainedSize:(CGSize)constrainedSize
  32. textKitAttributes:(const ASTextKitAttributes &)textComponentAttributes;
  33. /**
  34. * Returns the best fit scale factor for the text
  35. */
  36. - (CGFloat)scaleFactor;
  37. /**
  38. * Takes all of the attributed string attributes dealing with size (font size, line spacing, kerning, etc) and
  39. * scales them by the scaleFactor. I wouldn't be surprised if I missed some in here.
  40. */
  41. + (void)adjustFontSizeForAttributeString:(NSMutableAttributedString *)attrString withScaleFactor:(CGFloat)scaleFactor;
  42. @end
  43. NS_ASSUME_NONNULL_END