OLD | NEW |
| (Empty) |
1 /* | |
2 * Copyright 2011 Google Inc. | |
3 * | |
4 * Use of this source code is governed by a BSD-style license that can be | |
5 * found in the LICENSE file. | |
6 */ | |
7 | |
8 #include "SkFontHost.h" | |
9 #include "SkTypefaceCache.h" | |
10 | |
11 #define FONT_PATH "/Library/Fonts/Skia.ttf" | |
12 | |
13 class FTMacTypeface : public SkTypeface { | |
14 public: | |
15 FTMacTypeface(Style style, uint32_t id, SkStream* stream) : SkTypeface(style
, id) { | |
16 // we take ownership of the stream | |
17 fStream = stream; | |
18 } | |
19 | |
20 virtual ~FTMacTypeface() { | |
21 fStream->unref(); | |
22 } | |
23 | |
24 SkStream* fStream; | |
25 }; | |
26 | |
27 static FTMacTypeface* create_from_path(const char path[]) { | |
28 SkStream* stream = SkStream::NewFromFile(path); | |
29 if (!stream) { | |
30 return NULL; | |
31 } | |
32 | |
33 size_t size = stream->getLength(); | |
34 SkASSERT(size); | |
35 FTMacTypeface* tf = new FTMacTypeface(SkTypeface::kNormal, | |
36 SkTypefaceCache::NewFontID(), | |
37 stream); | |
38 SkTypefaceCache::Add(tf, SkTypeface::kNormal); | |
39 return tf; | |
40 } | |
41 | |
42 static SkTypeface* ref_default_typeface() { | |
43 static SkTypeface* gDef; | |
44 | |
45 if (NULL == gDef) { | |
46 gDef = create_from_path(FONT_PATH); | |
47 } | |
48 | |
49 gDef->ref(); | |
50 return gDef; | |
51 } | |
52 | |
53 /////////////////////////////////////////////////////////////////////////////// | |
54 | |
55 SkTypeface* SkFontHost::CreateTypeface(const SkTypeface* familyFace, | |
56 const char familyName[], | |
57 SkTypeface::Style style) { | |
58 return ref_default_typeface(); | |
59 } | |
60 | |
61 SkTypeface* SkFontHost::CreateTypefaceFromStream(SkStream* stream) { | |
62 SkDEBUGFAIL("SkFontHost::CreateTypefaceFromStream unimplemented"); | |
63 return NULL; | |
64 } | |
65 | |
66 SkTypeface* SkFontHost::CreateTypefaceFromFile(const char path[]) { | |
67 return create_from_path(path); | |
68 } | |
69 | |
70 SkStream* SkFontHost::OpenStream(uint32_t fontID) { | |
71 FTMacTypeface* tf = (FTMacTypeface*)SkTypefaceCache::FindByID(fontID); | |
72 if (tf) { | |
73 tf->fStream->ref(); | |
74 return tf->fStream; | |
75 } | |
76 return NULL; | |
77 } | |
78 | |
79 void SkFontHost::Serialize(const SkTypeface*, SkWStream*) { | |
80 SkDEBUGFAIL("SkFontHost::Serialize unimplemented"); | |
81 } | |
82 | |
83 SkTypeface* SkFontHost::Deserialize(SkStream* stream) { | |
84 SkDEBUGFAIL("SkFontHost::Deserialize unimplemented"); | |
85 return NULL; | |
86 } | |
87 | |
88 SkTypeface* SkFontHost::NextLogicalTypeface(SkFontID currFontID, SkFontID origFo
ntID) { | |
89 return NULL; | |
90 } | |
91 | |
92 #include "SkTypeface_mac.h" | |
93 | |
94 SkTypeface* SkCreateTypefaceFromCTFont(CTFontRef fontRef) { | |
95 SkDEBUGFAIL("Not supported"); | |
96 return NULL; | |
97 } | |
OLD | NEW |