diff options
author | halcanary <halcanary@google.com> | 2016-03-08 08:32:12 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-03-08 08:32:12 -0800 |
commit | ece83924384b2e9e8cd422324c44797deb99ec90 (patch) | |
tree | ae357771d64d75b40ebd914cb6c42fbc4e037650 /src | |
parent | cdaa97bf664e0d584187efc125bfff670a064a9a (diff) |
SkPDF: use sk_make_sp<T> when it makes sense.
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1773033002
Review URL: https://codereview.chromium.org/1773033002
Diffstat (limited to 'src')
-rw-r--r-- | src/doc/SkDocument_PDF.cpp | 16 | ||||
-rw-r--r-- | src/pdf/SkPDFDevice.cpp | 14 | ||||
-rw-r--r-- | src/pdf/SkPDFFont.cpp | 26 | ||||
-rw-r--r-- | src/pdf/SkPDFFormXObject.cpp | 2 | ||||
-rw-r--r-- | src/pdf/SkPDFGraphicState.cpp | 10 | ||||
-rw-r--r-- | src/pdf/SkPDFMetadata.cpp | 4 | ||||
-rw-r--r-- | src/pdf/SkPDFResourceDict.cpp | 6 | ||||
-rw-r--r-- | src/pdf/SkPDFShader.cpp | 8 | ||||
-rw-r--r-- | src/pdf/SkPDFShader.h | 2 | ||||
-rw-r--r-- | src/pdf/SkPDFTypes.h | 2 |
10 files changed, 44 insertions, 46 deletions
diff --git a/src/doc/SkDocument_PDF.cpp b/src/doc/SkDocument_PDF.cpp index 54e0fe0c5f..7e5e1a8eba 100644 --- a/src/doc/SkDocument_PDF.cpp +++ b/src/doc/SkDocument_PDF.cpp @@ -77,10 +77,10 @@ static SkPDFObject* create_pdf_page_content(const SkPDFDevice* pageDevice) { } static SkPDFDict* create_pdf_page(const SkPDFDevice* pageDevice) { - sk_sp<SkPDFDict> page(new SkPDFDict("Page")); + auto page = sk_make_sp<SkPDFDict>("Page"); page->insertObject("Resources", pageDevice->createResourceDict()); page->insertObject("MediaBox", pageDevice->copyMediaBox()); - sk_sp<SkPDFArray> annotations(new SkPDFArray); + auto annotations = sk_make_sp<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<SkPDFDict*>& pages, break; } - sk_sp<SkPDFDict> newNode(new SkPDFDict("Pages")); - sk_sp<SkPDFArray> kids(new SkPDFArray); + auto newNode = sk_make_sp<SkPDFDict>("Pages"); + auto kids = sk_make_sp<SkPDFArray>(); kids->reserve(kNodeSize); int count = 0; @@ -174,7 +174,7 @@ static bool emit_pdf_document(const SkTDArray<const SkPDFDevice*>& pageDevices, } SkTDArray<SkPDFDict*> pages; - sk_sp<SkPDFDict> dests(new SkPDFDict); + auto dests = sk_make_sp<SkPDFDict>(); for (int i = 0; i < pageDevices.count(); i++) { SkASSERT(pageDevices[i]); @@ -185,7 +185,7 @@ static bool emit_pdf_document(const SkTDArray<const SkPDFDevice*>& pageDevices, pages.push(page.release()); } - sk_sp<SkPDFDict> docCatalog(new SkPDFDict("Catalog")); + auto docCatalog = sk_make_sp<SkPDFDict>("Catalog"); sk_sp<SkPDFObject> infoDict( metadata.createDocumentInformationDict()); @@ -203,12 +203,12 @@ static bool emit_pdf_document(const SkTDArray<const SkPDFDevice*>& pageDevices, docCatalog->insertObjRef("Metadata", xmp.release()); // sRGB is specified by HTML, CSS, and SVG. - sk_sp<SkPDFDict> outputIntent(new SkPDFDict("OutputIntent")); + auto outputIntent = sk_make_sp<SkPDFDict>("OutputIntent"); outputIntent->insertName("S", "GTS_PDFA1"); outputIntent->insertString("RegistryName", "http://www.color.org"); outputIntent->insertString("OutputConditionIdentifier", "sRGB IEC61966-2.1"); - sk_sp<SkPDFArray> intentArray(new SkPDFArray); + auto intentArray = sk_make_sp<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. diff --git a/src/pdf/SkPDFDevice.cpp b/src/pdf/SkPDFDevice.cpp index 93627b276e..e988112f37 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) { - sk_sp<SkPDFDict> annotation(new SkPDFDict("Annot")); + auto annotation = sk_make_sp<SkPDFDict>("Annot"); annotation->insertName("Subtype", "Link"); - sk_sp<SkPDFArray> border(new SkPDFArray); + auto border = sk_make_sp<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()); - sk_sp<SkPDFArray> rect(new SkPDFArray); + auto rect = sk_make_sp<SkPDFArray>(); rect->reserve(4); rect->appendScalar(translatedRect.fLeft); rect->appendScalar(translatedRect.fTop); @@ -906,7 +906,7 @@ static SkPDFDict* create_link_to_url(const SkData* urlData, const SkRect& r) { SkString url(static_cast<const char *>(urlData->data()), urlData->size() - 1); - sk_sp<SkPDFDict> action(new SkPDFDict("Action")); + auto action = sk_make_sp<SkPDFDict>("Action"); action->insertName("S", "URI"); action->insertString("URI", url); annotation->insertObject("A", action.release()); @@ -1448,7 +1448,7 @@ void SkPDFDevice::drawDevice(const SkDraw& d, SkBaseDevice* device, return; } - sk_sp<SkPDFFormXObject> xObject(new SkPDFFormXObject(pdfDevice)); + auto xObject = sk_make_sp<SkPDFFormXObject>(pdfDevice); SkPDFUtils::DrawFormXObject(this->addXObjectResource(xObject.get()), &content.entry()->fContent); @@ -1527,7 +1527,7 @@ const SkTDArray<SkPDFFont*>& SkPDFDevice::getFontResources() const { SkPDFArray* SkPDFDevice::copyMediaBox() const { // should this be a singleton? - sk_sp<SkPDFArray> mediaBox(new SkPDFArray); + auto mediaBox = sk_make_sp<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) { - sk_sp<SkPDFArray> pdfDest(new SkPDFArray); + auto pdfDest = sk_make_sp<SkPDFArray>(); pdfDest->reserve(5); pdfDest->appendObjRef(SkRef(page)); pdfDest->appendName("XYZ"); diff --git a/src/pdf/SkPDFFont.cpp b/src/pdf/SkPDFFont.cpp index ff0a265746..8615db99ec 100644 --- a/src/pdf/SkPDFFont.cpp +++ b/src/pdf/SkPDFFont.cpp @@ -338,7 +338,7 @@ SkPDFArray* composeAdvanceData( break; } case SkAdvancedTypefaceMetrics::WidthRange::kRange: { - sk_sp<SkPDFArray> advanceArray(new SkPDFArray()); + auto advanceArray = sk_make_sp<SkPDFArray>(); for (int j = 0; j < advanceInfo->fAdvance.count(); j++) appendAdvance(advanceInfo->fAdvance[j], emSize, advanceArray.get()); @@ -1021,7 +1021,7 @@ bool SkPDFType0Font::populate(const SkPDFGlyphSet* subset) { sk_sp<SkPDFCIDFont> newCIDFont( new SkPDFCIDFont(fontInfo(), typeface(), subset)); - sk_sp<SkPDFArray> descendantFonts(new SkPDFArray()); + auto descendantFonts = sk_make_sp<SkPDFArray>(); descendantFonts->appendObjRef(newCIDFont.release()); this->insertObject("DescendantFonts", descendantFonts.release()); @@ -1046,7 +1046,7 @@ SkPDFCIDFont::~SkPDFCIDFont() {} bool SkPDFCIDFont::addFontDescriptor(int16_t defaultWidth, const SkTDArray<uint32_t>* subset) { - sk_sp<SkPDFDict> descriptor(new SkPDFDict("FontDescriptor")); + auto descriptor = sk_make_sp<SkPDFDict>("FontDescriptor"); setFontDescriptor(descriptor.get()); if (!addCommonFontDescriptorEntries(defaultWidth)) { this->insertObjRef("FontDescriptor", descriptor.release()); @@ -1143,7 +1143,7 @@ bool SkPDFCIDFont::populate(const SkPDFGlyphSet* subset) { SkASSERT(false); } - sk_sp<SkPDFDict> sysInfo(new SkPDFDict); + auto sysInfo = sk_make_sp<SkPDFDict>(); sysInfo->insertString("Registry", "Adobe"); sysInfo->insertString("Ordering", "Identity"); sysInfo->insertInt("Supplement", 0); @@ -1207,7 +1207,7 @@ bool SkPDFType1Font::addFontDescriptor(int16_t defaultWidth) { return true; } - sk_sp<SkPDFDict> descriptor(new SkPDFDict("FontDescriptor")); + auto descriptor = sk_make_sp<SkPDFDict>("FontDescriptor"); setFontDescriptor(descriptor.get()); int ttcIndex; @@ -1221,7 +1221,7 @@ bool SkPDFType1Font::addFontDescriptor(int16_t defaultWidth) { return false; } SkASSERT(this->canEmbed()); - sk_sp<SkPDFStream> fontStream(new SkPDFStream(fontData.get())); + auto fontStream = sk_make_sp<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); - sk_sp<SkPDFArray> encDiffs(new SkPDFArray); + auto encDiffs = sk_make_sp<SkPDFArray>(); encDiffs->reserve(lastGlyphID() - firstGlyphID() + 2); encDiffs->appendInt(1); for (int gID = firstGlyphID(); gID <= lastGlyphID(); gID++) { encDiffs->appendName(fontInfo()->fGlyphNames->get()[gID].c_str()); } - sk_sp<SkPDFDict> encoding(new SkPDFDict("Encoding")); + auto encoding = sk_make_sp<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) { - sk_sp<SkPDFArray> widthArray(new SkPDFArray()); + auto widthArray = sk_make_sp<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)); - sk_sp<SkPDFDict> charProcs(new SkPDFDict); - sk_sp<SkPDFDict> encoding(new SkPDFDict("Encoding")); + auto charProcs = sk_make_sp<SkPDFDict>(); + auto encoding = sk_make_sp<SkPDFDict>("Encoding"); - sk_sp<SkPDFArray> encDiffs(new SkPDFArray); + auto encDiffs = sk_make_sp<SkPDFArray>(); encDiffs->reserve(lastGlyphID() - firstGlyphID() + 2); encDiffs->appendInt(1); - sk_sp<SkPDFArray> widthArray(new SkPDFArray()); + auto widthArray = sk_make_sp<SkPDFArray>(); SkIRect bbox = SkIRect::MakeEmpty(); for (int gID = firstGlyphID(); gID <= lastGlyphID(); gID++) { diff --git a/src/pdf/SkPDFFormXObject.cpp b/src/pdf/SkPDFFormXObject.cpp index 4647f5a8a1..abf331f544 100644 --- a/src/pdf/SkPDFFormXObject.cpp +++ b/src/pdf/SkPDFFormXObject.cpp @@ -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. - sk_sp<SkPDFDict> group(new SkPDFDict("Group")); + auto group = sk_make_sp<SkPDFDict>("Group"); group->insertName("S", "Transparency"); if (colorSpace != nullptr) { diff --git a/src/pdf/SkPDFGraphicState.cpp b/src/pdf/SkPDFGraphicState.cpp index 121e583487..7c4c5e30eb 100644 --- a/src/pdf/SkPDFGraphicState.cpp +++ b/src/pdf/SkPDFGraphicState.cpp @@ -129,7 +129,7 @@ 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. - sk_sp<SkPDFArray> domainAndRange(new SkPDFArray); + auto domainAndRange = sk_make_sp<SkPDFArray>(); domainAndRange->reserve(2); domainAndRange->appendInt(0); domainAndRange->appendInt(1); @@ -139,7 +139,7 @@ static SkPDFObject* create_invert_function() { sk_sp<SkData> psInvertStream( SkData::NewWithoutCopy(psInvert, strlen(psInvert))); - sk_sp<SkPDFStream> invertFunction(new SkPDFStream(psInvertStream.get())); + auto invertFunction = sk_make_sp<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. - sk_sp<SkPDFDict> sMaskDict(new SkPDFDict("Mask")); + auto sMaskDict = sk_make_sp<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))); } - sk_sp<SkPDFDict> result(new SkPDFDict("ExtGState")); + auto result = sk_make_sp<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 { - sk_sp<SkPDFDict> dict(new SkPDFDict("ExtGState")); + auto dict = sk_make_sp<SkPDFDict>("ExtGState"); dict->insertName("Type", "ExtGState"); SkScalar alpha = SkIntToScalar(fAlpha) / 0xFF; diff --git a/src/pdf/SkPDFMetadata.cpp b/src/pdf/SkPDFMetadata.cpp index 387bde1be7..5e8c124d7b 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 { - sk_sp<SkPDFDict> dict(new SkPDFDict); + auto dict = sk_make_sp<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> ] - sk_sp<SkPDFArray> array(new SkPDFArray); + auto array = sk_make_sp<SkPDFArray>(); static_assert(sizeof(UUID) == 16, "uuid_size"); array->appendString( SkString(reinterpret_cast<const char*>(&doc), sizeof(UUID))); diff --git a/src/pdf/SkPDFResourceDict.cpp b/src/pdf/SkPDFResourceDict.cpp index 460d18c740..d3f4a6d533 100644 --- a/src/pdf/SkPDFResourceDict.cpp +++ b/src/pdf/SkPDFResourceDict.cpp @@ -61,7 +61,7 @@ static void add_subdict( if (0 == resourceList.count()) { return; } - sk_sp<SkPDFDict> resources(new SkPDFDict); + auto resources = sk_make_sp<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<SkPDFObject*>* patternResources, const SkTDArray<SkPDFObject*>* xObjectResources, const SkTDArray<SkPDFObject*>* fontResources) { - sk_sp<SkPDFDict> dict(new SkPDFDict); + auto dict = sk_make_sp<SkPDFDict>(); static const char kProcs[][7] = { "PDF", "Text", "ImageB", "ImageC", "ImageI"}; - sk_sp<SkPDFArray> procSets(new SkPDFArray); + auto procSets = sk_make_sp<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 8d5ee5a753..95ef9dcca0 100644 --- a/src/pdf/SkPDFShader.cpp +++ b/src/pdf/SkPDFShader.cpp @@ -771,7 +771,7 @@ SkPDFFunctionShader* SkPDFFunctionShader::Create( return nullptr; } - sk_sp<SkPDFArray> domain(new SkPDFArray); + auto domain = sk_make_sp<SkPDFArray>(); domain->reserve(4); domain->appendScalar(bbox.fLeft); domain->appendScalar(bbox.fRight); @@ -799,7 +799,7 @@ SkPDFFunctionShader* SkPDFFunctionShader::Create( functionCode = codeFunction(*info, perspectiveInverseOnly); } - sk_sp<SkPDFDict> pdfShader(new SkPDFDict); + auto pdfShader = sk_make_sp<SkPDFDict>(); pdfShader->insertInt("ShadingType", 1); pdfShader->insertName("ColorSpace", "DeviceRGB"); pdfShader->insertObject("Domain", SkRef(domain.get())); @@ -808,8 +808,8 @@ SkPDFFunctionShader* SkPDFFunctionShader::Create( make_ps_function(functionCode, domain.get())); pdfShader->insertObjRef("Function", function.release()); - sk_sp<SkPDFFunctionShader> pdfFunctionShader(new SkPDFFunctionShader(autoState->detach())); - + sk_sp<SkPDFFunctionShader> pdfFunctionShader( + new SkPDFFunctionShader(autoState->detach())); pdfFunctionShader->insertInt("PatternType", 2); pdfFunctionShader->insertObject("Matrix", SkPDFUtils::MatrixToArray(finalMatrix)); diff --git a/src/pdf/SkPDFShader.h b/src/pdf/SkPDFShader.h index 3de17cdc50..61b6de663d 100644 --- a/src/pdf/SkPDFShader.h +++ b/src/pdf/SkPDFShader.h @@ -51,8 +51,6 @@ public: }; class SkPDFFunctionShader final : public SkPDFDict { - - public: static SkPDFFunctionShader* Create(SkPDFCanon*, SkAutoTDelete<SkPDFShader::State>*); diff --git a/src/pdf/SkPDFTypes.h b/src/pdf/SkPDFTypes.h index 5a48019fd3..a6a3e12ee6 100644 --- a/src/pdf/SkPDFTypes.h +++ b/src/pdf/SkPDFTypes.h @@ -109,7 +109,7 @@ public: static SkPDFUnion String(const SkString&); /** This function DOES take ownership of the object. E.g. - sk_sp<SkPDFDict> dict(new SkPDFDict); + auto dict = sk_make_sp<SkPDFDict>(); dict->insert(.....); SkPDFUnion u = SkPDFUnion::Object(dict.detach()) */ static SkPDFUnion Object(SkPDFObject*); |