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
3 // found in the LICENSE file.
5 #include <Cocoa/Cocoa.h>
7 #include "testing/gtest/include/gtest/gtest.h"
8 #include "ui/gfx/font.h"
10 TEST(PlatformFontMacTest, DeriveFont) {
11 // Use a base font that support all traits.
12 gfx::Font base_font("Helvetica", 13);
15 gfx::Font bold_font(base_font.Derive(0, gfx::Font::BOLD));
16 NSFontTraitMask traits = [[NSFontManager sharedFontManager]
17 traitsOfFont:bold_font.GetNativeFont()];
18 EXPECT_EQ(NSBoldFontMask, traits);
21 gfx::Font italic_font(base_font.Derive(0, gfx::Font::ITALIC));
22 traits = [[NSFontManager sharedFontManager]
23 traitsOfFont:italic_font.GetNativeFont()];
24 EXPECT_EQ(NSItalicFontMask, traits);
27 gfx::Font bold_italic_font(base_font.Derive(
28 0, gfx::Font::BOLD | gfx::Font::ITALIC));
29 traits = [[NSFontManager sharedFontManager]
30 traitsOfFont:bold_italic_font.GetNativeFont()];
31 EXPECT_EQ(static_cast<NSFontTraitMask>(NSBoldFontMask | NSItalicFontMask),
35 TEST(PlatformFontMacTest, ConstructFromNativeFont) {
36 gfx::Font normal_font([NSFont fontWithName:@"Helvetica" size:12]);
37 EXPECT_EQ(12, normal_font.GetFontSize());
38 EXPECT_EQ("Helvetica", normal_font.GetFontName());
39 EXPECT_EQ(gfx::Font::NORMAL, normal_font.GetStyle());
41 gfx::Font bold_font([NSFont fontWithName:@"Helvetica-Bold" size:14]);
42 EXPECT_EQ(14, bold_font.GetFontSize());
43 EXPECT_EQ("Helvetica", bold_font.GetFontName());
44 EXPECT_EQ(gfx::Font::BOLD, bold_font.GetStyle());
46 gfx::Font italic_font([NSFont fontWithName:@"Helvetica-Oblique" size:14]);
47 EXPECT_EQ(14, italic_font.GetFontSize());
48 EXPECT_EQ("Helvetica", italic_font.GetFontName());
49 EXPECT_EQ(gfx::Font::ITALIC, italic_font.GetStyle());
51 gfx::Font bold_italic_font(
52 [NSFont fontWithName:@"Helvetica-BoldOblique" size:14]);
53 EXPECT_EQ(14, bold_italic_font.GetFontSize());
54 EXPECT_EQ("Helvetica", bold_italic_font.GetFontName());
55 EXPECT_EQ(gfx::Font::BOLD | gfx::Font::ITALIC, bold_italic_font.GetStyle());