OLD | NEW |
1 // Copyright (c) 2014 The Chromium Authors. All rights reserved. | 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 | 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/CachingWordShaper.h" | 5 #include "platform/fonts/shaping/CachingWordShaper.h" |
6 | 6 |
7 #include "platform/fonts/FontCache.h" | 7 #include "platform/fonts/FontCache.h" |
8 #include "platform/fonts/GlyphBuffer.h" | 8 #include "platform/fonts/GlyphBuffer.h" |
9 #include "platform/fonts/shaping/CachingWordShapeIterator.h" | 9 #include "platform/fonts/shaping/CachingWordShapeIterator.h" |
10 #include "platform/fonts/shaping/ShapeResultTestInfo.h" | 10 #include "platform/fonts/shaping/ShapeResultTestInfo.h" |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
172 ASSERT_GT(shaper.width(&font, textRun, nullptr, &glyphBounds), 0); | 172 ASSERT_GT(shaper.width(&font, textRun, nullptr, &glyphBounds), 0); |
173 | 173 |
174 GlyphBuffer glyphBuffer; | 174 GlyphBuffer glyphBuffer; |
175 shaper.fillGlyphBuffer(&font, textRun, fallbackFonts, &glyphBuffer, 0, 8); | 175 shaper.fillGlyphBuffer(&font, textRun, fallbackFonts, &glyphBuffer, 0, 8); |
176 | 176 |
177 FloatPoint point; | 177 FloatPoint point; |
178 int height = 16; | 178 int height = 16; |
179 shaper.selectionRect(&font, textRun, point, height, 0, 8); | 179 shaper.selectionRect(&font, textRun, point, height, 0, 8); |
180 } | 180 } |
181 | 181 |
| 182 TEST_F(CachingWordShaperTest, SegmentCJKByCharacter) |
| 183 { |
| 184 const UChar str[] = { |
| 185 0x56FD, 0x56FD, // CJK Unified Ideograph |
| 186 'a', 'b', |
| 187 0x56FD, // CJK Unified Ideograph |
| 188 'x', 'y', 'z', |
| 189 0x3042, // HIRAGANA LETTER A |
| 190 0x56FD, // CJK Unified Ideograph |
| 191 0x0 |
| 192 }; |
| 193 TextRun textRun(str, 10); |
| 194 |
| 195 RefPtr<ShapeResult> wordResult; |
| 196 CachingWordShapeIterator iterator(cache.get(), textRun, &font); |
| 197 |
| 198 ASSERT_TRUE(iterator.next(&wordResult)); |
| 199 EXPECT_EQ(1u, wordResult->numCharacters()); |
| 200 ASSERT_TRUE(iterator.next(&wordResult)); |
| 201 EXPECT_EQ(1u, wordResult->numCharacters()); |
| 202 |
| 203 ASSERT_TRUE(iterator.next(&wordResult)); |
| 204 EXPECT_EQ(2u, wordResult->numCharacters()); |
| 205 |
| 206 ASSERT_TRUE(iterator.next(&wordResult)); |
| 207 EXPECT_EQ(1u, wordResult->numCharacters()); |
| 208 |
| 209 ASSERT_TRUE(iterator.next(&wordResult)); |
| 210 EXPECT_EQ(3u, wordResult->numCharacters()); |
| 211 |
| 212 ASSERT_TRUE(iterator.next(&wordResult)); |
| 213 EXPECT_EQ(1u, wordResult->numCharacters()); |
| 214 ASSERT_TRUE(iterator.next(&wordResult)); |
| 215 EXPECT_EQ(1u, wordResult->numCharacters()); |
| 216 |
| 217 ASSERT_FALSE(iterator.next(&wordResult)); |
| 218 } |
| 219 |
| 220 TEST_F(CachingWordShaperTest, SegmentCJKAndCommon) |
| 221 { |
| 222 const UChar str[] = { |
| 223 'a', 'b', |
| 224 0xFF08, // FULLWIDTH LEFT PARENTHESIS (script=common) |
| 225 0x56FD, // CJK Unified Ideograph |
| 226 0x56FD, // CJK Unified Ideograph |
| 227 0x56FD, // CJK Unified Ideograph |
| 228 0x3002, // IDEOGRAPHIC FULL STOP (script=common) |
| 229 0x0 |
| 230 }; |
| 231 TextRun textRun(str, 7); |
| 232 |
| 233 RefPtr<ShapeResult> wordResult; |
| 234 CachingWordShapeIterator iterator(cache.get(), textRun, &font); |
| 235 |
| 236 ASSERT_TRUE(iterator.next(&wordResult)); |
| 237 EXPECT_EQ(2u, wordResult->numCharacters()); |
| 238 |
| 239 ASSERT_TRUE(iterator.next(&wordResult)); |
| 240 EXPECT_EQ(2u, wordResult->numCharacters()); |
| 241 |
| 242 ASSERT_TRUE(iterator.next(&wordResult)); |
| 243 EXPECT_EQ(1u, wordResult->numCharacters()); |
| 244 |
| 245 ASSERT_TRUE(iterator.next(&wordResult)); |
| 246 EXPECT_EQ(2u, wordResult->numCharacters()); |
| 247 |
| 248 ASSERT_FALSE(iterator.next(&wordResult)); |
| 249 } |
| 250 |
| 251 TEST_F(CachingWordShaperTest, SegmentCJKAndInherit) |
| 252 { |
| 253 const UChar str[] = { |
| 254 0x304B, // HIRAGANA LETTER KA |
| 255 0x304B, // HIRAGANA LETTER KA |
| 256 0x3009, // COMBINING KATAKANA-HIRAGANA VOICED SOUND MARK |
| 257 0x304B, // HIRAGANA LETTER KA |
| 258 0x0 |
| 259 }; |
| 260 TextRun textRun(str, 4); |
| 261 |
| 262 RefPtr<ShapeResult> wordResult; |
| 263 CachingWordShapeIterator iterator(cache.get(), textRun, &font); |
| 264 |
| 265 ASSERT_TRUE(iterator.next(&wordResult)); |
| 266 EXPECT_EQ(1u, wordResult->numCharacters()); |
| 267 |
| 268 ASSERT_TRUE(iterator.next(&wordResult)); |
| 269 EXPECT_EQ(2u, wordResult->numCharacters()); |
| 270 |
| 271 ASSERT_TRUE(iterator.next(&wordResult)); |
| 272 EXPECT_EQ(1u, wordResult->numCharacters()); |
| 273 |
| 274 ASSERT_FALSE(iterator.next(&wordResult)); |
| 275 } |
| 276 |
| 277 TEST_F(CachingWordShaperTest, SegmentCJKAndNonCJKCommon) |
| 278 { |
| 279 const UChar str[] = { |
| 280 0x56FD, // CJK Unified Ideograph |
| 281 ' ', |
| 282 0x0 |
| 283 }; |
| 284 TextRun textRun(str, 2); |
| 285 |
| 286 RefPtr<ShapeResult> wordResult; |
| 287 CachingWordShapeIterator iterator(cache.get(), textRun, &font); |
| 288 |
| 289 ASSERT_TRUE(iterator.next(&wordResult)); |
| 290 EXPECT_EQ(1u, wordResult->numCharacters()); |
| 291 |
| 292 ASSERT_TRUE(iterator.next(&wordResult)); |
| 293 EXPECT_EQ(1u, wordResult->numCharacters()); |
| 294 |
| 295 ASSERT_FALSE(iterator.next(&wordResult)); |
| 296 } |
| 297 |
| 298 TEST_F(CachingWordShaperTest, SegmentCJKCommon) |
| 299 { |
| 300 const UChar str[] = { |
| 301 0xFF08, // FULLWIDTH LEFT PARENTHESIS (script=common) |
| 302 0xFF08, // FULLWIDTH LEFT PARENTHESIS (script=common) |
| 303 0xFF08, // FULLWIDTH LEFT PARENTHESIS (script=common) |
| 304 0x0 |
| 305 }; |
| 306 TextRun textRun(str, 3); |
| 307 |
| 308 RefPtr<ShapeResult> wordResult; |
| 309 CachingWordShapeIterator iterator(cache.get(), textRun, &font); |
| 310 |
| 311 ASSERT_TRUE(iterator.next(&wordResult)); |
| 312 EXPECT_EQ(3u, wordResult->numCharacters()); |
| 313 |
| 314 ASSERT_FALSE(iterator.next(&wordResult)); |
| 315 } |
| 316 |
| 317 TEST_F(CachingWordShaperTest, SegmentCJKCommonAndNonCJK) |
| 318 { |
| 319 const UChar str[] = { |
| 320 0xFF08, // FULLWIDTH LEFT PARENTHESIS (script=common) |
| 321 'a', 'b', |
| 322 0x0 |
| 323 }; |
| 324 TextRun textRun(str, 3); |
| 325 |
| 326 RefPtr<ShapeResult> wordResult; |
| 327 CachingWordShapeIterator iterator(cache.get(), textRun, &font); |
| 328 |
| 329 ASSERT_TRUE(iterator.next(&wordResult)); |
| 330 EXPECT_EQ(1u, wordResult->numCharacters()); |
| 331 |
| 332 ASSERT_TRUE(iterator.next(&wordResult)); |
| 333 EXPECT_EQ(2u, wordResult->numCharacters()); |
| 334 |
| 335 ASSERT_FALSE(iterator.next(&wordResult)); |
| 336 } |
| 337 |
182 TEST_F(CachingWordShaperTest, TextOrientationFallbackShouldNotInFallbackList) | 338 TEST_F(CachingWordShaperTest, TextOrientationFallbackShouldNotInFallbackList) |
183 { | 339 { |
184 const UChar str[] = { | 340 const UChar str[] = { |
185 'A', // code point for verticalRightOrientationFontData() | 341 'A', // code point for verticalRightOrientationFontData() |
186 // Ideally we'd like to test uprightOrientationFontData() too | 342 // Ideally we'd like to test uprightOrientationFontData() too |
187 // using code point such as U+3042, but it'd fallback to system | 343 // using code point such as U+3042, but it'd fallback to system |
188 // fonts as the glyph is missing. | 344 // fonts as the glyph is missing. |
189 0x0 | 345 0x0 |
190 }; | 346 }; |
191 TextRun textRun(str, 1); | 347 TextRun textRun(str, 1); |
(...skipping 23 matching lines...) Expand all Loading... |
215 float periodsAndSpacesWidth = shaper.width(&font, periodsAndSpaces, nullptr,
&periodsAndSpacesGlyphBounds); | 371 float periodsAndSpacesWidth = shaper.width(&font, periodsAndSpaces, nullptr,
&periodsAndSpacesGlyphBounds); |
216 | 372 |
217 // The total width of periods and spaces should be longer than the width of
periods alone. | 373 // The total width of periods and spaces should be longer than the width of
periods alone. |
218 ASSERT_GT(periodsAndSpacesWidth, periodsWidth); | 374 ASSERT_GT(periodsAndSpacesWidth, periodsWidth); |
219 | 375 |
220 // The glyph bounds of periods and spaces should be longer than the glyph bo
unds of periods alone. | 376 // The glyph bounds of periods and spaces should be longer than the glyph bo
unds of periods alone. |
221 ASSERT_GT(periodsAndSpacesGlyphBounds.width(), periodsGlyphBounds.width()); | 377 ASSERT_GT(periodsAndSpacesGlyphBounds.width(), periodsGlyphBounds.width()); |
222 } | 378 } |
223 | 379 |
224 } // namespace blink | 380 } // namespace blink |
OLD | NEW |