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

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

Issue 1057413005: Remove filename from SkFontDescriptor. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Add file name to assert. Created 5 years, 8 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/SkPaint.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 kFontIndex = 0xFD, 20 kFontIndex = 0xFD,
21 kFontFileName = 0xFE, 21 kFontFileName = 0xFE, // Remove when MIN_PICTURE_VERSION > 41
22 kSentinel = 0xFF, 22 kSentinel = 0xFF,
23 }; 23 };
24 24
25 SkFontDescriptor::SkFontDescriptor(SkTypeface::Style style) : fFontIndex(0), fSt yle(style) { } 25 SkFontDescriptor::SkFontDescriptor(SkTypeface::Style style) : fFontIndex(0), fSt yle(style) { }
26 26
27 static void read_string(SkStream* stream, SkString* string) { 27 static void read_string(SkStream* stream, SkString* string) {
28 const uint32_t length = SkToU32(stream->readPackedUInt()); 28 const uint32_t length = SkToU32(stream->readPackedUInt());
29 if (length > 0) { 29 if (length > 0) {
30 string->resize(length); 30 string->resize(length);
31 stream->read(string->writable_str(), length); 31 stream->read(string->writable_str(), length);
32 } 32 }
33 } 33 }
34 34
35 // Remove when MIN_PICTURE_VERSION > 41
36 static void skip_string(SkStream* stream) {
37 const uint32_t length = SkToU32(stream->readPackedUInt());
38 if (length > 0) {
39 stream->skip(length);
40 }
41 }
42
35 static void write_string(SkWStream* stream, const SkString& string, 43 static void write_string(SkWStream* stream, const SkString& string,
36 uint32_t id) { 44 uint32_t id) {
37 if (!string.isEmpty()) { 45 if (!string.isEmpty()) {
38 stream->writePackedUInt(id); 46 stream->writePackedUInt(id);
39 stream->writePackedUInt(string.size()); 47 stream->writePackedUInt(string.size());
40 stream->write(string.c_str(), string.size()); 48 stream->write(string.c_str(), string.size());
41 } 49 }
42 } 50 }
43 51
44 static size_t read_uint(SkStream* stream) { 52 static size_t read_uint(SkStream* stream) {
(...skipping 15 matching lines...) Expand all
60 break; 68 break;
61 case kFullName: 69 case kFullName:
62 read_string(stream, &fFullName); 70 read_string(stream, &fFullName);
63 break; 71 break;
64 case kPostscriptName: 72 case kPostscriptName:
65 read_string(stream, &fPostscriptName); 73 read_string(stream, &fPostscriptName);
66 break; 74 break;
67 case kFontIndex: 75 case kFontIndex:
68 fFontIndex = read_uint(stream); 76 fFontIndex = read_uint(stream);
69 break; 77 break;
70 case kFontFileName: 78 case kFontFileName: // Remove when MIN_PICTURE_VERSION > 41
71 read_string(stream, &fFontFileName); 79 skip_string(stream);
72 break; 80 break;
73 default: 81 default:
74 SkDEBUGFAIL("Unknown id used by a font descriptor"); 82 SkDEBUGFAIL("Unknown id used by a font descriptor");
75 return; 83 return;
76 } 84 }
77 } 85 }
78 86
79 size_t length = stream->readPackedUInt(); 87 size_t length = stream->readPackedUInt();
80 if (length > 0) { 88 if (length > 0) {
81 SkAutoTUnref<SkData> data(SkData::NewUninitialized(length)); 89 SkAutoTUnref<SkData> data(SkData::NewUninitialized(length));
82 if (stream->read(data->writable_data(), length) == length) { 90 if (stream->read(data->writable_data(), length) == length) {
83 fFontData.reset(SkNEW_ARGS(SkMemoryStream, (data))); 91 fFontData.reset(SkNEW_ARGS(SkMemoryStream, (data)));
84 } 92 }
85 } 93 }
86 } 94 }
87 95
88 void SkFontDescriptor::serialize(SkWStream* stream) { 96 void SkFontDescriptor::serialize(SkWStream* stream) {
89 stream->writePackedUInt(fStyle); 97 stream->writePackedUInt(fStyle);
90 98
91 write_string(stream, fFamilyName, kFontFamilyName); 99 write_string(stream, fFamilyName, kFontFamilyName);
92 write_string(stream, fFullName, kFullName); 100 write_string(stream, fFullName, kFullName);
93 write_string(stream, fPostscriptName, kPostscriptName); 101 write_string(stream, fPostscriptName, kPostscriptName);
94 write_string(stream, fFontFileName, kFontFileName);
95 if (fFontIndex) { 102 if (fFontIndex) {
96 write_uint(stream, fFontIndex, kFontIndex); 103 write_uint(stream, fFontIndex, kFontIndex);
97 } 104 }
98 105
99 stream->writePackedUInt(kSentinel); 106 stream->writePackedUInt(kSentinel);
100 107
101 if (fFontData) { 108 if (fFontData) {
102 size_t length = fFontData->getLength(); 109 size_t length = fFontData->getLength();
103 stream->writePackedUInt(length); 110 stream->writePackedUInt(length);
104 stream->writeStream(fFontData, length); 111 stream->writeStream(fFontData, length);
105 } else { 112 } else {
106 stream->writePackedUInt(0); 113 stream->writePackedUInt(0);
107 } 114 }
108 } 115 }
OLDNEW
« no previous file with comments | « src/core/SkFontDescriptor.h ('k') | src/core/SkPaint.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698