summaryrefslogtreecommitdiff
path: root/fpdfsdk/fpdfeditpath.cpp
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.co.uk>2017-09-20 22:52:43 +0200
committerChromium commit bot <commit-bot@chromium.org>2017-09-20 21:04:08 +0000
commit36eed87d19e741be9909500c45dd12e50ff6a1ab (patch)
tree7311bbf0ba29245308ca79b34acb22086d6cbdd0 /fpdfsdk/fpdfeditpath.cpp
parent0c2e705f8d8dec68c1afc8344872fe8bee527c48 (diff)
downloadpdfium-36eed87d19e741be9909500c45dd12e50ff6a1ab.tar.xz
Add FPDFPath_GetPoint() APIchromium/3221
Combined with the previously added FPDFPath_CountPoint(), this allows getting the coordinates of all points of a path. Change-Id: Ic969723d4b01ee427498d38ce323c74147b87a9c Reviewed-on: https://pdfium-review.googlesource.com/14111 Commit-Queue: dsinclair <dsinclair@chromium.org> Reviewed-by: dsinclair <dsinclair@chromium.org>
Diffstat (limited to 'fpdfsdk/fpdfeditpath.cpp')
-rw-r--r--fpdfsdk/fpdfeditpath.cpp46
1 files changed, 46 insertions, 0 deletions
diff --git a/fpdfsdk/fpdfeditpath.cpp b/fpdfsdk/fpdfeditpath.cpp
index 164ab7015f..a91dfdb421 100644
--- a/fpdfsdk/fpdfeditpath.cpp
+++ b/fpdfsdk/fpdfeditpath.cpp
@@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include <vector>
+
#include "public/fpdf_edit.h"
#include "core/fpdfapi/page/cpdf_path.h"
@@ -26,6 +28,13 @@ static_assert(CFX_GraphStateData::LineJoinRound == FPDF_LINEJOIN_ROUND,
static_assert(CFX_GraphStateData::LineJoinBevel == FPDF_LINEJOIN_BEVEL,
"CFX_GraphStateData::LineJoinBevel value mismatch");
+static_assert(static_cast<int>(FXPT_TYPE::LineTo) == FPDF_SEGMENT_LINETO,
+ "FXPT_TYPE::LineTo value mismatch");
+static_assert(static_cast<int>(FXPT_TYPE::BezierTo) == FPDF_SEGMENT_BEZIERTO,
+ "FXPT_TYPE::BezierTo value mismatch");
+static_assert(static_cast<int>(FXPT_TYPE::MoveTo) == FPDF_SEGMENT_MOVETO,
+ "FXPT_TYPE::MoveTo value mismatch");
+
FPDF_EXPORT FPDF_PAGEOBJECT FPDF_CALLCONV FPDFPageObj_CreateNewPath(float x,
float y) {
auto pPathObj = pdfium::MakeUnique<CPDF_PathObject>();
@@ -125,6 +134,16 @@ FPDF_EXPORT int FPDF_CALLCONV FPDFPath_CountPoint(FPDF_PAGEOBJECT path) {
return pdfium::CollectionSize<int>(pPathObj->m_Path.GetPoints());
}
+FPDF_EXPORT FPDF_PATHSEGMENT FPDF_CALLCONV
+FPDFPath_GetPathSegment(FPDF_PAGEOBJECT path, int index) {
+ auto* pPathObj = CPDFPathObjectFromFPDFPageObject(path);
+ if (!pPathObj)
+ return nullptr;
+
+ const std::vector<FX_PATHPOINT>& points = pPathObj->m_Path.GetPoints();
+ return pdfium::IndexInBounds(points, index) ? &points[index] : nullptr;
+}
+
FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFPath_MoveTo(FPDF_PAGEOBJECT path,
float x,
float y) {
@@ -229,3 +248,30 @@ FPDF_EXPORT void FPDF_CALLCONV FPDFPath_SetLineCap(FPDF_PAGEOBJECT path,
pPathObj->m_GraphState.SetLineCap(lineCap);
pPathObj->SetDirty(true);
}
+
+FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV
+FPDFPathSegment_GetPoint(FPDF_PATHSEGMENT segment, float* x, float* y) {
+ auto* pPathPoint = FXPathPointFromFPDFPathSegment(segment);
+ if (!pPathPoint || !x || !y)
+ return false;
+
+ *x = pPathPoint->m_Point.x;
+ *y = pPathPoint->m_Point.y;
+
+ return true;
+}
+
+FPDF_EXPORT int FPDF_CALLCONV
+FPDFPathSegment_GetType(FPDF_PATHSEGMENT segment) {
+ auto* pPathPoint = FXPathPointFromFPDFPathSegment(segment);
+
+ return pPathPoint ? static_cast<int>(pPathPoint->m_Type)
+ : FPDF_SEGMENT_UNKNOWN;
+}
+
+FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV
+FPDFPathSegment_GetClose(FPDF_PATHSEGMENT segment) {
+ auto* pPathPoint = FXPathPointFromFPDFPathSegment(segment);
+
+ return pPathPoint ? pPathPoint->m_CloseFigure : false;
+}