gfx/skia/trunk/src/core/SkFontDescriptor.cpp

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

michael@0 1 /*
michael@0 2 * Copyright 2012 Google Inc.
michael@0 3 *
michael@0 4 * Use of this source code is governed by a BSD-style license that can be
michael@0 5 * found in the LICENSE file.
michael@0 6 */
michael@0 7
michael@0 8 #include "SkFontDescriptor.h"
michael@0 9 #include "SkStream.h"
michael@0 10
michael@0 11 enum {
michael@0 12 // these must match the sfnt 'name' enums
michael@0 13 kFontFamilyName = 0x01,
michael@0 14 kFullName = 0x04,
michael@0 15 kPostscriptName = 0x06,
michael@0 16
michael@0 17 // These count backwards from 0xFF, so as not to collide with the SFNT
michael@0 18 // defines for names in its 'name' table.
michael@0 19 kFontFileName = 0xFE,
michael@0 20 kSentinel = 0xFF,
michael@0 21 };
michael@0 22
michael@0 23 SkFontDescriptor::SkFontDescriptor(SkTypeface::Style style) {
michael@0 24 fStyle = style;
michael@0 25 }
michael@0 26
michael@0 27 static void read_string(SkStream* stream, SkString* string) {
michael@0 28 const uint32_t length = SkToU32(stream->readPackedUInt());
michael@0 29 if (length > 0) {
michael@0 30 string->resize(length);
michael@0 31 stream->read(string->writable_str(), length);
michael@0 32 }
michael@0 33 }
michael@0 34
michael@0 35 static void write_string(SkWStream* stream, const SkString& string,
michael@0 36 uint32_t id) {
michael@0 37 if (!string.isEmpty()) {
michael@0 38 stream->writePackedUInt(id);
michael@0 39 stream->writePackedUInt(string.size());
michael@0 40 stream->write(string.c_str(), string.size());
michael@0 41 }
michael@0 42 }
michael@0 43
michael@0 44 SkFontDescriptor::SkFontDescriptor(SkStream* stream) {
michael@0 45 fStyle = (SkTypeface::Style)stream->readPackedUInt();
michael@0 46
michael@0 47 for (;;) {
michael@0 48 switch (stream->readPackedUInt()) {
michael@0 49 case kFontFamilyName:
michael@0 50 read_string(stream, &fFamilyName);
michael@0 51 break;
michael@0 52 case kFullName:
michael@0 53 read_string(stream, &fFullName);
michael@0 54 break;
michael@0 55 case kPostscriptName:
michael@0 56 read_string(stream, &fPostscriptName);
michael@0 57 break;
michael@0 58 case kFontFileName:
michael@0 59 read_string(stream, &fFontFileName);
michael@0 60 break;
michael@0 61 case kSentinel:
michael@0 62 return;
michael@0 63 default:
michael@0 64 SkDEBUGFAIL("Unknown id used by a font descriptor");
michael@0 65 return;
michael@0 66 }
michael@0 67 }
michael@0 68 }
michael@0 69
michael@0 70 void SkFontDescriptor::serialize(SkWStream* stream) {
michael@0 71 stream->writePackedUInt(fStyle);
michael@0 72
michael@0 73 write_string(stream, fFamilyName, kFontFamilyName);
michael@0 74 write_string(stream, fFullName, kFullName);
michael@0 75 write_string(stream, fPostscriptName, kPostscriptName);
michael@0 76 write_string(stream, fFontFileName, kFontFileName);
michael@0 77
michael@0 78 stream->writePackedUInt(kSentinel);
michael@0 79 }

mercurial