| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "ui/gfx/render_text.h" | 5 #include "ui/gfx/render_text.h" |
| 6 | 6 |
| 7 #include <limits.h> | 7 #include <limits.h> |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 #include <stdint.h> | 9 #include <stdint.h> |
| 10 | 10 |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 70 RenderTextHarfBuzz* render_text = | 70 RenderTextHarfBuzz* render_text = |
| 71 static_cast<RenderTextHarfBuzz*>(render_text_); | 71 static_cast<RenderTextHarfBuzz*>(render_text_); |
| 72 return render_text->GetRunList(); | 72 return render_text->GetRunList(); |
| 73 } | 73 } |
| 74 | 74 |
| 75 void DrawVisualText(internal::SkiaTextRenderer* renderer) { | 75 void DrawVisualText(internal::SkiaTextRenderer* renderer) { |
| 76 render_text_->EnsureLayout(); | 76 render_text_->EnsureLayout(); |
| 77 render_text_->DrawVisualText(renderer); | 77 render_text_->DrawVisualText(renderer); |
| 78 } | 78 } |
| 79 | 79 |
| 80 const BreakList<SkColor>& colors() const { return render_text_->colors(); } |
| 81 |
| 82 const BreakList<BaselineStyle>& baselines() const { |
| 83 return render_text_->baselines(); |
| 84 } |
| 85 |
| 86 const BreakList<Font::Weight>& weights() const { |
| 87 return render_text_->weights(); |
| 88 } |
| 89 |
| 90 const std::vector<BreakList<bool>>& styles() const { |
| 91 return render_text_->styles(); |
| 92 } |
| 93 |
| 94 const std::vector<internal::Line>& lines() const { |
| 95 return render_text_->lines(); |
| 96 } |
| 97 |
| 98 SelectionModel EdgeSelectionModel(VisualCursorDirection direction) { |
| 99 return render_text_->EdgeSelectionModel(direction); |
| 100 } |
| 101 |
| 102 size_t TextIndexToDisplayIndex(size_t index) { |
| 103 return render_text_->TextIndexToDisplayIndex(index); |
| 104 } |
| 105 |
| 106 size_t DisplayIndexToTextIndex(size_t index) { |
| 107 return render_text_->DisplayIndexToTextIndex(index); |
| 108 } |
| 109 |
| 110 void EnsureLayout() { render_text_->EnsureLayout(); } |
| 111 |
| 112 Vector2d GetAlignmentOffset(size_t line_number) { |
| 113 return render_text_->GetAlignmentOffset(line_number); |
| 114 } |
| 115 |
| 80 private: | 116 private: |
| 81 RenderText* render_text_; | 117 RenderText* render_text_; |
| 82 | 118 |
| 83 DISALLOW_COPY_AND_ASSIGN(RenderTextTestApi); | 119 DISALLOW_COPY_AND_ASSIGN(RenderTextTestApi); |
| 84 }; | 120 }; |
| 85 | 121 |
| 86 } // namespace test | 122 } // namespace test |
| 87 | 123 |
| 88 namespace { | 124 namespace { |
| 89 | 125 |
| (...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 340 | 376 |
| 341 #if defined(OS_MACOSX) | 377 #if defined(OS_MACOSX) |
| 342 RenderTextMac* GetRenderTextMac() { | 378 RenderTextMac* GetRenderTextMac() { |
| 343 DCHECK_EQ(RENDER_TEXT_MAC, GetParam()); | 379 DCHECK_EQ(RENDER_TEXT_MAC, GetParam()); |
| 344 return static_cast<RenderTextMac*>(GetRenderText()); | 380 return static_cast<RenderTextMac*>(GetRenderText()); |
| 345 } | 381 } |
| 346 #endif | 382 #endif |
| 347 | 383 |
| 348 Canvas* canvas() { return &canvas_; } | 384 Canvas* canvas() { return &canvas_; } |
| 349 TestSkiaTextRenderer* renderer() { return &renderer_; } | 385 TestSkiaTextRenderer* renderer() { return &renderer_; } |
| 386 test::RenderTextTestApi* test_api() { return test_api_.get(); }; |
| 350 | 387 |
| 351 private: | 388 private: |
| 352 std::unique_ptr<RenderText> render_text_; | 389 std::unique_ptr<RenderText> render_text_; |
| 353 std::unique_ptr<test::RenderTextTestApi> test_api_; | 390 std::unique_ptr<test::RenderTextTestApi> test_api_; |
| 354 Canvas canvas_; | 391 Canvas canvas_; |
| 355 TestSkiaTextRenderer renderer_; | 392 TestSkiaTextRenderer renderer_; |
| 356 | 393 |
| 357 #if defined(OS_WIN) | 394 #if defined(OS_WIN) |
| 358 // Needed to bypass DCHECK in GetFallbackFont. | 395 // Needed to bypass DCHECK in GetFallbackFont. |
| 359 base::MessageLoopForUI message_loop_; | 396 base::MessageLoopForUI message_loop_; |
| 360 #endif | 397 #endif |
| 361 | 398 |
| 362 DISALLOW_COPY_AND_ASSIGN(RenderTextTest); | 399 DISALLOW_COPY_AND_ASSIGN(RenderTextTest); |
| 363 }; | 400 }; |
| 364 | 401 |
| 365 // Test fixture class. Use for tests which are only to be run for | 402 // Test fixture class. Use for tests which are only to be run for |
| 366 // RenderTextHarfBuzz. | 403 // RenderTextHarfBuzz. |
| 367 class RenderTextHarfBuzzTest : public RenderTextTest { | 404 class RenderTextHarfBuzzTest : public RenderTextTest { |
| 368 public: | 405 public: |
| 369 RenderTextHarfBuzzTest() {} | 406 RenderTextHarfBuzzTest() {} |
| 370 | 407 |
| 371 // Overridden from testing::Test: | 408 // Overridden from testing::Test: |
| 372 void SetUp() override { DCHECK_EQ(RENDER_TEXT_HARFBUZZ, GetParam()); } | 409 void SetUp() override { |
| 410 RenderTextTest::SetUp(); |
| 411 DCHECK_EQ(RENDER_TEXT_HARFBUZZ, GetParam()); |
| 412 } |
| 413 |
| 414 protected: |
| 415 void SetGlyphWidth(float test_width) { |
| 416 GetRenderTextHarfBuzz()->set_glyph_width_for_test(test_width); |
| 417 } |
| 418 |
| 419 bool ShapeRunWithFont(const base::string16& text, |
| 420 const Font& font, |
| 421 const FontRenderParams& params, |
| 422 internal::TextRunHarfBuzz* run) { |
| 423 return GetRenderTextHarfBuzz()->ShapeRunWithFont(text, font, params, run); |
| 424 } |
| 425 |
| 426 base::i18n::BreakIterator* GetGraphemeIterator() { |
| 427 return GetRenderTextHarfBuzz()->GetGraphemeIterator(); |
| 428 } |
| 373 | 429 |
| 374 private: | 430 private: |
| 375 DISALLOW_COPY_AND_ASSIGN(RenderTextHarfBuzzTest); | 431 DISALLOW_COPY_AND_ASSIGN(RenderTextHarfBuzzTest); |
| 376 }; | 432 }; |
| 377 | 433 |
| 434 #if defined(OS_MACOSX) |
| 378 // Test fixture class. Use for tests which are only to be run for RenderTextMac. | 435 // Test fixture class. Use for tests which are only to be run for RenderTextMac. |
| 379 class RenderTextMacTest : public RenderTextTest { | 436 class RenderTextMacTest : public RenderTextTest { |
| 380 public: | 437 public: |
| 381 RenderTextMacTest() {} | 438 RenderTextMacTest() {} |
| 382 | 439 |
| 383 // Overridden from testing::Test: | 440 // Overridden from testing::Test: |
| 384 void SetUp() override { DCHECK_EQ(RENDER_TEXT_MAC, GetParam()); } | 441 void SetUp() override { |
| 442 RenderTextTest::SetUp(); |
| 443 DCHECK_EQ(RENDER_TEXT_MAC, GetParam()); |
| 444 } |
| 445 |
| 446 protected: |
| 447 base::ScopedCFTypeRef<CTLineRef> GetCoreTextLine() { |
| 448 return GetRenderTextMac()->line_; |
| 449 } |
| 385 | 450 |
| 386 private: | 451 private: |
| 387 DISALLOW_COPY_AND_ASSIGN(RenderTextMacTest); | 452 DISALLOW_COPY_AND_ASSIGN(RenderTextMacTest); |
| 388 }; | 453 }; |
| 454 #endif |
| 389 | 455 |
| 390 TEST_P(RenderTextTest, DefaultStyles) { | 456 TEST_P(RenderTextTest, DefaultStyles) { |
| 391 // Check the default styles applied to new instances and adjusted text. | 457 // Check the default styles applied to new instances and adjusted text. |
| 392 RenderText* render_text = GetRenderText(); | 458 RenderText* render_text = GetRenderText(); |
| 393 EXPECT_TRUE(render_text->text().empty()); | 459 EXPECT_TRUE(render_text->text().empty()); |
| 394 const wchar_t* const cases[] = { kWeak, kLtr, L"Hello", kRtl, L"", L"" }; | 460 const wchar_t* const cases[] = { kWeak, kLtr, L"Hello", kRtl, L"", L"" }; |
| 395 for (size_t i = 0; i < arraysize(cases); ++i) { | 461 for (size_t i = 0; i < arraysize(cases); ++i) { |
| 396 EXPECT_TRUE(render_text->colors().EqualsValueForTesting(SK_ColorBLACK)); | 462 EXPECT_TRUE(test_api()->colors().EqualsValueForTesting(SK_ColorBLACK)); |
| 397 EXPECT_TRUE( | 463 EXPECT_TRUE(test_api()->baselines().EqualsValueForTesting(NORMAL_BASELINE)); |
| 398 render_text->baselines().EqualsValueForTesting(NORMAL_BASELINE)); | |
| 399 for (size_t style = 0; style < NUM_TEXT_STYLES; ++style) | 464 for (size_t style = 0; style < NUM_TEXT_STYLES; ++style) |
| 400 EXPECT_TRUE(render_text->styles()[style].EqualsValueForTesting(false)); | 465 EXPECT_TRUE(test_api()->styles()[style].EqualsValueForTesting(false)); |
| 401 render_text->SetText(WideToUTF16(cases[i])); | 466 render_text->SetText(WideToUTF16(cases[i])); |
| 402 } | 467 } |
| 403 } | 468 } |
| 404 | 469 |
| 405 TEST_P(RenderTextTest, SetStyles) { | 470 TEST_P(RenderTextTest, SetStyles) { |
| 406 // Ensure custom default styles persist across setting and clearing text. | 471 // Ensure custom default styles persist across setting and clearing text. |
| 407 RenderText* render_text = GetRenderText(); | 472 RenderText* render_text = GetRenderText(); |
| 408 const SkColor color = SK_ColorRED; | 473 const SkColor color = SK_ColorRED; |
| 409 render_text->SetColor(color); | 474 render_text->SetColor(color); |
| 410 render_text->SetBaselineStyle(SUPERSCRIPT); | 475 render_text->SetBaselineStyle(SUPERSCRIPT); |
| 411 render_text->SetWeight(Font::Weight::BOLD); | 476 render_text->SetWeight(Font::Weight::BOLD); |
| 412 render_text->SetStyle(UNDERLINE, false); | 477 render_text->SetStyle(UNDERLINE, false); |
| 413 const wchar_t* const cases[] = { kWeak, kLtr, L"Hello", kRtl, L"", L"" }; | 478 const wchar_t* const cases[] = { kWeak, kLtr, L"Hello", kRtl, L"", L"" }; |
| 414 for (size_t i = 0; i < arraysize(cases); ++i) { | 479 for (size_t i = 0; i < arraysize(cases); ++i) { |
| 415 EXPECT_TRUE(render_text->colors().EqualsValueForTesting(color)); | 480 EXPECT_TRUE(test_api()->colors().EqualsValueForTesting(color)); |
| 416 EXPECT_TRUE(render_text->baselines().EqualsValueForTesting(SUPERSCRIPT)); | 481 EXPECT_TRUE(test_api()->baselines().EqualsValueForTesting(SUPERSCRIPT)); |
| 417 EXPECT_TRUE( | 482 EXPECT_TRUE( |
| 418 render_text->weights().EqualsValueForTesting(Font::Weight::BOLD)); | 483 test_api()->weights().EqualsValueForTesting(Font::Weight::BOLD)); |
| 419 EXPECT_TRUE(render_text->styles()[UNDERLINE].EqualsValueForTesting(false)); | 484 EXPECT_TRUE(test_api()->styles()[UNDERLINE].EqualsValueForTesting(false)); |
| 420 render_text->SetText(WideToUTF16(cases[i])); | 485 render_text->SetText(WideToUTF16(cases[i])); |
| 421 | 486 |
| 422 // Ensure custom default styles can be applied after text has been set. | 487 // Ensure custom default styles can be applied after text has been set. |
| 423 if (i == 1) | 488 if (i == 1) |
| 424 render_text->SetStyle(STRIKE, true); | 489 render_text->SetStyle(STRIKE, true); |
| 425 if (i >= 1) | 490 if (i >= 1) |
| 426 EXPECT_TRUE(render_text->styles()[STRIKE].EqualsValueForTesting(true)); | 491 EXPECT_TRUE(test_api()->styles()[STRIKE].EqualsValueForTesting(true)); |
| 427 } | 492 } |
| 428 } | 493 } |
| 429 | 494 |
| 430 TEST_P(RenderTextTest, ApplyStyles) { | 495 TEST_P(RenderTextTest, ApplyStyles) { |
| 431 RenderText* render_text = GetRenderText(); | 496 RenderText* render_text = GetRenderText(); |
| 432 render_text->SetText(ASCIIToUTF16("012345678")); | 497 render_text->SetText(ASCIIToUTF16("012345678")); |
| 433 | 498 |
| 434 // Apply a ranged color and style and check the resulting breaks. | 499 // Apply a ranged color and style and check the resulting breaks. |
| 435 render_text->ApplyColor(SK_ColorRED, Range(1, 4)); | 500 render_text->ApplyColor(SK_ColorRED, Range(1, 4)); |
| 436 render_text->ApplyBaselineStyle(SUPERIOR, Range(2, 4)); | 501 render_text->ApplyBaselineStyle(SUPERIOR, Range(2, 4)); |
| 437 render_text->ApplyWeight(Font::Weight::BOLD, Range(2, 5)); | 502 render_text->ApplyWeight(Font::Weight::BOLD, Range(2, 5)); |
| 438 std::vector<std::pair<size_t, SkColor> > expected_color; | 503 std::vector<std::pair<size_t, SkColor> > expected_color; |
| 439 expected_color.push_back(std::pair<size_t, SkColor>(0, SK_ColorBLACK)); | 504 expected_color.push_back(std::pair<size_t, SkColor>(0, SK_ColorBLACK)); |
| 440 expected_color.push_back(std::pair<size_t, SkColor>(1, SK_ColorRED)); | 505 expected_color.push_back(std::pair<size_t, SkColor>(1, SK_ColorRED)); |
| 441 expected_color.push_back(std::pair<size_t, SkColor>(4, SK_ColorBLACK)); | 506 expected_color.push_back(std::pair<size_t, SkColor>(4, SK_ColorBLACK)); |
| 442 EXPECT_TRUE(render_text->colors().EqualsForTesting(expected_color)); | 507 EXPECT_TRUE(test_api()->colors().EqualsForTesting(expected_color)); |
| 443 std::vector<std::pair<size_t, BaselineStyle>> expected_baseline_style; | 508 std::vector<std::pair<size_t, BaselineStyle>> expected_baseline_style; |
| 444 expected_baseline_style.push_back( | 509 expected_baseline_style.push_back( |
| 445 std::pair<size_t, BaselineStyle>(0, NORMAL_BASELINE)); | 510 std::pair<size_t, BaselineStyle>(0, NORMAL_BASELINE)); |
| 446 expected_baseline_style.push_back( | 511 expected_baseline_style.push_back( |
| 447 std::pair<size_t, BaselineStyle>(2, SUPERIOR)); | 512 std::pair<size_t, BaselineStyle>(2, SUPERIOR)); |
| 448 expected_baseline_style.push_back( | 513 expected_baseline_style.push_back( |
| 449 std::pair<size_t, BaselineStyle>(4, NORMAL_BASELINE)); | 514 std::pair<size_t, BaselineStyle>(4, NORMAL_BASELINE)); |
| 450 EXPECT_TRUE( | 515 EXPECT_TRUE( |
| 451 render_text->baselines().EqualsForTesting(expected_baseline_style)); | 516 test_api()->baselines().EqualsForTesting(expected_baseline_style)); |
| 452 std::vector<std::pair<size_t, Font::Weight>> expected_weight; | 517 std::vector<std::pair<size_t, Font::Weight>> expected_weight; |
| 453 expected_weight.push_back( | 518 expected_weight.push_back( |
| 454 std::pair<size_t, Font::Weight>(0, Font::Weight::NORMAL)); | 519 std::pair<size_t, Font::Weight>(0, Font::Weight::NORMAL)); |
| 455 expected_weight.push_back( | 520 expected_weight.push_back( |
| 456 std::pair<size_t, Font::Weight>(2, Font::Weight::BOLD)); | 521 std::pair<size_t, Font::Weight>(2, Font::Weight::BOLD)); |
| 457 expected_weight.push_back( | 522 expected_weight.push_back( |
| 458 std::pair<size_t, Font::Weight>(5, Font::Weight::NORMAL)); | 523 std::pair<size_t, Font::Weight>(5, Font::Weight::NORMAL)); |
| 459 EXPECT_TRUE(render_text->weights().EqualsForTesting(expected_weight)); | 524 EXPECT_TRUE(test_api()->weights().EqualsForTesting(expected_weight)); |
| 460 | 525 |
| 461 // Ensure that setting a value overrides the ranged values. | 526 // Ensure that setting a value overrides the ranged values. |
| 462 render_text->SetColor(SK_ColorBLUE); | 527 render_text->SetColor(SK_ColorBLUE); |
| 463 EXPECT_TRUE(render_text->colors().EqualsValueForTesting(SK_ColorBLUE)); | 528 EXPECT_TRUE(test_api()->colors().EqualsValueForTesting(SK_ColorBLUE)); |
| 464 render_text->SetBaselineStyle(SUBSCRIPT); | 529 render_text->SetBaselineStyle(SUBSCRIPT); |
| 465 EXPECT_TRUE(render_text->baselines().EqualsValueForTesting(SUBSCRIPT)); | 530 EXPECT_TRUE(test_api()->baselines().EqualsValueForTesting(SUBSCRIPT)); |
| 466 render_text->SetWeight(Font::Weight::NORMAL); | 531 render_text->SetWeight(Font::Weight::NORMAL); |
| 467 EXPECT_TRUE( | 532 EXPECT_TRUE( |
| 468 render_text->weights().EqualsValueForTesting(Font::Weight::NORMAL)); | 533 test_api()->weights().EqualsValueForTesting(Font::Weight::NORMAL)); |
| 469 | 534 |
| 470 // Apply a value over the text end and check the resulting breaks (INT_MAX | 535 // Apply a value over the text end and check the resulting breaks (INT_MAX |
| 471 // should be used instead of the text length for the range end) | 536 // should be used instead of the text length for the range end) |
| 472 const size_t text_length = render_text->text().length(); | 537 const size_t text_length = render_text->text().length(); |
| 473 render_text->ApplyColor(SK_ColorRED, Range(0, text_length)); | 538 render_text->ApplyColor(SK_ColorRED, Range(0, text_length)); |
| 474 render_text->ApplyBaselineStyle(SUPERIOR, Range(0, text_length)); | 539 render_text->ApplyBaselineStyle(SUPERIOR, Range(0, text_length)); |
| 475 render_text->ApplyWeight(Font::Weight::BOLD, Range(2, text_length)); | 540 render_text->ApplyWeight(Font::Weight::BOLD, Range(2, text_length)); |
| 476 std::vector<std::pair<size_t, SkColor> > expected_color_end; | 541 std::vector<std::pair<size_t, SkColor> > expected_color_end; |
| 477 expected_color_end.push_back(std::pair<size_t, SkColor>(0, SK_ColorRED)); | 542 expected_color_end.push_back(std::pair<size_t, SkColor>(0, SK_ColorRED)); |
| 478 EXPECT_TRUE(render_text->colors().EqualsForTesting(expected_color_end)); | 543 EXPECT_TRUE(test_api()->colors().EqualsForTesting(expected_color_end)); |
| 479 std::vector<std::pair<size_t, BaselineStyle>> expected_baseline_end; | 544 std::vector<std::pair<size_t, BaselineStyle>> expected_baseline_end; |
| 480 expected_baseline_end.push_back( | 545 expected_baseline_end.push_back( |
| 481 std::pair<size_t, BaselineStyle>(0, SUPERIOR)); | 546 std::pair<size_t, BaselineStyle>(0, SUPERIOR)); |
| 482 EXPECT_TRUE(render_text->baselines().EqualsForTesting(expected_baseline_end)); | 547 EXPECT_TRUE(test_api()->baselines().EqualsForTesting(expected_baseline_end)); |
| 483 std::vector<std::pair<size_t, Font::Weight>> expected_weight_end; | 548 std::vector<std::pair<size_t, Font::Weight>> expected_weight_end; |
| 484 expected_weight_end.push_back( | 549 expected_weight_end.push_back( |
| 485 std::pair<size_t, Font::Weight>(0, Font::Weight::NORMAL)); | 550 std::pair<size_t, Font::Weight>(0, Font::Weight::NORMAL)); |
| 486 expected_weight_end.push_back( | 551 expected_weight_end.push_back( |
| 487 std::pair<size_t, Font::Weight>(2, Font::Weight::BOLD)); | 552 std::pair<size_t, Font::Weight>(2, Font::Weight::BOLD)); |
| 488 EXPECT_TRUE(render_text->weights().EqualsForTesting(expected_weight_end)); | 553 EXPECT_TRUE(test_api()->weights().EqualsForTesting(expected_weight_end)); |
| 489 | 554 |
| 490 // Ensure ranged values adjust to accommodate text length changes. | 555 // Ensure ranged values adjust to accommodate text length changes. |
| 491 render_text->ApplyStyle(ITALIC, true, Range(0, 2)); | 556 render_text->ApplyStyle(ITALIC, true, Range(0, 2)); |
| 492 render_text->ApplyStyle(ITALIC, true, Range(3, 6)); | 557 render_text->ApplyStyle(ITALIC, true, Range(3, 6)); |
| 493 render_text->ApplyStyle(ITALIC, true, Range(7, text_length)); | 558 render_text->ApplyStyle(ITALIC, true, Range(7, text_length)); |
| 494 std::vector<std::pair<size_t, bool> > expected_italic; | 559 std::vector<std::pair<size_t, bool> > expected_italic; |
| 495 expected_italic.push_back(std::pair<size_t, bool>(0, true)); | 560 expected_italic.push_back(std::pair<size_t, bool>(0, true)); |
| 496 expected_italic.push_back(std::pair<size_t, bool>(2, false)); | 561 expected_italic.push_back(std::pair<size_t, bool>(2, false)); |
| 497 expected_italic.push_back(std::pair<size_t, bool>(3, true)); | 562 expected_italic.push_back(std::pair<size_t, bool>(3, true)); |
| 498 expected_italic.push_back(std::pair<size_t, bool>(6, false)); | 563 expected_italic.push_back(std::pair<size_t, bool>(6, false)); |
| 499 expected_italic.push_back(std::pair<size_t, bool>(7, true)); | 564 expected_italic.push_back(std::pair<size_t, bool>(7, true)); |
| 500 EXPECT_TRUE(render_text->styles()[ITALIC].EqualsForTesting(expected_italic)); | 565 EXPECT_TRUE(test_api()->styles()[ITALIC].EqualsForTesting(expected_italic)); |
| 501 | 566 |
| 502 // Changing the text should clear any breaks except for the first one. | 567 // Changing the text should clear any breaks except for the first one. |
| 503 render_text->SetText(ASCIIToUTF16("0123456")); | 568 render_text->SetText(ASCIIToUTF16("0123456")); |
| 504 expected_italic.resize(1); | 569 expected_italic.resize(1); |
| 505 EXPECT_TRUE(render_text->styles()[ITALIC].EqualsForTesting(expected_italic)); | 570 EXPECT_TRUE(test_api()->styles()[ITALIC].EqualsForTesting(expected_italic)); |
| 506 render_text->ApplyStyle(ITALIC, false, Range(2, 4)); | 571 render_text->ApplyStyle(ITALIC, false, Range(2, 4)); |
| 507 render_text->SetText(ASCIIToUTF16("012345678")); | 572 render_text->SetText(ASCIIToUTF16("012345678")); |
| 508 EXPECT_TRUE(render_text->styles()[ITALIC].EqualsForTesting(expected_italic)); | 573 EXPECT_TRUE(test_api()->styles()[ITALIC].EqualsForTesting(expected_italic)); |
| 509 render_text->ApplyStyle(ITALIC, false, Range(0, 1)); | 574 render_text->ApplyStyle(ITALIC, false, Range(0, 1)); |
| 510 render_text->SetText(ASCIIToUTF16("0123456")); | 575 render_text->SetText(ASCIIToUTF16("0123456")); |
| 511 expected_italic.begin()->second = false; | 576 expected_italic.begin()->second = false; |
| 512 EXPECT_TRUE(render_text->styles()[ITALIC].EqualsForTesting(expected_italic)); | 577 EXPECT_TRUE(test_api()->styles()[ITALIC].EqualsForTesting(expected_italic)); |
| 513 render_text->ApplyStyle(ITALIC, true, Range(2, 4)); | 578 render_text->ApplyStyle(ITALIC, true, Range(2, 4)); |
| 514 render_text->SetText(ASCIIToUTF16("012345678")); | 579 render_text->SetText(ASCIIToUTF16("012345678")); |
| 515 EXPECT_TRUE(render_text->styles()[ITALIC].EqualsForTesting(expected_italic)); | 580 EXPECT_TRUE(test_api()->styles()[ITALIC].EqualsForTesting(expected_italic)); |
| 516 | 581 |
| 517 // TODO(tmoniuszko): Enable when RenderTextMac::IsValidCursorIndex is | 582 // TODO(tmoniuszko): Enable when RenderTextMac::IsValidCursorIndex is |
| 518 // implemented. See http://crbug.com/131618. | 583 // implemented. See http://crbug.com/131618. |
| 519 if (GetParam() != RENDER_TEXT_MAC) { | 584 if (GetParam() != RENDER_TEXT_MAC) { |
| 520 // Styles shouldn't be changed mid-grapheme. | 585 // Styles shouldn't be changed mid-grapheme. |
| 521 render_text->SetText( | 586 render_text->SetText( |
| 522 WideToUTF16(L"0" | 587 WideToUTF16(L"0" |
| 523 L"\x0915\x093f" | 588 L"\x0915\x093f" |
| 524 L"1" | 589 L"1" |
| 525 L"\x0915\x093f" | 590 L"\x0915\x093f" |
| 526 L"2")); | 591 L"2")); |
| 527 render_text->ApplyStyle(UNDERLINE, true, Range(2, 5)); | 592 render_text->ApplyStyle(UNDERLINE, true, Range(2, 5)); |
| 528 std::vector<std::pair<size_t, bool>> expected_underline; | 593 std::vector<std::pair<size_t, bool>> expected_underline; |
| 529 expected_underline.push_back(std::pair<size_t, bool>(0, false)); | 594 expected_underline.push_back(std::pair<size_t, bool>(0, false)); |
| 530 expected_underline.push_back(std::pair<size_t, bool>(1, true)); | 595 expected_underline.push_back(std::pair<size_t, bool>(1, true)); |
| 531 expected_underline.push_back(std::pair<size_t, bool>(6, false)); | 596 expected_underline.push_back(std::pair<size_t, bool>(6, false)); |
| 532 EXPECT_TRUE( | 597 EXPECT_TRUE( |
| 533 render_text->styles()[UNDERLINE].EqualsForTesting(expected_underline)); | 598 test_api()->styles()[UNDERLINE].EqualsForTesting(expected_underline)); |
| 534 } | 599 } |
| 535 } | 600 } |
| 536 | 601 |
| 537 TEST_P(RenderTextTest, AppendTextKeepsStyles) { | 602 TEST_P(RenderTextTest, AppendTextKeepsStyles) { |
| 538 RenderText* render_text = GetRenderText(); | 603 RenderText* render_text = GetRenderText(); |
| 539 // Setup basic functionality. | 604 // Setup basic functionality. |
| 540 render_text->SetText(ASCIIToUTF16("abc")); | 605 render_text->SetText(ASCIIToUTF16("abc")); |
| 541 render_text->ApplyColor(SK_ColorRED, Range(0, 1)); | 606 render_text->ApplyColor(SK_ColorRED, Range(0, 1)); |
| 542 render_text->ApplyBaselineStyle(SUPERSCRIPT, Range(1, 2)); | 607 render_text->ApplyBaselineStyle(SUPERSCRIPT, Range(1, 2)); |
| 543 render_text->ApplyStyle(UNDERLINE, true, Range(2, 3)); | 608 render_text->ApplyStyle(UNDERLINE, true, Range(2, 3)); |
| 544 // Verify basic functionality. | 609 // Verify basic functionality. |
| 545 std::vector<std::pair<size_t, SkColor>> expected_color; | 610 std::vector<std::pair<size_t, SkColor>> expected_color; |
| 546 expected_color.push_back(std::pair<size_t, SkColor>(0, SK_ColorRED)); | 611 expected_color.push_back(std::pair<size_t, SkColor>(0, SK_ColorRED)); |
| 547 expected_color.push_back(std::pair<size_t, SkColor>(1, SK_ColorBLACK)); | 612 expected_color.push_back(std::pair<size_t, SkColor>(1, SK_ColorBLACK)); |
| 548 EXPECT_TRUE(render_text->colors().EqualsForTesting(expected_color)); | 613 EXPECT_TRUE(test_api()->colors().EqualsForTesting(expected_color)); |
| 549 std::vector<std::pair<size_t, BaselineStyle>> expected_baseline; | 614 std::vector<std::pair<size_t, BaselineStyle>> expected_baseline; |
| 550 expected_baseline.push_back( | 615 expected_baseline.push_back( |
| 551 std::pair<size_t, BaselineStyle>(0, NORMAL_BASELINE)); | 616 std::pair<size_t, BaselineStyle>(0, NORMAL_BASELINE)); |
| 552 expected_baseline.push_back(std::pair<size_t, BaselineStyle>(1, SUPERSCRIPT)); | 617 expected_baseline.push_back(std::pair<size_t, BaselineStyle>(1, SUPERSCRIPT)); |
| 553 expected_baseline.push_back( | 618 expected_baseline.push_back( |
| 554 std::pair<size_t, BaselineStyle>(2, NORMAL_BASELINE)); | 619 std::pair<size_t, BaselineStyle>(2, NORMAL_BASELINE)); |
| 555 EXPECT_TRUE(render_text->baselines().EqualsForTesting(expected_baseline)); | 620 EXPECT_TRUE(test_api()->baselines().EqualsForTesting(expected_baseline)); |
| 556 std::vector<std::pair<size_t, bool>> expected_style; | 621 std::vector<std::pair<size_t, bool>> expected_style; |
| 557 expected_style.push_back(std::pair<size_t, bool>(0, false)); | 622 expected_style.push_back(std::pair<size_t, bool>(0, false)); |
| 558 expected_style.push_back(std::pair<size_t, bool>(2, true)); | 623 expected_style.push_back(std::pair<size_t, bool>(2, true)); |
| 559 EXPECT_TRUE( | 624 EXPECT_TRUE(test_api()->styles()[UNDERLINE].EqualsForTesting(expected_style)); |
| 560 render_text->styles()[UNDERLINE].EqualsForTesting(expected_style)); | |
| 561 // Ensure AppendText maintains current text styles. | 625 // Ensure AppendText maintains current text styles. |
| 562 render_text->AppendText(ASCIIToUTF16("def")); | 626 render_text->AppendText(ASCIIToUTF16("def")); |
| 563 EXPECT_EQ(render_text->GetDisplayText(), ASCIIToUTF16("abcdef")); | 627 EXPECT_EQ(render_text->GetDisplayText(), ASCIIToUTF16("abcdef")); |
| 564 EXPECT_TRUE(render_text->colors().EqualsForTesting(expected_color)); | 628 EXPECT_TRUE(test_api()->colors().EqualsForTesting(expected_color)); |
| 565 EXPECT_TRUE(render_text->baselines().EqualsForTesting(expected_baseline)); | 629 EXPECT_TRUE(test_api()->baselines().EqualsForTesting(expected_baseline)); |
| 566 EXPECT_TRUE( | 630 EXPECT_TRUE(test_api()->styles()[UNDERLINE].EqualsForTesting(expected_style)); |
| 567 render_text->styles()[UNDERLINE].EqualsForTesting(expected_style)); | |
| 568 } | 631 } |
| 569 | 632 |
| 570 void TestVisualCursorMotionInObscuredField( | 633 void TestVisualCursorMotionInObscuredField( |
| 571 RenderText* render_text, | 634 RenderText* render_text, |
| 572 const base::string16& text, | 635 const base::string16& text, |
| 573 SelectionBehavior selection_behavior) { | 636 SelectionBehavior selection_behavior) { |
| 574 const bool select = selection_behavior != SELECTION_NONE; | 637 const bool select = selection_behavior != SELECTION_NONE; |
| 575 ASSERT_TRUE(render_text->obscured()); | 638 ASSERT_TRUE(render_text->obscured()); |
| 576 render_text->SetText(text); | 639 render_text->SetText(text); |
| 577 int len = text.length(); | 640 int len = text.length(); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 619 render_text->SetText(invalid_surrogates); | 682 render_text->SetText(invalid_surrogates); |
| 620 EXPECT_EQ(ASCIIToUTF16("**"), render_text->GetDisplayText()); | 683 EXPECT_EQ(ASCIIToUTF16("**"), render_text->GetDisplayText()); |
| 621 const base::char16 valid_surrogates[] = {0xD800, 0xDC00, 0}; | 684 const base::char16 valid_surrogates[] = {0xD800, 0xDC00, 0}; |
| 622 render_text->SetText(valid_surrogates); | 685 render_text->SetText(valid_surrogates); |
| 623 EXPECT_EQ(ASCIIToUTF16("*"), render_text->GetDisplayText()); | 686 EXPECT_EQ(ASCIIToUTF16("*"), render_text->GetDisplayText()); |
| 624 EXPECT_EQ(0U, render_text->cursor_position()); | 687 EXPECT_EQ(0U, render_text->cursor_position()); |
| 625 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_RIGHT, SELECTION_NONE); | 688 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_RIGHT, SELECTION_NONE); |
| 626 EXPECT_EQ(2U, render_text->cursor_position()); | 689 EXPECT_EQ(2U, render_text->cursor_position()); |
| 627 | 690 |
| 628 // Test index conversion and cursor validity with a valid surrogate pair. | 691 // Test index conversion and cursor validity with a valid surrogate pair. |
| 629 EXPECT_EQ(0U, render_text->TextIndexToDisplayIndex(0U)); | 692 EXPECT_EQ(0U, test_api()->TextIndexToDisplayIndex(0U)); |
| 630 EXPECT_EQ(1U, render_text->TextIndexToDisplayIndex(1U)); | 693 EXPECT_EQ(1U, test_api()->TextIndexToDisplayIndex(1U)); |
| 631 EXPECT_EQ(1U, render_text->TextIndexToDisplayIndex(2U)); | 694 EXPECT_EQ(1U, test_api()->TextIndexToDisplayIndex(2U)); |
| 632 EXPECT_EQ(0U, render_text->DisplayIndexToTextIndex(0U)); | 695 EXPECT_EQ(0U, test_api()->DisplayIndexToTextIndex(0U)); |
| 633 EXPECT_EQ(2U, render_text->DisplayIndexToTextIndex(1U)); | 696 EXPECT_EQ(2U, test_api()->DisplayIndexToTextIndex(1U)); |
| 634 EXPECT_TRUE(render_text->IsValidCursorIndex(0U)); | 697 EXPECT_TRUE(render_text->IsValidCursorIndex(0U)); |
| 635 EXPECT_FALSE(render_text->IsValidCursorIndex(1U)); | 698 EXPECT_FALSE(render_text->IsValidCursorIndex(1U)); |
| 636 EXPECT_TRUE(render_text->IsValidCursorIndex(2U)); | 699 EXPECT_TRUE(render_text->IsValidCursorIndex(2U)); |
| 637 | 700 |
| 638 // FindCursorPosition() should not return positions between a surrogate pair. | 701 // FindCursorPosition() should not return positions between a surrogate pair. |
| 639 render_text->SetDisplayRect(Rect(0, 0, 20, 20)); | 702 render_text->SetDisplayRect(Rect(0, 0, 20, 20)); |
| 640 EXPECT_EQ(render_text->FindCursorPosition(Point(0, 0)).caret_pos(), 0U); | 703 EXPECT_EQ(render_text->FindCursorPosition(Point(0, 0)).caret_pos(), 0U); |
| 641 EXPECT_EQ(render_text->FindCursorPosition(Point(20, 0)).caret_pos(), 2U); | 704 EXPECT_EQ(render_text->FindCursorPosition(Point(20, 0)).caret_pos(), 2U); |
| 642 for (int x = -1; x <= 20; ++x) { | 705 for (int x = -1; x <= 20; ++x) { |
| 643 SelectionModel selection = render_text->FindCursorPosition(Point(x, 0)); | 706 SelectionModel selection = render_text->FindCursorPosition(Point(x, 0)); |
| (...skipping 1010 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1654 if (base::win::GetVersion() < base::win::VERSION_VISTA) | 1717 if (base::win::GetVersion() < base::win::VERSION_VISTA) |
| 1655 return; | 1718 return; |
| 1656 #endif | 1719 #endif |
| 1657 | 1720 |
| 1658 RenderText* render_text = GetRenderText(); | 1721 RenderText* render_text = GetRenderText(); |
| 1659 for (size_t i = 0; i < arraysize(cases); i++) { | 1722 for (size_t i = 0; i < arraysize(cases); i++) { |
| 1660 render_text->SetText(cases[i].text); | 1723 render_text->SetText(cases[i].text); |
| 1661 bool ltr = (cases[i].expected_text_direction == base::i18n::LEFT_TO_RIGHT); | 1724 bool ltr = (cases[i].expected_text_direction == base::i18n::LEFT_TO_RIGHT); |
| 1662 | 1725 |
| 1663 SelectionModel start_edge = | 1726 SelectionModel start_edge = |
| 1664 render_text->EdgeSelectionModel(ltr ? CURSOR_LEFT : CURSOR_RIGHT); | 1727 test_api()->EdgeSelectionModel(ltr ? CURSOR_LEFT : CURSOR_RIGHT); |
| 1665 EXPECT_EQ(start_edge, SelectionModel(0, CURSOR_BACKWARD)); | 1728 EXPECT_EQ(start_edge, SelectionModel(0, CURSOR_BACKWARD)); |
| 1666 | 1729 |
| 1667 SelectionModel end_edge = | 1730 SelectionModel end_edge = |
| 1668 render_text->EdgeSelectionModel(ltr ? CURSOR_RIGHT : CURSOR_LEFT); | 1731 test_api()->EdgeSelectionModel(ltr ? CURSOR_RIGHT : CURSOR_LEFT); |
| 1669 EXPECT_EQ(end_edge, SelectionModel(cases[i].text.length(), CURSOR_FORWARD)); | 1732 EXPECT_EQ(end_edge, SelectionModel(cases[i].text.length(), CURSOR_FORWARD)); |
| 1670 } | 1733 } |
| 1671 } | 1734 } |
| 1672 | 1735 |
| 1673 TEST_P(RenderTextTest, SelectAll) { | 1736 TEST_P(RenderTextTest, SelectAll) { |
| 1674 const wchar_t* const cases[] = | 1737 const wchar_t* const cases[] = |
| 1675 { kWeak, kLtr, kLtrRtl, kLtrRtlLtr, kRtl, kRtlLtr, kRtlLtrRtl }; | 1738 { kWeak, kLtr, kLtrRtl, kLtrRtlLtr, kRtl, kRtlLtr, kRtlLtrRtl }; |
| 1676 | 1739 |
| 1677 // Ensure that SelectAll respects the |reversed| argument regardless of | 1740 // Ensure that SelectAll respects the |reversed| argument regardless of |
| 1678 // application locale and text content directionality. | 1741 // application locale and text content directionality. |
| (...skipping 921 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2600 | 2663 |
| 2601 RenderText* render_text = GetRenderText(); | 2664 RenderText* render_text = GetRenderText(); |
| 2602 render_text->SetDisplayRect(Rect(1, 1000)); | 2665 render_text->SetDisplayRect(Rect(1, 1000)); |
| 2603 render_text->SetMultiline(true); | 2666 render_text->SetMultiline(true); |
| 2604 render_text->SetWordWrapBehavior(WRAP_LONG_WORDS); | 2667 render_text->SetWordWrapBehavior(WRAP_LONG_WORDS); |
| 2605 | 2668 |
| 2606 for (size_t i = 0; i < arraysize(kTestStrings); ++i) { | 2669 for (size_t i = 0; i < arraysize(kTestStrings); ++i) { |
| 2607 SCOPED_TRACE(base::StringPrintf("kTestStrings[%" PRIuS "]", i)); | 2670 SCOPED_TRACE(base::StringPrintf("kTestStrings[%" PRIuS "]", i)); |
| 2608 render_text->SetText(WideToUTF16(kTestStrings[i])); | 2671 render_text->SetText(WideToUTF16(kTestStrings[i])); |
| 2609 render_text->Draw(canvas()); | 2672 render_text->Draw(canvas()); |
| 2610 EXPECT_GT(render_text->lines_.size(), 1U); | 2673 EXPECT_GT(test_api()->lines().size(), 1U); |
| 2611 } | 2674 } |
| 2612 } | 2675 } |
| 2613 | 2676 |
| 2614 // Ensure strings wrap onto multiple lines for a normal available width. | 2677 // Ensure strings wrap onto multiple lines for a normal available width. |
| 2615 TEST_P(RenderTextHarfBuzzTest, Multiline_NormalWidth) { | 2678 TEST_P(RenderTextHarfBuzzTest, Multiline_NormalWidth) { |
| 2616 const struct { | 2679 const struct { |
| 2617 const wchar_t* const text; | 2680 const wchar_t* const text; |
| 2618 const Range first_line_char_range; | 2681 const Range first_line_char_range; |
| 2619 const Range second_line_char_range; | 2682 const Range second_line_char_range; |
| 2620 bool is_ltr; | 2683 bool is_ltr; |
| 2621 } kTestStrings[] = { | 2684 } kTestStrings[] = { |
| 2622 { L"abc defg hijkl", Range(0, 9), Range(9, 14), true }, | 2685 { L"abc defg hijkl", Range(0, 9), Range(9, 14), true }, |
| 2623 { L"qwertyzxcvbn", Range(0, 10), Range(10, 12), true }, | 2686 { L"qwertyzxcvbn", Range(0, 10), Range(10, 12), true }, |
| 2624 { L"\x0627\x0644\x0644\x063A\x0629 " | 2687 { L"\x0627\x0644\x0644\x063A\x0629 " |
| 2625 L"\x0627\x0644\x0639\x0631\x0628\x064A\x0629", | 2688 L"\x0627\x0644\x0639\x0631\x0628\x064A\x0629", |
| 2626 Range(0, 6), Range(6, 13), false }, | 2689 Range(0, 6), Range(6, 13), false }, |
| 2627 { L"\x062A\x0641\x0627\x062D \x05EA\x05E4\x05D5\x05D6\x05D9" | 2690 { L"\x062A\x0641\x0627\x062D \x05EA\x05E4\x05D5\x05D6\x05D9" |
| 2628 L"\x05DA\x05DB\x05DD", Range(0, 5), Range(5, 13), false } | 2691 L"\x05DA\x05DB\x05DD", Range(0, 5), Range(5, 13), false } |
| 2629 }; | 2692 }; |
| 2630 | 2693 |
| 2631 RenderTextHarfBuzz* render_text = GetRenderTextHarfBuzz(); | 2694 RenderTextHarfBuzz* render_text = GetRenderTextHarfBuzz(); |
| 2632 | 2695 |
| 2633 // Specify the fixed width for characters to suppress the possible variations | 2696 // Specify the fixed width for characters to suppress the possible variations |
| 2634 // of linebreak results. | 2697 // of linebreak results. |
| 2635 render_text->set_glyph_width_for_test(5); | 2698 SetGlyphWidth(5); |
| 2636 render_text->SetDisplayRect(Rect(50, 1000)); | 2699 render_text->SetDisplayRect(Rect(50, 1000)); |
| 2637 render_text->SetMultiline(true); | 2700 render_text->SetMultiline(true); |
| 2638 render_text->SetWordWrapBehavior(WRAP_LONG_WORDS); | 2701 render_text->SetWordWrapBehavior(WRAP_LONG_WORDS); |
| 2639 render_text->SetHorizontalAlignment(ALIGN_TO_HEAD); | 2702 render_text->SetHorizontalAlignment(ALIGN_TO_HEAD); |
| 2640 | 2703 |
| 2641 for (size_t i = 0; i < arraysize(kTestStrings); ++i) { | 2704 for (size_t i = 0; i < arraysize(kTestStrings); ++i) { |
| 2642 SCOPED_TRACE(base::StringPrintf("kTestStrings[%" PRIuS "]", i)); | 2705 SCOPED_TRACE(base::StringPrintf("kTestStrings[%" PRIuS "]", i)); |
| 2643 render_text->SetText(WideToUTF16(kTestStrings[i].text)); | 2706 render_text->SetText(WideToUTF16(kTestStrings[i].text)); |
| 2644 DrawVisualText(); | 2707 DrawVisualText(); |
| 2645 | 2708 |
| 2646 ASSERT_EQ(2U, render_text->lines_.size()); | 2709 ASSERT_EQ(2U, test_api()->lines().size()); |
| 2647 ASSERT_EQ(1U, render_text->lines_[0].segments.size()); | 2710 ASSERT_EQ(1U, test_api()->lines()[0].segments.size()); |
| 2648 EXPECT_EQ(kTestStrings[i].first_line_char_range, | 2711 EXPECT_EQ(kTestStrings[i].first_line_char_range, |
| 2649 render_text->lines_[0].segments[0].char_range); | 2712 test_api()->lines()[0].segments[0].char_range); |
| 2650 ASSERT_EQ(1U, render_text->lines_[1].segments.size()); | 2713 ASSERT_EQ(1U, test_api()->lines()[1].segments.size()); |
| 2651 EXPECT_EQ(kTestStrings[i].second_line_char_range, | 2714 EXPECT_EQ(kTestStrings[i].second_line_char_range, |
| 2652 render_text->lines_[1].segments[0].char_range); | 2715 test_api()->lines()[1].segments[0].char_range); |
| 2653 | 2716 |
| 2654 std::vector<TestSkiaTextRenderer::TextLog> text_log; | 2717 std::vector<TestSkiaTextRenderer::TextLog> text_log; |
| 2655 renderer()->GetTextLogAndReset(&text_log); | 2718 renderer()->GetTextLogAndReset(&text_log); |
| 2656 ASSERT_EQ(2U, text_log.size()); | 2719 ASSERT_EQ(2U, text_log.size()); |
| 2657 // NOTE: this expectation compares the character length and glyph counts, | 2720 // NOTE: this expectation compares the character length and glyph counts, |
| 2658 // which isn't always equal. This is okay only because all the test | 2721 // which isn't always equal. This is okay only because all the test |
| 2659 // strings are simple (like, no compound characters nor UTF16-surrogate | 2722 // strings are simple (like, no compound characters nor UTF16-surrogate |
| 2660 // pairs). Be careful in case more complicated test strings are added. | 2723 // pairs). Be careful in case more complicated test strings are added. |
| 2661 EXPECT_EQ(kTestStrings[i].first_line_char_range.length(), | 2724 EXPECT_EQ(kTestStrings[i].first_line_char_range.length(), |
| 2662 text_log[0].glyph_count); | 2725 text_log[0].glyph_count); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 2680 L"\x62E\x628\x632", L"\x62E \x628 \x632" }; | 2743 L"\x62E\x628\x632", L"\x62E \x628 \x632" }; |
| 2681 | 2744 |
| 2682 RenderText* render_text = GetRenderText(); | 2745 RenderText* render_text = GetRenderText(); |
| 2683 render_text->SetDisplayRect(Rect(1000, 1000)); | 2746 render_text->SetDisplayRect(Rect(1000, 1000)); |
| 2684 render_text->SetMultiline(true); | 2747 render_text->SetMultiline(true); |
| 2685 | 2748 |
| 2686 for (size_t i = 0; i < arraysize(kTestStrings); ++i) { | 2749 for (size_t i = 0; i < arraysize(kTestStrings); ++i) { |
| 2687 SCOPED_TRACE(base::StringPrintf("kTestStrings[%" PRIuS "]", i)); | 2750 SCOPED_TRACE(base::StringPrintf("kTestStrings[%" PRIuS "]", i)); |
| 2688 render_text->SetText(WideToUTF16(kTestStrings[i])); | 2751 render_text->SetText(WideToUTF16(kTestStrings[i])); |
| 2689 render_text->Draw(canvas()); | 2752 render_text->Draw(canvas()); |
| 2690 EXPECT_EQ(1U, render_text->lines_.size()); | 2753 EXPECT_EQ(1U, test_api()->lines().size()); |
| 2691 } | 2754 } |
| 2692 } | 2755 } |
| 2693 | 2756 |
| 2694 TEST_P(RenderTextHarfBuzzTest, Multiline_Newline) { | 2757 TEST_P(RenderTextHarfBuzzTest, Multiline_Newline) { |
| 2695 const struct { | 2758 const struct { |
| 2696 const wchar_t* const text; | 2759 const wchar_t* const text; |
| 2697 const size_t lines_count; | 2760 const size_t lines_count; |
| 2698 // Ranges of the characters on each line preceding the newline. | 2761 // Ranges of the characters on each line preceding the newline. |
| 2699 const Range line_char_ranges[3]; | 2762 const Range line_char_ranges[3]; |
| 2700 } kTestStrings[] = { | 2763 } kTestStrings[] = { |
| 2701 {L"abc\ndef", 2ul, { Range(0, 3), Range(4, 7), Range::InvalidRange() } }, | 2764 {L"abc\ndef", 2ul, { Range(0, 3), Range(4, 7), Range::InvalidRange() } }, |
| 2702 {L"a \n b ", 2ul, { Range(0, 2), Range(3, 6), Range::InvalidRange() } }, | 2765 {L"a \n b ", 2ul, { Range(0, 2), Range(3, 6), Range::InvalidRange() } }, |
| 2703 {L"ab\n", 2ul, { Range(0, 2), Range(), Range::InvalidRange() } }, | 2766 {L"ab\n", 2ul, { Range(0, 2), Range(), Range::InvalidRange() } }, |
| 2704 {L"a\n\nb", 3ul, { Range(0, 1), Range(), Range(3, 4) } }, | 2767 {L"a\n\nb", 3ul, { Range(0, 1), Range(), Range(3, 4) } }, |
| 2705 {L"\nab", 2ul, { Range(), Range(1, 3), Range::InvalidRange() } }, | 2768 {L"\nab", 2ul, { Range(), Range(1, 3), Range::InvalidRange() } }, |
| 2706 {L"\n", 2ul, { Range(), Range(), Range::InvalidRange() } }, | 2769 {L"\n", 2ul, { Range(), Range(), Range::InvalidRange() } }, |
| 2707 }; | 2770 }; |
| 2708 | 2771 |
| 2709 RenderText* render_text = GetRenderText(); | 2772 RenderText* render_text = GetRenderText(); |
| 2710 render_text->SetDisplayRect(Rect(200, 1000)); | 2773 render_text->SetDisplayRect(Rect(200, 1000)); |
| 2711 render_text->SetMultiline(true); | 2774 render_text->SetMultiline(true); |
| 2712 | 2775 |
| 2713 for (size_t i = 0; i < arraysize(kTestStrings); ++i) { | 2776 for (size_t i = 0; i < arraysize(kTestStrings); ++i) { |
| 2714 SCOPED_TRACE(base::StringPrintf("kTestStrings[%" PRIuS "]", i)); | 2777 SCOPED_TRACE(base::StringPrintf("kTestStrings[%" PRIuS "]", i)); |
| 2715 render_text->SetText(WideToUTF16(kTestStrings[i].text)); | 2778 render_text->SetText(WideToUTF16(kTestStrings[i].text)); |
| 2716 render_text->Draw(canvas()); | 2779 render_text->Draw(canvas()); |
| 2717 EXPECT_EQ(kTestStrings[i].lines_count, render_text->lines_.size()); | 2780 EXPECT_EQ(kTestStrings[i].lines_count, test_api()->lines().size()); |
| 2718 if (kTestStrings[i].lines_count != render_text->lines_.size()) | 2781 if (kTestStrings[i].lines_count != test_api()->lines().size()) |
| 2719 continue; | 2782 continue; |
| 2720 | 2783 |
| 2721 for (size_t j = 0; j < kTestStrings[i].lines_count; ++j) { | 2784 for (size_t j = 0; j < kTestStrings[i].lines_count; ++j) { |
| 2722 SCOPED_TRACE(base::StringPrintf("Line %" PRIuS "", j)); | 2785 SCOPED_TRACE(base::StringPrintf("Line %" PRIuS "", j)); |
| 2723 // There might be multiple segments in one line. Merge all the segments | 2786 // There might be multiple segments in one line. Merge all the segments |
| 2724 // ranges in the same line. | 2787 // ranges in the same line. |
| 2725 const size_t segment_size = render_text->lines()[j].segments.size(); | 2788 const size_t segment_size = test_api()->lines()[j].segments.size(); |
| 2726 Range line_range; | 2789 Range line_range; |
| 2727 if (segment_size > 0) | 2790 if (segment_size > 0) |
| 2728 line_range = | 2791 line_range = Range( |
| 2729 Range(render_text->lines()[j].segments[0].char_range.start(), | 2792 test_api()->lines()[j].segments[0].char_range.start(), |
| 2730 render_text->lines()[j] | 2793 test_api()->lines()[j].segments[segment_size - 1].char_range.end()); |
| 2731 .segments[segment_size - 1] | |
| 2732 .char_range.end()); | |
| 2733 EXPECT_EQ(kTestStrings[i].line_char_ranges[j], line_range); | 2794 EXPECT_EQ(kTestStrings[i].line_char_ranges[j], line_range); |
| 2734 } | 2795 } |
| 2735 } | 2796 } |
| 2736 } | 2797 } |
| 2737 | 2798 |
| 2738 // Make sure that multiline mode ignores elide behavior. | 2799 // Make sure that multiline mode ignores elide behavior. |
| 2739 TEST_P(RenderTextHarfBuzzTest, Multiline_IgnoreElide) { | 2800 TEST_P(RenderTextHarfBuzzTest, Multiline_IgnoreElide) { |
| 2740 const wchar_t kTestString[] = | 2801 const wchar_t kTestString[] = |
| 2741 L"very very very long string xxxxxxxxxxxxxxxxxxxxxxxxxx"; | 2802 L"very very very long string xxxxxxxxxxxxxxxxxxxxxxxxxx"; |
| 2742 const wchar_t kEllipsis[] = L"\x2026"; | 2803 const wchar_t kEllipsis[] = L"\x2026"; |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2794 // arabic, 2nd line shorter | 2855 // arabic, 2nd line shorter |
| 2795 { L"\x62a\x62b\x62c\x62d\x62e\x62f\x630\n\x660\x661\x662\x663\x664", | 2856 { L"\x62a\x62b\x62c\x62d\x62e\x62f\x630\n\x660\x661\x662\x663\x664", |
| 2796 ALIGN_RIGHT }, | 2857 ALIGN_RIGHT }, |
| 2797 // arabic, 2nd line longer | 2858 // arabic, 2nd line longer |
| 2798 { L"\x660\x661\x662\x663\x664\n\x62a\x62b\x62c\x62d\x62e\x62f\x630", | 2859 { L"\x660\x661\x662\x663\x664\n\x62a\x62b\x62c\x62d\x62e\x62f\x630", |
| 2799 ALIGN_RIGHT }, | 2860 ALIGN_RIGHT }, |
| 2800 }; | 2861 }; |
| 2801 const int kGlyphSize = 5; | 2862 const int kGlyphSize = 5; |
| 2802 RenderTextHarfBuzz* render_text = GetRenderTextHarfBuzz(); | 2863 RenderTextHarfBuzz* render_text = GetRenderTextHarfBuzz(); |
| 2803 render_text->SetHorizontalAlignment(ALIGN_TO_HEAD); | 2864 render_text->SetHorizontalAlignment(ALIGN_TO_HEAD); |
| 2804 render_text->set_glyph_width_for_test(kGlyphSize); | 2865 SetGlyphWidth(kGlyphSize); |
| 2805 render_text->SetDisplayRect(Rect(100, 1000)); | 2866 render_text->SetDisplayRect(Rect(100, 1000)); |
| 2806 render_text->SetMultiline(true); | 2867 render_text->SetMultiline(true); |
| 2807 | 2868 |
| 2808 for (size_t i = 0; i < arraysize(kTestStrings); ++i) { | 2869 for (size_t i = 0; i < arraysize(kTestStrings); ++i) { |
| 2809 SCOPED_TRACE(base::StringPrintf("kTestStrings[%" PRIuS "] %ls", i, | 2870 SCOPED_TRACE(base::StringPrintf("kTestStrings[%" PRIuS "] %ls", i, |
| 2810 kTestStrings[i].text)); | 2871 kTestStrings[i].text)); |
| 2811 render_text->SetText(WideToUTF16(kTestStrings[i].text)); | 2872 render_text->SetText(WideToUTF16(kTestStrings[i].text)); |
| 2812 render_text->Draw(canvas()); | 2873 render_text->Draw(canvas()); |
| 2813 ASSERT_LE(2u, render_text->lines().size()); | 2874 ASSERT_LE(2u, test_api()->lines().size()); |
| 2814 if (kTestStrings[i].alignment == ALIGN_LEFT) { | 2875 if (kTestStrings[i].alignment == ALIGN_LEFT) { |
| 2815 EXPECT_EQ(0, render_text->GetAlignmentOffset(0).x()); | 2876 EXPECT_EQ(0, test_api()->GetAlignmentOffset(0).x()); |
| 2816 EXPECT_EQ(0, render_text->GetAlignmentOffset(1).x()); | 2877 EXPECT_EQ(0, test_api()->GetAlignmentOffset(1).x()); |
| 2817 } else { | 2878 } else { |
| 2818 std::vector<base::string16> lines = base::SplitString( | 2879 std::vector<base::string16> lines = base::SplitString( |
| 2819 base::WideToUTF16(kTestStrings[i].text), | 2880 base::WideToUTF16(kTestStrings[i].text), |
| 2820 base::string16(1, '\n'), base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); | 2881 base::string16(1, '\n'), base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); |
| 2821 ASSERT_EQ(2u, lines.size()); | 2882 ASSERT_EQ(2u, lines.size()); |
| 2822 int difference = (lines[0].length() - lines[1].length()) * kGlyphSize; | 2883 int difference = (lines[0].length() - lines[1].length()) * kGlyphSize; |
| 2823 EXPECT_EQ(render_text->GetAlignmentOffset(0).x() + difference, | 2884 EXPECT_EQ(test_api()->GetAlignmentOffset(0).x() + difference, |
| 2824 render_text->GetAlignmentOffset(1).x()); | 2885 test_api()->GetAlignmentOffset(1).x()); |
| 2825 } | 2886 } |
| 2826 } | 2887 } |
| 2827 } | 2888 } |
| 2828 | 2889 |
| 2829 TEST_P(RenderTextHarfBuzzTest, Multiline_WordWrapBehavior) { | 2890 TEST_P(RenderTextHarfBuzzTest, Multiline_WordWrapBehavior) { |
| 2830 const int kGlyphSize = 5; | 2891 const int kGlyphSize = 5; |
| 2831 const struct { | 2892 const struct { |
| 2832 const WordWrapBehavior behavior; | 2893 const WordWrapBehavior behavior; |
| 2833 const size_t num_lines; | 2894 const size_t num_lines; |
| 2834 const Range char_ranges[4]; | 2895 const Range char_ranges[4]; |
| 2835 } kTestScenarios[] = { | 2896 } kTestScenarios[] = { |
| 2836 { IGNORE_LONG_WORDS, 3u, | 2897 { IGNORE_LONG_WORDS, 3u, |
| 2837 { Range(0, 4), Range(4, 11), Range(11, 14), Range::InvalidRange() } }, | 2898 { Range(0, 4), Range(4, 11), Range(11, 14), Range::InvalidRange() } }, |
| 2838 { TRUNCATE_LONG_WORDS, 3u, | 2899 { TRUNCATE_LONG_WORDS, 3u, |
| 2839 { Range(0, 4), Range(4, 8), Range(11, 14), Range::InvalidRange() } }, | 2900 { Range(0, 4), Range(4, 8), Range(11, 14), Range::InvalidRange() } }, |
| 2840 { WRAP_LONG_WORDS, 4u, | 2901 { WRAP_LONG_WORDS, 4u, |
| 2841 { Range(0, 4), Range(4, 8), Range(8, 11), Range(11, 14) } }, | 2902 { Range(0, 4), Range(4, 8), Range(8, 11), Range(11, 14) } }, |
| 2842 // TODO(mukai): implement ELIDE_LONG_WORDS. It's not used right now. | 2903 // TODO(mukai): implement ELIDE_LONG_WORDS. It's not used right now. |
| 2843 }; | 2904 }; |
| 2844 RenderTextHarfBuzz* render_text = GetRenderTextHarfBuzz(); | 2905 RenderTextHarfBuzz* render_text = GetRenderTextHarfBuzz(); |
| 2845 render_text->SetMultiline(true); | 2906 render_text->SetMultiline(true); |
| 2846 render_text->SetText(ASCIIToUTF16("foo fooooo foo")); | 2907 render_text->SetText(ASCIIToUTF16("foo fooooo foo")); |
| 2847 render_text->set_glyph_width_for_test(kGlyphSize); | 2908 SetGlyphWidth(kGlyphSize); |
| 2848 render_text->SetDisplayRect(Rect(0, 0, kGlyphSize * 4, 0)); | 2909 render_text->SetDisplayRect(Rect(0, 0, kGlyphSize * 4, 0)); |
| 2849 | 2910 |
| 2850 for (size_t i = 0; i < arraysize(kTestScenarios); ++i) { | 2911 for (size_t i = 0; i < arraysize(kTestScenarios); ++i) { |
| 2851 SCOPED_TRACE(base::StringPrintf( | 2912 SCOPED_TRACE(base::StringPrintf( |
| 2852 "kTestScenarios[%" PRIuS "] %d", i, kTestScenarios[i].behavior)); | 2913 "kTestScenarios[%" PRIuS "] %d", i, kTestScenarios[i].behavior)); |
| 2853 render_text->SetWordWrapBehavior(kTestScenarios[i].behavior); | 2914 render_text->SetWordWrapBehavior(kTestScenarios[i].behavior); |
| 2854 render_text->Draw(canvas()); | 2915 render_text->Draw(canvas()); |
| 2855 | 2916 |
| 2856 ASSERT_EQ(kTestScenarios[i].num_lines, render_text->lines().size()); | 2917 ASSERT_EQ(kTestScenarios[i].num_lines, test_api()->lines().size()); |
| 2857 for (size_t j = 0; j < render_text->lines().size(); ++j) { | 2918 for (size_t j = 0; j < test_api()->lines().size(); ++j) { |
| 2858 SCOPED_TRACE(base::StringPrintf("%" PRIuS "-th line", j)); | 2919 SCOPED_TRACE(base::StringPrintf("%" PRIuS "-th line", j)); |
| 2859 EXPECT_EQ(kTestScenarios[i].char_ranges[j], | 2920 EXPECT_EQ(kTestScenarios[i].char_ranges[j], |
| 2860 render_text->lines()[j].segments[0].char_range); | 2921 test_api()->lines()[j].segments[0].char_range); |
| 2861 EXPECT_EQ(kTestScenarios[i].char_ranges[j].length() * kGlyphSize, | 2922 EXPECT_EQ(kTestScenarios[i].char_ranges[j].length() * kGlyphSize, |
| 2862 render_text->lines()[j].size.width()); | 2923 test_api()->lines()[j].size.width()); |
| 2863 } | 2924 } |
| 2864 } | 2925 } |
| 2865 } | 2926 } |
| 2866 | 2927 |
| 2867 TEST_P(RenderTextHarfBuzzTest, Multiline_LineBreakerBehavior) { | 2928 TEST_P(RenderTextHarfBuzzTest, Multiline_LineBreakerBehavior) { |
| 2868 const int kGlyphSize = 5; | 2929 const int kGlyphSize = 5; |
| 2869 const struct { | 2930 const struct { |
| 2870 const wchar_t* const text; | 2931 const wchar_t* const text; |
| 2871 const WordWrapBehavior behavior; | 2932 const WordWrapBehavior behavior; |
| 2872 const Range char_ranges[3]; | 2933 const Range char_ranges[3]; |
| (...skipping 21 matching lines...) Expand all Loading... |
| 2894 { L"asingleword", WRAP_LONG_WORDS, | 2955 { L"asingleword", WRAP_LONG_WORDS, |
| 2895 {Range(0, 4), Range(4, 8), Range(8, 11) } }, | 2956 {Range(0, 4), Range(4, 8), Range(8, 11) } }, |
| 2896 { L"That's good", WRAP_LONG_WORDS, | 2957 { L"That's good", WRAP_LONG_WORDS, |
| 2897 {Range(0, 4), Range(4, 7), Range(7, 11) } }, | 2958 {Range(0, 4), Range(4, 7), Range(7, 11) } }, |
| 2898 { L"That's \"g\".", WRAP_LONG_WORDS, | 2959 { L"That's \"g\".", WRAP_LONG_WORDS, |
| 2899 {Range(0, 4), Range(4, 7), Range(7, 11) } }, | 2960 {Range(0, 4), Range(4, 7), Range(7, 11) } }, |
| 2900 }; | 2961 }; |
| 2901 | 2962 |
| 2902 RenderTextHarfBuzz* render_text = GetRenderTextHarfBuzz(); | 2963 RenderTextHarfBuzz* render_text = GetRenderTextHarfBuzz(); |
| 2903 render_text->SetMultiline(true); | 2964 render_text->SetMultiline(true); |
| 2904 render_text->set_glyph_width_for_test(kGlyphSize); | 2965 SetGlyphWidth(kGlyphSize); |
| 2905 render_text->SetDisplayRect(Rect(0, 0, kGlyphSize * 4, 0)); | 2966 render_text->SetDisplayRect(Rect(0, 0, kGlyphSize * 4, 0)); |
| 2906 | 2967 |
| 2907 for (size_t i = 0; i < arraysize(kTestScenarios); ++i) { | 2968 for (size_t i = 0; i < arraysize(kTestScenarios); ++i) { |
| 2908 SCOPED_TRACE(base::StringPrintf("kTestStrings[%" PRIuS "]", i)); | 2969 SCOPED_TRACE(base::StringPrintf("kTestStrings[%" PRIuS "]", i)); |
| 2909 render_text->SetText(WideToUTF16(kTestScenarios[i].text)); | 2970 render_text->SetText(WideToUTF16(kTestScenarios[i].text)); |
| 2910 render_text->SetWordWrapBehavior(kTestScenarios[i].behavior); | 2971 render_text->SetWordWrapBehavior(kTestScenarios[i].behavior); |
| 2911 render_text->Draw(canvas()); | 2972 render_text->Draw(canvas()); |
| 2912 | 2973 |
| 2913 ASSERT_EQ(3u, render_text->lines().size()); | 2974 ASSERT_EQ(3u, test_api()->lines().size()); |
| 2914 for (size_t j = 0; j < render_text->lines().size(); ++j) { | 2975 for (size_t j = 0; j < test_api()->lines().size(); ++j) { |
| 2915 SCOPED_TRACE(base::StringPrintf("%" PRIuS "-th line", j)); | 2976 SCOPED_TRACE(base::StringPrintf("%" PRIuS "-th line", j)); |
| 2916 // Merge all the segments ranges in the same line. | 2977 // Merge all the segments ranges in the same line. |
| 2917 size_t segment_size = render_text->lines()[j].segments.size(); | 2978 size_t segment_size = test_api()->lines()[j].segments.size(); |
| 2918 Range line_range; | 2979 Range line_range; |
| 2919 if (segment_size > 0) | 2980 if (segment_size > 0) |
| 2920 line_range = | 2981 line_range = Range( |
| 2921 Range(render_text->lines()[j].segments[0].char_range.start(), | 2982 test_api()->lines()[j].segments[0].char_range.start(), |
| 2922 render_text->lines()[j] | 2983 test_api()->lines()[j].segments[segment_size - 1].char_range.end()); |
| 2923 .segments[segment_size - 1] | |
| 2924 .char_range.end()); | |
| 2925 EXPECT_EQ(kTestScenarios[i].char_ranges[j], line_range); | 2984 EXPECT_EQ(kTestScenarios[i].char_ranges[j], line_range); |
| 2926 EXPECT_EQ(kTestScenarios[i].char_ranges[j].length() * kGlyphSize, | 2985 EXPECT_EQ(kTestScenarios[i].char_ranges[j].length() * kGlyphSize, |
| 2927 render_text->lines()[j].size.width()); | 2986 test_api()->lines()[j].size.width()); |
| 2928 } | 2987 } |
| 2929 } | 2988 } |
| 2930 } | 2989 } |
| 2931 | 2990 |
| 2932 // Test that Surrogate pairs or combining character sequences do not get | 2991 // Test that Surrogate pairs or combining character sequences do not get |
| 2933 // separated by line breaking. | 2992 // separated by line breaking. |
| 2934 TEST_P(RenderTextHarfBuzzTest, Multiline_SurrogatePairsOrCombiningChars) { | 2993 TEST_P(RenderTextHarfBuzzTest, Multiline_SurrogatePairsOrCombiningChars) { |
| 2935 RenderTextHarfBuzz* render_text = GetRenderTextHarfBuzz(); | 2994 RenderTextHarfBuzz* render_text = GetRenderTextHarfBuzz(); |
| 2936 render_text->SetMultiline(true); | 2995 render_text->SetMultiline(true); |
| 2937 render_text->SetWordWrapBehavior(WRAP_LONG_WORDS); | 2996 render_text->SetWordWrapBehavior(WRAP_LONG_WORDS); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 2962 std::min(kSurrogateWidth, kCombiningCharsWidth) / 2, | 3021 std::min(kSurrogateWidth, kCombiningCharsWidth) / 2, |
| 2963 { Range(0, 2), Range(2, 3), Range(3, 5) } }, | 3022 { Range(0, 2), Range(2, 3), Range(3, 5) } }, |
| 2964 }; | 3023 }; |
| 2965 | 3024 |
| 2966 for (size_t i = 0; i < arraysize(kTestScenarios); ++i) { | 3025 for (size_t i = 0; i < arraysize(kTestScenarios); ++i) { |
| 2967 SCOPED_TRACE(base::StringPrintf("kTestStrings[%" PRIuS "]", i)); | 3026 SCOPED_TRACE(base::StringPrintf("kTestStrings[%" PRIuS "]", i)); |
| 2968 render_text->SetText(kTestScenarios[i].text); | 3027 render_text->SetText(kTestScenarios[i].text); |
| 2969 render_text->SetDisplayRect(Rect(0, 0, kTestScenarios[i].display_width, 0)); | 3028 render_text->SetDisplayRect(Rect(0, 0, kTestScenarios[i].display_width, 0)); |
| 2970 render_text->Draw(canvas()); | 3029 render_text->Draw(canvas()); |
| 2971 | 3030 |
| 2972 ASSERT_EQ(3u, render_text->lines().size()); | 3031 ASSERT_EQ(3u, test_api()->lines().size()); |
| 2973 for (size_t j = 0; j < render_text->lines().size(); ++j) { | 3032 for (size_t j = 0; j < test_api()->lines().size(); ++j) { |
| 2974 SCOPED_TRACE(base::StringPrintf("%" PRIuS "-th line", j)); | 3033 SCOPED_TRACE(base::StringPrintf("%" PRIuS "-th line", j)); |
| 2975 // There is only one segment in each line. | 3034 // There is only one segment in each line. |
| 2976 EXPECT_EQ(kTestScenarios[i].char_ranges[j], | 3035 EXPECT_EQ(kTestScenarios[i].char_ranges[j], |
| 2977 render_text->lines()[j].segments[0].char_range); | 3036 test_api()->lines()[j].segments[0].char_range); |
| 2978 } | 3037 } |
| 2979 } | 3038 } |
| 2980 } | 3039 } |
| 2981 | 3040 |
| 2982 // Test that Zero width characters have the correct line breaking behavior. | 3041 // Test that Zero width characters have the correct line breaking behavior. |
| 2983 TEST_P(RenderTextHarfBuzzTest, Multiline_ZeroWidthChars) { | 3042 TEST_P(RenderTextHarfBuzzTest, Multiline_ZeroWidthChars) { |
| 2984 RenderTextHarfBuzz* render_text = GetRenderTextHarfBuzz(); | 3043 RenderTextHarfBuzz* render_text = GetRenderTextHarfBuzz(); |
| 2985 render_text->SetMultiline(true); | 3044 render_text->SetMultiline(true); |
| 2986 render_text->SetWordWrapBehavior(WRAP_LONG_WORDS); | 3045 render_text->SetWordWrapBehavior(WRAP_LONG_WORDS); |
| 2987 | 3046 |
| 2988 const base::char16 kZeroWidthSpace = {0x200B}; | 3047 const base::char16 kZeroWidthSpace = {0x200B}; |
| 2989 const base::string16 text(UTF8ToUTF16("test") + kZeroWidthSpace + | 3048 const base::string16 text(UTF8ToUTF16("test") + kZeroWidthSpace + |
| 2990 UTF8ToUTF16("\n") + kZeroWidthSpace + | 3049 UTF8ToUTF16("\n") + kZeroWidthSpace + |
| 2991 UTF8ToUTF16("test.")); | 3050 UTF8ToUTF16("test.")); |
| 2992 const int kTestWidth = | 3051 const int kTestWidth = |
| 2993 GetStringWidth(UTF8ToUTF16("test"), render_text->font_list()); | 3052 GetStringWidth(UTF8ToUTF16("test"), render_text->font_list()); |
| 2994 const Range char_ranges[3] = {Range(0, 5), Range(6, 11), Range(11, 12)}; | 3053 const Range char_ranges[3] = {Range(0, 5), Range(6, 11), Range(11, 12)}; |
| 2995 | 3054 |
| 2996 render_text->SetText(text); | 3055 render_text->SetText(text); |
| 2997 render_text->SetDisplayRect(Rect(0, 0, kTestWidth, 0)); | 3056 render_text->SetDisplayRect(Rect(0, 0, kTestWidth, 0)); |
| 2998 render_text->Draw(canvas()); | 3057 render_text->Draw(canvas()); |
| 2999 | 3058 |
| 3000 ASSERT_EQ(3u, render_text->lines().size()); | 3059 ASSERT_EQ(3u, test_api()->lines().size()); |
| 3001 for (size_t j = 0; j < render_text->lines().size(); ++j) { | 3060 for (size_t j = 0; j < test_api()->lines().size(); ++j) { |
| 3002 SCOPED_TRACE(base::StringPrintf("%" PRIuS "-th line", j)); | 3061 SCOPED_TRACE(base::StringPrintf("%" PRIuS "-th line", j)); |
| 3003 int segment_size = render_text->lines()[j].segments.size(); | 3062 int segment_size = test_api()->lines()[j].segments.size(); |
| 3004 ASSERT_GT(segment_size, 0); | 3063 ASSERT_GT(segment_size, 0); |
| 3005 Range line_range( | 3064 Range line_range( |
| 3006 render_text->lines()[j].segments[0].char_range.start(), | 3065 test_api()->lines()[j].segments[0].char_range.start(), |
| 3007 render_text->lines()[j].segments[segment_size - 1].char_range.end()); | 3066 test_api()->lines()[j].segments[segment_size - 1].char_range.end()); |
| 3008 EXPECT_EQ(char_ranges[j], line_range); | 3067 EXPECT_EQ(char_ranges[j], line_range); |
| 3009 } | 3068 } |
| 3010 } | 3069 } |
| 3011 | 3070 |
| 3012 TEST_P(RenderTextHarfBuzzTest, NewlineWithoutMultilineFlag) { | 3071 TEST_P(RenderTextHarfBuzzTest, NewlineWithoutMultilineFlag) { |
| 3013 const wchar_t* kTestStrings[] = { | 3072 const wchar_t* kTestStrings[] = { |
| 3014 L"abc\ndef", L"a \n b ", L"ab\n", L"a\n\nb", L"\nab", L"\n", | 3073 L"abc\ndef", L"a \n b ", L"ab\n", L"a\n\nb", L"\nab", L"\n", |
| 3015 }; | 3074 }; |
| 3016 | 3075 |
| 3017 RenderText* render_text = GetRenderText(); | 3076 RenderText* render_text = GetRenderText(); |
| 3018 render_text->SetDisplayRect(Rect(200, 1000)); | 3077 render_text->SetDisplayRect(Rect(200, 1000)); |
| 3019 | 3078 |
| 3020 for (size_t i = 0; i < arraysize(kTestStrings); ++i) { | 3079 for (size_t i = 0; i < arraysize(kTestStrings); ++i) { |
| 3021 SCOPED_TRACE(base::StringPrintf("kTestStrings[%" PRIuS "]", i)); | 3080 SCOPED_TRACE(base::StringPrintf("kTestStrings[%" PRIuS "]", i)); |
| 3022 render_text->SetText(WideToUTF16(kTestStrings[i])); | 3081 render_text->SetText(WideToUTF16(kTestStrings[i])); |
| 3023 render_text->Draw(canvas()); | 3082 render_text->Draw(canvas()); |
| 3024 | 3083 |
| 3025 EXPECT_EQ(1U, render_text->lines_.size()); | 3084 EXPECT_EQ(1U, test_api()->lines().size()); |
| 3026 } | 3085 } |
| 3027 } | 3086 } |
| 3028 | 3087 |
| 3029 // Make sure the horizontal positions of runs in a line (left-to-right for | 3088 // Make sure the horizontal positions of runs in a line (left-to-right for |
| 3030 // LTR languages and right-to-left for RTL languages). | 3089 // LTR languages and right-to-left for RTL languages). |
| 3031 TEST_P(RenderTextHarfBuzzTest, HarfBuzz_HorizontalPositions) { | 3090 TEST_P(RenderTextHarfBuzzTest, HarfBuzz_HorizontalPositions) { |
| 3032 const struct { | 3091 const struct { |
| 3033 const wchar_t* const text; | 3092 const wchar_t* const text; |
| 3034 const Range first_run_char_range; | 3093 const Range first_run_char_range; |
| 3035 const Range second_run_char_range; | 3094 const Range second_run_char_range; |
| 3036 bool is_rtl; | 3095 bool is_rtl; |
| 3037 } kTestStrings[] = { | 3096 } kTestStrings[] = { |
| 3038 { L"abc\x3042\x3044\x3046\x3048\x304A", Range(0, 3), Range(3, 8), false }, | 3097 { L"abc\x3042\x3044\x3046\x3048\x304A", Range(0, 3), Range(3, 8), false }, |
| 3039 { L"\x062A\x0641\x0627\x062D" | 3098 { L"\x062A\x0641\x0627\x062D" |
| 3040 L"\x05EA\x05E4\x05D5\x05D6\x05D9\x05DA\x05DB\x05DD", | 3099 L"\x05EA\x05E4\x05D5\x05D6\x05D9\x05DA\x05DB\x05DD", |
| 3041 Range(0, 4), Range(4, 12), true }, | 3100 Range(0, 4), Range(4, 12), true }, |
| 3042 }; | 3101 }; |
| 3043 | 3102 |
| 3044 RenderTextHarfBuzz* render_text = GetRenderTextHarfBuzz(); | 3103 RenderTextHarfBuzz* render_text = GetRenderTextHarfBuzz(); |
| 3045 | 3104 |
| 3046 for (size_t i = 0; i < arraysize(kTestStrings); ++i) { | 3105 for (size_t i = 0; i < arraysize(kTestStrings); ++i) { |
| 3047 SCOPED_TRACE(base::StringPrintf("kTestStrings[%" PRIuS "]", i)); | 3106 SCOPED_TRACE(base::StringPrintf("kTestStrings[%" PRIuS "]", i)); |
| 3048 render_text->SetText(WideToUTF16(kTestStrings[i].text)); | 3107 render_text->SetText(WideToUTF16(kTestStrings[i].text)); |
| 3049 | 3108 |
| 3050 render_text->EnsureLayout(); | 3109 test_api()->EnsureLayout(); |
| 3051 const internal::TextRunList* run_list = render_text->GetRunList(); | 3110 const internal::TextRunList* run_list = GetHarfBuzzRunList(); |
| 3052 ASSERT_EQ(2U, run_list->runs().size()); | 3111 ASSERT_EQ(2U, run_list->runs().size()); |
| 3053 EXPECT_EQ(kTestStrings[i].first_run_char_range, run_list->runs()[0]->range); | 3112 EXPECT_EQ(kTestStrings[i].first_run_char_range, run_list->runs()[0]->range); |
| 3054 EXPECT_EQ(kTestStrings[i].second_run_char_range, | 3113 EXPECT_EQ(kTestStrings[i].second_run_char_range, |
| 3055 run_list->runs()[1]->range); | 3114 run_list->runs()[1]->range); |
| 3056 // If it's RTL, the visual order is reversed. | 3115 // If it's RTL, the visual order is reversed. |
| 3057 if (kTestStrings[i].is_rtl) { | 3116 if (kTestStrings[i].is_rtl) { |
| 3058 EXPECT_EQ(1U, run_list->logical_to_visual(0)); | 3117 EXPECT_EQ(1U, run_list->logical_to_visual(0)); |
| 3059 EXPECT_EQ(0U, run_list->logical_to_visual(1)); | 3118 EXPECT_EQ(0U, run_list->logical_to_visual(1)); |
| 3060 } else { | 3119 } else { |
| 3061 EXPECT_EQ(0U, run_list->logical_to_visual(0)); | 3120 EXPECT_EQ(0U, run_list->logical_to_visual(0)); |
| 3062 EXPECT_EQ(1U, run_list->logical_to_visual(1)); | 3121 EXPECT_EQ(1U, run_list->logical_to_visual(1)); |
| 3063 } | 3122 } |
| 3064 | 3123 |
| 3065 render_text->DrawVisualText(renderer()); | 3124 DrawVisualText(); |
| 3066 | 3125 |
| 3067 std::vector<TestSkiaTextRenderer::TextLog> text_log; | 3126 std::vector<TestSkiaTextRenderer::TextLog> text_log; |
| 3068 renderer()->GetTextLogAndReset(&text_log); | 3127 renderer()->GetTextLogAndReset(&text_log); |
| 3069 | 3128 |
| 3070 EXPECT_EQ(2U, text_log.size()); | 3129 EXPECT_EQ(2U, text_log.size()); |
| 3071 | 3130 |
| 3072 // Verifies the DrawText happens in the visual order and left-to-right. | 3131 // Verifies the DrawText happens in the visual order and left-to-right. |
| 3073 // If the text is RTL, the logically first run should be drawn at last. | 3132 // If the text is RTL, the logically first run should be drawn at last. |
| 3074 EXPECT_EQ(run_list->runs()[run_list->logical_to_visual(0)]->glyph_count, | 3133 EXPECT_EQ(run_list->runs()[run_list->logical_to_visual(0)]->glyph_count, |
| 3075 text_log[0].glyph_count); | 3134 text_log[0].glyph_count); |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3147 L"\x0e08\x0e33\x0E50", | 3206 L"\x0e08\x0e33\x0E50", |
| 3148 }; | 3207 }; |
| 3149 | 3208 |
| 3150 RenderTextHarfBuzz* render_text = GetRenderTextHarfBuzz(); | 3209 RenderTextHarfBuzz* render_text = GetRenderTextHarfBuzz(); |
| 3151 | 3210 |
| 3152 for (size_t i = 0; i < arraysize(cases); ++i) { | 3211 for (size_t i = 0; i < arraysize(cases); ++i) { |
| 3153 SCOPED_TRACE(base::StringPrintf("Case %" PRIuS, i)); | 3212 SCOPED_TRACE(base::StringPrintf("Case %" PRIuS, i)); |
| 3154 | 3213 |
| 3155 base::string16 text = WideToUTF16(cases[i]); | 3214 base::string16 text = WideToUTF16(cases[i]); |
| 3156 render_text->SetText(text); | 3215 render_text->SetText(text); |
| 3157 render_text->EnsureLayout(); | 3216 test_api()->EnsureLayout(); |
| 3158 internal::TextRunList* run_list = render_text->GetRunList(); | 3217 internal::TextRunList* run_list = GetHarfBuzzRunList(); |
| 3159 ASSERT_EQ(1U, run_list->size()); | 3218 ASSERT_EQ(1U, run_list->size()); |
| 3160 internal::TextRunHarfBuzz* run = run_list->runs()[0]; | 3219 internal::TextRunHarfBuzz* run = run_list->runs()[0]; |
| 3161 | 3220 |
| 3162 base::i18n::BreakIterator* iter = render_text->grapheme_iterator_.get(); | 3221 base::i18n::BreakIterator* iter = GetGraphemeIterator(); |
| 3163 auto first_grapheme_bounds = run->GetGraphemeBounds(iter, 0); | 3222 auto first_grapheme_bounds = run->GetGraphemeBounds(iter, 0); |
| 3164 EXPECT_EQ(first_grapheme_bounds, run->GetGraphemeBounds(iter, 1)); | 3223 EXPECT_EQ(first_grapheme_bounds, run->GetGraphemeBounds(iter, 1)); |
| 3165 auto second_grapheme_bounds = run->GetGraphemeBounds(iter, 2); | 3224 auto second_grapheme_bounds = run->GetGraphemeBounds(iter, 2); |
| 3166 EXPECT_EQ(first_grapheme_bounds.end(), second_grapheme_bounds.start()); | 3225 EXPECT_EQ(first_grapheme_bounds.end(), second_grapheme_bounds.start()); |
| 3167 } | 3226 } |
| 3168 } | 3227 } |
| 3169 | 3228 |
| 3170 // Test the partition of a multi-grapheme cluster into grapheme ranges. | 3229 // Test the partition of a multi-grapheme cluster into grapheme ranges. |
| 3171 TEST_P(RenderTextHarfBuzzTest, HarfBuzz_SubglyphGraphemePartition) { | 3230 TEST_P(RenderTextHarfBuzzTest, HarfBuzz_SubglyphGraphemePartition) { |
| 3172 struct { | 3231 struct { |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3227 RenderTextHarfBuzz* render_text = GetRenderTextHarfBuzz(); | 3286 RenderTextHarfBuzz* render_text = GetRenderTextHarfBuzz(); |
| 3228 const base::string16 mixed = WideToUTF16( | 3287 const base::string16 mixed = WideToUTF16( |
| 3229 L"\x05D0\x05D1" | 3288 L"\x05D0\x05D1" |
| 3230 L"1234" | 3289 L"1234" |
| 3231 L"\x05D2\x05D3" | 3290 L"\x05D2\x05D3" |
| 3232 L"abc"); | 3291 L"abc"); |
| 3233 render_text->SetText(mixed); | 3292 render_text->SetText(mixed); |
| 3234 | 3293 |
| 3235 // Get the run list for both display directions. | 3294 // Get the run list for both display directions. |
| 3236 render_text->SetDirectionalityMode(DIRECTIONALITY_FORCE_LTR); | 3295 render_text->SetDirectionalityMode(DIRECTIONALITY_FORCE_LTR); |
| 3237 render_text->EnsureLayout(); | 3296 test_api()->EnsureLayout(); |
| 3238 internal::TextRunList* run_list = render_text->GetRunList(); | 3297 internal::TextRunList* run_list = GetHarfBuzzRunList(); |
| 3239 ASSERT_EQ(4U, run_list->size()); | 3298 ASSERT_EQ(4U, run_list->size()); |
| 3240 EXPECT_TRUE(run_list->runs()[0]->is_rtl); | 3299 EXPECT_TRUE(run_list->runs()[0]->is_rtl); |
| 3241 EXPECT_FALSE(run_list->runs()[1]->is_rtl); | 3300 EXPECT_FALSE(run_list->runs()[1]->is_rtl); |
| 3242 EXPECT_TRUE(run_list->runs()[2]->is_rtl); | 3301 EXPECT_TRUE(run_list->runs()[2]->is_rtl); |
| 3243 EXPECT_FALSE(run_list->runs()[3]->is_rtl); | 3302 EXPECT_FALSE(run_list->runs()[3]->is_rtl); |
| 3244 | 3303 |
| 3245 // The Latin letters should appear to the right of the other runs. | 3304 // The Latin letters should appear to the right of the other runs. |
| 3246 EXPECT_EQ(2U, run_list->logical_to_visual(0)); | 3305 EXPECT_EQ(2U, run_list->logical_to_visual(0)); |
| 3247 EXPECT_EQ(1U, run_list->logical_to_visual(1)); | 3306 EXPECT_EQ(1U, run_list->logical_to_visual(1)); |
| 3248 EXPECT_EQ(0U, run_list->logical_to_visual(2)); | 3307 EXPECT_EQ(0U, run_list->logical_to_visual(2)); |
| 3249 EXPECT_EQ(3U, run_list->logical_to_visual(3)); | 3308 EXPECT_EQ(3U, run_list->logical_to_visual(3)); |
| 3250 | 3309 |
| 3251 render_text->SetDirectionalityMode(DIRECTIONALITY_FORCE_RTL); | 3310 render_text->SetDirectionalityMode(DIRECTIONALITY_FORCE_RTL); |
| 3252 render_text->EnsureLayout(); | 3311 test_api()->EnsureLayout(); |
| 3253 run_list = render_text->GetRunList(); | 3312 run_list = GetHarfBuzzRunList(); |
| 3254 ASSERT_EQ(4U, run_list->size()); | 3313 ASSERT_EQ(4U, run_list->size()); |
| 3255 EXPECT_TRUE(run_list->runs()[0]->is_rtl); | 3314 EXPECT_TRUE(run_list->runs()[0]->is_rtl); |
| 3256 EXPECT_FALSE(run_list->runs()[1]->is_rtl); | 3315 EXPECT_FALSE(run_list->runs()[1]->is_rtl); |
| 3257 EXPECT_TRUE(run_list->runs()[2]->is_rtl); | 3316 EXPECT_TRUE(run_list->runs()[2]->is_rtl); |
| 3258 EXPECT_FALSE(run_list->runs()[3]->is_rtl); | 3317 EXPECT_FALSE(run_list->runs()[3]->is_rtl); |
| 3259 | 3318 |
| 3260 // The Latin letters should appear to the left of the other runs. | 3319 // The Latin letters should appear to the left of the other runs. |
| 3261 EXPECT_EQ(3U, run_list->logical_to_visual(0)); | 3320 EXPECT_EQ(3U, run_list->logical_to_visual(0)); |
| 3262 EXPECT_EQ(2U, run_list->logical_to_visual(1)); | 3321 EXPECT_EQ(2U, run_list->logical_to_visual(1)); |
| 3263 EXPECT_EQ(1U, run_list->logical_to_visual(2)); | 3322 EXPECT_EQ(1U, run_list->logical_to_visual(2)); |
| 3264 EXPECT_EQ(0U, run_list->logical_to_visual(3)); | 3323 EXPECT_EQ(0U, run_list->logical_to_visual(3)); |
| 3265 } | 3324 } |
| 3266 | 3325 |
| 3267 TEST_P(RenderTextHarfBuzzTest, HarfBuzz_BreakRunsByUnicodeBlocks) { | 3326 TEST_P(RenderTextHarfBuzzTest, HarfBuzz_BreakRunsByUnicodeBlocks) { |
| 3268 RenderTextHarfBuzz* render_text = GetRenderTextHarfBuzz(); | 3327 RenderTextHarfBuzz* render_text = GetRenderTextHarfBuzz(); |
| 3269 | 3328 |
| 3270 // The '\x25B6' "play character" should break runs. http://crbug.com/278913 | 3329 // The '\x25B6' "play character" should break runs. http://crbug.com/278913 |
| 3271 render_text->SetText(WideToUTF16(L"x\x25B6y")); | 3330 render_text->SetText(WideToUTF16(L"x\x25B6y")); |
| 3272 render_text->EnsureLayout(); | 3331 test_api()->EnsureLayout(); |
| 3273 internal::TextRunList* run_list = render_text->GetRunList(); | 3332 internal::TextRunList* run_list = GetHarfBuzzRunList(); |
| 3274 ASSERT_EQ(3U, run_list->size()); | 3333 ASSERT_EQ(3U, run_list->size()); |
| 3275 EXPECT_EQ(Range(0, 1), run_list->runs()[0]->range); | 3334 EXPECT_EQ(Range(0, 1), run_list->runs()[0]->range); |
| 3276 EXPECT_EQ(Range(1, 2), run_list->runs()[1]->range); | 3335 EXPECT_EQ(Range(1, 2), run_list->runs()[1]->range); |
| 3277 EXPECT_EQ(Range(2, 3), run_list->runs()[2]->range); | 3336 EXPECT_EQ(Range(2, 3), run_list->runs()[2]->range); |
| 3278 | 3337 |
| 3279 render_text->SetText(WideToUTF16(L"x \x25B6 y")); | 3338 render_text->SetText(WideToUTF16(L"x \x25B6 y")); |
| 3280 render_text->EnsureLayout(); | 3339 test_api()->EnsureLayout(); |
| 3281 run_list = render_text->GetRunList(); | 3340 run_list = GetHarfBuzzRunList(); |
| 3282 ASSERT_EQ(4U, run_list->size()); | 3341 ASSERT_EQ(4U, run_list->size()); |
| 3283 EXPECT_EQ(Range(0, 2), run_list->runs()[0]->range); | 3342 EXPECT_EQ(Range(0, 2), run_list->runs()[0]->range); |
| 3284 EXPECT_EQ(Range(2, 3), run_list->runs()[1]->range); | 3343 EXPECT_EQ(Range(2, 3), run_list->runs()[1]->range); |
| 3285 EXPECT_EQ(Range(3, 4), run_list->runs()[2]->range); | 3344 EXPECT_EQ(Range(3, 4), run_list->runs()[2]->range); |
| 3286 EXPECT_EQ(Range(4, 5), run_list->runs()[3]->range); | 3345 EXPECT_EQ(Range(4, 5), run_list->runs()[3]->range); |
| 3287 } | 3346 } |
| 3288 | 3347 |
| 3289 TEST_P(RenderTextHarfBuzzTest, HarfBuzz_BreakRunsByEmoji) { | 3348 TEST_P(RenderTextHarfBuzzTest, HarfBuzz_BreakRunsByEmoji) { |
| 3290 RenderTextHarfBuzz* render_text = GetRenderTextHarfBuzz(); | 3349 RenderTextHarfBuzz* render_text = GetRenderTextHarfBuzz(); |
| 3291 | 3350 |
| 3292 // \xF0\x9F\x98\x81 (U+1F601) is smile icon emoji. \xE2\x9C\xA8 (U+2728) is | 3351 // \xF0\x9F\x98\x81 (U+1F601) is smile icon emoji. \xE2\x9C\xA8 (U+2728) is |
| 3293 // a sparkle icon. Both can be drawn with color emoji fonts, so runs should be | 3352 // a sparkle icon. Both can be drawn with color emoji fonts, so runs should be |
| 3294 // separated. See crbug.com/448909 | 3353 // separated. See crbug.com/448909 |
| 3295 render_text->SetText(UTF8ToUTF16("x\xF0\x9F\x98\x81y\xE2\x9C\xA8")); | 3354 render_text->SetText(UTF8ToUTF16("x\xF0\x9F\x98\x81y\xE2\x9C\xA8")); |
| 3296 render_text->EnsureLayout(); | 3355 test_api()->EnsureLayout(); |
| 3297 internal::TextRunList* run_list = render_text->GetRunList(); | 3356 internal::TextRunList* run_list = GetHarfBuzzRunList(); |
| 3298 ASSERT_EQ(4U, run_list->size()); | 3357 ASSERT_EQ(4U, run_list->size()); |
| 3299 EXPECT_EQ(Range(0, 1), run_list->runs()[0]->range); | 3358 EXPECT_EQ(Range(0, 1), run_list->runs()[0]->range); |
| 3300 // The length is 2 since U+1F601 is represented as a surrogate pair in UTF16. | 3359 // The length is 2 since U+1F601 is represented as a surrogate pair in UTF16. |
| 3301 EXPECT_EQ(Range(1, 3), run_list->runs()[1]->range); | 3360 EXPECT_EQ(Range(1, 3), run_list->runs()[1]->range); |
| 3302 EXPECT_EQ(Range(3, 4), run_list->runs()[2]->range); | 3361 EXPECT_EQ(Range(3, 4), run_list->runs()[2]->range); |
| 3303 EXPECT_EQ(Range(4, 5), run_list->runs()[3]->range); | 3362 EXPECT_EQ(Range(4, 5), run_list->runs()[3]->range); |
| 3304 } | 3363 } |
| 3305 | 3364 |
| 3306 TEST_P(RenderTextHarfBuzzTest, HarfBuzz_BreakRunsByAscii) { | 3365 TEST_P(RenderTextHarfBuzzTest, HarfBuzz_BreakRunsByAscii) { |
| 3307 RenderTextHarfBuzz* render_text = GetRenderTextHarfBuzz(); | 3366 RenderTextHarfBuzz* render_text = GetRenderTextHarfBuzz(); |
| 3308 | 3367 |
| 3309 // \xF0\x9F\x90\xB1 (U+1F431) is a cat face. It should be put into a separate | 3368 // \xF0\x9F\x90\xB1 (U+1F431) is a cat face. It should be put into a separate |
| 3310 // run from the ASCII period character. | 3369 // run from the ASCII period character. |
| 3311 render_text->SetText(UTF8ToUTF16("\xF0\x9F\x90\xB1.")); | 3370 render_text->SetText(UTF8ToUTF16("\xF0\x9F\x90\xB1.")); |
| 3312 render_text->EnsureLayout(); | 3371 test_api()->EnsureLayout(); |
| 3313 internal::TextRunList* run_list = render_text->GetRunList(); | 3372 internal::TextRunList* run_list = GetHarfBuzzRunList(); |
| 3314 ASSERT_EQ(2U, run_list->size()); | 3373 ASSERT_EQ(2U, run_list->size()); |
| 3315 // U+1F431 is represented as a surrogate pair in UTF16. | 3374 // U+1F431 is represented as a surrogate pair in UTF16. |
| 3316 EXPECT_EQ(Range(0, 2), run_list->runs()[0]->range); | 3375 EXPECT_EQ(Range(0, 2), run_list->runs()[0]->range); |
| 3317 EXPECT_EQ(Range(2, 3), run_list->runs()[1]->range); | 3376 EXPECT_EQ(Range(2, 3), run_list->runs()[1]->range); |
| 3318 } | 3377 } |
| 3319 | 3378 |
| 3320 TEST_P(RenderTextHarfBuzzTest, GlyphBounds) { | 3379 TEST_P(RenderTextHarfBuzzTest, GlyphBounds) { |
| 3321 const wchar_t* kTestStrings[] = { | 3380 const wchar_t* kTestStrings[] = { |
| 3322 L"asdf 1234 qwer", L"\x0647\x0654", L"\x0645\x0631\x062D\x0628\x0627" | 3381 L"asdf 1234 qwer", L"\x0647\x0654", L"\x0645\x0631\x062D\x0628\x0627" |
| 3323 }; | 3382 }; |
| 3324 RenderText* render_text = GetRenderText(); | 3383 RenderText* render_text = GetRenderText(); |
| 3325 | 3384 |
| 3326 for (size_t i = 0; i < arraysize(kTestStrings); ++i) { | 3385 for (size_t i = 0; i < arraysize(kTestStrings); ++i) { |
| 3327 render_text->SetText(WideToUTF16(kTestStrings[i])); | 3386 render_text->SetText(WideToUTF16(kTestStrings[i])); |
| 3328 render_text->EnsureLayout(); | 3387 test_api()->EnsureLayout(); |
| 3329 | 3388 |
| 3330 for (size_t j = 0; j < render_text->text().length(); ++j) | 3389 for (size_t j = 0; j < render_text->text().length(); ++j) |
| 3331 EXPECT_FALSE(render_text->GetGlyphBounds(j).is_empty()); | 3390 EXPECT_FALSE(render_text->GetGlyphBounds(j).is_empty()); |
| 3332 } | 3391 } |
| 3333 } | 3392 } |
| 3334 | 3393 |
| 3335 // Ensure that shaping with a non-existent font does not cause a crash. | 3394 // Ensure that shaping with a non-existent font does not cause a crash. |
| 3336 TEST_P(RenderTextHarfBuzzTest, HarfBuzz_NonExistentFont) { | 3395 TEST_P(RenderTextHarfBuzzTest, HarfBuzz_NonExistentFont) { |
| 3337 RenderTextHarfBuzz* render_text = GetRenderTextHarfBuzz(); | 3396 RenderTextHarfBuzz* render_text = GetRenderTextHarfBuzz(); |
| 3338 render_text->SetText(ASCIIToUTF16("test")); | 3397 render_text->SetText(ASCIIToUTF16("test")); |
| 3339 render_text->EnsureLayout(); | 3398 test_api()->EnsureLayout(); |
| 3340 internal::TextRunList* run_list = render_text->GetRunList(); | 3399 internal::TextRunList* run_list = GetHarfBuzzRunList(); |
| 3341 ASSERT_EQ(1U, run_list->size()); | 3400 ASSERT_EQ(1U, run_list->size()); |
| 3342 internal::TextRunHarfBuzz* run = run_list->runs()[0]; | 3401 internal::TextRunHarfBuzz* run = run_list->runs()[0]; |
| 3343 render_text->ShapeRunWithFont(render_text->text(), | 3402 ShapeRunWithFont(render_text->text(), Font("TheFontThatDoesntExist", 13), |
| 3344 Font("TheFontThatDoesntExist", 13), | 3403 FontRenderParams(), run); |
| 3345 FontRenderParams(), run); | |
| 3346 } | 3404 } |
| 3347 | 3405 |
| 3348 // Ensure an empty run returns sane values to queries. | 3406 // Ensure an empty run returns sane values to queries. |
| 3349 TEST_P(RenderTextHarfBuzzTest, HarfBuzz_EmptyRun) { | 3407 TEST_P(RenderTextHarfBuzzTest, HarfBuzz_EmptyRun) { |
| 3350 internal::TextRunHarfBuzz run((Font())); | 3408 internal::TextRunHarfBuzz run((Font())); |
| 3351 const base::string16 kString = ASCIIToUTF16("abcdefgh"); | 3409 const base::string16 kString = ASCIIToUTF16("abcdefgh"); |
| 3352 std::unique_ptr<base::i18n::BreakIterator> iter(new base::i18n::BreakIterator( | 3410 std::unique_ptr<base::i18n::BreakIterator> iter(new base::i18n::BreakIterator( |
| 3353 kString, base::i18n::BreakIterator::BREAK_CHARACTER)); | 3411 kString, base::i18n::BreakIterator::BREAK_CHARACTER)); |
| 3354 ASSERT_TRUE(iter->Init()); | 3412 ASSERT_TRUE(iter->Init()); |
| 3355 | 3413 |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3428 RenderTextHarfBuzz* render_text = GetRenderTextHarfBuzz(); | 3486 RenderTextHarfBuzz* render_text = GetRenderTextHarfBuzz(); |
| 3429 PlatformFontWin* font_win = new PlatformFontWin("Meiryo", 12); | 3487 PlatformFontWin* font_win = new PlatformFontWin("Meiryo", 12); |
| 3430 // Japanese name for Meiryo. This name won't be found in the system's linked | 3488 // Japanese name for Meiryo. This name won't be found in the system's linked |
| 3431 // fonts, forcing RTHB to try the Uniscribe font and its fallbacks. | 3489 // fonts, forcing RTHB to try the Uniscribe font and its fallbacks. |
| 3432 font_win->font_ref_->font_name_ = WideToUTF8(L"\x30e1\x30a4\x30ea\x30aa"); | 3490 font_win->font_ref_->font_name_ = WideToUTF8(L"\x30e1\x30a4\x30ea\x30aa"); |
| 3433 FontList font_list((Font(font_win))); | 3491 FontList font_list((Font(font_win))); |
| 3434 | 3492 |
| 3435 render_text->SetFontList(font_list); | 3493 render_text->SetFontList(font_list); |
| 3436 // Korean character "han". | 3494 // Korean character "han". |
| 3437 render_text->SetText(WideToUTF16(L"\xd55c")); | 3495 render_text->SetText(WideToUTF16(L"\xd55c")); |
| 3438 render_text->EnsureLayout(); | 3496 test_api()->EnsureLayout(); |
| 3439 internal::TextRunList* run_list = render_text->GetRunList(); | 3497 internal::TextRunList* run_list = GetHarfBuzzRunList(); |
| 3440 ASSERT_EQ(1U, run_list->size()); | 3498 ASSERT_EQ(1U, run_list->size()); |
| 3441 EXPECT_EQ(0U, run_list->runs()[0]->CountMissingGlyphs()); | 3499 EXPECT_EQ(0U, run_list->runs()[0]->CountMissingGlyphs()); |
| 3442 } | 3500 } |
| 3443 #endif // defined(OS_WIN) | 3501 #endif // defined(OS_WIN) |
| 3444 | 3502 |
| 3445 // Ensure that the fallback fonts offered by GetFallbackFonts() are | 3503 // Ensure that the fallback fonts offered by GetFallbackFonts() are |
| 3446 // tried. Note this test assumes the font "Arial" doesn't provide a unicode | 3504 // tried. Note this test assumes the font "Arial" doesn't provide a unicode |
| 3447 // glyph for a particular character, and that there exists a system fallback | 3505 // glyph for a particular character, and that there exists a system fallback |
| 3448 // font which does. | 3506 // font which does. |
| 3449 // TODO(msw): Fallback doesn't find a glyph on Linux. | 3507 // TODO(msw): Fallback doesn't find a glyph on Linux. |
| 3450 #if !defined(OS_LINUX) | 3508 #if !defined(OS_LINUX) |
| 3451 TEST_P(RenderTextHarfBuzzTest, HarfBuzz_UnicodeFallback) { | 3509 TEST_P(RenderTextHarfBuzzTest, HarfBuzz_UnicodeFallback) { |
| 3452 RenderTextHarfBuzz* render_text = GetRenderTextHarfBuzz(); | 3510 RenderTextHarfBuzz* render_text = GetRenderTextHarfBuzz(); |
| 3453 render_text->SetFontList(FontList("Arial, 12px")); | 3511 render_text->SetFontList(FontList("Arial, 12px")); |
| 3454 | 3512 |
| 3455 // Korean character "han". | 3513 // Korean character "han". |
| 3456 render_text->SetText(WideToUTF16(L"\xd55c")); | 3514 render_text->SetText(WideToUTF16(L"\xd55c")); |
| 3457 render_text->EnsureLayout(); | 3515 test_api()->EnsureLayout(); |
| 3458 internal::TextRunList* run_list = render_text->GetRunList(); | 3516 internal::TextRunList* run_list = GetHarfBuzzRunList(); |
| 3459 ASSERT_EQ(1U, run_list->size()); | 3517 ASSERT_EQ(1U, run_list->size()); |
| 3460 EXPECT_EQ(0U, run_list->runs()[0]->CountMissingGlyphs()); | 3518 EXPECT_EQ(0U, run_list->runs()[0]->CountMissingGlyphs()); |
| 3461 } | 3519 } |
| 3462 #endif // !defined(OS_LINUX) | 3520 #endif // !defined(OS_LINUX) |
| 3463 | 3521 |
| 3464 // http://crbug/624513 | 3522 // http://crbug/624513 |
| 3465 #if !defined(OS_WIN) | 3523 #if !defined(OS_WIN) |
| 3466 // Ensure that the width reported by RenderText is sufficient for drawing. Draws | 3524 // Ensure that the width reported by RenderText is sufficient for drawing. Draws |
| 3467 // to a canvas and checks if any pixel beyond the bounding rectangle is colored. | 3525 // to a canvas and checks if any pixel beyond the bounding rectangle is colored. |
| 3468 TEST_P(RenderTextTest, TextDoesntClip) { | 3526 TEST_P(RenderTextTest, TextDoesntClip) { |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3629 } | 3687 } |
| 3630 } | 3688 } |
| 3631 | 3689 |
| 3632 #if defined(OS_MACOSX) | 3690 #if defined(OS_MACOSX) |
| 3633 TEST_P(RenderTextMacTest, Mac_ElidedText) { | 3691 TEST_P(RenderTextMacTest, Mac_ElidedText) { |
| 3634 RenderTextMac* render_text = GetRenderTextMac(); | 3692 RenderTextMac* render_text = GetRenderTextMac(); |
| 3635 base::string16 text(ASCIIToUTF16("This is an example.")); | 3693 base::string16 text(ASCIIToUTF16("This is an example.")); |
| 3636 render_text->SetText(text); | 3694 render_text->SetText(text); |
| 3637 Size string_size = render_text->GetStringSize(); | 3695 Size string_size = render_text->GetStringSize(); |
| 3638 render_text->SetDisplayRect(Rect(string_size)); | 3696 render_text->SetDisplayRect(Rect(string_size)); |
| 3639 render_text->EnsureLayout(); | 3697 test_api()->EnsureLayout(); |
| 3640 // NOTE: Character and glyph counts are only comparable for simple text. | 3698 // NOTE: Character and glyph counts are only comparable for simple text. |
| 3641 EXPECT_EQ(text.size(), | 3699 EXPECT_EQ(text.size(), |
| 3642 static_cast<size_t>(CTLineGetGlyphCount(render_text->line_))); | 3700 static_cast<size_t>(CTLineGetGlyphCount(GetCoreTextLine()))); |
| 3643 | 3701 |
| 3644 render_text->SetElideBehavior(ELIDE_TAIL); | 3702 render_text->SetElideBehavior(ELIDE_TAIL); |
| 3645 string_size.set_width(string_size.width() / 2); | 3703 string_size.set_width(string_size.width() / 2); |
| 3646 render_text->SetDisplayRect(Rect(string_size)); | 3704 render_text->SetDisplayRect(Rect(string_size)); |
| 3647 render_text->EnsureLayout(); | 3705 test_api()->EnsureLayout(); |
| 3648 CFIndex glyph_count = CTLineGetGlyphCount(render_text->line_); | 3706 CFIndex glyph_count = CTLineGetGlyphCount(GetCoreTextLine()); |
| 3649 EXPECT_GT(text.size(), static_cast<size_t>(glyph_count)); | 3707 EXPECT_GT(text.size(), static_cast<size_t>(glyph_count)); |
| 3650 EXPECT_NE(0, glyph_count); | 3708 EXPECT_NE(0, glyph_count); |
| 3651 } | 3709 } |
| 3652 #endif // defined(OS_MACOSX) | 3710 #endif // defined(OS_MACOSX) |
| 3653 | 3711 |
| 3654 // Ensure color changes are picked up by the RenderText implementation. | 3712 // Ensure color changes are picked up by the RenderText implementation. |
| 3655 TEST_P(RenderTextTest, ColorChange) { | 3713 TEST_P(RenderTextTest, ColorChange) { |
| 3656 RenderText* render_text = GetRenderText(); | 3714 RenderText* render_text = GetRenderText(); |
| 3657 render_text->SetText(ASCIIToUTF16("x")); | 3715 render_text->SetText(ASCIIToUTF16("x")); |
| 3658 DrawVisualText(); | 3716 DrawVisualText(); |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3746 ::testing::Values(RENDER_TEXT_HARFBUZZ), | 3804 ::testing::Values(RENDER_TEXT_HARFBUZZ), |
| 3747 PrintRenderTextBackend()); | 3805 PrintRenderTextBackend()); |
| 3748 #endif | 3806 #endif |
| 3749 | 3807 |
| 3750 INSTANTIATE_TEST_CASE_P(, | 3808 INSTANTIATE_TEST_CASE_P(, |
| 3751 RenderTextHarfBuzzTest, | 3809 RenderTextHarfBuzzTest, |
| 3752 ::testing::Values(RENDER_TEXT_HARFBUZZ), | 3810 ::testing::Values(RENDER_TEXT_HARFBUZZ), |
| 3753 PrintRenderTextBackend()); | 3811 PrintRenderTextBackend()); |
| 3754 | 3812 |
| 3755 } // namespace gfx | 3813 } // namespace gfx |
| OLD | NEW |