| 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 "platform/fonts/shaping/CachingWordShaper.h" | 5 #include "platform/fonts/shaping/CachingWordShaper.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 #include "platform/fonts/CharacterRange.h" | |
| 9 #include "platform/fonts/FontCache.h" | 8 #include "platform/fonts/FontCache.h" |
| 10 #include "platform/fonts/shaping/CachingWordShapeIterator.h" | 9 #include "platform/fonts/shaping/CachingWordShapeIterator.h" |
| 11 #include "platform/fonts/shaping/ShapeResultTestInfo.h" | 10 #include "platform/fonts/shaping/ShapeResultTestInfo.h" |
| 12 #include "platform/wtf/PtrUtil.h" | 11 #include "platform/wtf/PtrUtil.h" |
| 13 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
| 14 | 13 |
| 15 namespace blink { | 14 namespace blink { |
| 16 | 15 |
| 17 class CachingWordShaperTest : public ::testing::Test { | 16 class CachingWordShaperTest : public ::testing::Test { |
| 18 protected: | 17 protected: |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 101 TestInfo(result)->RunInfoForTesting(0, start_index, num_glyphs, script)); | 100 TestInfo(result)->RunInfoForTesting(0, start_index, num_glyphs, script)); |
| 102 EXPECT_EQ(4u, offset + start_index); | 101 EXPECT_EQ(4u, offset + start_index); |
| 103 EXPECT_EQ(1u, num_glyphs); | 102 EXPECT_EQ(1u, num_glyphs); |
| 104 EXPECT_EQ(HB_SCRIPT_COMMON, script); | 103 EXPECT_EQ(HB_SCRIPT_COMMON, script); |
| 105 offset += result->NumCharacters(); | 104 offset += result->NumCharacters(); |
| 106 | 105 |
| 107 ASSERT_EQ(5u, offset); | 106 ASSERT_EQ(5u, offset); |
| 108 ASSERT_FALSE(iterator.Next(&result)); | 107 ASSERT_FALSE(iterator.Next(&result)); |
| 109 } | 108 } |
| 110 | 109 |
| 111 // Tests that filling a glyph buffer for a specific range returns the same | |
| 112 // results when shaping word by word as when shaping the full run in one go. | |
| 113 TEST_F(CachingWordShaperTest, CommonAccentLeftToRightFillGlyphBuffer) { | |
| 114 // "/. ." with an accent mark over the first dot. | |
| 115 const UChar kStr[] = {0x2F, 0x301, 0x2E, 0x20, 0x2E, 0x0}; | |
| 116 TextRun text_run(kStr, 5); | |
| 117 TextRunPaintInfo run_info(text_run); | |
| 118 run_info.to = 3; | |
| 119 | |
| 120 ShapeResultBloberizer bloberizer(font, 1); | |
| 121 CachingWordShaper(font).FillGlyphs(run_info, bloberizer); | |
| 122 | |
| 123 Font reference_font(font_description); | |
| 124 reference_font.Update(nullptr); | |
| 125 reference_font.SetCanShapeWordByWordForTesting(false); | |
| 126 ShapeResultBloberizer reference_bloberizer(reference_font, 1); | |
| 127 CachingWordShaper(reference_font).FillGlyphs(run_info, reference_bloberizer); | |
| 128 | |
| 129 const auto& glyphs = | |
| 130 ShapeResultBloberizerTestInfo::PendingRunGlyphs(bloberizer); | |
| 131 ASSERT_EQ(glyphs.size(), 3ul); | |
| 132 const auto reference_glyphs = | |
| 133 ShapeResultBloberizerTestInfo::PendingRunGlyphs(reference_bloberizer); | |
| 134 ASSERT_EQ(reference_glyphs.size(), 3ul); | |
| 135 | |
| 136 EXPECT_EQ(reference_glyphs[0], glyphs[0]); | |
| 137 EXPECT_EQ(reference_glyphs[1], glyphs[1]); | |
| 138 EXPECT_EQ(reference_glyphs[2], glyphs[2]); | |
| 139 } | |
| 140 | |
| 141 // Tests that filling a glyph buffer for a specific range returns the same | |
| 142 // results when shaping word by word as when shaping the full run in one go. | |
| 143 TEST_F(CachingWordShaperTest, CommonAccentRightToLeftFillGlyphBuffer) { | |
| 144 // "[] []" with an accent mark over the last square bracket. | |
| 145 const UChar kStr[] = {0x5B, 0x5D, 0x20, 0x5B, 0x301, 0x5D, 0x0}; | |
| 146 TextRun text_run(kStr, 6); | |
| 147 text_run.SetDirection(TextDirection::kRtl); | |
| 148 TextRunPaintInfo run_info(text_run); | |
| 149 run_info.from = 1; | |
| 150 | |
| 151 ShapeResultBloberizer bloberizer(font, 1); | |
| 152 CachingWordShaper(font).FillGlyphs(run_info, bloberizer); | |
| 153 | |
| 154 Font reference_font(font_description); | |
| 155 reference_font.Update(nullptr); | |
| 156 reference_font.SetCanShapeWordByWordForTesting(false); | |
| 157 ShapeResultBloberizer reference_bloberizer(reference_font, 1); | |
| 158 CachingWordShaper(reference_font).FillGlyphs(run_info, reference_bloberizer); | |
| 159 | |
| 160 const auto& glyphs = | |
| 161 ShapeResultBloberizerTestInfo::PendingRunGlyphs(bloberizer); | |
| 162 ASSERT_EQ(5u, glyphs.size()); | |
| 163 const auto reference_glyphs = | |
| 164 ShapeResultBloberizerTestInfo::PendingRunGlyphs(reference_bloberizer); | |
| 165 ASSERT_EQ(5u, reference_glyphs.size()); | |
| 166 | |
| 167 EXPECT_EQ(reference_glyphs[0], glyphs[0]); | |
| 168 EXPECT_EQ(reference_glyphs[1], glyphs[1]); | |
| 169 EXPECT_EQ(reference_glyphs[2], glyphs[2]); | |
| 170 EXPECT_EQ(reference_glyphs[3], glyphs[3]); | |
| 171 EXPECT_EQ(reference_glyphs[4], glyphs[4]); | |
| 172 } | |
| 173 | |
| 174 // Tests that runs with zero glyphs (the ZWJ non-printable character in this | |
| 175 // case) are handled correctly. This test passes if it does not cause a crash. | |
| 176 TEST_F(CachingWordShaperTest, SubRunWithZeroGlyphs) { | |
| 177 // "Foo ‌ bar" | |
| 178 const UChar kStr[] = {0x46, 0x6F, 0x6F, 0x20, 0x200C, | |
| 179 0x20, 0x62, 0x61, 0x71, 0x0}; | |
| 180 TextRun text_run(kStr, 9); | |
| 181 | |
| 182 CachingWordShaper shaper(font); | |
| 183 FloatRect glyph_bounds; | |
| 184 ASSERT_GT(shaper.Width(text_run, nullptr, &glyph_bounds), 0); | |
| 185 | |
| 186 ShapeResultBloberizer bloberizer(font, 1); | |
| 187 TextRunPaintInfo run_info(text_run); | |
| 188 run_info.to = 8; | |
| 189 shaper.FillGlyphs(run_info, bloberizer); | |
| 190 | |
| 191 shaper.GetCharacterRange(text_run, 0, 8); | |
| 192 } | |
| 193 | |
| 194 TEST_F(CachingWordShaperTest, SegmentCJKByCharacter) { | 110 TEST_F(CachingWordShaperTest, SegmentCJKByCharacter) { |
| 195 const UChar kStr[] = {0x56FD, 0x56FD, // CJK Unified Ideograph | 111 const UChar kStr[] = {0x56FD, 0x56FD, // CJK Unified Ideograph |
| 196 'a', 'b', | 112 'a', 'b', |
| 197 0x56FD, // CJK Unified Ideograph | 113 0x56FD, // CJK Unified Ideograph |
| 198 'x', 'y', 'z', | 114 'x', 'y', 'z', |
| 199 0x3042, // HIRAGANA LETTER A | 115 0x3042, // HIRAGANA LETTER A |
| 200 0x56FD, // CJK Unified Ideograph | 116 0x56FD, // CJK Unified Ideograph |
| 201 0x0}; | 117 0x0}; |
| 202 TextRun text_run(kStr, 10); | 118 TextRun text_run(kStr, 10); |
| 203 | 119 |
| (...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 479 // periods alone. | 395 // periods alone. |
| 480 ASSERT_GT(periods_and_spaces_width, periods_width); | 396 ASSERT_GT(periods_and_spaces_width, periods_width); |
| 481 | 397 |
| 482 // The glyph bounds of periods and spaces should be longer than the glyph | 398 // The glyph bounds of periods and spaces should be longer than the glyph |
| 483 // bounds of periods alone. | 399 // bounds of periods alone. |
| 484 ASSERT_GT(periods_and_spaces_glyph_bounds.Width(), | 400 ASSERT_GT(periods_and_spaces_glyph_bounds.Width(), |
| 485 periods_glyph_bounds.Width()); | 401 periods_glyph_bounds.Width()); |
| 486 } | 402 } |
| 487 | 403 |
| 488 } // namespace blink | 404 } // namespace blink |
| OLD | NEW |