21 const std::vector<size_t>& expected_clusters) {
29 SkTextUtils::Align::kCenter_Align,
32 Shaper::LinebreakPolicy::kParagraph,
33 Shaper::Direction::kLTR,
45 for (
const auto& frag :
result.fFragments) {
46 const auto&
glyphs = frag.fGlyphs;
48 if (
flags & Shaper::kClusters) {
52 for (
const auto& utf_cluster :
glyphs.fClusters) {
62 check_clusters(r,
text, Shaper::kFragmentGlyphs, {});
63 check_clusters(r,
text, Shaper::kClusters,
64 {0, 1, 2, 3, 5, 6, 7, 8, 10, 11, 12, 13});
65 check_clusters(r,
text, (
Shaper::Flags)(Shaper::kClusters | Shaper::kFragmentGlyphs),
66 {0, 1, 2, 3, 5, 6, 7, 8, 10, 11, 12, 13});
73 static constexpr struct {
85 static constexpr struct {
98 for (
const auto& tsize : kTestSizes) {
99 for (
const auto& talign : kTestAligns) {
108 Shaper::VAlign::kTopBaseline,
110 Shaper::LinebreakPolicy::kExplicit,
111 Shaper::Direction::kLTR,
118 const auto shape_result =
123 const auto shape_bounds = shape_result.computeVisualBounds();
126 const auto expected_l = text_point.
x() - shape_bounds.width() * talign.l_selector;
128 std::fabs(shape_bounds.left() - expected_l) < tsize.tolerance,
129 "%f %f %f %f %d", shape_bounds.left(), expected_l, tsize.tolerance,
130 tsize.text_size, talign.align);
132 const auto expected_r = text_point.
x() + shape_bounds.width() * talign.r_selector;
134 std::fabs(shape_bounds.right() - expected_r) < tsize.tolerance,
135 "%f %f %f %f %d", shape_bounds.right(), expected_r, tsize.tolerance,
136 tsize.text_size, talign.align);
146 static constexpr struct {
171 for (
const auto& tsize : kTestSizes) {
172 for (
const auto& talign : kTestAligns) {
180 SkTextUtils::Align::kCenter_Align,
183 Shaper::LinebreakPolicy::kParagraph,
184 Shaper::Direction::kLTR,
195 const auto shape_bounds = shape_result.computeVisualBounds();
198 const auto v_diff = text_box.height() - shape_bounds.height();
200 const auto expected_t = text_box.top() + v_diff * talign.topFactor;
202 std::fabs(shape_bounds.top() - expected_t) < tsize.tolerance,
203 "%f %f %f %f %u", shape_bounds.top(), expected_t, tsize.tolerance,
204 tsize.text_size,
SkToU32(talign.align));
206 const auto expected_b = text_box.bottom() - v_diff * (1 - talign.topFactor);
208 std::fabs(shape_bounds.bottom() - expected_b) < tsize.tolerance,
209 "%f %f %f %f %u", shape_bounds.bottom(), expected_b, tsize.tolerance,
210 tsize.text_size,
SkToU32(talign.align));
223 SkTextUtils::Align::kCenter_Align,
224 Shaper::VAlign::kTop,
226 Shaper::LinebreakPolicy::kParagraph,
227 Shaper::Direction::kLTR,
241 SkASSERT(!shape_result.fFragments.empty());
246 desc.fFlags = Shaper::Flags::kFragmentGlyphs;
247 const auto shape_result =
250 const size_t expectedSize =
text.size();
252 SkASSERT(!shape_result.fFragments.empty());
253 for (
size_t i = 0;
i < expectedSize; ++
i) {
259#if defined(SK_SHAPER_HARFBUZZ_AVAILABLE) && !defined(SK_BUILD_FOR_WIN)
262 class CountingFontMgr :
public SkFontMgr {
264 size_t fallbackCount()
const {
return fFallbackCount; }
269 SkDEBUGFAIL(
"onGetFamilyName called with bad index");
272 SkDEBUGFAIL(
"onCreateStyleSet called with bad index");
308 mutable size_t fFallbackCount = 0;
311 auto fontmgr = sk_make_sp<CountingFontMgr>();
320 SkTextUtils::Align::kCenter_Align,
321 Shaper::VAlign::kTop,
323 Shaper::LinebreakPolicy::kParagraph,
324 Shaper::Direction::kLTR,
DEF_TEST(Skottie_Shaper_Clusters, r)
#define SkDEBUGFAIL(message)
constexpr uint32_t SkToU32(S x)
#define REPORTER_ASSERT(r, cond,...)
virtual void onGetFamilyName(int index, SkString *familyName) const =0
virtual sk_sp< SkTypeface > onMakeFromData(sk_sp< SkData >, int ttcIndex) const =0
virtual sk_sp< SkFontStyleSet > onCreateStyleSet(int index) const =0
virtual sk_sp< SkTypeface > onMatchFamilyStyleCharacter(const char familyName[], const SkFontStyle &, const char *bcp47[], int bcp47Count, SkUnichar character) const =0
virtual sk_sp< SkFontStyleSet > onMatchFamily(const char familyName[]) const =0
virtual sk_sp< SkTypeface > onMakeFromStreamIndex(std::unique_ptr< SkStreamAsset >, int ttcIndex) const =0
virtual sk_sp< SkTypeface > onMakeFromStreamArgs(std::unique_ptr< SkStreamAsset >, const SkFontArguments &) const =0
virtual sk_sp< SkTypeface > onMatchFamilyStyle(const char familyName[], const SkFontStyle &) const =0
virtual sk_sp< SkTypeface > onLegacyMakeTypeface(const char familyName[], SkFontStyle) const =0
virtual sk_sp< SkTypeface > onMakeFromFile(const char path[], int ttcIndex) const =0
virtual int onCountFamilies() const =0
static sk_sp< SkFontStyleSet > CreateEmpty()
static Result Shape(const SkString &text, const TextDesc &desc, const SkPoint &point, const sk_sp< SkFontMgr > &, const sk_sp< SkShapers::Factory > &)
FlutterSemanticsFlag flags
sk_sp< Factory > BestAvailable()
static constexpr SkPoint Make(float x, float y)
constexpr float x() const
static constexpr SkRect MakeXYWH(float x, float y, float w, float h)
static constexpr SkRect MakeWH(float w, float h)