| OLD | NEW |
| 1 // Copyright (c) 2014 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "config.h" | 5 #include "config.h" |
| 6 #include "platform/fonts/shaping/HarfBuzzShaper.h" | 6 #include "platform/fonts/shaping/HarfBuzzShaper.h" |
| 7 | 7 |
| 8 #include "platform/fonts/Font.h" | 8 #include "platform/fonts/Font.h" |
| 9 #include "platform/fonts/FontCache.h" | 9 #include "platform/fonts/FontCache.h" |
| 10 #include "platform/fonts/GlyphPage.h" | 10 #include "platform/fonts/GlyphPage.h" |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 fontDescription.setComputedSize(12.0); | 22 fontDescription.setComputedSize(12.0); |
| 23 font = new Font(fontDescription); | 23 font = new Font(fontDescription); |
| 24 font->update(nullptr); | 24 font->update(nullptr); |
| 25 } | 25 } |
| 26 | 26 |
| 27 void TearDown() override | 27 void TearDown() override |
| 28 { | 28 { |
| 29 delete font; | 29 delete font; |
| 30 } | 30 } |
| 31 | 31 |
| 32 HashSet<const SimpleFontData*> fallbackFonts; |
| 32 FontCachePurgePreventer fontCachePurgePreventer; | 33 FontCachePurgePreventer fontCachePurgePreventer; |
| 33 FontDescription fontDescription; | 34 FontDescription fontDescription; |
| 34 Font* font; | 35 Font* font; |
| 35 unsigned startIndex = 0; | 36 unsigned startIndex = 0; |
| 36 unsigned numGlyphs = 0; | 37 unsigned numGlyphs = 0; |
| 37 hb_script_t script = HB_SCRIPT_INVALID; | 38 hb_script_t script = HB_SCRIPT_INVALID; |
| 38 }; | 39 }; |
| 39 | 40 |
| 40 | 41 |
| 41 TEST_F(HarfBuzzShaperTest, ResolveCandidateRunsLatin) | 42 TEST_F(HarfBuzzShaperTest, ResolveCandidateRunsLatin) |
| 42 { | 43 { |
| 43 TextRun latinCommon("ABC DEF.", 8); | 44 TextRun latinCommon("ABC DEF.", 8); |
| 44 HarfBuzzShaper shaper(font, latinCommon); | 45 HarfBuzzShaper shaper(font, latinCommon, &fallbackFonts); |
| 45 RefPtr<ShapeResult> result = shaper.shapeResult(); | 46 RefPtr<ShapeResult> result = shaper.shapeResult(); |
| 46 | 47 |
| 47 ASSERT_EQ(1u, result->numberOfRunsForTesting()); | 48 ASSERT_EQ(1u, result->numberOfRunsForTesting()); |
| 48 ASSERT_TRUE(result->runInfoForTesting(0, startIndex, numGlyphs, script)); | 49 ASSERT_TRUE(result->runInfoForTesting(0, startIndex, numGlyphs, script)); |
| 49 EXPECT_EQ(0u, startIndex); | 50 EXPECT_EQ(0u, startIndex); |
| 50 EXPECT_EQ(8u, numGlyphs); | 51 EXPECT_EQ(8u, numGlyphs); |
| 51 EXPECT_EQ(HB_SCRIPT_LATIN, script); | 52 EXPECT_EQ(HB_SCRIPT_LATIN, script); |
| 52 } | 53 } |
| 53 | 54 |
| 54 TEST_F(HarfBuzzShaperTest, ResolveCandidateRunsLeadingCommon) | 55 TEST_F(HarfBuzzShaperTest, ResolveCandidateRunsLeadingCommon) |
| 55 { | 56 { |
| 56 TextRun leadingCommon("... test", 8); | 57 TextRun leadingCommon("... test", 8); |
| 57 HarfBuzzShaper shaper(font, leadingCommon); | 58 HarfBuzzShaper shaper(font, leadingCommon, &fallbackFonts); |
| 58 RefPtr<ShapeResult> result = shaper.shapeResult(); | 59 RefPtr<ShapeResult> result = shaper.shapeResult(); |
| 59 | 60 |
| 60 ASSERT_EQ(1u, result->numberOfRunsForTesting()); | 61 ASSERT_EQ(1u, result->numberOfRunsForTesting()); |
| 61 ASSERT_TRUE(result->runInfoForTesting(0, startIndex, numGlyphs, script)); | 62 ASSERT_TRUE(result->runInfoForTesting(0, startIndex, numGlyphs, script)); |
| 62 EXPECT_EQ(0u, startIndex); | 63 EXPECT_EQ(0u, startIndex); |
| 63 EXPECT_EQ(8u, numGlyphs); | 64 EXPECT_EQ(8u, numGlyphs); |
| 64 EXPECT_EQ(HB_SCRIPT_LATIN, script); | 65 EXPECT_EQ(HB_SCRIPT_LATIN, script); |
| 65 } | 66 } |
| 66 | 67 |
| 67 TEST_F(HarfBuzzShaperTest, ResolveCandidateRunsUnicodeVariants) | 68 TEST_F(HarfBuzzShaperTest, ResolveCandidateRunsUnicodeVariants) |
| 68 { | 69 { |
| 69 struct { | 70 struct { |
| 70 const char* name; | 71 const char* name; |
| 71 UChar string[4]; | 72 UChar string[4]; |
| 72 hb_script_t script; | 73 hb_script_t script; |
| 73 } testlist[] = { | 74 } testlist[] = { |
| 74 { "Standard Variants text style", { 0x30, 0xFE0E }, HB_SCRIPT_COMMON }, | 75 { "Standard Variants text style", { 0x30, 0xFE0E }, HB_SCRIPT_COMMON }, |
| 75 { "Standard Variants emoji style", { 0x203C, 0xFE0F }, HB_SCRIPT_COMMON
}, | 76 { "Standard Variants emoji style", { 0x203C, 0xFE0F }, HB_SCRIPT_COMMON
}, |
| 76 { "Standard Variants of Ideograph", { 0x4FAE, 0xFE00 }, HB_SCRIPT_HAN }, | 77 { "Standard Variants of Ideograph", { 0x4FAE, 0xFE00 }, HB_SCRIPT_HAN }, |
| 77 { "Ideographic Variants", { 0x3402, 0xDB40, 0xDD00 }, HB_SCRIPT_HAN }, | 78 { "Ideographic Variants", { 0x3402, 0xDB40, 0xDD00 }, HB_SCRIPT_HAN }, |
| 78 { "Not-defined Variants", { 0x41, 0xDB40, 0xDDEF }, HB_SCRIPT_LATIN }, | 79 { "Not-defined Variants", { 0x41, 0xDB40, 0xDDEF }, HB_SCRIPT_LATIN }, |
| 79 }; | 80 }; |
| 80 for (auto& test : testlist) { | 81 for (auto& test : testlist) { |
| 81 String str(test.string); | 82 String str(test.string); |
| 82 TextRun run(str); | 83 TextRun run(str); |
| 83 HarfBuzzShaper shaper(font, run); | 84 HarfBuzzShaper shaper(font, run, &fallbackFonts); |
| 84 RefPtr<ShapeResult> result = shaper.shapeResult(); | 85 RefPtr<ShapeResult> result = shaper.shapeResult(); |
| 85 | 86 |
| 86 EXPECT_EQ(1u, result->numberOfRunsForTesting()) << test.name; | 87 EXPECT_EQ(1u, result->numberOfRunsForTesting()) << test.name; |
| 87 ASSERT_TRUE(result->runInfoForTesting(0, startIndex, numGlyphs, script))
<< test.name; | 88 ASSERT_TRUE(result->runInfoForTesting(0, startIndex, numGlyphs, script))
<< test.name; |
| 88 EXPECT_EQ(0u, startIndex) << test.name; | 89 EXPECT_EQ(0u, startIndex) << test.name; |
| 89 if (numGlyphs == 2) { | 90 if (numGlyphs == 2) { |
| 90 // If the specified VS is not in the font, it's mapped to .notdef. | 91 // If the specified VS is not in the font, it's mapped to .notdef. |
| 91 // then hb_ot_hide_default_ignorables() swaps it to a space with zer
o-advance. | 92 // then hb_ot_hide_default_ignorables() swaps it to a space with zer
o-advance. |
| 92 // http://lists.freedesktop.org/archives/harfbuzz/2015-May/004888.ht
ml | 93 // http://lists.freedesktop.org/archives/harfbuzz/2015-May/004888.ht
ml |
| 93 // OpenType recommends Glyph ID 3 for a space; not a hard requiremen
t though. | 94 // OpenType recommends Glyph ID 3 for a space; not a hard requiremen
t though. |
| 94 // https://www.microsoft.com/typography/otspec/recom.htm | 95 // https://www.microsoft.com/typography/otspec/recom.htm |
| 95 #if !OS(MACOSX) | 96 #if !OS(MACOSX) |
| 96 EXPECT_EQ(3u, result->glyphForTesting(0, 1)) << test.name; | 97 EXPECT_EQ(3u, result->glyphForTesting(0, 1)) << test.name; |
| 97 #endif | 98 #endif |
| 98 EXPECT_EQ(0.f, result->advanceForTesting(0, 1)) << test.name; | 99 EXPECT_EQ(0.f, result->advanceForTesting(0, 1)) << test.name; |
| 99 } else { | 100 } else { |
| 100 EXPECT_EQ(1u, numGlyphs) << test.name; | 101 EXPECT_EQ(1u, numGlyphs) << test.name; |
| 101 } | 102 } |
| 102 EXPECT_EQ(test.script, script) << test.name; | 103 EXPECT_EQ(test.script, script) << test.name; |
| 103 } | 104 } |
| 104 } | 105 } |
| 105 | 106 |
| 106 TEST_F(HarfBuzzShaperTest, ResolveCandidateRunsDevanagariCommon) | 107 TEST_F(HarfBuzzShaperTest, ResolveCandidateRunsDevanagariCommon) |
| 107 { | 108 { |
| 108 UChar devanagariCommonString[] = { 0x915, 0x94d, 0x930, 0x28, 0x20, 0x29 }; | 109 UChar devanagariCommonString[] = { 0x915, 0x94d, 0x930, 0x28, 0x20, 0x29 }; |
| 109 TextRun devanagariCommonLatin(devanagariCommonString, 6); | 110 TextRun devanagariCommonLatin(devanagariCommonString, 6); |
| 110 HarfBuzzShaper shaper(font, devanagariCommonLatin); | 111 HarfBuzzShaper shaper(font, devanagariCommonLatin, &fallbackFonts); |
| 111 RefPtr<ShapeResult> result = shaper.shapeResult(); | 112 RefPtr<ShapeResult> result = shaper.shapeResult(); |
| 112 | 113 |
| 113 ASSERT_EQ(2u, result->numberOfRunsForTesting()); | 114 ASSERT_EQ(2u, result->numberOfRunsForTesting()); |
| 114 ASSERT_TRUE(result->runInfoForTesting(0, startIndex, numGlyphs, script)); | 115 ASSERT_TRUE(result->runInfoForTesting(0, startIndex, numGlyphs, script)); |
| 115 EXPECT_EQ(0u, startIndex); | 116 EXPECT_EQ(0u, startIndex); |
| 116 EXPECT_EQ(1u, numGlyphs); | 117 EXPECT_EQ(1u, numGlyphs); |
| 117 EXPECT_EQ(HB_SCRIPT_DEVANAGARI, script); | 118 EXPECT_EQ(HB_SCRIPT_DEVANAGARI, script); |
| 118 | 119 |
| 119 ASSERT_TRUE(result->runInfoForTesting(1, startIndex, numGlyphs, script)); | 120 ASSERT_TRUE(result->runInfoForTesting(1, startIndex, numGlyphs, script)); |
| 120 EXPECT_EQ(3u, startIndex); | 121 EXPECT_EQ(3u, startIndex); |
| 121 EXPECT_EQ(3u, numGlyphs); | 122 EXPECT_EQ(3u, numGlyphs); |
| 122 EXPECT_EQ(HB_SCRIPT_DEVANAGARI, script); | 123 EXPECT_EQ(HB_SCRIPT_DEVANAGARI, script); |
| 123 } | 124 } |
| 124 | 125 |
| 125 TEST_F(HarfBuzzShaperTest, ResolveCandidateRunsDevanagariCommonLatinCommon) | 126 TEST_F(HarfBuzzShaperTest, ResolveCandidateRunsDevanagariCommonLatinCommon) |
| 126 { | 127 { |
| 127 UChar devanagariCommonLatinString[] = { 0x915, 0x94d, 0x930, 0x20, 0x61, 0x6
2, 0x2E }; | 128 UChar devanagariCommonLatinString[] = { 0x915, 0x94d, 0x930, 0x20, 0x61, 0x6
2, 0x2E }; |
| 128 TextRun devanagariCommonLatin(devanagariCommonLatinString, 7); | 129 TextRun devanagariCommonLatin(devanagariCommonLatinString, 7); |
| 129 HarfBuzzShaper shaper(font, devanagariCommonLatin); | 130 HarfBuzzShaper shaper(font, devanagariCommonLatin, &fallbackFonts); |
| 130 RefPtr<ShapeResult> result = shaper.shapeResult(); | 131 RefPtr<ShapeResult> result = shaper.shapeResult(); |
| 131 | 132 |
| 132 ASSERT_EQ(3u, result->numberOfRunsForTesting()); | 133 ASSERT_EQ(3u, result->numberOfRunsForTesting()); |
| 133 ASSERT_TRUE(result->runInfoForTesting(0, startIndex, numGlyphs, script)); | 134 ASSERT_TRUE(result->runInfoForTesting(0, startIndex, numGlyphs, script)); |
| 134 EXPECT_EQ(0u, startIndex); | 135 EXPECT_EQ(0u, startIndex); |
| 135 EXPECT_EQ(1u, numGlyphs); | 136 EXPECT_EQ(1u, numGlyphs); |
| 136 EXPECT_EQ(HB_SCRIPT_DEVANAGARI, script); | 137 EXPECT_EQ(HB_SCRIPT_DEVANAGARI, script); |
| 137 | 138 |
| 138 ASSERT_TRUE(result->runInfoForTesting(1, startIndex, numGlyphs, script)); | 139 ASSERT_TRUE(result->runInfoForTesting(1, startIndex, numGlyphs, script)); |
| 139 EXPECT_EQ(3u, startIndex); | 140 EXPECT_EQ(3u, startIndex); |
| 140 EXPECT_EQ(1u, numGlyphs); | 141 EXPECT_EQ(1u, numGlyphs); |
| 141 EXPECT_EQ(HB_SCRIPT_DEVANAGARI, script); | 142 EXPECT_EQ(HB_SCRIPT_DEVANAGARI, script); |
| 142 | 143 |
| 143 ASSERT_TRUE(result->runInfoForTesting(2, startIndex, numGlyphs, script)); | 144 ASSERT_TRUE(result->runInfoForTesting(2, startIndex, numGlyphs, script)); |
| 144 EXPECT_EQ(4u, startIndex); | 145 EXPECT_EQ(4u, startIndex); |
| 145 EXPECT_EQ(3u, numGlyphs); | 146 EXPECT_EQ(3u, numGlyphs); |
| 146 EXPECT_EQ(HB_SCRIPT_LATIN, script); | 147 EXPECT_EQ(HB_SCRIPT_LATIN, script); |
| 147 } | 148 } |
| 148 | 149 |
| 149 TEST_F(HarfBuzzShaperTest, ResolveCandidateRunsArabicThaiHanLatin) | 150 TEST_F(HarfBuzzShaperTest, ResolveCandidateRunsArabicThaiHanLatin) |
| 150 { | 151 { |
| 151 UChar mixedString[] = { 0x628, 0x64A, 0x629, 0xE20, 0x65E5, 0x62 }; | 152 UChar mixedString[] = { 0x628, 0x64A, 0x629, 0xE20, 0x65E5, 0x62 }; |
| 152 TextRun mixed(mixedString, 6); | 153 TextRun mixed(mixedString, 6); |
| 153 HarfBuzzShaper shaper(font, mixed); | 154 HarfBuzzShaper shaper(font, mixed, &fallbackFonts); |
| 154 RefPtr<ShapeResult> result = shaper.shapeResult(); | 155 RefPtr<ShapeResult> result = shaper.shapeResult(); |
| 155 | 156 |
| 156 ASSERT_EQ(4u, result->numberOfRunsForTesting()); | 157 ASSERT_EQ(4u, result->numberOfRunsForTesting()); |
| 157 ASSERT_TRUE(result->runInfoForTesting(0, startIndex, numGlyphs, script)); | 158 ASSERT_TRUE(result->runInfoForTesting(0, startIndex, numGlyphs, script)); |
| 158 EXPECT_EQ(0u, startIndex); | 159 EXPECT_EQ(0u, startIndex); |
| 159 EXPECT_EQ(3u, numGlyphs); | 160 EXPECT_EQ(3u, numGlyphs); |
| 160 EXPECT_EQ(HB_SCRIPT_ARABIC, script); | 161 EXPECT_EQ(HB_SCRIPT_ARABIC, script); |
| 161 | 162 |
| 162 ASSERT_TRUE(result->runInfoForTesting(1, startIndex, numGlyphs, script)); | 163 ASSERT_TRUE(result->runInfoForTesting(1, startIndex, numGlyphs, script)); |
| 163 EXPECT_EQ(3u, startIndex); | 164 EXPECT_EQ(3u, startIndex); |
| 164 EXPECT_EQ(1u, numGlyphs); | 165 EXPECT_EQ(1u, numGlyphs); |
| 165 EXPECT_EQ(HB_SCRIPT_THAI, script); | 166 EXPECT_EQ(HB_SCRIPT_THAI, script); |
| 166 | 167 |
| 167 ASSERT_TRUE(result->runInfoForTesting(2, startIndex, numGlyphs, script)); | 168 ASSERT_TRUE(result->runInfoForTesting(2, startIndex, numGlyphs, script)); |
| 168 EXPECT_EQ(4u, startIndex); | 169 EXPECT_EQ(4u, startIndex); |
| 169 EXPECT_EQ(1u, numGlyphs); | 170 EXPECT_EQ(1u, numGlyphs); |
| 170 EXPECT_EQ(HB_SCRIPT_HAN, script); | 171 EXPECT_EQ(HB_SCRIPT_HAN, script); |
| 171 | 172 |
| 172 ASSERT_TRUE(result->runInfoForTesting(3, startIndex, numGlyphs, script)); | 173 ASSERT_TRUE(result->runInfoForTesting(3, startIndex, numGlyphs, script)); |
| 173 EXPECT_EQ(5u, startIndex); | 174 EXPECT_EQ(5u, startIndex); |
| 174 EXPECT_EQ(1u, numGlyphs); | 175 EXPECT_EQ(1u, numGlyphs); |
| 175 EXPECT_EQ(HB_SCRIPT_LATIN, script); | 176 EXPECT_EQ(HB_SCRIPT_LATIN, script); |
| 176 } | 177 } |
| 177 | 178 |
| 178 TEST_F(HarfBuzzShaperTest, ResolveCandidateRunsArabic) | 179 TEST_F(HarfBuzzShaperTest, ResolveCandidateRunsArabic) |
| 179 { | 180 { |
| 180 UChar arabicString[] = { 0x628, 0x64A, 0x629 }; | 181 UChar arabicString[] = { 0x628, 0x64A, 0x629 }; |
| 181 TextRun arabic(arabicString, 3); | 182 TextRun arabic(arabicString, 3); |
| 182 HarfBuzzShaper shaper(font, arabic); | 183 HarfBuzzShaper shaper(font, arabic, &fallbackFonts); |
| 183 RefPtr<ShapeResult> result = shaper.shapeResult(); | 184 RefPtr<ShapeResult> result = shaper.shapeResult(); |
| 184 | 185 |
| 185 ASSERT_EQ(1u, result->numberOfRunsForTesting()); | 186 ASSERT_EQ(1u, result->numberOfRunsForTesting()); |
| 186 ASSERT_TRUE(result->runInfoForTesting(0, startIndex, numGlyphs, script)); | 187 ASSERT_TRUE(result->runInfoForTesting(0, startIndex, numGlyphs, script)); |
| 187 EXPECT_EQ(0u, startIndex); | 188 EXPECT_EQ(0u, startIndex); |
| 188 EXPECT_EQ(3u, numGlyphs); | 189 EXPECT_EQ(3u, numGlyphs); |
| 189 EXPECT_EQ(HB_SCRIPT_ARABIC, script); | 190 EXPECT_EQ(HB_SCRIPT_ARABIC, script); |
| 190 } | 191 } |
| 191 | 192 |
| 192 } // namespace blink | 193 } // namespace blink |
| OLD | NEW |