Chromium Code Reviews| 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" |
| 11 #include "platform/text/TextRun.h" | 11 #include "platform/text/TextRun.h" |
| 12 #include "wtf/Vector.h" | 12 #include "wtf/Vector.h" |
| 13 #include <gtest/gtest.h> | 13 #include <gtest/gtest.h> |
| 14 #include <unicode/uscript.h> | 14 #include <unicode/uscript.h> |
| 15 | 15 |
| 16 namespace { | 16 namespace blink { |
| 17 | |
| 18 using namespace blink; | |
| 19 using namespace WTF; | |
| 20 | 17 |
| 21 class HarfBuzzShaperTest : public ::testing::Test { | 18 class HarfBuzzShaperTest : public ::testing::Test { |
| 22 protected: | 19 protected: |
| 23 virtual void SetUp() | 20 void SetUp() override |
| 24 { | 21 { |
| 25 fontDescription.setComputedSize(12.0); | 22 fontDescription.setComputedSize(12.0); |
| 26 font = new Font(fontDescription); | 23 font = new Font(fontDescription); |
| 27 font->update(nullptr); | 24 font->update(nullptr); |
| 28 } | 25 } |
| 29 | 26 |
| 30 virtual void TearDown() | 27 void TearDown() override |
| 31 { | 28 { |
| 32 delete font; | 29 delete font; |
| 33 } | 30 } |
| 34 | 31 |
| 35 FontCachePurgePreventer fontCachePurgePreventer; | 32 FontCachePurgePreventer fontCachePurgePreventer; |
| 36 FontDescription fontDescription; | 33 FontDescription fontDescription; |
| 37 Font* font; | 34 Font* font; |
| 38 unsigned startIndex = 0; | 35 unsigned startIndex = 0; |
| 39 unsigned numGlyphs = 0; | 36 unsigned numGlyphs = 0; |
| 40 hb_script_t script = HB_SCRIPT_INVALID; | 37 hb_script_t script = HB_SCRIPT_INVALID; |
| 41 }; | 38 }; |
| 42 | 39 |
| 43 | 40 |
| 44 TEST_F(HarfBuzzShaperTest, ResolveCandidateRunsLatin) | 41 TEST_F(HarfBuzzShaperTest, ResolveCandidateRunsLatin) |
| 45 { | 42 { |
| 46 TextRun latinCommon("ABC DEF.", 8); | 43 TextRun latinCommon("ABC DEF.", 8); |
| 47 HarfBuzzShaper shaper(font, latinCommon); | 44 HarfBuzzShaper shaper(font, latinCommon); |
| 48 shaper.shape(); | 45 shaper.shape(); |
| 49 | 46 |
| 50 ASSERT_EQ(shaper.numberOfRunsForTesting(), 1u); | 47 EXPECT_EQ(1u, shaper.numberOfRunsForTesting()); |
| 51 ASSERT_EQ(shaper.runInfoForTesting(0, startIndex, numGlyphs, script), true); | 48 ASSERT_TRUE(shaper.runInfoForTesting(0, startIndex, numGlyphs, script)); |
|
kochi
2015/06/12 02:22:20
Why not EXPECT_TRUE?
(same for the following inst
tkent
2015/06/12 02:41:06
runInfoForTesting() updates startIndex, numGlyphs,
kochi
2015/06/12 02:42:22
Acknowledged.
| |
| 52 ASSERT_EQ(startIndex, 0u); | 49 EXPECT_EQ(0u, startIndex); |
| 53 ASSERT_EQ(numGlyphs, 8u); | 50 EXPECT_EQ(8u, numGlyphs); |
| 54 ASSERT_EQ(script, HB_SCRIPT_LATIN); | 51 EXPECT_EQ(HB_SCRIPT_LATIN, script); |
| 55 } | 52 } |
| 56 | 53 |
| 57 TEST_F(HarfBuzzShaperTest, ResolveCandidateRunsLeadingCommon) | 54 TEST_F(HarfBuzzShaperTest, ResolveCandidateRunsLeadingCommon) |
| 58 { | 55 { |
| 59 TextRun leadingCommon("... test", 8); | 56 TextRun leadingCommon("... test", 8); |
| 60 HarfBuzzShaper shaper(font, leadingCommon); | 57 HarfBuzzShaper shaper(font, leadingCommon); |
| 61 shaper.shape(); | 58 shaper.shape(); |
| 62 | 59 |
| 63 ASSERT_EQ(shaper.numberOfRunsForTesting(), 1u); | 60 EXPECT_EQ(1u, shaper.numberOfRunsForTesting()); |
| 64 ASSERT_EQ(shaper.runInfoForTesting(0, startIndex, numGlyphs, script), true); | 61 ASSERT_TRUE(shaper.runInfoForTesting(0, startIndex, numGlyphs, script)); |
| 65 ASSERT_EQ(startIndex, 0u); | 62 EXPECT_EQ(0u, startIndex); |
| 66 ASSERT_EQ(numGlyphs, 8u); | 63 EXPECT_EQ(8u, numGlyphs); |
| 67 ASSERT_EQ(script, HB_SCRIPT_LATIN); | 64 EXPECT_EQ(HB_SCRIPT_LATIN, script); |
| 68 } | 65 } |
| 69 | 66 |
| 70 TEST_F(HarfBuzzShaperTest, ResolveCandidateRunsUnicodeVariants) | 67 TEST_F(HarfBuzzShaperTest, ResolveCandidateRunsUnicodeVariants) |
| 71 { | 68 { |
| 72 struct { | 69 struct { |
| 73 const char* name; | 70 const char* name; |
| 74 UChar string[4]; | 71 UChar string[4]; |
| 75 hb_script_t script; | 72 hb_script_t script; |
| 76 } testlist[] = { | 73 } testlist[] = { |
| 77 { "Standard Variants text style", { 0x30, 0xFE0E }, HB_SCRIPT_COMMON }, | 74 { "Standard Variants text style", { 0x30, 0xFE0E }, HB_SCRIPT_COMMON }, |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 94 } | 91 } |
| 95 } | 92 } |
| 96 | 93 |
| 97 TEST_F(HarfBuzzShaperTest, ResolveCandidateRunsDevanagariCommon) | 94 TEST_F(HarfBuzzShaperTest, ResolveCandidateRunsDevanagariCommon) |
| 98 { | 95 { |
| 99 UChar devanagariCommonString[] = { 0x915, 0x94d, 0x930, 0x28, 0x20, 0x29 }; | 96 UChar devanagariCommonString[] = { 0x915, 0x94d, 0x930, 0x28, 0x20, 0x29 }; |
| 100 TextRun devanagariCommonLatin(devanagariCommonString, 6); | 97 TextRun devanagariCommonLatin(devanagariCommonString, 6); |
| 101 HarfBuzzShaper shaper(font, devanagariCommonLatin); | 98 HarfBuzzShaper shaper(font, devanagariCommonLatin); |
| 102 shaper.shape(); | 99 shaper.shape(); |
| 103 | 100 |
| 104 ASSERT_EQ(shaper.numberOfRunsForTesting(), 2u); | 101 EXPECT_EQ(2u, shaper.numberOfRunsForTesting()); |
| 105 ASSERT_EQ(shaper.runInfoForTesting(0, startIndex, numGlyphs, script), true); | 102 ASSERT_TRUE(shaper.runInfoForTesting(0, startIndex, numGlyphs, script)); |
| 106 ASSERT_EQ(startIndex, 0u); | 103 EXPECT_EQ(0u, startIndex); |
| 107 ASSERT_EQ(numGlyphs, 1u); | 104 EXPECT_EQ(1u, numGlyphs); |
| 108 ASSERT_EQ(script, HB_SCRIPT_DEVANAGARI); | 105 EXPECT_EQ(HB_SCRIPT_DEVANAGARI, script); |
| 109 | 106 |
| 110 ASSERT_EQ(shaper.runInfoForTesting(1, startIndex, numGlyphs, script), true); | 107 ASSERT_TRUE(shaper.runInfoForTesting(1, startIndex, numGlyphs, script)); |
| 111 ASSERT_EQ(startIndex, 3u); | 108 EXPECT_EQ(3u, startIndex); |
| 112 ASSERT_EQ(numGlyphs, 3u); | 109 EXPECT_EQ(3u, numGlyphs); |
| 113 ASSERT_EQ(script, HB_SCRIPT_DEVANAGARI); | 110 EXPECT_EQ(HB_SCRIPT_DEVANAGARI, script); |
| 114 } | 111 } |
| 115 | 112 |
| 116 TEST_F(HarfBuzzShaperTest, ResolveCandidateRunsDevanagariCommonLatinCommon) | 113 TEST_F(HarfBuzzShaperTest, ResolveCandidateRunsDevanagariCommonLatinCommon) |
| 117 { | 114 { |
| 118 UChar devanagariCommonLatinString[] = { 0x915, 0x94d, 0x930, 0x20, 0x61, 0x6 2, 0x2E }; | 115 UChar devanagariCommonLatinString[] = { 0x915, 0x94d, 0x930, 0x20, 0x61, 0x6 2, 0x2E }; |
| 119 TextRun devanagariCommonLatin(devanagariCommonLatinString, 7); | 116 TextRun devanagariCommonLatin(devanagariCommonLatinString, 7); |
| 120 HarfBuzzShaper shaper(font, devanagariCommonLatin); | 117 HarfBuzzShaper shaper(font, devanagariCommonLatin); |
| 121 shaper.shape(); | 118 shaper.shape(); |
| 122 | 119 |
| 123 ASSERT_EQ(shaper.numberOfRunsForTesting(), 3u); | 120 EXPECT_EQ(3u, shaper.numberOfRunsForTesting()); |
| 124 ASSERT_EQ(shaper.runInfoForTesting(0, startIndex, numGlyphs, script), true); | 121 ASSERT_TRUE(shaper.runInfoForTesting(0, startIndex, numGlyphs, script)); |
| 125 ASSERT_EQ(startIndex, 0u); | 122 EXPECT_EQ(0u, startIndex); |
| 126 ASSERT_EQ(numGlyphs, 1u); | 123 EXPECT_EQ(1u, numGlyphs); |
| 127 ASSERT_EQ(script, HB_SCRIPT_DEVANAGARI); | 124 EXPECT_EQ(HB_SCRIPT_DEVANAGARI, script); |
| 128 | 125 |
| 129 ASSERT_EQ(shaper.runInfoForTesting(1, startIndex, numGlyphs, script), true); | 126 ASSERT_TRUE(shaper.runInfoForTesting(1, startIndex, numGlyphs, script)); |
| 130 ASSERT_EQ(startIndex, 3u); | 127 EXPECT_EQ(3u, startIndex); |
| 131 ASSERT_EQ(numGlyphs, 1u); | 128 EXPECT_EQ(1u, numGlyphs); |
| 132 ASSERT_EQ(script, HB_SCRIPT_DEVANAGARI); | 129 EXPECT_EQ(HB_SCRIPT_DEVANAGARI, script); |
| 133 | 130 |
| 134 ASSERT_EQ(shaper.runInfoForTesting(2, startIndex, numGlyphs, script), true); | 131 ASSERT_TRUE(shaper.runInfoForTesting(2, startIndex, numGlyphs, script)); |
| 135 ASSERT_EQ(startIndex, 4u); | 132 EXPECT_EQ(4u, startIndex); |
| 136 ASSERT_EQ(numGlyphs, 3u); | 133 EXPECT_EQ(3u, numGlyphs); |
| 137 ASSERT_EQ(script, HB_SCRIPT_LATIN); | 134 EXPECT_EQ(HB_SCRIPT_LATIN, script); |
| 138 } | 135 } |
| 139 | 136 |
| 140 TEST_F(HarfBuzzShaperTest, ResolveCandidateRunsArabicThaiHanLatin) | 137 TEST_F(HarfBuzzShaperTest, ResolveCandidateRunsArabicThaiHanLatin) |
| 141 { | 138 { |
| 142 UChar mixedString[] = { 0x628, 0x64A, 0x629, 0xE20, 0x65E5, 0x62 }; | 139 UChar mixedString[] = { 0x628, 0x64A, 0x629, 0xE20, 0x65E5, 0x62 }; |
| 143 TextRun mixed(mixedString, 6); | 140 TextRun mixed(mixedString, 6); |
| 144 HarfBuzzShaper shaper(font, mixed); | 141 HarfBuzzShaper shaper(font, mixed); |
| 145 shaper.shape(); | 142 shaper.shape(); |
| 146 | 143 |
| 147 ASSERT_EQ(shaper.numberOfRunsForTesting(), 4u); | 144 EXPECT_EQ(4u, shaper.numberOfRunsForTesting()); |
| 148 ASSERT_EQ(shaper.runInfoForTesting(0, startIndex, numGlyphs, script), true); | 145 ASSERT_TRUE(shaper.runInfoForTesting(0, startIndex, numGlyphs, script)); |
| 149 ASSERT_EQ(startIndex, 0u); | 146 EXPECT_EQ(0u, startIndex); |
| 150 ASSERT_EQ(numGlyphs, 3u); | 147 EXPECT_EQ(3u, numGlyphs); |
| 151 ASSERT_EQ(script, HB_SCRIPT_ARABIC); | 148 EXPECT_EQ(HB_SCRIPT_ARABIC, script); |
| 152 | 149 |
| 153 ASSERT_EQ(shaper.runInfoForTesting(1, startIndex, numGlyphs, script), true); | 150 ASSERT_TRUE(shaper.runInfoForTesting(1, startIndex, numGlyphs, script)); |
| 154 ASSERT_EQ(startIndex, 3u); | 151 EXPECT_EQ(3u, startIndex); |
| 155 ASSERT_EQ(numGlyphs, 1u); | 152 EXPECT_EQ(1u, numGlyphs); |
| 156 ASSERT_EQ(script, HB_SCRIPT_THAI); | 153 EXPECT_EQ(HB_SCRIPT_THAI, script); |
| 157 | 154 |
| 158 ASSERT_EQ(shaper.runInfoForTesting(2, startIndex, numGlyphs, script), true); | 155 ASSERT_TRUE(shaper.runInfoForTesting(2, startIndex, numGlyphs, script)); |
| 159 ASSERT_EQ(startIndex, 4u); | 156 EXPECT_EQ(4u, startIndex); |
| 160 ASSERT_EQ(numGlyphs, 1u); | 157 EXPECT_EQ(1u, numGlyphs); |
| 161 ASSERT_EQ(script, HB_SCRIPT_HAN); | 158 EXPECT_EQ(HB_SCRIPT_HAN, script); |
| 162 | 159 |
| 163 ASSERT_EQ(shaper.runInfoForTesting(3, startIndex, numGlyphs, script), true); | 160 ASSERT_TRUE(shaper.runInfoForTesting(3, startIndex, numGlyphs, script)); |
| 164 ASSERT_EQ(startIndex, 5u); | 161 EXPECT_EQ(5u, startIndex); |
| 165 ASSERT_EQ(numGlyphs, 1u); | 162 EXPECT_EQ(1u, numGlyphs); |
| 166 ASSERT_EQ(script, HB_SCRIPT_LATIN); | 163 EXPECT_EQ(HB_SCRIPT_LATIN, script); |
| 167 } | 164 } |
| 168 | 165 |
| 169 TEST_F(HarfBuzzShaperTest, ResolveCandidateRunsArabic) | 166 TEST_F(HarfBuzzShaperTest, ResolveCandidateRunsArabic) |
| 170 { | 167 { |
| 171 UChar arabicString[] = { 0x628, 0x64A, 0x629 }; | 168 UChar arabicString[] = { 0x628, 0x64A, 0x629 }; |
| 172 TextRun arabic(arabicString, 3); | 169 TextRun arabic(arabicString, 3); |
| 173 HarfBuzzShaper shaper(font, arabic); | 170 HarfBuzzShaper shaper(font, arabic); |
| 174 shaper.shape(); | 171 shaper.shape(); |
| 175 | 172 |
| 176 ASSERT_EQ(shaper.numberOfRunsForTesting(), 1u); | 173 EXPECT_EQ(1u, shaper.numberOfRunsForTesting()); |
| 177 ASSERT_EQ(shaper.runInfoForTesting(0, startIndex, numGlyphs, script), true); | 174 ASSERT_TRUE(shaper.runInfoForTesting(0, startIndex, numGlyphs, script)); |
| 178 ASSERT_EQ(startIndex, 0u); | 175 EXPECT_EQ(0u, startIndex); |
| 179 ASSERT_EQ(numGlyphs, 3u); | 176 EXPECT_EQ(3u, numGlyphs); |
| 180 ASSERT_EQ(script, HB_SCRIPT_ARABIC); | 177 EXPECT_EQ(HB_SCRIPT_ARABIC, script); |
| 181 } | 178 } |
| 182 | 179 |
| 183 } | 180 } // namespace blink |
| OLD | NEW |