summaryrefslogtreecommitdiff
path: root/fxjs
diff options
context:
space:
mode:
Diffstat (limited to 'fxjs')
-rw-r--r--fxjs/cjx_node.cpp29
-rw-r--r--fxjs/cjx_node.h5
2 files changed, 14 insertions, 20 deletions
diff --git a/fxjs/cjx_node.cpp b/fxjs/cjx_node.cpp
index e207ae488d..ac93397b77 100644
--- a/fxjs/cjx_node.cpp
+++ b/fxjs/cjx_node.cpp
@@ -303,11 +303,12 @@ pdfium::Optional<WideString> CJX_Node::TryAttribute(XFA_Attribute eAttr,
return {wsValue};
}
case XFA_AttributeType::Measure: {
- CXFA_Measurement mValue;
- if (!TryMeasure(pAttr->eName, mValue, bUseDefault))
+ pdfium::Optional<CXFA_Measurement> value =
+ TryMeasure(pAttr->eName, bUseDefault);
+ if (!value)
return {};
- return {mValue.ToString()};
+ return {value->ToString()};
}
default:
break;
@@ -3072,30 +3073,24 @@ bool CJX_Node::SetMeasure(XFA_Attribute eAttr,
return true;
}
-bool CJX_Node::TryMeasure(XFA_Attribute eAttr,
- CXFA_Measurement& mValue,
- bool bUseDefault) const {
+pdfium::Optional<CXFA_Measurement> CJX_Node::TryMeasure(
+ XFA_Attribute eAttr,
+ bool bUseDefault) const {
void* pKey = GetMapKey_Element(GetXFANode()->GetElementType(), eAttr);
void* pValue;
int32_t iBytes;
if (GetMapModuleBuffer(pKey, pValue, iBytes, true) &&
- iBytes == sizeof(mValue)) {
- memcpy(&mValue, pValue, sizeof(mValue));
- return true;
+ iBytes == sizeof(CXFA_Measurement)) {
+ return {*reinterpret_cast<CXFA_Measurement*>(pValue)};
}
if (!bUseDefault)
- return false;
+ return {};
- pdfium::Optional<CXFA_Measurement> measure =
- GetXFANode()->GetDefaultMeasurement(eAttr);
- if (measure)
- mValue = *measure;
- return !!measure;
+ return GetXFANode()->GetDefaultMeasurement(eAttr);
}
CXFA_Measurement CJX_Node::GetMeasure(XFA_Attribute eAttr) const {
- CXFA_Measurement mValue;
- return TryMeasure(eAttr, mValue, true) ? mValue : CXFA_Measurement();
+ return TryMeasure(eAttr, true).value_or(CXFA_Measurement());
}
WideString CJX_Node::GetCData(XFA_Attribute eAttr) {
diff --git a/fxjs/cjx_node.h b/fxjs/cjx_node.h
index 8cf167938c..cb6b6867fd 100644
--- a/fxjs/cjx_node.h
+++ b/fxjs/cjx_node.h
@@ -92,9 +92,8 @@ class CJX_Node : public CJX_Object {
bool SetBoolean(XFA_Attribute eAttr, bool bValue, bool bNotify);
bool GetBoolean(XFA_Attribute eAttr);
- bool TryMeasure(XFA_Attribute eAttr,
- CXFA_Measurement& mValue,
- bool bUseDefault) const;
+ pdfium::Optional<CXFA_Measurement> TryMeasure(XFA_Attribute eAttr,
+ bool bUseDefault) const;
bool SetMeasure(XFA_Attribute eAttr, CXFA_Measurement mValue, bool bNotify);
CXFA_Measurement GetMeasure(XFA_Attribute eAttr) const;