Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(54)

Side by Side Diff: src/core/SkTypeface.cpp

Issue 1128913008: Revert of Font variations. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/core/SkFontMgr.cpp ('k') | src/fonts/SkFontMgr_fontconfig.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2011 The Android Open Source Project 2 * Copyright 2011 The Android Open Source Project
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 "SkAdvancedTypefaceMetrics.h" 8 #include "SkAdvancedTypefaceMetrics.h"
9 #include "SkEndian.h" 9 #include "SkEndian.h"
10 #include "SkFontDescriptor.h" 10 #include "SkFontDescriptor.h"
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 italic ? SkFontStyle::kItalic_Slant 136 italic ? SkFontStyle::kItalic_Slant
137 : SkFontStyle::kUpright_Slant); 137 : SkFontStyle::kUpright_Slant);
138 return fm->matchFaceStyle(family, newStyle); 138 return fm->matchFaceStyle(family, newStyle);
139 } 139 }
140 140
141 SkTypeface* SkTypeface::CreateFromStream(SkStreamAsset* stream, int index) { 141 SkTypeface* SkTypeface::CreateFromStream(SkStreamAsset* stream, int index) {
142 SkAutoTUnref<SkFontMgr> fm(SkFontMgr::RefDefault()); 142 SkAutoTUnref<SkFontMgr> fm(SkFontMgr::RefDefault());
143 return fm->createFromStream(stream, index); 143 return fm->createFromStream(stream, index);
144 } 144 }
145 145
146 SkTypeface* SkTypeface::CreateFromFontData(SkFontData* data) {
147 SkAutoTUnref<SkFontMgr> fm(SkFontMgr::RefDefault());
148 return fm->createFromFontData(data);
149 }
150
151 SkTypeface* SkTypeface::CreateFromFile(const char path[], int index) { 146 SkTypeface* SkTypeface::CreateFromFile(const char path[], int index) {
152 SkAutoTUnref<SkFontMgr> fm(SkFontMgr::RefDefault()); 147 SkAutoTUnref<SkFontMgr> fm(SkFontMgr::RefDefault());
153 return fm->createFromFile(path, index); 148 return fm->createFromFile(path, index);
154 } 149 }
155 150
156 /////////////////////////////////////////////////////////////////////////////// 151 ///////////////////////////////////////////////////////////////////////////////
157 152
158 void SkTypeface::serialize(SkWStream* wstream) const { 153 void SkTypeface::serialize(SkWStream* wstream) const {
159 bool isLocal = false; 154 bool isLocal = false;
160 SkFontDescriptor desc(this->style()); 155 SkFontDescriptor desc(this->style());
161 this->onGetFontDescriptor(&desc, &isLocal); 156 this->onGetFontDescriptor(&desc, &isLocal);
162 157
163 // Embed font data if it's a local font. 158 // Embed font data if it's a local font.
164 if (!desc.hasFontData()) { 159 if (isLocal && !desc.hasFontData()) {
165 desc.setFontData(this->onCreateFontData()); 160 int ttcIndex;
161 desc.setFontData(this->onOpenStream(&ttcIndex));
162 desc.setFontIndex(ttcIndex);
166 } 163 }
167 desc.serialize(wstream); 164 desc.serialize(wstream);
168 } 165 }
169 166
170 void SkTypeface::serializeForcingEmbedding(SkWStream* wstream) const { 167 void SkTypeface::serializeForcingEmbedding(SkWStream* wstream) const {
171 bool ignoredIsLocal; 168 bool ignoredIsLocal;
172 SkFontDescriptor desc(this->style()); 169 SkFontDescriptor desc(this->style());
173 this->onGetFontDescriptor(&desc, &ignoredIsLocal); 170 this->onGetFontDescriptor(&desc, &ignoredIsLocal);
174 171
175 // Always embed font data. 172 // Always embed font data.
176 if (!desc.hasFontData()) { 173 if (!desc.hasFontData()) {
177 desc.setFontData(this->onCreateFontData()); 174 int ttcIndex;
175 desc.setFontData(this->onOpenStream(&ttcIndex));
176 desc.setFontIndex(ttcIndex);
178 } 177 }
179 desc.serialize(wstream); 178 desc.serialize(wstream);
180 } 179 }
181 180
182 SkTypeface* SkTypeface::Deserialize(SkStream* stream) { 181 SkTypeface* SkTypeface::Deserialize(SkStream* stream) {
183 SkFontDescriptor desc(stream); 182 SkFontDescriptor desc(stream);
184 SkFontData* data = desc.detachFontData(); 183 SkStreamAsset* data = desc.transferFontData();
185 if (data) { 184 if (data) {
186 SkTypeface* typeface = SkTypeface::CreateFromFontData(data); 185 SkTypeface* typeface = SkTypeface::CreateFromStream(data, desc.getFontIn dex());
187 if (typeface) { 186 if (typeface) {
188 return typeface; 187 return typeface;
189 } 188 }
190 } 189 }
191 return SkTypeface::CreateFromName(desc.getFamilyName(), desc.getStyle()); 190 return SkTypeface::CreateFromName(desc.getFamilyName(), desc.getStyle());
192 } 191 }
193 192
194 /////////////////////////////////////////////////////////////////////////////// 193 ///////////////////////////////////////////////////////////////////////////////
195 194
196 int SkTypeface::countTables() const { 195 int SkTypeface::countTables() const {
(...skipping 15 matching lines...) Expand all
212 211
213 SkStreamAsset* SkTypeface::openStream(int* ttcIndex) const { 212 SkStreamAsset* SkTypeface::openStream(int* ttcIndex) const {
214 int ttcIndexStorage; 213 int ttcIndexStorage;
215 if (NULL == ttcIndex) { 214 if (NULL == ttcIndex) {
216 // So our subclasses don't need to check for null param 215 // So our subclasses don't need to check for null param
217 ttcIndex = &ttcIndexStorage; 216 ttcIndex = &ttcIndexStorage;
218 } 217 }
219 return this->onOpenStream(ttcIndex); 218 return this->onOpenStream(ttcIndex);
220 } 219 }
221 220
222 SkFontData* SkTypeface::createFontData() const {
223 return this->onCreateFontData();
224 }
225
226 // This implementation is temporary until this method can be made pure virtual.
227 SkFontData* SkTypeface::onCreateFontData() const {
228 int index;
229 SkAutoTDelete<SkStreamAsset> stream(this->onOpenStream(&index));
230 return new SkFontData(stream.detach(), index, NULL, 0);
231 };
232
233 int SkTypeface::charsToGlyphs(const void* chars, Encoding encoding, 221 int SkTypeface::charsToGlyphs(const void* chars, Encoding encoding,
234 uint16_t glyphs[], int glyphCount) const { 222 uint16_t glyphs[], int glyphCount) const {
235 if (glyphCount <= 0) { 223 if (glyphCount <= 0) {
236 return 0; 224 return 0;
237 } 225 }
238 if (NULL == chars || (unsigned)encoding > kUTF32_Encoding) { 226 if (NULL == chars || (unsigned)encoding > kUTF32_Encoding) {
239 if (glyphs) { 227 if (glyphs) {
240 sk_bzero(glyphs, glyphCount * sizeof(glyphs[0])); 228 sk_bzero(glyphs, glyphCount * sizeof(glyphs[0]));
241 } 229 }
242 return 0; 230 return 0;
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
355 if (ctx.get()) { 343 if (ctx.get()) {
356 SkPaint::FontMetrics fm; 344 SkPaint::FontMetrics fm;
357 ctx->getFontMetrics(&fm); 345 ctx->getFontMetrics(&fm);
358 bounds->set(fm.fXMin * invTextSize, fm.fTop * invTextSize, 346 bounds->set(fm.fXMin * invTextSize, fm.fTop * invTextSize,
359 fm.fXMax * invTextSize, fm.fBottom * invTextSize); 347 fm.fXMax * invTextSize, fm.fBottom * invTextSize);
360 return true; 348 return true;
361 } 349 }
362 return false; 350 return false;
363 } 351 }
364 352
OLDNEW
« no previous file with comments | « src/core/SkFontMgr.cpp ('k') | src/fonts/SkFontMgr_fontconfig.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698