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

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

Issue 1819753003: Allow various font weights in gfx. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add a lost comment and modify a render text unittest to not test black because of test env font con… Created 4 years, 6 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
« no previous file with comments | « ui/gfx/platform_font_win.cc ('k') | ui/gfx/render_text.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/platform_font_win.h" 5 #include "ui/gfx/platform_font_win.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/memory/ref_counted.h" 8 #include "base/memory/ref_counted.h"
9 #include "base/strings/string16.h" 9 #include "base/strings/string16.h"
10 #include "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
11 #include "base/win/scoped_hdc.h" 11 #include "base/win/scoped_hdc.h"
12 #include "base/win/scoped_select_object.h" 12 #include "base/win/scoped_select_object.h"
13 #include "testing/gtest/include/gtest/gtest.h" 13 #include "testing/gtest/include/gtest/gtest.h"
14 #include "ui/gfx/font.h" 14 #include "ui/gfx/font.h"
15 #include "ui/gfx/win/direct_write.h" 15 #include "ui/gfx/win/direct_write.h"
16 #include "ui/gfx/win/scoped_set_map_mode.h" 16 #include "ui/gfx/win/scoped_set_map_mode.h"
17 17
18 namespace gfx { 18 namespace gfx {
19 19
20 TEST(PlatformFontWinTest, DeriveFontWithHeight) {
21 const Font base_font;
22 PlatformFontWin* platform_font =
23 static_cast<PlatformFontWin*>(base_font.platform_font());
24
25 for (int i = -10; i < 10; i++) {
26 const int target_height = base_font.GetHeight() + i;
27
28 Font derived_font = platform_font->DeriveFontWithHeight(target_height, 0);
29 EXPECT_LE(derived_font.GetHeight(), target_height);
30 EXPECT_GT(derived_font.Derive(1, 0).GetHeight(), target_height);
31 EXPECT_EQ(platform_font->GetActualFontNameForTesting(),
32 derived_font.GetActualFontNameForTesting());
33 EXPECT_EQ(0, derived_font.GetStyle());
34
35 derived_font = platform_font->DeriveFontWithHeight(target_height,
36 Font::BOLD);
37 EXPECT_LE(derived_font.GetHeight(), target_height);
38 EXPECT_GT(derived_font.Derive(1, 0).GetHeight(), target_height);
39 EXPECT_EQ(platform_font->GetActualFontNameForTesting(),
40 derived_font.GetActualFontNameForTesting());
41 EXPECT_EQ(Font::BOLD, derived_font.GetStyle());
42 }
43 }
44
45 TEST(PlatformFontWinTest, DeriveFontWithHeight_Consistency) {
46 gfx::Font arial_12("Arial", 12);
47 ASSERT_GT(16, arial_12.GetHeight());
48 gfx::Font derived_1 = static_cast<PlatformFontWin*>(
49 arial_12.platform_font())->DeriveFontWithHeight(16, 0);
50
51 gfx::Font arial_15("Arial", 15);
52 ASSERT_LT(16, arial_15.GetHeight());
53 gfx::Font derived_2 = static_cast<PlatformFontWin*>(
54 arial_15.platform_font())->DeriveFontWithHeight(16, 0);
55
56 EXPECT_EQ(derived_1.GetFontSize(), derived_2.GetFontSize());
57 EXPECT_EQ(16, derived_1.GetHeight());
58 EXPECT_EQ(16, derived_2.GetHeight());
59 }
60
61 // Callback function used by DeriveFontWithHeight_MinSize() below.
62 static int GetMinFontSize() {
63 return 10;
64 }
65
66 TEST(PlatformFontWinTest, DeriveFontWithHeight_MinSize) {
67 PlatformFontWin::GetMinimumFontSizeCallback old_callback =
68 PlatformFontWin::get_minimum_font_size_callback;
69 PlatformFontWin::get_minimum_font_size_callback = &GetMinFontSize;
70
71 const Font base_font;
72 const Font min_font(base_font.GetFontName(), GetMinFontSize());
73 PlatformFontWin* platform_font =
74 static_cast<PlatformFontWin*>(base_font.platform_font());
75
76 const Font derived_font =
77 platform_font->DeriveFontWithHeight(min_font.GetHeight() - 1, 0);
78 EXPECT_EQ(min_font.GetFontSize(), derived_font.GetFontSize());
79 EXPECT_EQ(min_font.GetHeight(), derived_font.GetHeight());
80
81 PlatformFontWin::get_minimum_font_size_callback = old_callback;
82 }
83
84 TEST(PlatformFontWinTest, DeriveFontWithHeight_TooSmall) {
85 const Font base_font;
86 PlatformFontWin* platform_font =
87 static_cast<PlatformFontWin*>(base_font.platform_font());
88
89 const Font derived_font = platform_font->DeriveFontWithHeight(1, 0);
90 EXPECT_GT(derived_font.GetHeight(), 1);
91 }
92
93 // Test whether font metrics retrieved by DirectWrite (skia) and GDI match as 20 // Test whether font metrics retrieved by DirectWrite (skia) and GDI match as
94 // per assumptions mentioned below:- 21 // per assumptions mentioned below:-
95 // 1. Font size is the same 22 // 1. Font size is the same
96 // 2. The difference between GDI and DirectWrite for font height, baseline, 23 // 2. The difference between GDI and DirectWrite for font height, baseline,
97 // and cap height is at most 1. For smaller font sizes under 12, GDI 24 // and cap height is at most 1. For smaller font sizes under 12, GDI
98 // font heights/baselines/cap height are equal/larger by 1 point. For larger 25 // font heights/baselines/cap height are equal/larger by 1 point. For larger
99 // font sizes DirectWrite font heights/baselines/cap height are equal/larger 26 // font sizes DirectWrite font heights/baselines/cap height are equal/larger
100 // by 1 point. 27 // by 1 point.
101 TEST(PlatformFontWinTest, Metrics_SkiaVersusGDI) { 28 TEST(PlatformFontWinTest, Metrics_SkiaVersusGDI) {
102 // Describes the font being tested. 29 // Describes the font being tested.
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 PlatformFontWin::GetTextMetricsForFont(screen_dc, hFont, &font_metrics); 119 PlatformFontWin::GetTextMetricsForFont(screen_dc, hFont, &font_metrics);
193 120
194 scoped_refptr<PlatformFontWin::HFontRef> h_font_skia( 121 scoped_refptr<PlatformFontWin::HFontRef> h_font_skia(
195 PlatformFontWin::CreateHFontRefFromSkia(hFont, font_metrics)); 122 PlatformFontWin::CreateHFontRefFromSkia(hFont, font_metrics));
196 123
197 EXPECT_EQ(font.expected_font_name, h_font_skia->font_name()); 124 EXPECT_EQ(font.expected_font_name, h_font_skia->font_name());
198 } 125 }
199 } 126 }
200 127
201 } // namespace gfx 128 } // namespace gfx
OLDNEW
« no previous file with comments | « ui/gfx/platform_font_win.cc ('k') | ui/gfx/render_text.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698