summaryrefslogtreecommitdiff
path: root/xfa/fxfa/parser
diff options
context:
space:
mode:
authorDan Sinclair <dsinclair@chromium.org>2017-11-16 14:19:47 +0000
committerChromium commit bot <commit-bot@chromium.org>2017-11-16 14:19:47 +0000
commitce7ccd5f638eff42c6c79da682061fa2c39b028f (patch)
treec150e99f3c7ffb4e2d611e33aba743b43d718ac9 /xfa/fxfa/parser
parent8873a4dffed0ae3ccd961ada58c588f92b210bf2 (diff)
downloadpdfium-ce7ccd5f638eff42c6c79da682061fa2c39b028f.tar.xz
Convert CJX_Node::TryMeasure to pdfium::Optional
This CL converts TryMeasure to return a pdfium::Optional instead of a bool with an out parameter. Change-Id: I6e92e53aa0eaa7a6b855253061acca8a59db49fd Reviewed-on: https://pdfium-review.googlesource.com/18550 Commit-Queue: dsinclair <dsinclair@chromium.org> Reviewed-by: Tom Sepez <tsepez@chromium.org>
Diffstat (limited to 'xfa/fxfa/parser')
-rw-r--r--xfa/fxfa/parser/cxfa_boxdata.cpp24
-rw-r--r--xfa/fxfa/parser/cxfa_captiondata.cpp6
-rw-r--r--xfa/fxfa/parser/cxfa_datadata.cpp13
-rw-r--r--xfa/fxfa/parser/cxfa_fontdata.cpp6
-rw-r--r--xfa/fxfa/parser/cxfa_itemlayoutprocessor.cpp87
-rw-r--r--xfa/fxfa/parser/cxfa_node.cpp5
-rw-r--r--xfa/fxfa/parser/cxfa_paradata.cpp36
-rw-r--r--xfa/fxfa/parser/cxfa_widgetdata.cpp35
8 files changed, 113 insertions, 99 deletions
diff --git a/xfa/fxfa/parser/cxfa_boxdata.cpp b/xfa/fxfa/parser/cxfa_boxdata.cpp
index fb4423ad71..813a0a6229 100644
--- a/xfa/fxfa/parser/cxfa_boxdata.cpp
+++ b/xfa/fxfa/parser/cxfa_boxdata.cpp
@@ -113,13 +113,13 @@ bool CXFA_BoxData::GetStartAngle(float& fStartAngle) const {
if (!m_pNode)
return false;
- CXFA_Measurement ms;
- bool bRet =
- m_pNode->JSNode()->TryMeasure(XFA_Attribute::StartAngle, ms, false);
- if (bRet)
- fStartAngle = ms.GetValue();
+ pdfium::Optional<CXFA_Measurement> measure =
+ m_pNode->JSNode()->TryMeasure(XFA_Attribute::StartAngle, false);
+ if (!measure)
+ return false;
- return bRet;
+ fStartAngle = measure->GetValue();
+ return true;
}
bool CXFA_BoxData::GetSweepAngle(float& fSweepAngle) const {
@@ -127,13 +127,13 @@ bool CXFA_BoxData::GetSweepAngle(float& fSweepAngle) const {
if (!m_pNode)
return false;
- CXFA_Measurement ms;
- bool bRet =
- m_pNode->JSNode()->TryMeasure(XFA_Attribute::SweepAngle, ms, false);
- if (bRet)
- fSweepAngle = ms.GetValue();
+ pdfium::Optional<CXFA_Measurement> measure =
+ m_pNode->JSNode()->TryMeasure(XFA_Attribute::SweepAngle, false);
+ if (!measure)
+ return false;
- return bRet;
+ fSweepAngle = measure->GetValue();
+ return true;
}
CXFA_FillData CXFA_BoxData::GetFillData(bool bModified) const {
diff --git a/xfa/fxfa/parser/cxfa_captiondata.cpp b/xfa/fxfa/parser/cxfa_captiondata.cpp
index db7ca9d875..2045524dd6 100644
--- a/xfa/fxfa/parser/cxfa_captiondata.cpp
+++ b/xfa/fxfa/parser/cxfa_captiondata.cpp
@@ -24,9 +24,9 @@ int32_t CXFA_CaptionData::GetPlacementType() {
}
float CXFA_CaptionData::GetReserve() {
- CXFA_Measurement ms;
- m_pNode->JSNode()->TryMeasure(XFA_Attribute::Reserve, ms, true);
- return ms.ToUnit(XFA_Unit::Pt);
+ return m_pNode->JSNode()
+ ->GetMeasure(XFA_Attribute::Reserve)
+ .ToUnit(XFA_Unit::Pt);
}
CXFA_MarginData CXFA_CaptionData::GetMarginData() {
diff --git a/xfa/fxfa/parser/cxfa_datadata.cpp b/xfa/fxfa/parser/cxfa_datadata.cpp
index 8f41c2f3dd..cf813fc017 100644
--- a/xfa/fxfa/parser/cxfa_datadata.cpp
+++ b/xfa/fxfa/parser/cxfa_datadata.cpp
@@ -68,12 +68,13 @@ XFA_Element CXFA_DataData::GetElementType() const {
bool CXFA_DataData::TryMeasure(XFA_Attribute eAttr,
float& fValue,
bool bUseDefault) const {
- CXFA_Measurement ms;
- if (m_pNode->JSNode()->TryMeasure(eAttr, ms, bUseDefault)) {
- fValue = ms.ToUnit(XFA_Unit::Pt);
- return true;
- }
- return false;
+ pdfium::Optional<CXFA_Measurement> measure =
+ m_pNode->JSNode()->TryMeasure(eAttr, bUseDefault);
+ if (!measure)
+ return false;
+
+ fValue = measure->ToUnit(XFA_Unit::Pt);
+ return true;
}
bool CXFA_DataData::SetMeasure(XFA_Attribute eAttr, float fValue) {
diff --git a/xfa/fxfa/parser/cxfa_fontdata.cpp b/xfa/fxfa/parser/cxfa_fontdata.cpp
index 5ca845f056..b3e23813ea 100644
--- a/xfa/fxfa/parser/cxfa_fontdata.cpp
+++ b/xfa/fxfa/parser/cxfa_fontdata.cpp
@@ -57,9 +57,9 @@ int32_t CXFA_FontData::GetUnderlinePeriod() {
}
float CXFA_FontData::GetFontSize() {
- CXFA_Measurement ms;
- m_pNode->JSNode()->TryMeasure(XFA_Attribute::Size, ms, true);
- return ms.ToUnit(XFA_Unit::Pt);
+ return m_pNode->JSNode()
+ ->GetMeasure(XFA_Attribute::Size)
+ .ToUnit(XFA_Unit::Pt);
}
void CXFA_FontData::GetTypeface(WideString& wsTypeFace) {
diff --git a/xfa/fxfa/parser/cxfa_itemlayoutprocessor.cpp b/xfa/fxfa/parser/cxfa_itemlayoutprocessor.cpp
index bf950ab543..cd6e57ce02 100644
--- a/xfa/fxfa/parser/cxfa_itemlayoutprocessor.cpp
+++ b/xfa/fxfa/parser/cxfa_itemlayoutprocessor.cpp
@@ -86,31 +86,38 @@ CFX_SizeF CalculateContainerSpecifiedSize(CXFA_Node* pFormNode,
*bContainerHeightAutoSize = true;
XFA_Element eType = pFormNode->GetElementType();
- CXFA_Measurement mTmpValue;
+
CFX_SizeF containerSize;
- if ((eType == XFA_Element::Subform || eType == XFA_Element::ExclGroup) &&
- pFormNode->JSNode()->TryMeasure(XFA_Attribute::W, mTmpValue, false) &&
- mTmpValue.GetValue() > XFA_LAYOUT_FLOAT_PERCISION) {
- containerSize.width = mTmpValue.ToUnit(XFA_Unit::Pt);
- *bContainerWidthAutoSize = false;
- }
- if ((eType == XFA_Element::Subform || eType == XFA_Element::ExclGroup) &&
- pFormNode->JSNode()->TryMeasure(XFA_Attribute::H, mTmpValue, false) &&
- mTmpValue.GetValue() > XFA_LAYOUT_FLOAT_PERCISION) {
- containerSize.height = mTmpValue.ToUnit(XFA_Unit::Pt);
- *bContainerHeightAutoSize = false;
- }
- if (*bContainerWidthAutoSize && eType == XFA_Element::Subform &&
- pFormNode->JSNode()->TryMeasure(XFA_Attribute::MaxW, mTmpValue, false) &&
- mTmpValue.GetValue() > XFA_LAYOUT_FLOAT_PERCISION) {
- containerSize.width = mTmpValue.ToUnit(XFA_Unit::Pt);
- *bContainerWidthAutoSize = false;
- }
- if (*bContainerHeightAutoSize && eType == XFA_Element::Subform &&
- pFormNode->JSNode()->TryMeasure(XFA_Attribute::MaxH, mTmpValue, false) &&
- mTmpValue.GetValue() > XFA_LAYOUT_FLOAT_PERCISION) {
- containerSize.height = mTmpValue.ToUnit(XFA_Unit::Pt);
- *bContainerHeightAutoSize = false;
+ if (eType == XFA_Element::Subform || eType == XFA_Element::ExclGroup) {
+ pdfium::Optional<CXFA_Measurement> wValue =
+ pFormNode->JSNode()->TryMeasure(XFA_Attribute::W, false);
+ if (wValue && wValue->GetValue() > XFA_LAYOUT_FLOAT_PERCISION) {
+ containerSize.width = wValue->ToUnit(XFA_Unit::Pt);
+ *bContainerWidthAutoSize = false;
+ }
+
+ pdfium::Optional<CXFA_Measurement> hValue =
+ pFormNode->JSNode()->TryMeasure(XFA_Attribute::H, false);
+ if (hValue && hValue->GetValue() > XFA_LAYOUT_FLOAT_PERCISION) {
+ containerSize.height = hValue->ToUnit(XFA_Unit::Pt);
+ *bContainerHeightAutoSize = false;
+ }
+ }
+
+ if (*bContainerWidthAutoSize && eType == XFA_Element::Subform) {
+ pdfium::Optional<CXFA_Measurement> maxW =
+ pFormNode->JSNode()->TryMeasure(XFA_Attribute::MaxW, false);
+ if (maxW && maxW->GetValue() > XFA_LAYOUT_FLOAT_PERCISION) {
+ containerSize.width = maxW->ToUnit(XFA_Unit::Pt);
+ *bContainerWidthAutoSize = false;
+ }
+
+ pdfium::Optional<CXFA_Measurement> maxH =
+ pFormNode->JSNode()->TryMeasure(XFA_Attribute::MaxH, false);
+ if (maxH && maxH->GetValue() > XFA_LAYOUT_FLOAT_PERCISION) {
+ containerSize.height = maxH->ToUnit(XFA_Unit::Pt);
+ *bContainerHeightAutoSize = false;
+ }
}
return containerSize;
}
@@ -124,29 +131,33 @@ CFX_SizeF CalculateContainerComponentSizeFromContentSize(
const CFX_SizeF& currentContainerSize) {
CFX_SizeF componentSize = currentContainerSize;
CXFA_Node* pMarginNode = pFormNode->GetFirstChildByClass(XFA_Element::Margin);
- CXFA_Measurement mTmpValue;
if (bContainerWidthAutoSize) {
componentSize.width = fContentCalculatedWidth;
if (pMarginNode) {
- if (pMarginNode->JSNode()->TryMeasure(XFA_Attribute::LeftInset, mTmpValue,
- false))
- componentSize.width += mTmpValue.ToUnit(XFA_Unit::Pt);
- if (pMarginNode->JSNode()->TryMeasure(XFA_Attribute::RightInset,
- mTmpValue, false))
- componentSize.width += mTmpValue.ToUnit(XFA_Unit::Pt);
+ pdfium::Optional<CXFA_Measurement> leftInset =
+ pMarginNode->JSNode()->TryMeasure(XFA_Attribute::LeftInset, false);
+ if (leftInset)
+ componentSize.width += leftInset->ToUnit(XFA_Unit::Pt);
+
+ pdfium::Optional<CXFA_Measurement> rightInset =
+ pMarginNode->JSNode()->TryMeasure(XFA_Attribute::RightInset, false);
+ if (rightInset)
+ componentSize.width += rightInset->ToUnit(XFA_Unit::Pt);
}
}
if (bContainerHeightAutoSize) {
componentSize.height = fContentCalculatedHeight;
if (pMarginNode) {
- if (pMarginNode->JSNode()->TryMeasure(XFA_Attribute::TopInset, mTmpValue,
- false))
- componentSize.height += mTmpValue.ToUnit(XFA_Unit::Pt);
- if (pMarginNode->JSNode()->TryMeasure(XFA_Attribute::BottomInset,
- mTmpValue, false)) {
- componentSize.height += mTmpValue.ToUnit(XFA_Unit::Pt);
- }
+ pdfium::Optional<CXFA_Measurement> topInset =
+ pMarginNode->JSNode()->TryMeasure(XFA_Attribute::TopInset, false);
+ if (topInset)
+ componentSize.height += topInset->ToUnit(XFA_Unit::Pt);
+
+ pdfium::Optional<CXFA_Measurement> bottomInset =
+ pMarginNode->JSNode()->TryMeasure(XFA_Attribute::BottomInset, false);
+ if (bottomInset)
+ componentSize.height += bottomInset->ToUnit(XFA_Unit::Pt);
}
}
return componentSize;
diff --git a/xfa/fxfa/parser/cxfa_node.cpp b/xfa/fxfa/parser/cxfa_node.cpp
index 465529e777..6ec3b98f7b 100644
--- a/xfa/fxfa/parser/cxfa_node.cpp
+++ b/xfa/fxfa/parser/cxfa_node.cpp
@@ -631,8 +631,9 @@ XFA_ATTRIBUTEENUM CXFA_Node::GetIntact() {
}
XFA_VERSION version = m_pDocument->GetCurVersionMode();
if (eParLayout == XFA_ATTRIBUTEENUM_Tb && version < XFA_VERSION_208) {
- CXFA_Measurement measureH;
- if (JSNode()->TryMeasure(XFA_Attribute::H, measureH, false))
+ pdfium::Optional<CXFA_Measurement> measureH =
+ JSNode()->TryMeasure(XFA_Attribute::H, false);
+ if (measureH)
return XFA_ATTRIBUTEENUM_ContentArea;
}
return XFA_ATTRIBUTEENUM_None;
diff --git a/xfa/fxfa/parser/cxfa_paradata.cpp b/xfa/fxfa/parser/cxfa_paradata.cpp
index a04c195ba6..95dc80a934 100644
--- a/xfa/fxfa/parser/cxfa_paradata.cpp
+++ b/xfa/fxfa/parser/cxfa_paradata.cpp
@@ -24,37 +24,37 @@ int32_t CXFA_ParaData::GetVerticalAlign() {
}
float CXFA_ParaData::GetLineHeight() {
- CXFA_Measurement ms;
- m_pNode->JSNode()->TryMeasure(XFA_Attribute::LineHeight, ms, true);
- return ms.ToUnit(XFA_Unit::Pt);
+ return m_pNode->JSNode()
+ ->GetMeasure(XFA_Attribute::LineHeight)
+ .ToUnit(XFA_Unit::Pt);
}
float CXFA_ParaData::GetMarginLeft() {
- CXFA_Measurement ms;
- m_pNode->JSNode()->TryMeasure(XFA_Attribute::MarginLeft, ms, true);
- return ms.ToUnit(XFA_Unit::Pt);
+ return m_pNode->JSNode()
+ ->GetMeasure(XFA_Attribute::MarginLeft)
+ .ToUnit(XFA_Unit::Pt);
}
float CXFA_ParaData::GetMarginRight() {
- CXFA_Measurement ms;
- m_pNode->JSNode()->TryMeasure(XFA_Attribute::MarginRight, ms, true);
- return ms.ToUnit(XFA_Unit::Pt);
+ return m_pNode->JSNode()
+ ->GetMeasure(XFA_Attribute::MarginRight)
+ .ToUnit(XFA_Unit::Pt);
}
float CXFA_ParaData::GetSpaceAbove() {
- CXFA_Measurement ms;
- m_pNode->JSNode()->TryMeasure(XFA_Attribute::SpaceAbove, ms, true);
- return ms.ToUnit(XFA_Unit::Pt);
+ return m_pNode->JSNode()
+ ->GetMeasure(XFA_Attribute::SpaceAbove)
+ .ToUnit(XFA_Unit::Pt);
}
float CXFA_ParaData::GetSpaceBelow() {
- CXFA_Measurement ms;
- m_pNode->JSNode()->TryMeasure(XFA_Attribute::SpaceBelow, ms, true);
- return ms.ToUnit(XFA_Unit::Pt);
+ return m_pNode->JSNode()
+ ->GetMeasure(XFA_Attribute::SpaceBelow)
+ .ToUnit(XFA_Unit::Pt);
}
float CXFA_ParaData::GetTextIndent() {
- CXFA_Measurement ms;
- m_pNode->JSNode()->TryMeasure(XFA_Attribute::TextIndent, ms, true);
- return ms.ToUnit(XFA_Unit::Pt);
+ return m_pNode->JSNode()
+ ->GetMeasure(XFA_Attribute::TextIndent)
+ .ToUnit(XFA_Unit::Pt);
}
diff --git a/xfa/fxfa/parser/cxfa_widgetdata.cpp b/xfa/fxfa/parser/cxfa_widgetdata.cpp
index 5dd680ab8c..e87abd8ff7 100644
--- a/xfa/fxfa/parser/cxfa_widgetdata.cpp
+++ b/xfa/fxfa/parser/cxfa_widgetdata.cpp
@@ -237,11 +237,12 @@ int32_t CXFA_WidgetData::GetAccess() {
}
int32_t CXFA_WidgetData::GetRotate() {
- CXFA_Measurement ms;
- if (!m_pNode->JSNode()->TryMeasure(XFA_Attribute::Rotate, ms, false))
+ pdfium::Optional<CXFA_Measurement> measure =
+ m_pNode->JSNode()->TryMeasure(XFA_Attribute::Rotate, false);
+ if (!measure)
return 0;
- int32_t iRotate = FXSYS_round(ms.GetValue());
+ int32_t iRotate = FXSYS_round(measure->GetValue());
iRotate = XFA_MapRotation(iRotate);
return iRotate / 90 * 90;
}
@@ -1206,23 +1207,23 @@ bool CXFA_WidgetData::GetBarcodeAttribute_ECLevel(int32_t* val) {
}
bool CXFA_WidgetData::GetBarcodeAttribute_ModuleWidth(int32_t* val) {
- CXFA_Measurement mModuleWidthHeight;
- if (GetUIChild()->JSNode()->TryMeasure(XFA_Attribute::ModuleWidth,
- mModuleWidthHeight, true)) {
- *val = static_cast<int32_t>(mModuleWidthHeight.ToUnit(XFA_Unit::Pt));
- return true;
- }
- return false;
+ pdfium::Optional<CXFA_Measurement> moduleWidthHeight =
+ GetUIChild()->JSNode()->TryMeasure(XFA_Attribute::ModuleWidth, true);
+ if (!moduleWidthHeight)
+ return false;
+
+ *val = static_cast<int32_t>(moduleWidthHeight->ToUnit(XFA_Unit::Pt));
+ return true;
}
bool CXFA_WidgetData::GetBarcodeAttribute_ModuleHeight(int32_t* val) {
- CXFA_Measurement mModuleWidthHeight;
- if (GetUIChild()->JSNode()->TryMeasure(XFA_Attribute::ModuleHeight,
- mModuleWidthHeight, true)) {
- *val = static_cast<int32_t>(mModuleWidthHeight.ToUnit(XFA_Unit::Pt));
- return true;
- }
- return false;
+ pdfium::Optional<CXFA_Measurement> moduleWidthHeight =
+ GetUIChild()->JSNode()->TryMeasure(XFA_Attribute::ModuleHeight, true);
+ if (!moduleWidthHeight)
+ return false;
+
+ *val = static_cast<int32_t>(moduleWidthHeight->ToUnit(XFA_Unit::Pt));
+ return true;
}
bool CXFA_WidgetData::GetBarcodeAttribute_PrintChecksum(bool* val) {