| 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 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 119 face = FontConfigTypeface::Create(SkFontStyle(outStyle), indentity, outFamil
yName); | 119 face = FontConfigTypeface::Create(SkFontStyle(outStyle), indentity, outFamil
yName); |
| 120 SkTypefaceCache::Add(face, requestedStyle); | 120 SkTypefaceCache::Add(face, requestedStyle); |
| 121 //SkDebugf("add face <%s> <%s> %p [%d]\n", | 121 //SkDebugf("add face <%s> <%s> %p [%d]\n", |
| 122 // familyName, outFamilyName.c_str(), | 122 // familyName, outFamilyName.c_str(), |
| 123 // face, face->getRefCnt()); | 123 // face, face->getRefCnt()); |
| 124 return face; | 124 return face; |
| 125 } | 125 } |
| 126 | 126 |
| 127 /////////////////////////////////////////////////////////////////////////////// | 127 /////////////////////////////////////////////////////////////////////////////// |
| 128 | 128 |
| 129 SkStream* FontConfigTypeface::onOpenStream(int* ttcIndex) const { | 129 SkStreamAsset* FontConfigTypeface::onOpenStream(int* ttcIndex) const { |
| 130 SkStream* stream = this->getLocalStream(); | 130 SkStreamAsset* stream = this->getLocalStream(); |
| 131 if (stream) { | 131 if (stream) { |
| 132 // should have been provided by CreateFromStream() | 132 // TODO: should have been provided by CreateFromStream() |
| 133 *ttcIndex = 0; | 133 *ttcIndex = 0; |
| 134 return stream->duplicate(); |
| 135 } |
| 134 | 136 |
| 135 SkAutoTDelete<SkStream> dupStream(stream->duplicate()); | 137 SkAutoTUnref<SkFontConfigInterface> fci(RefFCI()); |
| 136 if (dupStream) { | 138 if (NULL == fci.get()) { |
| 137 return dupStream.detach(); | 139 return NULL; |
| 138 } | 140 } |
| 139 | 141 |
| 140 // TODO: update interface use, remove the following code in this block. | 142 *ttcIndex = this->getIdentity().fTTCIndex; |
| 141 size_t length = stream->getLength(); | 143 return fci->openStream(this->getIdentity()); |
| 142 | |
| 143 const void* memory = stream->getMemoryBase(); | |
| 144 if (memory) { | |
| 145 return new SkMemoryStream(memory, length, true); | |
| 146 } | |
| 147 | |
| 148 SkAutoTMalloc<uint8_t> allocMemory(length); | |
| 149 stream->rewind(); | |
| 150 if (length == stream->read(allocMemory.get(), length)) { | |
| 151 SkAutoTDelete<SkMemoryStream> copyStream(new SkMemoryStream()); | |
| 152 copyStream->setMemoryOwned(allocMemory.detach(), length); | |
| 153 return copyStream.detach(); | |
| 154 } | |
| 155 } else { | |
| 156 SkAutoTUnref<SkFontConfigInterface> fci(RefFCI()); | |
| 157 if (NULL == fci.get()) { | |
| 158 return NULL; | |
| 159 } | |
| 160 stream = fci->openStream(this->getIdentity()); | |
| 161 *ttcIndex = this->getIdentity().fTTCIndex; | |
| 162 } | |
| 163 return stream; | |
| 164 } | 144 } |
| 165 | 145 |
| 166 void FontConfigTypeface::onGetFamilyName(SkString* familyName) const { | 146 void FontConfigTypeface::onGetFamilyName(SkString* familyName) const { |
| 167 *familyName = this->getFamilyName(); | 147 *familyName = this->getFamilyName(); |
| 168 } | 148 } |
| 169 | 149 |
| 170 void FontConfigTypeface::onGetFontDescriptor(SkFontDescriptor* desc, | 150 void FontConfigTypeface::onGetFontDescriptor(SkFontDescriptor* desc, |
| 171 bool* isLocalStream) const { | 151 bool* isLocalStream) const { |
| 172 desc->setFamilyName(this->getFamilyName()); | 152 desc->setFamilyName(this->getFamilyName()); |
| 173 desc->setFontIndex(this->getIdentity().fTTCIndex); | 153 desc->setFontIndex(this->getIdentity().fTTCIndex); |
| 174 *isLocalStream = SkToBool(this->getLocalStream()); | 154 *isLocalStream = SkToBool(this->getLocalStream()); |
| 175 } | 155 } |
| OLD | NEW |