OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 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 #include "SkFontHost.h" | 8 #include "SkFontHost.h" |
9 #include "SkMMapStream.h" | |
10 #include "SkTypefaceCache.h" | 9 #include "SkTypefaceCache.h" |
11 | 10 |
12 #define FONT_PATH "/Library/Fonts/Skia.ttf" | 11 #define FONT_PATH "/Library/Fonts/Skia.ttf" |
13 | 12 |
14 class FTMacTypeface : public SkTypeface { | 13 class FTMacTypeface : public SkTypeface { |
15 public: | 14 public: |
16 FTMacTypeface(Style style, uint32_t id, SkStream* stream) : SkTypeface(style
, id) { | 15 FTMacTypeface(Style style, uint32_t id, SkStream* stream) : SkTypeface(style
, id) { |
17 // we take ownership of the stream | 16 // we take ownership of the stream |
18 fStream = stream; | 17 fStream = stream; |
19 } | 18 } |
20 | 19 |
21 virtual ~FTMacTypeface() { | 20 virtual ~FTMacTypeface() { |
22 fStream->unref(); | 21 fStream->unref(); |
23 } | 22 } |
24 | 23 |
25 SkStream* fStream; | 24 SkStream* fStream; |
26 }; | 25 }; |
27 | 26 |
28 static FTMacTypeface* create_from_path(const char path[]) { | 27 static FTMacTypeface* create_from_path(const char path[]) { |
29 SkStream* stream = new SkMMAPStream(path); | 28 SkStream* stream = SkStream::NewFromFile(path); |
| 29 if (!stream) { |
| 30 return NULL; |
| 31 } |
| 32 |
30 size_t size = stream->getLength(); | 33 size_t size = stream->getLength(); |
31 SkASSERT(size); | 34 SkASSERT(size); |
32 FTMacTypeface* tf = new FTMacTypeface(SkTypeface::kNormal, | 35 FTMacTypeface* tf = new FTMacTypeface(SkTypeface::kNormal, |
33 SkTypefaceCache::NewFontID(), | 36 SkTypefaceCache::NewFontID(), |
34 stream); | 37 stream); |
35 SkTypefaceCache::Add(tf, SkTypeface::kNormal); | 38 SkTypefaceCache::Add(tf, SkTypeface::kNormal); |
36 return tf; | 39 return tf; |
37 } | 40 } |
38 | 41 |
39 static SkTypeface* ref_default_typeface() { | 42 static SkTypeface* ref_default_typeface() { |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 SkFontID SkFontHost::NextLogicalFont(SkFontID currFontID, SkFontID origFontID) { | 99 SkFontID SkFontHost::NextLogicalFont(SkFontID currFontID, SkFontID origFontID) { |
97 return 0; | 100 return 0; |
98 } | 101 } |
99 | 102 |
100 #include "SkTypeface_mac.h" | 103 #include "SkTypeface_mac.h" |
101 | 104 |
102 SkTypeface* SkCreateTypefaceFromCTFont(CTFontRef fontRef) { | 105 SkTypeface* SkCreateTypefaceFromCTFont(CTFontRef fontRef) { |
103 SkDEBUGFAIL("Not supported"); | 106 SkDEBUGFAIL("Not supported"); |
104 return NULL; | 107 return NULL; |
105 } | 108 } |
OLD | NEW |