From b054990307b7338e599a12d9af10eb2058b94051 Mon Sep 17 00:00:00 2001 From: "vandebo@chromium.org" Date: Fri, 13 Apr 2012 20:45:46 +0000 Subject: [PATCH] [PDF] If matrix inversion fails, use the identity matrix. BUG=chrome:123078 Review URL: https://codereview.appspot.com/6007044 git-svn-id: http://skia.googlecode.com/svn/trunk@3676 2bbb7eff-a529-9590-31e7-b0007b416f81 --- src/pdf/SkPDFDevice.cpp | 9 ++++++--- src/pdf/SkPDFFormXObject.cpp | 5 +++-- src/pdf/SkPDFShader.cpp | 9 ++++++--- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/src/pdf/SkPDFDevice.cpp b/src/pdf/SkPDFDevice.cpp index f3aaa5e..7e85afd 100644 --- a/src/pdf/SkPDFDevice.cpp +++ b/src/pdf/SkPDFDevice.cpp @@ -490,7 +490,9 @@ static inline SkBitmap makeContentBitmap(const SkISize& contentSize, SkMatrix inverse; drawingSize.set(SkIntToScalar(contentSize.fWidth), SkIntToScalar(contentSize.fHeight)); - initialTransform->invert(&inverse); + if (!initialTransform->invert(&inverse)) { + inverse.reset(); + } inverse.mapVectors(&drawingSize, 1); SkISize size = SkSize::Make(drawingSize.fX, drawingSize.fY).toRound(); bitmap.setConfig(SkBitmap::kNo_Config, abs(size.fWidth), @@ -600,8 +602,9 @@ void SkPDFDevice::internalDrawPaint(const SkPaint& paint, SkMatrix totalTransform = fInitialTransform; totalTransform.preConcat(contentEntry->fState.fMatrix); SkMatrix inverse; - inverse.reset(); - totalTransform.invert(&inverse); + if (!totalTransform.invert(&inverse)) { + inverse.reset(); + } inverse.mapRect(&bbox); SkPDFUtils::AppendRectangle(bbox, &contentEntry->fContent); diff --git a/src/pdf/SkPDFFormXObject.cpp b/src/pdf/SkPDFFormXObject.cpp index fb8a915..f368834 100644 --- a/src/pdf/SkPDFFormXObject.cpp +++ b/src/pdf/SkPDFFormXObject.cpp @@ -36,8 +36,9 @@ SkPDFFormXObject::SkPDFFormXObject(SkPDFDevice* device) { // embedded in things like shaders and images. if (!device->initialTransform().isIdentity()) { SkMatrix inverse; - inverse.reset(); - device->initialTransform().invert(&inverse); + if (!device->initialTransform().invert(&inverse)) { + inverse.reset(); + } insert("Matrix", SkPDFUtils::MatrixToArray(inverse))->unref(); } diff --git a/src/pdf/SkPDFShader.cpp b/src/pdf/SkPDFShader.cpp index 15acf67..3a559ba 100644 --- a/src/pdf/SkPDFShader.cpp +++ b/src/pdf/SkPDFShader.cpp @@ -23,8 +23,9 @@ static void transformBBox(const SkMatrix& matrix, SkRect* bbox) { SkMatrix inverse; - inverse.reset(); - matrix.invert(&inverse); + if (!matrix.invert(&inverse)) { + inverse.reset(); + } inverse.mapRect(bbox); } @@ -488,7 +489,9 @@ SkPDFFunctionShader::SkPDFFunctionShader(SkPDFShader::State* state) if (fState.get()->fType == SkShader::kRadial2_GradientType) { SkShader::GradientInfo twoPointRadialInfo = *info; SkMatrix inverseMapperMatrix; - mapperMatrix.invert(&inverseMapperMatrix); + if (!mapperMatrix.invert(&inverseMapperMatrix)) { + inverseMapperMatrix.reset(); + } inverseMapperMatrix.mapPoints(twoPointRadialInfo.fPoint, 2); twoPointRadialInfo.fRadius[0] = inverseMapperMatrix.mapRadius(info->fRadius[0]); -- 2.7.4