Change pdfTransform to asAffine.
http://codereview.appspot.com/4704044/ git-svn-id: http://skia.googlecode.com/svn/trunk@1851 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
parent
da44067ec9
commit
1ddd7c3928
@ -92,6 +92,18 @@ public:
|
||||
kMPersp2
|
||||
};
|
||||
|
||||
/** Affine arrays are in column major order
|
||||
because that's how PDF and XPS like it.
|
||||
*/
|
||||
enum {
|
||||
kAScaleX,
|
||||
kASkewY,
|
||||
kASkewX,
|
||||
kAScaleY,
|
||||
kATransX,
|
||||
kATransY
|
||||
};
|
||||
|
||||
SkScalar operator[](int index) const {
|
||||
SkASSERT((unsigned)index < 9);
|
||||
return fMat[index];
|
||||
@ -318,12 +330,19 @@ public:
|
||||
*/
|
||||
bool invert(SkMatrix* inverse) const;
|
||||
|
||||
/** Fills the passed array with the tranform values in the right order
|
||||
for PDFs. If the matrix is a perspective transform, returns false
|
||||
and fills the array with an identity transform.
|
||||
@param transform The array to fill in.
|
||||
/** Fills the passed array with affine identity values
|
||||
in column major order.
|
||||
@param affine The array to fill with affine identity values.
|
||||
Must not be NULL.
|
||||
*/
|
||||
bool pdfTransform(SkScalar transform[6]) const;
|
||||
static void SetAffineIdentity(SkScalar affine[6]);
|
||||
|
||||
/** Fills the passed array with the affine values in column major order.
|
||||
If the matrix is a perspective transform, returns false
|
||||
and does not change the passed array.
|
||||
@param affine The array to fill with affine values. Ignored if NULL.
|
||||
*/
|
||||
bool asAffine(SkScalar affine[6]) const;
|
||||
|
||||
/** Apply this matrix to the array of points specified by src, and write
|
||||
the transformed points into the array of points specified by dst.
|
||||
|
@ -760,21 +760,27 @@ bool SkMatrix::postConcat(const SkMatrix& mat) {
|
||||
}
|
||||
#endif
|
||||
|
||||
bool SkMatrix::pdfTransform(SkScalar transform[6]) const {
|
||||
SkMatrix identity;
|
||||
const SkMatrix* use = this;
|
||||
bool ret = true;
|
||||
void SkMatrix::SetAffineIdentity(SkScalar affine[6]) {
|
||||
affine[kAScaleX] = SK_Scalar1;
|
||||
affine[kASkewY] = 0;
|
||||
affine[kASkewX] = 0;
|
||||
affine[kAScaleY] = SK_Scalar1;
|
||||
affine[kATransX] = 0;
|
||||
affine[kATransY] = 0;
|
||||
}
|
||||
|
||||
bool SkMatrix::asAffine(SkScalar affine[6]) const {
|
||||
if (this->hasPerspective()) {
|
||||
identity.reset();
|
||||
use = &identity;
|
||||
ret = false;
|
||||
return false;
|
||||
}
|
||||
if (affine) {
|
||||
affine[kAScaleX] = this->fMat[kMScaleX];
|
||||
affine[kASkewY] = this->fMat[kMSkewY];
|
||||
affine[kASkewX] = this->fMat[kMSkewX];
|
||||
affine[kAScaleY] = this->fMat[kMScaleY];
|
||||
affine[kATransX] = this->fMat[kMTransX];
|
||||
affine[kATransY] = this->fMat[kMTransY];
|
||||
}
|
||||
transform[0] = use->fMat[kMScaleX];
|
||||
transform[1] = use->fMat[kMSkewY];
|
||||
transform[2] = use->fMat[kMSkewX];
|
||||
transform[3] = use->fMat[kMScaleY];
|
||||
transform[4] = use->fMat[kMTransX];
|
||||
transform[5] = use->fMat[kMTransY];
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -24,7 +24,9 @@
|
||||
// static
|
||||
SkPDFArray* SkPDFUtils::MatrixToArray(const SkMatrix& matrix) {
|
||||
SkScalar values[6];
|
||||
SkAssertResult(matrix.pdfTransform(values));
|
||||
if (!matrix.asAffine(values)) {
|
||||
SkMatrix::SetAffineIdentity(values);
|
||||
}
|
||||
|
||||
SkPDFArray* result = new SkPDFArray;
|
||||
result->reserve(6);
|
||||
@ -37,7 +39,9 @@ SkPDFArray* SkPDFUtils::MatrixToArray(const SkMatrix& matrix) {
|
||||
// static
|
||||
void SkPDFUtils::AppendTransform(const SkMatrix& matrix, SkWStream* content) {
|
||||
SkScalar values[6];
|
||||
SkAssertResult(matrix.pdfTransform(values));
|
||||
if (!matrix.asAffine(values)) {
|
||||
SkMatrix::SetAffineIdentity(values);
|
||||
}
|
||||
for (size_t i = 0; i < SK_ARRAY_COUNT(values); i++) {
|
||||
SkPDFScalar::Append(values[i], content);
|
||||
content->writeText(" ");
|
||||
|
@ -117,6 +117,30 @@ void TestMatrix(skiatest::Reporter* reporter) {
|
||||
m.rectStaysRect() == gRectStaysRectSamples[i].mStaysRect);
|
||||
}
|
||||
}
|
||||
|
||||
mat.set(SkMatrix::kMScaleX, SkIntToScalar(1));
|
||||
mat.set(SkMatrix::kMSkewX, SkIntToScalar(2));
|
||||
mat.set(SkMatrix::kMTransX, SkIntToScalar(3));
|
||||
mat.set(SkMatrix::kMSkewY, SkIntToScalar(4));
|
||||
mat.set(SkMatrix::kMScaleY, SkIntToScalar(5));
|
||||
mat.set(SkMatrix::kMTransY, SkIntToScalar(6));
|
||||
mat.set(SkMatrix::kMPersp0, SkIntToScalar(0));
|
||||
mat.set(SkMatrix::kMPersp1, SkIntToScalar(0));
|
||||
mat.set(SkMatrix::kMPersp2, SkIntToScalar(1));
|
||||
SkScalar affine[6];
|
||||
REPORTER_ASSERT(reporter, mat.asAffine(affine));
|
||||
|
||||
#define affineEqual(e) affine[SkMatrix::kA##e] == mat.get(SkMatrix::kM##e)
|
||||
REPORTER_ASSERT(reporter, affineEqual(ScaleX));
|
||||
REPORTER_ASSERT(reporter, affineEqual(SkewY));
|
||||
REPORTER_ASSERT(reporter, affineEqual(SkewX));
|
||||
REPORTER_ASSERT(reporter, affineEqual(ScaleY));
|
||||
REPORTER_ASSERT(reporter, affineEqual(TransX));
|
||||
REPORTER_ASSERT(reporter, affineEqual(TransY));
|
||||
#undef affineEqual
|
||||
|
||||
mat.set(SkMatrix::kMPersp1, SkIntToScalar(1));
|
||||
REPORTER_ASSERT(reporter, !mat.asAffine(affine));
|
||||
}
|
||||
|
||||
#include "TestClassDef.h"
|
||||
|
Loading…
Reference in New Issue
Block a user