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

Side by Side Diff: third_party/WebKit/Source/platform/fonts/shaping/ShapeResultBloberizerTest.cpp

Issue 2766373005: Add a ShapeResultBloberizer test for mixed rotations (Closed)
Patch Set: review Created 3 years, 9 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
« no previous file with comments | « third_party/WebKit/Source/platform/fonts/SimpleFontData.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 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/ShapeResultBloberizer.h" 5 #include "platform/fonts/shaping/ShapeResultBloberizer.h"
6 6
7 #include "platform/fonts/Font.h" 7 #include "platform/fonts/Font.h"
8 #include "platform/fonts/SimpleFontData.h" 8 #include "platform/fonts/SimpleFontData.h"
9 #include "platform/fonts/opentype/OpenTypeVerticalData.h"
9 #include "platform/fonts/shaping/ShapeResultTestInfo.h" 10 #include "platform/fonts/shaping/ShapeResultTestInfo.h"
10 #include "testing/gtest/include/gtest/gtest.h" 11 #include "testing/gtest/include/gtest/gtest.h"
11 #include "wtf/Optional.h" 12 #include "wtf/Optional.h"
12 13
13 namespace blink { 14 namespace blink {
14 15
15 namespace { 16 namespace {
16 17
17 // Minimal TestSimpleFontData implementation. 18 // Minimal TestSimpleFontData implementation.
18 // Font has no glyphs, but that's okay. 19 // Font has no glyphs, but that's okay.
19 class TestSimpleFontData : public SimpleFontData { 20 class TestSimpleFontData : public SimpleFontData {
20 public: 21 public:
21 static PassRefPtr<TestSimpleFontData> create() { 22 static PassRefPtr<TestSimpleFontData> create(bool forceRotation = false) {
22 return adoptRef(new TestSimpleFontData); 23 FontPlatformData platformData(
24 SkTypeface::MakeDefault(), nullptr, 10, false, false,
25 forceRotation ? FontOrientation::VerticalUpright
26 : FontOrientation::Horizontal);
27 RefPtr<OpenTypeVerticalData> verticalData(
28 forceRotation ? OpenTypeVerticalData::create(platformData) : nullptr);
29 return adoptRef(
30 new TestSimpleFontData(platformData, std::move(verticalData)));
23 } 31 }
24 32
25 private: 33 private:
26 TestSimpleFontData() : SimpleFontData(nullptr, 10, false, false) {} 34 TestSimpleFontData(const FontPlatformData& platformData,
35 PassRefPtr<OpenTypeVerticalData> verticalData)
36 : SimpleFontData(platformData, std::move(verticalData)) {}
27 }; 37 };
28 38
29 } // anonymous namespace 39 } // anonymous namespace
30 40
31 TEST(ShapeResultBloberizerTest, StartsEmpty) { 41 TEST(ShapeResultBloberizerTest, StartsEmpty) {
32 Font font; 42 Font font;
33 ShapeResultBloberizer bloberizer(font, 1); 43 ShapeResultBloberizer bloberizer(font, 1);
34 44
35 EXPECT_EQ(ShapeResultBloberizerTestInfo::pendingRunFontData(bloberizer), 45 EXPECT_EQ(ShapeResultBloberizerTestInfo::pendingRunFontData(bloberizer),
36 nullptr); 46 nullptr);
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 } 173 }
164 174
165 EXPECT_EQ(ShapeResultBloberizerTestInfo::pendingBlobRunCount(bloberizer), 175 EXPECT_EQ(ShapeResultBloberizerTestInfo::pendingBlobRunCount(bloberizer),
166 1ul); 176 1ul);
167 EXPECT_EQ(ShapeResultBloberizerTestInfo::committedBlobCount(bloberizer), 0ul); 177 EXPECT_EQ(ShapeResultBloberizerTestInfo::committedBlobCount(bloberizer), 0ul);
168 178
169 // flush everything (1 blob w/ 2 runs) 179 // flush everything (1 blob w/ 2 runs)
170 EXPECT_EQ(bloberizer.blobs().size(), 1ul); 180 EXPECT_EQ(bloberizer.blobs().size(), 1ul);
171 } 181 }
172 182
183 TEST(ShapeResultBloberizerTest, MixedBlobRotation) {
184 Font font;
185 ShapeResultBloberizer bloberizer(font, 1);
186
187 // Normal (horizontal) font.
188 RefPtr<SimpleFontData> fontNormal = TestSimpleFontData::create();
189 ASSERT_FALSE(fontNormal->platformData().isVerticalAnyUpright());
190 ASSERT_EQ(fontNormal->verticalData(), nullptr);
191
192 // Rotated (vertical upright) font.
193 RefPtr<SimpleFontData> fontRotated = TestSimpleFontData::create(true);
194 ASSERT_TRUE(fontRotated->platformData().isVerticalAnyUpright());
195 ASSERT_NE(fontRotated->verticalData(), nullptr);
196
197 struct {
198 const SimpleFontData* fontData;
199 size_t expectedPendingGlyphs;
200 size_t expectedPendingRuns;
201 size_t expectedCommittedBlobs;
202 } appendOps[] = {
203 // append 2 horizontal glyphs -> these go into the pending glyph buffer
204 {fontNormal.get(), 1u, 0u, 0u},
205 {fontNormal.get(), 2u, 0u, 0u},
206
207 // append 3 vertical rotated glyphs -> push the prev pending (horizontal)
208 // glyphs into a new run in the current (horizontal) blob
209 {fontRotated.get(), 1u, 1u, 0u},
210 {fontRotated.get(), 2u, 1u, 0u},
211 {fontRotated.get(), 3u, 1u, 0u},
212
213 // append 2 more horizontal glyphs -> flush the current (horizontal) blob,
214 // push prev (vertical) pending glyphs into new vertical blob run
215 {fontNormal.get(), 1u, 1u, 1u},
216 {fontNormal.get(), 2u, 1u, 1u},
217
218 // append 1 more vertical glyph -> flush current (vertical) blob, push
219 // prev (horizontal) pending glyphs into a new horizontal blob run
220 {fontRotated.get(), 1u, 1u, 2u},
221 };
222
223 for (const auto& op : appendOps) {
224 bloberizer.add(42, op.fontData, FloatPoint());
225 EXPECT_EQ(
226 op.expectedPendingGlyphs,
227 ShapeResultBloberizerTestInfo::pendingRunGlyphs(bloberizer).size());
228 EXPECT_EQ(op.expectedPendingRuns,
229 ShapeResultBloberizerTestInfo::pendingBlobRunCount(bloberizer));
230 EXPECT_EQ(op.expectedCommittedBlobs,
231 ShapeResultBloberizerTestInfo::committedBlobCount(bloberizer));
232 }
233
234 // flush everything -> 4 blobs total
235 EXPECT_EQ(4u, bloberizer.blobs().size());
236 }
237
173 } // namespace blink 238 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/platform/fonts/SimpleFontData.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698