SkPDF: PDFDevice cleanup.

Remove unused fContentSize.

Combine SkPDFDevice::writeContent and SkPDFDevice::content.

Remove unused SkPDFDevice::initialTransform().

BUG=skia:
GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2264113003

Review-Url: https://codereview.chromium.org/2264113003
This commit is contained in:
halcanary 2016-08-23 09:02:12 -07:00 committed by Commit bot
parent a2d2f38600
commit afdc177e77
2 changed files with 10 additions and 32 deletions

View File

@ -562,7 +562,6 @@ SkPDFDevice::SkPDFDevice(SkISize pageSize, SkScalar rasterDpi, SkPDFDocument* do
: INHERITED(SkImageInfo::MakeUnknown(pageSize.width(), pageSize.height()),
SkSurfaceProps(0, kUnknown_SkPixelGeometry))
, fPageSize(pageSize)
, fContentSize(pageSize)
, fExistingClipRegion(SkIRect::MakeSize(pageSize))
, fRasterDpi(rasterDpi)
, fDocument(doc) {
@ -1325,29 +1324,11 @@ sk_sp<SkPDFArray> SkPDFDevice::copyMediaBox() const {
std::unique_ptr<SkStreamAsset> SkPDFDevice::content() const {
SkDynamicMemoryWStream buffer;
this->writeContent(&buffer);
return std::unique_ptr<SkStreamAsset>(
buffer.bytesWritten() > 0
? buffer.detachAsStream()
: new SkMemoryStream);
}
void SkPDFDevice::writeContent(SkWStream* out) const {
if (fInitialTransform.getType() != SkMatrix::kIdentity_Mask) {
SkPDFUtils::AppendTransform(fInitialTransform, out);
SkPDFUtils::AppendTransform(fInitialTransform, &buffer);
}
// If the content area is the entire page, then we don't need to clip
// the content area (PDF area clips to the page size). Otherwise,
// we have to clip to the content area; we've already applied the
// initial transform, so just clip to the device size.
if (fPageSize != fContentSize) {
SkRect r = SkRect::MakeWH(SkIntToScalar(this->width()),
SkIntToScalar(this->height()));
emit_clip(nullptr, &r, out);
}
GraphicStackState gsState(fExistingClipStack, fExistingClipRegion, out);
GraphicStackState gsState(fExistingClipStack, fExistingClipRegion, &buffer);
for (const auto& entry : fContentEntries) {
SkPoint translation;
translation.iset(this->getOrigin());
@ -1357,9 +1338,14 @@ void SkPDFDevice::writeContent(SkWStream* out) const {
gsState.updateMatrix(entry.fState.fMatrix);
gsState.updateDrawingState(entry.fState);
entry.fContent.writeToStream(out);
entry.fContent.writeToStream(&buffer);
}
gsState.drainStack();
return std::unique_ptr<SkStreamAsset>(
buffer.bytesWritten() > 0
? buffer.detachAsStream()
: new SkMemoryStream);
}
/* Draws an inverse filled path by using Path Ops to compute the positive
@ -1499,8 +1485,8 @@ void SkPDFDevice::appendDestinations(SkPDFDict* dict, SkPDFObject* page) const {
sk_sp<SkPDFObject> SkPDFDevice::makeFormXObjectFromDevice() {
SkMatrix inverseTransform = SkMatrix::I();
if (!this->initialTransform().isIdentity()) {
if (!this->initialTransform().invert(&inverseTransform)) {
if (!fInitialTransform.isIdentity()) {
if (!fInitialTransform.invert(&inverseTransform)) {
SkDEBUGFAIL("Layer initial transform should be invertible.");
inverseTransform.reset();
}

View File

@ -143,13 +143,6 @@ public:
*/
std::unique_ptr<SkStreamAsset> content() const;
/** Writes the page contents to the stream. */
void writeContent(SkWStream*) const;
const SkMatrix& initialTransform() const {
return fInitialTransform;
}
SkPDFCanon* getCanon() const;
// It is important to not confuse GraphicStateEntry with SkPDFGraphicState, the
@ -218,7 +211,6 @@ private:
friend class ScopedContentEntry;
SkISize fPageSize;
SkISize fContentSize;
SkMatrix fInitialTransform;
SkClipStack fExistingClipStack;
SkRegion fExistingClipRegion;