summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHenrique Nakashima <hnakashima@chromium.org>2018-08-31 16:00:10 +0000
committerChromium commit bot <commit-bot@chromium.org>2018-08-31 16:00:10 +0000
commit2c0ef6a69dde06662d77fe9d2e80c4adb9b076cd (patch)
tree8a6b8d40db3c4b1767c92f717b34c294361772bc
parentb2d25960b75685aaed5ec1a0ac60975cd033a448 (diff)
downloadpdfium-2c0ef6a69dde06662d77fe9d2e80c4adb9b076cd.tar.xz
Fix radial shading when start circle is a point in the center of end circle.
The bug also requires end circle to be tiny (radius of < 0.01). Bug: pdfium:1140 Change-Id: I2b355f44f0383334b8988fe41f82cb3f587e9909 Reviewed-on: https://pdfium-review.googlesource.com/41672 Commit-Queue: Henrique Nakashima <hnakashima@chromium.org> Reviewed-by: Lei Zhang <thestig@chromium.org> Reviewed-by: Ryan Harrison <rharrison@chromium.org>
-rw-r--r--core/fpdfapi/render/cpdf_renderstatus.cpp13
-rw-r--r--testing/resources/pixel/radial_shading_point_at_center.in52
-rw-r--r--testing/resources/pixel/radial_shading_point_at_center_expected.pdf.0.pngbin0 -> 28058 bytes
3 files changed, 59 insertions, 6 deletions
diff --git a/core/fpdfapi/render/cpdf_renderstatus.cpp b/core/fpdfapi/render/cpdf_renderstatus.cpp
index 95d3cbe5de..c9b98f3bb6 100644
--- a/core/fpdfapi/render/cpdf_renderstatus.cpp
+++ b/core/fpdfapi/render/cpdf_renderstatus.cpp
@@ -260,11 +260,10 @@ void DrawRadialShading(const RetainPtr<CFX_DIBitmap>& pBitmap,
FXARGB_TODIB(ArgbEncode(alpha, FXSYS_round(R * 255),
FXSYS_round(G * 255), FXSYS_round(B * 255)));
}
- float a = ((start_x - end_x) * (start_x - end_x)) +
- ((start_y - end_y) * (start_y - end_y)) -
- ((start_r - end_r) * (start_r - end_r));
- if (IsFloatZero(a))
- a = 0.0f;
+ const float a = ((start_x - end_x) * (start_x - end_x)) +
+ ((start_y - end_y) * (start_y - end_y)) -
+ ((start_r - end_r) * (start_r - end_r));
+ const bool a_is_float_zero = IsFloatZero(a);
int width = pBitmap->GetWidth();
int height = pBitmap->GetHeight();
@@ -289,7 +288,9 @@ void DrawRadialShading(const RetainPtr<CFX_DIBitmap>& pBitmap,
float c = ((pos.x - start_x) * (pos.x - start_x)) +
((pos.y - start_y) * (pos.y - start_y)) - (start_r * start_r);
float s;
- if (a == 0.0f) {
+ if (IsFloatZero(b)) {
+ s = sqrt(-c / a);
+ } else if (a_is_float_zero) {
s = -c / b;
} else {
float b2_4ac = (b * b) - 4 * (a * c);
diff --git a/testing/resources/pixel/radial_shading_point_at_center.in b/testing/resources/pixel/radial_shading_point_at_center.in
new file mode 100644
index 0000000000..bc56cecb50
--- /dev/null
+++ b/testing/resources/pixel/radial_shading_point_at_center.in
@@ -0,0 +1,52 @@
+{{header}}
+
+{{object 1 0}}
+<< /Pages 2 0 R >>
+endobj
+
+{{object 2 0}}
+<< /Type /Pages /Count 1 /Kids [ 3 0 R ] >>
+endobj
+
+{{object 3 0}}
+<<
+ /Type /Page
+ /Parent 2 0 R
+ /MediaBox [0 0 300 400]
+ /Contents 4 0 R
+ /Resources << /Shading << /R9 5 0 R >> >>>>
+endobj
+
+{{object 4 0}}
+<< /Length 5 0 R >>
+stream
+50000 0 0 50000 150 100 cm
+10 10 280 380 re f
+/R9 sh
+endstream
+endobj
+
+{{object 5 0}}
+<<
+ /ShadingType 3
+ /ColorSpace /DeviceRGB
+ /Coords [0.0 0.0 0.0 0.0 0.0 0.005] % Concentric circles
+ /Function 6 0 R
+ /Extend [true true]
+ >>
+endobj
+
+{{object 6 0}}
+<<
+ /FunctionType 2
+ /Domain [0.0 1.0]
+ /C0 [0.8 0.1 0.2]
+ /C1 [0.2 0.025 0.05]
+ /N 1
+>>
+endobj
+
+{{xref}}
+{{trailer}}
+{{startxref}}
+%%EOF
diff --git a/testing/resources/pixel/radial_shading_point_at_center_expected.pdf.0.png b/testing/resources/pixel/radial_shading_point_at_center_expected.pdf.0.png
new file mode 100644
index 0000000000..c69c190b89
--- /dev/null
+++ b/testing/resources/pixel/radial_shading_point_at_center_expected.pdf.0.png
Binary files differ