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

Side by Side Diff: src/pdf/SkPDFFont.cpp

Issue 1837553002: SkPDF s/SkAutoTDelete/std::unique_ptr/ (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: 2016-03-28 (Monday) 10:22:50 EDT Created 4 years, 8 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/pdf/SkPDFDocument.cpp ('k') | src/pdf/SkPDFMetadata.h » ('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 2011 Google Inc. 2 * Copyright 2011 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 <ctype.h> 8 #include <ctype.h>
9 9
10 #include "SkData.h" 10 #include "SkData.h"
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 } 155 }
156 156
157 static SkData* handle_type1_stream(SkStream* srcStream, size_t* headerLen, 157 static SkData* handle_type1_stream(SkStream* srcStream, size_t* headerLen,
158 size_t* dataLen, size_t* trailerLen) { 158 size_t* dataLen, size_t* trailerLen) {
159 // srcStream may be backed by a file or a unseekable fd, so we may not be 159 // srcStream may be backed by a file or a unseekable fd, so we may not be
160 // able to use skip(), rewind(), or getMemoryBase(). read()ing through 160 // able to use skip(), rewind(), or getMemoryBase(). read()ing through
161 // the input only once is doable, but very ugly. Furthermore, it'd be nice 161 // the input only once is doable, but very ugly. Furthermore, it'd be nice
162 // if the data was NUL terminated so that we can use strstr() to search it. 162 // if the data was NUL terminated so that we can use strstr() to search it.
163 // Make as few copies as possible given these constraints. 163 // Make as few copies as possible given these constraints.
164 SkDynamicMemoryWStream dynamicStream; 164 SkDynamicMemoryWStream dynamicStream;
165 SkAutoTDelete<SkMemoryStream> staticStream; 165 std::unique_ptr<SkMemoryStream> staticStream;
166 SkData* data = nullptr; 166 SkData* data = nullptr;
167 const uint8_t* src; 167 const uint8_t* src;
168 size_t srcLen; 168 size_t srcLen;
169 if ((srcLen = srcStream->getLength()) > 0) { 169 if ((srcLen = srcStream->getLength()) > 0) {
170 staticStream.reset(new SkMemoryStream(srcLen + 1)); 170 staticStream.reset(new SkMemoryStream(srcLen + 1));
171 src = (const uint8_t*)staticStream->getMemoryBase(); 171 src = (const uint8_t*)staticStream->getMemoryBase();
172 if (srcStream->getMemoryBase() != nullptr) { 172 if (srcStream->getMemoryBase() != nullptr) {
173 memcpy((void *)src, srcStream->getMemoryBase(), srcLen); 173 memcpy((void *)src, srcStream->getMemoryBase(), srcLen);
174 } else { 174 } else {
175 size_t read = 0; 175 size_t read = 0;
(...skipping 406 matching lines...) Expand 10 before | Expand all | Expand 10 after
582 delete[] (unsigned char*)ptr; 582 delete[] (unsigned char*)ptr;
583 } 583 }
584 #endif 584 #endif
585 585
586 #if defined(SK_SFNTLY_SUBSETTER) 586 #if defined(SK_SFNTLY_SUBSETTER)
587 static size_t get_subset_font_stream(const char* fontName, 587 static size_t get_subset_font_stream(const char* fontName,
588 const SkTypeface* typeface, 588 const SkTypeface* typeface,
589 const SkTDArray<uint32_t>& subset, 589 const SkTDArray<uint32_t>& subset,
590 SkPDFStream** fontStream) { 590 SkPDFStream** fontStream) {
591 int ttcIndex; 591 int ttcIndex;
592 SkAutoTDelete<SkStream> fontData(typeface->openStream(&ttcIndex)); 592 std::unique_ptr<SkStream> fontData(typeface->openStream(&ttcIndex));
593 SkASSERT(fontData.get()); 593 SkASSERT(fontData.get());
594 594
595 size_t fontSize = fontData->getLength(); 595 size_t fontSize = fontData->getLength();
596 596
597 // Read font into buffer. 597 // Read font into buffer.
598 SkPDFStream* subsetFontStream = nullptr; 598 SkPDFStream* subsetFontStream = nullptr;
599 SkTDArray<unsigned char> originalFont; 599 SkTDArray<unsigned char> originalFont;
600 originalFont.setCount(SkToInt(fontSize)); 600 originalFont.setCount(SkToInt(fontSize));
601 if (fontData->read(originalFont.begin(), fontSize) == fontSize) { 601 if (fontData->read(originalFont.begin(), fontSize) == fontSize) {
602 unsigned char* subsetFont = nullptr; 602 unsigned char* subsetFont = nullptr;
(...skipping 446 matching lines...) Expand 10 before | Expand all | Expand 10 after
1049 &rawStream); 1049 &rawStream);
1050 if (rawStream) { 1050 if (rawStream) {
1051 fontStream.reset(rawStream); 1051 fontStream.reset(rawStream);
1052 fontStream->insertInt("Length1", fontSize); 1052 fontStream->insertInt("Length1", fontSize);
1053 descriptor->insertObjRef("FontFile2", std::move(fontStream)) ; 1053 descriptor->insertObjRef("FontFile2", std::move(fontStream)) ;
1054 break; 1054 break;
1055 } 1055 }
1056 } 1056 }
1057 #endif 1057 #endif
1058 sk_sp<SkPDFSharedStream> fontStream; 1058 sk_sp<SkPDFSharedStream> fontStream;
1059 SkAutoTDelete<SkStreamAsset> fontData( 1059 std::unique_ptr<SkStreamAsset> fontData(
1060 this->typeface()->openStream(nullptr)); 1060 this->typeface()->openStream(nullptr));
1061 SkASSERT(fontData); 1061 SkASSERT(fontData);
1062 fontSize = fontData->getLength(); 1062 fontSize = fontData->getLength();
1063 SkASSERT(fontSize > 0); 1063 SkASSERT(fontSize > 0);
1064 fontStream.reset(new SkPDFSharedStream(fontData.release())); 1064 fontStream.reset(new SkPDFSharedStream(fontData.release()));
1065 fontStream->dict()->insertInt("Length1", fontSize); 1065 fontStream->dict()->insertInt("Length1", fontSize);
1066 descriptor->insertObjRef("FontFile2", std::move(fontStream)); 1066 descriptor->insertObjRef("FontFile2", std::move(fontStream));
1067 break; 1067 break;
1068 } 1068 }
1069 case SkAdvancedTypefaceMetrics::kCFF_Font: 1069 case SkAdvancedTypefaceMetrics::kCFF_Font:
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
1191 return true; 1191 return true;
1192 } 1192 }
1193 1193
1194 auto descriptor = sk_make_sp<SkPDFDict>("FontDescriptor"); 1194 auto descriptor = sk_make_sp<SkPDFDict>("FontDescriptor");
1195 setFontDescriptor(descriptor.get()); 1195 setFontDescriptor(descriptor.get());
1196 1196
1197 int ttcIndex; 1197 int ttcIndex;
1198 size_t header SK_INIT_TO_AVOID_WARNING; 1198 size_t header SK_INIT_TO_AVOID_WARNING;
1199 size_t data SK_INIT_TO_AVOID_WARNING; 1199 size_t data SK_INIT_TO_AVOID_WARNING;
1200 size_t trailer SK_INIT_TO_AVOID_WARNING; 1200 size_t trailer SK_INIT_TO_AVOID_WARNING;
1201 SkAutoTDelete<SkStream> rawFontData(typeface()->openStream(&ttcIndex)); 1201 std::unique_ptr<SkStream> rawFontData(typeface()->openStream(&ttcIndex));
1202 sk_sp<SkData> fontData(handle_type1_stream(rawFontData.get(), &header, 1202 sk_sp<SkData> fontData(handle_type1_stream(rawFontData.get(), &header,
1203 &data, &trailer)); 1203 &data, &trailer));
1204 if (fontData.get() == nullptr) { 1204 if (fontData.get() == nullptr) {
1205 return false; 1205 return false;
1206 } 1206 }
1207 SkASSERT(this->canEmbed()); 1207 SkASSERT(this->canEmbed());
1208 auto fontStream = sk_make_sp<SkPDFStream>(fontData.get()); 1208 auto fontStream = sk_make_sp<SkPDFStream>(fontData.get());
1209 fontStream->insertInt("Length1", header); 1209 fontStream->insertInt("Length1", header);
1210 fontStream->insertInt("Length2", data); 1210 fontStream->insertInt("Length2", data);
1211 fontStream->insertInt("Length3", trailer); 1211 fontStream->insertInt("Length3", trailer);
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
1350 1350
1351 SkDynamicMemoryWStream content; 1351 SkDynamicMemoryWStream content;
1352 setGlyphWidthAndBoundingBox(SkFloatToScalar(glyph.fAdvanceX), glyphBBox, 1352 setGlyphWidthAndBoundingBox(SkFloatToScalar(glyph.fAdvanceX), glyphBBox,
1353 &content); 1353 &content);
1354 const SkPath* path = cache->findPath(glyph); 1354 const SkPath* path = cache->findPath(glyph);
1355 if (path) { 1355 if (path) {
1356 SkPDFUtils::EmitPath(*path, paint.getStyle(), &content); 1356 SkPDFUtils::EmitPath(*path, paint.getStyle(), &content);
1357 SkPDFUtils::PaintPath(paint.getStyle(), path->getFillType(), 1357 SkPDFUtils::PaintPath(paint.getStyle(), path->getFillType(),
1358 &content); 1358 &content);
1359 } 1359 }
1360 SkAutoTDelete<SkMemoryStream> glyphStream(new SkMemoryStream()); 1360 std::unique_ptr<SkMemoryStream> glyphStream(new SkMemoryStream());
1361 glyphStream->setData(content.copyToData())->unref(); 1361 glyphStream->setData(content.copyToData())->unref();
1362 1362
1363 charProcs->insertObjRef( 1363 charProcs->insertObjRef(
1364 characterName, sk_make_sp<SkPDFStream>(glyphStream.get())); 1364 characterName, sk_make_sp<SkPDFStream>(glyphStream.get()));
1365 } 1365 }
1366 1366
1367 encoding->insertObject("Differences", std::move(encDiffs)); 1367 encoding->insertObject("Differences", std::move(encDiffs));
1368 1368
1369 this->insertObject("CharProcs", std::move(charProcs)); 1369 this->insertObject("CharProcs", std::move(charProcs));
1370 this->insertObject("Encoding", std::move(encoding)); 1370 this->insertObject("Encoding", std::move(encoding));
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
1418 } 1418 }
1419 return *canon->fCanEmbedTypeface.set(id, canEmbed); 1419 return *canon->fCanEmbedTypeface.set(id, canEmbed);
1420 } 1420 }
1421 1421
1422 void SkPDFFont::drop() { 1422 void SkPDFFont::drop() {
1423 fTypeface = nullptr; 1423 fTypeface = nullptr;
1424 fFontInfo = nullptr; 1424 fFontInfo = nullptr;
1425 fDescriptor = nullptr; 1425 fDescriptor = nullptr;
1426 this->SkPDFDict::drop(); 1426 this->SkPDFDict::drop();
1427 } 1427 }
OLDNEW
« no previous file with comments | « src/pdf/SkPDFDocument.cpp ('k') | src/pdf/SkPDFMetadata.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698