OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2008 Google Inc. | 2 * Copyright 2008 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 "SkFontConfigInterface.h" | 8 #include "SkFontConfigInterface.h" |
9 #include "SkFontConfigTypeface.h" | 9 #include "SkFontConfigTypeface.h" |
10 #include "SkFontDescriptor.h" | 10 #include "SkFontDescriptor.h" |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
129 SkTypeface* SkFontHost::CreateTypefaceFromFile(const char path[]) { | 129 SkTypeface* SkFontHost::CreateTypefaceFromFile(const char path[]) { |
130 SkAutoTUnref<SkStream> stream(SkStream::NewFromFile(path)); | 130 SkAutoTUnref<SkStream> stream(SkStream::NewFromFile(path)); |
131 return stream.get() ? CreateTypefaceFromStream(stream) : NULL; | 131 return stream.get() ? CreateTypefaceFromStream(stream) : NULL; |
132 } | 132 } |
133 | 133 |
134 /////////////////////////////////////////////////////////////////////////////// | 134 /////////////////////////////////////////////////////////////////////////////// |
135 | 135 |
136 SkStream* FontConfigTypeface::onOpenStream(int* ttcIndex) const { | 136 SkStream* FontConfigTypeface::onOpenStream(int* ttcIndex) const { |
137 SkStream* stream = this->getLocalStream(); | 137 SkStream* stream = this->getLocalStream(); |
138 if (stream) { | 138 if (stream) { |
139 // TODO: fix issue 1176. | 139 // should have been provided by CreateFromStream() |
140 // As of now open_stream will return a stream and unwind it, but the | 140 *ttcIndex = 0; |
141 // SkStream is not thread safe, and if two threads use the stream they | 141 |
142 // may collide and print preview for example could still fail, | 142 SkAutoTUnref<SkStream> dupStream(stream->duplicate()); |
143 // or there could be some failures in rendering if this stream is used | 143 if (dupStream) { |
144 // there. | 144 return dupStream.detach(); |
| 145 } |
| 146 |
| 147 // TODO: update interface use, remove the following code in this block. |
| 148 size_t length = stream->getLength(); |
| 149 |
| 150 const void* memory = stream->getMemoryBase(); |
| 151 if (NULL != memory) { |
| 152 return new SkMemoryStream(memory, length); |
| 153 } |
| 154 |
| 155 SkAutoTMalloc<uint8_t> allocMemory(length); |
| 156 stream->rewind(); |
| 157 if (length == stream->read(allocMemory.get(), length)) { |
| 158 return new SkMemoryStream(allocMemory.detach(), length); |
| 159 } |
| 160 |
145 stream->rewind(); | 161 stream->rewind(); |
146 stream->ref(); | 162 stream->ref(); |
147 // should have been provided by CreateFromStream() | |
148 *ttcIndex = 0; | |
149 } else { | 163 } else { |
150 SkAutoTUnref<SkFontConfigInterface> fci(RefFCI()); | 164 SkAutoTUnref<SkFontConfigInterface> fci(RefFCI()); |
151 if (NULL == fci.get()) { | 165 if (NULL == fci.get()) { |
152 return NULL; | 166 return NULL; |
153 } | 167 } |
154 stream = fci->openStream(this->getIdentity()); | 168 stream = fci->openStream(this->getIdentity()); |
155 *ttcIndex = this->getIdentity().fTTCIndex; | 169 *ttcIndex = this->getIdentity().fTTCIndex; |
156 } | 170 } |
157 return stream; | 171 return stream; |
158 } | 172 } |
(...skipping 16 matching lines...) Expand all Loading... |
175 : 0; | 189 : 0; |
176 } | 190 } |
177 | 191 |
178 void FontConfigTypeface::onGetFontDescriptor(SkFontDescriptor* desc, | 192 void FontConfigTypeface::onGetFontDescriptor(SkFontDescriptor* desc, |
179 bool* isLocalStream) const { | 193 bool* isLocalStream) const { |
180 desc->setFamilyName(this->getFamilyName()); | 194 desc->setFamilyName(this->getFamilyName()); |
181 *isLocalStream = SkToBool(this->getLocalStream()); | 195 *isLocalStream = SkToBool(this->getLocalStream()); |
182 } | 196 } |
183 | 197 |
184 /////////////////////////////////////////////////////////////////////////////// | 198 /////////////////////////////////////////////////////////////////////////////// |
OLD | NEW |