|
| 1 | +/* |
| 2 | + * Copyright (c) Meta Platforms, Inc. and 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 | + |
| 8 | +#pragma once |
| 9 | + |
| 10 | +#include <react/renderer/attributedstring/AttributedStringBox.h> |
| 11 | +#include <react/renderer/attributedstring/ParagraphAttributes.h> |
| 12 | +#include <react/renderer/core/LayoutConstraints.h> |
| 13 | +#include <react/renderer/textlayoutmanager/TextLayoutContext.h> |
| 14 | +#include <react/renderer/textlayoutmanager/TextMeasureCache.h> |
| 15 | +#include <react/utils/ContextContainer.h> |
| 16 | +#include <memory> |
| 17 | + |
| 18 | +namespace facebook::react { |
| 19 | + |
| 20 | +/* |
| 21 | + * Cross platform facade for text measurement (e.g. Android-specific |
| 22 | + * TextLayoutManager) |
| 23 | + */ |
| 24 | +class TextLayoutManager { |
| 25 | + public: |
| 26 | + TextLayoutManager(const ContextContainer::Shared& contextContainer); |
| 27 | + |
| 28 | + /* |
| 29 | + * Not copyable. |
| 30 | + */ |
| 31 | + TextLayoutManager(const TextLayoutManager&) = delete; |
| 32 | + TextLayoutManager& operator=(const TextLayoutManager&) = delete; |
| 33 | + |
| 34 | + /* |
| 35 | + * Not movable. |
| 36 | + */ |
| 37 | + TextLayoutManager(TextLayoutManager&&) = delete; |
| 38 | + TextLayoutManager& operator=(TextLayoutManager&&) = delete; |
| 39 | + |
| 40 | + /* |
| 41 | + * Measures `attributedString` using native text rendering infrastructure. |
| 42 | + */ |
| 43 | + TextMeasurement measure( |
| 44 | + const AttributedStringBox& attributedStringBox, |
| 45 | + const ParagraphAttributes& paragraphAttributes, |
| 46 | + const TextLayoutContext& layoutContext, |
| 47 | + const LayoutConstraints& layoutConstraints) const; |
| 48 | + |
| 49 | + /* |
| 50 | + * Measures lines of `attributedString` using native text rendering |
| 51 | + * infrastructure. |
| 52 | + */ |
| 53 | + LinesMeasurements measureLines( |
| 54 | + const AttributedStringBox& attributedStringBox, |
| 55 | + const ParagraphAttributes& paragraphAttributes, |
| 56 | + const Size& size) const; |
| 57 | + |
| 58 | + /* |
| 59 | + * Returns an opaque pointer to platform-specific TextLayoutManager. |
| 60 | + * Is used on a native views layer to delegate text rendering to the manager. |
| 61 | + */ |
| 62 | + std::shared_ptr<void> getNativeTextLayoutManager() const; |
| 63 | + |
| 64 | + protected: |
| 65 | + std::shared_ptr<const ContextContainer> contextContainer_; |
| 66 | + std::shared_ptr<void> nativeTextLayoutManager_; |
| 67 | + TextMeasureCache textMeasureCache_; |
| 68 | + LineMeasureCache lineMeasureCache_; |
| 69 | +}; |
| 70 | + |
| 71 | +} // namespace facebook::react |
0 commit comments