OLD | NEW |
(Empty) | |
| 1 // Copyright 2014 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. |
| 4 |
| 5 #include "ui/gfx/font_render_params.h" |
| 6 |
| 7 #include "base/files/file_path.h" |
| 8 #include "base/files/scoped_temp_dir.h" |
| 9 #include "base/logging.h" |
| 10 #include "base/macros.h" |
| 11 #include "testing/gtest/include/gtest/gtest.h" |
| 12 #include "ui/gfx/test/fontconfig_util_linux.h" |
| 13 |
| 14 namespace gfx { |
| 15 |
| 16 class FontRenderParamsTest : public testing::Test { |
| 17 public: |
| 18 FontRenderParamsTest() { |
| 19 SetUpFontconfig(); |
| 20 CHECK(temp_dir_.CreateUniqueTempDir()); |
| 21 } |
| 22 |
| 23 virtual ~FontRenderParamsTest() { |
| 24 TearDownFontconfig(); |
| 25 } |
| 26 |
| 27 protected: |
| 28 base::ScopedTempDir temp_dir_; |
| 29 |
| 30 private: |
| 31 DISALLOW_COPY_AND_ASSIGN(FontRenderParamsTest); |
| 32 }; |
| 33 |
| 34 TEST_F(FontRenderParamsTest, Default) { |
| 35 // Fontconfig needs to know about at least one font to return a match. |
| 36 ASSERT_TRUE(LoadFontIntoFontconfig( |
| 37 base::FilePath(kSystemFontsForFontconfig[0]))); |
| 38 ASSERT_TRUE(LoadConfigDataIntoFontconfig(temp_dir_.path(), |
| 39 std::string(kFontconfigFileHeader) + |
| 40 kFontconfigMatchHeader + |
| 41 CreateFontconfigEditStanza("antialias", "bool", "true") + |
| 42 CreateFontconfigEditStanza("autohint", "bool", "false") + |
| 43 CreateFontconfigEditStanza("hinting", "bool", "true") + |
| 44 CreateFontconfigEditStanza("hintstyle", "const", "hintfull") + |
| 45 CreateFontconfigEditStanza("rgba", "const", "rgb") + |
| 46 kFontconfigMatchFooter + |
| 47 kFontconfigFileFooter)); |
| 48 |
| 49 FontRenderParams params = GetDefaultFontRenderParams(); |
| 50 #if defined(OS_CHROMEOS) |
| 51 // Chrome OS uses its own defaults for everything except subpixel rendering, |
| 52 // which comes from Fontconfig. |
| 53 EXPECT_TRUE(params.antialiasing); |
| 54 EXPECT_TRUE(params.autohinter); |
| 55 EXPECT_TRUE(params.use_bitmaps); |
| 56 EXPECT_EQ(FontRenderParams::HINTING_SLIGHT, params.hinting); |
| 57 #else |
| 58 // Desktop Linux gets all settings from fontconfig. |
| 59 EXPECT_TRUE(params.antialiasing); |
| 60 EXPECT_FALSE(params.autohinter); |
| 61 EXPECT_TRUE(params.use_bitmaps); |
| 62 EXPECT_EQ(FontRenderParams::HINTING_FULL, params.hinting); |
| 63 #endif |
| 64 EXPECT_FALSE(params.subpixel_positioning); |
| 65 EXPECT_EQ(FontRenderParams::SUBPIXEL_RENDERING_RGB, |
| 66 params.subpixel_rendering); |
| 67 } |
| 68 |
| 69 // Chrome OS ignores most Fontconfig settings. |
| 70 #if !defined(OS_CHROMEOS) |
| 71 TEST_F(FontRenderParamsTest, Size) { |
| 72 // Fontconfig needs to know about at least one font to return a match. |
| 73 ASSERT_TRUE(LoadFontIntoFontconfig( |
| 74 base::FilePath(kSystemFontsForFontconfig[0]))); |
| 75 ASSERT_TRUE(LoadConfigDataIntoFontconfig(temp_dir_.path(), |
| 76 std::string(kFontconfigFileHeader) + |
| 77 kFontconfigMatchHeader + |
| 78 CreateFontconfigEditStanza("antialias", "bool", "true") + |
| 79 CreateFontconfigEditStanza("hinting", "bool", "true") + |
| 80 CreateFontconfigEditStanza("hintstyle", "const", "hintfull") + |
| 81 CreateFontconfigEditStanza("rgba", "const", "none") + |
| 82 kFontconfigMatchFooter + |
| 83 kFontconfigMatchHeader + |
| 84 CreateFontconfigTestStanza("pixelsize", "less_eq", "double", "10") + |
| 85 CreateFontconfigEditStanza("antialias", "bool", "false") + |
| 86 kFontconfigMatchFooter + |
| 87 kFontconfigMatchHeader + |
| 88 CreateFontconfigTestStanza("size", "more_eq", "double", "20") + |
| 89 CreateFontconfigEditStanza("hintstyle", "const", "hintslight") + |
| 90 CreateFontconfigEditStanza("rgba", "const", "rgb") + |
| 91 kFontconfigMatchFooter + |
| 92 kFontconfigFileFooter)); |
| 93 |
| 94 // The defaults should be used when the supplied size isn't matched by the |
| 95 // second or third blocks. |
| 96 int pixel_size = 12; |
| 97 FontRenderParams params = GetCustomFontRenderParams( |
| 98 false, NULL, &pixel_size, NULL, NULL); |
| 99 EXPECT_TRUE(params.antialiasing); |
| 100 EXPECT_EQ(FontRenderParams::HINTING_FULL, params.hinting); |
| 101 EXPECT_EQ(FontRenderParams::SUBPIXEL_RENDERING_NONE, |
| 102 params.subpixel_rendering); |
| 103 |
| 104 pixel_size = 10; |
| 105 params = GetCustomFontRenderParams(false, NULL, &pixel_size, NULL, NULL); |
| 106 EXPECT_FALSE(params.antialiasing); |
| 107 EXPECT_EQ(FontRenderParams::HINTING_FULL, params.hinting); |
| 108 EXPECT_EQ(FontRenderParams::SUBPIXEL_RENDERING_NONE, |
| 109 params.subpixel_rendering); |
| 110 |
| 111 int point_size = 20; |
| 112 params = GetCustomFontRenderParams(false, NULL, NULL, &point_size, NULL); |
| 113 EXPECT_TRUE(params.antialiasing); |
| 114 EXPECT_EQ(FontRenderParams::HINTING_SLIGHT, params.hinting); |
| 115 EXPECT_EQ(FontRenderParams::SUBPIXEL_RENDERING_RGB, |
| 116 params.subpixel_rendering); |
| 117 } |
| 118 #endif // !defined(OS_CHROMEOS) |
| 119 |
| 120 } // namespace gfx |
OLD | NEW |