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.

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

mercurial