Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
SkOTUtils.h
Go to the documentation of this file.
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 */
7
8#ifndef SkOTUtils_DEFINED
9#define SkOTUtils_DEFINED
10
15
16class SkData;
17class SkStream;
19
20struct SkOTUtils {
21 /**
22 * Calculates the OpenType checksum for data.
23 */
24 static uint32_t CalcTableChecksum(SK_OT_ULONG *data, size_t length);
25
26 /**
27 * Renames an sfnt font. On failure (invalid data or not an sfnt font)
28 * returns nullptr.
29 *
30 * Essentially, this removes any existing 'name' table and replaces it
31 * with a new one in which FontFamilyName, FontSubfamilyName,
32 * UniqueFontIdentifier, FullFontName, and PostscriptName are fontName.
33 *
34 * The new 'name' table records will be written with the Windows,
35 * UnicodeBMPUCS2, and English_UnitedStates settings.
36 *
37 * fontName and fontNameLen must be specified in terms of ASCII chars.
38 *
39 * Does not affect fontData's ownership.
40 */
41 static SkData* RenameFont(SkStreamAsset* fontData, const char* fontName, int fontNameLen);
42
43 /** An implementation of LocalizedStrings which obtains it's data from a 'name' table. */
45 public:
46 /** Takes ownership of the nameTableData and will free it with SK_DELETE. */
47 LocalizedStrings_NameTable(std::unique_ptr<uint8_t[]> nameTableData, size_t size,
48 SK_OT_USHORT types[],
49 int typesCount)
50 : fTypes(types), fTypesCount(typesCount), fTypesIndex(0)
51 , fNameTableData(std::move(nameTableData))
52 , fFamilyNameIter(fNameTableData.get(), size, fTypes[fTypesIndex])
53 { }
54
55 /** Creates an iterator over all data in the 'name' table of a typeface.
56 * If no valid 'name' table can be found, returns nullptr.
57 */
59 const SkTypeface& typeface,
60 SK_OT_USHORT types[],
61 int typesCount);
62
63 /** Creates an iterator over all the family names in the 'name' table of a typeface.
64 * If no valid 'name' table can be found, returns nullptr.
65 */
67
68 bool next(SkTypeface::LocalizedString* localizedString) override;
69 private:
70 static SK_OT_USHORT familyNameTypes[3];
71
72 SK_OT_USHORT* fTypes;
73 int fTypesCount;
74 int fTypesIndex;
75 std::unique_ptr<uint8_t[]> fNameTableData;
76 SkOTTableName::Iterator fFamilyNameIter;
77 };
78
79 /** An implementation of LocalizedStrings which has one name. */
81 public:
83 : fName(std::move(name)), fLanguage(std::move(language)), fHasNext(true) {}
84
85 bool next(SkTypeface::LocalizedString* localizedString) override {
86 localizedString->fString = fName;
87 localizedString->fLanguage = fLanguage;
88
89 bool hadNext = fHasNext;
90 fHasNext = false;
91 return hadNext;
92 }
93
94 private:
95 SkString fName;
96 SkString fLanguage;
97 bool fHasNext;
98 };
99
102};
103
104#endif
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition DM.cpp:213
uint16_t SK_OT_USHORT
uint32_t SK_OT_ULONG
bool next(SkTypeface::LocalizedString *localizedString) override
static sk_sp< LocalizedStrings_NameTable > Make(const SkTypeface &typeface, SK_OT_USHORT types[], int typesCount)
static sk_sp< LocalizedStrings_NameTable > MakeForFamilyNames(const SkTypeface &typeface)
LocalizedStrings_NameTable(std::unique_ptr< uint8_t[]> nameTableData, size_t size, SK_OT_USHORT types[], int typesCount)
Definition SkOTUtils.h:47
bool next(SkTypeface::LocalizedString *localizedString) override
Definition SkOTUtils.h:85
LocalizedStrings_SingleName(SkString name, SkString language)
Definition SkOTUtils.h:82
const char * name
Definition fuchsia.cc:50
size_t length
Definition ref_ptr.h:256
static uint32_t CalcTableChecksum(SK_OT_ULONG *data, size_t length)
Definition SkOTUtils.cpp:22
static SkData * RenameFont(SkStreamAsset *fontData, const char *fontName, int fontNameLen)
Definition SkOTUtils.cpp:31
static void SetAdvancedTypefaceFlags(SkOTTableOS2_V4::Type fsType, SkAdvancedTypefaceMetrics *info)