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

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

Issue 12676024: Force all font backends to override onGetFontDescriptor, so we can (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: Created 7 years, 9 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 | Annotate | Revision Log
OLDNEW
1
2 /* 1 /*
3 * Copyright 2011 The Android Open Source Project 2 * Copyright 2011 The Android Open Source Project
4 * 3 *
5 * 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
6 * found in the LICENSE file. 5 * found in the LICENSE file.
7 */ 6 */
8 7
9
10 #include "SkAdvancedTypefaceMetrics.h" 8 #include "SkAdvancedTypefaceMetrics.h"
9 #include "SkFontDescriptor.h"
10 #include "SkFontHost.h"
11 #include "SkFontStream.h"
12 #include "SkStream.h"
11 #include "SkTypeface.h" 13 #include "SkTypeface.h"
12 #include "SkFontHost.h"
13 14
14 SK_DEFINE_INST_COUNT(SkTypeface) 15 SK_DEFINE_INST_COUNT(SkTypeface)
15 16
16 //#define TRACE_LIFECYCLE 17 //#define TRACE_LIFECYCLE
17 18
18 #ifdef TRACE_LIFECYCLE 19 #ifdef TRACE_LIFECYCLE
19 static int32_t gTypefaceCounter; 20 static int32_t gTypefaceCounter;
20 #endif 21 #endif
21 22
22 SkTypeface::SkTypeface(Style style, SkFontID fontID, bool isFixedWidth) 23 SkTypeface::SkTypeface(Style style, SkFontID fontID, bool isFixedWidth)
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 SkTypeface* SkTypeface::CreateFromStream(SkStream* stream) { 82 SkTypeface* SkTypeface::CreateFromStream(SkStream* stream) {
82 return SkFontHost::CreateTypefaceFromStream(stream); 83 return SkFontHost::CreateTypefaceFromStream(stream);
83 } 84 }
84 85
85 SkTypeface* SkTypeface::CreateFromFile(const char path[]) { 86 SkTypeface* SkTypeface::CreateFromFile(const char path[]) {
86 return SkFontHost::CreateTypefaceFromFile(path); 87 return SkFontHost::CreateTypefaceFromFile(path);
87 } 88 }
88 89
89 /////////////////////////////////////////////////////////////////////////////// 90 ///////////////////////////////////////////////////////////////////////////////
90 91
91 void SkTypeface::serialize(SkWStream* stream) const { 92 void SkTypeface::serialize(SkWStream* wstream) const {
92 SkFontHost::Serialize(this, stream); 93 bool isLocal = false;
94 SkFontDescriptor desc(this->style());
95 this->onGetFontDescriptor(&desc, &isLocal);
96
97 desc.serialize(wstream);
98 if (isLocal) {
99 int ttcIndex; // TODO: write this to the stream?
bungeman-skia 2013/03/22 21:04:05 Yes, we need a issue to track this.
reed1 2013/03/25 12:26:27 Done.
100 SkAutoTUnref<SkStream> rstream(this->openStream(&ttcIndex));
101 if (rstream.get()) {
102 size_t length = rstream->getLength();
103 wstream->writePackedUInt(length);
104 wstream->writeStream(rstream, length);
105 } else {
106 wstream->writePackedUInt(0);
107 }
108 } else {
109 wstream->writePackedUInt(0);
110 }
93 } 111 }
94 112
95 SkTypeface* SkTypeface::Deserialize(SkStream* stream) { 113 SkTypeface* SkTypeface::Deserialize(SkStream* stream) {
96 return SkFontHost::Deserialize(stream); 114 SkFontDescriptor desc(stream);
97 } 115 size_t length = stream->readPackedUInt();
116 if (length > 0) {
117 void* addr = sk_malloc_flags(length, 0);
118 if (addr) {
119 SkAutoTUnref<SkStream> localStream(SkNEW_ARGS(SkMemoryStream,
120 (addr, length, false)));
121 return SkTypeface::CreateFromStream(localStream.get());
bungeman-skia 2013/03/22 21:04:05 In the same issue, or maybe here in comment, note
reed1 2013/03/25 12:26:27 Done.
122 }
123 // failed to allocate, so just skip and create-from-name
124 stream->skip(length);
125 }
98 126
99 SkAdvancedTypefaceMetrics* SkTypeface::getAdvancedTypefaceMetrics( 127 return SkTypeface::CreateFromName(desc.getFamilyName(), desc.getStyle());
100 SkAdvancedTypefaceMetrics::PerGlyphInfo info,
101 const uint32_t* glyphIDs,
102 uint32_t glyphIDsCount) const {
103 return this->onGetAdvancedTypefaceMetrics(info, glyphIDs, glyphIDsCount);
104 } 128 }
105 129
106 /////////////////////////////////////////////////////////////////////////////// 130 ///////////////////////////////////////////////////////////////////////////////
107 131
108 int SkTypeface::countTables() const { 132 int SkTypeface::countTables() const {
109 return this->onGetTableTags(NULL); 133 return this->onGetTableTags(NULL);
110 } 134 }
111 135
112 int SkTypeface::getTableTags(SkFontTableTag tags[]) const { 136 int SkTypeface::getTableTags(SkFontTableTag tags[]) const {
113 return this->onGetTableTags(tags); 137 return this->onGetTableTags(tags);
(...skipping 15 matching lines...) Expand all
129 ttcIndex = &ttcIndexStorage; 153 ttcIndex = &ttcIndexStorage;
130 } 154 }
131 return this->onOpenStream(ttcIndex); 155 return this->onOpenStream(ttcIndex);
132 } 156 }
133 157
134 int SkTypeface::getUnitsPerEm() const { 158 int SkTypeface::getUnitsPerEm() const {
135 // should we try to cache this in the base-class? 159 // should we try to cache this in the base-class?
136 return this->onGetUPEM(); 160 return this->onGetUPEM();
137 } 161 }
138 162
163 SkAdvancedTypefaceMetrics* SkTypeface::getAdvancedTypefaceMetrics(
164 SkAdvancedTypefaceMetrics::PerGlyphInfo info,
165 const uint32_t* glyphIDs,
166 uint32_t glyphIDsCount) const {
167 return this->onGetAdvancedTypefaceMetrics(info, glyphIDs, glyphIDsCount);
168 }
169
139 /////////////////////////////////////////////////////////////////////////////// 170 ///////////////////////////////////////////////////////////////////////////////
140 /////////////////////////////////////////////////////////////////////////////// 171 ///////////////////////////////////////////////////////////////////////////////
141 172
142 #include "SkFontDescriptor.h"
143
144 int SkTypeface::onGetUPEM() const { 173 int SkTypeface::onGetUPEM() const {
145 int upem = 0; 174 int upem = 0;
146 175
147 SkAdvancedTypefaceMetrics* metrics; 176 SkAdvancedTypefaceMetrics* metrics;
148 metrics = this->getAdvancedTypefaceMetrics( 177 metrics = this->getAdvancedTypefaceMetrics(
149 SkAdvancedTypefaceMetrics::kNo_PerGlyphInfo, 178 SkAdvancedTypefaceMetrics::kNo_PerGlyphInfo,
150 NULL, 0); 179 NULL, 0);
151 if (metrics) { 180 if (metrics) {
152 upem = metrics->fEmSize; 181 upem = metrics->fEmSize;
153 metrics->unref(); 182 metrics->unref();
154 } 183 }
155 return upem; 184 return upem;
156 } 185 }
157 186
158 void SkTypeface::onGetFontDescriptor(SkFontDescriptor* desc) const {
159 desc->setStyle(this->style());
160 }
161
162 #include "SkFontStream.h"
163 #include "SkStream.h"
164
165 int SkTypeface::onGetTableTags(SkFontTableTag tags[]) const { 187 int SkTypeface::onGetTableTags(SkFontTableTag tags[]) const {
166 int ttcIndex; 188 int ttcIndex;
167 SkAutoTUnref<SkStream> stream(this->openStream(&ttcIndex)); 189 SkAutoTUnref<SkStream> stream(this->openStream(&ttcIndex));
168 return stream.get() ? SkFontStream::GetTableTags(stream, ttcIndex, tags) : 0 ; 190 return stream.get() ? SkFontStream::GetTableTags(stream, ttcIndex, tags) : 0 ;
169 } 191 }
170 192
171 size_t SkTypeface::onGetTableData(SkFontTableTag tag, size_t offset, 193 size_t SkTypeface::onGetTableData(SkFontTableTag tag, size_t offset,
172 size_t length, void* data) const { 194 size_t length, void* data) const {
173 int ttcIndex; 195 int ttcIndex;
174 SkAutoTUnref<SkStream> stream(this->openStream(&ttcIndex)); 196 SkAutoTUnref<SkStream> stream(this->openStream(&ttcIndex));
175 return stream.get() 197 return stream.get()
176 ? SkFontStream::GetTableData(stream, ttcIndex, tag, offset, length, data ) 198 ? SkFontStream::GetTableData(stream, ttcIndex, tag, offset, length, data )
177 : 0; 199 : 0;
178 } 200 }
201
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698