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 1488 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1499 render_text->SetText(UTF8ToUTF16(" ")); | 1499 render_text->SetText(UTF8ToUTF16(" ")); |
1500 EXPECT_EQ(font_list.GetHeight(), render_text->GetStringSize().height()); | 1500 EXPECT_EQ(font_list.GetHeight(), render_text->GetStringSize().height()); |
1501 EXPECT_EQ(font_list.GetBaseline(), render_text->GetBaseline()); | 1501 EXPECT_EQ(font_list.GetBaseline(), render_text->GetBaseline()); |
1502 } | 1502 } |
1503 #endif // !defined(OS_MACOSX) | 1503 #endif // !defined(OS_MACOSX) |
1504 | 1504 |
1505 TEST_F(RenderTextTest, StringSizeRespectsFontListMetrics) { | 1505 TEST_F(RenderTextTest, StringSizeRespectsFontListMetrics) { |
1506 // Check that Arial and Symbol have different font metrics. | 1506 // Check that Arial and Symbol have different font metrics. |
1507 Font arial_font("Arial", 16); | 1507 Font arial_font("Arial", 16); |
1508 ASSERT_EQ("arial", | 1508 ASSERT_EQ("arial", |
1509 base::StringToLowerASCII(arial_font.GetActualFontNameForTesting())); | 1509 base::ToLowerASCII(arial_font.GetActualFontNameForTesting())); |
1510 Font symbol_font("Symbol", 16); | 1510 Font symbol_font("Symbol", 16); |
1511 ASSERT_EQ("symbol", | 1511 ASSERT_EQ("symbol", |
1512 base::StringToLowerASCII( | 1512 base::ToLowerASCII(symbol_font.GetActualFontNameForTesting())); |
1513 symbol_font.GetActualFontNameForTesting())); | |
1514 EXPECT_NE(arial_font.GetHeight(), symbol_font.GetHeight()); | 1513 EXPECT_NE(arial_font.GetHeight(), symbol_font.GetHeight()); |
1515 EXPECT_NE(arial_font.GetBaseline(), symbol_font.GetBaseline()); | 1514 EXPECT_NE(arial_font.GetBaseline(), symbol_font.GetBaseline()); |
1516 // "a" should be rendered with Arial, not with Symbol. | 1515 // "a" should be rendered with Arial, not with Symbol. |
1517 const char* arial_font_text = "a"; | 1516 const char* arial_font_text = "a"; |
1518 // "®" (registered trademark symbol) should be rendered with Symbol, | 1517 // "®" (registered trademark symbol) should be rendered with Symbol, |
1519 // not with Arial. | 1518 // not with Arial. |
1520 const char* symbol_font_text = "\xC2\xAE"; | 1519 const char* symbol_font_text = "\xC2\xAE"; |
1521 | 1520 |
1522 Font smaller_font = arial_font; | 1521 Font smaller_font = arial_font; |
1523 Font larger_font = symbol_font; | 1522 Font larger_font = symbol_font; |
(...skipping 1366 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2890 // TODO(derat): Figure out why this fails on Windows: http://crbug.com/427184 | 2889 // TODO(derat): Figure out why this fails on Windows: http://crbug.com/427184 |
2891 #if !defined(OS_WIN) | 2890 #if !defined(OS_WIN) |
2892 // Ensure that RenderText examines all of the fonts in its FontList before | 2891 // Ensure that RenderText examines all of the fonts in its FontList before |
2893 // falling back to other fonts. | 2892 // falling back to other fonts. |
2894 TEST_F(RenderTextTest, HarfBuzz_FontListFallback) { | 2893 TEST_F(RenderTextTest, HarfBuzz_FontListFallback) { |
2895 // Double-check that the requested fonts are present. | 2894 // Double-check that the requested fonts are present. |
2896 FontList font_list("Arial, Symbol, 12px"); | 2895 FontList font_list("Arial, Symbol, 12px"); |
2897 const std::vector<Font>& fonts = font_list.GetFonts(); | 2896 const std::vector<Font>& fonts = font_list.GetFonts(); |
2898 ASSERT_EQ(2u, fonts.size()); | 2897 ASSERT_EQ(2u, fonts.size()); |
2899 ASSERT_EQ("arial", | 2898 ASSERT_EQ("arial", |
2900 base::StringToLowerASCII(fonts[0].GetActualFontNameForTesting())); | 2899 base::ToLowerASCII(fonts[0].GetActualFontNameForTesting())); |
2901 ASSERT_EQ("symbol", | 2900 ASSERT_EQ("symbol", |
2902 base::StringToLowerASCII(fonts[1].GetActualFontNameForTesting())); | 2901 base::ToLowerASCII(fonts[1].GetActualFontNameForTesting())); |
2903 | 2902 |
2904 // "⊕" (CIRCLED PLUS) should be rendered with Symbol rather than falling back | 2903 // "⊕" (CIRCLED PLUS) should be rendered with Symbol rather than falling back |
2905 // to some other font that's present on the system. | 2904 // to some other font that's present on the system. |
2906 RenderTextHarfBuzz render_text; | 2905 RenderTextHarfBuzz render_text; |
2907 render_text.SetFontList(font_list); | 2906 render_text.SetFontList(font_list); |
2908 render_text.SetText(UTF8ToUTF16("\xE2\x8A\x95")); | 2907 render_text.SetText(UTF8ToUTF16("\xE2\x8A\x95")); |
2909 const std::vector<RenderText::FontSpan> spans = | 2908 const std::vector<RenderText::FontSpan> spans = |
2910 render_text.GetFontSpansForTesting(); | 2909 render_text.GetFontSpansForTesting(); |
2911 ASSERT_EQ(static_cast<size_t>(1), spans.size()); | 2910 ASSERT_EQ(static_cast<size_t>(1), spans.size()); |
2912 EXPECT_EQ("Symbol", spans[0].first.GetFontName()); | 2911 EXPECT_EQ("Symbol", spans[0].first.GetFontName()); |
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3116 string_size.set_width(string_size.width() / 2); | 3115 string_size.set_width(string_size.width() / 2); |
3117 render_text.SetDisplayRect(gfx::Rect(string_size)); | 3116 render_text.SetDisplayRect(gfx::Rect(string_size)); |
3118 render_text.EnsureLayout(); | 3117 render_text.EnsureLayout(); |
3119 CFIndex glyph_count = CTLineGetGlyphCount(render_text.line_); | 3118 CFIndex glyph_count = CTLineGetGlyphCount(render_text.line_); |
3120 EXPECT_GT(text.size(), static_cast<size_t>(glyph_count)); | 3119 EXPECT_GT(text.size(), static_cast<size_t>(glyph_count)); |
3121 EXPECT_NE(0, glyph_count); | 3120 EXPECT_NE(0, glyph_count); |
3122 } | 3121 } |
3123 #endif | 3122 #endif |
3124 | 3123 |
3125 } // namespace gfx | 3124 } // namespace gfx |
OLD | NEW |