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 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257
|
// Copyright 2024 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "third_party/blink/renderer/platform/fonts/shaping/harfbuzz_face.h"
#include "hb.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/renderer/platform/fonts/font.h"
#include "third_party/blink/renderer/platform/fonts/font_platform_data.h"
#include "third_party/blink/renderer/platform/fonts/glyph.h"
#include "third_party/blink/renderer/platform/fonts/shaping/variation_selector_mode.h"
#include "third_party/blink/renderer/platform/testing/font_test_helpers.h"
#include "third_party/blink/renderer/platform/testing/runtime_enabled_features_test_helpers.h"
#include "third_party/blink/renderer/platform/testing/unit_test_helpers.h"
#include "third_party/googletest/src/googletest/include/gtest/gtest.h"
namespace blink {
namespace {
String WPTFontPath(const String& font_name) {
return test::BlinkWebTestsDir() +
"/external/wpt/css/css-fonts/resources/vs/" + font_name;
}
hb_codepoint_t GetGlyphForVariationSequenceFromFont(
Font* font,
UChar32 character,
UChar32 variation_selector) {
const FontPlatformData& font_without_char_platform_data =
font->PrimaryFont()->PlatformData();
HarfBuzzFace* face_without_char =
font_without_char_platform_data.GetHarfBuzzFace();
EXPECT_TRUE(face_without_char);
return face_without_char->HarfBuzzGetGlyphForTesting(character,
variation_selector);
}
hb_codepoint_t GetGlyphForEmojiVSFromFontWithVS15(UChar32 character,
UChar32 variation_selector) {
Font* font =
test::CreateTestFont(AtomicString("Noto Emoji"),
WPTFontPath("NotoEmoji-Regular_subset.ttf"), 11);
return GetGlyphForVariationSequenceFromFont(font, character,
variation_selector);
}
hb_codepoint_t GetGlyphForEmojiVSFromFontWithVS16(UChar32 character,
UChar32 variation_selector) {
Font* font = test::CreateTestFont(
AtomicString("Noto Color Emoji"),
WPTFontPath("NotoColorEmoji-Regular_subset.ttf"), 11);
return GetGlyphForVariationSequenceFromFont(font, character,
variation_selector);
}
hb_codepoint_t GetGlyphForEmojiVSFromFontWithBaseCharOnly(
UChar32 character,
UChar32 variation_selector) {
Font* font = test::CreateTestFont(
AtomicString("Noto Emoji Without VS"),
WPTFontPath("NotoEmoji-Regular_without-cmap14-subset.ttf"), 11);
return GetGlyphForVariationSequenceFromFont(font, character,
variation_selector);
}
hb_codepoint_t GetGlyphForStandardizedVSFromFontWithBaseCharOnly() {
UChar32 character = kMongolianLetterA;
UChar32 variation_selector = kMongolianFreeVariationSelectorTwo;
Font* font = test::CreateTestFont(AtomicString("Noto Sans Mongolian"),
blink::test::BlinkWebTestsFontsTestDataPath(
"noto/NotoSansMongolian-regular.woff2"),
11);
return GetGlyphForVariationSequenceFromFont(font, character,
variation_selector);
}
hb_codepoint_t GetGlyphForCJKVSFromFontWithVS() {
UChar32 character = kFullwidthExclamationMark;
UChar32 variation_selector = kVariationSelector2Character;
Font* font = test::CreateTestFont(
AtomicString("Noto Sans CJK JP"),
blink::test::BlinkWebTestsFontsTestDataPath(
"noto/cjk/NotoSansCJKjp-Regular-subset-chws.otf"),
11);
return GetGlyphForVariationSequenceFromFont(font, character,
variation_selector);
}
} // namespace
TEST(HarfBuzzFaceTest, HarfBuzzGetNominalGlyph_TestFontWithVS) {
HarfBuzzFace::SetVariationSelectorMode(kUseSpecifiedVariationSelector);
hb_codepoint_t glyph = GetGlyphForCJKVSFromFontWithVS();
EXPECT_TRUE(glyph);
EXPECT_NE(glyph, kUnmatchedVSGlyphId);
}
TEST(HarfBuzzFaceTest, HarfBuzzGetNominalGlyph_TestFontWithVS_IgnoreVS) {
HarfBuzzFace::SetVariationSelectorMode(kIgnoreVariationSelector);
hb_codepoint_t glyph = GetGlyphForCJKVSFromFontWithVS();
EXPECT_TRUE(glyph);
EXPECT_NE(glyph, kUnmatchedVSGlyphId);
}
TEST(HarfBuzzFaceTest, HarfBuzzGetNominalGlyph_TestFontWithBaseCharOnly) {
HarfBuzzFace::SetVariationSelectorMode(kUseSpecifiedVariationSelector);
EXPECT_EQ(GetGlyphForStandardizedVSFromFontWithBaseCharOnly(),
kUnmatchedVSGlyphId);
}
TEST(HarfBuzzFaceTest,
HarfBuzzGetNominalGlyph_TestFontWithBaseCharOnly_IgnoreVS) {
HarfBuzzFace::SetVariationSelectorMode(kIgnoreVariationSelector);
hb_codepoint_t glyph = GetGlyphForStandardizedVSFromFontWithBaseCharOnly();
EXPECT_FALSE(glyph);
}
TEST(HarfBuzzFaceTest, HarfBuzzGetNominalGlyph_TestFontWithoutBaseChar) {
HarfBuzzFace::SetVariationSelectorMode(kUseSpecifiedVariationSelector);
UChar32 character = kFullwidthExclamationMark;
UChar32 variation_selector = kVariationSelector2Character;
Font* font = test::CreateAhemFont(11);
EXPECT_FALSE(GetGlyphForVariationSequenceFromFont(font, character,
variation_selector));
}
TEST(HarfBuzzFaceTest, HarfBuzzGetNominalGlyph_TestVariantEmojiEmoji) {
HarfBuzzFace::SetVariationSelectorMode(kForceVariationSelector16);
UChar32 character = kShakingFaceEmoji;
UChar32 variation_selector = 0;
hb_codepoint_t glyph_from_font_with_vs15 =
GetGlyphForEmojiVSFromFontWithVS15(character, variation_selector);
EXPECT_EQ(glyph_from_font_with_vs15, kUnmatchedVSGlyphId);
hb_codepoint_t glyph_from_font_with_vs16 =
GetGlyphForEmojiVSFromFontWithVS16(character, variation_selector);
EXPECT_TRUE(glyph_from_font_with_vs16);
EXPECT_NE(glyph_from_font_with_vs16, kUnmatchedVSGlyphId);
if (!RuntimeEnabledFeatures::SystemFallbackEmojiVSSupportEnabled()) {
hb_codepoint_t glyph_from_font_without_vs =
GetGlyphForEmojiVSFromFontWithBaseCharOnly(character,
variation_selector);
EXPECT_EQ(glyph_from_font_without_vs, kUnmatchedVSGlyphId);
}
}
TEST(HarfBuzzFaceTest, HarfBuzzGetNominalGlyph_TestVariantEmojiText) {
HarfBuzzFace::SetVariationSelectorMode(kForceVariationSelector15);
UChar32 character = kShakingFaceEmoji;
UChar32 variation_selector = 0;
hb_codepoint_t glyph_from_font_with_vs15 =
GetGlyphForEmojiVSFromFontWithVS15(character, variation_selector);
EXPECT_TRUE(glyph_from_font_with_vs15);
EXPECT_NE(glyph_from_font_with_vs15, kUnmatchedVSGlyphId);
hb_codepoint_t glyph_from_font_with_vs16 =
GetGlyphForEmojiVSFromFontWithVS16(character, variation_selector);
EXPECT_EQ(glyph_from_font_with_vs16, kUnmatchedVSGlyphId);
if (!RuntimeEnabledFeatures::SystemFallbackEmojiVSSupportEnabled()) {
hb_codepoint_t glyph_from_font_without_vs =
GetGlyphForEmojiVSFromFontWithBaseCharOnly(character,
variation_selector);
EXPECT_EQ(glyph_from_font_without_vs, kUnmatchedVSGlyphId);
}
}
TEST(HarfBuzzFaceTest, HarfBuzzGetNominalGlyph_TestVariantEmojiUnicode) {
HarfBuzzFace::SetVariationSelectorMode(kUseUnicodeDefaultPresentation);
UChar32 character = kShakingFaceEmoji;
UChar32 variation_selector = 0;
hb_codepoint_t glyph_from_font_with_vs15 =
GetGlyphForEmojiVSFromFontWithVS15(character, variation_selector);
EXPECT_EQ(glyph_from_font_with_vs15, kUnmatchedVSGlyphId);
hb_codepoint_t glyph_from_font_with_vs16 =
GetGlyphForEmojiVSFromFontWithVS16(character, variation_selector);
EXPECT_TRUE(glyph_from_font_with_vs16);
EXPECT_NE(glyph_from_font_with_vs16, kUnmatchedVSGlyphId);
if (!RuntimeEnabledFeatures::SystemFallbackEmojiVSSupportEnabled()) {
hb_codepoint_t glyph_from_font_without_vs =
GetGlyphForEmojiVSFromFontWithBaseCharOnly(character,
variation_selector);
EXPECT_EQ(glyph_from_font_without_vs, kUnmatchedVSGlyphId);
}
}
TEST(HarfBuzzFaceTest, HarfBuzzGetNominalGlyph_TestVSOverrideVariantEmoji) {
HarfBuzzFace::SetVariationSelectorMode(kForceVariationSelector16);
UChar32 character = kShakingFaceEmoji;
UChar32 variation_selector = kVariationSelector15Character;
hb_codepoint_t glyph_from_font_with_vs15 =
GetGlyphForEmojiVSFromFontWithVS15(character, variation_selector);
EXPECT_TRUE(glyph_from_font_with_vs15);
EXPECT_NE(glyph_from_font_with_vs15, kUnmatchedVSGlyphId);
hb_codepoint_t glyph_from_font_with_vs16 =
GetGlyphForEmojiVSFromFontWithVS16(character, variation_selector);
EXPECT_EQ(glyph_from_font_with_vs16, kUnmatchedVSGlyphId);
if (!RuntimeEnabledFeatures::SystemFallbackEmojiVSSupportEnabled()) {
hb_codepoint_t glyph_from_font_without_vs =
GetGlyphForEmojiVSFromFontWithBaseCharOnly(character,
variation_selector);
EXPECT_EQ(glyph_from_font_without_vs, kUnmatchedVSGlyphId);
}
}
// Test emoji variation selectors support in system fallback. We are only
// enabling this feature on Windows, Android and Mac platforms.
#if BUILDFLAG(IS_MAC) || BUILDFLAG(IS_ANDROID) || BUILDFLAG(IS_WIN)
TEST(HarfBuzzFaceTest, HarfBuzzGetNominalGlyph_TestSystemFallbackEmojiVS) {
ScopedSystemFallbackEmojiVSSupportForTest scoped_system_emoji_vs_feature(
true);
HarfBuzzFace::SetVariationSelectorMode(kUseSpecifiedVariationSelector);
UChar32 character = kShakingFaceEmoji;
hb_codepoint_t glyph_from_font_with_vs15 = GetGlyphForEmojiVSFromFontWithVS15(
character, kVariationSelector15Character);
EXPECT_TRUE(glyph_from_font_with_vs15);
EXPECT_NE(glyph_from_font_with_vs15, kUnmatchedVSGlyphId);
hb_codepoint_t glyph_from_font_with_vs16 = GetGlyphForEmojiVSFromFontWithVS16(
character, kVariationSelector16Character);
EXPECT_TRUE(glyph_from_font_with_vs16);
EXPECT_NE(glyph_from_font_with_vs16, kUnmatchedVSGlyphId);
hb_codepoint_t glyph_from_font_without_vs =
GetGlyphForEmojiVSFromFontWithBaseCharOnly(character, 0);
EXPECT_TRUE(glyph_from_font_without_vs);
EXPECT_NE(glyph_from_font_without_vs, kUnmatchedVSGlyphId);
}
#endif
} // namespace blink
|