aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorGravatar vandebo@chromium.org <vandebo@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>2012-01-05 18:45:27 +0000
committerGravatar vandebo@chromium.org <vandebo@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>2012-01-05 18:45:27 +0000
commit663515bc59325092c4e47f5189782bd6fcd0586a (patch)
treef59d47e2b37bdaf9212114c6bdcee9b979f503d7 /src
parentb3a39b5b017eeb8a37ce5cb29c6e9b00d649d11b (diff)
[PDF] Fix some scalar/int assumptions.
Review URL: http://codereview.appspot.com/5516043 git-svn-id: http://skia.googlecode.com/svn/trunk@2975 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'src')
-rw-r--r--src/pdf/SkPDFDevice.cpp20
-rw-r--r--src/pdf/SkPDFGraphicState.cpp2
-rw-r--r--src/pdf/SkPDFShader.cpp12
3 files changed, 19 insertions, 15 deletions
diff --git a/src/pdf/SkPDFDevice.cpp b/src/pdf/SkPDFDevice.cpp
index f46cade14f..ced3107363 100644
--- a/src/pdf/SkPDFDevice.cpp
+++ b/src/pdf/SkPDFDevice.cpp
@@ -179,7 +179,7 @@ public:
}
void updateClip(const SkClipStack& clipStack, const SkRegion& clipRegion,
- const SkIPoint& translation);
+ const SkPoint& translation);
void updateMatrix(const SkMatrix& matrix);
void updateDrawingState(const GraphicStateEntry& state);
@@ -283,7 +283,7 @@ static void emit_clip(SkPath* clipPath, SkRect* clipRect,
// on the page to optimize this.
void GraphicStackState::updateClip(const SkClipStack& clipStack,
const SkRegion& clipRegion,
- const SkIPoint& translation) {
+ const SkPoint& translation) {
if (clipStack == currentEntry()->fClipStack) {
return;
}
@@ -488,7 +488,8 @@ static inline SkBitmap makeContentBitmap(const SkISize& contentSize,
// Compute the size of the drawing area.
SkVector drawingSize;
SkMatrix inverse;
- drawingSize.set(contentSize.fWidth, contentSize.fHeight);
+ drawingSize.set(SkIntToScalar(contentSize.fWidth),
+ SkIntToScalar(contentSize.fHeight));
initialTransform->invert(&inverse);
inverse.mapVectors(&drawingSize, 1);
SkISize size = SkSize::Make(drawingSize.fX, drawingSize.fY).toRound();
@@ -502,6 +503,7 @@ static inline SkBitmap makeContentBitmap(const SkISize& contentSize,
return bitmap;
}
+// TODO(vandebo) change pageSize to SkSize.
SkPDFDevice::SkPDFDevice(const SkISize& pageSize, const SkISize& contentSize,
const SkMatrix& initialTransform)
: SkDevice(makeContentBitmap(contentSize, &initialTransform)),
@@ -512,8 +514,8 @@ SkPDFDevice::SkPDFDevice(const SkISize& pageSize, const SkISize& contentSize,
// Skia generally uses the top left as the origin but PDF natively has the
// origin at the bottom left. This matrix corrects for that. But that only
// needs to be done once, we don't do it when layering.
- fInitialTransform.setTranslate(0, pageSize.fHeight);
- fInitialTransform.preScale(1, -1);
+ fInitialTransform.setTranslate(0, SkIntToScalar(pageSize.fHeight));
+ fInitialTransform.preScale(SK_Scalar1, -SK_Scalar1);
fInitialTransform.preConcat(initialTransform);
SkIRect existingClip = SkIRect::MakeWH(this->width(), this->height());
@@ -522,6 +524,7 @@ SkPDFDevice::SkPDFDevice(const SkISize& pageSize, const SkISize& contentSize,
this->init();
}
+// TODO(vandebo) change layerSize to SkSize.
SkPDFDevice::SkPDFDevice(const SkISize& layerSize,
const SkClipStack& existingClipStack,
const SkRegion& existingClipRegion)
@@ -1092,7 +1095,8 @@ void SkPDFDevice::copyContentEntriesToData(ContentEntry* entry,
// right thing to pass here.
GraphicStackState gsState(fExistingClipStack, fExistingClipRegion, data);
while (entry != NULL) {
- SkIPoint translation = this->getOrigin();
+ SkPoint translation;
+ translation.iset(this->getOrigin());
translation.negate();
gsState.updateClip(entry->fState.fClipStack, entry->fState.fClipRegion,
translation);
@@ -1501,8 +1505,8 @@ void SkPDFDevice::internalDrawBitmap(const SkMatrix& matrix,
const SkPaint& paint) {
SkMatrix scaled;
// Adjust for origin flip.
- scaled.setScale(1, -1);
- scaled.postTranslate(0, 1);
+ scaled.setScale(SK_Scalar1, -SK_Scalar1);
+ scaled.postTranslate(0, SK_Scalar1);
// Scale the image up from 1x1 to WxH.
SkIRect subset = SkIRect::MakeWH(bitmap.width(), bitmap.height());
scaled.postScale(SkIntToScalar(subset.width()),
diff --git a/src/pdf/SkPDFGraphicState.cpp b/src/pdf/SkPDFGraphicState.cpp
index d128630a58..ad3f57b822 100644
--- a/src/pdf/SkPDFGraphicState.cpp
+++ b/src/pdf/SkPDFGraphicState.cpp
@@ -200,7 +200,7 @@ void SkPDFGraphicState::populateDict() {
insertName("Type", "ExtGState");
SkRefPtr<SkPDFScalar> alpha =
- new SkPDFScalar(fPaint.getAlpha() * SkScalarInvert(0xFF));
+ new SkPDFScalar(SkScalarDiv(fPaint.getAlpha(), 0xFF));
alpha->unref(); // SkRefPtr and new both took a reference.
insert("CA", alpha.get());
insert("ca", alpha.get());
diff --git a/src/pdf/SkPDFShader.cpp b/src/pdf/SkPDFShader.cpp
index 84c55767ce..b6e09395a8 100644
--- a/src/pdf/SkPDFShader.cpp
+++ b/src/pdf/SkPDFShader.cpp
@@ -525,7 +525,7 @@ SkPDFImageShader::SkPDFImageShader(SkPDFShader::State* state) : fState(state) {
SkMatrix unflip;
unflip.setTranslate(0, SkScalarRound(surfaceBBox.height()));
- unflip.preScale(1, -1);
+ unflip.preScale(SK_Scalar1, -SK_Scalar1);
SkISize size = SkISize::Make(SkScalarRound(surfaceBBox.width()),
SkScalarRound(surfaceBBox.height()));
SkPDFDevice pattern(size, size, unflip);
@@ -554,7 +554,7 @@ SkPDFImageShader::SkPDFImageShader(SkPDFShader::State* state) : fState(state) {
}
if (tileModes[1] == SkShader::kMirror_TileMode) {
SkMatrix yMirror;
- yMirror.setScale(1, -1);
+ yMirror.setScale(SK_Scalar1, -SK_Scalar1);
yMirror.postTranslate(0, 2 * height);
canvas.drawBitmapMatrix(*image, yMirror);
patternBBox.fBottom += height;
@@ -616,7 +616,7 @@ SkPDFImageShader::SkPDFImageShader(SkPDFShader::State* state) : fState(state) {
canvas.drawBitmapMatrix(left, leftMatrix);
if (tileModes[1] == SkShader::kMirror_TileMode) {
- leftMatrix.postScale(1, -1);
+ leftMatrix.postScale(SK_Scalar1, -SK_Scalar1);
leftMatrix.postTranslate(0, 2 * height);
canvas.drawBitmapMatrix(left, leftMatrix);
}
@@ -634,7 +634,7 @@ SkPDFImageShader::SkPDFImageShader(SkPDFShader::State* state) : fState(state) {
canvas.drawBitmapMatrix(right, rightMatrix);
if (tileModes[1] == SkShader::kMirror_TileMode) {
- rightMatrix.postScale(1, -1);
+ rightMatrix.postScale(SK_Scalar1, -SK_Scalar1);
rightMatrix.postTranslate(0, 2 * height);
canvas.drawBitmapMatrix(right, rightMatrix);
}
@@ -649,7 +649,7 @@ SkPDFImageShader::SkPDFImageShader(SkPDFShader::State* state) : fState(state) {
SkAssertResult(image->extractSubset(&top, subset));
SkMatrix topMatrix;
- topMatrix.setScale(1, -surfaceBBox.fTop);
+ topMatrix.setScale(SK_Scalar1, -surfaceBBox.fTop);
topMatrix.postTranslate(0, surfaceBBox.fTop);
canvas.drawBitmapMatrix(top, topMatrix);
@@ -667,7 +667,7 @@ SkPDFImageShader::SkPDFImageShader(SkPDFShader::State* state) : fState(state) {
SkAssertResult(image->extractSubset(&bottom, subset));
SkMatrix bottomMatrix;
- bottomMatrix.setScale(1, surfaceBBox.fBottom - height);
+ bottomMatrix.setScale(SK_Scalar1, surfaceBBox.fBottom - height);
bottomMatrix.postTranslate(0, height);
canvas.drawBitmapMatrix(bottom, bottomMatrix);