Flutter Engine
The Flutter Engine
SkFont_serial.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2014 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 */
7
14#include "src/core/SkFontPriv.h"
17
18#include <cstdint>
19
20// packed int at the beginning of the serialized font:
21//
22// control_bits:8 size_as_byte:8 flags:12 edging:2 hinting:2
23
24enum {
26 kHas_ScaleX_Bit = 1 << 30,
27 kHas_SkewX_Bit = 1 << 29,
29
32
35
38
41};
42
44 int ix = (int)x;
45 return ix == x && ix >= 0 && ix <= kMask_For_Size;
46}
47
49 SkASSERT(font.fFlags <= SkFont::kAllFlags);
50 SkASSERT((font.fFlags & ~kMask_For_Flags) == 0);
51 SkASSERT((font.fEdging & ~kMask_For_Edging) == 0);
52 SkASSERT((font.fHinting & ~kMask_For_Hinting) == 0);
53
54 uint32_t packed = 0;
55 packed |= font.fFlags << kShift_For_Flags;
56 packed |= font.fEdging << kShift_For_Edging;
57 packed |= font.fHinting << kShift_For_Hinting;
58
59 if (scalar_is_byte(font.fSize)) {
60 packed |= kSize_Is_Byte_Bit;
61 packed |= (int)font.fSize << kShift_for_Size;
62 }
63 if (font.fScaleX != 1) {
64 packed |= kHas_ScaleX_Bit;
65 }
66 if (font.fSkewX != 0) {
67 packed |= kHas_SkewX_Bit;
68 }
69 if (font.fTypeface) {
70 packed |= kHas_Typeface_Bit;
71 }
72
73 buffer.write32(packed);
74 if (!(packed & kSize_Is_Byte_Bit)) {
75 buffer.writeScalar(font.fSize);
76 }
77 if (packed & kHas_ScaleX_Bit) {
78 buffer.writeScalar(font.fScaleX);
79 }
80 if (packed & kHas_SkewX_Bit) {
81 buffer.writeScalar(font.fSkewX);
82 }
83 if (packed & kHas_Typeface_Bit) {
84 buffer.writeTypeface(font.fTypeface.get());
85 }
86}
87
89 const uint32_t packed = buffer.read32();
90
91 if (packed & kSize_Is_Byte_Bit) {
92 font->fSize = (packed >> kShift_for_Size) & kMask_For_Size;
93 } else {
94 font->fSize = buffer.readScalar();
95 }
96 if (packed & kHas_ScaleX_Bit) {
97 font->fScaleX = buffer.readScalar();
98 }
99 if (packed & kHas_SkewX_Bit) {
100 font->fSkewX = buffer.readScalar();
101 }
102 if (packed & kHas_Typeface_Bit) {
103 font->setTypeface(buffer.readTypeface());
104 }
105
106 SkASSERT(SkFont::kAllFlags <= kMask_For_Flags);
107 // we & with kAllFlags, to clear out any unknown flag bits
108 font->fFlags = SkToU8((packed >> kShift_For_Flags) & SkFont::kAllFlags);
109
110 unsigned edging = (packed >> kShift_For_Edging) & kMask_For_Edging;
111 if (edging > (unsigned)SkFont::Edging::kSubpixelAntiAlias) {
112 edging = 0;
113 }
114 font->fEdging = SkToU8(edging);
115
116 unsigned hinting = (packed >> kShift_For_Hinting) & kMask_For_Hinting;
117 if (hinting > (unsigned)SkFontHinting::kFull) {
118 hinting = 0;
119 }
120 font->fHinting = SkToU8(hinting);
121
122 return buffer.isValid();
123}
#define SkASSERT(cond)
Definition: SkAssert.h:116
@ kFull
modifies glyph outlines for maximum constrast
static bool scalar_is_byte(SkScalar x)
@ kHas_ScaleX_Bit
@ kHas_Typeface_Bit
@ kMask_For_Hinting
@ kShift_For_Flags
@ kMask_For_Size
@ kShift_For_Edging
@ kSize_Is_Byte_Bit
@ kHas_SkewX_Bit
@ kMask_For_Edging
@ kShift_for_Size
@ kShift_For_Hinting
@ kMask_For_Flags
constexpr uint8_t SkToU8(S x)
Definition: SkTo.h:22
static void Flatten(const SkFont &, SkWriteBuffer &buffer)
static bool Unflatten(SkFont *, SkReadBuffer &buffer)
Definition: SkFont.h:35
@ kSubpixelAntiAlias
glyph positioned in pixel using transparency
float SkScalar
Definition: extension.cpp:12
double x
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir Path to the cache directory This is different from the persistent_cache_path in embedder which is used for Skia shader cache icu native lib Path to the library file that exports the ICU data vm service The hostname IP address on which the Dart VM Service should be served If not defaults to or::depending on whether ipv6 is specified vm service A custom Dart VM Service port The default is to pick a randomly available open port disable vm Disable the Dart VM Service The Dart VM Service is never available in release mode disable vm service Disable mDNS Dart VM Service publication Bind to the IPv6 localhost address for the Dart VM Service Ignored if vm service host is set endless trace buffer
Definition: switches.h:126
font
Font Metadata and Metrics.