summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorwileyrya <wileyrr@gmail.com>2017-05-26 09:26:27 -0500
committerChromium commit bot <commit-bot@chromium.org>2017-05-26 16:16:52 +0000
commit22a237fb403d76d65a254c4f9cf1c1a9d0b22772 (patch)
treeae2888307c024ece316778b3cc7fedca8f4f658a
parent1bbcb35e4e5593998837c832eabf16a91a695387 (diff)
downloadpdfium-22a237fb403d76d65a254c4f9cf1c1a9d0b22772.tar.xz
Add public API for setting LineJoin and LineCap on a path
BUG=pdfium:718 R=npm@chromium.org Change-Id: Icdc1546c87a676a7d05330dece2c5eacd92c0c92 Reviewed-on: https://pdfium-review.googlesource.com/5951 Reviewed-by: Nicolás Peña <npm@chromium.org> Commit-Queue: Nicolás Peña <npm@chromium.org>
-rw-r--r--core/fpdfapi/edit/cpdf_pagecontentgenerator.cpp6
-rw-r--r--core/fxge/ge/cfx_graphstate.cpp6
-rw-r--r--fpdfsdk/fpdfeditpath.cpp29
-rw-r--r--public/fpdf_edit.h17
4 files changed, 56 insertions, 2 deletions
diff --git a/core/fpdfapi/edit/cpdf_pagecontentgenerator.cpp b/core/fpdfapi/edit/cpdf_pagecontentgenerator.cpp
index fe65e5916c..6643035b09 100644
--- a/core/fpdfapi/edit/cpdf_pagecontentgenerator.cpp
+++ b/core/fpdfapi/edit/cpdf_pagecontentgenerator.cpp
@@ -215,6 +215,12 @@ void CPDF_PageContentGenerator::ProcessGraphics(CFX_ByteTextBuf* buf,
float lineWidth = pPageObj->m_GraphState.GetLineWidth();
if (lineWidth != 1.0f)
*buf << lineWidth << " w ";
+ CFX_GraphStateData::LineCap lineCap = pPageObj->m_GraphState.GetLineCap();
+ if (lineCap != CFX_GraphStateData::LineCapButt)
+ *buf << static_cast<int>(lineCap) << " J ";
+ CFX_GraphStateData::LineJoin lineJoin = pPageObj->m_GraphState.GetLineJoin();
+ if (lineJoin != CFX_GraphStateData::LineJoinMiter)
+ *buf << static_cast<int>(lineJoin) << " j ";
GraphicsData graphD;
graphD.fillAlpha = pPageObj->m_GeneralState.GetFillAlpha();
diff --git a/core/fxge/ge/cfx_graphstate.cpp b/core/fxge/ge/cfx_graphstate.cpp
index 54443b9636..ad6b5fc6c7 100644
--- a/core/fxge/ge/cfx_graphstate.cpp
+++ b/core/fxge/ge/cfx_graphstate.cpp
@@ -36,14 +36,16 @@ void CFX_GraphState::SetLineWidth(float width) {
}
CFX_GraphStateData::LineCap CFX_GraphState::GetLineCap() const {
- return m_Ref.GetObject()->m_LineCap;
+ return m_Ref.GetObject() ? m_Ref.GetObject()->m_LineCap
+ : CFX_GraphStateData::LineCapButt;
}
void CFX_GraphState::SetLineCap(CFX_GraphStateData::LineCap cap) {
m_Ref.GetPrivateCopy()->m_LineCap = cap;
}
CFX_GraphStateData::LineJoin CFX_GraphState::GetLineJoin() const {
- return m_Ref.GetObject()->m_LineJoin;
+ return m_Ref.GetObject() ? m_Ref.GetObject()->m_LineJoin
+ : CFX_GraphStateData::LineJoinMiter;
}
void CFX_GraphState::SetLineJoin(CFX_GraphStateData::LineJoin join) {
diff --git a/fpdfsdk/fpdfeditpath.cpp b/fpdfsdk/fpdfeditpath.cpp
index 60117cad32..54937ef91a 100644
--- a/fpdfsdk/fpdfeditpath.cpp
+++ b/fpdfsdk/fpdfeditpath.cpp
@@ -149,3 +149,32 @@ DLLEXPORT FPDF_BOOL FPDFPath_SetDrawMode(FPDF_PAGEOBJECT path,
pPathObj->m_bStroke = stroke != 0;
return true;
}
+
+DLLEXPORT void STDCALL FPDFPath_SetLineJoin(FPDF_PAGEOBJECT path,
+ int line_join) {
+ if (!path)
+ return;
+ if (line_join <
+ static_cast<int>(CFX_GraphStateData::LineJoin::LineJoinMiter) ||
+ line_join >
+ static_cast<int>(CFX_GraphStateData::LineJoin::LineJoinBevel)) {
+ return;
+ }
+ auto* pPathObj = static_cast<CPDF_PageObject*>(path);
+ CFX_GraphStateData::LineJoin lineJoin =
+ static_cast<CFX_GraphStateData::LineJoin>(line_join);
+ pPathObj->m_GraphState.SetLineJoin(lineJoin);
+}
+
+DLLEXPORT void STDCALL FPDFPath_SetLineCap(FPDF_PAGEOBJECT path, int line_cap) {
+ if (!path)
+ return;
+ if (line_cap < static_cast<int>(CFX_GraphStateData::LineCap::LineCapButt) ||
+ line_cap > static_cast<int>(CFX_GraphStateData::LineCap::LineCapSquare)) {
+ return;
+ }
+ auto* pPathObj = static_cast<CPDF_PageObject*>(path);
+ CFX_GraphStateData::LineCap lineCap =
+ static_cast<CFX_GraphStateData::LineCap>(line_cap);
+ pPathObj->m_GraphState.SetLineCap(lineCap);
+}
diff --git a/public/fpdf_edit.h b/public/fpdf_edit.h
index a84b42ab05..47a0e68f5a 100644
--- a/public/fpdf_edit.h
+++ b/public/fpdf_edit.h
@@ -319,6 +319,23 @@ DLLEXPORT FPDF_BOOL FPDFPath_SetStrokeColor(FPDF_PAGEOBJECT path,
// Returns TRUE on success
DLLEXPORT FPDF_BOOL FPDFPath_SetStrokeWidth(FPDF_PAGEOBJECT path, float width);
+// Set the line join of |pageObject|.
+//
+// pageObject - handle to a page object.
+// line_join - line join
+//
+// Line join can be one of following: Miter (0), Round (1), Bevel (2)
+DLLEXPORT void STDCALL FPDFPath_SetLineJoin(FPDF_PAGEOBJECT page,
+ int line_join);
+
+// Set the line cap of |pageObject|.
+//
+// pageObject - handle to a page object.
+// line_cap - line cap
+//
+// Line cap can be one of following: Butt (0), Round (1), Projecting square (2)
+DLLEXPORT void STDCALL FPDFPath_SetLineCap(FPDF_PAGEOBJECT page, int line_cap);
+
// Set the fill RGBA of a path. Range of values: 0 - 255.
//
// path - the handle to the path object.