From 36eed87d19e741be9909500c45dd12e50ff6a1ab Mon Sep 17 00:00:00 2001 From: Miklos Vajna Date: Wed, 20 Sep 2017 22:52:43 +0200 Subject: Add FPDFPath_GetPoint() API 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 Reviewed-by: dsinclair --- fpdfsdk/fpdfeditpath.cpp | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) (limited to 'fpdfsdk/fpdfeditpath.cpp') 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 + #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(FXPT_TYPE::LineTo) == FPDF_SEGMENT_LINETO, + "FXPT_TYPE::LineTo value mismatch"); +static_assert(static_cast(FXPT_TYPE::BezierTo) == FPDF_SEGMENT_BEZIERTO, + "FXPT_TYPE::BezierTo value mismatch"); +static_assert(static_cast(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(); @@ -125,6 +134,16 @@ FPDF_EXPORT int FPDF_CALLCONV FPDFPath_CountPoint(FPDF_PAGEOBJECT path) { return pdfium::CollectionSize(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& 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(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; +} -- cgit v1.2.3