OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 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 "config.h" | 5 #include "config.h" |
6 #include "platform/fonts/GlyphBuffer.h" | 6 #include "platform/fonts/GlyphBuffer.h" |
7 | 7 |
8 #include "platform/fonts/SimpleFontData.h" | 8 #include "platform/fonts/SimpleFontData.h" |
9 #include "wtf/PassRefPtr.h" | 9 #include "wtf/PassRefPtr.h" |
10 #include "wtf/RefPtr.h" | 10 #include "wtf/RefPtr.h" |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 { | 43 { |
44 RefPtr<SimpleFontData> font1 = TestSimpleFontData::create(); | 44 RefPtr<SimpleFontData> font1 = TestSimpleFontData::create(); |
45 RefPtr<SimpleFontData> font2 = TestSimpleFontData::create(); | 45 RefPtr<SimpleFontData> font2 = TestSimpleFontData::create(); |
46 | 46 |
47 GlyphBuffer glyphBuffer; | 47 GlyphBuffer glyphBuffer; |
48 glyphBuffer.add(42, font1.get(), 10); | 48 glyphBuffer.add(42, font1.get(), 10); |
49 glyphBuffer.add(43, font1.get(), 15); | 49 glyphBuffer.add(43, font1.get(), 15); |
50 glyphBuffer.add(44, font2.get(), 12); | 50 glyphBuffer.add(44, font2.get(), 12); |
51 | 51 |
52 EXPECT_FALSE(glyphBuffer.isEmpty()); | 52 EXPECT_FALSE(glyphBuffer.isEmpty()); |
| 53 EXPECT_FALSE(glyphBuffer.hasOffsets()); |
53 EXPECT_EQ(3u, glyphBuffer.size()); | 54 EXPECT_EQ(3u, glyphBuffer.size()); |
54 | 55 |
55 EXPECT_EQ(42, glyphBuffer.glyphAt(0)); | 56 EXPECT_EQ(42, glyphBuffer.glyphAt(0)); |
56 EXPECT_EQ(43, glyphBuffer.glyphAt(1)); | 57 EXPECT_EQ(43, glyphBuffer.glyphAt(1)); |
57 EXPECT_EQ(44, glyphBuffer.glyphAt(2)); | 58 EXPECT_EQ(44, glyphBuffer.glyphAt(2)); |
58 | 59 |
59 const Glyph* glyphs = glyphBuffer.glyphs(0); | 60 const Glyph* glyphs = glyphBuffer.glyphs(0); |
60 EXPECT_EQ(42, glyphs[0]); | 61 EXPECT_EQ(42, glyphs[0]); |
61 EXPECT_EQ(43, glyphs[1]); | 62 EXPECT_EQ(43, glyphs[1]); |
62 EXPECT_EQ(44, glyphs[2]); | 63 EXPECT_EQ(44, glyphs[2]); |
63 } | 64 } |
64 | 65 |
65 TEST(GlyphBufferTest, StoresOffsets) | 66 TEST(GlyphBufferTest, StoresOffsets) |
66 { | 67 { |
67 RefPtr<SimpleFontData> font1 = TestSimpleFontData::create(); | 68 RefPtr<SimpleFontData> font1 = TestSimpleFontData::create(); |
68 RefPtr<SimpleFontData> font2 = TestSimpleFontData::create(); | 69 RefPtr<SimpleFontData> font2 = TestSimpleFontData::create(); |
69 | 70 |
70 GlyphBufferWithOffsets glyphBuffer; | 71 GlyphBuffer glyphBuffer; |
71 glyphBuffer.add(42, font1.get(), FloatSize(10, 0), 0); | 72 glyphBuffer.add(42, font1.get(), FloatSize(10, 0), 0); |
72 glyphBuffer.add(43, font1.get(), FloatSize(15, 0), 0); | 73 glyphBuffer.add(43, font1.get(), FloatSize(15, 0), 0); |
73 glyphBuffer.add(44, font2.get(), FloatSize(12, 2), 0); | 74 glyphBuffer.add(44, font2.get(), FloatSize(12, 2), 0); |
74 | 75 |
75 EXPECT_FALSE(glyphBuffer.isEmpty()); | 76 EXPECT_FALSE(glyphBuffer.isEmpty()); |
| 77 EXPECT_TRUE(glyphBuffer.hasOffsets()); |
76 EXPECT_EQ(3u, glyphBuffer.size()); | 78 EXPECT_EQ(3u, glyphBuffer.size()); |
77 | 79 |
78 EXPECT_EQ(FloatSize(10, 0), glyphBuffer.offsetAt(0)); | |
79 EXPECT_EQ(FloatSize(15, 0), glyphBuffer.offsetAt(1)); | |
80 EXPECT_EQ(FloatSize(12, 2), glyphBuffer.offsetAt(2)); | |
81 | |
82 const FloatSize* offsets = glyphBuffer.offsets(0); | 80 const FloatSize* offsets = glyphBuffer.offsets(0); |
83 EXPECT_EQ(FloatSize(10, 0), offsets[0]); | 81 EXPECT_EQ(FloatSize(10, 0), offsets[0]); |
84 EXPECT_EQ(FloatSize(15, 0), offsets[1]); | 82 EXPECT_EQ(FloatSize(15, 0), offsets[1]); |
85 EXPECT_EQ(FloatSize(12, 2), offsets[2]); | 83 EXPECT_EQ(FloatSize(12, 2), offsets[2]); |
86 } | 84 } |
87 | 85 |
88 TEST(GlyphBufferTest, StoresAdvances) | 86 TEST(GlyphBufferTest, StoresAdvances) |
89 { | 87 { |
90 RefPtr<SimpleFontData> font1 = TestSimpleFontData::create(); | 88 RefPtr<SimpleFontData> font1 = TestSimpleFontData::create(); |
91 RefPtr<SimpleFontData> font2 = TestSimpleFontData::create(); | 89 RefPtr<SimpleFontData> font2 = TestSimpleFontData::create(); |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
198 GlyphBuffer glyphBuffer; | 196 GlyphBuffer glyphBuffer; |
199 glyphBuffer.add(42, font1.get(), 10); | 197 glyphBuffer.add(42, font1.get(), 10); |
200 glyphBuffer.add(43, font1.get(), 15); | 198 glyphBuffer.add(43, font1.get(), 15); |
201 glyphBuffer.add(44, font2.get(), 12); | 199 glyphBuffer.add(44, font2.get(), 12); |
202 | 200 |
203 glyphBuffer.expandLastAdvance(20); | 201 glyphBuffer.expandLastAdvance(20); |
204 EXPECT_EQ(32, glyphBuffer.advanceAt(2)); | 202 EXPECT_EQ(32, glyphBuffer.advanceAt(2)); |
205 } | 203 } |
206 | 204 |
207 } // namespace | 205 } // namespace |
OLD | NEW |