| 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" |
| 11 #include "SkFontHost.h" | 11 #include "SkFontHost.h" |
| 12 #include "SkFontHost_FreeType_common.h" | 12 #include "SkFontHost_FreeType_common.h" |
| 13 #include "SkFontStream.h" | 13 #include "SkFontStream.h" |
| 14 #include "SkStream.h" | 14 #include "SkStream.h" |
| 15 #include "SkTypeface.h" | 15 #include "SkTypeface.h" |
| 16 #include "SkTypefaceCache.h" | 16 #include "SkTypefaceCache.h" |
| 17 | 17 |
| 18 // Defined in SkFontHost_FreeType.cpp | |
| 19 bool find_name_and_attributes(SkStream* stream, SkString* name, | |
| 20 SkTypeface::Style* style, bool* isFixedWidth); | |
| 21 | |
| 22 /////////////////////////////////////////////////////////////////////////////// | 18 /////////////////////////////////////////////////////////////////////////////// |
| 23 /////////////////////////////////////////////////////////////////////////////// | 19 /////////////////////////////////////////////////////////////////////////////// |
| 24 | 20 |
| 25 SK_DECLARE_STATIC_MUTEX(gFontConfigInterfaceMutex); | 21 SK_DECLARE_STATIC_MUTEX(gFontConfigInterfaceMutex); |
| 26 static SkFontConfigInterface* gFontConfigInterface; | 22 static SkFontConfigInterface* gFontConfigInterface; |
| 27 | 23 |
| 28 SkFontConfigInterface* SkFontConfigInterface::RefGlobal() { | 24 SkFontConfigInterface* SkFontConfigInterface::RefGlobal() { |
| 29 SkAutoMutexAcquire ac(gFontConfigInterfaceMutex); | 25 SkAutoMutexAcquire ac(gFontConfigInterfaceMutex); |
| 30 | 26 |
| 31 return SkSafeRef(gFontConfigInterface); | 27 return SkSafeRef(gFontConfigInterface); |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 141 if (!length) { | 137 if (!length) { |
| 142 return NULL; | 138 return NULL; |
| 143 } | 139 } |
| 144 if (length >= 1024 * 1024 * 1024) { | 140 if (length >= 1024 * 1024 * 1024) { |
| 145 return NULL; // don't accept too large fonts (>= 1GB) for safety. | 141 return NULL; // don't accept too large fonts (>= 1GB) for safety. |
| 146 } | 142 } |
| 147 | 143 |
| 148 // ask freetype for reported style and if it is a fixed width font | 144 // ask freetype for reported style and if it is a fixed width font |
| 149 SkTypeface::Style style = SkTypeface::kNormal; | 145 SkTypeface::Style style = SkTypeface::kNormal; |
| 150 bool isFixedWidth = false; | 146 bool isFixedWidth = false; |
| 151 if (!find_name_and_attributes(stream, NULL, &style, &isFixedWidth)) { | 147 if (!SkTypeface_FreeType::ScanFont(stream, 0, NULL, &style, &isFixedWidth))
{ |
| 152 return NULL; | 148 return NULL; |
| 153 } | 149 } |
| 154 | 150 |
| 155 SkTypeface* face = SkNEW_ARGS(FontConfigTypeface, (style, isFixedWidth, stre
am)); | 151 SkTypeface* face = SkNEW_ARGS(FontConfigTypeface, (style, isFixedWidth, stre
am)); |
| 156 return face; | 152 return face; |
| 157 } | 153 } |
| 158 | 154 |
| 159 SkTypeface* SkFontHost::CreateTypefaceFromFile(const char path[]) { | 155 SkTypeface* SkFontHost::CreateTypefaceFromFile(const char path[]) { |
| 160 SkAutoTUnref<SkStream> stream(SkStream::NewFromFile(path)); | 156 SkAutoTUnref<SkStream> stream(SkStream::NewFromFile(path)); |
| 161 return stream.get() ? CreateTypefaceFromStream(stream) : NULL; | 157 return stream.get() ? CreateTypefaceFromStream(stream) : NULL; |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 203 *ttcIndex = this->getIdentity().fTTCIndex; | 199 *ttcIndex = this->getIdentity().fTTCIndex; |
| 204 } | 200 } |
| 205 return stream; | 201 return stream; |
| 206 } | 202 } |
| 207 | 203 |
| 208 void FontConfigTypeface::onGetFontDescriptor(SkFontDescriptor* desc, | 204 void FontConfigTypeface::onGetFontDescriptor(SkFontDescriptor* desc, |
| 209 bool* isLocalStream) const { | 205 bool* isLocalStream) const { |
| 210 desc->setFamilyName(this->getFamilyName()); | 206 desc->setFamilyName(this->getFamilyName()); |
| 211 *isLocalStream = SkToBool(this->getLocalStream()); | 207 *isLocalStream = SkToBool(this->getLocalStream()); |
| 212 } | 208 } |
| OLD | NEW |