SkPDF: Add sk_sp setters; .release() becomes std::move()
Note to reviewers: Start with changes to SkPDFTypes.h Many places that had a bare pointer owning a reference are refactored to use a sk_sp. There remain several places where a non-owning pointer `T*` should be replaced with `const sk_sp<T>&` to eliminate the common pattern `sk_sp<T>(SkRef(x))`. Review URL: https://codereview.chromium.org/1775043002
This commit is contained in:
parent
6b5c5cc7b7
commit
9904c92120
@ -31,17 +31,17 @@ static void emit_pdf_footer(SkWStream* stream,
|
||||
SkPDFObject* docCatalog,
|
||||
int64_t objCount,
|
||||
int32_t xRefFileOffset,
|
||||
SkPDFObject* info /* take ownership */,
|
||||
SkPDFObject* id /* take ownership */) {
|
||||
sk_sp<SkPDFObject> info,
|
||||
sk_sp<SkPDFObject> id) {
|
||||
SkPDFDict trailerDict;
|
||||
// TODO(http://crbug.com/80908): Linearized format will take a
|
||||
// Prev entry too.
|
||||
trailerDict.insertInt("Size", int(objCount));
|
||||
trailerDict.insertObjRef("Root", SkRef(docCatalog));
|
||||
trailerDict.insertObjRef("Root", sk_sp<SkPDFObject>(SkRef(docCatalog)));
|
||||
SkASSERT(info);
|
||||
trailerDict.insertObjRef("Info", info);
|
||||
trailerDict.insertObjRef("Info", std::move(info));
|
||||
if (id) {
|
||||
trailerDict.insertObject("ID", id);
|
||||
trailerDict.insertObject("ID", std::move(id));
|
||||
}
|
||||
stream->writeText("trailer\n");
|
||||
trailerDict.emitObject(stream, objNumMap, substitutes);
|
||||
@ -51,13 +51,13 @@ static void emit_pdf_footer(SkWStream* stream,
|
||||
}
|
||||
|
||||
static void perform_font_subsetting(
|
||||
const SkTDArray<const SkPDFDevice*>& pageDevices,
|
||||
const SkTArray<sk_sp<const SkPDFDevice>>& pageDevices,
|
||||
SkPDFSubstituteMap* substituteMap) {
|
||||
SkASSERT(substituteMap);
|
||||
|
||||
SkPDFGlyphSetMap usage;
|
||||
for (int i = 0; i < pageDevices.count(); ++i) {
|
||||
usage.merge(pageDevices[i]->getFontGlyphUsage());
|
||||
for (const sk_sp<const SkPDFDevice>& pageDevice : pageDevices) {
|
||||
usage.merge(pageDevice->getFontGlyphUsage());
|
||||
}
|
||||
SkPDFGlyphSetMap::F2BIter iterator(usage);
|
||||
const SkPDFGlyphSetMap::FontGlyphSetPair* entry = iterator.next();
|
||||
@ -71,27 +71,24 @@ static void perform_font_subsetting(
|
||||
}
|
||||
}
|
||||
|
||||
static SkPDFObject* create_pdf_page_content(const SkPDFDevice* pageDevice) {
|
||||
SkAutoTDelete<SkStreamAsset> content(pageDevice->content());
|
||||
return new SkPDFStream(content.get());
|
||||
}
|
||||
|
||||
static SkPDFDict* create_pdf_page(const SkPDFDevice* pageDevice) {
|
||||
static sk_sp<SkPDFDict> create_pdf_page(const SkPDFDevice* pageDevice) {
|
||||
auto page = sk_make_sp<SkPDFDict>("Page");
|
||||
page->insertObject("Resources", pageDevice->createResourceDict());
|
||||
page->insertObject("Resources", pageDevice->makeResourceDict());
|
||||
page->insertObject("MediaBox", pageDevice->copyMediaBox());
|
||||
auto annotations = sk_make_sp<SkPDFArray>();
|
||||
pageDevice->appendAnnotations(annotations.get());
|
||||
if (annotations->size() > 0) {
|
||||
page->insertObject("Annots", annotations.release());
|
||||
page->insertObject("Annots", std::move(annotations));
|
||||
}
|
||||
page->insertObjRef("Contents", create_pdf_page_content(pageDevice));
|
||||
return page.release();
|
||||
auto content = pageDevice->content();
|
||||
page->insertObjRef("Contents", sk_make_sp<SkPDFStream>(content.get()));
|
||||
return std::move(page);
|
||||
}
|
||||
|
||||
static void generate_page_tree(const SkTDArray<SkPDFDict*>& pages,
|
||||
SkTDArray<SkPDFDict*>* pageTree,
|
||||
SkPDFDict** rootNode) {
|
||||
// return root node.
|
||||
static sk_sp<SkPDFDict> generate_page_tree(
|
||||
const SkTDArray<SkPDFDict*>& pages,
|
||||
SkTDArray<SkPDFDict*>* pageTree) {
|
||||
// PDF wants a tree describing all the pages in the document. We arbitrary
|
||||
// choose 8 (kNodeSize) as the number of allowed children. The internal
|
||||
// nodes have type "Pages" with an array of children, a parent pointer, and
|
||||
@ -127,8 +124,8 @@ static void generate_page_tree(const SkTDArray<SkPDFDict*>& pages,
|
||||
|
||||
int count = 0;
|
||||
for (; i < curNodes.count() && count < kNodeSize; i++, count++) {
|
||||
curNodes[i]->insertObjRef("Parent", SkRef(newNode.get()));
|
||||
kids->appendObjRef(SkRef(curNodes[i]));
|
||||
curNodes[i]->insertObjRef("Parent", newNode);
|
||||
kids->appendObjRef(sk_sp<SkPDFDict>(SkRef(curNodes[i])));
|
||||
|
||||
// TODO(vandebo): put the objects in strict access order.
|
||||
// Probably doesn't matter because they are so small.
|
||||
@ -151,7 +148,7 @@ static void generate_page_tree(const SkTDArray<SkPDFDict*>& pages,
|
||||
pageCount = ((pages.count() - 1) % treeCapacity) + 1;
|
||||
}
|
||||
newNode->insertInt("Count", pageCount);
|
||||
newNode->insertObject("Kids", kids.release());
|
||||
newNode->insertObject("Kids", std::move(kids));
|
||||
nextRoundNodes.push(newNode.release()); // Transfer reference.
|
||||
}
|
||||
|
||||
@ -161,34 +158,30 @@ static void generate_page_tree(const SkTDArray<SkPDFDict*>& pages,
|
||||
} while (curNodes.count() > 1);
|
||||
|
||||
pageTree->push(curNodes[0]); // Transfer reference.
|
||||
if (rootNode) {
|
||||
*rootNode = curNodes[0];
|
||||
}
|
||||
return sk_sp<SkPDFDict>(SkRef(curNodes[0]));
|
||||
}
|
||||
|
||||
static bool emit_pdf_document(const SkTDArray<const SkPDFDevice*>& pageDevices,
|
||||
static bool emit_pdf_document(const SkTArray<sk_sp<const SkPDFDevice>>& pageDevices,
|
||||
const SkPDFMetadata& metadata,
|
||||
SkWStream* stream) {
|
||||
if (pageDevices.isEmpty()) {
|
||||
if (pageDevices.empty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
SkTDArray<SkPDFDict*> pages;
|
||||
SkTDArray<SkPDFDict*> pages; // TODO: SkTArray<sk_sp<SkPDFDict>>
|
||||
auto dests = sk_make_sp<SkPDFDict>();
|
||||
|
||||
for (int i = 0; i < pageDevices.count(); i++) {
|
||||
SkASSERT(pageDevices[i]);
|
||||
SkASSERT(i == 0 ||
|
||||
pageDevices[i - 1]->getCanon() == pageDevices[i]->getCanon());
|
||||
sk_sp<SkPDFDict> page(create_pdf_page(pageDevices[i]));
|
||||
pageDevices[i]->appendDestinations(dests.get(), page.get());
|
||||
for (const sk_sp<const SkPDFDevice>& pageDevice : pageDevices) {
|
||||
SkASSERT(pageDevice);
|
||||
SkASSERT(pageDevices[0]->getCanon() == pageDevice->getCanon());
|
||||
sk_sp<SkPDFDict> page(create_pdf_page(pageDevice.get()));
|
||||
pageDevice->appendDestinations(dests.get(), page.get());
|
||||
pages.push(page.release());
|
||||
}
|
||||
|
||||
auto docCatalog = sk_make_sp<SkPDFDict>("Catalog");
|
||||
|
||||
sk_sp<SkPDFObject> infoDict(
|
||||
metadata.createDocumentInformationDict());
|
||||
sk_sp<SkPDFObject> infoDict(metadata.createDocumentInformationDict());
|
||||
|
||||
sk_sp<SkPDFObject> id, xmp;
|
||||
#ifdef SK_PDF_GENERATE_PDFA
|
||||
@ -200,7 +193,7 @@ static bool emit_pdf_document(const SkTDArray<const SkPDFDevice*>& pageDevices,
|
||||
// works best with reproducible outputs.
|
||||
id.reset(SkPDFMetadata::CreatePdfId(uuid, uuid));
|
||||
xmp.reset(metadata.createXMPObject(uuid, uuid));
|
||||
docCatalog->insertObjRef("Metadata", xmp.release());
|
||||
docCatalog->insertObjRef("Metadata", std::move(xmp));
|
||||
|
||||
// sRGB is specified by HTML, CSS, and SVG.
|
||||
auto outputIntent = sk_make_sp<SkPDFDict>("OutputIntent");
|
||||
@ -209,19 +202,17 @@ static bool emit_pdf_document(const SkTDArray<const SkPDFDevice*>& pageDevices,
|
||||
outputIntent->insertString("OutputConditionIdentifier",
|
||||
"sRGB IEC61966-2.1");
|
||||
auto intentArray = sk_make_sp<SkPDFArray>();
|
||||
intentArray->appendObject(outputIntent.release());
|
||||
intentArray->appendObject(std::move(outputIntent));
|
||||
// Don't specify OutputIntents if we are not in PDF/A mode since
|
||||
// no one has ever asked for this feature.
|
||||
docCatalog->insertObject("OutputIntents", intentArray.release());
|
||||
docCatalog->insertObject("OutputIntents", std::move(intentArray));
|
||||
#endif
|
||||
|
||||
SkTDArray<SkPDFDict*> pageTree;
|
||||
SkPDFDict* pageTreeRoot;
|
||||
generate_page_tree(pages, &pageTree, &pageTreeRoot);
|
||||
docCatalog->insertObjRef("Pages", SkRef(pageTreeRoot));
|
||||
docCatalog->insertObjRef("Pages", generate_page_tree(pages, &pageTree));
|
||||
|
||||
if (dests->size() > 0) {
|
||||
docCatalog->insertObjRef("Dests", dests.release());
|
||||
docCatalog->insertObjRef("Dests", std::move(dests));
|
||||
}
|
||||
|
||||
// Build font subsetting info before proceeding.
|
||||
@ -262,7 +253,7 @@ static bool emit_pdf_document(const SkTDArray<const SkPDFDevice*>& pageDevices,
|
||||
stream->writeText(" 00000 n \n");
|
||||
}
|
||||
emit_pdf_footer(stream, objNumMap, substitutes, docCatalog.get(), objCount,
|
||||
xRefFileOffset, infoDict.release(), id.release());
|
||||
xRefFileOffset, std::move(infoDict), std::move(id));
|
||||
|
||||
// The page tree has both child and parent pointers, so it creates a
|
||||
// reference cycle. We must clear that cycle to properly reclaim memory.
|
||||
@ -344,7 +335,7 @@ protected:
|
||||
sk_sp<SkPDFDevice> device(
|
||||
SkPDFDevice::Create(pageSize, fRasterDpi, &fCanon));
|
||||
fCanvas.reset(new SkCanvas(device.get()));
|
||||
fPageDevices.push(device.release());
|
||||
fPageDevices.push_back(std::move(device));
|
||||
fCanvas->clipRect(trimBox);
|
||||
fCanvas->translate(trimBox.x(), trimBox.y());
|
||||
return fCanvas.get();
|
||||
@ -360,13 +351,13 @@ protected:
|
||||
SkASSERT(!fCanvas.get());
|
||||
|
||||
bool success = emit_pdf_document(fPageDevices, fMetadata, stream);
|
||||
fPageDevices.unrefAll();
|
||||
fPageDevices.reset();
|
||||
fCanon.reset();
|
||||
return success;
|
||||
}
|
||||
|
||||
void onAbort() override {
|
||||
fPageDevices.unrefAll();
|
||||
fPageDevices.reset();
|
||||
fCanon.reset();
|
||||
}
|
||||
|
||||
@ -381,7 +372,7 @@ protected:
|
||||
|
||||
private:
|
||||
SkPDFCanon fCanon;
|
||||
SkTDArray<const SkPDFDevice*> fPageDevices;
|
||||
SkTArray<sk_sp<const SkPDFDevice>> fPageDevices;
|
||||
sk_sp<SkCanvas> fCanvas;
|
||||
SkScalar fRasterDpi;
|
||||
SkPDFMetadata fMetadata;
|
||||
|
@ -297,8 +297,8 @@ static void bitmap_alpha_to_a8(const SkBitmap& bitmap, SkWStream* out) {
|
||||
}
|
||||
}
|
||||
|
||||
static SkPDFArray* make_indexed_color_space(const SkColorTable* table) {
|
||||
SkPDFArray* result = new SkPDFArray;
|
||||
static sk_sp<SkPDFArray> make_indexed_color_space(const SkColorTable* table) {
|
||||
auto result = sk_make_sp<SkPDFArray>();
|
||||
result->reserve(4);
|
||||
result->appendName("Indexed");
|
||||
result->appendName("DeviceRGB");
|
||||
@ -308,7 +308,7 @@ static SkPDFArray* make_indexed_color_space(const SkColorTable* table) {
|
||||
char shortTableArray[3] = {0, 0, 0};
|
||||
SkString tableString(shortTableArray, SK_ARRAY_COUNT(shortTableArray));
|
||||
result->appendString(tableString);
|
||||
return result;
|
||||
return std::move(result);
|
||||
}
|
||||
result->appendInt(table->count() - 1); // maximum color index.
|
||||
|
||||
@ -324,13 +324,13 @@ static SkPDFArray* make_indexed_color_space(const SkColorTable* table) {
|
||||
}
|
||||
SkString tableString(tableArray, 3 * table->count());
|
||||
result->appendString(tableString);
|
||||
return result;
|
||||
return std::move(result);
|
||||
}
|
||||
|
||||
static void emit_image_xobject(SkWStream* stream,
|
||||
const SkImage* image,
|
||||
bool alpha,
|
||||
SkPDFObject* smask,
|
||||
const sk_sp<SkPDFObject>& smask,
|
||||
const SkPDFObjNumMap& objNumMap,
|
||||
const SkPDFSubstituteMap& substitutes) {
|
||||
SkBitmap bitmap;
|
||||
@ -364,7 +364,7 @@ static void emit_image_xobject(SkWStream* stream,
|
||||
pdfDict.insertName("ColorSpace", "DeviceRGB");
|
||||
}
|
||||
if (smask) {
|
||||
pdfDict.insertObjRef("SMask", SkRef(smask));
|
||||
pdfDict.insertObjRef("SMask", smask);
|
||||
}
|
||||
pdfDict.insertInt("BitsPerComponent", 8);
|
||||
pdfDict.insertName("Filter", "FlateDecode");
|
||||
@ -404,7 +404,7 @@ public:
|
||||
void emitObject(SkWStream* stream,
|
||||
const SkPDFObjNumMap& objNumMap,
|
||||
const SkPDFSubstituteMap& subs) const override {
|
||||
emit_image_xobject(stream, fImage.get(), false, fSMask.get(), objNumMap, subs);
|
||||
emit_image_xobject(stream, fImage.get(), false, fSMask, objNumMap, subs);
|
||||
}
|
||||
void addResources(SkPDFObjNumMap* catalog,
|
||||
const SkPDFSubstituteMap& subs) const override {
|
||||
|
@ -879,7 +879,7 @@ void SkPDFDevice::drawPoints(const SkDraw& d,
|
||||
}
|
||||
}
|
||||
|
||||
static SkPDFDict* create_link_annotation(const SkRect& translatedRect) {
|
||||
static sk_sp<SkPDFDict> create_link_annotation(const SkRect& translatedRect) {
|
||||
auto annotation = sk_make_sp<SkPDFDict>("Annot");
|
||||
annotation->insertName("Subtype", "Link");
|
||||
|
||||
@ -888,7 +888,7 @@ static SkPDFDict* create_link_annotation(const SkRect& translatedRect) {
|
||||
border->appendInt(0); // Horizontal corner radius.
|
||||
border->appendInt(0); // Vertical corner radius.
|
||||
border->appendInt(0); // Width, 0 = no border.
|
||||
annotation->insertObject("Border", border.release());
|
||||
annotation->insertObject("Border", std::move(border));
|
||||
|
||||
auto rect = sk_make_sp<SkPDFArray>();
|
||||
rect->reserve(4);
|
||||
@ -896,30 +896,29 @@ static SkPDFDict* create_link_annotation(const SkRect& translatedRect) {
|
||||
rect->appendScalar(translatedRect.fTop);
|
||||
rect->appendScalar(translatedRect.fRight);
|
||||
rect->appendScalar(translatedRect.fBottom);
|
||||
annotation->insertObject("Rect", rect.release());
|
||||
annotation->insertObject("Rect", std::move(rect));
|
||||
|
||||
return annotation.release();
|
||||
return std::move(annotation);
|
||||
}
|
||||
|
||||
static SkPDFDict* create_link_to_url(const SkData* urlData, const SkRect& r) {
|
||||
sk_sp<SkPDFDict> annotation(create_link_annotation(r));
|
||||
|
||||
static sk_sp<SkPDFDict> create_link_to_url(const SkData* urlData, const SkRect& r) {
|
||||
auto annotation = create_link_annotation(r);
|
||||
SkString url(static_cast<const char *>(urlData->data()),
|
||||
urlData->size() - 1);
|
||||
auto action = sk_make_sp<SkPDFDict>("Action");
|
||||
action->insertName("S", "URI");
|
||||
action->insertString("URI", url);
|
||||
annotation->insertObject("A", action.release());
|
||||
return annotation.release();
|
||||
annotation->insertObject("A", std::move(action));
|
||||
return std::move(annotation);
|
||||
}
|
||||
|
||||
static SkPDFDict* create_link_named_dest(const SkData* nameData,
|
||||
const SkRect& r) {
|
||||
sk_sp<SkPDFDict> annotation(create_link_annotation(r));
|
||||
static sk_sp<SkPDFDict> create_link_named_dest(const SkData* nameData,
|
||||
const SkRect& r) {
|
||||
auto annotation = create_link_annotation(r);
|
||||
SkString name(static_cast<const char *>(nameData->data()),
|
||||
nameData->size() - 1);
|
||||
annotation->insertName("Dest", name);
|
||||
return annotation.release();
|
||||
return std::move(annotation);
|
||||
}
|
||||
|
||||
void SkPDFDevice::drawRect(const SkDraw& d,
|
||||
@ -1507,13 +1506,13 @@ void SkPDFDevice::setDrawingArea(DrawingArea drawingArea) {
|
||||
fDrawingArea = drawingArea;
|
||||
}
|
||||
|
||||
SkPDFDict* SkPDFDevice::createResourceDict() const {
|
||||
sk_sp<SkPDFDict> SkPDFDevice::makeResourceDict() const {
|
||||
SkTDArray<SkPDFObject*> fonts;
|
||||
fonts.setReserve(fFontResources.count());
|
||||
for (SkPDFFont* font : fFontResources) {
|
||||
fonts.push(font);
|
||||
}
|
||||
return SkPDFResourceDict::Create(
|
||||
return SkPDFResourceDict::Make(
|
||||
&fGraphicStateResources,
|
||||
&fShaderResources,
|
||||
&fXObjectResources,
|
||||
@ -1524,24 +1523,23 @@ const SkTDArray<SkPDFFont*>& SkPDFDevice::getFontResources() const {
|
||||
return fFontResources;
|
||||
}
|
||||
|
||||
SkPDFArray* SkPDFDevice::copyMediaBox() const {
|
||||
// should this be a singleton?
|
||||
|
||||
sk_sp<SkPDFArray> SkPDFDevice::copyMediaBox() const {
|
||||
auto mediaBox = sk_make_sp<SkPDFArray>();
|
||||
mediaBox->reserve(4);
|
||||
mediaBox->appendInt(0);
|
||||
mediaBox->appendInt(0);
|
||||
mediaBox->appendInt(fPageSize.fWidth);
|
||||
mediaBox->appendInt(fPageSize.fHeight);
|
||||
return mediaBox.release();
|
||||
mediaBox->appendInt(fPageSize.width());
|
||||
mediaBox->appendInt(fPageSize.height());
|
||||
return std::move(mediaBox);
|
||||
}
|
||||
|
||||
SkStreamAsset* SkPDFDevice::content() const {
|
||||
skstd::unique_ptr<SkStreamAsset> SkPDFDevice::content() const {
|
||||
SkDynamicMemoryWStream buffer;
|
||||
this->writeContent(&buffer);
|
||||
return buffer.bytesWritten() > 0
|
||||
? buffer.detachAsStream()
|
||||
: new SkMemoryStream;
|
||||
return skstd::unique_ptr<SkStreamAsset>(
|
||||
buffer.bytesWritten() > 0
|
||||
? buffer.detachAsStream()
|
||||
: new SkMemoryStream);
|
||||
}
|
||||
|
||||
void SkPDFDevice::copyContentEntriesToData(ContentEntry* entry,
|
||||
@ -1713,14 +1711,14 @@ void SkPDFDevice::appendDestinations(SkPDFDict* dict, SkPDFObject* page) const {
|
||||
for (const NamedDestination& dest : fNamedDestinations) {
|
||||
auto pdfDest = sk_make_sp<SkPDFArray>();
|
||||
pdfDest->reserve(5);
|
||||
pdfDest->appendObjRef(SkRef(page));
|
||||
pdfDest->appendObjRef(sk_sp<SkPDFObject>(SkRef(page)));
|
||||
pdfDest->appendName("XYZ");
|
||||
SkPoint p = fInitialTransform.mapXY(dest.point.x(), dest.point.y());
|
||||
pdfDest->appendScalar(p.x());
|
||||
pdfDest->appendScalar(p.y());
|
||||
pdfDest->appendInt(0); // Leave zoom unchanged
|
||||
SkString name(static_cast<const char*>(dest.nameData->data()));
|
||||
dict->insertObject(name, pdfDest.release());
|
||||
dict->insertObject(name, std::move(pdfDest));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -144,9 +144,8 @@ public:
|
||||
|
||||
// PDF specific methods.
|
||||
|
||||
/** Create the resource dictionary for this device.
|
||||
*/
|
||||
SkPDFDict* createResourceDict() const;
|
||||
/** Create the resource dictionary for this device. */
|
||||
sk_sp<SkPDFDict> makeResourceDict() const;
|
||||
|
||||
/** Get the fonts used on this device.
|
||||
*/
|
||||
@ -164,15 +163,12 @@ public:
|
||||
*/
|
||||
void appendDestinations(SkPDFDict* dict, SkPDFObject* page) const;
|
||||
|
||||
/** Returns a copy of the media box for this device. The caller is required
|
||||
* to unref() this when it is finished.
|
||||
*/
|
||||
SkPDFArray* copyMediaBox() const;
|
||||
/** Returns a copy of the media box for this device. */
|
||||
sk_sp<SkPDFArray> copyMediaBox() const;
|
||||
|
||||
/** Returns a SkStream with the page contents. The caller is responsible
|
||||
* for a deleting the returned value.
|
||||
/** Returns a SkStream with the page contents.
|
||||
*/
|
||||
SkStreamAsset* content() const;
|
||||
skstd::unique_ptr<SkStreamAsset> content() const;
|
||||
|
||||
/** Writes the page contents to the stream. */
|
||||
void writeContent(SkWStream*) const;
|
||||
|
@ -297,37 +297,35 @@ void setGlyphWidthAndBoundingBox(SkScalar width, SkIRect box,
|
||||
content->writeText(" d1\n");
|
||||
}
|
||||
|
||||
SkPDFArray* makeFontBBox(SkIRect glyphBBox, uint16_t emSize) {
|
||||
SkPDFArray* bbox = new SkPDFArray;
|
||||
static sk_sp<SkPDFArray> makeFontBBox(SkIRect glyphBBox, uint16_t emSize) {
|
||||
auto bbox = sk_make_sp<SkPDFArray>();
|
||||
bbox->reserve(4);
|
||||
bbox->appendScalar(scaleFromFontUnits(glyphBBox.fLeft, emSize));
|
||||
bbox->appendScalar(scaleFromFontUnits(glyphBBox.fBottom, emSize));
|
||||
bbox->appendScalar(scaleFromFontUnits(glyphBBox.fRight, emSize));
|
||||
bbox->appendScalar(scaleFromFontUnits(glyphBBox.fTop, emSize));
|
||||
return bbox;
|
||||
return std::move(bbox);
|
||||
}
|
||||
|
||||
SkPDFArray* appendWidth(const int16_t& width, uint16_t emSize,
|
||||
static void appendWidth(const int16_t& width, uint16_t emSize,
|
||||
SkPDFArray* array) {
|
||||
array->appendScalar(scaleFromFontUnits(width, emSize));
|
||||
return array;
|
||||
}
|
||||
|
||||
SkPDFArray* appendVerticalAdvance(
|
||||
static void appendVerticalAdvance(
|
||||
const SkAdvancedTypefaceMetrics::VerticalMetric& advance,
|
||||
uint16_t emSize, SkPDFArray* array) {
|
||||
appendWidth(advance.fVerticalAdvance, emSize, array);
|
||||
appendWidth(advance.fOriginXDisp, emSize, array);
|
||||
appendWidth(advance.fOriginYDisp, emSize, array);
|
||||
return array;
|
||||
}
|
||||
|
||||
template <typename Data>
|
||||
SkPDFArray* composeAdvanceData(
|
||||
SkAdvancedTypefaceMetrics::AdvanceMetric<Data>* advanceInfo,
|
||||
uint16_t emSize,
|
||||
SkPDFArray* (*appendAdvance)(const Data& advance, uint16_t emSize,
|
||||
SkPDFArray* array),
|
||||
void (*appendAdvance)(const Data& advance, uint16_t emSize,
|
||||
SkPDFArray* array),
|
||||
Data* defaultAdvance) {
|
||||
SkPDFArray* result = new SkPDFArray();
|
||||
for (; advanceInfo != nullptr; advanceInfo = advanceInfo->fNext.get()) {
|
||||
@ -343,7 +341,7 @@ SkPDFArray* composeAdvanceData(
|
||||
appendAdvance(advanceInfo->fAdvance[j], emSize,
|
||||
advanceArray.get());
|
||||
result->appendInt(advanceInfo->fStartId);
|
||||
result->appendObject(advanceArray.release());
|
||||
result->appendObject(std::move(advanceArray));
|
||||
break;
|
||||
}
|
||||
case SkAdvancedTypefaceMetrics::WidthRange::kRun: {
|
||||
@ -559,7 +557,7 @@ void append_cmap_sections(const SkTDArray<SkUnichar>& glyphToUnicode,
|
||||
append_bfrange_section(bfrangeEntries, cmap);
|
||||
}
|
||||
|
||||
static SkPDFStream* generate_tounicode_cmap(
|
||||
static sk_sp<SkPDFStream> generate_tounicode_cmap(
|
||||
const SkTDArray<SkUnichar>& glyphToUnicode,
|
||||
const SkPDFGlyphSet* subset,
|
||||
bool multiByteGlyphs,
|
||||
@ -575,7 +573,7 @@ static SkPDFStream* generate_tounicode_cmap(
|
||||
firstGlyphID, lastGlyphID);
|
||||
append_cmap_footer(&cmap);
|
||||
sk_sp<SkData> cmapData(cmap.copyToData());
|
||||
return new SkPDFStream(cmapData.get());
|
||||
return sk_make_sp<SkPDFStream>(cmapData.get());
|
||||
}
|
||||
|
||||
#if defined (SK_SFNTLY_SUBSETTER)
|
||||
@ -1022,8 +1020,8 @@ bool SkPDFType0Font::populate(const SkPDFGlyphSet* subset) {
|
||||
sk_sp<SkPDFCIDFont> newCIDFont(
|
||||
new SkPDFCIDFont(fontInfo(), typeface(), subset));
|
||||
auto descendantFonts = sk_make_sp<SkPDFArray>();
|
||||
descendantFonts->appendObjRef(newCIDFont.release());
|
||||
this->insertObject("DescendantFonts", descendantFonts.release());
|
||||
descendantFonts->appendObjRef(std::move(newCIDFont));
|
||||
this->insertObject("DescendantFonts", std::move(descendantFonts));
|
||||
|
||||
this->populateToUnicodeTable(subset);
|
||||
|
||||
@ -1049,7 +1047,7 @@ bool SkPDFCIDFont::addFontDescriptor(int16_t defaultWidth,
|
||||
auto descriptor = sk_make_sp<SkPDFDict>("FontDescriptor");
|
||||
setFontDescriptor(descriptor.get());
|
||||
if (!addCommonFontDescriptorEntries(defaultWidth)) {
|
||||
this->insertObjRef("FontDescriptor", descriptor.release());
|
||||
this->insertObjRef("FontDescriptor", std::move(descriptor));
|
||||
return false;
|
||||
}
|
||||
SkASSERT(this->canEmbed());
|
||||
@ -1068,7 +1066,7 @@ bool SkPDFCIDFont::addFontDescriptor(int16_t defaultWidth,
|
||||
if (rawStream) {
|
||||
fontStream.reset(rawStream);
|
||||
fontStream->insertInt("Length1", fontSize);
|
||||
descriptor->insertObjRef("FontFile2", fontStream.release());
|
||||
descriptor->insertObjRef("FontFile2", std::move(fontStream));
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -1081,7 +1079,7 @@ bool SkPDFCIDFont::addFontDescriptor(int16_t defaultWidth,
|
||||
SkASSERT(fontSize > 0);
|
||||
fontStream.reset(new SkPDFSharedStream(fontData.detach()));
|
||||
fontStream->dict()->insertInt("Length1", fontSize);
|
||||
descriptor->insertObjRef("FontFile2", fontStream.release());
|
||||
descriptor->insertObjRef("FontFile2", std::move(fontStream));
|
||||
break;
|
||||
}
|
||||
case SkAdvancedTypefaceMetrics::kCFF_Font:
|
||||
@ -1094,13 +1092,13 @@ bool SkPDFCIDFont::addFontDescriptor(int16_t defaultWidth,
|
||||
} else {
|
||||
fontStream->dict()->insertName("Subtype", "CIDFontType0c");
|
||||
}
|
||||
descriptor->insertObjRef("FontFile3", fontStream.release());
|
||||
descriptor->insertObjRef("FontFile3", std::move(fontStream));
|
||||
break;
|
||||
}
|
||||
default:
|
||||
SkASSERT(false);
|
||||
}
|
||||
this->insertObjRef("FontDescriptor", descriptor.release());
|
||||
this->insertObjRef("FontDescriptor", std::move(descriptor));
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -1147,7 +1145,7 @@ bool SkPDFCIDFont::populate(const SkPDFGlyphSet* subset) {
|
||||
sysInfo->insertString("Registry", "Adobe");
|
||||
sysInfo->insertString("Ordering", "Identity");
|
||||
sysInfo->insertInt("Supplement", 0);
|
||||
this->insertObject("CIDSystemInfo", sysInfo.release());
|
||||
this->insertObject("CIDSystemInfo", std::move(sysInfo));
|
||||
|
||||
if (fontInfo()->fGlyphWidths.get()) {
|
||||
int16_t defaultWidth = 0;
|
||||
@ -1156,7 +1154,7 @@ bool SkPDFCIDFont::populate(const SkPDFGlyphSet* subset) {
|
||||
fontInfo()->fEmSize, &appendWidth,
|
||||
&defaultWidth));
|
||||
if (widths->size())
|
||||
this->insertObject("W", widths.release());
|
||||
this->insertObject("W", std::move(widths));
|
||||
if (defaultWidth != 0) {
|
||||
this->insertScalar(
|
||||
"DW",
|
||||
@ -1173,14 +1171,15 @@ bool SkPDFCIDFont::populate(const SkPDFGlyphSet* subset) {
|
||||
fontInfo()->fEmSize, &appendVerticalAdvance,
|
||||
&defaultAdvance));
|
||||
if (advances->size())
|
||||
this->insertObject("W2", advances.release());
|
||||
this->insertObject("W2", std::move(advances));
|
||||
if (defaultAdvance.fVerticalAdvance ||
|
||||
defaultAdvance.fOriginXDisp ||
|
||||
defaultAdvance.fOriginYDisp) {
|
||||
this->insertObject("DW2",
|
||||
appendVerticalAdvance(defaultAdvance,
|
||||
fontInfo()->fEmSize,
|
||||
new SkPDFArray));
|
||||
auto array = sk_make_sp<SkPDFArray>();
|
||||
appendVerticalAdvance(defaultAdvance,
|
||||
fontInfo()->fEmSize,
|
||||
array.get());
|
||||
this->insertObject("DW2", std::move(array));
|
||||
}
|
||||
}
|
||||
|
||||
@ -1203,7 +1202,8 @@ SkPDFType1Font::~SkPDFType1Font() {}
|
||||
|
||||
bool SkPDFType1Font::addFontDescriptor(int16_t defaultWidth) {
|
||||
if (SkPDFDict* descriptor = getFontDescriptor()) {
|
||||
this->insertObjRef("FontDescriptor", SkRef(descriptor));
|
||||
this->insertObjRef("FontDescriptor",
|
||||
sk_sp<SkPDFDict>(SkRef(descriptor)));
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -1225,9 +1225,9 @@ bool SkPDFType1Font::addFontDescriptor(int16_t defaultWidth) {
|
||||
fontStream->insertInt("Length1", header);
|
||||
fontStream->insertInt("Length2", data);
|
||||
fontStream->insertInt("Length3", trailer);
|
||||
descriptor->insertObjRef("FontFile", fontStream.release());
|
||||
descriptor->insertObjRef("FontFile", std::move(fontStream));
|
||||
|
||||
this->insertObjRef("FontDescriptor", descriptor.release());
|
||||
this->insertObjRef("FontDescriptor", std::move(descriptor));
|
||||
|
||||
return addCommonFontDescriptorEntries(defaultWidth);
|
||||
}
|
||||
@ -1276,8 +1276,8 @@ bool SkPDFType1Font::populate(int16_t glyphID) {
|
||||
}
|
||||
|
||||
auto encoding = sk_make_sp<SkPDFDict>("Encoding");
|
||||
encoding->insertObject("Differences", encDiffs.release());
|
||||
this->insertObject("Encoding", encoding.release());
|
||||
encoding->insertObject("Differences", std::move(encDiffs));
|
||||
this->insertObject("Encoding", std::move(encoding));
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -1307,7 +1307,7 @@ void SkPDFType1Font::addWidthInfoFromRange(
|
||||
}
|
||||
this->insertInt("FirstChar", firstChar);
|
||||
this->insertInt("LastChar", firstChar + widthArray->size() - 1);
|
||||
this->insertObject("Widths", widthArray.release());
|
||||
this->insertObject("Widths", std::move(widthArray));
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
@ -1376,19 +1376,19 @@ bool SkPDFType3Font::populate(uint16_t glyphID) {
|
||||
SkAutoTDelete<SkMemoryStream> glyphStream(new SkMemoryStream());
|
||||
glyphStream->setData(content.copyToData())->unref();
|
||||
|
||||
charProcs->insertObjRef(characterName,
|
||||
new SkPDFStream(glyphStream.get()));
|
||||
charProcs->insertObjRef(
|
||||
characterName, sk_make_sp<SkPDFStream>(glyphStream.get()));
|
||||
}
|
||||
|
||||
encoding->insertObject("Differences", encDiffs.release());
|
||||
encoding->insertObject("Differences", std::move(encDiffs));
|
||||
|
||||
this->insertObject("CharProcs", charProcs.release());
|
||||
this->insertObject("Encoding", encoding.release());
|
||||
this->insertObject("CharProcs", std::move(charProcs));
|
||||
this->insertObject("Encoding", std::move(encoding));
|
||||
|
||||
this->insertObject("FontBBox", makeFontBBox(bbox, 1000));
|
||||
this->insertInt("FirstChar", 1);
|
||||
this->insertInt("LastChar", lastGlyphID() - firstGlyphID() + 1);
|
||||
this->insertObject("Widths", widthArray.release());
|
||||
this->insertObject("Widths", std::move(widthArray));
|
||||
this->insertName("CIDToGIDMap", "Identity");
|
||||
|
||||
this->populateToUnicodeTable(nullptr);
|
||||
|
@ -19,9 +19,9 @@ 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).
|
||||
sk_sp<SkPDFDict> resourceDict(device->createResourceDict());
|
||||
auto resourceDict = device->makeResourceDict();
|
||||
|
||||
SkAutoTDelete<SkStreamAsset> content(device->content());
|
||||
auto content = device->content();
|
||||
this->setData(content.get());
|
||||
|
||||
sk_sp<SkPDFArray> bboxArray(device->copyMediaBox());
|
||||
@ -60,8 +60,8 @@ void SkPDFFormXObject::init(const char* colorSpace,
|
||||
SkPDFDict* resourceDict, SkPDFArray* bbox) {
|
||||
this->insertName("Type", "XObject");
|
||||
this->insertName("Subtype", "Form");
|
||||
this->insertObject("Resources", SkRef(resourceDict));
|
||||
this->insertObject("BBox", SkRef(bbox));
|
||||
this->insertObject("Resources", sk_sp<SkPDFDict>(SkRef(resourceDict)));
|
||||
this->insertObject("BBox", sk_sp<SkPDFArray>(SkRef(bbox)));
|
||||
|
||||
// Right now SkPDFFormXObject is only used for saveLayer, which implies
|
||||
// isolated blending. Do this conditionally if that changes.
|
||||
@ -72,7 +72,7 @@ void SkPDFFormXObject::init(const char* colorSpace,
|
||||
group->insertName("CS", colorSpace);
|
||||
}
|
||||
group->insertBool("I", true); // Isolated.
|
||||
this->insertObject("Group", group.release());
|
||||
this->insertObject("Group", std::move(group));
|
||||
}
|
||||
|
||||
SkPDFFormXObject::~SkPDFFormXObject() {}
|
||||
|
@ -126,7 +126,7 @@ SkPDFGraphicState* SkPDFGraphicState::GetGraphicStateForPaint(
|
||||
return pdfGraphicState;
|
||||
}
|
||||
|
||||
static SkPDFObject* create_invert_function() {
|
||||
static SkPDFStream* 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.
|
||||
auto domainAndRange = sk_make_sp<SkPDFArray>();
|
||||
@ -141,12 +141,17 @@ static SkPDFObject* create_invert_function() {
|
||||
|
||||
auto invertFunction = sk_make_sp<SkPDFStream>(psInvertStream.get());
|
||||
invertFunction->insertInt("FunctionType", 4);
|
||||
invertFunction->insertObject("Domain", SkRef(domainAndRange.get()));
|
||||
invertFunction->insertObject("Range", domainAndRange.release());
|
||||
invertFunction->insertObject("Domain", domainAndRange);
|
||||
invertFunction->insertObject("Range", std::move(domainAndRange));
|
||||
return invertFunction.release();
|
||||
}
|
||||
|
||||
SK_DECLARE_STATIC_ONCE_PTR(SkPDFObject, invertFunction);
|
||||
SK_DECLARE_STATIC_ONCE_PTR(SkPDFStream, invertFunction);
|
||||
|
||||
static sk_sp<SkPDFStream> make_invert_function() {
|
||||
return sk_sp<SkPDFStream>(
|
||||
SkRef(invertFunction.get(create_invert_function)));
|
||||
}
|
||||
|
||||
// static
|
||||
SkPDFDict* SkPDFGraphicState::GetSMaskGraphicState(SkPDFFormXObject* sMask,
|
||||
@ -160,13 +165,13 @@ SkPDFDict* SkPDFGraphicState::GetSMaskGraphicState(SkPDFFormXObject* sMask,
|
||||
} else if (sMaskMode == kLuminosity_SMaskMode) {
|
||||
sMaskDict->insertName("S", "Luminosity");
|
||||
}
|
||||
sMaskDict->insertObjRef("G", SkRef(sMask));
|
||||
sMaskDict->insertObjRef("G", sk_sp<SkPDFFormXObject>(SkRef(sMask)));
|
||||
if (invert) {
|
||||
sMaskDict->insertObjRef("TR", SkRef(invertFunction.get(create_invert_function)));
|
||||
sMaskDict->insertObjRef("TR", make_invert_function());
|
||||
}
|
||||
|
||||
auto result = sk_make_sp<SkPDFDict>("ExtGState");
|
||||
result->insertObject("SMask", sMaskDict.release());
|
||||
result->insertObject("SMask", std::move(sMaskDict));
|
||||
return result.release();
|
||||
}
|
||||
|
||||
|
@ -64,12 +64,12 @@ static void add_subdict(
|
||||
auto resources = sk_make_sp<SkPDFDict>();
|
||||
for (int i = 0; i < resourceList.count(); i++) {
|
||||
resources->insertObjRef(SkPDFResourceDict::getResourceName(type, i),
|
||||
SkRef(resourceList[i]));
|
||||
sk_sp<SkPDFObject>(SkRef(resourceList[i])));
|
||||
}
|
||||
dst->insertObject(get_resource_type_name(type), resources.release());
|
||||
dst->insertObject(get_resource_type_name(type), std::move(resources));
|
||||
}
|
||||
|
||||
SkPDFDict* SkPDFResourceDict::Create(
|
||||
sk_sp<SkPDFDict> SkPDFResourceDict::Make(
|
||||
const SkTDArray<SkPDFObject*>* gStateResources,
|
||||
const SkTDArray<SkPDFObject*>* patternResources,
|
||||
const SkTDArray<SkPDFObject*>* xObjectResources,
|
||||
@ -83,7 +83,7 @@ SkPDFDict* SkPDFResourceDict::Create(
|
||||
for (size_t i = 0; i < SK_ARRAY_COUNT(kProcs); i++) {
|
||||
procSets->appendName(kProcs[i]);
|
||||
}
|
||||
dict->insertObject("ProcSets", procSets.release());
|
||||
dict->insertObject("ProcSets", std::move(procSets));
|
||||
|
||||
if (gStateResources) {
|
||||
add_subdict(*gStateResources, kExtGState_ResourceType, dict.get());
|
||||
@ -97,5 +97,5 @@ SkPDFDict* SkPDFResourceDict::Create(
|
||||
if (fontResources) {
|
||||
add_subdict(*fontResources, kFont_ResourceType, dict.get());
|
||||
}
|
||||
return dict.release();
|
||||
return std::move(dict);
|
||||
}
|
||||
|
@ -36,7 +36,7 @@ public:
|
||||
*
|
||||
* Any arguments can be nullptr.
|
||||
*/
|
||||
static SkPDFDict* Create(
|
||||
static sk_sp<SkPDFDict> Make(
|
||||
const SkTDArray<SkPDFObject*>* gStateResources,
|
||||
const SkTDArray<SkPDFObject*>* patternResources,
|
||||
const SkTDArray<SkPDFObject*>* xObjectResources,
|
||||
|
@ -523,7 +523,7 @@ SkPDFObject* SkPDFShader::GetPDFShader(SkPDFCanon* canon,
|
||||
return get_pdf_shader_by_state(canon, dpi, &state);
|
||||
}
|
||||
|
||||
static SkPDFDict* get_gradient_resource_dict(
|
||||
static sk_sp<SkPDFDict> get_gradient_resource_dict(
|
||||
SkPDFObject* functionShader,
|
||||
SkPDFObject* gState) {
|
||||
SkTDArray<SkPDFObject*> patterns;
|
||||
@ -534,7 +534,7 @@ static SkPDFDict* get_gradient_resource_dict(
|
||||
if (gState) {
|
||||
graphicStates.push(gState);
|
||||
}
|
||||
return SkPDFResourceDict::Create(&graphicStates, &patterns, nullptr, nullptr);
|
||||
return SkPDFResourceDict::Make(&graphicStates, &patterns, nullptr, nullptr);
|
||||
}
|
||||
|
||||
static void populate_tiling_pattern_dict(SkPDFDict* pattern,
|
||||
@ -552,7 +552,7 @@ static void populate_tiling_pattern_dict(SkPDFDict* pattern,
|
||||
pattern->insertObject("BBox", SkPDFUtils::RectToArray(bbox));
|
||||
pattern->insertScalar("XStep", bbox.width());
|
||||
pattern->insertScalar("YStep", bbox.height());
|
||||
pattern->insertObject("Resources", SkRef(resources));
|
||||
pattern->insertObject("Resources", sk_sp<SkPDFDict>(SkRef(resources)));
|
||||
if (!matrix.isIdentity()) {
|
||||
pattern->insertObject("Matrix", SkPDFUtils::MatrixToArray(matrix));
|
||||
}
|
||||
@ -592,8 +592,8 @@ static SkPDFObject* create_smask_graphic_state(
|
||||
|
||||
SkAutoTDelete<SkStream> alphaStream(create_pattern_fill_content(-1, bbox));
|
||||
|
||||
sk_sp<SkPDFDict>
|
||||
resources(get_gradient_resource_dict(luminosityShader.get(), nullptr));
|
||||
auto resources =
|
||||
get_gradient_resource_dict(luminosityShader.get(), nullptr);
|
||||
|
||||
sk_sp<SkPDFFormXObject> alphaMask(
|
||||
new SkPDFFormXObject(alphaStream.get(), bbox, resources.get()));
|
||||
@ -627,8 +627,8 @@ SkPDFAlphaFunctionShader* SkPDFAlphaFunctionShader::Create(
|
||||
SkPDFAlphaFunctionShader* alphaFunctionShader =
|
||||
new SkPDFAlphaFunctionShader(autoState->detach());
|
||||
|
||||
sk_sp<SkPDFDict> resourceDict(
|
||||
get_gradient_resource_dict(colorShader.get(), alphaGs.get()));
|
||||
auto resourceDict =
|
||||
get_gradient_resource_dict(colorShader.get(), alphaGs.get());
|
||||
|
||||
SkAutoTDelete<SkStream> colorStream(
|
||||
create_pattern_fill_content(0, bbox));
|
||||
@ -697,8 +697,8 @@ static SkPDFStream* make_ps_function(const SkString& psCode,
|
||||
SkData::NewWithCopy(psCode.c_str(), psCode.size()));
|
||||
SkPDFStream* result = new SkPDFStream(funcData.get());
|
||||
result->insertInt("FunctionType", 4);
|
||||
result->insertObject("Domain", SkRef(domain));
|
||||
result->insertObject("Range", SkRef(rangeObject.get(create_range_object)));
|
||||
result->insertObject("Domain", sk_sp<SkPDFObject>(SkRef(domain)));
|
||||
result->insertObject("Range", sk_sp<SkPDFObject>(SkRef(rangeObject.get(create_range_object))));
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -802,18 +802,18 @@ SkPDFFunctionShader* SkPDFFunctionShader::Create(
|
||||
auto pdfShader = sk_make_sp<SkPDFDict>();
|
||||
pdfShader->insertInt("ShadingType", 1);
|
||||
pdfShader->insertName("ColorSpace", "DeviceRGB");
|
||||
pdfShader->insertObject("Domain", SkRef(domain.get()));
|
||||
pdfShader->insertObject("Domain", sk_sp<SkPDFObject>(SkRef(domain.get())));
|
||||
|
||||
sk_sp<SkPDFStream> function(
|
||||
make_ps_function(functionCode, domain.get()));
|
||||
pdfShader->insertObjRef("Function", function.release());
|
||||
pdfShader->insertObjRef("Function", std::move(function));
|
||||
|
||||
sk_sp<SkPDFFunctionShader> pdfFunctionShader(
|
||||
new SkPDFFunctionShader(autoState->detach()));
|
||||
pdfFunctionShader->insertInt("PatternType", 2);
|
||||
pdfFunctionShader->insertObject("Matrix",
|
||||
SkPDFUtils::MatrixToArray(finalMatrix));
|
||||
pdfFunctionShader->insertObject("Shading", pdfShader.release());
|
||||
pdfFunctionShader->insertObject("Shading", std::move(pdfShader));
|
||||
|
||||
canon->addFunctionShader(pdfFunctionShader.get());
|
||||
return pdfFunctionShader.release();
|
||||
@ -1019,13 +1019,12 @@ SkPDFImageShader* SkPDFImageShader::Create(
|
||||
}
|
||||
|
||||
// Put the canvas into the pattern stream (fContent).
|
||||
SkAutoTDelete<SkStreamAsset> content(patternDevice->content());
|
||||
auto content = patternDevice->content();
|
||||
|
||||
SkPDFImageShader* imageShader = new SkPDFImageShader(autoState->detach());
|
||||
imageShader->setData(content.get());
|
||||
|
||||
sk_sp<SkPDFDict> resourceDict(
|
||||
patternDevice->createResourceDict());
|
||||
auto resourceDict = patternDevice->makeResourceDict();
|
||||
populate_tiling_pattern_dict(imageShader, patternBBox,
|
||||
resourceDict.get(), finalMatrix);
|
||||
|
||||
|
@ -1,4 +1,3 @@
|
||||
|
||||
/*
|
||||
* Copyright 2011 Google Inc.
|
||||
*
|
||||
@ -28,7 +27,8 @@ SkPDFUnion::~SkPDFUnion() {
|
||||
return;
|
||||
case Type::kObjRef:
|
||||
case Type::kObject:
|
||||
SkSafeUnref(fObject);
|
||||
SkASSERT(fObject);
|
||||
fObject->unref();
|
||||
return;
|
||||
default:
|
||||
return;
|
||||
@ -38,7 +38,7 @@ SkPDFUnion::~SkPDFUnion() {
|
||||
SkPDFUnion& SkPDFUnion::operator=(SkPDFUnion&& other) {
|
||||
if (this != &other) {
|
||||
this->~SkPDFUnion();
|
||||
new (this) SkPDFUnion(other.move());
|
||||
new (this) SkPDFUnion(std::move(other));
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
@ -56,14 +56,14 @@ SkPDFUnion SkPDFUnion::copy() const {
|
||||
switch (fType) {
|
||||
case Type::kNameSkS:
|
||||
case Type::kStringSkS:
|
||||
new (pun(u.fSkString)) SkString (*pun(fSkString));
|
||||
return u.move();
|
||||
new (pun(u.fSkString)) SkString(*pun(fSkString));
|
||||
return std::move(u);
|
||||
case Type::kObjRef:
|
||||
case Type::kObject:
|
||||
SkRef(u.fObject);
|
||||
return u.move();
|
||||
return std::move(u);
|
||||
default:
|
||||
return u.move();
|
||||
return std::move(u);
|
||||
}
|
||||
}
|
||||
SkPDFUnion& SkPDFUnion::operator=(const SkPDFUnion& other) {
|
||||
@ -191,19 +191,19 @@ void SkPDFUnion::addResources(SkPDFObjNumMap* objNumMap,
|
||||
SkPDFUnion SkPDFUnion::Int(int32_t value) {
|
||||
SkPDFUnion u(Type::kInt);
|
||||
u.fIntValue = value;
|
||||
return u.move();
|
||||
return std::move(u);
|
||||
}
|
||||
|
||||
SkPDFUnion SkPDFUnion::Bool(bool value) {
|
||||
SkPDFUnion u(Type::kBool);
|
||||
u.fBoolValue = value;
|
||||
return u.move();
|
||||
return std::move(u);
|
||||
}
|
||||
|
||||
SkPDFUnion SkPDFUnion::Scalar(SkScalar value) {
|
||||
SkPDFUnion u(Type::kScalar);
|
||||
u.fScalarValue = value;
|
||||
return u.move();
|
||||
return std::move(u);
|
||||
}
|
||||
|
||||
SkPDFUnion SkPDFUnion::Name(const char* value) {
|
||||
@ -211,40 +211,40 @@ SkPDFUnion SkPDFUnion::Name(const char* value) {
|
||||
SkASSERT(value);
|
||||
SkASSERT(is_valid_name(value));
|
||||
u.fStaticString = value;
|
||||
return u.move();
|
||||
return std::move(u);
|
||||
}
|
||||
|
||||
SkPDFUnion SkPDFUnion::String(const char* value) {
|
||||
SkPDFUnion u(Type::kString);
|
||||
SkASSERT(value);
|
||||
u.fStaticString = value;
|
||||
return u.move();
|
||||
return std::move(u);
|
||||
}
|
||||
|
||||
SkPDFUnion SkPDFUnion::Name(const SkString& s) {
|
||||
SkPDFUnion u(Type::kNameSkS);
|
||||
new (pun(u.fSkString)) SkString(s);
|
||||
return u.move();
|
||||
return std::move(u);
|
||||
}
|
||||
|
||||
SkPDFUnion SkPDFUnion::String(const SkString& s) {
|
||||
SkPDFUnion u(Type::kStringSkS);
|
||||
new (pun(u.fSkString)) SkString(s);
|
||||
return u.move();
|
||||
return std::move(u);
|
||||
}
|
||||
|
||||
SkPDFUnion SkPDFUnion::ObjRef(SkPDFObject* ptr) {
|
||||
SkPDFUnion SkPDFUnion::ObjRef(sk_sp<SkPDFObject> objSp) {
|
||||
SkPDFUnion u(Type::kObjRef);
|
||||
SkASSERT(ptr);
|
||||
u.fObject = ptr;
|
||||
return u.move();
|
||||
SkASSERT(objSp.get());
|
||||
u.fObject = objSp.release(); // take ownership into union{}
|
||||
return std::move(u);
|
||||
}
|
||||
|
||||
SkPDFUnion SkPDFUnion::Object(SkPDFObject* ptr) {
|
||||
SkPDFUnion SkPDFUnion::Object(sk_sp<SkPDFObject> objSp) {
|
||||
SkPDFUnion u(Type::kObject);
|
||||
SkASSERT(ptr);
|
||||
u.fObject = ptr;
|
||||
return u.move();
|
||||
SkASSERT(objSp.get());
|
||||
u.fObject = objSp.release(); // take ownership into union{}
|
||||
return std::move(u);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
@ -295,7 +295,9 @@ void SkPDFArray::addResources(SkPDFObjNumMap* catalog,
|
||||
}
|
||||
}
|
||||
|
||||
void SkPDFArray::append(SkPDFUnion&& value) { new (fValues.append()) SkPDFUnion(value.move()); }
|
||||
void SkPDFArray::append(SkPDFUnion&& value) {
|
||||
new (fValues.append()) SkPDFUnion(std::move(value));
|
||||
}
|
||||
|
||||
void SkPDFArray::appendInt(int32_t value) {
|
||||
this->append(SkPDFUnion::Int(value));
|
||||
@ -325,12 +327,12 @@ void SkPDFArray::appendString(const char value[]) {
|
||||
this->append(SkPDFUnion::String(value));
|
||||
}
|
||||
|
||||
void SkPDFArray::appendObject(SkPDFObject* value) {
|
||||
this->append(SkPDFUnion::Object(value));
|
||||
void SkPDFArray::appendObject(sk_sp<SkPDFObject> objSp) {
|
||||
this->append(SkPDFUnion::Object(std::move(objSp)));
|
||||
}
|
||||
|
||||
void SkPDFArray::appendObjRef(SkPDFObject* value) {
|
||||
this->append(SkPDFUnion::ObjRef(value));
|
||||
void SkPDFArray::appendObjRef(sk_sp<SkPDFObject> objSp) {
|
||||
this->append(SkPDFUnion::ObjRef(std::move(objSp)));
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
@ -373,24 +375,24 @@ void SkPDFDict::addResources(SkPDFObjNumMap* catalog,
|
||||
void SkPDFDict::set(SkPDFUnion&& name, SkPDFUnion&& value) {
|
||||
Record* rec = fRecords.append();
|
||||
SkASSERT(name.isName());
|
||||
new (&rec->fKey) SkPDFUnion(name.move());
|
||||
new (&rec->fValue) SkPDFUnion(value.move());
|
||||
new (&rec->fKey) SkPDFUnion(std::move(name));
|
||||
new (&rec->fValue) SkPDFUnion(std::move(value));
|
||||
}
|
||||
|
||||
int SkPDFDict::size() const { return fRecords.count(); }
|
||||
|
||||
void SkPDFDict::insertObjRef(const char key[], SkPDFObject* value) {
|
||||
this->set(SkPDFUnion::Name(key), SkPDFUnion::ObjRef(value));
|
||||
void SkPDFDict::insertObjRef(const char key[], sk_sp<SkPDFObject> objSp) {
|
||||
this->set(SkPDFUnion::Name(key), SkPDFUnion::ObjRef(std::move(objSp)));
|
||||
}
|
||||
void SkPDFDict::insertObjRef(const SkString& key, SkPDFObject* value) {
|
||||
this->set(SkPDFUnion::Name(key), SkPDFUnion::ObjRef(value));
|
||||
void SkPDFDict::insertObjRef(const SkString& key, sk_sp<SkPDFObject> objSp) {
|
||||
this->set(SkPDFUnion::Name(key), SkPDFUnion::ObjRef(std::move(objSp)));
|
||||
}
|
||||
|
||||
void SkPDFDict::insertObject(const char key[], SkPDFObject* value) {
|
||||
this->set(SkPDFUnion::Name(key), SkPDFUnion::Object(value));
|
||||
void SkPDFDict::insertObject(const char key[], sk_sp<SkPDFObject> objSp) {
|
||||
this->set(SkPDFUnion::Name(key), SkPDFUnion::Object(std::move(objSp)));
|
||||
}
|
||||
void SkPDFDict::insertObject(const SkString& key, SkPDFObject* value) {
|
||||
this->set(SkPDFUnion::Name(key), SkPDFUnion::Object(value));
|
||||
void SkPDFDict::insertObject(const SkString& key, sk_sp<SkPDFObject> objSp) {
|
||||
this->set(SkPDFUnion::Name(key), SkPDFUnion::Object(std::move(objSp)));
|
||||
}
|
||||
|
||||
void SkPDFDict::insertBool(const char key[], bool value) {
|
||||
|
@ -39,7 +39,6 @@ public:
|
||||
* @param catalog The object catalog to use.
|
||||
* @param stream The writable output stream to send the output to.
|
||||
*/
|
||||
// TODO(halcanary): make this method const
|
||||
virtual void emitObject(SkWStream* stream,
|
||||
const SkPDFObjNumMap& objNumMap,
|
||||
const SkPDFSubstituteMap& substitutes) const = 0;
|
||||
@ -65,8 +64,6 @@ private:
|
||||
*/
|
||||
class SkPDFUnion {
|
||||
public:
|
||||
// u.move() is analogous to std::move(u). It returns an rvalue.
|
||||
SkPDFUnion move() { return static_cast<SkPDFUnion&&>(*this); }
|
||||
// Move contstructor and assignemnt operator destroy the argument
|
||||
// and steal their references (if needed).
|
||||
SkPDFUnion(SkPDFUnion&& other);
|
||||
@ -85,7 +82,7 @@ public:
|
||||
|
||||
static SkPDFUnion Scalar(SkScalar);
|
||||
|
||||
/** These two functions do NOT take ownership of ptr, and do NOT
|
||||
/** These two functions do NOT take ownership of char*, and do NOT
|
||||
copy the string. Suitable for passing in static const
|
||||
strings. For example:
|
||||
SkPDFUnion n = SkPDFUnion::Name("Length");
|
||||
@ -108,17 +105,8 @@ public:
|
||||
/** SkPDFUnion::String will encode the passed string. */
|
||||
static SkPDFUnion String(const SkString&);
|
||||
|
||||
/** This function DOES take ownership of the object. E.g.
|
||||
auto dict = sk_make_sp<SkPDFDict>();
|
||||
dict->insert(.....);
|
||||
SkPDFUnion u = SkPDFUnion::Object(dict.detach()) */
|
||||
static SkPDFUnion Object(SkPDFObject*);
|
||||
|
||||
/** This function DOES take ownership of the object. E.g.
|
||||
sk_sp<SkPDFBitmap> image(
|
||||
SkPDFBitmap::Create(fCanon, bitmap));
|
||||
SkPDFUnion u = SkPDFUnion::ObjRef(image.detach()) */
|
||||
static SkPDFUnion ObjRef(SkPDFObject*);
|
||||
static SkPDFUnion Object(sk_sp<SkPDFObject>);
|
||||
static SkPDFUnion ObjRef(sk_sp<SkPDFObject>);
|
||||
|
||||
/** These two non-virtual methods mirror SkPDFObject's
|
||||
corresponding virtuals. */
|
||||
@ -174,7 +162,7 @@ public:
|
||||
const SkPDFObjNumMap& objNumMap,
|
||||
const SkPDFSubstituteMap& substitutes) final;
|
||||
void addResources(SkPDFObjNumMap*, const SkPDFSubstituteMap&) const final;
|
||||
SkPDFAtom(SkPDFUnion&& v) : fValue(v.move()) {}
|
||||
SkPDFAtom(SkPDFUnion&& v) : fValue(std::move(v) {}
|
||||
|
||||
private:
|
||||
const SkPDFUnion fValue;
|
||||
@ -223,9 +211,8 @@ public:
|
||||
void appendName(const SkString&);
|
||||
void appendString(const char[]);
|
||||
void appendString(const SkString&);
|
||||
/** appendObject and appendObjRef take ownership of the passed object */
|
||||
void appendObject(SkPDFObject*);
|
||||
void appendObjRef(SkPDFObject*);
|
||||
void appendObject(sk_sp<SkPDFObject>);
|
||||
void appendObjRef(sk_sp<SkPDFObject>);
|
||||
|
||||
private:
|
||||
SkTDArray<SkPDFUnion> fValues;
|
||||
@ -261,15 +248,14 @@ public:
|
||||
*/
|
||||
int size() const;
|
||||
|
||||
/** Add the value to the dictionary with the given key. Takes
|
||||
* ownership of the object.
|
||||
/** Add the value to the dictionary with the given key.
|
||||
* @param key The text of the key for this dictionary entry.
|
||||
* @param value The value for this dictionary entry.
|
||||
*/
|
||||
void insertObject(const char key[], SkPDFObject* value);
|
||||
void insertObject(const SkString& key, SkPDFObject* value);
|
||||
void insertObjRef(const char key[], SkPDFObject* value);
|
||||
void insertObjRef(const SkString& key, SkPDFObject* value);
|
||||
void insertObject(const char key[], sk_sp<SkPDFObject>);
|
||||
void insertObject(const SkString& key, sk_sp<SkPDFObject>);
|
||||
void insertObjRef(const char key[], sk_sp<SkPDFObject>);
|
||||
void insertObjRef(const SkString& key, sk_sp<SkPDFObject>);
|
||||
|
||||
/** Add the value to the dictionary with the given key.
|
||||
* @param key The text of the key for this dictionary entry.
|
||||
@ -317,7 +303,8 @@ private:
|
||||
class SkPDFSharedStream final : public SkPDFObject {
|
||||
public:
|
||||
// Takes ownership of asset.
|
||||
SkPDFSharedStream(SkStreamAsset* data) : fAsset(data), fDict(new SkPDFDict) { SkASSERT(data); }
|
||||
SkPDFSharedStream(SkStreamAsset* data)
|
||||
: fAsset(data), fDict(new SkPDFDict) { SkASSERT(data); }
|
||||
SkPDFDict* dict() { return fDict.get(); }
|
||||
void emitObject(SkWStream*,
|
||||
const SkPDFObjNumMap&,
|
||||
|
@ -18,9 +18,8 @@
|
||||
|
||||
#include <cmath>
|
||||
|
||||
//static
|
||||
SkPDFArray* SkPDFUtils::RectToArray(const SkRect& rect) {
|
||||
SkPDFArray* result = new SkPDFArray();
|
||||
sk_sp<SkPDFArray> SkPDFUtils::RectToArray(const SkRect& rect) {
|
||||
auto result = sk_make_sp<SkPDFArray>();
|
||||
result->reserve(4);
|
||||
result->appendScalar(rect.fLeft);
|
||||
result->appendScalar(rect.fTop);
|
||||
@ -29,14 +28,13 @@ SkPDFArray* SkPDFUtils::RectToArray(const SkRect& rect) {
|
||||
return result;
|
||||
}
|
||||
|
||||
// static
|
||||
SkPDFArray* SkPDFUtils::MatrixToArray(const SkMatrix& matrix) {
|
||||
sk_sp<SkPDFArray> SkPDFUtils::MatrixToArray(const SkMatrix& matrix) {
|
||||
SkScalar values[6];
|
||||
if (!matrix.asAffine(values)) {
|
||||
SkMatrix::SetAffineIdentity(values);
|
||||
}
|
||||
|
||||
SkPDFArray* result = new SkPDFArray;
|
||||
auto result = sk_make_sp<SkPDFArray>();
|
||||
result->reserve(6);
|
||||
for (size_t i = 0; i < SK_ARRAY_COUNT(values); i++) {
|
||||
result->appendScalar(values[i]);
|
||||
|
@ -35,8 +35,8 @@ class SkWStream;
|
||||
|
||||
class SkPDFUtils {
|
||||
public:
|
||||
static SkPDFArray* RectToArray(const SkRect& rect);
|
||||
static SkPDFArray* MatrixToArray(const SkMatrix& matrix);
|
||||
static sk_sp<SkPDFArray> RectToArray(const SkRect& rect);
|
||||
static sk_sp<SkPDFArray> MatrixToArray(const SkMatrix& matrix);
|
||||
static void AppendTransform(const SkMatrix& matrix, SkWStream* content);
|
||||
|
||||
static void MoveTo(SkScalar x, SkScalar y, SkWStream* content);
|
||||
|
@ -83,7 +83,7 @@ static void TestPDFStream(skiatest::Reporter* reporter) {
|
||||
char streamBytes[] = "Test\nFoo\tBar";
|
||||
SkAutoTDelete<SkMemoryStream> streamData(new SkMemoryStream(
|
||||
streamBytes, strlen(streamBytes), true));
|
||||
SkAutoTUnref<SkPDFStream> stream(new SkPDFStream(streamData.get()));
|
||||
sk_sp<SkPDFStream> stream(new SkPDFStream(streamData.get()));
|
||||
ASSERT_EMIT_EQ(reporter,
|
||||
*stream,
|
||||
"<</Length 12>> stream\nTest\nFoo\tBar\nendstream");
|
||||
@ -100,7 +100,7 @@ static void TestPDFStream(skiatest::Reporter* reporter) {
|
||||
"with an uncompressed string.";
|
||||
SkAutoDataUnref streamData2(SkData::NewWithCopy(streamBytes2,
|
||||
strlen(streamBytes2)));
|
||||
SkAutoTUnref<SkPDFStream> stream(new SkPDFStream(streamData2.get()));
|
||||
sk_sp<SkPDFStream> stream(new SkPDFStream(streamData2.get()));
|
||||
|
||||
SkDynamicMemoryWStream compressedByteStream;
|
||||
SkDeflateWStream deflateWStream(&compressedByteStream);
|
||||
@ -123,9 +123,9 @@ static void TestPDFStream(skiatest::Reporter* reporter) {
|
||||
|
||||
static void TestObjectNumberMap(skiatest::Reporter* reporter) {
|
||||
SkPDFObjNumMap objNumMap;
|
||||
SkAutoTUnref<SkPDFArray> a1(new SkPDFArray);
|
||||
SkAutoTUnref<SkPDFArray> a2(new SkPDFArray);
|
||||
SkAutoTUnref<SkPDFArray> a3(new SkPDFArray);
|
||||
sk_sp<SkPDFArray> a1(new SkPDFArray);
|
||||
sk_sp<SkPDFArray> a2(new SkPDFArray);
|
||||
sk_sp<SkPDFArray> a3(new SkPDFArray);
|
||||
|
||||
objNumMap.addObject(a1.get());
|
||||
objNumMap.addObject(a2.get());
|
||||
@ -142,9 +142,9 @@ static void TestObjectNumberMap(skiatest::Reporter* reporter) {
|
||||
}
|
||||
|
||||
static void TestObjectRef(skiatest::Reporter* reporter) {
|
||||
SkAutoTUnref<SkPDFArray> a1(new SkPDFArray);
|
||||
SkAutoTUnref<SkPDFArray> a2(new SkPDFArray);
|
||||
a2->appendObjRef(SkRef(a1.get()));
|
||||
sk_sp<SkPDFArray> a1(new SkPDFArray);
|
||||
sk_sp<SkPDFArray> a2(new SkPDFArray);
|
||||
a2->appendObjRef(a1);
|
||||
|
||||
Catalog catalog;
|
||||
catalog.numbers.addObject(a1.get());
|
||||
@ -157,8 +157,8 @@ static void TestObjectRef(skiatest::Reporter* reporter) {
|
||||
}
|
||||
|
||||
static void TestSubstitute(skiatest::Reporter* reporter) {
|
||||
SkAutoTUnref<SkPDFDict> proxy(new SkPDFDict());
|
||||
SkAutoTUnref<SkPDFDict> stub(new SkPDFDict());
|
||||
sk_sp<SkPDFDict> proxy(new SkPDFDict());
|
||||
sk_sp<SkPDFDict> stub(new SkPDFDict());
|
||||
|
||||
proxy->insertInt("Value", 33);
|
||||
stub->insertInt("Value", 44);
|
||||
@ -168,8 +168,8 @@ static void TestSubstitute(skiatest::Reporter* reporter) {
|
||||
SkPDFObjNumMap catalog;
|
||||
catalog.addObject(proxy.get());
|
||||
|
||||
REPORTER_ASSERT(reporter, stub.get() == substituteMap.getSubstitute(proxy));
|
||||
REPORTER_ASSERT(reporter, proxy.get() != substituteMap.getSubstitute(stub));
|
||||
REPORTER_ASSERT(reporter, stub.get() == substituteMap.getSubstitute(proxy.get()));
|
||||
REPORTER_ASSERT(reporter, proxy.get() != substituteMap.getSubstitute(stub.get()));
|
||||
}
|
||||
|
||||
// This test used to assert without the fix submitted for
|
||||
@ -178,7 +178,7 @@ static void TestSubstitute(skiatest::Reporter* reporter) {
|
||||
// and there is no assert on input data in Debug mode.
|
||||
static void test_issue1083() {
|
||||
SkDynamicMemoryWStream outStream;
|
||||
SkAutoTUnref<SkDocument> doc(SkDocument::CreatePDF(&outStream));
|
||||
sk_sp<SkDocument> doc(SkDocument::CreatePDF(&outStream));
|
||||
SkCanvas* canvas = doc->beginPage(100.0f, 100.0f);
|
||||
SkPaint paint;
|
||||
paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding);
|
||||
@ -238,7 +238,7 @@ static void TestPDFUnion(skiatest::Reporter* reporter) {
|
||||
}
|
||||
|
||||
static void TestPDFArray(skiatest::Reporter* reporter) {
|
||||
SkAutoTUnref<SkPDFArray> array(new SkPDFArray);
|
||||
sk_sp<SkPDFArray> array(new SkPDFArray);
|
||||
ASSERT_EMIT_EQ(reporter, *array, "[]");
|
||||
|
||||
array->appendInt(42);
|
||||
@ -268,19 +268,19 @@ static void TestPDFArray(skiatest::Reporter* reporter) {
|
||||
"[42 .5 0 true /ThisName /AnotherName (This String) "
|
||||
"(Another String)]");
|
||||
|
||||
SkAutoTUnref<SkPDFArray> innerArray(new SkPDFArray);
|
||||
sk_sp<SkPDFArray> innerArray(new SkPDFArray);
|
||||
innerArray->appendInt(-1);
|
||||
array->appendObject(innerArray.detach());
|
||||
array->appendObject(std::move(innerArray));
|
||||
ASSERT_EMIT_EQ(reporter, *array,
|
||||
"[42 .5 0 true /ThisName /AnotherName (This String) "
|
||||
"(Another String) [-1]]");
|
||||
|
||||
SkAutoTUnref<SkPDFArray> referencedArray(new SkPDFArray);
|
||||
sk_sp<SkPDFArray> referencedArray(new SkPDFArray);
|
||||
Catalog catalog;
|
||||
catalog.numbers.addObject(referencedArray.get());
|
||||
REPORTER_ASSERT(reporter, catalog.numbers.getObjectNumber(
|
||||
referencedArray.get()) == 1);
|
||||
array->appendObjRef(referencedArray.detach());
|
||||
array->appendObjRef(std::move(referencedArray));
|
||||
|
||||
SkString result = emit_to_string(*array, &catalog);
|
||||
ASSERT_EQ(reporter, result,
|
||||
@ -289,7 +289,7 @@ static void TestPDFArray(skiatest::Reporter* reporter) {
|
||||
}
|
||||
|
||||
static void TestPDFDict(skiatest::Reporter* reporter) {
|
||||
SkAutoTUnref<SkPDFDict> dict(new SkPDFDict);
|
||||
sk_sp<SkPDFDict> dict(new SkPDFDict);
|
||||
ASSERT_EMIT_EQ(reporter, *dict, "<<>>");
|
||||
|
||||
dict->insertInt("n1", SkToSizeT(42));
|
||||
@ -304,9 +304,9 @@ static void TestPDFDict(skiatest::Reporter* reporter) {
|
||||
dict->insertScalar("n2", SK_ScalarHalf);
|
||||
|
||||
SkString n3("n3");
|
||||
SkAutoTUnref<SkPDFArray> innerArray(new SkPDFArray);
|
||||
sk_sp<SkPDFArray> innerArray(new SkPDFArray);
|
||||
innerArray->appendInt(-100);
|
||||
dict->insertObject(n3, innerArray.detach());
|
||||
dict->insertObject(n3, std::move(innerArray));
|
||||
ASSERT_EMIT_EQ(reporter, *dict, "<</n1 42\n/n2 .5\n/n3 [-100]>>");
|
||||
|
||||
dict.reset(new SkPDFDict);
|
||||
@ -339,12 +339,12 @@ static void TestPDFDict(skiatest::Reporter* reporter) {
|
||||
dict.reset(new SkPDFDict("DType"));
|
||||
ASSERT_EMIT_EQ(reporter, *dict, "<</Type /DType>>");
|
||||
|
||||
SkAutoTUnref<SkPDFArray> referencedArray(new SkPDFArray);
|
||||
sk_sp<SkPDFArray> referencedArray(new SkPDFArray);
|
||||
Catalog catalog;
|
||||
catalog.numbers.addObject(referencedArray.get());
|
||||
REPORTER_ASSERT(reporter, catalog.numbers.getObjectNumber(
|
||||
referencedArray.get()) == 1);
|
||||
dict->insertObjRef("n1", referencedArray.detach());
|
||||
dict->insertObjRef("n1", std::move(referencedArray));
|
||||
SkString result = emit_to_string(*dict, &catalog);
|
||||
ASSERT_EQ(reporter, result, "<</Type /DType\n/n1 1 0 R>>");
|
||||
}
|
||||
@ -400,10 +400,10 @@ void DummyImageFilter::toString(SkString* str) const {
|
||||
// CPU rasterization.
|
||||
DEF_TEST(PDFImageFilter, reporter) {
|
||||
SkDynamicMemoryWStream stream;
|
||||
SkAutoTUnref<SkDocument> doc(SkDocument::CreatePDF(&stream));
|
||||
sk_sp<SkDocument> doc(SkDocument::CreatePDF(&stream));
|
||||
SkCanvas* canvas = doc->beginPage(100.0f, 100.0f);
|
||||
|
||||
SkAutoTUnref<DummyImageFilter> filter(new DummyImageFilter());
|
||||
sk_sp<DummyImageFilter> filter(new DummyImageFilter());
|
||||
|
||||
// Filter just created; should be unvisited.
|
||||
REPORTER_ASSERT(reporter, !filter->visited());
|
||||
@ -422,15 +422,15 @@ DEF_TEST(PDFFontCanEmbedTypeface, reporter) {
|
||||
SkPDFCanon canon;
|
||||
|
||||
const char resource[] = "fonts/Roboto2-Regular_NoEmbed.ttf";
|
||||
SkAutoTUnref<SkTypeface> noEmbedTypeface(GetResourceAsTypeface(resource));
|
||||
sk_sp<SkTypeface> noEmbedTypeface(GetResourceAsTypeface(resource));
|
||||
if (noEmbedTypeface) {
|
||||
REPORTER_ASSERT(reporter,
|
||||
!SkPDFFont::CanEmbedTypeface(noEmbedTypeface, &canon));
|
||||
!SkPDFFont::CanEmbedTypeface(noEmbedTypeface.get(), &canon));
|
||||
}
|
||||
SkAutoTUnref<SkTypeface> portableTypeface(
|
||||
sk_sp<SkTypeface> portableTypeface(
|
||||
sk_tool_utils::create_portable_typeface(NULL, SkTypeface::kNormal));
|
||||
REPORTER_ASSERT(reporter,
|
||||
SkPDFFont::CanEmbedTypeface(portableTypeface, &canon));
|
||||
SkPDFFont::CanEmbedTypeface(portableTypeface.get(), &canon));
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user