Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 | 10 |
| 11 enum { | 11 enum { |
| 12 // these must match the sfnt 'name' enums | 12 // these must match the sfnt 'name' enums |
| 13 kFontFamilyName = 0x01, | 13 kFontFamilyName = 0x01, |
| 14 kFullName = 0x04, | 14 kFullName = 0x04, |
| 15 kPostscriptName = 0x06, | 15 kPostscriptName = 0x06, |
| 16 | 16 |
| 17 // These count backwards from 0xFF, so as not to collide with the SFNT | 17 // These count backwards from 0xFF, so as not to collide with the SFNT |
| 18 // defines for names in its 'name' table. | 18 // defines for names in its 'name' table. |
| 19 kFontFileIndex = 0xFD, | |
| 19 kFontFileName = 0xFE, | 20 kFontFileName = 0xFE, |
| 20 kSentinel = 0xFF, | 21 kSentinel = 0xFF, |
| 21 }; | 22 }; |
| 22 | 23 |
| 23 SkFontDescriptor::SkFontDescriptor(SkTypeface::Style style) { | 24 SkFontDescriptor::SkFontDescriptor(SkTypeface::Style style) : fFontFileIndex(0), fStyle(style) { } |
|
bungeman-skia
2014/09/15 15:52:07
So I took a look into an 'unknown' or 'isn't a col
| |
| 24 fStyle = style; | |
| 25 } | |
| 26 | 25 |
| 27 static void read_string(SkStream* stream, SkString* string) { | 26 static void read_string(SkStream* stream, SkString* string) { |
| 28 const uint32_t length = SkToU32(stream->readPackedUInt()); | 27 const uint32_t length = SkToU32(stream->readPackedUInt()); |
| 29 if (length > 0) { | 28 if (length > 0) { |
| 30 string->resize(length); | 29 string->resize(length); |
| 31 stream->read(string->writable_str(), length); | 30 stream->read(string->writable_str(), length); |
| 32 } | 31 } |
| 33 } | 32 } |
| 34 | 33 |
| 35 static void write_string(SkWStream* stream, const SkString& string, | 34 static void write_string(SkWStream* stream, const SkString& string, |
| 36 uint32_t id) { | 35 uint32_t id) { |
| 37 if (!string.isEmpty()) { | 36 if (!string.isEmpty()) { |
| 38 stream->writePackedUInt(id); | 37 stream->writePackedUInt(id); |
| 39 stream->writePackedUInt(string.size()); | 38 stream->writePackedUInt(string.size()); |
| 40 stream->write(string.c_str(), string.size()); | 39 stream->write(string.c_str(), string.size()); |
| 41 } | 40 } |
| 42 } | 41 } |
| 43 | 42 |
| 44 SkFontDescriptor::SkFontDescriptor(SkStream* stream) { | 43 static size_t read_uint(SkStream* stream) { |
| 44 return stream->readPackedUInt(); | |
| 45 } | |
| 46 | |
| 47 static void write_uint(SkWStream* stream, size_t n, uint32_t id) { | |
| 48 stream->writePackedUInt(id); | |
| 49 stream->writePackedUInt(n); | |
| 50 } | |
| 51 | |
| 52 SkFontDescriptor::SkFontDescriptor(SkStream* stream) : fFontFileIndex(0) { | |
| 45 fStyle = (SkTypeface::Style)stream->readPackedUInt(); | 53 fStyle = (SkTypeface::Style)stream->readPackedUInt(); |
| 46 | 54 |
| 47 for (;;) { | 55 for (;;) { |
| 48 switch (stream->readPackedUInt()) { | 56 switch (stream->readPackedUInt()) { |
| 49 case kFontFamilyName: | 57 case kFontFamilyName: |
| 50 read_string(stream, &fFamilyName); | 58 read_string(stream, &fFamilyName); |
| 51 break; | 59 break; |
| 52 case kFullName: | 60 case kFullName: |
| 53 read_string(stream, &fFullName); | 61 read_string(stream, &fFullName); |
| 54 break; | 62 break; |
| 55 case kPostscriptName: | 63 case kPostscriptName: |
| 56 read_string(stream, &fPostscriptName); | 64 read_string(stream, &fPostscriptName); |
| 57 break; | 65 break; |
| 66 case kFontFileIndex: | |
| 67 fFontFileIndex = read_uint(stream); | |
| 68 break; | |
| 58 case kFontFileName: | 69 case kFontFileName: |
| 59 read_string(stream, &fFontFileName); | 70 read_string(stream, &fFontFileName); |
| 60 break; | 71 break; |
| 61 case kSentinel: | 72 case kSentinel: |
| 62 return; | 73 return; |
| 63 default: | 74 default: |
| 64 SkDEBUGFAIL("Unknown id used by a font descriptor"); | 75 SkDEBUGFAIL("Unknown id used by a font descriptor"); |
| 65 return; | 76 return; |
| 66 } | 77 } |
| 67 } | 78 } |
| 68 } | 79 } |
| 69 | 80 |
| 70 void SkFontDescriptor::serialize(SkWStream* stream) { | 81 void SkFontDescriptor::serialize(SkWStream* stream) { |
| 71 stream->writePackedUInt(fStyle); | 82 stream->writePackedUInt(fStyle); |
| 72 | 83 |
| 73 write_string(stream, fFamilyName, kFontFamilyName); | 84 write_string(stream, fFamilyName, kFontFamilyName); |
| 74 write_string(stream, fFullName, kFullName); | 85 write_string(stream, fFullName, kFullName); |
| 75 write_string(stream, fPostscriptName, kPostscriptName); | 86 write_string(stream, fPostscriptName, kPostscriptName); |
| 76 write_string(stream, fFontFileName, kFontFileName); | 87 write_string(stream, fFontFileName, kFontFileName); |
| 88 write_uint(stream, fFontFileIndex, kFontFileIndex); | |
| 77 | 89 |
| 78 stream->writePackedUInt(kSentinel); | 90 stream->writePackedUInt(kSentinel); |
| 79 } | 91 } |
| OLD | NEW |