OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "config.h" |
| 6 |
| 7 #include "platform/fonts/FontCache.h" |
| 8 #include "platform/fonts/GlyphBuffer.h" |
| 9 #include "platform/fonts/shaping/CachingWordShapeIterator.h" |
| 10 #include <gtest/gtest.h> |
| 11 |
| 12 namespace blink { |
| 13 |
| 14 class CachingWordShaperTest : public ::testing::Test { |
| 15 protected: |
| 16 void SetUp() override |
| 17 { |
| 18 fontDescription.setComputedSize(12.0); |
| 19 fontDescription.setScript(USCRIPT_LATIN); |
| 20 fontDescription.setGenericFamily(FontDescription::StandardFamily); |
| 21 |
| 22 font = new Font(fontDescription); |
| 23 font->update(nullptr); |
| 24 ASSERT_TRUE(font->canShapeWordByWord()); |
| 25 fallbackFonts = nullptr; |
| 26 cache = new ShapeCache(); |
| 27 } |
| 28 |
| 29 void TearDown() override |
| 30 { |
| 31 delete cache; |
| 32 delete font; |
| 33 } |
| 34 |
| 35 FontCachePurgePreventer fontCachePurgePreventer; |
| 36 FontDescription fontDescription; |
| 37 Font* font; |
| 38 ShapeCache* cache; |
| 39 HashSet<const SimpleFontData*>* fallbackFonts; |
| 40 unsigned startIndex = 0; |
| 41 unsigned numGlyphs = 0; |
| 42 hb_script_t script = HB_SCRIPT_INVALID; |
| 43 }; |
| 44 |
| 45 TEST_F(CachingWordShaperTest, LatinLeftToRightByWord) |
| 46 { |
| 47 TextRun textRun(reinterpret_cast<const LChar*>("ABC DEF."), 8); |
| 48 |
| 49 RefPtr<ShapeResult> result; |
| 50 CachingWordShapeIterator iterator(cache, textRun, font, fallbackFonts); |
| 51 ASSERT_TRUE(iterator.next(&result)); |
| 52 ASSERT_TRUE(result->runInfoForTesting(0, startIndex, numGlyphs, script)); |
| 53 EXPECT_EQ(0u, startIndex); |
| 54 EXPECT_EQ(3u, numGlyphs); |
| 55 EXPECT_EQ(HB_SCRIPT_LATIN, script); |
| 56 |
| 57 ASSERT_TRUE(iterator.next(&result)); |
| 58 ASSERT_TRUE(result->runInfoForTesting(0, startIndex, numGlyphs, script)); |
| 59 EXPECT_EQ(0u, startIndex); |
| 60 EXPECT_EQ(1u, numGlyphs); |
| 61 EXPECT_EQ(HB_SCRIPT_COMMON, script); |
| 62 |
| 63 ASSERT_TRUE(iterator.next(&result)); |
| 64 ASSERT_TRUE(result->runInfoForTesting(0, startIndex, numGlyphs, script)); |
| 65 EXPECT_EQ(0u, startIndex); |
| 66 EXPECT_EQ(4u, numGlyphs); |
| 67 EXPECT_EQ(HB_SCRIPT_LATIN, script); |
| 68 |
| 69 ASSERT_FALSE(iterator.next(&result)); |
| 70 } |
| 71 |
| 72 TEST_F(CachingWordShaperTest, CommonAccentLeftToRightByWord) |
| 73 { |
| 74 const UChar str[] = { 0x2F, 0x301, 0x2E, 0x20, 0x2E, 0x0 }; |
| 75 TextRun textRun(str, 5); |
| 76 |
| 77 unsigned offset = 0; |
| 78 RefPtr<ShapeResult> result; |
| 79 CachingWordShapeIterator iterator(cache, textRun, font, fallbackFonts); |
| 80 ASSERT_TRUE(iterator.next(&result)); |
| 81 ASSERT_TRUE(result->runInfoForTesting(0, startIndex, numGlyphs, script)); |
| 82 EXPECT_EQ(0u, offset + startIndex); |
| 83 EXPECT_EQ(3u, numGlyphs); |
| 84 EXPECT_EQ(HB_SCRIPT_COMMON, script); |
| 85 offset += result->numCharacters(); |
| 86 |
| 87 ASSERT_TRUE(iterator.next(&result)); |
| 88 ASSERT_TRUE(result->runInfoForTesting(0, startIndex, numGlyphs, script)); |
| 89 EXPECT_EQ(3u, offset + startIndex); |
| 90 EXPECT_EQ(1u, numGlyphs); |
| 91 EXPECT_EQ(HB_SCRIPT_COMMON, script); |
| 92 offset += result->numCharacters(); |
| 93 |
| 94 ASSERT_TRUE(iterator.next(&result)); |
| 95 ASSERT_TRUE(result->runInfoForTesting(0, startIndex, numGlyphs, script)); |
| 96 EXPECT_EQ(4u, offset + startIndex); |
| 97 EXPECT_EQ(1u, numGlyphs); |
| 98 EXPECT_EQ(HB_SCRIPT_COMMON, script); |
| 99 offset += result->numCharacters(); |
| 100 |
| 101 ASSERT_EQ(5u, offset); |
| 102 ASSERT_FALSE(iterator.next(&result)); |
| 103 } |
| 104 |
| 105 // Tests that filling a glyph buffer for a specific range returns the same |
| 106 // results when shaping word by word as when shaping the full run in one go. |
| 107 TEST_F(CachingWordShaperTest, CommonAccentLeftToRightFillGlyphBuffer) |
| 108 { |
| 109 // "/. ." with an accent mark over the first dot. |
| 110 const UChar str[] = { 0x2F, 0x301, 0x2E, 0x20, 0x2E, 0x0 }; |
| 111 TextRun textRun(str, 5); |
| 112 |
| 113 CachingWordShaper shaper; |
| 114 GlyphBuffer glyphBuffer; |
| 115 shaper.fillGlyphBuffer(font, textRun, fallbackFonts, &glyphBuffer, 0, 3); |
| 116 |
| 117 CachingWordShaper referenceShaper; |
| 118 GlyphBuffer referenceGlyphBuffer; |
| 119 font->setCanShapeWordByWordForTesting(false); |
| 120 referenceShaper.fillGlyphBuffer(font, textRun, fallbackFonts, |
| 121 &referenceGlyphBuffer, 0, 3); |
| 122 |
| 123 ASSERT_EQ(referenceGlyphBuffer.glyphAt(0), glyphBuffer.glyphAt(0)); |
| 124 ASSERT_EQ(referenceGlyphBuffer.glyphAt(1), glyphBuffer.glyphAt(1)); |
| 125 ASSERT_EQ(referenceGlyphBuffer.glyphAt(2), glyphBuffer.glyphAt(2)); |
| 126 } |
| 127 |
| 128 // Tests that filling a glyph buffer for a specific range returns the same |
| 129 // results when shaping word by word as when shaping the full run in one go. |
| 130 TEST_F(CachingWordShaperTest, CommonAccentRightToLeftFillGlyphBuffer) |
| 131 { |
| 132 // "[] []" with an accent mark over the last square bracket. |
| 133 const UChar str[] = { 0x5B, 0x5D, 0x20, 0x5B, 0x301, 0x5D, 0x0 }; |
| 134 TextRun textRun(str, 6); |
| 135 textRun.setDirection(RTL); |
| 136 |
| 137 CachingWordShaper shaper; |
| 138 GlyphBuffer glyphBuffer; |
| 139 shaper.fillGlyphBuffer(font, textRun, fallbackFonts, &glyphBuffer, 1, 6); |
| 140 |
| 141 CachingWordShaper referenceShaper; |
| 142 GlyphBuffer referenceGlyphBuffer; |
| 143 font->setCanShapeWordByWordForTesting(false); |
| 144 referenceShaper.fillGlyphBuffer(font, textRun, fallbackFonts, |
| 145 &referenceGlyphBuffer, 1, 6); |
| 146 |
| 147 ASSERT_EQ(5u, referenceGlyphBuffer.size()); |
| 148 ASSERT_EQ(referenceGlyphBuffer.size(), glyphBuffer.size()); |
| 149 |
| 150 ASSERT_EQ(referenceGlyphBuffer.glyphAt(0), glyphBuffer.glyphAt(0)); |
| 151 ASSERT_EQ(referenceGlyphBuffer.glyphAt(1), glyphBuffer.glyphAt(1)); |
| 152 ASSERT_EQ(referenceGlyphBuffer.glyphAt(2), glyphBuffer.glyphAt(2)); |
| 153 ASSERT_EQ(referenceGlyphBuffer.glyphAt(3), glyphBuffer.glyphAt(3)); |
| 154 ASSERT_EQ(referenceGlyphBuffer.glyphAt(4), glyphBuffer.glyphAt(4)); |
| 155 } |
| 156 |
| 157 } // namespace blink |
OLD | NEW |