diff options
author | reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2013-09-18 20:32:25 +0000 |
---|---|---|
committer | reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2013-09-18 20:32:25 +0000 |
commit | d44d988127841cf9180bb7ba91b6eba8127af467 (patch) | |
tree | 90e9fcea175b4782b04411b90d562bba1f9e4d17 | |
parent | 07f6cf372dc003694c79cfb313923fef9eaf8dc8 (diff) |
fix fontconfig backend to only cache new fonts if their outName was unique
BUG=
R=bungeman@google.com
Review URL: https://codereview.chromium.org/23710072
git-svn-id: http://skia.googlecode.com/svn/trunk@11364 2bbb7eff-a529-9590-31e7-b0007b416f81
-rw-r--r-- | src/ports/SkFontHost_fontconfig.cpp | 9 | ||||
-rw-r--r-- | tests/FontMgrTest.cpp | 22 |
2 files changed, 31 insertions, 0 deletions
diff --git a/src/ports/SkFontHost_fontconfig.cpp b/src/ports/SkFontHost_fontconfig.cpp index 012ce90c8c..0db44b242f 100644 --- a/src/ports/SkFontHost_fontconfig.cpp +++ b/src/ports/SkFontHost_fontconfig.cpp @@ -109,6 +109,15 @@ SkTypeface* FontConfigTypeface::LegacyCreateTypeface( return NULL; } + // check if we, in fact, already have this. perhaps fontconfig aliased the + // requested name to some other name we actually have... + rec.fFamilyName = outFamilyName.c_str(); + rec.fStyle = outStyle; + face = SkTypefaceCache::FindByProcAndRef(find_proc, &rec); + if (face) { + return face; + } + face = SkNEW_ARGS(FontConfigTypeface, (outStyle, indentity, outFamilyName)); SkTypefaceCache::Add(face, style); // SkDebugf("add face <%s> <%s> %p [%d]\n", familyName, outFamilyName.c_str(), face, face->getRefCnt()); diff --git a/tests/FontMgrTest.cpp b/tests/FontMgrTest.cpp index 6b6ee9a73f..00ff79b897 100644 --- a/tests/FontMgrTest.cpp +++ b/tests/FontMgrTest.cpp @@ -11,6 +11,27 @@ #include "SkFontMgr.h" #include "SkTypeface.h" +/* + * If the font backend is going to "alias" some font names to other fonts + * (e.g. sans -> Arial) then we want to at least get the same typeface back + * if we request the alias name multiple times. + */ +static void test_badnames(skiatest::Reporter* reporter) { + const char* inName = "sans"; + SkAutoTUnref<SkTypeface> first(SkTypeface::CreateFromName(inName, SkTypeface::kNormal)); + + SkString name; + for (int i = 0; i < 10; ++i) { + SkAutoTUnref<SkTypeface> face(SkTypeface::CreateFromName(inName, SkTypeface::kNormal)); +#if 0 + face->getFamilyName(&name); + printf("request %s, received %s, first id %x received %x\n", + inName, name.c_str(), first->uniqueID(), face->uniqueID()); +#endif + REPORTER_ASSERT(reporter, first->uniqueID() == face->uniqueID()); + } +} + static void test_fontiter(skiatest::Reporter* reporter, bool verbose) { SkAutoTUnref<SkFontMgr> fm(SkFontMgr::RefDefault()); int count = fm->countFamilies(); @@ -49,6 +70,7 @@ DEFINE_bool(verboseFontMgr, false, "run verbose fontmgr tests."); static void TestFontMgr(skiatest::Reporter* reporter) { test_fontiter(reporter, FLAGS_verboseFontMgr); + test_badnames(reporter); } #include "TestClassDef.h" |