| 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 font->setCanShapeWordByWordForTesting(true); |
| 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 const UChar str[] = { 0x2F, 0x301, 0x2E, 0x20, 0x2E, 0x0 }; |
| 110 TextRun textRun(str, 5); |
| 111 |
| 112 CachingWordShaper shaper; |
| 113 GlyphBuffer glyphBuffer; |
| 114 shaper.fillGlyphBuffer(font, textRun, fallbackFonts, &glyphBuffer, 0, 3); |
| 115 |
| 116 CachingWordShaper referenceShaper; |
| 117 GlyphBuffer referenceGlyphBuffer; |
| 118 font->setCanShapeWordByWordForTesting(false); |
| 119 referenceShaper.fillGlyphBuffer(font, textRun, fallbackFonts, |
| 120 &referenceGlyphBuffer, 0, 3); |
| 121 |
| 122 ASSERT_EQ(referenceGlyphBuffer.glyphAt(0), glyphBuffer.glyphAt(0)); |
| 123 ASSERT_EQ(referenceGlyphBuffer.xOffsetAt(0), glyphBuffer.xOffsetAt(0)); |
| 124 ASSERT_EQ(referenceGlyphBuffer.yOffsetAt(0), glyphBuffer.yOffsetAt(0)); |
| 125 |
| 126 ASSERT_EQ(referenceGlyphBuffer.glyphAt(1), glyphBuffer.glyphAt(1)); |
| 127 ASSERT_EQ(referenceGlyphBuffer.xOffsetAt(1), glyphBuffer.xOffsetAt(1)); |
| 128 ASSERT_EQ(referenceGlyphBuffer.yOffsetAt(1), glyphBuffer.yOffsetAt(1)); |
| 129 |
| 130 ASSERT_EQ(referenceGlyphBuffer.glyphAt(2), glyphBuffer.glyphAt(2)); |
| 131 ASSERT_EQ(referenceGlyphBuffer.xOffsetAt(2), glyphBuffer.xOffsetAt(2)); |
| 132 ASSERT_EQ(referenceGlyphBuffer.yOffsetAt(2), glyphBuffer.yOffsetAt(2)); |
| 133 } |
| 134 |
| 135 // Tests that filling a glyph buffer for a specific range returns the same |
| 136 // results when shaping word by word as when shaping the full run in one go. |
| 137 TEST_F(CachingWordShaperTest, CommonAccentRightToLeftFillGlyphBuffer) |
| 138 { |
| 139 const UChar str[] = { 0x5A, 0x05B, 0x20, 0x5C, 0x301, 0x5E, 0x0 }; |
| 140 TextRun textRun(str, 6); |
| 141 textRun.setDirection(RTL); |
| 142 |
| 143 CachingWordShaper shaper; |
| 144 GlyphBuffer glyphBuffer; |
| 145 shaper.fillGlyphBuffer(font, textRun, fallbackFonts, &glyphBuffer, 1, 6); |
| 146 |
| 147 CachingWordShaper referenceShaper; |
| 148 GlyphBuffer referenceGlyphBuffer; |
| 149 font->setCanShapeWordByWordForTesting(false); |
| 150 referenceShaper.fillGlyphBuffer(font, textRun, fallbackFonts, |
| 151 &referenceGlyphBuffer, 1, 6); |
| 152 |
| 153 ASSERT_EQ(5u, referenceGlyphBuffer.size()); |
| 154 ASSERT_EQ(referenceGlyphBuffer.size(), glyphBuffer.size()); |
| 155 |
| 156 ASSERT_EQ(referenceGlyphBuffer.glyphAt(0), glyphBuffer.glyphAt(0)); |
| 157 ASSERT_EQ(referenceGlyphBuffer.xOffsetAt(0), glyphBuffer.xOffsetAt(0)); |
| 158 ASSERT_EQ(referenceGlyphBuffer.yOffsetAt(0), glyphBuffer.yOffsetAt(0)); |
| 159 |
| 160 ASSERT_EQ(referenceGlyphBuffer.glyphAt(1), glyphBuffer.glyphAt(1)); |
| 161 ASSERT_EQ(referenceGlyphBuffer.xOffsetAt(1), glyphBuffer.xOffsetAt(1)); |
| 162 ASSERT_EQ(referenceGlyphBuffer.yOffsetAt(1), glyphBuffer.yOffsetAt(1)); |
| 163 |
| 164 ASSERT_EQ(referenceGlyphBuffer.glyphAt(2), glyphBuffer.glyphAt(2)); |
| 165 ASSERT_EQ(referenceGlyphBuffer.xOffsetAt(2), glyphBuffer.xOffsetAt(2)); |
| 166 ASSERT_EQ(referenceGlyphBuffer.yOffsetAt(2), glyphBuffer.yOffsetAt(2)); |
| 167 |
| 168 ASSERT_EQ(referenceGlyphBuffer.glyphAt(3), glyphBuffer.glyphAt(3)); |
| 169 ASSERT_EQ(referenceGlyphBuffer.xOffsetAt(3), glyphBuffer.xOffsetAt(3)); |
| 170 ASSERT_EQ(referenceGlyphBuffer.yOffsetAt(3), glyphBuffer.yOffsetAt(3)); |
| 171 |
| 172 ASSERT_EQ(referenceGlyphBuffer.glyphAt(4), glyphBuffer.glyphAt(4)); |
| 173 ASSERT_EQ(referenceGlyphBuffer.xOffsetAt(4), glyphBuffer.xOffsetAt(4)); |
| 174 ASSERT_EQ(referenceGlyphBuffer.yOffsetAt(4), glyphBuffer.yOffsetAt(4)); |
| 175 } |
| 176 |
| 177 } // namespace blink |
| OLD | NEW |