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