Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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/test/fontconfig_util_linux.h" | 5 #include "ui/gfx/test/fontconfig_util_linux.h" |
| 6 | 6 |
| 7 #include <fontconfig/fontconfig.h> | 7 #include <fontconfig/fontconfig.h> |
| 8 | 8 |
| 9 #include "base/files/file_util.h" | 9 #include "base/files/file_util.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 57 const char kFontconfigFileHeader[] = | 57 const char kFontconfigFileHeader[] = |
| 58 "<?xml version=\"1.0\"?>\n" | 58 "<?xml version=\"1.0\"?>\n" |
| 59 "<!DOCTYPE fontconfig SYSTEM \"fonts.dtd\">\n" | 59 "<!DOCTYPE fontconfig SYSTEM \"fonts.dtd\">\n" |
| 60 "<fontconfig>\n"; | 60 "<fontconfig>\n"; |
| 61 const char kFontconfigFileFooter[] = "</fontconfig>"; | 61 const char kFontconfigFileFooter[] = "</fontconfig>"; |
| 62 const char kFontconfigMatchFontHeader[] = " <match target=\"font\">\n"; | 62 const char kFontconfigMatchFontHeader[] = " <match target=\"font\">\n"; |
| 63 const char kFontconfigMatchPatternHeader[] = " <match target=\"pattern\">\n"; | 63 const char kFontconfigMatchPatternHeader[] = " <match target=\"pattern\">\n"; |
| 64 const char kFontconfigMatchFooter[] = " </match>\n"; | 64 const char kFontconfigMatchFooter[] = " </match>\n"; |
| 65 | 65 |
| 66 void SetUpFontconfig() { | 66 void SetUpFontconfig() { |
| 67 FcInit(); | 67 CHECK(FcInit()); |
| 68 | 68 CHECK(FcConfigGetCurrent()); |
|
Daniel Erat
2016/06/27 22:40:15
i think that the reason for the old code was to st
| |
| 69 // A primer on undocumented FcConfig reference-counting: | |
| 70 // | |
| 71 // - FcConfigCreate() creates a config with a refcount of 1. | |
| 72 // - FcConfigReference() increments a config's refcount. | |
| 73 // - FcConfigDestroy() decrements a config's refcount, deallocating the | |
| 74 // config when the count reaches 0. | |
| 75 // - FcConfigSetCurrent() calls FcConfigDestroy() on the old config, but | |
| 76 // interestingly does not call FcConfigReference() on the new config. | |
| 77 CHECK(FcConfigSetCurrent(FcConfigCreate())); | |
| 78 } | 69 } |
| 79 | 70 |
| 80 void TearDownFontconfig() { | 71 void TearDownFontconfig() { |
| 81 FcFini(); | 72 FcFini(); |
| 82 } | 73 } |
| 83 | 74 |
| 84 bool LoadFontIntoFontconfig(const base::FilePath& path) { | 75 bool LoadFontIntoFontconfig(const base::FilePath& path) { |
| 85 if (!base::PathExists(path)) { | 76 if (!base::PathExists(path)) { |
| 86 LOG(ERROR) << "You are missing " << path.value() << ". Try re-running " | 77 LOG(ERROR) << "You are missing " << path.value() << ". Try re-running " |
| 87 << "build/install-build-deps.sh. Also see " | 78 << "build/install-build-deps.sh. Also see " |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 159 const std::string& preferred_family) { | 150 const std::string& preferred_family) { |
| 160 return base::StringPrintf( | 151 return base::StringPrintf( |
| 161 " <alias>\n" | 152 " <alias>\n" |
| 162 " <family>%s</family>\n" | 153 " <family>%s</family>\n" |
| 163 " <prefer><family>%s</family></prefer>\n" | 154 " <prefer><family>%s</family></prefer>\n" |
| 164 " </alias>\n", | 155 " </alias>\n", |
| 165 original_family.c_str(), preferred_family.c_str()); | 156 original_family.c_str(), preferred_family.c_str()); |
| 166 } | 157 } |
| 167 | 158 |
| 168 } // namespace gfx | 159 } // namespace gfx |
| OLD | NEW |