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 405 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
416 GetRenderTextHarfBuzz()->set_glyph_width_for_test(test_width); | 416 GetRenderTextHarfBuzz()->set_glyph_width_for_test(test_width); |
417 } | 417 } |
418 | 418 |
419 bool ShapeRunWithFont(const base::string16& text, | 419 bool ShapeRunWithFont(const base::string16& text, |
420 const Font& font, | 420 const Font& font, |
421 const FontRenderParams& params, | 421 const FontRenderParams& params, |
422 internal::TextRunHarfBuzz* run) { | 422 internal::TextRunHarfBuzz* run) { |
423 return GetRenderTextHarfBuzz()->ShapeRunWithFont(text, font, params, run); | 423 return GetRenderTextHarfBuzz()->ShapeRunWithFont(text, font, params, run); |
424 } | 424 } |
425 | 425 |
426 base::i18n::BreakIterator* GetGraphemeIterator() { | |
427 return GetRenderTextHarfBuzz()->GetGraphemeIterator(); | |
428 } | |
429 | |
430 private: | 426 private: |
431 DISALLOW_COPY_AND_ASSIGN(RenderTextHarfBuzzTest); | 427 DISALLOW_COPY_AND_ASSIGN(RenderTextHarfBuzzTest); |
432 }; | 428 }; |
433 | 429 |
434 #if defined(OS_MACOSX) | 430 #if defined(OS_MACOSX) |
435 // Test fixture class. Use for tests which are only to be run for RenderTextMac. | 431 // Test fixture class. Use for tests which are only to be run for RenderTextMac. |
436 class RenderTextMacTest : public RenderTextTest { | 432 class RenderTextMacTest : public RenderTextTest { |
437 public: | 433 public: |
438 RenderTextMacTest() {} | 434 RenderTextMacTest() {} |
439 | 435 |
(...skipping 2771 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3211 for (size_t i = 0; i < arraysize(cases); ++i) { | 3207 for (size_t i = 0; i < arraysize(cases); ++i) { |
3212 SCOPED_TRACE(base::StringPrintf("Case %" PRIuS, i)); | 3208 SCOPED_TRACE(base::StringPrintf("Case %" PRIuS, i)); |
3213 | 3209 |
3214 base::string16 text = WideToUTF16(cases[i]); | 3210 base::string16 text = WideToUTF16(cases[i]); |
3215 render_text->SetText(text); | 3211 render_text->SetText(text); |
3216 test_api()->EnsureLayout(); | 3212 test_api()->EnsureLayout(); |
3217 internal::TextRunList* run_list = GetHarfBuzzRunList(); | 3213 internal::TextRunList* run_list = GetHarfBuzzRunList(); |
3218 ASSERT_EQ(1U, run_list->size()); | 3214 ASSERT_EQ(1U, run_list->size()); |
3219 internal::TextRunHarfBuzz* run = run_list->runs()[0]; | 3215 internal::TextRunHarfBuzz* run = run_list->runs()[0]; |
3220 | 3216 |
3221 base::i18n::BreakIterator* iter = GetGraphemeIterator(); | 3217 auto first_grapheme_bounds = run->GetGraphemeBounds(render_text, 0); |
3222 auto first_grapheme_bounds = run->GetGraphemeBounds(iter, 0); | 3218 EXPECT_EQ(first_grapheme_bounds, run->GetGraphemeBounds(render_text, 1)); |
3223 EXPECT_EQ(first_grapheme_bounds, run->GetGraphemeBounds(iter, 1)); | 3219 auto second_grapheme_bounds = run->GetGraphemeBounds(render_text, 2); |
3224 auto second_grapheme_bounds = run->GetGraphemeBounds(iter, 2); | |
3225 EXPECT_EQ(first_grapheme_bounds.end(), second_grapheme_bounds.start()); | 3220 EXPECT_EQ(first_grapheme_bounds.end(), second_grapheme_bounds.start()); |
3226 } | 3221 } |
3227 } | 3222 } |
3228 | 3223 |
3229 // Test the partition of a multi-grapheme cluster into grapheme ranges. | 3224 // Test the partition of a multi-grapheme cluster into grapheme ranges. |
3230 TEST_P(RenderTextHarfBuzzTest, HarfBuzz_SubglyphGraphemePartition) { | 3225 TEST_P(RenderTextHarfBuzzTest, HarfBuzz_SubglyphGraphemePartition) { |
3231 struct { | 3226 struct { |
3232 uint32_t glyph_to_char[2]; | 3227 uint32_t glyph_to_char[2]; |
3233 Range bounds[4]; | 3228 Range bounds[4]; |
3234 bool is_rtl; | 3229 bool is_rtl; |
(...skipping 20 matching lines...) Expand all Loading... | |
3255 }, | 3250 }, |
3256 }; | 3251 }; |
3257 | 3252 |
3258 internal::TextRunHarfBuzz run((Font())); | 3253 internal::TextRunHarfBuzz run((Font())); |
3259 run.range = Range(0, 4); | 3254 run.range = Range(0, 4); |
3260 run.glyph_count = 2; | 3255 run.glyph_count = 2; |
3261 run.glyph_to_char.resize(2); | 3256 run.glyph_to_char.resize(2); |
3262 run.positions.reset(new SkPoint[4]); | 3257 run.positions.reset(new SkPoint[4]); |
3263 run.width = 20; | 3258 run.width = 20; |
3264 | 3259 |
3260 RenderTextHarfBuzz* render_text = GetRenderTextHarfBuzz(); | |
3265 const base::string16 kString = ASCIIToUTF16("abcd"); | 3261 const base::string16 kString = ASCIIToUTF16("abcd"); |
msw
2016/09/30 19:10:17
optional nit: inline |render_text->SetText(ASCIITo
Alexei Svitkine (slow)
2016/09/30 19:14:16
Done.
| |
3266 std::unique_ptr<base::i18n::BreakIterator> iter(new base::i18n::BreakIterator( | 3262 render_text->SetText(kString); |
3267 kString, base::i18n::BreakIterator::BREAK_CHARACTER)); | |
3268 ASSERT_TRUE(iter->Init()); | |
3269 | 3263 |
3270 for (size_t i = 0; i < arraysize(cases); ++i) { | 3264 for (size_t i = 0; i < arraysize(cases); ++i) { |
3271 std::copy(cases[i].glyph_to_char, cases[i].glyph_to_char + 2, | 3265 std::copy(cases[i].glyph_to_char, cases[i].glyph_to_char + 2, |
3272 run.glyph_to_char.begin()); | 3266 run.glyph_to_char.begin()); |
3273 run.is_rtl = cases[i].is_rtl; | 3267 run.is_rtl = cases[i].is_rtl; |
3274 for (int j = 0; j < 2; ++j) | 3268 for (int j = 0; j < 2; ++j) |
3275 run.positions[j].set(j * 10, 0); | 3269 run.positions[j].set(j * 10, 0); |
3276 | 3270 |
3277 for (size_t j = 0; j < 4; ++j) { | 3271 for (size_t j = 0; j < 4; ++j) { |
3278 SCOPED_TRACE(base::StringPrintf("Case %" PRIuS ", char %" PRIuS, i, j)); | 3272 SCOPED_TRACE(base::StringPrintf("Case %" PRIuS ", char %" PRIuS, i, j)); |
3279 EXPECT_EQ(cases[i].bounds[j], | 3273 EXPECT_EQ(cases[i].bounds[j], |
3280 run.GetGraphemeBounds(iter.get(), j).Round()); | 3274 run.GetGraphemeBounds(render_text, j).Round()); |
3281 } | 3275 } |
3282 } | 3276 } |
3283 } | 3277 } |
3284 | 3278 |
3285 TEST_P(RenderTextHarfBuzzTest, HarfBuzz_RunDirection) { | 3279 TEST_P(RenderTextHarfBuzzTest, HarfBuzz_RunDirection) { |
3286 RenderTextHarfBuzz* render_text = GetRenderTextHarfBuzz(); | 3280 RenderTextHarfBuzz* render_text = GetRenderTextHarfBuzz(); |
3287 const base::string16 mixed = WideToUTF16( | 3281 const base::string16 mixed = WideToUTF16( |
3288 L"\x05D0\x05D1" | 3282 L"\x05D0\x05D1" |
3289 L"1234" | 3283 L"1234" |
3290 L"\x05D2\x05D3" | 3284 L"\x05D2\x05D3" |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3399 internal::TextRunList* run_list = GetHarfBuzzRunList(); | 3393 internal::TextRunList* run_list = GetHarfBuzzRunList(); |
3400 ASSERT_EQ(1U, run_list->size()); | 3394 ASSERT_EQ(1U, run_list->size()); |
3401 internal::TextRunHarfBuzz* run = run_list->runs()[0]; | 3395 internal::TextRunHarfBuzz* run = run_list->runs()[0]; |
3402 ShapeRunWithFont(render_text->text(), Font("TheFontThatDoesntExist", 13), | 3396 ShapeRunWithFont(render_text->text(), Font("TheFontThatDoesntExist", 13), |
3403 FontRenderParams(), run); | 3397 FontRenderParams(), run); |
3404 } | 3398 } |
3405 | 3399 |
3406 // Ensure an empty run returns sane values to queries. | 3400 // Ensure an empty run returns sane values to queries. |
3407 TEST_P(RenderTextHarfBuzzTest, HarfBuzz_EmptyRun) { | 3401 TEST_P(RenderTextHarfBuzzTest, HarfBuzz_EmptyRun) { |
3408 internal::TextRunHarfBuzz run((Font())); | 3402 internal::TextRunHarfBuzz run((Font())); |
3403 RenderTextHarfBuzz* render_text = GetRenderTextHarfBuzz(); | |
3409 const base::string16 kString = ASCIIToUTF16("abcdefgh"); | 3404 const base::string16 kString = ASCIIToUTF16("abcdefgh"); |
msw
2016/09/30 19:10:17
ditto optional nit: inline |render_text->SetText(A
Alexei Svitkine (slow)
2016/09/30 19:14:16
Done.
| |
3410 std::unique_ptr<base::i18n::BreakIterator> iter(new base::i18n::BreakIterator( | 3405 render_text->SetText(kString); |
3411 kString, base::i18n::BreakIterator::BREAK_CHARACTER)); | |
3412 ASSERT_TRUE(iter->Init()); | |
3413 | 3406 |
3414 run.range = Range(3, 8); | 3407 run.range = Range(3, 8); |
3415 run.glyph_count = 0; | 3408 run.glyph_count = 0; |
3416 EXPECT_EQ(Range(0, 0), run.CharRangeToGlyphRange(Range(4, 5))); | 3409 EXPECT_EQ(Range(0, 0), run.CharRangeToGlyphRange(Range(4, 5))); |
3417 EXPECT_EQ(Range(0, 0), run.GetGraphemeBounds(iter.get(), 4).Round()); | 3410 EXPECT_EQ(Range(0, 0), run.GetGraphemeBounds(render_text, 4).Round()); |
3418 Range chars; | 3411 Range chars; |
3419 Range glyphs; | 3412 Range glyphs; |
3420 run.GetClusterAt(4, &chars, &glyphs); | 3413 run.GetClusterAt(4, &chars, &glyphs); |
3421 EXPECT_EQ(Range(3, 8), chars); | 3414 EXPECT_EQ(Range(3, 8), chars); |
3422 EXPECT_EQ(Range(0, 0), glyphs); | 3415 EXPECT_EQ(Range(0, 0), glyphs); |
3423 } | 3416 } |
3424 | 3417 |
3425 // Ensure the line breaker doesn't compute the word's width bigger than the | 3418 // Ensure the line breaker doesn't compute the word's width bigger than the |
3426 // actual size. See http://crbug.com/470073 | 3419 // actual size. See http://crbug.com/470073 |
3427 TEST_P(RenderTextHarfBuzzTest, HarfBuzz_WordWidthWithDiacritics) { | 3420 TEST_P(RenderTextHarfBuzzTest, HarfBuzz_WordWidthWithDiacritics) { |
(...skipping 376 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3804 ::testing::Values(RENDER_TEXT_HARFBUZZ), | 3797 ::testing::Values(RENDER_TEXT_HARFBUZZ), |
3805 PrintRenderTextBackend()); | 3798 PrintRenderTextBackend()); |
3806 #endif | 3799 #endif |
3807 | 3800 |
3808 INSTANTIATE_TEST_CASE_P(, | 3801 INSTANTIATE_TEST_CASE_P(, |
3809 RenderTextHarfBuzzTest, | 3802 RenderTextHarfBuzzTest, |
3810 ::testing::Values(RENDER_TEXT_HARFBUZZ), | 3803 ::testing::Values(RENDER_TEXT_HARFBUZZ), |
3811 PrintRenderTextBackend()); | 3804 PrintRenderTextBackend()); |
3812 | 3805 |
3813 } // namespace gfx | 3806 } // namespace gfx |
OLD | NEW |