Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Side by Side Diff: ui/gfx/render_text_unittest.cc

Issue 943093002: Make bigger string size in RenderTextHarfBuzz. Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 1356 matching lines...) Expand 10 before | Expand all | Expand 10 after
1367 render_text->SetDisplayRect(Rect(0, 0, 0, font_list.GetHeight())); 1367 render_text->SetDisplayRect(Rect(0, 0, 0, font_list.GetHeight()));
1368 1368
1369 // The empty string respects FontList metrics for non-zero height 1369 // The empty string respects FontList metrics for non-zero height
1370 // and baseline. 1370 // and baseline.
1371 render_text->SetText(base::string16()); 1371 render_text->SetText(base::string16());
1372 EXPECT_EQ(font_list.GetHeight(), render_text->GetStringSize().height()); 1372 EXPECT_EQ(font_list.GetHeight(), render_text->GetStringSize().height());
1373 EXPECT_EQ(0, render_text->GetStringSize().width()); 1373 EXPECT_EQ(0, render_text->GetStringSize().width());
1374 EXPECT_EQ(font_list.GetBaseline(), render_text->GetBaseline()); 1374 EXPECT_EQ(font_list.GetBaseline(), render_text->GetBaseline());
1375 1375
1376 render_text->SetText(UTF8ToUTF16(" ")); 1376 render_text->SetText(UTF8ToUTF16(" "));
1377 EXPECT_EQ(font_list.GetHeight(), render_text->GetStringSize().height()); 1377 // If it's not empty, render_text's height could be slightly bigger than
msw 2015/02/24 23:31:36 nit: |render_text|'s. Also, what does this mean by
Jun Mukai 2015/02/25 23:49:19 Fixed. I meant the text isn't empty (in this case
1378 // the font height for the distance from the top bearing line to the ascender.
msw 2015/02/24 23:31:35 nit: try to keep the wording of these comments as
Jun Mukai 2015/02/25 23:49:19 Done (I think...)
1379 EXPECT_LE(font_list.GetHeight(), render_text->GetStringSize().height());
1378 EXPECT_EQ(font_list.GetBaseline(), render_text->GetBaseline()); 1380 EXPECT_EQ(font_list.GetBaseline(), render_text->GetBaseline());
1379 } 1381 }
1380 #endif // !defined(OS_MACOSX) 1382 #endif // !defined(OS_MACOSX)
1381 1383
1382 TEST_F(RenderTextTest, StringSizeRespectsFontListMetrics) { 1384 TEST_F(RenderTextTest, StringSizeRespectsFontListMetrics) {
1383 // Check that Arial and Symbol have different font metrics. 1385 // Check that Arial and Symbol have different font metrics.
1384 Font arial_font("Arial", 16); 1386 Font arial_font("Arial", 16);
1385 ASSERT_EQ("arial", 1387 ASSERT_EQ("arial",
1386 base::StringToLowerASCII(arial_font.GetActualFontNameForTesting())); 1388 base::StringToLowerASCII(arial_font.GetActualFontNameForTesting()));
1387 Font symbol_font("Symbol", 16); 1389 Font symbol_font("Symbol", 16);
(...skipping 19 matching lines...) Expand all
1407 } 1409 }
1408 ASSERT_LT(smaller_font.GetHeight(), larger_font.GetHeight()); 1410 ASSERT_LT(smaller_font.GetHeight(), larger_font.GetHeight());
1409 ASSERT_LT(smaller_font.GetBaseline(), larger_font.GetBaseline()); 1411 ASSERT_LT(smaller_font.GetBaseline(), larger_font.GetBaseline());
1410 1412
1411 // Check |smaller_font_text| is rendered with the smaller font. 1413 // Check |smaller_font_text| is rendered with the smaller font.
1412 scoped_ptr<RenderText> render_text(RenderText::CreateInstance()); 1414 scoped_ptr<RenderText> render_text(RenderText::CreateInstance());
1413 render_text->SetText(UTF8ToUTF16(smaller_font_text)); 1415 render_text->SetText(UTF8ToUTF16(smaller_font_text));
1414 render_text->SetFontList(FontList(smaller_font)); 1416 render_text->SetFontList(FontList(smaller_font));
1415 render_text->SetDisplayRect(Rect(0, 0, 0, 1417 render_text->SetDisplayRect(Rect(0, 0, 0,
1416 render_text->font_list().GetHeight())); 1418 render_text->font_list().GetHeight()));
1417 EXPECT_EQ(smaller_font.GetHeight(), render_text->GetStringSize().height()); 1419 // render text height may not be exactly same to smaller_font's height
msw 2015/02/24 23:31:36 nits: "|render_text|'s height", "exactly the same
Jun Mukai 2015/02/25 23:49:19 Done.
1420 // considering the gap between the top bearing line and the ascender.
1421 // See http://crbug.com/459812
1422 EXPECT_LE(smaller_font.GetHeight(), render_text->GetStringSize().height());
1418 EXPECT_EQ(smaller_font.GetBaseline(), render_text->GetBaseline()); 1423 EXPECT_EQ(smaller_font.GetBaseline(), render_text->GetBaseline());
1419 1424
1420 // Layout the same text with mixed fonts. The text should be rendered with 1425 // Layout the same text with mixed fonts. The text should be rendered with
1421 // the smaller font, but the height and baseline are determined with the 1426 // the smaller font, but the height and baseline are determined with the
1422 // metrics of the font list, which is equal to the larger font. 1427 // metrics of the font list, which is equal to the larger font.
1423 std::vector<Font> fonts; 1428 std::vector<Font> fonts;
1424 fonts.push_back(smaller_font); // The primary font is the smaller font. 1429 fonts.push_back(smaller_font); // The primary font is the smaller font.
1425 fonts.push_back(larger_font); 1430 fonts.push_back(larger_font);
1426 const FontList font_list(fonts); 1431 const FontList font_list(fonts);
1427 render_text->SetFontList(font_list); 1432 render_text->SetFontList(font_list);
1428 render_text->SetDisplayRect(Rect(0, 0, 0, 1433 render_text->SetDisplayRect(Rect(0, 0, 0,
1429 render_text->font_list().GetHeight())); 1434 render_text->font_list().GetHeight()));
1430 EXPECT_LT(smaller_font.GetHeight(), render_text->GetStringSize().height()); 1435 EXPECT_LT(smaller_font.GetHeight(), render_text->GetStringSize().height());
1431 EXPECT_LT(smaller_font.GetBaseline(), render_text->GetBaseline()); 1436 EXPECT_LT(smaller_font.GetBaseline(), render_text->GetBaseline());
1432 EXPECT_EQ(font_list.GetHeight(), render_text->GetStringSize().height()); 1437 // Again, it could be slightly different from font's height, see above.
1438 EXPECT_LE(font_list.GetHeight(), render_text->GetStringSize().height());
1433 EXPECT_EQ(font_list.GetBaseline(), render_text->GetBaseline()); 1439 EXPECT_EQ(font_list.GetBaseline(), render_text->GetBaseline());
1434 } 1440 }
1435 1441
1436 TEST_F(RenderTextTest, MinLineHeight) { 1442 TEST_F(RenderTextTest, MinLineHeight) {
1437 scoped_ptr<RenderText> render_text(RenderText::CreateInstance()); 1443 scoped_ptr<RenderText> render_text(RenderText::CreateInstance());
1438 1444
1439 render_text->SetText(ASCIIToUTF16("Hello!")); 1445 render_text->SetText(ASCIIToUTF16("Hello!"));
1440 SizeF default_size = render_text->GetStringSizeF(); 1446 SizeF default_size = render_text->GetStringSizeF();
1441 ASSERT_NE(0, default_size.height()); 1447 ASSERT_NE(0, default_size.height());
1442 ASSERT_NE(0, default_size.width()); 1448 ASSERT_NE(0, default_size.width());
1443 1449
1444 render_text->SetMinLineHeight(default_size.height() / 2); 1450 render_text->SetMinLineHeight(default_size.height() / 2);
1445 EXPECT_EQ(default_size.ToString(), render_text->GetStringSizeF().ToString()); 1451 EXPECT_EQ(default_size.ToString(), render_text->GetStringSizeF().ToString());
1446 1452
1447 render_text->SetMinLineHeight(default_size.height() * 2); 1453 render_text->SetMinLineHeight(default_size.height() * 2);
1448 SizeF taller_size = render_text->GetStringSizeF(); 1454 SizeF taller_size = render_text->GetStringSizeF();
1449 EXPECT_EQ(default_size.height() * 2, taller_size.height()); 1455 EXPECT_LT(default_size.height(), taller_size.height());
1450 EXPECT_EQ(default_size.width(), taller_size.width()); 1456 EXPECT_EQ(default_size.width(), taller_size.width());
1451 } 1457 }
1452 1458
1453 TEST_F(RenderTextTest, SetFontList) { 1459 TEST_F(RenderTextTest, SetFontList) {
1454 scoped_ptr<RenderText> render_text(RenderText::CreateInstance()); 1460 scoped_ptr<RenderText> render_text(RenderText::CreateInstance());
1455 render_text->SetFontList(FontList("Arial,Symbol, 13px")); 1461 render_text->SetFontList(FontList("Arial,Symbol, 13px"));
1456 const std::vector<Font>& fonts = render_text->font_list().GetFonts(); 1462 const std::vector<Font>& fonts = render_text->font_list().GetFonts();
1457 ASSERT_EQ(2U, fonts.size()); 1463 ASSERT_EQ(2U, fonts.size());
1458 EXPECT_EQ("Arial", fonts[0].GetFontName()); 1464 EXPECT_EQ("Arial", fonts[0].GetFontName());
1459 EXPECT_EQ("Symbol", fonts[1].GetFontName()); 1465 EXPECT_EQ("Symbol", fonts[1].GetFontName());
(...skipping 1092 matching lines...) Expand 10 before | Expand all | Expand 10 after
2552 EXPECT_LT(220U, color_utils::GetLuminanceForColor(color)) << string; 2558 EXPECT_LT(220U, color_utils::GetLuminanceForColor(color)) << string;
2553 for (int x = 1; x < kTestWidth; ++x) { 2559 for (int x = 1; x < kTestWidth; ++x) {
2554 color = buffer[width + x + y * kCanvasSize.width()]; 2560 color = buffer[width + x + y * kCanvasSize.width()];
2555 EXPECT_EQ(SK_ColorWHITE, color) << string; 2561 EXPECT_EQ(SK_ColorWHITE, color) << string;
2556 } 2562 }
2557 } 2563 }
2558 } 2564 }
2559 } 2565 }
2560 2566
2561 } // namespace gfx 2567 } // namespace gfx
OLDNEW
« ui/gfx/render_text_harfbuzz.cc ('K') | « ui/gfx/render_text_harfbuzz.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698