[PDF] Remove one copy of each content stream.
Review URL: http://codereview.appspot.com/4231044 git-svn-id: http://skia.googlecode.com/svn/trunk@856 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
parent
f60a001d1a
commit
c2a9b7fe56
@ -132,9 +132,10 @@ public:
|
||||
*/
|
||||
SkRefPtr<SkPDFArray> getMediaBox() const;
|
||||
|
||||
/** Returns a string with the page contents.
|
||||
/** Returns a SkStream with the page contents. The caller is responsible
|
||||
for a reference to the returned value.
|
||||
*/
|
||||
SkString content() const;
|
||||
SkStream* content() const;
|
||||
|
||||
private:
|
||||
int fWidth;
|
||||
|
@ -90,7 +90,6 @@ private:
|
||||
// Multiple pages may reference the content.
|
||||
SkRefPtr<SkPDFDevice> fDevice;
|
||||
|
||||
SkString fContent;
|
||||
// Once the content is finalized, put it into a stream for output.
|
||||
SkRefPtr<SkPDFStream> fContentStream;
|
||||
};
|
||||
|
@ -558,10 +558,16 @@ SkRefPtr<SkPDFArray> SkPDFDevice::getMediaBox() const {
|
||||
return mediaBox;
|
||||
}
|
||||
|
||||
SkString SkPDFDevice::content() const {
|
||||
SkString result = fContent;
|
||||
for (int i = 0; i < fGraphicStackIndex; i++)
|
||||
result.append("Q\n");
|
||||
SkStream* SkPDFDevice::content() const {
|
||||
size_t offset = fContent.size();
|
||||
char* data = (char*)sk_malloc_throw(offset + fGraphicStackIndex * 2);
|
||||
memcpy(data, fContent.c_str(), offset);
|
||||
for (int i = 0; i < fGraphicStackIndex; i++) {
|
||||
data[offset++] = 'Q';
|
||||
data[offset++] = '\n';
|
||||
}
|
||||
SkMemoryStream* result = new SkMemoryStream;
|
||||
result->setMemoryOwned(data, offset);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -28,11 +28,9 @@ SkPDFFormXObject::SkPDFFormXObject(SkPDFDevice* device) {
|
||||
// resources).
|
||||
device->getResources(&fResources);
|
||||
|
||||
SkString content = device->content();
|
||||
SkMemoryStream* stream_data = new SkMemoryStream(content.c_str(),
|
||||
content.size());
|
||||
SkAutoUnref stream_data_unref(stream_data);
|
||||
fStream = new SkPDFStream(stream_data);
|
||||
SkRefPtr<SkStream> content = device->content();
|
||||
content->unref(); // SkRefPtr and content() both took a reference.
|
||||
fStream = new SkPDFStream(content.get());
|
||||
fStream->unref(); // SkRefPtr and new both took a reference.
|
||||
|
||||
insert("Type", new SkPDFName("XObject"))->unref();
|
||||
|
@ -32,11 +32,9 @@ void SkPDFPage::finalizePage(SkPDFCatalog* catalog, bool firstPage,
|
||||
insert("Resources", fDevice->getResourceDict().get());
|
||||
insert("MediaBox", fDevice->getMediaBox().get());
|
||||
|
||||
fContent = fDevice->content();
|
||||
SkRefPtr<SkMemoryStream> contentStream = new SkMemoryStream(
|
||||
fContent.c_str(), fContent.size());
|
||||
contentStream->unref(); // SkRefPtr and new both took a reference.
|
||||
fContentStream = new SkPDFStream(contentStream.get());
|
||||
SkRefPtr<SkStream> content = fDevice->content();
|
||||
content->unref(); // SkRefPtr and content() both took a reference.
|
||||
fContentStream = new SkPDFStream(content.get());
|
||||
fContentStream->unref(); // SkRefPtr and new both took a reference.
|
||||
insert("Contents", new SkPDFObjRef(fContentStream.get()))->unref();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user