From 48810a023705ffac466adb93efdb3861cf2e197a Mon Sep 17 00:00:00 2001 From: halcanary Date: Mon, 7 Mar 2016 14:57:50 -0800 Subject: [PATCH] SkPDF: s/SkAutoTUnref/sk_sp/g Review URL: https://codereview.chromium.org/1771073002 --- src/doc/SkDocument_PDF.cpp | 28 ++++++++++---------- src/pdf/SkPDFBitmap.cpp | 10 ++++---- src/pdf/SkPDFCanon.h | 2 +- src/pdf/SkPDFDevice.cpp | 40 ++++++++++++++--------------- src/pdf/SkPDFFont.cpp | 48 +++++++++++++++++------------------ src/pdf/SkPDFFont.h | 6 ++--- src/pdf/SkPDFFormXObject.cpp | 8 +++--- src/pdf/SkPDFGraphicState.cpp | 12 ++++----- src/pdf/SkPDFMetadata.cpp | 4 +-- src/pdf/SkPDFResourceDict.cpp | 6 ++--- src/pdf/SkPDFShader.cpp | 24 +++++++++--------- src/pdf/SkPDFTypes.h | 6 ++--- 12 files changed, 97 insertions(+), 97 deletions(-) diff --git a/src/doc/SkDocument_PDF.cpp b/src/doc/SkDocument_PDF.cpp index 942e42c9c4..54e0fe0c5f 100644 --- a/src/doc/SkDocument_PDF.cpp +++ b/src/doc/SkDocument_PDF.cpp @@ -62,7 +62,7 @@ static void perform_font_subsetting( SkPDFGlyphSetMap::F2BIter iterator(usage); const SkPDFGlyphSetMap::FontGlyphSetPair* entry = iterator.next(); while (entry) { - SkAutoTUnref subsetFont( + sk_sp subsetFont( entry->fFont->getFontSubset(entry->fGlyphSet)); if (subsetFont) { substituteMap->setSubstitute(entry->fFont, subsetFont.get()); @@ -77,10 +77,10 @@ static SkPDFObject* create_pdf_page_content(const SkPDFDevice* pageDevice) { } static SkPDFDict* create_pdf_page(const SkPDFDevice* pageDevice) { - SkAutoTUnref page(new SkPDFDict("Page")); + sk_sp page(new SkPDFDict("Page")); page->insertObject("Resources", pageDevice->createResourceDict()); page->insertObject("MediaBox", pageDevice->copyMediaBox()); - SkAutoTUnref annotations(new SkPDFArray); + sk_sp annotations(new SkPDFArray); pageDevice->appendAnnotations(annotations.get()); if (annotations->size() > 0) { page->insertObject("Annots", annotations.release()); @@ -121,8 +121,8 @@ static void generate_page_tree(const SkTDArray& pages, break; } - SkAutoTUnref newNode(new SkPDFDict("Pages")); - SkAutoTUnref kids(new SkPDFArray); + sk_sp newNode(new SkPDFDict("Pages")); + sk_sp kids(new SkPDFArray); kids->reserve(kNodeSize); int count = 0; @@ -174,23 +174,23 @@ static bool emit_pdf_document(const SkTDArray& pageDevices, } SkTDArray pages; - SkAutoTUnref dests(new SkPDFDict); + sk_sp dests(new SkPDFDict); for (int i = 0; i < pageDevices.count(); i++) { SkASSERT(pageDevices[i]); SkASSERT(i == 0 || pageDevices[i - 1]->getCanon() == pageDevices[i]->getCanon()); - SkAutoTUnref page(create_pdf_page(pageDevices[i])); + sk_sp page(create_pdf_page(pageDevices[i])); pageDevices[i]->appendDestinations(dests.get(), page.get()); pages.push(page.release()); } - SkAutoTUnref docCatalog(new SkPDFDict("Catalog")); + sk_sp docCatalog(new SkPDFDict("Catalog")); - SkAutoTUnref infoDict( + sk_sp infoDict( metadata.createDocumentInformationDict()); - SkAutoTUnref id, xmp; + sk_sp id, xmp; #ifdef SK_PDF_GENERATE_PDFA SkPDFMetadata::UUID uuid = metadata.uuid(); // We use the same UUID for Document ID and Instance ID since this @@ -203,12 +203,12 @@ static bool emit_pdf_document(const SkTDArray& pageDevices, docCatalog->insertObjRef("Metadata", xmp.release()); // sRGB is specified by HTML, CSS, and SVG. - SkAutoTUnref outputIntent(new SkPDFDict("OutputIntent")); + sk_sp outputIntent(new SkPDFDict("OutputIntent")); outputIntent->insertName("S", "GTS_PDFA1"); outputIntent->insertString("RegistryName", "http://www.color.org"); outputIntent->insertString("OutputConditionIdentifier", "sRGB IEC61966-2.1"); - SkAutoTUnref intentArray(new SkPDFArray); + sk_sp intentArray(new SkPDFArray); intentArray->appendObject(outputIntent.release()); // Don't specify OutputIntents if we are not in PDF/A mode since // no one has ever asked for this feature. @@ -341,7 +341,7 @@ protected: SkISize pageSize = SkISize::Make( SkScalarRoundToInt(width), SkScalarRoundToInt(height)); - SkAutoTUnref device( + sk_sp device( SkPDFDevice::Create(pageSize, fRasterDpi, &fCanon)); fCanvas.reset(new SkCanvas(device.get())); fPageDevices.push(device.release()); @@ -382,7 +382,7 @@ protected: private: SkPDFCanon fCanon; SkTDArray fPageDevices; - SkAutoTUnref fCanvas; + sk_sp fCanvas; SkScalar fRasterDpi; SkPDFMetadata fMetadata; }; diff --git a/src/pdf/SkPDFBitmap.cpp b/src/pdf/SkPDFBitmap.cpp index 66124cef35..1e2e26aa71 100644 --- a/src/pdf/SkPDFBitmap.cpp +++ b/src/pdf/SkPDFBitmap.cpp @@ -391,7 +391,7 @@ public: } private: - SkAutoTUnref fImage; + sk_sp fImage; }; } // namespace @@ -418,8 +418,8 @@ public: : fImage(SkRef(image)), fSMask(smask) {} private: - SkAutoTUnref fImage; - const SkAutoTUnref fSMask; + sk_sp fImage; + const sk_sp fSMask; }; } // namespace @@ -434,7 +434,7 @@ namespace { class PDFJpegBitmap final : public SkPDFObject { public: SkISize fSize; - SkAutoTUnref fData; + sk_sp fData; bool fIsYUV; PDFJpegBitmap(SkISize size, SkData* data, bool isYUV) : fSize(size), fData(SkRef(data)), fIsYUV(isYUV) {} @@ -470,7 +470,7 @@ void PDFJpegBitmap::emitObject(SkWStream* stream, SkPDFObject* SkPDFCreateBitmapObject(const SkImage* image, SkPixelSerializer* pixelSerializer) { - SkAutoTUnref data(image->refEncoded()); + sk_sp data(image->refEncoded()); SkJFIFInfo info; if (data && SkIsJFIF(data.get(), &info) && (!pixelSerializer || diff --git a/src/pdf/SkPDFCanon.h b/src/pdf/SkPDFCanon.h index 4c92fcbf6f..80b1f83e8a 100644 --- a/src/pdf/SkPDFCanon.h +++ b/src/pdf/SkPDFCanon.h @@ -118,6 +118,6 @@ private: SkTHashMap fBitmapToImageMap; SkTHashMap fPDFBitmapMap; - SkAutoTUnref fPixelSerializer; + sk_sp fPixelSerializer; }; #endif // SkPDFCanon_DEFINED diff --git a/src/pdf/SkPDFDevice.cpp b/src/pdf/SkPDFDevice.cpp index 7a69c631d8..93627b276e 100644 --- a/src/pdf/SkPDFDevice.cpp +++ b/src/pdf/SkPDFDevice.cpp @@ -880,17 +880,17 @@ void SkPDFDevice::drawPoints(const SkDraw& d, } static SkPDFDict* create_link_annotation(const SkRect& translatedRect) { - SkAutoTUnref annotation(new SkPDFDict("Annot")); + sk_sp annotation(new SkPDFDict("Annot")); annotation->insertName("Subtype", "Link"); - SkAutoTUnref border(new SkPDFArray); + sk_sp border(new SkPDFArray); border->reserve(3); border->appendInt(0); // Horizontal corner radius. border->appendInt(0); // Vertical corner radius. border->appendInt(0); // Width, 0 = no border. annotation->insertObject("Border", border.release()); - SkAutoTUnref rect(new SkPDFArray); + sk_sp rect(new SkPDFArray); rect->reserve(4); rect->appendScalar(translatedRect.fLeft); rect->appendScalar(translatedRect.fTop); @@ -902,11 +902,11 @@ static SkPDFDict* create_link_annotation(const SkRect& translatedRect) { } static SkPDFDict* create_link_to_url(const SkData* urlData, const SkRect& r) { - SkAutoTUnref annotation(create_link_annotation(r)); + sk_sp annotation(create_link_annotation(r)); SkString url(static_cast(urlData->data()), urlData->size() - 1); - SkAutoTUnref action(new SkPDFDict("Action")); + sk_sp action(new SkPDFDict("Action")); action->insertName("S", "URI"); action->insertString("URI", url); annotation->insertObject("A", action.release()); @@ -915,7 +915,7 @@ static SkPDFDict* create_link_to_url(const SkData* urlData, const SkRect& r) { static SkPDFDict* create_link_named_dest(const SkData* nameData, const SkRect& r) { - SkAutoTUnref annotation(create_link_annotation(r)); + sk_sp annotation(create_link_annotation(r)); SkString name(static_cast(nameData->data()), nameData->size() - 1); annotation->insertName("Dest", name); @@ -1146,7 +1146,7 @@ void SkPDFDevice::drawImageRect(const SkDraw& draw, // clip the tmpSrc to the bounds of the bitmap, and recompute dstRect if // needed (if the src was clipped). No check needed if src==null. - SkAutoTUnref autoImageUnref; + sk_sp autoImageUnref; if (src) { if (!imageBounds.contains(*src)) { if (!tmpSrc.intersect(imageBounds)) { @@ -1448,7 +1448,7 @@ void SkPDFDevice::drawDevice(const SkDraw& d, SkBaseDevice* device, return; } - SkAutoTUnref xObject(new SkPDFFormXObject(pdfDevice)); + sk_sp xObject(new SkPDFFormXObject(pdfDevice)); SkPDFUtils::DrawFormXObject(this->addXObjectResource(xObject.get()), &content.entry()->fContent); @@ -1527,7 +1527,7 @@ const SkTDArray& SkPDFDevice::getFontResources() const { SkPDFArray* SkPDFDevice::copyMediaBox() const { // should this be a singleton? - SkAutoTUnref mediaBox(new SkPDFArray); + sk_sp mediaBox(new SkPDFArray); mediaBox->reserve(4); mediaBox->appendInt(0); mediaBox->appendInt(0); @@ -1711,7 +1711,7 @@ void SkPDFDevice::appendAnnotations(SkPDFArray* array) const { void SkPDFDevice::appendDestinations(SkPDFDict* dict, SkPDFObject* page) const { for (const NamedDestination& dest : fNamedDestinations) { - SkAutoTUnref pdfDest(new SkPDFArray); + sk_sp pdfDest(new SkPDFArray); pdfDest->reserve(5); pdfDest->appendObjRef(SkRef(page)); pdfDest->appendName("XYZ"); @@ -1744,7 +1744,7 @@ void SkPDFDevice::drawFormXObjectWithMask(int xObjectIndex, return; } - SkAutoTUnref sMaskGS(SkPDFGraphicState::GetSMaskGraphicState( + sk_sp sMaskGS(SkPDFGraphicState::GetSMaskGraphicState( mask, invertClip, SkPDFGraphicState::kAlpha_SMaskMode)); SkMatrix identity; @@ -1908,7 +1908,7 @@ void SkPDFDevice::finishContentEntry(SkXfermode::Mode xfermode, identity.reset(); SkPaint stockPaint; - SkAutoTUnref srcFormXObject; + sk_sp srcFormXObject; if (isContentEmpty()) { // If nothing was drawn and there's no shape, then the draw was a // no-op, but dst needs to be restored for that to be true. @@ -1942,7 +1942,7 @@ void SkPDFDevice::finishContentEntry(SkXfermode::Mode xfermode, &fExistingClipStack, fExistingClipRegion, SkXfermode::kSrcOver_Mode, true); } else { - SkAutoTUnref dstMaskStorage; + sk_sp dstMaskStorage; SkPDFFormXObject* dstMask = srcFormXObject.get(); if (shape != nullptr) { // Draw shape into a form-xobject. @@ -2043,7 +2043,7 @@ void SkPDFDevice::populateGraphicStateEntryFromPaint( entry->fShaderIndex = -1; // PDF treats a shader as a color, so we only set one or the other. - SkAutoTUnref pdfShader; + sk_sp pdfShader; const SkShader* shader = paint.getShader(); SkColor color = paint.getColor(); if (shader) { @@ -2094,7 +2094,7 @@ void SkPDFDevice::populateGraphicStateEntryFromPaint( } } - SkAutoTUnref newGraphicState; + sk_sp newGraphicState; if (color == paint.getColor()) { newGraphicState.reset( SkPDFGraphicState::GetGraphicStateForPaint(fCanon, paint)); @@ -2158,7 +2158,7 @@ void SkPDFDevice::updateFont(const SkPaint& paint, uint16_t glyphID, } int SkPDFDevice::getFontResourceIndex(SkTypeface* typeface, uint16_t glyphID) { - SkAutoTUnref newFont( + sk_sp newFont( SkPDFFont::GetFontResource(fCanon, typeface, glyphID)); int resourceIndex = fFontResources.find(newFont.get()); if (resourceIndex < 0) { @@ -2175,7 +2175,7 @@ static SkSize rect_to_size(const SkRect& r) { static const SkImage* color_filter(const SkImage* image, SkColorFilter* colorFilter) { - SkAutoTUnref surface(SkSurface::NewRaster( + sk_sp surface(SkSurface::NewRaster( SkImageInfo::MakeN32Premul(image->dimensions()))); if (!surface) { return image; @@ -2203,7 +2203,7 @@ void SkPDFDevice::internalDrawImage(const SkMatrix& origMatrix, SkMatrix matrix = origMatrix; SkRegion perspectiveBounds; const SkRegion* clipRegion = &origClipRegion; - SkAutoTUnref autoImageUnref; + sk_sp autoImageUnref; if (srcRect) { autoImageUnref.reset(image->newSubset(*srcRect)); @@ -2254,7 +2254,7 @@ void SkPDFDevice::internalDrawImage(const SkMatrix& origMatrix, SkISize wh = rect_to_size(physicalPerspectiveBounds).toCeil(); - SkAutoTUnref surface( + sk_sp surface( SkSurface::NewRaster(SkImageInfo::MakeN32Premul(wh))); if (!surface) { return; @@ -2323,7 +2323,7 @@ void SkPDFDevice::internalDrawImage(const SkMatrix& origMatrix, // TODO(halcanary): de-dupe this by caching filtered images. // (maybe in the resource cache?) } - SkAutoTUnref pdfimage(SkSafeRef(fCanon->findPDFBitmap(image))); + sk_sp pdfimage(SkSafeRef(fCanon->findPDFBitmap(image))); if (!pdfimage) { pdfimage.reset(SkPDFCreateBitmapObject( image, fCanon->getPixelSerializer())); diff --git a/src/pdf/SkPDFFont.cpp b/src/pdf/SkPDFFont.cpp index 48899ebe12..ff0a265746 100644 --- a/src/pdf/SkPDFFont.cpp +++ b/src/pdf/SkPDFFont.cpp @@ -338,7 +338,7 @@ SkPDFArray* composeAdvanceData( break; } case SkAdvancedTypefaceMetrics::WidthRange::kRange: { - SkAutoTUnref advanceArray(new SkPDFArray()); + sk_sp advanceArray(new SkPDFArray()); for (int j = 0; j < advanceInfo->fAdvance.count(); j++) appendAdvance(advanceInfo->fAdvance[j], emSize, advanceArray.get()); @@ -574,7 +574,7 @@ static SkPDFStream* generate_tounicode_cmap( append_cmap_sections(glyphToUnicode, subset, &cmap, multiByteGlyphs, firstGlyphID, lastGlyphID); append_cmap_footer(&cmap); - SkAutoTUnref cmapData(cmap.copyToData()); + sk_sp cmapData(cmap.copyToData()); return new SkPDFStream(cmapData.get()); } @@ -806,7 +806,7 @@ SkPDFFont* SkPDFFont::GetFontResource(SkPDFCanon* canon, return SkRef(pdfFont); } - SkAutoTUnref fontMetrics; + sk_sp fontMetrics; SkPDFDict* relatedFontDescriptor = nullptr; if (relatedFont) { fontMetrics.reset(SkSafeRef(relatedFont->fontInfo())); @@ -1019,9 +1019,9 @@ bool SkPDFType0Font::populate(const SkPDFGlyphSet* subset) { insertName("BaseFont", fontInfo()->fFontName); insertName("Encoding", "Identity-H"); - SkAutoTUnref newCIDFont( + sk_sp newCIDFont( new SkPDFCIDFont(fontInfo(), typeface(), subset)); - SkAutoTUnref descendantFonts(new SkPDFArray()); + sk_sp descendantFonts(new SkPDFArray()); descendantFonts->appendObjRef(newCIDFont.release()); this->insertObject("DescendantFonts", descendantFonts.release()); @@ -1046,7 +1046,7 @@ SkPDFCIDFont::~SkPDFCIDFont() {} bool SkPDFCIDFont::addFontDescriptor(int16_t defaultWidth, const SkTDArray* subset) { - SkAutoTUnref descriptor(new SkPDFDict("FontDescriptor")); + sk_sp descriptor(new SkPDFDict("FontDescriptor")); setFontDescriptor(descriptor.get()); if (!addCommonFontDescriptorEntries(defaultWidth)) { this->insertObjRef("FontDescriptor", descriptor.release()); @@ -1059,7 +1059,7 @@ bool SkPDFCIDFont::addFontDescriptor(int16_t defaultWidth, size_t fontSize = 0; #if defined(SK_SFNTLY_SUBSETTER) if (this->canSubset()) { - SkAutoTUnref fontStream; + sk_sp fontStream; SkPDFStream* rawStream = nullptr; fontSize = get_subset_font_stream(fontInfo()->fFontName.c_str(), typeface(), @@ -1073,7 +1073,7 @@ bool SkPDFCIDFont::addFontDescriptor(int16_t defaultWidth, } } #endif - SkAutoTUnref fontStream; + sk_sp fontStream; SkAutoTDelete fontData( this->typeface()->openStream(nullptr)); SkASSERT(fontData); @@ -1086,7 +1086,7 @@ bool SkPDFCIDFont::addFontDescriptor(int16_t defaultWidth, } case SkAdvancedTypefaceMetrics::kCFF_Font: case SkAdvancedTypefaceMetrics::kType1CID_Font: { - SkAutoTUnref fontStream( + sk_sp fontStream( new SkPDFSharedStream(this->typeface()->openStream(nullptr))); if (getType() == SkAdvancedTypefaceMetrics::kCFF_Font) { @@ -1123,7 +1123,7 @@ bool SkPDFCIDFont::populate(const SkPDFGlyphSet* subset) { info, SkTypeface::kHAdvance_PerGlyphInfo); uint32_t* glyphs = (glyphIDs.count() == 0) ? nullptr : glyphIDs.begin(); uint32_t glyphsCount = glyphs ? glyphIDs.count() : 0; - SkAutoTUnref fontMetrics( + sk_sp fontMetrics( typeface()->getAdvancedTypefaceMetrics(info, glyphs, glyphsCount)); setFontInfo(fontMetrics.get()); addFontDescriptor(0, &glyphIDs); @@ -1143,7 +1143,7 @@ bool SkPDFCIDFont::populate(const SkPDFGlyphSet* subset) { SkASSERT(false); } - SkAutoTUnref sysInfo(new SkPDFDict); + sk_sp sysInfo(new SkPDFDict); sysInfo->insertString("Registry", "Adobe"); sysInfo->insertString("Ordering", "Identity"); sysInfo->insertInt("Supplement", 0); @@ -1151,7 +1151,7 @@ bool SkPDFCIDFont::populate(const SkPDFGlyphSet* subset) { if (fontInfo()->fGlyphWidths.get()) { int16_t defaultWidth = 0; - SkAutoTUnref widths( + sk_sp widths( composeAdvanceData(fontInfo()->fGlyphWidths.get(), fontInfo()->fEmSize, &appendWidth, &defaultWidth)); @@ -1168,7 +1168,7 @@ bool SkPDFCIDFont::populate(const SkPDFGlyphSet* subset) { defaultAdvance.fVerticalAdvance = 0; defaultAdvance.fOriginXDisp = 0; defaultAdvance.fOriginYDisp = 0; - SkAutoTUnref advances( + sk_sp advances( composeAdvanceData(fontInfo()->fVerticalMetrics.get(), fontInfo()->fEmSize, &appendVerticalAdvance, &defaultAdvance)); @@ -1207,7 +1207,7 @@ bool SkPDFType1Font::addFontDescriptor(int16_t defaultWidth) { return true; } - SkAutoTUnref descriptor(new SkPDFDict("FontDescriptor")); + sk_sp descriptor(new SkPDFDict("FontDescriptor")); setFontDescriptor(descriptor.get()); int ttcIndex; @@ -1215,13 +1215,13 @@ bool SkPDFType1Font::addFontDescriptor(int16_t defaultWidth) { size_t data SK_INIT_TO_AVOID_WARNING; size_t trailer SK_INIT_TO_AVOID_WARNING; SkAutoTDelete rawFontData(typeface()->openStream(&ttcIndex)); - SkAutoTUnref fontData(handle_type1_stream(rawFontData.get(), &header, + sk_sp fontData(handle_type1_stream(rawFontData.get(), &header, &data, &trailer)); if (fontData.get() == nullptr) { return false; } SkASSERT(this->canEmbed()); - SkAutoTUnref fontStream(new SkPDFStream(fontData.get())); + sk_sp fontStream(new SkPDFStream(fontData.get())); fontStream->insertInt("Length1", header); fontStream->insertInt("Length2", data); fontStream->insertInt("Length3", trailer); @@ -1268,14 +1268,14 @@ bool SkPDFType1Font::populate(int16_t glyphID) { addWidthInfoFromRange(defaultWidth, widthRangeEntry); - SkAutoTUnref encDiffs(new SkPDFArray); + sk_sp encDiffs(new SkPDFArray); encDiffs->reserve(lastGlyphID() - firstGlyphID() + 2); encDiffs->appendInt(1); for (int gID = firstGlyphID(); gID <= lastGlyphID(); gID++) { encDiffs->appendName(fontInfo()->fGlyphNames->get()[gID].c_str()); } - SkAutoTUnref encoding(new SkPDFDict("Encoding")); + sk_sp encoding(new SkPDFDict("Encoding")); encoding->insertObject("Differences", encDiffs.release()); this->insertObject("Encoding", encoding.release()); return true; @@ -1284,7 +1284,7 @@ bool SkPDFType1Font::populate(int16_t glyphID) { void SkPDFType1Font::addWidthInfoFromRange( int16_t defaultWidth, const SkAdvancedTypefaceMetrics::WidthRange* widthRangeEntry) { - SkAutoTUnref widthArray(new SkPDFArray()); + sk_sp widthArray(new SkPDFArray()); int firstChar = 0; if (widthRangeEntry) { const uint16_t emSize = fontInfo()->fEmSize; @@ -1343,14 +1343,14 @@ bool SkPDFType3Font::populate(uint16_t glyphID) { fontMatrix.setScale(SkScalarInvert(1000), -SkScalarInvert(1000)); this->insertObject("FontMatrix", SkPDFUtils::MatrixToArray(fontMatrix)); - SkAutoTUnref charProcs(new SkPDFDict); - SkAutoTUnref encoding(new SkPDFDict("Encoding")); + sk_sp charProcs(new SkPDFDict); + sk_sp encoding(new SkPDFDict("Encoding")); - SkAutoTUnref encDiffs(new SkPDFArray); + sk_sp encDiffs(new SkPDFArray); encDiffs->reserve(lastGlyphID() - firstGlyphID() + 2); encDiffs->appendInt(1); - SkAutoTUnref widthArray(new SkPDFArray()); + sk_sp widthArray(new SkPDFArray()); SkIRect bbox = SkIRect::MakeEmpty(); for (int gID = firstGlyphID(); gID <= lastGlyphID(); gID++) { @@ -1424,7 +1424,7 @@ bool SkPDFFont::CanEmbedTypeface(SkTypeface* typeface, SkPDFCanon* canon) { return *value; } bool canEmbed = true; - SkAutoTUnref fontMetrics( + sk_sp fontMetrics( face->getAdvancedTypefaceMetrics( SkTypeface::kNo_PerGlyphInfo, nullptr, 0)); if (fontMetrics) { diff --git a/src/pdf/SkPDFFont.h b/src/pdf/SkPDFFont.h index ca0a51fca4..16c5a76971 100644 --- a/src/pdf/SkPDFFont.h +++ b/src/pdf/SkPDFFont.h @@ -194,14 +194,14 @@ protected: static bool Find(uint32_t fontID, uint16_t glyphID, int* index); private: - SkAutoTUnref fTypeface; + sk_sp fTypeface; // The glyph IDs accessible with this font. For Type1 (non CID) fonts, // this will be a subset if the font has more than 255 glyphs. uint16_t fFirstGlyphID; uint16_t fLastGlyphID; - SkAutoTUnref fFontInfo; - SkAutoTUnref fDescriptor; + sk_sp fFontInfo; + sk_sp fDescriptor; SkAdvancedTypefaceMetrics::FontType fFontType; diff --git a/src/pdf/SkPDFFormXObject.cpp b/src/pdf/SkPDFFormXObject.cpp index c6f1f70ba1..4647f5a8a1 100644 --- a/src/pdf/SkPDFFormXObject.cpp +++ b/src/pdf/SkPDFFormXObject.cpp @@ -19,12 +19,12 @@ SkPDFFormXObject::SkPDFFormXObject(SkPDFDevice* device) { // We don't want to keep around device because we'd have two copies // of content, so reference or copy everything we need (content and // resources). - SkAutoTUnref resourceDict(device->createResourceDict()); + sk_sp resourceDict(device->createResourceDict()); SkAutoTDelete content(device->content()); this->setData(content.get()); - SkAutoTUnref bboxArray(device->copyMediaBox()); + sk_sp bboxArray(device->copyMediaBox()); this->init(nullptr, resourceDict.get(), bboxArray.get()); // We invert the initial transform and apply that to the xobject so that @@ -48,7 +48,7 @@ SkPDFFormXObject::SkPDFFormXObject(SkStream* content, SkRect bbox, SkPDFDict* resourceDict) { setData(content); - SkAutoTUnref bboxArray(SkPDFUtils::RectToArray(bbox)); + sk_sp bboxArray(SkPDFUtils::RectToArray(bbox)); this->init("DeviceRGB", resourceDict, bboxArray.get()); } @@ -65,7 +65,7 @@ void SkPDFFormXObject::init(const char* colorSpace, // Right now SkPDFFormXObject is only used for saveLayer, which implies // isolated blending. Do this conditionally if that changes. - SkAutoTUnref group(new SkPDFDict("Group")); + sk_sp group(new SkPDFDict("Group")); group->insertName("S", "Transparency"); if (colorSpace != nullptr) { diff --git a/src/pdf/SkPDFGraphicState.cpp b/src/pdf/SkPDFGraphicState.cpp index 2bccac0cb9..121e583487 100644 --- a/src/pdf/SkPDFGraphicState.cpp +++ b/src/pdf/SkPDFGraphicState.cpp @@ -129,17 +129,17 @@ SkPDFGraphicState* SkPDFGraphicState::GetGraphicStateForPaint( static SkPDFObject* create_invert_function() { // Acrobat crashes if we use a type 0 function, kpdf crashes if we use // a type 2 function, so we use a type 4 function. - SkAutoTUnref domainAndRange(new SkPDFArray); + sk_sp domainAndRange(new SkPDFArray); domainAndRange->reserve(2); domainAndRange->appendInt(0); domainAndRange->appendInt(1); static const char psInvert[] = "{1 exch sub}"; // Do not copy the trailing '\0' into the SkData. - SkAutoTUnref psInvertStream( + sk_sp psInvertStream( SkData::NewWithoutCopy(psInvert, strlen(psInvert))); - SkAutoTUnref invertFunction(new SkPDFStream(psInvertStream.get())); + sk_sp invertFunction(new SkPDFStream(psInvertStream.get())); invertFunction->insertInt("FunctionType", 4); invertFunction->insertObject("Domain", SkRef(domainAndRange.get())); invertFunction->insertObject("Range", domainAndRange.release()); @@ -154,7 +154,7 @@ SkPDFDict* SkPDFGraphicState::GetSMaskGraphicState(SkPDFFormXObject* sMask, SkPDFSMaskMode sMaskMode) { // The practical chances of using the same mask more than once are unlikely // enough that it's not worth canonicalizing. - SkAutoTUnref sMaskDict(new SkPDFDict("Mask")); + sk_sp sMaskDict(new SkPDFDict("Mask")); if (sMaskMode == kAlpha_SMaskMode) { sMaskDict->insertName("S", "Alpha"); } else if (sMaskMode == kLuminosity_SMaskMode) { @@ -165,7 +165,7 @@ SkPDFDict* SkPDFGraphicState::GetSMaskGraphicState(SkPDFFormXObject* sMask, sMaskDict->insertObjRef("TR", SkRef(invertFunction.get(create_invert_function))); } - SkAutoTUnref result(new SkPDFDict("ExtGState")); + sk_sp result(new SkPDFDict("ExtGState")); result->insertObject("SMask", sMaskDict.release()); return result.release(); } @@ -186,7 +186,7 @@ void SkPDFGraphicState::emitObject( SkWStream* stream, const SkPDFObjNumMap& objNumMap, const SkPDFSubstituteMap& substitutes) const { - SkAutoTUnref dict(new SkPDFDict("ExtGState")); + sk_sp dict(new SkPDFDict("ExtGState")); dict->insertName("Type", "ExtGState"); SkScalar alpha = SkIntToScalar(fAlpha) / 0xFF; diff --git a/src/pdf/SkPDFMetadata.cpp b/src/pdf/SkPDFMetadata.cpp index 8359786afe..387bde1be7 100644 --- a/src/pdf/SkPDFMetadata.cpp +++ b/src/pdf/SkPDFMetadata.cpp @@ -28,7 +28,7 @@ static SkString pdf_date(const SkTime::DateTime& dt) { } SkPDFObject* SkPDFMetadata::createDocumentInformationDict() const { - SkAutoTUnref dict(new SkPDFDict); + sk_sp dict(new SkPDFDict); static const char* keys[] = { "Title", "Author", "Subject", "Keywords", "Creator"}; for (const char* key : keys) { @@ -86,7 +86,7 @@ SkPDFMetadata::UUID SkPDFMetadata::uuid() const { SkPDFObject* SkPDFMetadata::CreatePdfId(const UUID& doc, const UUID& instance) { // /ID [ <81b14aafa313db63dbd6f981e49f94f4> // <81b14aafa313db63dbd6f981e49f94f4> ] - SkAutoTUnref array(new SkPDFArray); + sk_sp array(new SkPDFArray); static_assert(sizeof(UUID) == 16, "uuid_size"); array->appendString( SkString(reinterpret_cast(&doc), sizeof(UUID))); diff --git a/src/pdf/SkPDFResourceDict.cpp b/src/pdf/SkPDFResourceDict.cpp index b72e6667fd..460d18c740 100644 --- a/src/pdf/SkPDFResourceDict.cpp +++ b/src/pdf/SkPDFResourceDict.cpp @@ -61,7 +61,7 @@ static void add_subdict( if (0 == resourceList.count()) { return; } - SkAutoTUnref resources(new SkPDFDict); + sk_sp resources(new SkPDFDict); for (int i = 0; i < resourceList.count(); i++) { resources->insertObjRef(SkPDFResourceDict::getResourceName(type, i), SkRef(resourceList[i])); @@ -74,10 +74,10 @@ SkPDFDict* SkPDFResourceDict::Create( const SkTDArray* patternResources, const SkTDArray* xObjectResources, const SkTDArray* fontResources) { - SkAutoTUnref dict(new SkPDFDict); + sk_sp dict(new SkPDFDict); static const char kProcs[][7] = { "PDF", "Text", "ImageB", "ImageC", "ImageI"}; - SkAutoTUnref procSets(new SkPDFArray); + sk_sp procSets(new SkPDFArray); procSets->reserve(SK_ARRAY_COUNT(kProcs)); for (size_t i = 0; i < SK_ARRAY_COUNT(kProcs); i++) { diff --git a/src/pdf/SkPDFShader.cpp b/src/pdf/SkPDFShader.cpp index 56926f3e6f..8d5ee5a753 100644 --- a/src/pdf/SkPDFShader.cpp +++ b/src/pdf/SkPDFShader.cpp @@ -587,15 +587,15 @@ static SkPDFObject* create_smask_graphic_state( SkAutoTDelete alphaToLuminosityState( state.CreateAlphaToLuminosityState()); - SkAutoTUnref luminosityShader( + sk_sp luminosityShader( get_pdf_shader_by_state(canon, dpi, &alphaToLuminosityState)); SkAutoTDelete alphaStream(create_pattern_fill_content(-1, bbox)); - SkAutoTUnref + sk_sp resources(get_gradient_resource_dict(luminosityShader.get(), nullptr)); - SkAutoTUnref alphaMask( + sk_sp alphaMask( new SkPDFFormXObject(alphaStream.get(), bbox, resources.get())); return SkPDFGraphicState::GetSMaskGraphicState( @@ -613,7 +613,7 @@ SkPDFAlphaFunctionShader* SkPDFAlphaFunctionShader::Create( SkAutoTDelete opaqueState(state.CreateOpaqueState()); - SkAutoTUnref colorShader( + sk_sp colorShader( get_pdf_shader_by_state(canon, dpi, &opaqueState)); if (!colorShader) { return nullptr; @@ -621,13 +621,13 @@ SkPDFAlphaFunctionShader* SkPDFAlphaFunctionShader::Create( // Create resource dict with alpha graphics state as G0 and // pattern shader as P0, then write content stream. - SkAutoTUnref alphaGs( + sk_sp alphaGs( create_smask_graphic_state(canon, dpi, state)); SkPDFAlphaFunctionShader* alphaFunctionShader = new SkPDFAlphaFunctionShader(autoState->detach()); - SkAutoTUnref resourceDict( + sk_sp resourceDict( get_gradient_resource_dict(colorShader.get(), alphaGs.get())); SkAutoTDelete colorStream( @@ -771,7 +771,7 @@ SkPDFFunctionShader* SkPDFFunctionShader::Create( return nullptr; } - SkAutoTUnref domain(new SkPDFArray); + sk_sp domain(new SkPDFArray); domain->reserve(4); domain->appendScalar(bbox.fLeft); domain->appendScalar(bbox.fRight); @@ -799,16 +799,16 @@ SkPDFFunctionShader* SkPDFFunctionShader::Create( functionCode = codeFunction(*info, perspectiveInverseOnly); } - SkAutoTUnref pdfShader(new SkPDFDict); + sk_sp pdfShader(new SkPDFDict); pdfShader->insertInt("ShadingType", 1); pdfShader->insertName("ColorSpace", "DeviceRGB"); pdfShader->insertObject("Domain", SkRef(domain.get())); - SkAutoTUnref function( + sk_sp function( make_ps_function(functionCode, domain.get())); pdfShader->insertObjRef("Function", function.release()); - SkAutoTUnref pdfFunctionShader(new SkPDFFunctionShader(autoState->detach())); + sk_sp pdfFunctionShader(new SkPDFFunctionShader(autoState->detach())); pdfFunctionShader->insertInt("PatternType", 2); pdfFunctionShader->insertObject("Matrix", @@ -859,7 +859,7 @@ SkPDFImageShader* SkPDFImageShader::Create( SkISize size = SkISize::Make(SkScalarRoundToInt(deviceBounds.width()), SkScalarRoundToInt(deviceBounds.height())); - SkAutoTUnref patternDevice( + sk_sp patternDevice( SkPDFDevice::CreateUnflipped(size, dpi, canon)); SkCanvas canvas(patternDevice.get()); @@ -1024,7 +1024,7 @@ SkPDFImageShader* SkPDFImageShader::Create( SkPDFImageShader* imageShader = new SkPDFImageShader(autoState->detach()); imageShader->setData(content.get()); - SkAutoTUnref resourceDict( + sk_sp resourceDict( patternDevice->createResourceDict()); populate_tiling_pattern_dict(imageShader, patternBBox, resourceDict.get(), finalMatrix); diff --git a/src/pdf/SkPDFTypes.h b/src/pdf/SkPDFTypes.h index 97c4fa1dbf..5a48019fd3 100644 --- a/src/pdf/SkPDFTypes.h +++ b/src/pdf/SkPDFTypes.h @@ -109,13 +109,13 @@ public: static SkPDFUnion String(const SkString&); /** This function DOES take ownership of the object. E.g. - SkAutoTUnref dict(new SkPDFDict); + sk_sp dict(new SkPDFDict); dict->insert(.....); SkPDFUnion u = SkPDFUnion::Object(dict.detach()) */ static SkPDFUnion Object(SkPDFObject*); /** This function DOES take ownership of the object. E.g. - SkAutoTUnref image( + sk_sp image( SkPDFBitmap::Create(fCanon, bitmap)); SkPDFUnion u = SkPDFUnion::ObjRef(image.detach()) */ static SkPDFUnion ObjRef(SkPDFObject*); @@ -327,7 +327,7 @@ public: private: SkAutoTDelete fAsset; - SkAutoTUnref fDict; + sk_sp fDict; typedef SkPDFObject INHERITED; };