| 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/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| 11 #include "base/strings/string_util.h" |
| 11 #include "base/strings/stringprintf.h" | 12 #include "base/strings/stringprintf.h" |
| 12 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
| 13 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
| 14 #include "ui/gfx/break_list.h" | 15 #include "ui/gfx/break_list.h" |
| 15 #include "ui/gfx/canvas.h" | 16 #include "ui/gfx/canvas.h" |
| 16 | 17 |
| 17 #if defined(OS_WIN) | 18 #if defined(OS_WIN) |
| 18 #include "base/win/windows_version.h" | 19 #include "base/win/windows_version.h" |
| 19 #include "ui/gfx/render_text_win.h" | 20 #include "ui/gfx/render_text_win.h" |
| 20 #endif | 21 #endif |
| (...skipping 1128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1149 EXPECT_EQ(font_list.GetHeight(), render_text->GetStringSize().height()); | 1150 EXPECT_EQ(font_list.GetHeight(), render_text->GetStringSize().height()); |
| 1150 EXPECT_EQ(0, render_text->GetStringSize().width()); | 1151 EXPECT_EQ(0, render_text->GetStringSize().width()); |
| 1151 EXPECT_EQ(font_list.GetBaseline(), render_text->GetBaseline()); | 1152 EXPECT_EQ(font_list.GetBaseline(), render_text->GetBaseline()); |
| 1152 | 1153 |
| 1153 render_text->SetText(UTF8ToUTF16(" ")); | 1154 render_text->SetText(UTF8ToUTF16(" ")); |
| 1154 EXPECT_EQ(font_list.GetHeight(), render_text->GetStringSize().height()); | 1155 EXPECT_EQ(font_list.GetHeight(), render_text->GetStringSize().height()); |
| 1155 EXPECT_EQ(font_list.GetBaseline(), render_text->GetBaseline()); | 1156 EXPECT_EQ(font_list.GetBaseline(), render_text->GetBaseline()); |
| 1156 } | 1157 } |
| 1157 #endif // !defined(OS_MACOSX) | 1158 #endif // !defined(OS_MACOSX) |
| 1158 | 1159 |
| 1159 // Disabled. http://crbug.com/316955 | 1160 TEST_F(RenderTextTest, StringSizeRespectsFontListMetrics) { |
| 1160 TEST_F(RenderTextTest, DISABLED_StringSizeRespectsFontListMetrics) { | |
| 1161 // Check that Arial and Symbol have different font metrics. | 1161 // Check that Arial and Symbol have different font metrics. |
| 1162 Font arial_font("Arial", 16); | 1162 Font arial_font("Arial", 16); |
| 1163 ASSERT_EQ("arial", |
| 1164 StringToLowerASCII(arial_font.GetActualFontNameForTesting())); |
| 1163 Font symbol_font("Symbol", 16); | 1165 Font symbol_font("Symbol", 16); |
| 1166 ASSERT_EQ("symbol", |
| 1167 StringToLowerASCII(symbol_font.GetActualFontNameForTesting())); |
| 1164 EXPECT_NE(arial_font.GetHeight(), symbol_font.GetHeight()); | 1168 EXPECT_NE(arial_font.GetHeight(), symbol_font.GetHeight()); |
| 1165 EXPECT_NE(arial_font.GetBaseline(), symbol_font.GetBaseline()); | 1169 EXPECT_NE(arial_font.GetBaseline(), symbol_font.GetBaseline()); |
| 1166 // "a" should be rendered with Arial, not with Symbol. | 1170 // "a" should be rendered with Arial, not with Symbol. |
| 1167 const char* arial_font_text = "a"; | 1171 const char* arial_font_text = "a"; |
| 1168 // "®" (registered trademark symbol) should be rendered with Symbol, | 1172 // "®" (registered trademark symbol) should be rendered with Symbol, |
| 1169 // not with Arial. | 1173 // not with Arial. |
| 1170 const char* symbol_font_text = "\xC2\xAE"; | 1174 const char* symbol_font_text = "\xC2\xAE"; |
| 1171 | 1175 |
| 1172 Font smaller_font = arial_font; | 1176 Font smaller_font = arial_font; |
| 1173 Font larger_font = symbol_font; | 1177 Font larger_font = symbol_font; |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1206 EXPECT_EQ(font_list.GetBaseline(), render_text->GetBaseline()); | 1210 EXPECT_EQ(font_list.GetBaseline(), render_text->GetBaseline()); |
| 1207 } | 1211 } |
| 1208 | 1212 |
| 1209 TEST_F(RenderTextTest, SetFont) { | 1213 TEST_F(RenderTextTest, SetFont) { |
| 1210 scoped_ptr<RenderText> render_text(RenderText::CreateInstance()); | 1214 scoped_ptr<RenderText> render_text(RenderText::CreateInstance()); |
| 1211 render_text->SetFont(Font("Arial", 12)); | 1215 render_text->SetFont(Font("Arial", 12)); |
| 1212 EXPECT_EQ("Arial", render_text->GetPrimaryFont().GetFontName()); | 1216 EXPECT_EQ("Arial", render_text->GetPrimaryFont().GetFontName()); |
| 1213 EXPECT_EQ(12, render_text->GetPrimaryFont().GetFontSize()); | 1217 EXPECT_EQ(12, render_text->GetPrimaryFont().GetFontSize()); |
| 1214 } | 1218 } |
| 1215 | 1219 |
| 1216 // Disabled. http://crbug.com/316955 | 1220 TEST_F(RenderTextTest, SetFontList) { |
| 1217 TEST_F(RenderTextTest, DISABLED_SetFontList) { | |
| 1218 scoped_ptr<RenderText> render_text(RenderText::CreateInstance()); | 1221 scoped_ptr<RenderText> render_text(RenderText::CreateInstance()); |
| 1219 render_text->SetFontList(FontList("Arial,Symbol, 13px")); | 1222 render_text->SetFontList(FontList("Arial,Symbol, 13px")); |
| 1220 const std::vector<Font>& fonts = render_text->font_list().GetFonts(); | 1223 const std::vector<Font>& fonts = render_text->font_list().GetFonts(); |
| 1221 ASSERT_EQ(2U, fonts.size()); | 1224 ASSERT_EQ(2U, fonts.size()); |
| 1222 EXPECT_EQ("Arial", fonts[0].GetFontName()); | 1225 EXPECT_EQ("Arial", fonts[0].GetFontName()); |
| 1223 EXPECT_EQ("Symbol", fonts[1].GetFontName()); | 1226 EXPECT_EQ("Symbol", fonts[1].GetFontName()); |
| 1224 EXPECT_EQ(13, render_text->GetPrimaryFont().GetFontSize()); | 1227 EXPECT_EQ(13, render_text->GetPrimaryFont().GetFontSize()); |
| 1225 } | 1228 } |
| 1226 | 1229 |
| 1227 TEST_F(RenderTextTest, StringSizeBoldWidth) { | 1230 TEST_F(RenderTextTest, StringSizeBoldWidth) { |
| (...skipping 567 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1795 render_text->SetText(WideToUTF16(L"x \x25B6 y")); | 1798 render_text->SetText(WideToUTF16(L"x \x25B6 y")); |
| 1796 render_text->EnsureLayout(); | 1799 render_text->EnsureLayout(); |
| 1797 ASSERT_EQ(3U, render_text->runs_.size()); | 1800 ASSERT_EQ(3U, render_text->runs_.size()); |
| 1798 EXPECT_EQ(Range(0, 2), render_text->runs_[0]->range); | 1801 EXPECT_EQ(Range(0, 2), render_text->runs_[0]->range); |
| 1799 EXPECT_EQ(Range(2, 3), render_text->runs_[1]->range); | 1802 EXPECT_EQ(Range(2, 3), render_text->runs_[1]->range); |
| 1800 EXPECT_EQ(Range(3, 5), render_text->runs_[2]->range); | 1803 EXPECT_EQ(Range(3, 5), render_text->runs_[2]->range); |
| 1801 } | 1804 } |
| 1802 #endif // defined(OS_WIN) | 1805 #endif // defined(OS_WIN) |
| 1803 | 1806 |
| 1804 } // namespace gfx | 1807 } // namespace gfx |
| OLD | NEW |