summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLei Zhang <thestig@chromium.org>2017-09-13 13:22:54 -0700
committerChromium commit bot <commit-bot@chromium.org>2017-09-14 05:42:50 +0000
commit038740c2fbd27f5a6a0fad8903546ecb69a2f9a4 (patch)
tree573da77f74b4277fec9be73f64354d5ea72b3bd4
parent24b0733a72bbc4013bff8628f198b0aea807aa06 (diff)
downloadpdfium-038740c2fbd27f5a6a0fad8903546ecb69a2f9a4.tar.xz
Fix CPDFPathObjectFromFPDFPageObject() implementation.
It should make sure the FPDF_PAGEOJECT passed in is actually a path. Change-Id: I89d0626dc350fd2f65b08282b276a4de2c3a7398 Reviewed-on: https://pdfium-review.googlesource.com/13710 Commit-Queue: Lei Zhang <thestig@chromium.org> Reviewed-by: Nicolás Peña <npm@chromium.org> Reviewed-by: Henrique Nakashima <hnakashima@chromium.org>
-rw-r--r--fpdfsdk/fpdfeditpath.cpp37
-rw-r--r--fpdfsdk/fpdfview.cpp3
2 files changed, 20 insertions, 20 deletions
diff --git a/fpdfsdk/fpdfeditpath.cpp b/fpdfsdk/fpdfeditpath.cpp
index 19d47e6a44..2b33dee934 100644
--- a/fpdfsdk/fpdfeditpath.cpp
+++ b/fpdfsdk/fpdfeditpath.cpp
@@ -50,11 +50,11 @@ FPDFPath_SetStrokeColor(FPDF_PAGEOBJECT path,
unsigned int G,
unsigned int B,
unsigned int A) {
- if (!path || R > 255 || G > 255 || B > 255 || A > 255)
+ auto* pPathObj = CPDFPathObjectFromFPDFPageObject(path);
+ if (!pPathObj || R > 255 || G > 255 || B > 255 || A > 255)
return false;
float rgb[3] = {R / 255.f, G / 255.f, B / 255.f};
- auto* pPathObj = CPDFPathObjectFromFPDFPageObject(path);
pPathObj->m_GeneralState.SetStrokeAlpha(A / 255.f);
pPathObj->m_ColorState.SetStrokeColor(
CPDF_ColorSpace::GetStockCS(PDFCS_DEVICERGB), rgb, 3);
@@ -68,10 +68,10 @@ FPDFPath_GetStrokeColor(FPDF_PAGEOBJECT path,
unsigned int* G,
unsigned int* B,
unsigned int* A) {
- if (!path || !R || !G || !B || !A)
+ auto* pPathObj = CPDFPathObjectFromFPDFPageObject(path);
+ if (!pPathObj || !R || !G || !B || !A)
return false;
- auto* pPathObj = CPDFPathObjectFromFPDFPageObject(path);
uint32_t strokeRGB = pPathObj->m_ColorState.GetStrokeRGB();
*R = FXSYS_GetRValue(strokeRGB);
*G = FXSYS_GetGValue(strokeRGB);
@@ -83,10 +83,10 @@ FPDFPath_GetStrokeColor(FPDF_PAGEOBJECT path,
FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV
FPDFPath_SetStrokeWidth(FPDF_PAGEOBJECT path, float width) {
- if (!path || width < 0.0f)
+ auto* pPathObj = CPDFPathObjectFromFPDFPageObject(path);
+ if (!pPathObj || width < 0.0f)
return false;
- auto* pPathObj = CPDFPathObjectFromFPDFPageObject(path);
pPathObj->m_GraphState.SetLineWidth(width);
pPathObj->SetDirty(true);
return true;
@@ -105,10 +105,10 @@ FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFPath_GetFillColor(FPDF_PAGEOBJECT path,
unsigned int* G,
unsigned int* B,
unsigned int* A) {
- if (!path || !R || !G || !B || !A)
+ auto* pPathObj = CPDFPathObjectFromFPDFPageObject(path);
+ if (!pPathObj || !R || !G || !B || !A)
return false;
- auto* pPathObj = CPDFPathObjectFromFPDFPageObject(path);
uint32_t fillRGB = pPathObj->m_ColorState.GetFillRGB();
*R = FXSYS_GetRValue(fillRGB);
*G = FXSYS_GetGValue(fillRGB);
@@ -121,10 +121,10 @@ FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFPath_GetFillColor(FPDF_PAGEOBJECT path,
FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFPath_MoveTo(FPDF_PAGEOBJECT path,
float x,
float y) {
- if (!path)
+ auto* pPathObj = CPDFPathObjectFromFPDFPageObject(path);
+ if (!pPathObj)
return false;
- auto* pPathObj = CPDFPathObjectFromFPDFPageObject(path);
pPathObj->m_Path.AppendPoint(CFX_PointF(x, y), FXPT_TYPE::MoveTo, false);
pPathObj->SetDirty(true);
return true;
@@ -133,10 +133,10 @@ FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFPath_MoveTo(FPDF_PAGEOBJECT path,
FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFPath_LineTo(FPDF_PAGEOBJECT path,
float x,
float y) {
- if (!path)
+ auto* pPathObj = CPDFPathObjectFromFPDFPageObject(path);
+ if (!pPathObj)
return false;
- auto* pPathObj = CPDFPathObjectFromFPDFPageObject(path);
pPathObj->m_Path.AppendPoint(CFX_PointF(x, y), FXPT_TYPE::LineTo, false);
pPathObj->SetDirty(true);
return true;
@@ -149,10 +149,10 @@ FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFPath_BezierTo(FPDF_PAGEOBJECT path,
float y2,
float x3,
float y3) {
- if (!path)
+ auto* pPathObj = CPDFPathObjectFromFPDFPageObject(path);
+ if (!pPathObj)
return false;
- auto* pPathObj = CPDFPathObjectFromFPDFPageObject(path);
pPathObj->m_Path.AppendPoint(CFX_PointF(x1, y1), FXPT_TYPE::BezierTo, false);
pPathObj->m_Path.AppendPoint(CFX_PointF(x2, y2), FXPT_TYPE::BezierTo, false);
pPathObj->m_Path.AppendPoint(CFX_PointF(x3, y3), FXPT_TYPE::BezierTo, false);
@@ -161,10 +161,10 @@ FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFPath_BezierTo(FPDF_PAGEOBJECT path,
}
FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFPath_Close(FPDF_PAGEOBJECT path) {
- if (!path)
+ auto* pPathObj = CPDFPathObjectFromFPDFPageObject(path);
+ if (!pPathObj)
return false;
- auto* pPathObj = CPDFPathObjectFromFPDFPageObject(path);
if (pPathObj->m_Path.GetPoints().empty())
return false;
@@ -176,10 +176,9 @@ FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFPath_Close(FPDF_PAGEOBJECT path) {
FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFPath_SetDrawMode(FPDF_PAGEOBJECT path,
int fillmode,
FPDF_BOOL stroke) {
- if (!path)
- return false;
-
auto* pPathObj = CPDFPathObjectFromFPDFPageObject(path);
+ if (!pPathObj)
+ return false;
if (fillmode == FPDF_FILLMODE_ALTERNATE)
pPathObj->m_FillType = FXFILL_ALTERNATE;
diff --git a/fpdfsdk/fpdfview.cpp b/fpdfsdk/fpdfview.cpp
index 5bcc643ac1..0aaafe8afb 100644
--- a/fpdfsdk/fpdfview.cpp
+++ b/fpdfsdk/fpdfview.cpp
@@ -336,7 +336,8 @@ CPDF_Page* CPDFPageFromFPDFPage(FPDF_PAGE page) {
}
CPDF_PathObject* CPDFPathObjectFromFPDFPageObject(FPDF_PAGEOBJECT page_object) {
- return static_cast<CPDF_PathObject*>(page_object);
+ auto* obj = CPDFPageObjectFromFPDFPageObject(page_object);
+ return obj ? obj->AsPath() : nullptr;
}
CPDF_PageObject* CPDFPageObjectFromFPDFPageObject(FPDF_PAGEOBJECT page_object) {