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

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

Issue 1027373002: Font variations. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Rebase 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
146 SkTypeface* SkTypeface::CreateFromFile(const char path[], int index) { 151 SkTypeface* SkTypeface::CreateFromFile(const char path[], int index) {
147 SkAutoTUnref<SkFontMgr> fm(SkFontMgr::RefDefault()); 152 SkAutoTUnref<SkFontMgr> fm(SkFontMgr::RefDefault());
148 return fm->createFromFile(path, index); 153 return fm->createFromFile(path, index);
149 } 154 }
150 155
151 /////////////////////////////////////////////////////////////////////////////// 156 ///////////////////////////////////////////////////////////////////////////////
152 157
153 void SkTypeface::serialize(SkWStream* wstream) const { 158 void SkTypeface::serialize(SkWStream* wstream) const {
154 bool isLocal = false; 159 bool isLocal = false;
155 SkFontDescriptor desc(this->style()); 160 SkFontDescriptor desc(this->style());
156 this->onGetFontDescriptor(&desc, &isLocal); 161 this->onGetFontDescriptor(&desc, &isLocal);
157 162
158 // Embed font data if it's a local font. 163 // Embed font data if it's a local font.
159 if (isLocal && !desc.hasFontData()) { 164 if (isLocal && !desc.hasFontData()) {
160 int ttcIndex; 165 desc.setFontData(this->onCreateFontData());
161 desc.setFontData(this->onOpenStream(&ttcIndex));
162 desc.setFontIndex(ttcIndex);
163 } 166 }
164 desc.serialize(wstream); 167 desc.serialize(wstream);
165 } 168 }
166 169
167 void SkTypeface::serializeForcingEmbedding(SkWStream* wstream) const { 170 void SkTypeface::serializeForcingEmbedding(SkWStream* wstream) const {
168 bool ignoredIsLocal; 171 bool ignoredIsLocal;
169 SkFontDescriptor desc(this->style()); 172 SkFontDescriptor desc(this->style());
170 this->onGetFontDescriptor(&desc, &ignoredIsLocal); 173 this->onGetFontDescriptor(&desc, &ignoredIsLocal);
171 174
172 // Always embed font data. 175 // Always embed font data.
173 if (!desc.hasFontData()) { 176 if (!desc.hasFontData()) {
174 int ttcIndex; 177 desc.setFontData(this->onCreateFontData());
175 desc.setFontData(this->onOpenStream(&ttcIndex));
176 desc.setFontIndex(ttcIndex);
177 } 178 }
178 desc.serialize(wstream); 179 desc.serialize(wstream);
179 } 180 }
180 181
181 SkTypeface* SkTypeface::Deserialize(SkStream* stream) { 182 SkTypeface* SkTypeface::Deserialize(SkStream* stream) {
182 SkFontDescriptor desc(stream); 183 SkFontDescriptor desc(stream);
183 SkStreamAsset* data = desc.transferFontData(); 184 SkFontData* data = desc.detachFontData();
184 if (data) { 185 if (data) {
185 SkTypeface* typeface = SkTypeface::CreateFromStream(data, desc.getFontIn dex()); 186 SkTypeface* typeface = SkTypeface::CreateFromFontData(data);
186 if (typeface) { 187 if (typeface) {
187 return typeface; 188 return typeface;
188 } 189 }
189 } 190 }
190 return SkTypeface::CreateFromName(desc.getFamilyName(), desc.getStyle()); 191 return SkTypeface::CreateFromName(desc.getFamilyName(), desc.getStyle());
191 } 192 }
192 193
193 /////////////////////////////////////////////////////////////////////////////// 194 ///////////////////////////////////////////////////////////////////////////////
194 195
195 int SkTypeface::countTables() const { 196 int SkTypeface::countTables() const {
(...skipping 15 matching lines...) Expand all
211 212
212 SkStreamAsset* SkTypeface::openStream(int* ttcIndex) const { 213 SkStreamAsset* SkTypeface::openStream(int* ttcIndex) const {
213 int ttcIndexStorage; 214 int ttcIndexStorage;
214 if (NULL == ttcIndex) { 215 if (NULL == ttcIndex) {
215 // So our subclasses don't need to check for null param 216 // So our subclasses don't need to check for null param
216 ttcIndex = &ttcIndexStorage; 217 ttcIndex = &ttcIndexStorage;
217 } 218 }
218 return this->onOpenStream(ttcIndex); 219 return this->onOpenStream(ttcIndex);
219 } 220 }
220 221
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
221 int SkTypeface::charsToGlyphs(const void* chars, Encoding encoding, 233 int SkTypeface::charsToGlyphs(const void* chars, Encoding encoding,
222 uint16_t glyphs[], int glyphCount) const { 234 uint16_t glyphs[], int glyphCount) const {
223 if (glyphCount <= 0) { 235 if (glyphCount <= 0) {
224 return 0; 236 return 0;
225 } 237 }
226 if (NULL == chars || (unsigned)encoding > kUTF32_Encoding) { 238 if (NULL == chars || (unsigned)encoding > kUTF32_Encoding) {
227 if (glyphs) { 239 if (glyphs) {
228 sk_bzero(glyphs, glyphCount * sizeof(glyphs[0])); 240 sk_bzero(glyphs, glyphCount * sizeof(glyphs[0]));
229 } 241 }
230 return 0; 242 return 0;
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
343 if (ctx.get()) { 355 if (ctx.get()) {
344 SkPaint::FontMetrics fm; 356 SkPaint::FontMetrics fm;
345 ctx->getFontMetrics(&fm); 357 ctx->getFontMetrics(&fm);
346 bounds->set(fm.fXMin * invTextSize, fm.fTop * invTextSize, 358 bounds->set(fm.fXMin * invTextSize, fm.fTop * invTextSize,
347 fm.fXMax * invTextSize, fm.fBottom * invTextSize); 359 fm.fXMax * invTextSize, fm.fBottom * invTextSize);
348 return true; 360 return true;
349 } 361 }
350 return false; 362 return false;
351 } 363 }
352 364
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