OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2009 Google Inc. | 2 * Copyright 2009 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 /* migrated from chrome/src/skia/ext/SkFontHost_fontconfig_direct.cpp */ | 8 /* migrated from chrome/src/skia/ext/SkFontHost_fontconfig_direct.cpp */ |
9 | 9 |
10 #include <string> | 10 #include <string> |
11 #include <unistd.h> | 11 #include <unistd.h> |
12 #include <fcntl.h> | 12 #include <fcntl.h> |
13 | 13 |
14 #include <fontconfig/fontconfig.h> | 14 #include <fontconfig/fontconfig.h> |
15 | 15 |
16 #include "SkBuffer.h" | 16 #include "SkBuffer.h" |
17 #include "SkFontConfigInterface.h" | 17 #include "SkFontConfigInterface.h" |
| 18 #include "SkOnce.h" |
18 #include "SkStream.h" | 19 #include "SkStream.h" |
19 | 20 |
20 size_t SkFontConfigInterface::FontIdentity::writeToMemory(void* addr) const { | 21 size_t SkFontConfigInterface::FontIdentity::writeToMemory(void* addr) const { |
21 size_t size = sizeof(fID) + sizeof(fTTCIndex); | 22 size_t size = sizeof(fID) + sizeof(fTTCIndex); |
22 size += sizeof(int32_t) + sizeof(int32_t) + sizeof(uint8_t); // weight, widt
h, italic | 23 size += sizeof(int32_t) + sizeof(int32_t) + sizeof(uint8_t); // weight, widt
h, italic |
23 size += sizeof(int32_t) + fString.size(); // store length+data | 24 size += sizeof(int32_t) + fString.size(); // store length+data |
24 if (addr) { | 25 if (addr) { |
25 SkWBuffer buffer(addr, size); | 26 SkWBuffer buffer(addr, size); |
26 | 27 |
27 buffer.write32(fID); | 28 buffer.write32(fID); |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
116 // new APIs | 117 // new APIs |
117 virtual SkDataTable* getFamilyNames() SK_OVERRIDE; | 118 virtual SkDataTable* getFamilyNames() SK_OVERRIDE; |
118 virtual bool matchFamilySet(const char inFamilyName[], | 119 virtual bool matchFamilySet(const char inFamilyName[], |
119 SkString* outFamilyName, | 120 SkString* outFamilyName, |
120 SkTArray<FontIdentity>*) SK_OVERRIDE; | 121 SkTArray<FontIdentity>*) SK_OVERRIDE; |
121 | 122 |
122 private: | 123 private: |
123 SkMutex mutex_; | 124 SkMutex mutex_; |
124 }; | 125 }; |
125 | 126 |
| 127 static void create_singleton_direct_interface(SkFontConfigInterface** singleton)
{ |
| 128 *singleton = new SkFontConfigInterfaceDirect; |
| 129 } |
126 SkFontConfigInterface* SkFontConfigInterface::GetSingletonDirectInterface() { | 130 SkFontConfigInterface* SkFontConfigInterface::GetSingletonDirectInterface() { |
127 static SkFontConfigInterface* gDirect; | 131 static SkFontConfigInterface* gDirect; |
128 if (NULL == gDirect) { | 132 SK_DECLARE_STATIC_ONCE(once); |
129 static SkMutex gMutex; | 133 SkOnce(&once, create_singleton_direct_interface, &gDirect); |
130 SkAutoMutexAcquire ac(gMutex); | |
131 | |
132 if (NULL == gDirect) { | |
133 gDirect = new SkFontConfigInterfaceDirect; | |
134 } | |
135 } | |
136 return gDirect; | 134 return gDirect; |
137 } | 135 } |
138 | 136 |
139 /////////////////////////////////////////////////////////////////////////////// | 137 /////////////////////////////////////////////////////////////////////////////// |
140 | 138 |
141 // Returns the string from the pattern, or NULL | 139 // Returns the string from the pattern, or NULL |
142 static const char* get_name(FcPattern* pattern, const char field[], | 140 static const char* get_name(FcPattern* pattern, const char field[], |
143 int index = 0) { | 141 int index = 0) { |
144 const char* name; | 142 const char* name; |
145 if (FcPatternGetString(pattern, field, index, | 143 if (FcPatternGetString(pattern, field, index, |
(...skipping 581 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
727 *trimmedMatches.append() = match[i]; | 725 *trimmedMatches.append() = match[i]; |
728 } | 726 } |
729 } | 727 } |
730 | 728 |
731 SkFontStyleSet_FC* sset = SkNEW_ARGS(SkFontStyleSet_FC, | 729 SkFontStyleSet_FC* sset = SkNEW_ARGS(SkFontStyleSet_FC, |
732 (trimmedMatches.begin(), | 730 (trimmedMatches.begin(), |
733 trimmedMatches.count())); | 731 trimmedMatches.count())); |
734 #endif | 732 #endif |
735 return false; | 733 return false; |
736 } | 734 } |
OLD | NEW |