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" | 13 #include "wtf/PtrUtil.h" |
14 #include <memory> | 14 #include <memory> |
15 | 15 |
16 namespace blink { | 16 namespace blink { |
17 | 17 |
18 class CachingWordShaperTest : public ::testing::Test { | 18 class CachingWordShaperTest : public ::testing::Test { |
19 protected: | 19 protected: |
20 void SetUp() override { | 20 void SetUp() override { |
21 fontDescription.setComputedSize(12.0); | 21 fontDescription.setComputedSize(12.0); |
22 fontDescription.setLocale(LayoutLocale::get("en")); | 22 fontDescription.setLocale(LayoutLocale::get("en")); |
23 ASSERT_EQ(USCRIPT_LATIN, fontDescription.script()); | 23 ASSERT_EQ(USCRIPT_LATIN, fontDescription.script()); |
24 fontDescription.setGenericFamily(FontDescription::StandardFamily); | 24 fontDescription.setGenericFamily(FontDescription::StandardFamily); |
25 | 25 |
26 font = Font(fontDescription); | 26 font = Font(fontDescription); |
27 font.update(nullptr); | 27 font.update(nullptr); |
28 ASSERT_TRUE(font.canShapeWordByWord()); | 28 ASSERT_TRUE(font.canShapeWordByWord()); |
29 fallbackFonts = nullptr; | 29 fallbackFonts = nullptr; |
30 cache = makeUnique<ShapeCache>(); | 30 cache = WTF::makeUnique<ShapeCache>(); |
31 } | 31 } |
32 | 32 |
33 FontCachePurgePreventer fontCachePurgePreventer; | 33 FontCachePurgePreventer fontCachePurgePreventer; |
34 FontDescription fontDescription; | 34 FontDescription fontDescription; |
35 Font font; | 35 Font font; |
36 std::unique_ptr<ShapeCache> cache; | 36 std::unique_ptr<ShapeCache> cache; |
37 HashSet<const SimpleFontData*>* fallbackFonts; | 37 HashSet<const SimpleFontData*>* fallbackFonts; |
38 unsigned startIndex = 0; | 38 unsigned startIndex = 0; |
39 unsigned numGlyphs = 0; | 39 unsigned numGlyphs = 0; |
40 hb_script_t script = HB_SCRIPT_INVALID; | 40 hb_script_t script = HB_SCRIPT_INVALID; |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
113 // results when shaping word by word as when shaping the full run in one go. | 113 // results when shaping word by word as when shaping the full run in one go. |
114 TEST_F(CachingWordShaperTest, CommonAccentLeftToRightFillGlyphBuffer) { | 114 TEST_F(CachingWordShaperTest, CommonAccentLeftToRightFillGlyphBuffer) { |
115 // "/. ." with an accent mark over the first dot. | 115 // "/. ." with an accent mark over the first dot. |
116 const UChar str[] = {0x2F, 0x301, 0x2E, 0x20, 0x2E, 0x0}; | 116 const UChar str[] = {0x2F, 0x301, 0x2E, 0x20, 0x2E, 0x0}; |
117 TextRun textRun(str, 5); | 117 TextRun textRun(str, 5); |
118 | 118 |
119 CachingWordShaper shaper(cache.get()); | 119 CachingWordShaper shaper(cache.get()); |
120 GlyphBuffer glyphBuffer; | 120 GlyphBuffer glyphBuffer; |
121 shaper.fillGlyphBuffer(&font, textRun, fallbackFonts, &glyphBuffer, 0, 3); | 121 shaper.fillGlyphBuffer(&font, textRun, fallbackFonts, &glyphBuffer, 0, 3); |
122 | 122 |
123 std::unique_ptr<ShapeCache> referenceCache = makeUnique<ShapeCache>(); | 123 std::unique_ptr<ShapeCache> referenceCache = WTF::makeUnique<ShapeCache>(); |
124 CachingWordShaper referenceShaper(referenceCache.get()); | 124 CachingWordShaper referenceShaper(referenceCache.get()); |
125 GlyphBuffer referenceGlyphBuffer; | 125 GlyphBuffer referenceGlyphBuffer; |
126 font.setCanShapeWordByWordForTesting(false); | 126 font.setCanShapeWordByWordForTesting(false); |
127 referenceShaper.fillGlyphBuffer(&font, textRun, fallbackFonts, | 127 referenceShaper.fillGlyphBuffer(&font, textRun, fallbackFonts, |
128 &referenceGlyphBuffer, 0, 3); | 128 &referenceGlyphBuffer, 0, 3); |
129 | 129 |
130 ASSERT_EQ(referenceGlyphBuffer.glyphAt(0), glyphBuffer.glyphAt(0)); | 130 ASSERT_EQ(referenceGlyphBuffer.glyphAt(0), glyphBuffer.glyphAt(0)); |
131 ASSERT_EQ(referenceGlyphBuffer.glyphAt(1), glyphBuffer.glyphAt(1)); | 131 ASSERT_EQ(referenceGlyphBuffer.glyphAt(1), glyphBuffer.glyphAt(1)); |
132 ASSERT_EQ(referenceGlyphBuffer.glyphAt(2), glyphBuffer.glyphAt(2)); | 132 ASSERT_EQ(referenceGlyphBuffer.glyphAt(2), glyphBuffer.glyphAt(2)); |
133 } | 133 } |
134 | 134 |
135 // Tests that filling a glyph buffer for a specific range returns the same | 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. | 136 // results when shaping word by word as when shaping the full run in one go. |
137 TEST_F(CachingWordShaperTest, CommonAccentRightToLeftFillGlyphBuffer) { | 137 TEST_F(CachingWordShaperTest, CommonAccentRightToLeftFillGlyphBuffer) { |
138 // "[] []" with an accent mark over the last square bracket. | 138 // "[] []" with an accent mark over the last square bracket. |
139 const UChar str[] = {0x5B, 0x5D, 0x20, 0x5B, 0x301, 0x5D, 0x0}; | 139 const UChar str[] = {0x5B, 0x5D, 0x20, 0x5B, 0x301, 0x5D, 0x0}; |
140 TextRun textRun(str, 6); | 140 TextRun textRun(str, 6); |
141 textRun.setDirection(RTL); | 141 textRun.setDirection(RTL); |
142 | 142 |
143 CachingWordShaper shaper(cache.get()); | 143 CachingWordShaper shaper(cache.get()); |
144 GlyphBuffer glyphBuffer; | 144 GlyphBuffer glyphBuffer; |
145 shaper.fillGlyphBuffer(&font, textRun, fallbackFonts, &glyphBuffer, 1, 6); | 145 shaper.fillGlyphBuffer(&font, textRun, fallbackFonts, &glyphBuffer, 1, 6); |
146 | 146 |
147 std::unique_ptr<ShapeCache> referenceCache = makeUnique<ShapeCache>(); | 147 std::unique_ptr<ShapeCache> referenceCache = WTF::makeUnique<ShapeCache>(); |
148 CachingWordShaper referenceShaper(referenceCache.get()); | 148 CachingWordShaper referenceShaper(referenceCache.get()); |
149 GlyphBuffer referenceGlyphBuffer; | 149 GlyphBuffer referenceGlyphBuffer; |
150 font.setCanShapeWordByWordForTesting(false); | 150 font.setCanShapeWordByWordForTesting(false); |
151 referenceShaper.fillGlyphBuffer(&font, textRun, fallbackFonts, | 151 referenceShaper.fillGlyphBuffer(&font, textRun, fallbackFonts, |
152 &referenceGlyphBuffer, 1, 6); | 152 &referenceGlyphBuffer, 1, 6); |
153 | 153 |
154 ASSERT_EQ(5u, referenceGlyphBuffer.size()); | 154 ASSERT_EQ(5u, referenceGlyphBuffer.size()); |
155 ASSERT_EQ(referenceGlyphBuffer.size(), glyphBuffer.size()); | 155 ASSERT_EQ(referenceGlyphBuffer.size(), glyphBuffer.size()); |
156 | 156 |
157 ASSERT_EQ(referenceGlyphBuffer.glyphAt(0), glyphBuffer.glyphAt(0)); | 157 ASSERT_EQ(referenceGlyphBuffer.glyphAt(0), glyphBuffer.glyphAt(0)); |
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
452 // The total width of periods and spaces should be longer than the width of | 452 // The total width of periods and spaces should be longer than the width of |
453 // periods alone. | 453 // periods alone. |
454 ASSERT_GT(periodsAndSpacesWidth, periodsWidth); | 454 ASSERT_GT(periodsAndSpacesWidth, periodsWidth); |
455 | 455 |
456 // The glyph bounds of periods and spaces should be longer than the glyph | 456 // The glyph bounds of periods and spaces should be longer than the glyph |
457 // bounds of periods alone. | 457 // bounds of periods alone. |
458 ASSERT_GT(periodsAndSpacesGlyphBounds.width(), periodsGlyphBounds.width()); | 458 ASSERT_GT(periodsAndSpacesGlyphBounds.width(), periodsGlyphBounds.width()); |
459 } | 459 } |
460 | 460 |
461 } // namespace blink | 461 } // namespace blink |
OLD | NEW |