| 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 <Cocoa/Cocoa.h> | 5 #include <Cocoa/Cocoa.h> |
| 6 #include <stddef.h> | 6 #include <stddef.h> |
| 7 | 7 |
| 8 #include "base/macros.h" | 8 #include "base/macros.h" |
| 9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
| 10 #include "ui/gfx/font.h" | 10 #include "ui/gfx/font.h" |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 | 29 |
| 30 // Bold italic | 30 // Bold italic |
| 31 gfx::Font bold_italic_font( | 31 gfx::Font bold_italic_font( |
| 32 base_font.Derive(0, gfx::Font::ITALIC, gfx::Font::Weight::BOLD)); | 32 base_font.Derive(0, gfx::Font::ITALIC, gfx::Font::Weight::BOLD)); |
| 33 traits = [[NSFontManager sharedFontManager] | 33 traits = [[NSFontManager sharedFontManager] |
| 34 traitsOfFont:bold_italic_font.GetNativeFont()]; | 34 traitsOfFont:bold_italic_font.GetNativeFont()]; |
| 35 EXPECT_EQ(static_cast<NSFontTraitMask>(NSBoldFontMask | NSItalicFontMask), | 35 EXPECT_EQ(static_cast<NSFontTraitMask>(NSBoldFontMask | NSItalicFontMask), |
| 36 traits); | 36 traits); |
| 37 } | 37 } |
| 38 | 38 |
| 39 TEST(PlatformFontMacTest, DeriveFontUnderline) { |
| 40 // Create a default font. |
| 41 gfx::Font base_font; |
| 42 |
| 43 // Make the font underlined. |
| 44 gfx::Font derived_font(base_font.Derive( |
| 45 0, base_font.GetStyle() | gfx::Font::UNDERLINE, base_font.GetWeight())); |
| 46 |
| 47 // Validate the derived font properties against its native font instance. |
| 48 NSFontTraitMask traits = [[NSFontManager sharedFontManager] |
| 49 traitsOfFont:derived_font.GetNativeFont()]; |
| 50 gfx::Font::Weight actual_weight = (traits & NSFontBoldTrait) |
| 51 ? gfx::Font::Weight::BOLD |
| 52 : gfx::Font::Weight::NORMAL; |
| 53 |
| 54 int actual_style = gfx::Font::UNDERLINE; |
| 55 if (traits & NSFontItalicTrait) |
| 56 actual_style |= gfx::Font::ITALIC; |
| 57 |
| 58 EXPECT_TRUE(derived_font.GetStyle() & gfx::Font::UNDERLINE); |
| 59 EXPECT_EQ(derived_font.GetStyle(), actual_style); |
| 60 EXPECT_EQ(derived_font.GetWeight(), actual_weight); |
| 61 } |
| 62 |
| 39 TEST(PlatformFontMacTest, ConstructFromNativeFont) { | 63 TEST(PlatformFontMacTest, ConstructFromNativeFont) { |
| 40 gfx::Font normal_font([NSFont fontWithName:@"Helvetica" size:12]); | 64 gfx::Font normal_font([NSFont fontWithName:@"Helvetica" size:12]); |
| 41 EXPECT_EQ(12, normal_font.GetFontSize()); | 65 EXPECT_EQ(12, normal_font.GetFontSize()); |
| 42 EXPECT_EQ("Helvetica", normal_font.GetFontName()); | 66 EXPECT_EQ("Helvetica", normal_font.GetFontName()); |
| 43 EXPECT_EQ(gfx::Font::NORMAL, normal_font.GetStyle()); | 67 EXPECT_EQ(gfx::Font::NORMAL, normal_font.GetStyle()); |
| 44 | 68 |
| 45 gfx::Font bold_font([NSFont fontWithName:@"Helvetica-Bold" size:14]); | 69 gfx::Font bold_font([NSFont fontWithName:@"Helvetica-Bold" size:14]); |
| 46 EXPECT_EQ(14, bold_font.GetFontSize()); | 70 EXPECT_EQ(14, bold_font.GetFontSize()); |
| 47 EXPECT_EQ("Helvetica", bold_font.GetFontName()); | 71 EXPECT_EQ("Helvetica", bold_font.GetFontName()); |
| 48 EXPECT_EQ(gfx::Font::Weight::BOLD, bold_font.GetWeight()); | 72 EXPECT_EQ(gfx::Font::Weight::BOLD, bold_font.GetWeight()); |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 // (plus baseline). So the height depends on the rounding of the ascender, | 119 // (plus baseline). So the height depends on the rounding of the ascender, |
| 96 // and can be as much as 1 greater than the simple sum of floats. | 120 // and can be as much as 1 greater than the simple sum of floats. |
| 97 EXPECT_LE(sum, font.GetHeight()); | 121 EXPECT_LE(sum, font.GetHeight()); |
| 98 EXPECT_GE(sum + 1, font.GetHeight()); | 122 EXPECT_GE(sum + 1, font.GetHeight()); |
| 99 | 123 |
| 100 // Recreate the rounding performed for GetBaseLine(). | 124 // Recreate the rounding performed for GetBaseLine(). |
| 101 EXPECT_EQ(ceil(ceil(ascender) - descender + leading), font.GetHeight()); | 125 EXPECT_EQ(ceil(ceil(ascender) - descender + leading), font.GetHeight()); |
| 102 } | 126 } |
| 103 } | 127 } |
| 104 } | 128 } |
| OLD | NEW |