Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(42)

Side by Side Diff: Source/platform/fonts/shaping/CachingWordShaperTest.cpp

Issue 1192223002: Optimize Complex Text Shaping and Caching (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Addressing review comments Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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);
drott 2015/06/23 12:45:52 Isn't there a small chance that the font found for
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 };
drott 2015/06/23 12:45:51 I am not sure, do our source files allow UTF-8? Ca
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.glyphAt(1), glyphBuffer.glyphAt(1));
124 ASSERT_EQ(referenceGlyphBuffer.glyphAt(2), glyphBuffer.glyphAt(2));
125 }
126
127 // Tests that filling a glyph buffer for a specific range returns the same
128 // results when shaping word by word as when shaping the full run in one go.
129 TEST_F(CachingWordShaperTest, CommonAccentRightToLeftFillGlyphBuffer)
130 {
131 const UChar str[] = { 0x5A, 0x05B, 0x20, 0x5C, 0x301, 0x5E, 0x0 };
132 TextRun textRun(str, 6);
133 textRun.setDirection(RTL);
134
135 CachingWordShaper shaper;
136 GlyphBuffer glyphBuffer;
137 shaper.fillGlyphBuffer(font, textRun, fallbackFonts, &glyphBuffer, 1, 6);
138
139 CachingWordShaper referenceShaper;
140 GlyphBuffer referenceGlyphBuffer;
141 font->setCanShapeWordByWordForTesting(false);
142 referenceShaper.fillGlyphBuffer(font, textRun, fallbackFonts,
143 &referenceGlyphBuffer, 1, 6);
144
145 ASSERT_EQ(5u, referenceGlyphBuffer.size());
146 ASSERT_EQ(referenceGlyphBuffer.size(), glyphBuffer.size());
147
148 ASSERT_EQ(referenceGlyphBuffer.glyphAt(0), glyphBuffer.glyphAt(0));
149 ASSERT_EQ(referenceGlyphBuffer.glyphAt(1), glyphBuffer.glyphAt(1));
150 ASSERT_EQ(referenceGlyphBuffer.glyphAt(2), glyphBuffer.glyphAt(2));
151 ASSERT_EQ(referenceGlyphBuffer.glyphAt(3), glyphBuffer.glyphAt(3));
152 ASSERT_EQ(referenceGlyphBuffer.glyphAt(4), glyphBuffer.glyphAt(4));
153 }
154
155 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698