ParagraphAttributes.h 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /*
  2. * Copyright (c) Facebook, Inc. and its affiliates.
  3. *
  4. * This source code is licensed under the MIT license found in the
  5. * LICENSE file in the root directory of this source tree.
  6. */
  7. #pragma once
  8. #include <limits>
  9. #include <folly/Hash.h>
  10. #include <react/attributedstring/primitives.h>
  11. #include <react/debug/DebugStringConvertible.h>
  12. #include <react/graphics/Geometry.h>
  13. namespace facebook {
  14. namespace react {
  15. class ParagraphAttributes;
  16. using SharedParagraphAttributes = std::shared_ptr<const ParagraphAttributes>;
  17. /*
  18. * Represents all visual attributes of a paragraph of text.
  19. * Two data structures, ParagraphAttributes and AttributedText, should be
  20. * enough to define visual representation of a piece of text on the screen.
  21. */
  22. class ParagraphAttributes : public DebugStringConvertible {
  23. public:
  24. #pragma mark - Fields
  25. /*
  26. * Maximum number of lines which paragraph can take.
  27. * Zero value represents "no limit".
  28. */
  29. int maximumNumberOfLines{};
  30. /*
  31. * In case if a text cannot fit given boundaries, defines a place where
  32. * an ellipsize should be placed.
  33. */
  34. EllipsizeMode ellipsizeMode{};
  35. TextBreakStrategy textBreakStrategy{};
  36. /*
  37. * Enables font size adjustment to fit constrained boundaries.
  38. */
  39. bool adjustsFontSizeToFit{};
  40. /*
  41. * In case of font size adjustment enabled, defines minimum and maximum
  42. * font sizes.
  43. */
  44. Float minimumFontSize{std::numeric_limits<Float>::quiet_NaN()};
  45. Float maximumFontSize{std::numeric_limits<Float>::quiet_NaN()};
  46. bool operator==(const ParagraphAttributes &) const;
  47. bool operator!=(const ParagraphAttributes &) const;
  48. #pragma mark - DebugStringConvertible
  49. #if RN_DEBUG_STRING_CONVERTIBLE
  50. SharedDebugStringConvertibleList getDebugProps() const override;
  51. #endif
  52. };
  53. } // namespace react
  54. } // namespace facebook
  55. namespace std {
  56. template <>
  57. struct hash<facebook::react::ParagraphAttributes> {
  58. size_t operator()(
  59. const facebook::react::ParagraphAttributes &attributes) const {
  60. return folly::hash::hash_combine(
  61. 0,
  62. attributes.maximumNumberOfLines,
  63. attributes.ellipsizeMode,
  64. attributes.textBreakStrategy,
  65. attributes.adjustsFontSizeToFit,
  66. attributes.minimumFontSize,
  67. attributes.maximumFontSize);
  68. }
  69. };
  70. } // namespace std