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