summaryrefslogtreecommitdiff
path: root/fpdfsdk/fpdf_editpage.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'fpdfsdk/fpdf_editpage.cpp')
-rw-r--r--fpdfsdk/fpdf_editpage.cpp110
1 files changed, 51 insertions, 59 deletions
diff --git a/fpdfsdk/fpdf_editpage.cpp b/fpdfsdk/fpdf_editpage.cpp
index 585e7e1740..d0ff962252 100644
--- a/fpdfsdk/fpdf_editpage.cpp
+++ b/fpdfsdk/fpdf_editpage.cpp
@@ -137,13 +137,14 @@ unsigned int GetUnsignedAlpha(float alpha) {
return static_cast<unsigned int>(alpha * 255.f + 0.5f);
}
-const CPDF_PageObjectList* CPDFPageObjListFromFPDFFormObject(
- FPDF_PAGEOBJECT page_object) {
+CPDF_FormObject* CPDFFormObjectFromFPDFPageObject(FPDF_PAGEOBJECT page_object) {
auto* pPageObj = CPDFPageObjectFromFPDFPageObject(page_object);
- if (!pPageObj)
- return nullptr;
+ return pPageObj ? pPageObj->AsForm() : nullptr;
+}
- CPDF_FormObject* pFormObject = pPageObj->AsForm();
+const CPDF_PageObjectList* CPDFPageObjListFromFPDFFormObject(
+ FPDF_PAGEOBJECT page_object) {
+ CPDF_FormObject* pFormObject = CPDFFormObjectFromFPDFPageObject(page_object);
if (!pFormObject)
return nullptr;
@@ -250,8 +251,8 @@ FPDF_EXPORT void FPDF_CALLCONV FPDFPage_InsertObject(FPDF_PAGE page,
CPDF_Page* pPage = CPDFPageFromFPDFPage(page);
if (!IsPageObject(pPage))
return;
- pPageObj->SetDirty(true);
+ pPageObj->SetDirty(true);
pPage->AppendPageObject(std::move(pPageObjHolder));
CalcBoundingBox(pPageObj);
}
@@ -297,24 +298,24 @@ FPDF_EXPORT void FPDF_CALLCONV FPDFPageObj_Destroy(FPDF_PAGEOBJECT page_obj) {
FPDF_EXPORT int FPDF_CALLCONV
FPDFPageObj_CountMarks(FPDF_PAGEOBJECT page_object) {
- if (!page_object)
+ CPDF_PageObject* pPageObj = CPDFPageObjectFromFPDFPageObject(page_object);
+ if (!pPageObj)
return -1;
- const auto& mark =
- CPDFPageObjectFromFPDFPageObject(page_object)->m_ContentMarks;
- return mark.CountItems();
+ return pPageObj->m_ContentMarks.CountItems();
}
FPDF_EXPORT FPDF_PAGEOBJECTMARK FPDF_CALLCONV
FPDFPageObj_GetMark(FPDF_PAGEOBJECT page_object, unsigned long index) {
- if (!page_object)
+ CPDF_PageObject* pPageObj = CPDFPageObjectFromFPDFPageObject(page_object);
+ if (!pPageObj)
return nullptr;
- auto* mark = &CPDFPageObjectFromFPDFPageObject(page_object)->m_ContentMarks;
- if (index >= mark->CountItems())
+ auto& mark = pPageObj->m_ContentMarks;
+ if (index >= mark.CountItems())
return nullptr;
- return FPDFPageObjectMarkFromCPDFContentMarkItem(mark->GetItem(index));
+ return FPDFPageObjectMarkFromCPDFContentMarkItem(mark.GetItem(index));
}
FPDF_EXPORT FPDF_PAGEOBJECTMARK FPDF_CALLCONV
@@ -323,13 +324,11 @@ FPDFPageObj_AddMark(FPDF_PAGEOBJECT page_object, FPDF_BYTESTRING name) {
if (!pPageObj)
return nullptr;
- auto* mark = &pPageObj->m_ContentMarks;
- mark->AddMark(name);
- unsigned long index = mark->CountItems() - 1;
-
+ auto& mark = pPageObj->m_ContentMarks;
+ mark.AddMark(name);
+ unsigned long index = mark.CountItems() - 1;
pPageObj->SetDirty(true);
-
- return FPDFPageObjectMarkFromCPDFContentMarkItem(mark->GetItem(index));
+ return FPDFPageObjectMarkFromCPDFContentMarkItem(mark.GetItem(index));
}
FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV
@@ -483,10 +482,10 @@ FPDFPageObjMark_GetParamBlobValue(FPDF_PAGEOBJECTMARK mark,
FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV
FPDFPageObj_HasTransparency(FPDF_PAGEOBJECT pageObject) {
- if (!pageObject)
+ CPDF_PageObject* pPageObj = CPDFPageObjectFromFPDFPageObject(pageObject);
+ if (!pPageObj)
return false;
- CPDF_PageObject* pPageObj = CPDFPageObjectFromFPDFPageObject(pageObject);
int blend_type = pPageObj->m_GeneralState.GetBlendType();
if (blend_type != FXDIB_BLEND_NORMAL)
return true;
@@ -598,11 +597,8 @@ FPDFPageObjMark_RemoveParam(FPDF_PAGEOBJECT page_object,
}
FPDF_EXPORT int FPDF_CALLCONV FPDFPageObj_GetType(FPDF_PAGEOBJECT pageObject) {
- if (!pageObject)
- return FPDF_PAGEOBJ_UNKNOWN;
-
CPDF_PageObject* pPageObj = CPDFPageObjectFromFPDFPageObject(pageObject);
- return pPageObj->GetType();
+ return pPageObj ? pPageObj->GetType() : FPDF_PAGEOBJ_UNKNOWN;
}
FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFPage_GenerateContent(FPDF_PAGE page) {
@@ -692,11 +688,11 @@ FPDF_BOOL FPDFPageObj_SetFillColor(FPDF_PAGEOBJECT page_object,
unsigned int G,
unsigned int B,
unsigned int A) {
- if (!page_object || R > 255 || G > 255 || B > 255 || A > 255)
+ CPDF_PageObject* pPageObj = CPDFPageObjectFromFPDFPageObject(page_object);
+ if (!pPageObj || R > 255 || G > 255 || B > 255 || A > 255)
return false;
std::vector<float> rgb = {R / 255.f, G / 255.f, B / 255.f};
- auto* pPageObj = CPDFPageObjectFromFPDFPageObject(page_object);
pPageObj->m_GeneralState.SetFillAlpha(A / 255.f);
pPageObj->m_ColorState.SetFillColor(
CPDF_ColorSpace::GetStockCS(PDFCS_DEVICERGB), rgb);
@@ -728,10 +724,10 @@ FPDFPageObj_GetBounds(FPDF_PAGEOBJECT pageObject,
float* bottom,
float* right,
float* top) {
- if (!pageObject)
+ CPDF_PageObject* pPageObj = CPDFPageObjectFromFPDFPageObject(pageObject);
+ if (!pPageObj)
return false;
- CPDF_PageObject* pPageObj = CPDFPageObjectFromFPDFPageObject(pageObject);
const CFX_FloatRect& bbox = pPageObj->GetRect();
*left = bbox.left;
*bottom = bbox.bottom;
@@ -799,34 +795,38 @@ FPDFPageObj_GetStrokeWidth(FPDF_PAGEOBJECT page_object, float* width) {
FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV
FPDFPageObj_SetLineJoin(FPDF_PAGEOBJECT page_object, int line_join) {
- if (!page_object)
+ auto* pPageObj = CPDFPageObjectFromFPDFPageObject(page_object);
+ if (!pPageObj)
return false;
- if (line_join <
- static_cast<int>(CFX_GraphStateData::LineJoin::LineJoinMiter) ||
- line_join >
- static_cast<int>(CFX_GraphStateData::LineJoin::LineJoinBevel)) {
+
+ constexpr int kLineJoinMiter =
+ static_cast<int>(CFX_GraphStateData::LineJoin::LineJoinMiter);
+ constexpr int kLineJoinBevel =
+ static_cast<int>(CFX_GraphStateData::LineJoin::LineJoinBevel);
+ if (line_join < kLineJoinMiter || line_join > kLineJoinBevel)
return false;
- }
- auto* pPageObj = CPDFPageObjectFromFPDFPageObject(page_object);
- CFX_GraphStateData::LineJoin lineJoin =
- static_cast<CFX_GraphStateData::LineJoin>(line_join);
- pPageObj->m_GraphState.SetLineJoin(lineJoin);
+
+ pPageObj->m_GraphState.SetLineJoin(
+ static_cast<CFX_GraphStateData::LineJoin>(line_join));
pPageObj->SetDirty(true);
return true;
}
FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV
FPDFPageObj_SetLineCap(FPDF_PAGEOBJECT page_object, int line_cap) {
- if (!page_object)
+ auto* pPageObj = CPDFPageObjectFromFPDFPageObject(page_object);
+ if (!pPageObj)
return false;
- if (line_cap < static_cast<int>(CFX_GraphStateData::LineCap::LineCapButt) ||
- line_cap > static_cast<int>(CFX_GraphStateData::LineCap::LineCapSquare)) {
+
+ constexpr int kLineCapButt =
+ static_cast<int>(CFX_GraphStateData::LineCap::LineCapButt);
+ constexpr int kLineCapSquare =
+ static_cast<int>(CFX_GraphStateData::LineCap::LineCapSquare);
+ if (line_cap < kLineCapButt || line_cap > kLineCapSquare)
return false;
- }
- auto* pPageObj = CPDFPageObjectFromFPDFPageObject(page_object);
- CFX_GraphStateData::LineCap lineCap =
- static_cast<CFX_GraphStateData::LineCap>(line_cap);
- pPageObj->m_GraphState.SetLineCap(lineCap);
+
+ pPageObj->m_GraphState.SetLineCap(
+ static_cast<CFX_GraphStateData::LineCap>(line_cap));
pPageObj->SetDirty(true);
return true;
}
@@ -835,10 +835,7 @@ FPDF_EXPORT int FPDF_CALLCONV
FPDFFormObj_CountObjects(FPDF_PAGEOBJECT page_object) {
const CPDF_PageObjectList* pObjectList =
CPDFPageObjListFromFPDFFormObject(page_object);
- if (!pObjectList)
- return -1;
-
- return pObjectList->size();
+ return pObjectList ? pObjectList->size() : -1;
}
FPDF_EXPORT FPDF_PAGEOBJECT FPDF_CALLCONV
@@ -860,12 +857,8 @@ FPDFFormObj_GetMatrix(FPDF_PAGEOBJECT form_object,
double* d,
double* e,
double* f) {
- if (!form_object || !a || !b || !c || !d || !e || !f)
- return false;
-
- auto* pPageObj = CPDFPageObjectFromFPDFPageObject(form_object);
- CPDF_FormObject* pFormObj = pPageObj->AsForm();
- if (!pFormObj)
+ CPDF_FormObject* pFormObj = CPDFFormObjectFromFPDFPageObject(form_object);
+ if (!pFormObj || !a || !b || !c || !d || !e || !f)
return false;
const CFX_Matrix& matrix = pFormObj->form_matrix();
@@ -875,6 +868,5 @@ FPDFFormObj_GetMatrix(FPDF_PAGEOBJECT form_object,
*d = matrix.d;
*e = matrix.e;
*f = matrix.f;
-
return true;
}