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/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
(...skipping 1180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1191 render_text->SetFontList(font_list); | 1191 render_text->SetFontList(font_list); |
1192 EXPECT_LT(smaller_font.GetHeight(), render_text->GetStringSize().height()); | 1192 EXPECT_LT(smaller_font.GetHeight(), render_text->GetStringSize().height()); |
1193 EXPECT_LT(smaller_font.GetBaseline(), render_text->GetBaseline()); | 1193 EXPECT_LT(smaller_font.GetBaseline(), render_text->GetBaseline()); |
1194 EXPECT_EQ(font_list.GetHeight(), render_text->GetStringSize().height()); | 1194 EXPECT_EQ(font_list.GetHeight(), render_text->GetStringSize().height()); |
1195 EXPECT_EQ(font_list.GetBaseline(), render_text->GetBaseline()); | 1195 EXPECT_EQ(font_list.GetBaseline(), render_text->GetBaseline()); |
1196 } | 1196 } |
1197 | 1197 |
1198 TEST_F(RenderTextTest, SetFont) { | 1198 TEST_F(RenderTextTest, SetFont) { |
1199 scoped_ptr<RenderText> render_text(RenderText::CreateInstance()); | 1199 scoped_ptr<RenderText> render_text(RenderText::CreateInstance()); |
1200 render_text->SetFont(Font("Arial", 12)); | 1200 render_text->SetFont(Font("Arial", 12)); |
1201 EXPECT_EQ("Arial", render_text->GetFont().GetFontName()); | 1201 EXPECT_EQ("Arial", render_text->GetPrimaryFont().GetFontName()); |
1202 EXPECT_EQ(12, render_text->GetFont().GetFontSize()); | 1202 EXPECT_EQ(12, render_text->GetPrimaryFont().GetFontSize()); |
1203 } | 1203 } |
1204 | 1204 |
1205 TEST_F(RenderTextTest, SetFontList) { | 1205 TEST_F(RenderTextTest, SetFontList) { |
1206 scoped_ptr<RenderText> render_text(RenderText::CreateInstance()); | 1206 scoped_ptr<RenderText> render_text(RenderText::CreateInstance()); |
1207 render_text->SetFontList(FontList("Arial,Symbol, 13px")); | 1207 render_text->SetFontList(FontList("Arial,Symbol, 13px")); |
1208 const std::vector<Font>& fonts = render_text->font_list().GetFonts(); | 1208 const std::vector<Font>& fonts = render_text->font_list().GetFonts(); |
1209 ASSERT_EQ(2U, fonts.size()); | 1209 ASSERT_EQ(2U, fonts.size()); |
1210 EXPECT_EQ("Arial", fonts[0].GetFontName()); | 1210 EXPECT_EQ("Arial", fonts[0].GetFontName()); |
1211 EXPECT_EQ("Symbol", fonts[1].GetFontName()); | 1211 EXPECT_EQ("Symbol", fonts[1].GetFontName()); |
1212 EXPECT_EQ(13, render_text->GetFont().GetFontSize()); | 1212 EXPECT_EQ(13, render_text->GetPrimaryFont().GetFontSize()); |
1213 } | 1213 } |
1214 | 1214 |
1215 TEST_F(RenderTextTest, StringSizeBoldWidth) { | 1215 TEST_F(RenderTextTest, StringSizeBoldWidth) { |
1216 scoped_ptr<RenderText> render_text(RenderText::CreateInstance()); | 1216 scoped_ptr<RenderText> render_text(RenderText::CreateInstance()); |
1217 render_text->SetText(UTF8ToUTF16("Hello World")); | 1217 render_text->SetText(UTF8ToUTF16("Hello World")); |
1218 | 1218 |
1219 const int plain_width = render_text->GetStringSize().width(); | 1219 const int plain_width = render_text->GetStringSize().width(); |
1220 EXPECT_GT(plain_width, 0); | 1220 EXPECT_GT(plain_width, 0); |
1221 | 1221 |
1222 // Apply a bold style and check that the new width is greater. | 1222 // Apply a bold style and check that the new width is greater. |
(...skipping 425 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1648 render_text->MoveCursorTo(SelectionModel(ui::Range(0, 1), CURSOR_FORWARD)); | 1648 render_text->MoveCursorTo(SelectionModel(ui::Range(0, 1), CURSOR_FORWARD)); |
1649 EXPECT_EQ(expected_width, render_text->GetStringSize().width()); | 1649 EXPECT_EQ(expected_width, render_text->GetStringSize().width()); |
1650 // Draw the text. It shouldn't hit any DCHECKs or crash. | 1650 // Draw the text. It shouldn't hit any DCHECKs or crash. |
1651 // See http://crbug.com/214150 | 1651 // See http://crbug.com/214150 |
1652 render_text->Draw(&canvas); | 1652 render_text->Draw(&canvas); |
1653 render_text->MoveCursorTo(SelectionModel(0, CURSOR_FORWARD)); | 1653 render_text->MoveCursorTo(SelectionModel(0, CURSOR_FORWARD)); |
1654 } | 1654 } |
1655 } | 1655 } |
1656 | 1656 |
1657 } // namespace gfx | 1657 } // namespace gfx |
OLD | NEW |