| 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(), FloatSize(12, 2)); | 50 glyphBuffer.add(44, font2.get(), 12); |
| 51 | 51 |
| 52 EXPECT_FALSE(glyphBuffer.isEmpty()); | 52 EXPECT_FALSE(glyphBuffer.isEmpty()); |
| 53 EXPECT_EQ(3u, glyphBuffer.size()); | 53 EXPECT_EQ(3u, glyphBuffer.size()); |
| 54 | 54 |
| 55 EXPECT_EQ(42, glyphBuffer.glyphAt(0)); | 55 EXPECT_EQ(42, glyphBuffer.glyphAt(0)); |
| 56 EXPECT_EQ(43, glyphBuffer.glyphAt(1)); | 56 EXPECT_EQ(43, glyphBuffer.glyphAt(1)); |
| 57 EXPECT_EQ(44, glyphBuffer.glyphAt(2)); | 57 EXPECT_EQ(44, glyphBuffer.glyphAt(2)); |
| 58 | 58 |
| 59 const Glyph* glyphs = glyphBuffer.glyphs(0); | 59 const Glyph* glyphs = glyphBuffer.glyphs(0); |
| 60 EXPECT_EQ(42, glyphs[0]); | 60 EXPECT_EQ(42, glyphs[0]); |
| 61 EXPECT_EQ(43, glyphs[1]); | 61 EXPECT_EQ(43, glyphs[1]); |
| 62 EXPECT_EQ(44, glyphs[2]); | 62 EXPECT_EQ(44, glyphs[2]); |
| 63 } | 63 } |
| 64 | 64 |
| 65 TEST(GlyphBufferTest, StoresOffsets) |
| 66 { |
| 67 RefPtr<SimpleFontData> font1 = TestSimpleFontData::create(); |
| 68 RefPtr<SimpleFontData> font2 = TestSimpleFontData::create(); |
| 69 |
| 70 GlyphBufferWithOffsets glyphBuffer; |
| 71 glyphBuffer.add(42, font1.get(), FloatSize(10, 0), 0); |
| 72 glyphBuffer.add(43, font1.get(), FloatSize(15, 0), 0); |
| 73 glyphBuffer.add(44, font2.get(), FloatSize(12, 2), 0); |
| 74 |
| 75 EXPECT_FALSE(glyphBuffer.isEmpty()); |
| 76 EXPECT_EQ(3u, glyphBuffer.size()); |
| 77 |
| 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); |
| 83 EXPECT_EQ(FloatSize(10, 0), offsets[0]); |
| 84 EXPECT_EQ(FloatSize(15, 0), offsets[1]); |
| 85 EXPECT_EQ(FloatSize(12, 2), offsets[2]); |
| 86 } |
| 87 |
| 65 TEST(GlyphBufferTest, StoresAdvances) | 88 TEST(GlyphBufferTest, StoresAdvances) |
| 66 { | 89 { |
| 67 RefPtr<SimpleFontData> font1 = TestSimpleFontData::create(); | 90 RefPtr<SimpleFontData> font1 = TestSimpleFontData::create(); |
| 68 RefPtr<SimpleFontData> font2 = TestSimpleFontData::create(); | 91 RefPtr<SimpleFontData> font2 = TestSimpleFontData::create(); |
| 69 | 92 |
| 70 GlyphBuffer glyphBuffer; | 93 GlyphBuffer glyphBuffer; |
| 71 glyphBuffer.add(42, font1.get(), 10); | 94 glyphBuffer.add(42, font1.get(), 10); |
| 72 glyphBuffer.add(43, font1.get(), 15); | 95 glyphBuffer.add(43, font1.get(), 15); |
| 73 glyphBuffer.add(44, font2.get(), FloatSize(12, 2)); | 96 glyphBuffer.add(44, font2.get(), 20); |
| 74 | 97 |
| 75 EXPECT_FALSE(glyphBuffer.isEmpty()); | 98 EXPECT_FALSE(glyphBuffer.isEmpty()); |
| 76 EXPECT_EQ(3u, glyphBuffer.size()); | 99 EXPECT_EQ(3u, glyphBuffer.size()); |
| 77 | 100 |
| 78 EXPECT_EQ(FloatSize(10, 0), glyphBuffer.advanceAt(0)); | 101 EXPECT_EQ(10, glyphBuffer.advanceAt(0)); |
| 79 EXPECT_EQ(FloatSize(15, 0), glyphBuffer.advanceAt(1)); | 102 EXPECT_EQ(15, glyphBuffer.advanceAt(1)); |
| 80 EXPECT_EQ(FloatSize(12, 2), glyphBuffer.advanceAt(2)); | 103 EXPECT_EQ(20, glyphBuffer.advanceAt(2)); |
| 81 | 104 |
| 82 const FloatSize* advances = glyphBuffer.advances(0); | 105 const float* advances = glyphBuffer.advances(0); |
| 83 EXPECT_EQ(FloatSize(10, 0), advances[0]); | 106 EXPECT_EQ(10, advances[0]); |
| 84 EXPECT_EQ(FloatSize(15, 0), advances[1]); | 107 EXPECT_EQ(15, advances[1]); |
| 85 EXPECT_EQ(FloatSize(12, 2), advances[2]); | 108 EXPECT_EQ(20, advances[2]); |
| 86 } | 109 } |
| 87 | 110 |
| 88 TEST(GlyphBufferTest, StoresSimpleFontData) | 111 TEST(GlyphBufferTest, StoresSimpleFontData) |
| 89 { | 112 { |
| 90 RefPtr<SimpleFontData> font1 = TestSimpleFontData::create(); | 113 RefPtr<SimpleFontData> font1 = TestSimpleFontData::create(); |
| 91 RefPtr<SimpleFontData> font2 = TestSimpleFontData::create(); | 114 RefPtr<SimpleFontData> font2 = TestSimpleFontData::create(); |
| 92 | 115 |
| 93 GlyphBuffer glyphBuffer; | 116 GlyphBuffer glyphBuffer; |
| 94 glyphBuffer.add(42, font1.get(), 10); | 117 glyphBuffer.add(42, font1.get(), 10); |
| 95 glyphBuffer.add(43, font1.get(), 15); | 118 glyphBuffer.add(43, font1.get(), 15); |
| 96 glyphBuffer.add(44, font2.get(), FloatSize(12, 2)); | 119 glyphBuffer.add(44, font2.get(), 12); |
| 97 | 120 |
| 98 EXPECT_FALSE(glyphBuffer.isEmpty()); | 121 EXPECT_FALSE(glyphBuffer.isEmpty()); |
| 99 EXPECT_EQ(3u, glyphBuffer.size()); | 122 EXPECT_EQ(3u, glyphBuffer.size()); |
| 100 | 123 |
| 101 EXPECT_EQ(font1.get(), glyphBuffer.fontDataAt(0)); | 124 EXPECT_EQ(font1.get(), glyphBuffer.fontDataAt(0)); |
| 102 EXPECT_EQ(font1.get(), glyphBuffer.fontDataAt(1)); | 125 EXPECT_EQ(font1.get(), glyphBuffer.fontDataAt(1)); |
| 103 EXPECT_EQ(font2.get(), glyphBuffer.fontDataAt(2)); | 126 EXPECT_EQ(font2.get(), glyphBuffer.fontDataAt(2)); |
| 104 } | 127 } |
| 105 | 128 |
| 106 TEST(GlyphBufferTest, GlyphArrayWithOffset) | 129 TEST(GlyphBufferTest, GlyphArrayWithOffset) |
| 107 { | 130 { |
| 108 RefPtr<SimpleFontData> font1 = TestSimpleFontData::create(); | 131 RefPtr<SimpleFontData> font1 = TestSimpleFontData::create(); |
| 109 RefPtr<SimpleFontData> font2 = TestSimpleFontData::create(); | 132 RefPtr<SimpleFontData> font2 = TestSimpleFontData::create(); |
| 110 | 133 |
| 111 GlyphBuffer glyphBuffer; | 134 GlyphBuffer glyphBuffer; |
| 112 glyphBuffer.add(42, font1.get(), 10); | 135 glyphBuffer.add(42, font1.get(), 10); |
| 113 glyphBuffer.add(43, font1.get(), 15); | 136 glyphBuffer.add(43, font1.get(), 15); |
| 114 glyphBuffer.add(44, font2.get(), FloatSize(12, 2)); | 137 glyphBuffer.add(44, font2.get(), 12); |
| 115 | 138 |
| 116 EXPECT_FALSE(glyphBuffer.isEmpty()); | 139 EXPECT_FALSE(glyphBuffer.isEmpty()); |
| 117 EXPECT_EQ(3u, glyphBuffer.size()); | 140 EXPECT_EQ(3u, glyphBuffer.size()); |
| 118 | 141 |
| 119 const Glyph* glyphs = glyphBuffer.glyphs(1); | 142 const Glyph* glyphs = glyphBuffer.glyphs(1); |
| 120 EXPECT_EQ(43, glyphs[0]); | 143 EXPECT_EQ(43, glyphs[0]); |
| 121 EXPECT_EQ(44, glyphs[1]); | 144 EXPECT_EQ(44, glyphs[1]); |
| 122 } | 145 } |
| 123 | 146 |
| 124 TEST(GlyphBufferTest, AdvanceArrayWithOffset) | 147 TEST(GlyphBufferTest, AdvanceArrayWithOffset) |
| 125 { | 148 { |
| 126 RefPtr<SimpleFontData> font1 = TestSimpleFontData::create(); | 149 RefPtr<SimpleFontData> font1 = TestSimpleFontData::create(); |
| 127 RefPtr<SimpleFontData> font2 = TestSimpleFontData::create(); | 150 RefPtr<SimpleFontData> font2 = TestSimpleFontData::create(); |
| 128 | 151 |
| 129 GlyphBuffer glyphBuffer; | 152 GlyphBuffer glyphBuffer; |
| 130 glyphBuffer.add(42, font1.get(), 10); | 153 glyphBuffer.add(42, font1.get(), 10); |
| 131 glyphBuffer.add(43, font1.get(), 15); | 154 glyphBuffer.add(43, font1.get(), 15); |
| 132 glyphBuffer.add(44, font2.get(), FloatSize(12, 2)); | 155 glyphBuffer.add(43, font1.get(), 12); |
| 133 | 156 |
| 134 EXPECT_FALSE(glyphBuffer.isEmpty()); | 157 EXPECT_FALSE(glyphBuffer.isEmpty()); |
| 135 EXPECT_EQ(3u, glyphBuffer.size()); | 158 EXPECT_EQ(3u, glyphBuffer.size()); |
| 136 | 159 |
| 137 const FloatSize* advances = glyphBuffer.advances(1); | 160 const float* advances = glyphBuffer.advances(1); |
| 138 EXPECT_EQ(FloatSize(15, 0), advances[0]); | 161 EXPECT_EQ(15, advances[0]); |
| 139 EXPECT_EQ(FloatSize(12, 2), advances[1]); | 162 EXPECT_EQ(12, advances[1]); |
| 140 } | 163 } |
| 141 | 164 |
| 142 TEST(GlyphBufferTest, Clear) | 165 TEST(GlyphBufferTest, Clear) |
| 143 { | 166 { |
| 144 RefPtr<SimpleFontData> font1 = TestSimpleFontData::create(); | 167 RefPtr<SimpleFontData> font1 = TestSimpleFontData::create(); |
| 145 RefPtr<SimpleFontData> font2 = TestSimpleFontData::create(); | 168 RefPtr<SimpleFontData> font2 = TestSimpleFontData::create(); |
| 146 | 169 |
| 147 GlyphBuffer glyphBuffer; | 170 GlyphBuffer glyphBuffer; |
| 148 glyphBuffer.add(42, font1.get(), 10); | 171 glyphBuffer.add(42, font1.get(), 10); |
| 149 glyphBuffer.add(43, font1.get(), 15); | 172 glyphBuffer.add(43, font1.get(), 15); |
| 150 glyphBuffer.add(44, font2.get(), FloatSize(12, 2)); | 173 glyphBuffer.add(44, font2.get(), 12); |
| 151 | 174 |
| 152 EXPECT_FALSE(glyphBuffer.isEmpty()); | 175 EXPECT_FALSE(glyphBuffer.isEmpty()); |
| 153 EXPECT_EQ(3u, glyphBuffer.size()); | 176 EXPECT_EQ(3u, glyphBuffer.size()); |
| 154 | 177 |
| 155 glyphBuffer.clear(); | 178 glyphBuffer.clear(); |
| 156 | 179 |
| 157 EXPECT_TRUE(glyphBuffer.isEmpty()); | 180 EXPECT_TRUE(glyphBuffer.isEmpty()); |
| 158 EXPECT_EQ(0u, glyphBuffer.size()); | 181 EXPECT_EQ(0u, glyphBuffer.size()); |
| 159 } | 182 } |
| 160 | 183 |
| 161 TEST(GlyphBufferTest, TracksVerticalAdvances) | |
| 162 { | |
| 163 RefPtr<SimpleFontData> font = TestSimpleFontData::create(); | |
| 164 GlyphBuffer glyphBuffer; | |
| 165 EXPECT_FALSE(glyphBuffer.hasVerticalAdvances()); | |
| 166 glyphBuffer.add(42, font.get(), 10); | |
| 167 EXPECT_FALSE(glyphBuffer.hasVerticalAdvances()); | |
| 168 glyphBuffer.add(43, font.get(), FloatSize(15, 0)); | |
| 169 EXPECT_FALSE(glyphBuffer.hasVerticalAdvances()); | |
| 170 glyphBuffer.add(44, font.get(), FloatSize(10, 5)); | |
| 171 EXPECT_TRUE(glyphBuffer.hasVerticalAdvances()); | |
| 172 glyphBuffer.clear(); | |
| 173 EXPECT_FALSE(glyphBuffer.hasVerticalAdvances()); | |
| 174 } | |
| 175 | |
| 176 TEST(GlyphBufferTest, Reverse) | 184 TEST(GlyphBufferTest, Reverse) |
| 177 { | 185 { |
| 178 RefPtr<SimpleFontData> font1 = TestSimpleFontData::create(); | 186 RefPtr<SimpleFontData> font1 = TestSimpleFontData::create(); |
| 179 RefPtr<SimpleFontData> font2 = TestSimpleFontData::create(); | 187 RefPtr<SimpleFontData> font2 = TestSimpleFontData::create(); |
| 180 | 188 |
| 181 GlyphBuffer glyphBuffer; | 189 GlyphBuffer glyphBuffer; |
| 182 glyphBuffer.add(42, font1.get(), 10); | 190 glyphBuffer.add(42, font1.get(), 10); |
| 183 glyphBuffer.add(43, font1.get(), 15); | 191 glyphBuffer.add(43, font1.get(), 15); |
| 184 glyphBuffer.add(44, font2.get(), FloatSize(12, 2)); | 192 glyphBuffer.add(44, font2.get(), 20); |
| 185 | 193 |
| 186 EXPECT_FALSE(glyphBuffer.isEmpty()); | 194 EXPECT_FALSE(glyphBuffer.isEmpty()); |
| 187 EXPECT_EQ(3u, glyphBuffer.size()); | 195 EXPECT_EQ(3u, glyphBuffer.size()); |
| 188 EXPECT_TRUE(glyphBuffer.hasVerticalAdvances()); | |
| 189 | 196 |
| 190 glyphBuffer.reverse(); | 197 glyphBuffer.reverse(); |
| 191 | 198 |
| 192 EXPECT_FALSE(glyphBuffer.isEmpty()); | 199 EXPECT_FALSE(glyphBuffer.isEmpty()); |
| 193 EXPECT_EQ(3u, glyphBuffer.size()); | 200 EXPECT_EQ(3u, glyphBuffer.size()); |
| 194 EXPECT_TRUE(glyphBuffer.hasVerticalAdvances()); | |
| 195 EXPECT_EQ(44, glyphBuffer.glyphAt(0)); | 201 EXPECT_EQ(44, glyphBuffer.glyphAt(0)); |
| 196 EXPECT_EQ(43, glyphBuffer.glyphAt(1)); | 202 EXPECT_EQ(43, glyphBuffer.glyphAt(1)); |
| 197 EXPECT_EQ(42, glyphBuffer.glyphAt(2)); | 203 EXPECT_EQ(42, glyphBuffer.glyphAt(2)); |
| 198 EXPECT_EQ(FloatSize(12, 2), glyphBuffer.advanceAt(0)); | 204 EXPECT_EQ(20, glyphBuffer.advanceAt(0)); |
| 199 EXPECT_EQ(FloatSize(15, 0), glyphBuffer.advanceAt(1)); | 205 EXPECT_EQ(15, glyphBuffer.advanceAt(1)); |
| 200 EXPECT_EQ(FloatSize(10, 0), glyphBuffer.advanceAt(2)); | 206 EXPECT_EQ(10, glyphBuffer.advanceAt(2)); |
| 201 EXPECT_EQ(font2.get(), glyphBuffer.fontDataAt(0)); | 207 EXPECT_EQ(font2.get(), glyphBuffer.fontDataAt(0)); |
| 202 EXPECT_EQ(font1.get(), glyphBuffer.fontDataAt(1)); | 208 EXPECT_EQ(font1.get(), glyphBuffer.fontDataAt(1)); |
| 203 EXPECT_EQ(font1.get(), glyphBuffer.fontDataAt(2)); | 209 EXPECT_EQ(font1.get(), glyphBuffer.fontDataAt(2)); |
| 204 } | 210 } |
| 205 | 211 |
| 206 TEST(GlyphBufferTest, SetAdvanceWidth) | |
| 207 { | |
| 208 RefPtr<SimpleFontData> font1 = TestSimpleFontData::create(); | |
| 209 RefPtr<SimpleFontData> font2 = TestSimpleFontData::create(); | |
| 210 | |
| 211 GlyphBuffer glyphBuffer; | |
| 212 glyphBuffer.add(42, font1.get(), 10); | |
| 213 glyphBuffer.add(43, font1.get(), 15); | |
| 214 glyphBuffer.add(44, font2.get(), FloatSize(12, 2)); | |
| 215 | |
| 216 glyphBuffer.setAdvanceWidth(1, 20); | |
| 217 EXPECT_EQ(FloatSize(20, 0), glyphBuffer.advanceAt(1)); | |
| 218 | |
| 219 glyphBuffer.setAdvanceWidth(2, 10); | |
| 220 EXPECT_EQ(FloatSize(10, 2), glyphBuffer.advanceAt(2)); | |
| 221 } | |
| 222 | |
| 223 TEST(GlyphBufferTest, ExpandLastAdvance) | 212 TEST(GlyphBufferTest, ExpandLastAdvance) |
| 224 { | 213 { |
| 225 RefPtr<SimpleFontData> font1 = TestSimpleFontData::create(); | 214 RefPtr<SimpleFontData> font1 = TestSimpleFontData::create(); |
| 226 RefPtr<SimpleFontData> font2 = TestSimpleFontData::create(); | 215 RefPtr<SimpleFontData> font2 = TestSimpleFontData::create(); |
| 227 | 216 |
| 228 GlyphBuffer glyphBuffer; | 217 GlyphBuffer glyphBuffer; |
| 229 glyphBuffer.add(42, font1.get(), 10); | 218 glyphBuffer.add(42, font1.get(), 10); |
| 230 glyphBuffer.add(43, font1.get(), 15); | 219 glyphBuffer.add(43, font1.get(), 15); |
| 231 glyphBuffer.add(44, font2.get(), FloatSize(12, 2)); | 220 glyphBuffer.add(44, font2.get(), 12); |
| 232 | 221 |
| 233 glyphBuffer.expandLastAdvance(20); | 222 glyphBuffer.expandLastAdvance(20); |
| 234 EXPECT_EQ(FloatSize(32, 2), glyphBuffer.advanceAt(2)); | 223 EXPECT_EQ(32, glyphBuffer.advanceAt(2)); |
| 235 } | 224 } |
| 236 | 225 |
| 237 } // namespace | 226 } // namespace |
| OLD | NEW |