summaryrefslogtreecommitdiff
path: root/xfa/fxfa/parser/cscript_layoutpseudomodel.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'xfa/fxfa/parser/cscript_layoutpseudomodel.cpp')
-rw-r--r--xfa/fxfa/parser/cscript_layoutpseudomodel.cpp98
1 files changed, 35 insertions, 63 deletions
diff --git a/xfa/fxfa/parser/cscript_layoutpseudomodel.cpp b/xfa/fxfa/parser/cscript_layoutpseudomodel.cpp
index 8eeb0ff30f..46db2ca78c 100644
--- a/xfa/fxfa/parser/cscript_layoutpseudomodel.cpp
+++ b/xfa/fxfa/parser/cscript_layoutpseudomodel.cpp
@@ -69,34 +69,27 @@ void CScript_LayoutPseudoModel::HWXY(CFXJSE_Arguments* pArguments,
ThrowParamCountMismatchException(methodName);
return;
}
- CXFA_Node* pNode = nullptr;
+ CXFA_Node* pNode = static_cast<CXFA_Node*>(pArguments->GetObject(0));
+ if (!pNode)
+ return;
+
CFX_WideString wsUnit(L"pt");
- int32_t iIndex = 0;
- if (iLength >= 1) {
- pNode = static_cast<CXFA_Node*>(pArguments->GetObject(0));
- }
if (iLength >= 2) {
CFX_ByteString bsUnit = pArguments->GetUTF8String(1);
- if (!bsUnit.IsEmpty()) {
+ if (!bsUnit.IsEmpty())
wsUnit = CFX_WideString::FromUTF8(bsUnit.AsStringC());
- }
- }
- if (iLength >= 3) {
- iIndex = pArguments->GetInt32(2);
- }
- if (!pNode) {
- return;
}
+
+ int32_t iIndex = iLength >= 3 ? pArguments->GetInt32(2) : 0;
+
CXFA_LayoutProcessor* pDocLayout = m_pDocument->GetDocLayout();
- if (!pDocLayout) {
+ if (!pDocLayout)
return;
- }
- CXFA_Measurement measure;
CXFA_LayoutItem* pLayoutItem = pDocLayout->GetLayoutItem(pNode);
- if (!pLayoutItem) {
+ if (!pLayoutItem)
return;
- }
+
while (iIndex > 0 && pLayoutItem) {
pLayoutItem = pLayoutItem->GetNext();
iIndex--;
@@ -107,6 +100,7 @@ void CScript_LayoutPseudoModel::HWXY(CFXJSE_Arguments* pArguments,
return;
}
+ CXFA_Measurement measure;
CFX_RectF rtRect = pLayoutItem->GetRect(true);
switch (layoutModel) {
case XFA_LAYOUTMODEL_H:
@@ -122,11 +116,10 @@ void CScript_LayoutPseudoModel::HWXY(CFXJSE_Arguments* pArguments,
measure.Set(rtRect.top, XFA_UNIT_Pt);
break;
}
- XFA_UNIT unit = measure.GetUnit(wsUnit.AsStringC());
- float fValue = measure.ToUnit(unit);
+ float fValue =
+ measure.ToUnit(CXFA_Measurement::GetUnitFromString(wsUnit.AsStringC()));
fValue = FXSYS_round(fValue * 1000) / 1000.0f;
- if (pValue)
- pValue->SetFloat(fValue);
+ pValue->SetFloat(fValue);
}
void CScript_LayoutPseudoModel::H(CFXJSE_Arguments* pArguments) {
@@ -167,9 +160,7 @@ void CScript_LayoutPseudoModel::NumberedPageCount(CFXJSE_Arguments* pArguments,
} else {
iPageCount = iPageNum;
}
- CFXJSE_Value* pValue = pArguments->GetReturnValue();
- if (pValue)
- pValue->SetInteger(iPageCount);
+ pArguments->GetReturnValue()->SetInteger(iPageCount);
}
void CScript_LayoutPseudoModel::PageCount(CFXJSE_Arguments* pArguments) {
@@ -202,12 +193,11 @@ void CScript_LayoutPseudoModel::PageSpan(CFXJSE_Arguments* pArguments) {
int32_t iLast = pLayoutItem->GetLast()->GetPage()->GetPageIndex();
int32_t iFirst = pLayoutItem->GetFirst()->GetPage()->GetPageIndex();
int32_t iPageSpan = iLast - iFirst + 1;
- if (pValue)
- pValue->SetInteger(iPageSpan);
+ pValue->SetInteger(iPageSpan);
}
void CScript_LayoutPseudoModel::Page(CFXJSE_Arguments* pArguments) {
- PageImp(pArguments, false);
+ PageInternals(pArguments, false);
}
std::vector<CXFA_Node*> CScript_LayoutPseudoModel::GetObjArray(
@@ -383,16 +373,12 @@ void CScript_LayoutPseudoModel::AbsPageCount(CFXJSE_Arguments* pArguments) {
void CScript_LayoutPseudoModel::AbsPageCountInBatch(
CFXJSE_Arguments* pArguments) {
- CFXJSE_Value* pValue = pArguments->GetReturnValue();
- if (pValue)
- pValue->SetInteger(0);
+ pArguments->GetReturnValue()->SetInteger(0);
}
void CScript_LayoutPseudoModel::SheetCountInBatch(
CFXJSE_Arguments* pArguments) {
- CFXJSE_Value* pValue = pArguments->GetReturnValue();
- if (pValue)
- pValue->SetInteger(0);
+ pArguments->GetReturnValue()->SetInteger(0);
}
void CScript_LayoutPseudoModel::Relayout(CFXJSE_Arguments* pArguments) {
@@ -416,9 +402,7 @@ void CScript_LayoutPseudoModel::AbsPageInBatch(CFXJSE_Arguments* pArguments) {
return;
}
- CFXJSE_Value* pValue = pArguments->GetReturnValue();
- if (pValue)
- pValue->SetInteger(0);
+ pArguments->GetReturnValue()->SetInteger(0);
}
void CScript_LayoutPseudoModel::SheetInBatch(CFXJSE_Arguments* pArguments) {
@@ -427,13 +411,11 @@ void CScript_LayoutPseudoModel::SheetInBatch(CFXJSE_Arguments* pArguments) {
return;
}
- CFXJSE_Value* pValue = pArguments->GetReturnValue();
- if (pValue)
- pValue->SetInteger(0);
+ pArguments->GetReturnValue()->SetInteger(0);
}
void CScript_LayoutPseudoModel::Sheet(CFXJSE_Arguments* pArguments) {
- PageImp(pArguments, true);
+ PageInternals(pArguments, true);
}
void CScript_LayoutPseudoModel::RelayoutPageArea(CFXJSE_Arguments* pArguments) {
@@ -444,43 +426,33 @@ void CScript_LayoutPseudoModel::SheetCount(CFXJSE_Arguments* pArguments) {
}
void CScript_LayoutPseudoModel::AbsPage(CFXJSE_Arguments* pArguments) {
- PageImp(pArguments, true);
+ PageInternals(pArguments, true);
}
-void CScript_LayoutPseudoModel::PageImp(CFXJSE_Arguments* pArguments,
- bool bAbsPage) {
+void CScript_LayoutPseudoModel::PageInternals(CFXJSE_Arguments* pArguments,
+ bool bAbsPage) {
int32_t iLength = pArguments->GetLength();
if (iLength != 1) {
- const wchar_t* methodName;
- if (bAbsPage) {
- methodName = L"absPage";
- } else {
- methodName = L"page";
- }
- ThrowParamCountMismatchException(methodName);
+ ThrowParamCountMismatchException(bAbsPage ? L"absPage" : L"page");
return;
}
- CXFA_Node* pNode = nullptr;
- if (iLength >= 1) {
- pNode = static_cast<CXFA_Node*>(pArguments->GetObject(0));
- }
- int32_t iPage = 0;
+
+ CXFA_Node* pNode = static_cast<CXFA_Node*>(pArguments->GetObject(0));
CFXJSE_Value* pValue = pArguments->GetReturnValue();
- if (!pNode && pValue)
- pValue->SetInteger(iPage);
+ if (!pNode)
+ pValue->SetInteger(0);
CXFA_LayoutProcessor* pDocLayout = m_pDocument->GetDocLayout();
- if (!pDocLayout) {
+ if (!pDocLayout)
return;
- }
+
CXFA_LayoutItem* pLayoutItem = pDocLayout->GetLayoutItem(pNode);
if (!pLayoutItem) {
pValue->SetInteger(-1);
return;
}
- iPage = pLayoutItem->GetFirst()->GetPage()->GetPageIndex();
- if (pValue)
- pValue->SetInteger(bAbsPage ? iPage : iPage + 1);
+ int32_t iPage = pLayoutItem->GetFirst()->GetPage()->GetPageIndex();
+ pValue->SetInteger(bAbsPage ? iPage : iPage + 1);
}
void CScript_LayoutPseudoModel::ThrowSetReadyException() const {