| Index: src/pdf/SkPDFTypes.cpp
|
| diff --git a/src/pdf/SkPDFTypes.cpp b/src/pdf/SkPDFTypes.cpp
|
| index e6fe74447df989bedb1b9c6411ca786f83d263aa..b8727a9145d5ab1c813490b55088068a88184308 100644
|
| --- a/src/pdf/SkPDFTypes.cpp
|
| +++ b/src/pdf/SkPDFTypes.cpp
|
| @@ -263,21 +263,26 @@ void SkPDFAtom::addResources(SkPDFObjNumMap* map,
|
|
|
| ////////////////////////////////////////////////////////////////////////////////
|
|
|
| -SkPDFArray::SkPDFArray() {}
|
| -SkPDFArray::~SkPDFArray() {
|
| - for (SkPDFUnion& value : fValues) {
|
| - value.~SkPDFUnion();
|
| - }
|
| +SkPDFArray::SkPDFArray() { SkDEBUGCODE(fDumped = false;) }
|
| +
|
| +SkPDFArray::~SkPDFArray() { this->drop(); }
|
| +
|
| +void SkPDFArray::drop() {
|
| fValues.reset();
|
| + SkDEBUGCODE(fDumped = true;)
|
| }
|
|
|
| int SkPDFArray::size() const { return fValues.count(); }
|
|
|
| -void SkPDFArray::reserve(int length) { fValues.setReserve(length); }
|
| +void SkPDFArray::reserve(int length) {
|
| + // TODO(halcanary): implement SkTArray<T>::reserve() or change the
|
| + // contstructor of SkPDFArray to take reserve size.
|
| +}
|
|
|
| void SkPDFArray::emitObject(SkWStream* stream,
|
| const SkPDFObjNumMap& objNumMap,
|
| const SkPDFSubstituteMap& substitutes) const {
|
| + SkASSERT(!fDumped);
|
| stream->writeText("[");
|
| for (int i = 0; i < fValues.count(); i++) {
|
| fValues[i].emitObject(stream, objNumMap, substitutes);
|
| @@ -290,13 +295,14 @@ void SkPDFArray::emitObject(SkWStream* stream,
|
|
|
| void SkPDFArray::addResources(SkPDFObjNumMap* catalog,
|
| const SkPDFSubstituteMap& substitutes) const {
|
| + SkASSERT(!fDumped);
|
| for (const SkPDFUnion& value : fValues) {
|
| value.addResources(catalog, substitutes);
|
| }
|
| }
|
|
|
| void SkPDFArray::append(SkPDFUnion&& value) {
|
| - new (fValues.append()) SkPDFUnion(std::move(value));
|
| + fValues.emplace_back(std::move(value));
|
| }
|
|
|
| void SkPDFArray::appendInt(int32_t value) {
|
| @@ -337,11 +343,19 @@ void SkPDFArray::appendObjRef(sk_sp<SkPDFObject> objSp) {
|
|
|
| ///////////////////////////////////////////////////////////////////////////////
|
|
|
| -SkPDFDict::SkPDFDict() {}
|
| +SkPDFDict::~SkPDFDict() { this->drop(); }
|
|
|
| -SkPDFDict::~SkPDFDict() { this->clear(); }
|
| +void SkPDFDict::drop() {
|
| + fRecords.reset();
|
| + SkDEBUGCODE(fDumped = true;)
|
| +}
|
|
|
| -SkPDFDict::SkPDFDict(const char type[]) { this->insertName("Type", type); }
|
| +SkPDFDict::SkPDFDict(const char type[]) {
|
| + SkDEBUGCODE(fDumped = false;)
|
| + if (type) {
|
| + this->insertName("Type", type);
|
| + }
|
| +}
|
|
|
| void SkPDFDict::emitObject(SkWStream* stream,
|
| const SkPDFObjNumMap& objNumMap,
|
| @@ -354,6 +368,7 @@ void SkPDFDict::emitObject(SkWStream* stream,
|
| void SkPDFDict::emitAll(SkWStream* stream,
|
| const SkPDFObjNumMap& objNumMap,
|
| const SkPDFSubstituteMap& substitutes) const {
|
| + SkASSERT(!fDumped);
|
| for (int i = 0; i < fRecords.count(); i++) {
|
| fRecords[i].fKey.emitObject(stream, objNumMap, substitutes);
|
| stream->writeText(" ");
|
| @@ -366,41 +381,48 @@ void SkPDFDict::emitAll(SkWStream* stream,
|
|
|
| void SkPDFDict::addResources(SkPDFObjNumMap* catalog,
|
| const SkPDFSubstituteMap& substitutes) const {
|
| + SkASSERT(!fDumped);
|
| for (int i = 0; i < fRecords.count(); i++) {
|
| fRecords[i].fKey.addResources(catalog, substitutes);
|
| fRecords[i].fValue.addResources(catalog, substitutes);
|
| }
|
| }
|
|
|
| -void SkPDFDict::set(SkPDFUnion&& name, SkPDFUnion&& value) {
|
| - Record* rec = fRecords.append();
|
| - SkASSERT(name.isName());
|
| - new (&rec->fKey) SkPDFUnion(std::move(name));
|
| - new (&rec->fValue) SkPDFUnion(std::move(value));
|
| +SkPDFDict::Record::Record(SkPDFUnion&& k, SkPDFUnion&& v)
|
| + : fKey(std::move(k)), fValue(std::move(v)) {}
|
| +
|
| +SkPDFDict::Record::Record(SkPDFDict::Record&& o)
|
| + : fKey(std::move(o.fKey)), fValue(std::move(o.fValue)) {}
|
| +
|
| +SkPDFDict::Record& SkPDFDict::Record::operator=(SkPDFDict::Record&& o) {
|
| + fKey = std::move(o.fKey);
|
| + fValue = std::move(o.fValue);
|
| + return *this;
|
| }
|
|
|
| int SkPDFDict::size() const { return fRecords.count(); }
|
|
|
| void SkPDFDict::insertObjRef(const char key[], sk_sp<SkPDFObject> objSp) {
|
| - this->set(SkPDFUnion::Name(key), SkPDFUnion::ObjRef(std::move(objSp)));
|
| + fRecords.emplace_back(SkPDFUnion::Name(key), SkPDFUnion::ObjRef(std::move(objSp)));
|
| }
|
| +
|
| void SkPDFDict::insertObjRef(const SkString& key, sk_sp<SkPDFObject> objSp) {
|
| - this->set(SkPDFUnion::Name(key), SkPDFUnion::ObjRef(std::move(objSp)));
|
| + fRecords.emplace_back(SkPDFUnion::Name(key), SkPDFUnion::ObjRef(std::move(objSp)));
|
| }
|
|
|
| void SkPDFDict::insertObject(const char key[], sk_sp<SkPDFObject> objSp) {
|
| - this->set(SkPDFUnion::Name(key), SkPDFUnion::Object(std::move(objSp)));
|
| + fRecords.emplace_back(SkPDFUnion::Name(key), SkPDFUnion::Object(std::move(objSp)));
|
| }
|
| void SkPDFDict::insertObject(const SkString& key, sk_sp<SkPDFObject> objSp) {
|
| - this->set(SkPDFUnion::Name(key), SkPDFUnion::Object(std::move(objSp)));
|
| + fRecords.emplace_back(SkPDFUnion::Name(key), SkPDFUnion::Object(std::move(objSp)));
|
| }
|
|
|
| void SkPDFDict::insertBool(const char key[], bool value) {
|
| - this->set(SkPDFUnion::Name(key), SkPDFUnion::Bool(value));
|
| + fRecords.emplace_back(SkPDFUnion::Name(key), SkPDFUnion::Bool(value));
|
| }
|
|
|
| void SkPDFDict::insertInt(const char key[], int32_t value) {
|
| - this->set(SkPDFUnion::Name(key), SkPDFUnion::Int(value));
|
| + fRecords.emplace_back(SkPDFUnion::Name(key), SkPDFUnion::Int(value));
|
| }
|
|
|
| void SkPDFDict::insertInt(const char key[], size_t value) {
|
| @@ -408,39 +430,46 @@ void SkPDFDict::insertInt(const char key[], size_t value) {
|
| }
|
|
|
| void SkPDFDict::insertScalar(const char key[], SkScalar value) {
|
| - this->set(SkPDFUnion::Name(key), SkPDFUnion::Scalar(value));
|
| + fRecords.emplace_back(SkPDFUnion::Name(key), SkPDFUnion::Scalar(value));
|
| }
|
|
|
| void SkPDFDict::insertName(const char key[], const char name[]) {
|
| - this->set(SkPDFUnion::Name(key), SkPDFUnion::Name(name));
|
| + fRecords.emplace_back(SkPDFUnion::Name(key), SkPDFUnion::Name(name));
|
| }
|
|
|
| void SkPDFDict::insertName(const char key[], const SkString& name) {
|
| - this->set(SkPDFUnion::Name(key), SkPDFUnion::Name(name));
|
| + fRecords.emplace_back(SkPDFUnion::Name(key), SkPDFUnion::Name(name));
|
| }
|
|
|
| void SkPDFDict::insertString(const char key[], const char value[]) {
|
| - this->set(SkPDFUnion::Name(key), SkPDFUnion::String(value));
|
| + fRecords.emplace_back(SkPDFUnion::Name(key), SkPDFUnion::String(value));
|
| }
|
|
|
| void SkPDFDict::insertString(const char key[], const SkString& value) {
|
| - this->set(SkPDFUnion::Name(key), SkPDFUnion::String(value));
|
| + fRecords.emplace_back(SkPDFUnion::Name(key), SkPDFUnion::String(value));
|
| }
|
|
|
| -void SkPDFDict::clear() {
|
| - for (Record& rec : fRecords) {
|
| - rec.fKey.~SkPDFUnion();
|
| - rec.fValue.~SkPDFUnion();
|
| - }
|
| - fRecords.reset();
|
| +////////////////////////////////////////////////////////////////////////////////
|
| +
|
| +SkPDFSharedStream::SkPDFSharedStream(SkStreamAsset* data)
|
| + : fAsset(data), fDict(new SkPDFDict) {
|
| + SkDEBUGCODE(fDumped = false;)
|
| + SkASSERT(data);
|
| }
|
|
|
| -////////////////////////////////////////////////////////////////////////////////
|
| +SkPDFSharedStream::~SkPDFSharedStream() { this->drop(); }
|
| +
|
| +void SkPDFSharedStream::drop() {
|
| + fAsset.reset();
|
| + fDict.reset(nullptr);
|
| + SkDEBUGCODE(fDumped = true;)
|
| +}
|
|
|
| void SkPDFSharedStream::emitObject(
|
| SkWStream* stream,
|
| const SkPDFObjNumMap& objNumMap,
|
| const SkPDFSubstituteMap& substitutes) const {
|
| + SkASSERT(!fDumped);
|
| SkDynamicMemoryWStream buffer;
|
| SkDeflateWStream deflateWStream(&buffer);
|
| // Since emitObject is const, this function doesn't change the dictionary.
|
| @@ -467,6 +496,7 @@ void SkPDFSharedStream::emitObject(
|
|
|
| void SkPDFSharedStream::addResources(
|
| SkPDFObjNumMap* catalog, const SkPDFSubstituteMap& substitutes) const {
|
| + SkASSERT(!fDumped);
|
| fDict->addResources(catalog, substitutes);
|
| }
|
|
|
| @@ -496,7 +526,7 @@ bool SkPDFObjNumMap::addObject(SkPDFObject* obj) {
|
| return false;
|
| }
|
| fObjectNumbers.set(obj, fObjectNumbers.count() + 1);
|
| - fObjects.push(obj);
|
| + fObjects.emplace_back(sk_ref_sp(obj));
|
| return true;
|
| }
|
|
|
|
|