summaryrefslogtreecommitdiff
path: root/fpdfsdk
diff options
context:
space:
mode:
authorLei Zhang <thestig@chromium.org>2017-06-19 12:25:54 -0700
committerChromium commit bot <commit-bot@chromium.org>2017-06-19 20:33:38 +0000
commitd3610056e36b9211e9ed3806a3f99a1184e9413e (patch)
treeaf646f11b126a54c2bcb1187e155897882b27b7f /fpdfsdk
parente5749afd07de3b66c02bb76176d145e11f6ced34 (diff)
downloadpdfium-d3610056e36b9211e9ed3806a3f99a1184e9413e.tar.xz
Fix code in fpdf_flatten.cpp that does no make sense.
Fix some nits and simplify code as well. Change-Id: I77c88f211b9ce32f38221d04c067f73818e0e970 Reviewed-on: https://pdfium-review.googlesource.com/6674 Reviewed-by: Nicolás Peña <npm@chromium.org> Reviewed-by: dsinclair <dsinclair@chromium.org> Commit-Queue: Lei Zhang <thestig@chromium.org>
Diffstat (limited to 'fpdfsdk')
-rw-r--r--fpdfsdk/fpdf_flatten.cpp70
-rw-r--r--fpdfsdk/javascript/Document.cpp5
2 files changed, 26 insertions, 49 deletions
diff --git a/fpdfsdk/fpdf_flatten.cpp b/fpdfsdk/fpdf_flatten.cpp
index 914008c1a3..e530553f5a 100644
--- a/fpdfsdk/fpdf_flatten.cpp
+++ b/fpdfsdk/fpdf_flatten.cpp
@@ -29,23 +29,19 @@ enum FPDF_VALUE { TOP, LEFT, RIGHT, BOTTOM };
namespace {
-bool IsValiableRect(CFX_FloatRect rect, CFX_FloatRect rcPage) {
- if (rect.left - rect.right > 0.000001f || rect.bottom - rect.top > 0.000001f)
+bool IsValidRect(const CFX_FloatRect& rect, const CFX_FloatRect& rcPage) {
+ constexpr float kMinSize = 0.000001f;
+ if (rect.IsEmpty() || rect.Width() < kMinSize || rect.Height() < kMinSize)
return false;
- if (rect.left == 0.0f && rect.top == 0.0f && rect.right == 0.0f &&
- rect.bottom == 0.0f)
- return false;
-
- if (!rcPage.IsEmpty()) {
- if (rect.left - rcPage.left < -10.000001f ||
- rect.right - rcPage.right > 10.000001f ||
- rect.top - rcPage.top > 10.000001f ||
- rect.bottom - rcPage.bottom < -10.000001f)
- return false;
- }
+ if (rcPage.IsEmpty())
+ return true;
- return true;
+ constexpr float kMinBorderSize = 10.000001f;
+ return rect.left - rcPage.left >= -kMinBorderSize &&
+ rect.right - rcPage.right <= kMinBorderSize &&
+ rect.top - rcPage.top <= kMinBorderSize &&
+ rect.bottom - rcPage.bottom >= -kMinBorderSize;
}
void GetContentsRect(CPDF_Document* pDoc,
@@ -60,7 +56,7 @@ void GetContentsRect(CPDF_Document* pDoc,
rc.right = pPageObject->m_Right;
rc.bottom = pPageObject->m_Bottom;
rc.top = pPageObject->m_Top;
- if (IsValiableRect(rc, pDict->GetRectFor("MediaBox")))
+ if (IsValidRect(rc, pDict->GetRectFor("MediaBox")))
pRectArray->push_back(rc);
}
}
@@ -77,7 +73,7 @@ void ParserStream(CPDF_Dictionary* pPageDic,
else if (pStream->KeyExist("BBox"))
rect = pStream->GetRectFor("BBox");
- if (IsValiableRect(rect, pPageDic->GetRectFor("MediaBox")))
+ if (IsValidRect(rect, pPageDic->GetRectFor("MediaBox")))
pRectArray->push_back(rect);
pObjectArray->push_back(pStream);
@@ -96,9 +92,8 @@ int ParserAnnots(CPDF_Document* pSourceDoc,
if (!pAnnots)
return FLATTEN_NOTHINGTODO;
- uint32_t dwSize = pAnnots->GetCount();
- for (int i = 0; i < (int)dwSize; i++) {
- CPDF_Dictionary* pAnnotDic = ToDictionary(pAnnots->GetDirectObjectAt(i));
+ for (const auto& pAnnot : *pAnnots) {
+ CPDF_Dictionary* pAnnotDic = ToDictionary(pAnnot->GetDirect());
if (!pAnnotDic)
continue;
@@ -110,15 +105,13 @@ int ParserAnnots(CPDF_Document* pSourceDoc,
if (nAnnotFlag & ANNOTFLAG_HIDDEN)
continue;
- if (nUsage == FLAT_NORMALDISPLAY) {
- if (nAnnotFlag & ANNOTFLAG_INVISIBLE)
- continue;
-
+ bool bParseStream;
+ if (nUsage == FLAT_NORMALDISPLAY)
+ bParseStream = !(nAnnotFlag & ANNOTFLAG_INVISIBLE);
+ else
+ bParseStream = !!(nAnnotFlag & ANNOTFLAG_PRINT);
+ if (bParseStream)
ParserStream(pPageDic, pAnnotDic, pRectArray, pObjectArray);
- } else {
- if (nAnnotFlag & ANNOTFLAG_PRINT)
- ParserStream(pPageDic, pAnnotDic, pRectArray, pObjectArray);
- }
}
return FLATTEN_SUCCESS;
}
@@ -126,10 +119,10 @@ int ParserAnnots(CPDF_Document* pSourceDoc,
float GetMinMaxValue(const std::vector<CFX_FloatRect>& array,
FPDF_TYPE type,
FPDF_VALUE value) {
- size_t nRects = array.size();
- if (nRects <= 0)
+ if (array.empty())
return 0.0f;
+ size_t nRects = array.size();
std::vector<float> pArray(nRects);
switch (value) {
case LEFT:
@@ -149,7 +142,7 @@ float GetMinMaxValue(const std::vector<CFX_FloatRect>& array,
pArray[i] = array[i].bottom;
break;
default:
- // Not reachable.
+ NOTREACHED();
return 0.0f;
}
@@ -330,7 +323,6 @@ DLLEXPORT int STDCALL FPDFPage_Flatten(FPDF_PAGE page, int nFlag) {
pNewOXbjectDic->SetNewFor<CPDF_Name>("Type", "XObject");
pNewOXbjectDic->SetNewFor<CPDF_Name>("Subtype", "Form");
pNewOXbjectDic->SetNewFor<CPDF_Number>("FormType", 1);
- pNewOXbjectDic->SetNewFor<CPDF_Name>("Name", "FRM");
CFX_FloatRect rcBBox = pPageDict->GetRectFor("ArtBox");
pNewOXbjectDic->SetRectFor("BBox", rcBBox);
}
@@ -357,9 +349,8 @@ DLLEXPORT int STDCALL FPDFPage_Flatten(FPDF_PAGE page, int nFlag) {
if (!sAnnotState.IsEmpty()) {
pAPStream = pAPDic->GetStreamFor(sAnnotState);
} else {
- auto it = pAPDic->begin();
- if (it != pAPDic->end()) {
- CPDF_Object* pFirstObj = it->second.get();
+ if (pAPDic->GetCount() > 0) {
+ CPDF_Object* pFirstObj = pAPDic->begin()->second.get();
if (pFirstObj) {
if (pFirstObj->IsReference())
pFirstObj = pFirstObj->GetDirect();
@@ -409,17 +400,8 @@ DLLEXPORT int STDCALL FPDFPage_Flatten(FPDF_PAGE page, int nFlag) {
pAcc->LoadAllData();
CFX_ByteString sStream(pAcc->GetData(), pAcc->GetSize());
CFX_Matrix matrix = pAPDic->GetMatrixFor("Matrix");
- if (matrix.IsIdentity()) {
- matrix.a = 1.0f;
- matrix.b = 0.0f;
- matrix.c = 0.0f;
- matrix.d = 1.0f;
- matrix.e = 0.0f;
- matrix.f = 0.0f;
- }
-
- CFX_ByteString sTemp;
CFX_Matrix m = GetMatrix(rcAnnot, rcStream, matrix);
+ CFX_ByteString sTemp;
sTemp.Format("q %f 0 0 %f %f %f cm /%s Do Q\n", m.a, m.d, m.e, m.f,
sFormName.c_str());
sStream += sTemp;
diff --git a/fpdfsdk/javascript/Document.cpp b/fpdfsdk/javascript/Document.cpp
index 5d5c2b5d6b..d5b075da62 100644
--- a/fpdfsdk/javascript/Document.cpp
+++ b/fpdfsdk/javascript/Document.cpp
@@ -273,11 +273,6 @@ bool Document::exportAsXFDF(CJS_Runtime* pRuntime,
return true;
}
-// Maps a field object in PDF document to a JavaScript variable
-// comment:
-// note: the paremter cName, this is clue how to treat if the cName is not a
-// valiable filed name in this document
-
bool Document::getField(CJS_Runtime* pRuntime,
const std::vector<CJS_Value>& params,
CJS_Value& vRet,