diff options
author | reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2013-04-19 20:45:30 +0000 |
---|---|---|
committer | reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2013-04-19 20:45:30 +0000 |
commit | 027fd204ad09fe3160c7319b1e55c4ae44747947 (patch) | |
tree | fd16e8b0f1416265074eeb6ce5bd2c5e21525f09 /src/ports/SkFontConfigInterface_direct.cpp | |
parent | 3cceb9f400583be4ec70da526c23fe81b68dc6ee (diff) | |
download | platform_external_skqp-027fd204ad09fe3160c7319b1e55c4ae44747947.tar.gz platform_external_skqp-027fd204ad09fe3160c7319b1e55c4ae44747947.tar.bz2 platform_external_skqp-027fd204ad09fe3160c7319b1e55c4ae44747947.zip |
use SkDataTable to return familyNames for fontmgr
git-svn-id: http://skia.googlecode.com/svn/trunk@8781 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'src/ports/SkFontConfigInterface_direct.cpp')
-rw-r--r-- | src/ports/SkFontConfigInterface_direct.cpp | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/src/ports/SkFontConfigInterface_direct.cpp b/src/ports/SkFontConfigInterface_direct.cpp index fcb309ea61..b0a2e46567 100644 --- a/src/ports/SkFontConfigInterface_direct.cpp +++ b/src/ports/SkFontConfigInterface_direct.cpp @@ -28,6 +28,12 @@ public: SkTypeface::Style* outStyle) SK_OVERRIDE; virtual SkStream* openStream(const FontIdentity&) SK_OVERRIDE; + // new APIs + virtual SkDataTable* getFamilyNames() SK_OVERRIDE; + virtual bool matchFamilySet(const char inFamilyName[], + SkString* outFamilyName, + SkTArray<FontIdentity>*) SK_OVERRIDE; + private: SkMutex mutex_; }; @@ -448,3 +454,61 @@ bool SkFontConfigInterfaceDirect::matchFamilyName(const char familyName[], SkStream* SkFontConfigInterfaceDirect::openStream(const FontIdentity& identity) { return SkStream::NewFromFile(identity.fString.c_str()); } + +/////////////////////////////////////////////////////////////////////////////// + +static const char* get_name(FcPattern* pattern, const char field[]) { + const char* name; + if (FcPatternGetString(pattern, field, 0, (FcChar8**)&name) != FcResultMatch) { + name = ""; + } + return name; +} + +static bool find_name(const SkTDArray<const char*>& list, const char* str) { + int count = list.count(); + for (int i = 0; i < count; ++i) { + if (!strcmp(list[i], str)) { + return true; + } + } + return false; +} + +SkDataTable* SkFontConfigInterfaceDirect::getFamilyNames() { + FcPattern* pat = FcPatternCreate(); + FcObjectSet* os = FcObjectSetBuild (FC_FAMILY, (char *) 0); + if (NULL == os) { + return false; + } + FcFontSet* fs = FcFontList(NULL, pat, os); + if (NULL == fs) { + FcObjectSetDestroy(os); + return false; + } + + SkTDArray<const char*> names; + SkTDArray<size_t> sizes; + for (int i = 0; i < fs->nfont; ++i) { + FcPattern* match = fs->fonts[i]; + const char* famName = get_name(match, FC_FAMILY); + if (!find_name(names, famName)) { + *names.append() = famName; + *sizes.append() = strlen(famName) + 1; + } + } + + FcFontSetDestroy(fs); + FcObjectSetDestroy(os); + FcPatternDestroy(pat); + + return SkDataTable::NewCopyArrays((const void*const*)names.begin(), + sizes.begin(), names.count()); +} + +bool SkFontConfigInterfaceDirect::matchFamilySet(const char inFamilyName[], + SkString* outFamilyName, + SkTArray<FontIdentity>* ids) { + return false; +} + |