[PDF] Clean up SkPDFStream and make it inherit from SkPDFDict.
A stream is a dictionary (with a couple particular entries) plus the data. The common parent is useful for the shader implementation. Review URL: http://codereview.appspot.com/4221045 git-svn-id: http://skia.googlecode.com/svn/trunk@852 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
parent
a09368c971
commit
d90c141feb
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2010 The Android Open Source Project
|
||||
* Copyright (C) 2010 Google Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@ -28,8 +28,7 @@ class SkPDFCatalog;
|
||||
|
||||
A stream object in a PDF.
|
||||
*/
|
||||
// TODO(vandebo) This should handle filters as well.
|
||||
class SkPDFStream : public SkPDFObject {
|
||||
class SkPDFStream : public SkPDFDict {
|
||||
public:
|
||||
/** Create a PDF stream. A Length entry is automatically added to the
|
||||
* stream dictionary.
|
||||
@ -43,26 +42,13 @@ public:
|
||||
bool indirect);
|
||||
virtual size_t getOutputSize(SkPDFCatalog* catalog, bool indirect);
|
||||
|
||||
/** Add the value to the stream dictionary with the given key. Refs value.
|
||||
* @param key The key for this dictionary entry.
|
||||
* @param value The value for this dictionary entry.
|
||||
* @return The value argument is returned.
|
||||
*/
|
||||
SkPDFObject* insert(SkPDFName* key, SkPDFObject* value);
|
||||
|
||||
/** Add the value to the stream dictionary with the given key. Refs value.
|
||||
* @param key The text of the key for this dictionary entry.
|
||||
* @param value The value for this dictionary entry.
|
||||
* @return The value argument is returned.
|
||||
*/
|
||||
SkPDFObject* insert(const char key[], SkPDFObject* value);
|
||||
|
||||
private:
|
||||
SkPDFDict fDict;
|
||||
size_t fLength;
|
||||
// Only one of the two streams will be valid.
|
||||
SkRefPtr<SkStream> fPlainData;
|
||||
SkDynamicMemoryWStream fCompressedData;
|
||||
|
||||
typedef SkPDFDict INHERITED;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2010 The Android Open Source Project
|
||||
* Copyright (C) 2010 Google Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@ -26,13 +26,13 @@ SkPDFStream::SkPDFStream(SkStream* stream) {
|
||||
if (SkFlate::HaveFlate() &&
|
||||
fCompressedData.getOffset() < stream->getLength()) {
|
||||
fLength = fCompressedData.getOffset();
|
||||
fDict.insert("Filter", new SkPDFName("FlateDecode"))->unref();
|
||||
insert("Filter", new SkPDFName("FlateDecode"))->unref();
|
||||
} else {
|
||||
fCompressedData.reset();
|
||||
fPlainData = stream;
|
||||
fLength = fPlainData->getLength();
|
||||
}
|
||||
fDict.insert("Length", new SkPDFInt(fLength))->unref();
|
||||
insert("Length", new SkPDFInt(fLength))->unref();
|
||||
}
|
||||
|
||||
SkPDFStream::~SkPDFStream() {
|
||||
@ -43,7 +43,7 @@ void SkPDFStream::emitObject(SkWStream* stream, SkPDFCatalog* catalog,
|
||||
if (indirect)
|
||||
return emitIndirectObject(stream, catalog);
|
||||
|
||||
fDict.emitObject(stream, catalog, false);
|
||||
this->INHERITED::emitObject(stream, catalog, false);
|
||||
stream->writeText(" stream\n");
|
||||
if (fPlainData.get())
|
||||
stream->write(fPlainData->getMemoryBase(), fLength);
|
||||
@ -56,14 +56,6 @@ size_t SkPDFStream::getOutputSize(SkPDFCatalog* catalog, bool indirect) {
|
||||
if (indirect)
|
||||
return getIndirectOutputSize(catalog);
|
||||
|
||||
return fDict.getOutputSize(catalog, false) +
|
||||
return this->INHERITED::getOutputSize(catalog, false) +
|
||||
strlen(" stream\n\nendstream") + fLength;
|
||||
}
|
||||
|
||||
SkPDFObject* SkPDFStream::insert(SkPDFName* key, SkPDFObject* value) {
|
||||
return fDict.insert(key, value);
|
||||
}
|
||||
|
||||
SkPDFObject* SkPDFStream::insert(const char key[], SkPDFObject* value) {
|
||||
return fDict.insert(key, value);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user