summaryrefslogtreecommitdiff
path: root/fpdfsdk/fpdf_editpath.cpp
diff options
context:
space:
mode:
authorTom Sepez <tsepez@chromium.org>2018-05-03 17:19:53 +0000
committerChromium commit bot <commit-bot@chromium.org>2018-05-03 17:19:53 +0000
commit525147a1f6d6cd736a407d1e189ac25d2f4726e8 (patch)
treebdc818c52d902a5a4e8ce8a4f0ba29bd11007b05 /fpdfsdk/fpdf_editpath.cpp
parentccd9421589922b8f35ee5330d7fdac7edea081db (diff)
downloadpdfium-525147a1f6d6cd736a407d1e189ac25d2f4726e8.tar.xz
Use strict types in FPDF API, try #3
Rather than messing with actual inheritence, add type-checking wrappers and just blatantly cast to incomplete types. Along the way, this points out places where we would downcast without checking, which I fix. Change-Id: Ieb303eb46ad8522dfe082454f1f10f247ffd52d5 Reviewed-on: https://pdfium-review.googlesource.com/32030 Reviewed-by: dsinclair <dsinclair@chromium.org> Commit-Queue: Tom Sepez <tsepez@chromium.org>
Diffstat (limited to 'fpdfsdk/fpdf_editpath.cpp')
-rw-r--r--fpdfsdk/fpdf_editpath.cpp17
1 files changed, 10 insertions, 7 deletions
diff --git a/fpdfsdk/fpdf_editpath.cpp b/fpdfsdk/fpdf_editpath.cpp
index 82c7ca13ef..aca2bebf81 100644
--- a/fpdfsdk/fpdf_editpath.cpp
+++ b/fpdfsdk/fpdf_editpath.cpp
@@ -42,10 +42,6 @@ CPDF_PathObject* CPDFPathObjectFromFPDFPageObject(FPDF_PAGEOBJECT page_object) {
return obj ? obj->AsPath() : nullptr;
}
-const FX_PATHPOINT* FXPathPointFromFPDFPathSegment(FPDF_PATHSEGMENT segment) {
- return static_cast<const FX_PATHPOINT*>(segment);
-}
-
unsigned int GetAlphaAsUnsignedInt(float alpha) {
return static_cast<unsigned int>(alpha * 255.f + 0.5f);
}
@@ -57,7 +53,9 @@ FPDF_EXPORT FPDF_PAGEOBJECT FPDF_CALLCONV FPDFPageObj_CreateNewPath(float x,
auto pPathObj = pdfium::MakeUnique<CPDF_PathObject>();
pPathObj->m_Path.AppendPoint(CFX_PointF(x, y), FXPT_TYPE::MoveTo, false);
pPathObj->DefaultStates();
- return pPathObj.release(); // Caller takes ownership.
+
+ // Caller takes ownership.
+ return FPDFPageObjectFromCPDFPageObject(pPathObj.release());
}
FPDF_EXPORT FPDF_PAGEOBJECT FPDF_CALLCONV FPDFPageObj_CreateNewRect(float x,
@@ -67,7 +65,9 @@ FPDF_EXPORT FPDF_PAGEOBJECT FPDF_CALLCONV FPDFPageObj_CreateNewRect(float x,
auto pPathObj = pdfium::MakeUnique<CPDF_PathObject>();
pPathObj->m_Path.AppendRect(x, y, x + w, y + h);
pPathObj->DefaultStates();
- return pPathObj.release(); // Caller takes ownership.
+
+ // Caller takes ownership.
+ return FPDFPageObjectFromCPDFPageObject(pPathObj.release());
}
FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV
@@ -156,7 +156,10 @@ FPDFPath_GetPathSegment(FPDF_PAGEOBJECT path, int index) {
return nullptr;
const std::vector<FX_PATHPOINT>& points = pPathObj->m_Path.GetPoints();
- return pdfium::IndexInBounds(points, index) ? &points[index] : nullptr;
+ if (!pdfium::IndexInBounds(points, index))
+ return nullptr;
+
+ return FPDFPathSegmentFromFXPathPoint(&points[index]);
}
FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFPath_MoveTo(FPDF_PAGEOBJECT path,