| 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 "platform/fonts/CharacterRange.h" | 7 #include "platform/fonts/CharacterRange.h" |
| 8 #include "platform/fonts/FontCache.h" | 8 #include "platform/fonts/FontCache.h" |
| 9 #include "platform/fonts/GlyphBuffer.h" | 9 #include "platform/fonts/GlyphBuffer.h" |
| 10 #include "platform/fonts/shaping/CachingWordShapeIterator.h" | 10 #include "platform/fonts/shaping/CachingWordShapeIterator.h" |
| 11 #include "platform/fonts/shaping/ShapeResultTestInfo.h" | 11 #include "platform/fonts/shaping/ShapeResultTestInfo.h" |
| 12 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
| 13 #include "wtf/PtrUtil.h" | |
| 14 #include <memory> | |
| 15 | 13 |
| 16 namespace blink { | 14 namespace blink { |
| 17 | 15 |
| 18 class CachingWordShaperTest : public ::testing::Test { | 16 class CachingWordShaperTest : public ::testing::Test { |
| 19 protected: | 17 protected: |
| 20 void SetUp() override | 18 void SetUp() override |
| 21 { | 19 { |
| 22 fontDescription.setComputedSize(12.0); | 20 fontDescription.setComputedSize(12.0); |
| 23 fontDescription.setLocale("en"); | 21 fontDescription.setLocale("en"); |
| 24 ASSERT_EQ(USCRIPT_LATIN, fontDescription.script()); | 22 ASSERT_EQ(USCRIPT_LATIN, fontDescription.script()); |
| 25 fontDescription.setGenericFamily(FontDescription::StandardFamily); | 23 fontDescription.setGenericFamily(FontDescription::StandardFamily); |
| 26 | 24 |
| 27 font = Font(fontDescription); | 25 font = Font(fontDescription); |
| 28 font.update(nullptr); | 26 font.update(nullptr); |
| 29 ASSERT_TRUE(font.canShapeWordByWord()); | 27 ASSERT_TRUE(font.canShapeWordByWord()); |
| 30 fallbackFonts = nullptr; | 28 fallbackFonts = nullptr; |
| 31 cache = wrapUnique(new ShapeCache()); | 29 cache = adoptPtr(new ShapeCache()); |
| 32 } | 30 } |
| 33 | 31 |
| 34 FontCachePurgePreventer fontCachePurgePreventer; | 32 FontCachePurgePreventer fontCachePurgePreventer; |
| 35 FontDescription fontDescription; | 33 FontDescription fontDescription; |
| 36 Font font; | 34 Font font; |
| 37 std::unique_ptr<ShapeCache> cache; | 35 OwnPtr<ShapeCache> cache; |
| 38 HashSet<const SimpleFontData*>* fallbackFonts; | 36 HashSet<const SimpleFontData*>* fallbackFonts; |
| 39 unsigned startIndex = 0; | 37 unsigned startIndex = 0; |
| 40 unsigned numGlyphs = 0; | 38 unsigned numGlyphs = 0; |
| 41 hb_script_t script = HB_SCRIPT_INVALID; | 39 hb_script_t script = HB_SCRIPT_INVALID; |
| 42 }; | 40 }; |
| 43 | 41 |
| 44 static inline const ShapeResultTestInfo* testInfo( | 42 static inline const ShapeResultTestInfo* testInfo( |
| 45 RefPtr<const ShapeResult>& result) | 43 RefPtr<const ShapeResult>& result) |
| 46 { | 44 { |
| 47 return static_cast<const ShapeResultTestInfo*>(result.get()); | 45 return static_cast<const ShapeResultTestInfo*>(result.get()); |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 TEST_F(CachingWordShaperTest, CommonAccentLeftToRightFillGlyphBuffer) | 110 TEST_F(CachingWordShaperTest, CommonAccentLeftToRightFillGlyphBuffer) |
| 113 { | 111 { |
| 114 // "/. ." with an accent mark over the first dot. | 112 // "/. ." with an accent mark over the first dot. |
| 115 const UChar str[] = { 0x2F, 0x301, 0x2E, 0x20, 0x2E, 0x0 }; | 113 const UChar str[] = { 0x2F, 0x301, 0x2E, 0x20, 0x2E, 0x0 }; |
| 116 TextRun textRun(str, 5); | 114 TextRun textRun(str, 5); |
| 117 | 115 |
| 118 CachingWordShaper shaper(cache.get()); | 116 CachingWordShaper shaper(cache.get()); |
| 119 GlyphBuffer glyphBuffer; | 117 GlyphBuffer glyphBuffer; |
| 120 shaper.fillGlyphBuffer(&font, textRun, fallbackFonts, &glyphBuffer, 0, 3); | 118 shaper.fillGlyphBuffer(&font, textRun, fallbackFonts, &glyphBuffer, 0, 3); |
| 121 | 119 |
| 122 std::unique_ptr<ShapeCache> referenceCache = wrapUnique(new ShapeCache()); | 120 OwnPtr<ShapeCache> referenceCache = adoptPtr(new ShapeCache()); |
| 123 CachingWordShaper referenceShaper(referenceCache.get()); | 121 CachingWordShaper referenceShaper(referenceCache.get()); |
| 124 GlyphBuffer referenceGlyphBuffer; | 122 GlyphBuffer referenceGlyphBuffer; |
| 125 font.setCanShapeWordByWordForTesting(false); | 123 font.setCanShapeWordByWordForTesting(false); |
| 126 referenceShaper.fillGlyphBuffer(&font, textRun, fallbackFonts, | 124 referenceShaper.fillGlyphBuffer(&font, textRun, fallbackFonts, |
| 127 &referenceGlyphBuffer, 0, 3); | 125 &referenceGlyphBuffer, 0, 3); |
| 128 | 126 |
| 129 ASSERT_EQ(referenceGlyphBuffer.glyphAt(0), glyphBuffer.glyphAt(0)); | 127 ASSERT_EQ(referenceGlyphBuffer.glyphAt(0), glyphBuffer.glyphAt(0)); |
| 130 ASSERT_EQ(referenceGlyphBuffer.glyphAt(1), glyphBuffer.glyphAt(1)); | 128 ASSERT_EQ(referenceGlyphBuffer.glyphAt(1), glyphBuffer.glyphAt(1)); |
| 131 ASSERT_EQ(referenceGlyphBuffer.glyphAt(2), glyphBuffer.glyphAt(2)); | 129 ASSERT_EQ(referenceGlyphBuffer.glyphAt(2), glyphBuffer.glyphAt(2)); |
| 132 } | 130 } |
| 133 | 131 |
| 134 // Tests that filling a glyph buffer for a specific range returns the same | 132 // Tests that filling a glyph buffer for a specific range returns the same |
| 135 // results when shaping word by word as when shaping the full run in one go. | 133 // results when shaping word by word as when shaping the full run in one go. |
| 136 TEST_F(CachingWordShaperTest, CommonAccentRightToLeftFillGlyphBuffer) | 134 TEST_F(CachingWordShaperTest, CommonAccentRightToLeftFillGlyphBuffer) |
| 137 { | 135 { |
| 138 // "[] []" with an accent mark over the last square bracket. | 136 // "[] []" with an accent mark over the last square bracket. |
| 139 const UChar str[] = { 0x5B, 0x5D, 0x20, 0x5B, 0x301, 0x5D, 0x0 }; | 137 const UChar str[] = { 0x5B, 0x5D, 0x20, 0x5B, 0x301, 0x5D, 0x0 }; |
| 140 TextRun textRun(str, 6); | 138 TextRun textRun(str, 6); |
| 141 textRun.setDirection(RTL); | 139 textRun.setDirection(RTL); |
| 142 | 140 |
| 143 CachingWordShaper shaper(cache.get()); | 141 CachingWordShaper shaper(cache.get()); |
| 144 GlyphBuffer glyphBuffer; | 142 GlyphBuffer glyphBuffer; |
| 145 shaper.fillGlyphBuffer(&font, textRun, fallbackFonts, &glyphBuffer, 1, 6); | 143 shaper.fillGlyphBuffer(&font, textRun, fallbackFonts, &glyphBuffer, 1, 6); |
| 146 | 144 |
| 147 std::unique_ptr<ShapeCache> referenceCache = wrapUnique(new ShapeCache()); | 145 OwnPtr<ShapeCache> referenceCache = adoptPtr(new ShapeCache()); |
| 148 CachingWordShaper referenceShaper(referenceCache.get()); | 146 CachingWordShaper referenceShaper(referenceCache.get()); |
| 149 GlyphBuffer referenceGlyphBuffer; | 147 GlyphBuffer referenceGlyphBuffer; |
| 150 font.setCanShapeWordByWordForTesting(false); | 148 font.setCanShapeWordByWordForTesting(false); |
| 151 referenceShaper.fillGlyphBuffer(&font, textRun, fallbackFonts, | 149 referenceShaper.fillGlyphBuffer(&font, textRun, fallbackFonts, |
| 152 &referenceGlyphBuffer, 1, 6); | 150 &referenceGlyphBuffer, 1, 6); |
| 153 | 151 |
| 154 ASSERT_EQ(5u, referenceGlyphBuffer.size()); | 152 ASSERT_EQ(5u, referenceGlyphBuffer.size()); |
| 155 ASSERT_EQ(referenceGlyphBuffer.size(), glyphBuffer.size()); | 153 ASSERT_EQ(referenceGlyphBuffer.size(), glyphBuffer.size()); |
| 156 | 154 |
| 157 ASSERT_EQ(referenceGlyphBuffer.glyphAt(0), glyphBuffer.glyphAt(0)); | 155 ASSERT_EQ(referenceGlyphBuffer.glyphAt(0), glyphBuffer.glyphAt(0)); |
| (...skipping 362 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 520 float periodsAndSpacesWidth = shaper.width(&font, periodsAndSpaces, nullptr,
&periodsAndSpacesGlyphBounds); | 518 float periodsAndSpacesWidth = shaper.width(&font, periodsAndSpaces, nullptr,
&periodsAndSpacesGlyphBounds); |
| 521 | 519 |
| 522 // The total width of periods and spaces should be longer than the width of
periods alone. | 520 // The total width of periods and spaces should be longer than the width of
periods alone. |
| 523 ASSERT_GT(periodsAndSpacesWidth, periodsWidth); | 521 ASSERT_GT(periodsAndSpacesWidth, periodsWidth); |
| 524 | 522 |
| 525 // The glyph bounds of periods and spaces should be longer than the glyph bo
unds of periods alone. | 523 // The glyph bounds of periods and spaces should be longer than the glyph bo
unds of periods alone. |
| 526 ASSERT_GT(periodsAndSpacesGlyphBounds.width(), periodsGlyphBounds.width()); | 524 ASSERT_GT(periodsAndSpacesGlyphBounds.width(), periodsGlyphBounds.width()); |
| 527 } | 525 } |
| 528 | 526 |
| 529 } // namespace blink | 527 } // namespace blink |
| OLD | NEW |