/* * Copyright (c) Meta Platforms, Inc. and affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */ #pragma once #include #include #include #include #include #include #include #include #include #include #include namespace facebook { namespace react { class TextAttributes; using SharedTextAttributes = std::shared_ptr; class TextAttributes : public DebugStringConvertible { public: /* * Returns TextAttribute object which has actual default attribute values * (e.g. `foregroundColor = black`), in oppose to TextAttribute's default * constructor which creates an object with nulled attributes. */ static TextAttributes defaultTextAttributes(); #pragma mark - Fields // Color SharedColor foregroundColor{}; SharedColor backgroundColor{}; Float opacity{std::numeric_limits::quiet_NaN()}; // Font std::string fontFamily{""}; Float fontSize{std::numeric_limits::quiet_NaN()}; Float fontSizeMultiplier{std::numeric_limits::quiet_NaN()}; std::optional fontWeight{}; std::optional fontStyle{}; std::optional fontVariant{}; std::optional allowFontScaling{}; std::optional dynamicTypeRamp{}; Float letterSpacing{std::numeric_limits::quiet_NaN()}; std::optional textTransform{}; // Paragraph Styles Float lineHeight{std::numeric_limits::quiet_NaN()}; std::optional alignment{}; std::optional baseWritingDirection{}; std::optional lineBreakStrategy{}; // Decoration SharedColor textDecorationColor{}; std::optional textDecorationLineType{}; std::optional textDecorationStyle{}; // Shadow // TODO: Use `Point` type instead of `Size` for `textShadowOffset` attribute. std::optional textShadowOffset{}; Float textShadowRadius{std::numeric_limits::quiet_NaN()}; SharedColor textShadowColor{}; // Special std::optional isHighlighted{}; // TODO T59221129: document where this value comes from and how it is set. // It's not clear if this is being used properly, or if it's being set at all. // Currently, it is intentionally *not* being set as part of BaseTextProps // construction. std::optional layoutDirection{}; std::optional accessibilityRole{}; #pragma mark - Operations void apply(TextAttributes textAttributes); #pragma mark - Operators bool operator==(const TextAttributes &rhs) const; bool operator!=(const TextAttributes &rhs) const; #pragma mark - DebugStringConvertible #if RN_DEBUG_STRING_CONVERTIBLE SharedDebugStringConvertibleList getDebugProps() const override; #endif }; } // namespace react } // namespace facebook namespace std { template <> struct hash { size_t operator()( const facebook::react::TextAttributes &textAttributes) const { return folly::hash::hash_combine( 0, textAttributes.foregroundColor, textAttributes.backgroundColor, textAttributes.opacity, textAttributes.fontFamily, textAttributes.fontSize, textAttributes.fontSizeMultiplier, textAttributes.fontWeight, textAttributes.fontStyle, textAttributes.fontVariant, textAttributes.allowFontScaling, textAttributes.letterSpacing, textAttributes.textTransform, textAttributes.lineHeight, textAttributes.alignment, textAttributes.baseWritingDirection, textAttributes.lineBreakStrategy, textAttributes.textDecorationColor, textAttributes.textDecorationLineType, textAttributes.textDecorationStyle, textAttributes.textShadowOffset, textAttributes.textShadowRadius, textAttributes.textShadowColor, textAttributes.isHighlighted, textAttributes.layoutDirection, textAttributes.accessibilityRole); } }; } // namespace std