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 <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/format_macros.h" | 9 #include "base/format_macros.h" |
10 #include "base/i18n/break_iterator.h" | 10 #include "base/i18n/break_iterator.h" |
(...skipping 2592 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2603 EXPECT_EQ(Range(0, 0), run.CharRangeToGlyphRange(Range(4, 5))); | 2603 EXPECT_EQ(Range(0, 0), run.CharRangeToGlyphRange(Range(4, 5))); |
2604 EXPECT_EQ(Range(0, 0), | 2604 EXPECT_EQ(Range(0, 0), |
2605 internal::RoundRangeF(run.GetGraphemeBounds(iter.get(), 4))); | 2605 internal::RoundRangeF(run.GetGraphemeBounds(iter.get(), 4))); |
2606 Range chars; | 2606 Range chars; |
2607 Range glyphs; | 2607 Range glyphs; |
2608 run.GetClusterAt(4, &chars, &glyphs); | 2608 run.GetClusterAt(4, &chars, &glyphs); |
2609 EXPECT_EQ(Range(3, 8), chars); | 2609 EXPECT_EQ(Range(3, 8), chars); |
2610 EXPECT_EQ(Range(0, 0), glyphs); | 2610 EXPECT_EQ(Range(0, 0), glyphs); |
2611 } | 2611 } |
2612 | 2612 |
| 2613 // Ensure the line breaker doesn't compute the word's width bigger than the |
| 2614 // actual size. See http://crbug.com/470073 |
| 2615 TEST_F(RenderTextTest, HarfBuzz_WordWidthWithDiacritics) { |
| 2616 RenderTextHarfBuzz render_text; |
| 2617 const base::string16 kWord = WideToUTF16(L"\u0906\u092A\u0915\u0947 "); |
| 2618 render_text.SetText(kWord); |
| 2619 const gfx::SizeF text_size = render_text.GetStringSizeF(); |
| 2620 |
| 2621 render_text.SetText(kWord + kWord); |
| 2622 render_text.SetMultiline(true); |
| 2623 EXPECT_EQ(text_size.width() * 2, render_text.GetStringSizeF().width()); |
| 2624 EXPECT_EQ(text_size.height(), render_text.GetStringSizeF().height()); |
| 2625 render_text.SetDisplayRect(gfx::Rect(0, 0, std::ceil(text_size.width()), 0)); |
| 2626 EXPECT_NEAR(text_size.width(), render_text.GetStringSizeF().width(), 1.0f); |
| 2627 EXPECT_EQ(text_size.height() * 2, render_text.GetStringSizeF().height()); |
| 2628 } |
| 2629 |
2613 // Ensure a string fits in a display rect with a width equal to the string's. | 2630 // Ensure a string fits in a display rect with a width equal to the string's. |
2614 TEST_F(RenderTextTest, StringFitsOwnWidth) { | 2631 TEST_F(RenderTextTest, StringFitsOwnWidth) { |
2615 scoped_ptr<RenderText> render_text(RenderText::CreateInstance()); | 2632 scoped_ptr<RenderText> render_text(RenderText::CreateInstance()); |
2616 const base::string16 kString = ASCIIToUTF16("www.example.com"); | 2633 const base::string16 kString = ASCIIToUTF16("www.example.com"); |
2617 | 2634 |
2618 render_text->SetText(kString); | 2635 render_text->SetText(kString); |
2619 render_text->ApplyStyle(BOLD, true, Range(0, 3)); | 2636 render_text->ApplyStyle(BOLD, true, Range(0, 3)); |
2620 render_text->SetElideBehavior(ELIDE_TAIL); | 2637 render_text->SetElideBehavior(ELIDE_TAIL); |
2621 | 2638 |
2622 render_text->SetDisplayRect(Rect(0, 0, 500, 100)); | 2639 render_text->SetDisplayRect(Rect(0, 0, 500, 100)); |
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2855 string_size.set_width(string_size.width() / 2); | 2872 string_size.set_width(string_size.width() / 2); |
2856 render_text.SetDisplayRect(gfx::Rect(string_size)); | 2873 render_text.SetDisplayRect(gfx::Rect(string_size)); |
2857 render_text.EnsureLayout(); | 2874 render_text.EnsureLayout(); |
2858 CFIndex glyph_count = CTLineGetGlyphCount(render_text.line_); | 2875 CFIndex glyph_count = CTLineGetGlyphCount(render_text.line_); |
2859 EXPECT_GT(text.size(), static_cast<size_t>(glyph_count)); | 2876 EXPECT_GT(text.size(), static_cast<size_t>(glyph_count)); |
2860 EXPECT_NE(0, glyph_count); | 2877 EXPECT_NE(0, glyph_count); |
2861 } | 2878 } |
2862 #endif | 2879 #endif |
2863 | 2880 |
2864 } // namespace gfx | 2881 } // namespace gfx |
OLD | NEW |