Chromium Code Reviews| 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 29 matching lines...) Expand all Loading... | |
| 40 } | 40 } |
| 41 | 41 |
| 42 TEST(GlyphBufferTest, StoresGlyphs) | 42 TEST(GlyphBufferTest, StoresGlyphs) |
| 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(), 22); |
| 51 | 51 |
| 52 EXPECT_FALSE(glyphBuffer.isEmpty()); | 52 EXPECT_FALSE(glyphBuffer.isEmpty()); |
| 53 EXPECT_FALSE(glyphBuffer.hasOffsets()); | 53 EXPECT_FALSE(glyphBuffer.hasVerticalOffsets()); |
| 54 EXPECT_EQ(3u, glyphBuffer.size()); | 54 EXPECT_EQ(3u, glyphBuffer.size()); |
| 55 | 55 |
| 56 EXPECT_EQ(42, glyphBuffer.glyphAt(0)); | 56 EXPECT_EQ(42, glyphBuffer.glyphAt(0)); |
| 57 EXPECT_EQ(43, glyphBuffer.glyphAt(1)); | 57 EXPECT_EQ(43, glyphBuffer.glyphAt(1)); |
| 58 EXPECT_EQ(44, glyphBuffer.glyphAt(2)); | 58 EXPECT_EQ(44, glyphBuffer.glyphAt(2)); |
| 59 | 59 |
| 60 const Glyph* glyphs = glyphBuffer.glyphs(0); | 60 const Glyph* glyphs = glyphBuffer.glyphs(0); |
| 61 EXPECT_EQ(42, glyphs[0]); | 61 EXPECT_EQ(42, glyphs[0]); |
| 62 EXPECT_EQ(43, glyphs[1]); | 62 EXPECT_EQ(43, glyphs[1]); |
| 63 EXPECT_EQ(44, glyphs[2]); | 63 EXPECT_EQ(44, glyphs[2]); |
| 64 } | 64 } |
| 65 | 65 |
| 66 TEST(GlyphBufferTest, StoresVerticalOffsets) | |
| 67 { | |
| 68 RefPtr<SimpleFontData> font1 = TestSimpleFontData::create(); | |
| 69 RefPtr<SimpleFontData> font2 = TestSimpleFontData::create(); | |
| 70 | |
| 71 GlyphBuffer glyphBuffer; | |
| 72 EXPECT_FALSE(glyphBuffer.hasVerticalOffsets()); | |
| 73 | |
| 74 glyphBuffer.add(42, font1.get(), FloatPoint(10, 0)); | |
| 75 glyphBuffer.add(43, font1.get(), FloatPoint(15, 0)); | |
| 76 glyphBuffer.add(44, font2.get(), FloatPoint(12, 2)); | |
| 77 | |
| 78 EXPECT_FALSE(glyphBuffer.isEmpty()); | |
| 79 EXPECT_TRUE(glyphBuffer.hasVerticalOffsets()); | |
| 80 EXPECT_EQ(3u, glyphBuffer.size()); | |
| 81 | |
| 82 const float* offsets = glyphBuffer.offsets(0); | |
| 83 EXPECT_EQ(10, glyphBuffer.xOffsetAt(0)); | |
| 84 EXPECT_EQ(0, glyphBuffer.yOffsetAt(0)); | |
| 85 EXPECT_EQ(15, glyphBuffer.xOffsetAt(1)); | |
| 86 EXPECT_EQ(0, glyphBuffer.yOffsetAt(1)); | |
| 87 EXPECT_EQ(12, glyphBuffer.xOffsetAt(2)); | |
| 88 EXPECT_EQ(2, glyphBuffer.yOffsetAt(2)); | |
| 89 | |
| 90 EXPECT_EQ(10, offsets[0]); | |
| 91 EXPECT_EQ(0, offsets[1]); | |
| 92 EXPECT_EQ(15, offsets[2]); | |
| 93 EXPECT_EQ(0, offsets[3]); | |
| 94 EXPECT_EQ(12, offsets[4]); | |
| 95 EXPECT_EQ(2, offsets[5]); | |
| 96 } | |
| 97 | |
| 66 TEST(GlyphBufferTest, StoresOffsets) | 98 TEST(GlyphBufferTest, StoresOffsets) |
| 67 { | 99 { |
| 68 RefPtr<SimpleFontData> font1 = TestSimpleFontData::create(); | 100 RefPtr<SimpleFontData> font1 = TestSimpleFontData::create(); |
| 69 RefPtr<SimpleFontData> font2 = TestSimpleFontData::create(); | 101 RefPtr<SimpleFontData> font2 = TestSimpleFontData::create(); |
| 70 | |
| 71 GlyphBuffer glyphBuffer; | |
| 72 glyphBuffer.add(42, font1.get(), FloatSize(10, 0), 0); | |
| 73 glyphBuffer.add(43, font1.get(), FloatSize(15, 0), 0); | |
| 74 glyphBuffer.add(44, font2.get(), FloatSize(12, 2), 0); | |
| 75 | |
| 76 EXPECT_FALSE(glyphBuffer.isEmpty()); | |
| 77 EXPECT_TRUE(glyphBuffer.hasOffsets()); | |
| 78 EXPECT_EQ(3u, glyphBuffer.size()); | |
| 79 | |
| 80 const FloatSize* offsets = glyphBuffer.offsets(0); | |
| 81 EXPECT_EQ(FloatSize(10, 0), offsets[0]); | |
| 82 EXPECT_EQ(FloatSize(15, 0), offsets[1]); | |
| 83 EXPECT_EQ(FloatSize(12, 2), offsets[2]); | |
| 84 } | |
| 85 | |
| 86 TEST(GlyphBufferTest, StoresAdvances) | |
| 87 { | |
| 88 RefPtr<SimpleFontData> font1 = TestSimpleFontData::create(); | |
| 89 RefPtr<SimpleFontData> font2 = TestSimpleFontData::create(); | |
| 90 | 102 |
| 91 GlyphBuffer glyphBuffer; | 103 GlyphBuffer glyphBuffer; |
| 92 glyphBuffer.add(42, font1.get(), 10); | 104 glyphBuffer.add(42, font1.get(), 10); |
| 93 glyphBuffer.add(43, font1.get(), 15); | 105 glyphBuffer.add(43, font1.get(), 15); |
| 94 glyphBuffer.add(44, font2.get(), 20); | 106 glyphBuffer.add(44, font2.get(), 20); |
| 95 | 107 |
| 96 EXPECT_FALSE(glyphBuffer.isEmpty()); | 108 EXPECT_FALSE(glyphBuffer.isEmpty()); |
| 109 EXPECT_FALSE(glyphBuffer.hasVerticalOffsets()); | |
| 97 EXPECT_EQ(3u, glyphBuffer.size()); | 110 EXPECT_EQ(3u, glyphBuffer.size()); |
| 98 | 111 |
| 99 EXPECT_EQ(10, glyphBuffer.advanceAt(0)); | 112 EXPECT_EQ(10, glyphBuffer.xOffsetAt(0)); |
| 100 EXPECT_EQ(15, glyphBuffer.advanceAt(1)); | 113 EXPECT_EQ(15, glyphBuffer.xOffsetAt(1)); |
| 101 EXPECT_EQ(20, glyphBuffer.advanceAt(2)); | 114 EXPECT_EQ(20, glyphBuffer.xOffsetAt(2)); |
| 102 | 115 |
| 103 const float* advances = glyphBuffer.advances(0); | 116 const float* offsets = glyphBuffer.offsets(0); |
| 104 EXPECT_EQ(10, advances[0]); | 117 EXPECT_EQ(10, offsets[0]); |
| 105 EXPECT_EQ(15, advances[1]); | 118 EXPECT_EQ(15, offsets[1]); |
| 106 EXPECT_EQ(20, advances[2]); | 119 EXPECT_EQ(20, offsets[2]); |
| 107 } | 120 } |
| 108 | 121 |
| 109 TEST(GlyphBufferTest, StoresSimpleFontData) | 122 TEST(GlyphBufferTest, StoresSimpleFontData) |
| 110 { | 123 { |
| 111 RefPtr<SimpleFontData> font1 = TestSimpleFontData::create(); | 124 RefPtr<SimpleFontData> font1 = TestSimpleFontData::create(); |
| 112 RefPtr<SimpleFontData> font2 = TestSimpleFontData::create(); | 125 RefPtr<SimpleFontData> font2 = TestSimpleFontData::create(); |
| 113 | 126 |
| 114 GlyphBuffer glyphBuffer; | 127 GlyphBuffer glyphBuffer; |
| 115 glyphBuffer.add(42, font1.get(), 10); | 128 glyphBuffer.add(42, font1.get(), 10); |
| 116 glyphBuffer.add(43, font1.get(), 15); | 129 glyphBuffer.add(43, font1.get(), 15); |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 135 glyphBuffer.add(44, font2.get(), 12); | 148 glyphBuffer.add(44, font2.get(), 12); |
| 136 | 149 |
| 137 EXPECT_FALSE(glyphBuffer.isEmpty()); | 150 EXPECT_FALSE(glyphBuffer.isEmpty()); |
| 138 EXPECT_EQ(3u, glyphBuffer.size()); | 151 EXPECT_EQ(3u, glyphBuffer.size()); |
| 139 | 152 |
| 140 const Glyph* glyphs = glyphBuffer.glyphs(1); | 153 const Glyph* glyphs = glyphBuffer.glyphs(1); |
| 141 EXPECT_EQ(43, glyphs[0]); | 154 EXPECT_EQ(43, glyphs[0]); |
| 142 EXPECT_EQ(44, glyphs[1]); | 155 EXPECT_EQ(44, glyphs[1]); |
| 143 } | 156 } |
| 144 | 157 |
| 145 TEST(GlyphBufferTest, AdvanceArrayWithOffset) | 158 TEST(GlyphBufferTest, OffsetArrayWithNonZeroIndex) |
| 146 { | 159 { |
| 147 RefPtr<SimpleFontData> font1 = TestSimpleFontData::create(); | 160 RefPtr<SimpleFontData> font1 = TestSimpleFontData::create(); |
| 148 RefPtr<SimpleFontData> font2 = TestSimpleFontData::create(); | 161 RefPtr<SimpleFontData> font2 = TestSimpleFontData::create(); |
| 149 | 162 |
| 150 GlyphBuffer glyphBuffer; | 163 { |
| 151 glyphBuffer.add(42, font1.get(), 10); | 164 GlyphBuffer glyphBuffer; |
| 152 glyphBuffer.add(43, font1.get(), 15); | 165 glyphBuffer.add(42, font1.get(), 10); |
| 153 glyphBuffer.add(43, font1.get(), 12); | 166 glyphBuffer.add(43, font1.get(), 15); |
| 167 glyphBuffer.add(43, font2.get(), 12); | |
| 154 | 168 |
| 155 EXPECT_FALSE(glyphBuffer.isEmpty()); | 169 EXPECT_FALSE(glyphBuffer.isEmpty()); |
| 156 EXPECT_EQ(3u, glyphBuffer.size()); | 170 EXPECT_FALSE(glyphBuffer.hasVerticalOffsets()); |
| 171 EXPECT_EQ(3u, glyphBuffer.size()); | |
| 157 | 172 |
| 158 const float* advances = glyphBuffer.advances(1); | 173 const float* offsets = glyphBuffer.offsets(1); |
| 159 EXPECT_EQ(15, advances[0]); | 174 EXPECT_EQ(15, offsets[0]); |
| 160 EXPECT_EQ(12, advances[1]); | 175 EXPECT_EQ(12, offsets[1]); |
| 176 } | |
| 177 | |
| 178 { | |
| 179 GlyphBuffer glyphBuffer; | |
| 180 glyphBuffer.add(42, font1.get(), FloatPoint(10, 0)); | |
| 181 glyphBuffer.add(43, font1.get(), FloatPoint(15, 0)); | |
| 182 glyphBuffer.add(43, font2.get(), FloatPoint(12, 2)); | |
| 183 | |
| 184 EXPECT_FALSE(glyphBuffer.isEmpty()); | |
| 185 EXPECT_TRUE(glyphBuffer.hasVerticalOffsets()); | |
| 186 EXPECT_EQ(3u, glyphBuffer.size()); | |
| 187 | |
| 188 const float* offsets = glyphBuffer.offsets(1); | |
| 189 EXPECT_EQ(15, offsets[0]); | |
| 190 EXPECT_EQ(0, offsets[1]); | |
| 191 EXPECT_EQ(12, offsets[2]); | |
| 192 EXPECT_EQ(2, offsets[3]); | |
| 193 } | |
| 161 } | 194 } |
| 162 | 195 |
| 163 TEST(GlyphBufferTest, Reverse) | 196 TEST(GlyphBufferTest, Reverse) |
|
jbroman
2014/10/29 19:05:36
nit: ReverseForSimpleRTL, since you've renamed the
f(malita)
2014/10/30 15:53:10
Done.
| |
| 164 { | 197 { |
| 165 RefPtr<SimpleFontData> font1 = TestSimpleFontData::create(); | 198 RefPtr<SimpleFontData> font1 = TestSimpleFontData::create(); |
| 166 RefPtr<SimpleFontData> font2 = TestSimpleFontData::create(); | 199 RefPtr<SimpleFontData> font2 = TestSimpleFontData::create(); |
| 167 | 200 |
| 168 GlyphBuffer glyphBuffer; | 201 GlyphBuffer glyphBuffer; |
| 169 glyphBuffer.add(42, font1.get(), 10); | 202 glyphBuffer.add(42, font1.get(), 10); |
| 170 glyphBuffer.add(43, font1.get(), 15); | 203 glyphBuffer.add(43, font1.get(), 15); |
| 171 glyphBuffer.add(44, font2.get(), 20); | 204 glyphBuffer.add(44, font2.get(), 25); |
| 172 | 205 |
| 173 EXPECT_FALSE(glyphBuffer.isEmpty()); | 206 EXPECT_FALSE(glyphBuffer.isEmpty()); |
| 174 EXPECT_EQ(3u, glyphBuffer.size()); | 207 EXPECT_EQ(3u, glyphBuffer.size()); |
| 175 | 208 |
| 176 glyphBuffer.reverse(); | 209 glyphBuffer.reverseForSimpleRTL(30, 100); |
| 177 | 210 |
| 178 EXPECT_FALSE(glyphBuffer.isEmpty()); | 211 EXPECT_FALSE(glyphBuffer.isEmpty()); |
| 179 EXPECT_EQ(3u, glyphBuffer.size()); | 212 EXPECT_EQ(3u, glyphBuffer.size()); |
| 180 EXPECT_EQ(44, glyphBuffer.glyphAt(0)); | 213 EXPECT_EQ(44, glyphBuffer.glyphAt(0)); |
| 181 EXPECT_EQ(43, glyphBuffer.glyphAt(1)); | 214 EXPECT_EQ(43, glyphBuffer.glyphAt(1)); |
| 182 EXPECT_EQ(42, glyphBuffer.glyphAt(2)); | 215 EXPECT_EQ(42, glyphBuffer.glyphAt(2)); |
| 183 EXPECT_EQ(20, glyphBuffer.advanceAt(0)); | |
| 184 EXPECT_EQ(15, glyphBuffer.advanceAt(1)); | |
| 185 EXPECT_EQ(10, glyphBuffer.advanceAt(2)); | |
| 186 EXPECT_EQ(font2.get(), glyphBuffer.fontDataAt(0)); | 216 EXPECT_EQ(font2.get(), glyphBuffer.fontDataAt(0)); |
| 187 EXPECT_EQ(font1.get(), glyphBuffer.fontDataAt(1)); | 217 EXPECT_EQ(font1.get(), glyphBuffer.fontDataAt(1)); |
| 188 EXPECT_EQ(font1.get(), glyphBuffer.fontDataAt(2)); | 218 EXPECT_EQ(font1.get(), glyphBuffer.fontDataAt(2)); |
| 189 } | 219 EXPECT_EQ(70, glyphBuffer.xOffsetAt(0)); |
| 190 | 220 EXPECT_EQ(75, glyphBuffer.xOffsetAt(1)); |
| 191 TEST(GlyphBufferTest, ExpandLastAdvance) | 221 EXPECT_EQ(85, glyphBuffer.xOffsetAt(2)); |
| 192 { | |
| 193 RefPtr<SimpleFontData> font1 = TestSimpleFontData::create(); | |
| 194 RefPtr<SimpleFontData> font2 = TestSimpleFontData::create(); | |
| 195 | |
| 196 GlyphBuffer glyphBuffer; | |
| 197 glyphBuffer.add(42, font1.get(), 10); | |
| 198 glyphBuffer.add(43, font1.get(), 15); | |
| 199 glyphBuffer.add(44, font2.get(), 12); | |
| 200 | |
| 201 glyphBuffer.expandLastAdvance(20); | |
| 202 EXPECT_EQ(32, glyphBuffer.advanceAt(2)); | |
| 203 } | 222 } |
| 204 | 223 |
| 205 } // namespace | 224 } // namespace |
| OLD | NEW |