Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(10)

Side by Side Diff: src/sfnt/SkOTUtils.cpp

Issue 1779263003: Make sp variants for SkData (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/ports/SkImageDecoder_CG.cpp ('k') | tests/CodexTest.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "SkData.h" 8 #include "SkData.h"
9 #include "SkEndian.h" 9 #include "SkEndian.h"
10 #include "SkSFNTHeader.h" 10 #include "SkSFNTHeader.h"
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 size_t nameTableLogicalSize = sizeof(SkOTTableName) + (namesCount * sizeof(S kOTTableName::Record)) + (fontNameLen * sizeof(wchar_t)); 76 size_t nameTableLogicalSize = sizeof(SkOTTableName) + (namesCount * sizeof(S kOTTableName::Record)) + (fontNameLen * sizeof(wchar_t));
77 size_t nameTablePhysicalSize = (nameTableLogicalSize + 3) & ~3; // Rounded u p to a multiple of 4. 77 size_t nameTablePhysicalSize = (nameTableLogicalSize + 3) & ~3; // Rounded u p to a multiple of 4.
78 78
79 size_t oldNameTablePhysicalSize = (SkEndian_SwapBE32(tableEntry.logicalLengt h) + 3) & ~3; // Rounded up to a multiple of 4. 79 size_t oldNameTablePhysicalSize = (SkEndian_SwapBE32(tableEntry.logicalLengt h) + 3) & ~3; // Rounded up to a multiple of 4.
80 size_t oldNameTableOffset = SkEndian_SwapBE32(tableEntry.offset); 80 size_t oldNameTableOffset = SkEndian_SwapBE32(tableEntry.offset);
81 81
82 //originalDataSize is the size of the original data without the name table. 82 //originalDataSize is the size of the original data without the name table.
83 size_t originalDataSize = fontData->getLength() - oldNameTablePhysicalSize; 83 size_t originalDataSize = fontData->getLength() - oldNameTablePhysicalSize;
84 size_t newDataSize = originalDataSize + nameTablePhysicalSize; 84 size_t newDataSize = originalDataSize + nameTablePhysicalSize;
85 85
86 SkAutoTUnref<SkData> rewrittenFontData(SkData::NewUninitialized(newDataSize) ); 86 auto rewrittenFontData = SkData::MakeUninitialized(newDataSize);
87 SK_OT_BYTE* data = static_cast<SK_OT_BYTE*>(rewrittenFontData->writable_data ()); 87 SK_OT_BYTE* data = static_cast<SK_OT_BYTE*>(rewrittenFontData->writable_data ());
88 88
89 if (fontData->read(data, oldNameTableOffset) < oldNameTableOffset) { 89 if (fontData->read(data, oldNameTableOffset) < oldNameTableOffset) {
90 return nullptr; 90 return nullptr;
91 } 91 }
92 if (fontData->skip(oldNameTablePhysicalSize) < oldNameTablePhysicalSize) { 92 if (fontData->skip(oldNameTablePhysicalSize) < oldNameTablePhysicalSize) {
93 return nullptr; 93 return nullptr;
94 } 94 }
95 if (fontData->read(data + oldNameTableOffset, originalDataSize - oldNameTabl eOffset) < originalDataSize - oldNameTableOffset) { 95 if (fontData->read(data + oldNameTableOffset, originalDataSize - oldNameTabl eOffset) < originalDataSize - oldNameTableOffset) {
96 return nullptr; 96 return nullptr;
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 if (headTableEntry) { 150 if (headTableEntry) {
151 size_t headTableOffset = SkEndian_SwapBE32(headTableEntry->offset); 151 size_t headTableOffset = SkEndian_SwapBE32(headTableEntry->offset);
152 if (headTableOffset + sizeof(SkOTTableHead) < originalDataSize) { 152 if (headTableOffset + sizeof(SkOTTableHead) < originalDataSize) {
153 SkOTTableHead* headTable = reinterpret_cast<SkOTTableHead*>(data + h eadTableOffset); 153 SkOTTableHead* headTable = reinterpret_cast<SkOTTableHead*>(data + h eadTableOffset);
154 headTable->checksumAdjustment = SkEndian_SwapBE32(0); 154 headTable->checksumAdjustment = SkEndian_SwapBE32(0);
155 uint32_t unadjustedFontChecksum = SkOTUtils::CalcTableChecksum(reint erpret_cast<SK_OT_ULONG*>(data), originalDataSize + nameTablePhysicalSize); 155 uint32_t unadjustedFontChecksum = SkOTUtils::CalcTableChecksum(reint erpret_cast<SK_OT_ULONG*>(data), originalDataSize + nameTablePhysicalSize);
156 headTable->checksumAdjustment = SkEndian_SwapBE32(SkOTTableHead::fon tChecksum - unadjustedFontChecksum); 156 headTable->checksumAdjustment = SkEndian_SwapBE32(SkOTTableHead::fon tChecksum - unadjustedFontChecksum);
157 } 157 }
158 } 158 }
159 159
160 return rewrittenFontData.detach(); 160 return rewrittenFontData.release();
161 } 161 }
162 162
163 163
164 SkOTUtils::LocalizedStrings_NameTable* 164 SkOTUtils::LocalizedStrings_NameTable*
165 SkOTUtils::LocalizedStrings_NameTable::CreateForFamilyNames(const SkTypeface& ty peface) { 165 SkOTUtils::LocalizedStrings_NameTable::CreateForFamilyNames(const SkTypeface& ty peface) {
166 static const SkFontTableTag nameTag = SkSetFourByteTag('n','a','m','e'); 166 static const SkFontTableTag nameTag = SkSetFourByteTag('n','a','m','e');
167 size_t nameTableSize = typeface.getTableSize(nameTag); 167 size_t nameTableSize = typeface.getTableSize(nameTag);
168 if (0 == nameTableSize) { 168 if (0 == nameTableSize) {
169 return nullptr; 169 return nullptr;
170 } 170 }
(...skipping 23 matching lines...) Expand all
194 fFamilyNameIter.reset(fTypes[fTypesIndex]); 194 fFamilyNameIter.reset(fTypes[fTypesIndex]);
195 } while (true); 195 } while (true);
196 } 196 }
197 197
198 SkOTTableName::Record::NameID::Predefined::Value 198 SkOTTableName::Record::NameID::Predefined::Value
199 SkOTUtils::LocalizedStrings_NameTable::familyNameTypes[3] = { 199 SkOTUtils::LocalizedStrings_NameTable::familyNameTypes[3] = {
200 SkOTTableName::Record::NameID::Predefined::FontFamilyName, 200 SkOTTableName::Record::NameID::Predefined::FontFamilyName,
201 SkOTTableName::Record::NameID::Predefined::PreferredFamily, 201 SkOTTableName::Record::NameID::Predefined::PreferredFamily,
202 SkOTTableName::Record::NameID::Predefined::WWSFamilyName, 202 SkOTTableName::Record::NameID::Predefined::WWSFamilyName,
203 }; 203 };
OLDNEW
« no previous file with comments | « src/ports/SkImageDecoder_CG.cpp ('k') | tests/CodexTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698