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

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

Issue 2030683002: Update typeface serialization style. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Rebase Created 4 years, 6 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/SkFontDescriptor.h ('k') | src/core/SkTypeface.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 2012 Google Inc. 2 * Copyright 2012 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 "SkFontDescriptor.h" 8 #include "SkFontDescriptor.h"
9 #include "SkStream.h" 9 #include "SkStream.h"
10 #include "SkData.h" 10 #include "SkData.h"
11 11
12 enum { 12 enum {
13 // these must match the sfnt 'name' enums 13 // these must match the sfnt 'name' enums
14 kFontFamilyName = 0x01, 14 kFontFamilyName = 0x01,
15 kFullName = 0x04, 15 kFullName = 0x04,
16 kPostscriptName = 0x06, 16 kPostscriptName = 0x06,
17 17
18 // These count backwards from 0xFF, so as not to collide with the SFNT 18 // These count backwards from 0xFF, so as not to collide with the SFNT
19 // defines for names in its 'name' table. 19 // defines for names in its 'name' table.
20 kFontAxes = 0xFC, 20 kFontAxes = 0xFC,
21 kFontIndex = 0xFD, 21 kFontIndex = 0xFD,
22 kFontFileName = 0xFE, // Remove when MIN_PICTURE_VERSION > 41 22 kFontFileName = 0xFE, // Remove when MIN_PICTURE_VERSION > 41
23 kSentinel = 0xFF, 23 kSentinel = 0xFF,
24 }; 24 };
25 25
26 SkFontDescriptor::SkFontDescriptor(SkTypeface::Style style) : fStyle(style) { } 26 SkFontDescriptor::SkFontDescriptor() { }
27 27
28 static void read_string(SkStream* stream, SkString* string) { 28 static void read_string(SkStream* stream, SkString* string) {
29 const uint32_t length = SkToU32(stream->readPackedUInt()); 29 const uint32_t length = SkToU32(stream->readPackedUInt());
30 if (length > 0) { 30 if (length > 0) {
31 string->resize(length); 31 string->resize(length);
32 stream->read(string->writable_str(), length); 32 stream->read(string->writable_str(), length);
33 } 33 }
34 } 34 }
35 35
36 // Remove when MIN_PICTURE_VERSION > 41 36 // Remove when MIN_PICTURE_VERSION > 41
(...skipping 15 matching lines...) Expand all
52 static size_t read_uint(SkStream* stream) { 52 static size_t read_uint(SkStream* stream) {
53 return stream->readPackedUInt(); 53 return stream->readPackedUInt();
54 } 54 }
55 55
56 static void write_uint(SkWStream* stream, size_t n, uint32_t id) { 56 static void write_uint(SkWStream* stream, size_t n, uint32_t id) {
57 stream->writePackedUInt(id); 57 stream->writePackedUInt(id);
58 stream->writePackedUInt(n); 58 stream->writePackedUInt(n);
59 } 59 }
60 60
61 bool SkFontDescriptor::Deserialize(SkStream* stream, SkFontDescriptor* result) { 61 bool SkFontDescriptor::Deserialize(SkStream* stream, SkFontDescriptor* result) {
62 result->fStyle = (SkTypeface::Style)stream->readPackedUInt(); 62 size_t styleBits = stream->readPackedUInt();
63 if (styleBits <= 2) {
64 // Remove this branch when MIN_PICTURE_VERSION > 45
65 result->fStyle = SkFontStyle::FromOldStyle(styleBits);
66 } else {
67 result->fStyle = SkFontStyle((styleBits >> 16) & 0xFFFF,
68 (styleBits >> 8 ) & 0xFF,
69 static_cast<SkFontStyle::Slant>(styleBits & 0xFF));
70 }
63 71
64 SkAutoSTMalloc<4, SkFixed> axis; 72 SkAutoSTMalloc<4, SkFixed> axis;
65 size_t axisCount = 0; 73 size_t axisCount = 0;
66 size_t index = 0; 74 size_t index = 0;
67 for (size_t id; (id = stream->readPackedUInt()) != kSentinel;) { 75 for (size_t id; (id = stream->readPackedUInt()) != kSentinel;) {
68 switch (id) { 76 switch (id) {
69 case kFontFamilyName: 77 case kFontFamilyName:
70 read_string(stream, &result->fFamilyName); 78 read_string(stream, &result->fFamilyName);
71 break; 79 break;
72 case kFullName: 80 case kFullName:
(...skipping 29 matching lines...) Expand all
102 index, axis, axisCount)); 110 index, axis, axisCount));
103 } else { 111 } else {
104 SkDEBUGFAIL("Could not read font data"); 112 SkDEBUGFAIL("Could not read font data");
105 return false; 113 return false;
106 } 114 }
107 } 115 }
108 return true; 116 return true;
109 } 117 }
110 118
111 void SkFontDescriptor::serialize(SkWStream* stream) { 119 void SkFontDescriptor::serialize(SkWStream* stream) {
112 stream->writePackedUInt(fStyle); 120 uint32_t styleBits = (fStyle.weight() << 16) | (fStyle.width() << 8) | (fSty le.slant());
121 stream->writePackedUInt(styleBits);
113 122
114 write_string(stream, fFamilyName, kFontFamilyName); 123 write_string(stream, fFamilyName, kFontFamilyName);
115 write_string(stream, fFullName, kFullName); 124 write_string(stream, fFullName, kFullName);
116 write_string(stream, fPostscriptName, kPostscriptName); 125 write_string(stream, fPostscriptName, kPostscriptName);
117 if (fFontData.get()) { 126 if (fFontData.get()) {
118 if (fFontData->getIndex()) { 127 if (fFontData->getIndex()) {
119 write_uint(stream, fFontData->getIndex(), kFontIndex); 128 write_uint(stream, fFontData->getIndex(), kFontIndex);
120 } 129 }
121 if (fFontData->getAxisCount()) { 130 if (fFontData->getAxisCount()) {
122 write_uint(stream, fFontData->getAxisCount(), kFontAxes); 131 write_uint(stream, fFontData->getAxisCount(), kFontAxes);
123 for (int i = 0; i < fFontData->getAxisCount(); ++i) { 132 for (int i = 0; i < fFontData->getAxisCount(); ++i) {
124 stream->writePackedUInt(fFontData->getAxis()[i]); 133 stream->writePackedUInt(fFontData->getAxis()[i]);
125 } 134 }
126 } 135 }
127 } 136 }
128 137
129 stream->writePackedUInt(kSentinel); 138 stream->writePackedUInt(kSentinel);
130 139
131 if (fFontData.get() && fFontData->hasStream()) { 140 if (fFontData.get() && fFontData->hasStream()) {
132 SkAutoTDelete<SkStreamAsset> fontData(fFontData->detachStream()); 141 SkAutoTDelete<SkStreamAsset> fontData(fFontData->detachStream());
133 size_t length = fontData->getLength(); 142 size_t length = fontData->getLength();
134 stream->writePackedUInt(length); 143 stream->writePackedUInt(length);
135 stream->writeStream(fontData, length); 144 stream->writeStream(fontData, length);
136 } else { 145 } else {
137 stream->writePackedUInt(0); 146 stream->writePackedUInt(0);
138 } 147 }
139 } 148 }
OLDNEW
« no previous file with comments | « src/core/SkFontDescriptor.h ('k') | src/core/SkTypeface.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698