-
Notifications
You must be signed in to change notification settings - Fork 24.6k
/
Copy pathTextLayoutManagerExtended.h
58 lines (49 loc) · 1.84 KB
/
TextLayoutManagerExtended.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/*
* 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 <glog/logging.h>
#include <type_traits>
#include <react/renderer/attributedstring/AttributedStringBox.h>
#include <react/renderer/attributedstring/ParagraphAttributes.h>
#include <react/renderer/graphics/Size.h>
#include <react/renderer/textlayoutmanager/TextLayoutManager.h>
#include <react/renderer/textlayoutmanager/TextMeasureCache.h>
namespace facebook::react {
/**
* TextLayoutManagerExtended acts as an adapter for TextLayoutManager methods
* which may not exist for a specific platform. Callers can check at
* compile-time whether a method is supported, and calling if it is not will
* terminate.
*/
template <typename TextLayoutManagerT>
requires(std::is_same_v<TextLayoutManager, std::decay_t<TextLayoutManagerT>>)
class TextLayoutManagerExtended {
public:
static constexpr bool supportsLineMeasurement() {
return requires(TextLayoutManagerT textLayoutManager) {
{
textLayoutManager.measureLines(
AttributedStringBox{}, ParagraphAttributes{}, Size{})
} -> std::same_as<LinesMeasurements>;
};
}
TextLayoutManagerExtended(TextLayoutManagerT& textLayoutManager)
: textLayoutManager_(textLayoutManager) {}
LinesMeasurements measureLines(
const AttributedStringBox& attributedStringBox,
const ParagraphAttributes& paragraphAttributes,
const Size& size) {
if constexpr (supportsLineMeasurement()) {
return textLayoutManager_.measureLines(
attributedStringBox, paragraphAttributes, size);
}
LOG(FATAL) << "Platform TextLayoutManager does not support measureLines";
}
private:
TextLayoutManagerT& textLayoutManager_;
};
} // namespace facebook::react