| 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 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 117 if (face) { | 117 if (face) { |
| 118 return face; | 118 return face; |
| 119 } | 119 } |
| 120 | 120 |
| 121 face = SkNEW_ARGS(FontConfigTypeface, (outStyle, indentity, outFamilyName)); | 121 face = SkNEW_ARGS(FontConfigTypeface, (outStyle, indentity, outFamilyName)); |
| 122 SkTypefaceCache::Add(face, style); | 122 SkTypefaceCache::Add(face, style); |
| 123 // SkDebugf("add face <%s> <%s> %p [%d]\n", familyName, outFamilyName.c_str()
, face, face->getRefCnt()); | 123 // SkDebugf("add face <%s> <%s> %p [%d]\n", familyName, outFamilyName.c_str()
, face, face->getRefCnt()); |
| 124 return face; | 124 return face; |
| 125 } | 125 } |
| 126 | 126 |
| 127 #ifndef SK_FONTHOST_USES_FONTMGR | |
| 128 | |
| 129 SkTypeface* SkFontHost::CreateTypeface(const SkTypeface* familyFace, | |
| 130 const char familyName[], | |
| 131 SkTypeface::Style style) { | |
| 132 return FontConfigTypeface::LegacyCreateTypeface(familyFace, familyName, | |
| 133 style); | |
| 134 } | |
| 135 | |
| 136 SkTypeface* SkFontHost::CreateTypefaceFromStream(SkStream* stream) { | |
| 137 if (!stream) { | |
| 138 return NULL; | |
| 139 } | |
| 140 const size_t length = stream->getLength(); | |
| 141 if (!length) { | |
| 142 return NULL; | |
| 143 } | |
| 144 if (length >= 1024 * 1024 * 1024) { | |
| 145 return NULL; // don't accept too large fonts (>= 1GB) for safety. | |
| 146 } | |
| 147 | |
| 148 // ask freetype for reported style and if it is a fixed width font | |
| 149 SkTypeface::Style style = SkTypeface::kNormal; | |
| 150 bool isFixedWidth = false; | |
| 151 if (!find_name_and_attributes(stream, NULL, &style, &isFixedWidth)) { | |
| 152 return NULL; | |
| 153 } | |
| 154 | |
| 155 SkTypeface* face = SkNEW_ARGS(FontConfigTypeface, (style, isFixedWidth, stre
am)); | |
| 156 return face; | |
| 157 } | |
| 158 | |
| 159 SkTypeface* SkFontHost::CreateTypefaceFromFile(const char path[]) { | |
| 160 SkAutoTUnref<SkStream> stream(SkStream::NewFromFile(path)); | |
| 161 return stream.get() ? CreateTypefaceFromStream(stream) : NULL; | |
| 162 } | |
| 163 | |
| 164 #endif | |
| 165 | |
| 166 /////////////////////////////////////////////////////////////////////////////// | 127 /////////////////////////////////////////////////////////////////////////////// |
| 167 | 128 |
| 168 SkStream* FontConfigTypeface::onOpenStream(int* ttcIndex) const { | 129 SkStream* FontConfigTypeface::onOpenStream(int* ttcIndex) const { |
| 169 SkStream* stream = this->getLocalStream(); | 130 SkStream* stream = this->getLocalStream(); |
| 170 if (stream) { | 131 if (stream) { |
| 171 // should have been provided by CreateFromStream() | 132 // should have been provided by CreateFromStream() |
| 172 *ttcIndex = 0; | 133 *ttcIndex = 0; |
| 173 | 134 |
| 174 SkAutoTUnref<SkStream> dupStream(stream->duplicate()); | 135 SkAutoTUnref<SkStream> dupStream(stream->duplicate()); |
| 175 if (dupStream) { | 136 if (dupStream) { |
| (...skipping 27 matching lines...) Expand all Loading... |
| 203 *ttcIndex = this->getIdentity().fTTCIndex; | 164 *ttcIndex = this->getIdentity().fTTCIndex; |
| 204 } | 165 } |
| 205 return stream; | 166 return stream; |
| 206 } | 167 } |
| 207 | 168 |
| 208 void FontConfigTypeface::onGetFontDescriptor(SkFontDescriptor* desc, | 169 void FontConfigTypeface::onGetFontDescriptor(SkFontDescriptor* desc, |
| 209 bool* isLocalStream) const { | 170 bool* isLocalStream) const { |
| 210 desc->setFamilyName(this->getFamilyName()); | 171 desc->setFamilyName(this->getFamilyName()); |
| 211 *isLocalStream = SkToBool(this->getLocalStream()); | 172 *isLocalStream = SkToBool(this->getLocalStream()); |
| 212 } | 173 } |
| 213 | |
| 214 SkTypeface* FontConfigTypeface::onRefMatchingStyle(Style style) const { | |
| 215 return LegacyCreateTypeface(this, NULL, style); | |
| 216 } | |
| OLD | NEW |