diff options
-rw-r--r-- | fxjs/cjx_node.cpp | 29 | ||||
-rw-r--r-- | fxjs/cjx_node.h | 5 | ||||
-rw-r--r-- | xfa/fxfa/parser/cxfa_boxdata.cpp | 24 | ||||
-rw-r--r-- | xfa/fxfa/parser/cxfa_captiondata.cpp | 6 | ||||
-rw-r--r-- | xfa/fxfa/parser/cxfa_datadata.cpp | 13 | ||||
-rw-r--r-- | xfa/fxfa/parser/cxfa_fontdata.cpp | 6 | ||||
-rw-r--r-- | xfa/fxfa/parser/cxfa_itemlayoutprocessor.cpp | 87 | ||||
-rw-r--r-- | xfa/fxfa/parser/cxfa_node.cpp | 5 | ||||
-rw-r--r-- | xfa/fxfa/parser/cxfa_paradata.cpp | 36 | ||||
-rw-r--r-- | xfa/fxfa/parser/cxfa_widgetdata.cpp | 35 |
10 files changed, 127 insertions, 119 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; 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) { |