OLD | NEW |
---|---|
(Empty) | |
1 | |
2 /* | |
3 * Copyright 2012 The Android Open Source Project | |
4 * | |
5 * Use of this source code is governed by a BSD-style license that can be | |
6 * found in the LICENSE file. | |
7 */ | |
8 | |
9 #ifdef SK_BUILD_FOR_ANDROID | |
10 | |
11 #include "SkPaintOptionsAndroid.h" | |
12 #include "SkFlattenableBuffers.h" | |
13 #include "SkTDict.h" | |
14 #include "SkThread.h" | |
15 #include <cstring> | |
16 | |
17 SkLanguage SkLanguage::getParent() const { | |
18 SkASSERT(fInfo != NULL); | |
19 const char* tag = fInfo->fTag.c_str(); | |
20 SkASSERT(tag != NULL); | |
21 | |
22 // strip off the rightmost "-.*" | |
23 char* parentTagEnd = strrchr(tag, '-'); | |
24 if (parentTagEnd == NULL) { | |
25 return SkLanguage(""); | |
26 } | |
27 size_t parentTagLen = parentTagEnd - tag; | |
28 char parentTag[parentTagLen + 1]; | |
29 strncpy(parentTag, tag, parentTagLen); | |
30 parentTag[parentTagLen] = '\0'; | |
31 return SkLanguage(parentTag); | |
32 } | |
33 | |
34 SK_DECLARE_STATIC_MUTEX(gGetInfoMutex); | |
35 const SkLanguageInfo* SkLanguage::getInfo(const char* tag) { | |
36 SkAutoMutexAcquire lock(gGetInfoMutex); | |
37 | |
38 static const size_t kDictSize = 128; | |
39 static SkTDict<SkLanguageInfo*> tagToInfo(kDictSize); | |
40 | |
41 // try a lookup | |
42 SkLanguageInfo* info; | |
43 if (tagToInfo.find(tag, &info)) { | |
44 return info; | |
45 } | |
46 | |
47 // no match - add this language | |
48 info = new SkLanguageInfo(tag); | |
49 tagToInfo.set(tag, info); | |
50 return info; | |
51 } | |
52 | |
53 void SkPaintOptionsAndroid::flatten(SkFlattenableWriteBuffer& buffer) const { | |
54 buffer.writeUInt(fFontVariant); | |
55 buffer.writeString(fLanguage.getTag().c_str()); | |
56 } | |
57 | |
58 void SkPaintOptionsAndroid::unflatten(SkFlattenableReadBuffer& buffer) { | |
59 fFontVariant = (FontVariant)buffer.readUInt(); | |
60 char* tag = buffer.readString(); | |
reed1
2013/05/09 20:41:19
(unrelated to this cl)
Ick. Can we change buffer.
| |
61 fLanguage = SkLanguage(tag); | |
62 sk_free(tag); | |
63 } | |
64 | |
65 #endif | |
OLD | NEW |