| 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/HarfBuzzShaper.h" | 5 #include "platform/fonts/shaping/HarfBuzzShaper.h" |
| 6 | 6 |
| 7 #include <unicode/uscript.h> | 7 #include <unicode/uscript.h> |
| 8 #include "platform/fonts/Font.h" | 8 #include "platform/fonts/Font.h" |
| 9 #include "platform/fonts/FontCache.h" | 9 #include "platform/fonts/FontCache.h" |
| 10 #include "platform/fonts/shaping/ShapeResultInlineHeaders.h" | 10 #include "platform/fonts/shaping/ShapeResultInlineHeaders.h" |
| (...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 301 UChar arabic_string[] = {0x628, 0x64A, 0x629}; | 301 UChar arabic_string[] = {0x628, 0x64A, 0x629}; |
| 302 TextDirection direction = TextDirection::kRtl; | 302 TextDirection direction = TextDirection::kRtl; |
| 303 | 303 |
| 304 HarfBuzzShaper shaper(arabic_string, 3); | 304 HarfBuzzShaper shaper(arabic_string, 3); |
| 305 RefPtr<ShapeResult> result = shaper.Shape(&font, direction); | 305 RefPtr<ShapeResult> result = shaper.Shape(&font, direction); |
| 306 | 306 |
| 307 EXPECT_EQ(0.0f, result->PositionForOffset(3)); | 307 EXPECT_EQ(0.0f, result->PositionForOffset(3)); |
| 308 ASSERT_NEAR(result->Width(), result->PositionForOffset(0), 0.1); | 308 ASSERT_NEAR(result->Width(), result->PositionForOffset(0), 0.1); |
| 309 } | 309 } |
| 310 | 310 |
| 311 TEST_F(HarfBuzzShaperTest, OffsetForPositionMatchesPositionForOffsetLatin) { | 311 // A Value-Parameterized Test class to test OffsetForPosition() with |
| 312 // |include_partial_glyphs| parameter. |
| 313 class WithIncludePartialGlyphs : public HarfBuzzShaperTest, |
| 314 public ::testing::WithParamInterface<bool> {}; |
| 315 |
| 316 INSTANTIATE_TEST_CASE_P(OffsetForPositionTest, |
| 317 WithIncludePartialGlyphs, |
| 318 ::testing::Bool()); |
| 319 |
| 320 TEST_P(WithIncludePartialGlyphs, |
| 321 OffsetForPositionMatchesPositionForOffsetLatin) { |
| 312 String string = To16Bit("Hello World!", 12); | 322 String string = To16Bit("Hello World!", 12); |
| 313 TextDirection direction = TextDirection::kLtr; | 323 TextDirection direction = TextDirection::kLtr; |
| 314 | 324 |
| 315 HarfBuzzShaper shaper(string.Characters16(), 12); | 325 HarfBuzzShaper shaper(string.Characters16(), 12); |
| 316 RefPtr<ShapeResult> result = shaper.Shape(&font, direction); | 326 RefPtr<ShapeResult> result = shaper.Shape(&font, direction); |
| 317 | 327 |
| 318 // Last argument is includePartialGlyphs | 328 bool include_partial_glyphs = GetParam(); |
| 319 EXPECT_EQ(0u, result->OffsetForPosition(result->PositionForOffset(0), true)); | 329 EXPECT_EQ(0u, result->OffsetForPosition(result->PositionForOffset(0), |
| 320 EXPECT_EQ(1u, result->OffsetForPosition(result->PositionForOffset(1), true)); | 330 include_partial_glyphs)); |
| 321 EXPECT_EQ(2u, result->OffsetForPosition(result->PositionForOffset(2), true)); | 331 EXPECT_EQ(1u, result->OffsetForPosition(result->PositionForOffset(1), |
| 322 EXPECT_EQ(3u, result->OffsetForPosition(result->PositionForOffset(3), true)); | 332 include_partial_glyphs)); |
| 323 EXPECT_EQ(4u, result->OffsetForPosition(result->PositionForOffset(4), true)); | 333 EXPECT_EQ(2u, result->OffsetForPosition(result->PositionForOffset(2), |
| 324 EXPECT_EQ(5u, result->OffsetForPosition(result->PositionForOffset(5), true)); | 334 include_partial_glyphs)); |
| 325 EXPECT_EQ(6u, result->OffsetForPosition(result->PositionForOffset(6), true)); | 335 EXPECT_EQ(3u, result->OffsetForPosition(result->PositionForOffset(3), |
| 326 EXPECT_EQ(7u, result->OffsetForPosition(result->PositionForOffset(7), true)); | 336 include_partial_glyphs)); |
| 327 EXPECT_EQ(8u, result->OffsetForPosition(result->PositionForOffset(8), true)); | 337 EXPECT_EQ(4u, result->OffsetForPosition(result->PositionForOffset(4), |
| 328 EXPECT_EQ(9u, result->OffsetForPosition(result->PositionForOffset(9), true)); | 338 include_partial_glyphs)); |
| 329 EXPECT_EQ(10u, | 339 EXPECT_EQ(5u, result->OffsetForPosition(result->PositionForOffset(5), |
| 330 result->OffsetForPosition(result->PositionForOffset(10), true)); | 340 include_partial_glyphs)); |
| 331 EXPECT_EQ(11u, | 341 EXPECT_EQ(6u, result->OffsetForPosition(result->PositionForOffset(6), |
| 332 result->OffsetForPosition(result->PositionForOffset(11), true)); | 342 include_partial_glyphs)); |
| 333 EXPECT_EQ(12u, | 343 EXPECT_EQ(7u, result->OffsetForPosition(result->PositionForOffset(7), |
| 334 result->OffsetForPosition(result->PositionForOffset(12), true)); | 344 include_partial_glyphs)); |
| 345 EXPECT_EQ(8u, result->OffsetForPosition(result->PositionForOffset(8), |
| 346 include_partial_glyphs)); |
| 347 EXPECT_EQ(9u, result->OffsetForPosition(result->PositionForOffset(9), |
| 348 include_partial_glyphs)); |
| 349 EXPECT_EQ(10u, result->OffsetForPosition(result->PositionForOffset(10), |
| 350 include_partial_glyphs)); |
| 351 EXPECT_EQ(11u, result->OffsetForPosition(result->PositionForOffset(11), |
| 352 include_partial_glyphs)); |
| 353 EXPECT_EQ(12u, result->OffsetForPosition(result->PositionForOffset(12), |
| 354 include_partial_glyphs)); |
| 335 } | 355 } |
| 336 | 356 |
| 337 TEST_F(HarfBuzzShaperTest, OffsetForPositionMatchesPositionForOffsetArabic) { | 357 TEST_P(WithIncludePartialGlyphs, |
| 358 OffsetForPositionMatchesPositionForOffsetArabic) { |
| 338 UChar arabic_string[] = {0x628, 0x64A, 0x629}; | 359 UChar arabic_string[] = {0x628, 0x64A, 0x629}; |
| 339 TextDirection direction = TextDirection::kRtl; | 360 TextDirection direction = TextDirection::kRtl; |
| 340 | 361 |
| 341 HarfBuzzShaper shaper(arabic_string, 3); | 362 HarfBuzzShaper shaper(arabic_string, 3); |
| 342 RefPtr<ShapeResult> result = shaper.Shape(&font, direction); | 363 RefPtr<ShapeResult> result = shaper.Shape(&font, direction); |
| 343 | 364 |
| 344 // Last argument is includePartialGlyphs | 365 bool include_partial_glyphs = GetParam(); |
| 345 EXPECT_EQ(0u, result->OffsetForPosition(result->PositionForOffset(0), true)); | 366 EXPECT_EQ(0u, result->OffsetForPosition(result->PositionForOffset(0), |
| 346 EXPECT_EQ(1u, result->OffsetForPosition(result->PositionForOffset(1), true)); | 367 include_partial_glyphs)); |
| 347 EXPECT_EQ(2u, result->OffsetForPosition(result->PositionForOffset(2), true)); | 368 EXPECT_EQ(1u, result->OffsetForPosition(result->PositionForOffset(1), |
| 348 EXPECT_EQ(3u, result->OffsetForPosition(result->PositionForOffset(3), true)); | 369 include_partial_glyphs)); |
| 370 EXPECT_EQ(2u, result->OffsetForPosition(result->PositionForOffset(2), |
| 371 include_partial_glyphs)); |
| 372 EXPECT_EQ(3u, result->OffsetForPosition(result->PositionForOffset(3), |
| 373 include_partial_glyphs)); |
| 349 } | 374 } |
| 350 | 375 |
| 351 TEST_F(HarfBuzzShaperTest, OffsetForPositionMatchesPositionForOffsetMixed) { | 376 TEST_P(WithIncludePartialGlyphs, |
| 377 OffsetForPositionMatchesPositionForOffsetMixed) { |
| 352 UChar mixed_string[] = {0x628, 0x64A, 0x629, 0xE20, 0x65E5, 0x62}; | 378 UChar mixed_string[] = {0x628, 0x64A, 0x629, 0xE20, 0x65E5, 0x62}; |
| 353 HarfBuzzShaper shaper(mixed_string, 6); | 379 HarfBuzzShaper shaper(mixed_string, 6); |
| 354 RefPtr<ShapeResult> result = shaper.Shape(&font, TextDirection::kLtr); | 380 RefPtr<ShapeResult> result = shaper.Shape(&font, TextDirection::kLtr); |
| 355 | 381 |
| 356 // Last argument is includePartialGlyphs | 382 bool include_partial_glyphs = GetParam(); |
| 357 EXPECT_EQ(0u, result->OffsetForPosition(result->PositionForOffset(0), true)); | 383 EXPECT_EQ(0u, result->OffsetForPosition(result->PositionForOffset(0), |
| 358 EXPECT_EQ(1u, result->OffsetForPosition(result->PositionForOffset(1), true)); | 384 include_partial_glyphs)); |
| 359 EXPECT_EQ(2u, result->OffsetForPosition(result->PositionForOffset(2), true)); | 385 EXPECT_EQ(1u, result->OffsetForPosition(result->PositionForOffset(1), |
| 360 EXPECT_EQ(3u, result->OffsetForPosition(result->PositionForOffset(3), true)); | 386 include_partial_glyphs)); |
| 361 EXPECT_EQ(4u, result->OffsetForPosition(result->PositionForOffset(4), true)); | 387 EXPECT_EQ(2u, result->OffsetForPosition(result->PositionForOffset(2), |
| 362 EXPECT_EQ(5u, result->OffsetForPosition(result->PositionForOffset(5), true)); | 388 include_partial_glyphs)); |
| 363 EXPECT_EQ(6u, result->OffsetForPosition(result->PositionForOffset(6), true)); | 389 EXPECT_EQ(3u, result->OffsetForPosition(result->PositionForOffset(3), |
| 390 include_partial_glyphs)); |
| 391 EXPECT_EQ(4u, result->OffsetForPosition(result->PositionForOffset(4), |
| 392 include_partial_glyphs)); |
| 393 EXPECT_EQ(5u, result->OffsetForPosition(result->PositionForOffset(5), |
| 394 include_partial_glyphs)); |
| 395 EXPECT_EQ(6u, result->OffsetForPosition(result->PositionForOffset(6), |
| 396 include_partial_glyphs)); |
| 364 } | 397 } |
| 365 | 398 |
| 366 TEST_F(HarfBuzzShaperTest, ShapeResultCopyRangeIntoLatin) { | 399 TEST_F(HarfBuzzShaperTest, ShapeResultCopyRangeIntoLatin) { |
| 367 String string = To16Bit("Testing ShapeResult::createSubRun", 33); | 400 String string = To16Bit("Testing ShapeResult::createSubRun", 33); |
| 368 TextDirection direction = TextDirection::kLtr; | 401 TextDirection direction = TextDirection::kLtr; |
| 369 | 402 |
| 370 HarfBuzzShaper shaper(string.Characters16(), 33); | 403 HarfBuzzShaper shaper(string.Characters16(), 33); |
| 371 RefPtr<ShapeResult> result = shaper.Shape(&font, direction); | 404 RefPtr<ShapeResult> result = shaper.Shape(&font, direction); |
| 372 | 405 |
| 373 RefPtr<ShapeResult> composite_result = | 406 RefPtr<ShapeResult> composite_result = |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 418 composite_result->SnappedStartPositionForOffset(5)); | 451 composite_result->SnappedStartPositionForOffset(5)); |
| 419 EXPECT_EQ(result->SnappedStartPositionForOffset(6), | 452 EXPECT_EQ(result->SnappedStartPositionForOffset(6), |
| 420 composite_result->SnappedStartPositionForOffset(6)); | 453 composite_result->SnappedStartPositionForOffset(6)); |
| 421 EXPECT_EQ(result->SnappedStartPositionForOffset(7), | 454 EXPECT_EQ(result->SnappedStartPositionForOffset(7), |
| 422 composite_result->SnappedStartPositionForOffset(7)); | 455 composite_result->SnappedStartPositionForOffset(7)); |
| 423 EXPECT_EQ(result->SnappedStartPositionForOffset(8), | 456 EXPECT_EQ(result->SnappedStartPositionForOffset(8), |
| 424 composite_result->SnappedStartPositionForOffset(8)); | 457 composite_result->SnappedStartPositionForOffset(8)); |
| 425 } | 458 } |
| 426 | 459 |
| 427 } // namespace blink | 460 } // namespace blink |
| OLD | NEW |