diff options
Diffstat (limited to 'chromium/third_party/pdfium/xfa/fxfa')
214 files changed, 6871 insertions, 7648 deletions
diff --git a/chromium/third_party/pdfium/xfa/fxfa/DEPS b/chromium/third_party/pdfium/xfa/fxfa/DEPS index 93a9acbc136..97e9f52afa9 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/DEPS +++ b/chromium/third_party/pdfium/xfa/fxfa/DEPS @@ -1,5 +1,8 @@ include_rules = [ '+core/fdrm/crypto', + '+core/fpdfapi/font', + '+core/fpdfapi/page', + '+core/fpdfdoc', '+core/fxcodec', '+fxjs', ] diff --git a/chromium/third_party/pdfium/xfa/fxfa/app/DEPS b/chromium/third_party/pdfium/xfa/fxfa/app/DEPS index 5c72d1d0b2e..f722184c917 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/app/DEPS +++ b/chromium/third_party/pdfium/xfa/fxfa/app/DEPS @@ -1,6 +1,3 @@ include_rules = [ '+core/fdrm/crypto', - '+core/fpdfapi/font', - '+core/fpdfapi/page', - '+core/fpdfdoc', ] diff --git a/chromium/third_party/pdfium/xfa/fxfa/app/cxfa_linkuserdata.cpp b/chromium/third_party/pdfium/xfa/fxfa/app/cxfa_linkuserdata.cpp index 4128cd88220..d657b285395 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/app/cxfa_linkuserdata.cpp +++ b/chromium/third_party/pdfium/xfa/fxfa/app/cxfa_linkuserdata.cpp @@ -6,7 +6,7 @@ #include "xfa/fxfa/app/cxfa_linkuserdata.h" -CXFA_LinkUserData::CXFA_LinkUserData(FX_WCHAR* pszText) +CXFA_LinkUserData::CXFA_LinkUserData(wchar_t* pszText) : m_wsURLContent(pszText) {} CXFA_LinkUserData::~CXFA_LinkUserData() {} diff --git a/chromium/third_party/pdfium/xfa/fxfa/app/cxfa_linkuserdata.h b/chromium/third_party/pdfium/xfa/fxfa/app/cxfa_linkuserdata.h index 852b4676483..a3ccd927124 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/app/cxfa_linkuserdata.h +++ b/chromium/third_party/pdfium/xfa/fxfa/app/cxfa_linkuserdata.h @@ -17,10 +17,10 @@ class CXFA_LinkUserData : public CFX_Retainable { template <typename T, typename... Args> friend CFX_RetainPtr<T> pdfium::MakeRetain(Args&&... args); - const FX_WCHAR* GetLinkURL() const { return m_wsURLContent.c_str(); } + const wchar_t* GetLinkURL() const { return m_wsURLContent.c_str(); } - protected: - explicit CXFA_LinkUserData(FX_WCHAR* pszText); + private: + explicit CXFA_LinkUserData(wchar_t* pszText); ~CXFA_LinkUserData() override; CFX_WideString m_wsURLContent; diff --git a/chromium/third_party/pdfium/xfa/fxfa/app/cxfa_loadercontext.cpp b/chromium/third_party/pdfium/xfa/fxfa/app/cxfa_loadercontext.cpp index 0733c52dfcc..2ac58ba07a1 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/app/cxfa_loadercontext.cpp +++ b/chromium/third_party/pdfium/xfa/fxfa/app/cxfa_loadercontext.cpp @@ -14,8 +14,8 @@ CXFA_LoaderContext::CXFA_LoaderContext() m_fStartLineOffset(0), m_iChar(0), m_iTotalLines(-1), + m_dwFlags(0), m_pXMLNode(nullptr), - m_pNode(nullptr), - m_dwFlags(0) {} + m_pNode(nullptr) {} CXFA_LoaderContext::~CXFA_LoaderContext() {} diff --git a/chromium/third_party/pdfium/xfa/fxfa/app/cxfa_loadercontext.h b/chromium/third_party/pdfium/xfa/fxfa/app/cxfa_loadercontext.h index d8ccdbe7e27..16d9608bace 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/app/cxfa_loadercontext.h +++ b/chromium/third_party/pdfium/xfa/fxfa/app/cxfa_loadercontext.h @@ -22,19 +22,19 @@ class CXFA_LoaderContext { ~CXFA_LoaderContext(); bool m_bSaveLineHeight; - FX_FLOAT m_fWidth; - FX_FLOAT m_fHeight; - FX_FLOAT m_fLastPos; - FX_FLOAT m_fStartLineOffset; + float m_fWidth; + float m_fHeight; + float m_fLastPos; + float m_fStartLineOffset; int32_t m_iChar; int32_t m_iLines; int32_t m_iTotalLines; + uint32_t m_dwFlags; CFDE_XMLNode* m_pXMLNode; CXFA_Node* m_pNode; CFX_RetainPtr<CFDE_CSSComputedStyle> m_pParentStyle; - CFX_ArrayTemplate<FX_FLOAT> m_lineHeights; - uint32_t m_dwFlags; - std::vector<FX_FLOAT> m_BlocksHeight; + std::vector<float> m_lineHeights; + std::vector<float> m_BlocksHeight; }; #endif // XFA_FXFA_APP_CXFA_LOADERCONTEXT_H_ diff --git a/chromium/third_party/pdfium/xfa/fxfa/app/cxfa_pieceline.h b/chromium/third_party/pdfium/xfa/fxfa/app/cxfa_pieceline.h index 3e6bb99876a..87f71fc1924 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/app/cxfa_pieceline.h +++ b/chromium/third_party/pdfium/xfa/fxfa/app/cxfa_pieceline.h @@ -20,7 +20,7 @@ class CXFA_PieceLine { ~CXFA_PieceLine(); std::vector<std::unique_ptr<XFA_TextPiece>> m_textPieces; - CFX_ArrayTemplate<int32_t> m_charCounts; + std::vector<int32_t> m_charCounts; }; #endif // XFA_FXFA_APP_CXFA_PIECELINE_H_ diff --git a/chromium/third_party/pdfium/xfa/fxfa/app/cxfa_textlayout.cpp b/chromium/third_party/pdfium/xfa/fxfa/app/cxfa_textlayout.cpp index 06cbfe0c70b..880bdf45852 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/app/cxfa_textlayout.cpp +++ b/chromium/third_party/pdfium/xfa/fxfa/app/cxfa_textlayout.cpp @@ -11,12 +11,15 @@ #include "third_party/base/ptr_util.h" #include "third_party/base/stl_util.h" +#include "xfa/fde/cfde_brush.h" #include "xfa/fde/cfde_path.h" +#include "xfa/fde/cfde_pen.h" +#include "xfa/fde/cfde_renderdevice.h" #include "xfa/fde/css/cfde_csscomputedstyle.h" #include "xfa/fde/css/cfde_cssstyleselector.h" -#include "xfa/fde/fde_gedevice.h" -#include "xfa/fde/fde_object.h" -#include "xfa/fde/xml/fde_xml_imp.h" +#include "xfa/fde/xml/cfde_xmlelement.h" +#include "xfa/fde/xml/cfde_xmlnode.h" +#include "xfa/fde/xml/cfde_xmltext.h" #include "xfa/fxfa/app/cxfa_linkuserdata.h" #include "xfa/fxfa/app/cxfa_loadercontext.h" #include "xfa/fxfa/app/cxfa_pieceline.h" @@ -26,8 +29,8 @@ #include "xfa/fxfa/app/xfa_ffwidgetacc.h" #include "xfa/fxfa/app/xfa_textpiece.h" #include "xfa/fxfa/parser/cxfa_font.h" +#include "xfa/fxfa/parser/cxfa_node.h" #include "xfa/fxfa/parser/cxfa_para.h" -#include "xfa/fxfa/parser/xfa_object.h" #define XFA_LOADERCNTXTFLG_FILTERSPACE 0x001 @@ -78,8 +81,7 @@ CFDE_XMLNode* CXFA_TextLayout::GetXMLContainerNode() { pXMLChild = pXMLChild->GetNodeItem(CFDE_XMLNode::NextSibling)) { if (pXMLChild->GetType() == FDE_XMLNODE_Element) { CFDE_XMLElement* pXMLElement = static_cast<CFDE_XMLElement*>(pXMLChild); - CFX_WideString wsTag; - pXMLElement->GetLocalTagName(wsTag); + CFX_WideString wsTag = pXMLElement->GetLocalTagName(); if (wsTag == L"body" || wsTag == L"html") { pXMLContainer = pXMLChild; break; @@ -90,9 +92,9 @@ CFDE_XMLNode* CXFA_TextLayout::GetXMLContainerNode() { } std::unique_ptr<CFX_RTFBreak> CXFA_TextLayout::CreateBreak(bool bDefault) { - uint32_t dwStyle = FX_RTFLAYOUTSTYLE_ExpandTab; + uint32_t dwStyle = FX_LAYOUTSTYLE_ExpandTab; if (!bDefault) - dwStyle |= FX_RTFLAYOUTSTYLE_Pagination; + dwStyle |= FX_LAYOUTSTYLE_Pagination; auto pBreak = pdfium::MakeUnique<CFX_RTFBreak>(dwStyle); pBreak->SetLineBreakTolerance(1); @@ -101,11 +103,11 @@ std::unique_ptr<CFX_RTFBreak> CXFA_TextLayout::CreateBreak(bool bDefault) { return pBreak; } -void CXFA_TextLayout::InitBreak(FX_FLOAT fLineWidth) { +void CXFA_TextLayout::InitBreak(float fLineWidth) { CXFA_Font font = m_pTextProvider->GetFontNode(); CXFA_Para para = m_pTextProvider->GetParaNode(); - FX_FLOAT fStart = 0; - FX_FLOAT fStartPos = 0; + float fStart = 0; + float fStartPos = 0; if (para) { CFX_RTFLineAlignment iAlign = CFX_RTFLineAlignment::Left; switch (para.GetHorizontalAlign()) { @@ -135,7 +137,7 @@ void CXFA_TextLayout::InitBreak(FX_FLOAT fLineWidth) { fLineWidth = fStart; fStartPos = fStart; - FX_FLOAT fIndent = para.GetTextIndent(); + float fIndent = para.GetTextIndent(); if (fIndent > 0) fStartPos += fIndent; } @@ -148,7 +150,7 @@ void CXFA_TextLayout::InitBreak(FX_FLOAT fLineWidth) { m_pBreak->SetCharSpace(font.GetLetterSpacing()); } - FX_FLOAT fFontSize = m_textParser.GetFontSize(m_pTextProvider, nullptr); + float fFontSize = m_textParser.GetFontSize(m_pTextProvider, nullptr); m_pBreak->SetFontSize(fFontSize); m_pBreak->SetFont(m_textParser.GetFont(m_pTextProvider, nullptr)); m_pBreak->SetLineBreakTolerance(fFontSize * 0.2f); @@ -156,7 +158,7 @@ void CXFA_TextLayout::InitBreak(FX_FLOAT fLineWidth) { void CXFA_TextLayout::InitBreak(CFDE_CSSComputedStyle* pStyle, FDE_CSSDisplay eDisplay, - FX_FLOAT fLineWidth, + float fLineWidth, CFDE_XMLNode* pXMLNode, CFDE_CSSComputedStyle* pParentStyle) { if (!pStyle) { @@ -185,7 +187,7 @@ void CXFA_TextLayout::InitBreak(CFDE_CSSComputedStyle* pStyle, } m_pBreak->SetAlignment(iAlign); - FX_FLOAT fStart = 0; + float fStart = 0; const FDE_CSSRect* pRect = pStyle->GetMarginWidth(); const FDE_CSSRect* pPaddingRect = pStyle->GetPaddingWidth(); if (pRect) { @@ -215,7 +217,7 @@ void CXFA_TextLayout::InitBreak(CFDE_CSSComputedStyle* pStyle, } } m_pBreak->SetLineBoundary(fStart, fLineWidth); - FX_FLOAT fIndent = pStyle->GetTextIndent().GetValue(); + float fIndent = pStyle->GetTextIndent().GetValue(); if (fIndent > 0) fStart += fIndent; @@ -224,13 +226,10 @@ void CXFA_TextLayout::InitBreak(CFDE_CSSComputedStyle* pStyle, if (!m_pTabstopContext) m_pTabstopContext = pdfium::MakeUnique<CXFA_TextTabstopsContext>(); m_textParser.GetTabstops(pStyle, m_pTabstopContext.get()); - for (int32_t i = 0; i < m_pTabstopContext->m_iTabCount; i++) { - XFA_TABSTOPS* pTab = m_pTabstopContext->m_tabstops.GetDataPtr(i); - m_pBreak->AddPositionedTab(pTab->fTabstops); - } + for (const auto& stop : m_pTabstopContext->m_tabstops) + m_pBreak->AddPositionedTab(stop.fTabstops); } - - FX_FLOAT fFontSize = m_textParser.GetFontSize(m_pTextProvider, pStyle); + float fFontSize = m_textParser.GetFontSize(m_pTextProvider, pStyle); m_pBreak->SetFontSize(fFontSize); m_pBreak->SetLineBreakTolerance(fFontSize * 0.2f); m_pBreak->SetFont(m_textParser.GetFont(m_pTextProvider, pStyle)); @@ -248,12 +247,11 @@ int32_t CXFA_TextLayout::GetText(CFX_WideString& wsText) { return wsText.GetLength(); } -FX_FLOAT CXFA_TextLayout::GetLayoutHeight() { +float CXFA_TextLayout::GetLayoutHeight() { if (!m_pLoader) return 0; - int32_t iCount = m_pLoader->m_lineHeights.GetSize(); - if (iCount == 0 && m_pLoader->m_fWidth > 0) { + if (m_pLoader->m_lineHeights.empty() && m_pLoader->m_fWidth > 0) { CFX_SizeF szMax(m_pLoader->m_fWidth, m_pLoader->m_fHeight); CFX_SizeF szDef; m_pLoader->m_bSaveLineHeight = true; @@ -263,23 +261,23 @@ FX_FLOAT CXFA_TextLayout::GetLayoutHeight() { return szDef.height; } - FX_FLOAT fHeight = m_pLoader->m_fHeight; + float fHeight = m_pLoader->m_fHeight; if (fHeight < 0.1f) { fHeight = 0; - for (int32_t i = 0; i < iCount; i++) - fHeight += m_pLoader->m_lineHeights.ElementAt(i); + for (float value : m_pLoader->m_lineHeights) + fHeight += value; } return fHeight; } -FX_FLOAT CXFA_TextLayout::StartLayout(FX_FLOAT fWidth) { +float CXFA_TextLayout::StartLayout(float fWidth) { if (!m_pLoader) m_pLoader = pdfium::MakeUnique<CXFA_LoaderContext>(); - if (fWidth < 0 || (m_pLoader->m_fWidth > -1 && - FXSYS_fabs(fWidth - m_pLoader->m_fWidth) > 0)) { - m_pLoader->m_lineHeights.RemoveAll(); - m_Blocks.RemoveAll(); + if (fWidth < 0 || + (m_pLoader->m_fWidth > -1 && fabs(fWidth - m_pLoader->m_fWidth) > 0)) { + m_pLoader->m_lineHeights.clear(); + m_Blocks.clear(); Unload(); m_pLoader->m_fStartLineOffset = 0; } @@ -298,14 +296,14 @@ FX_FLOAT CXFA_TextLayout::StartLayout(FX_FLOAT fWidth) { } bool CXFA_TextLayout::DoLayout(int32_t iBlockIndex, - FX_FLOAT& fCalcHeight, - FX_FLOAT fContentAreaHeight, - FX_FLOAT fTextHeight) { + float& fCalcHeight, + float fContentAreaHeight, + float fTextHeight) { if (!m_pLoader) return false; - int32_t iBlockCount = m_Blocks.GetSize(); - FX_FLOAT fHeight = fTextHeight; + int32_t iBlockCount = pdfium::CollectionSize<int32_t>(m_Blocks); + float fHeight = fTextHeight; if (fHeight < 0) fHeight = GetLayoutHeight(); @@ -326,14 +324,13 @@ bool CXFA_TextLayout::DoLayout(int32_t iBlockIndex, } } - FX_FLOAT fLinePos = m_pLoader->m_fStartLineOffset; + float fLinePos = m_pLoader->m_fStartLineOffset; int32_t iLineIndex = 0; if (iBlockCount > 1) { if (iBlockCount >= (iBlockIndex + 1) * 2) { - iLineIndex = m_Blocks.ElementAt(iBlockIndex * 2); + iLineIndex = m_Blocks[iBlockIndex * 2]; } else { - iLineIndex = m_Blocks.ElementAt(iBlockCount - 1) + - m_Blocks.ElementAt(iBlockCount - 2); + iLineIndex = m_Blocks[iBlockCount - 1] + m_Blocks[iBlockCount - 2]; } if (!m_pLoader->m_BlocksHeight.empty()) { for (int32_t i = 0; i < iBlockIndex; i++) @@ -341,21 +338,21 @@ bool CXFA_TextLayout::DoLayout(int32_t iBlockIndex, } } - int32_t iCount = m_pLoader->m_lineHeights.GetSize(); + int32_t iCount = pdfium::CollectionSize<int32_t>(m_pLoader->m_lineHeights); int32_t i = 0; for (i = iLineIndex; i < iCount; i++) { - FX_FLOAT fLineHeight = m_pLoader->m_lineHeights.ElementAt(i); - if ((i == iLineIndex) && (fLineHeight - fContentAreaHeight > 0.001)) { + float fLineHeight = m_pLoader->m_lineHeights[i]; + if (i == iLineIndex && fLineHeight - fContentAreaHeight > 0.001) { fCalcHeight = 0; return true; } if (fLinePos + fLineHeight - fContentAreaHeight > 0.001) { if (iBlockCount >= (iBlockIndex + 1) * 2) { - m_Blocks.SetAt(iBlockIndex * 2, iLineIndex); - m_Blocks.SetAt(iBlockIndex * 2 + 1, i - iLineIndex); + m_Blocks[iBlockIndex * 2] = iLineIndex; + m_Blocks[iBlockIndex * 2 + 1] = i - iLineIndex; } else { - m_Blocks.Add(iLineIndex); - m_Blocks.Add(i - iLineIndex); + m_Blocks.push_back(iLineIndex); + m_Blocks.push_back(i - iLineIndex); } if (i == iLineIndex) { if (fCalcHeight <= fLinePos) { @@ -364,7 +361,7 @@ bool CXFA_TextLayout::DoLayout(int32_t iBlockIndex, (m_pLoader->m_BlocksHeight[iBlockIndex * 2] == iBlockIndex)) { m_pLoader->m_BlocksHeight[iBlockIndex * 2 + 1] = fCalcHeight; } else { - m_pLoader->m_BlocksHeight.push_back((FX_FLOAT)iBlockIndex); + m_pLoader->m_BlocksHeight.push_back((float)iBlockIndex); m_pLoader->m_BlocksHeight.push_back(fCalcHeight); } } @@ -380,7 +377,7 @@ bool CXFA_TextLayout::DoLayout(int32_t iBlockIndex, } int32_t CXFA_TextLayout::CountBlocks() const { - int32_t iCount = m_Blocks.GetSize() / 2; + int32_t iCount = pdfium::CollectionSize<int32_t>(m_Blocks) / 2; return iCount > 0 ? iCount : 1; } @@ -392,7 +389,7 @@ bool CXFA_TextLayout::CalcSize(const CFX_SizeF& minSize, defaultSize.width = 0xFFFF; m_pBreak = CreateBreak(false); - FX_FLOAT fLinePos = 0; + float fLinePos = 0; m_iLines = 0; m_fMaxWidth = 0; Loader(defaultSize, fLinePos, false); @@ -404,7 +401,7 @@ bool CXFA_TextLayout::CalcSize(const CFX_SizeF& minSize, return true; } -bool CXFA_TextLayout::Layout(const CFX_SizeF& size, FX_FLOAT* fHeight) { +bool CXFA_TextLayout::Layout(const CFX_SizeF& size, float* fHeight) { if (size.width < 1) return false; @@ -416,7 +413,7 @@ bool CXFA_TextLayout::Layout(const CFX_SizeF& size, FX_FLOAT* fHeight) { } m_iLines = 0; - FX_FLOAT fLinePos = 0; + float fLinePos = 0; Loader(size, fLinePos, true); UpdateAlign(size.height, fLinePos); m_pTabstopContext.reset(); @@ -433,10 +430,10 @@ bool CXFA_TextLayout::Layout(int32_t iBlock) { m_pLoader->m_iTotalLines = -1; m_iLines = 0; - FX_FLOAT fLinePos = 0; + float fLinePos = 0; CXFA_Node* pNode = nullptr; CFX_SizeF szText(m_pLoader->m_fWidth, m_pLoader->m_fHeight); - int32_t iCount = m_Blocks.GetSize(); + int32_t iCount = pdfium::CollectionSize<int32_t>(m_Blocks); int32_t iBlocksHeightCount = pdfium::CollectionSize<int32_t>(m_pLoader->m_BlocksHeight); iBlocksHeightCount /= 2; @@ -451,7 +448,7 @@ bool CXFA_TextLayout::Layout(int32_t iBlock) { m_pLoader->m_iChar = 0; if (iCount > 1) - m_pLoader->m_iTotalLines = m_Blocks.ElementAt(iBlock * 2 + 1); + m_pLoader->m_iTotalLines = m_Blocks[iBlock * 2 + 1]; Loader(szText, fLinePos, true); if (iCount == 0 && m_pLoader->m_fStartLineOffset < 0.1f) @@ -459,7 +456,7 @@ bool CXFA_TextLayout::Layout(int32_t iBlock) { } else if (m_pTextDataNode) { iBlock *= 2; if (iBlock < iCount - 2) - m_pLoader->m_iTotalLines = m_Blocks.ElementAt(iBlock + 1); + m_pLoader->m_iTotalLines = m_Blocks[iBlock + 1]; m_pBreak->Reset(); if (m_bRichText) { @@ -517,13 +514,14 @@ void CXFA_TextLayout::ItemBlocks(const CFX_RectF& rtText, int32_t iBlockIndex) { if (!m_pLoader) return; - int32_t iCountHeight = m_pLoader->m_lineHeights.GetSize(); + int32_t iCountHeight = + pdfium::CollectionSize<int32_t>(m_pLoader->m_lineHeights); if (iCountHeight == 0) return; bool bEndItem = true; - int32_t iBlockCount = m_Blocks.GetSize(); - FX_FLOAT fLinePos = m_pLoader->m_fStartLineOffset; + int32_t iBlockCount = pdfium::CollectionSize<int32_t>(m_Blocks); + float fLinePos = m_pLoader->m_fStartLineOffset; int32_t iLineIndex = 0; if (iBlockIndex > 0) { int32_t iBlockHeightCount = @@ -540,18 +538,18 @@ void CXFA_TextLayout::ItemBlocks(const CFX_RectF& rtText, int32_t iBlockIndex) { int32_t i = 0; for (i = iLineIndex; i < iCountHeight; i++) { - FX_FLOAT fLineHeight = m_pLoader->m_lineHeights.ElementAt(i); + float fLineHeight = m_pLoader->m_lineHeights[i]; if (fLinePos + fLineHeight - rtText.height > 0.001) { - m_Blocks.Add(iLineIndex); - m_Blocks.Add(i - iLineIndex); + m_Blocks.push_back(iLineIndex); + m_Blocks.push_back(i - iLineIndex); bEndItem = false; break; } fLinePos += fLineHeight; } if (iCountHeight > 0 && (i - iLineIndex) > 0 && bEndItem) { - m_Blocks.Add(iLineIndex); - m_Blocks.Add(i - iLineIndex); + m_Blocks.push_back(iLineIndex); + m_Blocks.push_back(i - iLineIndex); } } @@ -562,8 +560,7 @@ bool CXFA_TextLayout::DrawString(CFX_RenderDevice* pFxDevice, if (!pFxDevice) return false; - std::unique_ptr<CFDE_RenderDevice> pDevice( - new CFDE_RenderDevice(pFxDevice, false)); + auto pDevice = pdfium::MakeUnique<CFDE_RenderDevice>(pFxDevice, false); pDevice->SaveState(); pDevice->SetClipRect(rtClip); @@ -579,12 +576,12 @@ bool CXFA_TextLayout::DrawString(CFX_RenderDevice* pFxDevice, int32_t iCharCount = 0; int32_t iLineStart = 0; int32_t iPieceLines = pdfium::CollectionSize<int32_t>(m_pieceLines); - int32_t iCount = m_Blocks.GetSize(); + int32_t iCount = pdfium::CollectionSize<int32_t>(m_Blocks); if (iCount > 0) { iBlock *= 2; if (iBlock < iCount) { - iLineStart = m_Blocks.ElementAt(iBlock); - iPieceLines = m_Blocks.ElementAt(iBlock + 1); + iLineStart = m_Blocks[iBlock]; + iPieceLines = m_Blocks[iBlock + 1]; } else { iPieceLines = 0; } @@ -605,7 +602,7 @@ bool CXFA_TextLayout::DrawString(CFX_RenderDevice* pFxDevice, pCharPos = FX_Alloc(FXTEXT_CHARPOS, iChars); iCharCount = iChars; } - FXSYS_memset(pCharPos, 0, iCharCount * sizeof(FXTEXT_CHARPOS)); + memset(pCharPos, 0, iCharCount * sizeof(FXTEXT_CHARPOS)); RenderString(pDevice.get(), pSolidBrush.get(), pPieceLine, j, pCharPos, tmDoc2Device); } @@ -619,7 +616,7 @@ bool CXFA_TextLayout::DrawString(CFX_RenderDevice* pFxDevice, return iPieceLines > 0; } -void CXFA_TextLayout::UpdateAlign(FX_FLOAT fHeight, FX_FLOAT fBottom) { +void CXFA_TextLayout::UpdateAlign(float fHeight, float fBottom) { fHeight -= fBottom; if (fHeight < 0.1f) return; @@ -641,7 +638,7 @@ void CXFA_TextLayout::UpdateAlign(FX_FLOAT fHeight, FX_FLOAT fBottom) { } bool CXFA_TextLayout::Loader(const CFX_SizeF& szText, - FX_FLOAT& fLinePos, + float& fLinePos, bool bSavePieces) { GetTextDataNode(); if (!m_pTextDataNode) @@ -665,12 +662,12 @@ bool CXFA_TextLayout::Loader(const CFX_SizeF& szText, void CXFA_TextLayout::LoadText(CXFA_Node* pNode, const CFX_SizeF& szText, - FX_FLOAT& fLinePos, + float& fLinePos, bool bSavePieces) { InitBreak(szText.width); CXFA_Para para = m_pTextProvider->GetParaNode(); - FX_FLOAT fSpaceAbove = 0; + float fSpaceAbove = 0; if (para) { fSpaceAbove = para.GetSpaceAbove(); if (fSpaceAbove < 0.1f) { @@ -693,13 +690,13 @@ void CXFA_TextLayout::LoadText(CXFA_Node* pNode, if (bRet && m_pLoader) m_pLoader->m_pNode = pNode; else - EndBreak(CFX_RTFBreakType::Paragraph, fLinePos, bSavePieces); + EndBreak(CFX_BreakType::Paragraph, fLinePos, bSavePieces); } bool CXFA_TextLayout::LoadRichText( CFDE_XMLNode* pXMLNode, const CFX_SizeF& szText, - FX_FLOAT& fLinePos, + float& fLinePos, const CFX_RetainPtr<CFDE_CSSComputedStyle>& pParentStyle, bool bSavePieces, CFX_RetainPtr<CXFA_LinkUserData> pLinkData, @@ -713,7 +710,7 @@ bool CXFA_TextLayout::LoadRichText( m_textParser.GetParseContextFromMap(pXMLNode); FDE_CSSDisplay eDisplay = FDE_CSSDisplay::None; bool bContentNode = false; - FX_FLOAT fSpaceBelow = 0; + float fSpaceBelow = 0; CFX_RetainPtr<CFDE_CSSComputedStyle> pStyle; CFX_WideString wsName; if (bEndBreak) { @@ -729,7 +726,7 @@ bool CXFA_TextLayout::LoadRichText( bContentNode = true; } else if (pXMLNode->GetType() == FDE_XMLNODE_Element) { pElement = static_cast<CFDE_XMLElement*>(pXMLNode); - pElement->GetLocalTagName(wsName); + wsName = pElement->GetLocalTagName(); } if (wsName == L"ol") { bIsOl = true; @@ -759,9 +756,8 @@ bool CXFA_TextLayout::LoadRichText( } if (wsName == L"a") { - CFX_WideString wsLinkContent; ASSERT(pElement); - pElement->GetString(L"href", wsLinkContent); + CFX_WideString wsLinkContent = pElement->GetString(L"href"); if (!wsLinkContent.IsEmpty()) { pLinkData = pdfium::MakeRetain<CXFA_LinkUserData>( wsLinkContent.GetBuffer(wsLinkContent.GetLength())); @@ -775,7 +771,7 @@ bool CXFA_TextLayout::LoadRichText( bContentNode ? pParentStyle.Get() : pStyle.Get()); CFX_WideString wsText; if (bContentNode && iTabCount == 0) { - static_cast<CFDE_XMLText*>(pXMLNode)->GetText(wsText); + wsText = static_cast<CFDE_XMLText*>(pXMLNode)->GetText(); } else if (wsName == L"br") { wsText = L'\n'; } else if (wsName == L"li") { @@ -856,7 +852,7 @@ bool CXFA_TextLayout::LoadRichText( m_pLoader->m_dwFlags |= XFA_LOADERCNTXTFLG_FILTERSPACE; } if (bCurLi) - EndBreak(CFX_RTFBreakType::Line, fLinePos, bSavePieces); + EndBreak(CFX_BreakType::Line, fLinePos, bSavePieces); } else { if (pContext) eDisplay = pContext->GetDisplay(); @@ -864,9 +860,9 @@ bool CXFA_TextLayout::LoadRichText( if (m_bBlockContinue) { if (pContext && !bContentNode) { - CFX_RTFBreakType dwStatus = (eDisplay == FDE_CSSDisplay::Block) - ? CFX_RTFBreakType::Paragraph - : CFX_RTFBreakType::Piece; + CFX_BreakType dwStatus = (eDisplay == FDE_CSSDisplay::Block) + ? CFX_BreakType::Paragraph + : CFX_BreakType::Piece; EndBreak(dwStatus, fLinePos, bSavePieces); if (eDisplay == FDE_CSSDisplay::Block) { fLinePos += fSpaceBelow; @@ -887,30 +883,29 @@ bool CXFA_TextLayout::LoadRichText( } bool CXFA_TextLayout::AppendChar(const CFX_WideString& wsText, - FX_FLOAT& fLinePos, - FX_FLOAT fSpaceAbove, + float& fLinePos, + float fSpaceAbove, bool bSavePieces) { - CFX_RTFBreakType dwStatus = CFX_RTFBreakType::None; + CFX_BreakType dwStatus = CFX_BreakType::None; int32_t iChar = 0; if (m_pLoader) iChar = m_pLoader->m_iChar; int32_t iLength = wsText.GetLength(); for (int32_t i = iChar; i < iLength; i++) { - FX_WCHAR wch = wsText.GetAt(i); + wchar_t wch = wsText.GetAt(i); if (wch == 0xA0) wch = 0x20; dwStatus = m_pBreak->AppendChar(wch); - if (dwStatus != CFX_RTFBreakType::None && - dwStatus != CFX_RTFBreakType::Piece) { + if (dwStatus != CFX_BreakType::None && dwStatus != CFX_BreakType::Piece) { AppendTextLine(dwStatus, fLinePos, bSavePieces); if (IsEnd(bSavePieces)) { if (m_pLoader) m_pLoader->m_iChar = i; return true; } - if (dwStatus == CFX_RTFBreakType::Paragraph && m_bRichText) + if (dwStatus == CFX_BreakType::Paragraph && m_bRichText) fLinePos += fSpaceAbove; } } @@ -933,9 +928,9 @@ void CXFA_TextLayout::ProcessText(CFX_WideString& wsText) { if (iLen == 0) return; - FX_WCHAR* psz = wsText.GetBuffer(iLen); + wchar_t* psz = wsText.GetBuffer(iLen); int32_t iTrimLeft = 0; - FX_WCHAR wch = 0, wPrev = 0; + wchar_t wch = 0, wPrev = 0; for (int32_t i = 0; i < iLen; i++) { wch = psz[i]; if (wch < 0x20) @@ -950,21 +945,22 @@ void CXFA_TextLayout::ProcessText(CFX_WideString& wsText) { wsText = wsText.Left(iTrimLeft); } -void CXFA_TextLayout::EndBreak(CFX_RTFBreakType dwStatus, - FX_FLOAT& fLinePos, +void CXFA_TextLayout::EndBreak(CFX_BreakType dwStatus, + float& fLinePos, bool bSavePieces) { dwStatus = m_pBreak->EndBreak(dwStatus); - if (dwStatus != CFX_RTFBreakType::None && dwStatus != CFX_RTFBreakType::Piece) + if (dwStatus != CFX_BreakType::None && dwStatus != CFX_BreakType::Piece) AppendTextLine(dwStatus, fLinePos, bSavePieces, true); } void CXFA_TextLayout::DoTabstops(CFDE_CSSComputedStyle* pStyle, CXFA_PieceLine* pPieceLine) { - if (!m_pTabstopContext || m_pTabstopContext->m_iTabCount == 0) - return; if (!pStyle || !pPieceLine) return; + if (!m_pTabstopContext || m_pTabstopContext->m_tabstops.empty()) + return; + int32_t iPieces = pdfium::CollectionSize<int32_t>(pPieceLine->m_textPieces); if (iPieces == 0) return; @@ -972,13 +968,13 @@ void CXFA_TextLayout::DoTabstops(CFDE_CSSComputedStyle* pStyle, XFA_TextPiece* pPiece = pPieceLine->m_textPieces[iPieces - 1].get(); int32_t& iTabstopsIndex = m_pTabstopContext->m_iTabIndex; int32_t iCount = m_textParser.CountTabs(pStyle); - if (iTabstopsIndex > m_pTabstopContext->m_iTabCount - 1) + if (!pdfium::IndexInBounds(m_pTabstopContext->m_tabstops, iTabstopsIndex)) return; if (iCount > 0) { iTabstopsIndex++; m_pTabstopContext->m_bTabstops = true; - FX_FLOAT fRight = 0; + float fRight = 0; if (iPieces > 1) { XFA_TextPiece* p = pPieceLine->m_textPieces[iPieces - 2].get(); fRight = p->rtPiece.right(); @@ -986,11 +982,9 @@ void CXFA_TextLayout::DoTabstops(CFDE_CSSComputedStyle* pStyle, m_pTabstopContext->m_fTabWidth = pPiece->rtPiece.width + pPiece->rtPiece.left - fRight; } else if (iTabstopsIndex > -1) { - FX_FLOAT fLeft = 0; + float fLeft = 0; if (m_pTabstopContext->m_bTabstops) { - XFA_TABSTOPS* pTabstops = - m_pTabstopContext->m_tabstops.GetDataPtr(iTabstopsIndex); - uint32_t dwAlign = pTabstops->dwAlign; + uint32_t dwAlign = m_pTabstopContext->m_tabstops[iTabstopsIndex].dwAlign; if (dwAlign == FX_HashCode_GetW(L"center", false)) { fLeft = pPiece->rtPiece.width / 2.0f; } else if (dwAlign == FX_HashCode_GetW(L"right", false) || @@ -1014,8 +1008,8 @@ void CXFA_TextLayout::DoTabstops(CFDE_CSSComputedStyle* pStyle, } } -void CXFA_TextLayout::AppendTextLine(CFX_RTFBreakType dwStatus, - FX_FLOAT& fLinePos, +void CXFA_TextLayout::AppendTextLine(CFX_BreakType dwStatus, + float& fLinePos, bool bSavePieces, bool bEndBreak) { int32_t iPieces = m_pBreak->CountBreakPieces(); @@ -1030,15 +1024,15 @@ void CXFA_TextLayout::AppendTextLine(CFX_RTFBreakType dwStatus, if (m_pTabstopContext) m_pTabstopContext->Reset(); - FX_FLOAT fLineStep = 0, fBaseLine = 0; + float fLineStep = 0, fBaseLine = 0; int32_t i = 0; for (i = 0; i < iPieces; i++) { - const CFX_RTFPiece* pPiece = m_pBreak->GetBreakPiece(i); + const CFX_BreakPiece* pPiece = m_pBreak->GetBreakPieceUnstable(i); CXFA_TextUserData* pUserData = static_cast<CXFA_TextUserData*>(pPiece->m_pUserData.Get()); if (pUserData) pStyle = pUserData->m_pStyle; - FX_FLOAT fVerScale = pPiece->m_iVerticalScale / 100.0f; + float fVerScale = pPiece->m_iVerticalScale / 100.0f; auto pTP = pdfium::MakeUnique<XFA_TextPiece>(); pTP->iChars = pPiece->m_iChars; @@ -1056,15 +1050,15 @@ void CXFA_TextLayout::AppendTextLine(CFX_RTFBreakType dwStatus, pTP->fFontSize = m_textParser.GetFontSize(m_pTextProvider, pStyle.Get()); pTP->rtPiece.left = pPiece->m_iStartPos / 20000.0f; pTP->rtPiece.width = pPiece->m_iWidth / 20000.0f; - pTP->rtPiece.height = (FX_FLOAT)pPiece->m_iFontSize * fVerScale / 20.0f; - FX_FLOAT fBaseLineTemp = + pTP->rtPiece.height = (float)pPiece->m_iFontSize * fVerScale / 20.0f; + float fBaseLineTemp = m_textParser.GetBaseline(m_pTextProvider, pStyle.Get()); pTP->rtPiece.top = fBaseLineTemp; - FX_FLOAT fLineHeight = m_textParser.GetLineHeight( + float fLineHeight = m_textParser.GetLineHeight( m_pTextProvider, pStyle.Get(), m_iLines == 0, fVerScale); if (fBaseLineTemp > 0) { - FX_FLOAT fLineHeightTmp = fBaseLineTemp + pTP->rtPiece.height; + float fLineHeightTmp = fBaseLineTemp + pTP->rtPiece.height; if (fLineHeight < fLineHeightTmp) fLineHeight = fLineHeightTmp; else @@ -1078,29 +1072,28 @@ void CXFA_TextLayout::AppendTextLine(CFX_RTFBreakType dwStatus, DoTabstops(pStyle.Get(), pPieceLine); } for (const auto& pTP : pPieceLine->m_textPieces) { - FX_FLOAT& fTop = pTP->rtPiece.top; - FX_FLOAT fBaseLineTemp = fTop; + float& fTop = pTP->rtPiece.top; + float fBaseLineTemp = fTop; fTop = fLinePos + fLineStep - pTP->rtPiece.height - fBaseLineTemp; fTop = std::max(0.0f, fTop); } fLinePos += fLineStep + fBaseLine; } else { - FX_FLOAT fLineStep = 0; - FX_FLOAT fLineWidth = 0; + float fLineStep = 0; + float fLineWidth = 0; for (int32_t i = 0; i < iPieces; i++) { - const CFX_RTFPiece* pPiece = m_pBreak->GetBreakPiece(i); + const CFX_BreakPiece* pPiece = m_pBreak->GetBreakPieceUnstable(i); CXFA_TextUserData* pUserData = static_cast<CXFA_TextUserData*>(pPiece->m_pUserData.Get()); if (pUserData) pStyle = pUserData->m_pStyle; - FX_FLOAT fVerScale = pPiece->m_iVerticalScale / 100.0f; - FX_FLOAT fBaseLine = - m_textParser.GetBaseline(m_pTextProvider, pStyle.Get()); - FX_FLOAT fLineHeight = m_textParser.GetLineHeight( + float fVerScale = pPiece->m_iVerticalScale / 100.0f; + float fBaseLine = m_textParser.GetBaseline(m_pTextProvider, pStyle.Get()); + float fLineHeight = m_textParser.GetLineHeight( m_pTextProvider, pStyle.Get(), m_iLines == 0, fVerScale); if (fBaseLine > 0) { - FX_FLOAT fLineHeightTmp = - fBaseLine + (FX_FLOAT)pPiece->m_iFontSize * fVerScale / 20.0f; + float fLineHeightTmp = + fBaseLine + (float)pPiece->m_iFontSize * fVerScale / 20.0f; if (fLineHeight < fLineHeightTmp) { fLineHeight = fLineHeightTmp; } @@ -1111,24 +1104,24 @@ void CXFA_TextLayout::AppendTextLine(CFX_RTFBreakType dwStatus, fLinePos += fLineStep; m_fMaxWidth = std::max(m_fMaxWidth, fLineWidth); if (m_pLoader && m_pLoader->m_bSaveLineHeight) { - FX_FLOAT fHeight = fLinePos - m_pLoader->m_fLastPos; + float fHeight = fLinePos - m_pLoader->m_fLastPos; m_pLoader->m_fLastPos = fLinePos; - m_pLoader->m_lineHeights.Add(fHeight); + m_pLoader->m_lineHeights.push_back(fHeight); } } m_pBreak->ClearBreakPieces(); - if (dwStatus == CFX_RTFBreakType::Paragraph) { + if (dwStatus == CFX_BreakType::Paragraph) { m_pBreak->Reset(); if (!pStyle && bEndBreak) { CXFA_Para para = m_pTextProvider->GetParaNode(); if (para) { - FX_FLOAT fStartPos = para.GetMarginLeft(); - FX_FLOAT fIndent = para.GetTextIndent(); + float fStartPos = para.GetMarginLeft(); + float fIndent = para.GetTextIndent(); if (fIndent > 0) fStartPos += fIndent; - FX_FLOAT fSpaceBelow = para.GetSpaceBelow(); + float fSpaceBelow = para.GetSpaceBelow(); if (fSpaceBelow < 0.1f) fSpaceBelow = 0; @@ -1139,12 +1132,12 @@ void CXFA_TextLayout::AppendTextLine(CFX_RTFBreakType dwStatus, } if (pStyle) { - FX_FLOAT fStart = 0; + float fStart = 0; const FDE_CSSRect* pRect = pStyle->GetMarginWidth(); if (pRect) fStart = pRect->left.GetValue(); - FX_FLOAT fTextIndent = pStyle->GetTextIndent().GetValue(); + float fTextIndent = pStyle->GetTextIndent().GetValue(); if (fTextIndent < 0) fStart -= fTextIndent; @@ -1166,7 +1159,7 @@ void CXFA_TextLayout::RenderString(CFDE_RenderDevice* pDevice, pDevice->DrawString(pBrush, pPiece->pFont, pCharPos, iCount, pPiece->fFontSize, &tmDoc2Device); } - pPieceLine->m_charCounts.Add(iCount); + pPieceLine->m_charCounts.push_back(iCount); } void CXFA_TextLayout::RenderPath(CFDE_RenderDevice* pDevice, @@ -1182,11 +1175,11 @@ void CXFA_TextLayout::RenderPath(CFDE_RenderDevice* pDevice, return; pPen->SetColor(pPiece->dwColor); - std::unique_ptr<CFDE_Path> pPath(new CFDE_Path); + auto pPath = pdfium::MakeUnique<CFDE_Path>(); int32_t iChars = GetDisplayPos(pPiece, pCharPos); if (iChars > 0) { CFX_PointF pt1, pt2; - FX_FLOAT fEndY = pCharPos[0].m_Origin.y + 1.05f; + float fEndY = pCharPos[0].m_Origin.y + 1.05f; if (pPiece->iPeriod == XFA_ATTRIBUTEENUM_Word) { for (int32_t i = 0; i < pPiece->iUnderline; i++) { for (int32_t j = 0; j < iChars; j++) { @@ -1224,10 +1217,11 @@ void CXFA_TextLayout::RenderPath(CFDE_RenderDevice* pDevice, return; } int32_t iCharsTmp = 0; - int32_t iPiecePrev = iPiece, iPieceNext = iPiece; + int32_t iPiecePrev = iPiece; + int32_t iPieceNext = iPiece; while (iPiecePrev > 0) { iPiecePrev--; - iCharsTmp = pPieceLine->m_charCounts.GetAt(iPiecePrev); + iCharsTmp = pPieceLine->m_charCounts[iPiecePrev]; if (iCharsTmp > 0) break; } @@ -1238,15 +1232,15 @@ void CXFA_TextLayout::RenderPath(CFDE_RenderDevice* pDevice, int32_t iPieces = pdfium::CollectionSize<int32_t>(pPieceLine->m_textPieces); while (iPieceNext < iPieces - 1) { iPieceNext++; - iCharsTmp = pPieceLine->m_charCounts.GetAt(iPieceNext); + iCharsTmp = pPieceLine->m_charCounts[iPieceNext]; if (iCharsTmp > 0) break; } if (iCharsTmp == 0) return; - FX_FLOAT fOrgX = 0.0f; - FX_FLOAT fEndX = 0.0f; + float fOrgX = 0.0f; + float fEndX = 0.0f; pPiece = pPieceLine->m_textPieces[iPiecePrev].get(); iChars = GetDisplayPos(pPiece, pCharPos); if (iChars < 1) @@ -1264,7 +1258,7 @@ void CXFA_TextLayout::RenderPath(CFDE_RenderDevice* pDevice, CFX_PointF pt2; pt1.x = fOrgX; pt2.x = fEndX; - FX_FLOAT fEndY = pCharPos[0].m_Origin.y + 1.05f; + float fEndY = pCharPos[0].m_Origin.y + 1.05f; for (int32_t i = 0; i < pPiece->iUnderline; i++) { pt1.y = fEndY; pt2.y = fEndY; diff --git a/chromium/third_party/pdfium/xfa/fxfa/app/cxfa_textlayout.h b/chromium/third_party/pdfium/xfa/fxfa/app/cxfa_textlayout.h index d4d60cf81e6..9bfc9772474 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/app/cxfa_textlayout.h +++ b/chromium/third_party/pdfium/xfa/fxfa/app/cxfa_textlayout.h @@ -37,17 +37,17 @@ class CXFA_TextLayout { ~CXFA_TextLayout(); int32_t GetText(CFX_WideString& wsText); - FX_FLOAT GetLayoutHeight(); - FX_FLOAT StartLayout(FX_FLOAT fWidth = -1); + float GetLayoutHeight(); + float StartLayout(float fWidth = -1); bool DoLayout(int32_t iBlockIndex, - FX_FLOAT& fCalcHeight, - FX_FLOAT fContentAreaHeight = -1, - FX_FLOAT fTextHeight = -1); + float& fCalcHeight, + float fContentAreaHeight = -1, + float fTextHeight = -1); bool CalcSize(const CFX_SizeF& minSize, const CFX_SizeF& maxSize, CFX_SizeF& defaultSize); - bool Layout(const CFX_SizeF& size, FX_FLOAT* fHeight = nullptr); + bool Layout(const CFX_SizeF& size, float* fHeight = nullptr); void ItemBlocks(const CFX_RectF& rtText, int32_t iBlockIndex); bool DrawString(CFX_RenderDevice* pFxDevice, const CFX_Matrix& tmDoc2Device, @@ -60,28 +60,28 @@ class CXFA_TextLayout { } bool m_bHasBlock; - CFX_ArrayTemplate<int32_t> m_Blocks; + std::vector<int32_t> m_Blocks; private: void GetTextDataNode(); CFDE_XMLNode* GetXMLContainerNode(); std::unique_ptr<CFX_RTFBreak> CreateBreak(bool bDefault); - void InitBreak(FX_FLOAT fLineWidth); + void InitBreak(float fLineWidth); void InitBreak(CFDE_CSSComputedStyle* pStyle, FDE_CSSDisplay eDisplay, - FX_FLOAT fLineWidth, + float fLineWidth, CFDE_XMLNode* pXMLNode, CFDE_CSSComputedStyle* pParentStyle = nullptr); bool Loader(const CFX_SizeF& szText, - FX_FLOAT& fLinePos, + float& fLinePos, bool bSavePieces = true); void LoadText(CXFA_Node* pNode, const CFX_SizeF& szText, - FX_FLOAT& fLinePos, + float& fLinePos, bool bSavePieces); bool LoadRichText(CFDE_XMLNode* pXMLNode, const CFX_SizeF& szText, - FX_FLOAT& fLinePos, + float& fLinePos, const CFX_RetainPtr<CFDE_CSSComputedStyle>& pParentStyle, bool bSavePieces, CFX_RetainPtr<CXFA_LinkUserData> pLinkData, @@ -89,17 +89,17 @@ class CXFA_TextLayout { bool bIsOl = false, int32_t iLiCount = 0); bool AppendChar(const CFX_WideString& wsText, - FX_FLOAT& fLinePos, - FX_FLOAT fSpaceAbove, + float& fLinePos, + float fSpaceAbove, bool bSavePieces); - void AppendTextLine(CFX_RTFBreakType dwStatus, - FX_FLOAT& fLinePos, + void AppendTextLine(CFX_BreakType dwStatus, + float& fLinePos, bool bSavePieces, bool bEndBreak = false); - void EndBreak(CFX_RTFBreakType dwStatus, FX_FLOAT& fLinePos, bool bDefault); + void EndBreak(CFX_BreakType dwStatus, float& fLinePos, bool bDefault); bool IsEnd(bool bSavePieces); void ProcessText(CFX_WideString& wsText); - void UpdateAlign(FX_FLOAT fHeight, FX_FLOAT fBottom); + void UpdateAlign(float fHeight, float fBottom); void RenderString(CFDE_RenderDevice* pDevice, CFDE_Brush* pBrush, CXFA_PieceLine* pPieceLine, @@ -126,7 +126,7 @@ class CXFA_TextLayout { std::unique_ptr<CFX_RTFBreak> m_pBreak; std::unique_ptr<CXFA_LoaderContext> m_pLoader; int32_t m_iLines; - FX_FLOAT m_fMaxWidth; + float m_fMaxWidth; CXFA_TextParser m_textParser; std::vector<std::unique_ptr<CXFA_PieceLine>> m_pieceLines; std::unique_ptr<CXFA_TextTabstopsContext> m_pTabstopContext; diff --git a/chromium/third_party/pdfium/xfa/fxfa/app/cxfa_textparsecontext.h b/chromium/third_party/pdfium/xfa/fxfa/app/cxfa_textparsecontext.h index 5ea68e94739..514d5d74783 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/app/cxfa_textparsecontext.h +++ b/chromium/third_party/pdfium/xfa/fxfa/app/cxfa_textparsecontext.h @@ -31,7 +31,7 @@ class CXFA_TextParseContext { CFX_RetainPtr<CFDE_CSSComputedStyle> m_pParentStyle; - protected: + private: std::vector<const CFDE_CSSDeclaration*> decls_; FDE_CSSDisplay m_eDisplay; }; diff --git a/chromium/third_party/pdfium/xfa/fxfa/app/cxfa_textparser.cpp b/chromium/third_party/pdfium/xfa/fxfa/app/cxfa_textparser.cpp index 9759cb219d2..6f394dd5e24 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/app/cxfa_textparser.cpp +++ b/chromium/third_party/pdfium/xfa/fxfa/app/cxfa_textparser.cpp @@ -15,16 +15,18 @@ #include "xfa/fde/css/cfde_cssstyleselector.h" #include "xfa/fde/css/cfde_cssstylesheet.h" #include "xfa/fde/css/fde_css.h" +#include "xfa/fde/xml/cfde_xmlelement.h" +#include "xfa/fde/xml/cfde_xmlnode.h" #include "xfa/fgas/crt/fgas_codepage.h" #include "xfa/fgas/font/cfgas_fontmgr.h" #include "xfa/fxfa/app/cxfa_csstagprovider.h" #include "xfa/fxfa/app/cxfa_textparsecontext.h" #include "xfa/fxfa/app/cxfa_texttabstopscontext.h" #include "xfa/fxfa/app/xfa_ffwidgetacc.h" +#include "xfa/fxfa/cxfa_ffapp.h" +#include "xfa/fxfa/cxfa_ffdoc.h" +#include "xfa/fxfa/cxfa_fontmgr.h" #include "xfa/fxfa/parser/cxfa_measurement.h" -#include "xfa/fxfa/xfa_ffapp.h" -#include "xfa/fxfa/xfa_ffdoc.h" -#include "xfa/fxfa/xfa_fontmgr.h" namespace { @@ -43,21 +45,13 @@ enum class TabStopStatus { CXFA_TextParser::CXFA_TextParser() : m_bParsed(false), m_cssInitialized(false) {} -CXFA_TextParser::~CXFA_TextParser() { - for (auto& pair : m_mapXMLNodeToParseContext) { - if (pair.second) - delete pair.second; - } -} +CXFA_TextParser::~CXFA_TextParser() {} void CXFA_TextParser::Reset() { - for (auto& pair : m_mapXMLNodeToParseContext) { - if (pair.second) - delete pair.second; - } m_mapXMLNodeToParseContext.clear(); m_bParsed = false; } + void CXFA_TextParser::InitCSSData(CXFA_TextProvider* pTextProvider) { if (!pTextProvider) return; @@ -67,12 +61,8 @@ void CXFA_TextParser::InitCSSData(CXFA_TextProvider* pTextProvider) { CFGAS_FontMgr* pFontMgr = pDoc->GetApp()->GetFDEFontMgr(); ASSERT(pFontMgr); m_pSelector = pdfium::MakeUnique<CFDE_CSSStyleSelector>(pFontMgr); - FX_FLOAT fFontSize = 10; CXFA_Font font = pTextProvider->GetFontNode(); - if (font) { - fFontSize = font.GetFontSize(); - } - m_pSelector->SetDefFontSize(fFontSize); + m_pSelector->SetDefFontSize(font ? font.GetFontSize() : 10.0f); } if (m_cssInitialized) @@ -85,7 +75,7 @@ void CXFA_TextParser::InitCSSData(CXFA_TextProvider* pTextProvider) { } std::unique_ptr<CFDE_CSSStyleSheet> CXFA_TextParser::LoadDefaultSheetStyle() { - static const FX_WCHAR s_pStyle[] = + static const wchar_t s_pStyle[] = L"html,body,ol,p,ul{display:block}" L"li{display:list-item}" L"ol,ul{padding-left:33px;margin:1.12em 0}" @@ -106,8 +96,8 @@ CFX_RetainPtr<CFDE_CSSComputedStyle> CXFA_TextParser::CreateRootStyle( CXFA_Font font = pTextProvider->GetFontNode(); CXFA_Para para = pTextProvider->GetParaNode(); auto pStyle = m_pSelector->CreateComputedStyle(nullptr); - FX_FLOAT fLineHeight = 0; - FX_FLOAT fFontSize = 10; + float fLineHeight = 0; + float fFontSize = 10; if (para) { fLineHeight = para.GetLineHeight(); @@ -171,7 +161,7 @@ CFX_RetainPtr<CFDE_CSSComputedStyle> CXFA_TextParser::CreateStyle( return pNewStyle; uint32_t dwDecoration = pParentStyle->GetTextDecoration(); - FX_FLOAT fBaseLine = 0; + float fBaseLine = 0; if (pParentStyle->GetVerticalAlign() == FDE_CSSVerticalAlign::Number) fBaseLine = pParentStyle->GetNumberVerticalAlign(); @@ -191,7 +181,7 @@ CFX_RetainPtr<CFDE_CSSComputedStyle> CXFA_TextParser::ComputeStyle( if (it == m_mapXMLNodeToParseContext.end()) return nullptr; - CXFA_TextParseContext* pContext = it->second; + CXFA_TextParseContext* pContext = it->second.get(); if (!pContext) return nullptr; @@ -231,7 +221,7 @@ void CXFA_TextParser::ParseRichText(CFDE_XMLNode* pXMLNode, CFX_RetainPtr<CFDE_CSSComputedStyle> pNewStyle; if ((tagProvider->GetTagName() != L"body") || (tagProvider->GetTagName() != L"html")) { - CXFA_TextParseContext* pTextContext = new CXFA_TextParseContext; + auto pTextContext = pdfium::MakeUnique<CXFA_TextParseContext>(); FDE_CSSDisplay eDisplay = FDE_CSSDisplay::Inline; if (!tagProvider->m_bContent) { auto declArray = @@ -247,7 +237,7 @@ void CXFA_TextParser::ParseRichText(CFDE_XMLNode* pXMLNode, eDisplay = pNewStyle->GetDisplay(); } pTextContext->SetDisplay(eDisplay); - m_mapXMLNodeToParseContext[pXMLNode] = pTextContext; + m_mapXMLNodeToParseContext[pXMLNode] = std::move(pTextContext); } for (CFDE_XMLNode* pXMLChild = @@ -287,12 +277,11 @@ std::unique_ptr<CXFA_CSSTagProvider> CXFA_TextParser::ParseTagInfo( CFX_WideString wsName; if (pXMLNode->GetType() == FDE_XMLNODE_Element) { CFDE_XMLElement* pXMLElement = static_cast<CFDE_XMLElement*>(pXMLNode); - pXMLElement->GetLocalTagName(wsName); + wsName = pXMLElement->GetLocalTagName(); tagProvider->SetTagName(wsName); tagProvider->m_bTagAvailable = TagValidate(wsName); - CFX_WideString wsValue; - pXMLElement->GetString(L"style", wsValue); + CFX_WideString wsValue = pXMLElement->GetString(L"style"); if (!wsValue.IsEmpty()) tagProvider->SetAttribute(L"style", wsValue); } else if (pXMLNode->GetType() == FDE_XMLNODE_Text) { @@ -307,7 +296,7 @@ int32_t CXFA_TextParser::GetVAlign(CXFA_TextProvider* pTextProvider) const { return para ? para.GetVerticalAlign() : XFA_ATTRIBUTEENUM_Top; } -FX_FLOAT CXFA_TextParser::GetTabInterval(CFDE_CSSComputedStyle* pStyle) const { +float CXFA_TextParser::GetTabInterval(CFDE_CSSComputedStyle* pStyle) const { CFX_WideString wsValue; if (pStyle && pStyle->GetCustomStyle(L"tab-interval", wsValue)) return CXFA_Measurement(wsValue.AsStringC()).ToUnit(XFA_UNIT_Pt); @@ -361,8 +350,8 @@ CFX_RetainPtr<CFGAS_GEFont> CXFA_TextParser::GetFont( return pFontMgr->GetFont(pDoc, wsFamily, dwStyle); } -FX_FLOAT CXFA_TextParser::GetFontSize(CXFA_TextProvider* pTextProvider, - CFDE_CSSComputedStyle* pStyle) const { +float CXFA_TextParser::GetFontSize(CXFA_TextProvider* pTextProvider, + CFDE_CSSComputedStyle* pStyle) const { if (pStyle) return pStyle->GetFontSize(); @@ -383,7 +372,7 @@ int32_t CXFA_TextParser::GetHorScale(CXFA_TextProvider* pTextProvider, while (pXMLNode) { auto it = m_mapXMLNodeToParseContext.find(pXMLNode); if (it != m_mapXMLNodeToParseContext.end()) { - CXFA_TextParseContext* pContext = it->second; + CXFA_TextParseContext* pContext = it->second.get(); if (pContext && pContext->m_pParentStyle && pContext->m_pParentStyle->GetCustomStyle( L"xfa-font-horizontal-scale", wsValue)) { @@ -466,8 +455,8 @@ FX_ARGB CXFA_TextParser::GetColor(CXFA_TextProvider* pTextProvider, return 0xFF000000; } -FX_FLOAT CXFA_TextParser::GetBaseline(CXFA_TextProvider* pTextProvider, - CFDE_CSSComputedStyle* pStyle) const { +float CXFA_TextParser::GetBaseline(CXFA_TextProvider* pTextProvider, + CFDE_CSSComputedStyle* pStyle) const { if (pStyle) { if (pStyle->GetVerticalAlign() == FDE_CSSVerticalAlign::Number) return pStyle->GetNumberVerticalAlign(); @@ -477,18 +466,18 @@ FX_FLOAT CXFA_TextParser::GetBaseline(CXFA_TextProvider* pTextProvider, return 0; } -FX_FLOAT CXFA_TextParser::GetLineHeight(CXFA_TextProvider* pTextProvider, - CFDE_CSSComputedStyle* pStyle, - bool bFirst, - FX_FLOAT fVerScale) const { - FX_FLOAT fLineHeight = 0; +float CXFA_TextParser::GetLineHeight(CXFA_TextProvider* pTextProvider, + CFDE_CSSComputedStyle* pStyle, + bool bFirst, + float fVerScale) const { + float fLineHeight = 0; if (pStyle) fLineHeight = pStyle->GetLineHeight(); else if (CXFA_Para para = pTextProvider->GetParaNode()) fLineHeight = para.GetLineHeight(); if (bFirst) { - FX_FLOAT fFontSize = GetFontSize(pTextProvider, pStyle); + float fFontSize = GetFontSize(pTextProvider, pStyle); if (fLineHeight < 0.1f) fLineHeight = fFontSize; else @@ -510,15 +499,13 @@ bool CXFA_TextParser::GetEmbbedObj(CXFA_TextProvider* pTextProvider, bool bRet = false; if (pXMLNode->GetType() == FDE_XMLNODE_Element) { CFDE_XMLElement* pElement = static_cast<CFDE_XMLElement*>(pXMLNode); - CFX_WideString wsAttr; - pElement->GetString(L"xfa:embed", wsAttr); + CFX_WideString wsAttr = pElement->GetString(L"xfa:embed"); if (wsAttr.IsEmpty()) return false; if (wsAttr.GetAt(0) == L'#') wsAttr.Delete(0); - CFX_WideString ws; - pElement->GetString(L"xfa:embedType", ws); + CFX_WideString ws = pElement->GetString(L"xfa:embedType"); if (ws.IsEmpty()) ws = L"som"; else @@ -528,8 +515,7 @@ bool CXFA_TextParser::GetEmbbedObj(CXFA_TextProvider* pTextProvider, if (!bURI && ws != L"som") return false; - ws.clear(); - pElement->GetString(L"xfa:embedMode", ws); + ws = pElement->GetString(L"xfa:embedMode"); if (ws.IsEmpty()) ws = L"formatted"; else @@ -547,7 +533,7 @@ bool CXFA_TextParser::GetEmbbedObj(CXFA_TextProvider* pTextProvider, CXFA_TextParseContext* CXFA_TextParser::GetParseContextFromMap( CFDE_XMLNode* pXMLNode) { auto it = m_mapXMLNodeToParseContext.find(pXMLNode); - return it != m_mapXMLNodeToParseContext.end() ? it->second : nullptr; + return it != m_mapXMLNodeToParseContext.end() ? it->second.get() : nullptr; } bool CXFA_TextParser::GetTabstops(CFDE_CSSComputedStyle* pStyle, @@ -562,12 +548,12 @@ bool CXFA_TextParser::GetTabstops(CFDE_CSSComputedStyle* pStyle, } int32_t iLength = wsValue.GetLength(); - const FX_WCHAR* pTabStops = wsValue.c_str(); + const wchar_t* pTabStops = wsValue.c_str(); int32_t iCur = 0; int32_t iLast = 0; CFX_WideString wsAlign; TabStopStatus eStatus = TabStopStatus::None; - FX_WCHAR ch; + wchar_t ch; while (iCur < iLength) { ch = pTabStops[iCur]; switch (eStatus) { @@ -618,7 +604,7 @@ bool CXFA_TextParser::GetTabstops(CFDE_CSSComputedStyle* pStyle, if (ch == ' ') { uint32_t dwHashCode = FX_HashCode_GetW(wsAlign.AsStringC(), true); CXFA_Measurement ms(CFX_WideStringC(pTabStops + iLast, iCur - iLast)); - FX_FLOAT fPos = ms.ToUnit(XFA_UNIT_Pt); + float fPos = ms.ToUnit(XFA_UNIT_Pt); pTabstopContext->Append(dwHashCode, fPos); wsAlign.clear(); eStatus = TabStopStatus::None; @@ -633,7 +619,7 @@ bool CXFA_TextParser::GetTabstops(CFDE_CSSComputedStyle* pStyle, if (!wsAlign.IsEmpty()) { uint32_t dwHashCode = FX_HashCode_GetW(wsAlign.AsStringC(), true); CXFA_Measurement ms(CFX_WideStringC(pTabStops + iLast, iCur - iLast)); - FX_FLOAT fPos = ms.ToUnit(XFA_UNIT_Pt); + float fPos = ms.ToUnit(XFA_UNIT_Pt); pTabstopContext->Append(dwHashCode, fPos); } return true; diff --git a/chromium/third_party/pdfium/xfa/fxfa/app/cxfa_textparser.h b/chromium/third_party/pdfium/xfa/fxfa/app/cxfa_textparser.h index 86da502dbf0..29f03a8dea7 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/app/cxfa_textparser.h +++ b/chromium/third_party/pdfium/xfa/fxfa/app/cxfa_textparser.h @@ -43,7 +43,7 @@ class CXFA_TextParser { int32_t GetVAlign(CXFA_TextProvider* pTextProvider) const; - FX_FLOAT GetTabInterval(CFDE_CSSComputedStyle* pStyle) const; + float GetTabInterval(CFDE_CSSComputedStyle* pStyle) const; int32_t CountTabs(CFDE_CSSComputedStyle* pStyle) const; bool IsSpaceRun(CFDE_CSSComputedStyle* pStyle) const; @@ -52,8 +52,8 @@ class CXFA_TextParser { CFX_RetainPtr<CFGAS_GEFont> GetFont(CXFA_TextProvider* pTextProvider, CFDE_CSSComputedStyle* pStyle) const; - FX_FLOAT GetFontSize(CXFA_TextProvider* pTextProvider, - CFDE_CSSComputedStyle* pStyle) const; + float GetFontSize(CXFA_TextProvider* pTextProvider, + CFDE_CSSComputedStyle* pStyle) const; int32_t GetHorScale(CXFA_TextProvider* pTextProvider, CFDE_CSSComputedStyle* pStyle, @@ -70,12 +70,12 @@ class CXFA_TextParser { int32_t& iLinethrough) const; FX_ARGB GetColor(CXFA_TextProvider* pTextProvider, CFDE_CSSComputedStyle* pStyle) const; - FX_FLOAT GetBaseline(CXFA_TextProvider* pTextProvider, - CFDE_CSSComputedStyle* pStyle) const; - FX_FLOAT GetLineHeight(CXFA_TextProvider* pTextProvider, - CFDE_CSSComputedStyle* pStyle, - bool bFirst, - FX_FLOAT fVerScale) const; + float GetBaseline(CXFA_TextProvider* pTextProvider, + CFDE_CSSComputedStyle* pStyle) const; + float GetLineHeight(CXFA_TextProvider* pTextProvider, + CFDE_CSSComputedStyle* pStyle, + bool bFirst, + float fVerScale) const; bool GetEmbbedObj(CXFA_TextProvider* pTextProvider, CFDE_XMLNode* pXMLNode, @@ -94,10 +94,11 @@ class CXFA_TextParser { CFX_RetainPtr<CFDE_CSSComputedStyle> CreateStyle( CFDE_CSSComputedStyle* pParentStyle); - std::unique_ptr<CFDE_CSSStyleSelector> m_pSelector; - std::map<CFDE_XMLNode*, CXFA_TextParseContext*> m_mapXMLNodeToParseContext; bool m_bParsed; bool m_cssInitialized; + std::unique_ptr<CFDE_CSSStyleSelector> m_pSelector; + std::map<CFDE_XMLNode*, std::unique_ptr<CXFA_TextParseContext>> + m_mapXMLNodeToParseContext; }; #endif // XFA_FXFA_APP_CXFA_TEXTPARSER_H_ diff --git a/chromium/third_party/pdfium/xfa/fxfa/app/cxfa_texttabstopscontext.cpp b/chromium/third_party/pdfium/xfa/fxfa/app/cxfa_texttabstopscontext.cpp index 3209603af3b..58ceb21a4b1 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/app/cxfa_texttabstopscontext.cpp +++ b/chromium/third_party/pdfium/xfa/fxfa/app/cxfa_texttabstopscontext.cpp @@ -7,33 +7,21 @@ #include "xfa/fxfa/app/cxfa_texttabstopscontext.h" CXFA_TextTabstopsContext::CXFA_TextTabstopsContext() - : m_iTabCount(0), - m_iTabIndex(-1), - m_bTabstops(false), - m_fTabWidth(0), - m_fLeft(0) {} + : m_iTabIndex(-1), m_bTabstops(false), m_fTabWidth(0), m_fLeft(0) {} CXFA_TextTabstopsContext::~CXFA_TextTabstopsContext() {} -void CXFA_TextTabstopsContext::Append(uint32_t dwAlign, FX_FLOAT fTabstops) { - int32_t i = 0; - for (i = 0; i < m_iTabCount; i++) { - XFA_TABSTOPS* pTabstop = m_tabstops.GetDataPtr(i); - if (fTabstops < pTabstop->fTabstops) { - break; - } - } - m_tabstops.InsertSpaceAt(i, 1); +void CXFA_TextTabstopsContext::Append(uint32_t dwAlign, float fTabstops) { XFA_TABSTOPS tabstop; tabstop.dwAlign = dwAlign; tabstop.fTabstops = fTabstops; - m_tabstops.SetAt(i, tabstop); - m_iTabCount++; + + auto it = std::lower_bound(m_tabstops.begin(), m_tabstops.end(), tabstop); + m_tabstops.insert(it, tabstop); } void CXFA_TextTabstopsContext::RemoveAll() { - m_tabstops.RemoveAll(); - m_iTabCount = 0; + m_tabstops.clear(); } void CXFA_TextTabstopsContext::Reset() { diff --git a/chromium/third_party/pdfium/xfa/fxfa/app/cxfa_texttabstopscontext.h b/chromium/third_party/pdfium/xfa/fxfa/app/cxfa_texttabstopscontext.h index 8fe0e6273f3..9be10dd61d0 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/app/cxfa_texttabstopscontext.h +++ b/chromium/third_party/pdfium/xfa/fxfa/app/cxfa_texttabstopscontext.h @@ -7,11 +7,17 @@ #ifndef XFA_FXFA_APP_CXFA_TEXTTABSTOPSCONTEXT_H_ #define XFA_FXFA_APP_CXFA_TEXTTABSTOPSCONTEXT_H_ +#include <vector> + #include "core/fxcrt/fx_basic.h" struct XFA_TABSTOPS { uint32_t dwAlign; - FX_FLOAT fTabstops; + float fTabstops; + + bool operator<(const XFA_TABSTOPS& that) const { + return fTabstops < that.fTabstops; + } }; class CXFA_TextTabstopsContext { @@ -19,16 +25,15 @@ class CXFA_TextTabstopsContext { CXFA_TextTabstopsContext(); ~CXFA_TextTabstopsContext(); - void Append(uint32_t dwAlign, FX_FLOAT fTabstops); + void Append(uint32_t dwAlign, float fTabstops); void RemoveAll(); void Reset(); - CFX_ArrayTemplate<XFA_TABSTOPS> m_tabstops; - int32_t m_iTabCount; int32_t m_iTabIndex; bool m_bTabstops; - FX_FLOAT m_fTabWidth; - FX_FLOAT m_fLeft; + float m_fTabWidth; + float m_fLeft; + std::vector<XFA_TABSTOPS> m_tabstops; }; #endif // XFA_FXFA_APP_CXFA_TEXTTABSTOPSCONTEXT_H_ diff --git a/chromium/third_party/pdfium/xfa/fxfa/app/cxfa_textuserdata.h b/chromium/third_party/pdfium/xfa/fxfa/app/cxfa_textuserdata.h index b0eff73f2e9..18a20cdc2ad 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/app/cxfa_textuserdata.h +++ b/chromium/third_party/pdfium/xfa/fxfa/app/cxfa_textuserdata.h @@ -21,7 +21,7 @@ class CXFA_TextUserData : public CFX_Retainable { CFX_RetainPtr<CFDE_CSSComputedStyle> m_pStyle; CFX_RetainPtr<CXFA_LinkUserData> m_pLinkData; - protected: + private: explicit CXFA_TextUserData( const CFX_RetainPtr<CFDE_CSSComputedStyle>& pStyle); CXFA_TextUserData(const CFX_RetainPtr<CFDE_CSSComputedStyle>& pStyle, diff --git a/chromium/third_party/pdfium/xfa/fxfa/app/xfa_checksum.cpp b/chromium/third_party/pdfium/xfa/fxfa/app/xfa_checksum.cpp deleted file mode 100644 index 09c42719c11..00000000000 --- a/chromium/third_party/pdfium/xfa/fxfa/app/xfa_checksum.cpp +++ /dev/null @@ -1,271 +0,0 @@ -// Copyright 2014 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#include "xfa/fxfa/xfa_checksum.h" - -#include "core/fdrm/crypto/fx_crypt.h" -#include "third_party/base/ptr_util.h" - -namespace { - -struct FX_BASE64DATA { - uint32_t data1 : 2; - uint32_t data2 : 6; - uint32_t data3 : 4; - uint32_t data4 : 4; - uint32_t data5 : 6; - uint32_t data6 : 2; - uint32_t data7 : 8; -}; - -const FX_CHAR g_FXBase64EncoderMap[64] = { - 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', - 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', - 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', - 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', - '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '+', '/', -}; - -void Base64EncodePiece(const FX_BASE64DATA& src, - int32_t iBytes, - FX_CHAR dst[4]) { - dst[0] = g_FXBase64EncoderMap[src.data2]; - uint32_t b = src.data1 << 4; - if (iBytes > 1) { - b |= src.data4; - } - dst[1] = g_FXBase64EncoderMap[b]; - if (iBytes > 1) { - b = src.data3 << 2; - if (iBytes > 2) { - b |= src.data6; - } - dst[2] = g_FXBase64EncoderMap[b]; - if (iBytes > 2) { - dst[3] = g_FXBase64EncoderMap[src.data5]; - } else { - dst[3] = '='; - } - } else { - dst[2] = dst[3] = '='; - } -} - -int32_t Base64EncodeA(const uint8_t* pSrc, int32_t iSrcLen, FX_CHAR* pDst) { - ASSERT(pSrc); - if (iSrcLen < 1) { - return 0; - } - if (!pDst) { - int32_t iDstLen = iSrcLen / 3 * 4; - if ((iSrcLen % 3) != 0) { - iDstLen += 4; - } - return iDstLen; - } - FX_BASE64DATA srcData; - int32_t iBytes = 3; - FX_CHAR* pDstEnd = pDst; - while (iSrcLen > 0) { - if (iSrcLen > 2) { - ((uint8_t*)&srcData)[0] = *pSrc++; - ((uint8_t*)&srcData)[1] = *pSrc++; - ((uint8_t*)&srcData)[2] = *pSrc++; - iSrcLen -= 3; - } else { - *((uint32_t*)&srcData) = 0; - ((uint8_t*)&srcData)[0] = *pSrc++; - if (iSrcLen > 1) { - ((uint8_t*)&srcData)[1] = *pSrc++; - } - iBytes = iSrcLen; - iSrcLen = 0; - } - Base64EncodePiece(srcData, iBytes, pDstEnd); - pDstEnd += 4; - } - return pDstEnd - pDst; -} - -} // namespace - -CXFA_SAXReaderHandler::CXFA_SAXReaderHandler(CXFA_ChecksumContext* pContext) - : m_pContext(pContext) { - ASSERT(m_pContext); -} -CXFA_SAXReaderHandler::~CXFA_SAXReaderHandler() {} -CXFA_SAXContext* CXFA_SAXReaderHandler::OnTagEnter( - const CFX_ByteStringC& bsTagName, - CFX_SAXItem::Type eType, - uint32_t dwStartPos) { - UpdateChecksum(true); - if (eType != CFX_SAXItem::Type::Tag && - eType != CFX_SAXItem::Type::Instruction) { - return nullptr; - } - m_SAXContext.m_eNode = eType; - CFX_ByteTextBuf& textBuf = m_SAXContext.m_TextBuf; - textBuf << "<"; - if (eType == CFX_SAXItem::Type::Instruction) { - textBuf << "?"; - } - textBuf << bsTagName; - m_SAXContext.m_bsTagName = bsTagName; - return &m_SAXContext; -} - -void CXFA_SAXReaderHandler::OnTagAttribute(CXFA_SAXContext* pTag, - const CFX_ByteStringC& bsAttri, - const CFX_ByteStringC& bsValue) { - if (!pTag) - return; - - pTag->m_TextBuf << " " << bsAttri << "=\"" << bsValue << "\""; -} - -void CXFA_SAXReaderHandler::OnTagBreak(CXFA_SAXContext* pTag) { - if (!pTag) - return; - - pTag->m_TextBuf << ">"; - UpdateChecksum(false); -} - -void CXFA_SAXReaderHandler::OnTagData(CXFA_SAXContext* pTag, - CFX_SAXItem::Type eType, - const CFX_ByteStringC& bsData, - uint32_t dwStartPos) { - if (!pTag) - return; - - CFX_ByteTextBuf& textBuf = pTag->m_TextBuf; - if (eType == CFX_SAXItem::Type::CharData) - textBuf << "<![CDATA["; - - textBuf << bsData; - if (eType == CFX_SAXItem::Type::CharData) - textBuf << "]]>"; -} - -void CXFA_SAXReaderHandler::OnTagClose(CXFA_SAXContext* pTag, - uint32_t dwEndPos) { - if (!pTag) - return; - - CFX_ByteTextBuf& textBuf = pTag->m_TextBuf; - if (pTag->m_eNode == CFX_SAXItem::Type::Instruction) - textBuf << "?>"; - else if (pTag->m_eNode == CFX_SAXItem::Type::Tag) - textBuf << "></" << pTag->m_bsTagName.AsStringC() << ">"; - - UpdateChecksum(false); -} - -void CXFA_SAXReaderHandler::OnTagEnd(CXFA_SAXContext* pTag, - const CFX_ByteStringC& bsTagName, - uint32_t dwEndPos) { - if (!pTag) - return; - - pTag->m_TextBuf << "</" << bsTagName << ">"; - UpdateChecksum(false); -} - -void CXFA_SAXReaderHandler::OnTargetData(CXFA_SAXContext* pTag, - CFX_SAXItem::Type eType, - const CFX_ByteStringC& bsData, - uint32_t dwStartPos) { - if (!pTag && eType != CFX_SAXItem::Type::Comment) - return; - - if (eType == CFX_SAXItem::Type::Comment) { - m_SAXContext.m_TextBuf << "<!--" << bsData << "-->"; - UpdateChecksum(false); - } else { - pTag->m_TextBuf << " " << bsData; - } -} - -void CXFA_SAXReaderHandler::UpdateChecksum(bool bCheckSpace) { - int32_t iLength = m_SAXContext.m_TextBuf.GetLength(); - if (iLength < 1) { - return; - } - uint8_t* pBuffer = m_SAXContext.m_TextBuf.GetBuffer(); - bool bUpdata = true; - if (bCheckSpace) { - bUpdata = false; - for (int32_t i = 0; i < iLength; i++) { - bUpdata = (pBuffer[i] > 0x20); - if (bUpdata) { - break; - } - } - } - if (bUpdata) { - m_pContext->Update(CFX_ByteStringC(pBuffer, iLength)); - } - m_SAXContext.m_TextBuf.Clear(); -} - -CXFA_ChecksumContext::CXFA_ChecksumContext() {} - -CXFA_ChecksumContext::~CXFA_ChecksumContext() {} - -void CXFA_ChecksumContext::StartChecksum() { - FinishChecksum(); - m_pByteContext = pdfium::MakeUnique<CRYPT_sha1_context>(); - CRYPT_SHA1Start(m_pByteContext.get()); - m_bsChecksum.clear(); - m_pSAXReader = pdfium::MakeUnique<CFX_SAXReader>(); -} - -bool CXFA_ChecksumContext::UpdateChecksum( - const CFX_RetainPtr<IFX_SeekableReadStream>& pSrcFile, - FX_FILESIZE offset, - size_t size) { - if (!m_pSAXReader || !pSrcFile) - return false; - - if (size < 1) - size = pSrcFile->GetSize(); - - CXFA_SAXReaderHandler handler(this); - m_pSAXReader->SetHandler(&handler); - if (m_pSAXReader->StartParse( - pSrcFile, (uint32_t)offset, (uint32_t)size, - CFX_SaxParseMode_NotSkipSpace | CFX_SaxParseMode_NotConvert_amp | - CFX_SaxParseMode_NotConvert_lt | CFX_SaxParseMode_NotConvert_gt | - CFX_SaxParseMode_NotConvert_sharp) < 0) { - return false; - } - return m_pSAXReader->ContinueParse(nullptr) > 99; -} - -void CXFA_ChecksumContext::FinishChecksum() { - m_pSAXReader.reset(); - if (m_pByteContext) { - uint8_t digest[20]; - FXSYS_memset(digest, 0, 20); - CRYPT_SHA1Finish(m_pByteContext.get(), digest); - int32_t nLen = Base64EncodeA(digest, 20, nullptr); - FX_CHAR* pBuffer = m_bsChecksum.GetBuffer(nLen); - Base64EncodeA(digest, 20, pBuffer); - m_bsChecksum.ReleaseBuffer(nLen); - m_pByteContext.reset(); - } -} - -CFX_ByteString CXFA_ChecksumContext::GetChecksum() const { - return m_bsChecksum; -} - -void CXFA_ChecksumContext::Update(const CFX_ByteStringC& bsText) { - if (!m_pByteContext) - return; - - CRYPT_SHA1Update(m_pByteContext.get(), bsText.raw_str(), bsText.GetLength()); -} diff --git a/chromium/third_party/pdfium/xfa/fxfa/app/xfa_ffbarcode.cpp b/chromium/third_party/pdfium/xfa/fxfa/app/xfa_ffbarcode.cpp index b136b8da5a5..72adb3c96b1 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/app/xfa_ffbarcode.cpp +++ b/chromium/third_party/pdfium/xfa/fxfa/app/xfa_ffbarcode.cpp @@ -13,8 +13,8 @@ #include "xfa/fxfa/app/xfa_fffield.h" #include "xfa/fxfa/app/xfa_fftextedit.h" #include "xfa/fxfa/app/xfa_fwladapter.h" -#include "xfa/fxfa/xfa_ffpageview.h" -#include "xfa/fxfa/xfa_ffwidget.h" +#include "xfa/fxfa/cxfa_ffpageview.h" +#include "xfa/fxfa/cxfa_ffwidget.h" namespace { @@ -174,9 +174,9 @@ void CXFA_FFBarcode::UpdateWidgetProperty() { pBarCodeWidget->SetType(pBarcodeTypeInfo->eBCType); CXFA_WidgetAcc* pAcc = GetDataAcc(); int32_t intVal; - FX_CHAR charVal; + char charVal; bool boolVal; - FX_FLOAT floatVal; + float floatVal; if (pAcc->GetBarcodeAttribute_CharEncoding(intVal)) { pBarCodeWidget->SetCharEncoding((BC_CHAR_ENCODING)intVal); } diff --git a/chromium/third_party/pdfium/xfa/fxfa/app/xfa_ffbarcode.h b/chromium/third_party/pdfium/xfa/fxfa/app/xfa_ffbarcode.h index c20feb5167b..ad12218f3d5 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/app/xfa_ffbarcode.h +++ b/chromium/third_party/pdfium/xfa/fxfa/app/xfa_ffbarcode.h @@ -7,9 +7,9 @@ #ifndef XFA_FXFA_APP_XFA_FFBARCODE_H_ #define XFA_FXFA_APP_XFA_FFBARCODE_H_ -#include "xfa/fxbarcode/BC_Library.h" +#include "fxbarcode/BC_Library.h" #include "xfa/fxfa/app/xfa_fftextedit.h" -#include "xfa/fxfa/xfa_ffpageview.h" +#include "xfa/fxfa/cxfa_ffpageview.h" class CXFA_FFBarcode : public CXFA_FFTextEdit { public: @@ -93,7 +93,7 @@ enum XFA_BARCODETYPEENUM { struct XFA_BARCODETYPEENUMINFO { uint32_t uHash; - const FX_WCHAR* pName; + const wchar_t* pName; XFA_BARCODETYPEENUM eName; BC_TYPE eBCType; }; diff --git a/chromium/third_party/pdfium/xfa/fxfa/app/xfa_ffcheckbutton.cpp b/chromium/third_party/pdfium/xfa/fxfa/app/xfa_ffcheckbutton.cpp index f088b5d4dda..9f003ad3a10 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/app/xfa_ffcheckbutton.cpp +++ b/chromium/third_party/pdfium/xfa/fxfa/app/xfa_ffcheckbutton.cpp @@ -12,11 +12,11 @@ #include "xfa/fwl/cfwl_widgetmgr.h" #include "xfa/fxfa/app/xfa_ffexclgroup.h" #include "xfa/fxfa/app/xfa_fffield.h" -#include "xfa/fxfa/xfa_ffapp.h" -#include "xfa/fxfa/xfa_ffdoc.h" -#include "xfa/fxfa/xfa_ffdocview.h" -#include "xfa/fxfa/xfa_ffpageview.h" -#include "xfa/fxfa/xfa_ffwidget.h" +#include "xfa/fxfa/cxfa_ffapp.h" +#include "xfa/fxfa/cxfa_ffdoc.h" +#include "xfa/fxfa/cxfa_ffdocview.h" +#include "xfa/fxfa/cxfa_ffpageview.h" +#include "xfa/fxfa/cxfa_ffwidget.h" CXFA_FFCheckButton::CXFA_FFCheckButton(CXFA_WidgetAcc* pDataAcc) : CXFA_FFField(pDataAcc), m_pOldDelegate(nullptr) {} @@ -49,7 +49,7 @@ void CXFA_FFCheckButton::UpdateWidgetProperty() { if (!m_pNormalWidget) { return; } - FX_FLOAT fSize = m_pDataAcc->GetCheckButtonSize(); + float fSize = m_pDataAcc->GetCheckButtonSize(); pCheckBox->SetBoxSize(fSize); uint32_t dwStyleEx = FWL_STYLEEXT_CKB_SignShapeCross; int32_t iCheckMark = m_pDataAcc->GetCheckButtonMark(); @@ -86,14 +86,14 @@ void CXFA_FFCheckButton::UpdateWidgetProperty() { } bool CXFA_FFCheckButton::PerformLayout() { CXFA_FFWidget::PerformLayout(); - FX_FLOAT fCheckSize = m_pDataAcc->GetCheckButtonSize(); + float fCheckSize = m_pDataAcc->GetCheckButtonSize(); CXFA_Margin mgWidget = m_pDataAcc->GetMargin(); CFX_RectF rtWidget = GetRectWithoutRotate(); if (mgWidget) { XFA_RectWidthoutMargin(rtWidget, mgWidget); } int32_t iCapPlacement = -1; - FX_FLOAT fCapReserve = 0; + float fCapReserve = 0; CXFA_Caption caption = m_pDataAcc->GetCaption(); if (caption && caption.GetPresence()) { m_rtCaption = rtWidget; @@ -189,8 +189,8 @@ void CXFA_FFCheckButton::CapLeftRightPlacement(CXFA_Margin mgCap) { void CXFA_FFCheckButton::AddUIMargin(int32_t iCapPlacement) { CFX_RectF rtUIMargin = m_pDataAcc->GetUIMargin(); m_rtUI.top -= rtUIMargin.top / 2 - rtUIMargin.height / 2; - FX_FLOAT fLeftAddRight = rtUIMargin.left + rtUIMargin.width; - FX_FLOAT fTopAddBottom = rtUIMargin.top + rtUIMargin.height; + float fLeftAddRight = rtUIMargin.left + rtUIMargin.width; + float fTopAddBottom = rtUIMargin.top + rtUIMargin.height; if (m_rtUI.width < fLeftAddRight) { if (iCapPlacement == XFA_ATTRIBUTEENUM_Right || iCapPlacement == XFA_ATTRIBUTEENUM_Left) { diff --git a/chromium/third_party/pdfium/xfa/fxfa/app/xfa_ffcheckbutton.h b/chromium/third_party/pdfium/xfa/fxfa/app/xfa_ffcheckbutton.h index 2c0acd6e3ec..75f884144d6 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/app/xfa_ffcheckbutton.h +++ b/chromium/third_party/pdfium/xfa/fxfa/app/xfa_ffcheckbutton.h @@ -8,7 +8,7 @@ #define XFA_FXFA_APP_XFA_FFCHECKBUTTON_H_ #include "xfa/fxfa/app/xfa_fffield.h" -#include "xfa/fxfa/xfa_ffpageview.h" +#include "xfa/fxfa/cxfa_ffpageview.h" class CXFA_FFCheckButton : public CXFA_FFField { public: @@ -32,7 +32,7 @@ class CXFA_FFCheckButton : public CXFA_FFField { void SetFWLCheckState(XFA_CHECKSTATE eCheckState); - protected: + private: bool CommitData() override; bool IsDataChanged() override; diff --git a/chromium/third_party/pdfium/xfa/fxfa/app/xfa_ffchoicelist.cpp b/chromium/third_party/pdfium/xfa/fxfa/app/xfa_ffchoicelist.cpp index 3aabde870af..c628d2e47f6 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/app/xfa_ffchoicelist.cpp +++ b/chromium/third_party/pdfium/xfa/fxfa/app/xfa_ffchoicelist.cpp @@ -6,6 +6,7 @@ #include "xfa/fxfa/app/xfa_ffchoicelist.h" +#include <algorithm> #include <vector> #include "third_party/base/ptr_util.h" @@ -20,10 +21,10 @@ #include "xfa/fxfa/app/xfa_fffield.h" #include "xfa/fxfa/app/xfa_fwladapter.h" #include "xfa/fxfa/cxfa_eventparam.h" -#include "xfa/fxfa/xfa_ffdoc.h" -#include "xfa/fxfa/xfa_ffdocview.h" -#include "xfa/fxfa/xfa_ffpageview.h" -#include "xfa/fxfa/xfa_ffwidget.h" +#include "xfa/fxfa/cxfa_ffdoc.h" +#include "xfa/fxfa/cxfa_ffdocview.h" +#include "xfa/fxfa/cxfa_ffpageview.h" +#include "xfa/fxfa/cxfa_ffwidget.h" CXFA_FFListBox::CXFA_FFListBox(CXFA_WidgetAcc* pDataAcc) : CXFA_FFField(pDataAcc), m_pOldDelegate(nullptr) {} @@ -52,25 +53,18 @@ bool CXFA_FFListBox::LoadWidget() { m_pNormalWidget->SetDelegate(this); m_pNormalWidget->LockUpdate(); - std::vector<CFX_WideString> wsLabelArray; - m_pDataAcc->GetChoiceListItems(wsLabelArray, false); - int32_t iItems = pdfium::CollectionSize<int32_t>(wsLabelArray); - for (int32_t i = 0; i < iItems; i++) { - pListBox->AddString(wsLabelArray[i].AsStringC()); - } + for (const auto& label : m_pDataAcc->GetChoiceListItems(false)) + pListBox->AddString(label.AsStringC()); + uint32_t dwExtendedStyle = FWL_STYLEEXT_LTB_ShowScrollBarFocus; - if (m_pDataAcc->GetChoiceListOpen() == XFA_ATTRIBUTEENUM_MultiSelect) { + if (m_pDataAcc->GetChoiceListOpen() == XFA_ATTRIBUTEENUM_MultiSelect) dwExtendedStyle |= FWL_STYLEEXT_LTB_MultiSelection; - } + dwExtendedStyle |= GetAlignment(); m_pNormalWidget->ModifyStylesEx(dwExtendedStyle, 0xFFFFFFFF); - CFX_ArrayTemplate<int32_t> iSelArray; - m_pDataAcc->GetSelectedItems(iSelArray); - int32_t iSelCount = iSelArray.GetSize(); - for (int32_t j = 0; j < iSelCount; j++) { - CFWL_ListItem* item = pListBox->GetItem(nullptr, iSelArray[j]); - pListBox->SetSelItem(item, true); - } + for (int32_t selected : m_pDataAcc->GetSelectedItems()) + pListBox->SetSelItem(pListBox->GetItem(nullptr, selected), true); + m_pNormalWidget->UnlockUpdate(); return CXFA_FFField::LoadWidget(); } @@ -84,19 +78,18 @@ bool CXFA_FFListBox::OnKillFocus(CXFA_FFWidget* pNewFocus) { bool CXFA_FFListBox::CommitData() { CFWL_ListBox* pListBox = static_cast<CFWL_ListBox*>(m_pNormalWidget); + std::vector<int32_t> iSelArray; int32_t iSels = pListBox->CountSelItems(); - CFX_ArrayTemplate<int32_t> iSelArray; for (int32_t i = 0; i < iSels; ++i) - iSelArray.Add(pListBox->GetSelIndex(i)); + iSelArray.push_back(pListBox->GetSelIndex(i)); m_pDataAcc->SetSelectedItems(iSelArray, true, false, true); return true; } bool CXFA_FFListBox::IsDataChanged() { - CFX_ArrayTemplate<int32_t> iSelArray; - m_pDataAcc->GetSelectedItems(iSelArray); - int32_t iOldSels = iSelArray.GetSize(); - CFWL_ListBox* pListBox = (CFWL_ListBox*)m_pNormalWidget; + std::vector<int32_t> iSelArray = m_pDataAcc->GetSelectedItems(); + int32_t iOldSels = pdfium::CollectionSize<int32_t>(iSelArray); + auto* pListBox = static_cast<CFWL_ListBox*>(m_pNormalWidget); int32_t iSels = pListBox->CountSelItems(); if (iOldSels != iSels) return true; @@ -134,28 +127,24 @@ uint32_t CXFA_FFListBox::GetAlignment() { return dwExtendedStyle; } bool CXFA_FFListBox::UpdateFWLData() { - if (!m_pNormalWidget) { + if (!m_pNormalWidget) return false; - } - CFWL_ListBox* pListBox = ((CFWL_ListBox*)m_pNormalWidget); - CFX_ArrayTemplate<CFWL_ListItem*> selItemArray; - CFX_ArrayTemplate<int32_t> iSelArray; - m_pDataAcc->GetSelectedItems(iSelArray); - int32_t iSelCount = iSelArray.GetSize(); - for (int32_t j = 0; j < iSelCount; j++) { - CFWL_ListItem* lpItemSel = pListBox->GetSelItem(iSelArray[j]); - selItemArray.Add(lpItemSel); - } + + auto* pListBox = static_cast<CFWL_ListBox*>(m_pNormalWidget); + std::vector<int32_t> iSelArray = m_pDataAcc->GetSelectedItems(); + std::vector<CFWL_ListItem*> selItemArray(iSelArray.size()); + std::transform(iSelArray.begin(), iSelArray.end(), selItemArray.begin(), + [pListBox](int32_t val) { return pListBox->GetSelItem(val); }); + pListBox->SetSelItem(pListBox->GetSelItem(-1), false); - for (int32_t i = 0; i < iSelCount; i++) { - ((CFWL_ListBox*)m_pNormalWidget)->SetSelItem(selItemArray[i], true); - } + for (CFWL_ListItem* pItem : selItemArray) + pListBox->SetSelItem(pItem, true); + m_pNormalWidget->Update(); return true; } -void CXFA_FFListBox::OnSelectChanged( - CFWL_Widget* pWidget, - const CFX_ArrayTemplate<int32_t>& arrSels) { +void CXFA_FFListBox::OnSelectChanged(CFWL_Widget* pWidget, + const std::vector<int32_t>& arrSels) { CXFA_EventParam eParam; eParam.m_eType = XFA_EVENT_Change; eParam.m_pTarget = m_pDataAcc; @@ -201,7 +190,7 @@ void CXFA_FFListBox::OnProcessEvent(CFWL_Event* pEvent) { CXFA_FFField::OnProcessEvent(pEvent); switch (pEvent->GetType()) { case CFWL_Event::Type::SelectChanged: { - CFX_ArrayTemplate<int32_t> arrSels; + std::vector<int32_t> arrSels; OnSelectChanged(m_pNormalWidget, arrSels); break; } @@ -227,7 +216,7 @@ CFX_RectF CXFA_FFComboBox::GetBBox(uint32_t dwStatus, bool bDrawFocus) { } bool CXFA_FFComboBox::PtInActiveRect(const CFX_PointF& point) { - auto pComboBox = static_cast<CFWL_ComboBox*>(m_pNormalWidget); + auto* pComboBox = static_cast<CFWL_ComboBox*>(m_pNormalWidget); return pComboBox && pComboBox->GetBBox().Contains(point); } @@ -244,17 +233,12 @@ bool CXFA_FFComboBox::LoadWidget() { m_pNormalWidget->SetDelegate(this); m_pNormalWidget->LockUpdate(); - std::vector<CFX_WideString> wsLabelArray; - m_pDataAcc->GetChoiceListItems(wsLabelArray, false); - int32_t iItems = pdfium::CollectionSize<int32_t>(wsLabelArray); - for (int32_t i = 0; i < iItems; i++) { - pComboBox->AddString(wsLabelArray[i].AsStringC()); - } - CFX_ArrayTemplate<int32_t> iSelArray; - m_pDataAcc->GetSelectedItems(iSelArray); - int32_t iSelCount = iSelArray.GetSize(); - if (iSelCount > 0) { - pComboBox->SetCurSel(iSelArray[0]); + for (const auto& label : m_pDataAcc->GetChoiceListItems(false)) + pComboBox->AddString(label.AsStringC()); + + std::vector<int32_t> iSelArray = m_pDataAcc->GetSelectedItems(); + if (!iSelArray.empty()) { + pComboBox->SetCurSel(iSelArray.front()); } else { CFX_WideString wsText; m_pDataAcc->GetValue(wsText, XFA_VALUEPICTURE_Raw); @@ -375,24 +359,25 @@ uint32_t CXFA_FFComboBox::GetAlignment() { } return dwExtendedStyle; } + bool CXFA_FFComboBox::UpdateFWLData() { - if (!m_pNormalWidget) { + auto* pComboBox = static_cast<CFWL_ComboBox*>(m_pNormalWidget); + if (!pComboBox) return false; - } - CFX_ArrayTemplate<int32_t> iSelArray; - m_pDataAcc->GetSelectedItems(iSelArray); - int32_t iSelCount = iSelArray.GetSize(); - if (iSelCount > 0) { - ((CFWL_ComboBox*)m_pNormalWidget)->SetCurSel(iSelArray[0]); + + std::vector<int32_t> iSelArray = m_pDataAcc->GetSelectedItems(); + if (!iSelArray.empty()) { + pComboBox->SetCurSel(iSelArray.front()); } else { CFX_WideString wsText; - ((CFWL_ComboBox*)m_pNormalWidget)->SetCurSel(-1); + pComboBox->SetCurSel(-1); m_pDataAcc->GetValue(wsText, XFA_VALUEPICTURE_Raw); - ((CFWL_ComboBox*)m_pNormalWidget)->SetEditText(wsText); + pComboBox->SetEditText(wsText); } - m_pNormalWidget->Update(); + pComboBox->Update(); return true; } + bool CXFA_FFComboBox::CanUndo() { return m_pDataAcc->IsChoiceListAllowTextEntry() && ((CFWL_ComboBox*)m_pNormalWidget)->EditCanUndo(); diff --git a/chromium/third_party/pdfium/xfa/fxfa/app/xfa_ffchoicelist.h b/chromium/third_party/pdfium/xfa/fxfa/app/xfa_ffchoicelist.h index e89366ad13d..8875655901c 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/app/xfa_ffchoicelist.h +++ b/chromium/third_party/pdfium/xfa/fxfa/app/xfa_ffchoicelist.h @@ -7,8 +7,10 @@ #ifndef XFA_FXFA_APP_XFA_FFCHOICELIST_H_ #define XFA_FXFA_APP_XFA_FFCHOICELIST_H_ +#include <vector> + #include "xfa/fxfa/app/xfa_fffield.h" -#include "xfa/fxfa/xfa_ffpageview.h" +#include "xfa/fxfa/cxfa_ffpageview.h" class CXFA_FFListBox : public CXFA_FFField { public: @@ -24,12 +26,12 @@ class CXFA_FFListBox : public CXFA_FFField { const CFX_Matrix* pMatrix = nullptr) override; void OnSelectChanged(CFWL_Widget* pWidget, - const CFX_ArrayTemplate<int32_t>& arrSels); + const std::vector<int32_t>& arrSels); void SetItemState(int32_t nIndex, bool bSelected); void InsertItem(const CFX_WideStringC& wsLabel, int32_t nIndex = -1); void DeleteItem(int32_t nIndex); - protected: + private: bool CommitData() override; bool UpdateFWLData() override; bool IsDataChanged() override; @@ -82,7 +84,7 @@ class CXFA_FFComboBox : public CXFA_FFField { void InsertItem(const CFX_WideStringC& wsLabel, int32_t nIndex = -1); void DeleteItem(int32_t nIndex); - protected: + private: // CXFA_FFField bool PtInActiveRect(const CFX_PointF& point) override; bool CommitData() override; diff --git a/chromium/third_party/pdfium/xfa/fxfa/app/xfa_ffdraw.cpp b/chromium/third_party/pdfium/xfa/fxfa/app/xfa_ffdraw.cpp index 37095ddb49b..8742b83c5bf 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/app/xfa_ffdraw.cpp +++ b/chromium/third_party/pdfium/xfa/fxfa/app/xfa_ffdraw.cpp @@ -6,10 +6,10 @@ #include "xfa/fxfa/app/xfa_ffdraw.h" -#include "xfa/fxfa/xfa_ffapp.h" -#include "xfa/fxfa/xfa_ffdoc.h" -#include "xfa/fxfa/xfa_ffpageview.h" -#include "xfa/fxfa/xfa_ffwidget.h" +#include "xfa/fxfa/cxfa_ffapp.h" +#include "xfa/fxfa/cxfa_ffdoc.h" +#include "xfa/fxfa/cxfa_ffpageview.h" +#include "xfa/fxfa/cxfa_ffwidget.h" CXFA_FFDraw::CXFA_FFDraw(CXFA_WidgetAcc* pDataAcc) : CXFA_FFWidget(pDataAcc) {} diff --git a/chromium/third_party/pdfium/xfa/fxfa/app/xfa_ffdraw.h b/chromium/third_party/pdfium/xfa/fxfa/app/xfa_ffdraw.h index 0212dcca0a7..bcd74f204c8 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/app/xfa_ffdraw.h +++ b/chromium/third_party/pdfium/xfa/fxfa/app/xfa_ffdraw.h @@ -7,8 +7,8 @@ #ifndef XFA_FXFA_APP_XFA_FFDRAW_H_ #define XFA_FXFA_APP_XFA_FFDRAW_H_ -#include "xfa/fxfa/xfa_ffpageview.h" -#include "xfa/fxfa/xfa_ffwidget.h" +#include "xfa/fxfa/cxfa_ffpageview.h" +#include "xfa/fxfa/cxfa_ffwidget.h" class CXFA_FFDraw : public CXFA_FFWidget { public: diff --git a/chromium/third_party/pdfium/xfa/fxfa/app/xfa_ffexclgroup.cpp b/chromium/third_party/pdfium/xfa/fxfa/app/xfa_ffexclgroup.cpp index 7d63daddbc7..9f2560f82fb 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/app/xfa_ffexclgroup.cpp +++ b/chromium/third_party/pdfium/xfa/fxfa/app/xfa_ffexclgroup.cpp @@ -6,10 +6,10 @@ #include "xfa/fxfa/app/xfa_ffexclgroup.h" -#include "xfa/fxfa/xfa_ffapp.h" -#include "xfa/fxfa/xfa_ffdoc.h" -#include "xfa/fxfa/xfa_ffpageview.h" -#include "xfa/fxfa/xfa_ffwidget.h" +#include "xfa/fxfa/cxfa_ffapp.h" +#include "xfa/fxfa/cxfa_ffdoc.h" +#include "xfa/fxfa/cxfa_ffpageview.h" +#include "xfa/fxfa/cxfa_ffwidget.h" CXFA_FFExclGroup::CXFA_FFExclGroup(CXFA_WidgetAcc* pDataAcc) : CXFA_FFWidget(pDataAcc) {} diff --git a/chromium/third_party/pdfium/xfa/fxfa/app/xfa_ffexclgroup.h b/chromium/third_party/pdfium/xfa/fxfa/app/xfa_ffexclgroup.h index 12a13aea92c..a14894566c4 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/app/xfa_ffexclgroup.h +++ b/chromium/third_party/pdfium/xfa/fxfa/app/xfa_ffexclgroup.h @@ -7,8 +7,8 @@ #ifndef XFA_FXFA_APP_XFA_FFEXCLGROUP_H_ #define XFA_FXFA_APP_XFA_FFEXCLGROUP_H_ -#include "xfa/fxfa/xfa_ffpageview.h" -#include "xfa/fxfa/xfa_ffwidget.h" +#include "xfa/fxfa/cxfa_ffpageview.h" +#include "xfa/fxfa/cxfa_ffwidget.h" class CXFA_FFExclGroup : public CXFA_FFWidget { public: diff --git a/chromium/third_party/pdfium/xfa/fxfa/app/xfa_fffield.cpp b/chromium/third_party/pdfium/xfa/fxfa/app/xfa_fffield.cpp index 630d04311fb..4193af82b48 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/app/xfa_fffield.cpp +++ b/chromium/third_party/pdfium/xfa/fxfa/app/xfa_fffield.cpp @@ -17,11 +17,12 @@ #include "xfa/fwl/cfwl_widgetmgr.h" #include "xfa/fxfa/app/cxfa_textlayout.h" #include "xfa/fxfa/app/xfa_fwltheme.h" -#include "xfa/fxfa/xfa_ffapp.h" -#include "xfa/fxfa/xfa_ffdoc.h" -#include "xfa/fxfa/xfa_ffdocview.h" -#include "xfa/fxfa/xfa_ffpageview.h" -#include "xfa/fxfa/xfa_ffwidget.h" +#include "xfa/fxfa/cxfa_ffapp.h" +#include "xfa/fxfa/cxfa_ffdoc.h" +#include "xfa/fxfa/cxfa_ffdocview.h" +#include "xfa/fxfa/cxfa_ffpageview.h" +#include "xfa/fxfa/cxfa_ffwidget.h" +#include "xfa/fxfa/parser/cxfa_node.h" #include "xfa/fxgraphics/cfx_color.h" #include "xfa/fxgraphics/cfx_path.h" @@ -94,7 +95,7 @@ void CXFA_FFField::DrawFocus(CFX_Graphics* pGS, CFX_Matrix* pMatrix) { if (m_dwStatus & XFA_WidgetStatus_Focused) { CFX_Color cr(0xFF000000); pGS->SetStrokeColor(&cr); - FX_FLOAT DashPattern[2] = {1, 1}; + float DashPattern[2] = {1, 1}; pGS->SetLineDash(0.0f, DashPattern, 2); pGS->SetLineWidth(0, false); @@ -124,7 +125,7 @@ void CXFA_FFField::SetEditScrollOffset() { XFA_Element eType = m_pDataAcc->GetUIType(); if (eType == XFA_Element::TextEdit || eType == XFA_Element::NumericEdit || eType == XFA_Element::PasswordEdit) { - FX_FLOAT fScrollOffset = 0; + float fScrollOffset = 0; CXFA_FFField* pPrev = static_cast<CXFA_FFField*>(GetPrev()); if (pPrev) { CFX_RectF rtMargin = m_pDataAcc->GetUIMargin(); @@ -153,7 +154,7 @@ void CXFA_FFField::CapPlacement() { CXFA_Margin mgWidget = m_pDataAcc->GetMargin(); if (mgWidget) { CXFA_LayoutItem* pItem = this; - FX_FLOAT fLeftInset = 0, fRightInset = 0, fTopInset = 0, fBottomInset = 0; + float fLeftInset = 0, fRightInset = 0, fTopInset = 0, fBottomInset = 0; mgWidget.GetLeftInset(fLeftInset); mgWidget.GetRightInset(fRightInset); mgWidget.GetTopInset(fTopInset); @@ -171,7 +172,7 @@ void CXFA_FFField::CapPlacement() { } XFA_ATTRIBUTEENUM iCapPlacement = XFA_ATTRIBUTEENUM_Unknown; - FX_FLOAT fCapReserve = 0; + float fCapReserve = 0; CXFA_Caption caption = m_pDataAcc->GetCaption(); if (caption && caption.GetPresence() != XFA_ATTRIBUTEENUM_Hidden) { iCapPlacement = (XFA_ATTRIBUTEENUM)caption.GetPlacementType(); @@ -260,8 +261,8 @@ void CXFA_FFField::CapTopBottomPlacement(CXFA_Caption caption, m_rtCaption.top += m_rtCaption.height; } } - FX_FLOAT fWidth = rtUIMargin.left + rtUIMargin.width; - FX_FLOAT fHeight = m_rtCaption.height + rtUIMargin.top + rtUIMargin.height; + float fWidth = rtUIMargin.left + rtUIMargin.width; + float fHeight = m_rtCaption.height + rtUIMargin.top + rtUIMargin.height; if (fWidth > rtWidget.width) { m_rtUI.width += fWidth - rtWidget.width; } @@ -287,8 +288,8 @@ void CXFA_FFField::CapLeftRightPlacement(CXFA_Caption caption, m_rtCaption.top += m_rtCaption.height; } } - FX_FLOAT fWidth = m_rtCaption.width + rtUIMargin.left + rtUIMargin.width; - FX_FLOAT fHeight = rtUIMargin.top + rtUIMargin.height; + float fWidth = m_rtCaption.width + rtUIMargin.left + rtUIMargin.width; + float fHeight = rtUIMargin.top + rtUIMargin.height; if (fWidth > rtWidget.width) { m_rtUI.width += fWidth - rtWidget.width; if (iCapPlacement == XFA_ATTRIBUTEENUM_Right) { @@ -323,7 +324,7 @@ void CXFA_FFField::SetFWLRect() { if (rtUi.width < 1.0) rtUi.width = 1.0; if (!m_pDataAcc->GetDoc()->GetXFADoc()->IsInteractive()) { - FX_FLOAT fFontSize = m_pDataAcc->GetFontSize(); + float fFontSize = m_pDataAcc->GetFontSize(); if (rtUi.height < fFontSize) { rtUi.height = fFontSize; } @@ -563,7 +564,7 @@ void CXFA_FFField::LayoutCaption() { if (!pCapTextLayout) return; - FX_FLOAT fHeight = 0; + float fHeight = 0; pCapTextLayout->Layout(CFX_SizeF(m_rtCaption.width, m_rtCaption.height), &fHeight); if (m_rtCaption.height < fHeight) diff --git a/chromium/third_party/pdfium/xfa/fxfa/app/xfa_fffield.h b/chromium/third_party/pdfium/xfa/fxfa/app/xfa_fffield.h index f10ce617388..0e9ac8661c2 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/app/xfa_fffield.h +++ b/chromium/third_party/pdfium/xfa/fxfa/app/xfa_fffield.h @@ -9,8 +9,8 @@ #include "xfa/fwl/cfwl_widget.h" #include "xfa/fwl/ifwl_widgetdelegate.h" -#include "xfa/fxfa/xfa_ffpageview.h" -#include "xfa/fxfa/xfa_ffwidget.h" +#include "xfa/fxfa/cxfa_ffpageview.h" +#include "xfa/fxfa/cxfa_ffwidget.h" #define XFA_MINUI_HEIGHT 4.32f #define XFA_DEFAULTUI_HEIGHT 2.0f diff --git a/chromium/third_party/pdfium/xfa/fxfa/app/xfa_ffimage.cpp b/chromium/third_party/pdfium/xfa/fxfa/app/xfa_ffimage.cpp index a613221ea63..23ed88616d8 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/app/xfa_ffimage.cpp +++ b/chromium/third_party/pdfium/xfa/fxfa/app/xfa_ffimage.cpp @@ -7,10 +7,10 @@ #include "xfa/fxfa/app/xfa_ffimage.h" #include "xfa/fxfa/app/xfa_ffdraw.h" -#include "xfa/fxfa/xfa_ffapp.h" -#include "xfa/fxfa/xfa_ffdoc.h" -#include "xfa/fxfa/xfa_ffpageview.h" -#include "xfa/fxfa/xfa_ffwidget.h" +#include "xfa/fxfa/cxfa_ffapp.h" +#include "xfa/fxfa/cxfa_ffdoc.h" +#include "xfa/fxfa/cxfa_ffpageview.h" +#include "xfa/fxfa/cxfa_ffwidget.h" CXFA_FFImage::CXFA_FFImage(CXFA_WidgetAcc* pDataAcc) : CXFA_FFDraw(pDataAcc) {} @@ -43,7 +43,7 @@ void CXFA_FFImage::RenderWidget(CFX_Graphics* pGS, CXFA_FFWidget::RenderWidget(pGS, &mtRotate, dwStatus); - CFX_DIBitmap* pDIBitmap = GetDataAcc()->GetImageImage(); + CFX_RetainPtr<CFX_DIBitmap> pDIBitmap = GetDataAcc()->GetImageImage(); if (!pDIBitmap) return; diff --git a/chromium/third_party/pdfium/xfa/fxfa/app/xfa_ffimageedit.cpp b/chromium/third_party/pdfium/xfa/fxfa/app/xfa_ffimageedit.cpp index 01d29eed419..624ef3f4426 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/app/xfa_ffimageedit.cpp +++ b/chromium/third_party/pdfium/xfa/fxfa/app/xfa_ffimageedit.cpp @@ -11,10 +11,10 @@ #include "xfa/fwl/cfwl_notedriver.h" #include "xfa/fwl/cfwl_picturebox.h" #include "xfa/fxfa/app/xfa_fffield.h" -#include "xfa/fxfa/xfa_ffdoc.h" -#include "xfa/fxfa/xfa_ffdocview.h" -#include "xfa/fxfa/xfa_ffpageview.h" -#include "xfa/fxfa/xfa_ffwidget.h" +#include "xfa/fxfa/cxfa_ffdoc.h" +#include "xfa/fxfa/cxfa_ffdocview.h" +#include "xfa/fxfa/cxfa_ffpageview.h" +#include "xfa/fxfa/cxfa_ffwidget.h" CXFA_FFImageEdit::CXFA_FFImageEdit(CXFA_WidgetAcc* pDataAcc) : CXFA_FFField(pDataAcc), m_pOldDelegate(nullptr) {} @@ -60,7 +60,7 @@ void CXFA_FFImageEdit::RenderWidget(CFX_Graphics* pGS, CXFA_Border borderUI = m_pDataAcc->GetUIBorder(); DrawBorder(pGS, borderUI, m_rtUI, &mtRotate); RenderCaption(pGS, &mtRotate); - CFX_DIBitmap* pDIBitmap = m_pDataAcc->GetImageEditImage(); + CFX_RetainPtr<CFX_DIBitmap> pDIBitmap = m_pDataAcc->GetImageEditImage(); if (!pDIBitmap) return; diff --git a/chromium/third_party/pdfium/xfa/fxfa/app/xfa_ffimageedit.h b/chromium/third_party/pdfium/xfa/fxfa/app/xfa_ffimageedit.h index 73032b98150..ee91a772e00 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/app/xfa_ffimageedit.h +++ b/chromium/third_party/pdfium/xfa/fxfa/app/xfa_ffimageedit.h @@ -26,7 +26,7 @@ class CXFA_FFImageEdit : public CXFA_FFField { void OnDrawWidget(CFX_Graphics* pGraphics, const CFX_Matrix* pMatrix = nullptr) override; - protected: + private: void SetFWLRect() override; bool UpdateFWLData() override; bool CommitData() override; diff --git a/chromium/third_party/pdfium/xfa/fxfa/app/xfa_ffnotify.cpp b/chromium/third_party/pdfium/xfa/fxfa/app/xfa_ffnotify.cpp index 951b4fd3f1d..d9ec99aba9f 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/app/xfa_ffnotify.cpp +++ b/chromium/third_party/pdfium/xfa/fxfa/app/xfa_ffnotify.cpp @@ -24,12 +24,13 @@ #include "xfa/fxfa/app/xfa_fftextedit.h" #include "xfa/fxfa/app/xfa_ffwidgetacc.h" #include "xfa/fxfa/app/xfa_fwladapter.h" -#include "xfa/fxfa/xfa_ffapp.h" -#include "xfa/fxfa/xfa_ffdoc.h" -#include "xfa/fxfa/xfa_ffdocview.h" -#include "xfa/fxfa/xfa_ffpageview.h" -#include "xfa/fxfa/xfa_ffwidget.h" -#include "xfa/fxfa/xfa_ffwidgethandler.h" +#include "xfa/fxfa/cxfa_ffapp.h" +#include "xfa/fxfa/cxfa_ffdoc.h" +#include "xfa/fxfa/cxfa_ffdocview.h" +#include "xfa/fxfa/cxfa_ffpageview.h" +#include "xfa/fxfa/cxfa_ffwidget.h" +#include "xfa/fxfa/cxfa_ffwidgethandler.h" +#include "xfa/fxfa/parser/cxfa_node.h" static void XFA_FFDeleteWidgetAcc(void* pData) { delete static_cast<CXFA_WidgetAcc*>(pData); @@ -49,8 +50,8 @@ void CXFA_FFNotify::OnPageEvent(CXFA_ContainerLayoutItem* pSender, } void CXFA_FFNotify::OnWidgetListItemAdded(CXFA_WidgetData* pSender, - const FX_WCHAR* pLabel, - const FX_WCHAR* pValue, + const wchar_t* pLabel, + const wchar_t* pValue, int32_t iIndex) { CXFA_WidgetAcc* pWidgetAcc = static_cast<CXFA_WidgetAcc*>(pSender); if (pWidgetAcc->GetUIType() != XFA_Element::ChoiceList) @@ -171,8 +172,8 @@ CXFA_LayoutItem* CXFA_FFNotify::OnCreateLayoutItem(CXFA_Node* pNode) { } void CXFA_FFNotify::StartFieldDrawLayout(CXFA_Node* pItem, - FX_FLOAT& fCalcWidth, - FX_FLOAT& fCalcHeight) { + float& fCalcWidth, + float& fCalcHeight) { CXFA_WidgetAcc* pAcc = static_cast<CXFA_WidgetAcc*>(pItem->GetWidgetData()); if (!pAcc) return; @@ -182,7 +183,7 @@ void CXFA_FFNotify::StartFieldDrawLayout(CXFA_Node* pItem, bool CXFA_FFNotify::FindSplitPos(CXFA_Node* pItem, int32_t iBlockIndex, - FX_FLOAT& fCalcHeightPos) { + float& fCalcHeightPos) { CXFA_WidgetAcc* pAcc = static_cast<CXFA_WidgetAcc*>(pItem->GetWidgetData()); return pAcc && pAcc->FindSplitPos(iBlockIndex, fCalcHeightPos); } @@ -262,8 +263,9 @@ void CXFA_FFNotify::OpenDropDownList(CXFA_FFWidget* hWidget) { pDocView->UpdateDocView(); } CFX_WideString CXFA_FFNotify::GetCurrentDateTime() { - CFX_Unitime dataTime; + CFX_DateTime dataTime; dataTime.Now(); + CFX_WideString wsDateTime; wsDateTime.Format(L"%d%02d%02dT%02d%02d%02d", dataTime.GetYear(), dataTime.GetMonth(), dataTime.GetDay(), dataTime.GetHour(), diff --git a/chromium/third_party/pdfium/xfa/fxfa/app/xfa_ffnotify.h b/chromium/third_party/pdfium/xfa/fxfa/app/xfa_ffnotify.h index 1bfaffec896..c002ed4c156 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/app/xfa_ffnotify.h +++ b/chromium/third_party/pdfium/xfa/fxfa/app/xfa_ffnotify.h @@ -20,8 +20,8 @@ class CXFA_FFNotify { void OnPageEvent(CXFA_ContainerLayoutItem* pSender, uint32_t dwEvent); void OnWidgetListItemAdded(CXFA_WidgetData* pSender, - const FX_WCHAR* pLabel, - const FX_WCHAR* pValue, + const wchar_t* pLabel, + const wchar_t* pValue, int32_t iIndex); void OnWidgetListItemRemoved(CXFA_WidgetData* pSender, int32_t iIndex); @@ -44,11 +44,11 @@ class CXFA_FFNotify { CXFA_LayoutItem* pSender); void StartFieldDrawLayout(CXFA_Node* pItem, - FX_FLOAT& fCalcWidth, - FX_FLOAT& fCalcHeight); + float& fCalcWidth, + float& fCalcHeight); bool FindSplitPos(CXFA_Node* pItem, int32_t iBlockIndex, - FX_FLOAT& fCalcHeightPos); + float& fCalcHeightPos); bool RunScript(CXFA_Node* pScript, CXFA_Node* pFormItem); int32_t ExecEventByDeepFirst(CXFA_Node* pFormNode, XFA_EVENTTYPE eEventType, diff --git a/chromium/third_party/pdfium/xfa/fxfa/app/xfa_ffpath.cpp b/chromium/third_party/pdfium/xfa/fxfa/app/xfa_ffpath.cpp index 43016fe5c63..854a028aaca 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/app/xfa_ffpath.cpp +++ b/chromium/third_party/pdfium/xfa/fxfa/app/xfa_ffpath.cpp @@ -7,10 +7,10 @@ #include "xfa/fxfa/app/xfa_ffpath.h" #include "xfa/fxfa/app/xfa_ffdraw.h" -#include "xfa/fxfa/xfa_ffapp.h" -#include "xfa/fxfa/xfa_ffdoc.h" -#include "xfa/fxfa/xfa_ffpageview.h" -#include "xfa/fxfa/xfa_ffwidget.h" +#include "xfa/fxfa/cxfa_ffapp.h" +#include "xfa/fxfa/cxfa_ffdoc.h" +#include "xfa/fxfa/cxfa_ffpageview.h" +#include "xfa/fxfa/cxfa_ffwidget.h" #include "xfa/fxgraphics/cfx_color.h" #include "xfa/fxgraphics/cfx_path.h" @@ -20,8 +20,8 @@ CXFA_FFLine::~CXFA_FFLine() {} void CXFA_FFLine::GetRectFromHand(CFX_RectF& rect, int32_t iHand, - FX_FLOAT fLineWidth) { - FX_FLOAT fHalfWidth = fLineWidth / 2.0f; + float fLineWidth) { + float fHalfWidth = fLineWidth / 2.0f; if (rect.height < 1.0f) { switch (iHand) { case XFA_ATTRIBUTEENUM_Left: @@ -64,7 +64,7 @@ void CXFA_FFLine::RenderWidget(CFX_Graphics* pGS, CXFA_Line lineObj = value.GetLine(); FX_ARGB lineColor = 0xFF000000; int32_t iStrokeType = 0; - FX_FLOAT fLineWidth = 1.0f; + float fLineWidth = 1.0f; int32_t iCap = 0; CXFA_Edge edge = lineObj.GetEdge(); if (edge) { diff --git a/chromium/third_party/pdfium/xfa/fxfa/app/xfa_ffpath.h b/chromium/third_party/pdfium/xfa/fxfa/app/xfa_ffpath.h index 002f75d262f..6df53f4e1d6 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/app/xfa_ffpath.h +++ b/chromium/third_party/pdfium/xfa/fxfa/app/xfa_ffpath.h @@ -20,7 +20,7 @@ class CXFA_FFLine : public CXFA_FFDraw { uint32_t dwStatus) override; private: - void GetRectFromHand(CFX_RectF& rect, int32_t iHand, FX_FLOAT fLineWidth); + void GetRectFromHand(CFX_RectF& rect, int32_t iHand, float fLineWidth); }; class CXFA_FFArc : public CXFA_FFDraw { diff --git a/chromium/third_party/pdfium/xfa/fxfa/app/xfa_ffpushbutton.cpp b/chromium/third_party/pdfium/xfa/fxfa/app/xfa_ffpushbutton.cpp index 7b6be820356..fa5c0dc9a14 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/app/xfa_ffpushbutton.cpp +++ b/chromium/third_party/pdfium/xfa/fxfa/app/xfa_ffpushbutton.cpp @@ -12,19 +12,14 @@ #include "xfa/fxfa/app/cxfa_textlayout.h" #include "xfa/fxfa/app/xfa_fffield.h" #include "xfa/fxfa/app/xfa_ffwidgetacc.h" -#include "xfa/fxfa/xfa_ffapp.h" -#include "xfa/fxfa/xfa_ffpageview.h" -#include "xfa/fxfa/xfa_ffwidget.h" +#include "xfa/fxfa/cxfa_ffapp.h" +#include "xfa/fxfa/cxfa_ffpageview.h" +#include "xfa/fxfa/cxfa_ffwidget.h" #include "xfa/fxgraphics/cfx_color.h" #include "xfa/fxgraphics/cfx_path.h" CXFA_FFPushButton::CXFA_FFPushButton(CXFA_WidgetAcc* pDataAcc) - : CXFA_FFField(pDataAcc), - m_pRolloverTextLayout(nullptr), - m_pDownTextLayout(nullptr), - m_pDownProvider(nullptr), - m_pRollProvider(nullptr), - m_pOldDelegate(nullptr) {} + : CXFA_FFField(pDataAcc), m_pOldDelegate(nullptr) {} CXFA_FFPushButton::~CXFA_FFPushButton() { CXFA_FFPushButton::UnloadWidget(); @@ -86,14 +81,10 @@ void CXFA_FFPushButton::UpdateWidgetProperty() { } void CXFA_FFPushButton::UnloadWidget() { - delete m_pRolloverTextLayout; - m_pRolloverTextLayout = nullptr; - delete m_pDownTextLayout; - m_pDownTextLayout = nullptr; - delete m_pDownProvider; - m_pDownProvider = nullptr; - delete m_pRollProvider; - m_pRollProvider = nullptr; + m_pRolloverTextLayout.reset(); + m_pDownTextLayout.reset(); + m_pRollProvider.reset(); + m_pDownProvider.reset(); CXFA_FFField::UnloadWidget(); } @@ -117,7 +108,7 @@ bool CXFA_FFPushButton::PerformLayout() { return true; } -FX_FLOAT CXFA_FFPushButton::GetLineWidth() { +float CXFA_FFPushButton::GetLineWidth() { CXFA_Border border = m_pDataAcc->GetBorder(); if (border && border.GetPresence() == XFA_ATTRIBUTEENUM_Visible) { CXFA_Edge edge = border.GetEdge(0); @@ -125,36 +116,41 @@ FX_FLOAT CXFA_FFPushButton::GetLineWidth() { } return 0; } + FX_ARGB CXFA_FFPushButton::GetLineColor() { return 0xFF000000; } + FX_ARGB CXFA_FFPushButton::GetFillColor() { return 0xFFFFFFFF; } + void CXFA_FFPushButton::LoadHighlightCaption() { CXFA_Caption caption = m_pDataAcc->GetCaption(); - if (caption && caption.GetPresence() != XFA_ATTRIBUTEENUM_Hidden) { - { - CFX_WideString wsRollover; - bool bRichText; - if (m_pDataAcc->GetButtonRollover(wsRollover, bRichText)) { - if (!m_pRollProvider) { - m_pRollProvider = - new CXFA_TextProvider(m_pDataAcc, XFA_TEXTPROVIDERTYPE_Rollover); - } - m_pRolloverTextLayout = new CXFA_TextLayout(m_pRollProvider); - } - CFX_WideString wsDown; - if (m_pDataAcc->GetButtonDown(wsDown, bRichText)) { - if (!m_pDownProvider) { - m_pDownProvider = - new CXFA_TextProvider(m_pDataAcc, XFA_TEXTPROVIDERTYPE_Down); - } - m_pDownTextLayout = new CXFA_TextLayout(m_pDownProvider); - } + if (!caption || caption.GetPresence() == XFA_ATTRIBUTEENUM_Hidden) + return; + + bool bRichText; + CFX_WideString wsRollover; + if (m_pDataAcc->GetButtonRollover(wsRollover, bRichText)) { + if (!m_pRollProvider) { + m_pRollProvider = pdfium::MakeUnique<CXFA_TextProvider>( + m_pDataAcc, XFA_TEXTPROVIDERTYPE_Rollover); + } + m_pRolloverTextLayout = + pdfium::MakeUnique<CXFA_TextLayout>(m_pRollProvider.get()); + } + CFX_WideString wsDown; + if (m_pDataAcc->GetButtonDown(wsDown, bRichText)) { + if (!m_pDownProvider) { + m_pDownProvider = pdfium::MakeUnique<CXFA_TextProvider>( + m_pDataAcc, XFA_TEXTPROVIDERTYPE_Down); } + m_pDownTextLayout = + pdfium::MakeUnique<CXFA_TextLayout>(m_pDownProvider.get()); } } + void CXFA_FFPushButton::LayoutHighlightCaption() { CFX_SizeF sz(m_rtCaption.width, m_rtCaption.height); LayoutCaption(); @@ -210,7 +206,7 @@ void CXFA_FFPushButton::OnDrawWidget(CFX_Graphics* pGraphics, if ((m_pNormalWidget->GetStates() & FWL_STATE_PSB_Pressed) && (m_pNormalWidget->GetStates() & FWL_STATE_PSB_Hovered)) { CFX_RectF rtFill(0, 0, m_pNormalWidget->GetWidgetRect().Size()); - FX_FLOAT fLineWith = GetLineWidth(); + float fLineWith = GetLineWidth(); rtFill.Deflate(fLineWith, fLineWith); CFX_Color cr(FXARGB_MAKE(128, 128, 255, 255)); pGraphics->SetFillColor(&cr); @@ -223,7 +219,7 @@ void CXFA_FFPushButton::OnDrawWidget(CFX_Graphics* pGraphics, XFA_FWL_PSBSTYLEEXT_HiliteOutLine) { if ((m_pNormalWidget->GetStates() & FWL_STATE_PSB_Pressed) && (m_pNormalWidget->GetStates() & FWL_STATE_PSB_Hovered)) { - FX_FLOAT fLineWidth = GetLineWidth(); + float fLineWidth = GetLineWidth(); CFX_Color cr(FXARGB_MAKE(255, 128, 255, 255)); pGraphics->SetStrokeColor(&cr); pGraphics->SetLineWidth(fLineWidth); diff --git a/chromium/third_party/pdfium/xfa/fxfa/app/xfa_ffpushbutton.h b/chromium/third_party/pdfium/xfa/fxfa/app/xfa_ffpushbutton.h index eb18ccb11ca..d2f5746fe92 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/app/xfa_ffpushbutton.h +++ b/chromium/third_party/pdfium/xfa/fxfa/app/xfa_ffpushbutton.h @@ -7,6 +7,8 @@ #ifndef XFA_FXFA_APP_XFA_FFPUSHBUTTON_H_ #define XFA_FXFA_APP_XFA_FFPUSHBUTTON_H_ +#include <memory> + #include "xfa/fxfa/app/xfa_fffield.h" #define XFA_FWL_PSBSTYLEEXT_HiliteNone (0L << 0) @@ -34,18 +36,18 @@ class CXFA_FFPushButton : public CXFA_FFField { void OnDrawWidget(CFX_Graphics* pGraphics, const CFX_Matrix* pMatrix = nullptr) override; - protected: + private: void LoadHighlightCaption(); void LayoutHighlightCaption(); void RenderHighlightCaption(CFX_Graphics* pGS, CFX_Matrix* pMatrix = nullptr); - FX_FLOAT GetLineWidth(); + float GetLineWidth(); FX_ARGB GetLineColor(); FX_ARGB GetFillColor(); - CXFA_TextLayout* m_pRolloverTextLayout; - CXFA_TextLayout* m_pDownTextLayout; - CXFA_TextProvider* m_pDownProvider; - CXFA_TextProvider* m_pRollProvider; + std::unique_ptr<CXFA_TextLayout> m_pRolloverTextLayout; + std::unique_ptr<CXFA_TextLayout> m_pDownTextLayout; + std::unique_ptr<CXFA_TextProvider> m_pRollProvider; + std::unique_ptr<CXFA_TextProvider> m_pDownProvider; IFWL_WidgetDelegate* m_pOldDelegate; }; diff --git a/chromium/third_party/pdfium/xfa/fxfa/app/xfa_ffsignature.cpp b/chromium/third_party/pdfium/xfa/fxfa/app/xfa_ffsignature.cpp index bf2bba3adff..edc34336c69 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/app/xfa_ffsignature.cpp +++ b/chromium/third_party/pdfium/xfa/fxfa/app/xfa_ffsignature.cpp @@ -7,9 +7,9 @@ #include "xfa/fxfa/app/xfa_ffsignature.h" #include "xfa/fxfa/app/xfa_fffield.h" -#include "xfa/fxfa/xfa_ffdoc.h" -#include "xfa/fxfa/xfa_ffpageview.h" -#include "xfa/fxfa/xfa_ffwidget.h" +#include "xfa/fxfa/cxfa_ffdoc.h" +#include "xfa/fxfa/cxfa_ffpageview.h" +#include "xfa/fxfa/cxfa_ffwidget.h" CXFA_FFSignature::CXFA_FFSignature(CXFA_WidgetAcc* pDataAcc) : CXFA_FFField(pDataAcc) {} diff --git a/chromium/third_party/pdfium/xfa/fxfa/app/xfa_ffsubform.cpp b/chromium/third_party/pdfium/xfa/fxfa/app/xfa_ffsubform.cpp index 0b479f4d4cd..d008c5b4f91 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/app/xfa_ffsubform.cpp +++ b/chromium/third_party/pdfium/xfa/fxfa/app/xfa_ffsubform.cpp @@ -6,10 +6,10 @@ #include "xfa/fxfa/app/xfa_ffsubform.h" -#include "xfa/fxfa/xfa_ffapp.h" -#include "xfa/fxfa/xfa_ffdoc.h" -#include "xfa/fxfa/xfa_ffpageview.h" -#include "xfa/fxfa/xfa_ffwidget.h" +#include "xfa/fxfa/cxfa_ffapp.h" +#include "xfa/fxfa/cxfa_ffdoc.h" +#include "xfa/fxfa/cxfa_ffpageview.h" +#include "xfa/fxfa/cxfa_ffwidget.h" CXFA_FFSubForm::CXFA_FFSubForm(CXFA_WidgetAcc* pDataAcc) : CXFA_FFWidget(pDataAcc) {} diff --git a/chromium/third_party/pdfium/xfa/fxfa/app/xfa_ffsubform.h b/chromium/third_party/pdfium/xfa/fxfa/app/xfa_ffsubform.h index e6b77a8b33e..c87688fdcef 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/app/xfa_ffsubform.h +++ b/chromium/third_party/pdfium/xfa/fxfa/app/xfa_ffsubform.h @@ -7,8 +7,8 @@ #ifndef XFA_FXFA_APP_XFA_FFSUBFORM_H_ #define XFA_FXFA_APP_XFA_FFSUBFORM_H_ -#include "xfa/fxfa/xfa_ffpageview.h" -#include "xfa/fxfa/xfa_ffwidget.h" +#include "xfa/fxfa/cxfa_ffpageview.h" +#include "xfa/fxfa/cxfa_ffwidget.h" class CXFA_FFSubForm : public CXFA_FFWidget { public: diff --git a/chromium/third_party/pdfium/xfa/fxfa/app/xfa_fftext.cpp b/chromium/third_party/pdfium/xfa/fxfa/app/xfa_fftext.cpp index e8d7aa32d02..6885bfc93f6 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/app/xfa_fftext.cpp +++ b/chromium/third_party/pdfium/xfa/fxfa/app/xfa_fftext.cpp @@ -13,10 +13,10 @@ #include "xfa/fxfa/app/cxfa_textlayout.h" #include "xfa/fxfa/app/xfa_ffdraw.h" #include "xfa/fxfa/app/xfa_textpiece.h" -#include "xfa/fxfa/xfa_ffapp.h" -#include "xfa/fxfa/xfa_ffdoc.h" -#include "xfa/fxfa/xfa_ffpageview.h" -#include "xfa/fxfa/xfa_ffwidget.h" +#include "xfa/fxfa/cxfa_ffapp.h" +#include "xfa/fxfa/cxfa_ffdoc.h" +#include "xfa/fxfa/cxfa_ffpageview.h" +#include "xfa/fxfa/cxfa_ffwidget.h" #include "xfa/fxgraphics/cfx_graphics.h" CXFA_FFText::CXFA_FFText(CXFA_WidgetAcc* pDataAcc) : CXFA_FFDraw(pDataAcc) {} @@ -46,10 +46,10 @@ void CXFA_FFText::RenderWidget(CFX_Graphics* pGS, if (!pItem->GetPrev() && !pItem->GetNext()) { XFA_RectWidthoutMargin(rtText, mgWidget); } else { - FX_FLOAT fLeftInset; - FX_FLOAT fRightInset; - FX_FLOAT fTopInset = 0; - FX_FLOAT fBottomInset = 0; + float fLeftInset; + float fRightInset; + float fTopInset = 0; + float fBottomInset = 0; mgWidget.GetLeftInset(fLeftInset); mgWidget.GetRightInset(fRightInset); if (!pItem->GetPrev()) @@ -75,13 +75,13 @@ bool CXFA_FFText::IsLoaded() { bool CXFA_FFText::PerformLayout() { CXFA_FFDraw::PerformLayout(); CXFA_TextLayout* pTextLayout = m_pDataAcc->GetTextLayout(); - if (!pTextLayout) { + if (!pTextLayout) return false; - } - if (!pTextLayout->m_bHasBlock) { + + if (!pTextLayout->m_bHasBlock) return true; - } - pTextLayout->m_Blocks.RemoveAll(); + + pTextLayout->m_Blocks.clear(); CXFA_LayoutItem* pItem = this; if (!pItem->GetPrev() && !pItem->GetNext()) { return true; @@ -91,11 +91,11 @@ bool CXFA_FFText::PerformLayout() { CFX_RectF rtText = pItem->GetRect(false); if (CXFA_Margin mgWidget = m_pDataAcc->GetMargin()) { if (!pItem->GetPrev()) { - FX_FLOAT fTopInset; + float fTopInset; mgWidget.GetTopInset(fTopInset); rtText.height -= fTopInset; } else if (!pItem->GetNext()) { - FX_FLOAT fBottomInset; + float fBottomInset; mgWidget.GetBottomInset(fBottomInset); rtText.height -= fBottomInset; } @@ -111,7 +111,7 @@ bool CXFA_FFText::OnLButtonDown(uint32_t dwFlags, const CFX_PointF& point) { if (!GetRectWithoutRotate().Contains(point)) return false; - const FX_WCHAR* wsURLContent = GetLinkURLAtPoint(point); + const wchar_t* wsURLContent = GetLinkURLAtPoint(point); if (!wsURLContent) return false; @@ -128,7 +128,7 @@ bool CXFA_FFText::OnLButtonUp(uint32_t dwFlags, const CFX_PointF& point) { return false; SetButtonDown(false); - const FX_WCHAR* wsURLContent = GetLinkURLAtPoint(point); + const wchar_t* wsURLContent = GetLinkURLAtPoint(point); if (!wsURLContent) return false; @@ -145,7 +145,7 @@ FWL_WidgetHit CXFA_FFText::OnHitTest(const CFX_PointF& point) { return FWL_WidgetHit::HyperLink; } -const FX_WCHAR* CXFA_FFText::GetLinkURLAtPoint(const CFX_PointF& point) { +const wchar_t* CXFA_FFText::GetLinkURLAtPoint(const CFX_PointF& point) { CXFA_TextLayout* pTextLayout = m_pDataAcc->GetTextLayout(); if (!pTextLayout) return nullptr; diff --git a/chromium/third_party/pdfium/xfa/fxfa/app/xfa_fftext.h b/chromium/third_party/pdfium/xfa/fxfa/app/xfa_fftext.h index c5538217914..eddc1224aca 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/app/xfa_fftext.h +++ b/chromium/third_party/pdfium/xfa/fxfa/app/xfa_fftext.h @@ -26,7 +26,7 @@ class CXFA_FFText : public CXFA_FFDraw { bool PerformLayout() override; private: - const FX_WCHAR* GetLinkURLAtPoint(const CFX_PointF& point); + const wchar_t* GetLinkURLAtPoint(const CFX_PointF& point); }; #endif // XFA_FXFA_APP_XFA_FFTEXT_H_ diff --git a/chromium/third_party/pdfium/xfa/fxfa/app/xfa_fftextedit.cpp b/chromium/third_party/pdfium/xfa/fxfa/app/xfa_fftextedit.cpp index 094839f4862..2658758718d 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/app/xfa_fftextedit.cpp +++ b/chromium/third_party/pdfium/xfa/fxfa/app/xfa_fftextedit.cpp @@ -21,12 +21,13 @@ #include "xfa/fxfa/app/xfa_fffield.h" #include "xfa/fxfa/app/xfa_fwladapter.h" #include "xfa/fxfa/cxfa_eventparam.h" -#include "xfa/fxfa/parser/xfa_localevalue.h" -#include "xfa/fxfa/xfa_ffapp.h" -#include "xfa/fxfa/xfa_ffdoc.h" -#include "xfa/fxfa/xfa_ffdocview.h" -#include "xfa/fxfa/xfa_ffpageview.h" -#include "xfa/fxfa/xfa_ffwidget.h" +#include "xfa/fxfa/cxfa_ffapp.h" +#include "xfa/fxfa/cxfa_ffdoc.h" +#include "xfa/fxfa/cxfa_ffdocview.h" +#include "xfa/fxfa/cxfa_ffpageview.h" +#include "xfa/fxfa/cxfa_ffwidget.h" +#include "xfa/fxfa/parser/cxfa_localevalue.h" +#include "xfa/fxfa/parser/cxfa_node.h" CXFA_FFTextEdit::CXFA_FFTextEdit(CXFA_WidgetAcc* pDataAcc) : CXFA_FFField(pDataAcc), m_pOldDelegate(nullptr) {} @@ -521,10 +522,9 @@ bool CXFA_FFDateTimeEdit::LoadWidget() { case XFA_Element::Date: { if (!wsText.IsEmpty()) { CXFA_LocaleValue lcValue = XFA_GetLocaleValue(m_pDataAcc); - CFX_Unitime date = lcValue.GetDate(); - if ((FX_UNITIME)date != 0) { + CFX_DateTime date = lcValue.GetDate(); + if (date.IsSet()) pWidget->SetCurSel(date.GetYear(), date.GetMonth(), date.GetDay()); - } } } break; default: @@ -618,10 +618,10 @@ bool CXFA_FFDateTimeEdit::UpdateFWLData() { ((CFWL_DateTimePicker*)m_pNormalWidget)->SetEditText(wsText); if (IsFocused() && !wsText.IsEmpty()) { CXFA_LocaleValue lcValue = XFA_GetLocaleValue(m_pDataAcc); - CFX_Unitime date = lcValue.GetDate(); + CFX_DateTime date = lcValue.GetDate(); if (lcValue.IsValid()) { - if ((FX_UNITIME)date != 0) { - ((CFWL_DateTimePicker*)m_pNormalWidget) + if (date.IsSet()) { + static_cast<CFWL_DateTimePicker*>(m_pNormalWidget) ->SetCurSel(date.GetYear(), date.GetMonth(), date.GetDay()); } } @@ -647,9 +647,8 @@ void CXFA_FFDateTimeEdit::OnSelectChanged(CFWL_Widget* pWidget, CFX_WideString wsPicture; m_pDataAcc->GetPictureContent(wsPicture, XFA_VALUEPICTURE_Edit); CXFA_LocaleValue date(XFA_VT_DATE, GetDoc()->GetXFADoc()->GetLocalMgr()); - CFX_Unitime dt; - dt.Set(iYear, iMonth, iDay); - date.SetDate(dt); + date.SetDate(CFX_DateTime(iYear, iMonth, iDay, 0, 0, 0, 0)); + CFX_WideString wsDate; date.FormatPatterns(wsDate, wsPicture, m_pDataAcc->GetLocal(), XFA_VALUEPICTURE_Edit); diff --git a/chromium/third_party/pdfium/xfa/fxfa/app/xfa_fftextedit.h b/chromium/third_party/pdfium/xfa/fxfa/app/xfa_fftextedit.h index 1e0562a75b3..9b9324f9d21 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/app/xfa_fftextedit.h +++ b/chromium/third_party/pdfium/xfa/fxfa/app/xfa_fftextedit.h @@ -36,14 +36,15 @@ class CXFA_FFTextEdit : public CXFA_FFField { bool CheckWord(const CFX_ByteStringC& sWord); protected: + uint32_t GetAlignment(); + + IFWL_WidgetDelegate* m_pOldDelegate; + + private: bool CommitData() override; bool UpdateFWLData() override; bool IsDataChanged() override; - - uint32_t GetAlignment(); void ValidateNumberField(const CFX_WideString& wsText); - - IFWL_WidgetDelegate* m_pOldDelegate; }; class CXFA_FFNumericEdit : public CXFA_FFTextEdit { @@ -56,7 +57,7 @@ class CXFA_FFNumericEdit : public CXFA_FFTextEdit { void UpdateWidgetProperty() override; void OnProcessEvent(CFWL_Event* pEvent) override; - public: + private: bool OnValidate(CFWL_Widget* pWidget, CFX_WideString& wsText); }; @@ -68,8 +69,6 @@ class CXFA_FFPasswordEdit : public CXFA_FFTextEdit { // CXFA_FFTextEdit bool LoadWidget() override; void UpdateWidgetProperty() override; - - protected: }; enum XFA_DATETIMETYPE { @@ -94,7 +93,7 @@ class CXFA_FFDateTimeEdit : public CXFA_FFTextEdit { int32_t iMonth, int32_t iDay); - protected: + private: bool PtInActiveRect(const CFX_PointF& point) override; bool CommitData() override; bool UpdateFWLData() override; diff --git a/chromium/third_party/pdfium/xfa/fxfa/app/xfa_ffwidgetacc.cpp b/chromium/third_party/pdfium/xfa/fxfa/app/xfa_ffwidgetacc.cpp index adc5c31cc66..760def2759f 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/app/xfa_ffwidgetacc.cpp +++ b/chromium/third_party/pdfium/xfa/fxfa/app/xfa_ffwidgetacc.cpp @@ -13,1525 +13,26 @@ #include "fxjs/cfxjse_value.h" #include "third_party/base/ptr_util.h" #include "third_party/base/stl_util.h" -#include "xfa/fde/tto/fde_textout.h" -#include "xfa/fde/xml/fde_xml_imp.h" +#include "xfa/fde/cfde_textout.h" +#include "xfa/fde/xml/cfde_xmlelement.h" +#include "xfa/fde/xml/cfde_xmlnode.h" #include "xfa/fxfa/app/xfa_ffcheckbutton.h" #include "xfa/fxfa/app/xfa_ffchoicelist.h" #include "xfa/fxfa/app/xfa_fffield.h" #include "xfa/fxfa/app/xfa_fwladapter.h" #include "xfa/fxfa/cxfa_eventparam.h" +#include "xfa/fxfa/cxfa_ffapp.h" +#include "xfa/fxfa/cxfa_ffdoc.h" +#include "xfa/fxfa/cxfa_ffdocview.h" +#include "xfa/fxfa/cxfa_ffpageview.h" +#include "xfa/fxfa/cxfa_ffwidget.h" +#include "xfa/fxfa/cxfa_fontmgr.h" #include "xfa/fxfa/parser/cxfa_layoutprocessor.h" +#include "xfa/fxfa/parser/cxfa_localevalue.h" +#include "xfa/fxfa/parser/cxfa_node.h" #include "xfa/fxfa/parser/cxfa_scriptcontext.h" -#include "xfa/fxfa/parser/xfa_localevalue.h" #include "xfa/fxfa/parser/xfa_resolvenode_rs.h" -#include "xfa/fxfa/xfa_ffapp.h" -#include "xfa/fxfa/xfa_ffdoc.h" -#include "xfa/fxfa/xfa_ffdocview.h" -#include "xfa/fxfa/xfa_ffpageview.h" -#include "xfa/fxfa/xfa_ffwidget.h" -#include "xfa/fxfa/xfa_fontmgr.h" -static void XFA_FFDeleteCalcData(void* pData) { - if (pData) { - delete ((CXFA_CalcData*)pData); - } -} - -static XFA_MAPDATABLOCKCALLBACKINFO gs_XFADeleteCalcData = { - XFA_FFDeleteCalcData, nullptr}; - -class CXFA_WidgetLayoutData { - public: - CXFA_WidgetLayoutData() : m_fWidgetHeight(-1) {} - virtual ~CXFA_WidgetLayoutData() {} - - FX_FLOAT m_fWidgetHeight; -}; - -class CXFA_TextLayoutData : public CXFA_WidgetLayoutData { - public: - CXFA_TextLayoutData() {} - ~CXFA_TextLayoutData() override {} - - CXFA_TextLayout* GetTextLayout() const { return m_pTextLayout.get(); } - CXFA_TextProvider* GetTextProvider() const { return m_pTextProvider.get(); } - - void LoadText(CXFA_WidgetAcc* pAcc) { - if (m_pTextLayout) - return; - - m_pTextProvider = - pdfium::MakeUnique<CXFA_TextProvider>(pAcc, XFA_TEXTPROVIDERTYPE_Text); - m_pTextLayout = pdfium::MakeUnique<CXFA_TextLayout>(m_pTextProvider.get()); - } - - private: - std::unique_ptr<CXFA_TextLayout> m_pTextLayout; - std::unique_ptr<CXFA_TextProvider> m_pTextProvider; -}; - -class CXFA_ImageLayoutData : public CXFA_WidgetLayoutData { - public: - CXFA_ImageLayoutData() - : m_pDIBitmap(nullptr), - m_bNamedImage(false), - m_iImageXDpi(0), - m_iImageYDpi(0) {} - - ~CXFA_ImageLayoutData() override { - if (m_pDIBitmap && !m_bNamedImage) - delete m_pDIBitmap; - } - - bool LoadImageData(CXFA_WidgetAcc* pAcc) { - if (m_pDIBitmap) - return true; - - CXFA_Value value = pAcc->GetFormValue(); - if (!value) - return false; - - CXFA_Image imageObj = value.GetImage(); - if (!imageObj) - return false; - - CXFA_FFDoc* pFFDoc = pAcc->GetDoc(); - pAcc->SetImageImage(XFA_LoadImageData(pFFDoc, &imageObj, m_bNamedImage, - m_iImageXDpi, m_iImageYDpi)); - return !!m_pDIBitmap; - } - - CFX_DIBitmap* m_pDIBitmap; - bool m_bNamedImage; - int32_t m_iImageXDpi; - int32_t m_iImageYDpi; -}; - -class CXFA_FieldLayoutData : public CXFA_WidgetLayoutData { - public: - CXFA_FieldLayoutData() {} - ~CXFA_FieldLayoutData() override {} - - bool LoadCaption(CXFA_WidgetAcc* pAcc) { - if (m_pCapTextLayout) - return true; - CXFA_Caption caption = pAcc->GetCaption(); - if (!caption || caption.GetPresence() == XFA_ATTRIBUTEENUM_Hidden) - return false; - m_pCapTextProvider.reset( - new CXFA_TextProvider(pAcc, XFA_TEXTPROVIDERTYPE_Caption)); - m_pCapTextLayout = - pdfium::MakeUnique<CXFA_TextLayout>(m_pCapTextProvider.get()); - return true; - } - - std::unique_ptr<CXFA_TextLayout> m_pCapTextLayout; - std::unique_ptr<CXFA_TextProvider> m_pCapTextProvider; - std::unique_ptr<CFDE_TextOut> m_pTextOut; - std::vector<FX_FLOAT> m_FieldSplitArray; -}; - -class CXFA_TextEditData : public CXFA_FieldLayoutData { - public: -}; - -class CXFA_ImageEditData : public CXFA_FieldLayoutData { - public: - CXFA_ImageEditData() - : m_pDIBitmap(nullptr), - m_bNamedImage(false), - m_iImageXDpi(0), - m_iImageYDpi(0) {} - - ~CXFA_ImageEditData() override { - if (m_pDIBitmap && !m_bNamedImage) - delete m_pDIBitmap; - } - - bool LoadImageData(CXFA_WidgetAcc* pAcc) { - if (m_pDIBitmap) - return true; - - CXFA_Value value = pAcc->GetFormValue(); - if (!value) - return false; - - CXFA_Image imageObj = value.GetImage(); - CXFA_FFDoc* pFFDoc = pAcc->GetDoc(); - pAcc->SetImageEditImage(XFA_LoadImageData(pFFDoc, &imageObj, m_bNamedImage, - m_iImageXDpi, m_iImageYDpi)); - return !!m_pDIBitmap; - } - - CFX_DIBitmap* m_pDIBitmap; - bool m_bNamedImage; - int32_t m_iImageXDpi; - int32_t m_iImageYDpi; -}; - -CXFA_WidgetAcc::CXFA_WidgetAcc(CXFA_FFDocView* pDocView, CXFA_Node* pNode) - : CXFA_WidgetData(pNode), - m_pDocView(pDocView), - m_nRecursionDepth(0) {} - -CXFA_WidgetAcc::~CXFA_WidgetAcc() {} - -bool CXFA_WidgetAcc::GetName(CFX_WideString& wsName, int32_t iNameType) { - if (iNameType == 0) { - m_pNode->TryCData(XFA_ATTRIBUTE_Name, wsName); - return !wsName.IsEmpty(); - } - m_pNode->GetSOMExpression(wsName); - if (iNameType == 2 && wsName.GetLength() >= 15) { - CFX_WideStringC wsPre = L"xfa[0].form[0]."; - if (wsPre == CFX_WideStringC(wsName.c_str(), wsPre.GetLength())) { - wsName.Delete(0, wsPre.GetLength()); - } - } - return true; -} -CXFA_Node* CXFA_WidgetAcc::GetDatasets() { - return m_pNode->GetBindData(); -} -bool CXFA_WidgetAcc::ProcessValueChanged() { - m_pDocView->AddValidateWidget(this); - m_pDocView->AddCalculateWidgetAcc(this); - m_pDocView->RunCalculateWidgets(); - m_pDocView->RunValidate(); - return true; -} -void CXFA_WidgetAcc::ResetData() { - CFX_WideString wsValue; - XFA_Element eUIType = GetUIType(); - switch (eUIType) { - case XFA_Element::ImageEdit: { - CXFA_Value imageValue = GetDefaultValue(); - CXFA_Image image = imageValue.GetImage(); - CFX_WideString wsContentType, wsHref; - if (image) { - image.GetContent(wsValue); - image.GetContentType(wsContentType); - image.GetHref(wsHref); - } - SetImageEdit(wsContentType, wsHref, wsValue); - } break; - case XFA_Element::ExclGroup: { - CXFA_Node* pNextChild = m_pNode->GetNodeItem( - XFA_NODEITEM_FirstChild, XFA_ObjectType::ContainerNode); - while (pNextChild) { - CXFA_Node* pChild = pNextChild; - CXFA_WidgetAcc* pAcc = - static_cast<CXFA_WidgetAcc*>(pChild->GetWidgetData()); - if (!pAcc) { - continue; - } - CXFA_Value defValue(nullptr); - if (wsValue.IsEmpty() && (defValue = pAcc->GetDefaultValue())) { - defValue.GetChildValueContent(wsValue); - SetValue(wsValue, XFA_VALUEPICTURE_Raw); - pAcc->SetValue(wsValue, XFA_VALUEPICTURE_Raw); - } else { - CXFA_Node* pItems = pChild->GetChild(0, XFA_Element::Items); - if (!pItems) { - continue; - } - CFX_WideString itemText; - if (pItems->CountChildren(XFA_Element::Unknown) > 1) { - itemText = pItems->GetChild(1, XFA_Element::Unknown)->GetContent(); - } - pAcc->SetValue(itemText, XFA_VALUEPICTURE_Raw); - } - pNextChild = pChild->GetNodeItem(XFA_NODEITEM_NextSibling, - XFA_ObjectType::ContainerNode); - } - } break; - case XFA_Element::ChoiceList: - ClearAllSelections(); - default: - if (CXFA_Value defValue = GetDefaultValue()) { - defValue.GetChildValueContent(wsValue); - } - SetValue(wsValue, XFA_VALUEPICTURE_Raw); - break; - } -} -void CXFA_WidgetAcc::SetImageEdit(const CFX_WideString& wsContentType, - const CFX_WideString& wsHref, - const CFX_WideString& wsData) { - CXFA_Image image = GetFormValue().GetImage(); - if (image) { - image.SetContentType(CFX_WideString(wsContentType)); - image.SetHref(wsHref); - } - CFX_WideString wsFormatValue(wsData); - GetFormatDataValue(wsData, wsFormatValue); - m_pNode->SetContent(wsData, wsFormatValue, true); - CXFA_Node* pBind = GetDatasets(); - if (!pBind) { - image.SetTransferEncoding(XFA_ATTRIBUTEENUM_Base64); - return; - } - pBind->SetCData(XFA_ATTRIBUTE_ContentType, wsContentType); - CXFA_Node* pHrefNode = pBind->GetNodeItem(XFA_NODEITEM_FirstChild); - if (pHrefNode) { - pHrefNode->SetCData(XFA_ATTRIBUTE_Value, wsHref); - } else { - CFDE_XMLNode* pXMLNode = pBind->GetXMLMappingNode(); - ASSERT(pXMLNode && pXMLNode->GetType() == FDE_XMLNODE_Element); - static_cast<CFDE_XMLElement*>(pXMLNode)->SetString(L"href", wsHref); - } -} - -CXFA_WidgetAcc* CXFA_WidgetAcc::GetExclGroup() { - CXFA_Node* pExcl = m_pNode->GetNodeItem(XFA_NODEITEM_Parent); - if (!pExcl || pExcl->GetElementType() != XFA_Element::ExclGroup) { - return nullptr; - } - return static_cast<CXFA_WidgetAcc*>(pExcl->GetWidgetData()); -} -CXFA_FFDocView* CXFA_WidgetAcc::GetDocView() { - return m_pDocView; -} -CXFA_FFDoc* CXFA_WidgetAcc::GetDoc() { - return m_pDocView->GetDoc(); -} -CXFA_FFApp* CXFA_WidgetAcc::GetApp() { - return GetDoc()->GetApp(); -} -IXFA_AppProvider* CXFA_WidgetAcc::GetAppProvider() { - return GetApp()->GetAppProvider(); -} -int32_t CXFA_WidgetAcc::ProcessEvent(int32_t iActivity, - CXFA_EventParam* pEventParam) { - if (GetElementType() == XFA_Element::Draw) { - return XFA_EVENTERROR_NotExist; - } - int32_t iRet = XFA_EVENTERROR_NotExist; - CXFA_NodeArray eventArray; - int32_t iCounts = - GetEventByActivity(iActivity, eventArray, pEventParam->m_bIsFormReady); - for (int32_t i = 0; i < iCounts; i++) { - CXFA_Event event(eventArray[i]); - int32_t result = ProcessEvent(event, pEventParam); - if (i == 0) { - iRet = result; - } else if (result == XFA_EVENTERROR_Success) { - iRet = result; - } - } - return iRet; -} -int32_t CXFA_WidgetAcc::ProcessEvent(CXFA_Event& event, - CXFA_EventParam* pEventParam) { - if (!event) - return XFA_EVENTERROR_NotExist; - - switch (event.GetEventType()) { - case XFA_Element::Execute: - break; - case XFA_Element::Script: { - CXFA_Script script = event.GetScript(); - return ExecuteScript(script, pEventParam); - } break; - case XFA_Element::SignData: - break; - case XFA_Element::Submit: { - CXFA_Submit submit = event.GetSubmit(); - return GetDoc()->GetDocEnvironment()->SubmitData(GetDoc(), submit); - } - default: - break; - } - return XFA_EVENTERROR_NotExist; -} - -int32_t CXFA_WidgetAcc::ProcessCalculate() { - if (GetElementType() == XFA_Element::Draw) - return XFA_EVENTERROR_NotExist; - - CXFA_Calculate calc = GetCalculate(); - if (!calc) - return XFA_EVENTERROR_NotExist; - if (GetNode()->IsUserInteractive()) - return XFA_EVENTERROR_Disabled; - - CXFA_EventParam EventParam; - EventParam.m_eType = XFA_EVENT_Calculate; - CXFA_Script script = calc.GetScript(); - int32_t iRet = ExecuteScript(script, &EventParam); - if (iRet != XFA_EVENTERROR_Success) - return iRet; - - if (GetRawValue() != EventParam.m_wsResult) { - SetValue(EventParam.m_wsResult, XFA_VALUEPICTURE_Raw); - UpdateUIDisplay(); - } - return XFA_EVENTERROR_Success; -} - -void CXFA_WidgetAcc::ProcessScriptTestValidate(CXFA_Validate validate, - int32_t iRet, - CFXJSE_Value* pRetValue, - bool bVersionFlag) { - if (iRet == XFA_EVENTERROR_Success && pRetValue) { - if (pRetValue->IsBoolean() && !pRetValue->ToBoolean()) { - IXFA_AppProvider* pAppProvider = GetAppProvider(); - if (!pAppProvider) { - return; - } - CFX_WideString wsTitle = pAppProvider->GetAppTitle(); - CFX_WideString wsScriptMsg; - validate.GetScriptMessageText(wsScriptMsg); - int32_t eScriptTest = validate.GetScriptTest(); - if (eScriptTest == XFA_ATTRIBUTEENUM_Warning) { - if (GetNode()->IsUserInteractive()) - return; - if (wsScriptMsg.IsEmpty()) - wsScriptMsg = GetValidateMessage(false, bVersionFlag); - - if (bVersionFlag) { - pAppProvider->MsgBox(wsScriptMsg, wsTitle, XFA_MBICON_Warning, - XFA_MB_OK); - return; - } - if (pAppProvider->MsgBox(wsScriptMsg, wsTitle, XFA_MBICON_Warning, - XFA_MB_YesNo) == XFA_IDYes) { - GetNode()->SetFlag(XFA_NodeFlag_UserInteractive, false); - } - } else { - if (wsScriptMsg.IsEmpty()) - wsScriptMsg = GetValidateMessage(true, bVersionFlag); - pAppProvider->MsgBox(wsScriptMsg, wsTitle, XFA_MBICON_Error, XFA_MB_OK); - } - } - } -} -int32_t CXFA_WidgetAcc::ProcessFormatTestValidate(CXFA_Validate validate, - bool bVersionFlag) { - CFX_WideString wsRawValue = GetRawValue(); - if (!wsRawValue.IsEmpty()) { - CFX_WideString wsPicture; - validate.GetPicture(wsPicture); - if (wsPicture.IsEmpty()) { - return XFA_EVENTERROR_NotExist; - } - IFX_Locale* pLocale = GetLocal(); - if (!pLocale) { - return XFA_EVENTERROR_NotExist; - } - CXFA_LocaleValue lcValue = XFA_GetLocaleValue(this); - if (!lcValue.ValidateValue(lcValue.GetValue(), wsPicture, pLocale)) { - IXFA_AppProvider* pAppProvider = GetAppProvider(); - if (!pAppProvider) { - return XFA_EVENTERROR_NotExist; - } - CFX_WideString wsFormatMsg; - validate.GetFormatMessageText(wsFormatMsg); - CFX_WideString wsTitle = pAppProvider->GetAppTitle(); - int32_t eFormatTest = validate.GetFormatTest(); - if (eFormatTest == XFA_ATTRIBUTEENUM_Error) { - if (wsFormatMsg.IsEmpty()) - wsFormatMsg = GetValidateMessage(true, bVersionFlag); - pAppProvider->MsgBox(wsFormatMsg, wsTitle, XFA_MBICON_Error, XFA_MB_OK); - return XFA_EVENTERROR_Success; - } - if (GetNode()->IsUserInteractive()) - return XFA_EVENTERROR_NotExist; - if (wsFormatMsg.IsEmpty()) - wsFormatMsg = GetValidateMessage(false, bVersionFlag); - - if (bVersionFlag) { - pAppProvider->MsgBox(wsFormatMsg, wsTitle, XFA_MBICON_Warning, - XFA_MB_OK); - return XFA_EVENTERROR_Success; - } - if (pAppProvider->MsgBox(wsFormatMsg, wsTitle, XFA_MBICON_Warning, - XFA_MB_YesNo) == XFA_IDYes) { - GetNode()->SetFlag(XFA_NodeFlag_UserInteractive, false); - } - return XFA_EVENTERROR_Success; - } - } - return XFA_EVENTERROR_NotExist; -} -int32_t CXFA_WidgetAcc::ProcessNullTestValidate(CXFA_Validate validate, - int32_t iFlags, - bool bVersionFlag) { - CFX_WideString wsValue; - GetValue(wsValue, XFA_VALUEPICTURE_Raw); - if (!wsValue.IsEmpty()) { - return XFA_EVENTERROR_Success; - } - if (m_bIsNull && (m_bPreNull == m_bIsNull)) { - return XFA_EVENTERROR_Success; - } - int32_t eNullTest = validate.GetNullTest(); - CFX_WideString wsNullMsg; - validate.GetNullMessageText(wsNullMsg); - if (iFlags & 0x01) { - int32_t iRet = XFA_EVENTERROR_Success; - if (eNullTest != XFA_ATTRIBUTEENUM_Disabled) { - iRet = XFA_EVENTERROR_Error; - } - if (!wsNullMsg.IsEmpty()) { - if (eNullTest != XFA_ATTRIBUTEENUM_Disabled) { - m_pDocView->m_arrNullTestMsg.push_back(wsNullMsg); - return XFA_EVENTERROR_Error; - } - return XFA_EVENTERROR_Success; - } - return iRet; - } - if (wsNullMsg.IsEmpty() && bVersionFlag && - eNullTest != XFA_ATTRIBUTEENUM_Disabled) { - return XFA_EVENTERROR_Error; - } - IXFA_AppProvider* pAppProvider = GetAppProvider(); - if (!pAppProvider) { - return XFA_EVENTERROR_NotExist; - } - CFX_WideString wsCaptionName; - CFX_WideString wsTitle = pAppProvider->GetAppTitle(); - switch (eNullTest) { - case XFA_ATTRIBUTEENUM_Error: { - if (wsNullMsg.IsEmpty()) { - wsCaptionName = GetValidateCaptionName(bVersionFlag); - wsNullMsg.Format(L"%s cannot be blank.", wsCaptionName.c_str()); - } - pAppProvider->MsgBox(wsNullMsg, wsTitle, XFA_MBICON_Status, XFA_MB_OK); - return XFA_EVENTERROR_Error; - } - case XFA_ATTRIBUTEENUM_Warning: { - if (GetNode()->IsUserInteractive()) - return true; - - if (wsNullMsg.IsEmpty()) { - wsCaptionName = GetValidateCaptionName(bVersionFlag); - wsNullMsg.Format( - L"%s cannot be blank. To ignore validations for %s, click Ignore.", - wsCaptionName.c_str(), wsCaptionName.c_str()); - } - if (pAppProvider->MsgBox(wsNullMsg, wsTitle, XFA_MBICON_Warning, - XFA_MB_YesNo) == XFA_IDYes) { - GetNode()->SetFlag(XFA_NodeFlag_UserInteractive, false); - } - return XFA_EVENTERROR_Error; - } - case XFA_ATTRIBUTEENUM_Disabled: - default: - break; - } - return XFA_EVENTERROR_Success; -} - -CFX_WideString CXFA_WidgetAcc::GetValidateCaptionName(bool bVersionFlag) { - CFX_WideString wsCaptionName; - - if (!bVersionFlag) { - if (CXFA_Caption caption = GetCaption()) { - if (CXFA_Value capValue = caption.GetValue()) { - if (CXFA_Text capText = capValue.GetText()) - capText.GetContent(wsCaptionName); - } - } - } - if (wsCaptionName.IsEmpty()) - GetName(wsCaptionName); - - return wsCaptionName; -} - -CFX_WideString CXFA_WidgetAcc::GetValidateMessage(bool bError, - bool bVersionFlag) { - CFX_WideString wsCaptionName = GetValidateCaptionName(bVersionFlag); - CFX_WideString wsMessage; - if (bVersionFlag) { - wsMessage.Format(L"%s validation failed", wsCaptionName.c_str()); - return wsMessage; - } - if (bError) { - wsMessage.Format(L"The value you entered for %s is invalid.", - wsCaptionName.c_str()); - return wsMessage; - } - wsMessage.Format( - L"The value you entered for %s is invalid. To ignore " - L"validations for %s, click Ignore.", - wsCaptionName.c_str(), wsCaptionName.c_str()); - return wsMessage; -} - -int32_t CXFA_WidgetAcc::ProcessValidate(int32_t iFlags) { - if (GetElementType() == XFA_Element::Draw) { - return XFA_EVENTERROR_NotExist; - } - CXFA_Validate validate = GetValidate(); - if (!validate) { - return XFA_EVENTERROR_NotExist; - } - bool bInitDoc = validate.GetNode()->NeedsInitApp(); - bool bStatus = m_pDocView->GetLayoutStatus() < XFA_DOCVIEW_LAYOUTSTATUS_End; - int32_t iFormat = 0; - CFXJSE_Value* pRetValue = nullptr; - int32_t iRet = XFA_EVENTERROR_NotExist; - CXFA_Script script = validate.GetScript(); - if (script) { - CXFA_EventParam eParam; - eParam.m_eType = XFA_EVENT_Validate; - eParam.m_pTarget = this; - iRet = ExecuteScript(script, &eParam, - ((bInitDoc || bStatus) && GetRawValue().IsEmpty()) - ? nullptr - : &pRetValue); - } - XFA_VERSION version = GetDoc()->GetXFADoc()->GetCurVersionMode(); - bool bVersionFlag = false; - if (version < XFA_VERSION_208) { - bVersionFlag = true; - } - if (bInitDoc) { - validate.GetNode()->ClearFlag(XFA_NodeFlag_NeedsInitApp); - } else { - iFormat = ProcessFormatTestValidate(validate, bVersionFlag); - if (!bVersionFlag) { - bVersionFlag = GetDoc()->GetXFADoc()->HasFlag(XFA_DOCFLAG_Scripting); - } - iRet |= ProcessNullTestValidate(validate, iFlags, bVersionFlag); - } - if (iFormat != XFA_EVENTERROR_Success) { - ProcessScriptTestValidate(validate, iRet, pRetValue, bVersionFlag); - } - delete pRetValue; - - return iRet | iFormat; -} -int32_t CXFA_WidgetAcc::ExecuteScript(CXFA_Script script, - CXFA_EventParam* pEventParam, - CFXJSE_Value** pRetValue) { - static const uint32_t MAX_RECURSION_DEPTH = 2; - if (m_nRecursionDepth > MAX_RECURSION_DEPTH) - return XFA_EVENTERROR_Success; - ASSERT(pEventParam); - if (!script) { - return XFA_EVENTERROR_NotExist; - } - if (script.GetRunAt() == XFA_ATTRIBUTEENUM_Server) { - return XFA_EVENTERROR_Disabled; - } - CFX_WideString wsExpression; - script.GetExpression(wsExpression); - if (wsExpression.IsEmpty()) { - return XFA_EVENTERROR_NotExist; - } - XFA_SCRIPTTYPE eScriptType = script.GetContentType(); - if (eScriptType == XFA_SCRIPTTYPE_Unkown) { - return XFA_EVENTERROR_Success; - } - CXFA_FFDoc* pDoc = GetDoc(); - CXFA_ScriptContext* pContext = pDoc->GetXFADoc()->GetScriptContext(); - pContext->SetEventParam(*pEventParam); - pContext->SetRunAtType((XFA_ATTRIBUTEENUM)script.GetRunAt()); - CXFA_NodeArray refNodes; - if (pEventParam->m_eType == XFA_EVENT_InitCalculate || - pEventParam->m_eType == XFA_EVENT_Calculate) { - pContext->SetNodesOfRunScript(&refNodes); - } - std::unique_ptr<CFXJSE_Value> pTmpRetValue( - new CFXJSE_Value(pContext->GetRuntime())); - ++m_nRecursionDepth; - bool bRet = pContext->RunScript((XFA_SCRIPTLANGTYPE)eScriptType, - wsExpression.AsStringC(), pTmpRetValue.get(), - m_pNode); - --m_nRecursionDepth; - int32_t iRet = XFA_EVENTERROR_Error; - if (bRet) { - iRet = XFA_EVENTERROR_Success; - if (pEventParam->m_eType == XFA_EVENT_Calculate || - pEventParam->m_eType == XFA_EVENT_InitCalculate) { - if (!pTmpRetValue->IsUndefined()) { - if (!pTmpRetValue->IsNull()) - pEventParam->m_wsResult = pTmpRetValue->ToWideString(); - - iRet = XFA_EVENTERROR_Success; - } else { - iRet = XFA_EVENTERROR_Error; - } - if (pEventParam->m_eType == XFA_EVENT_InitCalculate) { - if ((iRet == XFA_EVENTERROR_Success) && - (GetRawValue() != pEventParam->m_wsResult)) { - SetValue(pEventParam->m_wsResult, XFA_VALUEPICTURE_Raw); - m_pDocView->AddValidateWidget(this); - } - } - int32_t iRefs = refNodes.GetSize(); - for (int32_t r = 0; r < iRefs; r++) { - CXFA_WidgetAcc* pRefAcc = - static_cast<CXFA_WidgetAcc*>(refNodes[r]->GetWidgetData()); - if (pRefAcc && pRefAcc == this) { - continue; - } - CXFA_Node* pRefNode = refNodes[r]; - CXFA_CalcData* pGlobalData = - (CXFA_CalcData*)pRefNode->GetUserData(XFA_CalcData); - if (!pGlobalData) { - pGlobalData = new CXFA_CalcData; - pRefNode->SetUserData(XFA_CalcData, pGlobalData, - &gs_XFADeleteCalcData); - } - if (!pdfium::ContainsValue(pGlobalData->m_Globals, this)) - pGlobalData->m_Globals.push_back(this); - } - } - } - if (pRetValue) - *pRetValue = pTmpRetValue.release(); - - pContext->SetNodesOfRunScript(nullptr); - return iRet; -} -CXFA_FFWidget* CXFA_WidgetAcc::GetNextWidget(CXFA_FFWidget* pWidget) { - CXFA_LayoutItem* pLayout = nullptr; - if (pWidget) { - pLayout = pWidget->GetNext(); - } else { - pLayout = m_pDocView->GetXFALayout()->GetLayoutItem(m_pNode); - } - return static_cast<CXFA_FFWidget*>(pLayout); -} -void CXFA_WidgetAcc::UpdateUIDisplay(CXFA_FFWidget* pExcept) { - CXFA_FFWidget* pWidget = nullptr; - while ((pWidget = GetNextWidget(pWidget)) != nullptr) { - if (pWidget == pExcept || !pWidget->IsLoaded() || - (GetUIType() != XFA_Element::CheckButton && pWidget->IsFocused())) { - continue; - } - pWidget->UpdateFWLData(); - pWidget->AddInvalidateRect(); - } -} - -void CXFA_WidgetAcc::CalcCaptionSize(CFX_SizeF& szCap) { - CXFA_Caption caption = GetCaption(); - if (!caption || caption.GetPresence() != XFA_ATTRIBUTEENUM_Visible) { - return; - } - LoadCaption(); - XFA_Element eUIType = GetUIType(); - int32_t iCapPlacement = caption.GetPlacementType(); - FX_FLOAT fCapReserve = caption.GetReserve(); - const bool bVert = iCapPlacement == XFA_ATTRIBUTEENUM_Top || - iCapPlacement == XFA_ATTRIBUTEENUM_Bottom; - const bool bReserveExit = fCapReserve > 0.01; - CXFA_TextLayout* pCapTextLayout = - static_cast<CXFA_FieldLayoutData*>(m_pLayoutData.get()) - ->m_pCapTextLayout.get(); - if (pCapTextLayout) { - if (!bVert && eUIType != XFA_Element::Button) { - szCap.width = fCapReserve; - } - CFX_SizeF minSize; - pCapTextLayout->CalcSize(minSize, szCap, szCap); - if (bReserveExit) { - bVert ? szCap.height = fCapReserve : szCap.width = fCapReserve; - } - } else { - FX_FLOAT fFontSize = 10.0f; - if (CXFA_Font font = caption.GetFont()) { - fFontSize = font.GetFontSize(); - } else if (CXFA_Font widgetfont = GetFont()) { - fFontSize = widgetfont.GetFontSize(); - } - if (bVert) { - szCap.height = fCapReserve > 0 ? fCapReserve : fFontSize; - } else { - szCap.width = fCapReserve > 0 ? fCapReserve : 0; - szCap.height = fFontSize; - } - } - if (CXFA_Margin mgCap = caption.GetMargin()) { - FX_FLOAT fLeftInset, fTopInset, fRightInset, fBottomInset; - mgCap.GetLeftInset(fLeftInset); - mgCap.GetTopInset(fTopInset); - mgCap.GetRightInset(fRightInset); - mgCap.GetBottomInset(fBottomInset); - if (bReserveExit) { - bVert ? (szCap.width += fLeftInset + fRightInset) - : (szCap.height += fTopInset + fBottomInset); - } else { - szCap.width += fLeftInset + fRightInset; - szCap.height += fTopInset + fBottomInset; - } - } -} -bool CXFA_WidgetAcc::CalculateFieldAutoSize(CFX_SizeF& size) { - CFX_SizeF szCap; - CalcCaptionSize(szCap); - CFX_RectF rtUIMargin = GetUIMargin(); - size.width += rtUIMargin.left + rtUIMargin.width; - size.height += rtUIMargin.top + rtUIMargin.height; - if (szCap.width > 0 && szCap.height > 0) { - int32_t iCapPlacement = GetCaption().GetPlacementType(); - switch (iCapPlacement) { - case XFA_ATTRIBUTEENUM_Left: - case XFA_ATTRIBUTEENUM_Right: - case XFA_ATTRIBUTEENUM_Inline: { - size.width += szCap.width; - size.height = std::max(size.height, szCap.height); - } break; - case XFA_ATTRIBUTEENUM_Top: - case XFA_ATTRIBUTEENUM_Bottom: { - size.height += szCap.height; - size.width = std::max(size.width, szCap.width); - } - default: - break; - } - } - return CalculateWidgetAutoSize(size); -} -bool CXFA_WidgetAcc::CalculateWidgetAutoSize(CFX_SizeF& size) { - CXFA_Margin mgWidget = GetMargin(); - if (mgWidget) { - FX_FLOAT fLeftInset, fTopInset, fRightInset, fBottomInset; - mgWidget.GetLeftInset(fLeftInset); - mgWidget.GetTopInset(fTopInset); - mgWidget.GetRightInset(fRightInset); - mgWidget.GetBottomInset(fBottomInset); - size.width += fLeftInset + fRightInset; - size.height += fTopInset + fBottomInset; - } - CXFA_Para para = GetPara(); - if (para) - size.width += para.GetMarginLeft() + para.GetTextIndent(); - - FX_FLOAT fVal = 0; - FX_FLOAT fMin = 0; - FX_FLOAT fMax = 0; - if (GetWidth(fVal)) { - size.width = fVal; - } else { - if (GetMinWidth(fMin)) - size.width = std::max(size.width, fMin); - if (GetMaxWidth(fMax) && fMax > 0) - size.width = std::min(size.width, fMax); - } - fVal = 0; - fMin = 0; - fMax = 0; - if (GetHeight(fVal)) { - size.height = fVal; - } else { - if (GetMinHeight(fMin)) - size.height = std::max(size.height, fMin); - if (GetMaxHeight(fMax) && fMax > 0) - size.height = std::min(size.height, fMax); - } - return true; -} - -void CXFA_WidgetAcc::CalculateTextContentSize(CFX_SizeF& size) { - FX_FLOAT fFontSize = GetFontSize(); - CFX_WideString wsText; - GetValue(wsText, XFA_VALUEPICTURE_Display); - if (wsText.IsEmpty()) { - size.height += fFontSize; - return; - } - - FX_WCHAR wcEnter = '\n'; - FX_WCHAR wsLast = wsText.GetAt(wsText.GetLength() - 1); - if (wsLast == wcEnter) { - wsText = wsText + wcEnter; - } - - CXFA_FieldLayoutData* layoutData = - static_cast<CXFA_FieldLayoutData*>(m_pLayoutData.get()); - if (!layoutData->m_pTextOut) { - layoutData->m_pTextOut = pdfium::MakeUnique<CFDE_TextOut>(); - CFDE_TextOut* pTextOut = layoutData->m_pTextOut.get(); - pTextOut->SetFont(GetFDEFont()); - pTextOut->SetFontSize(fFontSize); - pTextOut->SetLineBreakTolerance(fFontSize * 0.2f); - pTextOut->SetLineSpace(GetLineHeight()); - uint32_t dwStyles = FDE_TTOSTYLE_LastLineHeight; - if (GetUIType() == XFA_Element::TextEdit && IsMultiLine()) { - dwStyles |= FDE_TTOSTYLE_LineWrap; - } - pTextOut->SetStyles(dwStyles); - } - layoutData->m_pTextOut->CalcLogicSize(wsText.c_str(), wsText.GetLength(), - size); -} -bool CXFA_WidgetAcc::CalculateTextEditAutoSize(CFX_SizeF& size) { - if (size.width > 0) { - CFX_SizeF szOrz = size; - CFX_SizeF szCap; - CalcCaptionSize(szCap); - bool bCapExit = szCap.width > 0.01 && szCap.height > 0.01; - int32_t iCapPlacement = XFA_ATTRIBUTEENUM_Unknown; - if (bCapExit) { - iCapPlacement = GetCaption().GetPlacementType(); - switch (iCapPlacement) { - case XFA_ATTRIBUTEENUM_Left: - case XFA_ATTRIBUTEENUM_Right: - case XFA_ATTRIBUTEENUM_Inline: { - size.width -= szCap.width; - } - default: - break; - } - } - CFX_RectF rtUIMargin = GetUIMargin(); - size.width -= rtUIMargin.left + rtUIMargin.width; - CXFA_Margin mgWidget = GetMargin(); - if (mgWidget) { - FX_FLOAT fLeftInset, fRightInset; - mgWidget.GetLeftInset(fLeftInset); - mgWidget.GetRightInset(fRightInset); - size.width -= fLeftInset + fRightInset; - } - CalculateTextContentSize(size); - size.height += rtUIMargin.top + rtUIMargin.height; - if (bCapExit) { - switch (iCapPlacement) { - case XFA_ATTRIBUTEENUM_Left: - case XFA_ATTRIBUTEENUM_Right: - case XFA_ATTRIBUTEENUM_Inline: { - size.height = std::max(size.height, szCap.height); - } break; - case XFA_ATTRIBUTEENUM_Top: - case XFA_ATTRIBUTEENUM_Bottom: { - size.height += szCap.height; - } - default: - break; - } - } - size.width = szOrz.width; - return CalculateWidgetAutoSize(size); - } - CalculateTextContentSize(size); - return CalculateFieldAutoSize(size); -} -bool CXFA_WidgetAcc::CalculateCheckButtonAutoSize(CFX_SizeF& size) { - FX_FLOAT fCheckSize = GetCheckButtonSize(); - size = CFX_SizeF(fCheckSize, fCheckSize); - return CalculateFieldAutoSize(size); -} -bool CXFA_WidgetAcc::CalculatePushButtonAutoSize(CFX_SizeF& size) { - CalcCaptionSize(size); - return CalculateWidgetAutoSize(size); -} -bool CXFA_WidgetAcc::CalculateImageAutoSize(CFX_SizeF& size) { - if (!GetImageImage()) { - LoadImageImage(); - } - size.clear(); - if (CFX_DIBitmap* pBitmap = GetImageImage()) { - int32_t iImageXDpi = 0; - int32_t iImageYDpi = 0; - GetImageDpi(iImageXDpi, iImageYDpi); - CFX_RectF rtImage( - 0, 0, - XFA_UnitPx2Pt((FX_FLOAT)pBitmap->GetWidth(), (FX_FLOAT)iImageXDpi), - XFA_UnitPx2Pt((FX_FLOAT)pBitmap->GetHeight(), (FX_FLOAT)iImageYDpi)); - - CFX_RectF rtFit; - if (GetWidth(rtFit.width)) { - GetWidthWithoutMargin(rtFit.width); - } else { - rtFit.width = rtImage.width; - } - if (GetHeight(rtFit.height)) { - GetHeightWithoutMargin(rtFit.height); - } else { - rtFit.height = rtImage.height; - } - size = rtFit.Size(); - } - return CalculateWidgetAutoSize(size); -} -bool CXFA_WidgetAcc::CalculateImageEditAutoSize(CFX_SizeF& size) { - if (!GetImageEditImage()) { - LoadImageEditImage(); - } - size.clear(); - if (CFX_DIBitmap* pBitmap = GetImageEditImage()) { - int32_t iImageXDpi = 0; - int32_t iImageYDpi = 0; - GetImageEditDpi(iImageXDpi, iImageYDpi); - CFX_RectF rtImage( - 0, 0, - XFA_UnitPx2Pt((FX_FLOAT)pBitmap->GetWidth(), (FX_FLOAT)iImageXDpi), - XFA_UnitPx2Pt((FX_FLOAT)pBitmap->GetHeight(), (FX_FLOAT)iImageYDpi)); - - CFX_RectF rtFit; - if (GetWidth(rtFit.width)) { - GetWidthWithoutMargin(rtFit.width); - } else { - rtFit.width = rtImage.width; - } - if (GetHeight(rtFit.height)) { - GetHeightWithoutMargin(rtFit.height); - } else { - rtFit.height = rtImage.height; - } - size.width = rtFit.width; - size.height = rtFit.height; - } - return CalculateFieldAutoSize(size); -} -bool CXFA_WidgetAcc::LoadImageImage() { - InitLayoutData(); - return static_cast<CXFA_ImageLayoutData*>(m_pLayoutData.get()) - ->LoadImageData(this); -} -bool CXFA_WidgetAcc::LoadImageEditImage() { - InitLayoutData(); - return static_cast<CXFA_ImageEditData*>(m_pLayoutData.get()) - ->LoadImageData(this); -} -void CXFA_WidgetAcc::GetImageDpi(int32_t& iImageXDpi, int32_t& iImageYDpi) { - CXFA_ImageLayoutData* pData = - static_cast<CXFA_ImageLayoutData*>(m_pLayoutData.get()); - iImageXDpi = pData->m_iImageXDpi; - iImageYDpi = pData->m_iImageYDpi; -} -void CXFA_WidgetAcc::GetImageEditDpi(int32_t& iImageXDpi, int32_t& iImageYDpi) { - CXFA_ImageEditData* pData = - static_cast<CXFA_ImageEditData*>(m_pLayoutData.get()); - iImageXDpi = pData->m_iImageXDpi; - iImageYDpi = pData->m_iImageYDpi; -} -bool CXFA_WidgetAcc::CalculateTextAutoSize(CFX_SizeF& size) { - LoadText(); - CXFA_TextLayout* pTextLayout = - static_cast<CXFA_TextLayoutData*>(m_pLayoutData.get())->GetTextLayout(); - if (pTextLayout) { - size.width = pTextLayout->StartLayout(size.width); - size.height = pTextLayout->GetLayoutHeight(); - } - return CalculateWidgetAutoSize(size); -} -void CXFA_WidgetAcc::LoadText() { - InitLayoutData(); - static_cast<CXFA_TextLayoutData*>(m_pLayoutData.get())->LoadText(this); -} -FX_FLOAT CXFA_WidgetAcc::CalculateWidgetAutoWidth(FX_FLOAT fWidthCalc) { - CXFA_Margin mgWidget = GetMargin(); - if (mgWidget) { - FX_FLOAT fLeftInset, fRightInset; - mgWidget.GetLeftInset(fLeftInset); - mgWidget.GetRightInset(fRightInset); - fWidthCalc += fLeftInset + fRightInset; - } - FX_FLOAT fMin = 0, fMax = 0; - if (GetMinWidth(fMin)) { - fWidthCalc = std::max(fWidthCalc, fMin); - } - if (GetMaxWidth(fMax) && fMax > 0) { - fWidthCalc = std::min(fWidthCalc, fMax); - } - return fWidthCalc; -} -FX_FLOAT CXFA_WidgetAcc::GetWidthWithoutMargin(FX_FLOAT fWidthCalc) { - CXFA_Margin mgWidget = GetMargin(); - if (mgWidget) { - FX_FLOAT fLeftInset, fRightInset; - mgWidget.GetLeftInset(fLeftInset); - mgWidget.GetRightInset(fRightInset); - fWidthCalc -= fLeftInset + fRightInset; - } - return fWidthCalc; -} -FX_FLOAT CXFA_WidgetAcc::CalculateWidgetAutoHeight(FX_FLOAT fHeightCalc) { - CXFA_Margin mgWidget = GetMargin(); - if (mgWidget) { - FX_FLOAT fTopInset, fBottomInset; - mgWidget.GetTopInset(fTopInset); - mgWidget.GetBottomInset(fBottomInset); - fHeightCalc += fTopInset + fBottomInset; - } - FX_FLOAT fMin = 0, fMax = 0; - if (GetMinHeight(fMin)) { - fHeightCalc = std::max(fHeightCalc, fMin); - } - if (GetMaxHeight(fMax) && fMax > 0) { - fHeightCalc = std::min(fHeightCalc, fMax); - } - return fHeightCalc; -} -FX_FLOAT CXFA_WidgetAcc::GetHeightWithoutMargin(FX_FLOAT fHeightCalc) { - CXFA_Margin mgWidget = GetMargin(); - if (mgWidget) { - FX_FLOAT fTopInset, fBottomInset; - mgWidget.GetTopInset(fTopInset); - mgWidget.GetBottomInset(fBottomInset); - fHeightCalc -= fTopInset + fBottomInset; - } - return fHeightCalc; -} -void CXFA_WidgetAcc::StartWidgetLayout(FX_FLOAT& fCalcWidth, - FX_FLOAT& fCalcHeight) { - InitLayoutData(); - XFA_Element eUIType = GetUIType(); - if (eUIType == XFA_Element::Text) { - m_pLayoutData->m_fWidgetHeight = -1; - GetHeight(m_pLayoutData->m_fWidgetHeight); - StartTextLayout(fCalcWidth, fCalcHeight); - return; - } - if (fCalcWidth > 0 && fCalcHeight > 0) { - return; - } - m_pLayoutData->m_fWidgetHeight = -1; - FX_FLOAT fWidth = 0; - if (fCalcWidth > 0 && fCalcHeight < 0) { - if (!GetHeight(fCalcHeight)) { - CalculateAccWidthAndHeight(eUIType, fCalcWidth, fCalcHeight); - } - m_pLayoutData->m_fWidgetHeight = fCalcHeight; - return; - } - if (fCalcWidth < 0 && fCalcHeight < 0) { - if (!GetWidth(fWidth) || !GetHeight(fCalcHeight)) { - CalculateAccWidthAndHeight(eUIType, fWidth, fCalcHeight); - } - fCalcWidth = fWidth; - } - m_pLayoutData->m_fWidgetHeight = fCalcHeight; -} -void CXFA_WidgetAcc::CalculateAccWidthAndHeight(XFA_Element eUIType, - FX_FLOAT& fWidth, - FX_FLOAT& fCalcHeight) { - CFX_SizeF sz(fWidth, m_pLayoutData->m_fWidgetHeight); - switch (eUIType) { - case XFA_Element::Barcode: - case XFA_Element::ChoiceList: - case XFA_Element::Signature: - CalculateFieldAutoSize(sz); - break; - case XFA_Element::ImageEdit: - CalculateImageEditAutoSize(sz); - break; - case XFA_Element::Button: - CalculatePushButtonAutoSize(sz); - break; - case XFA_Element::CheckButton: - CalculateCheckButtonAutoSize(sz); - break; - case XFA_Element::DateTimeEdit: - case XFA_Element::NumericEdit: - case XFA_Element::PasswordEdit: - case XFA_Element::TextEdit: - CalculateTextEditAutoSize(sz); - break; - case XFA_Element::Image: - CalculateImageAutoSize(sz); - break; - case XFA_Element::Arc: - case XFA_Element::Line: - case XFA_Element::Rectangle: - case XFA_Element::Subform: - case XFA_Element::ExclGroup: - CalculateWidgetAutoSize(sz); - break; - default: - break; - } - fWidth = sz.width; - m_pLayoutData->m_fWidgetHeight = sz.height; - fCalcHeight = sz.height; -} -bool CXFA_WidgetAcc::FindSplitPos(int32_t iBlockIndex, FX_FLOAT& fCalcHeight) { - XFA_Element eUIType = GetUIType(); - if (eUIType == XFA_Element::Subform) { - return false; - } - if (eUIType != XFA_Element::Text && eUIType != XFA_Element::TextEdit && - eUIType != XFA_Element::NumericEdit && - eUIType != XFA_Element::PasswordEdit) { - fCalcHeight = 0; - return true; - } - FX_FLOAT fTopInset = 0; - FX_FLOAT fBottomInset = 0; - if (iBlockIndex == 0) { - CXFA_Margin mgWidget = GetMargin(); - if (mgWidget) { - mgWidget.GetTopInset(fTopInset); - mgWidget.GetBottomInset(fBottomInset); - } - CFX_RectF rtUIMargin = GetUIMargin(); - fTopInset += rtUIMargin.top; - fBottomInset += rtUIMargin.width; - } - if (eUIType == XFA_Element::Text) { - FX_FLOAT fHeight = fCalcHeight; - if (iBlockIndex == 0) { - fCalcHeight = fCalcHeight - fTopInset; - if (fCalcHeight < 0) { - fCalcHeight = 0; - } - } - CXFA_TextLayout* pTextLayout = - static_cast<CXFA_TextLayoutData*>(m_pLayoutData.get())->GetTextLayout(); - pTextLayout->DoLayout(iBlockIndex, fCalcHeight, fCalcHeight, - m_pLayoutData->m_fWidgetHeight - fTopInset); - if (fCalcHeight != 0) { - if (iBlockIndex == 0) { - fCalcHeight = fCalcHeight + fTopInset; - } - if (fabs(fHeight - fCalcHeight) < XFA_FLOAT_PERCISION) { - return false; - } - } - return true; - } - XFA_ATTRIBUTEENUM iCapPlacement = XFA_ATTRIBUTEENUM_Unknown; - FX_FLOAT fCapReserve = 0; - if (iBlockIndex == 0) { - CXFA_Caption caption = GetCaption(); - if (caption && caption.GetPresence() != XFA_ATTRIBUTEENUM_Hidden) { - iCapPlacement = (XFA_ATTRIBUTEENUM)caption.GetPlacementType(); - fCapReserve = caption.GetReserve(); - } - if (iCapPlacement == XFA_ATTRIBUTEENUM_Top && - fCalcHeight < fCapReserve + fTopInset) { - fCalcHeight = 0; - return true; - } - if (iCapPlacement == XFA_ATTRIBUTEENUM_Bottom && - m_pLayoutData->m_fWidgetHeight - fCapReserve - fBottomInset) { - fCalcHeight = 0; - return true; - } - if (iCapPlacement != XFA_ATTRIBUTEENUM_Top) { - fCapReserve = 0; - } - } - CXFA_FieldLayoutData* pFieldData = - static_cast<CXFA_FieldLayoutData*>(m_pLayoutData.get()); - int32_t iLinesCount = 0; - FX_FLOAT fHeight = m_pLayoutData->m_fWidgetHeight; - CFX_WideString wsText; - GetValue(wsText, XFA_VALUEPICTURE_Display); - if (wsText.IsEmpty()) { - iLinesCount = 1; - } else { - if (!pFieldData->m_pTextOut) { - FX_FLOAT fWidth = 0; - GetWidth(fWidth); - CalculateAccWidthAndHeight(eUIType, fWidth, fHeight); - } - iLinesCount = pFieldData->m_pTextOut->GetTotalLines(); - } - std::vector<FX_FLOAT>* pFieldArray = &pFieldData->m_FieldSplitArray; - int32_t iFieldSplitCount = pdfium::CollectionSize<int32_t>(*pFieldArray); - for (int32_t i = 0; i < iBlockIndex * 3; i += 3) { - iLinesCount -= (int32_t)(*pFieldArray)[i + 1]; - fHeight -= (*pFieldArray)[i + 2]; - } - if (iLinesCount == 0) { - return false; - } - FX_FLOAT fLineHeight = GetLineHeight(); - FX_FLOAT fFontSize = GetFontSize(); - FX_FLOAT fTextHeight = iLinesCount * fLineHeight - fLineHeight + fFontSize; - FX_FLOAT fSpaceAbove = 0; - FX_FLOAT fStartOffset = 0; - if (fHeight > 0.1f && iBlockIndex == 0) { - fStartOffset = fTopInset; - fHeight -= (fTopInset + fBottomInset); - if (CXFA_Para para = GetPara()) { - fSpaceAbove = para.GetSpaceAbove(); - FX_FLOAT fSpaceBelow = para.GetSpaceBelow(); - fHeight -= (fSpaceAbove + fSpaceBelow); - switch (para.GetVerticalAlign()) { - case XFA_ATTRIBUTEENUM_Top: - fStartOffset += fSpaceAbove; - break; - case XFA_ATTRIBUTEENUM_Middle: - fStartOffset += ((fHeight - fTextHeight) / 2 + fSpaceAbove); - break; - case XFA_ATTRIBUTEENUM_Bottom: - fStartOffset += (fHeight - fTextHeight + fSpaceAbove); - break; - } - } - if (fStartOffset < 0.1f) - fStartOffset = 0; - } - for (int32_t i = iBlockIndex - 1; iBlockIndex > 0 && i < iBlockIndex; i++) { - fStartOffset = (*pFieldArray)[i * 3] - (*pFieldArray)[i * 3 + 2]; - if (fStartOffset < 0.1f) - fStartOffset = 0; - } - if (iFieldSplitCount / 3 == (iBlockIndex + 1)) { - (*pFieldArray)[0] = fStartOffset; - } else { - pFieldArray->push_back(fStartOffset); - } - XFA_VERSION version = GetDoc()->GetXFADoc()->GetCurVersionMode(); - bool bCanSplitNoContent = false; - XFA_ATTRIBUTEENUM eLayoutMode; - GetNode() - ->GetNodeItem(XFA_NODEITEM_Parent) - ->TryEnum(XFA_ATTRIBUTE_Layout, eLayoutMode, true); - if ((eLayoutMode == XFA_ATTRIBUTEENUM_Position || - eLayoutMode == XFA_ATTRIBUTEENUM_Tb || - eLayoutMode == XFA_ATTRIBUTEENUM_Row || - eLayoutMode == XFA_ATTRIBUTEENUM_Table) && - version > XFA_VERSION_208) { - bCanSplitNoContent = true; - } - if ((eLayoutMode == XFA_ATTRIBUTEENUM_Tb || - eLayoutMode == XFA_ATTRIBUTEENUM_Row || - eLayoutMode == XFA_ATTRIBUTEENUM_Table) && - version <= XFA_VERSION_208) { - if (fStartOffset < fCalcHeight) { - bCanSplitNoContent = true; - } else { - fCalcHeight = 0; - return true; - } - } - if (bCanSplitNoContent) { - if ((fCalcHeight - fTopInset - fSpaceAbove < fLineHeight)) { - fCalcHeight = 0; - return true; - } - if (fStartOffset + XFA_FLOAT_PERCISION >= fCalcHeight) { - if (iFieldSplitCount / 3 == (iBlockIndex + 1)) { - (*pFieldArray)[iBlockIndex * 3 + 1] = 0; - (*pFieldArray)[iBlockIndex * 3 + 2] = fCalcHeight; - } else { - pFieldArray->push_back(0); - pFieldArray->push_back(fCalcHeight); - } - return false; - } - if (fCalcHeight - fStartOffset < fLineHeight) { - fCalcHeight = fStartOffset; - if (iFieldSplitCount / 3 == (iBlockIndex + 1)) { - (*pFieldArray)[iBlockIndex * 3 + 1] = 0; - (*pFieldArray)[iBlockIndex * 3 + 2] = fCalcHeight; - } else { - pFieldArray->push_back(0); - pFieldArray->push_back(fCalcHeight); - } - return true; - } - FX_FLOAT fTextNum = - fCalcHeight + XFA_FLOAT_PERCISION - fCapReserve - fStartOffset; - int32_t iLineNum = - (int32_t)((fTextNum + (fLineHeight - fFontSize)) / fLineHeight); - if (iLineNum >= iLinesCount) { - if (fCalcHeight - fStartOffset - fTextHeight >= fFontSize) { - if (iFieldSplitCount / 3 == (iBlockIndex + 1)) { - (*pFieldArray)[iBlockIndex * 3 + 1] = (FX_FLOAT)iLinesCount; - (*pFieldArray)[iBlockIndex * 3 + 2] = fCalcHeight; - } else { - pFieldArray->push_back((FX_FLOAT)iLinesCount); - pFieldArray->push_back(fCalcHeight); - } - return false; - } - if (fHeight - fStartOffset - fTextHeight < fFontSize) { - iLineNum -= 1; - if (iLineNum == 0) { - fCalcHeight = 0; - return true; - } - } else { - iLineNum = (int32_t)(fTextNum / fLineHeight); - } - } - if (iLineNum > 0) { - FX_FLOAT fSplitHeight = - iLineNum * fLineHeight + fCapReserve + fStartOffset; - if (iFieldSplitCount / 3 == (iBlockIndex + 1)) { - (*pFieldArray)[iBlockIndex * 3 + 1] = (FX_FLOAT)iLineNum; - (*pFieldArray)[iBlockIndex * 3 + 2] = fSplitHeight; - } else { - pFieldArray->push_back((FX_FLOAT)iLineNum); - pFieldArray->push_back(fSplitHeight); - } - if (fabs(fSplitHeight - fCalcHeight) < XFA_FLOAT_PERCISION) { - return false; - } - fCalcHeight = fSplitHeight; - return true; - } - } - fCalcHeight = 0; - return true; -} -void CXFA_WidgetAcc::InitLayoutData() { - if (m_pLayoutData) { - return; - } - switch (GetUIType()) { - case XFA_Element::Text: - m_pLayoutData = pdfium::MakeUnique<CXFA_TextLayoutData>(); - return; - case XFA_Element::TextEdit: - m_pLayoutData = pdfium::MakeUnique<CXFA_TextEditData>(); - return; - case XFA_Element::Image: - m_pLayoutData = pdfium::MakeUnique<CXFA_ImageLayoutData>(); - return; - case XFA_Element::ImageEdit: - m_pLayoutData = pdfium::MakeUnique<CXFA_ImageEditData>(); - return; - default: - break; - } - if (GetElementType() == XFA_Element::Field) { - m_pLayoutData = pdfium::MakeUnique<CXFA_FieldLayoutData>(); - return; - } - m_pLayoutData = pdfium::MakeUnique<CXFA_WidgetLayoutData>(); -} - -void CXFA_WidgetAcc::StartTextLayout(FX_FLOAT& fCalcWidth, - FX_FLOAT& fCalcHeight) { - LoadText(); - CXFA_TextLayout* pTextLayout = - static_cast<CXFA_TextLayoutData*>(m_pLayoutData.get())->GetTextLayout(); - FX_FLOAT fTextHeight = 0; - if (fCalcWidth > 0 && fCalcHeight > 0) { - FX_FLOAT fWidth = GetWidthWithoutMargin(fCalcWidth); - pTextLayout->StartLayout(fWidth); - fTextHeight = fCalcHeight; - fTextHeight = GetHeightWithoutMargin(fTextHeight); - pTextLayout->DoLayout(0, fTextHeight, -1, fTextHeight); - return; - } - if (fCalcWidth > 0 && fCalcHeight < 0) { - FX_FLOAT fWidth = GetWidthWithoutMargin(fCalcWidth); - pTextLayout->StartLayout(fWidth); - } - if (fCalcWidth < 0 && fCalcHeight < 0) { - FX_FLOAT fMaxWidth = -1; - bool bRet = GetWidth(fMaxWidth); - if (bRet) { - FX_FLOAT fWidth = GetWidthWithoutMargin(fMaxWidth); - pTextLayout->StartLayout(fWidth); - } else { - FX_FLOAT fWidth = pTextLayout->StartLayout(fMaxWidth); - fMaxWidth = CalculateWidgetAutoWidth(fWidth); - fWidth = GetWidthWithoutMargin(fMaxWidth); - pTextLayout->StartLayout(fWidth); - } - fCalcWidth = fMaxWidth; - } - if (m_pLayoutData->m_fWidgetHeight < 0) { - m_pLayoutData->m_fWidgetHeight = pTextLayout->GetLayoutHeight(); - m_pLayoutData->m_fWidgetHeight = - CalculateWidgetAutoHeight(m_pLayoutData->m_fWidgetHeight); - } - fTextHeight = m_pLayoutData->m_fWidgetHeight; - fTextHeight = GetHeightWithoutMargin(fTextHeight); - pTextLayout->DoLayout(0, fTextHeight, -1, fTextHeight); - fCalcHeight = m_pLayoutData->m_fWidgetHeight; -} -bool CXFA_WidgetAcc::LoadCaption() { - InitLayoutData(); - return static_cast<CXFA_FieldLayoutData*>(m_pLayoutData.get()) - ->LoadCaption(this); -} -CXFA_TextLayout* CXFA_WidgetAcc::GetCaptionTextLayout() { - return m_pLayoutData - ? static_cast<CXFA_FieldLayoutData*>(m_pLayoutData.get()) - ->m_pCapTextLayout.get() - : nullptr; -} -CXFA_TextLayout* CXFA_WidgetAcc::GetTextLayout() { - return m_pLayoutData - ? static_cast<CXFA_TextLayoutData*>(m_pLayoutData.get()) - ->GetTextLayout() - : nullptr; -} -CFX_DIBitmap* CXFA_WidgetAcc::GetImageImage() { - return m_pLayoutData - ? static_cast<CXFA_ImageLayoutData*>(m_pLayoutData.get()) - ->m_pDIBitmap - : nullptr; -} -CFX_DIBitmap* CXFA_WidgetAcc::GetImageEditImage() { - return m_pLayoutData - ? static_cast<CXFA_ImageEditData*>(m_pLayoutData.get()) - ->m_pDIBitmap - : nullptr; -} - -void CXFA_WidgetAcc::SetImageImage(CFX_DIBitmap* newImage) { - CXFA_ImageLayoutData* pData = - static_cast<CXFA_ImageLayoutData*>(m_pLayoutData.get()); - if (pData->m_pDIBitmap == newImage) - return; - - if (pData->m_pDIBitmap && !pData->m_bNamedImage) - delete pData->m_pDIBitmap; - - pData->m_pDIBitmap = newImage; -} - -void CXFA_WidgetAcc::SetImageEditImage(CFX_DIBitmap* newImage) { - CXFA_ImageEditData* pData = - static_cast<CXFA_ImageEditData*>(m_pLayoutData.get()); - if (pData->m_pDIBitmap == newImage) - return; - - if (pData->m_pDIBitmap && !pData->m_bNamedImage) - delete pData->m_pDIBitmap; - - pData->m_pDIBitmap = newImage; -} - -CXFA_WidgetLayoutData* CXFA_WidgetAcc::GetWidgetLayoutData() { - return m_pLayoutData.get(); -} - -CFX_RetainPtr<CFGAS_GEFont> CXFA_WidgetAcc::GetFDEFont() { - CFX_WideStringC wsFontName = L"Courier"; - uint32_t dwFontStyle = 0; - if (CXFA_Font font = GetFont()) { - if (font.IsBold()) - dwFontStyle |= FX_FONTSTYLE_Bold; - if (font.IsItalic()) - dwFontStyle |= FX_FONTSTYLE_Italic; - font.GetTypeface(wsFontName); - } - - auto pDoc = GetDoc(); - return pDoc->GetApp()->GetXFAFontMgr()->GetFont(pDoc, wsFontName, - dwFontStyle); -} -FX_FLOAT CXFA_WidgetAcc::GetFontSize() { - FX_FLOAT fFontSize = 10.0f; - if (CXFA_Font font = GetFont()) { - fFontSize = font.GetFontSize(); - } - return fFontSize < 0.1f ? 10.0f : fFontSize; -} -FX_FLOAT CXFA_WidgetAcc::GetLineHeight() { - FX_FLOAT fLineHeight = 0; - if (CXFA_Para para = GetPara()) { - fLineHeight = para.GetLineHeight(); - } - if (fLineHeight < 1) { - fLineHeight = GetFontSize() * 1.2f; - } - return fLineHeight; -} -FX_ARGB CXFA_WidgetAcc::GetTextColor() { - if (CXFA_Font font = GetFont()) { - return font.GetColor(); - } - return 0xFF000000; -} CXFA_Node* CXFA_TextProvider::GetTextNode(bool& bRichText) { bRichText = false; if (m_pTextNode) { @@ -1636,7 +137,7 @@ CXFA_Font CXFA_TextProvider::GetFontNode() { bool CXFA_TextProvider::IsCheckButtonAndAutoWidth() { XFA_Element eType = m_pWidgetAcc->GetUIType(); if (eType == XFA_Element::CheckButton) { - FX_FLOAT fWidth = 0; + float fWidth = 0; return !m_pWidgetAcc->GetWidth(fWidth); } return false; diff --git a/chromium/third_party/pdfium/xfa/fxfa/app/xfa_ffwidgetacc.h b/chromium/third_party/pdfium/xfa/fxfa/app/xfa_ffwidgetacc.h index 2daa35e6cd5..c4988fde661 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/app/xfa_ffwidgetacc.h +++ b/chromium/third_party/pdfium/xfa/fxfa/app/xfa_ffwidgetacc.h @@ -9,7 +9,7 @@ #include "core/fxcrt/fx_string.h" #include "xfa/fxfa/app/cxfa_textlayout.h" -#include "xfa/fxfa/fxfa_widget.h" +#include "xfa/fxfa/cxfa_widgetacc.h" #include "xfa/fxfa/parser/cxfa_font.h" #include "xfa/fxfa/parser/cxfa_para.h" @@ -44,7 +44,7 @@ class CXFA_TextProvider { const CFX_WideString& wsAttr, CFX_WideString& wsValue); - protected: + private: CXFA_WidgetAcc* m_pWidgetAcc; XFA_TEXTPROVIDERTYPE m_eType; CXFA_Node* m_pTextNode; diff --git a/chromium/third_party/pdfium/xfa/fxfa/app/xfa_fwladapter.cpp b/chromium/third_party/pdfium/xfa/fxfa/app/xfa_fwladapter.cpp index e1f3e202ed3..3cf6e5e8fdd 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/app/xfa_fwladapter.cpp +++ b/chromium/third_party/pdfium/xfa/fxfa/app/xfa_fwladapter.cpp @@ -7,7 +7,7 @@ #include "xfa/fxfa/app/xfa_fwladapter.h" #include "xfa/fxfa/app/xfa_fffield.h" -#include "xfa/fxfa/xfa_ffdoc.h" +#include "xfa/fxfa/cxfa_ffdoc.h" CXFA_FWLAdapterWidgetMgr::CXFA_FWLAdapterWidgetMgr() {} @@ -25,8 +25,8 @@ void CXFA_FWLAdapterWidgetMgr::RepaintWidget(CFWL_Widget* pWidget) { } bool CXFA_FWLAdapterWidgetMgr::GetPopupPos(CFWL_Widget* pWidget, - FX_FLOAT fMinHeight, - FX_FLOAT fMaxHeight, + float fMinHeight, + float fMaxHeight, const CFX_RectF& rtAnchor, CFX_RectF& rtPopup) { CXFA_FFWidget* pFFWidget = pWidget->GetLayoutItem(); diff --git a/chromium/third_party/pdfium/xfa/fxfa/app/xfa_fwladapter.h b/chromium/third_party/pdfium/xfa/fxfa/app/xfa_fwladapter.h index c68fb7015f2..b4a34815885 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/app/xfa_fwladapter.h +++ b/chromium/third_party/pdfium/xfa/fxfa/app/xfa_fwladapter.h @@ -19,8 +19,8 @@ class CXFA_FWLAdapterWidgetMgr { void RepaintWidget(CFWL_Widget* pWidget); bool GetPopupPos(CFWL_Widget* pWidget, - FX_FLOAT fMinHeight, - FX_FLOAT fMaxHeight, + float fMinHeight, + float fMaxHeight, const CFX_RectF& rtAnchor, CFX_RectF& rtPopup); }; diff --git a/chromium/third_party/pdfium/xfa/fxfa/app/xfa_fwltheme.cpp b/chromium/third_party/pdfium/xfa/fxfa/app/xfa_fwltheme.cpp index 73abaecbc89..629cd509e83 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/app/xfa_fwltheme.cpp +++ b/chromium/third_party/pdfium/xfa/fxfa/app/xfa_fwltheme.cpp @@ -6,7 +6,7 @@ #include "xfa/fxfa/app/xfa_fwltheme.h" -#include "xfa/fde/tto/fde_textout.h" +#include "xfa/fde/cfde_textout.h" #include "xfa/fgas/crt/fgas_codepage.h" #include "xfa/fgas/font/cfgas_gefont.h" #include "xfa/fwl/cfwl_barcode.h" @@ -22,13 +22,13 @@ #include "xfa/fwl/cfwl_scrollbar.h" #include "xfa/fwl/cfwl_themebackground.h" #include "xfa/fwl/cfwl_themetext.h" -#include "xfa/fxfa/xfa_ffapp.h" -#include "xfa/fxfa/xfa_ffwidget.h" +#include "xfa/fxfa/cxfa_ffapp.h" +#include "xfa/fxfa/cxfa_ffwidget.h" #include "xfa/fxgraphics/cfx_color.h" namespace { -const FX_WCHAR* const g_FWLTheme_CalFonts[] = { +const wchar_t* const g_FWLTheme_CalFonts[] = { L"Arial", L"Courier New", L"DejaVu Sans", }; @@ -44,18 +44,18 @@ CXFA_FFWidget* XFA_ThemeGetOuterWidget(CFWL_Widget* pWidget) { } CXFA_FWLTheme::CXFA_FWLTheme(CXFA_FFApp* pApp) - : m_pCheckBoxTP(new CFWL_CheckBoxTP), - m_pListBoxTP(new CFWL_ListBoxTP), - m_pPictureBoxTP(new CFWL_PictureBoxTP), - m_pSrollBarTP(new CFWL_ScrollBarTP), - m_pEditTP(new CFWL_EditTP), - m_pComboBoxTP(new CFWL_ComboBoxTP), - m_pMonthCalendarTP(new CFWL_MonthCalendarTP), - m_pDateTimePickerTP(new CFWL_DateTimePickerTP), - m_pPushButtonTP(new CFWL_PushButtonTP), - m_pCaretTP(new CFWL_CaretTP), - m_pBarcodeTP(new CFWL_BarcodeTP), - m_pTextOut(new CFDE_TextOut), + : m_pCheckBoxTP(pdfium::MakeUnique<CFWL_CheckBoxTP>()), + m_pListBoxTP(pdfium::MakeUnique<CFWL_ListBoxTP>()), + m_pPictureBoxTP(pdfium::MakeUnique<CFWL_PictureBoxTP>()), + m_pSrollBarTP(pdfium::MakeUnique<CFWL_ScrollBarTP>()), + m_pEditTP(pdfium::MakeUnique<CFWL_EditTP>()), + m_pComboBoxTP(pdfium::MakeUnique<CFWL_ComboBoxTP>()), + m_pMonthCalendarTP(pdfium::MakeUnique<CFWL_MonthCalendarTP>()), + m_pDateTimePickerTP(pdfium::MakeUnique<CFWL_DateTimePickerTP>()), + m_pPushButtonTP(pdfium::MakeUnique<CFWL_PushButtonTP>()), + m_pCaretTP(pdfium::MakeUnique<CFWL_CaretTP>()), + m_pBarcodeTP(pdfium::MakeUnique<CFWL_BarcodeTP>()), + m_pTextOut(pdfium::MakeUnique<CFDE_TextOut>()), m_pCalendarFont(nullptr), m_pApp(pApp) { m_Rect.Reset(); diff --git a/chromium/third_party/pdfium/xfa/fxfa/app/xfa_fwltheme.h b/chromium/third_party/pdfium/xfa/fxfa/app/xfa_fwltheme.h index a8efad0ccff..33ea8e80a52 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/app/xfa_fwltheme.h +++ b/chromium/third_party/pdfium/xfa/fxfa/app/xfa_fwltheme.h @@ -22,7 +22,7 @@ #include "xfa/fwl/theme/cfwl_pushbuttontp.h" #include "xfa/fwl/theme/cfwl_scrollbartp.h" #include "xfa/fwl/theme/cfwl_widgettp.h" -#include "xfa/fxfa/xfa_ffapp.h" +#include "xfa/fxfa/cxfa_ffapp.h" class CXFA_FWLTheme final : public IFWL_ThemeProvider { public: diff --git a/chromium/third_party/pdfium/xfa/fxfa/app/xfa_textpiece.h b/chromium/third_party/pdfium/xfa/fxfa/app/xfa_textpiece.h index 6802df55664..fd1f3bdbaa4 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/app/xfa_textpiece.h +++ b/chromium/third_party/pdfium/xfa/fxfa/app/xfa_textpiece.h @@ -32,7 +32,7 @@ class XFA_TextPiece { int32_t iPeriod; int32_t iLineThrough; FX_ARGB dwColor; - FX_FLOAT fFontSize; + float fFontSize; CFX_RectF rtPiece; CFX_RetainPtr<CFGAS_GEFont> pFont; CFX_RetainPtr<CXFA_LinkUserData> pLinkData; diff --git a/chromium/third_party/pdfium/xfa/fxfa/cxfa_deffontmgr.cpp b/chromium/third_party/pdfium/xfa/fxfa/cxfa_deffontmgr.cpp new file mode 100644 index 00000000000..db730677b5c --- /dev/null +++ b/chromium/third_party/pdfium/xfa/fxfa/cxfa_deffontmgr.cpp @@ -0,0 +1,77 @@ +// Copyright 2017 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#include "xfa/fxfa/cxfa_deffontmgr.h" + +#include "xfa/fxfa/cxfa_ffapp.h" +#include "xfa/fxfa/cxfa_ffdoc.h" +#include "xfa/fxfa/cxfa_fontmgr.h" + +CXFA_DefFontMgr::CXFA_DefFontMgr() {} + +CXFA_DefFontMgr::~CXFA_DefFontMgr() {} + +CFX_RetainPtr<CFGAS_GEFont> CXFA_DefFontMgr::GetFont( + CXFA_FFDoc* hDoc, + const CFX_WideStringC& wsFontFamily, + uint32_t dwFontStyles, + uint16_t wCodePage) { + CFX_WideString wsFontName(wsFontFamily); + CFGAS_FontMgr* pFDEFontMgr = hDoc->GetApp()->GetFDEFontMgr(); + CFX_RetainPtr<CFGAS_GEFont> pFont = + pFDEFontMgr->LoadFont(wsFontName.c_str(), dwFontStyles, wCodePage); + if (!pFont) { + const XFA_FONTINFO* pCurFont = + XFA_GetFontINFOByFontName(wsFontName.AsStringC()); + if (pCurFont && pCurFont->pReplaceFont) { + uint32_t dwStyle = 0; + if (dwFontStyles & FX_FONTSTYLE_Bold) { + dwStyle |= FX_FONTSTYLE_Bold; + } + if (dwFontStyles & FX_FONTSTYLE_Italic) { + dwStyle |= FX_FONTSTYLE_Italic; + } + const wchar_t* pReplace = pCurFont->pReplaceFont; + int32_t iLength = FXSYS_wcslen(pReplace); + while (iLength > 0) { + const wchar_t* pNameText = pReplace; + while (*pNameText != L',' && iLength > 0) { + pNameText++; + iLength--; + } + CFX_WideString wsReplace = + CFX_WideString(pReplace, pNameText - pReplace); + pFont = pFDEFontMgr->LoadFont(wsReplace.c_str(), dwStyle, wCodePage); + if (pFont) + break; + + iLength--; + pNameText++; + pReplace = pNameText; + } + } + } + if (pFont) + m_CacheFonts.push_back(pFont); + return pFont; +} + +CFX_RetainPtr<CFGAS_GEFont> CXFA_DefFontMgr::GetDefaultFont( + CXFA_FFDoc* hDoc, + const CFX_WideStringC& wsFontFamily, + uint32_t dwFontStyles, + uint16_t wCodePage) { + CFGAS_FontMgr* pFDEFontMgr = hDoc->GetApp()->GetFDEFontMgr(); + CFX_RetainPtr<CFGAS_GEFont> pFont = + pFDEFontMgr->LoadFont(L"Arial Narrow", dwFontStyles, wCodePage); + if (!pFont) { + pFont = pFDEFontMgr->LoadFont(static_cast<const wchar_t*>(nullptr), + dwFontStyles, wCodePage); + } + if (pFont) + m_CacheFonts.push_back(pFont); + return pFont; +} diff --git a/chromium/third_party/pdfium/xfa/fxfa/cxfa_deffontmgr.h b/chromium/third_party/pdfium/xfa/fxfa/cxfa_deffontmgr.h new file mode 100644 index 00000000000..5f50ffb08d4 --- /dev/null +++ b/chromium/third_party/pdfium/xfa/fxfa/cxfa_deffontmgr.h @@ -0,0 +1,37 @@ +// Copyright 2017 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#ifndef XFA_FXFA_CXFA_DEFFONTMGR_H_ +#define XFA_FXFA_CXFA_DEFFONTMGR_H_ + +#include <vector> + +#include "core/fxcrt/cfx_retain_ptr.h" +#include "core/fxcrt/fx_string.h" +#include "xfa/fgas/font/cfgas_gefont.h" + +class CXFA_FFDoc; + +class CXFA_DefFontMgr { + public: + CXFA_DefFontMgr(); + ~CXFA_DefFontMgr(); + + CFX_RetainPtr<CFGAS_GEFont> GetFont(CXFA_FFDoc* hDoc, + const CFX_WideStringC& wsFontFamily, + uint32_t dwFontStyles, + uint16_t wCodePage = 0xFFFF); + CFX_RetainPtr<CFGAS_GEFont> GetDefaultFont( + CXFA_FFDoc* hDoc, + const CFX_WideStringC& wsFontFamily, + uint32_t dwFontStyles, + uint16_t wCodePage = 0xFFFF); + + private: + std::vector<CFX_RetainPtr<CFGAS_GEFont>> m_CacheFonts; +}; + +#endif // XFA_FXFA_CXFA_DEFFONTMGR_H_ diff --git a/chromium/third_party/pdfium/xfa/fxfa/app/cxfa_eventparam.cpp b/chromium/third_party/pdfium/xfa/fxfa/cxfa_eventparam.cpp index bcce7219bc3..bd6742f4dd9 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/app/cxfa_eventparam.cpp +++ b/chromium/third_party/pdfium/xfa/fxfa/cxfa_eventparam.cpp @@ -19,8 +19,7 @@ CXFA_EventParam::CXFA_EventParam() m_iSelEnd(0), m_iSelStart(0), m_bShift(false), - m_bIsFormReady(false), - m_iValidateActivities(XFA_VALIDATE_preSubmit) {} + m_bIsFormReady(false) {} CXFA_EventParam::~CXFA_EventParam() {} @@ -44,5 +43,4 @@ void CXFA_EventParam::Reset() { m_wsSoapFaultCode.clear(); m_wsSoapFaultString.clear(); m_bIsFormReady = false; - m_iValidateActivities = XFA_VALIDATE_preSubmit; } diff --git a/chromium/third_party/pdfium/xfa/fxfa/cxfa_eventparam.h b/chromium/third_party/pdfium/xfa/fxfa/cxfa_eventparam.h index 3ba7a8b7f27..1e7c12a34a2 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/cxfa_eventparam.h +++ b/chromium/third_party/pdfium/xfa/fxfa/cxfa_eventparam.h @@ -73,7 +73,6 @@ class CXFA_EventParam { CFX_WideString m_wsSoapFaultCode; CFX_WideString m_wsSoapFaultString; bool m_bIsFormReady; - int32_t m_iValidateActivities; }; #endif // XFA_FXFA_CXFA_EVENTPARAM_H_ diff --git a/chromium/third_party/pdfium/xfa/fxfa/app/xfa_ffapp.cpp b/chromium/third_party/pdfium/xfa/fxfa/cxfa_ffapp.cpp index 219f06e4ff7..c02fd30e860 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/app/xfa_ffapp.cpp +++ b/chromium/third_party/pdfium/xfa/fxfa/cxfa_ffapp.cpp @@ -4,7 +4,7 @@ // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com -#include "xfa/fxfa/xfa_ffapp.h" +#include "xfa/fxfa/cxfa_ffapp.h" #include <algorithm> #include <memory> @@ -18,76 +18,10 @@ #include "xfa/fwl/cfwl_widgetmgr.h" #include "xfa/fxfa/app/xfa_fwladapter.h" #include "xfa/fxfa/app/xfa_fwltheme.h" -#include "xfa/fxfa/xfa_ffdoc.h" -#include "xfa/fxfa/xfa_ffdochandler.h" -#include "xfa/fxfa/xfa_ffwidgethandler.h" -#include "xfa/fxfa/xfa_fontmgr.h" - -namespace { - -class CXFA_FileRead : public IFX_SeekableReadStream { - public: - explicit CXFA_FileRead(const std::vector<CPDF_Stream*>& streams); - ~CXFA_FileRead() override; - - // IFX_SeekableReadStream - FX_FILESIZE GetSize() override; - bool ReadBlock(void* buffer, FX_FILESIZE offset, size_t size) override; - - private: - std::vector<std::unique_ptr<CPDF_StreamAcc>> m_Data; -}; - -CXFA_FileRead::CXFA_FileRead(const std::vector<CPDF_Stream*>& streams) { - for (CPDF_Stream* pStream : streams) { - m_Data.push_back(pdfium::MakeUnique<CPDF_StreamAcc>()); - m_Data.back()->LoadAllData(pStream); - } -} - -CXFA_FileRead::~CXFA_FileRead() {} - -FX_FILESIZE CXFA_FileRead::GetSize() { - uint32_t dwSize = 0; - for (const auto& acc : m_Data) - dwSize += acc->GetSize(); - return dwSize; -} - -bool CXFA_FileRead::ReadBlock(void* buffer, FX_FILESIZE offset, size_t size) { - int32_t iCount = pdfium::CollectionSize<int32_t>(m_Data); - int32_t index = 0; - while (index < iCount) { - const auto& acc = m_Data[index]; - FX_FILESIZE dwSize = acc->GetSize(); - if (offset < dwSize) - break; - - offset -= dwSize; - index++; - } - while (index < iCount) { - const auto& acc = m_Data[index]; - uint32_t dwSize = acc->GetSize(); - size_t dwRead = std::min(size, static_cast<size_t>(dwSize - offset)); - FXSYS_memcpy(buffer, acc->GetData() + offset, dwRead); - size -= dwRead; - if (size == 0) - return true; - - buffer = (uint8_t*)buffer + dwRead; - offset = 0; - index++; - } - return false; -} - -} // namespace - -CFX_RetainPtr<IFX_SeekableReadStream> MakeSeekableReadStream( - const std::vector<CPDF_Stream*>& streams) { - return CFX_RetainPtr<IFX_SeekableReadStream>(new CXFA_FileRead(streams)); -} +#include "xfa/fxfa/cxfa_ffdoc.h" +#include "xfa/fxfa/cxfa_ffdochandler.h" +#include "xfa/fxfa/cxfa_ffwidgethandler.h" +#include "xfa/fxfa/cxfa_fontmgr.h" CXFA_FFApp::CXFA_FFApp(IXFA_AppProvider* pProvider) : m_pProvider(pProvider), diff --git a/chromium/third_party/pdfium/xfa/fxfa/xfa_ffapp.h b/chromium/third_party/pdfium/xfa/fxfa/cxfa_ffapp.h index 411fd2d273b..0a6409d3d13 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/xfa_ffapp.h +++ b/chromium/third_party/pdfium/xfa/fxfa/cxfa_ffapp.h @@ -4,8 +4,8 @@ // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com -#ifndef XFA_FXFA_XFA_FFAPP_H_ -#define XFA_FXFA_XFA_FFAPP_H_ +#ifndef XFA_FXFA_CXFA_FFAPP_H_ +#define XFA_FXFA_CXFA_FFAPP_H_ #include <memory> #include <vector> @@ -25,11 +25,6 @@ class CXFA_FontMgr; class IFWL_AdapterTimerMgr; class CFWL_WidgetMgrDelegate; -// Layering prevents fxcrt from knowing about CPDF_Streams; this could go -// in fpdfsdk, but it is XFA-Only. -CFX_RetainPtr<IFX_SeekableReadStream> MakeSeekableReadStream( - const std::vector<CPDF_Stream*>& streams); - class CXFA_FFApp { public: explicit CXFA_FFApp(IXFA_AppProvider* pProvider); @@ -54,7 +49,7 @@ class CXFA_FFApp { void ClearEventTargets(); - protected: + private: std::unique_ptr<CXFA_FFDocHandler> m_pDocHandler; IXFA_AppProvider* const m_pProvider; @@ -83,4 +78,4 @@ class CXFA_FFApp { std::unique_ptr<CFWL_App> m_pFWLApp; }; -#endif // XFA_FXFA_XFA_FFAPP_H_ +#endif // XFA_FXFA_CXFA_FFAPP_H_ diff --git a/chromium/third_party/pdfium/xfa/fxfa/app/xfa_ffapp_unittest.cpp b/chromium/third_party/pdfium/xfa/fxfa/cxfa_ffapp_unittest.cpp index b0879012b42..fc1d038bacd 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/app/xfa_ffapp_unittest.cpp +++ b/chromium/third_party/pdfium/xfa/fxfa/cxfa_ffapp_unittest.cpp @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "xfa/fxfa/xfa_ffapp.h" +#include "xfa/fxfa/cxfa_ffapp.h" #include <memory> #include <vector> @@ -11,12 +11,15 @@ #include "core/fpdfapi/parser/cpdf_stream.h" #include "core/fxcrt/fx_memory.h" #include "testing/gtest/include/gtest/gtest.h" +#include "testing/test_support.h" #include "third_party/base/ptr_util.h" +#include "xfa/fxfa/cxfa_fileread.h" -TEST(CXFAFileRead, NoStreams) { +class CXFAFileReadTest : public pdfium::FPDF_Test {}; + +TEST_F(CXFAFileReadTest, NoStreams) { std::vector<CPDF_Stream*> streams; - CFX_RetainPtr<IFX_SeekableReadStream> fileread = - MakeSeekableReadStream(streams); + auto fileread = pdfium::MakeRetain<CXFA_FileRead>(streams); uint8_t output_buffer[16]; memset(output_buffer, 0xbd, sizeof(output_buffer)); @@ -24,12 +27,11 @@ TEST(CXFAFileRead, NoStreams) { EXPECT_EQ(0xbd, output_buffer[0]); } -TEST(CXFAFileRead, EmptyStreams) { +TEST_F(CXFAFileReadTest, EmptyStreams) { std::vector<CPDF_Stream*> streams; auto stream1 = pdfium::MakeUnique<CPDF_Stream>(); streams.push_back(stream1.get()); - CFX_RetainPtr<IFX_SeekableReadStream> fileread = - MakeSeekableReadStream(streams); + auto fileread = pdfium::MakeRetain<CXFA_FileRead>(streams); uint8_t output_buffer[16]; memset(output_buffer, 0xbd, sizeof(output_buffer)); @@ -37,7 +39,7 @@ TEST(CXFAFileRead, EmptyStreams) { EXPECT_EQ(0xbd, output_buffer[0]); } -TEST(CXFAFileRead, NormalStreams) { +TEST_F(CXFAFileReadTest, NormalStreams) { std::vector<CPDF_Stream*> streams; auto stream1 = pdfium::MakeUnique<CPDF_Stream>(); auto stream2 = pdfium::MakeUnique<CPDF_Stream>(); @@ -54,8 +56,7 @@ TEST(CXFAFileRead, NormalStreams) { streams.push_back(stream1.get()); streams.push_back(stream2.get()); streams.push_back(stream3.get()); - CFX_RetainPtr<IFX_SeekableReadStream> fileread = - MakeSeekableReadStream(streams); + auto fileread = pdfium::MakeRetain<CXFA_FileRead>(streams); uint8_t output_buffer[16]; memset(output_buffer, 0xbd, sizeof(output_buffer)); diff --git a/chromium/third_party/pdfium/xfa/fxfa/app/xfa_ffdoc.cpp b/chromium/third_party/pdfium/xfa/fxfa/cxfa_ffdoc.cpp index 911bdf84006..2bbdfa1b9c8 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/app/xfa_ffdoc.cpp +++ b/chromium/third_party/pdfium/xfa/fxfa/cxfa_ffdoc.cpp @@ -4,7 +4,7 @@ // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com -#include "xfa/fxfa/xfa_ffdoc.h" +#include "xfa/fxfa/cxfa_ffdoc.h" #include <algorithm> #include <memory> @@ -14,20 +14,23 @@ #include "core/fpdfapi/parser/cpdf_document.h" #include "core/fpdfapi/parser/fpdf_parser_decode.h" #include "core/fpdfdoc/cpdf_nametree.h" +#include "core/fxcrt/cfx_checksumcontext.h" #include "core/fxcrt/fx_ext.h" #include "core/fxcrt/fx_memory.h" #include "third_party/base/ptr_util.h" -#include "xfa/fde/xml/fde_xml_imp.h" +#include "xfa/fde/xml/cfde_xmlelement.h" +#include "xfa/fde/xml/cfde_xmlnode.h" #include "xfa/fwl/cfwl_notedriver.h" #include "xfa/fxfa/app/xfa_ffnotify.h" +#include "xfa/fxfa/cxfa_ffapp.h" +#include "xfa/fxfa/cxfa_ffdocview.h" +#include "xfa/fxfa/cxfa_ffwidget.h" +#include "xfa/fxfa/cxfa_fileread.h" +#include "xfa/fxfa/cxfa_fontmgr.h" #include "xfa/fxfa/parser/cxfa_dataexporter.h" #include "xfa/fxfa/parser/cxfa_dataimporter.h" #include "xfa/fxfa/parser/cxfa_document.h" -#include "xfa/fxfa/xfa_checksum.h" -#include "xfa/fxfa/xfa_ffapp.h" -#include "xfa/fxfa/xfa_ffdocview.h" -#include "xfa/fxfa/xfa_ffwidget.h" -#include "xfa/fxfa/xfa_fontmgr.h" +#include "xfa/fxfa/parser/cxfa_node.h" namespace { @@ -59,7 +62,7 @@ uint8_t base64DecoderValue(uint8_t val) { return g_FXBase64DecoderMap[val - kStartValuesRemoved]; } -void Base64DecodePiece(const FX_CHAR src[4], +void Base64DecodePiece(const char src[4], int32_t iChars, FX_BASE64DATA& dst, int32_t& iBytes) { @@ -89,7 +92,7 @@ void Base64DecodePiece(const FX_CHAR src[4], } } -int32_t Base64DecodeW(const FX_WCHAR* pSrc, int32_t iSrcLen, uint8_t* pDst) { +int32_t Base64DecodeW(const wchar_t* pSrc, int32_t iSrcLen, uint8_t* pDst) { ASSERT(pSrc); if (iSrcLen < 1) { return 0; @@ -112,26 +115,26 @@ int32_t Base64DecodeW(const FX_WCHAR* pSrc, int32_t iSrcLen, uint8_t* pDst) { } return iDstLen; } - FX_CHAR srcData[4]; + char srcData[4]; FX_BASE64DATA dstData; int32_t iChars = 4, iBytes; uint8_t* pDstEnd = pDst; while (iSrcLen > 0) { if (iSrcLen > 3) { - srcData[0] = (FX_CHAR)*pSrc++; - srcData[1] = (FX_CHAR)*pSrc++; - srcData[2] = (FX_CHAR)*pSrc++; - srcData[3] = (FX_CHAR)*pSrc++; + srcData[0] = (char)*pSrc++; + srcData[1] = (char)*pSrc++; + srcData[2] = (char)*pSrc++; + srcData[3] = (char)*pSrc++; iSrcLen -= 4; } else { *((uint32_t*)&dstData) = 0; *((uint32_t*)srcData) = 0; - srcData[0] = (FX_CHAR)*pSrc++; + srcData[0] = (char)*pSrc++; if (iSrcLen > 1) { - srcData[1] = (FX_CHAR)*pSrc++; + srcData[1] = (char)*pSrc++; } if (iSrcLen > 2) { - srcData[2] = (FX_CHAR)*pSrc++; + srcData[2] = (char)*pSrc++; } iChars = iSrcLen; iSrcLen = 0; @@ -156,16 +159,12 @@ CXFA_FFDoc::CXFA_FFDoc(CXFA_FFApp* pApp, IXFA_DocEnvironment* pDocEnvironment) m_pApp(pApp), m_pNotify(nullptr), m_pPDFDoc(nullptr), - m_dwDocType(XFA_DOCTYPE_Static) {} + m_dwDocType(XFA_DocType::Static) {} CXFA_FFDoc::~CXFA_FFDoc() { CloseDoc(); } -uint32_t CXFA_FFDoc::GetDocType() { - return m_dwDocType; -} - int32_t CXFA_FFDoc::StartLoad() { m_pNotify = pdfium::MakeUnique<CXFA_FFNotify>(this); m_pDocumentParser = pdfium::MakeUnique<CXFA_DocumentParser>(m_pNotify.get()); @@ -180,9 +179,8 @@ bool XFA_GetPDFContentsFromPDFXML(CFDE_XMLNode* pPDFElement, pPDFElement->GetNodeItem(CFDE_XMLNode::FirstChild); pXMLNode; pXMLNode = pXMLNode->GetNodeItem(CFDE_XMLNode::NextSibling)) { if (pXMLNode->GetType() == FDE_XMLNODE_Element) { - CFX_WideString wsTagName; CFDE_XMLElement* pXMLElement = static_cast<CFDE_XMLElement*>(pXMLNode); - pXMLElement->GetTagName(wsTagName); + CFX_WideString wsTagName = pXMLElement->GetName(); if (wsTagName == L"document") { pDocumentElement = pXMLElement; break; @@ -197,9 +195,8 @@ bool XFA_GetPDFContentsFromPDFXML(CFDE_XMLNode* pPDFElement, pDocumentElement->GetNodeItem(CFDE_XMLNode::FirstChild); pXMLNode; pXMLNode = pXMLNode->GetNodeItem(CFDE_XMLNode::NextSibling)) { if (pXMLNode->GetType() == FDE_XMLNODE_Element) { - CFX_WideString wsTagName; CFDE_XMLElement* pXMLElement = static_cast<CFDE_XMLElement*>(pXMLNode); - pXMLElement->GetTagName(wsTagName); + CFX_WideString wsTagName = pXMLElement->GetName(); if (wsTagName == L"chunk") { pChunkElement = pXMLElement; break; @@ -209,8 +206,7 @@ bool XFA_GetPDFContentsFromPDFXML(CFDE_XMLNode* pPDFElement, if (!pChunkElement) { return false; } - CFX_WideString wsPDFContent; - pChunkElement->GetTextData(wsPDFContent); + CFX_WideString wsPDFContent = pChunkElement->GetTextData(); iBufferSize = Base64DecodeW(wsPDFContent.c_str(), wsPDFContent.GetLength(), nullptr); pByteBuffer = FX_Alloc(uint8_t, iBufferSize + 1); @@ -245,55 +241,51 @@ int32_t CXFA_FFDoc::DoLoad(IFX_Pause* pPause) { void CXFA_FFDoc::StopLoad() { m_pApp->GetXFAFontMgr()->LoadDocFonts(this); - m_dwDocType = XFA_DOCTYPE_Static; + m_dwDocType = XFA_DocType::Static; CXFA_Node* pConfig = ToNode( m_pDocumentParser->GetDocument()->GetXFAObject(XFA_HASHCODE_Config)); - if (!pConfig) { + if (!pConfig) return; - } + CXFA_Node* pAcrobat = pConfig->GetFirstChildByClass(XFA_Element::Acrobat); - if (!pAcrobat) { + if (!pAcrobat) return; - } + CXFA_Node* pAcrobat7 = pAcrobat->GetFirstChildByClass(XFA_Element::Acrobat7); - if (!pAcrobat7) { + if (!pAcrobat7) return; - } + CXFA_Node* pDynamicRender = pAcrobat7->GetFirstChildByClass(XFA_Element::DynamicRender); - if (!pDynamicRender) { + if (!pDynamicRender) return; - } + CFX_WideString wsType; - if (pDynamicRender->TryContent(wsType) && wsType == L"required") { - m_dwDocType = XFA_DOCTYPE_Dynamic; - } + if (pDynamicRender->TryContent(wsType) && wsType == L"required") + m_dwDocType = XFA_DocType::Dynamic; } -CXFA_FFDocView* CXFA_FFDoc::CreateDocView(uint32_t dwView) { - if (!m_TypeToDocViewMap[dwView]) - m_TypeToDocViewMap[dwView] = pdfium::MakeUnique<CXFA_FFDocView>(this); +CXFA_FFDocView* CXFA_FFDoc::CreateDocView() { + if (!m_DocView) + m_DocView = pdfium::MakeUnique<CXFA_FFDocView>(this); - return m_TypeToDocViewMap[dwView].get(); + return m_DocView.get(); } CXFA_FFDocView* CXFA_FFDoc::GetDocView(CXFA_LayoutProcessor* pLayout) { - for (const auto& pair : m_TypeToDocViewMap) { - if (pair.second->GetXFALayout() == pLayout) - return pair.second.get(); - } - return nullptr; + return m_DocView && m_DocView->GetXFALayout() == pLayout ? m_DocView.get() + : nullptr; } CXFA_FFDocView* CXFA_FFDoc::GetDocView() { - auto it = m_TypeToDocViewMap.begin(); - return it != m_TypeToDocViewMap.end() ? it->second.get() : nullptr; + return m_DocView.get(); } bool CXFA_FFDoc::OpenDoc(const CFX_RetainPtr<IFX_SeekableReadStream>& pStream) { m_pStream = pStream; return true; } + bool CXFA_FFDoc::OpenDoc(CPDF_Document* pPDFDoc) { if (!pPDFDoc) return false; @@ -324,41 +316,35 @@ bool CXFA_FFDoc::OpenDoc(CPDF_Document* pPDFDoc) { return false; m_pPDFDoc = pPDFDoc; - m_pStream = MakeSeekableReadStream(xfaStreams); + m_pStream = pdfium::MakeRetain<CXFA_FileRead>(xfaStreams); return true; } bool CXFA_FFDoc::CloseDoc() { - for (const auto& pair : m_TypeToDocViewMap) - pair.second->RunDocClose(); + if (m_DocView) + m_DocView->RunDocClose(); CXFA_Document* doc = m_pDocumentParser ? m_pDocumentParser->GetDocument() : nullptr; if (doc) doc->ClearLayoutData(); - m_TypeToDocViewMap.clear(); - + m_DocView.reset(); m_pNotify.reset(nullptr); m_pApp->GetXFAFontMgr()->ReleaseDocFonts(this); - - for (const auto& pair : m_HashToDibDpiMap) - delete pair.second.pDibSource; - m_HashToDibDpiMap.clear(); m_pApp->ClearEventTargets(); return true; } -void CXFA_FFDoc::SetDocType(uint32_t dwType) { - m_dwDocType = dwType; -} + CPDF_Document* CXFA_FFDoc::GetPDFDoc() { return m_pPDFDoc; } -CFX_DIBitmap* CXFA_FFDoc::GetPDFNamedImage(const CFX_WideStringC& wsName, - int32_t& iImageXDpi, - int32_t& iImageYDpi) { +CFX_RetainPtr<CFX_DIBitmap> CXFA_FFDoc::GetPDFNamedImage( + const CFX_WideStringC& wsName, + int32_t& iImageXDpi, + int32_t& iImageYDpi) { if (!m_pPDFDoc) return nullptr; @@ -367,7 +353,7 @@ CFX_DIBitmap* CXFA_FFDoc::GetPDFNamedImage(const CFX_WideStringC& wsName, if (it != m_HashToDibDpiMap.end()) { iImageXDpi = it->second.iImageXDpi; iImageYDpi = it->second.iImageYDpi; - return static_cast<CFX_DIBitmap*>(it->second.pDibSource); + return it->second.pDibSource.As<CFX_DIBitmap>(); } CPDF_Dictionary* pRoot = m_pPDFDoc->GetRoot(); @@ -388,7 +374,7 @@ CFX_DIBitmap* CXFA_FFDoc::GetPDFNamedImage(const CFX_WideStringC& wsName, if (!pObject) { for (size_t i = 0; i < nametree.GetCount(); i++) { CFX_ByteString bsTemp; - CPDF_Object* pTempObject = nametree.LookupValue(i, bsTemp); + CPDF_Object* pTempObject = nametree.LookupValueAndName(i, &bsTemp); if (bsTemp == bsName) { pObject = pTempObject; break; @@ -400,14 +386,14 @@ CFX_DIBitmap* CXFA_FFDoc::GetPDFNamedImage(const CFX_WideStringC& wsName, if (!pStream) return nullptr; - CPDF_StreamAcc streamAcc; - streamAcc.LoadAllData(pStream); + auto pAcc = pdfium::MakeRetain<CPDF_StreamAcc>(pStream); + pAcc->LoadAllData(); CFX_RetainPtr<IFX_SeekableReadStream> pImageFileRead = - IFX_MemoryStream::Create((uint8_t*)streamAcc.GetData(), - streamAcc.GetSize()); + IFX_MemoryStream::Create(const_cast<uint8_t*>(pAcc->GetData()), + pAcc->GetSize()); - CFX_DIBitmap* pDibSource = XFA_LoadImageFromBuffer( + CFX_RetainPtr<CFX_DIBitmap> pDibSource = XFA_LoadImageFromBuffer( pImageFileRead, FXCODEC_IMAGE_UNKNOWN, iImageXDpi, iImageYDpi); m_HashToDibDpiMap[dwHash] = {pDibSource, iImageXDpi, iImageYDpi}; return pDibSource; @@ -416,9 +402,9 @@ CFX_DIBitmap* CXFA_FFDoc::GetPDFNamedImage(const CFX_WideStringC& wsName, bool CXFA_FFDoc::SavePackage( XFA_HashCode code, const CFX_RetainPtr<IFX_SeekableWriteStream>& pFile, - CXFA_ChecksumContext* pCSContext) { + CFX_ChecksumContext* pCSContext) { CXFA_Document* doc = m_pDocumentParser->GetDocument(); - std::unique_ptr<CXFA_DataExporter> pExport(new CXFA_DataExporter(doc)); + auto pExport = pdfium::MakeUnique<CXFA_DataExporter>(doc); CXFA_Node* pNode = code == XFA_HASHCODE_Xfa ? doc->GetRoot() : ToNode(doc->GetXFAObject(code)); if (!pNode) diff --git a/chromium/third_party/pdfium/xfa/fxfa/xfa_ffdoc.h b/chromium/third_party/pdfium/xfa/fxfa/cxfa_ffdoc.h index 44079704e7b..0bba956f147 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/xfa_ffdoc.h +++ b/chromium/third_party/pdfium/xfa/fxfa/cxfa_ffdoc.h @@ -4,8 +4,8 @@ // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com -#ifndef XFA_FXFA_XFA_FFDOC_H_ -#define XFA_FXFA_XFA_FFDOC_H_ +#ifndef XFA_FXFA_CXFA_FFDOC_H_ +#define XFA_FXFA_CXFA_FFDOC_H_ #include <map> #include <memory> @@ -14,31 +14,49 @@ #include "xfa/fxfa/parser/cxfa_document.h" #include "xfa/fxfa/parser/cxfa_document_parser.h" -class CXFA_ChecksumContext; +class CFX_ChecksumContext; class CXFA_FFApp; class CXFA_FFNotify; class CXFA_FFDocView; struct FX_IMAGEDIB_AND_DPI { - CFX_DIBSource* pDibSource; + FX_IMAGEDIB_AND_DPI(); + FX_IMAGEDIB_AND_DPI(const FX_IMAGEDIB_AND_DPI& that); + FX_IMAGEDIB_AND_DPI(const CFX_RetainPtr<CFX_DIBSource>& pDib, + int32_t xDpi, + int32_t yDpi); + ~FX_IMAGEDIB_AND_DPI(); + + CFX_RetainPtr<CFX_DIBSource> pDibSource; int32_t iImageXDpi; int32_t iImageYDpi; }; +inline FX_IMAGEDIB_AND_DPI::FX_IMAGEDIB_AND_DPI() = default; +inline FX_IMAGEDIB_AND_DPI::FX_IMAGEDIB_AND_DPI( + const FX_IMAGEDIB_AND_DPI& that) = default; + +inline FX_IMAGEDIB_AND_DPI::FX_IMAGEDIB_AND_DPI( + const CFX_RetainPtr<CFX_DIBSource>& pDib, + int32_t xDpi, + int32_t yDpi) + : pDibSource(pDib), iImageXDpi(xDpi), iImageYDpi(yDpi) {} + +inline FX_IMAGEDIB_AND_DPI::~FX_IMAGEDIB_AND_DPI() = default; + class CXFA_FFDoc { public: CXFA_FFDoc(CXFA_FFApp* pApp, IXFA_DocEnvironment* pDocEnvironment); ~CXFA_FFDoc(); IXFA_DocEnvironment* GetDocEnvironment() const { return m_pDocEnvironment; } - uint32_t GetDocType(); - void SetDocType(uint32_t dwType); + XFA_DocType GetDocType() const { return m_dwDocType; } int32_t StartLoad(); int32_t DoLoad(IFX_Pause* pPause = nullptr); void StopLoad(); - CXFA_FFDocView* CreateDocView(uint32_t dwView = 0); + CXFA_FFDocView* CreateDocView(); bool OpenDoc(const CFX_RetainPtr<IFX_SeekableReadStream>& pStream); bool OpenDoc(CPDF_Document* pPDFDoc); @@ -49,17 +67,17 @@ class CXFA_FFDoc { CXFA_FFDocView* GetDocView(CXFA_LayoutProcessor* pLayout); CXFA_FFDocView* GetDocView(); CPDF_Document* GetPDFDoc(); - CFX_DIBitmap* GetPDFNamedImage(const CFX_WideStringC& wsName, - int32_t& iImageXDpi, - int32_t& iImageYDpi); + CFX_RetainPtr<CFX_DIBitmap> GetPDFNamedImage(const CFX_WideStringC& wsName, + int32_t& iImageXDpi, + int32_t& iImageYDpi); bool SavePackage(XFA_HashCode code, const CFX_RetainPtr<IFX_SeekableWriteStream>& pFile, - CXFA_ChecksumContext* pCSContext); + CFX_ChecksumContext* pCSContext); bool ImportData(const CFX_RetainPtr<IFX_SeekableReadStream>& pStream, bool bXDP = true); - protected: + private: IXFA_DocEnvironment* const m_pDocEnvironment; std::unique_ptr<CXFA_DocumentParser> m_pDocumentParser; CFX_RetainPtr<IFX_SeekableReadStream> m_pStream; @@ -67,8 +85,8 @@ class CXFA_FFDoc { std::unique_ptr<CXFA_FFNotify> m_pNotify; CPDF_Document* m_pPDFDoc; std::map<uint32_t, FX_IMAGEDIB_AND_DPI> m_HashToDibDpiMap; - std::map<uint32_t, std::unique_ptr<CXFA_FFDocView>> m_TypeToDocViewMap; - uint32_t m_dwDocType; + std::unique_ptr<CXFA_FFDocView> m_DocView; + XFA_DocType m_dwDocType; }; -#endif // XFA_FXFA_XFA_FFDOC_H_ +#endif // XFA_FXFA_CXFA_FFDOC_H_ diff --git a/chromium/third_party/pdfium/xfa/fxfa/app/xfa_ffdochandler.cpp b/chromium/third_party/pdfium/xfa/fxfa/cxfa_ffdochandler.cpp index db73531ccc5..b0a84fa29a4 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/app/xfa_ffdochandler.cpp +++ b/chromium/third_party/pdfium/xfa/fxfa/cxfa_ffdochandler.cpp @@ -4,12 +4,13 @@ // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com -#include "xfa/fxfa/xfa_ffdochandler.h" +#include "xfa/fxfa/cxfa_ffdochandler.h" +#include "core/fxcrt/cfx_checksumcontext.h" +#include "xfa/fxfa/cxfa_ffdoc.h" +#include "xfa/fxfa/parser/cxfa_node.h" #include "xfa/fxfa/parser/cxfa_scriptcontext.h" #include "xfa/fxfa/parser/xfa_resolvenode_rs.h" -#include "xfa/fxfa/xfa_checksum.h" -#include "xfa/fxfa/xfa_ffdoc.h" CXFA_FFDocHandler::CXFA_FFDocHandler() {} diff --git a/chromium/third_party/pdfium/xfa/fxfa/xfa_ffdochandler.h b/chromium/third_party/pdfium/xfa/fxfa/cxfa_ffdochandler.h index 0e4f71786ca..45b2ee07e10 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/xfa_ffdochandler.h +++ b/chromium/third_party/pdfium/xfa/fxfa/cxfa_ffdochandler.h @@ -4,12 +4,12 @@ // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com -#ifndef XFA_FXFA_XFA_FFDOCHANDLER_H_ -#define XFA_FXFA_XFA_FFDOCHANDLER_H_ +#ifndef XFA_FXFA_CXFA_FFDOCHANDLER_H_ +#define XFA_FXFA_CXFA_FFDOCHANDLER_H_ #include "xfa/fxfa/fxfa.h" -class CXFA_ChecksumContext; +class CFX_ChecksumContext; class CXFA_FFDocHandler { public: @@ -24,8 +24,6 @@ class CXFA_FFDocHandler { const CFX_WideStringC& wsScript, CFXJSE_Value* pRetValue, CFXJSE_Value* pThisObject); - - protected: }; -#endif // XFA_FXFA_XFA_FFDOCHANDLER_H_ +#endif // XFA_FXFA_CXFA_FFDOCHANDLER_H_ diff --git a/chromium/third_party/pdfium/xfa/fxfa/app/xfa_ffdocview.cpp b/chromium/third_party/pdfium/xfa/fxfa/cxfa_ffdocview.cpp index 87441814e53..488a31f299a 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/app/xfa_ffdocview.cpp +++ b/chromium/third_party/pdfium/xfa/fxfa/cxfa_ffdocview.cpp @@ -4,7 +4,7 @@ // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com -#include "xfa/fxfa/xfa_ffdocview.h" +#include "xfa/fxfa/cxfa_ffdocview.h" #include "core/fxcrt/fx_ext.h" #include "third_party/base/ptr_util.h" @@ -25,15 +25,18 @@ #include "xfa/fxfa/app/xfa_fftextedit.h" #include "xfa/fxfa/app/xfa_ffwidgetacc.h" #include "xfa/fxfa/app/xfa_fwladapter.h" +#include "xfa/fxfa/cxfa_ffapp.h" +#include "xfa/fxfa/cxfa_ffdoc.h" +#include "xfa/fxfa/cxfa_ffpageview.h" +#include "xfa/fxfa/cxfa_ffwidget.h" +#include "xfa/fxfa/cxfa_ffwidgethandler.h" +#include "xfa/fxfa/cxfa_widgetacciterator.h" #include "xfa/fxfa/parser/cxfa_binditems.h" #include "xfa/fxfa/parser/cxfa_layoutprocessor.h" #include "xfa/fxfa/parser/cxfa_scriptcontext.h" #include "xfa/fxfa/parser/xfa_resolvenode_rs.h" -#include "xfa/fxfa/xfa_ffapp.h" -#include "xfa/fxfa/xfa_ffdoc.h" -#include "xfa/fxfa/xfa_ffpageview.h" -#include "xfa/fxfa/xfa_ffwidget.h" -#include "xfa/fxfa/xfa_ffwidgethandler.h" + +#define XFA_CalcRefCount (void*)(uintptr_t) FXBSTR_ID('X', 'F', 'A', 'R') const XFA_ATTRIBUTEENUM gs_EventActivity[] = { XFA_ATTRIBUTEENUM_Click, XFA_ATTRIBUTEENUM_Change, @@ -240,7 +243,7 @@ void CXFA_FFDocView::ResetWidgetData(CXFA_WidgetAcc* pWidgetAcc) { } if (pFormNode->GetElementType() != XFA_Element::Field && pFormNode->GetElementType() != XFA_Element::ExclGroup) { - CXFA_WidgetAccIterator Iterator(this, pFormNode); + CXFA_WidgetAccIterator Iterator(pFormNode); while (CXFA_WidgetAcc* pAcc = Iterator.MoveToNext()) { bChanged |= ResetSingleWidgetAccData(pAcc); if (pAcc->GetNode()->GetElementType() == XFA_Element::ExclGroup) { @@ -274,42 +277,28 @@ int32_t CXFA_FFDocView::ProcessWidgetEvent(CXFA_EventParam* pParam, ? pPresentNode->GetChild(0, XFA_Element::Validate) : nullptr; } - if (pValidateNode) { + if (pValidateNode) wsValidateStr = pValidateNode->GetContent(); - } - } - bool bValidate = false; - switch (pParam->m_iValidateActivities) { - case XFA_VALIDATE_preSubmit: - bValidate = wsValidateStr.Find(L"preSubmit") != -1; - break; - case XFA_VALIDATE_prePrint: - bValidate = wsValidateStr.Find(L"prePrint") != -1; - break; - case XFA_VALIDATE_preExecute: - bValidate = wsValidateStr.Find(L"preExecute") != -1; - break; - case XFA_VALIDATE_preSave: - bValidate = wsValidateStr.Find(L"preSave") != -1; - break; } - if (!bValidate) { + + if (wsValidateStr.Find(L"preSubmit") == -1) return XFA_EVENTERROR_Success; - } } + CXFA_Node* pNode = pWidgetAcc ? pWidgetAcc->GetNode() : nullptr; if (!pNode) { CXFA_Node* pRootItem = ToNode(m_pDoc->GetXFADoc()->GetXFAObject(XFA_HASHCODE_Form)); - if (!pRootItem) { + if (!pRootItem) return XFA_EVENTERROR_Error; - } + pNode = pRootItem->GetChild(0, XFA_Element::Subform); } ExecEventActivityByDeepFirst(pNode, pParam->m_eType, pParam->m_bIsFormReady, true, nullptr); return XFA_EVENTERROR_Success; } + CXFA_FFWidgetHandler* CXFA_FFDocView::GetWidgetHandler() { if (!m_pWidgetHandler) m_pWidgetHandler = pdfium::MakeUnique<CXFA_FFWidgetHandler>(this); @@ -320,11 +309,13 @@ CXFA_FFWidgetHandler* CXFA_FFDocView::GetWidgetHandler() { CXFA_WidgetAccIterator* CXFA_FFDocView::CreateWidgetAccIterator( XFA_WIDGETORDER eOrder) { CXFA_Node* pFormRoot = GetRootSubform(); - return pFormRoot ? new CXFA_WidgetAccIterator(this, pFormRoot) : nullptr; + return pFormRoot ? new CXFA_WidgetAccIterator(pFormRoot) : nullptr; } + CXFA_FFWidget* CXFA_FFDocView::GetFocusWidget() { return m_pFocusWidget; } + void CXFA_FFDocView::KillFocus() { if (m_pFocusWidget && (m_pFocusWidget->GetStatus() & XFA_WidgetStatus_Focused)) { @@ -514,10 +505,9 @@ CXFA_WidgetAcc* CXFA_FFDocView::GetWidgetAccByName( return nullptr; } if (resoveNodeRS.dwFlags == XFA_RESOVENODE_RSTYPE_Nodes) { - CXFA_Node* pNode = resoveNodeRS.nodes[0]->AsNode(); - if (pNode) { - return (CXFA_WidgetAcc*)pNode->GetWidgetData(); - } + CXFA_Node* pNode = resoveNodeRS.objects.front()->AsNode(); + if (pNode) + return static_cast<CXFA_WidgetAcc*>(pNode->GetWidgetData()); } return nullptr; } @@ -556,7 +546,7 @@ void CXFA_FFDocView::AddInvalidateRect(CXFA_FFPageView* pPageView, void CXFA_FFDocView::RunInvalidate() { for (const auto& pair : m_mapPageInvalidate) - m_pDoc->GetDocEnvironment()->InvalidateRect(pair.first, *pair.second, 0); + m_pDoc->GetDocEnvironment()->InvalidateRect(pair.first, *pair.second); m_mapPageInvalidate.clear(); } @@ -613,6 +603,7 @@ void CXFA_FFDocView::RunDocClose() { ExecEventActivityByDeepFirst(pRootItem, XFA_EVENT_DocClose, false, true, nullptr); } + void CXFA_FFDocView::DestroyDocView() { ClearInvalidateList(); m_iStatus = XFA_DOCVIEW_LAYOUTSTATUS_None; @@ -621,8 +612,9 @@ void CXFA_FFDocView::DestroyDocView() { m_BindItems.clear(); m_CalculateAccs.clear(); } + bool CXFA_FFDocView::IsStaticNotify() { - return m_pDoc->GetDocType() == XFA_DOCTYPE_Static; + return m_pDoc->GetDocType() == XFA_DocType::Static; } void CXFA_FFDocView::AddCalculateWidgetAcc(CXFA_WidgetAcc* pWidgetAcc) { @@ -633,12 +625,12 @@ void CXFA_FFDocView::AddCalculateWidgetAcc(CXFA_WidgetAcc* pWidgetAcc) { } void CXFA_FFDocView::AddCalculateNodeNotify(CXFA_Node* pNodeChange) { - auto pGlobalData = + auto* pGlobalData = static_cast<CXFA_CalcData*>(pNodeChange->GetUserData(XFA_CalcData)); if (!pGlobalData) return; - for (const auto& pResultAcc : pGlobalData->m_Globals) { + for (auto* pResultAcc : pGlobalData->m_Globals) { if (!pResultAcc->GetNode()->HasRemovedChildren()) AddCalculateWidgetAcc(pResultAcc); } @@ -722,8 +714,9 @@ bool CXFA_FFDocView::RunEventLayoutReady() { RunLayout(); return true; } + void CXFA_FFDocView::RunBindItems() { - for (const auto& item : m_BindItems) { + for (auto* item : m_BindItems) { if (item->HasRemovedChildren()) continue; @@ -743,9 +736,8 @@ void CXFA_FFDocView::RunBindItems() { XFA_RESOLVENODE_ALL; XFA_RESOLVENODE_RS rs; pScriptContext->ResolveObjects(pWidgetNode, wsRef, rs, dwStyle); - int32_t iCount = rs.nodes.GetSize(); pAcc->DeleteItem(-1); - if (rs.dwFlags != XFA_RESOVENODE_RSTYPE_Nodes || iCount < 1) + if (rs.dwFlags != XFA_RESOVENODE_RSTYPE_Nodes || rs.objects.empty()) continue; CFX_WideStringC wsValueRef, wsLabelRef; @@ -757,12 +749,10 @@ void CXFA_FFDocView::RunBindItems() { CFX_WideString wsValue; CFX_WideString wsLabel; uint32_t uValueHash = FX_HashCode_GetW(wsValueRef, false); - for (int32_t j = 0; j < iCount; j++) { - CXFA_Object* refObj = rs.nodes[j]; - if (!refObj->IsNode()) { + for (CXFA_Object* refObject : rs.objects) { + CXFA_Node* refNode = refObject->AsNode(); + if (!refNode) continue; - } - CXFA_Node* refNode = refObj->AsNode(); if (bValueUseContent) { wsValue = refNode->GetContent(); } else { @@ -785,6 +775,7 @@ void CXFA_FFDocView::RunBindItems() { } m_BindItems.clear(); } + void CXFA_FFDocView::SetChangeMark() { if (m_iStatus < XFA_DOCVIEW_LAYOUTSTATUS_End) { return; @@ -799,52 +790,3 @@ CXFA_Node* CXFA_FFDocView::GetRootSubform() { } return pFormPacketNode->GetFirstChildByClass(XFA_Element::Subform); } - -CXFA_WidgetAccIterator::CXFA_WidgetAccIterator(CXFA_FFDocView* pDocView, - CXFA_Node* pTravelRoot) - : m_ContentIterator(pTravelRoot), - m_pDocView(pDocView), - m_pCurWidgetAcc(nullptr) {} - -CXFA_WidgetAccIterator::~CXFA_WidgetAccIterator() {} -void CXFA_WidgetAccIterator::Reset() { - m_pCurWidgetAcc = nullptr; - m_ContentIterator.Reset(); -} - -CXFA_WidgetAcc* CXFA_WidgetAccIterator::MoveToFirst() { - return nullptr; -} - -CXFA_WidgetAcc* CXFA_WidgetAccIterator::MoveToLast() { - return nullptr; -} - -CXFA_WidgetAcc* CXFA_WidgetAccIterator::MoveToNext() { - CXFA_Node* pItem = m_pCurWidgetAcc ? m_ContentIterator.MoveToNext() - : m_ContentIterator.GetCurrent(); - while (pItem) { - m_pCurWidgetAcc = static_cast<CXFA_WidgetAcc*>(pItem->GetWidgetData()); - if (m_pCurWidgetAcc) - return m_pCurWidgetAcc; - pItem = m_ContentIterator.MoveToNext(); - } - return nullptr; -} - -CXFA_WidgetAcc* CXFA_WidgetAccIterator::MoveToPrevious() { - return nullptr; -} - -CXFA_WidgetAcc* CXFA_WidgetAccIterator::GetCurrentWidgetAcc() { - return nullptr; -} - -bool CXFA_WidgetAccIterator::SetCurrentWidgetAcc(CXFA_WidgetAcc* hWidget) { - return false; -} - -void CXFA_WidgetAccIterator::SkipTree() { - m_ContentIterator.SkipChildrenAndMoveToNext(); - m_pCurWidgetAcc = nullptr; -} diff --git a/chromium/third_party/pdfium/xfa/fxfa/xfa_ffdocview.h b/chromium/third_party/pdfium/xfa/fxfa/cxfa_ffdocview.h index d8df8b4312d..05ed9d70867 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/xfa_ffdocview.h +++ b/chromium/third_party/pdfium/xfa/fxfa/cxfa_ffdocview.h @@ -4,15 +4,15 @@ // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com -#ifndef XFA_FXFA_XFA_FFDOCVIEW_H_ -#define XFA_FXFA_XFA_FFDOCVIEW_H_ +#ifndef XFA_FXFA_CXFA_FFDOCVIEW_H_ +#define XFA_FXFA_CXFA_FFDOCVIEW_H_ #include <map> #include <memory> #include <vector> #include "xfa/fxfa/cxfa_eventparam.h" -#include "xfa/fxfa/xfa_ffdoc.h" +#include "xfa/fxfa/cxfa_ffdoc.h" class CXFA_FFWidgetHandler; class CXFA_FFDoc; @@ -36,6 +36,7 @@ enum XFA_DOCVIEW_LAYOUTSTATUS { XFA_DOCVIEW_LAYOUTSTATUS_DocReady, XFA_DOCVIEW_LAYOUTSTATUS_End }; + class CXFA_FFDocView { public: explicit CXFA_FFDocView(CXFA_FFDoc* pDoc); @@ -103,7 +104,9 @@ class CXFA_FFDocView { CXFA_FFWidget* m_pListFocusWidget; bool m_bInLayoutStatus; - protected: + private: + friend class CXFA_FFNotify; + bool RunEventLayoutReady(); void RunBindItems(); bool InitCalculate(CXFA_Node* pNode); @@ -127,27 +130,6 @@ class CXFA_FFDocView { std::vector<CXFA_Node*> m_IndexChangedSubforms; XFA_DOCVIEW_LAYOUTSTATUS m_iStatus; int32_t m_iLock; - friend class CXFA_FFNotify; -}; - -class CXFA_WidgetAccIterator { - public: - CXFA_WidgetAccIterator(CXFA_FFDocView* pDocView, CXFA_Node* pTravelRoot); - ~CXFA_WidgetAccIterator(); - - void Reset(); - CXFA_WidgetAcc* MoveToFirst(); - CXFA_WidgetAcc* MoveToLast(); - CXFA_WidgetAcc* MoveToNext(); - CXFA_WidgetAcc* MoveToPrevious(); - CXFA_WidgetAcc* GetCurrentWidgetAcc(); - bool SetCurrentWidgetAcc(CXFA_WidgetAcc* hWidget); - void SkipTree(); - - protected: - CXFA_ContainerIterator m_ContentIterator; - CXFA_FFDocView* const m_pDocView; - CXFA_WidgetAcc* m_pCurWidgetAcc; // not owned. }; -#endif // XFA_FXFA_XFA_FFDOCVIEW_H_ +#endif // XFA_FXFA_CXFA_FFDOCVIEW_H_ diff --git a/chromium/third_party/pdfium/xfa/fxfa/app/xfa_ffpageview.cpp b/chromium/third_party/pdfium/xfa/fxfa/cxfa_ffpageview.cpp index 7ae5493ba60..49033bc0ded 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/app/xfa_ffpageview.cpp +++ b/chromium/third_party/pdfium/xfa/fxfa/cxfa_ffpageview.cpp @@ -4,14 +4,15 @@ // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com -#include "xfa/fxfa/xfa_ffpageview.h" +#include "xfa/fxfa/cxfa_ffpageview.h" +#include <algorithm> #include <memory> #include <vector> #include "third_party/base/ptr_util.h" #include "third_party/base/stl_util.h" -#include "xfa/fde/fde_render.h" +#include "xfa/fde/cfde_rendercontext.h" #include "xfa/fxfa/app/xfa_ffcheckbutton.h" #include "xfa/fxfa/app/xfa_ffchoicelist.h" #include "xfa/fxfa/app/xfa_fffield.h" @@ -19,9 +20,10 @@ #include "xfa/fxfa/app/xfa_ffpushbutton.h" #include "xfa/fxfa/app/xfa_fftextedit.h" #include "xfa/fxfa/app/xfa_fwladapter.h" -#include "xfa/fxfa/xfa_ffdoc.h" -#include "xfa/fxfa/xfa_ffdocview.h" -#include "xfa/fxfa/xfa_ffwidget.h" +#include "xfa/fxfa/cxfa_ffdoc.h" +#include "xfa/fxfa/cxfa_ffdocview.h" +#include "xfa/fxfa/cxfa_ffwidget.h" +#include "xfa/fxfa/parser/cxfa_node.h" namespace { @@ -35,37 +37,29 @@ CFX_Matrix GetPageMatrix(const CFX_RectF& docPageRect, bool bFlipY = (dwCoordinatesType & 0x02) != 0; CFX_Matrix m((bFlipX ? -1.0f : 1.0f), 0, 0, (bFlipY ? -1.0f : 1.0f), 0, 0); if (iRotate == 0 || iRotate == 2) { - m.a *= (FX_FLOAT)devicePageRect.width / docPageRect.width; - m.d *= (FX_FLOAT)devicePageRect.height / docPageRect.height; + m.a *= (float)devicePageRect.width / docPageRect.width; + m.d *= (float)devicePageRect.height / docPageRect.height; } else { - m.a *= (FX_FLOAT)devicePageRect.height / docPageRect.width; - m.d *= (FX_FLOAT)devicePageRect.width / docPageRect.height; + m.a *= (float)devicePageRect.height / docPageRect.width; + m.d *= (float)devicePageRect.width / docPageRect.height; } m.Rotate(iRotate * 1.57079632675f); switch (iRotate) { case 0: - m.e = bFlipX ? (FX_FLOAT)devicePageRect.right() - : (FX_FLOAT)devicePageRect.left; - m.f = bFlipY ? (FX_FLOAT)devicePageRect.bottom() - : (FX_FLOAT)devicePageRect.top; + m.e = bFlipX ? (float)devicePageRect.right() : (float)devicePageRect.left; + m.f = bFlipY ? (float)devicePageRect.bottom() : (float)devicePageRect.top; break; case 1: - m.e = bFlipY ? (FX_FLOAT)devicePageRect.left - : (FX_FLOAT)devicePageRect.right(); - m.f = bFlipX ? (FX_FLOAT)devicePageRect.bottom() - : (FX_FLOAT)devicePageRect.top; + m.e = bFlipY ? (float)devicePageRect.left : (float)devicePageRect.right(); + m.f = bFlipX ? (float)devicePageRect.bottom() : (float)devicePageRect.top; break; case 2: - m.e = bFlipX ? (FX_FLOAT)devicePageRect.left - : (FX_FLOAT)devicePageRect.right(); - m.f = bFlipY ? (FX_FLOAT)devicePageRect.top - : (FX_FLOAT)devicePageRect.bottom(); + m.e = bFlipX ? (float)devicePageRect.left : (float)devicePageRect.right(); + m.f = bFlipY ? (float)devicePageRect.top : (float)devicePageRect.bottom(); break; case 3: - m.e = bFlipY ? (FX_FLOAT)devicePageRect.right() - : (FX_FLOAT)devicePageRect.left; - m.f = bFlipX ? (FX_FLOAT)devicePageRect.top - : (FX_FLOAT)devicePageRect.bottom(); + m.e = bFlipY ? (float)devicePageRect.right() : (float)devicePageRect.left; + m.f = bFlipX ? (float)devicePageRect.top : (float)devicePageRect.bottom(); break; default: break; @@ -146,18 +140,19 @@ IXFA_WidgetIterator* CXFA_FFPageView::CreateWidgetIterator( } CXFA_FFPageWidgetIterator::CXFA_FFPageWidgetIterator(CXFA_FFPageView* pPageView, - uint32_t dwFilter) { - m_pPageView = pPageView; - m_dwFilter = dwFilter; - m_sIterator.Init(pPageView); + uint32_t dwFilter) + : m_pPageView(pPageView), m_dwFilter(dwFilter), m_sIterator(pPageView) { m_bIgnorerelevant = m_pPageView->GetDocView()->GetDoc()->GetXFADoc()->GetCurVersionMode() < XFA_VERSION_205; } + CXFA_FFPageWidgetIterator::~CXFA_FFPageWidgetIterator() {} + void CXFA_FFPageWidgetIterator::Reset() { m_sIterator.Reset(); } + CXFA_FFWidget* CXFA_FFPageWidgetIterator::MoveToFirst() { m_sIterator.Reset(); for (CXFA_LayoutItem* pLayoutItem = m_sIterator.GetCurrent(); pLayoutItem; @@ -168,10 +163,12 @@ CXFA_FFWidget* CXFA_FFPageWidgetIterator::MoveToFirst() { } return nullptr; } + CXFA_FFWidget* CXFA_FFPageWidgetIterator::MoveToLast() { m_sIterator.SetCurrent(nullptr); return MoveToPrevious(); } + CXFA_FFWidget* CXFA_FFPageWidgetIterator::MoveToNext() { for (CXFA_LayoutItem* pLayoutItem = m_sIterator.MoveToNext(); pLayoutItem; pLayoutItem = m_sIterator.MoveToNext()) { @@ -181,6 +178,7 @@ CXFA_FFWidget* CXFA_FFPageWidgetIterator::MoveToNext() { } return nullptr; } + CXFA_FFWidget* CXFA_FFPageWidgetIterator::MoveToPrevious() { for (CXFA_LayoutItem* pLayoutItem = m_sIterator.MoveToPrev(); pLayoutItem; pLayoutItem = m_sIterator.MoveToPrev()) { @@ -190,26 +188,40 @@ CXFA_FFWidget* CXFA_FFPageWidgetIterator::MoveToPrevious() { } return nullptr; } + CXFA_FFWidget* CXFA_FFPageWidgetIterator::GetCurrentWidget() { CXFA_LayoutItem* pLayoutItem = m_sIterator.GetCurrent(); return pLayoutItem ? XFA_GetWidgetFromLayoutItem(pLayoutItem) : nullptr; } + bool CXFA_FFPageWidgetIterator::SetCurrentWidget(CXFA_FFWidget* hWidget) { return hWidget && m_sIterator.SetCurrent(hWidget); } + CXFA_FFWidget* CXFA_FFPageWidgetIterator::GetWidget( CXFA_LayoutItem* pLayoutItem) { - if (CXFA_FFWidget* pWidget = XFA_GetWidgetFromLayoutItem(pLayoutItem)) { - if (!PageWidgetFilter(pWidget, m_dwFilter, false, m_bIgnorerelevant)) { - return nullptr; - } - if (!pWidget->IsLoaded() && - (pWidget->GetStatus() & XFA_WidgetStatus_Visible) != 0) { - pWidget->LoadWidget(); - } - return pWidget; + CXFA_FFWidget* pWidget = XFA_GetWidgetFromLayoutItem(pLayoutItem); + if (!pWidget) + return nullptr; + + if (!PageWidgetFilter(pWidget, m_dwFilter, false, m_bIgnorerelevant)) + return nullptr; + + if (!pWidget->IsLoaded() && + !!(pWidget->GetStatus() & XFA_WidgetStatus_Visible)) { + pWidget->LoadWidget(); } - return nullptr; + return pWidget; +} + +void CXFA_TabParam::AppendTabParam(CXFA_TabParam* pParam) { + m_Children.push_back(pParam->GetWidget()); + m_Children.insert(m_Children.end(), pParam->GetChildren().begin(), + pParam->GetChildren().end()); +} + +void CXFA_TabParam::ClearChildren() { + m_Children.clear(); } CXFA_FFTabOrderPageWidgetIterator::CXFA_FFTabOrderPageWidgetIterator( @@ -361,18 +373,6 @@ void CXFA_FFTabOrderPageWidgetIterator::CreateTabOrderWidgetArray() { } } -static int32_t XFA_TabOrderWidgetComparator(const void* phWidget1, - const void* phWidget2) { - auto param1 = *static_cast<CXFA_TabParam**>(const_cast<void*>(phWidget1)); - auto param2 = *static_cast<CXFA_TabParam**>(const_cast<void*>(phWidget2)); - CFX_RectF rt1 = param1->m_pWidget->GetWidgetRect(); - CFX_RectF rt2 = param2->m_pWidget->GetWidgetRect(); - FX_FLOAT x1 = rt1.left, y1 = rt1.top, x2 = rt2.left, y2 = rt2.top; - if (y1 < y2 || (y1 - y2 < XFA_FLOAT_PERCISION && x1 < x2)) - return -1; - return 1; -} - void CXFA_FFTabOrderPageWidgetIterator::OrderContainer( CXFA_LayoutItemIterator* sIterator, CXFA_LayoutItem* pContainerItem, @@ -380,7 +380,7 @@ void CXFA_FFTabOrderPageWidgetIterator::OrderContainer( bool& bCurrentItem, bool& bContentArea, bool bMarsterPage) { - CFX_ArrayTemplate<CXFA_TabParam*> tabParams; + std::vector<std::unique_ptr<CXFA_TabParam>> tabParams; CXFA_LayoutItem* pSearchItem = sIterator->MoveToNext(); while (pSearchItem) { if (!pSearchItem->IsContentLayoutItem()) { @@ -401,12 +401,10 @@ void CXFA_FFTabOrderPageWidgetIterator::OrderContainer( bCurrentItem = true; break; } - CXFA_TabParam* pParam = new CXFA_TabParam; - pParam->m_pWidget = hWidget; - tabParams.Add(pParam); + tabParams.push_back(pdfium::MakeUnique<CXFA_TabParam>(hWidget)); if (IsLayoutElement(pSearchItem->GetFormNode()->GetElementType(), true)) { - OrderContainer(sIterator, pSearchItem, pParam, bCurrentItem, - bContentArea, bMarsterPage); + OrderContainer(sIterator, pSearchItem, tabParams.back().get(), + bCurrentItem, bContentArea, bMarsterPage); } } if (bCurrentItem) { @@ -416,39 +414,37 @@ void CXFA_FFTabOrderPageWidgetIterator::OrderContainer( pSearchItem = sIterator->MoveToNext(); } } - int32_t iChildren = tabParams.GetSize(); - if (iChildren > 1) { - FXSYS_qsort(tabParams.GetData(), iChildren, sizeof(void*), - XFA_TabOrderWidgetComparator); - } - for (int32_t iStart = 0; iStart < iChildren; iStart++) { - std::unique_ptr<CXFA_TabParam> pParam(tabParams[iStart]); - pContainer->m_Children.push_back(pParam->m_pWidget); - pContainer->m_Children.insert(pContainer->m_Children.end(), - pParam->m_Children.begin(), - pParam->m_Children.end()); - } - tabParams.RemoveAll(); + std::sort(tabParams.begin(), tabParams.end(), + [](const std::unique_ptr<CXFA_TabParam>& arg1, + const std::unique_ptr<CXFA_TabParam>& arg2) { + const CFX_RectF& rt1 = arg1->GetWidget()->GetWidgetRect(); + const CFX_RectF& rt2 = arg2->GetWidget()->GetWidgetRect(); + if (rt1.top - rt2.top >= XFA_FLOAT_PERCISION) + return rt1.top < rt2.top; + return rt1.left < rt2.left; + }); + for (const auto& pParam : tabParams) + pContainer->AppendTabParam(pParam.get()); } + void CXFA_FFTabOrderPageWidgetIterator::CreateSpaceOrderWidgetArray( std::vector<CXFA_FFWidget*>* WidgetArray) { - CXFA_LayoutItemIterator sIterator; - sIterator.Init(m_pPageView); - auto pParam = pdfium::MakeUnique<CXFA_TabParam>(); + CXFA_LayoutItemIterator sIterator(m_pPageView); + auto pParam = pdfium::MakeUnique<CXFA_TabParam>(nullptr); bool bCurrentItem = false; bool bContentArea = false; OrderContainer(&sIterator, nullptr, pParam.get(), bCurrentItem, bContentArea); - WidgetArray->insert(WidgetArray->end(), pParam->m_Children.begin(), - pParam->m_Children.end()); + WidgetArray->insert(WidgetArray->end(), pParam->GetChildren().begin(), + pParam->GetChildren().end()); sIterator.Reset(); bCurrentItem = false; bContentArea = false; - pParam->m_Children.clear(); + pParam->ClearChildren(); OrderContainer(&sIterator, nullptr, pParam.get(), bCurrentItem, bContentArea, true); - WidgetArray->insert(WidgetArray->end(), pParam->m_Children.begin(), - pParam->m_Children.end()); + WidgetArray->insert(WidgetArray->end(), pParam->GetChildren().begin(), + pParam->GetChildren().end()); } CXFA_FFWidget* CXFA_FFTabOrderPageWidgetIterator::GetWidget( @@ -463,6 +459,6 @@ CXFA_FFWidget* CXFA_FFTabOrderPageWidgetIterator::GetWidget( return nullptr; } -CXFA_TabParam::CXFA_TabParam() : m_pWidget(nullptr) {} +CXFA_TabParam::CXFA_TabParam(CXFA_FFWidget* pWidget) : m_pWidget(pWidget) {} CXFA_TabParam::~CXFA_TabParam() {} diff --git a/chromium/third_party/pdfium/xfa/fxfa/xfa_ffpageview.h b/chromium/third_party/pdfium/xfa/fxfa/cxfa_ffpageview.h index 4b50a2365db..df4fc6d2c17 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/xfa_ffpageview.h +++ b/chromium/third_party/pdfium/xfa/fxfa/cxfa_ffpageview.h @@ -4,14 +4,15 @@ // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com -#ifndef XFA_FXFA_XFA_FFPAGEVIEW_H_ -#define XFA_FXFA_XFA_FFPAGEVIEW_H_ +#ifndef XFA_FXFA_CXFA_FFPAGEVIEW_H_ +#define XFA_FXFA_CXFA_FFPAGEVIEW_H_ #include <vector> #include "xfa/fxfa/parser/cxfa_containerlayoutitem.h" #include "xfa/fxfa/parser/cxfa_contentlayoutitem.h" #include "xfa/fxfa/parser/cxfa_traversestrategy_layoutitem.h" +#include "xfa/fxfa/parser/xfa_utils.h" class CXFA_FFWidget; class CXFA_FFDocView; @@ -62,10 +63,16 @@ class CXFA_FFPageWidgetIterator : public IXFA_WidgetIterator { class CXFA_TabParam { public: - CXFA_TabParam(); + explicit CXFA_TabParam(CXFA_FFWidget* pWidget); ~CXFA_TabParam(); - CXFA_FFWidget* m_pWidget; + void AppendTabParam(CXFA_TabParam* pParam); + void ClearChildren(); + CXFA_FFWidget* GetWidget() { return m_pWidget; } + const std::vector<CXFA_FFWidget*>& GetChildren() const { return m_Children; } + + private: + CXFA_FFWidget* const m_pWidget; std::vector<CXFA_FFWidget*> m_Children; }; @@ -104,4 +111,4 @@ class CXFA_FFTabOrderPageWidgetIterator : public IXFA_WidgetIterator { bool m_bIgnorerelevant; }; -#endif // XFA_FXFA_XFA_FFPAGEVIEW_H_ +#endif // XFA_FXFA_CXFA_FFPAGEVIEW_H_ diff --git a/chromium/third_party/pdfium/xfa/fxfa/app/xfa_ffwidget.cpp b/chromium/third_party/pdfium/xfa/fxfa/cxfa_ffwidget.cpp index 9995fd11b2a..18d6f94bc71 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/app/xfa_ffwidget.cpp +++ b/chromium/third_party/pdfium/xfa/fxfa/cxfa_ffwidget.cpp @@ -4,7 +4,7 @@ // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com -#include "xfa/fxfa/xfa_ffwidget.h" +#include "xfa/fxfa/cxfa_ffwidget.h" #include <algorithm> #include <memory> @@ -17,15 +17,18 @@ #include "core/fxge/cfx_gemodule.h" #include "core/fxge/cfx_pathdata.h" #include "core/fxge/cfx_renderdevice.h" +#include "core/fxge/dib/cfx_imagerenderer.h" +#include "core/fxge/dib/cfx_imagetransformer.h" #include "xfa/fwl/fwl_widgethit.h" #include "xfa/fxfa/app/cxfa_textlayout.h" #include "xfa/fxfa/cxfa_eventparam.h" -#include "xfa/fxfa/fxfa_widget.h" +#include "xfa/fxfa/cxfa_ffapp.h" +#include "xfa/fxfa/cxfa_ffdoc.h" +#include "xfa/fxfa/cxfa_ffdocview.h" +#include "xfa/fxfa/cxfa_ffpageview.h" +#include "xfa/fxfa/cxfa_widgetacc.h" #include "xfa/fxfa/parser/cxfa_corner.h" -#include "xfa/fxfa/xfa_ffapp.h" -#include "xfa/fxfa/xfa_ffdoc.h" -#include "xfa/fxfa/xfa_ffdocview.h" -#include "xfa/fxfa/xfa_ffpageview.h" +#include "xfa/fxfa/parser/cxfa_node.h" #include "xfa/fxgraphics/cfx_color.h" #include "xfa/fxgraphics/cfx_graphics.h" #include "xfa/fxgraphics/cfx_path.h" @@ -43,13 +46,13 @@ const CFWL_App* CXFA_FFWidget::GetFWLApp() { return GetPageView()->GetDocView()->GetDoc()->GetApp()->GetFWLApp(); } -CFX_RectF CXFA_FFWidget::GetWidgetRect() { +const CFX_RectF& CXFA_FFWidget::GetWidgetRect() const { if ((m_dwStatus & XFA_WidgetStatus_RectCached) == 0) RecacheWidgetRect(); return m_rtWidget; } -CFX_RectF CXFA_FFWidget::RecacheWidgetRect() { +const CFX_RectF& CXFA_FFWidget::RecacheWidgetRect() const { m_dwStatus |= XFA_WidgetStatus_RectCached; m_rtWidget = GetRect(false); return m_rtWidget; @@ -57,7 +60,7 @@ CFX_RectF CXFA_FFWidget::RecacheWidgetRect() { CFX_RectF CXFA_FFWidget::GetRectWithoutRotate() { CFX_RectF rtWidget = GetWidgetRect(); - FX_FLOAT fValue = 0; + float fValue = 0; switch (m_pDataAcc->GetRotate()) { case 90: rtWidget.top = rtWidget.bottom(); @@ -151,15 +154,13 @@ void CXFA_FFWidget::DrawBorder(CFX_Graphics* pGS, void CXFA_FFWidget::InvalidateWidget(const CFX_RectF* pRect) { if (pRect) { - GetDoc()->GetDocEnvironment()->InvalidateRect(m_pPageView, *pRect, - XFA_INVALIDATE_CurrentPage); + GetDoc()->GetDocEnvironment()->InvalidateRect(m_pPageView, *pRect); return; } CFX_RectF rtWidget = GetBBox(XFA_WidgetStatus_Focused); rtWidget.Inflate(2, 2); - GetDoc()->GetDocEnvironment()->InvalidateRect(m_pPageView, rtWidget, - XFA_INVALIDATE_CurrentPage); + GetDoc()->GetDocEnvironment()->InvalidateRect(m_pPageView, rtWidget); } void CXFA_FFWidget::AddInvalidateRect(const CFX_RectF* pRect) { @@ -357,8 +358,8 @@ static void XFA_GetMatrix(CFX_Matrix& m, if (!iRotate) { return; } - FX_FLOAT fAnchorX = 0; - FX_FLOAT fAnchorY = 0; + float fAnchorX = 0; + float fAnchorY = 0; switch (at) { case XFA_ATTRIBUTEENUM_TopLeft: fAnchorX = rt.left, fAnchorY = rt.top; @@ -502,7 +503,7 @@ int32_t XFA_StrokeTypeSetLineDash(CFX_Graphics* pGraphics, int32_t iCapType) { switch (iStrokeType) { case XFA_ATTRIBUTEENUM_DashDot: { - FX_FLOAT dashArray[] = {4, 1, 2, 1}; + float dashArray[] = {4, 1, 2, 1}; if (iCapType != XFA_ATTRIBUTEENUM_Butt) { dashArray[1] = 2; dashArray[3] = 2; @@ -511,7 +512,7 @@ int32_t XFA_StrokeTypeSetLineDash(CFX_Graphics* pGraphics, return FX_DASHSTYLE_DashDot; } case XFA_ATTRIBUTEENUM_DashDotDot: { - FX_FLOAT dashArray[] = {4, 1, 2, 1, 2, 1}; + float dashArray[] = {4, 1, 2, 1, 2, 1}; if (iCapType != XFA_ATTRIBUTEENUM_Butt) { dashArray[1] = 2; dashArray[3] = 2; @@ -521,7 +522,7 @@ int32_t XFA_StrokeTypeSetLineDash(CFX_Graphics* pGraphics, return FX_DASHSTYLE_DashDotDot; } case XFA_ATTRIBUTEENUM_Dashed: { - FX_FLOAT dashArray[] = {5, 1}; + float dashArray[] = {5, 1}; if (iCapType != XFA_ATTRIBUTEENUM_Butt) { dashArray[1] = 2; } @@ -529,7 +530,7 @@ int32_t XFA_StrokeTypeSetLineDash(CFX_Graphics* pGraphics, return FX_DASHSTYLE_Dash; } case XFA_ATTRIBUTEENUM_Dotted: { - FX_FLOAT dashArray[] = {2, 1}; + float dashArray[] = {2, 1}; if (iCapType != XFA_ATTRIBUTEENUM_Butt) { dashArray[1] = 2; } @@ -560,7 +561,7 @@ class CXFA_ImageRenderer { ~CXFA_ImageRenderer(); bool Start(CFX_RenderDevice* pDevice, - CFX_DIBSource* pDIBSource, + const CFX_RetainPtr<CFX_DIBSource>& pDIBSource, FX_ARGB bitmap_argb, int bitmap_alpha, const CFX_Matrix* pImage2Device, @@ -570,7 +571,7 @@ class CXFA_ImageRenderer { protected: bool StartDIBSource(); - void CompositeDIBitmap(CFX_DIBitmap* pDIBitmap, + void CompositeDIBitmap(const CFX_RetainPtr<CFX_DIBitmap>& pDIBitmap, int left, int top, FX_ARGB mask_argb, @@ -581,13 +582,13 @@ class CXFA_ImageRenderer { CFX_RenderDevice* m_pDevice; int m_Status; CFX_Matrix m_ImageMatrix; - CFX_DIBSource* m_pDIBSource; - std::unique_ptr<CFX_DIBitmap> m_pCloneConvert; + CFX_RetainPtr<CFX_DIBSource> m_pDIBSource; + CFX_RetainPtr<CFX_DIBitmap> m_pCloneConvert; int m_BitmapAlpha; FX_ARGB m_FillArgb; uint32_t m_Flags; std::unique_ptr<CFX_ImageTransformer> m_pTransformer; - void* m_DeviceHandle; + std::unique_ptr<CFX_ImageRenderer> m_DeviceHandle; int32_t m_BlendType; bool m_Result; bool m_bPrint; @@ -596,7 +597,6 @@ class CXFA_ImageRenderer { CXFA_ImageRenderer::CXFA_ImageRenderer() : m_pDevice(nullptr), m_Status(0), - m_pDIBSource(nullptr), m_BitmapAlpha(255), m_FillArgb(0), m_Flags(0), @@ -605,13 +605,10 @@ CXFA_ImageRenderer::CXFA_ImageRenderer() m_Result(true), m_bPrint(false) {} -CXFA_ImageRenderer::~CXFA_ImageRenderer() { - if (m_DeviceHandle) - m_pDevice->CancelDIBits(m_DeviceHandle); -} +CXFA_ImageRenderer::~CXFA_ImageRenderer() {} bool CXFA_ImageRenderer::Start(CFX_RenderDevice* pDevice, - CFX_DIBSource* pDIBSource, + const CFX_RetainPtr<CFX_DIBSource>& pDIBSource, FX_ARGB bitmap_argb, int bitmap_alpha, const CFX_Matrix* pImage2Device, @@ -629,7 +626,7 @@ bool CXFA_ImageRenderer::Start(CFX_RenderDevice* pDevice, bool CXFA_ImageRenderer::StartDIBSource() { if (m_pDevice->StartDIBitsWithBlend(m_pDIBSource, m_BitmapAlpha, m_FillArgb, - &m_ImageMatrix, m_Flags, m_DeviceHandle, + &m_ImageMatrix, m_Flags, &m_DeviceHandle, m_BlendType)) { if (m_DeviceHandle) { m_Status = 3; @@ -641,13 +638,13 @@ bool CXFA_ImageRenderer::StartDIBSource() { FX_RECT image_rect = image_rect_f.GetOuterRect(); int dest_width = image_rect.Width(); int dest_height = image_rect.Height(); - if ((FXSYS_fabs(m_ImageMatrix.b) >= 0.5f || m_ImageMatrix.a == 0) || - (FXSYS_fabs(m_ImageMatrix.c) >= 0.5f || m_ImageMatrix.d == 0)) { + if ((fabs(m_ImageMatrix.b) >= 0.5f || m_ImageMatrix.a == 0) || + (fabs(m_ImageMatrix.c) >= 0.5f || m_ImageMatrix.d == 0)) { if (m_bPrint && !(m_pDevice->GetRenderCaps() & FXRC_BLEND_MODE)) { m_Result = false; return false; } - CFX_DIBSource* pDib = m_pDIBSource; + CFX_RetainPtr<CFX_DIBSource> pDib = m_pDIBSource; if (m_pDIBSource->HasAlpha() && !(m_pDevice->GetRenderCaps() & FXRC_ALPHA_IMAGE) && !(m_pDevice->GetRenderCaps() & FXRC_GET_BITS)) { @@ -656,13 +653,13 @@ bool CXFA_ImageRenderer::StartDIBSource() { m_Result = false; return false; } - pDib = m_pCloneConvert.get(); + pDib = m_pCloneConvert; } FX_RECT clip_box = m_pDevice->GetClipBox(); clip_box.Intersect(image_rect); m_Status = 2; - m_pTransformer.reset( - new CFX_ImageTransformer(pDib, &m_ImageMatrix, m_Flags, &clip_box)); + m_pTransformer = pdfium::MakeUnique<CFX_ImageTransformer>( + pDib, &m_ImageMatrix, m_Flags, &clip_box); m_pTransformer->Start(); return true; } @@ -702,11 +699,11 @@ bool CXFA_ImageRenderer::StartDIBSource() { FX_RECT dest_clip( dest_rect.left - image_rect.left, dest_rect.top - image_rect.top, dest_rect.right - image_rect.left, dest_rect.bottom - image_rect.top); - std::unique_ptr<CFX_DIBitmap> pStretched( - m_pDIBSource->StretchTo(dest_width, dest_height, m_Flags, &dest_clip)); + CFX_RetainPtr<CFX_DIBitmap> pStretched = + m_pDIBSource->StretchTo(dest_width, dest_height, m_Flags, &dest_clip); if (pStretched) { - CompositeDIBitmap(pStretched.get(), dest_rect.left, dest_rect.top, - m_FillArgb, m_BitmapAlpha, m_BlendType, false); + CompositeDIBitmap(pStretched, dest_rect.left, dest_rect.top, m_FillArgb, + m_BitmapAlpha, m_BlendType, false); } return false; } @@ -716,7 +713,7 @@ bool CXFA_ImageRenderer::Continue(IFX_Pause* pPause) { if (m_pTransformer->Continue(pPause)) return true; - std::unique_ptr<CFX_DIBitmap> pBitmap(m_pTransformer->DetachBitmap()); + CFX_RetainPtr<CFX_DIBitmap> pBitmap = m_pTransformer->DetachBitmap(); if (!pBitmap) return false; @@ -724,30 +721,31 @@ bool CXFA_ImageRenderer::Continue(IFX_Pause* pPause) { if (m_BitmapAlpha != 255) m_FillArgb = FXARGB_MUL_ALPHA(m_FillArgb, m_BitmapAlpha); m_Result = - m_pDevice->SetBitMask(pBitmap.get(), m_pTransformer->result().left, + m_pDevice->SetBitMask(pBitmap, m_pTransformer->result().left, m_pTransformer->result().top, m_FillArgb); } else { if (m_BitmapAlpha != 255) pBitmap->MultiplyAlpha(m_BitmapAlpha); m_Result = m_pDevice->SetDIBitsWithBlend( - pBitmap.get(), m_pTransformer->result().left, - m_pTransformer->result().top, m_BlendType); + pBitmap, m_pTransformer->result().left, m_pTransformer->result().top, + m_BlendType); } return false; } if (m_Status == 3) - return m_pDevice->ContinueDIBits(m_DeviceHandle, pPause); + return m_pDevice->ContinueDIBits(m_DeviceHandle.get(), pPause); return false; } -void CXFA_ImageRenderer::CompositeDIBitmap(CFX_DIBitmap* pDIBitmap, - int left, - int top, - FX_ARGB mask_argb, - int bitmap_alpha, - int blend_mode, - int Transparency) { +void CXFA_ImageRenderer::CompositeDIBitmap( + const CFX_RetainPtr<CFX_DIBitmap>& pDIBitmap, + int left, + int top, + FX_ARGB mask_argb, + int bitmap_alpha, + int blend_mode, + int Transparency) { if (!pDIBitmap) { return; } @@ -787,10 +785,10 @@ void CXFA_ImageRenderer::CompositeDIBitmap(CFX_DIBitmap* pDIBitmap, FX_RECT rect(left, top, left + pDIBitmap->GetWidth(), top + pDIBitmap->GetHeight()); rect.Intersect(m_pDevice->GetClipBox()); - CFX_MaybeOwned<CFX_DIBitmap> pClone; + CFX_RetainPtr<CFX_DIBitmap> pClone; if (m_pDevice->GetBackDrop() && m_pDevice->GetBitmap()) { pClone = m_pDevice->GetBackDrop()->Clone(&rect); - CFX_DIBitmap* pForeBitmap = m_pDevice->GetBitmap(); + CFX_RetainPtr<CFX_DIBitmap> pForeBitmap = m_pDevice->GetBitmap(); pClone->CompositeBitmap(0, 0, pClone->GetWidth(), pClone->GetHeight(), pForeBitmap, rect.left, rect.top); left = left >= 0 ? 0 : left; @@ -805,7 +803,7 @@ void CXFA_ImageRenderer::CompositeDIBitmap(CFX_DIBitmap* pDIBitmap, pClone = pDIBitmap; } if (m_pDevice->GetBackDrop()) { - m_pDevice->SetDIBits(pClone.Get(), rect.left, rect.top); + m_pDevice->SetDIBits(pClone, rect.left, rect.top); } else { if (pDIBitmap->IsAlphaMask()) return; @@ -819,14 +817,14 @@ void CXFA_ImageRenderer::CompositeDIBitmap(CFX_DIBitmap* pDIBitmap, (m_pDevice->GetRenderCaps() & FXRC_ALPHA_IMAGE)) { return; } - std::unique_ptr<CFX_DIBitmap> pCloneConvert = + CFX_RetainPtr<CFX_DIBitmap> pCloneConvert = pDIBitmap->CloneConvert(FXDIB_Rgb); if (!pCloneConvert) return; CXFA_ImageRenderer imageRender; - if (!imageRender.Start(m_pDevice, pCloneConvert.get(), m_FillArgb, - m_BitmapAlpha, &m_ImageMatrix, m_Flags)) { + if (!imageRender.Start(m_pDevice, pCloneConvert, m_FillArgb, m_BitmapAlpha, + &m_ImageMatrix, m_Flags)) { return; } while (imageRender.Continue(nullptr)) @@ -836,7 +834,7 @@ void CXFA_ImageRenderer::CompositeDIBitmap(CFX_DIBitmap* pDIBitmap, void XFA_DrawImage(CFX_Graphics* pGS, const CFX_RectF& rtImage, CFX_Matrix* pMatrix, - CFX_DIBitmap* pDIBitmap, + const CFX_RetainPtr<CFX_DIBitmap>& pDIBitmap, int32_t iAspect, int32_t iImageXDpi, int32_t iImageYDpi, @@ -849,12 +847,12 @@ void XFA_DrawImage(CFX_Graphics* pGS, CFX_RectF rtFit( rtImage.TopLeft(), - XFA_UnitPx2Pt((FX_FLOAT)pDIBitmap->GetWidth(), (FX_FLOAT)iImageXDpi), - XFA_UnitPx2Pt((FX_FLOAT)pDIBitmap->GetHeight(), (FX_FLOAT)iImageYDpi)); + XFA_UnitPx2Pt((float)pDIBitmap->GetWidth(), (float)iImageXDpi), + XFA_UnitPx2Pt((float)pDIBitmap->GetHeight(), (float)iImageYDpi)); switch (iAspect) { case XFA_ATTRIBUTEENUM_Fit: { - FX_FLOAT f1 = rtImage.height / rtFit.height; - FX_FLOAT f2 = rtImage.width / rtFit.width; + float f1 = rtImage.height / rtFit.height; + float f2 = rtImage.width / rtFit.width; f1 = std::min(f1, f2); rtFit.height = rtFit.height * f1; rtFit.width = rtFit.width * f1; @@ -862,7 +860,7 @@ void XFA_DrawImage(CFX_Graphics* pGS, case XFA_ATTRIBUTEENUM_Actual: break; case XFA_ATTRIBUTEENUM_Height: { - FX_FLOAT f1 = rtImage.height / rtFit.height; + float f1 = rtImage.height / rtFit.height; rtFit.height = rtImage.height; rtFit.width = f1 * rtFit.width; } break; @@ -871,7 +869,7 @@ void XFA_DrawImage(CFX_Graphics* pGS, rtFit.width = rtImage.width; break; case XFA_ATTRIBUTEENUM_Width: { - FX_FLOAT f1 = rtImage.width / rtFit.width; + float f1 = rtImage.width / rtFit.width; rtFit.width = rtImage.width; rtFit.height = rtFit.height * f1; } break; @@ -923,7 +921,7 @@ static uint8_t* XFA_RemoveBase64Whitespace(const uint8_t* pStr, int32_t iLen) { uint8_t* pCP; int32_t i = 0, j = 0; if (iLen == 0) { - iLen = FXSYS_strlen((FX_CHAR*)pStr); + iLen = FXSYS_strlen((char*)pStr); } pCP = FX_Alloc(uint8_t, iLen + 1); for (; i < iLen; i++) { @@ -936,16 +934,16 @@ static uint8_t* XFA_RemoveBase64Whitespace(const uint8_t* pStr, int32_t iLen) { pCP[j] = '\0'; return pCP; } -static int32_t XFA_Base64Decode(const FX_CHAR* pStr, uint8_t* pOutBuffer) { +static int32_t XFA_Base64Decode(const char* pStr, uint8_t* pOutBuffer) { if (!pStr) { return 0; } uint8_t* pBuffer = - XFA_RemoveBase64Whitespace((uint8_t*)pStr, FXSYS_strlen((FX_CHAR*)pStr)); + XFA_RemoveBase64Whitespace((uint8_t*)pStr, FXSYS_strlen((char*)pStr)); if (!pBuffer) { return 0; } - int32_t iLen = FXSYS_strlen((FX_CHAR*)pBuffer); + int32_t iLen = FXSYS_strlen((char*)pBuffer); int32_t i = 0, j = 0; uint32_t dwLimb = 0; for (; i + 3 < iLen; i += 4) { @@ -982,14 +980,14 @@ static int32_t XFA_Base64Decode(const FX_CHAR* pStr, uint8_t* pOutBuffer) { return j; } -static const FX_CHAR g_base64_chars[] = +static const char g_base64_chars[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; -FX_CHAR* XFA_Base64Encode(const uint8_t* buf, int32_t buf_len) { - FX_CHAR* out = nullptr; +char* XFA_Base64Encode(const uint8_t* buf, int32_t buf_len) { + char* out = nullptr; int i, j; uint32_t limb; - out = FX_Alloc(FX_CHAR, ((buf_len * 8 + 5) / 6) + 5); + out = FX_Alloc(char, ((buf_len * 8 + 5) / 6) + 5); for (i = 0, j = 0, limb = 0; i + 2 < buf_len; i += 3, j += 4) { limb = ((uint32_t)buf[i] << 16) | ((uint32_t)buf[i + 1] << 8) | ((uint32_t)buf[i + 2]); @@ -1036,18 +1034,19 @@ FXCODEC_IMAGE_TYPE XFA_GetImageType(const CFX_WideString& wsType) { return FXCODEC_IMAGE_TIF; return FXCODEC_IMAGE_UNKNOWN; } -CFX_DIBitmap* XFA_LoadImageData(CXFA_FFDoc* pDoc, - CXFA_Image* pImage, - bool& bNameImage, - int32_t& iImageXDpi, - int32_t& iImageYDpi) { + +CFX_RetainPtr<CFX_DIBitmap> XFA_LoadImageData(CXFA_FFDoc* pDoc, + CXFA_Image* pImage, + bool& bNameImage, + int32_t& iImageXDpi, + int32_t& iImageYDpi) { CFX_WideString wsHref; - pImage->GetHref(wsHref); CFX_WideString wsImage; + pImage->GetHref(wsHref); pImage->GetContent(wsImage); - if (wsHref.IsEmpty() && wsImage.IsEmpty()) { + if (wsHref.IsEmpty() && wsImage.IsEmpty()) return nullptr; - } + CFX_WideString wsContentType; pImage->GetContentType(wsContentType); FXCODEC_IMAGE_TYPE type = XFA_GetImageType(wsContentType); @@ -1073,7 +1072,7 @@ CFX_DIBitmap* XFA_LoadImageData(CXFA_FFDoc* pDoc, } else { CFX_WideString wsURL = wsHref; if (wsURL.Left(7) != L"http://" && wsURL.Left(6) != L"ftp://") { - CFX_DIBitmap* pBitmap = + CFX_RetainPtr<CFX_DIBitmap> pBitmap = pDoc->GetPDFNamedImage(wsURL.AsStringC(), iImageXDpi, iImageYDpi); if (pBitmap) { bNameImage = true; @@ -1087,7 +1086,7 @@ CFX_DIBitmap* XFA_LoadImageData(CXFA_FFDoc* pDoc, return nullptr; } bNameImage = false; - CFX_DIBitmap* pBitmap = + CFX_RetainPtr<CFX_DIBitmap> pBitmap = XFA_LoadImageFromBuffer(pImageFileRead, type, iImageXDpi, iImageYDpi); FX_Free(pImageBuffer); return pBitmap; @@ -1113,7 +1112,7 @@ static FXDIB_Format XFA_GetDIBFormat(FXCODEC_IMAGE_TYPE type, return dibFormat; } -CFX_DIBitmap* XFA_LoadImageFromBuffer( +CFX_RetainPtr<CFX_DIBitmap> XFA_LoadImageFromBuffer( const CFX_RetainPtr<IFX_SeekableReadStream>& pImageFileRead, FXCODEC_IMAGE_TYPE type, int32_t& iImageXDpi, @@ -1127,7 +1126,7 @@ CFX_DIBitmap* XFA_LoadImageFromBuffer( return nullptr; CFX_DIBAttribute dibAttr; - CFX_DIBitmap* pBitmap = nullptr; + CFX_RetainPtr<CFX_DIBitmap> pBitmap; std::unique_ptr<CCodec_ProgressiveDecoder> pProgressiveDecoder = pCodecMgr->CreateProgressiveDecoder(); pProgressiveDecoder->LoadImageInfo(pImageFileRead, type, &dibAttr, false); @@ -1137,8 +1136,8 @@ CFX_DIBitmap* XFA_LoadImageFromBuffer( dibAttr.m_nYDPI = (int32_t)(dibAttr.m_nYDPI * 2.54f); break; case FXCODEC_RESUNIT_METER: - dibAttr.m_nXDPI = (int32_t)(dibAttr.m_nXDPI / (FX_FLOAT)100 * 2.54f); - dibAttr.m_nYDPI = (int32_t)(dibAttr.m_nYDPI / (FX_FLOAT)100 * 2.54f); + dibAttr.m_nXDPI = (int32_t)(dibAttr.m_nXDPI / (float)100 * 2.54f); + dibAttr.m_nYDPI = (int32_t)(dibAttr.m_nYDPI / (float)100 * 2.54f); break; default: break; @@ -1151,7 +1150,7 @@ CFX_DIBitmap* XFA_LoadImageFromBuffer( int32_t iComponents = pProgressiveDecoder->GetNumComponents(); int32_t iBpc = pProgressiveDecoder->GetBPC(); FXDIB_Format dibFormat = XFA_GetDIBFormat(type, iComponents, iBpc); - pBitmap = new CFX_DIBitmap(); + pBitmap = pdfium::MakeRetain<CFX_DIBitmap>(); pBitmap->Create(pProgressiveDecoder->GetWidth(), pProgressiveDecoder->GetHeight(), dibFormat); pBitmap->Clear(0xffffffff); @@ -1171,7 +1170,7 @@ void XFA_RectWidthoutMargin(CFX_RectF& rt, const CXFA_Margin& mg, bool bUI) { if (!mg) { return; } - FX_FLOAT fLeftInset, fTopInset, fRightInset, fBottomInset; + float fLeftInset, fTopInset, fRightInset, fBottomInset; mg.GetLeftInset(fLeftInset); mg.GetTopInset(fTopInset); mg.GetRightInset(fRightInset); @@ -1191,7 +1190,7 @@ static void XFA_BOX_GetPath_Arc(CXFA_Box box, CFX_RectF rtDraw, CFX_Path& fillPath, uint32_t dwFlags) { - FX_FLOAT a, b; + float a, b; a = rtDraw.width / 2.0f; b = rtDraw.height / 2.0f; if (box.IsCircular() || (dwFlags & XFA_DRAWBOX_ForceRound) != 0) { @@ -1202,7 +1201,7 @@ static void XFA_BOX_GetPath_Arc(CXFA_Box box, rtDraw.top = center.y - b; rtDraw.width = a + a; rtDraw.height = b + b; - FX_FLOAT startAngle = 0, sweepAngle = 360; + float startAngle = 0, sweepAngle = 360; bool bStart = box.GetStartAngle(startAngle); bool bEnd = box.GetSweepAngle(sweepAngle); if (!bStart && !bEnd) { @@ -1225,14 +1224,14 @@ static void XFA_BOX_GetPath(CXFA_Box box, int32_t n = (nIndex & 1) ? nIndex - 1 : nIndex; CXFA_Corner corner1(strokes[n].GetNode()); CXFA_Corner corner2(strokes[(n + 2) % 8].GetNode()); - FX_FLOAT fRadius1 = bCorner ? corner1.GetRadius() : 0.0f; - FX_FLOAT fRadius2 = bCorner ? corner2.GetRadius() : 0.0f; + float fRadius1 = bCorner ? corner1.GetRadius() : 0.0f; + float fRadius2 = bCorner ? corner2.GetRadius() : 0.0f; bool bInverted = corner1.IsInverted(); - FX_FLOAT offsetY = 0.0f; - FX_FLOAT offsetX = 0.0f; + float offsetY = 0.0f; + float offsetX = 0.0f; bool bRound = corner1.GetJoinType() == XFA_ATTRIBUTEENUM_Round; - FX_FLOAT halfAfter = 0.0f; - FX_FLOAT halfBefore = 0.0f; + float halfAfter = 0.0f; + float halfBefore = 0.0f; CXFA_Stroke stroke = strokes[nIndex]; if (stroke.IsCorner()) { CXFA_Stroke edgeBefore = strokes[(nIndex + 1 * 8 - 1) % 8]; @@ -1253,14 +1252,14 @@ static void XFA_BOX_GetPath(CXFA_Box box, halfAfter = edgeAfter.GetThickness() / 2; } } - FX_FLOAT offsetEX = 0.0f; - FX_FLOAT offsetEY = 0.0f; - FX_FLOAT sx = 0.0f; - FX_FLOAT sy = 0.0f; - FX_FLOAT vx = 1.0f; - FX_FLOAT vy = 1.0f; - FX_FLOAT nx = 1.0f; - FX_FLOAT ny = 1.0f; + float offsetEX = 0.0f; + float offsetEY = 0.0f; + float sx = 0.0f; + float sy = 0.0f; + float vx = 1.0f; + float vy = 1.0f; + float nx = 1.0f; + float ny = 1.0f; CFX_PointF cpStart; CFX_PointF cp1; CFX_PointF cp2; @@ -1390,11 +1389,11 @@ static void XFA_BOX_GetFillPath(CXFA_Box box, uint16_t dwFlags) { if (box.IsArc() || (dwFlags & XFA_DRAWBOX_ForceRound) != 0) { CXFA_Edge edge = box.GetEdge(0); - FX_FLOAT fThickness = edge.GetThickness(); + float fThickness = edge.GetThickness(); if (fThickness < 0) { fThickness = 0; } - FX_FLOAT fHalf = fThickness / 2; + float fHalf = fThickness / 2; int32_t iHand = box.GetHand(); if (iHand == XFA_ATTRIBUTEENUM_Left) { rtWidget.Inflate(fHalf, fHalf); @@ -1442,17 +1441,17 @@ static void XFA_BOX_GetFillPath(CXFA_Box box, } for (int32_t i = 0; i < 8; i += 2) { - FX_FLOAT sx = 0.0f; - FX_FLOAT sy = 0.0f; - FX_FLOAT vx = 1.0f; - FX_FLOAT vy = 1.0f; - FX_FLOAT nx = 1.0f; - FX_FLOAT ny = 1.0f; + float sx = 0.0f; + float sy = 0.0f; + float vx = 1.0f; + float vy = 1.0f; + float nx = 1.0f; + float ny = 1.0f; CFX_PointF cp1, cp2; CXFA_Corner corner1(strokes[i].GetNode()); CXFA_Corner corner2(strokes[(i + 2) % 8].GetNode()); - FX_FLOAT fRadius1 = corner1.GetRadius(); - FX_FLOAT fRadius2 = corner2.GetRadius(); + float fRadius1 = corner1.GetRadius(); + float fRadius2 = corner2.GetRadius(); bool bInverted = corner1.IsInverted(); bool bRound = corner1.GetJoinType() == XFA_ATTRIBUTEENUM_Round; if (bRound) { @@ -1549,8 +1548,8 @@ static void XFA_BOX_Fill_Radial(CXFA_Box box, crStart = temp; } CFX_Shading shading(rtFill.Center(), rtFill.Center(), 0, - FXSYS_sqrt(rtFill.Width() * rtFill.Width() + - rtFill.Height() * rtFill.Height()) / + sqrt(rtFill.Width() * rtFill.Width() + + rtFill.Height() * rtFill.Height()) / 2, true, true, crStart, crEnd); CFX_Color cr(&shading); @@ -1682,7 +1681,7 @@ static void XFA_BOX_StrokePath(CXFA_Stroke stroke, if (!stroke || !stroke.IsVisible()) { return; } - FX_FLOAT fThickness = stroke.GetThickness(); + float fThickness = stroke.GetThickness(); if (fThickness < 0.001f) { return; } @@ -1709,14 +1708,14 @@ static void XFA_BOX_StrokeArc(CXFA_Box box, return; } bool bVisible = false; - FX_FLOAT fThickness = 0; + float fThickness = 0; int32_t i3DType = box.Get3DStyle(bVisible, fThickness); if (i3DType) { if (bVisible && fThickness >= 0.001f) { dwFlags |= XFA_DRAWBOX_Lowered3D; } } - FX_FLOAT fHalf = edge.GetThickness() / 2; + float fHalf = edge.GetThickness() / 2; if (fHalf < 0) { fHalf = 0; } @@ -1739,7 +1738,7 @@ static void XFA_BOX_StrokeArc(CXFA_Box box, pGS->SaveGraphState(); pGS->SetLineWidth(fHalf); - FX_FLOAT a, b; + float a, b; a = rtWidget.width / 2.0f; b = rtWidget.height / 2.0f; if (dwFlags & XFA_DRAWBOX_ForceRound) { @@ -1753,7 +1752,7 @@ static void XFA_BOX_StrokeArc(CXFA_Box box, rtWidget.width = a + a; rtWidget.height = b + b; - FX_FLOAT startAngle = 0, sweepAngle = 360; + float startAngle = 0, sweepAngle = 360; startAngle = startAngle * FX_PI / 180.0f; sweepAngle = -sweepAngle * FX_PI / 180.0f; @@ -1790,14 +1789,14 @@ static void XFA_BOX_StrokeArc(CXFA_Box box, } static void XFA_Draw3DRect(CFX_Graphics* pGraphic, const CFX_RectF& rt, - FX_FLOAT fLineWidth, + float fLineWidth, CFX_Matrix* pMatrix, FX_ARGB argbTopLeft, FX_ARGB argbBottomRight) { CFX_Color crLT(argbTopLeft); pGraphic->SetFillColor(&crLT); - FX_FLOAT fBottom = rt.bottom(); - FX_FLOAT fRight = rt.right(); + float fBottom = rt.bottom(); + float fRight = rt.right(); CFX_Path pathLT; pathLT.MoveTo(CFX_PointF(rt.left, fBottom)); pathLT.LineTo(CFX_PointF(rt.left, rt.top)); @@ -1823,9 +1822,9 @@ static void XFA_Draw3DRect(CFX_Graphics* pGraphic, } static void XFA_BOX_Stroke_3DRect_Lowered(CFX_Graphics* pGS, CFX_RectF rt, - FX_FLOAT fThickness, + float fThickness, CFX_Matrix* pMatrix) { - FX_FLOAT fHalfWidth = fThickness / 2.0f; + float fHalfWidth = fThickness / 2.0f; CFX_RectF rtInner(rt); rtInner.Deflate(fHalfWidth, fHalfWidth); CFX_Color cr(0xFF000000); @@ -1838,9 +1837,9 @@ static void XFA_BOX_Stroke_3DRect_Lowered(CFX_Graphics* pGS, } static void XFA_BOX_Stroke_3DRect_Raised(CFX_Graphics* pGS, CFX_RectF rt, - FX_FLOAT fThickness, + float fThickness, CFX_Matrix* pMatrix) { - FX_FLOAT fHalfWidth = fThickness / 2.0f; + float fHalfWidth = fThickness / 2.0f; CFX_RectF rtInner(rt); rtInner.Deflate(fHalfWidth, fHalfWidth); CFX_Color cr(0xFF000000); @@ -1853,9 +1852,9 @@ static void XFA_BOX_Stroke_3DRect_Raised(CFX_Graphics* pGS, } static void XFA_BOX_Stroke_3DRect_Etched(CFX_Graphics* pGS, CFX_RectF rt, - FX_FLOAT fThickness, + float fThickness, CFX_Matrix* pMatrix) { - FX_FLOAT fHalfWidth = fThickness / 2.0f; + float fHalfWidth = fThickness / 2.0f; XFA_Draw3DRect(pGS, rt, fThickness, pMatrix, 0xFF808080, 0xFFFFFFFF); CFX_RectF rtInner(rt); rtInner.Deflate(fHalfWidth, fHalfWidth); @@ -1863,9 +1862,9 @@ static void XFA_BOX_Stroke_3DRect_Etched(CFX_Graphics* pGS, } static void XFA_BOX_Stroke_3DRect_Embossed(CFX_Graphics* pGS, CFX_RectF rt, - FX_FLOAT fThickness, + float fThickness, CFX_Matrix* pMatrix) { - FX_FLOAT fHalfWidth = fThickness / 2.0f; + float fHalfWidth = fThickness / 2.0f; XFA_Draw3DRect(pGS, rt, fThickness, pMatrix, 0xFF808080, 0xFF000000); CFX_RectF rtInner(rt); rtInner.Deflate(fHalfWidth, fHalfWidth); @@ -1877,7 +1876,7 @@ static void XFA_BOX_Stroke_Rect(CXFA_Box box, CFX_RectF rtWidget, CFX_Matrix* pMatrix) { bool bVisible = false; - FX_FLOAT fThickness = 0; + float fThickness = 0; int32_t i3DType = box.Get3DStyle(bVisible, fThickness); if (i3DType) { if (!bVisible || fThickness < 0.001f) { @@ -1981,11 +1980,11 @@ static void XFA_BOX_Stroke(CXFA_Box box, } for (int32_t i = 1; i < 8; i += 2) { CXFA_Edge edge(strokes[i].GetNode()); - FX_FLOAT fThickness = edge.GetThickness(); + float fThickness = edge.GetThickness(); if (fThickness < 0) { fThickness = 0; } - FX_FLOAT fHalf = fThickness / 2; + float fHalf = fThickness / 2; int32_t iHand = box.GetHand(); switch (i) { case 1: diff --git a/chromium/third_party/pdfium/xfa/fxfa/xfa_ffwidget.h b/chromium/third_party/pdfium/xfa/fxfa/cxfa_ffwidget.h index 5972b8ad70e..35a36002c72 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/xfa_ffwidget.h +++ b/chromium/third_party/pdfium/xfa/fxfa/cxfa_ffwidget.h @@ -4,8 +4,8 @@ // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com -#ifndef XFA_FXFA_XFA_FFWIDGET_H_ -#define XFA_FXFA_XFA_FFWIDGET_H_ +#ifndef XFA_FXFA_CXFA_FFWIDGET_H_ +#define XFA_FXFA_CXFA_FFWIDGET_H_ #include <vector> @@ -21,11 +21,12 @@ class CXFA_FFDoc; class CXFA_FFApp; enum class FWL_WidgetHit; -inline FX_FLOAT XFA_UnitPx2Pt(FX_FLOAT fPx, FX_FLOAT fDpi) { +inline float XFA_UnitPx2Pt(float fPx, float fDpi) { return fPx * 72.0f / fDpi; } #define XFA_FLOAT_PERCISION 0.001f +#define XFA_CalcData (void*)(uintptr_t) FXBSTR_ID('X', 'F', 'A', 'C') enum XFA_WIDGETITEM { XFA_WIDGETITEM_Parent, @@ -34,6 +35,47 @@ enum XFA_WIDGETITEM { XFA_WIDGETITEM_PrevSibling, }; +int32_t XFA_StrokeTypeSetLineDash(CFX_Graphics* pGraphics, + int32_t iStrokeType, + int32_t iCapType); +CFX_GraphStateData::LineCap XFA_LineCapToFXGE(int32_t iLineCap); +void XFA_DrawImage(CFX_Graphics* pGS, + const CFX_RectF& rtImage, + CFX_Matrix* pMatrix, + const CFX_RetainPtr<CFX_DIBitmap>& pDIBitmap, + int32_t iAspect, + int32_t iImageXDpi, + int32_t iImageYDpi, + int32_t iHorzAlign = XFA_ATTRIBUTEENUM_Left, + int32_t iVertAlign = XFA_ATTRIBUTEENUM_Top); + +CFX_RetainPtr<CFX_DIBitmap> XFA_LoadImageData(CXFA_FFDoc* pDoc, + CXFA_Image* pImage, + bool& bNameImage, + int32_t& iImageXDpi, + int32_t& iImageYDpi); + +CFX_RetainPtr<CFX_DIBitmap> XFA_LoadImageFromBuffer( + const CFX_RetainPtr<IFX_SeekableReadStream>& pImageFileRead, + FXCODEC_IMAGE_TYPE type, + int32_t& iImageXDpi, + int32_t& iImageYDpi); + +FXCODEC_IMAGE_TYPE XFA_GetImageType(const CFX_WideString& wsType); +char* XFA_Base64Encode(const uint8_t* buf, int32_t buf_len); +void XFA_RectWidthoutMargin(CFX_RectF& rt, + const CXFA_Margin& mg, + bool bUI = false); +CXFA_FFWidget* XFA_GetWidgetFromLayoutItem(CXFA_LayoutItem* pLayoutItem); +bool XFA_IsCreateWidget(XFA_Element iType); +#define XFA_DRAWBOX_ForceRound 1 +#define XFA_DRAWBOX_Lowered3D 2 +void XFA_DrawBox(CXFA_Box box, + CFX_Graphics* pGS, + const CFX_RectF& rtWidget, + CFX_Matrix* pMatrix, + uint32_t dwFlags = 0); + class CXFA_CalcData { public: CXFA_CalcData(); @@ -101,8 +143,8 @@ class CXFA_FFWidget : public CXFA_ContentLayoutItem { CXFA_FFPageView* GetPageView() const { return m_pPageView; } void SetPageView(CXFA_FFPageView* pPageView) { m_pPageView = pPageView; } - CFX_RectF GetWidgetRect(); - CFX_RectF RecacheWidgetRect(); + const CFX_RectF& GetWidgetRect() const; + const CFX_RectF& RecacheWidgetRect() const; uint32_t GetStatus(); void ModifyStatus(uint32_t dwAdded, uint32_t dwRemoved); @@ -142,49 +184,8 @@ class CXFA_FFWidget : public CXFA_ContentLayoutItem { CXFA_FFDocView* m_pDocView; CXFA_FFPageView* m_pPageView; - CXFA_WidgetAcc* m_pDataAcc; - CFX_RectF m_rtWidget; + CXFA_WidgetAcc* const m_pDataAcc; + mutable CFX_RectF m_rtWidget; }; -int32_t XFA_StrokeTypeSetLineDash(CFX_Graphics* pGraphics, - int32_t iStrokeType, - int32_t iCapType); -CFX_GraphStateData::LineCap XFA_LineCapToFXGE(int32_t iLineCap); -void XFA_DrawImage(CFX_Graphics* pGS, - const CFX_RectF& rtImage, - CFX_Matrix* pMatrix, - CFX_DIBitmap* pDIBitmap, - int32_t iAspect, - int32_t iImageXDpi, - int32_t iImageYDpi, - int32_t iHorzAlign = XFA_ATTRIBUTEENUM_Left, - int32_t iVertAlign = XFA_ATTRIBUTEENUM_Top); - -CFX_DIBitmap* XFA_LoadImageData(CXFA_FFDoc* pDoc, - CXFA_Image* pImage, - bool& bNameImage, - int32_t& iImageXDpi, - int32_t& iImageYDpi); - -CFX_DIBitmap* XFA_LoadImageFromBuffer( - const CFX_RetainPtr<IFX_SeekableReadStream>& pImageFileRead, - FXCODEC_IMAGE_TYPE type, - int32_t& iImageXDpi, - int32_t& iImageYDpi); - -FXCODEC_IMAGE_TYPE XFA_GetImageType(const CFX_WideString& wsType); -FX_CHAR* XFA_Base64Encode(const uint8_t* buf, int32_t buf_len); -void XFA_RectWidthoutMargin(CFX_RectF& rt, - const CXFA_Margin& mg, - bool bUI = false); -CXFA_FFWidget* XFA_GetWidgetFromLayoutItem(CXFA_LayoutItem* pLayoutItem); -bool XFA_IsCreateWidget(XFA_Element iType); -#define XFA_DRAWBOX_ForceRound 1 -#define XFA_DRAWBOX_Lowered3D 2 -void XFA_DrawBox(CXFA_Box box, - CFX_Graphics* pGS, - const CFX_RectF& rtWidget, - CFX_Matrix* pMatrix, - uint32_t dwFlags = 0); - -#endif // XFA_FXFA_XFA_FFWIDGET_H_ +#endif // XFA_FXFA_CXFA_FFWIDGET_H_ diff --git a/chromium/third_party/pdfium/xfa/fxfa/app/xfa_ffwidgethandler.cpp b/chromium/third_party/pdfium/xfa/fxfa/cxfa_ffwidgethandler.cpp index 2fddfb61569..ffc1c27070b 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/app/xfa_ffwidgethandler.cpp +++ b/chromium/third_party/pdfium/xfa/fxfa/cxfa_ffwidgethandler.cpp @@ -4,18 +4,19 @@ // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com -#include "xfa/fxfa/xfa_ffwidgethandler.h" +#include "xfa/fxfa/cxfa_ffwidgethandler.h" #include <vector> #include "xfa/fxfa/app/xfa_ffchoicelist.h" #include "xfa/fxfa/app/xfa_fffield.h" #include "xfa/fxfa/app/xfa_fwladapter.h" +#include "xfa/fxfa/cxfa_ffdoc.h" +#include "xfa/fxfa/cxfa_ffdocview.h" +#include "xfa/fxfa/cxfa_ffwidget.h" #include "xfa/fxfa/parser/cxfa_layoutprocessor.h" #include "xfa/fxfa/parser/cxfa_measurement.h" -#include "xfa/fxfa/xfa_ffdoc.h" -#include "xfa/fxfa/xfa_ffdocview.h" -#include "xfa/fxfa/xfa_ffwidget.h" +#include "xfa/fxfa/parser/cxfa_node.h" CXFA_FFWidgetHandler::CXFA_FFWidgetHandler(CXFA_FFDocView* pDocView) : m_pDocView(pDocView) {} @@ -164,34 +165,25 @@ void CXFA_FFWidgetHandler::RenderWidget(CXFA_FFWidget* hWidget, bool CXFA_FFWidgetHandler::HasEvent(CXFA_WidgetAcc* pWidgetAcc, XFA_EVENTTYPE eEventType) { - if (!pWidgetAcc || eEventType == XFA_EVENT_Unknown) + if (eEventType == XFA_EVENT_Unknown) return false; - if (pWidgetAcc->GetElementType() == XFA_Element::Draw) + + if (!pWidgetAcc || pWidgetAcc->GetElementType() == XFA_Element::Draw) return false; switch (eEventType) { case XFA_EVENT_Calculate: { CXFA_Calculate calc = pWidgetAcc->GetCalculate(); - if (!calc) - return false; - if (calc.GetScript()) - return true; - return false; + return calc && calc.GetScript(); } case XFA_EVENT_Validate: { CXFA_Validate val = pWidgetAcc->GetValidate(); - if (!val) - return false; - if (val.GetScript()) - return true; - return false; + return val && val.GetScript(); } default: break; } - CXFA_NodeArray eventArray; - return pWidgetAcc->GetEventByActivity(gs_EventActivity[eEventType], - eventArray) > 0; + return !pWidgetAcc->GetEventByActivity(gs_EventActivity[eEventType]).empty(); } int32_t CXFA_FFWidgetHandler::ProcessEvent(CXFA_WidgetAcc* pWidgetAcc, @@ -499,7 +491,7 @@ CXFA_Node* CXFA_FFWidgetHandler::CreateFontNode(CXFA_Node* pParent) const { CXFA_Node* CXFA_FFWidgetHandler::CreateMarginNode(CXFA_Node* pParent, uint32_t dwFlags, - FX_FLOAT fInsets[4]) const { + float fInsets[4]) const { CXFA_Node* pMargin = CreateCopyNode(XFA_Element::Margin, pParent); if (dwFlags & 0x01) pMargin->SetMeasure(XFA_ATTRIBUTE_LeftInset, @@ -530,4 +522,3 @@ CXFA_Document* CXFA_FFWidgetHandler::GetObjFactory() const { CXFA_Document* CXFA_FFWidgetHandler::GetXFADoc() const { return m_pDocView->GetDoc()->GetXFADoc(); } - diff --git a/chromium/third_party/pdfium/xfa/fxfa/xfa_ffwidgethandler.h b/chromium/third_party/pdfium/xfa/fxfa/cxfa_ffwidgethandler.h index 66bda3e02a5..8f44dbbd454 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/xfa_ffwidgethandler.h +++ b/chromium/third_party/pdfium/xfa/fxfa/cxfa_ffwidgethandler.h @@ -4,8 +4,8 @@ // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com -#ifndef XFA_FXFA_XFA_FFWIDGETHANDLER_H_ -#define XFA_FXFA_XFA_FFWIDGETHANDLER_H_ +#ifndef XFA_FXFA_CXFA_FFWIDGETHANDLER_H_ +#define XFA_FXFA_CXFA_FFWIDGETHANDLER_H_ #include <vector> @@ -65,7 +65,7 @@ class CXFA_FFWidgetHandler { bool HasEvent(CXFA_WidgetAcc* pWidgetAcc, XFA_EVENTTYPE eEventType); int32_t ProcessEvent(CXFA_WidgetAcc* pWidgetAcc, CXFA_EventParam* pParam); - protected: + private: CXFA_Node* CreateWidgetFormItem(XFA_WIDGETTYPE eType, CXFA_Node* pParent, CXFA_Node* pBefore) const; @@ -108,7 +108,7 @@ class CXFA_FFWidgetHandler { CXFA_Node* CreateFontNode(CXFA_Node* pParent) const; CXFA_Node* CreateMarginNode(CXFA_Node* pParent, uint32_t dwFlags, - FX_FLOAT fInsets[4]) const; + float fInsets[4]) const; CXFA_Node* CreateValueNode(XFA_Element eValue, CXFA_Node* pParent) const; CXFA_Document* GetObjFactory() const; CXFA_Document* GetXFADoc() const; @@ -116,4 +116,4 @@ class CXFA_FFWidgetHandler { CXFA_FFDocView* m_pDocView; }; -#endif // XFA_FXFA_XFA_FFWIDGETHANDLER_H_ +#endif // XFA_FXFA_CXFA_FFWIDGETHANDLER_H_ diff --git a/chromium/third_party/pdfium/xfa/fxfa/cxfa_fileread.cpp b/chromium/third_party/pdfium/xfa/fxfa/cxfa_fileread.cpp new file mode 100644 index 00000000000..e2ecad2e93f --- /dev/null +++ b/chromium/third_party/pdfium/xfa/fxfa/cxfa_fileread.cpp @@ -0,0 +1,56 @@ +// Copyright 2017 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#include "xfa/fxfa/cxfa_fileread.h" + +#include <algorithm> + +#include "core/fpdfapi/parser/cpdf_stream_acc.h" +#include "third_party/base/stl_util.h" + +CXFA_FileRead::CXFA_FileRead(const std::vector<CPDF_Stream*>& streams) { + for (CPDF_Stream* pStream : streams) { + m_Data.push_back(pdfium::MakeRetain<CPDF_StreamAcc>(pStream)); + m_Data.back()->LoadAllData(); + } +} + +CXFA_FileRead::~CXFA_FileRead() {} + +FX_FILESIZE CXFA_FileRead::GetSize() { + uint32_t dwSize = 0; + for (const auto& acc : m_Data) + dwSize += acc->GetSize(); + return dwSize; +} + +bool CXFA_FileRead::ReadBlock(void* buffer, FX_FILESIZE offset, size_t size) { + int32_t iCount = pdfium::CollectionSize<int32_t>(m_Data); + int32_t index = 0; + while (index < iCount) { + const auto& acc = m_Data[index]; + FX_FILESIZE dwSize = acc->GetSize(); + if (offset < dwSize) + break; + + offset -= dwSize; + index++; + } + while (index < iCount) { + const auto& acc = m_Data[index]; + uint32_t dwSize = acc->GetSize(); + size_t dwRead = std::min(size, static_cast<size_t>(dwSize - offset)); + memcpy(buffer, acc->GetData() + offset, dwRead); + size -= dwRead; + if (size == 0) + return true; + + buffer = static_cast<uint8_t*>(buffer) + dwRead; + offset = 0; + index++; + } + return false; +} diff --git a/chromium/third_party/pdfium/xfa/fxfa/cxfa_fileread.h b/chromium/third_party/pdfium/xfa/fxfa/cxfa_fileread.h new file mode 100644 index 00000000000..0c3348b8d5d --- /dev/null +++ b/chromium/third_party/pdfium/xfa/fxfa/cxfa_fileread.h @@ -0,0 +1,31 @@ +// Copyright 2017 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#ifndef XFA_FXFA_CXFA_FILEREAD_H_ +#define XFA_FXFA_CXFA_FILEREAD_H_ + +#include <vector> + +#include "core/fxcrt/cfx_retain_ptr.h" +#include "core/fxcrt/fx_stream.h" + +class CPDF_Stream; +class CPDF_StreamAcc; + +class CXFA_FileRead : public IFX_SeekableReadStream { + public: + explicit CXFA_FileRead(const std::vector<CPDF_Stream*>& streams); + ~CXFA_FileRead() override; + + // IFX_SeekableReadStream + FX_FILESIZE GetSize() override; + bool ReadBlock(void* buffer, FX_FILESIZE offset, size_t size) override; + + private: + std::vector<CFX_RetainPtr<CPDF_StreamAcc>> m_Data; +}; + +#endif // XFA_FXFA_CXFA_FILEREAD_H_ diff --git a/chromium/third_party/pdfium/xfa/fxfa/app/xfa_fontmgr.cpp b/chromium/third_party/pdfium/xfa/fxfa/cxfa_fontmgr.cpp index 5db389663a6..81e296f8a4c 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/app/xfa_fontmgr.cpp +++ b/chromium/third_party/pdfium/xfa/fxfa/cxfa_fontmgr.cpp @@ -4,7 +4,7 @@ // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com -#include "xfa/fxfa/xfa_fontmgr.h" +#include "xfa/fxfa/cxfa_fontmgr.h" #include <algorithm> #include <memory> @@ -15,18 +15,11 @@ #include "core/fpdfapi/parser/cpdf_document.h" #include "third_party/base/ptr_util.h" #include "xfa/fgas/font/cfgas_gefont.h" -#include "xfa/fxfa/xfa_ffapp.h" -#include "xfa/fxfa/xfa_ffdoc.h" +#include "xfa/fxfa/cxfa_ffapp.h" +#include "xfa/fxfa/cxfa_ffdoc.h" namespace { -// The 5 names per entry are: PsName, Normal, Bold, Italic, BoldItalic. -const char* const g_XFAPDFFontName[][5] = { - {"Adobe PI Std", "AdobePIStd", "AdobePIStd", "AdobePIStd", "AdobePIStd"}, - {"Myriad Pro Light", "MyriadPro-Light", "MyriadPro-Semibold", - "MyriadPro-LightIt", "MyriadPro-SemiboldIt"}, -}; - #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ const XFA_FONTINFO g_XFAFontsMap[] = { {0x01d5d33e, L"SimSun", L"Arial", 0, 936}, @@ -1705,6 +1698,8 @@ const XFA_FONTINFO g_XFAFontsMap[] = { }; #endif +} // namespace + CFX_WideString XFA_LocalFontNameToEnglishName( const CFX_WideStringC& wsLocalName) { uint32_t dwLocalNameHash = FX_HashCode_GetW(wsLocalName, true); @@ -1736,259 +1731,6 @@ const XFA_FONTINFO* XFA_GetFontINFOByFontName( return nullptr; } -} // namespace - -CXFA_DefFontMgr::CXFA_DefFontMgr() {} - -CXFA_DefFontMgr::~CXFA_DefFontMgr() {} - -CFX_RetainPtr<CFGAS_GEFont> CXFA_DefFontMgr::GetFont( - CXFA_FFDoc* hDoc, - const CFX_WideStringC& wsFontFamily, - uint32_t dwFontStyles, - uint16_t wCodePage) { - CFX_WideString wsFontName(wsFontFamily); - CFGAS_FontMgr* pFDEFontMgr = hDoc->GetApp()->GetFDEFontMgr(); - CFX_RetainPtr<CFGAS_GEFont> pFont = - pFDEFontMgr->LoadFont(wsFontName.c_str(), dwFontStyles, wCodePage); - if (!pFont) { - const XFA_FONTINFO* pCurFont = - XFA_GetFontINFOByFontName(wsFontName.AsStringC()); - if (pCurFont && pCurFont->pReplaceFont) { - uint32_t dwStyle = 0; - if (dwFontStyles & FX_FONTSTYLE_Bold) { - dwStyle |= FX_FONTSTYLE_Bold; - } - if (dwFontStyles & FX_FONTSTYLE_Italic) { - dwStyle |= FX_FONTSTYLE_Italic; - } - const FX_WCHAR* pReplace = pCurFont->pReplaceFont; - int32_t iLength = FXSYS_wcslen(pReplace); - while (iLength > 0) { - const FX_WCHAR* pNameText = pReplace; - while (*pNameText != L',' && iLength > 0) { - pNameText++; - iLength--; - } - CFX_WideString wsReplace = - CFX_WideString(pReplace, pNameText - pReplace); - pFont = pFDEFontMgr->LoadFont(wsReplace.c_str(), dwStyle, wCodePage); - if (pFont) - break; - - iLength--; - pNameText++; - pReplace = pNameText; - } - } - } - if (pFont) - m_CacheFonts.push_back(pFont); - return pFont; -} - -CFX_RetainPtr<CFGAS_GEFont> CXFA_DefFontMgr::GetDefaultFont( - CXFA_FFDoc* hDoc, - const CFX_WideStringC& wsFontFamily, - uint32_t dwFontStyles, - uint16_t wCodePage) { - CFGAS_FontMgr* pFDEFontMgr = hDoc->GetApp()->GetFDEFontMgr(); - CFX_RetainPtr<CFGAS_GEFont> pFont = - pFDEFontMgr->LoadFont(L"Arial Narrow", dwFontStyles, wCodePage); - if (!pFont) { - pFont = pFDEFontMgr->LoadFont(static_cast<const FX_WCHAR*>(nullptr), - dwFontStyles, wCodePage); - } - if (pFont) - m_CacheFonts.push_back(pFont); - return pFont; -} - -CXFA_PDFFontMgr::CXFA_PDFFontMgr(CXFA_FFDoc* pDoc) : m_pDoc(pDoc) {} - -CXFA_PDFFontMgr::~CXFA_PDFFontMgr() {} - -CFX_RetainPtr<CFGAS_GEFont> CXFA_PDFFontMgr::FindFont( - const CFX_ByteString& strPsName, - bool bBold, - bool bItalic, - CPDF_Font** pDstPDFFont, - bool bStrictMatch) { - CPDF_Document* pDoc = m_pDoc->GetPDFDoc(); - if (!pDoc) - return nullptr; - - CPDF_Dictionary* pFontSetDict = - pDoc->GetRoot()->GetDictFor("AcroForm")->GetDictFor("DR"); - if (!pFontSetDict) - return nullptr; - - pFontSetDict = pFontSetDict->GetDictFor("Font"); - if (!pFontSetDict) - return nullptr; - - CFX_ByteString name = strPsName; - name.Remove(' '); - CFGAS_FontMgr* pFDEFontMgr = m_pDoc->GetApp()->GetFDEFontMgr(); - for (const auto& it : *pFontSetDict) { - const CFX_ByteString& key = it.first; - CPDF_Object* pObj = it.second.get(); - if (!PsNameMatchDRFontName(name.AsStringC(), bBold, bItalic, key, - bStrictMatch)) { - continue; - } - CPDF_Dictionary* pFontDict = ToDictionary(pObj->GetDirect()); - if (!pFontDict || pFontDict->GetStringFor("Type") != "Font") { - return nullptr; - } - CPDF_Font* pPDFFont = pDoc->LoadFont(pFontDict); - if (!pPDFFont) { - return nullptr; - } - if (!pPDFFont->IsEmbedded()) { - *pDstPDFFont = pPDFFont; - return nullptr; - } - return CFGAS_GEFont::LoadFont(&pPDFFont->m_Font, pFDEFontMgr); - } - return nullptr; -} - -CFX_RetainPtr<CFGAS_GEFont> CXFA_PDFFontMgr::GetFont( - const CFX_WideStringC& wsFontFamily, - uint32_t dwFontStyles, - CPDF_Font** pPDFFont, - bool bStrictMatch) { - uint32_t dwHashCode = FX_HashCode_GetW(wsFontFamily, false); - CFX_ByteString strKey; - strKey.Format("%u%u", dwHashCode, dwFontStyles); - auto it = m_FontMap.find(strKey); - if (it != m_FontMap.end()) - return it->second; - CFX_ByteString bsPsName = - CFX_ByteString::FromUnicode(CFX_WideString(wsFontFamily)); - bool bBold = (dwFontStyles & FX_FONTSTYLE_Bold) == FX_FONTSTYLE_Bold; - bool bItalic = (dwFontStyles & FX_FONTSTYLE_Italic) == FX_FONTSTYLE_Italic; - CFX_ByteString strFontName = PsNameToFontName(bsPsName, bBold, bItalic); - CFX_RetainPtr<CFGAS_GEFont> pFont = - FindFont(strFontName, bBold, bItalic, pPDFFont, bStrictMatch); - if (pFont) - m_FontMap[strKey] = pFont; - return pFont; -} - -CFX_ByteString CXFA_PDFFontMgr::PsNameToFontName( - const CFX_ByteString& strPsName, - bool bBold, - bool bItalic) { - for (size_t i = 0; i < FX_ArraySize(g_XFAPDFFontName); ++i) { - if (strPsName == g_XFAPDFFontName[i][0]) { - size_t index = 1; - if (bBold) - ++index; - if (bItalic) - index += 2; - return g_XFAPDFFontName[i][index]; - } - } - return strPsName; -} - -bool CXFA_PDFFontMgr::PsNameMatchDRFontName(const CFX_ByteStringC& bsPsName, - bool bBold, - bool bItalic, - const CFX_ByteString& bsDRFontName, - bool bStrictMatch) { - CFX_ByteString bsDRName = bsDRFontName; - bsDRName.Remove('-'); - int32_t iPsLen = bsPsName.GetLength(); - int32_t nIndex = bsDRName.Find(bsPsName); - if (nIndex != -1 && !bStrictMatch) - return true; - - if (nIndex != 0) - return false; - - int32_t iDifferLength = bsDRName.GetLength() - iPsLen; - if (iDifferLength > 1 || (bBold || bItalic)) { - int32_t iBoldIndex = bsDRName.Find("Bold"); - bool bBoldFont = iBoldIndex > 0; - if (bBold != bBoldFont) - return false; - - if (bBoldFont) { - iDifferLength = - std::min(iDifferLength - 4, bsDRName.GetLength() - iBoldIndex - 4); - } - bool bItalicFont = true; - if (bsDRName.Find("Italic") > 0) { - iDifferLength -= 6; - } else if (bsDRName.Find("It") > 0) { - iDifferLength -= 2; - } else if (bsDRName.Find("Oblique") > 0) { - iDifferLength -= 7; - } else { - bItalicFont = false; - } - if (bItalic != bItalicFont) - return false; - - if (iDifferLength > 1) { - CFX_ByteString bsDRTailer = bsDRName.Right(iDifferLength); - if (bsDRTailer == "MT" || bsDRTailer == "PSMT" || - bsDRTailer == "Regular" || bsDRTailer == "Reg") { - return true; - } - if (bBoldFont || bItalicFont) - return false; - - bool bMatch = false; - switch (bsPsName.GetAt(iPsLen - 1)) { - case 'L': { - if (bsDRName.Right(5) == "Light") { - bMatch = true; - } - } break; - case 'R': { - if (bsDRName.Right(7) == "Regular" || bsDRName.Right(3) == "Reg") { - bMatch = true; - } - } break; - case 'M': { - if (bsDRName.Right(5) == "Medium") { - bMatch = true; - } - } break; - default: - break; - } - return bMatch; - } - } - return true; -} - -bool CXFA_PDFFontMgr::GetCharWidth(const CFX_RetainPtr<CFGAS_GEFont>& pFont, - FX_WCHAR wUnicode, - bool bCharCode, - int32_t* pWidth) { - if (wUnicode != 0x20 || bCharCode) - return false; - - auto it = m_FDE2PDFFont.find(pFont); - if (it == m_FDE2PDFFont.end()) - return false; - - CPDF_Font* pPDFFont = it->second; - *pWidth = pPDFFont->GetCharWidthF(pPDFFont->CharCodeFromUnicode(wUnicode)); - return true; -} - -void CXFA_PDFFontMgr::SetFont(const CFX_RetainPtr<CFGAS_GEFont>& pFont, - CPDF_Font* pPDFFont) { - m_FDE2PDFFont[pFont] = pPDFFont; -} - CXFA_FontMgr::CXFA_FontMgr() {} CXFA_FontMgr::~CXFA_FontMgr() {} diff --git a/chromium/third_party/pdfium/xfa/fxfa/cxfa_fontmgr.h b/chromium/third_party/pdfium/xfa/fxfa/cxfa_fontmgr.h new file mode 100644 index 00000000000..8652a344223 --- /dev/null +++ b/chromium/third_party/pdfium/xfa/fxfa/cxfa_fontmgr.h @@ -0,0 +1,56 @@ +// Copyright 2014 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#ifndef XFA_FXFA_CXFA_FONTMGR_H_ +#define XFA_FXFA_CXFA_FONTMGR_H_ + +#include <map> +#include <memory> +#include <vector> + +#include "core/fxcrt/cfx_retain_ptr.h" +#include "core/fxcrt/fx_ext.h" +#include "core/fxcrt/fx_system.h" +#include "xfa/fgas/font/cfgas_fontmgr.h" +#include "xfa/fxfa/cxfa_deffontmgr.h" +#include "xfa/fxfa/cxfa_pdffontmgr.h" +#include "xfa/fxfa/fxfa.h" + +class CPDF_Font; + +struct XFA_FONTINFO { + uint32_t dwFontNameHash; + const wchar_t* pPsName; + const wchar_t* pReplaceFont; + uint16_t dwStyles; + uint16_t wCodePage; +}; + +CFX_WideString XFA_LocalFontNameToEnglishName( + const CFX_WideStringC& wsLocalName); +const XFA_FONTINFO* XFA_GetFontINFOByFontName( + const CFX_WideStringC& wsFontName); + +class CXFA_FontMgr { + public: + CXFA_FontMgr(); + ~CXFA_FontMgr(); + + CFX_RetainPtr<CFGAS_GEFont> GetFont(CXFA_FFDoc* hDoc, + const CFX_WideStringC& wsFontFamily, + uint32_t dwFontStyles, + uint16_t wCodePage = 0xFFFF); + void LoadDocFonts(CXFA_FFDoc* hDoc); + void ReleaseDocFonts(CXFA_FFDoc* hDoc); + void SetDefFontMgr(std::unique_ptr<CXFA_DefFontMgr> pFontMgr); + + private: + std::unique_ptr<CXFA_DefFontMgr> m_pDefFontMgr; + std::map<CXFA_FFDoc*, std::unique_ptr<CXFA_PDFFontMgr>> m_PDFFontMgrMap; + std::map<CFX_ByteString, CFX_RetainPtr<CFGAS_GEFont>> m_FontMap; +}; + +#endif // XFA_FXFA_CXFA_FONTMGR_H_ diff --git a/chromium/third_party/pdfium/xfa/fxfa/cxfa_pdffontmgr.cpp b/chromium/third_party/pdfium/xfa/fxfa/cxfa_pdffontmgr.cpp new file mode 100644 index 00000000000..cadb7cbab55 --- /dev/null +++ b/chromium/third_party/pdfium/xfa/fxfa/cxfa_pdffontmgr.cpp @@ -0,0 +1,208 @@ +// Copyright 2017 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#include "xfa/fxfa/cxfa_pdffontmgr.h" + +#include <algorithm> + +#include "core/fpdfapi/font/cpdf_font.h" +#include "xfa/fxfa/cxfa_ffapp.h" + +namespace { + +// The 5 names per entry are: PsName, Normal, Bold, Italic, BoldItalic. +const char* const g_XFAPDFFontName[][5] = { + {"Adobe PI Std", "AdobePIStd", "AdobePIStd", "AdobePIStd", "AdobePIStd"}, + {"Myriad Pro Light", "MyriadPro-Light", "MyriadPro-Semibold", + "MyriadPro-LightIt", "MyriadPro-SemiboldIt"}, +}; + +} // namespace + +CXFA_PDFFontMgr::CXFA_PDFFontMgr(CXFA_FFDoc* pDoc) : m_pDoc(pDoc) {} + +CXFA_PDFFontMgr::~CXFA_PDFFontMgr() {} + +CFX_RetainPtr<CFGAS_GEFont> CXFA_PDFFontMgr::FindFont( + const CFX_ByteString& strPsName, + bool bBold, + bool bItalic, + CPDF_Font** pDstPDFFont, + bool bStrictMatch) { + CPDF_Document* pDoc = m_pDoc->GetPDFDoc(); + if (!pDoc) + return nullptr; + + CPDF_Dictionary* pFontSetDict = + pDoc->GetRoot()->GetDictFor("AcroForm")->GetDictFor("DR"); + if (!pFontSetDict) + return nullptr; + + pFontSetDict = pFontSetDict->GetDictFor("Font"); + if (!pFontSetDict) + return nullptr; + + CFX_ByteString name = strPsName; + name.Remove(' '); + CFGAS_FontMgr* pFDEFontMgr = m_pDoc->GetApp()->GetFDEFontMgr(); + for (const auto& it : *pFontSetDict) { + const CFX_ByteString& key = it.first; + CPDF_Object* pObj = it.second.get(); + if (!PsNameMatchDRFontName(name.AsStringC(), bBold, bItalic, key, + bStrictMatch)) { + continue; + } + CPDF_Dictionary* pFontDict = ToDictionary(pObj->GetDirect()); + if (!pFontDict || pFontDict->GetStringFor("Type") != "Font") { + return nullptr; + } + CPDF_Font* pPDFFont = pDoc->LoadFont(pFontDict); + if (!pPDFFont) { + return nullptr; + } + if (!pPDFFont->IsEmbedded()) { + *pDstPDFFont = pPDFFont; + return nullptr; + } + return CFGAS_GEFont::LoadFont(&pPDFFont->m_Font, pFDEFontMgr); + } + return nullptr; +} + +CFX_RetainPtr<CFGAS_GEFont> CXFA_PDFFontMgr::GetFont( + const CFX_WideStringC& wsFontFamily, + uint32_t dwFontStyles, + CPDF_Font** pPDFFont, + bool bStrictMatch) { + uint32_t dwHashCode = FX_HashCode_GetW(wsFontFamily, false); + CFX_ByteString strKey; + strKey.Format("%u%u", dwHashCode, dwFontStyles); + auto it = m_FontMap.find(strKey); + if (it != m_FontMap.end()) + return it->second; + CFX_ByteString bsPsName = + CFX_ByteString::FromUnicode(CFX_WideString(wsFontFamily)); + bool bBold = (dwFontStyles & FX_FONTSTYLE_Bold) == FX_FONTSTYLE_Bold; + bool bItalic = (dwFontStyles & FX_FONTSTYLE_Italic) == FX_FONTSTYLE_Italic; + CFX_ByteString strFontName = PsNameToFontName(bsPsName, bBold, bItalic); + CFX_RetainPtr<CFGAS_GEFont> pFont = + FindFont(strFontName, bBold, bItalic, pPDFFont, bStrictMatch); + if (pFont) + m_FontMap[strKey] = pFont; + return pFont; +} + +CFX_ByteString CXFA_PDFFontMgr::PsNameToFontName( + const CFX_ByteString& strPsName, + bool bBold, + bool bItalic) { + for (size_t i = 0; i < FX_ArraySize(g_XFAPDFFontName); ++i) { + if (strPsName == g_XFAPDFFontName[i][0]) { + size_t index = 1; + if (bBold) + ++index; + if (bItalic) + index += 2; + return g_XFAPDFFontName[i][index]; + } + } + return strPsName; +} + +bool CXFA_PDFFontMgr::PsNameMatchDRFontName(const CFX_ByteStringC& bsPsName, + bool bBold, + bool bItalic, + const CFX_ByteString& bsDRFontName, + bool bStrictMatch) { + CFX_ByteString bsDRName = bsDRFontName; + bsDRName.Remove('-'); + int32_t iPsLen = bsPsName.GetLength(); + int32_t nIndex = bsDRName.Find(bsPsName); + if (nIndex != -1 && !bStrictMatch) + return true; + + if (nIndex != 0) + return false; + + int32_t iDifferLength = bsDRName.GetLength() - iPsLen; + if (iDifferLength > 1 || (bBold || bItalic)) { + int32_t iBoldIndex = bsDRName.Find("Bold"); + bool bBoldFont = iBoldIndex > 0; + if (bBold != bBoldFont) + return false; + + if (bBoldFont) { + iDifferLength = + std::min(iDifferLength - 4, bsDRName.GetLength() - iBoldIndex - 4); + } + bool bItalicFont = true; + if (bsDRName.Find("Italic") > 0) { + iDifferLength -= 6; + } else if (bsDRName.Find("It") > 0) { + iDifferLength -= 2; + } else if (bsDRName.Find("Oblique") > 0) { + iDifferLength -= 7; + } else { + bItalicFont = false; + } + if (bItalic != bItalicFont) + return false; + + if (iDifferLength > 1) { + CFX_ByteString bsDRTailer = bsDRName.Right(iDifferLength); + if (bsDRTailer == "MT" || bsDRTailer == "PSMT" || + bsDRTailer == "Regular" || bsDRTailer == "Reg") { + return true; + } + if (bBoldFont || bItalicFont) + return false; + + bool bMatch = false; + switch (bsPsName.GetAt(iPsLen - 1)) { + case 'L': { + if (bsDRName.Right(5) == "Light") { + bMatch = true; + } + } break; + case 'R': { + if (bsDRName.Right(7) == "Regular" || bsDRName.Right(3) == "Reg") { + bMatch = true; + } + } break; + case 'M': { + if (bsDRName.Right(5) == "Medium") { + bMatch = true; + } + } break; + default: + break; + } + return bMatch; + } + } + return true; +} + +bool CXFA_PDFFontMgr::GetCharWidth(const CFX_RetainPtr<CFGAS_GEFont>& pFont, + wchar_t wUnicode, + bool bCharCode, + int32_t* pWidth) { + if (wUnicode != 0x20 || bCharCode) + return false; + + auto it = m_FDE2PDFFont.find(pFont); + if (it == m_FDE2PDFFont.end()) + return false; + + CPDF_Font* pPDFFont = it->second; + *pWidth = pPDFFont->GetCharWidthF(pPDFFont->CharCodeFromUnicode(wUnicode)); + return true; +} + +void CXFA_PDFFontMgr::SetFont(const CFX_RetainPtr<CFGAS_GEFont>& pFont, + CPDF_Font* pPDFFont) { + m_FDE2PDFFont[pFont] = pPDFFont; +} diff --git a/chromium/third_party/pdfium/xfa/fxfa/cxfa_pdffontmgr.h b/chromium/third_party/pdfium/xfa/fxfa/cxfa_pdffontmgr.h new file mode 100644 index 00000000000..1188ce1fba6 --- /dev/null +++ b/chromium/third_party/pdfium/xfa/fxfa/cxfa_pdffontmgr.h @@ -0,0 +1,57 @@ +// Copyright 2017 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#ifndef XFA_FXFA_CXFA_PDFFONTMGR_H_ +#define XFA_FXFA_CXFA_PDFFONTMGR_H_ + +#include <map> + +#include "core/fpdfapi/parser/cpdf_dictionary.h" +#include "core/fpdfapi/parser/cpdf_document.h" +#include "core/fxcrt/cfx_retain_ptr.h" +#include "core/fxcrt/fx_string.h" +#include "xfa/fgas/font/cfgas_gefont.h" +#include "xfa/fxfa/cxfa_ffdoc.h" + +class CPDF_Font; +class CXFA_FFDoc; + +class CXFA_PDFFontMgr { + public: + explicit CXFA_PDFFontMgr(CXFA_FFDoc* pDoc); + ~CXFA_PDFFontMgr(); + + CFX_RetainPtr<CFGAS_GEFont> GetFont(const CFX_WideStringC& wsFontFamily, + uint32_t dwFontStyles, + CPDF_Font** pPDFFont, + bool bStrictMatch); + bool GetCharWidth(const CFX_RetainPtr<CFGAS_GEFont>& pFont, + wchar_t wUnicode, + bool bCharCode, + int32_t* pWidth); + void SetFont(const CFX_RetainPtr<CFGAS_GEFont>& pFont, CPDF_Font* pPDFFont); + + private: + CFX_RetainPtr<CFGAS_GEFont> FindFont(const CFX_ByteString& strFamilyName, + bool bBold, + bool bItalic, + CPDF_Font** pPDFFont, + bool bStrictMatch); + CFX_ByteString PsNameToFontName(const CFX_ByteString& strPsName, + bool bBold, + bool bItalic); + bool PsNameMatchDRFontName(const CFX_ByteStringC& bsPsName, + bool bBold, + bool bItalic, + const CFX_ByteString& bsDRFontName, + bool bStrictMatch); + + CXFA_FFDoc* const m_pDoc; + std::map<CFX_RetainPtr<CFGAS_GEFont>, CPDF_Font*> m_FDE2PDFFont; + std::map<CFX_ByteString, CFX_RetainPtr<CFGAS_GEFont>> m_FontMap; +}; + +#endif // XFA_FXFA_CXFA_PDFFONTMGR_H_ diff --git a/chromium/third_party/pdfium/xfa/fxfa/app/xfa_rendercontext.cpp b/chromium/third_party/pdfium/xfa/fxfa/cxfa_rendercontext.cpp index a855105e3dc..ecb42918cb5 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/app/xfa_rendercontext.cpp +++ b/chromium/third_party/pdfium/xfa/fxfa/cxfa_rendercontext.cpp @@ -4,10 +4,10 @@ // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com -#include "xfa/fxfa/xfa_rendercontext.h" +#include "xfa/fxfa/cxfa_rendercontext.h" -#include "xfa/fxfa/xfa_ffpageview.h" -#include "xfa/fxfa/xfa_ffwidget.h" +#include "xfa/fxfa/cxfa_ffpageview.h" +#include "xfa/fxfa/cxfa_ffwidget.h" #include "xfa/fxgraphics/cfx_graphics.h" namespace { diff --git a/chromium/third_party/pdfium/xfa/fxfa/xfa_rendercontext.h b/chromium/third_party/pdfium/xfa/fxfa/cxfa_rendercontext.h index c424005b1e2..960bd058d10 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/xfa_rendercontext.h +++ b/chromium/third_party/pdfium/xfa/fxfa/cxfa_rendercontext.h @@ -4,8 +4,8 @@ // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com -#ifndef XFA_FXFA_XFA_RENDERCONTEXT_H_ -#define XFA_FXFA_XFA_RENDERCONTEXT_H_ +#ifndef XFA_FXFA_CXFA_RENDERCONTEXT_H_ +#define XFA_FXFA_CXFA_RENDERCONTEXT_H_ #include <memory> @@ -31,7 +31,7 @@ class CXFA_RenderContext { int32_t DoRender(IFX_Pause* pPause = nullptr); void StopRender(); - protected: + private: std::unique_ptr<IXFA_WidgetIterator> m_pWidgetIterator; CXFA_FFWidget* m_pWidget; CXFA_FFPageView* m_pPageView; @@ -42,4 +42,4 @@ class CXFA_RenderContext { CFX_RectF m_rtClipRect; }; -#endif // XFA_FXFA_XFA_RENDERCONTEXT_H_ +#endif // XFA_FXFA_CXFA_RENDERCONTEXT_H_ diff --git a/chromium/third_party/pdfium/xfa/fxfa/cxfa_widgetacc.cpp b/chromium/third_party/pdfium/xfa/fxfa/cxfa_widgetacc.cpp new file mode 100644 index 00000000000..be7556ee241 --- /dev/null +++ b/chromium/third_party/pdfium/xfa/fxfa/cxfa_widgetacc.cpp @@ -0,0 +1,1533 @@ +// Copyright 2017 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#include "xfa/fxfa/cxfa_widgetacc.h" + +#include <algorithm> +#include <vector> + +#include "third_party/base/stl_util.h" +#include "xfa/fde/cfde_textout.h" +#include "xfa/fde/xml/cfde_xmlelement.h" +#include "xfa/fde/xml/cfde_xmlnode.h" +#include "xfa/fxfa/app/cxfa_textlayout.h" +#include "xfa/fxfa/app/xfa_ffwidgetacc.h" +#include "xfa/fxfa/cxfa_ffapp.h" +#include "xfa/fxfa/cxfa_ffdoc.h" +#include "xfa/fxfa/cxfa_ffdocview.h" +#include "xfa/fxfa/cxfa_ffwidget.h" +#include "xfa/fxfa/cxfa_fontmgr.h" +#include "xfa/fxfa/parser/cxfa_layoutprocessor.h" +#include "xfa/fxfa/parser/cxfa_localevalue.h" +#include "xfa/fxfa/parser/cxfa_node.h" +#include "xfa/fxfa/parser/cxfa_scriptcontext.h" +#include "xfa/fxfa/parser/xfa_utils.h" + +class CXFA_WidgetLayoutData { + public: + CXFA_WidgetLayoutData() : m_fWidgetHeight(-1) {} + virtual ~CXFA_WidgetLayoutData() {} + + float m_fWidgetHeight; +}; + +namespace { + +void FFDeleteCalcData(void* pData) { + if (pData) + delete ((CXFA_CalcData*)pData); +} + +static XFA_MAPDATABLOCKCALLBACKINFO gs_XFADeleteCalcData = {FFDeleteCalcData, + nullptr}; + +class CXFA_TextLayoutData : public CXFA_WidgetLayoutData { + public: + CXFA_TextLayoutData() {} + ~CXFA_TextLayoutData() override {} + + CXFA_TextLayout* GetTextLayout() const { return m_pTextLayout.get(); } + CXFA_TextProvider* GetTextProvider() const { return m_pTextProvider.get(); } + + void LoadText(CXFA_WidgetAcc* pAcc) { + if (m_pTextLayout) + return; + + m_pTextProvider = + pdfium::MakeUnique<CXFA_TextProvider>(pAcc, XFA_TEXTPROVIDERTYPE_Text); + m_pTextLayout = pdfium::MakeUnique<CXFA_TextLayout>(m_pTextProvider.get()); + } + + private: + std::unique_ptr<CXFA_TextLayout> m_pTextLayout; + std::unique_ptr<CXFA_TextProvider> m_pTextProvider; +}; + +class CXFA_ImageLayoutData : public CXFA_WidgetLayoutData { + public: + CXFA_ImageLayoutData() + : m_bNamedImage(false), m_iImageXDpi(0), m_iImageYDpi(0) {} + + ~CXFA_ImageLayoutData() override {} + + bool LoadImageData(CXFA_WidgetAcc* pAcc) { + if (m_pDIBitmap) + return true; + + CXFA_Value value = pAcc->GetFormValue(); + if (!value) + return false; + + CXFA_Image imageObj = value.GetImage(); + if (!imageObj) + return false; + + CXFA_FFDoc* pFFDoc = pAcc->GetDoc(); + pAcc->SetImageImage(XFA_LoadImageData(pFFDoc, &imageObj, m_bNamedImage, + m_iImageXDpi, m_iImageYDpi)); + return !!m_pDIBitmap; + } + + CFX_RetainPtr<CFX_DIBitmap> m_pDIBitmap; + bool m_bNamedImage; + int32_t m_iImageXDpi; + int32_t m_iImageYDpi; +}; + +class CXFA_FieldLayoutData : public CXFA_WidgetLayoutData { + public: + CXFA_FieldLayoutData() {} + ~CXFA_FieldLayoutData() override {} + + bool LoadCaption(CXFA_WidgetAcc* pAcc) { + if (m_pCapTextLayout) + return true; + CXFA_Caption caption = pAcc->GetCaption(); + if (!caption || caption.GetPresence() == XFA_ATTRIBUTEENUM_Hidden) + return false; + m_pCapTextProvider.reset( + new CXFA_TextProvider(pAcc, XFA_TEXTPROVIDERTYPE_Caption)); + m_pCapTextLayout = + pdfium::MakeUnique<CXFA_TextLayout>(m_pCapTextProvider.get()); + return true; + } + + std::unique_ptr<CXFA_TextLayout> m_pCapTextLayout; + std::unique_ptr<CXFA_TextProvider> m_pCapTextProvider; + std::unique_ptr<CFDE_TextOut> m_pTextOut; + std::vector<float> m_FieldSplitArray; +}; + +class CXFA_TextEditData : public CXFA_FieldLayoutData { + public: +}; + +class CXFA_ImageEditData : public CXFA_FieldLayoutData { + public: + CXFA_ImageEditData() + : m_bNamedImage(false), m_iImageXDpi(0), m_iImageYDpi(0) {} + + ~CXFA_ImageEditData() override {} + + bool LoadImageData(CXFA_WidgetAcc* pAcc) { + if (m_pDIBitmap) + return true; + + CXFA_Value value = pAcc->GetFormValue(); + if (!value) + return false; + + CXFA_Image imageObj = value.GetImage(); + CXFA_FFDoc* pFFDoc = pAcc->GetDoc(); + pAcc->SetImageEditImage(XFA_LoadImageData(pFFDoc, &imageObj, m_bNamedImage, + m_iImageXDpi, m_iImageYDpi)); + return !!m_pDIBitmap; + } + + CFX_RetainPtr<CFX_DIBitmap> m_pDIBitmap; + bool m_bNamedImage; + int32_t m_iImageXDpi; + int32_t m_iImageYDpi; +}; + +} // namespace + +CXFA_WidgetAcc::CXFA_WidgetAcc(CXFA_FFDocView* pDocView, CXFA_Node* pNode) + : CXFA_WidgetData(pNode), m_pDocView(pDocView), m_nRecursionDepth(0) {} + +CXFA_WidgetAcc::~CXFA_WidgetAcc() {} + +bool CXFA_WidgetAcc::GetName(CFX_WideString& wsName, int32_t iNameType) { + if (iNameType == 0) { + m_pNode->TryCData(XFA_ATTRIBUTE_Name, wsName); + return !wsName.IsEmpty(); + } + m_pNode->GetSOMExpression(wsName); + if (iNameType == 2 && wsName.GetLength() >= 15) { + CFX_WideStringC wsPre = L"xfa[0].form[0]."; + if (wsPre == CFX_WideStringC(wsName.c_str(), wsPre.GetLength())) + wsName.Delete(0, wsPre.GetLength()); + } + return true; +} + +CXFA_Node* CXFA_WidgetAcc::GetDatasets() { + return m_pNode->GetBindData(); +} + +bool CXFA_WidgetAcc::ProcessValueChanged() { + m_pDocView->AddValidateWidget(this); + m_pDocView->AddCalculateWidgetAcc(this); + m_pDocView->RunCalculateWidgets(); + m_pDocView->RunValidate(); + return true; +} + +void CXFA_WidgetAcc::ResetData() { + CFX_WideString wsValue; + XFA_Element eUIType = GetUIType(); + switch (eUIType) { + case XFA_Element::ImageEdit: { + CXFA_Value imageValue = GetDefaultValue(); + CXFA_Image image = imageValue.GetImage(); + CFX_WideString wsContentType, wsHref; + if (image) { + image.GetContent(wsValue); + image.GetContentType(wsContentType); + image.GetHref(wsHref); + } + SetImageEdit(wsContentType, wsHref, wsValue); + break; + } + case XFA_Element::ExclGroup: { + CXFA_Node* pNextChild = m_pNode->GetNodeItem( + XFA_NODEITEM_FirstChild, XFA_ObjectType::ContainerNode); + while (pNextChild) { + CXFA_Node* pChild = pNextChild; + CXFA_WidgetAcc* pAcc = + static_cast<CXFA_WidgetAcc*>(pChild->GetWidgetData()); + if (!pAcc) + continue; + + CXFA_Value defValue(nullptr); + if (wsValue.IsEmpty() && (defValue = pAcc->GetDefaultValue())) { + defValue.GetChildValueContent(wsValue); + SetValue(wsValue, XFA_VALUEPICTURE_Raw); + pAcc->SetValue(wsValue, XFA_VALUEPICTURE_Raw); + } else { + CXFA_Node* pItems = pChild->GetChild(0, XFA_Element::Items); + if (!pItems) + continue; + + CFX_WideString itemText; + if (pItems->CountChildren(XFA_Element::Unknown) > 1) + itemText = pItems->GetChild(1, XFA_Element::Unknown)->GetContent(); + + pAcc->SetValue(itemText, XFA_VALUEPICTURE_Raw); + } + pNextChild = pChild->GetNodeItem(XFA_NODEITEM_NextSibling, + XFA_ObjectType::ContainerNode); + } + break; + } + case XFA_Element::ChoiceList: + ClearAllSelections(); + default: + if (CXFA_Value defValue = GetDefaultValue()) + defValue.GetChildValueContent(wsValue); + + SetValue(wsValue, XFA_VALUEPICTURE_Raw); + break; + } +} + +void CXFA_WidgetAcc::SetImageEdit(const CFX_WideString& wsContentType, + const CFX_WideString& wsHref, + const CFX_WideString& wsData) { + CXFA_Image image = GetFormValue().GetImage(); + if (image) { + image.SetContentType(CFX_WideString(wsContentType)); + image.SetHref(wsHref); + } + CFX_WideString wsFormatValue(wsData); + GetFormatDataValue(wsData, wsFormatValue); + m_pNode->SetContent(wsData, wsFormatValue, true); + CXFA_Node* pBind = GetDatasets(); + if (!pBind) { + image.SetTransferEncoding(XFA_ATTRIBUTEENUM_Base64); + return; + } + pBind->SetCData(XFA_ATTRIBUTE_ContentType, wsContentType); + CXFA_Node* pHrefNode = pBind->GetNodeItem(XFA_NODEITEM_FirstChild); + if (pHrefNode) { + pHrefNode->SetCData(XFA_ATTRIBUTE_Value, wsHref); + } else { + CFDE_XMLNode* pXMLNode = pBind->GetXMLMappingNode(); + ASSERT(pXMLNode && pXMLNode->GetType() == FDE_XMLNODE_Element); + static_cast<CFDE_XMLElement*>(pXMLNode)->SetString(L"href", wsHref); + } +} + +CXFA_WidgetAcc* CXFA_WidgetAcc::GetExclGroup() { + CXFA_Node* pExcl = m_pNode->GetNodeItem(XFA_NODEITEM_Parent); + if (!pExcl || pExcl->GetElementType() != XFA_Element::ExclGroup) + return nullptr; + return static_cast<CXFA_WidgetAcc*>(pExcl->GetWidgetData()); +} + +CXFA_FFDocView* CXFA_WidgetAcc::GetDocView() { + return m_pDocView; +} + +CXFA_FFDoc* CXFA_WidgetAcc::GetDoc() { + return m_pDocView->GetDoc(); +} + +CXFA_FFApp* CXFA_WidgetAcc::GetApp() { + return GetDoc()->GetApp(); +} + +IXFA_AppProvider* CXFA_WidgetAcc::GetAppProvider() { + return GetApp()->GetAppProvider(); +} + +int32_t CXFA_WidgetAcc::ProcessEvent(int32_t iActivity, + CXFA_EventParam* pEventParam) { + if (GetElementType() == XFA_Element::Draw) + return XFA_EVENTERROR_NotExist; + + std::vector<CXFA_Node*> eventArray = + GetEventByActivity(iActivity, pEventParam->m_bIsFormReady); + bool first = true; + int32_t iRet = XFA_EVENTERROR_NotExist; + for (CXFA_Node* pNode : eventArray) { + int32_t result = ProcessEvent(CXFA_Event(pNode), pEventParam); + if (first || result == XFA_EVENTERROR_Success) + iRet = result; + first = false; + } + return iRet; +} + +int32_t CXFA_WidgetAcc::ProcessEvent(const CXFA_Event& event, + CXFA_EventParam* pEventParam) { + if (!event) + return XFA_EVENTERROR_NotExist; + + switch (event.GetEventType()) { + case XFA_Element::Execute: + break; + case XFA_Element::Script: + return ExecuteScript(event.GetScript(), pEventParam); + case XFA_Element::SignData: + break; + case XFA_Element::Submit: + return GetDoc()->GetDocEnvironment()->SubmitData(GetDoc(), + event.GetSubmit()); + default: + break; + } + return XFA_EVENTERROR_NotExist; +} + +int32_t CXFA_WidgetAcc::ProcessCalculate() { + if (GetElementType() == XFA_Element::Draw) + return XFA_EVENTERROR_NotExist; + + CXFA_Calculate calc = GetCalculate(); + if (!calc) + return XFA_EVENTERROR_NotExist; + if (GetNode()->IsUserInteractive()) + return XFA_EVENTERROR_Disabled; + + CXFA_EventParam EventParam; + EventParam.m_eType = XFA_EVENT_Calculate; + CXFA_Script script = calc.GetScript(); + int32_t iRet = ExecuteScript(script, &EventParam); + if (iRet != XFA_EVENTERROR_Success) + return iRet; + + if (GetRawValue() != EventParam.m_wsResult) { + SetValue(EventParam.m_wsResult, XFA_VALUEPICTURE_Raw); + UpdateUIDisplay(); + } + return XFA_EVENTERROR_Success; +} + +void CXFA_WidgetAcc::ProcessScriptTestValidate(CXFA_Validate validate, + int32_t iRet, + CFXJSE_Value* pRetValue, + bool bVersionFlag) { + if (iRet == XFA_EVENTERROR_Success && pRetValue) { + if (pRetValue->IsBoolean() && !pRetValue->ToBoolean()) { + IXFA_AppProvider* pAppProvider = GetAppProvider(); + if (!pAppProvider) { + return; + } + CFX_WideString wsTitle = pAppProvider->GetAppTitle(); + CFX_WideString wsScriptMsg; + validate.GetScriptMessageText(wsScriptMsg); + int32_t eScriptTest = validate.GetScriptTest(); + if (eScriptTest == XFA_ATTRIBUTEENUM_Warning) { + if (GetNode()->IsUserInteractive()) + return; + if (wsScriptMsg.IsEmpty()) + wsScriptMsg = GetValidateMessage(false, bVersionFlag); + + if (bVersionFlag) { + pAppProvider->MsgBox(wsScriptMsg, wsTitle, XFA_MBICON_Warning, + XFA_MB_OK); + return; + } + if (pAppProvider->MsgBox(wsScriptMsg, wsTitle, XFA_MBICON_Warning, + XFA_MB_YesNo) == XFA_IDYes) { + GetNode()->SetFlag(XFA_NodeFlag_UserInteractive, false); + } + } else { + if (wsScriptMsg.IsEmpty()) + wsScriptMsg = GetValidateMessage(true, bVersionFlag); + pAppProvider->MsgBox(wsScriptMsg, wsTitle, XFA_MBICON_Error, XFA_MB_OK); + } + } + } +} + +int32_t CXFA_WidgetAcc::ProcessFormatTestValidate(CXFA_Validate validate, + bool bVersionFlag) { + CFX_WideString wsRawValue = GetRawValue(); + if (!wsRawValue.IsEmpty()) { + CFX_WideString wsPicture; + validate.GetPicture(wsPicture); + if (wsPicture.IsEmpty()) + return XFA_EVENTERROR_NotExist; + + IFX_Locale* pLocale = GetLocal(); + if (!pLocale) + return XFA_EVENTERROR_NotExist; + + CXFA_LocaleValue lcValue = XFA_GetLocaleValue(this); + if (!lcValue.ValidateValue(lcValue.GetValue(), wsPicture, pLocale)) { + IXFA_AppProvider* pAppProvider = GetAppProvider(); + if (!pAppProvider) + return XFA_EVENTERROR_NotExist; + + CFX_WideString wsFormatMsg; + validate.GetFormatMessageText(wsFormatMsg); + CFX_WideString wsTitle = pAppProvider->GetAppTitle(); + int32_t eFormatTest = validate.GetFormatTest(); + if (eFormatTest == XFA_ATTRIBUTEENUM_Error) { + if (wsFormatMsg.IsEmpty()) + wsFormatMsg = GetValidateMessage(true, bVersionFlag); + pAppProvider->MsgBox(wsFormatMsg, wsTitle, XFA_MBICON_Error, XFA_MB_OK); + return XFA_EVENTERROR_Success; + } + if (GetNode()->IsUserInteractive()) + return XFA_EVENTERROR_NotExist; + if (wsFormatMsg.IsEmpty()) + wsFormatMsg = GetValidateMessage(false, bVersionFlag); + + if (bVersionFlag) { + pAppProvider->MsgBox(wsFormatMsg, wsTitle, XFA_MBICON_Warning, + XFA_MB_OK); + return XFA_EVENTERROR_Success; + } + if (pAppProvider->MsgBox(wsFormatMsg, wsTitle, XFA_MBICON_Warning, + XFA_MB_YesNo) == XFA_IDYes) { + GetNode()->SetFlag(XFA_NodeFlag_UserInteractive, false); + } + return XFA_EVENTERROR_Success; + } + } + return XFA_EVENTERROR_NotExist; +} + +int32_t CXFA_WidgetAcc::ProcessNullTestValidate(CXFA_Validate validate, + int32_t iFlags, + bool bVersionFlag) { + CFX_WideString wsValue; + GetValue(wsValue, XFA_VALUEPICTURE_Raw); + if (!wsValue.IsEmpty()) + return XFA_EVENTERROR_Success; + if (m_bIsNull && (m_bPreNull == m_bIsNull)) + return XFA_EVENTERROR_Success; + + int32_t eNullTest = validate.GetNullTest(); + CFX_WideString wsNullMsg; + validate.GetNullMessageText(wsNullMsg); + if (iFlags & 0x01) { + int32_t iRet = XFA_EVENTERROR_Success; + if (eNullTest != XFA_ATTRIBUTEENUM_Disabled) + iRet = XFA_EVENTERROR_Error; + + if (!wsNullMsg.IsEmpty()) { + if (eNullTest != XFA_ATTRIBUTEENUM_Disabled) { + m_pDocView->m_arrNullTestMsg.push_back(wsNullMsg); + return XFA_EVENTERROR_Error; + } + return XFA_EVENTERROR_Success; + } + return iRet; + } + if (wsNullMsg.IsEmpty() && bVersionFlag && + eNullTest != XFA_ATTRIBUTEENUM_Disabled) { + return XFA_EVENTERROR_Error; + } + IXFA_AppProvider* pAppProvider = GetAppProvider(); + if (!pAppProvider) + return XFA_EVENTERROR_NotExist; + + CFX_WideString wsCaptionName; + CFX_WideString wsTitle = pAppProvider->GetAppTitle(); + switch (eNullTest) { + case XFA_ATTRIBUTEENUM_Error: { + if (wsNullMsg.IsEmpty()) { + wsCaptionName = GetValidateCaptionName(bVersionFlag); + wsNullMsg.Format(L"%s cannot be blank.", wsCaptionName.c_str()); + } + pAppProvider->MsgBox(wsNullMsg, wsTitle, XFA_MBICON_Status, XFA_MB_OK); + return XFA_EVENTERROR_Error; + } + case XFA_ATTRIBUTEENUM_Warning: { + if (GetNode()->IsUserInteractive()) + return true; + + if (wsNullMsg.IsEmpty()) { + wsCaptionName = GetValidateCaptionName(bVersionFlag); + wsNullMsg.Format( + L"%s cannot be blank. To ignore validations for %s, click Ignore.", + wsCaptionName.c_str(), wsCaptionName.c_str()); + } + if (pAppProvider->MsgBox(wsNullMsg, wsTitle, XFA_MBICON_Warning, + XFA_MB_YesNo) == XFA_IDYes) { + GetNode()->SetFlag(XFA_NodeFlag_UserInteractive, false); + } + return XFA_EVENTERROR_Error; + } + case XFA_ATTRIBUTEENUM_Disabled: + default: + break; + } + return XFA_EVENTERROR_Success; +} + +CFX_WideString CXFA_WidgetAcc::GetValidateCaptionName(bool bVersionFlag) { + CFX_WideString wsCaptionName; + + if (!bVersionFlag) { + if (CXFA_Caption caption = GetCaption()) { + if (CXFA_Value capValue = caption.GetValue()) { + if (CXFA_Text capText = capValue.GetText()) + capText.GetContent(wsCaptionName); + } + } + } + if (wsCaptionName.IsEmpty()) + GetName(wsCaptionName); + + return wsCaptionName; +} + +CFX_WideString CXFA_WidgetAcc::GetValidateMessage(bool bError, + bool bVersionFlag) { + CFX_WideString wsCaptionName = GetValidateCaptionName(bVersionFlag); + CFX_WideString wsMessage; + if (bVersionFlag) { + wsMessage.Format(L"%s validation failed", wsCaptionName.c_str()); + return wsMessage; + } + if (bError) { + wsMessage.Format(L"The value you entered for %s is invalid.", + wsCaptionName.c_str()); + return wsMessage; + } + wsMessage.Format( + L"The value you entered for %s is invalid. To ignore " + L"validations for %s, click Ignore.", + wsCaptionName.c_str(), wsCaptionName.c_str()); + return wsMessage; +} + +int32_t CXFA_WidgetAcc::ProcessValidate(int32_t iFlags) { + if (GetElementType() == XFA_Element::Draw) + return XFA_EVENTERROR_NotExist; + + CXFA_Validate validate = GetValidate(); + if (!validate) + return XFA_EVENTERROR_NotExist; + + bool bInitDoc = validate.GetNode()->NeedsInitApp(); + bool bStatus = m_pDocView->GetLayoutStatus() < XFA_DOCVIEW_LAYOUTSTATUS_End; + int32_t iFormat = 0; + CFXJSE_Value* pRetValue = nullptr; + int32_t iRet = XFA_EVENTERROR_NotExist; + CXFA_Script script = validate.GetScript(); + if (script) { + CXFA_EventParam eParam; + eParam.m_eType = XFA_EVENT_Validate; + eParam.m_pTarget = this; + iRet = ExecuteScript(script, &eParam, + ((bInitDoc || bStatus) && GetRawValue().IsEmpty()) + ? nullptr + : &pRetValue); + } + XFA_VERSION version = GetDoc()->GetXFADoc()->GetCurVersionMode(); + bool bVersionFlag = false; + if (version < XFA_VERSION_208) + bVersionFlag = true; + + if (bInitDoc) { + validate.GetNode()->ClearFlag(XFA_NodeFlag_NeedsInitApp); + } else { + iFormat = ProcessFormatTestValidate(validate, bVersionFlag); + if (!bVersionFlag) + bVersionFlag = GetDoc()->GetXFADoc()->HasFlag(XFA_DOCFLAG_Scripting); + + iRet |= ProcessNullTestValidate(validate, iFlags, bVersionFlag); + } + if (iFormat != XFA_EVENTERROR_Success) + ProcessScriptTestValidate(validate, iRet, pRetValue, bVersionFlag); + + delete pRetValue; + + return iRet | iFormat; +} + +int32_t CXFA_WidgetAcc::ExecuteScript(CXFA_Script script, + CXFA_EventParam* pEventParam, + CFXJSE_Value** pRetValue) { + static const uint32_t MAX_RECURSION_DEPTH = 2; + if (m_nRecursionDepth > MAX_RECURSION_DEPTH) + return XFA_EVENTERROR_Success; + + ASSERT(pEventParam); + if (!script) + return XFA_EVENTERROR_NotExist; + if (script.GetRunAt() == XFA_ATTRIBUTEENUM_Server) + return XFA_EVENTERROR_Disabled; + + CFX_WideString wsExpression; + script.GetExpression(wsExpression); + if (wsExpression.IsEmpty()) + return XFA_EVENTERROR_NotExist; + + XFA_SCRIPTTYPE eScriptType = script.GetContentType(); + if (eScriptType == XFA_SCRIPTTYPE_Unkown) + return XFA_EVENTERROR_Success; + + CXFA_FFDoc* pDoc = GetDoc(); + CXFA_ScriptContext* pContext = pDoc->GetXFADoc()->GetScriptContext(); + pContext->SetEventParam(*pEventParam); + pContext->SetRunAtType((XFA_ATTRIBUTEENUM)script.GetRunAt()); + std::vector<CXFA_Node*> refNodes; + if (pEventParam->m_eType == XFA_EVENT_InitCalculate || + pEventParam->m_eType == XFA_EVENT_Calculate) { + pContext->SetNodesOfRunScript(&refNodes); + } + std::unique_ptr<CFXJSE_Value> pTmpRetValue( + new CFXJSE_Value(pContext->GetRuntime())); + ++m_nRecursionDepth; + bool bRet = pContext->RunScript((XFA_SCRIPTLANGTYPE)eScriptType, + wsExpression.AsStringC(), pTmpRetValue.get(), + m_pNode); + --m_nRecursionDepth; + int32_t iRet = XFA_EVENTERROR_Error; + if (bRet) { + iRet = XFA_EVENTERROR_Success; + if (pEventParam->m_eType == XFA_EVENT_Calculate || + pEventParam->m_eType == XFA_EVENT_InitCalculate) { + if (!pTmpRetValue->IsUndefined()) { + if (!pTmpRetValue->IsNull()) + pEventParam->m_wsResult = pTmpRetValue->ToWideString(); + + iRet = XFA_EVENTERROR_Success; + } else { + iRet = XFA_EVENTERROR_Error; + } + if (pEventParam->m_eType == XFA_EVENT_InitCalculate) { + if ((iRet == XFA_EVENTERROR_Success) && + (GetRawValue() != pEventParam->m_wsResult)) { + SetValue(pEventParam->m_wsResult, XFA_VALUEPICTURE_Raw); + m_pDocView->AddValidateWidget(this); + } + } + for (CXFA_Node* pRefNode : refNodes) { + if (static_cast<CXFA_WidgetAcc*>(pRefNode->GetWidgetData()) == this) + continue; + + auto* pGlobalData = + static_cast<CXFA_CalcData*>(pRefNode->GetUserData(XFA_CalcData)); + if (!pGlobalData) { + pGlobalData = new CXFA_CalcData; + pRefNode->SetUserData(XFA_CalcData, pGlobalData, + &gs_XFADeleteCalcData); + } + if (!pdfium::ContainsValue(pGlobalData->m_Globals, this)) + pGlobalData->m_Globals.push_back(this); + } + } + } + if (pRetValue) + *pRetValue = pTmpRetValue.release(); + + pContext->SetNodesOfRunScript(nullptr); + return iRet; +} + +CXFA_FFWidget* CXFA_WidgetAcc::GetNextWidget(CXFA_FFWidget* pWidget) { + CXFA_LayoutItem* pLayout = nullptr; + if (pWidget) + pLayout = pWidget->GetNext(); + else + pLayout = m_pDocView->GetXFALayout()->GetLayoutItem(m_pNode); + + return static_cast<CXFA_FFWidget*>(pLayout); +} + +void CXFA_WidgetAcc::UpdateUIDisplay(CXFA_FFWidget* pExcept) { + CXFA_FFWidget* pWidget = nullptr; + while ((pWidget = GetNextWidget(pWidget)) != nullptr) { + if (pWidget == pExcept || !pWidget->IsLoaded() || + (GetUIType() != XFA_Element::CheckButton && pWidget->IsFocused())) { + continue; + } + pWidget->UpdateFWLData(); + pWidget->AddInvalidateRect(); + } +} + +void CXFA_WidgetAcc::CalcCaptionSize(CFX_SizeF& szCap) { + CXFA_Caption caption = GetCaption(); + if (!caption || caption.GetPresence() != XFA_ATTRIBUTEENUM_Visible) + return; + + LoadCaption(); + XFA_Element eUIType = GetUIType(); + int32_t iCapPlacement = caption.GetPlacementType(); + float fCapReserve = caption.GetReserve(); + const bool bVert = iCapPlacement == XFA_ATTRIBUTEENUM_Top || + iCapPlacement == XFA_ATTRIBUTEENUM_Bottom; + const bool bReserveExit = fCapReserve > 0.01; + CXFA_TextLayout* pCapTextLayout = + static_cast<CXFA_FieldLayoutData*>(m_pLayoutData.get()) + ->m_pCapTextLayout.get(); + if (pCapTextLayout) { + if (!bVert && eUIType != XFA_Element::Button) + szCap.width = fCapReserve; + + CFX_SizeF minSize; + pCapTextLayout->CalcSize(minSize, szCap, szCap); + if (bReserveExit) + bVert ? szCap.height = fCapReserve : szCap.width = fCapReserve; + } else { + float fFontSize = 10.0f; + if (CXFA_Font font = caption.GetFont()) + fFontSize = font.GetFontSize(); + else if (CXFA_Font widgetfont = GetFont()) + fFontSize = widgetfont.GetFontSize(); + + if (bVert) { + szCap.height = fCapReserve > 0 ? fCapReserve : fFontSize; + } else { + szCap.width = fCapReserve > 0 ? fCapReserve : 0; + szCap.height = fFontSize; + } + } + if (CXFA_Margin mgCap = caption.GetMargin()) { + float fLeftInset, fTopInset, fRightInset, fBottomInset; + mgCap.GetLeftInset(fLeftInset); + mgCap.GetTopInset(fTopInset); + mgCap.GetRightInset(fRightInset); + mgCap.GetBottomInset(fBottomInset); + if (bReserveExit) { + bVert ? (szCap.width += fLeftInset + fRightInset) + : (szCap.height += fTopInset + fBottomInset); + } else { + szCap.width += fLeftInset + fRightInset; + szCap.height += fTopInset + fBottomInset; + } + } +} + +bool CXFA_WidgetAcc::CalculateFieldAutoSize(CFX_SizeF& size) { + CFX_SizeF szCap; + CalcCaptionSize(szCap); + CFX_RectF rtUIMargin = GetUIMargin(); + size.width += rtUIMargin.left + rtUIMargin.width; + size.height += rtUIMargin.top + rtUIMargin.height; + if (szCap.width > 0 && szCap.height > 0) { + int32_t iCapPlacement = GetCaption().GetPlacementType(); + switch (iCapPlacement) { + case XFA_ATTRIBUTEENUM_Left: + case XFA_ATTRIBUTEENUM_Right: + case XFA_ATTRIBUTEENUM_Inline: { + size.width += szCap.width; + size.height = std::max(size.height, szCap.height); + } break; + case XFA_ATTRIBUTEENUM_Top: + case XFA_ATTRIBUTEENUM_Bottom: { + size.height += szCap.height; + size.width = std::max(size.width, szCap.width); + } + default: + break; + } + } + return CalculateWidgetAutoSize(size); +} + +bool CXFA_WidgetAcc::CalculateWidgetAutoSize(CFX_SizeF& size) { + CXFA_Margin mgWidget = GetMargin(); + if (mgWidget) { + float fLeftInset, fTopInset, fRightInset, fBottomInset; + mgWidget.GetLeftInset(fLeftInset); + mgWidget.GetTopInset(fTopInset); + mgWidget.GetRightInset(fRightInset); + mgWidget.GetBottomInset(fBottomInset); + size.width += fLeftInset + fRightInset; + size.height += fTopInset + fBottomInset; + } + CXFA_Para para = GetPara(); + if (para) + size.width += para.GetMarginLeft() + para.GetTextIndent(); + + float fVal = 0; + float fMin = 0; + float fMax = 0; + if (GetWidth(fVal)) { + size.width = fVal; + } else { + if (GetMinWidth(fMin)) + size.width = std::max(size.width, fMin); + if (GetMaxWidth(fMax) && fMax > 0) + size.width = std::min(size.width, fMax); + } + fVal = 0; + fMin = 0; + fMax = 0; + if (GetHeight(fVal)) { + size.height = fVal; + } else { + if (GetMinHeight(fMin)) + size.height = std::max(size.height, fMin); + if (GetMaxHeight(fMax) && fMax > 0) + size.height = std::min(size.height, fMax); + } + return true; +} + +void CXFA_WidgetAcc::CalculateTextContentSize(CFX_SizeF& size) { + float fFontSize = GetFontSize(); + CFX_WideString wsText; + GetValue(wsText, XFA_VALUEPICTURE_Display); + if (wsText.IsEmpty()) { + size.height += fFontSize; + return; + } + + wchar_t wcEnter = '\n'; + wchar_t wsLast = wsText.GetAt(wsText.GetLength() - 1); + if (wsLast == wcEnter) + wsText = wsText + wcEnter; + + CXFA_FieldLayoutData* layoutData = + static_cast<CXFA_FieldLayoutData*>(m_pLayoutData.get()); + if (!layoutData->m_pTextOut) { + layoutData->m_pTextOut = pdfium::MakeUnique<CFDE_TextOut>(); + CFDE_TextOut* pTextOut = layoutData->m_pTextOut.get(); + pTextOut->SetFont(GetFDEFont()); + pTextOut->SetFontSize(fFontSize); + pTextOut->SetLineBreakTolerance(fFontSize * 0.2f); + pTextOut->SetLineSpace(GetLineHeight()); + uint32_t dwStyles = FDE_TTOSTYLE_LastLineHeight; + if (GetUIType() == XFA_Element::TextEdit && IsMultiLine()) + dwStyles |= FDE_TTOSTYLE_LineWrap; + + pTextOut->SetStyles(dwStyles); + } + layoutData->m_pTextOut->CalcLogicSize(wsText.c_str(), wsText.GetLength(), + size); +} + +bool CXFA_WidgetAcc::CalculateTextEditAutoSize(CFX_SizeF& size) { + if (size.width > 0) { + CFX_SizeF szOrz = size; + CFX_SizeF szCap; + CalcCaptionSize(szCap); + bool bCapExit = szCap.width > 0.01 && szCap.height > 0.01; + int32_t iCapPlacement = XFA_ATTRIBUTEENUM_Unknown; + if (bCapExit) { + iCapPlacement = GetCaption().GetPlacementType(); + switch (iCapPlacement) { + case XFA_ATTRIBUTEENUM_Left: + case XFA_ATTRIBUTEENUM_Right: + case XFA_ATTRIBUTEENUM_Inline: { + size.width -= szCap.width; + } + default: + break; + } + } + CFX_RectF rtUIMargin = GetUIMargin(); + size.width -= rtUIMargin.left + rtUIMargin.width; + CXFA_Margin mgWidget = GetMargin(); + if (mgWidget) { + float fLeftInset, fRightInset; + mgWidget.GetLeftInset(fLeftInset); + mgWidget.GetRightInset(fRightInset); + size.width -= fLeftInset + fRightInset; + } + CalculateTextContentSize(size); + size.height += rtUIMargin.top + rtUIMargin.height; + if (bCapExit) { + switch (iCapPlacement) { + case XFA_ATTRIBUTEENUM_Left: + case XFA_ATTRIBUTEENUM_Right: + case XFA_ATTRIBUTEENUM_Inline: { + size.height = std::max(size.height, szCap.height); + } break; + case XFA_ATTRIBUTEENUM_Top: + case XFA_ATTRIBUTEENUM_Bottom: { + size.height += szCap.height; + } + default: + break; + } + } + size.width = szOrz.width; + return CalculateWidgetAutoSize(size); + } + CalculateTextContentSize(size); + return CalculateFieldAutoSize(size); +} + +bool CXFA_WidgetAcc::CalculateCheckButtonAutoSize(CFX_SizeF& size) { + float fCheckSize = GetCheckButtonSize(); + size = CFX_SizeF(fCheckSize, fCheckSize); + return CalculateFieldAutoSize(size); +} + +bool CXFA_WidgetAcc::CalculatePushButtonAutoSize(CFX_SizeF& size) { + CalcCaptionSize(size); + return CalculateWidgetAutoSize(size); +} + +bool CXFA_WidgetAcc::CalculateImageAutoSize(CFX_SizeF& size) { + if (!GetImageImage()) + LoadImageImage(); + + size.clear(); + CFX_RetainPtr<CFX_DIBitmap> pBitmap = GetImageImage(); + if (pBitmap) { + int32_t iImageXDpi = 0; + int32_t iImageYDpi = 0; + GetImageDpi(iImageXDpi, iImageYDpi); + CFX_RectF rtImage( + 0, 0, XFA_UnitPx2Pt((float)pBitmap->GetWidth(), (float)iImageXDpi), + XFA_UnitPx2Pt((float)pBitmap->GetHeight(), (float)iImageYDpi)); + + CFX_RectF rtFit; + if (GetWidth(rtFit.width)) + GetWidthWithoutMargin(rtFit.width); + else + rtFit.width = rtImage.width; + + if (GetHeight(rtFit.height)) + GetHeightWithoutMargin(rtFit.height); + else + rtFit.height = rtImage.height; + + size = rtFit.Size(); + } + return CalculateWidgetAutoSize(size); +} + +bool CXFA_WidgetAcc::CalculateImageEditAutoSize(CFX_SizeF& size) { + if (!GetImageEditImage()) + LoadImageEditImage(); + + size.clear(); + CFX_RetainPtr<CFX_DIBitmap> pBitmap = GetImageEditImage(); + if (pBitmap) { + int32_t iImageXDpi = 0; + int32_t iImageYDpi = 0; + GetImageEditDpi(iImageXDpi, iImageYDpi); + CFX_RectF rtImage( + 0, 0, XFA_UnitPx2Pt((float)pBitmap->GetWidth(), (float)iImageXDpi), + XFA_UnitPx2Pt((float)pBitmap->GetHeight(), (float)iImageYDpi)); + + CFX_RectF rtFit; + if (GetWidth(rtFit.width)) + GetWidthWithoutMargin(rtFit.width); + else + rtFit.width = rtImage.width; + + if (GetHeight(rtFit.height)) + GetHeightWithoutMargin(rtFit.height); + else + rtFit.height = rtImage.height; + + size.width = rtFit.width; + size.height = rtFit.height; + } + return CalculateFieldAutoSize(size); +} + +bool CXFA_WidgetAcc::LoadImageImage() { + InitLayoutData(); + return static_cast<CXFA_ImageLayoutData*>(m_pLayoutData.get()) + ->LoadImageData(this); +} + +bool CXFA_WidgetAcc::LoadImageEditImage() { + InitLayoutData(); + return static_cast<CXFA_ImageEditData*>(m_pLayoutData.get()) + ->LoadImageData(this); +} + +void CXFA_WidgetAcc::GetImageDpi(int32_t& iImageXDpi, int32_t& iImageYDpi) { + CXFA_ImageLayoutData* pData = + static_cast<CXFA_ImageLayoutData*>(m_pLayoutData.get()); + iImageXDpi = pData->m_iImageXDpi; + iImageYDpi = pData->m_iImageYDpi; +} + +void CXFA_WidgetAcc::GetImageEditDpi(int32_t& iImageXDpi, int32_t& iImageYDpi) { + CXFA_ImageEditData* pData = + static_cast<CXFA_ImageEditData*>(m_pLayoutData.get()); + iImageXDpi = pData->m_iImageXDpi; + iImageYDpi = pData->m_iImageYDpi; +} + +bool CXFA_WidgetAcc::CalculateTextAutoSize(CFX_SizeF& size) { + LoadText(); + CXFA_TextLayout* pTextLayout = + static_cast<CXFA_TextLayoutData*>(m_pLayoutData.get())->GetTextLayout(); + if (pTextLayout) { + size.width = pTextLayout->StartLayout(size.width); + size.height = pTextLayout->GetLayoutHeight(); + } + return CalculateWidgetAutoSize(size); +} + +void CXFA_WidgetAcc::LoadText() { + InitLayoutData(); + static_cast<CXFA_TextLayoutData*>(m_pLayoutData.get())->LoadText(this); +} + +float CXFA_WidgetAcc::CalculateWidgetAutoWidth(float fWidthCalc) { + CXFA_Margin mgWidget = GetMargin(); + if (mgWidget) { + float fLeftInset, fRightInset; + mgWidget.GetLeftInset(fLeftInset); + mgWidget.GetRightInset(fRightInset); + fWidthCalc += fLeftInset + fRightInset; + } + + float fMin = 0, fMax = 0; + if (GetMinWidth(fMin)) + fWidthCalc = std::max(fWidthCalc, fMin); + if (GetMaxWidth(fMax) && fMax > 0) + fWidthCalc = std::min(fWidthCalc, fMax); + + return fWidthCalc; +} + +float CXFA_WidgetAcc::GetWidthWithoutMargin(float fWidthCalc) { + CXFA_Margin mgWidget = GetMargin(); + if (mgWidget) { + float fLeftInset, fRightInset; + mgWidget.GetLeftInset(fLeftInset); + mgWidget.GetRightInset(fRightInset); + fWidthCalc -= fLeftInset + fRightInset; + } + return fWidthCalc; +} + +float CXFA_WidgetAcc::CalculateWidgetAutoHeight(float fHeightCalc) { + CXFA_Margin mgWidget = GetMargin(); + if (mgWidget) { + float fTopInset, fBottomInset; + mgWidget.GetTopInset(fTopInset); + mgWidget.GetBottomInset(fBottomInset); + fHeightCalc += fTopInset + fBottomInset; + } + + float fMin = 0, fMax = 0; + if (GetMinHeight(fMin)) + fHeightCalc = std::max(fHeightCalc, fMin); + if (GetMaxHeight(fMax) && fMax > 0) + fHeightCalc = std::min(fHeightCalc, fMax); + + return fHeightCalc; +} + +float CXFA_WidgetAcc::GetHeightWithoutMargin(float fHeightCalc) { + CXFA_Margin mgWidget = GetMargin(); + if (mgWidget) { + float fTopInset, fBottomInset; + mgWidget.GetTopInset(fTopInset); + mgWidget.GetBottomInset(fBottomInset); + fHeightCalc -= fTopInset + fBottomInset; + } + return fHeightCalc; +} + +void CXFA_WidgetAcc::StartWidgetLayout(float& fCalcWidth, float& fCalcHeight) { + InitLayoutData(); + XFA_Element eUIType = GetUIType(); + if (eUIType == XFA_Element::Text) { + m_pLayoutData->m_fWidgetHeight = -1; + GetHeight(m_pLayoutData->m_fWidgetHeight); + StartTextLayout(fCalcWidth, fCalcHeight); + return; + } + if (fCalcWidth > 0 && fCalcHeight > 0) + return; + + m_pLayoutData->m_fWidgetHeight = -1; + float fWidth = 0; + if (fCalcWidth > 0 && fCalcHeight < 0) { + if (!GetHeight(fCalcHeight)) + CalculateAccWidthAndHeight(eUIType, fCalcWidth, fCalcHeight); + + m_pLayoutData->m_fWidgetHeight = fCalcHeight; + return; + } + if (fCalcWidth < 0 && fCalcHeight < 0) { + if (!GetWidth(fWidth) || !GetHeight(fCalcHeight)) + CalculateAccWidthAndHeight(eUIType, fWidth, fCalcHeight); + + fCalcWidth = fWidth; + } + m_pLayoutData->m_fWidgetHeight = fCalcHeight; +} + +void CXFA_WidgetAcc::CalculateAccWidthAndHeight(XFA_Element eUIType, + float& fWidth, + float& fCalcHeight) { + CFX_SizeF sz(fWidth, m_pLayoutData->m_fWidgetHeight); + switch (eUIType) { + case XFA_Element::Barcode: + case XFA_Element::ChoiceList: + case XFA_Element::Signature: + CalculateFieldAutoSize(sz); + break; + case XFA_Element::ImageEdit: + CalculateImageEditAutoSize(sz); + break; + case XFA_Element::Button: + CalculatePushButtonAutoSize(sz); + break; + case XFA_Element::CheckButton: + CalculateCheckButtonAutoSize(sz); + break; + case XFA_Element::DateTimeEdit: + case XFA_Element::NumericEdit: + case XFA_Element::PasswordEdit: + case XFA_Element::TextEdit: + CalculateTextEditAutoSize(sz); + break; + case XFA_Element::Image: + CalculateImageAutoSize(sz); + break; + case XFA_Element::Arc: + case XFA_Element::Line: + case XFA_Element::Rectangle: + case XFA_Element::Subform: + case XFA_Element::ExclGroup: + CalculateWidgetAutoSize(sz); + break; + default: + break; + } + fWidth = sz.width; + m_pLayoutData->m_fWidgetHeight = sz.height; + fCalcHeight = sz.height; +} + +bool CXFA_WidgetAcc::FindSplitPos(int32_t iBlockIndex, float& fCalcHeight) { + XFA_Element eUIType = GetUIType(); + if (eUIType == XFA_Element::Subform) + return false; + + if (eUIType != XFA_Element::Text && eUIType != XFA_Element::TextEdit && + eUIType != XFA_Element::NumericEdit && + eUIType != XFA_Element::PasswordEdit) { + fCalcHeight = 0; + return true; + } + + float fTopInset = 0; + float fBottomInset = 0; + if (iBlockIndex == 0) { + CXFA_Margin mgWidget = GetMargin(); + if (mgWidget) { + mgWidget.GetTopInset(fTopInset); + mgWidget.GetBottomInset(fBottomInset); + } + CFX_RectF rtUIMargin = GetUIMargin(); + fTopInset += rtUIMargin.top; + fBottomInset += rtUIMargin.width; + } + if (eUIType == XFA_Element::Text) { + float fHeight = fCalcHeight; + if (iBlockIndex == 0) { + fCalcHeight = fCalcHeight - fTopInset; + if (fCalcHeight < 0) + fCalcHeight = 0; + } + + CXFA_TextLayout* pTextLayout = + static_cast<CXFA_TextLayoutData*>(m_pLayoutData.get())->GetTextLayout(); + pTextLayout->DoLayout(iBlockIndex, fCalcHeight, fCalcHeight, + m_pLayoutData->m_fWidgetHeight - fTopInset); + if (fCalcHeight != 0) { + if (iBlockIndex == 0) + fCalcHeight = fCalcHeight + fTopInset; + if (fabs(fHeight - fCalcHeight) < XFA_FLOAT_PERCISION) + return false; + } + return true; + } + XFA_ATTRIBUTEENUM iCapPlacement = XFA_ATTRIBUTEENUM_Unknown; + float fCapReserve = 0; + if (iBlockIndex == 0) { + CXFA_Caption caption = GetCaption(); + if (caption && caption.GetPresence() != XFA_ATTRIBUTEENUM_Hidden) { + iCapPlacement = (XFA_ATTRIBUTEENUM)caption.GetPlacementType(); + fCapReserve = caption.GetReserve(); + } + if (iCapPlacement == XFA_ATTRIBUTEENUM_Top && + fCalcHeight < fCapReserve + fTopInset) { + fCalcHeight = 0; + return true; + } + if (iCapPlacement == XFA_ATTRIBUTEENUM_Bottom && + m_pLayoutData->m_fWidgetHeight - fCapReserve - fBottomInset) { + fCalcHeight = 0; + return true; + } + if (iCapPlacement != XFA_ATTRIBUTEENUM_Top) + fCapReserve = 0; + } + CXFA_FieldLayoutData* pFieldData = + static_cast<CXFA_FieldLayoutData*>(m_pLayoutData.get()); + int32_t iLinesCount = 0; + float fHeight = m_pLayoutData->m_fWidgetHeight; + CFX_WideString wsText; + GetValue(wsText, XFA_VALUEPICTURE_Display); + if (wsText.IsEmpty()) { + iLinesCount = 1; + } else { + if (!pFieldData->m_pTextOut) { + float fWidth = 0; + GetWidth(fWidth); + CalculateAccWidthAndHeight(eUIType, fWidth, fHeight); + } + iLinesCount = pFieldData->m_pTextOut->GetTotalLines(); + } + std::vector<float>* pFieldArray = &pFieldData->m_FieldSplitArray; + int32_t iFieldSplitCount = pdfium::CollectionSize<int32_t>(*pFieldArray); + for (int32_t i = 0; i < iBlockIndex * 3; i += 3) { + iLinesCount -= (int32_t)(*pFieldArray)[i + 1]; + fHeight -= (*pFieldArray)[i + 2]; + } + if (iLinesCount == 0) + return false; + + float fLineHeight = GetLineHeight(); + float fFontSize = GetFontSize(); + float fTextHeight = iLinesCount * fLineHeight - fLineHeight + fFontSize; + float fSpaceAbove = 0; + float fStartOffset = 0; + if (fHeight > 0.1f && iBlockIndex == 0) { + fStartOffset = fTopInset; + fHeight -= (fTopInset + fBottomInset); + if (CXFA_Para para = GetPara()) { + fSpaceAbove = para.GetSpaceAbove(); + float fSpaceBelow = para.GetSpaceBelow(); + fHeight -= (fSpaceAbove + fSpaceBelow); + switch (para.GetVerticalAlign()) { + case XFA_ATTRIBUTEENUM_Top: + fStartOffset += fSpaceAbove; + break; + case XFA_ATTRIBUTEENUM_Middle: + fStartOffset += ((fHeight - fTextHeight) / 2 + fSpaceAbove); + break; + case XFA_ATTRIBUTEENUM_Bottom: + fStartOffset += (fHeight - fTextHeight + fSpaceAbove); + break; + } + } + if (fStartOffset < 0.1f) + fStartOffset = 0; + } + for (int32_t i = iBlockIndex - 1; iBlockIndex > 0 && i < iBlockIndex; i++) { + fStartOffset = (*pFieldArray)[i * 3] - (*pFieldArray)[i * 3 + 2]; + if (fStartOffset < 0.1f) + fStartOffset = 0; + } + if (iFieldSplitCount / 3 == (iBlockIndex + 1)) + (*pFieldArray)[0] = fStartOffset; + else + pFieldArray->push_back(fStartOffset); + + XFA_VERSION version = GetDoc()->GetXFADoc()->GetCurVersionMode(); + bool bCanSplitNoContent = false; + XFA_ATTRIBUTEENUM eLayoutMode; + GetNode() + ->GetNodeItem(XFA_NODEITEM_Parent) + ->TryEnum(XFA_ATTRIBUTE_Layout, eLayoutMode, true); + if ((eLayoutMode == XFA_ATTRIBUTEENUM_Position || + eLayoutMode == XFA_ATTRIBUTEENUM_Tb || + eLayoutMode == XFA_ATTRIBUTEENUM_Row || + eLayoutMode == XFA_ATTRIBUTEENUM_Table) && + version > XFA_VERSION_208) { + bCanSplitNoContent = true; + } + if ((eLayoutMode == XFA_ATTRIBUTEENUM_Tb || + eLayoutMode == XFA_ATTRIBUTEENUM_Row || + eLayoutMode == XFA_ATTRIBUTEENUM_Table) && + version <= XFA_VERSION_208) { + if (fStartOffset < fCalcHeight) { + bCanSplitNoContent = true; + } else { + fCalcHeight = 0; + return true; + } + } + if (bCanSplitNoContent) { + if ((fCalcHeight - fTopInset - fSpaceAbove < fLineHeight)) { + fCalcHeight = 0; + return true; + } + if (fStartOffset + XFA_FLOAT_PERCISION >= fCalcHeight) { + if (iFieldSplitCount / 3 == (iBlockIndex + 1)) { + (*pFieldArray)[iBlockIndex * 3 + 1] = 0; + (*pFieldArray)[iBlockIndex * 3 + 2] = fCalcHeight; + } else { + pFieldArray->push_back(0); + pFieldArray->push_back(fCalcHeight); + } + return false; + } + if (fCalcHeight - fStartOffset < fLineHeight) { + fCalcHeight = fStartOffset; + if (iFieldSplitCount / 3 == (iBlockIndex + 1)) { + (*pFieldArray)[iBlockIndex * 3 + 1] = 0; + (*pFieldArray)[iBlockIndex * 3 + 2] = fCalcHeight; + } else { + pFieldArray->push_back(0); + pFieldArray->push_back(fCalcHeight); + } + return true; + } + float fTextNum = + fCalcHeight + XFA_FLOAT_PERCISION - fCapReserve - fStartOffset; + int32_t iLineNum = + (int32_t)((fTextNum + (fLineHeight - fFontSize)) / fLineHeight); + if (iLineNum >= iLinesCount) { + if (fCalcHeight - fStartOffset - fTextHeight >= fFontSize) { + if (iFieldSplitCount / 3 == (iBlockIndex + 1)) { + (*pFieldArray)[iBlockIndex * 3 + 1] = (float)iLinesCount; + (*pFieldArray)[iBlockIndex * 3 + 2] = fCalcHeight; + } else { + pFieldArray->push_back((float)iLinesCount); + pFieldArray->push_back(fCalcHeight); + } + return false; + } + if (fHeight - fStartOffset - fTextHeight < fFontSize) { + iLineNum -= 1; + if (iLineNum == 0) { + fCalcHeight = 0; + return true; + } + } else { + iLineNum = (int32_t)(fTextNum / fLineHeight); + } + } + if (iLineNum > 0) { + float fSplitHeight = iLineNum * fLineHeight + fCapReserve + fStartOffset; + if (iFieldSplitCount / 3 == (iBlockIndex + 1)) { + (*pFieldArray)[iBlockIndex * 3 + 1] = (float)iLineNum; + (*pFieldArray)[iBlockIndex * 3 + 2] = fSplitHeight; + } else { + pFieldArray->push_back((float)iLineNum); + pFieldArray->push_back(fSplitHeight); + } + if (fabs(fSplitHeight - fCalcHeight) < XFA_FLOAT_PERCISION) + return false; + + fCalcHeight = fSplitHeight; + return true; + } + } + fCalcHeight = 0; + return true; +} + +void CXFA_WidgetAcc::InitLayoutData() { + if (m_pLayoutData) + return; + + switch (GetUIType()) { + case XFA_Element::Text: + m_pLayoutData = pdfium::MakeUnique<CXFA_TextLayoutData>(); + return; + case XFA_Element::TextEdit: + m_pLayoutData = pdfium::MakeUnique<CXFA_TextEditData>(); + return; + case XFA_Element::Image: + m_pLayoutData = pdfium::MakeUnique<CXFA_ImageLayoutData>(); + return; + case XFA_Element::ImageEdit: + m_pLayoutData = pdfium::MakeUnique<CXFA_ImageEditData>(); + return; + default: + break; + } + if (GetElementType() == XFA_Element::Field) { + m_pLayoutData = pdfium::MakeUnique<CXFA_FieldLayoutData>(); + return; + } + m_pLayoutData = pdfium::MakeUnique<CXFA_WidgetLayoutData>(); +} + +void CXFA_WidgetAcc::StartTextLayout(float& fCalcWidth, float& fCalcHeight) { + LoadText(); + CXFA_TextLayout* pTextLayout = + static_cast<CXFA_TextLayoutData*>(m_pLayoutData.get())->GetTextLayout(); + float fTextHeight = 0; + if (fCalcWidth > 0 && fCalcHeight > 0) { + float fWidth = GetWidthWithoutMargin(fCalcWidth); + pTextLayout->StartLayout(fWidth); + fTextHeight = fCalcHeight; + fTextHeight = GetHeightWithoutMargin(fTextHeight); + pTextLayout->DoLayout(0, fTextHeight, -1, fTextHeight); + return; + } + if (fCalcWidth > 0 && fCalcHeight < 0) { + float fWidth = GetWidthWithoutMargin(fCalcWidth); + pTextLayout->StartLayout(fWidth); + } + if (fCalcWidth < 0 && fCalcHeight < 0) { + float fMaxWidth = -1; + bool bRet = GetWidth(fMaxWidth); + if (bRet) { + float fWidth = GetWidthWithoutMargin(fMaxWidth); + pTextLayout->StartLayout(fWidth); + } else { + float fWidth = pTextLayout->StartLayout(fMaxWidth); + fMaxWidth = CalculateWidgetAutoWidth(fWidth); + fWidth = GetWidthWithoutMargin(fMaxWidth); + pTextLayout->StartLayout(fWidth); + } + fCalcWidth = fMaxWidth; + } + if (m_pLayoutData->m_fWidgetHeight < 0) { + m_pLayoutData->m_fWidgetHeight = pTextLayout->GetLayoutHeight(); + m_pLayoutData->m_fWidgetHeight = + CalculateWidgetAutoHeight(m_pLayoutData->m_fWidgetHeight); + } + fTextHeight = m_pLayoutData->m_fWidgetHeight; + fTextHeight = GetHeightWithoutMargin(fTextHeight); + pTextLayout->DoLayout(0, fTextHeight, -1, fTextHeight); + fCalcHeight = m_pLayoutData->m_fWidgetHeight; +} + +bool CXFA_WidgetAcc::LoadCaption() { + InitLayoutData(); + return static_cast<CXFA_FieldLayoutData*>(m_pLayoutData.get()) + ->LoadCaption(this); +} + +CXFA_TextLayout* CXFA_WidgetAcc::GetCaptionTextLayout() { + return m_pLayoutData + ? static_cast<CXFA_FieldLayoutData*>(m_pLayoutData.get()) + ->m_pCapTextLayout.get() + : nullptr; +} + +CXFA_TextLayout* CXFA_WidgetAcc::GetTextLayout() { + return m_pLayoutData + ? static_cast<CXFA_TextLayoutData*>(m_pLayoutData.get()) + ->GetTextLayout() + : nullptr; +} + +CFX_RetainPtr<CFX_DIBitmap> CXFA_WidgetAcc::GetImageImage() { + return m_pLayoutData + ? static_cast<CXFA_ImageLayoutData*>(m_pLayoutData.get()) + ->m_pDIBitmap + : nullptr; +} + +CFX_RetainPtr<CFX_DIBitmap> CXFA_WidgetAcc::GetImageEditImage() { + return m_pLayoutData + ? static_cast<CXFA_ImageEditData*>(m_pLayoutData.get()) + ->m_pDIBitmap + : nullptr; +} + +void CXFA_WidgetAcc::SetImageImage( + const CFX_RetainPtr<CFX_DIBitmap>& newImage) { + CXFA_ImageLayoutData* pData = + static_cast<CXFA_ImageLayoutData*>(m_pLayoutData.get()); + if (pData->m_pDIBitmap != newImage) + pData->m_pDIBitmap = newImage; +} + +void CXFA_WidgetAcc::SetImageEditImage( + const CFX_RetainPtr<CFX_DIBitmap>& newImage) { + CXFA_ImageEditData* pData = + static_cast<CXFA_ImageEditData*>(m_pLayoutData.get()); + if (pData->m_pDIBitmap != newImage) + pData->m_pDIBitmap = newImage; +} + +CXFA_WidgetLayoutData* CXFA_WidgetAcc::GetWidgetLayoutData() { + return m_pLayoutData.get(); +} + +CFX_RetainPtr<CFGAS_GEFont> CXFA_WidgetAcc::GetFDEFont() { + CFX_WideStringC wsFontName = L"Courier"; + uint32_t dwFontStyle = 0; + if (CXFA_Font font = GetFont()) { + if (font.IsBold()) + dwFontStyle |= FX_FONTSTYLE_Bold; + if (font.IsItalic()) + dwFontStyle |= FX_FONTSTYLE_Italic; + font.GetTypeface(wsFontName); + } + + auto* pDoc = GetDoc(); + return pDoc->GetApp()->GetXFAFontMgr()->GetFont(pDoc, wsFontName, + dwFontStyle); +} + +float CXFA_WidgetAcc::GetFontSize() { + float fFontSize = 10.0f; + if (CXFA_Font font = GetFont()) + fFontSize = font.GetFontSize(); + return fFontSize < 0.1f ? 10.0f : fFontSize; +} + +float CXFA_WidgetAcc::GetLineHeight() { + float fLineHeight = 0; + if (CXFA_Para para = GetPara()) + fLineHeight = para.GetLineHeight(); + if (fLineHeight < 1) + fLineHeight = GetFontSize() * 1.2f; + return fLineHeight; +} + +FX_ARGB CXFA_WidgetAcc::GetTextColor() { + if (CXFA_Font font = GetFont()) { + return font.GetColor(); + } + return 0xFF000000; +} diff --git a/chromium/third_party/pdfium/xfa/fxfa/fxfa_widget.h b/chromium/third_party/pdfium/xfa/fxfa/cxfa_widgetacc.h index 74c63c9d52e..38b17ef63fa 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/fxfa_widget.h +++ b/chromium/third_party/pdfium/xfa/fxfa/cxfa_widgetacc.h @@ -4,13 +4,14 @@ // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com -#ifndef XFA_FXFA_FXFA_WIDGET_H_ -#define XFA_FXFA_FXFA_WIDGET_H_ +#ifndef XFA_FXFA_CXFA_WIDGETACC_H_ +#define XFA_FXFA_CXFA_WIDGETACC_H_ #include <memory> #include "core/fxcrt/cfx_retain_ptr.h" #include "core/fxcrt/fx_coordinates.h" +#include "core/fxge/dib/cfx_dibitmap.h" #include "core/fxge/fx_dib.h" #include "xfa/fxfa/parser/cxfa_box.h" #include "xfa/fxfa/parser/cxfa_event.h" @@ -51,7 +52,7 @@ class CXFA_WidgetAcc : public CXFA_WidgetData { IXFA_AppProvider* GetAppProvider(); int32_t ProcessEvent(int32_t iActivity, CXFA_EventParam* pEventParam); - int32_t ProcessEvent(CXFA_Event& event, CXFA_EventParam* pEventParam); + int32_t ProcessEvent(const CXFA_Event& event, CXFA_EventParam* pEventParam); int32_t ProcessCalculate(); int32_t ProcessValidate(int32_t iFlags = 0); int32_t ExecuteScript(CXFA_Script script, @@ -59,8 +60,8 @@ class CXFA_WidgetAcc : public CXFA_WidgetData { CFXJSE_Value** pRetValue = nullptr); CXFA_FFWidget* GetNextWidget(CXFA_FFWidget* pWidget); - void StartWidgetLayout(FX_FLOAT& fCalcWidth, FX_FLOAT& fCalcHeight); - bool FindSplitPos(int32_t iBlockIndex, FX_FLOAT& fCalcHeight); + void StartWidgetLayout(float& fCalcWidth, float& fCalcHeight); + bool FindSplitPos(int32_t iBlockIndex, float& fCalcHeight); bool LoadCaption(); void LoadText(); bool LoadImageImage(); @@ -69,20 +70,20 @@ class CXFA_WidgetAcc : public CXFA_WidgetData { void GetImageEditDpi(int32_t& iImageXDpi, int32_t& iImageYDpi); CXFA_TextLayout* GetCaptionTextLayout(); CXFA_TextLayout* GetTextLayout(); - CFX_DIBitmap* GetImageImage(); - CFX_DIBitmap* GetImageEditImage(); - void SetImageImage(CFX_DIBitmap* newImage); - void SetImageEditImage(CFX_DIBitmap* newImage); + CFX_RetainPtr<CFX_DIBitmap> GetImageImage(); + CFX_RetainPtr<CFX_DIBitmap> GetImageEditImage(); + void SetImageImage(const CFX_RetainPtr<CFX_DIBitmap>& newImage); + void SetImageEditImage(const CFX_RetainPtr<CFX_DIBitmap>& newImage); void UpdateUIDisplay(CXFA_FFWidget* pExcept = nullptr); CXFA_Node* GetDatasets(); CFX_RetainPtr<CFGAS_GEFont> GetFDEFont(); - FX_FLOAT GetFontSize(); + float GetFontSize(); FX_ARGB GetTextColor(); - FX_FLOAT GetLineHeight(); + float GetLineHeight(); CXFA_WidgetLayoutData* GetWidgetLayoutData(); - protected: + private: void ProcessScriptTestValidate(CXFA_Validate validate, int32_t iRet, CFXJSE_Value* pRetValue, @@ -102,20 +103,20 @@ class CXFA_WidgetAcc : public CXFA_WidgetData { bool CalculateImageEditAutoSize(CFX_SizeF& size); bool CalculateImageAutoSize(CFX_SizeF& size); bool CalculateTextAutoSize(CFX_SizeF& size); - FX_FLOAT CalculateWidgetAutoHeight(FX_FLOAT fHeightCalc); - FX_FLOAT CalculateWidgetAutoWidth(FX_FLOAT fWidthCalc); - FX_FLOAT GetWidthWithoutMargin(FX_FLOAT fWidthCalc); - FX_FLOAT GetHeightWithoutMargin(FX_FLOAT fHeightCalc); + float CalculateWidgetAutoHeight(float fHeightCalc); + float CalculateWidgetAutoWidth(float fWidthCalc); + float GetWidthWithoutMargin(float fWidthCalc); + float GetHeightWithoutMargin(float fHeightCalc); void CalculateTextContentSize(CFX_SizeF& size); void CalculateAccWidthAndHeight(XFA_Element eUIType, - FX_FLOAT& fWidth, - FX_FLOAT& fCalcHeight); + float& fWidth, + float& fCalcHeight); void InitLayoutData(); - void StartTextLayout(FX_FLOAT& fCalcWidth, FX_FLOAT& fCalcHeight); + void StartTextLayout(float& fCalcWidth, float& fCalcHeight); CXFA_FFDocView* m_pDocView; std::unique_ptr<CXFA_WidgetLayoutData> m_pLayoutData; uint32_t m_nRecursionDepth; }; -#endif // XFA_FXFA_FXFA_WIDGET_H_ +#endif // XFA_FXFA_CXFA_WIDGETACC_H_ diff --git a/chromium/third_party/pdfium/xfa/fxfa/cxfa_widgetacciterator.cpp b/chromium/third_party/pdfium/xfa/fxfa/cxfa_widgetacciterator.cpp new file mode 100644 index 00000000000..373fba99dc8 --- /dev/null +++ b/chromium/third_party/pdfium/xfa/fxfa/cxfa_widgetacciterator.cpp @@ -0,0 +1,31 @@ +// Copyright 2017 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#include "xfa/fxfa/cxfa_widgetacciterator.h" + +#include "xfa/fxfa/cxfa_widgetacc.h" + +CXFA_WidgetAccIterator::CXFA_WidgetAccIterator(CXFA_Node* pTravelRoot) + : m_ContentIterator(pTravelRoot), m_pCurWidgetAcc(nullptr) {} + +CXFA_WidgetAccIterator::~CXFA_WidgetAccIterator() {} + +CXFA_WidgetAcc* CXFA_WidgetAccIterator::MoveToNext() { + CXFA_Node* pItem = m_pCurWidgetAcc ? m_ContentIterator.MoveToNext() + : m_ContentIterator.GetCurrent(); + while (pItem) { + m_pCurWidgetAcc = static_cast<CXFA_WidgetAcc*>(pItem->GetWidgetData()); + if (m_pCurWidgetAcc) + return m_pCurWidgetAcc; + pItem = m_ContentIterator.MoveToNext(); + } + return nullptr; +} + +void CXFA_WidgetAccIterator::SkipTree() { + m_ContentIterator.SkipChildrenAndMoveToNext(); + m_pCurWidgetAcc = nullptr; +} diff --git a/chromium/third_party/pdfium/xfa/fxfa/cxfa_widgetacciterator.h b/chromium/third_party/pdfium/xfa/fxfa/cxfa_widgetacciterator.h new file mode 100644 index 00000000000..ab18e833c2c --- /dev/null +++ b/chromium/third_party/pdfium/xfa/fxfa/cxfa_widgetacciterator.h @@ -0,0 +1,28 @@ +// Copyright 2017 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#ifndef XFA_FXFA_CXFA_WIDGETACCITERATOR_H_ +#define XFA_FXFA_CXFA_WIDGETACCITERATOR_H_ + +#include "xfa/fxfa/parser/cxfa_traversestrategy_xfacontainernode.h" + +class CXFA_Node; +class CXFA_WidgetAcc; + +class CXFA_WidgetAccIterator { + public: + explicit CXFA_WidgetAccIterator(CXFA_Node* pTravelRoot); + ~CXFA_WidgetAccIterator(); + + CXFA_WidgetAcc* MoveToNext(); + void SkipTree(); + + private: + CXFA_ContainerIterator m_ContentIterator; + CXFA_WidgetAcc* m_pCurWidgetAcc; // not owned. +}; + +#endif // XFA_FXFA_CXFA_WIDGETACCITERATOR_H_ diff --git a/chromium/third_party/pdfium/xfa/fxfa/fm2js/xfa_error.cpp b/chromium/third_party/pdfium/xfa/fxfa/fm2js/xfa_error.cpp index 020d9bc5091..1d31ce6958f 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/fm2js/xfa_error.cpp +++ b/chromium/third_party/pdfium/xfa/fxfa/fm2js/xfa_error.cpp @@ -6,12 +6,14 @@ #include "xfa/fxfa/fm2js/xfa_error.h" -const FX_WCHAR kFMErrUnsupportedChar[] = L"unsupported char '%c'"; -const FX_WCHAR kFMErrBadSuffixNumber[] = L"bad suffix on number"; -const FX_WCHAR kFMErrExpectedIdentifier[] = +const wchar_t kFMErrUnsupportedChar[] = L"unsupported char '%c'"; +const wchar_t kFMErrBadSuffixNumber[] = L"bad suffix on number"; +const wchar_t kFMErrExpectedIdentifier[] = L"expected identifier instead of '%s'"; -const FX_WCHAR kFMErrExpectedToken[] = L"expected '%s' instead of '%s'"; -const FX_WCHAR kFMErrExpectedEndIf[] = L"expected 'endif' instead of '%s'"; -const FX_WCHAR kFMErrUnexpectedExpression[] = L"unexpected expression '%s'"; -const FX_WCHAR kFMErrExpectedNonEmptyExpression[] = +const wchar_t kFMErrExpectedToken[] = L"expected '%s' instead of '%s'"; +const wchar_t kFMErrExpectedEndIf[] = L"expected 'endif' instead of '%s'"; +const wchar_t kFMErrUnexpectedExpression[] = L"unexpected expression '%s'"; +const wchar_t kFMErrExpectedNonEmptyExpression[] = L"expected non-empty expression"; +const wchar_t kFMErrLongAssignmentChain[] = + L"long assignment chains are unsupported"; diff --git a/chromium/third_party/pdfium/xfa/fxfa/fm2js/xfa_error.h b/chromium/third_party/pdfium/xfa/fxfa/fm2js/xfa_error.h index 5e3fbbe1bab..b6621da4401 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/fm2js/xfa_error.h +++ b/chromium/third_party/pdfium/xfa/fxfa/fm2js/xfa_error.h @@ -10,13 +10,14 @@ #include "core/fxcrt/fx_string.h" #include "core/fxcrt/fx_system.h" -extern const FX_WCHAR kFMErrUnsupportedChar[]; -extern const FX_WCHAR kFMErrBadSuffixNumber[]; -extern const FX_WCHAR kFMErrExpectedIdentifier[]; -extern const FX_WCHAR kFMErrExpectedToken[]; -extern const FX_WCHAR kFMErrExpectedEndIf[]; -extern const FX_WCHAR kFMErrUnexpectedExpression[]; -extern const FX_WCHAR kFMErrExpectedNonEmptyExpression[]; +extern const wchar_t kFMErrUnsupportedChar[]; +extern const wchar_t kFMErrBadSuffixNumber[]; +extern const wchar_t kFMErrExpectedIdentifier[]; +extern const wchar_t kFMErrExpectedToken[]; +extern const wchar_t kFMErrExpectedEndIf[]; +extern const wchar_t kFMErrUnexpectedExpression[]; +extern const wchar_t kFMErrExpectedNonEmptyExpression[]; +extern const wchar_t kFMErrLongAssignmentChain[]; class CXFA_FMErrorInfo { public: diff --git a/chromium/third_party/pdfium/xfa/fxfa/fm2js/xfa_expression.cpp b/chromium/third_party/pdfium/xfa/fxfa/fm2js/xfa_expression.cpp index 32db6d24df0..c1e451eade0 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/fm2js/xfa_expression.cpp +++ b/chromium/third_party/pdfium/xfa/fxfa/fm2js/xfa_expression.cpp @@ -12,10 +12,10 @@ namespace { -const FX_WCHAR RUNTIMEBLOCKTEMPARRAY[] = +const wchar_t RUNTIMEBLOCKTEMPARRAY[] = L"foxit_xfa_formcalc_runtime_block_temp_array"; -const FX_WCHAR RUNTIMEBLOCKTEMPARRAYINDEX[] = +const wchar_t RUNTIMEBLOCKTEMPARRAYINDEX[] = L"foxit_xfa_formcalc_runtime_block_temp_array_index"; } // namespace diff --git a/chromium/third_party/pdfium/xfa/fxfa/fm2js/xfa_expression.h b/chromium/third_party/pdfium/xfa/fxfa/fm2js/xfa_expression.h index 6b55ea58155..9177c305d2c 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/fm2js/xfa_expression.h +++ b/chromium/third_party/pdfium/xfa/fxfa/fm2js/xfa_expression.h @@ -33,7 +33,7 @@ class CXFA_FMExpression { uint32_t GetLine() { return m_line; } XFA_FM_EXPTYPE GetExpType() const { return m_type; } - protected: + private: XFA_FM_EXPTYPE m_type; uint32_t m_line; }; diff --git a/chromium/third_party/pdfium/xfa/fxfa/fm2js/xfa_fm2jscontext.cpp b/chromium/third_party/pdfium/xfa/fxfa/fm2js/xfa_fm2jscontext.cpp index e8cb2d0279a..56a99157d33 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/fm2js/xfa_fm2jscontext.cpp +++ b/chromium/third_party/pdfium/xfa/fxfa/fm2js/xfa_fm2jscontext.cpp @@ -10,17 +10,21 @@ #include <algorithm> +#include "core/fxcrt/cfx_decimal.h" #include "core/fxcrt/fx_ext.h" #include "fxjs/cfxjse_arguments.h" #include "fxjs/cfxjse_class.h" #include "fxjs/cfxjse_value.h" #include "third_party/base/ptr_util.h" -#include "xfa/fgas/localization/fgas_locale.h" +#include "third_party/base/stl_util.h" #include "xfa/fxfa/app/xfa_ffnotify.h" #include "xfa/fxfa/fm2js/xfa_program.h" #include "xfa/fxfa/parser/cxfa_document.h" +#include "xfa/fxfa/parser/cxfa_localevalue.h" +#include "xfa/fxfa/parser/cxfa_node.h" #include "xfa/fxfa/parser/cxfa_scriptcontext.h" -#include "xfa/fxfa/parser/xfa_localevalue.h" +#include "xfa/fxfa/parser/cxfa_timezoneprovider.h" +#include "xfa/fxfa/parser/xfa_utils.h" namespace { @@ -28,7 +32,7 @@ const double kFinancialPrecision = 0.00000001; struct XFA_FMHtmlReserveCode { uint32_t m_uCode; - const FX_WCHAR* m_htmlReserve; + const wchar_t* m_htmlReserve; }; struct XFA_FMHtmlHashedReserveCode { @@ -384,7 +388,7 @@ void AlternateDateTimeSymbols(CFX_WideString& wsPattern, bool bEscape = false; int32_t i = 0; while (i < nLength) { - FX_WCHAR wc = wsPattern[i]; + wchar_t wc = wsPattern[i]; if (wc == L'\'') { bInConstRange = !bInConstRange; if (bEscape) { @@ -442,11 +446,11 @@ bool PatternStringType(const CFX_ByteStringC& szPattern, patternType = XFA_VT_NULL; wsPattern.MakeLower(); - const FX_WCHAR* pData = wsPattern.c_str(); + const wchar_t* pData = wsPattern.c_str(); int32_t iLength = wsPattern.GetLength(); int32_t iIndex = 0; bool bSingleQuotation = false; - FX_WCHAR patternChar; + wchar_t patternChar; while (iIndex < iLength) { patternChar = pData[iIndex]; if (patternChar == 0x27) { @@ -455,7 +459,7 @@ bool PatternStringType(const CFX_ByteStringC& szPattern, (patternChar == 'y' || patternChar == 'j')) { patternType = XFA_VT_DATE; iIndex++; - FX_WCHAR timePatternChar; + wchar_t timePatternChar; while (iIndex < iLength) { timePatternChar = pData[iIndex]; if (timePatternChar == 0x27) { @@ -505,6 +509,40 @@ bool IsWhitespace(char c) { c == 0x0D; } +IFX_Locale* LocaleFromString(CXFA_Document* pDoc, + CXFA_LocaleMgr* pMgr, + const CFX_ByteStringC& szLocale) { + if (!szLocale.IsEmpty()) + return pMgr->GetLocaleByName(CFX_WideString::FromUTF8(szLocale)); + + CXFA_Node* pThisNode = ToNode(pDoc->GetScriptContext()->GetThisObject()); + ASSERT(pThisNode); + return CXFA_WidgetData(pThisNode).GetLocal(); +} + +CFX_WideString FormatFromString(IFX_Locale* pLocale, + const CFX_ByteStringC& szFormat) { + if (!szFormat.IsEmpty()) + return CFX_WideString::FromUTF8(szFormat); + + return pLocale->GetDatePattern(FX_LOCALEDATETIMESUBCATEGORY_Default); +} + +FX_LOCALEDATETIMESUBCATEGORY SubCategoryFromInt(int32_t iStyle) { + switch (iStyle) { + case 1: + return FX_LOCALEDATETIMESUBCATEGORY_Short; + case 3: + return FX_LOCALEDATETIMESUBCATEGORY_Long; + case 4: + return FX_LOCALEDATETIMESUBCATEGORY_Full; + case 0: + case 2: + default: + return FX_LOCALEDATETIMESUBCATEGORY_Medium; + } +} + } // namespace // static @@ -522,7 +560,7 @@ void CXFA_FM2JSContext::Abs(CFXJSE_Value* pThis, return; } - FX_DOUBLE dValue = ValueToDouble(pThis, argOne.get()); + double dValue = ValueToDouble(pThis, argOne.get()); if (dValue < 0) dValue = -dValue; @@ -541,7 +579,7 @@ void CXFA_FM2JSContext::Avg(CFXJSE_Value* pThis, v8::Isolate* pIsolate = ToJSContext(pThis, nullptr)->GetScriptRuntime(); uint32_t uCount = 0; - FX_DOUBLE dSum = 0.0; + double dSum = 0.0; for (int32_t i = 0; i < argc; i++) { std::unique_ptr<CFXJSE_Value> argValue = args.GetValue(i); if (argValue->IsNull()) @@ -611,8 +649,7 @@ void CXFA_FM2JSContext::Ceil(CFXJSE_Value* pThis, return; } - args.GetReturnValue()->SetFloat( - FXSYS_ceil(ValueToFloat(pThis, argValue.get()))); + args.GetReturnValue()->SetFloat(ceil(ValueToFloat(pThis, argValue.get()))); } // static @@ -684,8 +721,7 @@ void CXFA_FM2JSContext::Floor(CFXJSE_Value* pThis, return; } - args.GetReturnValue()->SetFloat( - FXSYS_floor(ValueToFloat(pThis, argValue.get()))); + args.GetReturnValue()->SetFloat(floor(ValueToFloat(pThis, argValue.get()))); } // static @@ -695,7 +731,7 @@ void CXFA_FM2JSContext::Max(CFXJSE_Value* pThis, CXFA_FM2JSContext* pContext = ToJSContext(pThis, nullptr); v8::Isolate* pIsolate = pContext->GetScriptRuntime(); uint32_t uCount = 0; - FX_DOUBLE dMaxValue = 0.0; + double dMaxValue = 0.0; for (int32_t i = 0; i < args.GetLength(); i++) { std::unique_ptr<CFXJSE_Value> argValue = args.GetValue(i); if (argValue->IsNull()) @@ -723,7 +759,7 @@ void CXFA_FM2JSContext::Max(CFXJSE_Value* pThis, continue; uCount++; - FX_DOUBLE dValue = ValueToDouble(pThis, newPropertyValue.get()); + double dValue = ValueToDouble(pThis, newPropertyValue.get()); dMaxValue = (uCount == 1) ? dValue : std::max(dMaxValue, dValue); } } else { @@ -735,7 +771,7 @@ void CXFA_FM2JSContext::Max(CFXJSE_Value* pThis, continue; uCount++; - FX_DOUBLE dValue = ValueToDouble(pThis, newPropertyValue.get()); + double dValue = ValueToDouble(pThis, newPropertyValue.get()); dMaxValue = (uCount == 1) ? dValue : std::max(dMaxValue, dValue); } } @@ -746,11 +782,11 @@ void CXFA_FM2JSContext::Max(CFXJSE_Value* pThis, continue; uCount++; - FX_DOUBLE dValue = ValueToDouble(pThis, newPropertyValue.get()); + double dValue = ValueToDouble(pThis, newPropertyValue.get()); dMaxValue = (uCount == 1) ? dValue : std::max(dMaxValue, dValue); } else { uCount++; - FX_DOUBLE dValue = ValueToDouble(pThis, argValue.get()); + double dValue = ValueToDouble(pThis, argValue.get()); dMaxValue = (uCount == 1) ? dValue : std::max(dMaxValue, dValue); } } @@ -769,7 +805,7 @@ void CXFA_FM2JSContext::Min(CFXJSE_Value* pThis, CXFA_FM2JSContext* pContext = ToJSContext(pThis, nullptr); v8::Isolate* pIsolate = pContext->GetScriptRuntime(); uint32_t uCount = 0; - FX_DOUBLE dMinValue = 0.0; + double dMinValue = 0.0; for (int32_t i = 0; i < args.GetLength(); i++) { std::unique_ptr<CFXJSE_Value> argValue = args.GetValue(i); if (argValue->IsNull()) @@ -797,7 +833,7 @@ void CXFA_FM2JSContext::Min(CFXJSE_Value* pThis, continue; uCount++; - FX_DOUBLE dValue = ValueToDouble(pThis, newPropertyValue.get()); + double dValue = ValueToDouble(pThis, newPropertyValue.get()); dMinValue = uCount == 1 ? dValue : std::min(dMinValue, dValue); } } else { @@ -809,7 +845,7 @@ void CXFA_FM2JSContext::Min(CFXJSE_Value* pThis, continue; uCount++; - FX_DOUBLE dValue = ValueToDouble(pThis, newPropertyValue.get()); + double dValue = ValueToDouble(pThis, newPropertyValue.get()); dMinValue = uCount == 1 ? dValue : std::min(dMinValue, dValue); } } @@ -820,11 +856,11 @@ void CXFA_FM2JSContext::Min(CFXJSE_Value* pThis, continue; uCount++; - FX_DOUBLE dValue = ValueToDouble(pThis, newPropertyValue.get()); + double dValue = ValueToDouble(pThis, newPropertyValue.get()); dMinValue = uCount == 1 ? dValue : std::min(dMinValue, dValue); } else { uCount++; - FX_DOUBLE dValue = ValueToDouble(pThis, argValue.get()); + double dValue = ValueToDouble(pThis, argValue.get()); dMinValue = uCount == 1 ? dValue : std::min(dMinValue, dValue); } } @@ -854,9 +890,9 @@ void CXFA_FM2JSContext::Mod(CFXJSE_Value* pThis, } bool argOneResult; - FX_DOUBLE dDividend = ExtractDouble(pThis, argOne.get(), &argOneResult); + double dDividend = ExtractDouble(pThis, argOne.get(), &argOneResult); bool argTwoResult; - FX_DOUBLE dDivisor = ExtractDouble(pThis, argTwo.get(), &argTwoResult); + double dDivisor = ExtractDouble(pThis, argTwo.get(), &argTwoResult); if (!argOneResult || !argTwoResult) { pContext->ThrowArgumentMismatchException(); return; @@ -889,7 +925,7 @@ void CXFA_FM2JSContext::Round(CFXJSE_Value* pThis, } bool dValueRet; - FX_DOUBLE dValue = ExtractDouble(pThis, argOne.get(), &dValueRet); + double dValue = ExtractDouble(pThis, argOne.get(), &dValueRet); if (!dValueRet) { pContext->ThrowArgumentMismatchException(); return; @@ -904,17 +940,16 @@ void CXFA_FM2JSContext::Round(CFXJSE_Value* pThis, } bool dPrecisionRet; - FX_DOUBLE dPrecision = ExtractDouble(pThis, argTwo.get(), &dPrecisionRet); + double dPrecision = ExtractDouble(pThis, argTwo.get(), &dPrecisionRet); if (!dPrecisionRet) { pContext->ThrowArgumentMismatchException(); return; } - uPrecision = - static_cast<uint8_t>(std::min(std::max(dPrecision, 0.0), 12.0)); + uPrecision = static_cast<uint8_t>(pdfium::clamp(dPrecision, 0.0, 12.0)); } - CFX_Decimal decimalValue((FX_FLOAT)dValue, uPrecision); + CFX_Decimal decimalValue((float)dValue, uPrecision); CFX_WideString wsValue = decimalValue; args.GetReturnValue()->SetString(wsValue.UTF8Encode().AsStringC()); } @@ -932,7 +967,7 @@ void CXFA_FM2JSContext::Sum(CFXJSE_Value* pThis, CXFA_FM2JSContext* pContext = ToJSContext(pThis, nullptr); v8::Isolate* pIsolate = pContext->GetScriptRuntime(); uint32_t uCount = 0; - FX_DOUBLE dSum = 0.0; + double dSum = 0.0; for (int32_t i = 0; i < argc; i++) { std::unique_ptr<CFXJSE_Value> argValue = args.GetValue(i); if (argValue->IsNull()) @@ -1034,9 +1069,7 @@ void CXFA_FM2JSContext::Date2Num(CFXJSE_Value* pThis, return; } - CFX_ByteString dateString; - ValueToUTF8String(dateValue.get(), dateString); - + CFX_ByteString dateString = ValueToUTF8String(dateValue.get()); CFX_ByteString formatString; if (argc > 1) { std::unique_ptr<CFXJSE_Value> formatValue = GetSimpleValue(pThis, args, 1); @@ -1044,7 +1077,7 @@ void CXFA_FM2JSContext::Date2Num(CFXJSE_Value* pThis, args.GetReturnValue()->SetNull(); return; } - ValueToUTF8String(formatValue.get(), formatString); + formatString = ValueToUTF8String(formatValue.get()); } CFX_ByteString localString; @@ -1054,16 +1087,12 @@ void CXFA_FM2JSContext::Date2Num(CFXJSE_Value* pThis, args.GetReturnValue()->SetNull(); return; } - ValueToUTF8String(localValue.get(), localString); - } - - CFX_ByteString szIsoDateString; - if (!Local2IsoDate(pThis, dateString.AsStringC(), formatString.AsStringC(), - localString.AsStringC(), szIsoDateString)) { - args.GetReturnValue()->SetInteger(0); - return; + localString = ValueToUTF8String(localValue.get()); } + CFX_ByteString szIsoDateString = + Local2IsoDate(pThis, dateString.AsStringC(), formatString.AsStringC(), + localString.AsStringC()); args.GetReturnValue()->SetInteger( DateString2Num(szIsoDateString.AsStringC())); } @@ -1098,11 +1127,11 @@ void CXFA_FM2JSContext::DateFmt(CFXJSE_Value* pThis, args.GetReturnValue()->SetNull(); return; } - ValueToUTF8String(argLocal.get(), szLocal); + szLocal = ValueToUTF8String(argLocal.get()); } - CFX_ByteString formatStr; - GetStandardDateFormat(pThis, iStyle, szLocal.AsStringC(), formatStr); + CFX_ByteString formatStr = + GetStandardDateFormat(pThis, iStyle, szLocal.AsStringC()); args.GetReturnValue()->SetString(formatStr.AsStringC()); } @@ -1115,15 +1144,12 @@ void CXFA_FM2JSContext::IsoDate2Num(CFXJSE_Value* pThis, ->ThrowParamCountMismatchException(L"IsoDate2Num"); return; } - std::unique_ptr<CFXJSE_Value> argOne = GetSimpleValue(pThis, args, 0); if (argOne->IsNull()) { args.GetReturnValue()->SetNull(); return; } - - CFX_ByteString szArgString; - ValueToUTF8String(argOne.get(), szArgString); + CFX_ByteString szArgString = ValueToUTF8String(argOne.get()); args.GetReturnValue()->SetInteger(DateString2Num(szArgString.AsStringC())); } @@ -1145,9 +1171,7 @@ void CXFA_FM2JSContext::IsoTime2Num(CFXJSE_Value* pThis, CXFA_Document* pDoc = pContext->GetDocument(); CXFA_LocaleMgr* pMgr = pDoc->GetLocalMgr(); - - CFX_ByteString szArgString; - ValueToUTF8String(argOne.get(), szArgString); + CFX_ByteString szArgString = ValueToUTF8String(argOne.get()); szArgString = szArgString.Mid(szArgString.Find('T', 0) + 1); if (szArgString.IsEmpty()) { args.GetReturnValue()->SetInteger(0); @@ -1161,19 +1185,16 @@ void CXFA_FM2JSContext::IsoTime2Num(CFXJSE_Value* pThis, return; } - CFX_Unitime uniTime = timeValue.GetTime(); + CFX_DateTime uniTime = timeValue.GetTime(); int32_t hour = uniTime.GetHour(); int32_t min = uniTime.GetMinute(); int32_t second = uniTime.GetSecond(); int32_t milSecond = uniTime.GetMillisecond(); - FX_TIMEZONE tzLocale; - pMgr->GetDefLocale()->GetTimeZone(&tzLocale); - // TODO(dsinclair): See if there is other time conversion code in pdfium and // consolidate. int32_t mins = hour * 60 + min; - mins -= (tzLocale.tzHour * 60); + mins -= (pMgr->GetDefLocale()->GetTimeZone().tzHour * 60); while (mins > 1440) mins -= 1440; while (mins < 0) @@ -1215,11 +1236,11 @@ void CXFA_FM2JSContext::LocalDateFmt(CFXJSE_Value* pThis, args.GetReturnValue()->SetNull(); return; } - ValueToUTF8String(argLocal.get(), szLocal); + szLocal = ValueToUTF8String(argLocal.get()); } - CFX_ByteString formatStr; - GetLocalDateFormat(pThis, iStyle, szLocal.AsStringC(), formatStr, false); + CFX_ByteString formatStr = + GetLocalDateFormat(pThis, iStyle, szLocal.AsStringC(), false); args.GetReturnValue()->SetString(formatStr.AsStringC()); } @@ -1253,11 +1274,11 @@ void CXFA_FM2JSContext::LocalTimeFmt(CFXJSE_Value* pThis, args.GetReturnValue()->SetNull(); return; } - ValueToUTF8String(argLocal.get(), szLocal); + szLocal = ValueToUTF8String(argLocal.get()); } - CFX_ByteString formatStr; - GetLocalTimeFormat(pThis, iStyle, szLocal.AsStringC(), formatStr, false); + CFX_ByteString formatStr = + GetLocalTimeFormat(pThis, iStyle, szLocal.AsStringC(), false); args.GetReturnValue()->SetString(formatStr.AsStringC()); } @@ -1289,7 +1310,7 @@ void CXFA_FM2JSContext::Num2Date(CFXJSE_Value* pThis, args.GetReturnValue()->SetNull(); return; } - ValueToUTF8String(formatValue.get(), formatString); + formatString = ValueToUTF8String(formatValue.get()); } CFX_ByteString localString; @@ -1299,7 +1320,7 @@ void CXFA_FM2JSContext::Num2Date(CFXJSE_Value* pThis, args.GetReturnValue()->SetNull(); return; } - ValueToUTF8String(localValue.get(), localString); + localString = ValueToUTF8String(localValue.get()); } int32_t iYear = 1900; @@ -1396,9 +1417,9 @@ void CXFA_FM2JSContext::Num2Date(CFXJSE_Value* pThis, CFX_ByteString szIsoDateString; szIsoDateString.Format("%d%02d%02d", iYear + i, iMonth, iDay); - CFX_ByteString szLocalDateString; - IsoDate2Local(pThis, szIsoDateString.AsStringC(), formatString.AsStringC(), - localString.AsStringC(), szLocalDateString); + CFX_ByteString szLocalDateString = + IsoDate2Local(pThis, szIsoDateString.AsStringC(), + formatString.AsStringC(), localString.AsStringC()); args.GetReturnValue()->SetString(szLocalDateString.AsStringC()); } @@ -1419,7 +1440,7 @@ void CXFA_FM2JSContext::Num2GMTime(CFXJSE_Value* pThis, return; } int32_t iTime = (int32_t)ValueToFloat(pThis, timeValue.get()); - if (FXSYS_abs(iTime) < 1.0) { + if (abs(iTime) < 1.0) { args.GetReturnValue()->SetNull(); return; } @@ -1431,7 +1452,7 @@ void CXFA_FM2JSContext::Num2GMTime(CFXJSE_Value* pThis, args.GetReturnValue()->SetNull(); return; } - ValueToUTF8String(formatValue.get(), formatString); + formatString = ValueToUTF8String(formatValue.get()); } CFX_ByteString localString; @@ -1441,12 +1462,11 @@ void CXFA_FM2JSContext::Num2GMTime(CFXJSE_Value* pThis, args.GetReturnValue()->SetNull(); return; } - ValueToUTF8String(localValue.get(), localString); + localString = ValueToUTF8String(localValue.get()); } - CFX_ByteString szGMTTimeString; - Num2AllTime(pThis, iTime, formatString.AsStringC(), localString.AsStringC(), - true, szGMTTimeString); + CFX_ByteString szGMTTimeString = Num2AllTime( + pThis, iTime, formatString.AsStringC(), localString.AsStringC(), true); args.GetReturnValue()->SetString(szGMTTimeString.AsStringC()); } @@ -1465,8 +1485,8 @@ void CXFA_FM2JSContext::Num2Time(CFXJSE_Value* pThis, args.GetReturnValue()->SetNull(); return; } - FX_FLOAT fTime = ValueToFloat(pThis, timeValue.get()); - if (FXSYS_fabs(fTime) < 1.0) { + float fTime = ValueToFloat(pThis, timeValue.get()); + if (fabs(fTime) < 1.0) { args.GetReturnValue()->SetNull(); return; } @@ -1478,7 +1498,7 @@ void CXFA_FM2JSContext::Num2Time(CFXJSE_Value* pThis, args.GetReturnValue()->SetNull(); return; } - ValueToUTF8String(formatValue.get(), formatString); + formatString = ValueToUTF8String(formatValue.get()); } CFX_ByteString localString; @@ -1488,12 +1508,12 @@ void CXFA_FM2JSContext::Num2Time(CFXJSE_Value* pThis, args.GetReturnValue()->SetNull(); return; } - ValueToUTF8String(localValue.get(), localString); + localString = ValueToUTF8String(localValue.get()); } - CFX_ByteString szLocalTimeString; - Num2AllTime(pThis, (int32_t)fTime, formatString.AsStringC(), - localString.AsStringC(), false, szLocalTimeString); + CFX_ByteString szLocalTimeString = + Num2AllTime(pThis, static_cast<int32_t>(fTime), formatString.AsStringC(), + localString.AsStringC(), false); args.GetReturnValue()->SetString(szLocalTimeString.AsStringC()); } @@ -1530,7 +1550,7 @@ void CXFA_FM2JSContext::Time2Num(CFXJSE_Value* pThis, args.GetReturnValue()->SetNull(); return; } - ValueToUTF8String(timeValue.get(), timeString); + timeString = ValueToUTF8String(timeValue.get()); CFX_ByteString formatString; if (argc > 1) { @@ -1539,7 +1559,7 @@ void CXFA_FM2JSContext::Time2Num(CFXJSE_Value* pThis, args.GetReturnValue()->SetNull(); return; } - ValueToUTF8String(formatValue.get(), formatString); + formatString = ValueToUTF8String(formatValue.get()); } CFX_ByteString localString; @@ -1549,7 +1569,7 @@ void CXFA_FM2JSContext::Time2Num(CFXJSE_Value* pThis, args.GetReturnValue()->SetNull(); return; } - ValueToUTF8String(localValue.get(), localString); + localString = ValueToUTF8String(localValue.get()); } CXFA_Document* pDoc = ToJSContext(pThis, nullptr)->GetDocument(); @@ -1558,7 +1578,6 @@ void CXFA_FM2JSContext::Time2Num(CFXJSE_Value* pThis, if (localString.IsEmpty()) { CXFA_Node* pThisNode = ToNode(pDoc->GetScriptContext()->GetThisObject()); ASSERT(pThisNode); - CXFA_WidgetData widgetData(pThisNode); pLocale = widgetData.GetLocal(); } else { @@ -1568,7 +1587,7 @@ void CXFA_FM2JSContext::Time2Num(CFXJSE_Value* pThis, CFX_WideString wsFormat; if (formatString.IsEmpty()) - pLocale->GetTimePattern(FX_LOCALEDATETIMESUBCATEGORY_Default, wsFormat); + wsFormat = pLocale->GetTimePattern(FX_LOCALEDATETIMESUBCATEGORY_Default); else wsFormat = CFX_WideString::FromUTF8(formatString.AsStringC()); @@ -1581,17 +1600,14 @@ void CXFA_FM2JSContext::Time2Num(CFXJSE_Value* pThis, return; } - CFX_Unitime uniTime = localeValue.GetTime(); + CFX_DateTime uniTime = localeValue.GetTime(); int32_t hour = uniTime.GetHour(); int32_t min = uniTime.GetMinute(); int32_t second = uniTime.GetSecond(); int32_t milSecond = uniTime.GetMillisecond(); int32_t mins = hour * 60 + min; - FX_TIMEZONE tz; - CXFA_TimeZoneProvider provider; - provider.GetTimeZone(&tz); - mins -= (tz.tzHour * 60); + mins -= (CXFA_TimeZoneProvider().GetTimeZone().tzHour * 60); while (mins > 1440) mins -= 1440; @@ -1633,16 +1649,16 @@ void CXFA_FM2JSContext::TimeFmt(CFXJSE_Value* pThis, args.GetReturnValue()->SetNull(); return; } - ValueToUTF8String(argLocal.get(), szLocal); + szLocal = ValueToUTF8String(argLocal.get()); } - CFX_ByteString formatStr; - GetStandardTimeFormat(pThis, iStyle, szLocal.AsStringC(), formatStr); + CFX_ByteString formatStr = + GetStandardTimeFormat(pThis, iStyle, szLocal.AsStringC()); args.GetReturnValue()->SetString(formatStr.AsStringC()); } // static -bool CXFA_FM2JSContext::IsIsoDateFormat(const FX_CHAR* pData, +bool CXFA_FM2JSContext::IsIsoDateFormat(const char* pData, int32_t iLength, int32_t& iStyle, int32_t& iYear, @@ -1655,7 +1671,7 @@ bool CXFA_FM2JSContext::IsIsoDateFormat(const FX_CHAR* pData, if (iLength < 4) return false; - FX_CHAR strYear[5]; + char strYear[5]; strYear[4] = '\0'; for (int32_t i = 0; i < 4; ++i) { if (pData[i] > '9' || pData[i] < '0') @@ -1670,7 +1686,7 @@ bool CXFA_FM2JSContext::IsIsoDateFormat(const FX_CHAR* pData, iStyle = pData[4] == '-' ? 1 : 0; - FX_CHAR strTemp[3]; + char strTemp[3]; strTemp[2] = '\0'; int32_t iPosOff = iStyle == 0 ? 4 : 5; if ((pData[iPosOff] > '9' || pData[iPosOff] < '0') || @@ -1721,7 +1737,7 @@ bool CXFA_FM2JSContext::IsIsoDateFormat(const FX_CHAR* pData, } // static -bool CXFA_FM2JSContext::IsIsoTimeFormat(const FX_CHAR* pData, +bool CXFA_FM2JSContext::IsIsoTimeFormat(const char* pData, int32_t iLength, int32_t& iHour, int32_t& iMinute, @@ -1738,7 +1754,7 @@ bool CXFA_FM2JSContext::IsIsoTimeFormat(const FX_CHAR* pData, if (!pData) return false; - FX_CHAR strTemp[3]; + char strTemp[3]; strTemp[2] = '\0'; int32_t iZone = 0; int32_t i = 0; @@ -1796,7 +1812,7 @@ bool CXFA_FM2JSContext::IsIsoTimeFormat(const FX_CHAR* pData, } if (pData[iIndex] == '.') { ++iIndex; - FX_CHAR strSec[4]; + char strSec[4]; strSec[3] = '\0'; if (pData[iIndex] > '9' || pData[iIndex] < '0') return false; @@ -1868,7 +1884,7 @@ bool CXFA_FM2JSContext::IsIsoTimeFormat(const FX_CHAR* pData, } // static -bool CXFA_FM2JSContext::IsIsoDateTimeFormat(const FX_CHAR* pData, +bool CXFA_FM2JSContext::IsIsoDateTimeFormat(const char* pData, int32_t iLength, int32_t& iYear, int32_t& iMonth, @@ -1917,195 +1933,76 @@ bool CXFA_FM2JSContext::IsIsoDateTimeFormat(const FX_CHAR* pData, } // static -bool CXFA_FM2JSContext::Local2IsoDate(CFXJSE_Value* pThis, - const CFX_ByteStringC& szDate, - const CFX_ByteStringC& szFormat, - const CFX_ByteStringC& szLocale, - CFX_ByteString& strIsoDate) { +CFX_ByteString CXFA_FM2JSContext::Local2IsoDate( + CFXJSE_Value* pThis, + const CFX_ByteStringC& szDate, + const CFX_ByteStringC& szFormat, + const CFX_ByteStringC& szLocale) { CXFA_Document* pDoc = ToJSContext(pThis, nullptr)->GetDocument(); if (!pDoc) - return false; + return CFX_ByteString(); CXFA_LocaleMgr* pMgr = pDoc->GetLocalMgr(); - IFX_Locale* pLocale = nullptr; - if (szLocale.IsEmpty()) { - CXFA_Node* pThisNode = ToNode(pDoc->GetScriptContext()->GetThisObject()); - ASSERT(pThisNode); - - CXFA_WidgetData widgetData(pThisNode); - pLocale = widgetData.GetLocal(); - } else { - pLocale = pMgr->GetLocaleByName(CFX_WideString::FromUTF8(szLocale)); - } + IFX_Locale* pLocale = LocaleFromString(pDoc, pMgr, szLocale); if (!pLocale) - return false; + return CFX_ByteString(); - CFX_WideString wsFormat; - if (szFormat.IsEmpty()) - pLocale->GetDatePattern(FX_LOCALEDATETIMESUBCATEGORY_Default, wsFormat); - else - wsFormat = CFX_WideString::FromUTF8(szFormat); + CFX_WideString wsFormat = FormatFromString(pLocale, szFormat); + CFX_DateTime dt = + CXFA_LocaleValue(XFA_VT_DATE, CFX_WideString::FromUTF8(szDate), wsFormat, + pLocale, pMgr) + .GetDate(); - CXFA_LocaleValue widgetValue(XFA_VT_DATE, CFX_WideString::FromUTF8(szDate), - wsFormat, pLocale, pMgr); - CFX_Unitime dt = widgetValue.GetDate(); + CFX_ByteString strIsoDate; strIsoDate.Format("%4d-%02d-%02d", dt.GetYear(), dt.GetMonth(), dt.GetDay()); - return true; -} - -// static -bool CXFA_FM2JSContext::Local2IsoTime(CFXJSE_Value* pThis, - const CFX_ByteStringC& szTime, - const CFX_ByteStringC& szFormat, - const CFX_ByteStringC& szLocale, - CFX_ByteString& strIsoTime) { - CXFA_Document* pDoc = ToJSContext(pThis, nullptr)->GetDocument(); - if (!pDoc) - return false; - - CXFA_LocaleMgr* pMgr = pDoc->GetLocalMgr(); - IFX_Locale* pLocale = nullptr; - if (szLocale.IsEmpty()) { - CXFA_Node* pThisNode = ToNode(pDoc->GetScriptContext()->GetThisObject()); - ASSERT(pThisNode); - - CXFA_WidgetData widgetData(pThisNode); - pLocale = widgetData.GetLocal(); - } else { - pLocale = pMgr->GetLocaleByName(CFX_WideString::FromUTF8(szLocale)); - } - if (!pLocale) - return false; - - CFX_WideString wsFormat; - if (szFormat.IsEmpty()) - pLocale->GetTimePattern(FX_LOCALEDATETIMESUBCATEGORY_Default, wsFormat); - else - wsFormat = CFX_WideString::FromUTF8(szFormat); - - wsFormat = L"time{" + wsFormat + L"}"; - CXFA_LocaleValue widgetValue(XFA_VT_TIME, CFX_WideString::FromUTF8(szTime), - wsFormat, pLocale, pMgr); - CFX_Unitime utime = widgetValue.GetTime(); - strIsoTime.Format("%02d:%02d:%02d.%03d", utime.GetHour(), utime.GetMinute(), - utime.GetSecond(), utime.GetMillisecond()); - return true; + return strIsoDate; } // static -bool CXFA_FM2JSContext::IsoDate2Local(CFXJSE_Value* pThis, - const CFX_ByteStringC& szDate, - const CFX_ByteStringC& szFormat, - const CFX_ByteStringC& szLocale, - CFX_ByteString& strLocalDate) { +CFX_ByteString CXFA_FM2JSContext::IsoDate2Local( + CFXJSE_Value* pThis, + const CFX_ByteStringC& szDate, + const CFX_ByteStringC& szFormat, + const CFX_ByteStringC& szLocale) { CXFA_Document* pDoc = ToJSContext(pThis, nullptr)->GetDocument(); if (!pDoc) - return false; + return CFX_ByteString(); CXFA_LocaleMgr* pMgr = pDoc->GetLocalMgr(); - IFX_Locale* pLocale = nullptr; - if (szLocale.IsEmpty()) { - CXFA_Node* pThisNode = ToNode(pDoc->GetScriptContext()->GetThisObject()); - ASSERT(pThisNode); - CXFA_WidgetData widgetData(pThisNode); - pLocale = widgetData.GetLocal(); - } else { - pLocale = pMgr->GetLocaleByName(CFX_WideString::FromUTF8(szLocale)); - } + IFX_Locale* pLocale = LocaleFromString(pDoc, pMgr, szLocale); if (!pLocale) - return false; + return CFX_ByteString(); - CFX_WideString wsFormat; - if (szFormat.IsEmpty()) - pLocale->GetDatePattern(FX_LOCALEDATETIMESUBCATEGORY_Default, wsFormat); - else - wsFormat = CFX_WideString::FromUTF8(szFormat); - - CXFA_LocaleValue widgetValue(XFA_VT_DATE, CFX_WideString::FromUTF8(szDate), - pMgr); + CFX_WideString wsFormat = FormatFromString(pLocale, szFormat); CFX_WideString wsRet; - widgetValue.FormatPatterns(wsRet, wsFormat, pLocale, - XFA_VALUEPICTURE_Display); - strLocalDate = wsRet.UTF8Encode(); - return true; + CXFA_LocaleValue(XFA_VT_DATE, CFX_WideString::FromUTF8(szDate), pMgr) + .FormatPatterns(wsRet, wsFormat, pLocale, XFA_VALUEPICTURE_Display); + return wsRet.UTF8Encode(); } // static -bool CXFA_FM2JSContext::IsoTime2Local(CFXJSE_Value* pThis, - const CFX_ByteStringC& szTime, - const CFX_ByteStringC& szFormat, - const CFX_ByteStringC& szLocale, - CFX_ByteString& strLocalTime) { - CXFA_Document* pDoc = ToJSContext(pThis, nullptr)->GetDocument(); - if (!pDoc) - return false; - - CXFA_LocaleMgr* pMgr = pDoc->GetLocalMgr(); - IFX_Locale* pLocale = nullptr; - if (szLocale.IsEmpty()) { - CXFA_Node* pThisNode = ToNode(pDoc->GetScriptContext()->GetThisObject()); - ASSERT(pThisNode); - CXFA_WidgetData widgetData(pThisNode); - pLocale = widgetData.GetLocal(); - } else { - pLocale = pMgr->GetLocaleByName(CFX_WideString::FromUTF8(szLocale)); - } - if (!pLocale) - return false; - - CFX_WideString wsFormat; - if (szFormat.IsEmpty()) - pLocale->GetTimePattern(FX_LOCALEDATETIMESUBCATEGORY_Default, wsFormat); - else - wsFormat = CFX_WideString::FromUTF8(szFormat); - - wsFormat = L"time{" + wsFormat + L"}"; - CXFA_LocaleValue widgetValue(XFA_VT_TIME, CFX_WideString::FromUTF8(szTime), - pMgr); - CFX_WideString wsRet; - widgetValue.FormatPatterns(wsRet, wsFormat, pLocale, - XFA_VALUEPICTURE_Display); - strLocalTime = wsRet.UTF8Encode(); - return true; -} - -// static -bool CXFA_FM2JSContext::GetGMTTime(CFXJSE_Value* pThis, - const CFX_ByteStringC& szTime, - const CFX_ByteStringC& szFormat, - const CFX_ByteStringC& szLocale, - CFX_ByteString& strGMTTime) { +CFX_ByteString CXFA_FM2JSContext::IsoTime2Local( + CFXJSE_Value* pThis, + const CFX_ByteStringC& szTime, + const CFX_ByteStringC& szFormat, + const CFX_ByteStringC& szLocale) { CXFA_Document* pDoc = ToJSContext(pThis, nullptr)->GetDocument(); if (!pDoc) - return false; + return CFX_ByteString(); CXFA_LocaleMgr* pMgr = pDoc->GetLocalMgr(); - IFX_Locale* pLocale = nullptr; - if (szLocale.IsEmpty()) { - CXFA_Node* pThisNode = ToNode(pDoc->GetScriptContext()->GetThisObject()); - ASSERT(pThisNode); - CXFA_WidgetData widgetData(pThisNode); - pLocale = widgetData.GetLocal(); - } else { - pLocale = pMgr->GetLocaleByName(CFX_WideString::FromUTF8(szLocale)); - } + IFX_Locale* pLocale = LocaleFromString(pDoc, pMgr, szLocale); if (!pLocale) - return false; + return CFX_ByteString(); - CFX_WideString wsFormat; - if (szFormat.IsEmpty()) - pLocale->GetTimePattern(FX_LOCALEDATETIMESUBCATEGORY_Default, wsFormat); - else - wsFormat = CFX_WideString::FromUTF8(szFormat); - - wsFormat = L"time{" + wsFormat + L"}"; + CFX_WideString wsFormat = { + L"time{", FormatFromString(pLocale, szFormat).AsStringC(), L"}"}; CXFA_LocaleValue widgetValue(XFA_VT_TIME, CFX_WideString::FromUTF8(szTime), pMgr); CFX_WideString wsRet; widgetValue.FormatPatterns(wsRet, wsFormat, pLocale, XFA_VALUEPICTURE_Display); - strGMTTime = wsRet.UTF8Encode(); - return true; + return wsRet.UTF8Encode(); } // static @@ -2134,7 +2031,7 @@ int32_t CXFA_FM2JSContext::DateString2Num(const CFX_ByteStringC& szDateString) { } } - FX_FLOAT dDays = 0; + float dDays = 0; int32_t i = 1; if (iYear < 1900) return 0; @@ -2166,130 +2063,73 @@ int32_t CXFA_FM2JSContext::DateString2Num(const CFX_ByteStringC& szDateString) { } // static -void CXFA_FM2JSContext::GetLocalDateFormat(CFXJSE_Value* pThis, - int32_t iStyle, - const CFX_ByteStringC& szLocalStr, - CFX_ByteString& strFormat, - bool bStandard) { - FX_LOCALEDATETIMESUBCATEGORY strStyle; - switch (iStyle) { - case 1: - strStyle = FX_LOCALEDATETIMESUBCATEGORY_Short; - break; - case 3: - strStyle = FX_LOCALEDATETIMESUBCATEGORY_Long; - break; - case 4: - strStyle = FX_LOCALEDATETIMESUBCATEGORY_Full; - break; - case 0: - case 2: - default: - strStyle = FX_LOCALEDATETIMESUBCATEGORY_Medium; - break; - } +CFX_ByteString CXFA_FM2JSContext::GetLocalDateFormat( + CFXJSE_Value* pThis, + int32_t iStyle, + const CFX_ByteStringC& szLocale, + bool bStandard) { CXFA_Document* pDoc = ToJSContext(pThis, nullptr)->GetDocument(); if (!pDoc) - return; + return CFX_ByteString(); - IFX_Locale* pLocale = nullptr; - if (szLocalStr.IsEmpty()) { - CXFA_Node* pThisNode = ToNode(pDoc->GetScriptContext()->GetThisObject()); - ASSERT(pThisNode); - - CXFA_WidgetData widgetData(pThisNode); - pLocale = widgetData.GetLocal(); - } else { - pLocale = pDoc->GetLocalMgr()->GetLocaleByName( - CFX_WideString::FromUTF8(szLocalStr)); - } + CXFA_LocaleMgr* pMgr = pDoc->GetLocalMgr(); + IFX_Locale* pLocale = LocaleFromString(pDoc, pMgr, szLocale); if (!pLocale) - return; + return CFX_ByteString(); - CFX_WideString strRet; - pLocale->GetDatePattern(strStyle, strRet); + CFX_WideString strRet = pLocale->GetDatePattern(SubCategoryFromInt(iStyle)); if (!bStandard) { - CFX_WideString wsSymbols; - pLocale->GetDateTimeSymbols(wsSymbols); - AlternateDateTimeSymbols(strRet, wsSymbols, g_sAltTable_Date); + AlternateDateTimeSymbols(strRet, pLocale->GetDateTimeSymbols(), + g_sAltTable_Date); } - strFormat = strRet.UTF8Encode(); + return strRet.UTF8Encode(); } // static -void CXFA_FM2JSContext::GetLocalTimeFormat(CFXJSE_Value* pThis, - int32_t iStyle, - const CFX_ByteStringC& szLocalStr, - CFX_ByteString& strFormat, - bool bStandard) { - FX_LOCALEDATETIMESUBCATEGORY strStyle; - switch (iStyle) { - case 1: - strStyle = FX_LOCALEDATETIMESUBCATEGORY_Short; - break; - case 3: - strStyle = FX_LOCALEDATETIMESUBCATEGORY_Long; - break; - case 4: - strStyle = FX_LOCALEDATETIMESUBCATEGORY_Full; - break; - case 0: - case 2: - default: - strStyle = FX_LOCALEDATETIMESUBCATEGORY_Medium; - break; - } +CFX_ByteString CXFA_FM2JSContext::GetLocalTimeFormat( + CFXJSE_Value* pThis, + int32_t iStyle, + const CFX_ByteStringC& szLocale, + bool bStandard) { CXFA_Document* pDoc = ToJSContext(pThis, nullptr)->GetDocument(); if (!pDoc) - return; - - IFX_Locale* pLocale = nullptr; - if (szLocalStr.IsEmpty()) { - CXFA_Node* pThisNode = ToNode(pDoc->GetScriptContext()->GetThisObject()); - ASSERT(pThisNode); + return CFX_ByteString(); - CXFA_WidgetData widgetData(pThisNode); - pLocale = widgetData.GetLocal(); - } else { - pLocale = pDoc->GetLocalMgr()->GetLocaleByName( - CFX_WideString::FromUTF8(szLocalStr)); - } + CXFA_LocaleMgr* pMgr = pDoc->GetLocalMgr(); + IFX_Locale* pLocale = LocaleFromString(pDoc, pMgr, szLocale); if (!pLocale) - return; + return CFX_ByteString(); - CFX_WideString strRet; - pLocale->GetTimePattern(strStyle, strRet); + CFX_WideString strRet = pLocale->GetTimePattern(SubCategoryFromInt(iStyle)); if (!bStandard) { - CFX_WideString wsSymbols; - pLocale->GetDateTimeSymbols(wsSymbols); - AlternateDateTimeSymbols(strRet, wsSymbols, g_sAltTable_Time); + AlternateDateTimeSymbols(strRet, pLocale->GetDateTimeSymbols(), + g_sAltTable_Time); } - strFormat = strRet.UTF8Encode(); + return strRet.UTF8Encode(); } // static -void CXFA_FM2JSContext::GetStandardDateFormat(CFXJSE_Value* pThis, - int32_t iStyle, - const CFX_ByteStringC& szLocalStr, - CFX_ByteString& strFormat) { - GetLocalDateFormat(pThis, iStyle, szLocalStr, strFormat, true); +CFX_ByteString CXFA_FM2JSContext::GetStandardDateFormat( + CFXJSE_Value* pThis, + int32_t iStyle, + const CFX_ByteStringC& szLocalStr) { + return GetLocalDateFormat(pThis, iStyle, szLocalStr, true); } // static -void CXFA_FM2JSContext::GetStandardTimeFormat(CFXJSE_Value* pThis, - int32_t iStyle, - const CFX_ByteStringC& szLocalStr, - CFX_ByteString& strFormat) { - GetLocalTimeFormat(pThis, iStyle, szLocalStr, strFormat, true); +CFX_ByteString CXFA_FM2JSContext::GetStandardTimeFormat( + CFXJSE_Value* pThis, + int32_t iStyle, + const CFX_ByteStringC& szLocalStr) { + return GetLocalTimeFormat(pThis, iStyle, szLocalStr, true); } // static -void CXFA_FM2JSContext::Num2AllTime(CFXJSE_Value* pThis, - int32_t iTime, - const CFX_ByteStringC& szFormat, - const CFX_ByteStringC& szLocale, - bool bGM, - CFX_ByteString& strTime) { +CFX_ByteString CXFA_FM2JSContext::Num2AllTime(CFXJSE_Value* pThis, + int32_t iTime, + const CFX_ByteStringC& szFormat, + const CFX_ByteStringC& szLocale, + bool bGM) { int32_t iHour = 0; int32_t iMin = 0; int32_t iSec = 0; @@ -2307,18 +2147,9 @@ void CXFA_FM2JSContext::Num2AllTime(CFXJSE_Value* pThis, iSec += iZoneSec; } - bool iRet = false; CFX_ByteString strIsoTime; strIsoTime.Format("%02d:%02d:%02d", iHour, iMin, iSec); - if (bGM) { - iRet = - GetGMTTime(pThis, strIsoTime.AsStringC(), szFormat, szLocale, strTime); - } else { - iRet = IsoTime2Local(pThis, strIsoTime.AsStringC(), szFormat, szLocale, - strTime); - } - if (!iRet) - strTime = ""; + return IsoTime2Local(pThis, strIsoTime.AsStringC(), szFormat, szLocale); } // static @@ -2354,23 +2185,22 @@ void CXFA_FM2JSContext::Apr(CFXJSE_Value* pThis, return; } - FX_DOUBLE nPrincipal = ValueToDouble(pThis, argOne.get()); - FX_DOUBLE nPayment = ValueToDouble(pThis, argTwo.get()); - FX_DOUBLE nPeriods = ValueToDouble(pThis, argThree.get()); + double nPrincipal = ValueToDouble(pThis, argOne.get()); + double nPayment = ValueToDouble(pThis, argTwo.get()); + double nPeriods = ValueToDouble(pThis, argThree.get()); if (nPrincipal <= 0 || nPayment <= 0 || nPeriods <= 0) { pContext->ThrowArgumentMismatchException(); return; } - FX_DOUBLE r = - 2 * (nPeriods * nPayment - nPrincipal) / (nPeriods * nPrincipal); - FX_DOUBLE nTemp = 1; + double r = 2 * (nPeriods * nPayment - nPrincipal) / (nPeriods * nPrincipal); + double nTemp = 1; for (int32_t i = 0; i < nPeriods; ++i) nTemp *= (1 + r); - FX_DOUBLE nRet = r * nTemp / (nTemp - 1) - nPayment / nPrincipal; + double nRet = r * nTemp / (nTemp - 1) - nPayment / nPrincipal; while (fabs(nRet) > kFinancialPrecision) { - FX_DOUBLE nDerivative = + double nDerivative = ((nTemp + r * nPeriods * (nTemp / (1 + r))) * (nTemp - 1) - (r * nTemp * nPeriods * (nTemp / (1 + r)))) / ((nTemp - 1) * (nTemp - 1)); @@ -2408,17 +2238,16 @@ void CXFA_FM2JSContext::CTerm(CFXJSE_Value* pThis, return; } - FX_FLOAT nRate = ValueToFloat(pThis, argOne.get()); - FX_FLOAT nFutureValue = ValueToFloat(pThis, argTwo.get()); - FX_FLOAT nInitAmount = ValueToFloat(pThis, argThree.get()); + float nRate = ValueToFloat(pThis, argOne.get()); + float nFutureValue = ValueToFloat(pThis, argTwo.get()); + float nInitAmount = ValueToFloat(pThis, argThree.get()); if ((nRate <= 0) || (nFutureValue <= 0) || (nInitAmount <= 0)) { pContext->ThrowArgumentMismatchException(); return; } - args.GetReturnValue()->SetFloat( - FXSYS_log((FX_FLOAT)(nFutureValue / nInitAmount)) / - FXSYS_log((FX_FLOAT)(1 + nRate))); + args.GetReturnValue()->SetFloat(log((float)(nFutureValue / nInitAmount)) / + log((float)(1 + nRate))); } // static @@ -2440,17 +2269,17 @@ void CXFA_FM2JSContext::FV(CFXJSE_Value* pThis, return; } - FX_DOUBLE nAmount = ValueToDouble(pThis, argOne.get()); - FX_DOUBLE nRate = ValueToDouble(pThis, argTwo.get()); - FX_DOUBLE nPeriod = ValueToDouble(pThis, argThree.get()); + double nAmount = ValueToDouble(pThis, argOne.get()); + double nRate = ValueToDouble(pThis, argTwo.get()); + double nPeriod = ValueToDouble(pThis, argThree.get()); if ((nRate < 0) || (nPeriod <= 0) || (nAmount <= 0)) { pContext->ThrowArgumentMismatchException(); return; } - FX_DOUBLE dResult = 0; + double dResult = 0; if (nRate) { - FX_DOUBLE nTemp = 1; + double nTemp = 1; for (int i = 0; i < nPeriod; ++i) { nTemp *= 1 + nRate; } @@ -2484,22 +2313,22 @@ void CXFA_FM2JSContext::IPmt(CFXJSE_Value* pThis, return; } - FX_FLOAT nPrincipalAmount = ValueToFloat(pThis, argOne.get()); - FX_FLOAT nRate = ValueToFloat(pThis, argTwo.get()); - FX_FLOAT nPayment = ValueToFloat(pThis, argThree.get()); - FX_FLOAT nFirstMonth = ValueToFloat(pThis, argFour.get()); - FX_FLOAT nNumberOfMonths = ValueToFloat(pThis, argFive.get()); + float nPrincipalAmount = ValueToFloat(pThis, argOne.get()); + float nRate = ValueToFloat(pThis, argTwo.get()); + float nPayment = ValueToFloat(pThis, argThree.get()); + float nFirstMonth = ValueToFloat(pThis, argFour.get()); + float nNumberOfMonths = ValueToFloat(pThis, argFive.get()); if ((nPrincipalAmount <= 0) || (nRate <= 0) || (nPayment <= 0) || (nFirstMonth < 0) || (nNumberOfMonths < 0)) { pContext->ThrowArgumentMismatchException(); return; } - FX_FLOAT nRateOfMonth = nRate / 12; - int32_t iNums = (int32_t)( - (FXSYS_log10((FX_FLOAT)(nPayment / nPrincipalAmount)) - - FXSYS_log10((FX_FLOAT)(nPayment / nPrincipalAmount - nRateOfMonth))) / - FXSYS_log10((FX_FLOAT)(1 + nRateOfMonth))); + float nRateOfMonth = nRate / 12; + int32_t iNums = + (int32_t)((log10((float)(nPayment / nPrincipalAmount)) - + log10((float)(nPayment / nPrincipalAmount - nRateOfMonth))) / + log10((float)(1 + nRateOfMonth))); int32_t iEnd = std::min((int32_t)(nFirstMonth + nNumberOfMonths - 1), iNums); if (nPayment < nPrincipalAmount * nRateOfMonth) { @@ -2511,7 +2340,7 @@ void CXFA_FM2JSContext::IPmt(CFXJSE_Value* pThis, for (i = 0; i < nFirstMonth - 1; ++i) nPrincipalAmount -= nPayment - nPrincipalAmount * nRateOfMonth; - FX_FLOAT nSum = 0; + float nSum = 0; for (; i < iEnd; ++i) { nSum += nPrincipalAmount * nRateOfMonth; nPrincipalAmount -= nPayment - nPrincipalAmount * nRateOfMonth; @@ -2539,24 +2368,24 @@ void CXFA_FM2JSContext::NPV(CFXJSE_Value* pThis, } } - FX_DOUBLE nRate = ValueToDouble(pThis, argValues[0].get()); + double nRate = ValueToDouble(pThis, argValues[0].get()); if (nRate <= 0) { pContext->ThrowArgumentMismatchException(); return; } - std::vector<FX_DOUBLE> data(argc - 1); + std::vector<double> data(argc - 1); for (int32_t i = 1; i < argc; i++) data.push_back(ValueToDouble(pThis, argValues[i].get())); - FX_DOUBLE nSum = 0; + double nSum = 0; int32_t iIndex = 0; for (int32_t i = 0; i < argc - 1; i++) { - FX_DOUBLE nTemp = 1; + double nTemp = 1; for (int32_t j = 0; j <= i; j++) nTemp *= 1 + nRate; - FX_DOUBLE nNum = data[iIndex++]; + double nNum = data[iIndex++]; nSum += nNum / nTemp; } args.GetReturnValue()->SetDouble(nSum); @@ -2581,16 +2410,16 @@ void CXFA_FM2JSContext::Pmt(CFXJSE_Value* pThis, return; } - FX_FLOAT nPrincipal = ValueToFloat(pThis, argOne.get()); - FX_FLOAT nRate = ValueToFloat(pThis, argTwo.get()); - FX_FLOAT nPeriods = ValueToFloat(pThis, argThree.get()); + float nPrincipal = ValueToFloat(pThis, argOne.get()); + float nRate = ValueToFloat(pThis, argTwo.get()); + float nPeriods = ValueToFloat(pThis, argThree.get()); if ((nPrincipal <= 0) || (nRate <= 0) || (nPeriods <= 0)) { pContext->ThrowArgumentMismatchException(); return; } - FX_FLOAT nTmp = 1 + nRate; - FX_FLOAT nSum = nTmp; + float nTmp = 1 + nRate; + float nSum = nTmp; for (int32_t i = 0; i < nPeriods - 1; ++i) nSum *= nTmp; @@ -2619,22 +2448,22 @@ void CXFA_FM2JSContext::PPmt(CFXJSE_Value* pThis, return; } - FX_FLOAT nPrincipalAmount = ValueToFloat(pThis, argOne.get()); - FX_FLOAT nRate = ValueToFloat(pThis, argTwo.get()); - FX_FLOAT nPayment = ValueToFloat(pThis, argThree.get()); - FX_FLOAT nFirstMonth = ValueToFloat(pThis, argFour.get()); - FX_FLOAT nNumberOfMonths = ValueToFloat(pThis, argFive.get()); + float nPrincipalAmount = ValueToFloat(pThis, argOne.get()); + float nRate = ValueToFloat(pThis, argTwo.get()); + float nPayment = ValueToFloat(pThis, argThree.get()); + float nFirstMonth = ValueToFloat(pThis, argFour.get()); + float nNumberOfMonths = ValueToFloat(pThis, argFive.get()); if ((nPrincipalAmount <= 0) || (nRate <= 0) || (nPayment <= 0) || (nFirstMonth < 0) || (nNumberOfMonths < 0)) { pContext->ThrowArgumentMismatchException(); return; } - FX_FLOAT nRateOfMonth = nRate / 12; - int32_t iNums = (int32_t)( - (FXSYS_log10((FX_FLOAT)(nPayment / nPrincipalAmount)) - - FXSYS_log10((FX_FLOAT)(nPayment / nPrincipalAmount - nRateOfMonth))) / - FXSYS_log10((FX_FLOAT)(1 + nRateOfMonth))); + float nRateOfMonth = nRate / 12; + int32_t iNums = + (int32_t)((log10((float)(nPayment / nPrincipalAmount)) - + log10((float)(nPayment / nPrincipalAmount - nRateOfMonth))) / + log10((float)(1 + nRateOfMonth))); int32_t iEnd = std::min((int32_t)(nFirstMonth + nNumberOfMonths - 1), iNums); if (nPayment < nPrincipalAmount * nRateOfMonth) { pContext->ThrowArgumentMismatchException(); @@ -2645,8 +2474,8 @@ void CXFA_FM2JSContext::PPmt(CFXJSE_Value* pThis, for (i = 0; i < nFirstMonth - 1; ++i) nPrincipalAmount -= nPayment - nPrincipalAmount * nRateOfMonth; - FX_FLOAT nTemp = 0; - FX_FLOAT nSum = 0; + float nTemp = 0; + float nSum = 0; for (; i < iEnd; ++i) { nTemp = nPayment - nPrincipalAmount * nRateOfMonth; nSum += nTemp; @@ -2674,15 +2503,15 @@ void CXFA_FM2JSContext::PV(CFXJSE_Value* pThis, return; } - FX_DOUBLE nAmount = ValueToDouble(pThis, argOne.get()); - FX_DOUBLE nRate = ValueToDouble(pThis, argTwo.get()); - FX_DOUBLE nPeriod = ValueToDouble(pThis, argThree.get()); + double nAmount = ValueToDouble(pThis, argOne.get()); + double nRate = ValueToDouble(pThis, argTwo.get()); + double nPeriod = ValueToDouble(pThis, argThree.get()); if ((nAmount <= 0) || (nRate < 0) || (nPeriod <= 0)) { pContext->ThrowArgumentMismatchException(); return; } - FX_DOUBLE nTemp = 1; + double nTemp = 1; for (int32_t i = 0; i < nPeriod; ++i) nTemp *= 1 + nRate; @@ -2709,17 +2538,16 @@ void CXFA_FM2JSContext::Rate(CFXJSE_Value* pThis, return; } - FX_FLOAT nFuture = ValueToFloat(pThis, argOne.get()); - FX_FLOAT nPresent = ValueToFloat(pThis, argTwo.get()); - FX_FLOAT nTotalNumber = ValueToFloat(pThis, argThree.get()); + float nFuture = ValueToFloat(pThis, argOne.get()); + float nPresent = ValueToFloat(pThis, argTwo.get()); + float nTotalNumber = ValueToFloat(pThis, argThree.get()); if ((nFuture <= 0) || (nPresent < 0) || (nTotalNumber <= 0)) { pContext->ThrowArgumentMismatchException(); return; } args.GetReturnValue()->SetFloat( - FXSYS_pow((FX_FLOAT)(nFuture / nPresent), (FX_FLOAT)(1 / nTotalNumber)) - - 1); + FXSYS_pow((float)(nFuture / nPresent), (float)(1 / nTotalNumber)) - 1); } // static @@ -2741,17 +2569,16 @@ void CXFA_FM2JSContext::Term(CFXJSE_Value* pThis, return; } - FX_FLOAT nMount = ValueToFloat(pThis, argOne.get()); - FX_FLOAT nRate = ValueToFloat(pThis, argTwo.get()); - FX_FLOAT nFuture = ValueToFloat(pThis, argThree.get()); + float nMount = ValueToFloat(pThis, argOne.get()); + float nRate = ValueToFloat(pThis, argTwo.get()); + float nFuture = ValueToFloat(pThis, argThree.get()); if ((nMount <= 0) || (nRate <= 0) || (nFuture <= 0)) { pContext->ThrowArgumentMismatchException(); return; } - args.GetReturnValue()->SetFloat( - FXSYS_log((FX_FLOAT)(nFuture / nMount * nRate) + 1) / - FXSYS_log((FX_FLOAT)(1 + nRate))); + args.GetReturnValue()->SetFloat(log((float)(nFuture / nMount * nRate) + 1) / + log((float)(1 + nRate))); } // static @@ -2805,17 +2632,15 @@ void CXFA_FM2JSContext::Choose(CFXJSE_Value* pThis, jsObjectValue->GetObjectProperty( propertyValue->ToString().AsStringC(), newPropertyValue.get()); } - CFX_ByteString bsChoosed; - ValueToUTF8String(newPropertyValue.get(), bsChoosed); - args.GetReturnValue()->SetString(bsChoosed.AsStringC()); + CFX_ByteString bsChosen = ValueToUTF8String(newPropertyValue.get()); + args.GetReturnValue()->SetString(bsChosen.AsStringC()); bFound = true; } } else { iValueIndex++; if (iValueIndex == iIndex) { - CFX_ByteString bsChoosed; - ValueToUTF8String(argIndexValue.get(), bsChoosed); - args.GetReturnValue()->SetString(bsChoosed.AsStringC()); + CFX_ByteString bsChosen = ValueToUTF8String(argIndexValue.get()); + args.GetReturnValue()->SetString(bsChosen.AsStringC()); bFound = true; } } @@ -2898,20 +2723,17 @@ void CXFA_FM2JSContext::Within(CFXJSE_Value* pThis, std::unique_ptr<CFXJSE_Value> argLow = GetSimpleValue(pThis, args, 1); std::unique_ptr<CFXJSE_Value> argHigh = GetSimpleValue(pThis, args, 2); if (argOne->IsNumber()) { - FX_FLOAT oneNumber = ValueToFloat(pThis, argOne.get()); - FX_FLOAT lowNumber = ValueToFloat(pThis, argLow.get()); - FX_FLOAT heightNumber = ValueToFloat(pThis, argHigh.get()); + float oneNumber = ValueToFloat(pThis, argOne.get()); + float lowNumber = ValueToFloat(pThis, argLow.get()); + float heightNumber = ValueToFloat(pThis, argHigh.get()); args.GetReturnValue()->SetInteger((oneNumber >= lowNumber) && (oneNumber <= heightNumber)); return; } - CFX_ByteString oneString; - CFX_ByteString lowString; - CFX_ByteString heightString; - ValueToUTF8String(argOne.get(), oneString); - ValueToUTF8String(argLow.get(), lowString); - ValueToUTF8String(argHigh.get(), heightString); + CFX_ByteString oneString = ValueToUTF8String(argOne.get()); + CFX_ByteString lowString = ValueToUTF8String(argLow.get()); + CFX_ByteString heightString = ValueToUTF8String(argHigh.get()); args.GetReturnValue()->SetInteger( (oneString.Compare(lowString.AsStringC()) >= 0) && (oneString.Compare(heightString.AsStringC()) <= 0)); @@ -2943,8 +2765,7 @@ void CXFA_FM2JSContext::Eval(CFXJSE_Value* pThis, v8::Isolate* pIsolate = pContext->GetScriptRuntime(); std::unique_ptr<CFXJSE_Value> scriptValue = GetSimpleValue(pThis, args, 0); - CFX_ByteString utf8ScriptString; - ValueToUTF8String(scriptValue.get(), utf8ScriptString); + CFX_ByteString utf8ScriptString = ValueToUTF8String(scriptValue.get()); if (utf8ScriptString.IsEmpty()) { args.GetReturnValue()->SetNull(); return; @@ -3038,8 +2859,7 @@ void CXFA_FM2JSContext::UnitType(CFXJSE_Value* pThis, return; } - CFX_ByteString unitspanString; - ValueToUTF8String(unitspanValue.get(), unitspanString); + CFX_ByteString unitspanString = ValueToUTF8String(unitspanValue.get()); if (unitspanString.IsEmpty()) { args.GetReturnValue()->SetString("in"); return; @@ -3059,14 +2879,14 @@ void CXFA_FM2JSContext::UnitType(CFXJSE_Value* pThis, unitspanString.MakeLower(); CFX_WideString wsTypeString = CFX_WideString::FromUTF8(unitspanString.AsStringC()); - const FX_WCHAR* pData = wsTypeString.c_str(); + const wchar_t* pData = wsTypeString.c_str(); int32_t u = 0; int32_t uLen = wsTypeString.GetLength(); while (IsWhitespace(pData[u])) u++; XFA_FM2JS_VALUETYPE_ParserStatus eParserStatus = VALUETYPE_START; - FX_WCHAR typeChar; + wchar_t typeChar; // TODO(dsinclair): Cleanup this parser, figure out what the various checks // are for. while (u < uLen) { @@ -3086,7 +2906,7 @@ void CXFA_FM2JSContext::UnitType(CFXJSE_Value* pThis, } eParserStatus = VALUETYPE_HAVEDIGIT; } else if ((typeChar == 'c' || typeChar == 'p') && (u + 1 < uLen)) { - FX_WCHAR nextChar = pData[u + 1]; + wchar_t nextChar = pData[u + 1]; if ((eParserStatus == VALUETYPE_START || eParserStatus == VALUETYPE_HAVEDIGIT || eParserStatus == VALUETYPE_HAVEDIGITWHITE) && @@ -3097,7 +2917,7 @@ void CXFA_FM2JSContext::UnitType(CFXJSE_Value* pThis, } eParserStatus = VALUETYPE_HAVEINVALIDCHAR; } else if (typeChar == 'm' && (u + 1 < uLen)) { - FX_WCHAR nextChar = pData[u + 1]; + wchar_t nextChar = pData[u + 1]; if ((eParserStatus == VALUETYPE_START || eParserStatus == VALUETYPE_HAVEDIGIT || eParserStatus == VALUETYPE_HAVEDIGITWHITE) && @@ -3151,9 +2971,8 @@ void CXFA_FM2JSContext::UnitValue(CFXJSE_Value* pThis, return; } - CFX_ByteString unitspanString; - ValueToUTF8String(unitspanValue.get(), unitspanString); - const FX_CHAR* pData = unitspanString.c_str(); + CFX_ByteString unitspanString = ValueToUTF8String(unitspanValue.get()); + const char* pData = unitspanString.c_str(); if (!pData) { args.GetReturnValue()->SetInteger(0); return; @@ -3171,8 +2990,8 @@ void CXFA_FM2JSContext::UnitValue(CFXJSE_Value* pThis, ++u; } - FX_CHAR* pTemp = nullptr; - FX_DOUBLE dFirstNumber = strtod(pData, &pTemp); + char* pTemp = nullptr; + double dFirstNumber = strtod(pData, &pTemp); while (IsWhitespace(pData[u])) ++u; @@ -3190,9 +3009,8 @@ void CXFA_FM2JSContext::UnitValue(CFXJSE_Value* pThis, CFX_ByteString strUnit; if (argc > 1) { std::unique_ptr<CFXJSE_Value> unitValue = GetSimpleValue(pThis, args, 1); - CFX_ByteString unitTempString; - ValueToUTF8String(unitValue.get(), unitTempString); - const FX_CHAR* pChar = unitTempString.c_str(); + CFX_ByteString unitTempString = ValueToUTF8String(unitValue.get()); + const char* pChar = unitTempString.c_str(); int32_t uVal = 0; while (IsWhitespace(pChar[uVal])) ++uVal; @@ -3219,7 +3037,7 @@ void CXFA_FM2JSContext::UnitValue(CFXJSE_Value* pThis, strUnit = strFirstUnit; } - FX_DOUBLE dResult = 0; + double dResult = 0; if (strFirstUnit == "in" || strFirstUnit == "inches") { if (strUnit == "mm" || strUnit == "millimeters") dResult = dFirstNumber * 25.4; @@ -3295,15 +3113,13 @@ void CXFA_FM2JSContext::At(CFXJSE_Value* pThis, return; } - CFX_ByteString stringTwo; - ValueToUTF8String(argTwo.get(), stringTwo); + CFX_ByteString stringTwo = ValueToUTF8String(argTwo.get()); if (stringTwo.IsEmpty()) { args.GetReturnValue()->SetInteger(1); return; } - CFX_ByteString stringOne; - ValueToUTF8String(argOne.get(), stringOne); + CFX_ByteString stringOne = ValueToUTF8String(argOne.get()); FX_STRSIZE iPosition = stringOne.Find(stringTwo.AsStringC()); args.GetReturnValue()->SetInteger(iPosition + 1); } @@ -3326,10 +3142,7 @@ void CXFA_FM2JSContext::Concat(CFXJSE_Value* pThis, continue; bAllNull = false; - - CFX_ByteString valueStr; - ValueToUTF8String(value.get(), valueStr); - resultString += valueStr; + resultString += ValueToUTF8String(value.get()); } if (bAllNull) { @@ -3357,8 +3170,7 @@ void CXFA_FM2JSContext::Decode(CFXJSE_Value* pThis, return; } - CFX_ByteString toDecodeString; - ValueToUTF8String(argOne.get(), toDecodeString); + CFX_ByteString toDecodeString = ValueToUTF8String(argOne.get()); CFX_ByteTextBuf resultBuf; DecodeURL(toDecodeString.AsStringC(), resultBuf); args.GetReturnValue()->SetString(resultBuf.AsStringC()); @@ -3372,12 +3184,8 @@ void CXFA_FM2JSContext::Decode(CFXJSE_Value* pThis, return; } - CFX_ByteString toDecodeString; - ValueToUTF8String(argOne.get(), toDecodeString); - - CFX_ByteString identifyString; - ValueToUTF8String(argTwo.get(), identifyString); - + CFX_ByteString toDecodeString = ValueToUTF8String(argOne.get()); + CFX_ByteString identifyString = ValueToUTF8String(argTwo.get()); CFX_ByteTextBuf resultBuf; if (identifyString.EqualNoCase("html")) DecodeHTML(toDecodeString.AsStringC(), resultBuf); @@ -3393,18 +3201,18 @@ void CXFA_FM2JSContext::Decode(CFXJSE_Value* pThis, void CXFA_FM2JSContext::DecodeURL(const CFX_ByteStringC& szURLString, CFX_ByteTextBuf& szResultString) { CFX_WideString wsURLString = CFX_WideString::FromUTF8(szURLString); - const FX_WCHAR* pData = wsURLString.c_str(); + const wchar_t* pData = wsURLString.c_str(); int32_t i = 0; CFX_WideTextBuf wsResultBuf; while (i < wsURLString.GetLength()) { - FX_WCHAR ch = pData[i]; + wchar_t ch = pData[i]; if ('%' != ch) { wsResultBuf.AppendChar(ch); ++i; continue; } - FX_WCHAR chTemp = 0; + wchar_t chTemp = 0; int32_t iCount = 0; while (iCount < 2) { ++i; @@ -3434,15 +3242,15 @@ void CXFA_FM2JSContext::DecodeURL(const CFX_ByteStringC& szURLString, void CXFA_FM2JSContext::DecodeHTML(const CFX_ByteStringC& szHTMLString, CFX_ByteTextBuf& szResultString) { CFX_WideString wsHTMLString = CFX_WideString::FromUTF8(szHTMLString); - FX_WCHAR strString[9]; + wchar_t strString[9]; int32_t iStrIndex = 0; int32_t iLen = wsHTMLString.GetLength(); int32_t i = 0; int32_t iCode = 0; - const FX_WCHAR* pData = wsHTMLString.c_str(); + const wchar_t* pData = wsHTMLString.c_str(); CFX_WideTextBuf wsResultBuf; while (i < iLen) { - FX_WCHAR ch = pData[i]; + wchar_t ch = pData[i]; if (ch != '&') { wsResultBuf.AppendChar(ch); ++i; @@ -3492,7 +3300,7 @@ void CXFA_FM2JSContext::DecodeHTML(const CFX_ByteStringC& szHTMLString, } uint32_t iData = 0; if (HTMLSTR2Code(strString, iData)) { - wsResultBuf.AppendChar((FX_WCHAR)iData); + wsResultBuf.AppendChar((wchar_t)iData); } else { wsResultBuf.AppendChar(iCode); } @@ -3510,13 +3318,13 @@ void CXFA_FM2JSContext::DecodeHTML(const CFX_ByteStringC& szHTMLString, void CXFA_FM2JSContext::DecodeXML(const CFX_ByteStringC& szXMLString, CFX_ByteTextBuf& szResultString) { CFX_WideString wsXMLString = CFX_WideString::FromUTF8(szXMLString); - FX_WCHAR strString[9]; + wchar_t strString[9]; int32_t iStrIndex = 0; int32_t iLen = wsXMLString.GetLength(); int32_t i = 0; int32_t iCode = 0; - FX_WCHAR ch = 0; - const FX_WCHAR* pData = wsXMLString.c_str(); + wchar_t ch = 0; + const wchar_t* pData = wsXMLString.c_str(); CFX_WideTextBuf wsXMLBuf; while (i < iLen) { ch = pData[i]; @@ -3568,11 +3376,11 @@ void CXFA_FM2JSContext::DecodeXML(const CFX_ByteStringC& szXMLString, strString[iStrIndex] = 0; } - const FX_WCHAR* const strName[] = {L"quot", L"amp", L"apos", L"lt", L"gt"}; + const wchar_t* const strName[] = {L"quot", L"amp", L"apos", L"lt", L"gt"}; int32_t iIndex = 0; while (iIndex < 5) { - if (FXSYS_memcmp(strString, strName[iIndex], - FXSYS_wcslen(strName[iIndex])) == 0) { + if (memcmp(strString, strName[iIndex], FXSYS_wcslen(strName[iIndex])) == + 0) { break; } ++iIndex; @@ -3624,8 +3432,7 @@ void CXFA_FM2JSContext::Encode(CFXJSE_Value* pThis, return; } - CFX_ByteString toEncodeString; - ValueToUTF8String(argOne.get(), toEncodeString); + CFX_ByteString toEncodeString = ValueToUTF8String(argOne.get()); CFX_ByteTextBuf resultBuf; EncodeURL(toEncodeString.AsStringC(), resultBuf); args.GetReturnValue()->SetString(resultBuf.AsStringC()); @@ -3639,10 +3446,8 @@ void CXFA_FM2JSContext::Encode(CFXJSE_Value* pThis, return; } - CFX_ByteString toEncodeString; - ValueToUTF8String(argOne.get(), toEncodeString); - CFX_ByteString identifyString; - ValueToUTF8String(argTwo.get(), identifyString); + CFX_ByteString toEncodeString = ValueToUTF8String(argOne.get()); + CFX_ByteString identifyString = ValueToUTF8String(argTwo.get()); CFX_ByteTextBuf resultBuf; if (identifyString.EqualNoCase("html")) EncodeHTML(toEncodeString.AsStringC(), resultBuf); @@ -3659,16 +3464,16 @@ void CXFA_FM2JSContext::EncodeURL(const CFX_ByteStringC& szURLString, CFX_ByteTextBuf& szResultBuf) { CFX_WideString wsURLString = CFX_WideString::FromUTF8(szURLString); CFX_WideTextBuf wsResultBuf; - FX_WCHAR strEncode[4]; + wchar_t strEncode[4]; strEncode[0] = '%'; strEncode[3] = 0; - FX_WCHAR strUnsafe[] = {' ', '<', '>', '"', '#', '%', '{', '}', - '|', '\\', '^', '~', '[', ']', '`'}; - FX_WCHAR strReserved[] = {';', '/', '?', ':', '@', '=', '&'}; - FX_WCHAR strSpecial[] = {'$', '-', '+', '!', '*', '\'', '(', ')', ','}; - const FX_WCHAR* strCode = L"0123456789abcdef"; + wchar_t strUnsafe[] = {' ', '<', '>', '"', '#', '%', '{', '}', + '|', '\\', '^', '~', '[', ']', '`'}; + wchar_t strReserved[] = {';', '/', '?', ':', '@', '=', '&'}; + wchar_t strSpecial[] = {'$', '-', '+', '!', '*', '\'', '(', ')', ','}; + const wchar_t* strCode = L"0123456789abcdef"; for (int32_t u = 0; u < wsURLString.GetLength(); ++u) { - FX_WCHAR ch = wsURLString.GetAt(u); + wchar_t ch = wsURLString.GetAt(u); int32_t i = 0; int32_t iCount = FX_ArraySize(strUnsafe); while (i < iCount) { @@ -3719,10 +3524,10 @@ void CXFA_FM2JSContext::EncodeURL(const CFX_ByteStringC& szURLString, } else if (ch >= 0x20 && ch <= 0x7e) { wsResultBuf.AppendChar(ch); } else { - const FX_WCHAR iRadix = 16; + const wchar_t iRadix = 16; CFX_WideString strTmp; while (ch >= iRadix) { - FX_WCHAR tmp = strCode[ch % iRadix]; + wchar_t tmp = strCode[ch % iRadix]; ch /= iRadix; strTmp += tmp; } @@ -3760,8 +3565,8 @@ void CXFA_FM2JSContext::EncodeHTML(const CFX_ByteStringC& szHTMLString, CFX_ByteTextBuf& szResultBuf) { CFX_ByteString str = szHTMLString.c_str(); CFX_WideString wsHTMLString = CFX_WideString::FromUTF8(str.AsStringC()); - const FX_WCHAR* strCode = L"0123456789abcdef"; - FX_WCHAR strEncode[9]; + const wchar_t* strCode = L"0123456789abcdef"; + wchar_t strEncode[9]; strEncode[0] = '&'; strEncode[1] = '#'; strEncode[2] = 'x'; @@ -3772,7 +3577,7 @@ void CXFA_FM2JSContext::EncodeHTML(const CFX_ByteStringC& szHTMLString, CFX_WideTextBuf wsResultBuf; int32_t iLen = wsHTMLString.GetLength(); int32_t i = 0; - const FX_WCHAR* pData = wsHTMLString.c_str(); + const wchar_t* pData = wsHTMLString.c_str(); while (i < iLen) { uint32_t ch = pData[i]; CFX_WideString htmlReserve; @@ -3781,7 +3586,7 @@ void CXFA_FM2JSContext::EncodeHTML(const CFX_ByteStringC& szHTMLString, wsResultBuf << htmlReserve; wsResultBuf.AppendChar(L';'); } else if (ch >= 32 && ch <= 126) { - wsResultBuf.AppendChar((FX_WCHAR)ch); + wsResultBuf.AppendChar((wchar_t)ch); } else if (ch < 256) { int32_t iIndex = ch / 16; strEncode[3] = strCode[iIndex]; @@ -3810,7 +3615,7 @@ void CXFA_FM2JSContext::EncodeXML(const CFX_ByteStringC& szXMLString, CFX_ByteTextBuf& szResultBuf) { CFX_WideString wsXMLString = CFX_WideString::FromUTF8(szXMLString); CFX_WideTextBuf wsResultBuf; - FX_WCHAR strEncode[9]; + wchar_t strEncode[9]; strEncode[0] = '&'; strEncode[1] = '#'; strEncode[2] = 'x'; @@ -3818,10 +3623,10 @@ void CXFA_FM2JSContext::EncodeXML(const CFX_ByteStringC& szXMLString, strEncode[6] = 0; strEncode[7] = ';'; strEncode[8] = 0; - const FX_WCHAR* strCode = L"0123456789abcdef"; - const FX_WCHAR* pData = wsXMLString.c_str(); + const wchar_t* strCode = L"0123456789abcdef"; + const wchar_t* pData = wsXMLString.c_str(); for (int32_t u = 0; u < wsXMLString.GetLength(); ++u) { - FX_WCHAR ch = pData[u]; + wchar_t ch = pData[u]; switch (ch) { case '"': wsResultBuf.AppendChar('&'); @@ -3930,12 +3735,10 @@ void CXFA_FM2JSContext::Format(CFXJSE_Value* pThis, } std::unique_ptr<CFXJSE_Value> argOne = GetSimpleValue(pThis, args, 0); - CFX_ByteString szPattern; - ValueToUTF8String(argOne.get(), szPattern); + CFX_ByteString szPattern = ValueToUTF8String(argOne.get()); std::unique_ptr<CFXJSE_Value> argTwo = GetSimpleValue(pThis, args, 1); - CFX_ByteString szValue; - ValueToUTF8String(argTwo.get(), szValue); + CFX_ByteString szValue = ValueToUTF8String(argTwo.get()); CXFA_Document* pDoc = pContext->GetDocument(); CXFA_LocaleMgr* pMgr = pDoc->GetLocalMgr(); @@ -4014,8 +3817,7 @@ void CXFA_FM2JSContext::Left(CFXJSE_Value* pThis, return; } - CFX_ByteString sourceString; - ValueToUTF8String(argOne.get(), sourceString); + CFX_ByteString sourceString = ValueToUTF8String(argOne.get()); int32_t count = std::max(0, ValueToInteger(pThis, argTwo.get())); args.GetReturnValue()->SetString(sourceString.Left(count).AsStringC()); } @@ -4035,8 +3837,7 @@ void CXFA_FM2JSContext::Len(CFXJSE_Value* pThis, return; } - CFX_ByteString sourceString; - ValueToUTF8String(argOne.get(), sourceString); + CFX_ByteString sourceString = ValueToUTF8String(argOne.get()); args.GetReturnValue()->SetInteger(sourceString.GetLength()); } @@ -4050,17 +3851,16 @@ void CXFA_FM2JSContext::Lower(CFXJSE_Value* pThis, return; } - CFX_ByteString argString; std::unique_ptr<CFXJSE_Value> argOne = GetSimpleValue(pThis, args, 0); if (ValueIsNull(pThis, argOne.get())) { args.GetReturnValue()->SetNull(); return; } - ValueToUTF8String(argOne.get(), argString); CFX_WideTextBuf lowStringBuf; + CFX_ByteString argString = ValueToUTF8String(argOne.get()); CFX_WideString wsArgString = CFX_WideString::FromUTF8(argString.AsStringC()); - const FX_WCHAR* pData = wsArgString.c_str(); + const wchar_t* pData = wsArgString.c_str(); int32_t i = 0; while (i < argString.GetLength()) { int32_t ch = pData[i]; @@ -4093,8 +3893,7 @@ void CXFA_FM2JSContext::Ltrim(CFXJSE_Value* pThis, return; } - CFX_ByteString sourceString; - ValueToUTF8String(argOne.get(), sourceString); + CFX_ByteString sourceString = ValueToUTF8String(argOne.get()); sourceString.TrimLeft(); args.GetReturnValue()->SetString(sourceString.AsStringC()); } @@ -4116,11 +3915,8 @@ void CXFA_FM2JSContext::Parse(CFXJSE_Value* pThis, return; } - CFX_ByteString szPattern; - ValueToUTF8String(argOne.get(), szPattern); - CFX_ByteString szValue; - ValueToUTF8String(argTwo.get(), szValue); - + CFX_ByteString szPattern = ValueToUTF8String(argOne.get()); + CFX_ByteString szValue = ValueToUTF8String(argTwo.get()); CXFA_Document* pDoc = pContext->GetDocument(); CXFA_LocaleMgr* pMgr = pDoc->GetLocalMgr(); CXFA_Node* pThisNode = ToNode(pDoc->GetScriptContext()->GetThisObject()); @@ -4245,14 +4041,14 @@ void CXFA_FM2JSContext::Replace(CFXJSE_Value* pThis, CFX_ByteString oneString; CFX_ByteString twoString; if (!ValueIsNull(pThis, argOne.get()) && !ValueIsNull(pThis, argTwo.get())) { - ValueToUTF8String(argOne.get(), oneString); - ValueToUTF8String(argTwo.get(), twoString); + oneString = ValueToUTF8String(argOne.get()); + twoString = ValueToUTF8String(argTwo.get()); } CFX_ByteString threeString; if (argc > 2) { std::unique_ptr<CFXJSE_Value> argThree = GetSimpleValue(pThis, args, 2); - ValueToUTF8String(argThree.get(), threeString); + threeString = ValueToUTF8String(argThree.get()); } int32_t iFindLen = twoString.GetLength(); @@ -4306,8 +4102,7 @@ void CXFA_FM2JSContext::Right(CFXJSE_Value* pThis, return; } - CFX_ByteString sourceString; - ValueToUTF8String(argOne.get(), sourceString); + CFX_ByteString sourceString = ValueToUTF8String(argOne.get()); int32_t count = std::max(0, ValueToInteger(pThis, argTwo.get())); args.GetReturnValue()->SetString(sourceString.Right(count).AsStringC()); } @@ -4327,8 +4122,7 @@ void CXFA_FM2JSContext::Rtrim(CFXJSE_Value* pThis, return; } - CFX_ByteString sourceString; - ValueToUTF8String(argOne.get(), sourceString); + CFX_ByteString sourceString = ValueToUTF8String(argOne.get()); sourceString.TrimRight(); args.GetReturnValue()->SetString(sourceString.AsStringC()); } @@ -4374,7 +4168,7 @@ void CXFA_FM2JSContext::Str(CFXJSE_Value* pThis, args.GetReturnValue()->SetNull(); return; } - FX_FLOAT fNumber = ValueToFloat(pThis, numberValue.get()); + float fNumber = ValueToFloat(pThis, numberValue.get()); int32_t iWidth = 10; if (argc > 1) { @@ -4399,7 +4193,7 @@ void CXFA_FM2JSContext::Str(CFXJSE_Value* pThis, formatStr += "f"; numberString.Format(formatStr.c_str(), fNumber); - const FX_CHAR* pData = numberString.c_str(); + const char* pData = numberString.c_str(); int32_t iLength = numberString.GetLength(); int32_t u = 0; while (u < iLength) { @@ -4495,17 +4289,18 @@ void CXFA_FM2JSContext::Stuff(CFXJSE_Value* pThis, std::unique_ptr<CFXJSE_Value> deleteValue = GetSimpleValue(pThis, args, 2); if (!sourceValue->IsNull() && !startValue->IsNull() && !deleteValue->IsNull()) { - ValueToUTF8String(sourceValue.get(), sourceString); + sourceString = ValueToUTF8String(sourceValue.get()); iLength = sourceString.GetLength(); - iStart = std::min(iLength, std::max(1, static_cast<int32_t>(ValueToFloat( - pThis, startValue.get())))); + iStart = pdfium::clamp( + static_cast<int32_t>(ValueToFloat(pThis, startValue.get())), 1, + iLength); iDelete = std::max( 0, static_cast<int32_t>(ValueToFloat(pThis, deleteValue.get()))); } if (argc > 3) { std::unique_ptr<CFXJSE_Value> insertValue = GetSimpleValue(pThis, args, 3); - ValueToUTF8String(insertValue.get(), insertString); + insertString = ValueToUTF8String(insertValue.get()); } iStart -= 1; @@ -4544,19 +4339,17 @@ void CXFA_FM2JSContext::Substr(CFXJSE_Value* pThis, return; } - CFX_ByteString szSourceStr; int32_t iStart = 0; int32_t iCount = 0; - ValueToUTF8String(stringValue.get(), szSourceStr); + CFX_ByteString szSourceStr = ValueToUTF8String(stringValue.get()); int32_t iLength = szSourceStr.GetLength(); if (iLength == 0) { args.GetReturnValue()->SetString(""); return; } - iStart = std::min( - iLength, - std::max(1, static_cast<int32_t>(ValueToFloat(pThis, startValue.get())))); + iStart = pdfium::clamp( + iLength, 1, static_cast<int32_t>(ValueToFloat(pThis, startValue.get()))); iCount = std::max(0, static_cast<int32_t>(ValueToFloat(pThis, endValue.get()))); @@ -4582,8 +4375,7 @@ void CXFA_FM2JSContext::Uuid(CFXJSE_Value* pThis, FX_GUID guid; FX_GUID_CreateV4(&guid); - CFX_ByteString bsUId; - FX_GUID_ToString(&guid, bsUId, !!iNum); + CFX_ByteString bsUId = FX_GUID_ToString(&guid, !!iNum); args.GetReturnValue()->SetString(bsUId.AsStringC()); } @@ -4603,12 +4395,10 @@ void CXFA_FM2JSContext::Upper(CFXJSE_Value* pThis, return; } - CFX_ByteString argString; - ValueToUTF8String(argOne.get(), argString); - CFX_WideTextBuf upperStringBuf; + CFX_ByteString argString = ValueToUTF8String(argOne.get()); CFX_WideString wsArgString = CFX_WideString::FromUTF8(argString.AsStringC()); - const FX_WCHAR* pData = wsArgString.c_str(); + const wchar_t* pData = wsArgString.c_str(); int32_t i = 0; while (i < wsArgString.GetLength()) { int32_t ch = pData[i]; @@ -4641,7 +4431,7 @@ void CXFA_FM2JSContext::WordNum(CFXJSE_Value* pThis, args.GetReturnValue()->SetNull(); return; } - FX_FLOAT fNumber = ValueToFloat(pThis, numberValue.get()); + float fNumber = ValueToFloat(pThis, numberValue.get()); int32_t iIdentifier = 0; if (argc > 1) { @@ -4662,7 +4452,7 @@ void CXFA_FM2JSContext::WordNum(CFXJSE_Value* pThis, args.GetReturnValue()->SetNull(); return; } - ValueToUTF8String(localeValue.get(), localeString); + localeString = ValueToUTF8String(localeValue.get()); } if (fNumber < 0.0f || fNumber > 922337203685477550.0f) { @@ -4692,7 +4482,7 @@ void CXFA_FM2JSContext::TrillionUS(const CFX_ByteStringC& szData, "Sixty", "Seventy", "Eighty", "Ninety"}; CFX_ByteStringC pComm[] = {" Hundred ", " Thousand ", " Million ", " Billion ", "Trillion"}; - const FX_CHAR* pData = szData.c_str(); + const char* pData = szData.c_str(); int32_t iLength = szData.GetLength(); int32_t iComm = 0; if (iLength > 12) @@ -4781,7 +4571,7 @@ void CXFA_FM2JSContext::TrillionUS(const CFX_ByteStringC& szData, void CXFA_FM2JSContext::WordUS(const CFX_ByteStringC& szData, int32_t iStyle, CFX_ByteTextBuf& strBuf) { - const FX_CHAR* pData = szData.c_str(); + const char* pData = szData.c_str(); int32_t iLength = szData.GetLength(); if (iStyle < 0 || iStyle > 2) { return; @@ -4845,8 +4635,7 @@ void CXFA_FM2JSContext::Get(CFXJSE_Value* pThis, return; std::unique_ptr<CFXJSE_Value> argOne = GetSimpleValue(pThis, args, 0); - CFX_ByteString urlString; - ValueToUTF8String(argOne.get(), urlString); + CFX_ByteString urlString = ValueToUTF8String(argOne.get()); CFX_RetainPtr<IFX_SeekableReadStream> pFile = pAppProvider->DownloadURL( CFX_WideString::FromUTF8(urlString.AsStringC())); if (!pFile) @@ -4877,30 +4666,28 @@ void CXFA_FM2JSContext::Post(CFXJSE_Value* pThis, if (!pAppProvider) return; - CFX_ByteString bsURL; std::unique_ptr<CFXJSE_Value> argOne = GetSimpleValue(pThis, args, 0); - ValueToUTF8String(argOne.get(), bsURL); + CFX_ByteString bsURL = ValueToUTF8String(argOne.get()); - CFX_ByteString bsData; std::unique_ptr<CFXJSE_Value> argTwo = GetSimpleValue(pThis, args, 1); - ValueToUTF8String(argTwo.get(), bsData); + CFX_ByteString bsData = ValueToUTF8String(argTwo.get()); CFX_ByteString bsContentType; if (argc > 2) { std::unique_ptr<CFXJSE_Value> argThree = GetSimpleValue(pThis, args, 2); - ValueToUTF8String(argThree.get(), bsContentType); + bsContentType = ValueToUTF8String(argThree.get()); } CFX_ByteString bsEncode; if (argc > 3) { std::unique_ptr<CFXJSE_Value> argFour = GetSimpleValue(pThis, args, 3); - ValueToUTF8String(argFour.get(), bsEncode); + bsEncode = ValueToUTF8String(argFour.get()); } CFX_ByteString bsHeader; if (argc > 4) { std::unique_ptr<CFXJSE_Value> argFive = GetSimpleValue(pThis, args, 4); - ValueToUTF8String(argFive.get(), bsHeader); + bsHeader = ValueToUTF8String(argFive.get()); } CFX_WideString decodedResponse; @@ -4935,18 +4722,16 @@ void CXFA_FM2JSContext::Put(CFXJSE_Value* pThis, if (!pAppProvider) return; - CFX_ByteString bsURL; std::unique_ptr<CFXJSE_Value> argOne = GetSimpleValue(pThis, args, 0); - ValueToUTF8String(argOne.get(), bsURL); + CFX_ByteString bsURL = ValueToUTF8String(argOne.get()); - CFX_ByteString bsData; std::unique_ptr<CFXJSE_Value> argTwo = GetSimpleValue(pThis, args, 1); - ValueToUTF8String(argTwo.get(), bsData); + CFX_ByteString bsData = ValueToUTF8String(argTwo.get()); CFX_ByteString bsEncode; if (argc > 2) { std::unique_ptr<CFXJSE_Value> argThree = GetSimpleValue(pThis, args, 2); - ValueToUTF8String(argThree.get(), bsEncode); + bsEncode = ValueToUTF8String(argThree.get()); } if (!pAppProvider->PutRequestURL( @@ -5020,8 +4805,8 @@ void CXFA_FM2JSContext::logical_or_operator(CFXJSE_Value* pThis, return; } - FX_FLOAT first = ValueToFloat(pThis, argFirst.get()); - FX_FLOAT second = ValueToFloat(pThis, argSecond.get()); + float first = ValueToFloat(pThis, argFirst.get()); + float second = ValueToFloat(pThis, argSecond.get()); args.GetReturnValue()->SetInteger((first || second) ? 1 : 0); } @@ -5041,8 +4826,8 @@ void CXFA_FM2JSContext::logical_and_operator(CFXJSE_Value* pThis, return; } - FX_FLOAT first = ValueToFloat(pThis, argFirst.get()); - FX_FLOAT second = ValueToFloat(pThis, argSecond.get()); + float first = ValueToFloat(pThis, argFirst.get()); + float second = ValueToFloat(pThis, argSecond.get()); args.GetReturnValue()->SetInteger((first && second) ? 1 : 0); } @@ -5074,8 +4859,8 @@ void CXFA_FM2JSContext::equality_operator(CFXJSE_Value* pThis, return; } - FX_DOUBLE first = ValueToDouble(pThis, argFirst.get()); - FX_DOUBLE second = ValueToDouble(pThis, argSecond.get()); + double first = ValueToDouble(pThis, argFirst.get()); + double second = ValueToDouble(pThis, argSecond.get()); args.GetReturnValue()->SetInteger((first == second) ? 1 : 0); } @@ -5107,8 +4892,8 @@ void CXFA_FM2JSContext::notequality_operator(CFXJSE_Value* pThis, return; } - FX_DOUBLE first = ValueToDouble(pThis, argFirst.get()); - FX_DOUBLE second = ValueToDouble(pThis, argSecond.get()); + double first = ValueToDouble(pThis, argFirst.get()); + double second = ValueToDouble(pThis, argSecond.get()); args.GetReturnValue()->SetInteger(first != second); } @@ -5161,8 +4946,8 @@ void CXFA_FM2JSContext::less_operator(CFXJSE_Value* pThis, return; } - FX_DOUBLE first = ValueToDouble(pThis, argFirst.get()); - FX_DOUBLE second = ValueToDouble(pThis, argSecond.get()); + double first = ValueToDouble(pThis, argFirst.get()); + double second = ValueToDouble(pThis, argSecond.get()); args.GetReturnValue()->SetInteger((first < second) ? 1 : 0); } @@ -5189,8 +4974,8 @@ void CXFA_FM2JSContext::lessequal_operator(CFXJSE_Value* pThis, return; } - FX_DOUBLE first = ValueToDouble(pThis, argFirst.get()); - FX_DOUBLE second = ValueToDouble(pThis, argSecond.get()); + double first = ValueToDouble(pThis, argFirst.get()); + double second = ValueToDouble(pThis, argSecond.get()); args.GetReturnValue()->SetInteger((first <= second) ? 1 : 0); } @@ -5216,8 +5001,8 @@ void CXFA_FM2JSContext::greater_operator(CFXJSE_Value* pThis, return; } - FX_DOUBLE first = ValueToDouble(pThis, argFirst.get()); - FX_DOUBLE second = ValueToDouble(pThis, argSecond.get()); + double first = ValueToDouble(pThis, argFirst.get()); + double second = ValueToDouble(pThis, argSecond.get()); args.GetReturnValue()->SetInteger((first > second) ? 1 : 0); } @@ -5244,8 +5029,8 @@ void CXFA_FM2JSContext::greaterequal_operator(CFXJSE_Value* pThis, return; } - FX_DOUBLE first = ValueToDouble(pThis, argFirst.get()); - FX_DOUBLE second = ValueToDouble(pThis, argSecond.get()); + double first = ValueToDouble(pThis, argFirst.get()); + double second = ValueToDouble(pThis, argSecond.get()); args.GetReturnValue()->SetInteger((first >= second) ? 1 : 0); } @@ -5266,8 +5051,8 @@ void CXFA_FM2JSContext::plus_operator(CFXJSE_Value* pThis, return; } - FX_DOUBLE first = ValueToDouble(pThis, argFirst.get()); - FX_DOUBLE second = ValueToDouble(pThis, argSecond.get()); + double first = ValueToDouble(pThis, argFirst.get()); + double second = ValueToDouble(pThis, argSecond.get()); args.GetReturnValue()->SetDouble(first + second); } @@ -5287,8 +5072,8 @@ void CXFA_FM2JSContext::minus_operator(CFXJSE_Value* pThis, return; } - FX_DOUBLE first = ValueToDouble(pThis, argFirst.get()); - FX_DOUBLE second = ValueToDouble(pThis, argSecond.get()); + double first = ValueToDouble(pThis, argFirst.get()); + double second = ValueToDouble(pThis, argSecond.get()); args.GetReturnValue()->SetDouble(first - second); } @@ -5308,8 +5093,8 @@ void CXFA_FM2JSContext::multiple_operator(CFXJSE_Value* pThis, return; } - FX_DOUBLE first = ValueToDouble(pThis, argFirst.get()); - FX_DOUBLE second = ValueToDouble(pThis, argSecond.get()); + double first = ValueToDouble(pThis, argFirst.get()); + double second = ValueToDouble(pThis, argSecond.get()); args.GetReturnValue()->SetDouble(first * second); } @@ -5330,13 +5115,13 @@ void CXFA_FM2JSContext::divide_operator(CFXJSE_Value* pThis, return; } - FX_DOUBLE second = ValueToDouble(pThis, argSecond.get()); + double second = ValueToDouble(pThis, argSecond.get()); if (second == 0.0) { pContext->ThrowDivideByZeroException(); return; } - FX_DOUBLE first = ValueToDouble(pThis, argFirst.get()); + double first = ValueToDouble(pThis, argFirst.get()); args.GetReturnValue()->SetDouble(first / second); } @@ -5389,7 +5174,7 @@ void CXFA_FM2JSContext::logical_not_operator(CFXJSE_Value* pThis, return; } - FX_DOUBLE first = ValueToDouble(pThis, argOne.get()); + double first = ValueToDouble(pThis, argOne.get()); args.GetReturnValue()->SetInteger((first == 0.0) ? 1 : 0); } @@ -5413,9 +5198,8 @@ void CXFA_FM2JSContext::dot_accessor(CFXJSE_Value* pThis, } CFX_ByteString szName = args.GetUTF8String(2); - CFX_ByteString szSomExp; - GenerateSomExpression(szName.AsStringC(), args.GetInt32(3), iIndexValue, - bIsStar, szSomExp); + CFX_ByteString szSomExp = GenerateSomExpression( + szName.AsStringC(), args.GetInt32(3), iIndexValue, bIsStar); std::unique_ptr<CFXJSE_Value> argAccessor = args.GetValue(0); if (argAccessor->IsArray()) { @@ -5531,10 +5315,9 @@ void CXFA_FM2JSContext::dotdot_accessor(CFXJSE_Value* pThis, iIndexValue = ValueToInteger(pThis, args.GetValue(4).get()); } - CFX_ByteString szSomExp; CFX_ByteString szName = args.GetUTF8String(2); - GenerateSomExpression(szName.AsStringC(), args.GetInt32(3), iIndexValue, - bIsStar, szSomExp); + CFX_ByteString szSomExp = GenerateSomExpression( + szName.AsStringC(), args.GetInt32(3), iIndexValue, bIsStar); std::unique_ptr<CFXJSE_Value> argAccessor = args.GetValue(0); if (argAccessor->IsArray()) { @@ -5642,8 +5425,7 @@ void CXFA_FM2JSContext::eval_translation(CFXJSE_Value* pThis, } std::unique_ptr<CFXJSE_Value> argOne = GetSimpleValue(pThis, args, 0); - CFX_ByteString argString; - ValueToUTF8String(argOne.get(), argString); + CFX_ByteString argString = ValueToUTF8String(argOne.get()); if (argString.IsEmpty()) { pContext->ThrowArgumentMismatchException(); return; @@ -5941,18 +5723,17 @@ bool CXFA_FM2JSContext::simpleValueCompare(CFXJSE_Value* pThis, return false; if (firstValue->IsString()) { - CFX_ByteString firstString, secondString; - ValueToUTF8String(firstValue, firstString); - ValueToUTF8String(secondValue, secondString); + CFX_ByteString firstString = ValueToUTF8String(firstValue); + CFX_ByteString secondString = ValueToUTF8String(secondValue); return firstString == secondString; } if (firstValue->IsNumber()) { - FX_FLOAT first = ValueToFloat(pThis, firstValue); - FX_FLOAT second = ValueToFloat(pThis, secondValue); - return (first == second); + float first = ValueToFloat(pThis, firstValue); + float second = ValueToFloat(pThis, secondValue); + return first == second; } if (firstValue->IsBoolean()) - return (firstValue->ToBoolean() == secondValue->ToBoolean()); + return firstValue->ToBoolean() == secondValue->ToBoolean(); return firstValue->IsNull() && secondValue && secondValue->IsNull(); } @@ -6045,24 +5826,23 @@ bool CXFA_FM2JSContext::SetObjectDefaultValue(CFXJSE_Value* pValue, } // static -void CXFA_FM2JSContext::GenerateSomExpression(const CFX_ByteStringC& szName, - int32_t iIndexFlags, - int32_t iIndexValue, - bool bIsStar, - CFX_ByteString& szSomExp) { - if (bIsStar) { - szSomExp = szName + "[*]"; - return; - } - if (iIndexFlags == 0) { - szSomExp = szName; - return; - } +CFX_ByteString CXFA_FM2JSContext::GenerateSomExpression( + const CFX_ByteStringC& szName, + int32_t iIndexFlags, + int32_t iIndexValue, + bool bIsStar) { + if (bIsStar) + return CFX_ByteString(szName, "[*]"); + + if (iIndexFlags == 0) + return CFX_ByteString(szName); + if (iIndexFlags == 1 || iIndexValue == 0) { - szSomExp = szName + "[" + - CFX_ByteString::FormatInteger(iIndexValue, FXFORMAT_SIGNED) + - "]"; - } else if (iIndexFlags == 2) { + return CFX_ByteString(szName, "[") + + CFX_ByteString::FormatInteger(iIndexValue, FXFORMAT_SIGNED) + "]"; + } + CFX_ByteString szSomExp; + if (iIndexFlags == 2) { szSomExp = (iIndexValue < 0) ? (szName + "[-") : (szName + "[+"); iIndexValue = (iIndexValue < 0) ? (0 - iIndexValue) : iIndexValue; szSomExp += CFX_ByteString::FormatInteger(iIndexValue); @@ -6073,6 +5853,7 @@ void CXFA_FM2JSContext::GenerateSomExpression(const CFX_ByteStringC& szName, szSomExp += CFX_ByteString::FormatInteger(iIndexValue); szSomExp += "]"; } + return szSomExp; } // static @@ -6094,7 +5875,7 @@ bool CXFA_FM2JSContext::GetObjectForName( dwFlags); if (iRet >= 1 && resoveNodeRS.dwFlags == XFA_RESOVENODE_RSTYPE_Nodes) { accessorValue->Assign( - pScriptContext->GetJSValueFromMap(resoveNodeRS.nodes.GetAt(0))); + pScriptContext->GetJSValueFromMap(resoveNodeRS.objects.front())); return true; } return false; @@ -6162,23 +5943,23 @@ void CXFA_FM2JSContext::ParseResolveResult( if (resoveNodeRS.dwFlags == XFA_RESOVENODE_RSTYPE_Nodes) { *bAttribute = false; - for (int32_t i = 0; i < resoveNodeRS.nodes.GetSize(); i++) { + CXFA_ScriptContext* pScriptContext = + pContext->GetDocument()->GetScriptContext(); + for (CXFA_Object* pObject : resoveNodeRS.objects) { resultValues->push_back(pdfium::MakeUnique<CFXJSE_Value>(pIsolate)); - resultValues->back()->Assign( - pContext->GetDocument()->GetScriptContext()->GetJSValueFromMap( - resoveNodeRS.nodes.GetAt(i))); + resultValues->back()->Assign(pScriptContext->GetJSValueFromMap(pObject)); } return; } CXFA_ValueArray objectProperties(pIsolate); - int32_t iRet = resoveNodeRS.GetAttributeResult(objectProperties); + int32_t iRet = resoveNodeRS.GetAttributeResult(&objectProperties); *bAttribute = true; if (iRet != 0) { *bAttribute = false; for (int32_t i = 0; i < iRet; i++) { resultValues->push_back(pdfium::MakeUnique<CFXJSE_Value>(pIsolate)); - resultValues->back()->Assign(objectProperties[i]); + resultValues->back()->Assign(objectProperties.m_Values[i].get()); } return; } @@ -6223,8 +6004,7 @@ int32_t CXFA_FM2JSContext::ValueToInteger(CFXJSE_Value* pThis, } // static -FX_FLOAT CXFA_FM2JSContext::ValueToFloat(CFXJSE_Value* pThis, - CFXJSE_Value* arg) { +float CXFA_FM2JSContext::ValueToFloat(CFXJSE_Value* pThis, CFXJSE_Value* arg) { if (!arg) return 0.0f; @@ -6249,7 +6029,7 @@ FX_FLOAT CXFA_FM2JSContext::ValueToFloat(CFXJSE_Value* pThis, return ValueToFloat(pThis, newPropertyValue.get()); } if (arg->IsString()) - return (FX_FLOAT)XFA_ByteStringToDouble(arg->ToString().AsStringC()); + return (float)XFA_ByteStringToDouble(arg->ToString().AsStringC()); if (arg->IsUndefined()) return 0; @@ -6257,8 +6037,8 @@ FX_FLOAT CXFA_FM2JSContext::ValueToFloat(CFXJSE_Value* pThis, } // static -FX_DOUBLE CXFA_FM2JSContext::ValueToDouble(CFXJSE_Value* pThis, - CFXJSE_Value* arg) { +double CXFA_FM2JSContext::ValueToDouble(CFXJSE_Value* pThis, + CFXJSE_Value* arg) { if (!arg) return 0; @@ -6325,17 +6105,12 @@ double CXFA_FM2JSContext::ExtractDouble(CFXJSE_Value* pThis, } // static -void CXFA_FM2JSContext::ValueToUTF8String(CFXJSE_Value* arg, - CFX_ByteString& szOutputString) { - if (!arg) - return; - - if (arg->IsNull() || arg->IsUndefined()) - szOutputString = ""; - else if (arg->IsBoolean()) - szOutputString = arg->ToBoolean() ? "1" : "0"; - else - szOutputString = arg->ToString(); +CFX_ByteString CXFA_FM2JSContext::ValueToUTF8String(CFXJSE_Value* arg) { + if (!arg || arg->IsNull() || arg->IsUndefined()) + return CFX_ByteString(); + if (arg->IsBoolean()) + return arg->ToBoolean() ? "1" : "0"; + return arg->ToString(); } // static. @@ -6411,7 +6186,7 @@ void CXFA_FM2JSContext::ThrowArgumentMismatchException() const { ThrowException(L"Argument mismatch in property or function argument."); } -void CXFA_FM2JSContext::ThrowException(const FX_WCHAR* str, ...) const { +void CXFA_FM2JSContext::ThrowException(const wchar_t* str, ...) const { CFX_WideString wsMessage; va_list arg_ptr; va_start(arg_ptr, str); diff --git a/chromium/third_party/pdfium/xfa/fxfa/fm2js/xfa_fm2jscontext.h b/chromium/third_party/pdfium/xfa/fxfa/fm2js/xfa_fm2jscontext.h index 0f802fe65e4..33f739f1cc5 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/fm2js/xfa_fm2jscontext.h +++ b/chromium/third_party/pdfium/xfa/fxfa/fm2js/xfa_fm2jscontext.h @@ -14,6 +14,8 @@ #include "fxjs/cfxjse_context.h" #include "xfa/fxfa/parser/xfa_resolvenode_rs.h" +class CXFA_Document; + class CXFA_FM2JSContext : public CFXJSE_HostObject { public: CXFA_FM2JSContext(v8::Isolate* pScriptIsolate, @@ -91,13 +93,13 @@ class CXFA_FM2JSContext : public CFXJSE_HostObject { const CFX_ByteStringC& szFuncName, CFXJSE_Arguments& args); - static bool IsIsoDateFormat(const FX_CHAR* pData, + static bool IsIsoDateFormat(const char* pData, int32_t iLength, int32_t& iStyle, int32_t& iYear, int32_t& iMonth, int32_t& iDay); - static bool IsIsoTimeFormat(const FX_CHAR* pData, + static bool IsIsoTimeFormat(const char* pData, int32_t iLength, int32_t& iHour, int32_t& iMinute, @@ -105,7 +107,7 @@ class CXFA_FM2JSContext : public CFXJSE_HostObject { int32_t& iMilliSecond, int32_t& iZoneHour, int32_t& iZoneMinute); - static bool IsIsoDateTimeFormat(const FX_CHAR* pData, + static bool IsIsoDateTimeFormat(const char* pData, int32_t iLength, int32_t& iYear, int32_t& iMonth, @@ -116,57 +118,40 @@ class CXFA_FM2JSContext : public CFXJSE_HostObject { int32_t& iMillionSecond, int32_t& iZoneHour, int32_t& iZoneMinute); - static bool Local2IsoDate(CFXJSE_Value* pThis, - const CFX_ByteStringC& szDate, - const CFX_ByteStringC& szFormat, - const CFX_ByteStringC& szLocale, - CFX_ByteString& strIsoDate); - static bool Local2IsoTime(CFXJSE_Value* pThis, - const CFX_ByteStringC& szTime, - const CFX_ByteStringC& szFormat, - const CFX_ByteStringC& szLocale, - CFX_ByteString& strIsoTime); - static bool IsoDate2Local(CFXJSE_Value* pThis, - const CFX_ByteStringC& szDate, - const CFX_ByteStringC& szFormat, - const CFX_ByteStringC& szLocale, - CFX_ByteString& strLocalDate); - static bool IsoTime2Local(CFXJSE_Value* pThis, - const CFX_ByteStringC& szTime, - const CFX_ByteStringC& szFormat, - const CFX_ByteStringC& szLocale, - CFX_ByteString& strLocalTime); - static bool GetGMTTime(CFXJSE_Value* pThis, - const CFX_ByteStringC& szTime, - const CFX_ByteStringC& szFormat, - const CFX_ByteStringC& szLocale, - CFX_ByteString& strGMTTime); + static CFX_ByteString Local2IsoDate(CFXJSE_Value* pThis, + const CFX_ByteStringC& szDate, + const CFX_ByteStringC& szFormat, + const CFX_ByteStringC& szLocale); + static CFX_ByteString IsoDate2Local(CFXJSE_Value* pThis, + const CFX_ByteStringC& szDate, + const CFX_ByteStringC& szFormat, + const CFX_ByteStringC& szLocale); + static CFX_ByteString IsoTime2Local(CFXJSE_Value* pThis, + const CFX_ByteStringC& szTime, + const CFX_ByteStringC& szFormat, + const CFX_ByteStringC& szLocale); static int32_t DateString2Num(const CFX_ByteStringC& szDateString); - static void GetLocalDateFormat(CFXJSE_Value* pThis, - int32_t iStyle, - const CFX_ByteStringC& szLocalStr, - CFX_ByteString& strFormat, - bool bStandard); - static void GetLocalTimeFormat(CFXJSE_Value* pThis, - int32_t iStyle, - const CFX_ByteStringC& szLocalStr, - CFX_ByteString& strFormat, - bool bStandard); - static void GetStandardDateFormat(CFXJSE_Value* pThis, - int32_t iStyle, - const CFX_ByteStringC& szLocalStr, - CFX_ByteString& strFormat); - static void GetStandardTimeFormat(CFXJSE_Value* pThis, - int32_t iStyle, - const CFX_ByteStringC& szLocalStr, - CFX_ByteString& strFormat); - - static void Num2AllTime(CFXJSE_Value* pThis, - int32_t iTime, - const CFX_ByteStringC& szFormat, - const CFX_ByteStringC& szLocale, - bool bGM, - CFX_ByteString& strTime); + static CFX_ByteString GetLocalDateFormat(CFXJSE_Value* pThis, + int32_t iStyle, + const CFX_ByteStringC& szLocalStr, + bool bStandard); + static CFX_ByteString GetLocalTimeFormat(CFXJSE_Value* pThis, + int32_t iStyle, + const CFX_ByteStringC& szLocalStr, + bool bStandard); + static CFX_ByteString GetStandardDateFormat( + CFXJSE_Value* pThis, + int32_t iStyle, + const CFX_ByteStringC& szLocalStr); + static CFX_ByteString GetStandardTimeFormat( + CFXJSE_Value* pThis, + int32_t iStyle, + const CFX_ByteStringC& szLocalStr); + static CFX_ByteString Num2AllTime(CFXJSE_Value* pThis, + int32_t iTime, + const CFX_ByteStringC& szFormat, + const CFX_ByteStringC& szLocale, + bool bGM); static void GetLocalTimeZone(int32_t& iHour, int32_t& iMin, int32_t& iSec); static void Apr(CFXJSE_Value* pThis, @@ -410,11 +395,10 @@ class CXFA_FM2JSContext : public CFXJSE_HostObject { CFXJSE_Value* pDefaultValue); static bool SetObjectDefaultValue(CFXJSE_Value* pObjectValue, CFXJSE_Value* pNewValue); - static void GenerateSomExpression(const CFX_ByteStringC& szName, - int32_t iIndexFlags, - int32_t iIndexValue, - bool bIsStar, - CFX_ByteString& szSomExp); + static CFX_ByteString GenerateSomExpression(const CFX_ByteStringC& szName, + int32_t iIndexFlags, + int32_t iIndexValue, + bool bIsStar); static bool GetObjectForName(CFXJSE_Value* pThis, CFXJSE_Value* accessorValue, const CFX_ByteStringC& szAccessorName); @@ -436,10 +420,9 @@ class CXFA_FM2JSContext : public CFXJSE_HostObject { uint32_t index); static bool ValueIsNull(CFXJSE_Value* pThis, CFXJSE_Value* pValue); static int32_t ValueToInteger(CFXJSE_Value* pThis, CFXJSE_Value* pValue); - static FX_FLOAT ValueToFloat(CFXJSE_Value* pThis, CFXJSE_Value* pValue); - static FX_DOUBLE ValueToDouble(CFXJSE_Value* pThis, CFXJSE_Value* pValue); - static void ValueToUTF8String(CFXJSE_Value* pValue, - CFX_ByteString& outputValue); + static float ValueToFloat(CFXJSE_Value* pThis, CFXJSE_Value* pValue); + static double ValueToDouble(CFXJSE_Value* pThis, CFXJSE_Value* pValue); + static CFX_ByteString ValueToUTF8String(CFXJSE_Value* pValue); static double ExtractDouble(CFXJSE_Value* pThis, CFXJSE_Value* src, bool* ret); @@ -462,7 +445,7 @@ class CXFA_FM2JSContext : public CFXJSE_HostObject { const CFX_WideString& exp) const; void ThrowArgumentMismatchException() const; void ThrowParamCountMismatchException(const CFX_WideString& method) const; - void ThrowException(const FX_WCHAR* str, ...) const; + void ThrowException(const wchar_t* str, ...) const; v8::Isolate* m_pIsolate; CFXJSE_Class* m_pFMClass; diff --git a/chromium/third_party/pdfium/xfa/fxfa/fm2js/xfa_fmparse.cpp b/chromium/third_party/pdfium/xfa/fxfa/fm2js/xfa_fmparse.cpp index 52161e8c0ac..c1f609315b4 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/fm2js/xfa_fmparse.cpp +++ b/chromium/third_party/pdfium/xfa/fxfa/fm2js/xfa_fmparse.cpp @@ -12,6 +12,12 @@ #include "third_party/base/ptr_util.h" +namespace { + +const int kMaxAssignmentChainLength = 12; + +} // namespace + CXFA_FMParse::CXFA_FMParse(const CFX_WideStringC& wsFormcalc, CXFA_FMErrorInfo* pErrorInfo) : m_pToken(nullptr), m_pErrorInfo(pErrorInfo) { @@ -39,7 +45,7 @@ void CXFA_FMParse::Check(XFA_FM_TOKEN op) { NextToken(); } -void CXFA_FMParse::Error(uint32_t lineNum, const FX_WCHAR* msg, ...) { +void CXFA_FMParse::Error(uint32_t lineNum, const wchar_t* msg, ...) { m_pErrorInfo->linenum = lineNum; va_list ap; va_start(ap, msg); @@ -208,9 +214,12 @@ std::unique_ptr<CXFA_FMExpression> CXFA_FMParse::ParseVarExpression() { std::unique_ptr<CXFA_FMSimpleExpression> CXFA_FMParse::ParseSimpleExpression() { uint32_t line = m_pToken->m_uLinenum; std::unique_ptr<CXFA_FMSimpleExpression> pExp1 = ParseLogicalOrExpression(); + int level = 1; while (m_pToken->m_type == TOKassign) { NextToken(); std::unique_ptr<CXFA_FMSimpleExpression> pExp2 = ParseLogicalOrExpression(); + if (level++ == kMaxAssignmentChainLength) + Error(m_pToken->m_uLinenum, kFMErrLongAssignmentChain); if (m_pErrorInfo->message.IsEmpty()) { pExp1 = pdfium::MakeUnique<CXFA_FMAssignExpression>( line, TOKassign, std::move(pExp1), std::move(pExp2)); @@ -776,9 +785,12 @@ std::unique_ptr<CXFA_FMSimpleExpression> CXFA_FMParse::ParseParenExpression() { uint32_t line = m_pToken->m_uLinenum; std::unique_ptr<CXFA_FMSimpleExpression> pExp1 = ParseLogicalOrExpression(); + int level = 1; while (m_pToken->m_type == TOKassign) { NextToken(); std::unique_ptr<CXFA_FMSimpleExpression> pExp2 = ParseLogicalOrExpression(); + if (level++ == kMaxAssignmentChainLength) + Error(m_pToken->m_uLinenum, kFMErrLongAssignmentChain); if (m_pErrorInfo->message.IsEmpty()) { pExp1 = pdfium::MakeUnique<CXFA_FMAssignExpression>( line, TOKassign, std::move(pExp1), std::move(pExp2)); @@ -832,7 +844,7 @@ std::unique_ptr<CXFA_FMExpression> CXFA_FMParse::ParseBlockExpression() { std::unique_ptr<CXFA_FMExpression> CXFA_FMParse::ParseIfExpression() { uint32_t line = m_pToken->m_uLinenum; - const FX_WCHAR* pStartPos = m_lexer->SavePos(); + const wchar_t* pStartPos = m_lexer->SavePos(); NextToken(); Check(TOKlparen); std::unique_ptr<CXFA_FMSimpleExpression> pExpression; diff --git a/chromium/third_party/pdfium/xfa/fxfa/fm2js/xfa_fmparse.h b/chromium/third_party/pdfium/xfa/fxfa/fm2js/xfa_fmparse.h index 8f2671d1b0d..ccb793ae684 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/fm2js/xfa_fmparse.h +++ b/chromium/third_party/pdfium/xfa/fxfa/fm2js/xfa_fmparse.h @@ -20,7 +20,7 @@ class CXFA_FMParse { void NextToken(); void Check(XFA_FM_TOKEN op); - void Error(uint32_t lineNum, const FX_WCHAR* msg, ...); + void Error(uint32_t lineNum, const wchar_t* msg, ...); std::vector<std::unique_ptr<CXFA_FMExpression>> ParseTopExpression(); std::unique_ptr<CXFA_FMExpression> ParseFunction(); std::unique_ptr<CXFA_FMExpression> ParseExpression(); diff --git a/chromium/third_party/pdfium/xfa/fxfa/fm2js/xfa_lexer.cpp b/chromium/third_party/pdfium/xfa/fxfa/fm2js/xfa_lexer.cpp index 6e844bcdf05..7ccd4773fbc 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/fm2js/xfa_lexer.cpp +++ b/chromium/third_party/pdfium/xfa/fxfa/fm2js/xfa_lexer.cpp @@ -11,41 +11,39 @@ namespace { struct XFA_FMDChar { - static const FX_WCHAR* inc(const FX_WCHAR*& p) { + static const wchar_t* inc(const wchar_t*& p) { ++p; return p; } - static const FX_WCHAR* dec(const FX_WCHAR*& p) { + static const wchar_t* dec(const wchar_t*& p) { --p; return p; } - static uint16_t get(const FX_WCHAR* p) { return *p; } - static bool isWhiteSpace(const FX_WCHAR* p) { + static uint16_t get(const wchar_t* p) { return *p; } + static bool isWhiteSpace(const wchar_t* p) { return (*p) == 0x09 || (*p) == 0x0b || (*p) == 0x0c || (*p) == 0x20; } - static bool isLineTerminator(const FX_WCHAR* p) { + static bool isLineTerminator(const wchar_t* p) { return *p == 0x0A || *p == 0x0D; } - static bool isBinary(const FX_WCHAR* p) { return (*p) >= '0' && (*p) <= '1'; } - static bool isOctal(const FX_WCHAR* p) { return (*p) >= '0' && (*p) <= '7'; } - static bool isDigital(const FX_WCHAR* p) { - return (*p) >= '0' && (*p) <= '9'; - } - static bool isHex(const FX_WCHAR* p) { + static bool isBinary(const wchar_t* p) { return (*p) >= '0' && (*p) <= '1'; } + static bool isOctal(const wchar_t* p) { return (*p) >= '0' && (*p) <= '7'; } + static bool isDigital(const wchar_t* p) { return (*p) >= '0' && (*p) <= '9'; } + static bool isHex(const wchar_t* p) { return isDigital(p) || ((*p) >= 'a' && (*p) <= 'f') || ((*p) >= 'A' && (*p) <= 'F'); } - static bool isAlpha(const FX_WCHAR* p) { + static bool isAlpha(const wchar_t* p) { return ((*p) <= 'z' && (*p) >= 'a') || ((*p) <= 'Z' && (*p) >= 'A'); } - static bool isAvalid(const FX_WCHAR* p, bool flag = 0); - static bool string2number(const FX_WCHAR* s, - FX_DOUBLE* pValue, - const FX_WCHAR*& pEnd); + static bool isAvalid(const wchar_t* p, bool flag = 0); + static bool string2number(const wchar_t* s, + double* pValue, + const wchar_t*& pEnd); static bool isUnicodeAlpha(uint16_t ch); }; -inline bool XFA_FMDChar::isAvalid(const FX_WCHAR* p, bool flag) { +inline bool XFA_FMDChar::isAvalid(const wchar_t* p, bool flag) { if (*p == 0) { return 1; } @@ -61,12 +59,12 @@ inline bool XFA_FMDChar::isAvalid(const FX_WCHAR* p, bool flag) { return 0; } -inline bool XFA_FMDChar::string2number(const FX_WCHAR* s, - FX_DOUBLE* pValue, - const FX_WCHAR*& pEnd) { - if (s) { - *pValue = wcstod((wchar_t*)s, (wchar_t**)&pEnd); - } +inline bool XFA_FMDChar::string2number(const wchar_t* s, + double* pValue, + const wchar_t*& pEnd) { + if (s) + *pValue = wcstod(const_cast<wchar_t*>(s), const_cast<wchar_t**>(&pEnd)); + return 0; } @@ -148,7 +146,7 @@ const XFA_FM_TOKEN KEYWORD_END = TOKendif; } // namespace -const FX_WCHAR* XFA_FM_KeywordToString(XFA_FM_TOKEN op) { +const wchar_t* XFA_FM_KeywordToString(XFA_FM_TOKEN op) { if (op < KEYWORD_START || op > KEYWORD_END) return L""; return keyWords[op].m_keyword; @@ -199,12 +197,12 @@ CXFA_FMToken* CXFA_FMLexer::Scan() { XFA_FMDChar::inc(m_ptr); break; case ';': { - const FX_WCHAR* pTemp = 0; + const wchar_t* pTemp = 0; Comment(m_ptr, pTemp); m_ptr = pTemp; } break; case '"': { - const FX_WCHAR* pTemp = 0; + const wchar_t* pTemp = 0; p->m_type = TOKstring; iRet = String(p, m_ptr, pTemp); m_ptr = pTemp; @@ -221,7 +219,7 @@ CXFA_FMToken* CXFA_FMLexer::Scan() { case '8': case '9': { p->m_type = TOKnumber; - const FX_WCHAR* pTemp = 0; + const wchar_t* pTemp = 0; iRet = Number(p, m_ptr, pTemp); m_ptr = pTemp; if (iRet) { @@ -333,7 +331,7 @@ CXFA_FMToken* CXFA_FMLexer::Scan() { if (XFA_FMDChar::isAvalid(m_ptr)) { ch = XFA_FMDChar::get(m_ptr); if (ch == '/') { - const FX_WCHAR* pTemp = 0; + const wchar_t* pTemp = 0; Comment(m_ptr, pTemp); m_ptr = pTemp; break; @@ -365,7 +363,7 @@ CXFA_FMToken* CXFA_FMLexer::Scan() { return p; } else if (ch <= '9' && ch >= '0') { p->m_type = TOKnumber; - const FX_WCHAR* pTemp = 0; + const wchar_t* pTemp = 0; XFA_FMDChar::dec(m_ptr); iRet = Number(p, m_ptr, pTemp); m_ptr = pTemp; @@ -389,7 +387,7 @@ CXFA_FMToken* CXFA_FMLexer::Scan() { XFA_FMDChar::inc(m_ptr); break; default: { - const FX_WCHAR* pTemp = 0; + const wchar_t* pTemp = 0; iRet = Identifiers(p, m_ptr, pTemp); m_ptr = pTemp; if (iRet) { @@ -403,23 +401,22 @@ CXFA_FMToken* CXFA_FMLexer::Scan() { } uint32_t CXFA_FMLexer::Number(CXFA_FMToken* t, - const FX_WCHAR* p, - const FX_WCHAR*& pEnd) { - FX_DOUBLE number = 0; - if (XFA_FMDChar::string2number(p, &number, pEnd)) { + const wchar_t* p, + const wchar_t*& pEnd) { + double number = 0; + if (XFA_FMDChar::string2number(p, &number, pEnd)) return 1; - } - if (pEnd && XFA_FMDChar::isAlpha(pEnd)) { + if (pEnd && XFA_FMDChar::isAlpha(pEnd)) return 1; - } + t->m_wstring = CFX_WideStringC(p, (pEnd - p)); return 0; } uint32_t CXFA_FMLexer::String(CXFA_FMToken* t, - const FX_WCHAR* p, - const FX_WCHAR*& pEnd) { - const FX_WCHAR* pStart = p; + const wchar_t* p, + const wchar_t*& pEnd) { + const wchar_t* pStart = p; uint16_t ch = 0; XFA_FMDChar::inc(p); ch = XFA_FMDChar::get(p); @@ -457,9 +454,9 @@ uint32_t CXFA_FMLexer::String(CXFA_FMToken* t, } uint32_t CXFA_FMLexer::Identifiers(CXFA_FMToken* t, - const FX_WCHAR* p, - const FX_WCHAR*& pEnd) { - const FX_WCHAR* pStart = p; + const wchar_t* p, + const wchar_t*& pEnd) { + const wchar_t* pStart = p; uint16_t ch = 0; ch = XFA_FMDChar::get(p); XFA_FMDChar::inc(p); @@ -491,7 +488,7 @@ uint32_t CXFA_FMLexer::Identifiers(CXFA_FMToken* t, return 0; } -void CXFA_FMLexer::Comment(const FX_WCHAR* p, const FX_WCHAR*& pEnd) { +void CXFA_FMLexer::Comment(const wchar_t* p, const wchar_t*& pEnd) { unsigned ch = 0; XFA_FMDChar::inc(p); ch = XFA_FMDChar::get(p); @@ -530,7 +527,7 @@ XFA_FM_TOKEN CXFA_FMLexer::IsKeyword(const CFX_WideStringC& str) { return TOKidentifier; } -void CXFA_FMLexer::Error(const FX_WCHAR* msg, ...) { +void CXFA_FMLexer::Error(const wchar_t* msg, ...) { m_pErrorInfo->linenum = m_uCurrentLine; va_list ap; va_start(ap, msg); diff --git a/chromium/third_party/pdfium/xfa/fxfa/fm2js/xfa_lexer.h b/chromium/third_party/pdfium/xfa/fxfa/fm2js/xfa_lexer.h index 9395c06814f..860c50f30a9 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/fm2js/xfa_lexer.h +++ b/chromium/third_party/pdfium/xfa/fxfa/fm2js/xfa_lexer.h @@ -86,10 +86,10 @@ enum XFA_FM_TOKEN { struct XFA_FMKeyword { XFA_FM_TOKEN m_type; uint32_t m_uHash; - const FX_WCHAR* m_keyword; + const wchar_t* m_keyword; }; -const FX_WCHAR* XFA_FM_KeywordToString(XFA_FM_TOKEN op); +const wchar_t* XFA_FM_KeywordToString(XFA_FM_TOKEN op); class CXFA_FMToken { public: @@ -107,27 +107,25 @@ class CXFA_FMLexer { ~CXFA_FMLexer(); CXFA_FMToken* NextToken(); - uint32_t Number(CXFA_FMToken* t, const FX_WCHAR* p, const FX_WCHAR*& pEnd); - uint32_t String(CXFA_FMToken* t, const FX_WCHAR* p, const FX_WCHAR*& pEnd); - uint32_t Identifiers(CXFA_FMToken* t, - const FX_WCHAR* p, - const FX_WCHAR*& pEnd); - void Comment(const FX_WCHAR* p, const FX_WCHAR*& pEnd); + uint32_t Number(CXFA_FMToken* t, const wchar_t* p, const wchar_t*& pEnd); + uint32_t String(CXFA_FMToken* t, const wchar_t* p, const wchar_t*& pEnd); + uint32_t Identifiers(CXFA_FMToken* t, const wchar_t* p, const wchar_t*& pEnd); + void Comment(const wchar_t* p, const wchar_t*& pEnd); XFA_FM_TOKEN IsKeyword(const CFX_WideStringC& p); void SetCurrentLine(uint32_t line) { m_uCurrentLine = line; } void SetToken(CXFA_FMToken* pToken) { if (m_pToken.get() != pToken) m_pToken.reset(pToken); } - const FX_WCHAR* SavePos() { return m_ptr; } - void RestorePos(const FX_WCHAR* pPos) { m_ptr = pPos; } - void Error(const FX_WCHAR* msg, ...); + const wchar_t* SavePos() { return m_ptr; } + void RestorePos(const wchar_t* pPos) { m_ptr = pPos; } + void Error(const wchar_t* msg, ...); bool HasError() const; - protected: + private: CXFA_FMToken* Scan(); - const FX_WCHAR* m_ptr; + const wchar_t* m_ptr; uint32_t m_uCurrentLine; std::unique_ptr<CXFA_FMToken> m_pToken; CXFA_FMErrorInfo* m_pErrorInfo; diff --git a/chromium/third_party/pdfium/xfa/fxfa/fm2js/xfa_simpleexpression.cpp b/chromium/third_party/pdfium/xfa/fxfa/fm2js/xfa_simpleexpression.cpp index 686ddaa17dc..7bc703b59b9 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/fm2js/xfa_simpleexpression.cpp +++ b/chromium/third_party/pdfium/xfa/fxfa/fm2js/xfa_simpleexpression.cpp @@ -12,7 +12,7 @@ namespace { -const FX_WCHAR* const gs_lpStrExpFuncName[] = { +const wchar_t* const gs_lpStrExpFuncName[] = { L"foxit_xfa_formcalc_runtime.assign_value_operator", L"foxit_xfa_formcalc_runtime.logical_or_operator", L"foxit_xfa_formcalc_runtime.logical_and_operator", @@ -42,7 +42,7 @@ const FX_WCHAR* const gs_lpStrExpFuncName[] = { struct XFA_FMBuildInFunc { uint32_t m_uHash; - const FX_WCHAR* m_buildinfunc; + const wchar_t* m_buildinfunc; }; const XFA_FMBuildInFunc g_BuildInFuncs[] = { @@ -83,7 +83,7 @@ const XFA_FMBuildInFunc g_BuildInFuncs[] = { struct XFA_FMSOMMethod { uint32_t m_uHash; - const FX_WCHAR* m_wsSomMethodName; + const wchar_t* m_wsSomMethodName; uint32_t m_dParameters; }; const XFA_FMSOMMethod gs_FMSomMethods[] = { @@ -155,7 +155,7 @@ void CXFA_FMStringExpression::ToJavaScript(CFX_WideTextBuf& javascript) { CFX_WideString tempStr(m_wsString); if (tempStr.GetLength() > 2) { javascript.AppendChar(L'\"'); - FX_WCHAR oneChar; + wchar_t oneChar; for (int16_t i = 1; i < tempStr.GetLength() - 1; i++) { oneChar = tempStr[i]; switch (oneChar) { diff --git a/chromium/third_party/pdfium/xfa/fxfa/fm2js/xfa_simpleexpression_unittest.cpp b/chromium/third_party/pdfium/xfa/fxfa/fm2js/xfa_simpleexpression_unittest.cpp index 7826d9b53c3..a2c7f1b878a 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/fm2js/xfa_simpleexpression_unittest.cpp +++ b/chromium/third_party/pdfium/xfa/fxfa/fm2js/xfa_simpleexpression_unittest.cpp @@ -8,10 +8,13 @@ #include <utility> #include "testing/gtest/include/gtest/gtest.h" +#include "testing/test_support.h" #include "third_party/base/ptr_util.h" #include "xfa/fxfa/fm2js/xfa_lexer.h" -TEST(FMCallExpression, more_than_32_arguments) { +class FMCallExpressionTest : public pdfium::FPDF_Test {}; + +TEST_F(FMCallExpressionTest, more_than_32_arguments) { // Use sign as it has 3 object parameters at positions 0, 5, and 6. auto exp = pdfium::MakeUnique<CXFA_FMIdentifierExpression>(0, L"sign"); diff --git a/chromium/third_party/pdfium/xfa/fxfa/fxfa.h b/chromium/third_party/pdfium/xfa/fxfa/fxfa.h index dd5fc0fcbc4..559035cba1a 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/fxfa.h +++ b/chromium/third_party/pdfium/xfa/fxfa/fxfa.h @@ -10,8 +10,8 @@ #include <vector> #include "core/fxcrt/cfx_retain_ptr.h" +#include "xfa/fxfa/cxfa_widgetacc.h" #include "xfa/fxfa/fxfa_basic.h" -#include "xfa/fxfa/fxfa_widget.h" class CFGAS_GEFont; class CFX_Graphics; @@ -39,24 +39,15 @@ class IXFA_WidgetIterator; #define XFA_IDNo 3 #define XFA_IDYes 4 -#define XFA_DOCVIEW_View 0x00000000 -#define XFA_DOCVIEW_MasterPage 0x00000001 -#define XFA_DOCVIEW_Design 0x00000002 -#define XFA_DOCTYPE_Dynamic 0 -#define XFA_DOCTYPE_Static 1 -#define XFA_DOCTYPE_XDP 2 +// Note, values match fpdf_formfill.h DOCTYPE_* flags. +enum class XFA_DocType { PDF = 0, Dynamic = 1, Static = 2 }; + #define XFA_PARSESTATUS_StatusErr -3 #define XFA_PARSESTATUS_StreamErr -2 #define XFA_PARSESTATUS_SyntaxErr -1 #define XFA_PARSESTATUS_Ready 0 #define XFA_PARSESTATUS_Done 100 -#define XFA_VALIDATE_preSubmit 1 -#define XFA_VALIDATE_prePrint 2 -#define XFA_VALIDATE_preExecute 3 -#define XFA_VALIDATE_preSave 4 -#define XFA_INVALIDATE_AllPages 0x00000000 -#define XFA_INVALIDATE_CurrentPage 0x00000001 #define XFA_PRINTOPT_ShowDialog 0x00000001 #define XFA_PRINTOPT_CanCancel 0x00000002 #define XFA_PRINTOPT_ShrinkPage 0x00000004 @@ -233,14 +224,13 @@ class IXFA_DocEnvironment { virtual void SetChangeMark(CXFA_FFDoc* hDoc) = 0; virtual void InvalidateRect(CXFA_FFPageView* pPageView, - const CFX_RectF& rt, - uint32_t dwFlags) = 0; + const CFX_RectF& rt) = 0; virtual void DisplayCaret(CXFA_FFWidget* hWidget, bool bVisible, const CFX_RectF* pRtAnchor) = 0; virtual bool GetPopupPos(CXFA_FFWidget* hWidget, - FX_FLOAT fMinPopup, - FX_FLOAT fMaxPopup, + float fMinPopup, + float fMaxPopup, const CFX_RectF& rtAnchor, CFX_RectF& rtPopup) = 0; virtual bool PopupMenu(CXFA_FFWidget* hWidget, CFX_PointF ptPopup) = 0; diff --git a/chromium/third_party/pdfium/xfa/fxfa/fxfa_basic.h b/chromium/third_party/pdfium/xfa/fxfa/fxfa_basic.h index d16f50fd90d..a33f8c81538 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/fxfa_basic.h +++ b/chromium/third_party/pdfium/xfa/fxfa/fxfa_basic.h @@ -90,9 +90,9 @@ enum XFA_XDPPACKET_FLAGS { }; struct XFA_PACKETINFO { uint32_t uHash; - const FX_WCHAR* pName; + const wchar_t* pName; XFA_XDPPACKET eName; - const FX_WCHAR* pURI; + const wchar_t* pURI; uint32_t eFlags; }; @@ -928,7 +928,7 @@ enum class XFA_Element : int32_t { }; struct XFA_ELEMENTINFO { uint32_t uHash; - const FX_WCHAR* pName; + const wchar_t* pName; XFA_Element eName; uint32_t dwPackets; XFA_ObjectType eObjectType; @@ -944,7 +944,7 @@ enum XFA_ATTRIBUTETYPE { }; struct XFA_ATTRIBUTEINFO { uint32_t uHash; - const FX_WCHAR* pName; + const wchar_t* pName; XFA_ATTRIBUTE eName; XFA_ATTRIBUTETYPE eType; uint32_t dwPackets; @@ -974,7 +974,7 @@ struct XFA_PROPERTY { struct XFA_ATTRIBUTEENUMINFO { uint32_t uHash; - const FX_WCHAR* pName; + const wchar_t* pName; XFA_ATTRIBUTEENUM eName; }; @@ -1004,7 +1004,7 @@ class CXFA_Object; typedef void (CXFA_Object::*XFA_METHOD_CALLBACK)(CFXJSE_Arguments* pArguments); struct XFA_METHODINFO { uint32_t uHash; - const FX_WCHAR* pName; + const wchar_t* pName; XFA_METHOD_CALLBACK lpfnCallback; }; @@ -1017,7 +1017,7 @@ enum XFA_SCRIPT_TYPE { }; struct XFA_SCRIPTATTRIBUTEINFO { uint32_t uHash; - const FX_WCHAR* pName; + const wchar_t* pName; XFA_ATTRIBUTE_CALLBACK lpfnCallback; int32_t eAttribute; uint16_t eValueType; diff --git a/chromium/third_party/pdfium/xfa/fxfa/parser/cscript_datawindow.cpp b/chromium/third_party/pdfium/xfa/fxfa/parser/cscript_datawindow.cpp index c0354a112c5..e2d9f043d17 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/parser/cscript_datawindow.cpp +++ b/chromium/third_party/pdfium/xfa/fxfa/parser/cscript_datawindow.cpp @@ -8,8 +8,7 @@ #include "fxjs/cfxjse_arguments.h" #include "xfa/fxfa/parser/cxfa_document.h" -#include "xfa/fxfa/parser/xfa_localemgr.h" -#include "xfa/fxfa/parser/xfa_object.h" +#include "xfa/fxfa/parser/cxfa_localemgr.h" #include "xfa/fxfa/parser/xfa_utils.h" CScript_DataWindow::CScript_DataWindow(CXFA_Document* pDocument) diff --git a/chromium/third_party/pdfium/xfa/fxfa/parser/cscript_datawindow.h b/chromium/third_party/pdfium/xfa/fxfa/parser/cscript_datawindow.h index e41b7fe17da..ae123168912 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/parser/cscript_datawindow.h +++ b/chromium/third_party/pdfium/xfa/fxfa/parser/cscript_datawindow.h @@ -7,8 +7,9 @@ #ifndef XFA_FXFA_PARSER_CSCRIPT_DATAWINDOW_H_ #define XFA_FXFA_PARSER_CSCRIPT_DATAWINDOW_H_ -#include "fxjs/cfxjse_arguments.h" -#include "xfa/fxfa/parser/xfa_object.h" +#include "xfa/fxfa/parser/cxfa_object.h" + +class CFXJSE_Arguments; class CScript_DataWindow : public CXFA_Object { public: diff --git a/chromium/third_party/pdfium/xfa/fxfa/parser/cscript_eventpseudomodel.cpp b/chromium/third_party/pdfium/xfa/fxfa/parser/cscript_eventpseudomodel.cpp index 8cfedd29987..c57b0bdc781 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/parser/cscript_eventpseudomodel.cpp +++ b/chromium/third_party/pdfium/xfa/fxfa/parser/cscript_eventpseudomodel.cpp @@ -9,12 +9,11 @@ #include "fxjs/cfxjse_arguments.h" #include "xfa/fxfa/app/xfa_ffnotify.h" #include "xfa/fxfa/cxfa_eventparam.h" +#include "xfa/fxfa/cxfa_ffwidgethandler.h" #include "xfa/fxfa/parser/cxfa_document.h" +#include "xfa/fxfa/parser/cxfa_localemgr.h" #include "xfa/fxfa/parser/cxfa_scriptcontext.h" -#include "xfa/fxfa/parser/xfa_localemgr.h" -#include "xfa/fxfa/parser/xfa_object.h" #include "xfa/fxfa/parser/xfa_utils.h" -#include "xfa/fxfa/xfa_ffwidgethandler.h" namespace { diff --git a/chromium/third_party/pdfium/xfa/fxfa/parser/cscript_eventpseudomodel.h b/chromium/third_party/pdfium/xfa/fxfa/parser/cscript_eventpseudomodel.h index 6415287c8e3..dfad255d7ef 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/parser/cscript_eventpseudomodel.h +++ b/chromium/third_party/pdfium/xfa/fxfa/parser/cscript_eventpseudomodel.h @@ -8,7 +8,7 @@ #define XFA_FXFA_PARSER_CSCRIPT_EVENTPSEUDOMODEL_H_ #include "fxjs/cfxjse_arguments.h" -#include "xfa/fxfa/parser/xfa_object.h" +#include "xfa/fxfa/parser/cxfa_object.h" enum class XFA_Event { Change = 0, @@ -63,7 +63,7 @@ class CScript_EventPseudoModel : public CXFA_Object { void Emit(CFXJSE_Arguments* pArguments); void Reset(CFXJSE_Arguments* pArguments); - protected: + private: void Property(CFXJSE_Value* pValue, XFA_Event dwFlag, bool bSetting); }; diff --git a/chromium/third_party/pdfium/xfa/fxfa/parser/cscript_hostpseudomodel.cpp b/chromium/third_party/pdfium/xfa/fxfa/parser/cscript_hostpseudomodel.cpp index a06e02f56d3..d2633ec4aee 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/parser/cscript_hostpseudomodel.cpp +++ b/chromium/third_party/pdfium/xfa/fxfa/parser/cscript_hostpseudomodel.cpp @@ -12,9 +12,9 @@ #include "xfa/fxfa/app/xfa_ffnotify.h" #include "xfa/fxfa/parser/cxfa_document.h" #include "xfa/fxfa/parser/cxfa_layoutprocessor.h" +#include "xfa/fxfa/parser/cxfa_localemgr.h" +#include "xfa/fxfa/parser/cxfa_node.h" #include "xfa/fxfa/parser/cxfa_scriptcontext.h" -#include "xfa/fxfa/parser/xfa_localemgr.h" -#include "xfa/fxfa/parser/xfa_object.h" #include "xfa/fxfa/parser/xfa_resolvenode_rs.h" #include "xfa/fxfa/parser/xfa_utils.h" @@ -224,6 +224,7 @@ void CScript_HostPseudoModel::GotoURL(CFXJSE_Arguments* pArguments) { } pNotify->GetDocEnvironment()->GotoURL(hDoc, wsURL); } + void CScript_HostPseudoModel::OpenList(CFXJSE_Arguments* pArguments) { if (!m_pDocument->GetScriptContext()->IsRunAtClient()) { return; @@ -256,10 +257,10 @@ void CScript_HostPseudoModel::OpenList(CFXJSE_Arguments* pArguments) { XFA_RESOLVENODE_RS resoveNodeRS; int32_t iRet = pScriptContext->ResolveObjects( pObject, pValue->ToWideString().AsStringC(), resoveNodeRS, dwFlag); - if (iRet < 1 || !resoveNodeRS.nodes[0]->IsNode()) + if (iRet < 1 || !resoveNodeRS.objects.front()->IsNode()) return; - pNode = resoveNodeRS.nodes[0]->AsNode(); + pNode = resoveNodeRS.objects.front()->AsNode(); } } CXFA_LayoutProcessor* pDocLayout = m_pDocument->GetDocLayout(); @@ -322,10 +323,10 @@ static int32_t XFA_FilterName(const CFX_WideStringC& wsExpression, if (nStart >= iLength) { return iLength; } - FX_WCHAR* pBuf = wsFilter.GetBuffer(iLength - nStart); + wchar_t* pBuf = wsFilter.GetBuffer(iLength - nStart); int32_t nCount = 0; - const FX_WCHAR* pSrc = wsExpression.c_str(); - FX_WCHAR wCur; + const wchar_t* pSrc = wsExpression.c_str(); + wchar_t wCur; while (nStart < iLength) { wCur = pSrc[nStart++]; if (wCur == ',') { @@ -364,22 +365,22 @@ void CScript_HostPseudoModel::ResetData(CFXJSE_Arguments* pArguments) { while (iStart < iExpLength) { iStart = XFA_FilterName(wsExpression.AsStringC(), iStart, wsName); CXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext(); - if (!pScriptContext) { + if (!pScriptContext) return; - } + CXFA_Object* pObject = pScriptContext->GetThisObject(); - if (!pObject) { + if (!pObject) return; - } + uint32_t dwFlag = XFA_RESOLVENODE_Children | XFA_RESOLVENODE_Parent | XFA_RESOLVENODE_Siblings; XFA_RESOLVENODE_RS resoveNodeRS; int32_t iRet = pScriptContext->ResolveObjects(pObject, wsName.AsStringC(), resoveNodeRS, dwFlag); - if (iRet < 1 || !resoveNodeRS.nodes[0]->IsNode()) { + if (iRet < 1 || !resoveNodeRS.objects.front()->IsNode()) { continue; } - pNode = resoveNodeRS.nodes[0]->AsNode(); + pNode = resoveNodeRS.objects.front()->AsNode(); pNotify->ResetData(pNode->GetWidgetData()); } if (!pNode) { @@ -437,10 +438,10 @@ void CScript_HostPseudoModel::SetFocus(CFXJSE_Arguments* pArguments) { XFA_RESOLVENODE_RS resoveNodeRS; int32_t iRet = pScriptContext->ResolveObjects( pObject, pValue->ToWideString().AsStringC(), resoveNodeRS, dwFlag); - if (iRet < 1 || !resoveNodeRS.nodes[0]->IsNode()) + if (iRet < 1 || !resoveNodeRS.objects.front()->IsNode()) return; - pNode = resoveNodeRS.nodes[0]->AsNode(); + pNode = resoveNodeRS.objects.front()->AsNode(); } } pNotify->SetFocusWidgetNode(pNode); diff --git a/chromium/third_party/pdfium/xfa/fxfa/parser/cscript_hostpseudomodel.h b/chromium/third_party/pdfium/xfa/fxfa/parser/cscript_hostpseudomodel.h index 7d24a1d2b42..821f88d1376 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/parser/cscript_hostpseudomodel.h +++ b/chromium/third_party/pdfium/xfa/fxfa/parser/cscript_hostpseudomodel.h @@ -7,9 +7,10 @@ #ifndef XFA_FXFA_PARSER_CSCRIPT_HOSTPSEUDOMODEL_H_ #define XFA_FXFA_PARSER_CSCRIPT_HOSTPSEUDOMODEL_H_ -#include "fxjs/cfxjse_arguments.h" -#include "xfa/fxfa/parser/cxfa_document.h" -#include "xfa/fxfa/parser/xfa_object.h" +#include "xfa/fxfa/parser/cxfa_object.h" + +class CFXJSE_Arguments; +class CXFA_Document; class CScript_HostPseudoModel : public CXFA_Object { public: @@ -50,12 +51,10 @@ class CScript_HostPseudoModel : public CXFA_Object { void PageDown(CFXJSE_Arguments* pArguments); void CurrentDateTime(CFXJSE_Arguments* pArguments); - protected: + private: bool ValidateArgsForMsg(CFXJSE_Arguments* pArguments, int32_t iArgIndex, CFX_WideString& wsValue); - - private: void ThrowSetLanguageException() const; void ThrowSetNumPagesException() const; void ThrowSetPlatformException() const; diff --git a/chromium/third_party/pdfium/xfa/fxfa/parser/cscript_layoutpseudomodel.cpp b/chromium/third_party/pdfium/xfa/fxfa/parser/cscript_layoutpseudomodel.cpp index 152b5686195..693d4029a36 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/parser/cscript_layoutpseudomodel.cpp +++ b/chromium/third_party/pdfium/xfa/fxfa/parser/cscript_layoutpseudomodel.cpp @@ -11,16 +11,17 @@ #include "fxjs/cfxjse_arguments.h" #include "third_party/base/stl_util.h" #include "xfa/fxfa/app/xfa_ffnotify.h" +#include "xfa/fxfa/parser/cxfa_arraynodelist.h" #include "xfa/fxfa/parser/cxfa_containerlayoutitem.h" #include "xfa/fxfa/parser/cxfa_contentlayoutitem.h" #include "xfa/fxfa/parser/cxfa_document.h" #include "xfa/fxfa/parser/cxfa_layoutitem.h" #include "xfa/fxfa/parser/cxfa_layoutprocessor.h" +#include "xfa/fxfa/parser/cxfa_localemgr.h" #include "xfa/fxfa/parser/cxfa_measurement.h" +#include "xfa/fxfa/parser/cxfa_node.h" #include "xfa/fxfa/parser/cxfa_scriptcontext.h" #include "xfa/fxfa/parser/cxfa_traversestrategy_contentlayoutitem.h" -#include "xfa/fxfa/parser/xfa_localemgr.h" -#include "xfa/fxfa/parser/xfa_object.h" #include "xfa/fxfa/parser/xfa_utils.h" CScript_LayoutPseudoModel::CScript_LayoutPseudoModel(CXFA_Document* pDocument) @@ -50,7 +51,7 @@ void CScript_LayoutPseudoModel::HWXY(CFXJSE_Arguments* pArguments, XFA_LAYOUTMODEL_HWXY layoutModel) { int32_t iLength = pArguments->GetLength(); if (iLength < 1 || iLength > 3) { - const FX_WCHAR* methodName = nullptr; + const wchar_t* methodName = nullptr; switch (layoutModel) { case XFA_LAYOUTMODEL_H: methodName = L"h"; @@ -122,7 +123,7 @@ void CScript_LayoutPseudoModel::HWXY(CFXJSE_Arguments* pArguments, break; } XFA_UNIT unit = measure.GetUnit(wsUnit.AsStringC()); - FX_FLOAT fValue = measure.ToUnit(unit); + float fValue = measure.ToUnit(unit); fValue = FXSYS_round(fValue * 1000) / 1000.0f; if (pValue) pValue->SetFloat(fValue); @@ -209,39 +210,38 @@ void CScript_LayoutPseudoModel::Page(CFXJSE_Arguments* pArguments) { PageImp(pArguments, false); } -void CScript_LayoutPseudoModel::GetObjArray(CXFA_LayoutProcessor* pDocLayout, - int32_t iPageNo, - const CFX_WideString& wsType, - bool bOnPageArea, - CXFA_NodeArray& retArray) { +std::vector<CXFA_Node*> CScript_LayoutPseudoModel::GetObjArray( + CXFA_LayoutProcessor* pDocLayout, + int32_t iPageNo, + const CFX_WideString& wsType, + bool bOnPageArea) { CXFA_ContainerLayoutItem* pLayoutPage = pDocLayout->GetPage(iPageNo); - if (!pLayoutPage) { - return; - } + if (!pLayoutPage) + return std::vector<CXFA_Node*>(); + + std::vector<CXFA_Node*> retArray; if (wsType == L"pageArea") { - if (CXFA_Node* pMasterPage = pLayoutPage->m_pFormNode) { - retArray.Add(pMasterPage); - } - return; + if (pLayoutPage->m_pFormNode) + retArray.push_back(pLayoutPage->m_pFormNode); + return retArray; } if (wsType == L"contentArea") { for (CXFA_LayoutItem* pItem = pLayoutPage->m_pFirstChild; pItem; pItem = pItem->m_pNextSibling) { - if (pItem->m_pFormNode->GetElementType() == XFA_Element::ContentArea) { - retArray.Add(pItem->m_pFormNode); - } + if (pItem->m_pFormNode->GetElementType() == XFA_Element::ContentArea) + retArray.push_back(pItem->m_pFormNode); } - return; + return retArray; } std::set<CXFA_Node*> formItems; if (wsType.IsEmpty()) { - if (CXFA_Node* pMasterPage = pLayoutPage->m_pFormNode) { - retArray.Add(pMasterPage); - } + if (pLayoutPage->m_pFormNode) + retArray.push_back(pLayoutPage->m_pFormNode); + for (CXFA_LayoutItem* pItem = pLayoutPage->m_pFirstChild; pItem; pItem = pItem->m_pNextSibling) { if (pItem->m_pFormNode->GetElementType() == XFA_Element::ContentArea) { - retArray.Add(pItem->m_pFormNode); + retArray.push_back(pItem->m_pFormNode); if (!bOnPageArea) { CXFA_NodeIteratorTemplate<CXFA_ContentLayoutItem, CXFA_TraverseStrategy_ContentLayoutItem> @@ -260,7 +260,7 @@ void CScript_LayoutPseudoModel::GetObjArray(CXFA_LayoutProcessor* pDocLayout, continue; formItems.insert(pItemChild->m_pFormNode); - retArray.Add(pItemChild->m_pFormNode); + retArray.push_back(pItemChild->m_pFormNode); } } } else { @@ -281,12 +281,12 @@ void CScript_LayoutPseudoModel::GetObjArray(CXFA_LayoutProcessor* pDocLayout, if (pdfium::ContainsValue(formItems, pItemChild->m_pFormNode)) continue; formItems.insert(pItemChild->m_pFormNode); - retArray.Add(pItemChild->m_pFormNode); + retArray.push_back(pItemChild->m_pFormNode); } } } } - return; + return retArray; } XFA_Element eType = XFA_Element::Unknown; if (wsType == L"field") { @@ -315,7 +315,7 @@ void CScript_LayoutPseudoModel::GetObjArray(CXFA_LayoutProcessor* pDocLayout, if (pdfium::ContainsValue(formItems, pItemChild->m_pFormNode)) continue; formItems.insert(pItemChild->m_pFormNode); - retArray.Add(pItemChild->m_pFormNode); + retArray.push_back(pItemChild->m_pFormNode); } } } else { @@ -332,13 +332,13 @@ void CScript_LayoutPseudoModel::GetObjArray(CXFA_LayoutProcessor* pDocLayout, if (pdfium::ContainsValue(formItems, pItemChild->m_pFormNode)) continue; formItems.insert(pItemChild->m_pFormNode); - retArray.Add(pItemChild->m_pFormNode); + retArray.push_back(pItemChild->m_pFormNode); } } } } - return; } + return retArray; } void CScript_LayoutPseudoModel::PageContent(CFXJSE_Arguments* pArguments) { @@ -350,30 +350,30 @@ void CScript_LayoutPseudoModel::PageContent(CFXJSE_Arguments* pArguments) { int32_t iIndex = 0; CFX_WideString wsType; bool bOnPageArea = false; - if (iLength >= 1) { + if (iLength >= 1) iIndex = pArguments->GetInt32(0); - } + if (iLength >= 2) { CFX_ByteString bsType = pArguments->GetUTF8String(1); wsType = CFX_WideString::FromUTF8(bsType.AsStringC()); } - if (iLength >= 3) { + if (iLength >= 3) bOnPageArea = pArguments->GetInt32(2) == 0 ? false : true; - } + CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); - if (!pNotify) { + if (!pNotify) return; - } + CXFA_LayoutProcessor* pDocLayout = m_pDocument->GetDocLayout(); - if (!pDocLayout) { + if (!pDocLayout) return; - } - CXFA_NodeArray retArray; - GetObjArray(pDocLayout, iIndex, wsType, bOnPageArea, retArray); - CXFA_ArrayNodeList* pArrayNodeList = new CXFA_ArrayNodeList(m_pDocument); - pArrayNodeList->SetArrayNodeList(retArray); + + auto pArrayNodeList = pdfium::MakeUnique<CXFA_ArrayNodeList>(m_pDocument); + pArrayNodeList->SetArrayNodeList( + GetObjArray(pDocLayout, iIndex, wsType, bOnPageArea)); pArguments->GetReturnValue()->SetObject( - pArrayNodeList, m_pDocument->GetScriptContext()->GetJseNormalClass()); + pArrayNodeList.release(), + m_pDocument->GetScriptContext()->GetJseNormalClass()); } void CScript_LayoutPseudoModel::AbsPageCount(CFXJSE_Arguments* pArguments) { @@ -397,12 +397,11 @@ void CScript_LayoutPseudoModel::SheetCountInBatch( void CScript_LayoutPseudoModel::Relayout(CFXJSE_Arguments* pArguments) { CXFA_Node* pRootNode = m_pDocument->GetRoot(); CXFA_Node* pFormRoot = pRootNode->GetFirstChildByClass(XFA_Element::Form); - ASSERT(pFormRoot); CXFA_Node* pContentRootNode = pFormRoot->GetNodeItem(XFA_NODEITEM_FirstChild); CXFA_LayoutProcessor* pLayoutProcessor = m_pDocument->GetLayoutProcessor(); - if (pContentRootNode) { + if (pContentRootNode) pLayoutProcessor->AddChangedContainer(pContentRootNode); - } + pLayoutProcessor->SetForceReLayout(true); } @@ -451,7 +450,7 @@ void CScript_LayoutPseudoModel::PageImp(CFXJSE_Arguments* pArguments, bool bAbsPage) { int32_t iLength = pArguments->GetLength(); if (iLength != 1) { - const FX_WCHAR* methodName; + const wchar_t* methodName; if (bAbsPage) { methodName = L"absPage"; } else { diff --git a/chromium/third_party/pdfium/xfa/fxfa/parser/cscript_layoutpseudomodel.h b/chromium/third_party/pdfium/xfa/fxfa/parser/cscript_layoutpseudomodel.h index 55a00db14ae..ea31a4205ef 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/parser/cscript_layoutpseudomodel.h +++ b/chromium/third_party/pdfium/xfa/fxfa/parser/cscript_layoutpseudomodel.h @@ -7,8 +7,9 @@ #ifndef XFA_FXFA_PARSER_CSCRIPT_LAYOUTPSEUDOMODEL_H_ #define XFA_FXFA_PARSER_CSCRIPT_LAYOUTPSEUDOMODEL_H_ -#include "fxjs/cfxjse_arguments.h" -#include "xfa/fxfa/parser/xfa_object.h" +#include <vector> + +#include "xfa/fxfa/parser/cxfa_object.h" enum XFA_LAYOUTMODEL_HWXY { XFA_LAYOUTMODEL_H, @@ -17,6 +18,7 @@ enum XFA_LAYOUTMODEL_HWXY { XFA_LAYOUTMODEL_Y }; +class CFXJSE_Arguments; class CXFA_LayoutProcessor; class CScript_LayoutPseudoModel : public CXFA_Object { @@ -48,15 +50,12 @@ class CScript_LayoutPseudoModel : public CXFA_Object { void SheetCount(CFXJSE_Arguments* pArguments); void AbsPage(CFXJSE_Arguments* pArguments); - protected: - void GetObjArray(CXFA_LayoutProcessor* pDocLayout, - int32_t iPageNo, - const CFX_WideString& wsType, - bool bOnPageArea, - CXFA_NodeArray& retArray); - void PageImp(CFXJSE_Arguments* pArguments, bool bAbsPage); - private: + std::vector<CXFA_Node*> GetObjArray(CXFA_LayoutProcessor* pDocLayout, + int32_t iPageNo, + const CFX_WideString& wsType, + bool bOnPageArea); + void PageImp(CFXJSE_Arguments* pArguments, bool bAbsPage); void ThrowSetReadyException() const; }; diff --git a/chromium/third_party/pdfium/xfa/fxfa/parser/cscript_logpseudomodel.cpp b/chromium/third_party/pdfium/xfa/fxfa/parser/cscript_logpseudomodel.cpp index 48ccce027fa..d9563ac93e7 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/parser/cscript_logpseudomodel.cpp +++ b/chromium/third_party/pdfium/xfa/fxfa/parser/cscript_logpseudomodel.cpp @@ -8,8 +8,7 @@ #include "fxjs/cfxjse_arguments.h" #include "xfa/fxfa/parser/cxfa_document.h" -#include "xfa/fxfa/parser/xfa_localemgr.h" -#include "xfa/fxfa/parser/xfa_object.h" +#include "xfa/fxfa/parser/cxfa_localemgr.h" #include "xfa/fxfa/parser/xfa_utils.h" CScript_LogPseudoModel::CScript_LogPseudoModel(CXFA_Document* pDocument) diff --git a/chromium/third_party/pdfium/xfa/fxfa/parser/cscript_logpseudomodel.h b/chromium/third_party/pdfium/xfa/fxfa/parser/cscript_logpseudomodel.h index 18f9f51ae7a..2e465e851b5 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/parser/cscript_logpseudomodel.h +++ b/chromium/third_party/pdfium/xfa/fxfa/parser/cscript_logpseudomodel.h @@ -7,8 +7,9 @@ #ifndef XFA_FXFA_PARSER_CSCRIPT_LOGPSEUDOMODEL_H_ #define XFA_FXFA_PARSER_CSCRIPT_LOGPSEUDOMODEL_H_ -#include "fxjs/cfxjse_arguments.h" -#include "xfa/fxfa/parser/xfa_object.h" +#include "xfa/fxfa/parser/cxfa_object.h" + +class CFXJSE_Arguments; class CScript_LogPseudoModel : public CXFA_Object { public: diff --git a/chromium/third_party/pdfium/xfa/fxfa/parser/cscript_signaturepseudomodel.cpp b/chromium/third_party/pdfium/xfa/fxfa/parser/cscript_signaturepseudomodel.cpp index e5874a61cc6..0886809db1b 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/parser/cscript_signaturepseudomodel.cpp +++ b/chromium/third_party/pdfium/xfa/fxfa/parser/cscript_signaturepseudomodel.cpp @@ -9,9 +9,8 @@ #include "fxjs/cfxjse_arguments.h" #include "xfa/fxfa/app/xfa_ffnotify.h" #include "xfa/fxfa/parser/cxfa_document.h" +#include "xfa/fxfa/parser/cxfa_localemgr.h" #include "xfa/fxfa/parser/cxfa_scriptcontext.h" -#include "xfa/fxfa/parser/xfa_localemgr.h" -#include "xfa/fxfa/parser/xfa_object.h" #include "xfa/fxfa/parser/xfa_utils.h" CScript_SignaturePseudoModel::CScript_SignaturePseudoModel( diff --git a/chromium/third_party/pdfium/xfa/fxfa/parser/cscript_signaturepseudomodel.h b/chromium/third_party/pdfium/xfa/fxfa/parser/cscript_signaturepseudomodel.h index 4f9ded06632..ee527443206 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/parser/cscript_signaturepseudomodel.h +++ b/chromium/third_party/pdfium/xfa/fxfa/parser/cscript_signaturepseudomodel.h @@ -7,8 +7,9 @@ #ifndef XFA_FXFA_PARSER_CSCRIPT_SIGNATUREPSEUDOMODEL_H_ #define XFA_FXFA_PARSER_CSCRIPT_SIGNATUREPSEUDOMODEL_H_ -#include "fxjs/cfxjse_arguments.h" -#include "xfa/fxfa/parser/xfa_object.h" +#include "xfa/fxfa/parser/cxfa_object.h" + +class CFXJSE_Arguments; class CScript_SignaturePseudoModel : public CXFA_Object { public: diff --git a/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_arraynodelist.cpp b/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_arraynodelist.cpp index 8c9040a1214..03966c3c6c1 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_arraynodelist.cpp +++ b/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_arraynodelist.cpp @@ -4,58 +4,51 @@ // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com -#include "xfa/fxfa/parser/xfa_object.h" +#include "xfa/fxfa/parser/cxfa_arraynodelist.h" + +#include <vector> + +#include "third_party/base/stl_util.h" CXFA_ArrayNodeList::CXFA_ArrayNodeList(CXFA_Document* pDocument) : CXFA_NodeList(pDocument) {} CXFA_ArrayNodeList::~CXFA_ArrayNodeList() {} -void CXFA_ArrayNodeList::SetArrayNodeList(const CXFA_NodeArray& srcArray) { - if (srcArray.GetSize() > 0) { - m_array.Copy(srcArray); - } +void CXFA_ArrayNodeList::SetArrayNodeList( + const std::vector<CXFA_Node*>& srcArray) { + if (!srcArray.empty()) + m_array = srcArray; } int32_t CXFA_ArrayNodeList::GetLength() { - return m_array.GetSize(); + return pdfium::CollectionSize<int32_t>(m_array); } bool CXFA_ArrayNodeList::Append(CXFA_Node* pNode) { - m_array.Add(pNode); + m_array.push_back(pNode); return true; } bool CXFA_ArrayNodeList::Insert(CXFA_Node* pNewNode, CXFA_Node* pBeforeNode) { if (!pBeforeNode) { - m_array.Add(pNewNode); + m_array.push_back(pNewNode); } else { - int32_t iSize = m_array.GetSize(); - for (int32_t i = 0; i < iSize; ++i) { - if (m_array[i] == pBeforeNode) { - m_array.InsertAt(i, pNewNode); - break; - } - } + auto it = std::find(m_array.begin(), m_array.end(), pBeforeNode); + if (it != m_array.end()) + m_array.insert(it, pNewNode); } return true; } bool CXFA_ArrayNodeList::Remove(CXFA_Node* pNode) { - int32_t iSize = m_array.GetSize(); - for (int32_t i = 0; i < iSize; ++i) { - if (m_array[i] == pNode) { - m_array.RemoveAt(i); - break; - } - } + auto it = std::find(m_array.begin(), m_array.end(), pNode); + if (it != m_array.end()) + m_array.erase(it); return true; } CXFA_Node* CXFA_ArrayNodeList::Item(int32_t iIndex) { - int32_t iSize = m_array.GetSize(); - if (iIndex >= 0 && iIndex < iSize) { - return m_array[iIndex]; - } - return nullptr; + int32_t iSize = pdfium::CollectionSize<int32_t>(m_array); + return (iIndex >= 0 && iIndex < iSize) ? m_array[iIndex] : nullptr; } diff --git a/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_arraynodelist.h b/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_arraynodelist.h new file mode 100644 index 00000000000..ba00f3045e5 --- /dev/null +++ b/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_arraynodelist.h @@ -0,0 +1,35 @@ +// Copyright 2017 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#ifndef XFA_FXFA_PARSER_CXFA_ARRAYNODELIST_H_ +#define XFA_FXFA_PARSER_CXFA_ARRAYNODELIST_H_ + +#include <vector> + +#include "xfa/fxfa/parser/cxfa_nodelist.h" + +class CXFA_Document; +class CXFA_Node; + +class CXFA_ArrayNodeList : public CXFA_NodeList { + public: + explicit CXFA_ArrayNodeList(CXFA_Document* pDocument); + ~CXFA_ArrayNodeList() override; + + // From CXFA_NodeList. + int32_t GetLength() override; + bool Append(CXFA_Node* pNode) override; + bool Insert(CXFA_Node* pNewNode, CXFA_Node* pBeforeNode) override; + bool Remove(CXFA_Node* pNode) override; + CXFA_Node* Item(int32_t iIndex) override; + + void SetArrayNodeList(const std::vector<CXFA_Node*>& srcArray); + + private: + std::vector<CXFA_Node*> m_array; +}; + +#endif // XFA_FXFA_PARSER_CXFA_ARRAYNODELIST_H_ diff --git a/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_assist.cpp b/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_assist.cpp index 894e729d6d2..809081d9601 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_assist.cpp +++ b/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_assist.cpp @@ -6,7 +6,7 @@ #include "xfa/fxfa/parser/cxfa_assist.h" -#include "xfa/fxfa/parser/xfa_object.h" +#include "xfa/fxfa/parser/cxfa_node.h" CXFA_Assist::CXFA_Assist(CXFA_Node* pNode) : CXFA_Data(pNode) {} diff --git a/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_attachnodelist.cpp b/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_attachnodelist.cpp index c23b900af69..9c0b0fd18eb 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_attachnodelist.cpp +++ b/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_attachnodelist.cpp @@ -4,7 +4,9 @@ // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com -#include "xfa/fxfa/parser/xfa_object.h" +#include "xfa/fxfa/parser/cxfa_attachnodelist.h" + +#include "xfa/fxfa/parser/cxfa_node.h" CXFA_AttachNodeList::CXFA_AttachNodeList(CXFA_Document* pDocument, CXFA_Node* pAttachNode) @@ -20,17 +22,17 @@ int32_t CXFA_AttachNodeList::GetLength() { bool CXFA_AttachNodeList::Append(CXFA_Node* pNode) { CXFA_Node* pParent = pNode->GetNodeItem(XFA_NODEITEM_Parent); - if (pParent) { + if (pParent) pParent->RemoveChild(pNode); - } + return m_pAttachNode->InsertChild(pNode); } bool CXFA_AttachNodeList::Insert(CXFA_Node* pNewNode, CXFA_Node* pBeforeNode) { CXFA_Node* pParent = pNewNode->GetNodeItem(XFA_NODEITEM_Parent); - if (pParent) { + if (pParent) pParent->RemoveChild(pNewNode); - } + return m_pAttachNode->InsertChild(pNewNode, pBeforeNode); } diff --git a/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_attachnodelist.h b/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_attachnodelist.h new file mode 100644 index 00000000000..3bb771a476e --- /dev/null +++ b/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_attachnodelist.h @@ -0,0 +1,30 @@ +// Copyright 2017 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#ifndef XFA_FXFA_PARSER_CXFA_ATTACHNODELIST_H_ +#define XFA_FXFA_PARSER_CXFA_ATTACHNODELIST_H_ + +#include "xfa/fxfa/parser/cxfa_nodelist.h" + +class CXFA_Document; +class CXFA_Node; + +class CXFA_AttachNodeList : public CXFA_NodeList { + public: + CXFA_AttachNodeList(CXFA_Document* pDocument, CXFA_Node* pAttachNode); + + // From CXFA_NodeList. + int32_t GetLength() override; + bool Append(CXFA_Node* pNode) override; + bool Insert(CXFA_Node* pNewNode, CXFA_Node* pBeforeNode) override; + bool Remove(CXFA_Node* pNode) override; + CXFA_Node* Item(int32_t iIndex) override; + + private: + CXFA_Node* m_pAttachNode; +}; + +#endif // XFA_FXFA_PARSER_CXFA_ATTACHNODELIST_H_ diff --git a/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_bind.cpp b/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_bind.cpp index 16efd1f4404..aac2c183212 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_bind.cpp +++ b/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_bind.cpp @@ -6,7 +6,7 @@ #include "xfa/fxfa/parser/cxfa_bind.h" -#include "xfa/fxfa/parser/xfa_object.h" +#include "xfa/fxfa/parser/cxfa_node.h" CXFA_Bind::CXFA_Bind(CXFA_Node* pNode) : CXFA_Data(pNode) {} diff --git a/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_binditems.cpp b/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_binditems.cpp index fdb4f0c3762..c3c5cabe4ec 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_binditems.cpp +++ b/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_binditems.cpp @@ -6,7 +6,7 @@ #include "xfa/fxfa/parser/cxfa_binditems.h" -#include "xfa/fxfa/parser/xfa_object.h" +#include "xfa/fxfa/parser/cxfa_node.h" CXFA_BindItems::CXFA_BindItems(CXFA_Node* pNode) : CXFA_Data(pNode) {} diff --git a/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_box.cpp b/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_box.cpp index 552c98031a4..300edd01ad3 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_box.cpp +++ b/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_box.cpp @@ -8,7 +8,7 @@ #include "xfa/fxfa/parser/cxfa_corner.h" #include "xfa/fxfa/parser/cxfa_measurement.h" -#include "xfa/fxfa/parser/xfa_object.h" +#include "xfa/fxfa/parser/cxfa_node.h" namespace { @@ -109,7 +109,7 @@ bool CXFA_Box::IsCircular() const { return m_pNode->GetBoolean(XFA_ATTRIBUTE_Circular); } -bool CXFA_Box::GetStartAngle(FX_FLOAT& fStartAngle) const { +bool CXFA_Box::GetStartAngle(float& fStartAngle) const { fStartAngle = 0; if (!m_pNode) return false; @@ -122,7 +122,7 @@ bool CXFA_Box::GetStartAngle(FX_FLOAT& fStartAngle) const { return bRet; } -bool CXFA_Box::GetSweepAngle(FX_FLOAT& fSweepAngle) const { +bool CXFA_Box::GetSweepAngle(float& fSweepAngle) const { fSweepAngle = 360; if (!m_pNode) return false; @@ -148,7 +148,7 @@ CXFA_Margin CXFA_Box::GetMargin() const { : nullptr); } -int32_t CXFA_Box::Get3DStyle(bool& bVisible, FX_FLOAT& fThickness) const { +int32_t CXFA_Box::Get3DStyle(bool& bVisible, float& fThickness) const { if (IsArc()) return 0; diff --git a/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_box.h b/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_box.h index a0af2f449b2..d2b79fae566 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_box.h +++ b/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_box.h @@ -32,23 +32,23 @@ class CXFA_Box : public CXFA_Data { CXFA_Edge GetEdge(int32_t nIndex = 0) const; void GetStrokes(std::vector<CXFA_Stroke>* strokes) const; bool IsCircular() const; - bool GetStartAngle(FX_FLOAT& fStartAngle) const; - FX_FLOAT GetStartAngle() const { - FX_FLOAT fStartAngle; + bool GetStartAngle(float& fStartAngle) const; + float GetStartAngle() const { + float fStartAngle; GetStartAngle(fStartAngle); return fStartAngle; } - bool GetSweepAngle(FX_FLOAT& fSweepAngle) const; - FX_FLOAT GetSweepAngle() const { - FX_FLOAT fSweepAngle; + bool GetSweepAngle(float& fSweepAngle) const; + float GetSweepAngle() const { + float fSweepAngle; GetSweepAngle(fSweepAngle); return fSweepAngle; } CXFA_Fill GetFill(bool bModified = false) const; CXFA_Margin GetMargin() const; - int32_t Get3DStyle(bool& bVisible, FX_FLOAT& fThickness) const; + int32_t Get3DStyle(bool& bVisible, float& fThickness) const; }; #endif // XFA_FXFA_PARSER_CXFA_BOX_H_ diff --git a/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_calculate.cpp b/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_calculate.cpp index d7b1f71caa8..bc89d817772 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_calculate.cpp +++ b/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_calculate.cpp @@ -6,8 +6,8 @@ #include "xfa/fxfa/parser/cxfa_calculate.h" +#include "xfa/fxfa/parser/cxfa_node.h" #include "xfa/fxfa/parser/cxfa_text.h" -#include "xfa/fxfa/parser/xfa_object.h" CXFA_Calculate::CXFA_Calculate(CXFA_Node* pNode) : CXFA_Data(pNode) {} diff --git a/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_caption.cpp b/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_caption.cpp index 7f9e88e8e7f..1be4a206e72 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_caption.cpp +++ b/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_caption.cpp @@ -7,7 +7,7 @@ #include "xfa/fxfa/parser/cxfa_caption.h" #include "xfa/fxfa/parser/cxfa_measurement.h" -#include "xfa/fxfa/parser/xfa_object.h" +#include "xfa/fxfa/parser/cxfa_node.h" CXFA_Caption::CXFA_Caption(CXFA_Node* pNode) : CXFA_Data(pNode) {} @@ -23,7 +23,7 @@ int32_t CXFA_Caption::GetPlacementType() { return eAttr; } -FX_FLOAT CXFA_Caption::GetReserve() { +float CXFA_Caption::GetReserve() { CXFA_Measurement ms; m_pNode->TryMeasure(XFA_ATTRIBUTE_Reserve, ms); return ms.ToUnit(XFA_UNIT_Pt); diff --git a/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_caption.h b/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_caption.h index 70dd435653f..74650ef9a23 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_caption.h +++ b/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_caption.h @@ -20,7 +20,7 @@ class CXFA_Caption : public CXFA_Data { int32_t GetPresence(); int32_t GetPlacementType(); - FX_FLOAT GetReserve(); + float GetReserve(); CXFA_Margin GetMargin(); CXFA_Font GetFont(); CXFA_Value GetValue(); diff --git a/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_containerlayoutitem.cpp b/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_containerlayoutitem.cpp index 5ef29f14cfb..cf4e1ce3f33 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_containerlayoutitem.cpp +++ b/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_containerlayoutitem.cpp @@ -9,6 +9,7 @@ #include "xfa/fxfa/parser/cxfa_layoutpagemgr.h" #include "xfa/fxfa/parser/cxfa_layoutprocessor.h" #include "xfa/fxfa/parser/cxfa_measurement.h" +#include "xfa/fxfa/parser/cxfa_node.h" CXFA_ContainerLayoutItem::CXFA_ContainerLayoutItem(CXFA_Node* pNode) : CXFA_LayoutItem(pNode, false), m_pOldSubform(nullptr) {} diff --git a/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_contentlayoutitem.cpp b/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_contentlayoutitem.cpp index a10a6782794..c8acff2b1c3 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_contentlayoutitem.cpp +++ b/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_contentlayoutitem.cpp @@ -6,6 +6,8 @@ #include "xfa/fxfa/parser/cxfa_contentlayoutitem.h" +#include "xfa/fxfa/parser/cxfa_node.h" + CXFA_ContentLayoutItem::CXFA_ContentLayoutItem(CXFA_Node* pNode) : CXFA_LayoutItem(pNode, true), m_pPrev(nullptr), diff --git a/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_contentlayoutitem.h b/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_contentlayoutitem.h index 9ac1dceb425..9d1fc2abcfb 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_contentlayoutitem.h +++ b/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_contentlayoutitem.h @@ -9,6 +9,8 @@ #include "xfa/fxfa/parser/cxfa_layoutitem.h" +#define XFA_LAYOUTITEMKEY (void*)(uintptr_t) FXBSTR_ID('L', 'Y', 'I', 'M') + class CXFA_ContentLayoutItem : public CXFA_LayoutItem { public: explicit CXFA_ContentLayoutItem(CXFA_Node* pNode); @@ -18,7 +20,7 @@ class CXFA_ContentLayoutItem : public CXFA_LayoutItem { CXFA_ContentLayoutItem* m_pNext; CFX_PointF m_sPos; CFX_SizeF m_sSize; - uint32_t m_dwStatus; + mutable uint32_t m_dwStatus; }; inline CXFA_ContentLayoutItem* ToContentLayoutItem(CXFA_LayoutItem* pItem) { diff --git a/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_data.cpp b/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_data.cpp index 19f85088b8d..9f265b41be3 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_data.cpp +++ b/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_data.cpp @@ -8,7 +8,7 @@ #include "core/fxcrt/fx_ext.h" #include "xfa/fxfa/parser/cxfa_measurement.h" -#include "xfa/fxfa/parser/xfa_object.h" +#include "xfa/fxfa/parser/cxfa_node.h" // Static. FX_ARGB CXFA_Data::ToColor(const CFX_WideStringC& wsValue) { @@ -17,7 +17,7 @@ FX_ARGB CXFA_Data::ToColor(const CFX_WideStringC& wsValue) { return 0xff000000; int cc = 0; - const FX_WCHAR* str = wsValue.c_str(); + const wchar_t* str = wsValue.c_str(); int len = wsValue.GetLength(); while (FXSYS_iswspace(str[cc]) && cc < len) cc++; @@ -66,7 +66,7 @@ XFA_Element CXFA_Data::GetElementType() const { } bool CXFA_Data::TryMeasure(XFA_ATTRIBUTE eAttr, - FX_FLOAT& fValue, + float& fValue, bool bUseDefault) const { CXFA_Measurement ms; if (m_pNode->TryMeasure(eAttr, ms, bUseDefault)) { @@ -76,7 +76,7 @@ bool CXFA_Data::TryMeasure(XFA_ATTRIBUTE eAttr, return false; } -bool CXFA_Data::SetMeasure(XFA_ATTRIBUTE eAttr, FX_FLOAT fValue) { +bool CXFA_Data::SetMeasure(XFA_ATTRIBUTE eAttr, float fValue) { CXFA_Measurement ms(fValue, XFA_UNIT_Pt); return m_pNode->SetMeasure(eAttr, ms); } diff --git a/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_data.h b/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_data.h index 890486d5fa5..90b689020b2 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_data.h +++ b/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_data.h @@ -19,15 +19,15 @@ class CXFA_Data { explicit CXFA_Data(CXFA_Node* pNode) : m_pNode(pNode) {} - operator bool() const { return !!m_pNode; } + explicit operator bool() const { return !!m_pNode; } CXFA_Node* GetNode() const { return m_pNode; } XFA_Element GetElementType() const; protected: bool TryMeasure(XFA_ATTRIBUTE eAttr, - FX_FLOAT& fValue, + float& fValue, bool bUseDefault = false) const; - bool SetMeasure(XFA_ATTRIBUTE eAttr, FX_FLOAT fValue); + bool SetMeasure(XFA_ATTRIBUTE eAttr, float fValue); CXFA_Node* m_pNode; }; diff --git a/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_dataexporter.cpp b/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_dataexporter.cpp index fe9947527d6..3963b162cbe 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_dataexporter.cpp +++ b/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_dataexporter.cpp @@ -10,11 +10,14 @@ #include "core/fxcrt/fx_basic.h" #include "third_party/base/stl_util.h" -#include "xfa/fde/xml/fde_xml_imp.h" +#include "xfa/fde/xml/cfde_xmldoc.h" +#include "xfa/fde/xml/cfde_xmlelement.h" +#include "xfa/fde/xml/cfde_xmlnode.h" #include "xfa/fgas/crt/fgas_codepage.h" #include "xfa/fxfa/parser/cxfa_document.h" +#include "xfa/fxfa/parser/cxfa_node.h" #include "xfa/fxfa/parser/cxfa_widgetdata.h" -#include "xfa/fxfa/parser/xfa_object.h" +#include "xfa/fxfa/parser/xfa_utils.h" namespace { @@ -45,12 +48,33 @@ CFX_WideString ExportEncodeAttribute(const CFX_WideString& str) { return textBuf.MakeString(); } +const uint16_t g_XMLValidCharRange[][2] = {{0x09, 0x09}, + {0x0A, 0x0A}, + {0x0D, 0x0D}, + {0x20, 0xD7FF}, + {0xE000, 0xFFFD}}; +bool IsXMLValidChar(wchar_t ch) { + int32_t iStart = 0; + int32_t iEnd = FX_ArraySize(g_XMLValidCharRange) - 1; + while (iStart <= iEnd) { + int32_t iMid = (iStart + iEnd) / 2; + if (ch < g_XMLValidCharRange[iMid][0]) { + iEnd = iMid - 1; + } else if (ch > g_XMLValidCharRange[iMid][1]) { + iStart = iMid + 1; + } else { + return true; + } + } + return false; +} + CFX_WideString ExportEncodeContent(const CFX_WideStringC& str) { CFX_WideTextBuf textBuf; int32_t iLen = str.GetLength(); for (int32_t i = 0; i < iLen; i++) { - FX_WCHAR ch = str.GetAt(i); - if (!FDE_IsXMLValidChar(ch)) + wchar_t ch = str.GetAt(i); + if (!IsXMLValidChar(ch)) continue; if (ch == '&') { @@ -202,12 +226,8 @@ void RegenerateFormFile_Changed(CXFA_Node* pNode, CFX_RetainPtr<IFX_MemoryStream> pMemStream = IFX_MemoryStream::Create(true); - - // Note: ambiguous without cast below. - CFX_RetainPtr<IFGAS_Stream> pTempStream = IFGAS_Stream::CreateStream( - CFX_RetainPtr<IFX_SeekableWriteStream>(pMemStream), - FX_STREAMACCESS_Text | FX_STREAMACCESS_Write | - FX_STREAMACCESS_Append); + CFX_RetainPtr<IFGAS_Stream> pTempStream = + IFGAS_Stream::CreateWriteStream(pMemStream); pTempStream->SetCodePage(FX_CODEPAGE_UTF8); pRichTextXML->SaveXMLNode(pTempStream); @@ -332,7 +352,7 @@ void RegenerateFormFile_Container(CXFA_Node* pNode, RegenerateFormFile_Changed(pNode, buf, bSaveXML); FX_STRSIZE nLen = buf.GetLength(); if (nLen > 0) - pStream->WriteString((const FX_WCHAR*)buf.GetBuffer(), nLen); + pStream->WriteString((const wchar_t*)buf.GetBuffer(), nLen); return; } @@ -379,21 +399,21 @@ void RegenerateFormFile_Container(CXFA_Node* pNode, void XFA_DataExporter_RegenerateFormFile( CXFA_Node* pNode, const CFX_RetainPtr<IFGAS_Stream>& pStream, - const FX_CHAR* pChecksum, + const char* pChecksum, bool bSaveXML) { if (pNode->IsModelNode()) { - static const FX_WCHAR s_pwsTagName[] = L"<form"; - static const FX_WCHAR s_pwsClose[] = L"</form\n>"; + static const wchar_t s_pwsTagName[] = L"<form"; + static const wchar_t s_pwsClose[] = L"</form\n>"; pStream->WriteString(s_pwsTagName, FXSYS_wcslen(s_pwsTagName)); if (pChecksum) { - static const FX_WCHAR s_pwChecksum[] = L" checksum=\""; + static const wchar_t s_pwChecksum[] = L" checksum=\""; CFX_WideString wsChecksum = CFX_WideString::FromUTF8(pChecksum); pStream->WriteString(s_pwChecksum, FXSYS_wcslen(s_pwChecksum)); pStream->WriteString(wsChecksum.c_str(), wsChecksum.GetLength()); pStream->WriteString(L"\"", 1); } pStream->WriteString(L" xmlns=\"", FXSYS_wcslen(L" xmlns=\"")); - const FX_WCHAR* pURI = XFA_GetPacketByIndex(XFA_PACKET_Form)->pURI; + const wchar_t* pURI = XFA_GetPacketByIndex(XFA_PACKET_Form)->pURI; pStream->WriteString(pURI, FXSYS_wcslen(pURI)); CFX_WideString wsVersionNumber; RecognizeXFAVersionNumber( @@ -460,14 +480,12 @@ bool CXFA_DataExporter::Export( const CFX_RetainPtr<IFX_SeekableWriteStream>& pWrite, CXFA_Node* pNode, uint32_t dwFlag, - const FX_CHAR* pChecksum) { + const char* pChecksum) { ASSERT(pWrite); if (!pWrite) return false; - CFX_RetainPtr<IFGAS_Stream> pStream = IFGAS_Stream::CreateStream( - pWrite, - FX_STREAMACCESS_Text | FX_STREAMACCESS_Write | FX_STREAMACCESS_Append); + CFX_RetainPtr<IFGAS_Stream> pStream = IFGAS_Stream::CreateWriteStream(pWrite); if (!pStream) return false; @@ -478,19 +496,19 @@ bool CXFA_DataExporter::Export( bool CXFA_DataExporter::Export(const CFX_RetainPtr<IFGAS_Stream>& pStream, CXFA_Node* pNode, uint32_t dwFlag, - const FX_CHAR* pChecksum) { + const char* pChecksum) { CFDE_XMLDoc* pXMLDoc = m_pDocument->GetXMLDoc(); if (pNode->IsModelNode()) { switch (pNode->GetPacketID()) { case XFA_XDPPACKET_XDP: { - static const FX_WCHAR s_pwsPreamble[] = + static const wchar_t s_pwsPreamble[] = L"<xdp:xdp xmlns:xdp=\"http://ns.adobe.com/xdp/\">"; pStream->WriteString(s_pwsPreamble, FXSYS_wcslen(s_pwsPreamble)); for (CXFA_Node* pChild = pNode->GetNodeItem(XFA_NODEITEM_FirstChild); pChild; pChild = pChild->GetNodeItem(XFA_NODEITEM_NextSibling)) { Export(pStream, pChild, dwFlag, pChecksum); } - static const FX_WCHAR s_pwsPostamble[] = L"</xdp:xdp\n>"; + static const wchar_t s_pwsPostamble[] = L"</xdp:xdp\n>"; pStream->WriteString(s_pwsPostamble, FXSYS_wcslen(s_pwsPostamble)); break; } diff --git a/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_dataexporter.h b/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_dataexporter.h index 0e5de007963..ac441ca21d3 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_dataexporter.h +++ b/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_dataexporter.h @@ -23,13 +23,13 @@ class CXFA_DataExporter { bool Export(const CFX_RetainPtr<IFX_SeekableWriteStream>& pWrite, CXFA_Node* pNode, uint32_t dwFlag, - const FX_CHAR* pChecksum); + const char* pChecksum); - protected: + private: bool Export(const CFX_RetainPtr<IFGAS_Stream>& pStream, CXFA_Node* pNode, uint32_t dwFlag, - const FX_CHAR* pChecksum); + const char* pChecksum); CXFA_Document* const m_pDocument; }; diff --git a/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_dataimporter.cpp b/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_dataimporter.cpp index 0199028ecd6..200841f5cb4 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_dataimporter.cpp +++ b/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_dataimporter.cpp @@ -10,12 +10,12 @@ #include "core/fxcrt/fx_stream.h" #include "third_party/base/ptr_util.h" -#include "xfa/fde/xml/fde_xml_imp.h" +#include "xfa/fde/xml/cfde_xmlnode.h" #include "xfa/fxfa/fxfa.h" #include "xfa/fxfa/fxfa_basic.h" #include "xfa/fxfa/parser/cxfa_document.h" +#include "xfa/fxfa/parser/cxfa_node.h" #include "xfa/fxfa/parser/cxfa_simple_parser.h" -#include "xfa/fxfa/parser/xfa_object.h" CXFA_DataImporter::CXFA_DataImporter(CXFA_Document* pDocument) : m_pDocument(pDocument) { diff --git a/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_dataimporter.h b/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_dataimporter.h index bf04b05846d..4e8bdda314e 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_dataimporter.h +++ b/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_dataimporter.h @@ -19,7 +19,7 @@ class CXFA_DataImporter { bool ImportData(const CFX_RetainPtr<IFX_SeekableReadStream>& pDataDocument); - protected: + private: CXFA_Document* const m_pDocument; }; diff --git a/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_document.cpp b/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_document.cpp index adb8eb2e0b9..7c979fec227 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_document.cpp +++ b/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_document.cpp @@ -15,9 +15,10 @@ #include "xfa/fxfa/parser/cxfa_document.h" #include "xfa/fxfa/parser/cxfa_document_parser.h" #include "xfa/fxfa/parser/cxfa_layoutprocessor.h" +#include "xfa/fxfa/parser/cxfa_localemgr.h" +#include "xfa/fxfa/parser/cxfa_node.h" #include "xfa/fxfa/parser/cxfa_scriptcontext.h" -#include "xfa/fxfa/parser/xfa_localemgr.h" -#include "xfa/fxfa/parser/xfa_object.h" +#include "xfa/fxfa/parser/cxfa_traversestrategy_xfanode.h" #include "xfa/fxfa/parser/xfa_resolvenode_rs.h" #include "xfa/fxfa/parser/xfa_utils.h" @@ -85,16 +86,7 @@ void MergeNode(CXFA_Document* pDocument, CXFA_Document::CXFA_Document(CXFA_DocumentParser* pParser) : m_pParser(pParser), - m_pScriptContext(nullptr), - m_pLayoutProcessor(nullptr), m_pRootNode(nullptr), - m_pLocalMgr(nullptr), - m_pScriptDataWindow(nullptr), - m_pScriptEvent(nullptr), - m_pScriptHost(nullptr), - m_pScriptLog(nullptr), - m_pScriptLayout(nullptr), - m_pScriptSignature(nullptr), m_eCurVersionMode(XFA_VERSION_DEFAULT), m_dwDocFlags(0) { ASSERT(m_pParser); @@ -107,8 +99,8 @@ CXFA_Document::~CXFA_Document() { CXFA_LayoutProcessor* CXFA_Document::GetLayoutProcessor() { if (!m_pLayoutProcessor) - m_pLayoutProcessor = new CXFA_LayoutProcessor(this); - return m_pLayoutProcessor; + m_pLayoutProcessor = pdfium::MakeUnique<CXFA_LayoutProcessor>(this); + return m_pLayoutProcessor.get(); } CXFA_LayoutProcessor* CXFA_Document::GetDocLayout() { @@ -116,24 +108,15 @@ CXFA_LayoutProcessor* CXFA_Document::GetDocLayout() { } void CXFA_Document::ClearLayoutData() { - delete m_pLayoutProcessor; - m_pLayoutProcessor = nullptr; - delete m_pScriptContext; - m_pScriptContext = nullptr; - delete m_pLocalMgr; - m_pLocalMgr = nullptr; - delete m_pScriptDataWindow; - m_pScriptDataWindow = nullptr; - delete m_pScriptEvent; - m_pScriptEvent = nullptr; - delete m_pScriptHost; - m_pScriptHost = nullptr; - delete m_pScriptLog; - m_pScriptLog = nullptr; - delete m_pScriptLayout; - m_pScriptLayout = nullptr; - delete m_pScriptSignature; - m_pScriptSignature = nullptr; + m_pLayoutProcessor.reset(); + m_pScriptContext.reset(); + m_pLocalMgr.reset(); + m_pScriptDataWindow.reset(); + m_pScriptEvent.reset(); + m_pScriptHost.reset(); + m_pScriptLog.reset(); + m_pScriptLayout.reset(); + m_pScriptSignature.reset(); } void CXFA_Document::SetRoot(CXFA_Node* pNewRoot) { @@ -186,33 +169,34 @@ CXFA_Object* CXFA_Document::GetXFAObject(XFA_HashCode dwNodeNameHash) { } case XFA_HASHCODE_DataWindow: { if (!m_pScriptDataWindow) - m_pScriptDataWindow = new CScript_DataWindow(this); - return m_pScriptDataWindow; + m_pScriptDataWindow = pdfium::MakeUnique<CScript_DataWindow>(this); + return m_pScriptDataWindow.get(); } case XFA_HASHCODE_Event: { if (!m_pScriptEvent) - m_pScriptEvent = new CScript_EventPseudoModel(this); - return m_pScriptEvent; + m_pScriptEvent = pdfium::MakeUnique<CScript_EventPseudoModel>(this); + return m_pScriptEvent.get(); } case XFA_HASHCODE_Host: { if (!m_pScriptHost) - m_pScriptHost = new CScript_HostPseudoModel(this); - return m_pScriptHost; + m_pScriptHost = pdfium::MakeUnique<CScript_HostPseudoModel>(this); + return m_pScriptHost.get(); } case XFA_HASHCODE_Log: { if (!m_pScriptLog) - m_pScriptLog = new CScript_LogPseudoModel(this); - return m_pScriptLog; + m_pScriptLog = pdfium::MakeUnique<CScript_LogPseudoModel>(this); + return m_pScriptLog.get(); } case XFA_HASHCODE_Signature: { if (!m_pScriptSignature) - m_pScriptSignature = new CScript_SignaturePseudoModel(this); - return m_pScriptSignature; + m_pScriptSignature = + pdfium::MakeUnique<CScript_SignaturePseudoModel>(this); + return m_pScriptSignature.get(); } case XFA_HASHCODE_Layout: { if (!m_pScriptLayout) - m_pScriptLayout = new CScript_LayoutPseudoModel(this); - return m_pScriptLayout; + m_pScriptLayout = pdfium::MakeUnique<CScript_LayoutPseudoModel>(this); + return m_pScriptLayout.get(); } default: return m_pRootNode->GetFirstChildByName(dwNodeNameHash); @@ -292,28 +276,27 @@ bool CXFA_Document::IsInteractive() { CXFA_LocaleMgr* CXFA_Document::GetLocalMgr() { if (!m_pLocalMgr) { - m_pLocalMgr = - new CXFA_LocaleMgr(ToNode(GetXFAObject(XFA_HASHCODE_LocaleSet)), - GetNotify()->GetAppProvider()->GetLanguage()); + m_pLocalMgr = pdfium::MakeUnique<CXFA_LocaleMgr>( + ToNode(GetXFAObject(XFA_HASHCODE_LocaleSet)), + GetNotify()->GetAppProvider()->GetLanguage()); } - return m_pLocalMgr; + return m_pLocalMgr.get(); } CXFA_ScriptContext* CXFA_Document::InitScriptContext(v8::Isolate* pIsolate) { - if (!m_pScriptContext) - m_pScriptContext = new CXFA_ScriptContext(this); - m_pScriptContext->Initialize(pIsolate); - return m_pScriptContext; + CXFA_ScriptContext* result = GetScriptContext(); + result->Initialize(pIsolate); + return result; } CXFA_ScriptContext* CXFA_Document::GetScriptContext() { if (!m_pScriptContext) - m_pScriptContext = new CXFA_ScriptContext(this); - return m_pScriptContext; + m_pScriptContext = pdfium::MakeUnique<CXFA_ScriptContext>(this); + return m_pScriptContext.get(); } XFA_VERSION CXFA_Document::RecognizeXFAVersionNumber( - CFX_WideString& wsTemplateNS) { + const CFX_WideString& wsTemplateNS) { CFX_WideStringC wsTemplateURIPrefix = XFA_GetPacketByIndex(XFA_PACKET_Template)->pURI; FX_STRSIZE nPrefixLength = wsTemplateURIPrefix.GetLength(); @@ -361,7 +344,7 @@ void CXFA_Document::DoProtoMerge() { return; std::map<uint32_t, CXFA_Node*> mIDMap; - CXFA_NodeSet sUseNodes; + std::unordered_set<CXFA_Node*> sUseNodes; CXFA_NodeIterator sIterator(pTemplateRoot); for (CXFA_Node* pNode = sIterator.GetCurrent(); pNode; pNode = sIterator.MoveToNext()) { @@ -418,8 +401,8 @@ void CXFA_Document::DoProtoMerge() { XFA_RESOLVENODE_RS resoveNodeRS; int32_t iRet = m_pScriptContext->ResolveObjects(pUseHrefNode, wsSOM, resoveNodeRS, dwFlag); - if (iRet > 0 && resoveNodeRS.nodes[0]->IsNode()) - pProtoNode = resoveNodeRS.nodes[0]->AsNode(); + if (iRet > 0 && resoveNodeRS.objects.front()->IsNode()) + pProtoNode = resoveNodeRS.objects.front()->AsNode(); } else if (!wsID.IsEmpty()) { auto it = mIDMap.find(FX_HashCode_GetW(wsID, false)); if (it == mIDMap.end()) diff --git a/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_document.h b/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_document.h index fdd230dca77..101b23332e5 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_document.h +++ b/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_document.h @@ -8,10 +8,12 @@ #define XFA_FXFA_PARSER_CXFA_DOCUMENT_H_ #include <map> +#include <memory> +#include <unordered_set> +#include <vector> #include "xfa/fxfa/fxfa.h" -#include "xfa/fxfa/parser/xfa_localemgr.h" -#include "xfa/fxfa/parser/xfa_object.h" +#include "xfa/fxfa/parser/cxfa_localemgr.h" enum XFA_VERSION { XFA_VERSION_UNKNOWN = 0, @@ -69,7 +71,7 @@ class CXFA_Document { CXFA_LocaleMgr* GetLocalMgr(); CXFA_Object* GetXFAObject(XFA_HashCode wsNodeNameHash); CXFA_Node* GetNodeByID(CXFA_Node* pRoot, const CFX_WideStringC& wsID); - CXFA_Node* GetNotBindNode(CXFA_ObjArray& arrayNodes); + CXFA_Node* GetNotBindNode(const std::vector<CXFA_Object*>& arrayNodes); CXFA_LayoutProcessor* GetLayoutProcessor(); CXFA_LayoutProcessor* GetDocLayout(); CXFA_ScriptContext* GetScriptContext(); @@ -85,7 +87,7 @@ class CXFA_Document { bool IsInteractive(); XFA_VERSION GetCurVersionMode() { return m_eCurVersionMode; } - XFA_VERSION RecognizeXFAVersionNumber(CFX_WideString& wsTemplateNS); + XFA_VERSION RecognizeXFAVersionNumber(const CFX_WideString& wsTemplateNS); CXFA_Node* CreateNode(uint32_t dwPacket, XFA_Element eElement); CXFA_Node* CreateNode(const XFA_PACKETINFO* pPacket, XFA_Element eElement); @@ -104,21 +106,21 @@ class CXFA_Document { void ClearLayoutData(); std::map<uint32_t, CXFA_Node*> m_rgGlobalBinding; - CXFA_NodeArray m_pPendingPageSet; + std::vector<CXFA_Node*> m_pPendingPageSet; - protected: + private: CXFA_DocumentParser* m_pParser; - CXFA_ScriptContext* m_pScriptContext; - CXFA_LayoutProcessor* m_pLayoutProcessor; CXFA_Node* m_pRootNode; - CXFA_LocaleMgr* m_pLocalMgr; - CScript_DataWindow* m_pScriptDataWindow; - CScript_EventPseudoModel* m_pScriptEvent; - CScript_HostPseudoModel* m_pScriptHost; - CScript_LogPseudoModel* m_pScriptLog; - CScript_LayoutPseudoModel* m_pScriptLayout; - CScript_SignaturePseudoModel* m_pScriptSignature; - CXFA_NodeSet m_PurgeNodes; + std::unique_ptr<CXFA_ScriptContext> m_pScriptContext; + std::unique_ptr<CXFA_LayoutProcessor> m_pLayoutProcessor; + std::unique_ptr<CXFA_LocaleMgr> m_pLocalMgr; + std::unique_ptr<CScript_DataWindow> m_pScriptDataWindow; + std::unique_ptr<CScript_EventPseudoModel> m_pScriptEvent; + std::unique_ptr<CScript_HostPseudoModel> m_pScriptHost; + std::unique_ptr<CScript_LogPseudoModel> m_pScriptLog; + std::unique_ptr<CScript_LayoutPseudoModel> m_pScriptLayout; + std::unique_ptr<CScript_SignaturePseudoModel> m_pScriptSignature; + std::unordered_set<CXFA_Node*> m_PurgeNodes; XFA_VERSION m_eCurVersionMode; uint32_t m_dwDocFlags; }; diff --git a/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_document_parser.cpp b/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_document_parser.cpp index 90be5687855..b855513f526 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_document_parser.cpp +++ b/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_document_parser.cpp @@ -7,6 +7,7 @@ #include "xfa/fxfa/parser/cxfa_document_parser.h" #include "third_party/base/ptr_util.h" +#include "xfa/fde/xml/cfde_xmldoc.h" #include "xfa/fxfa/fxfa.h" #include "xfa/fxfa/parser/cxfa_document.h" diff --git a/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_document_parser.h b/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_document_parser.h index 617bddf55be..9a219f74c10 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_document_parser.h +++ b/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_document_parser.h @@ -31,7 +31,7 @@ class CXFA_DocumentParser { CXFA_FFNotify* GetNotify() const; CXFA_Document* GetDocument() const; - protected: + private: CXFA_SimpleParser m_nodeParser; CXFA_FFNotify* m_pNotify; std::unique_ptr<CXFA_Document> m_pDocument; diff --git a/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_event.cpp b/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_event.cpp index 3e5639617b1..d7534289b38 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_event.cpp +++ b/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_event.cpp @@ -6,7 +6,7 @@ #include "xfa/fxfa/parser/cxfa_event.h" -#include "xfa/fxfa/parser/xfa_object.h" +#include "xfa/fxfa/parser/cxfa_node.h" CXFA_Event::CXFA_Event(CXFA_Node* pNode) : CXFA_Data(pNode) {} @@ -14,7 +14,7 @@ int32_t CXFA_Event::GetActivity() { return m_pNode->GetEnum(XFA_ATTRIBUTE_Activity); } -XFA_Element CXFA_Event::GetEventType() { +XFA_Element CXFA_Event::GetEventType() const { CXFA_Node* pChild = m_pNode->GetNodeItem(XFA_NODEITEM_FirstChild); while (pChild) { XFA_Element eType = pChild->GetElementType(); @@ -30,11 +30,11 @@ void CXFA_Event::GetRef(CFX_WideStringC& wsRef) { m_pNode->TryCData(XFA_ATTRIBUTE_Ref, wsRef); } -CXFA_Script CXFA_Event::GetScript() { +CXFA_Script CXFA_Event::GetScript() const { return CXFA_Script(m_pNode->GetChild(0, XFA_Element::Script)); } -CXFA_Submit CXFA_Event::GetSubmit() { +CXFA_Submit CXFA_Event::GetSubmit() const { return CXFA_Submit(m_pNode->GetChild(0, XFA_Element::Submit)); } diff --git a/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_event.h b/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_event.h index b151b399b59..fc0bcf34cc8 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_event.h +++ b/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_event.h @@ -21,12 +21,10 @@ class CXFA_Event : public CXFA_Data { explicit CXFA_Event(CXFA_Node* pNode); int32_t GetActivity(); - XFA_Element GetEventType(); + XFA_Element GetEventType() const; + CXFA_Script GetScript() const; + CXFA_Submit GetSubmit() const; void GetRef(CFX_WideStringC& wsRef); - - CXFA_Script GetScript(); - CXFA_Submit GetSubmit(); - void GetSignDataTarget(CFX_WideString& wsTarget); }; diff --git a/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_exdata.cpp b/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_exdata.cpp index bf1e930330e..ac82b3043cf 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_exdata.cpp +++ b/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_exdata.cpp @@ -6,7 +6,7 @@ #include "xfa/fxfa/parser/cxfa_exdata.h" -#include "xfa/fxfa/parser/xfa_object.h" +#include "xfa/fxfa/parser/cxfa_node.h" CXFA_ExData::CXFA_ExData(CXFA_Node* pNode) : CXFA_Data(pNode) {} diff --git a/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_fill.cpp b/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_fill.cpp index 63949c193dd..8621c3c961a 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_fill.cpp +++ b/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_fill.cpp @@ -6,7 +6,7 @@ #include "xfa/fxfa/parser/cxfa_fill.h" -#include "xfa/fxfa/parser/xfa_object.h" +#include "xfa/fxfa/parser/cxfa_node.h" CXFA_Fill::CXFA_Fill(CXFA_Node* pNode) : CXFA_Data(pNode) {} diff --git a/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_font.cpp b/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_font.cpp index cedfda6294e..56e04b75f75 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_font.cpp +++ b/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_font.cpp @@ -9,29 +9,29 @@ #include "core/fxge/fx_dib.h" #include "xfa/fxfa/parser/cxfa_fill.h" #include "xfa/fxfa/parser/cxfa_measurement.h" -#include "xfa/fxfa/parser/xfa_object.h" +#include "xfa/fxfa/parser/cxfa_node.h" CXFA_Font::CXFA_Font(CXFA_Node* pNode) : CXFA_Data(pNode) {} -FX_FLOAT CXFA_Font::GetBaselineShift() { +float CXFA_Font::GetBaselineShift() { return m_pNode->GetMeasure(XFA_ATTRIBUTE_BaselineShift).ToUnit(XFA_UNIT_Pt); } -FX_FLOAT CXFA_Font::GetHorizontalScale() { +float CXFA_Font::GetHorizontalScale() { CFX_WideString wsValue; m_pNode->TryCData(XFA_ATTRIBUTE_FontHorizontalScale, wsValue); int32_t iScale = FXSYS_wtoi(wsValue.c_str()); - return iScale > 0 ? (FX_FLOAT)iScale : 100.0f; + return iScale > 0 ? (float)iScale : 100.0f; } -FX_FLOAT CXFA_Font::GetVerticalScale() { +float CXFA_Font::GetVerticalScale() { CFX_WideString wsValue; m_pNode->TryCData(XFA_ATTRIBUTE_FontVerticalScale, wsValue); int32_t iScale = FXSYS_wtoi(wsValue.c_str()); - return iScale > 0 ? (FX_FLOAT)iScale : 100.0f; + return iScale > 0 ? (float)iScale : 100.0f; } -FX_FLOAT CXFA_Font::GetLetterSpacing() { +float CXFA_Font::GetLetterSpacing() { CFX_WideStringC wsValue; if (!m_pNode->TryCData(XFA_ATTRIBUTE_LetterSpacing, wsValue)) return 0; @@ -60,7 +60,7 @@ int32_t CXFA_Font::GetUnderlinePeriod() { return eAttr; } -FX_FLOAT CXFA_Font::GetFontSize() { +float CXFA_Font::GetFontSize() { CXFA_Measurement ms; m_pNode->TryMeasure(XFA_ATTRIBUTE_Size, ms); return ms.ToUnit(XFA_UNIT_Pt); diff --git a/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_font.h b/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_font.h index 0342f68b278..2a5fef11226 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_font.h +++ b/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_font.h @@ -16,14 +16,14 @@ class CXFA_Font : public CXFA_Data { public: explicit CXFA_Font(CXFA_Node* pNode); - FX_FLOAT GetBaselineShift(); - FX_FLOAT GetHorizontalScale(); - FX_FLOAT GetVerticalScale(); - FX_FLOAT GetLetterSpacing(); + float GetBaselineShift(); + float GetHorizontalScale(); + float GetVerticalScale(); + float GetLetterSpacing(); int32_t GetLineThrough(); int32_t GetUnderline(); int32_t GetUnderlinePeriod(); - FX_FLOAT GetFontSize(); + float GetFontSize(); void GetTypeface(CFX_WideStringC& wsTypeFace); bool IsBold(); diff --git a/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_image.cpp b/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_image.cpp index 8cf7fc1e230..8d14d629608 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_image.cpp +++ b/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_image.cpp @@ -6,7 +6,7 @@ #include "xfa/fxfa/parser/cxfa_image.h" -#include "xfa/fxfa/parser/xfa_object.h" +#include "xfa/fxfa/parser/cxfa_node.h" CXFA_Image::CXFA_Image(CXFA_Node* pNode, bool bDefValue) : CXFA_Data(pNode), m_bDefValue(bDefValue) {} diff --git a/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_image.h b/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_image.h index bf69897693e..204441ab6b5 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_image.h +++ b/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_image.h @@ -26,7 +26,7 @@ class CXFA_Image : public CXFA_Data { bool SetHref(const CFX_WideString& wsHref); bool SetTransferEncoding(int32_t iTransferEncoding); - protected: + private: bool m_bDefValue; }; diff --git a/chromium/third_party/pdfium/xfa/fxfa/parser/xfa_layout_itemlayout.cpp b/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_itemlayoutprocessor.cpp index dd38c963d68..8911227f3d6 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/parser/xfa_layout_itemlayout.cpp +++ b/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_itemlayoutprocessor.cpp @@ -4,7 +4,7 @@ // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com -#include "xfa/fxfa/parser/xfa_layout_itemlayout.h" +#include "xfa/fxfa/parser/cxfa_itemlayoutprocessor.h" #include <algorithm> #include <memory> @@ -17,26 +17,28 @@ #include "xfa/fxfa/parser/cxfa_containerlayoutitem.h" #include "xfa/fxfa/parser/cxfa_contentlayoutitem.h" #include "xfa/fxfa/parser/cxfa_document.h" +#include "xfa/fxfa/parser/cxfa_layoutcontext.h" #include "xfa/fxfa/parser/cxfa_layoutpagemgr.h" +#include "xfa/fxfa/parser/cxfa_localemgr.h" #include "xfa/fxfa/parser/cxfa_measurement.h" +#include "xfa/fxfa/parser/cxfa_node.h" #include "xfa/fxfa/parser/cxfa_occur.h" -#include "xfa/fxfa/parser/xfa_localemgr.h" -#include "xfa/fxfa/parser/xfa_object.h" +#include "xfa/fxfa/parser/cxfa_traversestrategy_xfanode.h" #include "xfa/fxfa/parser/xfa_utils.h" namespace { -std::vector<CFX_WideString> SeparateStringW(const FX_WCHAR* pStr, +std::vector<CFX_WideString> SeparateStringW(const wchar_t* pStr, int32_t iStrLen, - FX_WCHAR delimiter) { + wchar_t delimiter) { std::vector<CFX_WideString> ret; if (!pStr) return ret; if (iStrLen < 0) iStrLen = FXSYS_wcslen(pStr); - const FX_WCHAR* pToken = pStr; - const FX_WCHAR* pEnd = pStr + iStrLen; + const wchar_t* pToken = pStr; + const wchar_t* pEnd = pStr + iStrLen; while (true) { if (pStr >= pEnd || delimiter == *pStr) { ret.push_back(CFX_WideString(pToken, pStr - pToken)); @@ -50,8 +52,8 @@ std::vector<CFX_WideString> SeparateStringW(const FX_WCHAR* pStr, } void UpdateWidgetSize(CXFA_ContentLayoutItem* pLayoutItem, - FX_FLOAT* fWidth, - FX_FLOAT* fHeight) { + float* fWidth, + float* fHeight) { CXFA_Node* pNode = pLayoutItem->m_pFormNode; switch (pNode->GetElementType()) { case XFA_Element::Subform: @@ -114,9 +116,9 @@ CFX_SizeF CalculateContainerSpecifiedSize(CXFA_Node* pFormNode, CFX_SizeF CalculateContainerComponentSizeFromContentSize( CXFA_Node* pFormNode, bool bContainerWidthAutoSize, - FX_FLOAT fContentCalculatedWidth, + float fContentCalculatedWidth, bool bContainerHeightAutoSize, - FX_FLOAT fContentCalculatedHeight, + float fContentCalculatedHeight, const CFX_SizeF& currentContainerSize) { CFX_SizeF componentSize = currentContainerSize; CXFA_Node* pMarginNode = pFormNode->GetFirstChildByClass(XFA_Element::Margin); @@ -145,10 +147,9 @@ CFX_SizeF CalculateContainerComponentSizeFromContentSize( return componentSize; } -void RelocateTableRowCells( - CXFA_ContentLayoutItem* pLayoutRow, - const CFX_ArrayTemplate<FX_FLOAT>& rgSpecifiedColumnWidths, - XFA_ATTRIBUTEENUM eLayout) { +void RelocateTableRowCells(CXFA_ContentLayoutItem* pLayoutRow, + const std::vector<float>& rgSpecifiedColumnWidths, + XFA_ATTRIBUTEENUM eLayout) { bool bContainerWidthAutoSize = true; bool bContainerHeightAutoSize = true; CFX_SizeF containerSize = CalculateContainerSpecifiedSize( @@ -156,10 +157,10 @@ void RelocateTableRowCells( &bContainerHeightAutoSize); CXFA_Node* pMarginNode = pLayoutRow->m_pFormNode->GetFirstChildByClass(XFA_Element::Margin); - FX_FLOAT fLeftInset = 0; - FX_FLOAT fTopInset = 0; - FX_FLOAT fRightInset = 0; - FX_FLOAT fBottomInset = 0; + float fLeftInset = 0; + float fTopInset = 0; + float fRightInset = 0; + float fBottomInset = 0; if (pMarginNode) { fLeftInset = pMarginNode->GetMeasure(XFA_ATTRIBUTE_LeftInset).ToUnit(XFA_UNIT_Pt); @@ -171,28 +172,30 @@ void RelocateTableRowCells( pMarginNode->GetMeasure(XFA_ATTRIBUTE_BottomInset).ToUnit(XFA_UNIT_Pt); } - FX_FLOAT fContentWidthLimit = + float fContentWidthLimit = bContainerWidthAutoSize ? FLT_MAX : containerSize.width - fLeftInset - fRightInset; - FX_FLOAT fContentCurrentHeight = + float fContentCurrentHeight = pLayoutRow->m_sSize.height - fTopInset - fBottomInset; - FX_FLOAT fContentCalculatedWidth = 0; - FX_FLOAT fContentCalculatedHeight = 0; - FX_FLOAT fCurrentColX = 0; + float fContentCalculatedWidth = 0; + float fContentCalculatedHeight = 0; + float fCurrentColX = 0; int32_t nCurrentColIdx = 0; bool bMetWholeRowCell = false; - for (auto pLayoutChild = + for (auto* pLayoutChild = static_cast<CXFA_ContentLayoutItem*>(pLayoutRow->m_pFirstChild); pLayoutChild; pLayoutChild = static_cast<CXFA_ContentLayoutItem*>( pLayoutChild->m_pNextSibling)) { int32_t nOriginalColSpan = pLayoutChild->m_pFormNode->GetInteger(XFA_ATTRIBUTE_ColSpan); int32_t nColSpan = nOriginalColSpan; - FX_FLOAT fColSpanWidth = 0; + float fColSpanWidth = 0; if (nColSpan == -1 || - nCurrentColIdx + nColSpan > rgSpecifiedColumnWidths.GetSize()) { - nColSpan = rgSpecifiedColumnWidths.GetSize() - nCurrentColIdx; + nCurrentColIdx + nColSpan > + pdfium::CollectionSize<int32_t>(rgSpecifiedColumnWidths)) { + nColSpan = pdfium::CollectionSize<int32_t>(rgSpecifiedColumnWidths) - + nCurrentColIdx; } for (int32_t i = 0; i < nColSpan; i++) fColSpanWidth += rgSpecifiedColumnWidths[nCurrentColIdx + i]; @@ -212,7 +215,7 @@ void RelocateTableRowCells( fCurrentColX += fColSpanWidth; nCurrentColIdx += nColSpan; - FX_FLOAT fNewHeight = bContainerHeightAutoSize ? -1 : fContentCurrentHeight; + float fNewHeight = bContainerHeightAutoSize ? -1 : fContentCurrentHeight; UpdateWidgetSize(pLayoutChild, &fColSpanWidth, &fNewHeight); pLayoutChild->m_sSize.height = fNewHeight; if (bContainerHeightAutoSize) { @@ -228,12 +231,12 @@ void RelocateTableRowCells( pLayoutChild = (CXFA_ContentLayoutItem*)pLayoutChild->m_pNextSibling) { UpdateWidgetSize(pLayoutChild, &pLayoutChild->m_sSize.width, &fContentCalculatedHeight); - FX_FLOAT fOldChildHeight = pLayoutChild->m_sSize.height; + float fOldChildHeight = pLayoutChild->m_sSize.height; pLayoutChild->m_sSize.height = fContentCalculatedHeight; CXFA_Node* pParaNode = pLayoutChild->m_pFormNode->GetFirstChildByClass(XFA_Element::Para); if (pParaNode && pLayoutChild->m_pFirstChild) { - FX_FLOAT fOffHeight = fContentCalculatedHeight - fOldChildHeight; + float fOffHeight = fContentCalculatedHeight - fOldChildHeight; XFA_ATTRIBUTEENUM eVType = pParaNode->GetEnum(XFA_ATTRIBUTE_VAlign); switch (eVType) { case XFA_ATTRIBUTEENUM_Middle: @@ -260,7 +263,7 @@ void RelocateTableRowCells( } if (bContainerWidthAutoSize) { - FX_FLOAT fChildSuppliedWidth = fCurrentColX; + float fChildSuppliedWidth = fCurrentColX; if (fContentWidthLimit < FLT_MAX && fContentWidthLimit > fChildSuppliedWidth) { fChildSuppliedWidth = fContentWidthLimit; @@ -303,15 +306,15 @@ void UpdatePendingItemLayout(CXFA_ItemLayoutProcessor* pProcessor, } void AddTrailerBeforeSplit(CXFA_ItemLayoutProcessor* pProcessor, - FX_FLOAT fSplitPos, + float fSplitPos, CXFA_ContentLayoutItem* pTrailerLayoutItem, bool bUseInherited) { if (!pTrailerLayoutItem) return; - FX_FLOAT fHeight = pTrailerLayoutItem->m_sSize.height; + float fHeight = pTrailerLayoutItem->m_sSize.height; if (bUseInherited) { - FX_FLOAT fNewSplitPos = 0; + float fNewSplitPos = 0; if (fSplitPos - fHeight > XFA_LAYOUT_FLOAT_PERCISION) fNewSplitPos = pProcessor->FindSplitPos(fSplitPos - fHeight); if (fNewSplitPos > XFA_LAYOUT_FLOAT_PERCISION) @@ -322,10 +325,10 @@ void AddTrailerBeforeSplit(CXFA_ItemLayoutProcessor* pProcessor, UpdatePendingItemLayout(pProcessor, pTrailerLayoutItem); CXFA_Node* pMarginNode = pProcessor->m_pFormNode->GetFirstChildByClass(XFA_Element::Margin); - FX_FLOAT fLeftInset = 0; - FX_FLOAT fTopInset = 0; - FX_FLOAT fRightInset = 0; - FX_FLOAT fBottomInset = 0; + float fLeftInset = 0; + float fTopInset = 0; + float fRightInset = 0; + float fBottomInset = 0; if (pMarginNode) { fLeftInset = pMarginNode->GetMeasure(XFA_ATTRIBUTE_LeftInset).ToUnit(XFA_UNIT_Pt); @@ -346,7 +349,7 @@ void AddTrailerBeforeSplit(CXFA_ItemLayoutProcessor* pProcessor, return; } - FX_FLOAT fNewSplitPos = 0; + float fNewSplitPos = 0; if (fSplitPos - fHeight > XFA_LAYOUT_FLOAT_PERCISION) fNewSplitPos = pProcessor->FindSplitPos(fSplitPos - fHeight); @@ -384,8 +387,8 @@ void AddLeaderAfterSplit(CXFA_ItemLayoutProcessor* pProcessor, CXFA_Node* pMarginNode = pProcessor->m_pFormNode->GetFirstChildByClass(XFA_Element::Margin); - FX_FLOAT fLeftInset = 0; - FX_FLOAT fRightInset = 0; + float fLeftInset = 0; + float fRightInset = 0; if (pMarginNode) { fLeftInset = pMarginNode->GetMeasure(XFA_ATTRIBUTE_LeftInset).ToUnit(XFA_UNIT_Pt); @@ -393,7 +396,7 @@ void AddLeaderAfterSplit(CXFA_ItemLayoutProcessor* pProcessor, pMarginNode->GetMeasure(XFA_ATTRIBUTE_RightInset).ToUnit(XFA_UNIT_Pt); } - FX_FLOAT fHeight = pLeaderLayoutItem->m_sSize.height; + float fHeight = pLeaderLayoutItem->m_sSize.height; for (CXFA_ContentLayoutItem* pChildItem = (CXFA_ContentLayoutItem*)pProcessor->m_pLayoutItem->m_pFirstChild; pChildItem; @@ -430,9 +433,9 @@ void AddPendingNode(CXFA_ItemLayoutProcessor* pProcessor, pProcessor->m_bBreakPending = bBreakPending; } -FX_FLOAT InsertPendingItems(CXFA_ItemLayoutProcessor* pProcessor, - CXFA_Node* pCurChildNode) { - FX_FLOAT fTotalHeight = 0; +float InsertPendingItems(CXFA_ItemLayoutProcessor* pProcessor, + CXFA_Node* pCurChildNode) { + float fTotalHeight = 0; if (pProcessor->m_PendingNodes.empty()) return fTotalHeight; @@ -605,17 +608,17 @@ XFA_ItemLayoutProcessorResult InsertFlowedItem( CXFA_ItemLayoutProcessor* pProcessor, bool bContainerWidthAutoSize, bool bContainerHeightAutoSize, - FX_FLOAT fContainerHeight, + float fContainerHeight, XFA_ATTRIBUTEENUM eFlowStrategy, uint8_t* uCurHAlignState, - CFX_ArrayTemplate<CXFA_ContentLayoutItem*> (&rgCurLineLayoutItems)[3], + std::vector<CXFA_ContentLayoutItem*> (&rgCurLineLayoutItems)[3], bool bUseBreakControl, - FX_FLOAT fAvailHeight, - FX_FLOAT fRealHeight, - FX_FLOAT fContentWidthLimit, - FX_FLOAT* fContentCurRowY, - FX_FLOAT* fContentCurRowAvailWidth, - FX_FLOAT* fContentCurRowHeight, + float fAvailHeight, + float fRealHeight, + float fContentWidthLimit, + float* fContentCurRowY, + float* fContentCurRowAvailWidth, + float* fContentCurRowHeight, bool* bAddedItemInRow, bool* bForceEndPage, CXFA_LayoutContext* pLayoutContext, @@ -763,7 +766,7 @@ XFA_ItemLayoutProcessorResult InsertFlowedItem( } else { pThis->m_arrayKeepItems.clear(); } - rgCurLineLayoutItems[uHAlign].Add(pChildLayoutItem); + rgCurLineLayoutItems[uHAlign].push_back(pChildLayoutItem); *bAddedItemInRow = true; if (bTakeSpace) { *fContentCurRowAvailWidth -= childSize.width; @@ -792,7 +795,7 @@ XFA_ItemLayoutProcessorResult InsertFlowedItem( pTrailerLayoutItem, pFormNode); } } - rgCurLineLayoutItems[uHAlign].Add(pProcessor->ExtractLayoutItem()); + rgCurLineLayoutItems[uHAlign].push_back(pProcessor->ExtractLayoutItem()); *bAddedItemInRow = true; *fContentCurRowAvailWidth -= childSize.width; *fContentCurRowHeight = std::max(*fContentCurRowHeight, childSize.height); @@ -808,8 +811,7 @@ XFA_ItemLayoutProcessorResult InsertFlowedItem( } *bForceEndPage = true; - FX_FLOAT fSplitPos = - pProcessor->FindSplitPos(fAvailHeight - *fContentCurRowY); + float fSplitPos = pProcessor->FindSplitPos(fAvailHeight - *fContentCurRowY); if (fSplitPos > XFA_LAYOUT_FLOAT_PERCISION) { XFA_ATTRIBUTEENUM eLayout = pProcessor->m_pFormNode->GetEnum(XFA_ATTRIBUTE_Layout); @@ -818,7 +820,7 @@ XFA_ItemLayoutProcessorResult InsertFlowedItem( pProcessor->ProcessUnUseOverFlow(pOverflowLeaderNode, pOverflowTrailerNode, pTrailerLayoutItem, pFormNode); - rgCurLineLayoutItems[uHAlign].Add(pProcessor->ExtractLayoutItem()); + rgCurLineLayoutItems[uHAlign].push_back(pProcessor->ExtractLayoutItem()); *bAddedItemInRow = true; if (bTakeSpace) { *fContentCurRowAvailWidth -= childSize.width; @@ -862,7 +864,7 @@ XFA_ItemLayoutProcessorResult InsertFlowedItem( if (pProcessor->m_pLayoutItem->m_pNextSibling) { childSize = pProcessor->GetCurrentComponentSize(); - rgCurLineLayoutItems[uHAlign].Add(pProcessor->ExtractLayoutItem()); + rgCurLineLayoutItems[uHAlign].push_back(pProcessor->ExtractLayoutItem()); *bAddedItemInRow = true; if (bTakeSpace) { *fContentCurRowAvailWidth -= childSize.width; @@ -894,7 +896,7 @@ XFA_ItemLayoutProcessorResult InsertFlowedItem( return XFA_ItemLayoutProcessorResult::PageFullBreak; } - rgCurLineLayoutItems[uHAlign].Add(pProcessor->ExtractLayoutItem()); + rgCurLineLayoutItems[uHAlign].push_back(pProcessor->ExtractLayoutItem()); *bAddedItemInRow = true; if (bTakeSpace) { *fContentCurRowAvailWidth -= childSize.width; @@ -940,8 +942,8 @@ XFA_ItemLayoutProcessorResult InsertFlowedItem( } bool FindLayoutItemSplitPos(CXFA_ContentLayoutItem* pLayoutItem, - FX_FLOAT fCurVerticalOffset, - FX_FLOAT* fProposedSplitPos, + float fCurVerticalOffset, + float* fProposedSplitPos, bool* bAppChange, bool bCalculateMargin) { CXFA_Node* pFormNode = pLayoutItem->m_pFormNode; @@ -956,7 +958,7 @@ bool FindLayoutItemSplitPos(CXFA_ContentLayoutItem* pLayoutItem, bool bAnyChanged = false; CXFA_Document* pDocument = pFormNode->GetDocument(); CXFA_FFNotify* pNotify = pDocument->GetNotify(); - FX_FLOAT fCurTopMargin = 0, fCurBottomMargin = 0; + float fCurTopMargin = 0, fCurBottomMargin = 0; CXFA_Node* pMarginNode = pFormNode->GetFirstChildByClass(XFA_Element::Margin); if (pMarginNode && bCalculateMargin) { @@ -969,7 +971,7 @@ bool FindLayoutItemSplitPos(CXFA_ContentLayoutItem* pLayoutItem, while (bChanged) { bChanged = false; { - FX_FLOAT fRelSplitPos = *fProposedSplitPos - fCurVerticalOffset; + float fRelSplitPos = *fProposedSplitPos - fCurVerticalOffset; if (pNotify->FindSplitPos(pFormNode, pLayoutItem->GetIndex(), fRelSplitPos)) { bAnyChanged = true; @@ -982,12 +984,12 @@ bool FindLayoutItemSplitPos(CXFA_ContentLayoutItem* pLayoutItem, } } } - FX_FLOAT fRelSplitPos = *fProposedSplitPos - fCurBottomMargin; + float fRelSplitPos = *fProposedSplitPos - fCurBottomMargin; for (CXFA_ContentLayoutItem* pChildItem = (CXFA_ContentLayoutItem*)pLayoutItem->m_pFirstChild; pChildItem; pChildItem = (CXFA_ContentLayoutItem*)pChildItem->m_pNextSibling) { - FX_FLOAT fChildOffset = + float fChildOffset = fCurVerticalOffset + fCurTopMargin + pChildItem->m_sPos.y; bool bChange = false; if (FindLayoutItemSplitPos(pChildItem, fChildOffset, &fRelSplitPos, @@ -1149,7 +1151,7 @@ CXFA_ContentLayoutItem* CXFA_ItemLayoutProcessor::CreateContentLayoutItem( return pLayoutItem; } -FX_FLOAT CXFA_ItemLayoutProcessor::FindSplitPos(FX_FLOAT fProposedSplitPos) { +float CXFA_ItemLayoutProcessor::FindSplitPos(float fProposedSplitPos) { ASSERT(m_pLayoutItem); XFA_ATTRIBUTEENUM eLayout = m_pFormNode->GetEnum(XFA_ATTRIBUTE_Layout); bool bCalculateMargin = eLayout != XFA_ATTRIBUTEENUM_Position; @@ -1166,8 +1168,8 @@ FX_FLOAT CXFA_ItemLayoutProcessor::FindSplitPos(FX_FLOAT fProposedSplitPos) { void CXFA_ItemLayoutProcessor::SplitLayoutItem( CXFA_ContentLayoutItem* pLayoutItem, CXFA_ContentLayoutItem* pSecondParent, - FX_FLOAT fSplitPos) { - FX_FLOAT fCurTopMargin = 0, fCurBottomMargin = 0; + float fSplitPos) { + float fCurTopMargin = 0, fCurBottomMargin = 0; XFA_ATTRIBUTEENUM eLayout = m_pFormNode->GetEnum(XFA_ATTRIBUTE_Layout); bool bCalculateMargin = true; if (eLayout == XFA_ATTRIBUTEENUM_Position) @@ -1218,9 +1220,10 @@ void CXFA_ItemLayoutProcessor::SplitLayoutItem( CXFA_ContentLayoutItem* pChildren = (CXFA_ContentLayoutItem*)pLayoutItem->m_pFirstChild; pLayoutItem->m_pFirstChild = nullptr; - FX_FLOAT lHeightForKeep = 0; - CFX_ArrayTemplate<CXFA_ContentLayoutItem*> keepLayoutItems; - FX_FLOAT fAddMarginHeight = 0; + + float lHeightForKeep = 0; + float fAddMarginHeight = 0; + std::vector<CXFA_ContentLayoutItem*> keepLayoutItems; for (CXFA_ContentLayoutItem *pChildItem = pChildren, *pChildNext = nullptr; pChildItem; pChildItem = pChildNext) { pChildNext = (CXFA_ContentLayoutItem*)pChildItem->m_pNextSibling; @@ -1234,15 +1237,12 @@ void CXFA_ItemLayoutProcessor::SplitLayoutItem( pSecondLayoutItem->AddChild(pChildItem); continue; } - if (lHeightForKeep < XFA_LAYOUT_FLOAT_PERCISION) { - for (int32_t iIndex = 0; iIndex < keepLayoutItems.GetSize(); iIndex++) { - CXFA_ContentLayoutItem* pPreItem = keepLayoutItems[iIndex]; + for (auto* pPreItem : keepLayoutItems) { pLayoutItem->RemoveChild(pPreItem); pPreItem->m_sPos.y -= fSplitPos; if (pPreItem->m_sPos.y < 0) pPreItem->m_sPos.y = 0; - if (pPreItem->m_sPos.y + pPreItem->m_sSize.height > lHeightForKeep) { pPreItem->m_sPos.y = lHeightForKeep; lHeightForKeep += pPreItem->m_sSize.height; @@ -1253,27 +1253,24 @@ void CXFA_ItemLayoutProcessor::SplitLayoutItem( pSecondLayoutItem->AddChild(pPreItem); } } - pChildItem->m_sPos.y -= fSplitPos; pChildItem->m_sPos.y += lHeightForKeep; pChildItem->m_sPos.y += fAddMarginHeight; pSecondLayoutItem->AddChild(pChildItem); continue; } - if (fSplitPos + XFA_LAYOUT_FLOAT_PERCISION >= fCurTopMargin + fCurBottomMargin + pChildItem->m_sPos.y + pChildItem->m_sSize.height) { pLayoutItem->AddChild(pChildItem); if (ExistContainerKeep(pChildItem->m_pFormNode, false)) - keepLayoutItems.Add(pChildItem); + keepLayoutItems.push_back(pChildItem); else - keepLayoutItems.RemoveAll(); - + keepLayoutItems.clear(); continue; } - FX_FLOAT fOldHeight = pSecondLayoutItem->m_sSize.height; + float fOldHeight = pSecondLayoutItem->m_sSize.height; SplitLayoutItem( pChildItem, pSecondLayoutItem, fSplitPos - fCurTopMargin - fCurBottomMargin - pChildItem->m_sPos.y); @@ -1282,7 +1279,7 @@ void CXFA_ItemLayoutProcessor::SplitLayoutItem( } } -void CXFA_ItemLayoutProcessor::SplitLayoutItem(FX_FLOAT fSplitPos) { +void CXFA_ItemLayoutProcessor::SplitLayoutItem(float fSplitPos) { ASSERT(m_pLayoutItem); SplitLayoutItem(m_pLayoutItem, nullptr, fSplitPos); } @@ -1624,10 +1621,10 @@ void CXFA_ItemLayoutProcessor::DoLayoutPositionedContainer( CFX_SizeF containerSize = CalculateContainerSpecifiedSize( m_pFormNode, &bContainerWidthAutoSize, &bContainerHeightAutoSize); - FX_FLOAT fContentCalculatedWidth = 0; - FX_FLOAT fContentCalculatedHeight = 0; - FX_FLOAT fHiddenContentCalculatedWidth = 0; - FX_FLOAT fHiddenContentCalculatedHeight = 0; + float fContentCalculatedWidth = 0; + float fContentCalculatedHeight = 0; + float fHiddenContentCalculatedWidth = 0; + float fHiddenContentCalculatedHeight = 0; if (m_pCurChildNode == XFA_LAYOUT_INVALIDNODE) { GotoNextContainerNode(m_pCurChildNode, m_nCurChildNodeStage, m_pFormNode, false); @@ -1645,16 +1642,18 @@ void CXFA_ItemLayoutProcessor::DoLayoutPositionedContainer( m_pCurChildNode, m_pPageMgr); if (pContext && pContext->m_prgSpecifiedColumnWidths) { int32_t iColSpan = m_pCurChildNode->GetInteger(XFA_ATTRIBUTE_ColSpan); - if (iColSpan <= - pContext->m_prgSpecifiedColumnWidths->GetSize() - iColIndex) { + if (iColSpan <= pdfium::CollectionSize<int32_t>( + *pContext->m_prgSpecifiedColumnWidths) - + iColIndex) { pContext->m_fCurColumnWidth = 0; pContext->m_bCurColumnWidthAvaiable = true; - if (iColSpan == -1) - iColSpan = pContext->m_prgSpecifiedColumnWidths->GetSize(); - + if (iColSpan == -1) { + iColSpan = pdfium::CollectionSize<int32_t>( + *pContext->m_prgSpecifiedColumnWidths); + } for (int32_t i = 0; iColIndex + i < iColSpan; ++i) { pContext->m_fCurColumnWidth += - pContext->m_prgSpecifiedColumnWidths->GetAt(iColIndex + i); + (*pContext->m_prgSpecifiedColumnWidths)[iColIndex + i]; } if (pContext->m_fCurColumnWidth == 0) pContext->m_bCurColumnWidthAvaiable = false; @@ -1678,7 +1677,7 @@ void CXFA_ItemLayoutProcessor::DoLayoutPositionedContainer( pProcessor->SetCurrentComponentPos(absolutePos); if (bContainerWidthAutoSize) { - FX_FLOAT fChildSuppliedWidth = absolutePos.x + size.width; + float fChildSuppliedWidth = absolutePos.x + size.width; if (bChangeParentSize) { fContentCalculatedWidth = std::max(fContentCalculatedWidth, fChildSuppliedWidth); @@ -1691,7 +1690,7 @@ void CXFA_ItemLayoutProcessor::DoLayoutPositionedContainer( } if (bContainerHeightAutoSize) { - FX_FLOAT fChildSuppliedHeight = absolutePos.y + size.height; + float fChildSuppliedHeight = absolutePos.y + size.height; if (bChangeParentSize) { fContentCalculatedHeight = std::max(fContentCalculatedHeight, fChildSuppliedHeight); @@ -1730,12 +1729,12 @@ void CXFA_ItemLayoutProcessor::DoLayoutTableContainer(CXFA_Node* pLayoutNode) { bool bContainerHeightAutoSize = true; CFX_SizeF containerSize = CalculateContainerSpecifiedSize( m_pFormNode, &bContainerWidthAutoSize, &bContainerHeightAutoSize); - FX_FLOAT fContentCalculatedWidth = 0; - FX_FLOAT fContentCalculatedHeight = 0; + float fContentCalculatedWidth = 0; + float fContentCalculatedHeight = 0; CXFA_Node* pMarginNode = m_pFormNode->GetFirstChildByClass(XFA_Element::Margin); - FX_FLOAT fLeftInset = 0; - FX_FLOAT fRightInset = 0; + float fLeftInset = 0; + float fRightInset = 0; if (pMarginNode) { fLeftInset = pMarginNode->GetMeasure(XFA_ATTRIBUTE_LeftInset).ToUnit(XFA_UNIT_Pt); @@ -1743,7 +1742,7 @@ void CXFA_ItemLayoutProcessor::DoLayoutTableContainer(CXFA_Node* pLayoutNode) { pMarginNode->GetMeasure(XFA_ATTRIBUTE_RightInset).ToUnit(XFA_UNIT_Pt); } - FX_FLOAT fContentWidthLimit = + float fContentWidthLimit = bContainerWidthAutoSize ? FLT_MAX : containerSize.width - fLeftInset - fRightInset; CFX_WideStringC wsColumnWidths; @@ -1755,12 +1754,13 @@ void CXFA_ItemLayoutProcessor::DoLayoutTableContainer(CXFA_Node* pLayoutNode) { if (width.IsEmpty()) continue; - CXFA_Measurement measure(width.AsStringC()); - m_rgSpecifiedColumnWidths.Add(measure.ToUnit(XFA_UNIT_Pt)); + m_rgSpecifiedColumnWidths.push_back( + CXFA_Measurement(width.AsStringC()).ToUnit(XFA_UNIT_Pt)); } } - int32_t iSpecifiedColumnCount = m_rgSpecifiedColumnWidths.GetSize(); + int32_t iSpecifiedColumnCount = + pdfium::CollectionSize<int32_t>(m_rgSpecifiedColumnWidths); CXFA_LayoutContext layoutContext; layoutContext.m_prgSpecifiedColumnWidths = &m_rgSpecifiedColumnWidths; CXFA_LayoutContext* pLayoutContext = @@ -1789,13 +1789,13 @@ void CXFA_ItemLayoutProcessor::DoLayoutTableContainer(CXFA_Node* pLayoutNode) { int32_t iRowCount = 0; int32_t iColCount = 0; { - CFX_ArrayTemplate<CXFA_ContentLayoutItem*> rgRowItems; - CFX_ArrayTemplate<int32_t> rgRowItemsSpan; - CFX_ArrayTemplate<FX_FLOAT> rgRowItemsWidth; - for (CXFA_ContentLayoutItem* pLayoutChild = - (CXFA_ContentLayoutItem*)m_pLayoutItem->m_pFirstChild; - pLayoutChild; - pLayoutChild = (CXFA_ContentLayoutItem*)pLayoutChild->m_pNextSibling) { + std::vector<CXFA_ContentLayoutItem*> rgRowItems; + std::vector<int32_t> rgRowItemsSpan; + std::vector<float> rgRowItemsWidth; + for (auto* pLayoutChild = + static_cast<CXFA_ContentLayoutItem*>(m_pLayoutItem->m_pFirstChild); + pLayoutChild; pLayoutChild = static_cast<CXFA_ContentLayoutItem*>( + pLayoutChild->m_pNextSibling)) { if (pLayoutChild->m_pFormNode->GetElementType() != XFA_Element::Subform) continue; if (!XFA_ItemLayoutProcessor_IsTakingSpace(pLayoutChild->m_pFormNode)) @@ -1809,15 +1809,15 @@ void CXFA_ItemLayoutProcessor::DoLayoutTableContainer(CXFA_Node* pLayoutNode) { } if (CXFA_ContentLayoutItem* pRowLayoutCell = (CXFA_ContentLayoutItem*)pLayoutChild->m_pFirstChild) { - rgRowItems.Add(pRowLayoutCell); + rgRowItems.push_back(pRowLayoutCell); int32_t iColSpan = pRowLayoutCell->m_pFormNode->GetInteger(XFA_ATTRIBUTE_ColSpan); - rgRowItemsSpan.Add(iColSpan); - rgRowItemsWidth.Add(pRowLayoutCell->m_sSize.width); + rgRowItemsSpan.push_back(iColSpan); + rgRowItemsWidth.push_back(pRowLayoutCell->m_sSize.width); } } - iRowCount = rgRowItems.GetSize(); + iRowCount = pdfium::CollectionSize<int32_t>(rgRowItems); iColCount = 0; bool bMoreColumns = true; while (bMoreColumns) { @@ -1849,9 +1849,10 @@ void CXFA_ItemLayoutProcessor::DoLayoutTableContainer(CXFA_Node* pLayoutNode) { continue; if (iColCount >= iSpecifiedColumnCount) { - int32_t c = iColCount + 1 - m_rgSpecifiedColumnWidths.GetSize(); + int32_t c = iColCount + 1 - pdfium::CollectionSize<int32_t>( + m_rgSpecifiedColumnWidths); for (int32_t j = 0; j < c; j++) - m_rgSpecifiedColumnWidths.Add(0); + m_rgSpecifiedColumnWidths.push_back(0); } if (m_rgSpecifiedColumnWidths[iColCount] < XFA_LAYOUT_FLOAT_PERCISION) bAutoCol = true; @@ -1864,9 +1865,10 @@ void CXFA_ItemLayoutProcessor::DoLayoutTableContainer(CXFA_Node* pLayoutNode) { if (!bMoreColumns) continue; - FX_FLOAT fFinalColumnWidth = 0.0f; - if (iColCount < m_rgSpecifiedColumnWidths.GetSize()) + float fFinalColumnWidth = 0.0f; + if (pdfium::IndexInBounds(m_rgSpecifiedColumnWidths, iColCount)) fFinalColumnWidth = m_rgSpecifiedColumnWidths[iColCount]; + for (int32_t i = 0; i < iRowCount; ++i) { if (!rgRowItems[i]) continue; @@ -1877,7 +1879,7 @@ void CXFA_ItemLayoutProcessor::DoLayoutTableContainer(CXFA_Node* pLayoutNode) { } } - FX_FLOAT fCurrentRowY = 0; + float fCurrentRowY = 0; for (CXFA_ContentLayoutItem* pLayoutChild = (CXFA_ContentLayoutItem*)m_pLayoutItem->m_pFirstChild; pLayoutChild; @@ -1916,7 +1918,7 @@ void CXFA_ItemLayoutProcessor::DoLayoutTableContainer(CXFA_Node* pLayoutNode) { } if (bContainerWidthAutoSize) { - FX_FLOAT fChildSuppliedWidth = + float fChildSuppliedWidth = pLayoutChild->m_sPos.x + pLayoutChild->m_sSize.width; if (fContentWidthLimit < FLT_MAX && fContentWidthLimit > fChildSuppliedWidth) { @@ -1942,12 +1944,12 @@ bool CXFA_ItemLayoutProcessor::IsAddNewRowForTrailer( if (!pTrailerItem) return false; - FX_FLOAT fWidth = pTrailerItem->m_sSize.width; + float fWidth = pTrailerItem->m_sSize.width; XFA_ATTRIBUTEENUM eLayout = m_pFormNode->GetEnum(XFA_ATTRIBUTE_Layout); return eLayout == XFA_ATTRIBUTEENUM_Tb || m_fWidthLimite <= fWidth; } -FX_FLOAT CXFA_ItemLayoutProcessor::InsertKeepLayoutItems() { +float CXFA_ItemLayoutProcessor::InsertKeepLayoutItems() { if (m_arrayKeepItems.empty()) return 0; @@ -1956,7 +1958,7 @@ FX_FLOAT CXFA_ItemLayoutProcessor::InsertKeepLayoutItems() { m_pLayoutItem->m_sSize.clear(); } - FX_FLOAT fTotalHeight = 0; + float fTotalHeight = 0; for (auto iter = m_arrayKeepItems.rbegin(); iter != m_arrayKeepItems.rend(); iter++) { AddLeaderAfterSplit(this, *iter); @@ -1971,10 +1973,10 @@ bool CXFA_ItemLayoutProcessor::ProcessKeepForSplit( CXFA_ItemLayoutProcessor* pParentProcessor, CXFA_ItemLayoutProcessor* pChildProcessor, XFA_ItemLayoutProcessorResult eRetValue, - CFX_ArrayTemplate<CXFA_ContentLayoutItem*>* rgCurLineLayoutItem, - FX_FLOAT* fContentCurRowAvailWidth, - FX_FLOAT* fContentCurRowHeight, - FX_FLOAT* fContentCurRowY, + std::vector<CXFA_ContentLayoutItem*>* rgCurLineLayoutItem, + float* fContentCurRowAvailWidth, + float* fContentCurRowHeight, + float* fContentCurRowY, bool* bAddedItemInRow, bool* bForceEndPage, XFA_ItemLayoutProcessorResult* result) { @@ -1995,7 +1997,7 @@ bool CXFA_ItemLayoutProcessor::ProcessKeepForSplit( childSize.height, &keepLayoutItems)) { m_arrayKeepItems.clear(); - for (auto item : keepLayoutItems) { + for (auto* item : keepLayoutItems) { pParentProcessor->m_pLayoutItem->RemoveChild(item); *fContentCurRowY -= item->m_sSize.height; m_arrayKeepItems.push_back(item); @@ -2006,7 +2008,7 @@ bool CXFA_ItemLayoutProcessor::ProcessKeepForSplit( return true; } - rgCurLineLayoutItem->Add(pChildProcessor->ExtractLayoutItem()); + rgCurLineLayoutItem->push_back(pChildProcessor->ExtractLayoutItem()); *bAddedItemInRow = true; *fContentCurRowAvailWidth -= childSize.width; *fContentCurRowHeight = std::max(*fContentCurRowHeight, childSize.height); @@ -2017,12 +2019,12 @@ bool CXFA_ItemLayoutProcessor::ProcessKeepForSplit( bool CXFA_ItemLayoutProcessor::JudgePutNextPage( CXFA_ContentLayoutItem* pParentLayoutItem, - FX_FLOAT fChildHeight, + float fChildHeight, std::vector<CXFA_ContentLayoutItem*>* pKeepItems) { if (!pParentLayoutItem) return false; - FX_FLOAT fItemsHeight = 0; + float fItemsHeight = 0; for (CXFA_ContentLayoutItem* pChildLayoutItem = (CXFA_ContentLayoutItem*)pParentLayoutItem->m_pFirstChild; pChildLayoutItem; @@ -2084,8 +2086,8 @@ void CXFA_ItemLayoutProcessor::ProcessUnUseOverFlow( XFA_ItemLayoutProcessorResult CXFA_ItemLayoutProcessor::DoLayoutFlowedContainer( bool bUseBreakControl, XFA_ATTRIBUTEENUM eFlowStrategy, - FX_FLOAT fHeightLimit, - FX_FLOAT fRealHeight, + float fHeightLimit, + float fRealHeight, CXFA_LayoutContext* pContext, bool bRootForceTb) { m_bHasAvailHeight = true; @@ -2126,10 +2128,10 @@ XFA_ItemLayoutProcessorResult CXFA_ItemLayoutProcessor::DoLayoutFlowedContainer( CXFA_Node* pMarginNode = m_pFormNode->GetFirstChildByClass(XFA_Element::Margin); - FX_FLOAT fLeftInset = 0; - FX_FLOAT fTopInset = 0; - FX_FLOAT fRightInset = 0; - FX_FLOAT fBottomInset = 0; + float fLeftInset = 0; + float fTopInset = 0; + float fRightInset = 0; + float fBottomInset = 0; if (pMarginNode) { fLeftInset = pMarginNode->GetMeasure(XFA_ATTRIBUTE_LeftInset).ToUnit(XFA_UNIT_Pt); @@ -2140,17 +2142,17 @@ XFA_ItemLayoutProcessorResult CXFA_ItemLayoutProcessor::DoLayoutFlowedContainer( fBottomInset = pMarginNode->GetMeasure(XFA_ATTRIBUTE_BottomInset).ToUnit(XFA_UNIT_Pt); } - FX_FLOAT fContentWidthLimit = + float fContentWidthLimit = bContainerWidthAutoSize ? FLT_MAX : containerSize.width - fLeftInset - fRightInset; - FX_FLOAT fContentCalculatedWidth = 0; - FX_FLOAT fContentCalculatedHeight = 0; - FX_FLOAT fAvailHeight = fHeightLimit - fTopInset - fBottomInset; + float fContentCalculatedWidth = 0; + float fContentCalculatedHeight = 0; + float fAvailHeight = fHeightLimit - fTopInset - fBottomInset; if (fAvailHeight < 0) m_bHasAvailHeight = false; fRealHeight = fRealHeight - fTopInset - fBottomInset; - FX_FLOAT fContentCurRowY = 0; + float fContentCurRowY = 0; CXFA_ContentLayoutItem* pLayoutChild = nullptr; if (m_pLayoutItem) { if (m_nCurChildNodeStage != XFA_ItemLayoutProcessorStages::Done && @@ -2202,10 +2204,10 @@ XFA_ItemLayoutProcessorResult CXFA_ItemLayoutProcessor::DoLayoutFlowedContainer( } while (m_nCurChildNodeStage != XFA_ItemLayoutProcessorStages::Done) { - FX_FLOAT fContentCurRowHeight = 0; - FX_FLOAT fContentCurRowAvailWidth = fContentWidthLimit; + float fContentCurRowHeight = 0; + float fContentCurRowAvailWidth = fContentWidthLimit; m_fWidthLimite = fContentCurRowAvailWidth; - CFX_ArrayTemplate<CXFA_ContentLayoutItem*> rgCurLineLayoutItems[3]; + std::vector<CXFA_ContentLayoutItem*> rgCurLineLayoutItems[3]; uint8_t uCurHAlignState = (eFlowStrategy != XFA_ATTRIBUTEENUM_Rl_tb ? 0 : 2); if (pLayoutChild) { @@ -2219,7 +2221,7 @@ XFA_ItemLayoutProcessorResult CXFA_ItemLayoutProcessor::DoLayoutFlowedContainer( } uint8_t uHAlign = HAlignEnumToInt( pLayoutNext->m_pFormNode->GetEnum(XFA_ATTRIBUTE_HAlign)); - rgCurLineLayoutItems[uHAlign].Add(pLayoutNext); + rgCurLineLayoutItems[uHAlign].push_back(pLayoutNext); if (eFlowStrategy == XFA_ATTRIBUTEENUM_Lr_tb) { if (uHAlign > uCurHAlignState) uCurHAlignState = uHAlign; @@ -2271,7 +2273,7 @@ XFA_ItemLayoutProcessorResult CXFA_ItemLayoutProcessor::DoLayoutFlowedContainer( case XFA_ItemLayoutProcessorStages::None: break; case XFA_ItemLayoutProcessorStages::BreakBefore: { - for (auto item : m_arrayKeepItems) { + for (auto* item : m_arrayKeepItems) { m_pLayoutItem->RemoveChild(item); fContentCalculatedHeight -= item->m_sSize.height; } @@ -2345,7 +2347,7 @@ XFA_ItemLayoutProcessorResult CXFA_ItemLayoutProcessor::DoLayoutFlowedContainer( bContainerWidthAutoSize, &fContentCalculatedWidth, &fContentCalculatedHeight, &fContentCurRowY, fContentCurRowHeight, fContentWidthLimit, false); - rgCurLineLayoutItems->RemoveAll(); + rgCurLineLayoutItems->clear(); auto pTempProcessor = pdfium::MakeUnique<CXFA_ItemLayoutProcessor>(pLeaderNode, nullptr); @@ -2531,21 +2533,21 @@ XFA_ItemLayoutProcessorResult CXFA_ItemLayoutProcessor::DoLayoutFlowedContainer( } bool CXFA_ItemLayoutProcessor::CalculateRowChildPosition( - CFX_ArrayTemplate<CXFA_ContentLayoutItem*> (&rgCurLineLayoutItems)[3], + std::vector<CXFA_ContentLayoutItem*> (&rgCurLineLayoutItems)[3], XFA_ATTRIBUTEENUM eFlowStrategy, bool bContainerHeightAutoSize, bool bContainerWidthAutoSize, - FX_FLOAT* fContentCalculatedWidth, - FX_FLOAT* fContentCalculatedHeight, - FX_FLOAT* fContentCurRowY, - FX_FLOAT fContentCurRowHeight, - FX_FLOAT fContentWidthLimit, + float* fContentCalculatedWidth, + float* fContentCalculatedHeight, + float* fContentCurRowY, + float fContentCurRowHeight, + float fContentWidthLimit, bool bRootForceTb) { int32_t nGroupLengths[3] = {0, 0, 0}; - FX_FLOAT fGroupWidths[3] = {0, 0, 0}; + float fGroupWidths[3] = {0, 0, 0}; int32_t nTotalLength = 0; for (int32_t i = 0; i < 3; i++) { - nGroupLengths[i] = rgCurLineLayoutItems[i].GetSize(); + nGroupLengths[i] = pdfium::CollectionSize<int32_t>(rgCurLineLayoutItems[i]); for (int32_t c = nGroupLengths[i], j = 0; j < c; j++) { nTotalLength++; if (XFA_ItemLayoutProcessor_IsTakingSpace( @@ -2554,7 +2556,6 @@ bool CXFA_ItemLayoutProcessor::CalculateRowChildPosition( } } } - if (!nTotalLength) { if (bContainerHeightAutoSize) { *fContentCalculatedHeight = @@ -2562,12 +2563,11 @@ bool CXFA_ItemLayoutProcessor::CalculateRowChildPosition( } return false; } - if (!m_pLayoutItem) m_pLayoutItem = CreateContentLayoutItem(m_pFormNode); if (eFlowStrategy != XFA_ATTRIBUTEENUM_Rl_tb) { - FX_FLOAT fCurPos; + float fCurPos; fCurPos = 0; for (int32_t c = nGroupLengths[0], j = 0; j < c; j++) { if (bRootForceTb) { @@ -2622,7 +2622,7 @@ bool CXFA_ItemLayoutProcessor::CalculateRowChildPosition( m_fLastRowWidth = fCurPos; } } else { - FX_FLOAT fCurPos; + float fCurPos; fCurPos = fGroupWidths[0]; for (int32_t c = nGroupLengths[0], j = 0; j < c; j++) { if (XFA_ItemLayoutProcessor_IsTakingSpace( @@ -2662,7 +2662,7 @@ bool CXFA_ItemLayoutProcessor::CalculateRowChildPosition( m_fLastRowY = *fContentCurRowY; *fContentCurRowY += fContentCurRowHeight; if (bContainerWidthAutoSize) { - FX_FLOAT fChildSuppliedWidth = fGroupWidths[0]; + float fChildSuppliedWidth = fGroupWidths[0]; if (fContentWidthLimit < FLT_MAX && fContentWidthLimit > fChildSuppliedWidth) { fChildSuppliedWidth = fContentWidthLimit; @@ -2715,8 +2715,8 @@ void CXFA_ItemLayoutProcessor::DoLayoutField() { XFA_ItemLayoutProcessorResult CXFA_ItemLayoutProcessor::DoLayout( bool bUseBreakControl, - FX_FLOAT fHeightLimit, - FX_FLOAT fRealHeight, + float fHeightLimit, + float fRealHeight, CXFA_LayoutContext* pContext) { switch (m_pFormNode->GetElementType()) { case XFA_Element::Subform: diff --git a/chromium/third_party/pdfium/xfa/fxfa/parser/xfa_layout_itemlayout.h b/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_itemlayoutprocessor.h index d411bf0e9fa..d5d706e62e6 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/parser/xfa_layout_itemlayout.h +++ b/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_itemlayoutprocessor.h @@ -4,8 +4,8 @@ // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com -#ifndef XFA_FXFA_PARSER_XFA_LAYOUT_ITEMLAYOUT_H_ -#define XFA_FXFA_PARSER_XFA_LAYOUT_ITEMLAYOUT_H_ +#ifndef XFA_FXFA_PARSER_CXFA_ITEMLAYOUTPROCESSOR_H_ +#define XFA_FXFA_PARSER_CXFA_ITEMLAYOUTPROCESSOR_H_ #include <float.h> @@ -24,6 +24,7 @@ class CXFA_ContainerLayoutItem; class CXFA_ContentLayoutItem; class CXFA_ItemLayoutProcessor; +class CXFA_LayoutContext; class CXFA_LayoutPageMgr; class CXFA_LayoutProcessor; class CXFA_Node; @@ -46,23 +47,6 @@ enum class XFA_ItemLayoutProcessorStages { Done, }; -class CXFA_LayoutContext { - public: - CXFA_LayoutContext() - : m_prgSpecifiedColumnWidths(nullptr), - m_fCurColumnWidth(0), - m_bCurColumnWidthAvaiable(false), - m_pOverflowProcessor(nullptr), - m_pOverflowNode(nullptr) {} - ~CXFA_LayoutContext() {} - - CFX_ArrayTemplate<FX_FLOAT>* m_prgSpecifiedColumnWidths; - FX_FLOAT m_fCurColumnWidth; - bool m_bCurColumnWidthAvaiable; - CXFA_ItemLayoutProcessor* m_pOverflowProcessor; - CXFA_Node* m_pOverflowNode; -}; - bool XFA_ItemLayoutProcessor_IsTakingSpace(CXFA_Node* pNode); class CXFA_ItemLayoutProcessor { @@ -75,8 +59,8 @@ class CXFA_ItemLayoutProcessor { ~CXFA_ItemLayoutProcessor(); XFA_ItemLayoutProcessorResult DoLayout(bool bUseBreakControl, - FX_FLOAT fHeightLimit, - FX_FLOAT fRealHeight, + float fHeightLimit, + float fRealHeight, CXFA_LayoutContext* pContext); void DoLayoutPageArea(CXFA_ContainerLayoutItem* pPageAreaLayoutItem); @@ -84,18 +68,18 @@ class CXFA_ItemLayoutProcessor { CXFA_Node* GetFormNode() { return m_pFormNode; } bool HasLayoutItem() const { return !!m_pLayoutItem; } CXFA_ContentLayoutItem* ExtractLayoutItem(); - void SplitLayoutItem(FX_FLOAT fSplitPos); + void SplitLayoutItem(float fSplitPos); - FX_FLOAT FindSplitPos(FX_FLOAT fProposedSplitPos); + float FindSplitPos(float fProposedSplitPos); bool ProcessKeepForSplit( CXFA_ItemLayoutProcessor* pParentProcessor, CXFA_ItemLayoutProcessor* pChildProcessor, XFA_ItemLayoutProcessorResult eRetValue, - CFX_ArrayTemplate<CXFA_ContentLayoutItem*>* rgCurLineLayoutItem, - FX_FLOAT* fContentCurRowAvailWidth, - FX_FLOAT* fContentCurRowHeight, - FX_FLOAT* fContentCurRowY, + std::vector<CXFA_ContentLayoutItem*>* rgCurLineLayoutItem, + float* fContentCurRowAvailWidth, + float* fContentCurRowHeight, + float* fContentCurRowY, bool* bAddedItemInRow, bool* bForceEndPage, XFA_ItemLayoutProcessorResult* result); @@ -111,14 +95,14 @@ class CXFA_ItemLayoutProcessor { CXFA_Node* m_pFormNode; CXFA_ContentLayoutItem* m_pLayoutItem; CXFA_Node* m_pCurChildNode; - FX_FLOAT m_fUsedSize; + float m_fUsedSize; CXFA_LayoutPageMgr* m_pPageMgr; std::list<CXFA_Node*> m_PendingNodes; bool m_bBreakPending; - CFX_ArrayTemplate<FX_FLOAT> m_rgSpecifiedColumnWidths; + std::vector<float> m_rgSpecifiedColumnWidths; std::vector<CXFA_ContentLayoutItem*> m_arrayKeepItems; - FX_FLOAT m_fLastRowWidth; - FX_FLOAT m_fLastRowY; + float m_fLastRowWidth; + float m_fLastRowY; bool m_bUseInheriated; XFA_ItemLayoutProcessorResult m_ePreProcessRs; @@ -128,22 +112,22 @@ class CXFA_ItemLayoutProcessor { void SplitLayoutItem(CXFA_ContentLayoutItem* pLayoutItem, CXFA_ContentLayoutItem* pSecondParent, - FX_FLOAT fSplitPos); - FX_FLOAT InsertKeepLayoutItems(); + float fSplitPos); + float InsertKeepLayoutItems(); bool CalculateRowChildPosition( - CFX_ArrayTemplate<CXFA_ContentLayoutItem*> (&rgCurLineLayoutItems)[3], + std::vector<CXFA_ContentLayoutItem*> (&rgCurLineLayoutItems)[3], XFA_ATTRIBUTEENUM eFlowStrategy, bool bContainerHeightAutoSize, bool bContainerWidthAutoSize, - FX_FLOAT* fContentCalculatedWidth, - FX_FLOAT* fContentCalculatedHeight, - FX_FLOAT* fContentCurRowY, - FX_FLOAT fContentCurRowHeight, - FX_FLOAT fContentWidthLimit, + float* fContentCalculatedWidth, + float* fContentCalculatedHeight, + float* fContentCurRowY, + float fContentCurRowHeight, + float fContentWidthLimit, bool bRootForceTb); void ProcessUnUseBinds(CXFA_Node* pFormNode); bool JudgePutNextPage(CXFA_ContentLayoutItem* pParentLayoutItem, - FX_FLOAT fChildHeight, + float fChildHeight, std::vector<CXFA_ContentLayoutItem*>* pKeepItems); void DoLayoutPositionedContainer(CXFA_LayoutContext* pContext); @@ -151,8 +135,8 @@ class CXFA_ItemLayoutProcessor { XFA_ItemLayoutProcessorResult DoLayoutFlowedContainer( bool bUseBreakControl, XFA_ATTRIBUTEENUM eFlowStrategy, - FX_FLOAT fHeightLimit, - FX_FLOAT fRealHeight, + float fHeightLimit, + float fRealHeight, CXFA_LayoutContext* pContext, bool bRootForceTb); void DoLayoutField(); @@ -181,8 +165,8 @@ class CXFA_ItemLayoutProcessor { CXFA_ItemLayoutProcessor* m_pCurChildPreprocessor; XFA_ItemLayoutProcessorStages m_nCurChildNodeStage; std::map<CXFA_Node*, int32_t> m_PendingNodesCount; - FX_FLOAT m_fWidthLimite; + float m_fWidthLimite; bool m_bHasAvailHeight; }; -#endif // XFA_FXFA_PARSER_XFA_LAYOUT_ITEMLAYOUT_H_ +#endif // XFA_FXFA_PARSER_CXFA_ITEMLAYOUTPROCESSOR_H_ diff --git a/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_layoutcontext.h b/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_layoutcontext.h new file mode 100644 index 00000000000..a133ee19d99 --- /dev/null +++ b/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_layoutcontext.h @@ -0,0 +1,32 @@ +// Copyright 2017 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#ifndef XFA_FXFA_PARSER_CXFA_LAYOUTCONTEXT_H_ +#define XFA_FXFA_PARSER_CXFA_LAYOUTCONTEXT_H_ + +#include <vector> + +class CXFA_ItemLayoutProcess; +class CXFA_Node; + +class CXFA_LayoutContext { + public: + CXFA_LayoutContext() + : m_prgSpecifiedColumnWidths(nullptr), + m_fCurColumnWidth(0), + m_bCurColumnWidthAvaiable(false), + m_pOverflowProcessor(nullptr), + m_pOverflowNode(nullptr) {} + ~CXFA_LayoutContext() {} + + std::vector<float>* m_prgSpecifiedColumnWidths; + float m_fCurColumnWidth; + bool m_bCurColumnWidthAvaiable; + CXFA_ItemLayoutProcessor* m_pOverflowProcessor; + CXFA_Node* m_pOverflowNode; +}; + +#endif // XFA_FXFA_PARSER_CXFA_LAYOUTCONTEXT_H_ diff --git a/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_layoutitem.cpp b/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_layoutitem.cpp index 476d6118ac3..b227be9e855 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_layoutitem.cpp +++ b/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_layoutitem.cpp @@ -10,6 +10,7 @@ #include "xfa/fxfa/parser/cxfa_containerlayoutitem.h" #include "xfa/fxfa/parser/cxfa_contentlayoutitem.h" #include "xfa/fxfa/parser/cxfa_measurement.h" +#include "xfa/fxfa/parser/cxfa_node.h" void XFA_ReleaseLayoutItem(CXFA_LayoutItem* pLayoutItem) { CXFA_LayoutItem* pNode = pLayoutItem->m_pFirstChild; @@ -64,7 +65,7 @@ CXFA_ContainerLayoutItem* CXFA_LayoutItem::GetPage() const { CFX_RectF CXFA_LayoutItem::GetRect(bool bRelative) const { ASSERT(m_bIsContentLayoutItem); - auto pThis = static_cast<const CXFA_ContentLayoutItem*>(this); + auto* pThis = static_cast<const CXFA_ContentLayoutItem*>(this); CFX_PointF sPos = pThis->m_sPos; CFX_SizeF sSize = pThis->m_sSize; if (bRelative) diff --git a/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_layoutpagemgr.cpp b/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_layoutpagemgr.cpp index f38ef0ebfda..b88dca90097 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_layoutpagemgr.cpp +++ b/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_layoutpagemgr.cpp @@ -6,19 +6,23 @@ #include "xfa/fxfa/parser/cxfa_layoutpagemgr.h" +#include "third_party/base/stl_util.h" #include "xfa/fxfa/app/xfa_ffnotify.h" #include "xfa/fxfa/parser/cxfa_containerlayoutitem.h" #include "xfa/fxfa/parser/cxfa_contentlayoutitem.h" #include "xfa/fxfa/parser/cxfa_document.h" +#include "xfa/fxfa/parser/cxfa_itemlayoutprocessor.h" #include "xfa/fxfa/parser/cxfa_layoutprocessor.h" +#include "xfa/fxfa/parser/cxfa_localemgr.h" #include "xfa/fxfa/parser/cxfa_measurement.h" +#include "xfa/fxfa/parser/cxfa_node.h" +#include "xfa/fxfa/parser/cxfa_object.h" #include "xfa/fxfa/parser/cxfa_scriptcontext.h" #include "xfa/fxfa/parser/cxfa_traversestrategy_contentareacontainerlayoutitem.h" #include "xfa/fxfa/parser/cxfa_traversestrategy_layoutitem.h" +#include "xfa/fxfa/parser/cxfa_traversestrategy_xfacontainernode.h" +#include "xfa/fxfa/parser/cxfa_traversestrategy_xfanode.h" #include "xfa/fxfa/parser/xfa_document_datamerger_imp.h" -#include "xfa/fxfa/parser/xfa_layout_itemlayout.h" -#include "xfa/fxfa/parser/xfa_localemgr.h" -#include "xfa/fxfa/parser/xfa_object.h" #include "xfa/fxfa/parser/xfa_resolvenode_rs.h" #include "xfa/fxfa/parser/xfa_utils.h" @@ -172,8 +176,8 @@ CXFA_Node* ResolveBreakTarget(CXFA_Node* pPageSetRoot, XFA_RESOLVENODE_Children | XFA_RESOLVENODE_Properties | XFA_RESOLVENODE_Attributes | XFA_RESOLVENODE_Siblings | XFA_RESOLVENODE_Parent); - if (iCount > 0 && rs.nodes[0]->IsNode()) - return rs.nodes[0]->AsNode(); + if (iCount > 0 && rs.objects.front()->IsNode()) + return rs.objects.front()->AsNode(); } iSplitIndex = iSplitNextIndex; } @@ -454,13 +458,13 @@ void CXFA_LayoutPageMgr::SubmitContentItem( } } -FX_FLOAT CXFA_LayoutPageMgr::GetAvailHeight() { +float CXFA_LayoutPageMgr::GetAvailHeight() { CXFA_ContainerLayoutItem* pLayoutItem = GetCurrentContainerRecord()->pCurContentArea; if (!pLayoutItem || !pLayoutItem->m_pFormNode) return 0.0f; - FX_FLOAT fAvailHeight = + float fAvailHeight = pLayoutItem->m_pFormNode->GetMeasure(XFA_ATTRIBUTE_H).ToUnit(XFA_UNIT_Pt); if (fAvailHeight >= XFA_LAYOUT_FLOAT_PERCISION) return fAvailHeight; @@ -552,17 +556,16 @@ CXFA_ContainerRecord* CXFA_LayoutPageMgr::CreateContainerRecord( void CXFA_LayoutPageMgr::AddPageAreaLayoutItem(CXFA_ContainerRecord* pNewRecord, CXFA_Node* pNewPageArea) { CXFA_ContainerLayoutItem* pNewPageAreaLayoutItem = nullptr; - if (m_PageArray.GetSize() > m_nAvailPages) { + if (pdfium::IndexInBounds(m_PageArray, m_nAvailPages)) { CXFA_ContainerLayoutItem* pContainerItem = m_PageArray[m_nAvailPages]; pContainerItem->m_pFormNode = pNewPageArea; m_nAvailPages++; pNewPageAreaLayoutItem = pContainerItem; } else { CXFA_FFNotify* pNotify = pNewPageArea->GetDocument()->GetNotify(); - CXFA_ContainerLayoutItem* pContainerItem = - static_cast<CXFA_ContainerLayoutItem*>( - pNotify->OnCreateLayoutItem(pNewPageArea)); - m_PageArray.Add(pContainerItem); + auto* pContainerItem = static_cast<CXFA_ContainerLayoutItem*>( + pNotify->OnCreateLayoutItem(pNewPageArea)); + m_PageArray.push_back(pContainerItem); m_nAvailPages++; pNotify->OnPageEvent(pContainerItem, XFA_PAGEVIEWEVENT_PostRemoved); pNewPageAreaLayoutItem = pContainerItem; @@ -647,7 +650,7 @@ void CXFA_LayoutPageMgr::FinishPaginatedPageSets() { } } bool bUsable = true; - CFX_ArrayTemplate<FX_FLOAT> rgUsedHeights; + std::vector<float> rgUsedHeights; for (CXFA_LayoutItem* pChildLayoutItem = pLastPageAreaLayoutItem->m_pFirstChild; pChildLayoutItem; @@ -656,7 +659,7 @@ void CXFA_LayoutPageMgr::FinishPaginatedPageSets() { XFA_Element::ContentArea) { continue; } - FX_FLOAT fUsedHeight = 0; + float fUsedHeight = 0; for (CXFA_LayoutItem* pContentChildLayoutItem = pChildLayoutItem->m_pFirstChild; pContentChildLayoutItem; @@ -667,7 +670,7 @@ void CXFA_LayoutPageMgr::FinishPaginatedPageSets() { fUsedHeight += pContent->m_sSize.height; } } - rgUsedHeights.Add(fUsedHeight); + rgUsedHeights.push_back(fUsedHeight); } int32_t iCurContentAreaIndex = -1; for (CXFA_Node* pContentAreaNode = @@ -723,19 +726,19 @@ void CXFA_LayoutPageMgr::FinishPaginatedPageSets() { } int32_t CXFA_LayoutPageMgr::GetPageCount() const { - return m_PageArray.GetSize(); + return pdfium::CollectionSize<int32_t>(m_PageArray); } CXFA_ContainerLayoutItem* CXFA_LayoutPageMgr::GetPage(int32_t index) const { - if (index < 0 || index >= m_PageArray.GetSize()) + if (!pdfium::IndexInBounds(m_PageArray, index)) return nullptr; return m_PageArray[index]; } int32_t CXFA_LayoutPageMgr::GetPageIndex( const CXFA_ContainerLayoutItem* pPage) const { - // FIXME: Find() method should take const. - return m_PageArray.Find(const_cast<CXFA_ContainerLayoutItem*>(pPage)); + auto it = std::find(m_PageArray.begin(), m_PageArray.end(), pPage); + return it != m_PageArray.end() ? it - m_PageArray.begin() : -1; } bool CXFA_LayoutPageMgr::RunBreak(XFA_Element eBreakType, @@ -1511,7 +1514,7 @@ void CXFA_LayoutPageMgr::ProcessLastPageSet() { } } -bool CXFA_LayoutPageMgr::GetNextAvailContentHeight(FX_FLOAT fChildHeight) { +bool CXFA_LayoutPageMgr::GetNextAvailContentHeight(float fChildHeight) { CXFA_Node* pCurContentNode = GetCurrentContainerRecord()->pCurContentArea->m_pFormNode; if (!pCurContentNode) @@ -1520,7 +1523,7 @@ bool CXFA_LayoutPageMgr::GetNextAvailContentHeight(FX_FLOAT fChildHeight) { pCurContentNode = pCurContentNode->GetNextSameClassSibling(XFA_Element::ContentArea); if (pCurContentNode) { - FX_FLOAT fNextContentHeight = + float fNextContentHeight = pCurContentNode->GetMeasure(XFA_ATTRIBUTE_H).ToUnit(XFA_UNIT_Pt); return fNextContentHeight > fChildHeight; } @@ -1549,7 +1552,7 @@ bool CXFA_LayoutPageMgr::GetNextAvailContentHeight(FX_FLOAT fChildHeight) { CXFA_Node* pContentArea = pNextPage->GetFirstChildByClass(XFA_Element::ContentArea); if (pContentArea) { - FX_FLOAT fNextContentHeight = + float fNextContentHeight = pContentArea->GetMeasure(XFA_ATTRIBUTE_H).ToUnit(XFA_UNIT_Pt); if (fNextContentHeight > fChildHeight) return true; @@ -1561,7 +1564,7 @@ bool CXFA_LayoutPageMgr::GetNextAvailContentHeight(FX_FLOAT fChildHeight) { CXFA_Node* pContentArea = pPageNode->GetFirstChildByClass(XFA_Element::ContentArea); - FX_FLOAT fNextContentHeight = + float fNextContentHeight = pContentArea->GetMeasure(XFA_ATTRIBUTE_H).ToUnit(XFA_UNIT_Pt); if (fNextContentHeight < XFA_LAYOUT_FLOAT_PERCISION) return true; @@ -1632,9 +1635,7 @@ void CXFA_LayoutPageMgr::SaveLayoutItem(CXFA_LayoutItem* pParentLayoutItem) { } } -CXFA_Node* CXFA_LayoutPageMgr::QueryOverflow( - CXFA_Node* pFormNode, - CXFA_LayoutContext* pLayoutContext) { +CXFA_Node* CXFA_LayoutPageMgr::QueryOverflow(CXFA_Node* pFormNode) { for (CXFA_Node* pCurNode = pFormNode->GetNodeItem(XFA_NODEITEM_FirstChild); pCurNode; pCurNode = pCurNode->GetNodeItem((XFA_NODEITEM_NextSibling))) { if (pCurNode->GetElementType() == XFA_Element::Break) { @@ -1661,22 +1662,19 @@ void CXFA_LayoutPageMgr::MergePageSetContents() { CXFA_FFNotify* pNotify = pDocument->GetNotify(); CXFA_LayoutProcessor* pDocLayout = pDocument->GetDocLayout(); CXFA_ContainerLayoutItem* pRootLayout = GetRootLayoutItem(); - { - for (int32_t iIndex = 0; iIndex < pDocument->m_pPendingPageSet.GetSize(); - iIndex++) { - CXFA_NodeIteratorTemplate<CXFA_Node, CXFA_TraverseStrategy_XFANode> - sIterator(pDocument->m_pPendingPageSet.GetAt(iIndex)); - for (CXFA_Node* pNode = sIterator.GetCurrent(); pNode; - pNode = sIterator.MoveToNext()) { - if (pNode->IsContainerNode()) { - CXFA_Node* pBindNode = pNode->GetBindData(); - if (pBindNode) { - pBindNode->RemoveBindItem(pNode); - pNode->SetObject(XFA_ATTRIBUTE_BindingNode, nullptr); - } + for (CXFA_Node* pPageNode : pDocument->m_pPendingPageSet) { + CXFA_NodeIteratorTemplate<CXFA_Node, CXFA_TraverseStrategy_XFANode> + sIterator(pPageNode); + for (CXFA_Node* pNode = sIterator.GetCurrent(); pNode; + pNode = sIterator.MoveToNext()) { + if (pNode->IsContainerNode()) { + CXFA_Node* pBindNode = pNode->GetBindData(); + if (pBindNode) { + pBindNode->RemoveBindItem(pNode); + pNode->SetObject(XFA_ATTRIBUTE_BindingNode, nullptr); } - pNode->SetFlag(XFA_NodeFlag_UnusedNode, true); } + pNode->SetFlag(XFA_NodeFlag_UnusedNode, true); } } @@ -1691,8 +1689,9 @@ void CXFA_LayoutPageMgr::MergePageSetContents() { CXFA_ContainerLayoutItem* pRootPageSetContainerItem = iterator.GetCurrent(); ASSERT(pRootPageSetContainerItem->m_pFormNode->GetElementType() == XFA_Element::PageSet); - if (iIndex < pDocument->m_pPendingPageSet.GetSize()) { - pPendingPageSet = pDocument->m_pPendingPageSet.GetAt(iIndex); + if (iIndex < + pdfium::CollectionSize<int32_t>(pDocument->m_pPendingPageSet)) { + pPendingPageSet = pDocument->m_pPendingPageSet[iIndex]; iIndex++; } if (!pPendingPageSet) { @@ -1924,10 +1923,10 @@ void CXFA_LayoutPageMgr::SyncLayoutData() { } } - int32_t nPage = m_PageArray.GetSize(); + int32_t nPage = pdfium::CollectionSize<int32_t>(m_PageArray); for (int32_t i = nPage - 1; i >= m_nAvailPages; i--) { CXFA_ContainerLayoutItem* pPage = m_PageArray[i]; - m_PageArray.RemoveAt(i); + m_PageArray.erase(m_PageArray.begin() + i); pNotify->OnPageEvent(pPage, XFA_PAGEVIEWEVENT_PostRemoved); delete pPage; } @@ -1958,20 +1957,20 @@ void CXFA_LayoutPageMgr::PrepareLayout() { if (pRootLayoutItem && pRootLayoutItem->m_pFormNode->GetPacketID() == XFA_XDPPACKET_Form) { CXFA_Node* pPageSetFormNode = pRootLayoutItem->m_pFormNode; - pRootLayoutItem->m_pFormNode->GetDocument()->m_pPendingPageSet.RemoveAll(); + pRootLayoutItem->m_pFormNode->GetDocument()->m_pPendingPageSet.clear(); if (pPageSetFormNode->HasRemovedChildren()) { XFA_ReleaseLayoutItem(pRootLayoutItem); m_pPageSetLayoutItemRoot = nullptr; pRootLayoutItem = nullptr; pPageSetFormNode = nullptr; - m_PageArray.RemoveAll(); + m_PageArray.clear(); } while (pPageSetFormNode) { CXFA_Node* pNextPageSet = pPageSetFormNode->GetNextSameClassSibling(XFA_Element::PageSet); pPageSetFormNode->GetNodeItem(XFA_NODEITEM_Parent) ->RemoveChild(pPageSetFormNode, false); - pRootLayoutItem->m_pFormNode->GetDocument()->m_pPendingPageSet.Add( + pRootLayoutItem->m_pFormNode->GetDocument()->m_pPendingPageSet.push_back( pPageSetFormNode); pPageSetFormNode = pNextPageSet; } diff --git a/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_layoutpagemgr.h b/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_layoutpagemgr.h index 3c8e7f9d1e0..085ea896710 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_layoutpagemgr.h +++ b/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_layoutpagemgr.h @@ -10,11 +10,13 @@ #include <iterator> #include <list> #include <map> +#include <vector> -#include "xfa/fxfa/parser/xfa_layout_itemlayout.h" +#include "xfa/fxfa/parser/cxfa_itemlayoutprocessor.h" class CXFA_ContainerRecord; class CXFA_LayoutItem; +class CXFA_Node; class CXFA_LayoutPageMgr { public: @@ -23,8 +25,8 @@ class CXFA_LayoutPageMgr { bool InitLayoutPage(CXFA_Node* pFormNode); bool PrepareFirstPage(CXFA_Node* pRootSubform); - FX_FLOAT GetAvailHeight(); - bool GetNextAvailContentHeight(FX_FLOAT fChildHeight); + float GetAvailHeight(); + bool GetNextAvailContentHeight(float fChildHeight); void SubmitContentItem(CXFA_ContentLayoutItem* pContentLayoutItem, XFA_ItemLayoutProcessorResult eStatus); void FinishPaginatedPageSets(); @@ -45,13 +47,12 @@ class CXFA_LayoutPageMgr { CXFA_Node*& pTrailerNode, bool bDataMerge = false, bool bCreatePage = true); - CXFA_Node* QueryOverflow(CXFA_Node* pFormNode, - CXFA_LayoutContext* pLayoutContext = nullptr); + CXFA_Node* QueryOverflow(CXFA_Node* pFormNode); bool ProcessBookendLeaderOrTrailer(CXFA_Node* pBookendNode, bool bLeader, CXFA_Node*& pBookendAppendNode); - protected: + private: bool AppendNewPage(bool bFirstTemPage = false); void ReorderPendingLayoutRecordToTail(CXFA_ContainerRecord* pNewRecord, CXFA_ContainerRecord* pPrevRecord); @@ -140,7 +141,7 @@ class CXFA_LayoutPageMgr { XFA_ATTRIBUTEENUM m_ePageSetMode; bool m_bCreateOverFlowPage; std::map<CXFA_Node*, int32_t> m_pPageSetMap; - CFX_ArrayTemplate<CXFA_ContainerLayoutItem*> m_PageArray; + std::vector<CXFA_ContainerLayoutItem*> m_PageArray; }; #endif // XFA_FXFA_PARSER_CXFA_LAYOUTPAGEMGR_H_ diff --git a/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_layoutprocessor.cpp b/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_layoutprocessor.cpp index e179d389854..2e919dbc843 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_layoutprocessor.cpp +++ b/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_layoutprocessor.cpp @@ -7,20 +7,19 @@ #include "xfa/fxfa/parser/cxfa_layoutprocessor.h" #include "third_party/base/ptr_util.h" +#include "third_party/base/stl_util.h" #include "xfa/fxfa/parser/cxfa_contentlayoutitem.h" #include "xfa/fxfa/parser/cxfa_document.h" +#include "xfa/fxfa/parser/cxfa_itemlayoutprocessor.h" #include "xfa/fxfa/parser/cxfa_layoutpagemgr.h" +#include "xfa/fxfa/parser/cxfa_localemgr.h" #include "xfa/fxfa/parser/cxfa_measurement.h" +#include "xfa/fxfa/parser/cxfa_node.h" #include "xfa/fxfa/parser/xfa_document_datamerger_imp.h" -#include "xfa/fxfa/parser/xfa_layout_itemlayout.h" -#include "xfa/fxfa/parser/xfa_localemgr.h" -#include "xfa/fxfa/parser/xfa_object.h" #include "xfa/fxfa/parser/xfa_utils.h" CXFA_LayoutProcessor::CXFA_LayoutProcessor(CXFA_Document* pDocument) - : m_pDocument(pDocument), - m_nProgressCounter(0), - m_bNeeLayout(true) {} + : m_pDocument(pDocument), m_nProgressCounter(0), m_bNeedLayout(true) {} CXFA_LayoutProcessor::~CXFA_LayoutProcessor() {} @@ -64,10 +63,10 @@ int32_t CXFA_LayoutProcessor::DoLayout(IFX_Pause* pPause) { XFA_ItemLayoutProcessorResult eStatus; CXFA_Node* pFormNode = m_pRootItemLayoutProcessor->GetFormNode(); - FX_FLOAT fPosX = pFormNode->GetMeasure(XFA_ATTRIBUTE_X).ToUnit(XFA_UNIT_Pt); - FX_FLOAT fPosY = pFormNode->GetMeasure(XFA_ATTRIBUTE_Y).ToUnit(XFA_UNIT_Pt); + float fPosX = pFormNode->GetMeasure(XFA_ATTRIBUTE_X).ToUnit(XFA_UNIT_Pt); + float fPosY = pFormNode->GetMeasure(XFA_ATTRIBUTE_Y).ToUnit(XFA_UNIT_Pt); do { - FX_FLOAT fAvailHeight = m_pLayoutPageMgr->GetAvailHeight(); + float fAvailHeight = m_pLayoutPageMgr->GetAvailHeight(); eStatus = m_pRootItemLayoutProcessor->DoLayout(true, fAvailHeight, fAvailHeight, nullptr); if (eStatus != XFA_ItemLayoutProcessorResult::Done) @@ -85,8 +84,8 @@ int32_t CXFA_LayoutProcessor::DoLayout(IFX_Pause* pPause) { if (eStatus == XFA_ItemLayoutProcessorResult::Done) { m_pLayoutPageMgr->FinishPaginatedPageSets(); m_pLayoutPageMgr->SyncLayoutData(); - m_bNeeLayout = false; - m_rgChangedContainers.RemoveAll(); + m_bNeedLayout = false; + m_rgChangedContainers.clear(); } return 100 * (eStatus == XFA_ItemLayoutProcessorResult::Done ? m_nProgressCounter @@ -95,13 +94,11 @@ int32_t CXFA_LayoutProcessor::DoLayout(IFX_Pause* pPause) { } bool CXFA_LayoutProcessor::IncrementLayout() { - if (m_bNeeLayout) { + if (m_bNeedLayout) { StartLayout(true); return DoLayout(nullptr) == 100; } - - for (int32_t i = 0, c = m_rgChangedContainers.GetSize(); i < c; i++) { - CXFA_Node* pNode = m_rgChangedContainers[i]; + for (CXFA_Node* pNode : m_rgChangedContainers) { CXFA_Node* pParentNode = pNode->GetNodeItem(XFA_NODEITEM_Parent, XFA_ObjectType::ContainerNode); if (!pParentNode) @@ -111,7 +108,7 @@ bool CXFA_LayoutProcessor::IncrementLayout() { return false; } } - m_rgChangedContainers.RemoveAll(); + m_rgChangedContainers.clear(); return true; } @@ -129,8 +126,8 @@ CXFA_LayoutItem* CXFA_LayoutProcessor::GetLayoutItem(CXFA_Node* pFormItem) { } void CXFA_LayoutProcessor::AddChangedContainer(CXFA_Node* pContainer) { - if (m_rgChangedContainers.Find(pContainer) < 0) - m_rgChangedContainers.Add(pContainer); + if (!pdfium::ContainsValue(m_rgChangedContainers, pContainer)) + m_rgChangedContainers.push_back(pContainer); } CXFA_ContainerLayoutItem* CXFA_LayoutProcessor::GetRootLayoutItem() const { @@ -138,5 +135,5 @@ CXFA_ContainerLayoutItem* CXFA_LayoutProcessor::GetRootLayoutItem() const { } bool CXFA_LayoutProcessor::IsNeedLayout() { - return m_bNeeLayout || m_rgChangedContainers.GetSize() > 0; + return m_bNeedLayout || !m_rgChangedContainers.empty(); } diff --git a/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_layoutprocessor.h b/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_layoutprocessor.h index 5861bf7048e..75bf2597c55 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_layoutprocessor.h +++ b/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_layoutprocessor.h @@ -8,9 +8,9 @@ #define XFA_FXFA_PARSER_CXFA_LAYOUTPROCESSOR_H_ #include <memory> +#include <vector> #include "core/fxcrt/fx_system.h" -#include "xfa/fxfa/parser/xfa_object.h" class CXFA_ContainerLayoutItem; class CXFA_Document; @@ -33,7 +33,7 @@ class CXFA_LayoutProcessor { CXFA_ContainerLayoutItem* GetPage(int32_t index) const; CXFA_LayoutItem* GetLayoutItem(CXFA_Node* pFormItem); void AddChangedContainer(CXFA_Node* pContainer); - void SetForceReLayout(bool bForceRestart) { m_bNeeLayout = bForceRestart; } + void SetForceReLayout(bool bForceRestart) { m_bNeedLayout = bForceRestart; } CXFA_ContainerLayoutItem* GetRootLayoutItem() const; CXFA_ItemLayoutProcessor* GetRootRootItemLayoutProcessor() const { return m_pRootItemLayoutProcessor.get(); @@ -48,9 +48,9 @@ class CXFA_LayoutProcessor { CXFA_Document* const m_pDocument; std::unique_ptr<CXFA_ItemLayoutProcessor> m_pRootItemLayoutProcessor; std::unique_ptr<CXFA_LayoutPageMgr> m_pLayoutPageMgr; - CXFA_NodeArray m_rgChangedContainers; + std::vector<CXFA_Node*> m_rgChangedContainers; uint32_t m_nProgressCounter; - bool m_bNeeLayout; + bool m_bNeedLayout; }; #endif // XFA_FXFA_PARSER_CXFA_LAYOUTPROCESSOR_H_ diff --git a/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_line.cpp b/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_line.cpp index 38de0d8ca88..8be1d25a46d 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_line.cpp +++ b/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_line.cpp @@ -6,7 +6,7 @@ #include "xfa/fxfa/parser/cxfa_line.h" -#include "xfa/fxfa/parser/xfa_object.h" +#include "xfa/fxfa/parser/cxfa_node.h" int32_t CXFA_Line::GetHand() { return m_pNode->GetEnum(XFA_ATTRIBUTE_Hand); diff --git a/chromium/third_party/pdfium/xfa/fxfa/parser/xfa_localemgr.cpp b/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_localemgr.cpp index 0cd64ea6dc6..b0828576339 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/parser/xfa_localemgr.cpp +++ b/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_localemgr.cpp @@ -4,7 +4,7 @@ // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com -#include "xfa/fxfa/parser/xfa_localemgr.h" +#include "xfa/fxfa/parser/cxfa_localemgr.h" #include <time.h> @@ -12,11 +12,11 @@ #include <utility> #include "core/fxcodec/fx_codec.h" -#include "core/fxcrt/fx_xml.h" +#include "core/fxcrt/xml/cxml_element.h" #include "core/fxge/cfx_gemodule.h" -#include "xfa/fxfa/parser/cxfa_document.h" -#include "xfa/fxfa/parser/xfa_locale.h" -#include "xfa/fxfa/parser/xfa_object.h" +#include "xfa/fxfa/parser/cxfa_node.h" +#include "xfa/fxfa/parser/cxfa_nodelocale.h" +#include "xfa/fxfa/parser/cxfa_xmllocale.h" #include "xfa/fxfa/parser/xfa_utils.h" const uint8_t g_enUS_Locale[] = { @@ -1246,29 +1246,3 @@ CFX_WideStringC CXFA_LocaleMgr::GetConfigLocaleName(CXFA_Node* pConfig) { } return m_wsConfigLocale.AsStringC(); } - -static bool g_bProviderTimeZoneSet = false; - -CXFA_TimeZoneProvider::CXFA_TimeZoneProvider() { -#if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ - if (!g_bProviderTimeZoneSet) { - g_bProviderTimeZoneSet = true; - _tzset(); - } - m_tz.tzHour = (int8_t)(_timezone / 3600 * -1); - m_tz.tzMinute = (int8_t)((FXSYS_abs(_timezone) % 3600) / 60); -#else - if (!g_bProviderTimeZoneSet) { - g_bProviderTimeZoneSet = true; - tzset(); - } - m_tz.tzHour = (int8_t)(timezone / 3600 * -1); - m_tz.tzMinute = (int8_t)((FXSYS_abs((int)timezone) % 3600) / 60); -#endif -} - -CXFA_TimeZoneProvider::~CXFA_TimeZoneProvider() {} - -void CXFA_TimeZoneProvider::GetTimeZone(FX_TIMEZONE* tz) const { - *tz = m_tz; -} diff --git a/chromium/third_party/pdfium/xfa/fxfa/parser/xfa_localemgr.h b/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_localemgr.h index eb405dcfc72..307cc621d05 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/parser/xfa_localemgr.h +++ b/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_localemgr.h @@ -4,15 +4,15 @@ // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com -#ifndef XFA_FXFA_PARSER_XFA_LOCALEMGR_H_ -#define XFA_FXFA_PARSER_XFA_LOCALEMGR_H_ +#ifndef XFA_FXFA_PARSER_CXFA_LOCALEMGR_H_ +#define XFA_FXFA_PARSER_CXFA_LOCALEMGR_H_ #include <memory> #include <vector> -#include "xfa/fgas/localization/fgas_datetime.h" -#include "xfa/fgas/localization/fgas_locale.h" -#include "xfa/fxfa/parser/xfa_localemgr.h" +#include "core/fxcrt/cfx_datetime.h" +#include "core/fxcrt/ifx_locale.h" +#include "xfa/fxfa/parser/cxfa_localemgr.h" class CXFA_Node; class IFX_Locale; @@ -33,21 +33,20 @@ class IFX_Locale; #define XFA_LANGID_nl_NL 0x0413 #define XFA_LANGID_ru_RU 0x0419 -class CXFA_LocaleMgr : public IFX_LocaleMgr { +class CXFA_LocaleMgr { public: CXFA_LocaleMgr(CXFA_Node* pLocaleSet, CFX_WideString wsDeflcid); - ~CXFA_LocaleMgr() override; + ~CXFA_LocaleMgr(); - // IFX_LocaleMgr - uint16_t GetDefLocaleID() const override; - IFX_Locale* GetDefLocale() override; - IFX_Locale* GetLocaleByName(const CFX_WideString& wsLocaleName) override; + uint16_t GetDefLocaleID() const; + IFX_Locale* GetDefLocale(); + IFX_Locale* GetLocaleByName(const CFX_WideString& wsLocaleName); void SetDefLocale(IFX_Locale* pLocale); CFX_WideStringC GetConfigLocaleName(CXFA_Node* pConfig); - protected: - std::unique_ptr<IFX_Locale> GetLocale(uint16_t lcid) override; + private: + std::unique_ptr<IFX_Locale> GetLocale(uint16_t lcid); std::vector<std::unique_ptr<IFX_Locale>> m_LocaleArray; std::vector<std::unique_ptr<IFX_Locale>> m_XMLLocaleArray; @@ -57,15 +56,4 @@ class CXFA_LocaleMgr : public IFX_LocaleMgr { uint16_t m_dwLocaleFlags; }; -class CXFA_TimeZoneProvider { - public: - CXFA_TimeZoneProvider(); - ~CXFA_TimeZoneProvider(); - - void GetTimeZone(FX_TIMEZONE* tz) const; - - private: - FX_TIMEZONE m_tz; -}; - -#endif // XFA_FXFA_PARSER_XFA_LOCALEMGR_H_ +#endif // XFA_FXFA_PARSER_CXFA_LOCALEMGR_H_ diff --git a/chromium/third_party/pdfium/xfa/fxfa/parser/xfa_localevalue.cpp b/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_localevalue.cpp index 7e92535c3d5..67780924c2a 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/parser/xfa_localevalue.cpp +++ b/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_localevalue.cpp @@ -4,35 +4,18 @@ // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com -#include "xfa/fxfa/parser/xfa_localevalue.h" +#include "xfa/fxfa/parser/cxfa_localevalue.h" #include <vector> #include "core/fxcrt/fx_ext.h" #include "third_party/base/ptr_util.h" #include "third_party/base/stl_util.h" -#include "xfa/fgas/localization/fgas_localeimp.h" +#include "xfa/fgas/crt/cfgas_formatstring.h" #include "xfa/fxfa/parser/cxfa_document.h" -#include "xfa/fxfa/parser/xfa_localemgr.h" -#include "xfa/fxfa/parser/xfa_object.h" +#include "xfa/fxfa/parser/cxfa_localemgr.h" #include "xfa/fxfa/parser/xfa_utils.h" -static const FX_DOUBLE fraction_scales[] = {0.1, - 0.01, - 0.001, - 0.0001, - 0.00001, - 0.000001, - 0.0000001, - 0.00000001, - 0.000000001, - 0.0000000001, - 0.00000000001, - 0.000000000001, - 0.0000000000001, - 0.00000000000001, - 0.000000000000001, - 0.0000000000000001}; CXFA_LocaleValue::CXFA_LocaleValue() { m_dwType = XFA_VT_NULL; m_bValid = true; @@ -107,7 +90,7 @@ bool CXFA_LocaleValue::ValidateValue(const CFX_WideString& wsValue, if (pLocale) m_pLocaleMgr->SetDefLocale(pLocale); - auto pFormat = pdfium::MakeUnique<CFX_FormatString>(m_pLocaleMgr, false); + auto pFormat = pdfium::MakeUnique<CFGAS_FormatString>(m_pLocaleMgr); std::vector<CFX_WideString> wsPatterns; pFormat->SplitFormatString(wsPattern, wsPatterns); @@ -147,11 +130,11 @@ bool CXFA_LocaleValue::ValidateValue(const CFX_WideString& wsValue, } break; case FX_LOCALECATEGORY_Date: { - CFX_Unitime dt; - bRet = ValidateCanonicalDate(wsValue, dt); + CFX_DateTime dt; + bRet = ValidateCanonicalDate(wsValue, &dt); if (!bRet) { bRet = pFormat->ParseDateTime(wsValue, wsFormat, FX_DATETIMETYPE_Date, - dt); + &dt); if (!bRet) { bRet = pFormat->FormatDateTime(wsValue, wsFormat, wsOutput, FX_DATETIMETYPE_Date); @@ -160,9 +143,9 @@ bool CXFA_LocaleValue::ValidateValue(const CFX_WideString& wsValue, break; } case FX_LOCALECATEGORY_Time: { - CFX_Unitime dt; - bRet = - pFormat->ParseDateTime(wsValue, wsFormat, FX_DATETIMETYPE_Time, dt); + CFX_DateTime dt; + bRet = pFormat->ParseDateTime(wsValue, wsFormat, FX_DATETIMETYPE_Time, + &dt); if (!bRet) { bRet = pFormat->FormatDateTime(wsValue, wsFormat, wsOutput, FX_DATETIMETYPE_Time); @@ -170,9 +153,9 @@ bool CXFA_LocaleValue::ValidateValue(const CFX_WideString& wsValue, break; } case FX_LOCALECATEGORY_DateTime: { - CFX_Unitime dt; + CFX_DateTime dt; bRet = pFormat->ParseDateTime(wsValue, wsFormat, - FX_DATETIMETYPE_DateTime, dt); + FX_DATETIMETYPE_DateTime, &dt); if (!bRet) { bRet = pFormat->FormatDateTime(wsValue, wsFormat, wsOutput, FX_DATETIMETYPE_DateTime); @@ -210,7 +193,7 @@ CFX_WideString CXFA_LocaleValue::GetText() const { } return CFX_WideString(); } -FX_FLOAT CXFA_LocaleValue::GetNum() const { +float CXFA_LocaleValue::GetNum() const { if (m_bValid && (m_dwType == XFA_VT_BOOLEAN || m_dwType == XFA_VT_INTEGER || m_dwType == XFA_VT_DECIMAL || m_dwType == XFA_VT_FLOAT)) { int64_t nIntegral = 0; @@ -218,7 +201,7 @@ FX_FLOAT CXFA_LocaleValue::GetNum() const { int32_t nExponent = 0; int cc = 0; bool bNegative = false, bExpSign = false; - const FX_WCHAR* str = m_wsValue.c_str(); + const wchar_t* str = m_wsValue.c_str(); int len = m_wsValue.GetLength(); while (FXSYS_iswspace(str[cc]) && cc < len) { cc++; @@ -248,10 +231,10 @@ FX_FLOAT CXFA_LocaleValue::GetNum() const { if (cc < len && str[cc] == '.') { cc++; while (cc < len) { - fraction += fraction_scales[scale] * (str[cc] - '0'); + fraction += XFA_GetFractionalScale(scale) * (str[cc] - '0'); scale++; cc++; - if (scale == sizeof fraction_scales / sizeof(double) || + if (scale == XFA_GetMaxFractionalScale() || !FXSYS_isDecimalDigit(str[cc])) { break; } @@ -277,16 +260,16 @@ FX_FLOAT CXFA_LocaleValue::GetNum() const { } nExponent = bExpSign ? -nExponent : nExponent; } - FX_FLOAT fValue = (FX_FLOAT)(dwFractional / 4294967296.0); + float fValue = (float)(dwFractional / 4294967296.0); fValue = nIntegral + (nIntegral >= 0 ? fValue : -fValue); if (nExponent != 0) { - fValue *= FXSYS_pow(10, (FX_FLOAT)nExponent); + fValue *= FXSYS_pow(10, (float)nExponent); } return fValue; } return 0; } -FX_DOUBLE CXFA_LocaleValue::GetDoubleNum() const { +double CXFA_LocaleValue::GetDoubleNum() const { if (m_bValid && (m_dwType == XFA_VT_BOOLEAN || m_dwType == XFA_VT_INTEGER || m_dwType == XFA_VT_DECIMAL || m_dwType == XFA_VT_FLOAT)) { int64_t nIntegral = 0; @@ -294,20 +277,20 @@ FX_DOUBLE CXFA_LocaleValue::GetDoubleNum() const { int32_t nExponent = 0; int32_t cc = 0; bool bNegative = false, bExpSign = false; - const FX_WCHAR* str = m_wsValue.c_str(); + const wchar_t* str = m_wsValue.c_str(); int len = m_wsValue.GetLength(); - while (FXSYS_iswspace(str[cc]) && cc < len) { + while (FXSYS_iswspace(str[cc]) && cc < len) cc++; - } - if (cc >= len) { + + if (cc >= len) return 0; - } if (str[0] == '+') { cc++; } else if (str[0] == '-') { bNegative = true; cc++; } + int32_t nIntegralLen = 0; while (cc < len) { if (str[cc] == '.' || !FXSYS_isDecimalDigit(str[cc]) || @@ -320,19 +303,19 @@ FX_DOUBLE CXFA_LocaleValue::GetDoubleNum() const { } nIntegral = bNegative ? -nIntegral : nIntegral; int32_t scale = 0; - FX_DOUBLE fraction = 0.0; + double fraction = 0.0; if (cc < len && str[cc] == '.') { cc++; while (cc < len) { - fraction += fraction_scales[scale] * (str[cc] - '0'); + fraction += XFA_GetFractionalScale(scale) * (str[cc] - '0'); scale++; cc++; - if (scale == sizeof fraction_scales / sizeof(FX_DOUBLE) || + if (scale == XFA_GetMaxFractionalScale() || !FXSYS_isDecimalDigit(str[cc])) { break; } } - dwFractional = (uint32_t)(fraction * 4294967296.0); + dwFractional = static_cast<uint32_t>(fraction * 4294967296.0); } if (cc < len && (str[cc] == 'E' || str[cc] == 'e')) { cc++; @@ -345,88 +328,100 @@ FX_DOUBLE CXFA_LocaleValue::GetDoubleNum() const { } } while (cc < len) { - if (str[cc] == '.' || !FXSYS_isDecimalDigit(str[cc])) { + if (str[cc] == '.' || !FXSYS_isDecimalDigit(str[cc])) break; - } + nExponent = nExponent * 10 + str[cc] - '0'; cc++; } nExponent = bExpSign ? -nExponent : nExponent; } - FX_DOUBLE dValue = (dwFractional / 4294967296.0); + + double dValue = dwFractional / 4294967296.0; dValue = nIntegral + (nIntegral >= 0 ? dValue : -dValue); - if (nExponent != 0) { - dValue *= FXSYS_pow(10, (FX_FLOAT)nExponent); - } + if (nExponent != 0) + dValue *= FXSYS_pow(10, static_cast<float>(nExponent)); + return dValue; } return 0; } -CFX_Unitime CXFA_LocaleValue::GetDate() const { + +CFX_DateTime CXFA_LocaleValue::GetDate() const { if (m_bValid && m_dwType == XFA_VT_DATE) { - CFX_Unitime dt; - FX_DateFromCanonical(m_wsValue, dt); + CFX_DateTime dt; + FX_DateFromCanonical(m_wsValue, &dt); return dt; } - return CFX_Unitime(); + return CFX_DateTime(); } -CFX_Unitime CXFA_LocaleValue::GetTime() const { + +CFX_DateTime CXFA_LocaleValue::GetTime() const { if (m_bValid && m_dwType == XFA_VT_TIME) { - CFX_Unitime dt(0); ASSERT(m_pLocaleMgr); - FX_TimeFromCanonical(m_wsValue.AsStringC(), dt, + + CFX_DateTime dt; + FX_TimeFromCanonical(m_wsValue.AsStringC(), &dt, m_pLocaleMgr->GetDefLocale()); return dt; } - return CFX_Unitime(); + return CFX_DateTime(); } -CFX_Unitime CXFA_LocaleValue::GetDateTime() const { + +CFX_DateTime CXFA_LocaleValue::GetDateTime() const { if (m_bValid && m_dwType == XFA_VT_DATETIME) { int32_t index = m_wsValue.Find('T'); - CFX_Unitime dt; - FX_DateFromCanonical(m_wsValue.Left(index), dt); + CFX_DateTime dt; + FX_DateFromCanonical(m_wsValue.Left(index), &dt); ASSERT(m_pLocaleMgr); FX_TimeFromCanonical( - m_wsValue.Right(m_wsValue.GetLength() - index - 1).AsStringC(), dt, + m_wsValue.Right(m_wsValue.GetLength() - index - 1).AsStringC(), &dt, m_pLocaleMgr->GetDefLocale()); return dt; } - return CFX_Unitime(); + return CFX_DateTime(); } + bool CXFA_LocaleValue::SetText(const CFX_WideString& wsText) { m_dwType = XFA_VT_TEXT; m_wsValue = wsText; return true; } + bool CXFA_LocaleValue::SetText(const CFX_WideString& wsText, const CFX_WideString& wsFormat, IFX_Locale* pLocale) { m_dwType = XFA_VT_TEXT; return m_bValid = ParsePatternValue(wsText, wsFormat, pLocale); } -bool CXFA_LocaleValue::SetNum(FX_FLOAT fNum) { + +bool CXFA_LocaleValue::SetNum(float fNum) { m_dwType = XFA_VT_FLOAT; - m_wsValue.Format(L"%.8g", (FX_DOUBLE)fNum); + m_wsValue.Format(L"%.8g", static_cast<double>(fNum)); return true; } + bool CXFA_LocaleValue::SetNum(const CFX_WideString& wsNum, const CFX_WideString& wsFormat, IFX_Locale* pLocale) { m_dwType = XFA_VT_FLOAT; return m_bValid = ParsePatternValue(wsNum, wsFormat, pLocale); } -bool CXFA_LocaleValue::SetDate(const CFX_Unitime& d) { + +bool CXFA_LocaleValue::SetDate(const CFX_DateTime& d) { m_dwType = XFA_VT_DATE; m_wsValue.Format(L"%04d-%02d-%02d", d.GetYear(), d.GetMonth(), d.GetDay()); return true; } + bool CXFA_LocaleValue::SetDate(const CFX_WideString& wsDate, const CFX_WideString& wsFormat, IFX_Locale* pLocale) { m_dwType = XFA_VT_DATE; return m_bValid = ParsePatternValue(wsDate, wsFormat, pLocale); } -bool CXFA_LocaleValue::SetTime(const CFX_Unitime& t) { + +bool CXFA_LocaleValue::SetTime(const CFX_DateTime& t) { m_dwType = XFA_VT_TIME; m_wsValue.Format(L"%02d:%02d:%02d", t.GetHour(), t.GetMinute(), t.GetSecond()); @@ -437,13 +432,15 @@ bool CXFA_LocaleValue::SetTime(const CFX_Unitime& t) { } return true; } + bool CXFA_LocaleValue::SetTime(const CFX_WideString& wsTime, const CFX_WideString& wsFormat, IFX_Locale* pLocale) { m_dwType = XFA_VT_TIME; return m_bValid = ParsePatternValue(wsTime, wsFormat, pLocale); } -bool CXFA_LocaleValue::SetDateTime(const CFX_Unitime& dt) { + +bool CXFA_LocaleValue::SetDateTime(const CFX_DateTime& dt) { m_dwType = XFA_VT_DATETIME; m_wsValue.Format(L"%04d-%02d-%02dT%02d:%02d:%02d", dt.GetYear(), dt.GetMonth(), dt.GetDay(), dt.GetHour(), dt.GetMinute(), @@ -455,6 +452,7 @@ bool CXFA_LocaleValue::SetDateTime(const CFX_Unitime& dt) { } return true; } + bool CXFA_LocaleValue::SetDateTime(const CFX_WideString& wsDateTime, const CFX_WideString& wsFormat, IFX_Locale* pLocale) { @@ -466,7 +464,7 @@ bool CXFA_LocaleValue::FormatPatterns(CFX_WideString& wsResult, const CFX_WideString& wsFormat, IFX_Locale* pLocale, XFA_VALUEPICTURE eValueType) const { - auto pFormat = pdfium::MakeUnique<CFX_FormatString>(m_pLocaleMgr, false); + auto pFormat = pdfium::MakeUnique<CFGAS_FormatString>(m_pLocaleMgr); std::vector<CFX_WideString> wsPatterns; pFormat->SplitFormatString(wsFormat, wsPatterns); wsResult.clear(); @@ -488,7 +486,7 @@ bool CXFA_LocaleValue::FormatSinglePattern(CFX_WideString& wsResult, wsResult.clear(); bool bRet = false; - auto pFormat = pdfium::MakeUnique<CFX_FormatString>(m_pLocaleMgr, false); + auto pFormat = pdfium::MakeUnique<CFGAS_FormatString>(m_pLocaleMgr); FX_LOCALECATEGORY eCategory = pFormat->GetCategory(wsFormat); eCategory = XFA_ValugeCategory(eCategory, m_dwType); switch (eCategory) { @@ -559,23 +557,23 @@ bool CXFA_LocaleValue::ValidateCanonicalValue(const CFX_WideString& wsValue, if (wsValue.IsEmpty()) { return true; } - CFX_Unitime dt; + CFX_DateTime dt; switch (dwVType) { case XFA_VT_DATE: { - if (ValidateCanonicalDate(wsValue, dt)) { + if (ValidateCanonicalDate(wsValue, &dt)) return true; - } + CFX_WideString wsDate, wsTime; if (XFA_ValueSplitDateTime(wsValue, wsDate, wsTime) && - ValidateCanonicalDate(wsDate, dt)) { + ValidateCanonicalDate(wsDate, &dt)) { return true; } return false; } case XFA_VT_TIME: { - if (ValidateCanonicalTime(wsValue)) { + if (ValidateCanonicalTime(wsValue)) return true; - } + CFX_WideString wsDate, wsTime; if (XFA_ValueSplitDateTime(wsValue, wsDate, wsTime) && ValidateCanonicalTime(wsTime)) { @@ -586,7 +584,7 @@ bool CXFA_LocaleValue::ValidateCanonicalValue(const CFX_WideString& wsValue, case XFA_VT_DATETIME: { CFX_WideString wsDate, wsTime; if (XFA_ValueSplitDateTime(wsValue, wsDate, wsTime) && - ValidateCanonicalDate(wsDate, dt) && ValidateCanonicalTime(wsTime)) { + ValidateCanonicalDate(wsDate, &dt) && ValidateCanonicalTime(wsTime)) { return true; } } break; @@ -594,7 +592,7 @@ bool CXFA_LocaleValue::ValidateCanonicalValue(const CFX_WideString& wsValue, return true; } bool CXFA_LocaleValue::ValidateCanonicalDate(const CFX_WideString& wsDate, - CFX_Unitime& unDate) { + CFX_DateTime* unDate) { const uint16_t LastDay[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; const uint16_t wCountY = 4, wCountM = 2, wCountD = 2; int nLen = wsDate.GetLength(); @@ -605,7 +603,7 @@ bool CXFA_LocaleValue::ValidateCanonicalDate(const CFX_WideString& wsDate, uint16_t wYear = 0; uint16_t wMonth = 0; uint16_t wDay = 0; - const FX_WCHAR* pDate = wsDate.c_str(); + const wchar_t* pDate = wsDate.c_str(); int nIndex = 0, nStart = 0; while (pDate[nIndex] != '\0' && nIndex < wCountY) { if (!FXSYS_isDecimalDigit(pDate[nIndex])) { @@ -673,11 +671,12 @@ bool CXFA_LocaleValue::ValidateCanonicalDate(const CFX_WideString& wsDate, } else if (wDay > LastDay[wMonth - 1]) { return false; } - CFX_Unitime ut; - ut.Set(wYear, static_cast<uint8_t>(wMonth), static_cast<uint8_t>(wDay)); - unDate = unDate + ut; + + unDate->SetDate(wYear, static_cast<uint8_t>(wMonth), + static_cast<uint8_t>(wDay)); return true; } + bool CXFA_LocaleValue::ValidateCanonicalTime(const CFX_WideString& wsTime) { int nLen = wsTime.GetLength(); if (nLen < 2) @@ -691,7 +690,7 @@ bool CXFA_LocaleValue::ValidateCanonicalTime(const CFX_WideString& wsTime) { uint16_t wMinute = 0; uint16_t wSecond = 0; uint16_t wFraction = 0; - const FX_WCHAR* pTime = wsTime.c_str(); + const wchar_t* pTime = wsTime.c_str(); int nIndex = 0; int nStart = 0; while (nIndex - nStart < wCountH && pTime[nIndex]) { @@ -769,25 +768,26 @@ bool CXFA_LocaleValue::ValidateCanonicalTime(const CFX_WideString& wsTime) { return nIndex == nLen && wHour < 24 && wMinute < 60 && wSecond < 60 && wFraction <= 999; } + bool CXFA_LocaleValue::ValidateCanonicalDateTime( const CFX_WideString& wsDateTime) { CFX_WideString wsDate, wsTime; - if (wsDateTime.IsEmpty()) { + if (wsDateTime.IsEmpty()) return false; - } + int nSplitIndex = -1; nSplitIndex = wsDateTime.Find('T'); - if (nSplitIndex < 0) { + if (nSplitIndex < 0) nSplitIndex = wsDateTime.Find(' '); - } - if (nSplitIndex < 0) { + if (nSplitIndex < 0) return false; - } + wsDate = wsDateTime.Left(nSplitIndex); wsTime = wsDateTime.Right(wsDateTime.GetLength() - nSplitIndex - 1); - CFX_Unitime dt; - return ValidateCanonicalDate(wsDate, dt) && ValidateCanonicalTime(wsTime); + CFX_DateTime dt; + return ValidateCanonicalDate(wsDate, &dt) && ValidateCanonicalTime(wsTime); } + bool CXFA_LocaleValue::ParsePatternValue(const CFX_WideString& wsValue, const CFX_WideString& wsPattern, IFX_Locale* pLocale) { @@ -795,7 +795,7 @@ bool CXFA_LocaleValue::ParsePatternValue(const CFX_WideString& wsValue, if (pLocale) m_pLocaleMgr->SetDefLocale(pLocale); - auto pFormat = pdfium::MakeUnique<CFX_FormatString>(m_pLocaleMgr, false); + auto pFormat = pdfium::MakeUnique<CFGAS_FormatString>(m_pLocaleMgr); std::vector<CFX_WideString> wsPatterns; pFormat->SplitFormatString(wsPattern, wsPatterns); bool bRet = false; @@ -828,33 +828,30 @@ bool CXFA_LocaleValue::ParsePatternValue(const CFX_WideString& wsValue, bRet = pFormat->ParseText(wsValue, wsFormat, m_wsValue); break; case FX_LOCALECATEGORY_Date: { - CFX_Unitime dt; - bRet = ValidateCanonicalDate(wsValue, dt); + CFX_DateTime dt; + bRet = ValidateCanonicalDate(wsValue, &dt); if (!bRet) { bRet = pFormat->ParseDateTime(wsValue, wsFormat, FX_DATETIMETYPE_Date, - dt); + &dt); } - if (bRet) { + if (bRet) SetDate(dt); - } break; } case FX_LOCALECATEGORY_Time: { - CFX_Unitime dt; - bRet = - pFormat->ParseDateTime(wsValue, wsFormat, FX_DATETIMETYPE_Time, dt); - if (bRet) { + CFX_DateTime dt; + bRet = pFormat->ParseDateTime(wsValue, wsFormat, FX_DATETIMETYPE_Time, + &dt); + if (bRet) SetTime(dt); - } break; } case FX_LOCALECATEGORY_DateTime: { - CFX_Unitime dt; + CFX_DateTime dt; bRet = pFormat->ParseDateTime(wsValue, wsFormat, - FX_DATETIMETYPE_DateTime, dt); - if (bRet) { + FX_DATETIMETYPE_DateTime, &dt); + if (bRet) SetDateTime(dt); - } break; } default: @@ -880,7 +877,7 @@ void CXFA_LocaleValue::GetNumbericFormat(CFX_WideString& wsFormat, ASSERT(nIntLen >= -1 && nDecLen >= -1); int32_t nTotalLen = (nIntLen >= 0 ? nIntLen : 2) + (bSign ? 1 : 0) + (nDecLen >= 0 ? nDecLen : 2) + (nDecLen == 0 ? 0 : 1); - FX_WCHAR* lpBuf = wsFormat.GetBuffer(nTotalLen); + wchar_t* lpBuf = wsFormat.GetBuffer(nTotalLen); int32_t nPos = 0; if (bSign) { lpBuf[nPos++] = L's'; @@ -915,11 +912,11 @@ bool CXFA_LocaleValue::ValidateNumericTemp(CFX_WideString& wsNumeric, if (wsFormat.IsEmpty() || wsNumeric.IsEmpty()) { return true; } - const FX_WCHAR* pNum = wsNumeric.c_str(); - const FX_WCHAR* pFmt = wsFormat.c_str(); + const wchar_t* pNum = wsNumeric.c_str(); + const wchar_t* pFmt = wsFormat.c_str(); int32_t n = 0, nf = 0; - FX_WCHAR c = pNum[n]; - FX_WCHAR cf = pFmt[nf]; + wchar_t c = pNum[n]; + wchar_t cf = pFmt[nf]; if (cf == L's') { if (c == L'-' || c == L'+') { ++n; @@ -942,28 +939,26 @@ bool CXFA_LocaleValue::ValidateNumericTemp(CFX_WideString& wsNumeric, } n++; } - if (n == nCount) { + if (n == nCount) return true; - } - if (nf == nCountFmt) { + if (nf == nCountFmt) return false; - } + while (nf < nCountFmt && (cf = pFmt[nf]) != L'.') { ASSERT(cf == L'z' || cf == L'*'); ++nf; } CFX_WideString wsDecimalSymbol; - if (pLocale) { - pLocale->GetNumbericSymbol(FX_LOCALENUMSYMBOL_Decimal, wsDecimalSymbol); - } else { + if (pLocale) + wsDecimalSymbol = pLocale->GetNumbericSymbol(FX_LOCALENUMSYMBOL_Decimal); + else wsDecimalSymbol = CFX_WideString(L'.'); - } - if (pFmt[nf] != L'.') { + + if (pFmt[nf] != L'.') return false; - } - if (wsDecimalSymbol != CFX_WideStringC(c) && c != L'.') { + if (wsDecimalSymbol != CFX_WideStringC(c) && c != L'.') return false; - } + ++nf; ++n; bLimit = true; diff --git a/chromium/third_party/pdfium/xfa/fxfa/parser/xfa_localevalue.h b/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_localevalue.h index dbc3513a3f3..cb30d377922 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/parser/xfa_localevalue.h +++ b/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_localevalue.h @@ -4,15 +4,15 @@ // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com -#ifndef XFA_FXFA_PARSER_XFA_LOCALEVALUE_H_ -#define XFA_FXFA_PARSER_XFA_LOCALEVALUE_H_ +#ifndef XFA_FXFA_PARSER_CXFA_LOCALEVALUE_H_ +#define XFA_FXFA_PARSER_CXFA_LOCALEVALUE_H_ #include "core/fxcrt/fx_string.h" #include "core/fxcrt/fx_system.h" #include "xfa/fxfa/parser/cxfa_widgetdata.h" class IFX_Locale; -class CFX_Unitime; +class CFX_DateTime; class CXFA_LocaleMgr; #define XFA_VT_NULL 0 @@ -54,7 +54,8 @@ class CXFA_LocaleValue { IFX_Locale* pLocale, XFA_VALUEPICTURE eValueType) const; bool ValidateCanonicalValue(const CFX_WideString& wsValue, uint32_t dwVType); - bool ValidateCanonicalDate(const CFX_WideString& wsDate, CFX_Unitime& unDate); + bool ValidateCanonicalDate(const CFX_WideString& wsDate, + CFX_DateTime* unDate); bool ValidateCanonicalTime(const CFX_WideString& wsTime); bool ValidateCanonicalDateTime(const CFX_WideString& wsDateTime); void GetNumbericFormat(CFX_WideString& wsFormat, @@ -70,28 +71,28 @@ class CXFA_LocaleValue { uint32_t GetType() const; void SetValue(const CFX_WideString& wsValue, uint32_t dwType); CFX_WideString GetText() const; - FX_FLOAT GetNum() const; - FX_DOUBLE GetDoubleNum() const; - CFX_Unitime GetDate() const; - CFX_Unitime GetTime() const; - CFX_Unitime GetDateTime() const; + float GetNum() const; + double GetDoubleNum() const; + CFX_DateTime GetDate() const; + CFX_DateTime GetTime() const; + CFX_DateTime GetDateTime() const; bool SetText(const CFX_WideString& wsText); bool SetText(const CFX_WideString& wsText, const CFX_WideString& wsFormat, IFX_Locale* pLocale); - bool SetNum(FX_FLOAT fNum); + bool SetNum(float fNum); bool SetNum(const CFX_WideString& wsNum, const CFX_WideString& wsFormat, IFX_Locale* pLocale); - bool SetDate(const CFX_Unitime& d); + bool SetDate(const CFX_DateTime& d); bool SetDate(const CFX_WideString& wsDate, const CFX_WideString& wsFormat, IFX_Locale* pLocale); - bool SetTime(const CFX_Unitime& t); + bool SetTime(const CFX_DateTime& t); bool SetTime(const CFX_WideString& wsTime, const CFX_WideString& wsFormat, IFX_Locale* pLocale); - bool SetDateTime(const CFX_Unitime& dt); + bool SetDateTime(const CFX_DateTime& dt); bool SetDateTime(const CFX_WideString& wsDateTime, const CFX_WideString& wsFormat, IFX_Locale* pLocale); @@ -99,7 +100,7 @@ class CXFA_LocaleValue { bool IsEmpty() const { return m_wsValue.IsEmpty(); } bool IsValid() const { return m_bValid; } - protected: + private: bool ParsePatternValue(const CFX_WideString& wsValue, const CFX_WideString& wsPattern, IFX_Locale* pLocale); @@ -109,4 +110,4 @@ class CXFA_LocaleValue { bool m_bValid; }; -#endif // XFA_FXFA_PARSER_XFA_LOCALEVALUE_H_ +#endif // XFA_FXFA_PARSER_CXFA_LOCALEVALUE_H_ diff --git a/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_margin.cpp b/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_margin.cpp index 38f9626a882..e3153f26715 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_margin.cpp +++ b/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_margin.cpp @@ -6,26 +6,24 @@ #include "xfa/fxfa/parser/cxfa_margin.h" -#include "xfa/fxfa/parser/xfa_object.h" - CXFA_Margin::CXFA_Margin(CXFA_Node* pNode) : CXFA_Data(pNode) {} -bool CXFA_Margin::GetLeftInset(FX_FLOAT& fInset, FX_FLOAT fDefInset) const { +bool CXFA_Margin::GetLeftInset(float& fInset, float fDefInset) const { fInset = fDefInset; return TryMeasure(XFA_ATTRIBUTE_LeftInset, fInset); } -bool CXFA_Margin::GetTopInset(FX_FLOAT& fInset, FX_FLOAT fDefInset) const { +bool CXFA_Margin::GetTopInset(float& fInset, float fDefInset) const { fInset = fDefInset; return TryMeasure(XFA_ATTRIBUTE_TopInset, fInset); } -bool CXFA_Margin::GetRightInset(FX_FLOAT& fInset, FX_FLOAT fDefInset) const { +bool CXFA_Margin::GetRightInset(float& fInset, float fDefInset) const { fInset = fDefInset; return TryMeasure(XFA_ATTRIBUTE_RightInset, fInset); } -bool CXFA_Margin::GetBottomInset(FX_FLOAT& fInset, FX_FLOAT fDefInset) const { +bool CXFA_Margin::GetBottomInset(float& fInset, float fDefInset) const { fInset = fDefInset; return TryMeasure(XFA_ATTRIBUTE_BottomInset, fInset); } diff --git a/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_margin.h b/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_margin.h index d1c19551945..89fc4ce38a6 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_margin.h +++ b/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_margin.h @@ -16,10 +16,10 @@ class CXFA_Margin : public CXFA_Data { public: explicit CXFA_Margin(CXFA_Node* pNode); - bool GetLeftInset(FX_FLOAT& fInset, FX_FLOAT fDefInset = 0) const; - bool GetTopInset(FX_FLOAT& fInset, FX_FLOAT fDefInset = 0) const; - bool GetRightInset(FX_FLOAT& fInset, FX_FLOAT fDefInset = 0) const; - bool GetBottomInset(FX_FLOAT& fInset, FX_FLOAT fDefInset = 0) const; + bool GetLeftInset(float& fInset, float fDefInset = 0) const; + bool GetTopInset(float& fInset, float fDefInset = 0) const; + bool GetRightInset(float& fInset, float fDefInset = 0) const; + bool GetBottomInset(float& fInset, float fDefInset = 0) const; }; #endif // XFA_FXFA_PARSER_CXFA_MARGIN_H_ diff --git a/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_measurement.cpp b/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_measurement.cpp index ebf7b7bff74..fd00c42d340 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_measurement.cpp +++ b/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_measurement.cpp @@ -16,7 +16,7 @@ CXFA_Measurement::CXFA_Measurement() { Set(-1, XFA_UNIT_Unknown); } -CXFA_Measurement::CXFA_Measurement(FX_FLOAT fValue, XFA_UNIT eUnit) { +CXFA_Measurement::CXFA_Measurement(float fValue, XFA_UNIT eUnit) { Set(fValue, eUnit); } @@ -28,8 +28,8 @@ void CXFA_Measurement::Set(const CFX_WideStringC& wsMeasure) { } int32_t iUsedLen = 0; int32_t iOffset = (wsMeasure.GetAt(0) == L'=') ? 1 : 0; - FX_FLOAT fValue = FXSYS_wcstof(wsMeasure.c_str() + iOffset, - wsMeasure.GetLength() - iOffset, &iUsedLen); + float fValue = FXSYS_wcstof(wsMeasure.c_str() + iOffset, + wsMeasure.GetLength() - iOffset, &iUsedLen); XFA_UNIT eUnit = GetUnit(wsMeasure.Mid(iOffset + iUsedLen)); Set(fValue, eUnit); } @@ -66,7 +66,7 @@ bool CXFA_Measurement::ToString(CFX_WideString& wsMeasure) const { } } -bool CXFA_Measurement::ToUnit(XFA_UNIT eUnit, FX_FLOAT& fValue) const { +bool CXFA_Measurement::ToUnit(XFA_UNIT eUnit, float& fValue) const { fValue = GetValue(); XFA_UNIT eFrom = GetUnit(); if (eFrom == eUnit) diff --git a/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_measurement.h b/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_measurement.h index 40f71a7fab7..34cf780f817 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_measurement.h +++ b/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_measurement.h @@ -15,27 +15,27 @@ class CXFA_Measurement { public: explicit CXFA_Measurement(const CFX_WideStringC& wsMeasure); CXFA_Measurement(); - CXFA_Measurement(FX_FLOAT fValue, XFA_UNIT eUnit); + CXFA_Measurement(float fValue, XFA_UNIT eUnit); void Set(const CFX_WideStringC& wsMeasure); - void Set(FX_FLOAT fValue, XFA_UNIT eUnit) { + void Set(float fValue, XFA_UNIT eUnit) { m_fValue = fValue; m_eUnit = eUnit; } XFA_UNIT GetUnit(const CFX_WideStringC& wsUnit); XFA_UNIT GetUnit() const { return m_eUnit; } - FX_FLOAT GetValue() const { return m_fValue; } + float GetValue() const { return m_fValue; } bool ToString(CFX_WideString& wsMeasure) const; - bool ToUnit(XFA_UNIT eUnit, FX_FLOAT& fValue) const; - FX_FLOAT ToUnit(XFA_UNIT eUnit) const { - FX_FLOAT f; + bool ToUnit(XFA_UNIT eUnit, float& fValue) const; + float ToUnit(XFA_UNIT eUnit) const { + float f; return ToUnit(eUnit, f) ? f : 0; } private: - FX_FLOAT m_fValue; + float m_fValue; XFA_UNIT m_eUnit; }; diff --git a/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_node.cpp b/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_node.cpp index 1e508969d1a..5f582458dee 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_node.cpp +++ b/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_node.cpp @@ -4,27 +4,35 @@ // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com -#include "xfa/fxfa/parser/xfa_object.h" +#include "xfa/fxfa/parser/cxfa_node.h" #include <map> #include <memory> +#include <unordered_set> #include <utility> #include <vector> +#include "core/fxcrt/cfx_decimal.h" #include "core/fxcrt/fx_ext.h" #include "fxjs/cfxjse_value.h" #include "third_party/base/ptr_util.h" #include "third_party/base/stl_util.h" -#include "xfa/fde/xml/fde_xml_imp.h" +#include "xfa/fde/xml/cfde_xmlelement.h" +#include "xfa/fde/xml/cfde_xmlnode.h" +#include "xfa/fde/xml/cfde_xmltext.h" #include "xfa/fgas/crt/fgas_codepage.h" #include "xfa/fxfa/app/xfa_ffnotify.h" #include "xfa/fxfa/cxfa_eventparam.h" +#include "xfa/fxfa/cxfa_ffwidget.h" +#include "xfa/fxfa/parser/cxfa_arraynodelist.h" +#include "xfa/fxfa/parser/cxfa_attachnodelist.h" #include "xfa/fxfa/parser/cxfa_document.h" #include "xfa/fxfa/parser/cxfa_layoutprocessor.h" #include "xfa/fxfa/parser/cxfa_measurement.h" #include "xfa/fxfa/parser/cxfa_occur.h" #include "xfa/fxfa/parser/cxfa_scriptcontext.h" #include "xfa/fxfa/parser/cxfa_simple_parser.h" +#include "xfa/fxfa/parser/cxfa_traversestrategy_xfacontainernode.h" #include "xfa/fxfa/parser/xfa_basic_data.h" namespace { @@ -44,7 +52,7 @@ XFA_MAPDATABLOCKCALLBACKINFO deleteWideStringCallBack = {XFA_DeleteWideString, XFA_CopyWideString}; void XFA_DataNodeDeleteBindItem(void* pData) { - delete static_cast<CXFA_NodeArray*>(pData); + delete static_cast<std::vector<CXFA_Node*>*>(pData); } XFA_MAPDATABLOCKCALLBACKINFO deleteBindItemCallBack = { @@ -80,32 +88,24 @@ int32_t GetCount(CXFA_Node* pInstMgrNode) { return iCount; } -void SortNodeArrayByDocumentIdx(const CXFA_NodeSet& rgNodeSet, - CXFA_NodeArray& rgNodeArray, - CFX_ArrayTemplate<int32_t>& rgIdxArray) { - int32_t iCount = pdfium::CollectionSize<int32_t>(rgNodeSet); - rgNodeArray.SetSize(iCount); - rgIdxArray.SetSize(iCount); - if (iCount == 0) - return; +std::vector<CXFA_Node*> NodesSortedByDocumentIdx( + const std::unordered_set<CXFA_Node*>& rgNodeSet) { + if (rgNodeSet.empty()) + return std::vector<CXFA_Node*>(); - int32_t iIndex = -1; - int32_t iTotalIndex = -1; + std::vector<CXFA_Node*> rgNodeArray; CXFA_Node* pCommonParent = (*rgNodeSet.begin())->GetNodeItem(XFA_NODEITEM_Parent); for (CXFA_Node* pNode = pCommonParent->GetNodeItem(XFA_NODEITEM_FirstChild); - pNode && iIndex < iCount; - pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) { - iTotalIndex++; - if (pdfium::ContainsValue(rgNodeSet, pNode)) { - iIndex++; - rgNodeArray[iIndex] = pNode; - rgIdxArray[iIndex] = iTotalIndex; - } + pNode; pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) { + if (pdfium::ContainsValue(rgNodeSet, pNode)) + rgNodeArray.push_back(pNode); } + return rgNodeArray; } -using CXFA_NodeSetPair = std::pair<CXFA_NodeSet, CXFA_NodeSet>; +using CXFA_NodeSetPair = + std::pair<std::unordered_set<CXFA_Node*>, std::unordered_set<CXFA_Node*>>; using CXFA_NodeSetPairMap = std::map<uint32_t, std::unique_ptr<CXFA_NodeSetPair>>; using CXFA_NodeSetPairMapMap = @@ -128,8 +128,8 @@ CXFA_NodeSetPair* NodeSetPairForNode(CXFA_Node* pNode, return (*pNodeSetPairMap)[dwNameHash].get(); } -void ReorderDataNodes(const CXFA_NodeSet& sSet1, - const CXFA_NodeSet& sSet2, +void ReorderDataNodes(const std::unordered_set<CXFA_Node*>& sSet1, + const std::unordered_set<CXFA_Node*>& sSet2, bool bInsertBefore) { CXFA_NodeSetPairMapMap rgMap; for (CXFA_Node* pNode : sSet1) { @@ -156,26 +156,21 @@ void ReorderDataNodes(const CXFA_NodeSet& sSet1, if (!pNodeSetPair) continue; if (!pNodeSetPair->first.empty() && !pNodeSetPair->second.empty()) { - CXFA_NodeArray rgNodeArray1; - CXFA_NodeArray rgNodeArray2; - CFX_ArrayTemplate<int32_t> rgIdxArray1; - CFX_ArrayTemplate<int32_t> rgIdxArray2; - SortNodeArrayByDocumentIdx(pNodeSetPair->first, rgNodeArray1, - rgIdxArray1); - SortNodeArrayByDocumentIdx(pNodeSetPair->second, rgNodeArray2, - rgIdxArray2); + std::vector<CXFA_Node*> rgNodeArray1 = + NodesSortedByDocumentIdx(pNodeSetPair->first); + std::vector<CXFA_Node*> rgNodeArray2 = + NodesSortedByDocumentIdx(pNodeSetPair->second); CXFA_Node* pParentNode = nullptr; CXFA_Node* pBeforeNode = nullptr; if (bInsertBefore) { - pBeforeNode = rgNodeArray2[0]; + pBeforeNode = rgNodeArray2.front(); pParentNode = pBeforeNode->GetNodeItem(XFA_NODEITEM_Parent); } else { - CXFA_Node* pLastNode = rgNodeArray2[rgIdxArray2.GetSize() - 1]; + CXFA_Node* pLastNode = rgNodeArray2.back(); pParentNode = pLastNode->GetNodeItem(XFA_NODEITEM_Parent); pBeforeNode = pLastNode->GetNodeItem(XFA_NODEITEM_NextSibling); } - for (int32_t iIdx = 0; iIdx < rgIdxArray1.GetSize(); iIdx++) { - CXFA_Node* pCurNode = rgNodeArray1[iIdx]; + for (auto* pCurNode : rgNodeArray1) { pParentNode->RemoveChild(pCurNode); pParentNode->InsertChild(pCurNode, pBeforeNode); } @@ -235,8 +230,8 @@ void InsertItem(CXFA_Node* pInstMgrNode, pInstMgrNode->GetNodeItem(XFA_NODEITEM_Parent) ->InsertChild(pNewInstance, pNextSibling); if (bMoveDataBindingNodes) { - CXFA_NodeSet sNew; - CXFA_NodeSet sAfter; + std::unordered_set<CXFA_Node*> sNew; + std::unordered_set<CXFA_Node*> sAfter; CXFA_NodeIteratorTemplate<CXFA_Node, CXFA_TraverseStrategy_XFAContainerNode> sIteratorNew(pNewInstance); @@ -266,8 +261,8 @@ void InsertItem(CXFA_Node* pInstMgrNode, pInstMgrNode->GetNodeItem(XFA_NODEITEM_Parent) ->InsertChild(pNewInstance, pBeforeInstance); if (bMoveDataBindingNodes) { - CXFA_NodeSet sNew; - CXFA_NodeSet sBefore; + std::unordered_set<CXFA_Node*> sNew; + std::unordered_set<CXFA_Node*> sBefore; CXFA_NodeIteratorTemplate<CXFA_Node, CXFA_TraverseStrategy_XFAContainerNode> sIteratorNew(pNewInstance); @@ -348,7 +343,7 @@ CXFA_Node* CreateInstance(CXFA_Node* pInstMgrNode, bool bDataMerge) { struct XFA_ExecEventParaInfo { public: uint32_t m_uHash; - const FX_WCHAR* m_lpcEventName; + const wchar_t* m_lpcEventName; XFA_EVENTTYPE m_eventType; uint32_t m_validFlags; }; @@ -406,11 +401,11 @@ void StrToRGB(const CFX_WideString& strRGB, g = 0; b = 0; - FX_WCHAR zero = '0'; + wchar_t zero = '0'; int32_t iIndex = 0; int32_t iLen = strRGB.GetLength(); for (int32_t i = 0; i < iLen; ++i) { - FX_WCHAR ch = strRGB.GetAt(i); + wchar_t ch = strRGB.GetAt(i); if (ch == L',') ++iIndex; if (iIndex > 2) @@ -522,22 +517,21 @@ CXFA_Node* CXFA_Node::Clone(bool bRecursive) { MergeAllData(pClone); pClone->UpdateNameHash(); if (IsNeedSavingXMLNode()) { - CFDE_XMLNode* pCloneXML = nullptr; + std::unique_ptr<CFDE_XMLNode> pCloneXML; if (IsAttributeInXML()) { CFX_WideString wsName; GetAttribute(XFA_ATTRIBUTE_Name, wsName, false); - CFDE_XMLElement* pCloneXMLElement = new CFDE_XMLElement(wsName); + auto pCloneXMLElement = pdfium::MakeUnique<CFDE_XMLElement>(wsName); CFX_WideStringC wsValue = GetCData(XFA_ATTRIBUTE_Value); if (!wsValue.IsEmpty()) { pCloneXMLElement->SetTextData(CFX_WideString(wsValue)); } - pCloneXML = pCloneXMLElement; - pCloneXMLElement = nullptr; + pCloneXML.reset(pCloneXMLElement.release()); pClone->SetEnum(XFA_ATTRIBUTE_Contains, XFA_ATTRIBUTEENUM_Unknown); } else { - pCloneXML = m_pXMLNode->Clone(false); + pCloneXML = m_pXMLNode->Clone(); } - pClone->SetXMLMappingNode(pCloneXML); + pClone->SetXMLMappingNode(pCloneXML.release()); pClone->SetFlag(XFA_NodeFlag_OwnXMLNode, false); } if (bRecursive) { @@ -612,34 +606,18 @@ CXFA_Node* CXFA_Node::GetNodeItem(XFA_NODEITEM eItem, return pNode; } -int32_t CXFA_Node::GetNodeList(CXFA_NodeArray& nodes, - uint32_t dwTypeFilter, - XFA_Element eTypeFilter, - int32_t iLevel) { - if (--iLevel < 0) { - return nodes.GetSize(); - } +std::vector<CXFA_Node*> CXFA_Node::GetNodeList(uint32_t dwTypeFilter, + XFA_Element eTypeFilter) { + std::vector<CXFA_Node*> nodes; if (eTypeFilter != XFA_Element::Unknown) { - CXFA_Node* pChild = m_pChild; - while (pChild) { - if (pChild->GetElementType() == eTypeFilter) { - nodes.Add(pChild); - if (iLevel > 0) { - GetNodeList(nodes, dwTypeFilter, eTypeFilter, iLevel); - } - } - pChild = pChild->m_pNext; + for (CXFA_Node* pChild = m_pChild; pChild; pChild = pChild->m_pNext) { + if (pChild->GetElementType() == eTypeFilter) + nodes.push_back(pChild); } } else if (dwTypeFilter == (XFA_NODEFILTER_Children | XFA_NODEFILTER_Properties)) { - CXFA_Node* pChild = m_pChild; - while (pChild) { - nodes.Add(pChild); - if (iLevel > 0) { - GetNodeList(nodes, dwTypeFilter, eTypeFilter, iLevel); - } - pChild = pChild->m_pNext; - } + for (CXFA_Node* pChild = m_pChild; pChild; pChild = pChild->m_pNext) + nodes.push_back(pChild); } else if (dwTypeFilter != 0) { bool bFilterChildren = !!(dwTypeFilter & XFA_NODEFILTER_Children); bool bFilterProperties = !!(dwTypeFilter & XFA_NODEFILTER_Properties); @@ -651,26 +629,26 @@ int32_t CXFA_Node::GetNodeList(CXFA_NodeArray& nodes, GetElementType(), pChild->GetElementType(), XFA_XDPPACKET_UNKNOWN); if (pProperty) { if (bFilterProperties) { - nodes.Add(pChild); + nodes.push_back(pChild); } else if (bFilterOneOfProperties && (pProperty->uFlags & XFA_PROPERTYFLAG_OneOf)) { - nodes.Add(pChild); + nodes.push_back(pChild); } else if (bFilterChildren && (pChild->GetElementType() == XFA_Element::Variables || pChild->GetElementType() == XFA_Element::PageSet)) { - nodes.Add(pChild); + nodes.push_back(pChild); } } else if (bFilterChildren) { - nodes.Add(pChild); + nodes.push_back(pChild); } pChild = pChild->m_pNext; } - if (bFilterOneOfProperties && nodes.GetSize() < 1) { + if (bFilterOneOfProperties && nodes.empty()) { int32_t iProperties = 0; const XFA_PROPERTY* pProperty = XFA_GetElementProperties(GetElementType(), iProperties); if (!pProperty || iProperties < 1) - return 0; + return nodes; for (int32_t i = 0; i < iProperties; i++) { if (pProperty[i].uFlags & XFA_PROPERTYFLAG_DefaultOneOf) { const XFA_PACKETINFO* pPacket = XFA_GetPacketByID(GetPacketID()); @@ -680,13 +658,13 @@ int32_t CXFA_Node::GetNodeList(CXFA_NodeArray& nodes, break; InsertChild(pNewNode, nullptr); pNewNode->SetFlag(XFA_NodeFlag_Initialized, true); - nodes.Add(pNewNode); + nodes.push_back(pNewNode); break; } } } } - return nodes.GetSize(); + return nodes; } CXFA_Node* CXFA_Node::CreateSamePacketNode(XFA_Element eType, @@ -729,74 +707,72 @@ CXFA_Node* CXFA_Node::GetBindData() { return static_cast<CXFA_Node*>(GetObject(XFA_ATTRIBUTE_BindingNode)); } -int32_t CXFA_Node::GetBindItems(CXFA_NodeArray& formItems) { +std::vector<CXFA_Node*> CXFA_Node::GetBindItems() { if (BindsFormItems()) { - CXFA_NodeArray* pItems = nullptr; - TryObject(XFA_ATTRIBUTE_BindingNode, (void*&)pItems); - formItems.Copy(*pItems); - return formItems.GetSize(); + void* pBinding = nullptr; + TryObject(XFA_ATTRIBUTE_BindingNode, pBinding); + return *static_cast<std::vector<CXFA_Node*>*>(pBinding); } + std::vector<CXFA_Node*> result; CXFA_Node* pFormNode = static_cast<CXFA_Node*>(GetObject(XFA_ATTRIBUTE_BindingNode)); if (pFormNode) - formItems.Add(pFormNode); - return formItems.GetSize(); + result.push_back(pFormNode); + return result; } int32_t CXFA_Node::AddBindItem(CXFA_Node* pFormNode) { ASSERT(pFormNode); if (BindsFormItems()) { - CXFA_NodeArray* pItems = nullptr; - TryObject(XFA_ATTRIBUTE_BindingNode, (void*&)pItems); - ASSERT(pItems); - if (pItems->Find(pFormNode) < 0) { - pItems->Add(pFormNode); - } - return pItems->GetSize(); + void* pBinding = nullptr; + TryObject(XFA_ATTRIBUTE_BindingNode, pBinding); + auto* pItems = static_cast<std::vector<CXFA_Node*>*>(pBinding); + if (!pdfium::ContainsValue(*pItems, pFormNode)) + pItems->push_back(pFormNode); + return pdfium::CollectionSize<int32_t>(*pItems); } CXFA_Node* pOldFormItem = static_cast<CXFA_Node*>(GetObject(XFA_ATTRIBUTE_BindingNode)); if (!pOldFormItem) { SetObject(XFA_ATTRIBUTE_BindingNode, pFormNode); return 1; - } else if (pOldFormItem == pFormNode) { - return 1; } - CXFA_NodeArray* pItems = new CXFA_NodeArray; + if (pOldFormItem == pFormNode) + return 1; + + std::vector<CXFA_Node*>* pItems = new std::vector<CXFA_Node*>; SetObject(XFA_ATTRIBUTE_BindingNode, pItems, &deleteBindItemCallBack); - pItems->Add(pOldFormItem); - pItems->Add(pFormNode); + pItems->push_back(pOldFormItem); + pItems->push_back(pFormNode); m_uNodeFlags |= XFA_NodeFlag_BindFormItems; return 2; } int32_t CXFA_Node::RemoveBindItem(CXFA_Node* pFormNode) { if (BindsFormItems()) { - CXFA_NodeArray* pItems = nullptr; - TryObject(XFA_ATTRIBUTE_BindingNode, (void*&)pItems); - ASSERT(pItems); - int32_t iIndex = pItems->Find(pFormNode); - int32_t iCount = pItems->GetSize(); - if (iIndex >= 0) { - if (iIndex != iCount - 1) - pItems->SetAt(iIndex, pItems->GetAt(iCount - 1)); - pItems->RemoveAt(iCount - 1); - if (iCount == 2) { - CXFA_Node* pLastFormNode = pItems->GetAt(0); - SetObject(XFA_ATTRIBUTE_BindingNode, pLastFormNode); + void* pBinding = nullptr; + TryObject(XFA_ATTRIBUTE_BindingNode, pBinding); + auto* pItems = static_cast<std::vector<CXFA_Node*>*>(pBinding); + auto iter = std::find(pItems->begin(), pItems->end(), pFormNode); + if (iter != pItems->end()) { + *iter = pItems->back(); + pItems->pop_back(); + if (pItems->size() == 1) { + SetObject(XFA_ATTRIBUTE_BindingNode, + (*pItems)[0]); // Invalidates pItems. m_uNodeFlags &= ~XFA_NodeFlag_BindFormItems; + return 1; } - iCount--; } - return iCount; + return pdfium::CollectionSize<int32_t>(*pItems); } CXFA_Node* pOldFormItem = static_cast<CXFA_Node*>(GetObject(XFA_ATTRIBUTE_BindingNode)); - if (pOldFormItem == pFormNode) { - SetObject(XFA_ATTRIBUTE_BindingNode, nullptr); - pOldFormItem = nullptr; - } - return pOldFormItem ? 1 : 0; + if (pOldFormItem != pFormNode) + return pOldFormItem ? 1 : 0; + + SetObject(XFA_ATTRIBUTE_BindingNode, nullptr); + return 0; } bool CXFA_Node::HasBindItem() { @@ -836,10 +812,7 @@ CXFA_WidgetData* CXFA_Node::GetContainerWidgetData() { if (!pDataNode) return nullptr; pFieldWidgetData = nullptr; - CXFA_NodeArray formNodes; - pDataNode->GetBindItems(formNodes); - for (int32_t i = 0; i < formNodes.GetSize(); i++) { - CXFA_Node* pFormNode = formNodes.GetAt(i); + for (CXFA_Node* pFormNode : pDataNode->GetBindItems()) { if (!pFormNode || pFormNode->HasRemovedChildren()) continue; pFieldWidgetData = pFormNode->GetWidgetData(); @@ -1016,16 +989,16 @@ void CXFA_Node::Script_TreeClass_ResolveNode(CFXJSE_Arguments* pArguments) { return; } if (resoveNodeRS.dwFlags == XFA_RESOVENODE_RSTYPE_Nodes) { - CXFA_Object* pNode = resoveNodeRS.nodes[0]; + CXFA_Object* pObject = resoveNodeRS.objects.front(); pArguments->GetReturnValue()->Assign( - pScriptContext->GetJSValueFromMap(pNode)); + pScriptContext->GetJSValueFromMap(pObject)); } else { const XFA_SCRIPTATTRIBUTEINFO* lpAttributeInfo = resoveNodeRS.pScriptAttribute; if (lpAttributeInfo && lpAttributeInfo->eValueType == XFA_SCRIPT_Object) { std::unique_ptr<CFXJSE_Value> pValue( new CFXJSE_Value(pScriptContext->GetRuntime())); - (resoveNodeRS.nodes[0]->*(lpAttributeInfo->lpfnCallback))( + (resoveNodeRS.objects.front()->*(lpAttributeInfo->lpfnCallback))( pValue.get(), false, (XFA_ATTRIBUTE)lpAttributeInfo->eAttribute); pArguments->GetReturnValue()->Assign(pValue.get()); } else { @@ -1068,18 +1041,16 @@ void CXFA_Node::Script_Som_ResolveNodeList(CFXJSE_Value* pValue, resoveNodeRS, dwFlag); CXFA_ArrayNodeList* pNodeList = new CXFA_ArrayNodeList(m_pDocument); if (resoveNodeRS.dwFlags == XFA_RESOVENODE_RSTYPE_Nodes) { - for (int32_t i = 0; i < resoveNodeRS.nodes.GetSize(); i++) { - if (resoveNodeRS.nodes[i]->IsNode()) - pNodeList->Append(resoveNodeRS.nodes[i]->AsNode()); + for (CXFA_Object* pObject : resoveNodeRS.objects) { + if (pObject->IsNode()) + pNodeList->Append(pObject->AsNode()); } } else { CXFA_ValueArray valueArray(pScriptContext->GetRuntime()); - if (resoveNodeRS.GetAttributeResult(valueArray) > 0) { - CXFA_ObjArray objectArray; - valueArray.GetAttributeObject(objectArray); - for (int32_t i = 0; i < objectArray.GetSize(); i++) { - if (objectArray[i]->IsNode()) - pNodeList->Append(objectArray[i]->AsNode()); + if (resoveNodeRS.GetAttributeResult(&valueArray) > 0) { + for (CXFA_Object* pObject : valueArray.GetAttributeObject()) { + if (pObject->IsNode()) + pNodeList->Append(pObject->AsNode()); } } } @@ -1331,13 +1302,16 @@ void CXFA_Node::Script_NodeClass_LoadXML(CFXJSE_Arguments* pArguments) { pFakeRoot->SetCData(XFA_ATTRIBUTE_ContentType, CFX_WideString(wsContentType)); } - CFDE_XMLNode* pFakeXMLRoot = pFakeRoot->GetXMLMappingNode(); + + std::unique_ptr<CFDE_XMLNode> pFakeXMLRoot(pFakeRoot->GetXMLMappingNode()); if (!pFakeXMLRoot) { CFDE_XMLNode* pThisXMLRoot = GetXMLMappingNode(); - pFakeXMLRoot = pThisXMLRoot ? pThisXMLRoot->Clone(false) : nullptr; + pFakeXMLRoot = pThisXMLRoot ? pThisXMLRoot->Clone() : nullptr; + } + if (!pFakeXMLRoot) { + pFakeXMLRoot = + pdfium::MakeUnique<CFDE_XMLElement>(CFX_WideString(GetClassName())); } - if (!pFakeXMLRoot) - pFakeXMLRoot = new CFDE_XMLElement(CFX_WideString(GetClassName())); if (bIgnoreRoot) { CFDE_XMLNode* pXMLChild = pXMLNode->GetNodeItem(CFDE_XMLNode::FirstChild); @@ -1355,57 +1329,54 @@ void CXFA_Node::Script_NodeClass_LoadXML(CFXJSE_Arguments* pArguments) { } pFakeXMLRoot->InsertChildNode(pXMLNode); } - pParser->ConstructXFANode(pFakeRoot, pFakeXMLRoot); + pParser->ConstructXFANode(pFakeRoot, pFakeXMLRoot.get()); pFakeRoot = pParser->GetRootNode(); - if (pFakeRoot) { - if (bOverwrite) { - CXFA_Node* pChild = GetNodeItem(XFA_NODEITEM_FirstChild); - CXFA_Node* pNewChild = pFakeRoot->GetNodeItem(XFA_NODEITEM_FirstChild); - int32_t index = 0; - while (pNewChild) { - CXFA_Node* pItem = pNewChild->GetNodeItem(XFA_NODEITEM_NextSibling); - pFakeRoot->RemoveChild(pNewChild); - InsertChild(index++, pNewChild); - pNewChild->SetFlag(XFA_NodeFlag_Initialized, true); - pNewChild = pItem; - } - while (pChild) { - CXFA_Node* pItem = pChild->GetNodeItem(XFA_NODEITEM_NextSibling); - RemoveChild(pChild); - pFakeRoot->InsertChild(pChild); - pChild = pItem; - } - if (GetPacketID() == XFA_XDPPACKET_Form && - GetElementType() == XFA_Element::ExData) { - CFDE_XMLNode* pTempXMLNode = GetXMLMappingNode(); - SetXMLMappingNode(pFakeXMLRoot); - SetFlag(XFA_NodeFlag_OwnXMLNode, false); - if (pTempXMLNode && !pTempXMLNode->GetNodeItem(CFDE_XMLNode::Parent)) { - pFakeXMLRoot = pTempXMLNode; - } else { - pFakeXMLRoot = nullptr; - } - } - MoveBufferMapData(pFakeRoot, this, XFA_CalcData, true); - } else { - CXFA_Node* pChild = pFakeRoot->GetNodeItem(XFA_NODEITEM_FirstChild); - while (pChild) { - CXFA_Node* pItem = pChild->GetNodeItem(XFA_NODEITEM_NextSibling); - pFakeRoot->RemoveChild(pChild); - InsertChild(pChild); - pChild->SetFlag(XFA_NodeFlag_Initialized, true); - pChild = pItem; - } + if (!pFakeRoot) + return; + + if (bOverwrite) { + CXFA_Node* pChild = GetNodeItem(XFA_NODEITEM_FirstChild); + CXFA_Node* pNewChild = pFakeRoot->GetNodeItem(XFA_NODEITEM_FirstChild); + int32_t index = 0; + while (pNewChild) { + CXFA_Node* pItem = pNewChild->GetNodeItem(XFA_NODEITEM_NextSibling); + pFakeRoot->RemoveChild(pNewChild); + InsertChild(index++, pNewChild); + pNewChild->SetFlag(XFA_NodeFlag_Initialized, true); + pNewChild = pItem; } - if (pFakeXMLRoot) { - pFakeRoot->SetXMLMappingNode(pFakeXMLRoot); - pFakeRoot->SetFlag(XFA_NodeFlag_OwnXMLNode, false); + while (pChild) { + CXFA_Node* pItem = pChild->GetNodeItem(XFA_NODEITEM_NextSibling); + RemoveChild(pChild); + pFakeRoot->InsertChild(pChild); + pChild = pItem; } - pFakeRoot->SetFlag(XFA_NodeFlag_HasRemovedChildren, false); + if (GetPacketID() == XFA_XDPPACKET_Form && + GetElementType() == XFA_Element::ExData) { + CFDE_XMLNode* pTempXMLNode = GetXMLMappingNode(); + SetXMLMappingNode(pFakeXMLRoot.release()); + SetFlag(XFA_NodeFlag_OwnXMLNode, false); + if (pTempXMLNode && !pTempXMLNode->GetNodeItem(CFDE_XMLNode::Parent)) + pFakeXMLRoot.reset(pTempXMLNode); + else + pFakeXMLRoot = nullptr; + } + MoveBufferMapData(pFakeRoot, this, XFA_CalcData, true); } else { - delete pFakeXMLRoot; - pFakeXMLRoot = nullptr; + CXFA_Node* pChild = pFakeRoot->GetNodeItem(XFA_NODEITEM_FirstChild); + while (pChild) { + CXFA_Node* pItem = pChild->GetNodeItem(XFA_NODEITEM_NextSibling); + pFakeRoot->RemoveChild(pChild); + InsertChild(pChild); + pChild->SetFlag(XFA_NodeFlag_Initialized, true); + pChild = pItem; + } } + if (pFakeXMLRoot) { + pFakeRoot->SetXMLMappingNode(pFakeXMLRoot.release()); + pFakeRoot->SetFlag(XFA_NodeFlag_OwnXMLNode, false); + } + pFakeRoot->SetFlag(XFA_NodeFlag_HasRemovedChildren, false); } void CXFA_Node::Script_NodeClass_SaveFilteredXML(CFXJSE_Arguments* pArguments) { @@ -1440,11 +1411,8 @@ void CXFA_Node::Script_NodeClass_SaveXML(CFXJSE_Arguments* pArguments) { } CFX_RetainPtr<IFX_MemoryStream> pMemoryStream = IFX_MemoryStream::Create(true); - - // Note: ambiguious below without static_cast. - CFX_RetainPtr<IFGAS_Stream> pStream = IFGAS_Stream::CreateStream( - CFX_RetainPtr<IFX_SeekableWriteStream>(pMemoryStream), - FX_STREAMACCESS_Text | FX_STREAMACCESS_Write | FX_STREAMACCESS_Append); + CFX_RetainPtr<IFGAS_Stream> pStream = + IFGAS_Stream::CreateWriteStream(pMemoryStream); if (!pStream) { pArguments->GetReturnValue()->SetString(bsXMLHeader); @@ -1552,12 +1520,11 @@ void CXFA_Node::Script_NodeClass_OneOfChild(CFXJSE_Value* pValue, ThrowInvalidPropertyException(); return; } - - CXFA_NodeArray properts; - int32_t iSize = GetNodeList(properts, XFA_NODEFILTER_OneOfProperty); - if (iSize > 0) { + std::vector<CXFA_Node*> properties = + GetNodeList(XFA_NODEFILTER_OneOfProperty); + if (!properties.empty()) { pValue->Assign( - m_pDocument->GetScriptContext()->GetJSValueFromMap(properts[0])); + m_pDocument->GetScriptContext()->GetJSValueFromMap(properties.front())); } } @@ -1826,8 +1793,8 @@ void CXFA_Node::Script_Attribute_String(CFXJSE_Value* pValue, XFA_RESOLVENODE_RS resoveNodeRS; int32_t iRet = m_pDocument->GetScriptContext()->ResolveObjects( pProtoRoot, wsSOM.AsStringC(), resoveNodeRS, dwFlag); - if (iRet > 0 && resoveNodeRS.nodes[0]->IsNode()) { - pProtoNode = resoveNodeRS.nodes[0]->AsNode(); + if (iRet > 0 && resoveNodeRS.objects.front()->IsNode()) { + pProtoNode = resoveNodeRS.objects.front()->AsNode(); } } else if (!wsID.IsEmpty()) { pProtoNode = m_pDocument->GetNodeByID(pProtoRoot, wsID.AsStringC()); @@ -1998,22 +1965,17 @@ void CXFA_Node::Script_Som_DefaultValue(CFXJSE_Value* pValue, CFX_WideString wsFormatValue(wsNewValue); CXFA_WidgetData* pContainerWidgetData = nullptr; if (GetPacketID() == XFA_XDPPACKET_Datasets) { - CXFA_NodeArray formNodes; - GetBindItems(formNodes); CFX_WideString wsPicture; - for (int32_t i = 0; i < formNodes.GetSize(); i++) { - CXFA_Node* pFormNode = formNodes.GetAt(i); - if (!pFormNode || pFormNode->HasRemovedChildren()) { + for (CXFA_Node* pFormNode : GetBindItems()) { + if (!pFormNode || pFormNode->HasRemovedChildren()) continue; - } pContainerWidgetData = pFormNode->GetContainerWidgetData(); if (pContainerWidgetData) { pContainerWidgetData->GetPictureContent(wsPicture, XFA_VALUEPICTURE_DataBind); } - if (!wsPicture.IsEmpty()) { + if (!wsPicture.IsEmpty()) break; - } pContainerWidgetData = nullptr; } } else if (GetPacketID() == XFA_XDPPACKET_Form) { @@ -2032,7 +1994,7 @@ void CXFA_Node::Script_Som_DefaultValue(CFXJSE_Value* pValue, pValue->SetInteger(FXSYS_wtoi(content.c_str())); } else if (eType == XFA_Element::Float || eType == XFA_Element::Decimal) { CFX_Decimal decimal(content.AsStringC()); - pValue->SetFloat((FX_FLOAT)(double)decimal); + pValue->SetFloat((float)(double)decimal); } else { pValue->SetString(content.UTF8Encode().AsStringC()); } @@ -2253,7 +2215,7 @@ void CXFA_Node::Script_Field_DefaultValue(CFXJSE_Value* pValue, pValue->SetString(content.UTF8Encode().AsStringC()); } else { CFX_Decimal decimal(content.AsStringC()); - pValue->SetFloat((FX_FLOAT)(double)decimal); + pValue->SetFloat((float)(double)decimal); } } else if (pNode && pNode->GetElementType() == XFA_Element::Integer) { pValue->SetInteger(FXSYS_wtoi(content.c_str())); @@ -2261,7 +2223,7 @@ void CXFA_Node::Script_Field_DefaultValue(CFXJSE_Value* pValue, pValue->SetBoolean(FXSYS_wtoi(content.c_str()) == 0 ? false : true); } else if (pNode && pNode->GetElementType() == XFA_Element::Float) { CFX_Decimal decimal(content.AsStringC()); - pValue->SetFloat((FX_FLOAT)(double)decimal); + pValue->SetFloat((float)(double)decimal); } else { pValue->SetString(content.UTF8Encode().AsStringC()); } @@ -3310,7 +3272,7 @@ void CXFA_Node::Script_Form_FormNodes(CFXJSE_Arguments* pArguments) { return; } - CXFA_NodeArray formItems; + std::vector<CXFA_Node*> formItems; CXFA_ArrayNodeList* pFormNodes = new CXFA_ArrayNodeList(m_pDocument); pFormNodes->SetArrayNodeList(formItems); pArguments->GetReturnValue()->SetObject( @@ -3413,9 +3375,8 @@ void CXFA_Node::Script_Packet_GetAttribute(CFXJSE_Arguments* pArguments) { CFX_WideString wsAttributeValue; CFDE_XMLNode* pXMLNode = GetXMLMappingNode(); if (pXMLNode && pXMLNode->GetType() == FDE_XMLNODE_Element) { - static_cast<CFDE_XMLElement*>(pXMLNode)->GetString( - CFX_WideString::FromUTF8(bsAttributeName.AsStringC()).c_str(), - wsAttributeValue); + wsAttributeValue = static_cast<CFDE_XMLElement*>(pXMLNode)->GetString( + CFX_WideString::FromUTF8(bsAttributeName.AsStringC()).c_str()); } pArguments->GetReturnValue()->SetString( wsAttributeValue.UTF8Encode().AsStringC()); @@ -3469,7 +3430,7 @@ void CXFA_Node::Script_Packet_Content(CFXJSE_Value* pValue, CFDE_XMLNode* pXMLNode = GetXMLMappingNode(); if (pXMLNode && pXMLNode->GetType() == FDE_XMLNODE_Element) { CFDE_XMLElement* pXMLElement = static_cast<CFDE_XMLElement*>(pXMLNode); - pXMLElement->GetTextData(wsTextData); + wsTextData = pXMLElement->GetTextData(); } pValue->SetString(wsTextData.UTF8Encode().AsStringC()); } @@ -3783,13 +3744,13 @@ bool CXFA_Node::TryMeasure(XFA_ATTRIBUTE eAttr, void* pValue; int32_t iBytes; if (GetMapModuleBuffer(pKey, pValue, iBytes) && iBytes == sizeof(mValue)) { - FXSYS_memcpy(&mValue, pValue, sizeof(mValue)); + memcpy(&mValue, pValue, sizeof(mValue)); return true; } if (bUseDefault && XFA_GetAttributeDefaultValue(pValue, GetElementType(), eAttr, XFA_ATTRIBUTETYPE_Measure, m_ePacket)) { - FXSYS_memcpy(&mValue, pValue, sizeof(mValue)); + memcpy(&mValue, pValue, sizeof(mValue)); return true; } return false; @@ -3842,8 +3803,7 @@ bool CXFA_Node::SetCData(XFA_ATTRIBUTE eAttr, GetNodeItem(XFA_NODEITEM_FirstChild); pChildDataNode; pChildDataNode = pChildDataNode->GetNodeItem( XFA_NODEITEM_NextSibling)) { - CXFA_NodeArray formNodes; - if (pChildDataNode->GetBindItems(formNodes) > 0) { + if (!pChildDataNode->GetBindItems().empty()) { bDeleteChildren = false; break; } @@ -3900,8 +3860,7 @@ bool CXFA_Node::SetAttributeValue(const CFX_WideString& wsValue, GetNodeItem(XFA_NODEITEM_FirstChild); pChildDataNode; pChildDataNode = pChildDataNode->GetNodeItem( XFA_NODEITEM_NextSibling)) { - CXFA_NodeArray formNodes; - if (pChildDataNode->GetBindItems(formNodes) > 0) { + if (!pChildDataNode->GetBindItems().empty()) { bDeleteChildren = false; break; } @@ -3947,7 +3906,7 @@ bool CXFA_Node::TryCData(XFA_ATTRIBUTE eAttr, void* pValue = nullptr; if (XFA_GetAttributeDefaultValue(pValue, GetElementType(), eAttr, XFA_ATTRIBUTETYPE_Cdata, m_ePacket)) { - wsValue = (const FX_WCHAR*)pValue; + wsValue = (const wchar_t*)pValue; return true; } return false; @@ -3975,7 +3934,7 @@ bool CXFA_Node::TryCData(XFA_ATTRIBUTE eAttr, void* pValue = nullptr; if (XFA_GetAttributeDefaultValue(pValue, GetElementType(), eAttr, XFA_ATTRIBUTETYPE_Cdata, m_ePacket)) { - wsValue = (CFX_WideStringC)(const FX_WCHAR*)pValue; + wsValue = (CFX_WideStringC)(const wchar_t*)pValue; return true; } return false; @@ -4018,10 +3977,14 @@ bool CXFA_Node::SetValue(XFA_ATTRIBUTE eAttr, static_cast<CFDE_XMLElement*>(m_pXMLNode) ->SetString(pInfo->pName, pValue ? L"1" : L"0"); break; - case XFA_ATTRIBUTETYPE_Integer: + case XFA_ATTRIBUTETYPE_Integer: { + CFX_WideString wsValue; + wsValue.Format( + L"%d", static_cast<int32_t>(reinterpret_cast<uintptr_t>(pValue))); static_cast<CFDE_XMLElement*>(m_pXMLNode) - ->SetInteger(pInfo->pName, (int32_t)(uintptr_t)pValue); + ->SetString(pInfo->pName, wsValue); break; + } default: ASSERT(0); } @@ -4058,7 +4021,7 @@ bool CXFA_Node::TryUserData(void* pKey, void*& pData, bool bProtoAlso) { if (!GetMapModuleBuffer(pKey, pData, iBytes, bProtoAlso)) { return false; } - return iBytes == sizeof(void*) && FXSYS_memcpy(&pData, pData, iBytes); + return iBytes == sizeof(void*) && memcpy(&pData, pData, iBytes); } bool CXFA_Node::SetScriptContent(const CFX_WideString& wsContent, @@ -4080,7 +4043,7 @@ bool CXFA_Node::SetScriptContent(const CFX_WideString& wsContent, CXFA_Node* pBind = GetBindData(); if (bSyncData && pBind) { std::vector<CFX_WideString> wsSaveTextArray; - int32_t iSize = 0; + size_t iSize = 0; if (!wsContent.IsEmpty()) { int32_t iStart = 0; int32_t iLength = wsContent.GetLength(); @@ -4098,7 +4061,7 @@ bool CXFA_Node::SetScriptContent(const CFX_WideString& wsContent, wsContent.Mid(iStart, iLength - iStart)); } } - iSize = pdfium::CollectionSize<int32_t>(wsSaveTextArray); + iSize = wsSaveTextArray.size(); } if (iSize == 0) { while (CXFA_Node* pChildNode = @@ -4106,11 +4069,11 @@ bool CXFA_Node::SetScriptContent(const CFX_WideString& wsContent, pBind->RemoveChild(pChildNode); } } else { - CXFA_NodeArray valueNodes; - int32_t iDatas = pBind->GetNodeList( - valueNodes, XFA_NODEFILTER_Children, XFA_Element::DataValue); + std::vector<CXFA_Node*> valueNodes = pBind->GetNodeList( + XFA_NODEFILTER_Children, XFA_Element::DataValue); + size_t iDatas = valueNodes.size(); if (iDatas < iSize) { - int32_t iAddNodes = iSize - iDatas; + size_t iAddNodes = iSize - iDatas; CXFA_Node* pValueNodes = nullptr; while (iAddNodes-- > 0) { pValueNodes = @@ -4121,7 +4084,7 @@ bool CXFA_Node::SetScriptContent(const CFX_WideString& wsContent, } pValueNodes = nullptr; } else if (iDatas > iSize) { - int32_t iDelNodes = iDatas - iSize; + size_t iDelNodes = iDatas - iSize; while (iDelNodes-- > 0) { pBind->RemoveChild(pBind->GetNodeItem(XFA_NODEITEM_FirstChild)); } @@ -4136,12 +4099,10 @@ bool CXFA_Node::SetScriptContent(const CFX_WideString& wsContent, i++; } } - CXFA_NodeArray nodeArray; - pBind->GetBindItems(nodeArray); - for (int32_t i = 0; i < nodeArray.GetSize(); i++) { - if (nodeArray[i] != this) { - nodeArray[i]->SetScriptContent(wsContent, wsContent, bNotify, - bScriptModify, false); + for (CXFA_Node* pArrayNode : pBind->GetBindItems()) { + if (pArrayNode != this) { + pArrayNode->SetScriptContent(wsContent, wsContent, bNotify, + bScriptModify, false); } } } @@ -4159,12 +4120,10 @@ bool CXFA_Node::SetScriptContent(const CFX_WideString& wsContent, if (pBindNode && bSyncData) { pBindNode->SetScriptContent(wsContent, wsXMLValue, bNotify, bScriptModify, false); - CXFA_NodeArray nodeArray; - pBindNode->GetBindItems(nodeArray); - for (int32_t i = 0; i < nodeArray.GetSize(); i++) { - if (nodeArray[i] != this) { - nodeArray[i]->SetScriptContent(wsContent, wsContent, bNotify, true, - false); + for (CXFA_Node* pArrayNode : pBindNode->GetBindItems()) { + if (pArrayNode != this) { + pArrayNode->SetScriptContent(wsContent, wsContent, bNotify, true, + false); } } } @@ -4223,11 +4182,9 @@ bool CXFA_Node::SetScriptContent(const CFX_WideString& wsContent, if (pNode) { SetAttributeValue(wsContent, wsXMLValue, bNotify, bScriptModify); if (pBindNode && bSyncData) { - CXFA_NodeArray nodeArray; - pBindNode->GetBindItems(nodeArray); - for (int32_t i = 0; i < nodeArray.GetSize(); i++) { - nodeArray[i]->SetScriptContent(wsContent, wsContent, bNotify, - bScriptModify, false); + for (CXFA_Node* pArrayNode : pBindNode->GetBindItems()) { + pArrayNode->SetScriptContent(wsContent, wsContent, bNotify, + bScriptModify, false); } } return true; @@ -4347,7 +4304,7 @@ bool CXFA_Node::TryNamespace(CFX_WideString& wsNamespace) { if (!pXMLNode || pXMLNode->GetType() != FDE_XMLNODE_Element) { return false; } - static_cast<CFDE_XMLElement*>(pXMLNode)->GetNamespaceURI(wsNamespace); + wsNamespace = static_cast<CFDE_XMLElement*>(pXMLNode)->GetNamespaceURI(); return true; } else if (GetPacketID() == XFA_XDPPACKET_Datasets) { CFDE_XMLNode* pXMLNode = GetXMLMappingNode(); @@ -4361,9 +4318,9 @@ bool CXFA_Node::TryNamespace(CFX_WideString& wsNamespace) { GetEnum(XFA_ATTRIBUTE_Contains) == XFA_ATTRIBUTEENUM_MetaData) { return XFA_FDEExtension_ResolveNamespaceQualifier( static_cast<CFDE_XMLElement*>(pXMLNode), - GetCData(XFA_ATTRIBUTE_QualifiedName), wsNamespace); + GetCData(XFA_ATTRIBUTE_QualifiedName), &wsNamespace); } - static_cast<CFDE_XMLElement*>(pXMLNode)->GetNamespaceURI(wsNamespace); + wsNamespace = static_cast<CFDE_XMLElement*>(pXMLNode)->GetNamespaceURI(); return true; } else { CXFA_Node* pModelNode = GetModelNode(); @@ -4896,7 +4853,7 @@ bool CXFA_Node::GetMapModuleValue(void* pKey, void*& pValue) { void CXFA_Node::SetMapModuleString(void* pKey, const CFX_WideStringC& wsValue) { SetMapModuleBuffer(pKey, (void*)wsValue.c_str(), - wsValue.GetLength() * sizeof(FX_WCHAR)); + wsValue.GetLength() * sizeof(wchar_t)); } bool CXFA_Node::GetMapModuleString(void* pKey, CFX_WideStringC& wsValue) { @@ -4905,7 +4862,7 @@ bool CXFA_Node::GetMapModuleString(void* pKey, CFX_WideStringC& wsValue) { if (!GetMapModuleBuffer(pKey, pValue, iBytes)) { return false; } - wsValue = CFX_WideStringC((const FX_WCHAR*)pValue, iBytes / sizeof(FX_WCHAR)); + wsValue = CFX_WideStringC((const wchar_t*)pValue, iBytes / sizeof(wchar_t)); return true; } @@ -4933,7 +4890,7 @@ void CXFA_Node::SetMapModuleBuffer( pBuffer->pCallbackInfo = pCallbackInfo; pBuffer->iBytes = iBytes; - FXSYS_memcpy(pBuffer->GetData(), pValue, iBytes); + memcpy(pBuffer->GetData(), pValue, iBytes); } bool CXFA_Node::GetMapModuleBuffer(void* pKey, @@ -5050,8 +5007,7 @@ void CXFA_Node::MergeAllData(void* pDstModule) { } pDstBuffer->pCallbackInfo = pSrcBuffer->pCallbackInfo; pDstBuffer->iBytes = pSrcBuffer->iBytes; - FXSYS_memcpy(pDstBuffer->GetData(), pSrcBuffer->GetData(), - pSrcBuffer->iBytes); + memcpy(pDstBuffer->GetData(), pSrcBuffer->GetData(), pSrcBuffer->iBytes); if (pDstBuffer->pCallbackInfo && pDstBuffer->pCallbackInfo->pCopy) { pDstBuffer->pCallbackInfo->pCopy(*(void**)pDstBuffer->GetData()); } diff --git a/chromium/third_party/pdfium/xfa/fxfa/parser/xfa_object.h b/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_node.h index cc116505e0a..970d267ff3b 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/parser/xfa_object.h +++ b/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_node.h @@ -1,36 +1,25 @@ -// Copyright 2014 PDFium Authors. All rights reserved. +// Copyright 2017 PDFium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com -#ifndef XFA_FXFA_PARSER_XFA_OBJECT_H_ -#define XFA_FXFA_PARSER_XFA_OBJECT_H_ +#ifndef XFA_FXFA_PARSER_CXFA_NODE_H_ +#define XFA_FXFA_PARSER_CXFA_NODE_H_ #include <map> -#include <unordered_set> +#include <vector> -#include "fxjs/cfxjse_arguments.h" -#include "xfa/fde/xml/fde_xml.h" -#include "xfa/fxfa/parser/xfa_utils.h" +#include "core/fxcrt/fx_string.h" +#include "xfa/fxfa/parser/cxfa_object.h" -class CXFA_Document; -class CXFA_Node; -class CXFA_NodeList; +class CFDE_XMLNode; +class CFXJSE_Argument; +class CXFA_WidgetData; -enum class XFA_ObjectType { - Object, - List, - NodeList, - Node, - NodeC, - NodeV, - ModelNode, - TextNode, - ContainerNode, - ContentNode, - VariablesThis -}; +#define XFA_NODEFILTER_Children 0x01 +#define XFA_NODEFILTER_Properties 0x02 +#define XFA_NODEFILTER_OneOfProperty 0x04 enum XFA_NodeFlag { XFA_NodeFlag_None = 0, @@ -45,89 +34,18 @@ enum XFA_NodeFlag { XFA_NodeFlag_LayoutGeneratedNode = 1 << 8 }; -class CXFA_Object : public CFXJSE_HostObject { - public: - CXFA_Object(CXFA_Document* pDocument, - XFA_ObjectType objectType, - XFA_Element eType, - const CFX_WideStringC& elementName); - ~CXFA_Object() override; - - CXFA_Document* GetDocument() const { return m_pDocument; } - XFA_ObjectType GetObjectType() const { return m_objectType; } - - bool IsNode() const { - return m_objectType == XFA_ObjectType::Node || - m_objectType == XFA_ObjectType::NodeC || - m_objectType == XFA_ObjectType::NodeV || - m_objectType == XFA_ObjectType::ModelNode || - m_objectType == XFA_ObjectType::TextNode || - m_objectType == XFA_ObjectType::ContainerNode || - m_objectType == XFA_ObjectType::ContentNode || - m_objectType == XFA_ObjectType::VariablesThis; - } - bool IsNodeList() const { return m_objectType == XFA_ObjectType::NodeList; } - bool IsContentNode() const { - return m_objectType == XFA_ObjectType::ContentNode; - } - bool IsContainerNode() const { - return m_objectType == XFA_ObjectType::ContainerNode; - } - bool IsModelNode() const { return m_objectType == XFA_ObjectType::ModelNode; } - bool IsNodeV() const { return m_objectType == XFA_ObjectType::NodeV; } - bool IsVariablesThis() const { - return m_objectType == XFA_ObjectType::VariablesThis; - } - - CXFA_Node* AsNode(); - CXFA_NodeList* AsNodeList(); - - const CXFA_Node* AsNode() const; - const CXFA_NodeList* AsNodeList() const; - - XFA_Element GetElementType() const; - CFX_WideStringC GetClassName() const; - uint32_t GetClassHashCode() const; - void Script_ObjectClass_ClassName(CFXJSE_Value* pValue, - bool bSetting, - XFA_ATTRIBUTE eAttribute); - - void ThrowInvalidPropertyException() const; - void ThrowArgumentMismatchException() const; - void ThrowIndexOutOfBoundsException() const; - void ThrowParamCountMismatchException(const CFX_WideString& method) const; - - protected: - void ThrowException(const FX_WCHAR* str, ...) const; - - CXFA_Document* const m_pDocument; - const XFA_ObjectType m_objectType; - const XFA_Element m_elementType; - - const uint32_t m_elementNameHash; - const CFX_WideStringC m_elementName; +enum XFA_SOM_MESSAGETYPE { + XFA_SOM_ValidationMessage, + XFA_SOM_FormatMessage, + XFA_SOM_MandatoryMessage }; -using CXFA_ObjArray = CFX_ArrayTemplate<CXFA_Object*>; -#define XFA_NODEFILTER_Children 0x01 -#define XFA_NODEFILTER_Properties 0x02 -#define XFA_NODEFILTER_OneOfProperty 0x04 -#define XFA_CLONEFLAG_Content 0x01 enum XFA_NODEITEM { XFA_NODEITEM_Parent, XFA_NODEITEM_FirstChild, XFA_NODEITEM_NextSibling, XFA_NODEITEM_PrevSibling, }; -enum XFA_SOM_MESSAGETYPE { - XFA_SOM_ValidationMessage, - XFA_SOM_FormatMessage, - XFA_SOM_MandatoryMessage -}; - -using CXFA_NodeArray = CFX_ArrayTemplate<CXFA_Node*>; -using CXFA_NodeStack = CFX_StackTemplate<CXFA_Node*>; -using CXFA_NodeSet = std::unordered_set<CXFA_Node*>; typedef void (*PD_CALLBACK_FREEDATA)(void* pData); typedef void (*PD_CALLBACK_DUPLICATEDATA)(void*& pData); @@ -151,10 +69,6 @@ struct XFA_MAPMODULEDATA { std::map<void*, XFA_MAPDATABLOCK*> m_BufferMap; }; -#define XFA_CalcRefCount (void*)(uintptr_t) FXBSTR_ID('X', 'F', 'A', 'R') -#define XFA_CalcData (void*)(uintptr_t) FXBSTR_ID('X', 'F', 'A', 'C') -#define XFA_LAYOUTITEMKEY (void*)(uintptr_t) FXBSTR_ID('L', 'Y', 'I', 'M') - class CXFA_Node : public CXFA_Object { public: uint32_t GetPacketID() const { return m_ePacket; } @@ -304,11 +218,10 @@ class CXFA_Node : public CXFA_Object { CXFA_Node* Clone(bool bRecursive); CXFA_Node* GetNodeItem(XFA_NODEITEM eItem) const; CXFA_Node* GetNodeItem(XFA_NODEITEM eItem, XFA_ObjectType eType) const; - int32_t GetNodeList(CXFA_NodeArray& nodes, - uint32_t dwTypeFilter = XFA_NODEFILTER_Children | - XFA_NODEFILTER_Properties, - XFA_Element eTypeFilter = XFA_Element::Unknown, - int32_t iLevel = 1); + std::vector<CXFA_Node*> GetNodeList( + uint32_t dwTypeFilter = XFA_NODEFILTER_Children | + XFA_NODEFILTER_Properties, + XFA_Element eTypeFilter = XFA_Element::Unknown); CXFA_Node* CreateSamePacketNode(XFA_Element eType, uint32_t dwFlags = XFA_NodeFlag_Initialized); CXFA_Node* CloneTemplateToForm(bool bRecursive); @@ -317,7 +230,7 @@ class CXFA_Node : public CXFA_Object { CXFA_Node* GetDataDescriptionNode(); void SetDataDescriptionNode(CXFA_Node* pDataDescriptionNode); CXFA_Node* GetBindData(); - int32_t GetBindItems(CXFA_NodeArray& formItems); + std::vector<CXFA_Node*> GetBindItems(); int32_t AddBindItem(CXFA_Node* pFormNode); int32_t RemoveBindItem(CXFA_Node* pFormNode); bool HasBindItem(); @@ -620,7 +533,7 @@ class CXFA_Node : public CXFA_Object { bool bSetting, XFA_ATTRIBUTE eAttribute); - protected: + private: friend class CXFA_Document; CXFA_Node(CXFA_Document* pDoc, @@ -692,132 +605,4 @@ class CXFA_Node : public CXFA_Object { void ThrowTooManyOccurancesException(const CFX_WideString& obj) const; }; -class CXFA_ThisProxy : public CXFA_Object { - public: - CXFA_ThisProxy(CXFA_Node* pThisNode, CXFA_Node* pScriptNode); - ~CXFA_ThisProxy() override; - - CXFA_Node* GetThisNode() const; - CXFA_Node* GetScriptNode() const; - - private: - CXFA_Node* m_pThisNode; - CXFA_Node* m_pScriptNode; -}; - -class CXFA_NodeList : public CXFA_Object { - public: - explicit CXFA_NodeList(CXFA_Document* pDocument); - ~CXFA_NodeList() override; - - CXFA_Node* NamedItem(const CFX_WideStringC& wsName); - virtual int32_t GetLength() = 0; - virtual bool Append(CXFA_Node* pNode) = 0; - virtual bool Insert(CXFA_Node* pNewNode, CXFA_Node* pBeforeNode) = 0; - virtual bool Remove(CXFA_Node* pNode) = 0; - virtual CXFA_Node* Item(int32_t iIndex) = 0; - - void Script_ListClass_Append(CFXJSE_Arguments* pArguments); - void Script_ListClass_Insert(CFXJSE_Arguments* pArguments); - void Script_ListClass_Remove(CFXJSE_Arguments* pArguments); - void Script_ListClass_Item(CFXJSE_Arguments* pArguments); - - void Script_TreelistClass_NamedItem(CFXJSE_Arguments* pArguments); - void Script_ListClass_Length(CFXJSE_Value* pValue, - bool bSetting, - XFA_ATTRIBUTE eAttribute); -}; - -class CXFA_ArrayNodeList : public CXFA_NodeList { - public: - explicit CXFA_ArrayNodeList(CXFA_Document* pDocument); - ~CXFA_ArrayNodeList() override; - - // From CXFA_NodeList. - int32_t GetLength() override; - bool Append(CXFA_Node* pNode) override; - bool Insert(CXFA_Node* pNewNode, CXFA_Node* pBeforeNode) override; - bool Remove(CXFA_Node* pNode) override; - CXFA_Node* Item(int32_t iIndex) override; - - void SetArrayNodeList(const CXFA_NodeArray& srcArray); - - protected: - CXFA_NodeArray m_array; -}; - -class CXFA_AttachNodeList : public CXFA_NodeList { - public: - CXFA_AttachNodeList(CXFA_Document* pDocument, CXFA_Node* pAttachNode); - - // From CXFA_NodeList. - int32_t GetLength() override; - bool Append(CXFA_Node* pNode) override; - bool Insert(CXFA_Node* pNewNode, CXFA_Node* pBeforeNode) override; - bool Remove(CXFA_Node* pNode) override; - CXFA_Node* Item(int32_t iIndex) override; - - protected: - CXFA_Node* m_pAttachNode; -}; -class CXFA_TraverseStrategy_XFAContainerNode { - public: - static CXFA_Node* GetFirstChild(CXFA_Node* pTemplateNode, - void* pUserData = nullptr) { - return pTemplateNode->GetNodeItem(XFA_NODEITEM_FirstChild, - XFA_ObjectType::ContainerNode); - } - static CXFA_Node* GetNextSibling(CXFA_Node* pTemplateNode, - void* pUserData = nullptr) { - return pTemplateNode->GetNodeItem(XFA_NODEITEM_NextSibling, - XFA_ObjectType::ContainerNode); - } - static CXFA_Node* GetParent(CXFA_Node* pTemplateNode, - void* pUserData = nullptr) { - return pTemplateNode->GetNodeItem(XFA_NODEITEM_Parent, - XFA_ObjectType::ContainerNode); - } -}; -typedef CXFA_NodeIteratorTemplate<CXFA_Node, - CXFA_TraverseStrategy_XFAContainerNode> - CXFA_ContainerIterator; -class CXFA_TraverseStrategy_XFANode { - public: - static inline CXFA_Node* GetFirstChild(CXFA_Node* pTemplateNode) { - return pTemplateNode->GetNodeItem(XFA_NODEITEM_FirstChild); - } - static inline CXFA_Node* GetNextSibling(CXFA_Node* pTemplateNode) { - return pTemplateNode->GetNodeItem(XFA_NODEITEM_NextSibling); - } - static inline CXFA_Node* GetParent(CXFA_Node* pTemplateNode) { - return pTemplateNode->GetNodeItem(XFA_NODEITEM_Parent); - } -}; -typedef CXFA_NodeIteratorTemplate<CXFA_Node, CXFA_TraverseStrategy_XFANode> - CXFA_NodeIterator; - -inline CXFA_Node* CXFA_Object::AsNode() { - return IsNode() ? static_cast<CXFA_Node*>(this) : nullptr; -} - -inline CXFA_NodeList* CXFA_Object::AsNodeList() { - return IsNodeList() ? static_cast<CXFA_NodeList*>(this) : nullptr; -} - -inline const CXFA_Node* CXFA_Object::AsNode() const { - return IsNode() ? static_cast<const CXFA_Node*>(this) : nullptr; -} - -inline const CXFA_NodeList* CXFA_Object::AsNodeList() const { - return IsNodeList() ? static_cast<const CXFA_NodeList*>(this) : nullptr; -} - -inline CXFA_Node* ToNode(CXFA_Object* pObj) { - return pObj ? pObj->AsNode() : nullptr; -} - -inline const CXFA_Node* ToNode(const CXFA_Object* pObj) { - return pObj ? pObj->AsNode() : nullptr; -} - -#endif // XFA_FXFA_PARSER_XFA_OBJECT_H_ +#endif // XFA_FXFA_PARSER_CXFA_NODE_H_ diff --git a/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_nodehelper.cpp b/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_nodehelper.cpp index 2290892318b..abfca846093 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_nodehelper.cpp +++ b/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_nodehelper.cpp @@ -8,9 +8,9 @@ #include "core/fxcrt/fx_ext.h" #include "xfa/fxfa/parser/cxfa_document.h" +#include "xfa/fxfa/parser/cxfa_localemgr.h" +#include "xfa/fxfa/parser/cxfa_node.h" #include "xfa/fxfa/parser/cxfa_scriptcontext.h" -#include "xfa/fxfa/parser/xfa_localemgr.h" -#include "xfa/fxfa/parser/xfa_object.h" #include "xfa/fxfa/parser/xfa_resolvenode_rs.h" #include "xfa/fxfa/parser/xfa_utils.h" @@ -25,23 +25,20 @@ CXFA_NodeHelper::CXFA_NodeHelper() CXFA_NodeHelper::~CXFA_NodeHelper() {} CXFA_Node* CXFA_NodeHelper::ResolveNodes_GetOneChild(CXFA_Node* parent, - const FX_WCHAR* pwsName, + const wchar_t* pwsName, bool bIsClassName) { - if (!parent) { + if (!parent) return nullptr; - } - CXFA_NodeArray siblings; + + std::vector<CXFA_Node*> siblings; uint32_t uNameHash = FX_HashCode_GetW(CFX_WideStringC(pwsName), false); NodeAcc_TraverseAnySiblings(parent, uNameHash, &siblings, bIsClassName); - if (siblings.GetSize() == 0) { - return nullptr; - } - return siblings[0]; + return !siblings.empty() ? siblings[0] : nullptr; } int32_t CXFA_NodeHelper::CountSiblings(CXFA_Node* pNode, XFA_LOGIC_TYPE eLogicType, - CXFA_NodeArray* pSiblings, + std::vector<CXFA_Node*>* pSiblings, bool bIsClassName) { if (!pNode) return 0; @@ -52,99 +49,81 @@ int32_t CXFA_NodeHelper::CountSiblings(CXFA_Node* pNode, parent->GetElementType(), pNode->GetElementType(), XFA_XDPPACKET_UNKNOWN); if (!pProperty && eLogicType == XFA_LOGIC_Transparent) { parent = ResolveNodes_GetParent(pNode, XFA_LOGIC_Transparent); - if (!parent) { + if (!parent) return 0; - } } if (bIsClassName) { return NodeAcc_TraverseSiblings(parent, pNode->GetClassHashCode(), pSiblings, eLogicType, bIsClassName); - } else { - return NodeAcc_TraverseSiblings(parent, pNode->GetNameHash(), pSiblings, - eLogicType, bIsClassName); } + return NodeAcc_TraverseSiblings(parent, pNode->GetNameHash(), pSiblings, + eLogicType, bIsClassName); } -int32_t CXFA_NodeHelper::NodeAcc_TraverseAnySiblings(CXFA_Node* parent, - uint32_t dNameHash, - CXFA_NodeArray* pSiblings, - bool bIsClassName) { - if (!parent || !pSiblings) { +int32_t CXFA_NodeHelper::NodeAcc_TraverseAnySiblings( + CXFA_Node* parent, + uint32_t dNameHash, + std::vector<CXFA_Node*>* pSiblings, + bool bIsClassName) { + if (!parent || !pSiblings) return 0; - } + int32_t nCount = 0; - int32_t i = 0; - CXFA_NodeArray properties; - parent->GetNodeList(properties, XFA_NODEFILTER_Properties); - int32_t nProperties = properties.GetSize(); - for (i = 0; i < nProperties; ++i) { - CXFA_Node* child = properties[i]; + for (CXFA_Node* child : parent->GetNodeList(XFA_NODEFILTER_Properties)) { if (bIsClassName) { if (child->GetClassHashCode() == dNameHash) { - pSiblings->Add(child); + pSiblings->push_back(child); nCount++; } } else { if (child->GetNameHash() == dNameHash) { - pSiblings->Add(child); + pSiblings->push_back(child); nCount++; } } - if (nCount > 0) { + if (nCount > 0) return nCount; - } + nCount += NodeAcc_TraverseAnySiblings(child, dNameHash, pSiblings, bIsClassName); } - CXFA_NodeArray children; - parent->GetNodeList(children, XFA_NODEFILTER_Children); - int32_t nChildren = children.GetSize(); - for (i = 0; i < nChildren; i++) { - CXFA_Node* child = children[i]; + for (CXFA_Node* child : parent->GetNodeList(XFA_NODEFILTER_Children)) { if (bIsClassName) { if (child->GetClassHashCode() == dNameHash) { - if (pSiblings) { - pSiblings->Add(child); - } + pSiblings->push_back(child); nCount++; } } else { if (child->GetNameHash() == dNameHash) { - if (pSiblings) { - pSiblings->Add(child); - } + pSiblings->push_back(child); nCount++; } } - if (nCount > 0) { + if (nCount > 0) return nCount; - } + nCount += NodeAcc_TraverseAnySiblings(child, dNameHash, pSiblings, bIsClassName); } return nCount; } -int32_t CXFA_NodeHelper::NodeAcc_TraverseSiblings(CXFA_Node* parent, - uint32_t dNameHash, - CXFA_NodeArray* pSiblings, - XFA_LOGIC_TYPE eLogicType, - bool bIsClassName, - bool bIsFindProperty) { - if (!parent || !pSiblings) { +int32_t CXFA_NodeHelper::NodeAcc_TraverseSiblings( + CXFA_Node* parent, + uint32_t dNameHash, + std::vector<CXFA_Node*>* pSiblings, + XFA_LOGIC_TYPE eLogicType, + bool bIsClassName, + bool bIsFindProperty) { + if (!parent || !pSiblings) return 0; - } + int32_t nCount = 0; - int32_t i = 0; if (bIsFindProperty) { - CXFA_NodeArray properties; - parent->GetNodeList(properties, XFA_NODEFILTER_Properties); - int32_t nProperties = properties.GetSize(); - for (i = 0; i < nProperties; ++i) { - CXFA_Node* child = properties[i]; + for (CXFA_Node* child : parent->GetNodeList(XFA_NODEFILTER_Properties)) { if (bIsClassName) { if (child->GetClassHashCode() == dNameHash) { - pSiblings->Add(child); + pSiblings->push_back(child); nCount++; } } else { @@ -152,7 +131,7 @@ int32_t CXFA_NodeHelper::NodeAcc_TraverseSiblings(CXFA_Node* parent, if (child->GetElementType() != XFA_Element::PageSet && child->GetElementType() != XFA_Element::Extras && child->GetElementType() != XFA_Element::Items) { - pSiblings->Add(child); + pSiblings->push_back(child); nCount++; } } @@ -163,36 +142,27 @@ int32_t CXFA_NodeHelper::NodeAcc_TraverseSiblings(CXFA_Node* parent, eLogicType, bIsClassName, false); } } - if (nCount > 0) { + if (nCount > 0) return nCount; - } } - CXFA_NodeArray children; - parent->GetNodeList(children, XFA_NODEFILTER_Children); - int32_t nChildren = children.GetSize(); - for (i = 0; i < nChildren; i++) { - CXFA_Node* child = children[i]; - if (child->GetElementType() == XFA_Element::Variables) { + for (CXFA_Node* child : parent->GetNodeList(XFA_NODEFILTER_Children)) { + if (child->GetElementType() == XFA_Element::Variables) continue; - } + if (bIsClassName) { if (child->GetClassHashCode() == dNameHash) { - if (pSiblings) { - pSiblings->Add(child); - } + pSiblings->push_back(child); nCount++; } } else { if (child->GetNameHash() == dNameHash) { - if (pSiblings) { - pSiblings->Add(child); - } + pSiblings->push_back(child); nCount++; } } - if (eLogicType == XFA_LOGIC_NoTransparent) { + if (eLogicType == XFA_LOGIC_NoTransparent) continue; - } + if (NodeIsTransparent(child) && child->GetElementType() != XFA_Element::PageSet) { nCount += NodeAcc_TraverseSiblings(child, dNameHash, pSiblings, @@ -245,7 +215,7 @@ int32_t CXFA_NodeHelper::GetIndex(CXFA_Node* pNode, if (bIsClassIndex) { dwHashName = pNode->GetClassHashCode(); } - CXFA_NodeArray siblings; + std::vector<CXFA_Node*> siblings; int32_t iSize = NodeAcc_TraverseSiblings(parent, dwHashName, &siblings, eLogicType, bIsClassIndex); for (int32_t i = 0; i < iSize; ++i) { @@ -316,7 +286,7 @@ bool CXFA_NodeHelper::CreateNode_ForCondition(CFX_WideString& wsCondition) { if (wsCondition.GetAt(0) == '[') { int32_t i = 1; for (; i < iLen; ++i) { - FX_WCHAR ch = wsCondition[i]; + wchar_t ch = wsCondition[i]; if (ch == ' ') { continue; } diff --git a/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_nodehelper.h b/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_nodehelper.h index 5097feabacd..cf6c2f17a0b 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_nodehelper.h +++ b/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_nodehelper.h @@ -7,7 +7,8 @@ #ifndef XFA_FXFA_PARSER_CXFA_NODEHELPER_H_ #define XFA_FXFA_PARSER_CXFA_NODEHELPER_H_ -#include "xfa/fxfa/parser/xfa_object.h" +#include <vector> + #include "xfa/fxfa/parser/xfa_resolvenode_rs.h" class CXFA_ScriptContext; @@ -23,7 +24,7 @@ class CXFA_NodeHelper { ~CXFA_NodeHelper(); CXFA_Node* ResolveNodes_GetOneChild(CXFA_Node* parent, - const FX_WCHAR* pwsName, + const wchar_t* pwsName, bool bIsClassName = false); CXFA_Node* ResolveNodes_GetParent( CXFA_Node* pNode, @@ -31,17 +32,17 @@ class CXFA_NodeHelper { int32_t NodeAcc_TraverseSiblings(CXFA_Node* parent, uint32_t dNameHash, - CXFA_NodeArray* pSiblings, + std::vector<CXFA_Node*>* pSiblings, XFA_LOGIC_TYPE eLogicType, bool bIsClassName = false, bool bIsFindProperty = true); int32_t NodeAcc_TraverseAnySiblings(CXFA_Node* parent, uint32_t dNameHash, - CXFA_NodeArray* pSiblings, + std::vector<CXFA_Node*>* pSiblings, bool bIsClassName = false); int32_t CountSiblings(CXFA_Node* pNode, XFA_LOGIC_TYPE eLogicType, - CXFA_NodeArray* pSiblings, + std::vector<CXFA_Node*>* pSiblings, bool bIsClassName = false); int32_t GetIndex(CXFA_Node* pNode, XFA_LOGIC_TYPE eLogicType = XFA_LOGIC_NoTransparent, @@ -60,7 +61,6 @@ class CXFA_NodeHelper { void SetCreateNodeType(CXFA_Node* refNode); bool NodeIsProperty(CXFA_Node* refNode); - public: XFA_Element m_eLastCreateType; CXFA_Node* m_pCreateParent; int32_t m_iCreateCount; diff --git a/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_nodelist.cpp b/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_nodelist.cpp index 97c531f33b6..86efb29eba6 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_nodelist.cpp +++ b/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_nodelist.cpp @@ -4,12 +4,13 @@ // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com -#include "xfa/fxfa/parser/xfa_object.h" +#include "xfa/fxfa/parser/cxfa_nodelist.h" #include <memory> #include "core/fxcrt/fx_ext.h" #include "xfa/fxfa/parser/cxfa_document.h" +#include "xfa/fxfa/parser/cxfa_node.h" #include "xfa/fxfa/parser/cxfa_scriptcontext.h" CXFA_NodeList::CXFA_NodeList(CXFA_Document* pDocument) diff --git a/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_nodelist.h b/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_nodelist.h new file mode 100644 index 00000000000..6fffb7bb67b --- /dev/null +++ b/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_nodelist.h @@ -0,0 +1,40 @@ +// Copyright 2017 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#ifndef XFA_FXFA_PARSER_CXFA_NODELIST_H_ +#define XFA_FXFA_PARSER_CXFA_NODELIST_H_ + +#include "xfa/fxfa/fxfa_basic.h" +#include "xfa/fxfa/parser/cxfa_object.h" + +class CXFA_Node; +class CFXJSE_Arguments; +class CFXJSE_Value; + +class CXFA_NodeList : public CXFA_Object { + public: + explicit CXFA_NodeList(CXFA_Document* pDocument); + ~CXFA_NodeList() override; + + CXFA_Node* NamedItem(const CFX_WideStringC& wsName); + virtual int32_t GetLength() = 0; + virtual bool Append(CXFA_Node* pNode) = 0; + virtual bool Insert(CXFA_Node* pNewNode, CXFA_Node* pBeforeNode) = 0; + virtual bool Remove(CXFA_Node* pNode) = 0; + virtual CXFA_Node* Item(int32_t iIndex) = 0; + + void Script_ListClass_Append(CFXJSE_Arguments* pArguments); + void Script_ListClass_Insert(CFXJSE_Arguments* pArguments); + void Script_ListClass_Remove(CFXJSE_Arguments* pArguments); + void Script_ListClass_Item(CFXJSE_Arguments* pArguments); + + void Script_TreelistClass_NamedItem(CFXJSE_Arguments* pArguments); + void Script_ListClass_Length(CFXJSE_Value* pValue, + bool bSetting, + XFA_ATTRIBUTE eAttribute); +}; + +#endif // XFA_FXFA_PARSER_CXFA_NODELIST_H_ diff --git a/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_nodelocale.cpp b/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_nodelocale.cpp new file mode 100644 index 00000000000..78b0cef2782 --- /dev/null +++ b/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_nodelocale.cpp @@ -0,0 +1,175 @@ +// Copyright 2014 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#include "xfa/fxfa/parser/cxfa_nodelocale.h" + +#include <utility> + +#include "core/fxcrt/xml/cxml_element.h" +#include "xfa/fxfa/parser/cxfa_document.h" +#include "xfa/fxfa/parser/cxfa_localemgr.h" +#include "xfa/fxfa/parser/cxfa_node.h" +#include "xfa/fxfa/parser/cxfa_timezoneprovider.h" +#include "xfa/fxfa/parser/xfa_utils.h" + +namespace { + +const wchar_t g_FX_Percent[] = L"z,zzz,zzz,zzz,zzz,zzz%"; +const wchar_t g_FX_Currency[] = L"$z,zzz,zzz,zzz,zzz,zz9.99"; +const wchar_t g_FX_Decimal[] = L"z,zzz,zzz,zzz,zzz,zz9.zzz"; +const wchar_t g_FX_Integer[] = L"z,zzz,zzz,zzz,zzz,zzz"; + +} // namespace + +CFX_WideString XFA_PatternToString(FX_LOCALENUMSUBCATEGORY category) { + switch (category) { + case FX_LOCALENUMPATTERN_Percent: + return g_FX_Percent; + case FX_LOCALENUMPATTERN_Currency: + return g_FX_Currency; + case FX_LOCALENUMPATTERN_Decimal: + return g_FX_Decimal; + case FX_LOCALENUMPATTERN_Integer: + return g_FX_Integer; + } + return CFX_WideString(); +} + +CXFA_NodeLocale::CXFA_NodeLocale(CXFA_Node* pLocale) : m_pLocale(pLocale) {} + +CXFA_NodeLocale::~CXFA_NodeLocale() {} + +CFX_WideString CXFA_NodeLocale::GetName() const { + return CFX_WideString(m_pLocale ? m_pLocale->GetCData(XFA_ATTRIBUTE_Name) + : nullptr); +} + +CFX_WideString CXFA_NodeLocale::GetNumbericSymbol( + FX_LOCALENUMSYMBOL eType) const { + switch (eType) { + case FX_LOCALENUMSYMBOL_Decimal: + return GetSymbol(XFA_Element::NumberSymbols, L"decimal"); + case FX_LOCALENUMSYMBOL_Grouping: + return GetSymbol(XFA_Element::NumberSymbols, L"grouping"); + case FX_LOCALENUMSYMBOL_Percent: + return GetSymbol(XFA_Element::NumberSymbols, L"percent"); + case FX_LOCALENUMSYMBOL_Minus: + return GetSymbol(XFA_Element::NumberSymbols, L"minus"); + case FX_LOCALENUMSYMBOL_Zero: + return GetSymbol(XFA_Element::NumberSymbols, L"zero"); + case FX_LOCALENUMSYMBOL_CurrencySymbol: + return GetSymbol(XFA_Element::CurrencySymbols, L"symbol"); + case FX_LOCALENUMSYMBOL_CurrencyName: + return GetSymbol(XFA_Element::CurrencySymbols, L"isoname"); + } + return CFX_WideString(); +} + +CFX_WideString CXFA_NodeLocale::GetDateTimeSymbols() const { + CXFA_Node* pSymbols = + m_pLocale ? m_pLocale->GetChild(0, XFA_Element::DateTimeSymbols) + : nullptr; + return pSymbols ? pSymbols->GetContent() : CFX_WideString(); +} + +CFX_WideString CXFA_NodeLocale::GetMonthName(int32_t nMonth, bool bAbbr) const { + return GetCalendarSymbol(XFA_Element::MonthNames, nMonth, bAbbr); +} + +CFX_WideString CXFA_NodeLocale::GetDayName(int32_t nWeek, bool bAbbr) const { + return GetCalendarSymbol(XFA_Element::DayNames, nWeek, bAbbr); +} + +CFX_WideString CXFA_NodeLocale::GetMeridiemName(bool bAM) const { + return GetCalendarSymbol(XFA_Element::MeridiemNames, bAM ? 0 : 1, false); +} + +FX_TIMEZONE CXFA_NodeLocale::GetTimeZone() const { + return CXFA_TimeZoneProvider().GetTimeZone(); +} + +CFX_WideString CXFA_NodeLocale::GetEraName(bool bAD) const { + return GetCalendarSymbol(XFA_Element::EraNames, bAD ? 1 : 0, false); +} + +CFX_WideString CXFA_NodeLocale::GetDatePattern( + FX_LOCALEDATETIMESUBCATEGORY eType) const { + switch (eType) { + case FX_LOCALEDATETIMESUBCATEGORY_Short: + return GetSymbol(XFA_Element::DatePatterns, L"short"); + case FX_LOCALEDATETIMESUBCATEGORY_Medium: + case FX_LOCALEDATETIMESUBCATEGORY_Default: + return GetSymbol(XFA_Element::DatePatterns, L"med"); + case FX_LOCALEDATETIMESUBCATEGORY_Full: + return GetSymbol(XFA_Element::DatePatterns, L"full"); + case FX_LOCALEDATETIMESUBCATEGORY_Long: + return GetSymbol(XFA_Element::DatePatterns, L"long"); + } + return CFX_WideString(); +} + +CFX_WideString CXFA_NodeLocale::GetTimePattern( + FX_LOCALEDATETIMESUBCATEGORY eType) const { + switch (eType) { + case FX_LOCALEDATETIMESUBCATEGORY_Short: + return GetSymbol(XFA_Element::TimePatterns, L"short"); + case FX_LOCALEDATETIMESUBCATEGORY_Medium: + case FX_LOCALEDATETIMESUBCATEGORY_Default: + return GetSymbol(XFA_Element::TimePatterns, L"med"); + case FX_LOCALEDATETIMESUBCATEGORY_Full: + return GetSymbol(XFA_Element::TimePatterns, L"full"); + case FX_LOCALEDATETIMESUBCATEGORY_Long: + return GetSymbol(XFA_Element::TimePatterns, L"long"); + } + return CFX_WideString(); +} + +CFX_WideString CXFA_NodeLocale::GetNumPattern( + FX_LOCALENUMSUBCATEGORY eType) const { + return XFA_PatternToString(eType); +} + +CXFA_Node* CXFA_NodeLocale::GetNodeByName(CXFA_Node* pParent, + const CFX_WideStringC& wsName) const { + CXFA_Node* pChild = + pParent ? pParent->GetNodeItem(XFA_NODEITEM_FirstChild) : nullptr; + while (pChild) { + CFX_WideString wsChild; + if (pChild->GetAttribute(XFA_ATTRIBUTE_Name, wsChild)) { + if (wsChild == wsName) + return pChild; + } + pChild = pChild->GetNodeItem(XFA_NODEITEM_NextSibling); + } + return nullptr; +} + +CFX_WideString CXFA_NodeLocale::GetSymbol( + XFA_Element eElement, + const CFX_WideStringC& symbol_type) const { + CXFA_Node* pSymbols = m_pLocale ? m_pLocale->GetChild(0, eElement) : nullptr; + CXFA_Node* pSymbol = GetNodeByName(pSymbols, symbol_type); + return pSymbol ? pSymbol->GetContent() : CFX_WideString(); +} + +CFX_WideString CXFA_NodeLocale::GetCalendarSymbol(XFA_Element eElement, + int index, + bool bAbbr) const { + CXFA_Node* pCalendar = + m_pLocale ? m_pLocale->GetChild(0, XFA_Element::CalendarSymbols) + : nullptr; + if (!pCalendar) + return CFX_WideString(); + + CXFA_Node* pNode = pCalendar->GetFirstChildByClass(eElement); + for (; pNode; pNode = pNode->GetNextSameClassSibling(eElement)) { + if (pNode->GetBoolean(XFA_ATTRIBUTE_Abbr) == bAbbr) { + CXFA_Node* pSymbol = pNode->GetChild(index, XFA_Element::Unknown); + return pSymbol ? pSymbol->GetContent() : CFX_WideString(); + } + } + return CFX_WideString(); +} diff --git a/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_nodelocale.h b/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_nodelocale.h new file mode 100644 index 00000000000..2465650b473 --- /dev/null +++ b/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_nodelocale.h @@ -0,0 +1,53 @@ +// Copyright 2014 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#ifndef XFA_FXFA_PARSER_CXFA_NODELOCALE_H_ +#define XFA_FXFA_PARSER_CXFA_NODELOCALE_H_ + +#include <memory> + +#include "core/fxcrt/ifx_locale.h" +#include "xfa/fxfa/fxfa_basic.h" + +class CXFA_Node; + +CFX_WideString XFA_PatternToString(FX_LOCALENUMSUBCATEGORY category); + +class CXFA_NodeLocale : public IFX_Locale { + public: + explicit CXFA_NodeLocale(CXFA_Node* pLocale); + ~CXFA_NodeLocale() override; + + // IFX_Locale + CFX_WideString GetName() const override; + CFX_WideString GetNumbericSymbol(FX_LOCALENUMSYMBOL eType) const override; + + CFX_WideString GetDateTimeSymbols() const override; + CFX_WideString GetMonthName(int32_t nMonth, bool bAbbr) const override; + CFX_WideString GetDayName(int32_t nWeek, bool bAbbr) const override; + CFX_WideString GetMeridiemName(bool bAM) const override; + FX_TIMEZONE GetTimeZone() const override; + CFX_WideString GetEraName(bool bAD) const override; + + CFX_WideString GetDatePattern( + FX_LOCALEDATETIMESUBCATEGORY eType) const override; + CFX_WideString GetTimePattern( + FX_LOCALEDATETIMESUBCATEGORY eType) const override; + CFX_WideString GetNumPattern(FX_LOCALENUMSUBCATEGORY eType) const override; + + private: + CXFA_Node* GetNodeByName(CXFA_Node* pParent, + const CFX_WideStringC& wsName) const; + CFX_WideString GetSymbol(XFA_Element eElement, + const CFX_WideStringC& symbol_type) const; + CFX_WideString GetCalendarSymbol(XFA_Element eElement, + int index, + bool bAbbr) const; + + CXFA_Node* const m_pLocale; +}; + +#endif // XFA_FXFA_PARSER_CXFA_NODELOCALE_H_ diff --git a/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_object.cpp b/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_object.cpp index c8cd354b485..9bbee4ec758 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_object.cpp +++ b/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_object.cpp @@ -4,12 +4,14 @@ // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com -#include "xfa/fxfa/parser/xfa_object.h" +#include "xfa/fxfa/parser/cxfa_object.h" #include "core/fxcrt/fx_ext.h" #include "fxjs/cfxjse_value.h" #include "xfa/fxfa/app/xfa_ffnotify.h" #include "xfa/fxfa/parser/cxfa_document.h" +#include "xfa/fxfa/parser/cxfa_node.h" +#include "xfa/fxfa/parser/cxfa_nodelist.h" CXFA_Object::CXFA_Object(CXFA_Document* pDocument, XFA_ObjectType objectType, @@ -23,18 +25,6 @@ CXFA_Object::CXFA_Object(CXFA_Document* pDocument, CXFA_Object::~CXFA_Object() {} -CFX_WideStringC CXFA_Object::GetClassName() const { - return m_elementName; -} - -uint32_t CXFA_Object::GetClassHashCode() const { - return m_elementNameHash; -} - -XFA_Element CXFA_Object::GetElementType() const { - return m_elementType; -} - void CXFA_Object::Script_ObjectClass_ClassName(CFXJSE_Value* pValue, bool bSetting, XFA_ATTRIBUTE eAttribute) { @@ -63,7 +53,7 @@ void CXFA_Object::ThrowArgumentMismatchException() const { ThrowException(L"Argument mismatch in property or function argument."); } -void CXFA_Object::ThrowException(const FX_WCHAR* str, ...) const { +void CXFA_Object::ThrowException(const wchar_t* str, ...) const { CFX_WideString wsMessage; va_list arg_ptr; va_start(arg_ptr, str); @@ -71,3 +61,27 @@ void CXFA_Object::ThrowException(const FX_WCHAR* str, ...) const { va_end(arg_ptr); FXJSE_ThrowMessage(wsMessage.UTF8Encode().AsStringC()); } + +CXFA_Node* CXFA_Object::AsNode() { + return IsNode() ? static_cast<CXFA_Node*>(this) : nullptr; +} + +CXFA_NodeList* CXFA_Object::AsNodeList() { + return IsNodeList() ? static_cast<CXFA_NodeList*>(this) : nullptr; +} + +const CXFA_Node* CXFA_Object::AsNode() const { + return IsNode() ? static_cast<const CXFA_Node*>(this) : nullptr; +} + +const CXFA_NodeList* CXFA_Object::AsNodeList() const { + return IsNodeList() ? static_cast<const CXFA_NodeList*>(this) : nullptr; +} + +CXFA_Node* ToNode(CXFA_Object* pObj) { + return pObj ? pObj->AsNode() : nullptr; +} + +const CXFA_Node* ToNode(const CXFA_Object* pObj) { + return pObj ? pObj->AsNode() : nullptr; +} diff --git a/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_object.h b/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_object.h new file mode 100644 index 00000000000..95964537127 --- /dev/null +++ b/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_object.h @@ -0,0 +1,100 @@ +// Copyright 2017 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#ifndef XFA_FXFA_PARSER_CXFA_OBJECT_H_ +#define XFA_FXFA_PARSER_CXFA_OBJECT_H_ + +#include "core/fxcrt/fx_string.h" +#include "fxjs/fxjse.h" +#include "xfa/fxfa/fxfa_basic.h" + +enum class XFA_ObjectType { + Object, + List, + NodeList, + Node, + NodeC, + NodeV, + ModelNode, + TextNode, + ContainerNode, + ContentNode, + VariablesThis +}; + +class CFXJSE_Value; +class CXFA_Document; +class CXFA_Node; +class CXFA_NodeList; + +class CXFA_Object : public CFXJSE_HostObject { + public: + CXFA_Object(CXFA_Document* pDocument, + XFA_ObjectType objectType, + XFA_Element eType, + const CFX_WideStringC& elementName); + ~CXFA_Object() override; + + CXFA_Document* GetDocument() const { return m_pDocument; } + XFA_ObjectType GetObjectType() const { return m_objectType; } + + bool IsNode() const { + return m_objectType == XFA_ObjectType::Node || + m_objectType == XFA_ObjectType::NodeC || + m_objectType == XFA_ObjectType::NodeV || + m_objectType == XFA_ObjectType::ModelNode || + m_objectType == XFA_ObjectType::TextNode || + m_objectType == XFA_ObjectType::ContainerNode || + m_objectType == XFA_ObjectType::ContentNode || + m_objectType == XFA_ObjectType::VariablesThis; + } + bool IsNodeList() const { return m_objectType == XFA_ObjectType::NodeList; } + bool IsContentNode() const { + return m_objectType == XFA_ObjectType::ContentNode; + } + bool IsContainerNode() const { + return m_objectType == XFA_ObjectType::ContainerNode; + } + bool IsModelNode() const { return m_objectType == XFA_ObjectType::ModelNode; } + bool IsNodeV() const { return m_objectType == XFA_ObjectType::NodeV; } + bool IsVariablesThis() const { + return m_objectType == XFA_ObjectType::VariablesThis; + } + + CXFA_Node* AsNode(); + CXFA_NodeList* AsNodeList(); + + const CXFA_Node* AsNode() const; + const CXFA_NodeList* AsNodeList() const; + + XFA_Element GetElementType() const { return m_elementType; } + CFX_WideStringC GetClassName() const { return m_elementName; } + uint32_t GetClassHashCode() const { return m_elementNameHash; } + + void Script_ObjectClass_ClassName(CFXJSE_Value* pValue, + bool bSetting, + XFA_ATTRIBUTE eAttribute); + + void ThrowInvalidPropertyException() const; + void ThrowArgumentMismatchException() const; + void ThrowIndexOutOfBoundsException() const; + void ThrowParamCountMismatchException(const CFX_WideString& method) const; + + protected: + void ThrowException(const wchar_t* str, ...) const; + + CXFA_Document* const m_pDocument; + const XFA_ObjectType m_objectType; + const XFA_Element m_elementType; + + const uint32_t m_elementNameHash; + const CFX_WideStringC m_elementName; +}; + +CXFA_Node* ToNode(CXFA_Object* pObj); +const CXFA_Node* ToNode(const CXFA_Object* pObj); + +#endif // XFA_FXFA_PARSER_CXFA_OBJECT_H_ diff --git a/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_occur.cpp b/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_occur.cpp index a8994223f93..ddce8d6422a 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_occur.cpp +++ b/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_occur.cpp @@ -6,7 +6,7 @@ #include "xfa/fxfa/parser/cxfa_occur.h" -#include "xfa/fxfa/parser/xfa_object.h" +#include "xfa/fxfa/parser/cxfa_node.h" CXFA_Occur::CXFA_Occur(CXFA_Node* pNode) : CXFA_Data(pNode) {} diff --git a/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_para.cpp b/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_para.cpp index bd3a1bb8ff0..c3d55f21648 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_para.cpp +++ b/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_para.cpp @@ -7,7 +7,7 @@ #include "xfa/fxfa/parser/cxfa_para.h" #include "xfa/fxfa/parser/cxfa_measurement.h" -#include "xfa/fxfa/parser/xfa_object.h" +#include "xfa/fxfa/parser/cxfa_node.h" CXFA_Para::CXFA_Para(CXFA_Node* pNode) : CXFA_Data(pNode) {} @@ -23,37 +23,37 @@ int32_t CXFA_Para::GetVerticalAlign() { return eAttr; } -FX_FLOAT CXFA_Para::GetLineHeight() { +float CXFA_Para::GetLineHeight() { CXFA_Measurement ms; m_pNode->TryMeasure(XFA_ATTRIBUTE_LineHeight, ms); return ms.ToUnit(XFA_UNIT_Pt); } -FX_FLOAT CXFA_Para::GetMarginLeft() { +float CXFA_Para::GetMarginLeft() { CXFA_Measurement ms; m_pNode->TryMeasure(XFA_ATTRIBUTE_MarginLeft, ms); return ms.ToUnit(XFA_UNIT_Pt); } -FX_FLOAT CXFA_Para::GetMarginRight() { +float CXFA_Para::GetMarginRight() { CXFA_Measurement ms; m_pNode->TryMeasure(XFA_ATTRIBUTE_MarginRight, ms); return ms.ToUnit(XFA_UNIT_Pt); } -FX_FLOAT CXFA_Para::GetSpaceAbove() { +float CXFA_Para::GetSpaceAbove() { CXFA_Measurement ms; m_pNode->TryMeasure(XFA_ATTRIBUTE_SpaceAbove, ms); return ms.ToUnit(XFA_UNIT_Pt); } -FX_FLOAT CXFA_Para::GetSpaceBelow() { +float CXFA_Para::GetSpaceBelow() { CXFA_Measurement ms; m_pNode->TryMeasure(XFA_ATTRIBUTE_SpaceBelow, ms); return ms.ToUnit(XFA_UNIT_Pt); } -FX_FLOAT CXFA_Para::GetTextIndent() { +float CXFA_Para::GetTextIndent() { CXFA_Measurement ms; m_pNode->TryMeasure(XFA_ATTRIBUTE_TextIndent, ms); return ms.ToUnit(XFA_UNIT_Pt); diff --git a/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_para.h b/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_para.h index e12d48f9fa3..c2d67b8a199 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_para.h +++ b/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_para.h @@ -18,12 +18,12 @@ class CXFA_Para : public CXFA_Data { int32_t GetHorizontalAlign(); int32_t GetVerticalAlign(); - FX_FLOAT GetLineHeight(); - FX_FLOAT GetMarginLeft(); - FX_FLOAT GetMarginRight(); - FX_FLOAT GetSpaceAbove(); - FX_FLOAT GetSpaceBelow(); - FX_FLOAT GetTextIndent(); + float GetLineHeight(); + float GetMarginLeft(); + float GetMarginRight(); + float GetSpaceAbove(); + float GetSpaceBelow(); + float GetTextIndent(); }; #endif // XFA_FXFA_PARSER_CXFA_PARA_H_ diff --git a/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_resolveprocessor.cpp b/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_resolveprocessor.cpp index 3ef4e976cab..51487a1e2bb 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_resolveprocessor.cpp +++ b/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_resolveprocessor.cpp @@ -6,12 +6,19 @@ #include "xfa/fxfa/parser/cxfa_resolveprocessor.h" +#include <algorithm> +#include <utility> +#include <vector> + #include "core/fxcrt/fx_ext.h" +#include "third_party/base/ptr_util.h" +#include "third_party/base/stl_util.h" #include "xfa/fxfa/parser/cxfa_document.h" +#include "xfa/fxfa/parser/cxfa_localemgr.h" +#include "xfa/fxfa/parser/cxfa_node.h" #include "xfa/fxfa/parser/cxfa_nodehelper.h" +#include "xfa/fxfa/parser/cxfa_object.h" #include "xfa/fxfa/parser/cxfa_scriptcontext.h" -#include "xfa/fxfa/parser/xfa_localemgr.h" -#include "xfa/fxfa/parser/xfa_object.h" #include "xfa/fxfa/parser/xfa_resolvenode_rs.h" #include "xfa/fxfa/parser/xfa_utils.h" @@ -21,12 +28,12 @@ CXFA_ResolveProcessor::CXFA_ResolveProcessor() CXFA_ResolveProcessor::~CXFA_ResolveProcessor() {} int32_t CXFA_ResolveProcessor::Resolve(CXFA_ResolveNodesData& rnd) { - if (!rnd.m_CurNode) { + if (!rnd.m_CurObject) return -1; - } - if (!rnd.m_CurNode->IsNode()) { + + if (!rnd.m_CurObject->IsNode()) { if (rnd.m_dwStyles & XFA_RESOLVENODE_Attributes) { - return ResolveForAttributeRs(rnd.m_CurNode, rnd, + return ResolveForAttributeRs(rnd.m_CurObject, rnd, rnd.m_wsName.AsStringC()); } return 0; @@ -34,7 +41,7 @@ int32_t CXFA_ResolveProcessor::Resolve(CXFA_ResolveNodesData& rnd) { if (rnd.m_dwStyles & XFA_RESOLVENODE_AnyChild) { return ResolveAnyChild(rnd); } - FX_WCHAR wch = rnd.m_wsName.GetAt(0); + wchar_t wch = rnd.m_wsName.GetAt(0); switch (wch) { case '$': return ResolveDollar(rnd); @@ -51,62 +58,66 @@ int32_t CXFA_ResolveProcessor::Resolve(CXFA_ResolveNodesData& rnd) { break; } if (rnd.m_uHashName == XFA_HASHCODE_This && rnd.m_nLevel == 0) { - rnd.m_Nodes.Add(rnd.m_pSC->GetThisObject()); + rnd.m_Objects.push_back(rnd.m_pSC->GetThisObject()); return 1; - } else if (rnd.m_CurNode->GetElementType() == XFA_Element::Xfa) { + } + if (rnd.m_CurObject->GetElementType() == XFA_Element::Xfa) { CXFA_Object* pObjNode = rnd.m_pSC->GetDocument()->GetXFAObject(rnd.m_uHashName); if (pObjNode) { - rnd.m_Nodes.Add(pObjNode); + rnd.m_Objects.push_back(pObjNode); } else if (rnd.m_uHashName == XFA_HASHCODE_Xfa) { - rnd.m_Nodes.Add(rnd.m_CurNode); + rnd.m_Objects.push_back(rnd.m_CurObject); } else if ((rnd.m_dwStyles & XFA_RESOLVENODE_Attributes) && - ResolveForAttributeRs(rnd.m_CurNode, rnd, + ResolveForAttributeRs(rnd.m_CurObject, rnd, rnd.m_wsName.AsStringC())) { return 1; } - if (rnd.m_Nodes.GetSize() > 0) { + if (!rnd.m_Objects.empty()) FilterCondition(rnd, rnd.m_wsCondition); - } - return rnd.m_Nodes.GetSize(); - } - int32_t nRet = ResolveNormal(rnd); - if (nRet < 1 && rnd.m_uHashName == XFA_HASHCODE_Xfa) { - rnd.m_Nodes.Add(rnd.m_pSC->GetDocument()->GetRoot()); + + return pdfium::CollectionSize<int32_t>(rnd.m_Objects); } - return rnd.m_Nodes.GetSize(); + if (ResolveNormal(rnd) < 1 && rnd.m_uHashName == XFA_HASHCODE_Xfa) + rnd.m_Objects.push_back(rnd.m_pSC->GetDocument()->GetRoot()); + + return pdfium::CollectionSize<int32_t>(rnd.m_Objects); } + int32_t CXFA_ResolveProcessor::ResolveAnyChild(CXFA_ResolveNodesData& rnd) { CFX_WideString wsName = rnd.m_wsName; CFX_WideString wsCondition = rnd.m_wsCondition; CXFA_Node* findNode = nullptr; - CXFA_NodeArray siblings; bool bClassName = false; if (wsName.GetAt(0) == '#') { bClassName = true; wsName = wsName.Right(wsName.GetLength() - 1); } findNode = m_pNodeHelper->ResolveNodes_GetOneChild( - ToNode(rnd.m_CurNode), wsName.c_str(), bClassName); + ToNode(rnd.m_CurObject), wsName.c_str(), bClassName); if (!findNode) { return 0; } if (wsCondition.IsEmpty()) { - rnd.m_Nodes.Add(findNode); - return rnd.m_Nodes.GetSize(); - } - m_pNodeHelper->CountSiblings(findNode, XFA_LOGIC_Transparent, - (CXFA_NodeArray*)&rnd.m_Nodes, bClassName); + rnd.m_Objects.push_back(findNode); + return pdfium::CollectionSize<int32_t>(rnd.m_Objects); + } + std::vector<CXFA_Node*> tempNodes; + for (CXFA_Object* pObject : rnd.m_Objects) + tempNodes.push_back(pObject->AsNode()); + m_pNodeHelper->CountSiblings(findNode, XFA_LOGIC_Transparent, &tempNodes, + bClassName); + rnd.m_Objects = std::vector<CXFA_Object*>(tempNodes.begin(), tempNodes.end()); FilterCondition(rnd, wsCondition); - return rnd.m_Nodes.GetSize(); + return pdfium::CollectionSize<int32_t>(rnd.m_Objects); } + int32_t CXFA_ResolveProcessor::ResolveDollar(CXFA_ResolveNodesData& rnd) { - CXFA_ObjArray& nodes = rnd.m_Nodes; CFX_WideString wsName = rnd.m_wsName; CFX_WideString wsCondition = rnd.m_wsCondition; int32_t iNameLen = wsName.GetLength(); if (iNameLen == 1) { - nodes.Add(rnd.m_CurNode); + rnd.m_Objects.push_back(rnd.m_CurObject); return 1; } if (rnd.m_nLevel > 0) { @@ -115,30 +126,30 @@ int32_t CXFA_ResolveProcessor::ResolveDollar(CXFA_ResolveNodesData& rnd) { XFA_HashCode dwNameHash = static_cast<XFA_HashCode>(FX_HashCode_GetW( CFX_WideStringC(wsName.c_str() + 1, iNameLen - 1), false)); if (dwNameHash == XFA_HASHCODE_Xfa) { - nodes.Add(rnd.m_pSC->GetDocument()->GetRoot()); + rnd.m_Objects.push_back(rnd.m_pSC->GetDocument()->GetRoot()); } else { CXFA_Object* pObjNode = rnd.m_pSC->GetDocument()->GetXFAObject(dwNameHash); - if (pObjNode) { - rnd.m_Nodes.Add(pObjNode); - } + if (pObjNode) + rnd.m_Objects.push_back(pObjNode); } - if (rnd.m_Nodes.GetSize() > 0) { + if (!rnd.m_Objects.empty()) FilterCondition(rnd, wsCondition); - } - return rnd.m_Nodes.GetSize(); + + return pdfium::CollectionSize<int32_t>(rnd.m_Objects); } + int32_t CXFA_ResolveProcessor::ResolveExcalmatory(CXFA_ResolveNodesData& rnd) { - if (rnd.m_nLevel > 0) { + if (rnd.m_nLevel > 0) return 0; - } + CXFA_Node* datasets = ToNode(rnd.m_pSC->GetDocument()->GetXFAObject(XFA_HASHCODE_Datasets)); - if (!datasets) { + if (!datasets) return 0; - } + CXFA_ResolveNodesData rndFind; rndFind.m_pSC = rnd.m_pSC; - rndFind.m_CurNode = datasets; + rndFind.m_CurObject = datasets; rndFind.m_wsName = rnd.m_wsName.Right(rnd.m_wsName.GetLength() - 1); rndFind.m_uHashName = static_cast<XFA_HashCode>( FX_HashCode_GetW(rndFind.m_wsName.AsStringC(), false)); @@ -146,19 +157,18 @@ int32_t CXFA_ResolveProcessor::ResolveExcalmatory(CXFA_ResolveNodesData& rnd) { rndFind.m_dwStyles = XFA_RESOLVENODE_Children; rndFind.m_wsCondition = rnd.m_wsCondition; Resolve(rndFind); - if (rndFind.m_Nodes.GetSize() > 0) { - rnd.m_Nodes.Append(rndFind.m_Nodes); - rndFind.m_Nodes.RemoveAll(); - } - return rnd.m_Nodes.GetSize(); + rnd.m_Objects.insert(rnd.m_Objects.end(), rndFind.m_Objects.begin(), + rndFind.m_Objects.end()); + return pdfium::CollectionSize<int32_t>(rnd.m_Objects); } + int32_t CXFA_ResolveProcessor::ResolveNumberSign(CXFA_ResolveNodesData& rnd) { CFX_WideString wsName = rnd.m_wsName.Right(rnd.m_wsName.GetLength() - 1); CFX_WideString wsCondition = rnd.m_wsCondition; - CXFA_Node* curNode = ToNode(rnd.m_CurNode); - if (ResolveForAttributeRs(curNode, rnd, wsName.AsStringC())) { + CXFA_Node* curNode = ToNode(rnd.m_CurObject); + if (ResolveForAttributeRs(curNode, rnd, wsName.AsStringC())) return 1; - } + CXFA_ResolveNodesData rndFind; rndFind.m_pSC = rnd.m_pSC; rndFind.m_nLevel = rnd.m_nLevel + 1; @@ -169,42 +179,42 @@ int32_t CXFA_ResolveProcessor::ResolveNumberSign(CXFA_ResolveNodesData& rnd) { rndFind.m_uHashName = static_cast<XFA_HashCode>( FX_HashCode_GetW(rndFind.m_wsName.AsStringC(), false)); rndFind.m_wsCondition = wsCondition; - rndFind.m_CurNode = curNode; + rndFind.m_CurObject = curNode; ResolveNormal(rndFind); - if (rndFind.m_Nodes.GetSize() > 0) { - if (wsCondition.GetLength() == 0 && rndFind.m_Nodes.Find(curNode) >= 0) { - rnd.m_Nodes.Add(curNode); - } else { - rnd.m_Nodes.Append(rndFind.m_Nodes); - rndFind.m_Nodes.RemoveAll(); - } + if (rndFind.m_Objects.empty()) + return 0; + + if (wsCondition.GetLength() == 0 && + pdfium::ContainsValue(rndFind.m_Objects, curNode)) { + rnd.m_Objects.push_back(curNode); + } else { + rnd.m_Objects.insert(rnd.m_Objects.end(), rndFind.m_Objects.begin(), + rndFind.m_Objects.end()); } - return rnd.m_Nodes.GetSize(); + return pdfium::CollectionSize<int32_t>(rnd.m_Objects); } + int32_t CXFA_ResolveProcessor::ResolveForAttributeRs( CXFA_Object* curNode, CXFA_ResolveNodesData& rnd, const CFX_WideStringC& strAttr) { const XFA_SCRIPTATTRIBUTEINFO* lpScriptAttribute = XFA_GetScriptAttributeByName(curNode->GetElementType(), strAttr); - if (lpScriptAttribute) { - rnd.m_pScriptAttribute = lpScriptAttribute; - rnd.m_Nodes.Add(curNode); - rnd.m_dwFlag = XFA_RESOVENODE_RSTYPE_Attribute; - return 1; - } - return 0; + if (!lpScriptAttribute) + return 0; + + rnd.m_pScriptAttribute = lpScriptAttribute; + rnd.m_Objects.push_back(curNode); + rnd.m_dwFlag = XFA_RESOVENODE_RSTYPE_Attribute; + return 1; } + int32_t CXFA_ResolveProcessor::ResolveNormal(CXFA_ResolveNodesData& rnd) { - if (rnd.m_nLevel > 32) { - return 0; - } - if (!rnd.m_CurNode->IsNode()) { + if (rnd.m_nLevel > 32 || !rnd.m_CurObject->IsNode()) return 0; - } - CXFA_Node* curNode = ToNode(rnd.m_CurNode); - CXFA_ObjArray& nodes = rnd.m_Nodes; - int32_t nNum = nodes.GetSize(); + + CXFA_Node* curNode = rnd.m_CurObject->AsNode(); + size_t nNum = rnd.m_Objects.size(); uint32_t dwStyles = rnd.m_dwStyles; CFX_WideString& wsName = rnd.m_wsName; XFA_HashCode uNameHash = rnd.m_uHashName; @@ -215,69 +225,59 @@ int32_t CXFA_ResolveProcessor::ResolveNormal(CXFA_ResolveNodesData& rnd) { rndFind.m_pSC = rnd.m_pSC; rndFind.m_nLevel = rnd.m_nLevel + 1; rndFind.m_uHashName = uNameHash; - CXFA_NodeArray children; - CXFA_NodeArray properties; + std::vector<CXFA_Node*> children; + std::vector<CXFA_Node*> properties; CXFA_Node* pVariablesNode = nullptr; CXFA_Node* pPageSetNode = nullptr; - CXFA_Node* pChild = curNode->GetNodeItem(XFA_NODEITEM_FirstChild); - while (pChild) { + for (CXFA_Node* pChild = curNode->GetNodeItem(XFA_NODEITEM_FirstChild); + pChild; pChild = pChild->GetNodeItem(XFA_NODEITEM_NextSibling)) { if (pChild->GetElementType() == XFA_Element::Variables) { pVariablesNode = pChild; - pChild = pChild->GetNodeItem(XFA_NODEITEM_NextSibling); continue; - } else if (pChild->GetElementType() == XFA_Element::PageSet) { + } + if (pChild->GetElementType() == XFA_Element::PageSet) { pPageSetNode = pChild; - pChild = pChild->GetNodeItem(XFA_NODEITEM_NextSibling); continue; - } else { - const XFA_PROPERTY* pPropert = XFA_GetPropertyOfElement( - curNode->GetElementType(), pChild->GetElementType(), - XFA_XDPPACKET_UNKNOWN); - if (pPropert) { - properties.Add(pChild); - } else { - children.Add(pChild); - } } - pChild = pChild->GetNodeItem(XFA_NODEITEM_NextSibling); + const XFA_PROPERTY* pProperty = XFA_GetPropertyOfElement( + curNode->GetElementType(), pChild->GetElementType(), + XFA_XDPPACKET_UNKNOWN); + if (pProperty) + properties.push_back(pChild); + else + children.push_back(pChild); } if ((dwStyles & XFA_RESOLVENODE_Properties) && pVariablesNode) { uint32_t uPropHash = pVariablesNode->GetClassHashCode(); if (uPropHash == uNameHash) { - nodes.Add(pVariablesNode); + rnd.m_Objects.push_back(pVariablesNode); } else { - rndFind.m_CurNode = pVariablesNode; + rndFind.m_CurObject = pVariablesNode; SetStylesForChild(dwStyles, rndFind); CFX_WideString wsSaveCondition = rndFind.m_wsCondition; rndFind.m_wsCondition.clear(); ResolveNormal(rndFind); rndFind.m_wsCondition = wsSaveCondition; - if (rndFind.m_Nodes.GetSize() > 0) { - nodes.Append(rndFind.m_Nodes); - rndFind.m_Nodes.RemoveAll(); - } + rnd.m_Objects.insert(rnd.m_Objects.end(), rndFind.m_Objects.begin(), + rndFind.m_Objects.end()); + rndFind.m_Objects.clear(); } - if (nodes.GetSize() > nNum) { + if (rnd.m_Objects.size() > nNum) { FilterCondition(rnd, wsCondition); - if (nodes.GetSize() > 0) { - return 1; - } - return 0; + return !rnd.m_Objects.empty() ? 1 : 0; } } if (dwStyles & XFA_RESOLVENODE_Children) { bool bSetFlag = false; - if (pPageSetNode && (dwStyles & XFA_RESOLVENODE_Properties)) { - children.Add(pPageSetNode); - } - for (int32_t i = 0; i < children.GetSize(); i++) { - CXFA_Node* child = children[i]; + if (pPageSetNode && (dwStyles & XFA_RESOLVENODE_Properties)) + children.push_back(pPageSetNode); + + for (CXFA_Node* child : children) { if (dwStyles & XFA_RESOLVENODE_TagName) { - if (child->GetClassHashCode() == uNameHash) { - nodes.Add(child); - } + if (child->GetClassHashCode() == uNameHash) + rnd.m_Objects.push_back(child); } else if (child->GetNameHash() == uNameHash) { - nodes.Add(child); + rnd.m_Objects.push_back(child); } if (m_pNodeHelper->NodeIsTransparent(child) && child->GetElementType() != XFA_Element::PageSet) { @@ -285,64 +285,55 @@ int32_t CXFA_ResolveProcessor::ResolveNormal(CXFA_ResolveNodesData& rnd) { SetStylesForChild(dwStyles, rndFind); bSetFlag = true; } - rndFind.m_CurNode = child; + rndFind.m_CurObject = child; CFX_WideString wsSaveCondition = rndFind.m_wsCondition; rndFind.m_wsCondition.clear(); ResolveNormal(rndFind); rndFind.m_wsCondition = wsSaveCondition; - if (rndFind.m_Nodes.GetSize() > 0) { - nodes.Append(rndFind.m_Nodes); - rndFind.m_Nodes.RemoveAll(); - } + rnd.m_Objects.insert(rnd.m_Objects.end(), rndFind.m_Objects.begin(), + rndFind.m_Objects.end()); + rndFind.m_Objects.clear(); } } - if (nodes.GetSize() > nNum) { + if (rnd.m_Objects.size() > nNum) { if (!(dwStyles & XFA_RESOLVENODE_ALL)) { - CXFA_NodeArray upArrayNodes; + std::vector<CXFA_Node*> upArrayNodes; if (m_pNodeHelper->NodeIsTransparent(ToNode(curNode))) { - m_pNodeHelper->CountSiblings(ToNode(nodes[0]), XFA_LOGIC_Transparent, - &upArrayNodes, + m_pNodeHelper->CountSiblings(ToNode(rnd.m_Objects[0]), + XFA_LOGIC_Transparent, &upArrayNodes, !!(dwStyles & XFA_RESOLVENODE_TagName)); } - if (upArrayNodes.GetSize() > nodes.GetSize()) { - upArrayNodes[0] = ToNode(nodes[0]); - nodes.RemoveAll(); - nodes.Append((CXFA_ObjArray&)upArrayNodes); - upArrayNodes.RemoveAll(); + if (upArrayNodes.size() > rnd.m_Objects.size()) { + CXFA_Object* pSaveObject = rnd.m_Objects.front(); + rnd.m_Objects = std::vector<CXFA_Object*>(upArrayNodes.begin(), + upArrayNodes.end()); + rnd.m_Objects.front() = pSaveObject; } } FilterCondition(rnd, wsCondition); - if (nodes.GetSize() > 0) { - return 1; - } - return 0; + return !rnd.m_Objects.empty() ? 1 : 0; } } if (dwStyles & XFA_RESOLVENODE_Attributes) { - if (ResolveForAttributeRs(curNode, rnd, wsName.AsStringC())) { + if (ResolveForAttributeRs(curNode, rnd, wsName.AsStringC())) return 1; - } } if (dwStyles & XFA_RESOLVENODE_Properties) { - for (int32_t i = 0; i < properties.GetSize(); i++) { - CXFA_Node* childProperty = properties[i]; - if (childProperty->IsUnnamed()) { - uint32_t uPropHash = childProperty->GetClassHashCode(); - if (uPropHash == uNameHash) { - nodes.Add(childProperty); - } - } else if (childProperty->GetNameHash() == uNameHash && - childProperty->GetElementType() != XFA_Element::Extras && - childProperty->GetElementType() != XFA_Element::Items) { - nodes.Add(childProperty); + for (CXFA_Node* pChildProperty : properties) { + if (pChildProperty->IsUnnamed()) { + if (pChildProperty->GetClassHashCode() == uNameHash) + rnd.m_Objects.push_back(pChildProperty); + continue; + } + if (pChildProperty->GetNameHash() == uNameHash && + pChildProperty->GetElementType() != XFA_Element::Extras && + pChildProperty->GetElementType() != XFA_Element::Items) { + rnd.m_Objects.push_back(pChildProperty); } } - if (nodes.GetSize() > nNum) { + if (rnd.m_Objects.size() > nNum) { FilterCondition(rnd, wsCondition); - if (nodes.GetSize() > 0) { - return 1; - } - return 0; + return !rnd.m_Objects.empty() ? 1 : 0; } CXFA_Node* pProp = nullptr; if (XFA_Element::Subform == curNode->GetElementType() && @@ -360,8 +351,8 @@ int32_t CXFA_ResolveProcessor::ResolveNormal(CXFA_ResolveNodesData& rnd) { } } if (pProp) { - nodes.Add(pProp); - return nodes.GetSize(); + rnd.m_Objects.push_back(pProp); + return pdfium::CollectionSize<int32_t>(rnd.m_Objects); } } CXFA_Node* parentNode = m_pNodeHelper->ResolveNodes_GetParent( @@ -369,11 +360,10 @@ int32_t CXFA_ResolveProcessor::ResolveNormal(CXFA_ResolveNodesData& rnd) { uint32_t uCurClassHash = curNode->GetClassHashCode(); if (!parentNode) { if (uCurClassHash == uNameHash) { - nodes.Add(curNode->AsNode()); + rnd.m_Objects.push_back(curNode->AsNode()); FilterCondition(rnd, wsCondition); - if (nodes.GetSize() > 0) { + if (!rnd.m_Objects.empty()) return 1; - } } return 0; } @@ -381,25 +371,23 @@ int32_t CXFA_ResolveProcessor::ResolveNormal(CXFA_ResolveNodesData& rnd) { CXFA_Node* child = parentNode->GetNodeItem(XFA_NODEITEM_FirstChild); uint32_t dwSubStyles = XFA_RESOLVENODE_Children | XFA_RESOLVENODE_Properties; - if (dwStyles & XFA_RESOLVENODE_TagName) { + if (dwStyles & XFA_RESOLVENODE_TagName) dwSubStyles |= XFA_RESOLVENODE_TagName; - } - if (dwStyles & XFA_RESOLVENODE_ALL) { + if (dwStyles & XFA_RESOLVENODE_ALL) dwSubStyles |= XFA_RESOLVENODE_ALL; - } rndFind.m_dwStyles = dwSubStyles; while (child) { if (child == curNode) { if (dwStyles & XFA_RESOLVENODE_TagName) { if (uCurClassHash == uNameHash) { - nodes.Add(curNode); + rnd.m_Objects.push_back(curNode); } } else { if (child->GetNameHash() == uNameHash) { - nodes.Add(curNode); + rnd.m_Objects.push_back(curNode); if (rnd.m_nLevel == 0 && wsCondition.GetLength() == 0) { - nodes.RemoveAll(); - nodes.Add(curNode); + rnd.m_Objects.clear(); + rnd.m_Objects.push_back(curNode); return 1; } } @@ -408,11 +396,10 @@ int32_t CXFA_ResolveProcessor::ResolveNormal(CXFA_ResolveNodesData& rnd) { continue; } if (dwStyles & XFA_RESOLVENODE_TagName) { - if (child->GetClassHashCode() == uNameHash) { - nodes.Add(child); - } + if (child->GetClassHashCode() == uNameHash) + rnd.m_Objects.push_back(child); } else if (child->GetNameHash() == uNameHash) { - nodes.Add(child); + rnd.m_Objects.push_back(child); } const XFA_PROPERTY* pPropert = XFA_GetPropertyOfElement( parentNode->GetElementType(), child->GetElementType(), @@ -429,7 +416,7 @@ int32_t CXFA_ResolveProcessor::ResolveNormal(CXFA_ResolveNodesData& rnd) { } } if (bInnerSearch) { - rndFind.m_CurNode = child; + rndFind.m_CurObject = child; CFX_WideString wsOriginCondition = rndFind.m_wsCondition; rndFind.m_wsCondition.clear(); uint32_t dwOriginStyle = rndFind.m_dwStyles; @@ -437,31 +424,27 @@ int32_t CXFA_ResolveProcessor::ResolveNormal(CXFA_ResolveNodesData& rnd) { ResolveNormal(rndFind); rndFind.m_dwStyles = dwOriginStyle; rndFind.m_wsCondition = wsOriginCondition; - if (rndFind.m_Nodes.GetSize() > 0) { - nodes.Append(rndFind.m_Nodes); - rndFind.m_Nodes.RemoveAll(); - } + rnd.m_Objects.insert(rnd.m_Objects.end(), rndFind.m_Objects.begin(), + rndFind.m_Objects.end()); + rndFind.m_Objects.clear(); } child = child->GetNodeItem(XFA_NODEITEM_NextSibling); } - if (nodes.GetSize() > nNum) { + if (rnd.m_Objects.size() > nNum) { if (m_pNodeHelper->NodeIsTransparent(parentNode)) { - CXFA_NodeArray upArrayNodes; - m_pNodeHelper->CountSiblings(ToNode(nodes[0]), XFA_LOGIC_Transparent, - &upArrayNodes, + std::vector<CXFA_Node*> upArrayNodes; + m_pNodeHelper->CountSiblings(ToNode(rnd.m_Objects.front()), + XFA_LOGIC_Transparent, &upArrayNodes, !!(dwStyles & XFA_RESOLVENODE_TagName)); - if (upArrayNodes.GetSize() > nodes.GetSize()) { - upArrayNodes[0] = ToNode(nodes[0]); - nodes.RemoveAll(); - nodes.Append((CXFA_ObjArray&)upArrayNodes); - upArrayNodes.RemoveAll(); + if (upArrayNodes.size() > rnd.m_Objects.size()) { + CXFA_Object* pSaveObject = rnd.m_Objects.front(); + rnd.m_Objects = std::vector<CXFA_Object*>(upArrayNodes.begin(), + upArrayNodes.end()); + rnd.m_Objects.front() = pSaveObject; } } FilterCondition(rnd, wsCondition); - if (nodes.GetSize() > 0) { - return 1; - } - return 0; + return !rnd.m_Objects.empty() ? 1 : 0; } } if (dwStyles & XFA_RESOLVENODE_Parent) { @@ -474,39 +457,35 @@ int32_t CXFA_ResolveProcessor::ResolveNormal(CXFA_ResolveNodesData& rnd) { dwSubStyles |= XFA_RESOLVENODE_ALL; } rndFind.m_dwStyles = dwSubStyles; - rndFind.m_CurNode = parentNode; - CXFA_NodeArray& array = rnd.m_pSC->GetUpObjectArray(); - array.Add(parentNode); + rndFind.m_CurObject = parentNode; + rnd.m_pSC->GetUpObjectArray()->push_back(parentNode); ResolveNormal(rndFind); - if (rndFind.m_Nodes.GetSize() > 0) { - nodes.Append(rndFind.m_Nodes); - rndFind.m_Nodes.RemoveAll(); - } - if (nodes.GetSize() > nNum) { + rnd.m_Objects.insert(rnd.m_Objects.end(), rndFind.m_Objects.begin(), + rndFind.m_Objects.end()); + rndFind.m_Objects.clear(); + if (rnd.m_Objects.size() > nNum) return 1; - } } return 0; } + int32_t CXFA_ResolveProcessor::ResolveAsterisk(CXFA_ResolveNodesData& rnd) { - CXFA_Node* curNode = ToNode(rnd.m_CurNode); - CXFA_ObjArray& nodes = rnd.m_Nodes; - CXFA_NodeArray array; - curNode->GetNodeList(array, - XFA_NODEFILTER_Children | XFA_NODEFILTER_Properties); - nodes.Append((CXFA_ObjArray&)array); - return nodes.GetSize(); + CXFA_Node* curNode = ToNode(rnd.m_CurObject); + std::vector<CXFA_Node*> array = + curNode->GetNodeList(XFA_NODEFILTER_Children | XFA_NODEFILTER_Properties); + rnd.m_Objects.insert(rnd.m_Objects.end(), array.begin(), array.end()); + return pdfium::CollectionSize<int32_t>(rnd.m_Objects); } -int32_t CXFA_ResolveProcessor::ResolvePopStack( - CFX_ArrayTemplate<int32_t>& stack) { - int32_t nType = -1; - int32_t iSize = stack.GetSize() - 1; - if (iSize > -1) { - nType = stack[iSize]; - stack.RemoveAt(iSize, 1); - } + +int32_t CXFA_ResolveProcessor::ResolvePopStack(std::vector<int32_t>* stack) { + if (stack->empty()) + return -1; + + int32_t nType = stack->back(); + stack->pop_back(); return nType; } + int32_t CXFA_ResolveProcessor::GetFilter(const CFX_WideStringC& wsExpression, int32_t nStart, CXFA_ResolveNodesData& rnd) { @@ -517,14 +496,14 @@ int32_t CXFA_ResolveProcessor::GetFilter(const CFX_WideStringC& wsExpression, } CFX_WideString& wsName = rnd.m_wsName; CFX_WideString& wsCondition = rnd.m_wsCondition; - FX_WCHAR* pNameBuf = wsName.GetBuffer(iLength - nStart); - FX_WCHAR* pConditionBuf = wsCondition.GetBuffer(iLength - nStart); + wchar_t* pNameBuf = wsName.GetBuffer(iLength - nStart); + wchar_t* pConditionBuf = wsCondition.GetBuffer(iLength - nStart); int32_t nNameCount = 0; int32_t nConditionCount = 0; - CFX_ArrayTemplate<int32_t> stack; + std::vector<int32_t> stack; int32_t nType = -1; - const FX_WCHAR* pSrc = wsExpression.c_str(); - FX_WCHAR wPrev = 0, wCur; + const wchar_t* pSrc = wsExpression.c_str(); + wchar_t wPrev = 0, wCur; bool bIsCondition = false; while (nStart < iLength) { wCur = pSrc[nStart++]; @@ -537,7 +516,7 @@ int32_t CXFA_ResolveProcessor::GetFilter(const CFX_WideStringC& wsExpression, rnd.m_dwStyles |= XFA_RESOLVENODE_AnyChild; continue; } - FX_WCHAR wLookahead = nStart < iLength ? pSrc[nStart] : 0; + wchar_t wLookahead = nStart < iLength ? pSrc[nStart] : 0; if (wLookahead != '[' && wLookahead != '(') { if (nType < 0) { break; @@ -559,19 +538,19 @@ int32_t CXFA_ResolveProcessor::GetFilter(const CFX_WideStringC& wsExpression, switch (nType) { case 0: if (wCur == ']') { - nType = ResolvePopStack(stack); + nType = ResolvePopStack(&stack); bRecursive = false; } break; case 1: if (wCur == ')') { - nType = ResolvePopStack(stack); + nType = ResolvePopStack(&stack); bRecursive = false; } break; case 2: if (wCur == '"') { - nType = ResolvePopStack(stack); + nType = ResolvePopStack(&stack); bRecursive = false; } break; @@ -579,24 +558,24 @@ int32_t CXFA_ResolveProcessor::GetFilter(const CFX_WideStringC& wsExpression, if (bRecursive) { switch (wCur) { case '[': - stack.Add(nType); + stack.push_back(nType); nType = 0; break; case '(': - stack.Add(nType); + stack.push_back(nType); nType = 1; break; case '"': - stack.Add(nType); + stack.push_back(nType); nType = 2; break; } } wPrev = wCur; } - if (stack.GetSize() > 0) { + if (!stack.empty()) return -1; - } + wsName.ReleaseBuffer(nNameCount); wsName.TrimLeft(); wsName.TrimRight(); @@ -611,13 +590,12 @@ void CXFA_ResolveProcessor::ConditionArray(int32_t iCurIndex, CFX_WideString wsCondition, int32_t iFoundCount, CXFA_ResolveNodesData& rnd) { - CXFA_NodeArray& findNodes = (CXFA_NodeArray&)rnd.m_Nodes; int32_t iLen = wsCondition.GetLength(); bool bRelative = false; bool bAll = false; int32_t i = 1; for (; i < iLen; ++i) { - FX_WCHAR ch = wsCondition[i]; + wchar_t ch = wsCondition[i]; if (ch == ' ') { continue; } @@ -634,15 +612,15 @@ void CXFA_ResolveProcessor::ConditionArray(int32_t iCurIndex, if (bAll) { if (rnd.m_dwStyles & XFA_RESOLVENODE_CreateNode) { if (rnd.m_dwStyles & XFA_RESOLVENODE_Bind) { - m_pNodeHelper->m_pCreateParent = ToNode(rnd.m_CurNode); + m_pNodeHelper->m_pCreateParent = ToNode(rnd.m_CurObject); m_pNodeHelper->m_iCreateCount = 1; - findNodes.RemoveAll(); + rnd.m_Objects.clear(); m_pNodeHelper->m_iCurAllStart = -1; m_pNodeHelper->m_pAllStartParent = nullptr; } else { if (m_pNodeHelper->m_iCurAllStart == -1) { m_pNodeHelper->m_iCurAllStart = m_iCurStart; - m_pNodeHelper->m_pAllStartParent = ToNode(rnd.m_CurNode); + m_pNodeHelper->m_pAllStartParent = ToNode(rnd.m_CurObject); } } } else if (rnd.m_dwStyles & XFA_RESOLVENODE_BindNew) { @@ -663,22 +641,22 @@ void CXFA_ResolveProcessor::ConditionArray(int32_t iCurIndex, } if (iFoundCount <= iIndex || iIndex < 0) { if (rnd.m_dwStyles & XFA_RESOLVENODE_CreateNode) { - m_pNodeHelper->m_pCreateParent = ToNode(rnd.m_CurNode); + m_pNodeHelper->m_pCreateParent = ToNode(rnd.m_CurObject); m_pNodeHelper->m_iCreateCount = iIndex - iFoundCount + 1; } - findNodes.RemoveAll(); + rnd.m_Objects.clear(); } else { - CXFA_Node* ret = findNodes[iIndex]; - findNodes.RemoveAll(); - findNodes.Add(ret); + CXFA_Object* ret = rnd.m_Objects[iIndex]; + rnd.m_Objects.clear(); + rnd.m_Objects.push_back(ret); } } + void CXFA_ResolveProcessor::DoPredicateFilter(int32_t iCurIndex, CFX_WideString wsCondition, int32_t iFoundCount, CXFA_ResolveNodesData& rnd) { - CXFA_NodeArray& findNodes = (CXFA_NodeArray&)rnd.m_Nodes; - ASSERT(iFoundCount == findNodes.GetSize()); + ASSERT(iFoundCount == pdfium::CollectionSize<int32_t>(rnd.m_Objects)); CFX_WideString wsExpression; XFA_SCRIPTLANGTYPE eLangType = XFA_SCRIPTLANGTYPE_Unkown; if (wsCondition.Left(2) == L".[" && wsCondition.Right(1) == L"]") { @@ -692,25 +670,20 @@ void CXFA_ResolveProcessor::DoPredicateFilter(int32_t iCurIndex, CXFA_ScriptContext* pContext = rnd.m_pSC; wsExpression = wsCondition.Mid(2, wsCondition.GetLength() - 3); for (int32_t i = iFoundCount - 1; i >= 0; i--) { - CXFA_Object* node = findNodes[i]; - bool bRet = false; - std::unique_ptr<CFXJSE_Value> pRetValue( - new CFXJSE_Value(rnd.m_pSC->GetRuntime())); - bRet = pContext->RunScript(eLangType, wsExpression.AsStringC(), - pRetValue.get(), node); + auto pRetValue = pdfium::MakeUnique<CFXJSE_Value>(rnd.m_pSC->GetRuntime()); + bool bRet = pContext->RunScript(eLangType, wsExpression.AsStringC(), + pRetValue.get(), rnd.m_Objects[i]); if (!bRet || !pRetValue->ToBoolean()) - findNodes.RemoveAt(i); + rnd.m_Objects.erase(rnd.m_Objects.begin() + i); } } void CXFA_ResolveProcessor::FilterCondition(CXFA_ResolveNodesData& rnd, CFX_WideString wsCondition) { - CXFA_NodeArray& findNodes = (CXFA_NodeArray&)rnd.m_Nodes; int32_t iCurrIndex = 0; - const CXFA_NodeArray& array = rnd.m_pSC->GetUpObjectArray(); - int32_t iSize = array.GetSize(); - if (iSize) { - CXFA_Node* curNode = array[iSize - 1]; + const std::vector<CXFA_Node*>* pArray = rnd.m_pSC->GetUpObjectArray(); + if (!pArray->empty()) { + CXFA_Node* curNode = pArray->back(); bool bIsProperty = m_pNodeHelper->NodeIsProperty(curNode); if (curNode->IsUnnamed() || (bIsProperty && curNode->GetElementType() != XFA_Element::PageSet)) { @@ -721,7 +694,7 @@ void CXFA_ResolveProcessor::FilterCondition(CXFA_ResolveNodesData& rnd, bIsProperty, false); } } - int32_t iFoundCount = findNodes.GetSize(); + int32_t iFoundCount = pdfium::CollectionSize<int32_t>(rnd.m_Objects); wsCondition.TrimLeft(); wsCondition.TrimRight(); int32_t iLen = wsCondition.GetLength(); @@ -734,19 +707,19 @@ void CXFA_ResolveProcessor::FilterCondition(CXFA_ResolveNodesData& rnd, } if (iFoundCount <= iCurrIndex) { if (rnd.m_dwStyles & XFA_RESOLVENODE_CreateNode) { - m_pNodeHelper->m_pCreateParent = ToNode(rnd.m_CurNode); + m_pNodeHelper->m_pCreateParent = ToNode(rnd.m_CurObject); m_pNodeHelper->m_iCreateCount = iCurrIndex - iFoundCount + 1; } - findNodes.RemoveAll(); + rnd.m_Objects.clear(); return; } else { - CXFA_Node* ret = findNodes[iCurrIndex]; - findNodes.RemoveAll(); - findNodes.Add(ret); + CXFA_Object* ret = rnd.m_Objects[iCurrIndex]; + rnd.m_Objects.clear(); + rnd.m_Objects.push_back(ret); return; } } - FX_WCHAR wTypeChar = wsCondition[0]; + wchar_t wTypeChar = wsCondition[0]; switch (wTypeChar) { case '[': ConditionArray(iCurrIndex, wsCondition, iFoundCount, rnd); @@ -775,22 +748,23 @@ void CXFA_ResolveProcessor::SetStylesForChild(uint32_t dwParentStyles, dwSubStyles |= XFA_RESOLVENODE_ALL; rnd.m_dwStyles = dwSubStyles; } + int32_t CXFA_ResolveProcessor::SetResultCreateNode( XFA_RESOLVENODE_RS& resolveNodeRS, CFX_WideString& wsLastCondition) { - if (m_pNodeHelper->m_pCreateParent) { - resolveNodeRS.nodes.Add(m_pNodeHelper->m_pCreateParent); - } else { + if (m_pNodeHelper->m_pCreateParent) + resolveNodeRS.objects.push_back(m_pNodeHelper->m_pCreateParent); + else m_pNodeHelper->CreateNode_ForCondition(wsLastCondition); - } + resolveNodeRS.dwFlags = m_pNodeHelper->m_iCreateFlag; if (resolveNodeRS.dwFlags == XFA_RESOLVENODE_RSTYPE_CreateNodeOne) { - if (m_pNodeHelper->m_iCurAllStart != -1) { + if (m_pNodeHelper->m_iCurAllStart != -1) resolveNodeRS.dwFlags = XFA_RESOLVENODE_RSTYPE_CreateNodeMidAll; - } } - return resolveNodeRS.nodes.GetSize(); + return pdfium::CollectionSize<int32_t>(resolveNodeRS.objects); } + void CXFA_ResolveProcessor::SetIndexDataBind(CFX_WideString& wsNextCondition, int32_t& iIndex, int32_t iCount) { @@ -807,16 +781,14 @@ void CXFA_ResolveProcessor::SetIndexDataBind(CFX_WideString& wsNextCondition, CXFA_ResolveNodesData::CXFA_ResolveNodesData(CXFA_ScriptContext* pSC) : m_pSC(pSC), - m_CurNode(nullptr), + m_CurObject(nullptr), m_wsName(), m_uHashName(XFA_HASHCODE_None), m_wsCondition(), m_nLevel(0), - m_Nodes(), + m_Objects(), m_dwStyles(XFA_RESOLVENODE_Children), m_pScriptAttribute(nullptr), m_dwFlag(XFA_RESOVENODE_RSTYPE_Nodes) {} -CXFA_ResolveNodesData::~CXFA_ResolveNodesData() { - m_Nodes.RemoveAll(); -} +CXFA_ResolveNodesData::~CXFA_ResolveNodesData() {} diff --git a/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_resolveprocessor.h b/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_resolveprocessor.h index d806d57b93e..f4eafea0236 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_resolveprocessor.h +++ b/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_resolveprocessor.h @@ -8,8 +8,8 @@ #define XFA_FXFA_PARSER_CXFA_RESOLVEPROCESSOR_H_ #include <memory> +#include <vector> -#include "xfa/fxfa/parser/xfa_object.h" #include "xfa/fxfa/parser/xfa_resolvenode_rs.h" class CXFA_NodeHelper; @@ -21,12 +21,12 @@ class CXFA_ResolveNodesData { ~CXFA_ResolveNodesData(); CXFA_ScriptContext* m_pSC; - CXFA_Object* m_CurNode; + CXFA_Object* m_CurObject; CFX_WideString m_wsName; XFA_HashCode m_uHashName; CFX_WideString m_wsCondition; int32_t m_nLevel; - CXFA_ObjArray m_Nodes; + std::vector<CXFA_Object*> m_Objects; // Not owned. uint32_t m_dwStyles; const XFA_SCRIPTATTRIBUTEINFO* m_pScriptAttribute; XFA_RESOVENODE_RSTYPE m_dwFlag; @@ -60,7 +60,7 @@ class CXFA_ResolveProcessor { int32_t ResolveNumberSign(CXFA_ResolveNodesData& rnd); int32_t ResolveAsterisk(CXFA_ResolveNodesData& rnd); int32_t ResolveNormal(CXFA_ResolveNodesData& rnd); - int32_t ResolvePopStack(CFX_ArrayTemplate<int32_t>& stack); + int32_t ResolvePopStack(std::vector<int32_t>* stack); void SetStylesForChild(uint32_t dwParentStyles, CXFA_ResolveNodesData& rnd); void ConditionArray(int32_t iCurIndex, diff --git a/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_script.cpp b/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_script.cpp index 16f65f99f44..ccd1997c471 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_script.cpp +++ b/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_script.cpp @@ -6,7 +6,7 @@ #include "xfa/fxfa/parser/cxfa_script.h" -#include "xfa/fxfa/parser/xfa_object.h" +#include "xfa/fxfa/parser/cxfa_node.h" CXFA_Script::CXFA_Script(CXFA_Node* pNode) : CXFA_Data(pNode) {} diff --git a/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_scriptcontext.cpp b/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_scriptcontext.cpp index 584cd76bedd..f539c39f760 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_scriptcontext.cpp +++ b/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_scriptcontext.cpp @@ -13,14 +13,18 @@ #include "fxjs/cfxjse_class.h" #include "fxjs/cfxjse_value.h" #include "third_party/base/ptr_util.h" +#include "third_party/base/stl_util.h" #include "xfa/fxfa/app/xfa_ffnotify.h" #include "xfa/fxfa/cxfa_eventparam.h" #include "xfa/fxfa/parser/cxfa_document.h" +#include "xfa/fxfa/parser/cxfa_localemgr.h" +#include "xfa/fxfa/parser/cxfa_node.h" #include "xfa/fxfa/parser/cxfa_nodehelper.h" +#include "xfa/fxfa/parser/cxfa_nodelist.h" +#include "xfa/fxfa/parser/cxfa_object.h" #include "xfa/fxfa/parser/cxfa_resolveprocessor.h" +#include "xfa/fxfa/parser/cxfa_thisproxy.h" #include "xfa/fxfa/parser/xfa_basic_data.h" -#include "xfa/fxfa/parser/xfa_localemgr.h" -#include "xfa/fxfa/parser/xfa_object.h" #include "xfa/fxfa/parser/xfa_resolvenode_rs.h" #include "xfa/fxfa/parser/xfa_utils.h" @@ -131,7 +135,6 @@ CXFA_ScriptContext::~CXFA_ScriptContext() { delete pVariableContext; } m_mapVariableToContext.clear(); - m_upObjectArray.RemoveAll(); } void CXFA_ScriptContext::Initialize(v8::Isolate* pIsolate) { @@ -146,12 +149,12 @@ bool CXFA_ScriptContext::RunScript(XFA_SCRIPTLANGTYPE eScriptType, CFXJSE_Value* hRetValue, CXFA_Object* pThisObject) { CFX_ByteString btScript; - XFA_SCRIPTLANGTYPE eSaveType = m_eScriptType; + CFX_AutoRestorer<XFA_SCRIPTLANGTYPE> typeRestorer(&m_eScriptType); m_eScriptType = eScriptType; if (eScriptType == XFA_SCRIPTLANGTYPE_Formcalc) { if (!m_FM2JSContext) { - m_FM2JSContext.reset( - new CXFA_FM2JSContext(m_pIsolate, m_JsContext.get(), m_pDocument)); + m_FM2JSContext = pdfium::MakeUnique<CXFA_FM2JSContext>( + m_pIsolate, m_JsContext.get(), m_pDocument); } CFX_WideTextBuf wsJavaScript; CFX_WideString wsErrorInfo; @@ -165,14 +168,12 @@ bool CXFA_ScriptContext::RunScript(XFA_SCRIPTLANGTYPE eScriptType, } else { btScript = FX_UTF8Encode(wsScript); } - CXFA_Object* pOriginalObject = m_pThisObject; + CFX_AutoRestorer<CXFA_Object*> nodeRestorer(&m_pThisObject); m_pThisObject = pThisObject; CFXJSE_Value* pValue = pThisObject ? GetJSValueFromMap(pThisObject) : nullptr; - bool bRet = m_JsContext->ExecuteScript(btScript.c_str(), hRetValue, pValue); - m_pThisObject = pOriginalObject; - m_eScriptType = eSaveType; - return bRet; + return m_JsContext->ExecuteScript(btScript.c_str(), hRetValue, pValue); } + void CXFA_ScriptContext::GlobalPropertySetter(CFXJSE_Value* pObject, const CFX_ByteStringC& szPropName, CFXJSE_Value* pValue) { @@ -215,13 +216,13 @@ bool CXFA_ScriptContext::QueryNodeByFlag(CXFA_Node* refNode, if (ResolveObjects(refNode, propname, resolveRs, dwFlag) <= 0) return false; if (resolveRs.dwFlags == XFA_RESOVENODE_RSTYPE_Nodes) { - pValue->Assign(GetJSValueFromMap(resolveRs.nodes[0])); + pValue->Assign(GetJSValueFromMap(resolveRs.objects.front())); return true; } if (resolveRs.dwFlags == XFA_RESOVENODE_RSTYPE_Attribute) { const XFA_SCRIPTATTRIBUTEINFO* lpAttributeInfo = resolveRs.pScriptAttribute; if (lpAttributeInfo) { - (resolveRs.nodes[0]->*(lpAttributeInfo->lpfnCallback))( + (resolveRs.objects.front()->*(lpAttributeInfo->lpfnCallback))( pValue, bSetting, (XFA_ATTRIBUTE)lpAttributeInfo->eAttribute); } } @@ -491,16 +492,13 @@ bool CXFA_ScriptContext::RunVariablesScript(CXFA_Node* pScriptNode) { return false; CFX_ByteString btScript = FX_UTF8Encode(wsScript); - std::unique_ptr<CFXJSE_Value> hRetValue(new CFXJSE_Value(m_pIsolate)); + auto hRetValue = pdfium::MakeUnique<CFXJSE_Value>(m_pIsolate); CXFA_Node* pThisObject = pParent->GetNodeItem(XFA_NODEITEM_Parent); CFXJSE_Context* pVariablesContext = CreateVariablesContext(pScriptNode, pThisObject); - CXFA_Object* pOriginalObject = m_pThisObject; + CFX_AutoRestorer<CXFA_Object*> nodeRestorer(&m_pThisObject); m_pThisObject = pThisObject; - bool bRet = - pVariablesContext->ExecuteScript(btScript.c_str(), hRetValue.get()); - m_pThisObject = pOriginalObject; - return bRet; + return pVariablesContext->ExecuteScript(btScript.c_str(), hRetValue.get()); } bool CXFA_ScriptContext::QueryVariableValue(CXFA_Node* pScriptNode, @@ -523,7 +521,7 @@ bool CXFA_ScriptContext::QueryVariableValue(CXFA_Node* pScriptNode, bool bRes = false; CFXJSE_Context* pVariableContext = static_cast<CFXJSE_Context*>(lpVariables); std::unique_ptr<CFXJSE_Value> pObject = pVariableContext->GetGlobalObject(); - std::unique_ptr<CFXJSE_Value> hVariableValue(new CFXJSE_Value(m_pIsolate)); + auto hVariableValue = pdfium::MakeUnique<CFXJSE_Value>(m_pIsolate); if (!bGetter) { pObject->SetObjectOwnProperty(szPropName, pValue); bRes = true; @@ -547,7 +545,7 @@ void CXFA_ScriptContext::DefineJsClass() { void CXFA_ScriptContext::RemoveBuiltInObjs(CFXJSE_Context* pContext) const { static const CFX_ByteStringC OBJ_NAME[2] = {"Number", "Date"}; std::unique_ptr<CFXJSE_Value> pObject = pContext->GetGlobalObject(); - std::unique_ptr<CFXJSE_Value> hProp(new CFXJSE_Value(m_pIsolate)); + auto hProp = pdfium::MakeUnique<CFXJSE_Value>(m_pIsolate); for (int i = 0; i < 2; ++i) { if (pObject->GetObjectProperty(OBJ_NAME[i], hProp.get())) pObject->DeleteObjectProperty(OBJ_NAME[i]); @@ -556,38 +554,41 @@ void CXFA_ScriptContext::RemoveBuiltInObjs(CFXJSE_Context* pContext) const { CFXJSE_Class* CXFA_ScriptContext::GetJseNormalClass() { return m_pJsClass; } -int32_t CXFA_ScriptContext::ResolveObjects(CXFA_Object* refNode, + +int32_t CXFA_ScriptContext::ResolveObjects(CXFA_Object* refObject, const CFX_WideStringC& wsExpression, XFA_RESOLVENODE_RS& resolveNodeRS, uint32_t dwStyles, CXFA_Node* bindNode) { - if (wsExpression.IsEmpty()) { + if (wsExpression.IsEmpty()) return 0; - } + if (m_eScriptType != XFA_SCRIPTLANGTYPE_Formcalc || (dwStyles & (XFA_RESOLVENODE_Parent | XFA_RESOLVENODE_Siblings))) { - m_upObjectArray.RemoveAll(); + m_upObjectArray.clear(); } - if (refNode && refNode->IsNode() && + if (refObject && refObject->IsNode() && (dwStyles & (XFA_RESOLVENODE_Parent | XFA_RESOLVENODE_Siblings))) { - m_upObjectArray.Add(refNode->AsNode()); + m_upObjectArray.push_back(refObject->AsNode()); } + bool bNextCreate = false; if (dwStyles & XFA_RESOLVENODE_CreateNode) { m_ResolveProcessor->GetNodeHelper()->SetCreateNodeType(bindNode); } m_ResolveProcessor->GetNodeHelper()->m_pCreateParent = nullptr; m_ResolveProcessor->GetNodeHelper()->m_iCurAllStart = -1; + CXFA_ResolveNodesData rndFind; int32_t nStart = 0; int32_t nLevel = 0; int32_t nRet = -1; rndFind.m_pSC = this; - CXFA_ObjArray findNodes; - findNodes.Add(refNode ? refNode : m_pDocument->GetRoot()); + std::vector<CXFA_Object*> findObjects; + findObjects.push_back(refObject ? refObject : m_pDocument->GetRoot()); int32_t nNodes = 0; while (true) { - nNodes = findNodes.GetSize(); + nNodes = pdfium::CollectionSize<int32_t>(findObjects); int32_t i = 0; rndFind.m_dwStyles = dwStyles; m_ResolveProcessor->SetCurStart(nStart); @@ -597,21 +598,22 @@ int32_t CXFA_ScriptContext::ResolveObjects(CXFA_Object* refNode, CXFA_Node* pDataNode = nullptr; nStart = m_ResolveProcessor->GetNodeHelper()->m_iCurAllStart; if (nStart != -1) { - pDataNode = m_pDocument->GetNotBindNode(findNodes); + pDataNode = m_pDocument->GetNotBindNode(findObjects); if (pDataNode) { - findNodes.RemoveAll(); - findNodes.Add(pDataNode); + findObjects.clear(); + findObjects.push_back(pDataNode); break; } } else { - pDataNode = findNodes[0]->AsNode(); - findNodes.RemoveAll(); - findNodes.Add(pDataNode); + pDataNode = findObjects.front()->AsNode(); + findObjects.clear(); + findObjects.push_back(pDataNode); break; } dwStyles |= XFA_RESOLVENODE_Bind; - findNodes.RemoveAll(); - findNodes.Add(m_ResolveProcessor->GetNodeHelper()->m_pAllStartParent); + findObjects.clear(); + findObjects.push_back( + m_ResolveProcessor->GetNodeHelper()->m_pAllStartParent); continue; } else { break; @@ -628,7 +630,7 @@ int32_t CXFA_ScriptContext::ResolveObjects(CXFA_Object* refNode, break; } } - CXFA_ObjArray retNodes; + std::vector<CXFA_Object*> retObjects; while (i < nNodes) { bool bDataBind = false; if (((dwStyles & XFA_RESOLVENODE_Bind) || @@ -639,7 +641,7 @@ int32_t CXFA_ScriptContext::ResolveObjects(CXFA_Object* refNode, m_ResolveProcessor->SetIndexDataBind(rndBind.m_wsCondition, i, nNodes); bDataBind = true; } - rndFind.m_CurNode = findNodes[i++]; + rndFind.m_CurObject = findObjects[i++]; rndFind.m_nLevel = nLevel; rndFind.m_dwFlag = XFA_RESOVENODE_RSTYPE_Nodes; nRet = m_ResolveProcessor->Resolve(rndFind); @@ -648,30 +650,29 @@ int32_t CXFA_ScriptContext::ResolveObjects(CXFA_Object* refNode, } if (rndFind.m_dwFlag == XFA_RESOVENODE_RSTYPE_Attribute && rndFind.m_pScriptAttribute && nStart < wsExpression.GetLength()) { - std::unique_ptr<CFXJSE_Value> pValue(new CFXJSE_Value(m_pIsolate)); - (rndFind.m_Nodes[0]->*(rndFind.m_pScriptAttribute->lpfnCallback))( + auto pValue = pdfium::MakeUnique<CFXJSE_Value>(m_pIsolate); + (rndFind.m_Objects.front() + ->*(rndFind.m_pScriptAttribute->lpfnCallback))( pValue.get(), false, (XFA_ATTRIBUTE)rndFind.m_pScriptAttribute->eAttribute); - rndFind.m_Nodes.SetAt(0, ToObject(pValue.get(), nullptr)); + rndFind.m_Objects.front() = ToObject(pValue.get(), nullptr); } - int32_t iSize = m_upObjectArray.GetSize(); - if (iSize) { - m_upObjectArray.RemoveAt(iSize - 1); - } - retNodes.Append(rndFind.m_Nodes); - rndFind.m_Nodes.RemoveAll(); - if (bDataBind) { + if (!m_upObjectArray.empty()) + m_upObjectArray.pop_back(); + retObjects.insert(retObjects.end(), rndFind.m_Objects.begin(), + rndFind.m_Objects.end()); + rndFind.m_Objects.clear(); + if (bDataBind) break; - } } - findNodes.RemoveAll(); - nNodes = retNodes.GetSize(); + findObjects.clear(); + nNodes = pdfium::CollectionSize<int32_t>(retObjects); if (nNodes < 1) { if (dwStyles & XFA_RESOLVENODE_CreateNode) { bNextCreate = true; if (!m_ResolveProcessor->GetNodeHelper()->m_pCreateParent) { m_ResolveProcessor->GetNodeHelper()->m_pCreateParent = - ToNode(rndFind.m_CurNode); + ToNode(rndFind.m_CurObject); m_ResolveProcessor->GetNodeHelper()->m_iCreateCount = 1; } bool bCreate = @@ -687,8 +688,9 @@ int32_t CXFA_ScriptContext::ResolveObjects(CXFA_Object* refNode, break; } } - findNodes.Copy(retNodes); - rndFind.m_Nodes.RemoveAll(); + findObjects = + std::vector<CXFA_Object*>(retObjects.begin(), retObjects.end()); + rndFind.m_Objects.clear(); if (nLevel == 0) { dwStyles &= ~(XFA_RESOLVENODE_Parent | XFA_RESOLVENODE_Siblings); } @@ -697,7 +699,8 @@ int32_t CXFA_ScriptContext::ResolveObjects(CXFA_Object* refNode, if (!bNextCreate) { resolveNodeRS.dwFlags = rndFind.m_dwFlag; if (nNodes > 0) { - resolveNodeRS.nodes.Append(findNodes); + resolveNodeRS.objects.insert(resolveNodeRS.objects.end(), + findObjects.begin(), findObjects.end()); } if (rndFind.m_dwFlag == XFA_RESOVENODE_RSTYPE_Attribute) { resolveNodeRS.pScriptAttribute = rndFind.m_pScriptAttribute; @@ -711,7 +714,7 @@ int32_t CXFA_ScriptContext::ResolveObjects(CXFA_Object* refNode, if (!bNextCreate && (dwStyles & XFA_RESOLVENODE_CreateNode)) { resolveNodeRS.dwFlags = XFA_RESOVENODE_RSTYPE_ExistNodes; } - return resolveNodeRS.nodes.GetSize(); + return pdfium::CollectionSize<int32_t>(resolveNodeRS.objects); } return nNodes; } @@ -730,7 +733,7 @@ CFXJSE_Value* CXFA_ScriptContext::GetJSValueFromMap(CXFA_Object* pObject) { if (iter != m_mapObjectToValue.end()) return iter->second.get(); - std::unique_ptr<CFXJSE_Value> jsValue(new CFXJSE_Value(m_pIsolate)); + auto jsValue = pdfium::MakeUnique<CFXJSE_Value>(m_pIsolate); jsValue->SetObject(pObject, m_pJsClass); CFXJSE_Value* pValue = jsValue.get(); m_mapObjectToValue.insert(std::make_pair(pObject, std::move(jsValue))); @@ -752,18 +755,17 @@ void CXFA_ScriptContext::GetSomExpression(CXFA_Node* refNode, lpNodeHelper->GetNameExpression(refNode, wsExpression, true, XFA_LOGIC_Transparent); } -void CXFA_ScriptContext::SetNodesOfRunScript(CXFA_NodeArray* pArray) { +void CXFA_ScriptContext::SetNodesOfRunScript(std::vector<CXFA_Node*>* pArray) { m_pScriptNodeArray = pArray; } -void CXFA_ScriptContext::AddNodesOfRunScript(const CXFA_NodeArray& nodes) { - if (!m_pScriptNodeArray) - return; - if (nodes.GetSize() > 0) - m_pScriptNodeArray->Copy(nodes); + +void CXFA_ScriptContext::AddNodesOfRunScript( + const std::vector<CXFA_Node*>& nodes) { + if (m_pScriptNodeArray && !nodes.empty()) + *m_pScriptNodeArray = nodes; } + void CXFA_ScriptContext::AddNodesOfRunScript(CXFA_Node* pNode) { - if (!m_pScriptNodeArray) - return; - if (m_pScriptNodeArray->Find(pNode) == -1) - m_pScriptNodeArray->Add(pNode); + if (m_pScriptNodeArray && !pdfium::ContainsValue(*m_pScriptNodeArray, pNode)) + m_pScriptNodeArray->push_back(pNode); } diff --git a/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_scriptcontext.h b/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_scriptcontext.h index 6d4f73a632f..3f81bb8ebe3 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_scriptcontext.h +++ b/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_scriptcontext.h @@ -32,9 +32,9 @@ class CXFA_ScriptContext { bool RunScript(XFA_SCRIPTLANGTYPE eScriptType, const CFX_WideStringC& wsScript, CFXJSE_Value* pRetValue, - CXFA_Object* pThisObject = nullptr); + CXFA_Object* pThisObject); - int32_t ResolveObjects(CXFA_Object* refNode, + int32_t ResolveObjects(CXFA_Object* refObject, const CFX_WideStringC& wsExpression, XFA_RESOLVENODE_RS& resolveNodeRS, uint32_t dwStyles = XFA_RESOLVENODE_Children, @@ -48,8 +48,8 @@ class CXFA_ScriptContext { int32_t GetIndexByClassName(CXFA_Node* refNode); void GetSomExpression(CXFA_Node* refNode, CFX_WideString& wsExpression); - void SetNodesOfRunScript(CXFA_NodeArray* pArray); - void AddNodesOfRunScript(const CXFA_NodeArray& nodes); + void SetNodesOfRunScript(std::vector<CXFA_Node*>* pArray); + void AddNodesOfRunScript(const std::vector<CXFA_Node*>& nodes); void AddNodesOfRunScript(CXFA_Node* pNode); CFXJSE_Class* GetJseNormalClass(); @@ -91,7 +91,7 @@ class CXFA_ScriptContext { CXFA_Object* GetVariablesThis(CXFA_Object* pObject, bool bScriptNode = false); bool IsStrictScopeInJavaScript(); XFA_SCRIPTLANGTYPE GetType(); - CXFA_NodeArray& GetUpObjectArray() { return m_upObjectArray; } + std::vector<CXFA_Node*>* GetUpObjectArray() { return &m_upObjectArray; } CXFA_Document* GetDocument() const { return m_pDocument; } static CXFA_Object* ToObject(CFXJSE_Value* pValue, CFXJSE_Class* pClass); @@ -111,10 +111,10 @@ class CXFA_ScriptContext { std::map<CXFA_Object*, std::unique_ptr<CFXJSE_Value>> m_mapObjectToValue; std::map<CXFA_Object*, CFXJSE_Context*> m_mapVariableToContext; CXFA_EventParam m_eventParam; - CXFA_NodeArray m_upObjectArray; + std::vector<CXFA_Node*> m_upObjectArray; // CacheList holds the NodeList items so we can clean them up when we're done. std::vector<std::unique_ptr<CXFA_NodeList>> m_CacheList; - CXFA_NodeArray* m_pScriptNodeArray; + std::vector<CXFA_Node*>* m_pScriptNodeArray; std::unique_ptr<CXFA_ResolveProcessor> m_ResolveProcessor; std::unique_ptr<CXFA_FM2JSContext> m_FM2JSContext; CXFA_Object* m_pThisObject; diff --git a/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_simple_parser.cpp b/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_simple_parser.cpp index 4a6956de198..cce4b68a270 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_simple_parser.cpp +++ b/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_simple_parser.cpp @@ -7,17 +7,25 @@ #include "xfa/fxfa/parser/cxfa_simple_parser.h" #include <utility> +#include <vector> +#include "core/fxcrt/cfx_checksumcontext.h" #include "core/fxcrt/fx_ext.h" #include "third_party/base/ptr_util.h" +#include "xfa/fde/xml/cfde_xmlchardata.h" +#include "xfa/fde/xml/cfde_xmldoc.h" +#include "xfa/fde/xml/cfde_xmlelement.h" +#include "xfa/fde/xml/cfde_xmlinstruction.h" +#include "xfa/fde/xml/cfde_xmlnode.h" +#include "xfa/fde/xml/cfde_xmlparser.h" +#include "xfa/fde/xml/cfde_xmltext.h" #include "xfa/fgas/crt/fgas_codepage.h" +#include "xfa/fgas/crt/ifgas_stream.h" #include "xfa/fxfa/fxfa.h" #include "xfa/fxfa/parser/cxfa_document.h" -#include "xfa/fxfa/parser/cxfa_widetextread.h" -#include "xfa/fxfa/parser/cxfa_xml_parser.h" +#include "xfa/fxfa/parser/cxfa_node.h" #include "xfa/fxfa/parser/xfa_basic_data.h" #include "xfa/fxfa/parser/xfa_utils.h" -#include "xfa/fxfa/xfa_checksum.h" namespace { @@ -47,14 +55,14 @@ CFDE_XMLNode* GetDocumentNode(CFDE_XMLDoc* pXMLDoc, return nullptr; } -void GetElementTagNamespaceURI(CFDE_XMLElement* pElement, - CFX_WideString& wsNamespaceURI) { - CFX_WideString wsNodeStr; - pElement->GetNamespacePrefix(wsNodeStr); +CFX_WideString GetElementTagNamespaceURI(CFDE_XMLElement* pElement) { + CFX_WideString wsNodeStr = pElement->GetNamespacePrefix(); + CFX_WideString wsNamespaceURI; if (!XFA_FDEExtension_ResolveNamespaceQualifier( - pElement, wsNodeStr.AsStringC(), wsNamespaceURI)) { - wsNamespaceURI.clear(); + pElement, wsNodeStr.AsStringC(), &wsNamespaceURI)) { + return CFX_WideString(); } + return wsNamespaceURI; } bool MatchNodeName(CFDE_XMLNode* pNode, @@ -65,18 +73,18 @@ bool MatchNodeName(CFDE_XMLNode* pNode, return false; CFDE_XMLElement* pElement = reinterpret_cast<CFDE_XMLElement*>(pNode); - CFX_WideString wsNodeStr; - pElement->GetLocalTagName(wsNodeStr); + CFX_WideString wsNodeStr = pElement->GetLocalTagName(); if (wsNodeStr != wsLocalTagName) return false; - GetElementTagNamespaceURI(pElement, wsNodeStr); + wsNodeStr = GetElementTagNamespaceURI(pElement); if (eMatchFlags & XFA_XDPPACKET_FLAGS_NOMATCH) return true; if (eMatchFlags & XFA_XDPPACKET_FLAGS_PREFIXMATCH) { return wsNodeStr.Left(wsNamespaceURIPrefix.GetLength()) == wsNamespaceURIPrefix; } + return wsNodeStr == wsNamespaceURIPrefix; } @@ -107,7 +115,7 @@ bool ResolveAttribute(CFDE_XMLElement* pElement, return false; } if (!XFA_FDEExtension_ResolveNamespaceQualifier( - pElement, wsNSPrefix.AsStringC(), wsNamespaceURI)) { + pElement, wsNSPrefix.AsStringC(), &wsNamespaceURI)) { wsNamespaceURI.clear(); return false; } @@ -122,26 +130,23 @@ bool FindAttributeWithNS(CFDE_XMLElement* pElement, if (!pElement) return false; - CFX_WideString wsAttrName; - CFX_WideString wsAttrValue; CFX_WideString wsAttrNS; - for (int32_t iAttrCount = pElement->CountAttributes(), i = 0; i < iAttrCount; - i++) { - pElement->GetAttribute(i, wsAttrName, wsAttrValue); - FX_STRSIZE iFind = wsAttrName.Find(L':', 0); + for (auto it : pElement->GetAttributes()) { + FX_STRSIZE iFind = it.first.Find(L':', 0); CFX_WideString wsNSPrefix; if (iFind < 0) { - if (wsLocalAttributeName != wsAttrName) + if (wsLocalAttributeName != it.first) continue; } else { if (wsLocalAttributeName != - wsAttrName.Right(wsAttrName.GetLength() - iFind - 1)) { + it.first.Right(it.first.GetLength() - iFind - 1)) { continue; } - wsNSPrefix = wsAttrName.Left(iFind); + wsNSPrefix = it.first.Left(iFind); } + if (!XFA_FDEExtension_ResolveNamespaceQualifier( - pElement, wsNSPrefix.AsStringC(), wsAttrNS)) { + pElement, wsNSPrefix.AsStringC(), &wsAttrNS)) { continue; } if (bMatchNSAsPrefix) { @@ -153,7 +158,7 @@ bool FindAttributeWithNS(CFDE_XMLElement* pElement, if (wsAttrNS != wsNamespaceURIPrefix) continue; } - wsValue = wsAttrValue; + wsValue = it.second; return true; } return false; @@ -200,30 +205,22 @@ void ConvertXMLToPlainText(CFDE_XMLElement* pRootXMLNode, pXMLChild = pXMLChild->GetNodeItem(CFDE_XMLNode::NextSibling)) { switch (pXMLChild->GetType()) { case FDE_XMLNODE_Element: { - CFX_WideString wsTextData; - static_cast<CFDE_XMLElement*>(pXMLChild)->GetTextData(wsTextData); + CFX_WideString wsTextData = + static_cast<CFDE_XMLElement*>(pXMLChild)->GetTextData(); wsTextData += L"\n"; wsOutput += wsTextData; break; } - case FDE_XMLNODE_Text: { - CFX_WideString wsText; - static_cast<CFDE_XMLText*>(pXMLChild)->GetText(wsText); + case FDE_XMLNODE_Text: + case FDE_XMLNODE_CharData: { + CFX_WideString wsText = + static_cast<CFDE_XMLText*>(pXMLChild)->GetText(); if (IsStringAllWhitespace(wsText)) continue; wsOutput = wsText; break; } - case FDE_XMLNODE_CharData: { - CFX_WideString wsCharData; - static_cast<CFDE_XMLCharData*>(pXMLChild)->GetCharData(wsCharData); - if (IsStringAllWhitespace(wsCharData)) - continue; - - wsOutput = wsCharData; - break; - } default: ASSERT(false); break; @@ -254,13 +251,8 @@ const XFA_PACKETINFO* GetPacketByName(const CFX_WideStringC& wsName) { } // namespace bool XFA_RecognizeRichText(CFDE_XMLElement* pRichTextXMLNode) { - if (pRichTextXMLNode) { - CFX_WideString wsNamespaceURI; - GetElementTagNamespaceURI(pRichTextXMLNode, wsNamespaceURI); - if (wsNamespaceURI == L"http://www.w3.org/1999/xhtml") - return true; - } - return false; + return pRichTextXMLNode && GetElementTagNamespaceURI(pRichTextXMLNode) == + L"http://www.w3.org/1999/xhtml"; } CXFA_SimpleParser::CXFA_SimpleParser(CXFA_Document* pFactory, @@ -285,8 +277,7 @@ int32_t CXFA_SimpleParser::StartParse( XFA_XDPPACKET ePacketID) { CloseParser(); m_pFileRead = pStream; - m_pStream = IFGAS_Stream::CreateStream( - pStream, FX_STREAMACCESS_Read | FX_STREAMACCESS_Text); + m_pStream = IFGAS_Stream::CreateReadStream(pStream); if (!m_pStream) return XFA_PARSESTATUS_StreamErr; @@ -297,7 +288,7 @@ int32_t CXFA_SimpleParser::StartParse( } m_pXMLDoc = pdfium::MakeUnique<CFDE_XMLDoc>(); auto pNewParser = - pdfium::MakeUnique<CXFA_XMLParser>(m_pXMLDoc->GetRoot(), m_pStream); + pdfium::MakeUnique<CFDE_XMLParser>(m_pXMLDoc->GetRoot(), m_pStream); m_pXMLParser = pNewParser.get(); if (!m_pXMLDoc->LoadXML(std::move(pNewParser))) return XFA_PARSESTATUS_StatusErr; @@ -319,6 +310,7 @@ int32_t CXFA_SimpleParser::DoParse(IFX_Pause* pPause) { m_pRootNode = ParseAsXDPPacket(GetDocumentNode(m_pXMLDoc.get()), m_ePacketID); m_pXMLDoc->CloseXML(); m_pStream.Reset(); + if (!m_pRootNode) return XFA_PARSESTATUS_StatusErr; @@ -331,9 +323,10 @@ int32_t CXFA_SimpleParser::ParseXMLData(const CFX_WideString& wsXML, CloseParser(); pXMLNode = nullptr; m_pXMLDoc = pdfium::MakeUnique<CFDE_XMLDoc>(); - auto pStream = pdfium::MakeRetain<CXFA_WideTextRead>(wsXML); + CFX_RetainPtr<IFGAS_Stream> pStream = + IFGAS_Stream::CreateWideStringReadStream(wsXML); auto pParser = - pdfium::MakeUnique<CXFA_XMLParser>(m_pXMLDoc->GetRoot(), pStream); + pdfium::MakeUnique<CFDE_XMLParser>(m_pXMLDoc->GetRoot(), pStream); pParser->m_dwCheckStatus = 0x03; if (!m_pXMLDoc->LoadXML(std::move(pParser))) return XFA_PARSESTATUS_StatusErr; @@ -369,9 +362,8 @@ void CXFA_SimpleParser::ConstructXFANode(CXFA_Node* pXFANode, if (!pXFAChild) return; - CFX_WideString wsNodeStr; CFDE_XMLElement* child = static_cast<CFDE_XMLElement*>(pXMLChild); - child->GetLocalTagName(wsNodeStr); + CFX_WideString wsNodeStr = child->GetLocalTagName(); pXFAChild->SetCData(XFA_ATTRIBUTE_Name, wsNodeStr); CFX_WideString wsChildValue; XFA_GetPlainTextFromRichText(child, wsChildValue); @@ -407,7 +399,7 @@ CFDE_XMLDoc* CXFA_SimpleParser::GetXMLDoc() const { bool XFA_FDEExtension_ResolveNamespaceQualifier( CFDE_XMLElement* pNode, const CFX_WideStringC& wsQualifier, - CFX_WideString& wsNamespaceURI) { + CFX_WideString* wsNamespaceURI) { if (!pNode) return false; @@ -420,17 +412,18 @@ bool XFA_FDEExtension_ResolveNamespaceQualifier( } else { wsNSAttribute = L"xmlns:" + wsQualifier; } - for (; pNode != pFakeRoot; pNode = static_cast<CFDE_XMLElement*>( - pNode->GetNodeItem(CFDE_XMLNode::Parent))) { - if (pNode->GetType() != FDE_XMLNODE_Element) + for (CFDE_XMLNode* pParent = pNode; pParent != pFakeRoot; + pParent = pParent->GetNodeItem(CFDE_XMLNode::Parent)) { + if (pParent->GetType() != FDE_XMLNODE_Element) continue; - if (pNode->HasAttribute(wsNSAttribute.c_str())) { - pNode->GetString(wsNSAttribute.c_str(), wsNamespaceURI); + auto* pElement = static_cast<CFDE_XMLElement*>(pParent); + if (pElement->HasAttribute(wsNSAttribute.c_str())) { + *wsNamespaceURI = pElement->GetString(wsNSAttribute.c_str()); return true; } } - wsNamespaceURI.clear(); + wsNamespaceURI->clear(); return bRet; } @@ -469,6 +462,7 @@ CXFA_Node* CXFA_SimpleParser::ParseAsXDPPacket_XDP( XFA_GetPacketByIndex(XFA_PACKET_XDP)->eFlags)) { return nullptr; } + CXFA_Node* pXFARootNode = m_pFactory->CreateNode(XFA_XDPPACKET_XDP, XFA_Element::Xfa); if (!pXFARootNode) @@ -476,109 +470,98 @@ CXFA_Node* CXFA_SimpleParser::ParseAsXDPPacket_XDP( m_pRootNode = pXFARootNode; pXFARootNode->SetCData(XFA_ATTRIBUTE_Name, L"xfa"); - { - CFDE_XMLElement* pElement = static_cast<CFDE_XMLElement*>(pXMLDocumentNode); - int32_t iAttributeCount = pElement->CountAttributes(); - for (int32_t i = 0; i < iAttributeCount; i++) { - CFX_WideString wsAttriName, wsAttriValue; - pElement->GetAttribute(i, wsAttriName, wsAttriValue); - if (wsAttriName == L"uuid") - pXFARootNode->SetCData(XFA_ATTRIBUTE_Uuid, wsAttriValue); - else if (wsAttriName == L"timeStamp") - pXFARootNode->SetCData(XFA_ATTRIBUTE_TimeStamp, wsAttriValue); - } + + CFDE_XMLElement* pElement = static_cast<CFDE_XMLElement*>(pXMLDocumentNode); + for (auto it : pElement->GetAttributes()) { + if (it.first == L"uuid") + pXFARootNode->SetCData(XFA_ATTRIBUTE_Uuid, it.second); + else if (it.first == L"timeStamp") + pXFARootNode->SetCData(XFA_ATTRIBUTE_TimeStamp, it.second); } CFDE_XMLNode* pXMLConfigDOMRoot = nullptr; CXFA_Node* pXFAConfigDOMRoot = nullptr; - { - for (CFDE_XMLNode* pChildItem = - pXMLDocumentNode->GetNodeItem(CFDE_XMLNode::FirstChild); - pChildItem; - pChildItem = pChildItem->GetNodeItem(CFDE_XMLNode::NextSibling)) { - const XFA_PACKETINFO* pPacketInfo = - XFA_GetPacketByIndex(XFA_PACKET_Config); - if (!MatchNodeName(pChildItem, pPacketInfo->pName, pPacketInfo->pURI, - pPacketInfo->eFlags)) { - continue; - } - if (pXFARootNode->GetFirstChildByName(pPacketInfo->uHash)) { - return nullptr; - } - pXMLConfigDOMRoot = pChildItem; - pXFAConfigDOMRoot = - ParseAsXDPPacket_Config(pXMLConfigDOMRoot, XFA_XDPPACKET_Config); - pXFARootNode->InsertChild(pXFAConfigDOMRoot, nullptr); + for (CFDE_XMLNode* pChildItem = + pXMLDocumentNode->GetNodeItem(CFDE_XMLNode::FirstChild); + pChildItem; + pChildItem = pChildItem->GetNodeItem(CFDE_XMLNode::NextSibling)) { + const XFA_PACKETINFO* pPacketInfo = XFA_GetPacketByIndex(XFA_PACKET_Config); + if (!MatchNodeName(pChildItem, pPacketInfo->pName, pPacketInfo->pURI, + pPacketInfo->eFlags)) { + continue; } + if (pXFARootNode->GetFirstChildByName(pPacketInfo->uHash)) + return nullptr; + + pXMLConfigDOMRoot = pChildItem; + pXFAConfigDOMRoot = + ParseAsXDPPacket_Config(pXMLConfigDOMRoot, XFA_XDPPACKET_Config); + pXFARootNode->InsertChild(pXFAConfigDOMRoot, nullptr); } CFDE_XMLNode* pXMLDatasetsDOMRoot = nullptr; CFDE_XMLNode* pXMLFormDOMRoot = nullptr; CFDE_XMLNode* pXMLTemplateDOMRoot = nullptr; - { - for (CFDE_XMLNode* pChildItem = - pXMLDocumentNode->GetNodeItem(CFDE_XMLNode::FirstChild); - pChildItem; - pChildItem = pChildItem->GetNodeItem(CFDE_XMLNode::NextSibling)) { - if (!pChildItem || pChildItem->GetType() != FDE_XMLNODE_Element) - continue; - if (pChildItem == pXMLConfigDOMRoot) - continue; + for (CFDE_XMLNode* pChildItem = + pXMLDocumentNode->GetNodeItem(CFDE_XMLNode::FirstChild); + pChildItem; + pChildItem = pChildItem->GetNodeItem(CFDE_XMLNode::NextSibling)) { + if (!pChildItem || pChildItem->GetType() != FDE_XMLNODE_Element) + continue; + if (pChildItem == pXMLConfigDOMRoot) + continue; - CFDE_XMLElement* pElement = - reinterpret_cast<CFDE_XMLElement*>(pChildItem); - CFX_WideString wsPacketName; - pElement->GetLocalTagName(wsPacketName); - const XFA_PACKETINFO* pPacketInfo = - GetPacketByName(wsPacketName.AsStringC()); - if (pPacketInfo && pPacketInfo->pURI) { - if (!MatchNodeName(pElement, pPacketInfo->pName, pPacketInfo->pURI, - pPacketInfo->eFlags)) { - pPacketInfo = nullptr; - } + CFDE_XMLElement* pElement = reinterpret_cast<CFDE_XMLElement*>(pChildItem); + CFX_WideString wsPacketName = pElement->GetLocalTagName(); + const XFA_PACKETINFO* pPacketInfo = + GetPacketByName(wsPacketName.AsStringC()); + if (pPacketInfo && pPacketInfo->pURI) { + if (!MatchNodeName(pElement, pPacketInfo->pName, pPacketInfo->pURI, + pPacketInfo->eFlags)) { + pPacketInfo = nullptr; } - XFA_XDPPACKET ePacket = - pPacketInfo ? pPacketInfo->eName : XFA_XDPPACKET_USER; - if (ePacket == XFA_XDPPACKET_XDP) - continue; - if (ePacket == XFA_XDPPACKET_Datasets) { - if (pXMLDatasetsDOMRoot) - return nullptr; + } + XFA_XDPPACKET ePacket = + pPacketInfo ? pPacketInfo->eName : XFA_XDPPACKET_USER; + if (ePacket == XFA_XDPPACKET_XDP) + continue; + if (ePacket == XFA_XDPPACKET_Datasets) { + if (pXMLDatasetsDOMRoot) + return nullptr; - pXMLDatasetsDOMRoot = pElement; - } else if (ePacket == XFA_XDPPACKET_Form) { - if (pXMLFormDOMRoot) - return nullptr; + pXMLDatasetsDOMRoot = pElement; + } else if (ePacket == XFA_XDPPACKET_Form) { + if (pXMLFormDOMRoot) + return nullptr; - pXMLFormDOMRoot = pElement; - } else if (ePacket == XFA_XDPPACKET_Template) { - if (pXMLTemplateDOMRoot) { - // Found a duplicate template packet. + pXMLFormDOMRoot = pElement; + } else if (ePacket == XFA_XDPPACKET_Template) { + // Found a duplicate template packet. + if (pXMLTemplateDOMRoot) + return nullptr; + + CXFA_Node* pPacketNode = ParseAsXDPPacket(pElement, ePacket); + if (pPacketNode) { + pXMLTemplateDOMRoot = pElement; + pXFARootNode->InsertChild(pPacketNode); + } + } else { + CXFA_Node* pPacketNode = ParseAsXDPPacket(pElement, ePacket); + if (pPacketNode) { + if (pPacketInfo && + (pPacketInfo->eFlags & XFA_XDPPACKET_FLAGS_SUPPORTONE) && + pXFARootNode->GetFirstChildByName(pPacketInfo->uHash)) { return nullptr; } - CXFA_Node* pPacketNode = ParseAsXDPPacket(pElement, ePacket); - if (pPacketNode) { - pXMLTemplateDOMRoot = pElement; - pXFARootNode->InsertChild(pPacketNode); - } - } else { - CXFA_Node* pPacketNode = ParseAsXDPPacket(pElement, ePacket); - if (pPacketNode) { - if (pPacketInfo && - (pPacketInfo->eFlags & XFA_XDPPACKET_FLAGS_SUPPORTONE) && - pXFARootNode->GetFirstChildByName(pPacketInfo->uHash)) { - return nullptr; - } - pXFARootNode->InsertChild(pPacketNode); - } + pXFARootNode->InsertChild(pPacketNode); } } } - if (!pXMLTemplateDOMRoot) { - // No template is found. + // No template is found. + if (!pXMLTemplateDOMRoot) return nullptr; - } + if (pXMLDatasetsDOMRoot) { CXFA_Node* pPacketNode = ParseAsXDPPacket(pXMLDatasetsDOMRoot, XFA_XDPPACKET_Datasets); @@ -591,6 +574,7 @@ CXFA_Node* CXFA_SimpleParser::ParseAsXDPPacket_XDP( if (pPacketNode) pXFARootNode->InsertChild(pPacketNode); } + pXFARootNode->SetXMLMappingNode(pXMLDocumentNode); return pXFARootNode; } @@ -635,12 +619,11 @@ CXFA_Node* CXFA_SimpleParser::ParseAsXDPPacket_TemplateForm( pNode->SetCData(XFA_ATTRIBUTE_Name, XFA_GetPacketByIndex(XFA_PACKET_Template)->pName); if (m_bDocumentParser) { - CFX_WideString wsNamespaceURI; CFDE_XMLElement* pXMLDocumentElement = static_cast<CFDE_XMLElement*>(pXMLDocumentNode); - pXMLDocumentElement->GetNamespaceURI(wsNamespaceURI); + CFX_WideString wsNamespaceURI = pXMLDocumentElement->GetNamespaceURI(); if (wsNamespaceURI.IsEmpty()) - pXMLDocumentElement->GetString(L"xmlns:xfa", wsNamespaceURI); + wsNamespaceURI = pXMLDocumentElement->GetString(L"xmlns:xfa"); pNode->GetDocument()->RecognizeXFAVersionNumber(wsNamespaceURI); } @@ -654,13 +637,13 @@ CXFA_Node* CXFA_SimpleParser::ParseAsXDPPacket_TemplateForm( XFA_GetPacketByIndex(XFA_PACKET_Form)->eFlags)) { CFDE_XMLElement* pXMLDocumentElement = static_cast<CFDE_XMLElement*>(pXMLDocumentNode); - CFX_WideString wsChecksum; - pXMLDocumentElement->GetString(L"checksum", wsChecksum); + CFX_WideString wsChecksum = pXMLDocumentElement->GetString(L"checksum"); if (wsChecksum.GetLength() != 28 || m_pXMLParser->m_dwCheckStatus != 0x03) { return nullptr; } - std::unique_ptr<CXFA_ChecksumContext> pChecksum(new CXFA_ChecksumContext); + + auto pChecksum = pdfium::MakeUnique<CFX_ChecksumContext>(); pChecksum->StartChecksum(); pChecksum->UpdateChecksum(m_pFileRead, m_pXMLParser->m_nStart[0], m_pXMLParser->m_nSize[0]); @@ -750,8 +733,8 @@ CXFA_Node* CXFA_SimpleParser::ParseAsXDPPacket_Data( delete pDataXMLNode; return nullptr; } - CFX_WideString wsLocalName; - static_cast<CFDE_XMLElement*>(pDataXMLNode)->GetLocalTagName(wsLocalName); + CFX_WideString wsLocalName = + static_cast<CFDE_XMLElement*>(pDataXMLNode)->GetLocalTagName(); pNode->SetCData(XFA_ATTRIBUTE_Name, wsLocalName); if (!DataLoader(pNode, pDataXMLNode, true)) return nullptr; @@ -847,8 +830,8 @@ CXFA_Node* CXFA_SimpleParser::ParseAsXDPPacket_User( if (!pNode) return nullptr; - CFX_WideString wsName; - static_cast<CFDE_XMLElement*>(pXMLDocumentNode)->GetLocalTagName(wsName); + CFX_WideString wsName = + static_cast<CFDE_XMLElement*>(pXMLDocumentNode)->GetLocalTagName(); pNode->SetCData(XFA_ATTRIBUTE_Name, wsName); if (!UserPacketLoader(pNode, pXMLDocumentNode)) return nullptr; @@ -880,8 +863,7 @@ CXFA_Node* CXFA_SimpleParser::NormalLoader(CXFA_Node* pXFANode, switch (pXMLChild->GetType()) { case FDE_XMLNODE_Element: { CFDE_XMLElement* pXMLElement = static_cast<CFDE_XMLElement*>(pXMLChild); - CFX_WideString wsTagName; - pXMLElement->GetLocalTagName(wsTagName); + CFX_WideString wsTagName = pXMLElement->GetLocalTagName(); XFA_Element eType = XFA_GetElementTypeForName(wsTagName.AsStringC()); if (eType == XFA_Element::Unknown) continue; @@ -903,16 +885,12 @@ CXFA_Node* CXFA_SimpleParser::NormalLoader(CXFA_Node* pXFANode, pXFAChild->SetAttribute(XFA_ATTRIBUTE_Name, wsTagName.AsStringC()); bool IsNeedValue = true; - for (int32_t i = 0, count = pXMLElement->CountAttributes(); i < count; - i++) { - CFX_WideString wsAttrQualifiedName; + for (auto it : pXMLElement->GetAttributes()) { CFX_WideString wsAttrName; - CFX_WideString wsAttrValue; - pXMLElement->GetAttribute(i, wsAttrQualifiedName, wsAttrValue); - GetAttributeLocalName(wsAttrQualifiedName.AsStringC(), wsAttrName); - if (wsAttrName == L"nil" && wsAttrValue == L"true") { + GetAttributeLocalName(it.first.AsStringC(), wsAttrName); + if (wsAttrName == L"nil" && it.second == L"true") IsNeedValue = false; - } + const XFA_ATTRIBUTEINFO* lpAttrInfo = XFA_GetAttributeByName(wsAttrName.AsStringC()); if (!lpAttrInfo) @@ -922,7 +900,7 @@ CXFA_Node* CXFA_SimpleParser::NormalLoader(CXFA_Node* pXFANode, lpAttrInfo->eName != XFA_ATTRIBUTE_Save) { continue; } - pXFAChild->SetAttribute(lpAttrInfo->eName, wsAttrValue.AsStringC()); + pXFAChild->SetAttribute(lpAttrInfo->eName, it.second.AsStringC()); } pXFANode->InsertChild(pXFAChild); if (eType == XFA_Element::Validate || eType == XFA_Element::Locale) { @@ -996,10 +974,8 @@ void CXFA_SimpleParser::ParseContentNode(CXFA_Node* pXFANode, } else { if (eNodeType == FDE_XMLNODE_Element) break; - if (eNodeType == FDE_XMLNODE_Text) - static_cast<CFDE_XMLText*>(pXMLChild)->GetText(wsValue); - else if (eNodeType == FDE_XMLNODE_CharData) - static_cast<CFDE_XMLCharData*>(pXMLChild)->GetCharData(wsValue); + if (eNodeType == FDE_XMLNODE_Text || eNodeType == FDE_XMLNODE_CharData) + wsValue = static_cast<CFDE_XMLText*>(pXMLChild)->GetText(); } break; } @@ -1027,8 +1003,8 @@ void CXFA_SimpleParser::ParseDataGroup(CXFA_Node* pXFANode, case FDE_XMLNODE_Element: { CFDE_XMLElement* pXMLElement = static_cast<CFDE_XMLElement*>(pXMLChild); { - CFX_WideString wsNamespaceURI; - GetElementTagNamespaceURI(pXMLElement, wsNamespaceURI); + CFX_WideString wsNamespaceURI = + GetElementTagNamespaceURI(pXMLElement); if (wsNamespaceURI == L"http://www.xfa.com/schema/xfa-package/" || wsNamespaceURI == L"http://www.xfa.org/schema/xfa-package/" || wsNamespaceURI == L"http://www.w3.org/2001/XMLSchema-instance") { @@ -1079,21 +1055,17 @@ void CXFA_SimpleParser::ParseDataGroup(CXFA_Node* pXFANode, if (!pXFAChild) return; - CFX_WideString wsNodeName; - pXMLElement->GetLocalTagName(wsNodeName); - pXFAChild->SetCData(XFA_ATTRIBUTE_Name, wsNodeName); + pXFAChild->SetCData(XFA_ATTRIBUTE_Name, pXMLElement->GetLocalTagName()); bool bNeedValue = true; - for (int32_t i = 0; i < pXMLElement->CountAttributes(); ++i) { - CFX_WideString wsQualifiedName; - CFX_WideString wsValue; + + for (auto it : pXMLElement->GetAttributes()) { CFX_WideString wsName; CFX_WideString wsNS; - pXMLElement->GetAttribute(i, wsQualifiedName, wsValue); - if (!ResolveAttribute(pXMLElement, wsQualifiedName.AsStringC(), - wsName, wsNS)) { + if (!ResolveAttribute(pXMLElement, it.first.AsStringC(), wsName, + wsNS)) { continue; } - if (wsName == L"nil" && wsValue == L"true") { + if (wsName == L"nil" && it.second == L"true") { bNeedValue = false; continue; } @@ -1109,8 +1081,8 @@ void CXFA_SimpleParser::ParseDataGroup(CXFA_Node* pXFANode, return; pXFAMetaData->SetCData(XFA_ATTRIBUTE_Name, wsName); - pXFAMetaData->SetCData(XFA_ATTRIBUTE_QualifiedName, wsQualifiedName); - pXFAMetaData->SetCData(XFA_ATTRIBUTE_Value, wsValue); + pXFAMetaData->SetCData(XFA_ATTRIBUTE_QualifiedName, it.first); + pXFAMetaData->SetCData(XFA_ATTRIBUTE_Value, it.second); pXFAMetaData->SetEnum(XFA_ATTRIBUTE_Contains, XFA_ATTRIBUTEENUM_MetaData); pXFAChild->InsertChild(pXFAMetaData); @@ -1132,29 +1104,10 @@ void CXFA_SimpleParser::ParseDataGroup(CXFA_Node* pXFANode, pXFAChild->SetFlag(XFA_NodeFlag_Initialized, false); continue; } - case FDE_XMLNODE_CharData: { - CFDE_XMLCharData* pXMLCharData = - static_cast<CFDE_XMLCharData*>(pXMLChild); - CFX_WideString wsCharData; - pXMLCharData->GetCharData(wsCharData); - if (IsStringAllWhitespace(wsCharData)) - continue; - - CXFA_Node* pXFAChild = m_pFactory->CreateNode(XFA_XDPPACKET_Datasets, - XFA_Element::DataValue); - if (!pXFAChild) - return; - - pXFAChild->SetCData(XFA_ATTRIBUTE_Value, wsCharData); - pXFANode->InsertChild(pXFAChild); - pXFAChild->SetXMLMappingNode(pXMLCharData); - pXFAChild->SetFlag(XFA_NodeFlag_Initialized, false); - continue; - } + case FDE_XMLNODE_CharData: case FDE_XMLNODE_Text: { CFDE_XMLText* pXMLText = static_cast<CFDE_XMLText*>(pXMLChild); - CFX_WideString wsText; - pXMLText->GetText(wsText); + CFX_WideString wsText = pXMLText->GetText(); if (IsStringAllWhitespace(wsText)) continue; @@ -1191,14 +1144,8 @@ void CXFA_SimpleParser::ParseDataValue(CXFA_Node* pXFANode, continue; CFX_WideString wsText; - if (eNodeType == FDE_XMLNODE_Text) { - static_cast<CFDE_XMLText*>(pXMLChild)->GetText(wsText); - if (!pXMLCurValueNode) - pXMLCurValueNode = pXMLChild; - - wsCurValueTextBuf << wsText; - } else if (eNodeType == FDE_XMLNODE_CharData) { - static_cast<CFDE_XMLCharData*>(pXMLChild)->GetCharData(wsText); + if (eNodeType == FDE_XMLNODE_Text || eNodeType == FDE_XMLNODE_CharData) { + wsText = static_cast<CFDE_XMLText*>(pXMLChild)->GetText(); if (!pXMLCurValueNode) pXMLCurValueNode = pXMLChild; @@ -1236,8 +1183,8 @@ void CXFA_SimpleParser::ParseDataValue(CXFA_Node* pXFANode, if (!pXFAChild) return; - CFX_WideString wsNodeStr; - static_cast<CFDE_XMLElement*>(pXMLChild)->GetLocalTagName(wsNodeStr); + CFX_WideString wsNodeStr = + static_cast<CFDE_XMLElement*>(pXMLChild)->GetLocalTagName(); pXFAChild->SetCData(XFA_ATTRIBUTE_Name, wsNodeStr); ParseDataValue(pXFAChild, pXMLChild, ePacketID); pXFANode->InsertChild(pXFAChild); @@ -1277,25 +1224,20 @@ void CXFA_SimpleParser::ParseInstruction(CXFA_Node* pXFANode, if (!m_bDocumentParser) return; - CFX_WideString wsTargetName; - pXMLInstruction->GetTargetName(wsTargetName); + CFX_WideString wsTargetName = pXMLInstruction->GetName(); + const std::vector<CFX_WideString>& target_data = + pXMLInstruction->GetTargetData(); if (wsTargetName == L"originalXFAVersion") { - CFX_WideString wsData; - if (pXMLInstruction->GetData(0, wsData) && - (pXFANode->GetDocument()->RecognizeXFAVersionNumber(wsData) != - XFA_VERSION_UNKNOWN)) { - wsData.clear(); - if (pXMLInstruction->GetData(1, wsData) && - wsData == L"v2.7-scripting:1") { - pXFANode->GetDocument()->SetFlag(XFA_DOCFLAG_Scripting, true); - } + if (target_data.size() > 1 && + (pXFANode->GetDocument()->RecognizeXFAVersionNumber(target_data[0]) != + XFA_VERSION_UNKNOWN) && + target_data[1] == L"v2.7-scripting:1") { + pXFANode->GetDocument()->SetFlag(XFA_DOCFLAG_Scripting, true); } } else if (wsTargetName == L"acrobat") { - CFX_WideString wsData; - if (pXMLInstruction->GetData(0, wsData) && wsData == L"JavaScript") { - if (pXMLInstruction->GetData(1, wsData) && wsData == L"strictScoping") { - pXFANode->GetDocument()->SetFlag(XFA_DOCFLAG_StrictScoping, true); - } + if (target_data.size() > 1 && target_data[0] == L"JavaScript" && + target_data[1] == L"strictScoping") { + pXFANode->GetDocument()->SetFlag(XFA_DOCFLAG_StrictScoping, true); } } } diff --git a/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_simple_parser.h b/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_simple_parser.h index 5f61ad7d28f..a9bcec21390 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_simple_parser.h +++ b/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_simple_parser.h @@ -9,12 +9,14 @@ #include <memory> -#include "xfa/fde/xml/fde_xml_imp.h" #include "xfa/fxfa/fxfa_basic.h" class CXFA_Document; class CXFA_Node; -class CXFA_XMLParser; +class CFDE_XMLDoc; +class CFDE_XMLInstruction; +class CFDE_XMLNode; +class CFDE_XMLParser; class IFX_SeekableReadStream; class IFX_Pause; class IFGAS_Stream; @@ -76,7 +78,7 @@ class CXFA_SimpleParser { CFDE_XMLInstruction* pXMLInstruction, XFA_XDPPACKET ePacketID); - CXFA_XMLParser* m_pXMLParser; + CFDE_XMLParser* m_pXMLParser; std::unique_ptr<CFDE_XMLDoc> m_pXMLDoc; CFX_RetainPtr<IFGAS_Stream> m_pStream; CFX_RetainPtr<IFX_SeekableReadStream> m_pFileRead; diff --git a/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_stroke.cpp b/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_stroke.cpp index 602f2f9f1fa..df11cbee00c 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_stroke.cpp +++ b/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_stroke.cpp @@ -7,7 +7,8 @@ #include "xfa/fxfa/parser/cxfa_stroke.h" #include "xfa/fxfa/parser/cxfa_measurement.h" -#include "xfa/fxfa/parser/xfa_object.h" +#include "xfa/fxfa/parser/cxfa_node.h" +#include "xfa/fxfa/parser/xfa_utils.h" int32_t CXFA_Stroke::GetPresence() const { return m_pNode ? m_pNode->GetEnum(XFA_ATTRIBUTE_Presence) @@ -25,7 +26,7 @@ int32_t CXFA_Stroke::GetStrokeType() const { : XFA_ATTRIBUTEENUM_Solid; } -FX_FLOAT CXFA_Stroke::GetThickness() const { +float CXFA_Stroke::GetThickness() const { return GetMSThickness().ToUnit(XFA_UNIT_Pt); } @@ -80,7 +81,7 @@ bool CXFA_Stroke::IsInverted() const { return m_pNode ? m_pNode->GetBoolean(XFA_ATTRIBUTE_Inverted) : false; } -FX_FLOAT CXFA_Stroke::GetRadius() const { +float CXFA_Stroke::GetRadius() const { return m_pNode ? m_pNode->GetMeasure(XFA_ATTRIBUTE_Radius).ToUnit(XFA_UNIT_Pt) : 0; } @@ -88,7 +89,7 @@ FX_FLOAT CXFA_Stroke::GetRadius() const { bool CXFA_Stroke::SameStyles(CXFA_Stroke stroke, uint32_t dwFlags) const { if (m_pNode == stroke.GetNode()) return true; - if (FXSYS_fabs(GetThickness() - stroke.GetThickness()) >= 0.01f) + if (fabs(GetThickness() - stroke.GetThickness()) >= 0.01f) return false; if ((dwFlags & XFA_STROKE_SAMESTYLE_NoPresence) == 0 && IsVisible() != stroke.IsVisible()) { @@ -99,7 +100,7 @@ bool CXFA_Stroke::SameStyles(CXFA_Stroke stroke, uint32_t dwFlags) const { if (GetColor() != stroke.GetColor()) return false; if ((dwFlags & XFA_STROKE_SAMESTYLE_Corner) != 0 && - FXSYS_fabs(GetRadius() - stroke.GetRadius()) >= 0.01f) { + fabs(GetRadius() - stroke.GetRadius()) >= 0.01f) { return false; } return true; diff --git a/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_stroke.h b/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_stroke.h index cf941c8f0f9..63709b91602 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_stroke.h +++ b/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_stroke.h @@ -30,14 +30,14 @@ class CXFA_Stroke : public CXFA_Data { int32_t GetPresence() const; int32_t GetCapType() const; int32_t GetStrokeType() const; - FX_FLOAT GetThickness() const; + float GetThickness() const; CXFA_Measurement GetMSThickness() const; void SetMSThickness(CXFA_Measurement msThinkness); FX_ARGB GetColor() const; void SetColor(FX_ARGB argb); int32_t GetJoinType() const; bool IsInverted() const; - FX_FLOAT GetRadius() const; + float GetRadius() const; bool SameStyles(CXFA_Stroke stroke, uint32_t dwFlags = 0) const; }; diff --git a/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_submit.cpp b/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_submit.cpp index 50bef1e811a..e390e6314b6 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_submit.cpp +++ b/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_submit.cpp @@ -6,7 +6,7 @@ #include "xfa/fxfa/parser/cxfa_submit.h" -#include "xfa/fxfa/parser/xfa_object.h" +#include "xfa/fxfa/parser/cxfa_node.h" CXFA_Submit::CXFA_Submit(CXFA_Node* pNode) : CXFA_Data(pNode) {} diff --git a/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_text.cpp b/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_text.cpp index fc7d7aa280e..192a4deac45 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_text.cpp +++ b/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_text.cpp @@ -6,7 +6,7 @@ #include "xfa/fxfa/parser/cxfa_text.h" -#include "xfa/fxfa/parser/xfa_object.h" +#include "xfa/fxfa/parser/cxfa_node.h" CXFA_Text::CXFA_Text(CXFA_Node* pNode) : CXFA_Data(pNode) {} diff --git a/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_thisproxy.cpp b/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_thisproxy.cpp index bf6f12c804d..2938c1fb3fb 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_thisproxy.cpp +++ b/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_thisproxy.cpp @@ -4,7 +4,9 @@ // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com -#include "xfa/fxfa/parser/xfa_object.h" +#include "xfa/fxfa/parser/cxfa_thisproxy.h" + +#include "xfa/fxfa/parser/cxfa_node.h" CXFA_ThisProxy::CXFA_ThisProxy(CXFA_Node* pThisNode, CXFA_Node* pScriptNode) : CXFA_Object(pThisNode->GetDocument(), @@ -18,11 +20,3 @@ CXFA_ThisProxy::CXFA_ThisProxy(CXFA_Node* pThisNode, CXFA_Node* pScriptNode) } CXFA_ThisProxy::~CXFA_ThisProxy() {} - -CXFA_Node* CXFA_ThisProxy::GetThisNode() const { - return m_pThisNode; -} - -CXFA_Node* CXFA_ThisProxy::GetScriptNode() const { - return m_pScriptNode; -} diff --git a/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_thisproxy.h b/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_thisproxy.h new file mode 100644 index 00000000000..4bb0f5a1b53 --- /dev/null +++ b/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_thisproxy.h @@ -0,0 +1,27 @@ +// Copyright 2017 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#ifndef XFA_FXFA_PARSER_CXFA_THISPROXY_H_ +#define XFA_FXFA_PARSER_CXFA_THISPROXY_H_ + +#include "xfa/fxfa/parser/cxfa_object.h" + +class CXFA_Node; + +class CXFA_ThisProxy : public CXFA_Object { + public: + CXFA_ThisProxy(CXFA_Node* pThisNode, CXFA_Node* pScriptNode); + ~CXFA_ThisProxy() override; + + CXFA_Node* GetThisNode() const { return m_pThisNode; } + CXFA_Node* GetScriptNode() const { return m_pScriptNode; } + + private: + CXFA_Node* m_pThisNode; + CXFA_Node* m_pScriptNode; +}; + +#endif // XFA_FXFA_PARSER_CXFA_THISPROXY_H_ diff --git a/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_timezoneprovider.cpp b/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_timezoneprovider.cpp new file mode 100644 index 00000000000..022b9225b47 --- /dev/null +++ b/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_timezoneprovider.cpp @@ -0,0 +1,32 @@ +// Copyright 2017 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#include "xfa/fxfa/parser/cxfa_timezoneprovider.h" + +#include <time.h> + +static bool g_bProviderTimeZoneSet = false; + +CXFA_TimeZoneProvider::CXFA_TimeZoneProvider() { +#if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ + if (!g_bProviderTimeZoneSet) { + g_bProviderTimeZoneSet = true; + _tzset(); + } + m_tz.tzHour = static_cast<int8_t>(_timezone / 3600 * -1); + m_tz.tzMinute = static_cast<int8_t>((abs(_timezone) % 3600) / 60); +#else + if (!g_bProviderTimeZoneSet) { + g_bProviderTimeZoneSet = true; + tzset(); + } + m_tz.tzHour = static_cast<int8_t>(timezone / 3600 * -1); + m_tz.tzMinute = + static_cast<int8_t>((abs(static_cast<int>(timezone)) % 3600) / 60); +#endif +} + +CXFA_TimeZoneProvider::~CXFA_TimeZoneProvider() {} diff --git a/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_timezoneprovider.h b/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_timezoneprovider.h new file mode 100644 index 00000000000..753fbb74daa --- /dev/null +++ b/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_timezoneprovider.h @@ -0,0 +1,23 @@ +// Copyright 2017 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#ifndef XFA_FXFA_PARSER_CXFA_TIMEZONEPROVIDER_H_ +#define XFA_FXFA_PARSER_CXFA_TIMEZONEPROVIDER_H_ + +#include "core/fxcrt/cfx_datetime.h" + +class CXFA_TimeZoneProvider { + public: + CXFA_TimeZoneProvider(); + ~CXFA_TimeZoneProvider(); + + FX_TIMEZONE GetTimeZone() const { return m_tz; } + + private: + FX_TIMEZONE m_tz; +}; + +#endif // XFA_FXFA_PARSER_CXFA_TIMEZONEPROVIDER_H_ diff --git a/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_tooltip.cpp b/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_tooltip.cpp index afe0e224afa..f3de7aa5916 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_tooltip.cpp +++ b/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_tooltip.cpp @@ -6,7 +6,7 @@ #include "xfa/fxfa/parser/cxfa_tooltip.h" -#include "xfa/fxfa/parser/xfa_object.h" +#include "xfa/fxfa/parser/cxfa_node.h" CXFA_ToolTip::CXFA_ToolTip(CXFA_Node* pNode) : CXFA_Data(pNode) {} diff --git a/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_traversestrategy_xfacontainernode.h b/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_traversestrategy_xfacontainernode.h new file mode 100644 index 00000000000..d507c262fef --- /dev/null +++ b/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_traversestrategy_xfacontainernode.h @@ -0,0 +1,33 @@ +// Copyright 2017 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#ifndef XFA_FXFA_PARSER_CXFA_TRAVERSESTRATEGY_XFACONTAINERNODE_H_ +#define XFA_FXFA_PARSER_CXFA_TRAVERSESTRATEGY_XFACONTAINERNODE_H_ + +#include "xfa/fxfa/parser/cxfa_node.h" +#include "xfa/fxfa/parser/xfa_utils.h" + +class CXFA_TraverseStrategy_XFAContainerNode { + public: + static CXFA_Node* GetFirstChild(CXFA_Node* pTemplateNode) { + return pTemplateNode->GetNodeItem(XFA_NODEITEM_FirstChild, + XFA_ObjectType::ContainerNode); + } + static CXFA_Node* GetNextSibling(CXFA_Node* pTemplateNode) { + return pTemplateNode->GetNodeItem(XFA_NODEITEM_NextSibling, + XFA_ObjectType::ContainerNode); + } + static CXFA_Node* GetParent(CXFA_Node* pTemplateNode) { + return pTemplateNode->GetNodeItem(XFA_NODEITEM_Parent, + XFA_ObjectType::ContainerNode); + } +}; + +typedef CXFA_NodeIteratorTemplate<CXFA_Node, + CXFA_TraverseStrategy_XFAContainerNode> + CXFA_ContainerIterator; + +#endif // XFA_FXFA_PARSER_CXFA_TRAVERSESTRATEGY_XFACONTAINERNODE_H_ diff --git a/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_traversestrategy_xfanode.h b/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_traversestrategy_xfanode.h new file mode 100644 index 00000000000..b6fb156cb95 --- /dev/null +++ b/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_traversestrategy_xfanode.h @@ -0,0 +1,28 @@ +// Copyright 2017 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#ifndef XFA_FXFA_PARSER_CXFA_TRAVERSESTRATEGY_XFANODE_H_ +#define XFA_FXFA_PARSER_CXFA_TRAVERSESTRATEGY_XFANODE_H_ + +#include "xfa/fxfa/parser/xfa_utils.h" + +class CXFA_TraverseStrategy_XFANode { + public: + static inline CXFA_Node* GetFirstChild(CXFA_Node* pTemplateNode) { + return pTemplateNode->GetNodeItem(XFA_NODEITEM_FirstChild); + } + static inline CXFA_Node* GetNextSibling(CXFA_Node* pTemplateNode) { + return pTemplateNode->GetNodeItem(XFA_NODEITEM_NextSibling); + } + static inline CXFA_Node* GetParent(CXFA_Node* pTemplateNode) { + return pTemplateNode->GetNodeItem(XFA_NODEITEM_Parent); + } +}; + +typedef CXFA_NodeIteratorTemplate<CXFA_Node, CXFA_TraverseStrategy_XFANode> + CXFA_NodeIterator; + +#endif // XFA_FXFA_PARSER_CXFA_TRAVERSESTRATEGY_XFANODE_H_ diff --git a/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_validate.cpp b/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_validate.cpp index 5706d96aaa3..712d0f28297 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_validate.cpp +++ b/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_validate.cpp @@ -6,7 +6,8 @@ #include "xfa/fxfa/parser/cxfa_validate.h" -#include "xfa/fxfa/parser/xfa_object.h" +#include "xfa/fxfa/parser/cxfa_node.h" +#include "xfa/fxfa/parser/xfa_utils.h" CXFA_Validate::CXFA_Validate(CXFA_Node* pNode) : CXFA_Data(pNode) {} diff --git a/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_validate.h b/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_validate.h index 03bbaddf7bb..470cefe7735 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_validate.h +++ b/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_validate.h @@ -31,7 +31,7 @@ class CXFA_Validate : public CXFA_Data { void GetPicture(CFX_WideString& wsPicture); CXFA_Script GetScript(); - protected: + private: void GetMessageText(CFX_WideString& wsMessage, const CFX_WideString& wsMessageType); void SetMessageText(CFX_WideString& wsMessage, diff --git a/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_value.cpp b/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_value.cpp index 4d467aee2c5..4f166d5d420 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_value.cpp +++ b/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_value.cpp @@ -6,7 +6,7 @@ #include "xfa/fxfa/parser/cxfa_value.h" -#include "xfa/fxfa/parser/xfa_object.h" +#include "xfa/fxfa/parser/cxfa_node.h" XFA_Element CXFA_Value::GetChildValueClassID() { if (!m_pNode) diff --git a/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_valuearray.cpp b/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_valuearray.cpp index 04afc40b0ee..eded624c360 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_valuearray.cpp +++ b/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_valuearray.cpp @@ -6,17 +6,20 @@ #include "xfa/fxfa/parser/cxfa_valuearray.h" +#include <algorithm> + #include "xfa/fxfa/parser/cxfa_scriptcontext.h" CXFA_ValueArray::CXFA_ValueArray(v8::Isolate* pIsolate) : m_pIsolate(pIsolate) {} -CXFA_ValueArray::~CXFA_ValueArray() { - for (int32_t i = 0; i < GetSize(); i++) - delete GetAt(i); -} +CXFA_ValueArray::~CXFA_ValueArray() {} -void CXFA_ValueArray::GetAttributeObject(CXFA_ObjArray& objArray) { - for (int32_t i = 0; i < GetSize(); i++) - objArray.Add(CXFA_ScriptContext::ToObject(GetAt(i), nullptr)); +std::vector<CXFA_Object*> CXFA_ValueArray::GetAttributeObject() { + std::vector<CXFA_Object*> result(m_Values.size()); + std::transform(m_Values.begin(), m_Values.end(), result.begin(), + [](const std::unique_ptr<CFXJSE_Value>& value) { + return CXFA_ScriptContext::ToObject(value.get(), nullptr); + }); + return result; } diff --git a/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_valuearray.h b/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_valuearray.h index 2c4ea297796..f0c5d234c91 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_valuearray.h +++ b/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_valuearray.h @@ -7,17 +7,21 @@ #ifndef XFA_FXFA_PARSER_CXFA_VALUEARRAY_H_ #define XFA_FXFA_PARSER_CXFA_VALUEARRAY_H_ +#include <memory> +#include <vector> + #include "fxjs/cfxjse_value.h" #include "xfa/fxfa/fxfa.h" -class CXFA_ValueArray : public CFX_ArrayTemplate<CFXJSE_Value*> { +class CXFA_ValueArray { public: explicit CXFA_ValueArray(v8::Isolate* pIsolate); ~CXFA_ValueArray(); - void GetAttributeObject(CXFA_ObjArray& objArray); + std::vector<CXFA_Object*> GetAttributeObject(); v8::Isolate* const m_pIsolate; + std::vector<std::unique_ptr<CFXJSE_Value>> m_Values; }; #endif // XFA_FXFA_PARSER_CXFA_VALUEARRAY_H_ diff --git a/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_widetextread.cpp b/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_widetextread.cpp deleted file mode 100644 index 34fa6b9c5e5..00000000000 --- a/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_widetextread.cpp +++ /dev/null @@ -1,102 +0,0 @@ -// Copyright 2016 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#include "xfa/fxfa/parser/cxfa_widetextread.h" - -#include <algorithm> - -#include "core/fxcrt/fx_ext.h" -#include "xfa/fgas/crt/fgas_codepage.h" - -CXFA_WideTextRead::CXFA_WideTextRead(const CFX_WideString& wsBuffer) - : m_wsBuffer(wsBuffer), m_iPosition(0) {} - -CXFA_WideTextRead::~CXFA_WideTextRead() {} - -uint32_t CXFA_WideTextRead::GetAccessModes() const { - return FX_STREAMACCESS_Read | FX_STREAMACCESS_Text; -} - -int32_t CXFA_WideTextRead::GetLength() const { - return m_wsBuffer.GetLength() * sizeof(FX_WCHAR); -} - -int32_t CXFA_WideTextRead::Seek(FX_STREAMSEEK eSeek, int32_t iOffset) { - switch (eSeek) { - case FX_STREAMSEEK_Begin: - m_iPosition = iOffset; - break; - case FX_STREAMSEEK_Current: - m_iPosition += iOffset; - break; - case FX_STREAMSEEK_End: - m_iPosition = m_wsBuffer.GetLength() + iOffset; - break; - } - m_iPosition = std::min(std::max(0, m_iPosition), m_wsBuffer.GetLength()); - return GetPosition(); -} - -int32_t CXFA_WideTextRead::GetPosition() { - return m_iPosition * sizeof(FX_WCHAR); -} - -bool CXFA_WideTextRead::IsEOF() const { - return m_iPosition >= m_wsBuffer.GetLength(); -} - -int32_t CXFA_WideTextRead::ReadData(uint8_t* pBuffer, int32_t iBufferSize) { - return 0; -} - -int32_t CXFA_WideTextRead::ReadString(FX_WCHAR* pStr, - int32_t iMaxLength, - bool& bEOS) { - iMaxLength = std::min(iMaxLength, m_wsBuffer.GetLength() - m_iPosition); - if (iMaxLength == 0) - return 0; - - FXSYS_wcsncpy(pStr, m_wsBuffer.c_str() + m_iPosition, iMaxLength); - m_iPosition += iMaxLength; - bEOS = IsEOF(); - return iMaxLength; -} - -int32_t CXFA_WideTextRead::WriteData(const uint8_t* pBuffer, - int32_t iBufferSize) { - return 0; -} - -int32_t CXFA_WideTextRead::WriteString(const FX_WCHAR* pStr, int32_t iLength) { - return 0; -} - -bool CXFA_WideTextRead::SetLength(int32_t iLength) { - return false; -} - -int32_t CXFA_WideTextRead::GetBOM(uint8_t bom[4]) const { - return 0; -} - -uint16_t CXFA_WideTextRead::GetCodePage() const { - return (sizeof(FX_WCHAR) == 2) ? FX_CODEPAGE_UTF16LE : FX_CODEPAGE_UTF32LE; -} - -uint16_t CXFA_WideTextRead::SetCodePage(uint16_t wCodePage) { - return GetCodePage(); -} - -CFX_RetainPtr<IFGAS_Stream> CXFA_WideTextRead::CreateSharedStream( - uint32_t dwAccess, - int32_t iOffset, - int32_t iLength) { - return nullptr; -} - -CFX_WideString CXFA_WideTextRead::GetSrcText() const { - return m_wsBuffer; -} diff --git a/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_widetextread.h b/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_widetextread.h deleted file mode 100644 index 2ccb042908c..00000000000 --- a/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_widetextread.h +++ /dev/null @@ -1,47 +0,0 @@ -// Copyright 2016 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#ifndef XFA_FXFA_PARSER_CXFA_WIDETEXTREAD_H_ -#define XFA_FXFA_PARSER_CXFA_WIDETEXTREAD_H_ - -#include "core/fxcrt/cfx_retain_ptr.h" -#include "xfa/fgas/crt/fgas_stream.h" - -class CXFA_WideTextRead : public IFGAS_Stream { - public: - template <typename T, typename... Args> - friend CFX_RetainPtr<T> pdfium::MakeRetain(Args&&... args); - - // IFGAS_Stream - uint32_t GetAccessModes() const override; - int32_t GetLength() const override; - int32_t Seek(FX_STREAMSEEK eSeek, int32_t iOffset) override; - int32_t GetPosition() override; - bool IsEOF() const override; - int32_t ReadData(uint8_t* pBuffer, int32_t iBufferSize) override; - int32_t ReadString(FX_WCHAR* pStr, int32_t iMaxLength, bool& bEOS) override; - int32_t WriteData(const uint8_t* pBuffer, int32_t iBufferSize) override; - int32_t WriteString(const FX_WCHAR* pStr, int32_t iLength) override; - void Flush() override {} - bool SetLength(int32_t iLength) override; - int32_t GetBOM(uint8_t bom[4]) const override; - uint16_t GetCodePage() const override; - uint16_t SetCodePage(uint16_t wCodePage) override; - CFX_RetainPtr<IFGAS_Stream> CreateSharedStream(uint32_t dwAccess, - int32_t iOffset, - int32_t iLength) override; - - CFX_WideString GetSrcText() const; - - protected: - explicit CXFA_WideTextRead(const CFX_WideString& wsBuffer); - ~CXFA_WideTextRead() override; - - CFX_WideString m_wsBuffer; - int32_t m_iPosition; -}; - -#endif // XFA_FXFA_PARSER_CXFA_WIDETEXTREAD_H_ diff --git a/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_widgetdata.cpp b/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_widgetdata.cpp index d3533c277aa..8784b6e9d13 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_widgetdata.cpp +++ b/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_widgetdata.cpp @@ -6,22 +6,24 @@ #include "xfa/fxfa/parser/cxfa_widgetdata.h" +#include "core/fxcrt/cfx_decimal.h" #include "core/fxcrt/fx_ext.h" +#include "fxbarcode/BC_Library.h" #include "third_party/base/stl_util.h" -#include "xfa/fxbarcode/BC_Library.h" #include "xfa/fxfa/app/xfa_ffnotify.h" #include "xfa/fxfa/parser/cxfa_document.h" #include "xfa/fxfa/parser/cxfa_event.h" +#include "xfa/fxfa/parser/cxfa_localevalue.h" #include "xfa/fxfa/parser/cxfa_measurement.h" -#include "xfa/fxfa/parser/xfa_localevalue.h" -#include "xfa/fxfa/parser/xfa_object.h" +#include "xfa/fxfa/parser/cxfa_node.h" +#include "xfa/fxfa/parser/xfa_utils.h" namespace { -FX_FLOAT GetEdgeThickness(const std::vector<CXFA_Stroke>& strokes, - bool b3DStyle, - int32_t nIndex) { - FX_FLOAT fThickness = 0; +float GetEdgeThickness(const std::vector<CXFA_Stroke>& strokes, + bool b3DStyle, + int32_t nIndex) { + float fThickness = 0; if (strokes[nIndex * 2 + 1].GetPresence() == XFA_ATTRIBUTEENUM_Visible) { if (nIndex == 0) @@ -225,7 +227,7 @@ CFX_WideStringC GetAttributeDefaultValue_Cdata(XFA_Element eElement, void* pValue; if (XFA_GetAttributeDefaultValue(pValue, eElement, eAttribute, XFA_ATTRIBUTETYPE_Cdata, dwPacket)) { - return (const FX_WCHAR*)pValue; + return (const wchar_t*)pValue; } return nullptr; } @@ -315,35 +317,32 @@ CXFA_Para CXFA_WidgetData::GetPara(bool bModified) { return CXFA_Para(m_pNode->GetProperty(0, XFA_Element::Para, bModified)); } -void CXFA_WidgetData::GetEventList(CXFA_NodeArray& events) { - m_pNode->GetNodeList(events, 0, XFA_Element::Event); +std::vector<CXFA_Node*> CXFA_WidgetData::GetEventList() { + return m_pNode->GetNodeList(0, XFA_Element::Event); } -int32_t CXFA_WidgetData::GetEventByActivity(int32_t iActivity, - CXFA_NodeArray& events, - bool bIsFormReady) { - CXFA_NodeArray allEvents; - GetEventList(allEvents); - int32_t iCount = allEvents.GetSize(); - for (int32_t i = 0; i < iCount; i++) { - CXFA_Event event(allEvents[i]); +std::vector<CXFA_Node*> CXFA_WidgetData::GetEventByActivity(int32_t iActivity, + bool bIsFormReady) { + std::vector<CXFA_Node*> events; + for (CXFA_Node* pNode : GetEventList()) { + CXFA_Event event(pNode); if (event.GetActivity() == iActivity) { if (iActivity == XFA_ATTRIBUTEENUM_Ready) { CFX_WideStringC wsRef; event.GetRef(wsRef); if (bIsFormReady) { if (wsRef == CFX_WideStringC(L"$form")) - events.Add(allEvents[i]); + events.push_back(pNode); } else { if (wsRef == CFX_WideStringC(L"$layout")) - events.Add(allEvents[i]); + events.push_back(pNode); } } else { - events.Add(allEvents[i]); + events.push_back(pNode); } } } - return events.GetSize(); + return events; } CXFA_Value CXFA_WidgetData::GetDefaultValue(bool bModified) { @@ -375,27 +374,27 @@ CXFA_Assist CXFA_WidgetData::GetAssist(bool bModified) { return CXFA_Assist(m_pNode->GetProperty(0, XFA_Element::Assist, bModified)); } -bool CXFA_WidgetData::GetWidth(FX_FLOAT& fWidth) { +bool CXFA_WidgetData::GetWidth(float& fWidth) { return TryMeasure(XFA_ATTRIBUTE_W, fWidth); } -bool CXFA_WidgetData::GetHeight(FX_FLOAT& fHeight) { +bool CXFA_WidgetData::GetHeight(float& fHeight) { return TryMeasure(XFA_ATTRIBUTE_H, fHeight); } -bool CXFA_WidgetData::GetMinWidth(FX_FLOAT& fMinWidth) { +bool CXFA_WidgetData::GetMinWidth(float& fMinWidth) { return TryMeasure(XFA_ATTRIBUTE_MinW, fMinWidth); } -bool CXFA_WidgetData::GetMinHeight(FX_FLOAT& fMinHeight) { +bool CXFA_WidgetData::GetMinHeight(float& fMinHeight) { return TryMeasure(XFA_ATTRIBUTE_MinH, fMinHeight); } -bool CXFA_WidgetData::GetMaxWidth(FX_FLOAT& fMaxWidth) { +bool CXFA_WidgetData::GetMaxWidth(float& fMaxWidth) { return TryMeasure(XFA_ATTRIBUTE_MaxW, fMaxWidth); } -bool CXFA_WidgetData::GetMaxHeight(FX_FLOAT& fMaxHeight) { +bool CXFA_WidgetData::GetMaxHeight(float& fMaxHeight) { return TryMeasure(XFA_ATTRIBUTE_MaxH, fMaxHeight); } @@ -419,14 +418,14 @@ CFX_RectF CXFA_WidgetData::GetUIMargin() { if (border && border.GetPresence() != XFA_ATTRIBUTEENUM_Visible) return CFX_RectF(); - FX_FLOAT fLeftInset, fTopInset, fRightInset, fBottomInset; + float fLeftInset, fTopInset, fRightInset, fBottomInset; bool bLeft = mgUI.GetLeftInset(fLeftInset); bool bTop = mgUI.GetTopInset(fTopInset); bool bRight = mgUI.GetRightInset(fRightInset); bool bBottom = mgUI.GetBottomInset(fBottomInset); if (border) { bool bVisible = false; - FX_FLOAT fThickness = 0; + float fThickness = 0; border.Get3DStyle(bVisible, fThickness); if (!bLeft || !bTop || !bRight || !bBottom) { std::vector<CXFA_Stroke> strokes; @@ -509,7 +508,7 @@ bool CXFA_WidgetData::IsRadioButton() { return false; } -FX_FLOAT CXFA_WidgetData::GetCheckButtonSize() { +float CXFA_WidgetData::GetCheckButtonSize() { CXFA_Node* pUIChild = GetUIChild(); if (pUIChild) return pUIChild->GetMeasure(XFA_ATTRIBUTE_Size).ToUnit(XFA_UNIT_Pt); @@ -733,35 +732,32 @@ int32_t CXFA_WidgetData::GetChoiceListOpen() { bool CXFA_WidgetData::IsListBox() { int32_t iOpenMode = GetChoiceListOpen(); - return (iOpenMode == XFA_ATTRIBUTEENUM_Always || - iOpenMode == XFA_ATTRIBUTEENUM_MultiSelect); + return iOpenMode == XFA_ATTRIBUTEENUM_Always || + iOpenMode == XFA_ATTRIBUTEENUM_MultiSelect; } int32_t CXFA_WidgetData::CountChoiceListItems(bool bSaveValue) { - CXFA_NodeArray pItems; - CXFA_Node* pItem = nullptr; + std::vector<CXFA_Node*> pItems; int32_t iCount = 0; - CXFA_Node* pNode = m_pNode->GetNodeItem(XFA_NODEITEM_FirstChild); - for (; pNode; pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) { + for (CXFA_Node* pNode = m_pNode->GetNodeItem(XFA_NODEITEM_FirstChild); pNode; + pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) { if (pNode->GetElementType() != XFA_Element::Items) continue; - iCount++; - pItems.Add(pNode); + pItems.push_back(pNode); if (iCount == 2) break; } if (iCount == 0) return 0; - pItem = pItems[0]; + CXFA_Node* pItem = pItems[0]; if (iCount > 1) { bool bItemOneHasSave = pItems[0]->GetBoolean(XFA_ATTRIBUTE_Save); bool bItemTwoHasSave = pItems[1]->GetBoolean(XFA_ATTRIBUTE_Save); if (bItemOneHasSave != bItemTwoHasSave && bSaveValue == bItemTwoHasSave) pItem = pItems[1]; } - pItems.RemoveAll(); return pItem->CountChildren(XFA_Element::Unknown); } @@ -769,16 +765,15 @@ bool CXFA_WidgetData::GetChoiceListItem(CFX_WideString& wsText, int32_t nIndex, bool bSaveValue) { wsText.clear(); - CXFA_NodeArray pItemsArray; + std::vector<CXFA_Node*> pItemsArray; CXFA_Node* pItems = nullptr; int32_t iCount = 0; CXFA_Node* pNode = m_pNode->GetNodeItem(XFA_NODEITEM_FirstChild); for (; pNode; pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) { if (pNode->GetElementType() != XFA_Element::Items) continue; - iCount++; - pItemsArray.Add(pNode); + pItemsArray.push_back(pNode); if (iCount == 2) break; } @@ -802,97 +797,74 @@ bool CXFA_WidgetData::GetChoiceListItem(CFX_WideString& wsText, return false; } -void CXFA_WidgetData::GetChoiceListItems( - std::vector<CFX_WideString>& wsTextArray, +std::vector<CFX_WideString> CXFA_WidgetData::GetChoiceListItems( bool bSaveValue) { - CXFA_NodeArray pItems; - CXFA_Node* pItem = nullptr; - int32_t iCount = 0; - CXFA_Node* pNode = m_pNode->GetNodeItem(XFA_NODEITEM_FirstChild); - for (; pNode; pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) { - if (pNode->GetElementType() != XFA_Element::Items) - continue; - - iCount++; - pItems.Add(pNode); - if (iCount == 2) - break; + std::vector<CXFA_Node*> items; + for (CXFA_Node* pNode = m_pNode->GetNodeItem(XFA_NODEITEM_FirstChild); + pNode && items.size() < 2; + pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) { + if (pNode->GetElementType() == XFA_Element::Items) + items.push_back(pNode); } - if (iCount == 0) - return; + if (items.empty()) + return std::vector<CFX_WideString>(); - pItem = pItems[0]; - if (iCount > 1) { - bool bItemOneHasSave = pItems[0]->GetBoolean(XFA_ATTRIBUTE_Save); - bool bItemTwoHasSave = pItems[1]->GetBoolean(XFA_ATTRIBUTE_Save); + CXFA_Node* pItem = items.front(); + if (items.size() > 1) { + bool bItemOneHasSave = items[0]->GetBoolean(XFA_ATTRIBUTE_Save); + bool bItemTwoHasSave = items[1]->GetBoolean(XFA_ATTRIBUTE_Save); if (bItemOneHasSave != bItemTwoHasSave && bSaveValue == bItemTwoHasSave) - pItem = pItems[1]; + pItem = items[1]; } - pItems.RemoveAll(); - pNode = pItem->GetNodeItem(XFA_NODEITEM_FirstChild); - for (; pNode; pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) { + + std::vector<CFX_WideString> wsTextArray; + for (CXFA_Node* pNode = pItem->GetNodeItem(XFA_NODEITEM_FirstChild); pNode; + pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) { wsTextArray.emplace_back(); pNode->TryContent(wsTextArray.back()); } + return wsTextArray; } int32_t CXFA_WidgetData::CountSelectedItems() { - std::vector<CFX_WideString> wsValueArray; - GetSelectedItemsValue(wsValueArray); + std::vector<CFX_WideString> wsValueArray = GetSelectedItemsValue(); if (IsListBox() || !IsChoiceListAllowTextEntry()) return pdfium::CollectionSize<int32_t>(wsValueArray); int32_t iSelected = 0; - std::vector<CFX_WideString> wsSaveTextArray; - GetChoiceListItems(wsSaveTextArray, true); - int32_t iValues = pdfium::CollectionSize<int32_t>(wsValueArray); - for (int32_t i = 0; i < iValues; i++) { - int32_t iSaves = pdfium::CollectionSize<int32_t>(wsSaveTextArray); - for (int32_t j = 0; j < iSaves; j++) { - if (wsValueArray[i] == wsSaveTextArray[j]) { - iSelected++; - break; - } - } + std::vector<CFX_WideString> wsSaveTextArray = GetChoiceListItems(true); + for (const auto& value : wsValueArray) { + if (pdfium::ContainsValue(wsSaveTextArray, value)) + iSelected++; } return iSelected; } int32_t CXFA_WidgetData::GetSelectedItem(int32_t nIndex) { - std::vector<CFX_WideString> wsValueArray; - GetSelectedItemsValue(wsValueArray); - std::vector<CFX_WideString> wsSaveTextArray; - GetChoiceListItems(wsSaveTextArray, true); - int32_t iSaves = pdfium::CollectionSize<int32_t>(wsSaveTextArray); - for (int32_t j = 0; j < iSaves; j++) { - if (wsValueArray[nIndex] == wsSaveTextArray[j]) - return j; - } - return -1; -} + std::vector<CFX_WideString> wsValueArray = GetSelectedItemsValue(); + if (!pdfium::IndexInBounds(wsValueArray, nIndex)) + return -1; -void CXFA_WidgetData::GetSelectedItems(CFX_ArrayTemplate<int32_t>& iSelArray) { - std::vector<CFX_WideString> wsValueArray; - GetSelectedItemsValue(wsValueArray); - int32_t iValues = pdfium::CollectionSize<int32_t>(wsValueArray); - if (iValues < 1) - return; + std::vector<CFX_WideString> wsSaveTextArray = GetChoiceListItems(true); + auto it = std::find(wsSaveTextArray.begin(), wsSaveTextArray.end(), + wsValueArray[nIndex]); + return it != wsSaveTextArray.end() ? it - wsSaveTextArray.begin() : -1; +} - std::vector<CFX_WideString> wsSaveTextArray; - GetChoiceListItems(wsSaveTextArray, true); - int32_t iSaves = pdfium::CollectionSize<int32_t>(wsSaveTextArray); - for (int32_t i = 0; i < iValues; i++) { - for (int32_t j = 0; j < iSaves; j++) { - if (wsValueArray[i] == wsSaveTextArray[j]) { - iSelArray.Add(j); - break; - } - } +std::vector<int32_t> CXFA_WidgetData::GetSelectedItems() { + std::vector<int32_t> iSelArray; + std::vector<CFX_WideString> wsValueArray = GetSelectedItemsValue(); + std::vector<CFX_WideString> wsSaveTextArray = GetChoiceListItems(true); + for (const auto& value : wsValueArray) { + auto it = std::find(wsSaveTextArray.begin(), wsSaveTextArray.end(), value); + if (it != wsSaveTextArray.end()) + iSelArray.push_back(it - wsSaveTextArray.begin()); } + return iSelArray; } -void CXFA_WidgetData::GetSelectedItemsValue( - std::vector<CFX_WideString>& wsSelTextArray) { +std::vector<CFX_WideString> CXFA_WidgetData::GetSelectedItemsValue() { + std::vector<CFX_WideString> wsSelTextArray; CFX_WideString wsValue = GetRawValue(); if (GetChoiceListOpen() == XFA_ATTRIBUTEENUM_MultiSelect) { if (!wsValue.IsEmpty()) { @@ -905,7 +877,6 @@ void CXFA_WidgetData::GetSelectedItemsValue( iStart = iEnd + 1; if (iStart >= iLength) break; - iEnd = wsValue.Find(L'\n', iStart); if (iEnd < 0) wsSelTextArray.push_back(wsValue.Mid(iStart, iLength - iStart)); @@ -914,25 +885,14 @@ void CXFA_WidgetData::GetSelectedItemsValue( } else { wsSelTextArray.push_back(wsValue); } + return wsSelTextArray; } bool CXFA_WidgetData::GetItemState(int32_t nIndex) { - if (nIndex < 0) - return false; - - std::vector<CFX_WideString> wsSaveTextArray; - GetChoiceListItems(wsSaveTextArray, true); - if (pdfium::CollectionSize<int32_t>(wsSaveTextArray) <= nIndex) - return false; - - std::vector<CFX_WideString> wsValueArray; - GetSelectedItemsValue(wsValueArray); - int32_t iValues = pdfium::CollectionSize<int32_t>(wsValueArray); - for (int32_t j = 0; j < iValues; j++) { - if (wsValueArray[j] == wsSaveTextArray[nIndex]) - return true; - } - return false; + std::vector<CFX_WideString> wsSaveTextArray = GetChoiceListItems(true); + return pdfium::IndexInBounds(wsSaveTextArray, nIndex) && + pdfium::ContainsValue(GetSelectedItemsValue(), + wsSaveTextArray[nIndex]); } void CXFA_WidgetData::SetItemState(int32_t nIndex, @@ -940,24 +900,17 @@ void CXFA_WidgetData::SetItemState(int32_t nIndex, bool bNotify, bool bScriptModify, bool bSyncData) { - if (nIndex < 0) - return; - - std::vector<CFX_WideString> wsSaveTextArray; - GetChoiceListItems(wsSaveTextArray, true); - if (pdfium::CollectionSize<int32_t>(wsSaveTextArray) <= nIndex) + std::vector<CFX_WideString> wsSaveTextArray = GetChoiceListItems(true); + if (!pdfium::IndexInBounds(wsSaveTextArray, nIndex)) return; int32_t iSel = -1; - std::vector<CFX_WideString> wsValueArray; - GetSelectedItemsValue(wsValueArray); - int32_t iValues = pdfium::CollectionSize<int32_t>(wsValueArray); - for (int32_t j = 0; j < iValues; j++) { - if (wsValueArray[j] == wsSaveTextArray[nIndex]) { - iSel = j; - break; - } - } + std::vector<CFX_WideString> wsValueArray = GetSelectedItemsValue(); + auto it = std::find(wsValueArray.begin(), wsValueArray.end(), + wsSaveTextArray[nIndex]); + if (it != wsValueArray.end()) + iSel = it - wsValueArray.begin(); + if (GetChoiceListOpen() == XFA_ATTRIBUTEENUM_MultiSelect) { if (bSelected) { if (iSel < 0) { @@ -970,14 +923,10 @@ void CXFA_WidgetData::SetItemState(int32_t nIndex, bSyncData); } } else if (iSel >= 0) { - CFX_ArrayTemplate<int32_t> iSelArray; - GetSelectedItems(iSelArray); - for (int32_t i = 0; i < iSelArray.GetSize(); i++) { - if (iSelArray[i] == nIndex) { - iSelArray.RemoveAt(i); - break; - } - } + std::vector<int32_t> iSelArray = GetSelectedItems(); + auto it = std::find(iSelArray.begin(), iSelArray.end(), nIndex); + if (it != iSelArray.end()) + iSelArray.erase(it); SetSelectedItems(iSelArray, bNotify, bScriptModify, bSyncData); } } else { @@ -996,15 +945,14 @@ void CXFA_WidgetData::SetItemState(int32_t nIndex, } } -void CXFA_WidgetData::SetSelectedItems(CFX_ArrayTemplate<int32_t>& iSelArray, +void CXFA_WidgetData::SetSelectedItems(const std::vector<int32_t>& iSelArray, bool bNotify, bool bScriptModify, bool bSyncData) { CFX_WideString wsValue; - int32_t iSize = iSelArray.GetSize(); + int32_t iSize = pdfium::CollectionSize<int32_t>(iSelArray); if (iSize >= 1) { - std::vector<CFX_WideString> wsSaveTextArray; - GetChoiceListItems(wsSaveTextArray, true); + std::vector<CFX_WideString> wsSaveTextArray = GetChoiceListItems(true); CFX_WideString wsItemValue; for (int32_t i = 0; i < iSize; i++) { wsItemValue = (iSize == 1) ? wsSaveTextArray[iSelArray[i]] @@ -1038,18 +986,13 @@ void CXFA_WidgetData::InsertItem(const CFX_WideString& wsLabel, if (wsNewValue.IsEmpty()) wsNewValue = wsLabel; - CXFA_NodeArray listitems; - int32_t iCount = 0; - CXFA_Node* pItemNode = m_pNode->GetNodeItem(XFA_NODEITEM_FirstChild); - for (; pItemNode; - pItemNode = pItemNode->GetNodeItem(XFA_NODEITEM_NextSibling)) { - if (pItemNode->GetElementType() != XFA_Element::Items) - continue; - - listitems.Add(pItemNode); - iCount++; + std::vector<CXFA_Node*> listitems; + for (CXFA_Node* pItem = m_pNode->GetNodeItem(XFA_NODEITEM_FirstChild); pItem; + pItem = pItem->GetNodeItem(XFA_NODEITEM_NextSibling)) { + if (pItem->GetElementType() == XFA_Element::Items) + listitems.push_back(pItem); } - if (iCount < 1) { + if (listitems.empty()) { CXFA_Node* pItems = m_pNode->CreateSamePacketNode(XFA_Element::Items); m_pNode->InsertChild(-1, pItems); InsertListTextItem(pItems, wsLabel, nIndex); @@ -1057,7 +1000,7 @@ void CXFA_WidgetData::InsertItem(const CFX_WideString& wsLabel, m_pNode->InsertChild(-1, pSaveItems); pSaveItems->SetBoolean(XFA_ATTRIBUTE_Save, true); InsertListTextItem(pSaveItems, wsNewValue, nIndex); - } else if (iCount > 1) { + } else if (listitems.size() > 1) { for (int32_t i = 0; i < 2; i++) { CXFA_Node* pNode = listitems[i]; bool bHasSave = pNode->GetBoolean(XFA_ATTRIBUTE_Save); @@ -1074,7 +1017,6 @@ void CXFA_WidgetData::InsertItem(const CFX_WideString& wsLabel, m_pNode->InsertChild(-1, pSaveItems); pSaveItems->SetBoolean(XFA_ATTRIBUTE_Save, true); pSaveItems->SetEnum(XFA_ATTRIBUTE_Presence, XFA_ATTRIBUTEENUM_Hidden); - listitems.RemoveAll(); CXFA_Node* pListNode = pNode->GetNodeItem(XFA_NODEITEM_FirstChild); int32_t i = 0; while (pListNode) { @@ -1097,14 +1039,13 @@ void CXFA_WidgetData::InsertItem(const CFX_WideString& wsLabel, void CXFA_WidgetData::GetItemLabel(const CFX_WideStringC& wsValue, CFX_WideString& wsLabel) { int32_t iCount = 0; - CXFA_NodeArray listitems; + std::vector<CXFA_Node*> listitems; CXFA_Node* pItems = m_pNode->GetNodeItem(XFA_NODEITEM_FirstChild); for (; pItems; pItems = pItems->GetNodeItem(XFA_NODEITEM_NextSibling)) { if (pItems->GetElementType() != XFA_Element::Items) continue; - iCount++; - listitems.Add(pItems); + listitems.push_back(pItems); } if (iCount <= 1) { wsLabel = wsValue; @@ -1143,14 +1084,13 @@ void CXFA_WidgetData::GetItemLabel(const CFX_WideStringC& wsValue, void CXFA_WidgetData::GetItemValue(const CFX_WideStringC& wsLabel, CFX_WideString& wsValue) { int32_t iCount = 0; - CXFA_NodeArray listitems; - CXFA_Node* pItems = m_pNode->GetNodeItem(XFA_NODEITEM_FirstChild); - for (; pItems; pItems = pItems->GetNodeItem(XFA_NODEITEM_NextSibling)) { + std::vector<CXFA_Node*> listitems; + for (CXFA_Node* pItems = m_pNode->GetNodeItem(XFA_NODEITEM_FirstChild); + pItems; pItems = pItems->GetNodeItem(XFA_NODEITEM_NextSibling)) { if (pItems->GetElementType() != XFA_Element::Items) continue; - iCount++; - listitems.Add(pItems); + listitems.push_back(pItems); } if (iCount <= 1) { wsValue = wsLabel; @@ -1292,24 +1232,24 @@ bool CXFA_WidgetData::GetBarcodeAttribute_DataLength(int32_t& val) { return false; } -bool CXFA_WidgetData::GetBarcodeAttribute_StartChar(FX_CHAR& val) { +bool CXFA_WidgetData::GetBarcodeAttribute_StartChar(char& val) { CXFA_Node* pUIChild = GetUIChild(); CFX_WideStringC wsStartEndChar; if (pUIChild->TryCData(XFA_ATTRIBUTE_StartChar, wsStartEndChar)) { if (wsStartEndChar.GetLength()) { - val = (FX_CHAR)wsStartEndChar.GetAt(0); + val = (char)wsStartEndChar.GetAt(0); return true; } } return false; } -bool CXFA_WidgetData::GetBarcodeAttribute_EndChar(FX_CHAR& val) { +bool CXFA_WidgetData::GetBarcodeAttribute_EndChar(char& val) { CXFA_Node* pUIChild = GetUIChild(); CFX_WideStringC wsStartEndChar; if (pUIChild->TryCData(XFA_ATTRIBUTE_EndChar, wsStartEndChar)) { if (wsStartEndChar.GetLength()) { - val = (FX_CHAR)wsStartEndChar.GetAt(0); + val = (char)wsStartEndChar.GetAt(0); return true; } } @@ -1393,20 +1333,20 @@ bool CXFA_WidgetData::GetBarcodeAttribute_Truncate(bool& val) { return false; } -bool CXFA_WidgetData::GetBarcodeAttribute_WideNarrowRatio(FX_FLOAT& val) { +bool CXFA_WidgetData::GetBarcodeAttribute_WideNarrowRatio(float& val) { CXFA_Node* pUIChild = GetUIChild(); CFX_WideString wsWideNarrowRatio; if (pUIChild->TryCData(XFA_ATTRIBUTE_WideNarrowRatio, wsWideNarrowRatio)) { FX_STRSIZE ptPos = wsWideNarrowRatio.Find(':'); - FX_FLOAT fRatio = 0; + float fRatio = 0; if (ptPos >= 0) { - fRatio = (FX_FLOAT)FXSYS_wtoi(wsWideNarrowRatio.c_str()); + fRatio = (float)FXSYS_wtoi(wsWideNarrowRatio.c_str()); } else { int32_t fA, fB; fA = FXSYS_wtoi(wsWideNarrowRatio.Left(ptPos).c_str()); fB = FXSYS_wtoi(wsWideNarrowRatio.Mid(ptPos + 1).c_str()); if (fB) - fRatio = (FX_FLOAT)fA / fB; + fRatio = (float)fA / fB; } val = fRatio; return true; @@ -1548,7 +1488,7 @@ bool CXFA_WidgetData::GetPictureContent(CFX_WideString& wsPicture, return true; } } - CFX_WideString wsDataPicture, wsTimePicture; + IFX_Locale* pLocale = GetLocal(); if (!pLocale) return false; @@ -1556,19 +1496,18 @@ bool CXFA_WidgetData::GetPictureContent(CFX_WideString& wsPicture, uint32_t dwType = widgetValue.GetType(); switch (dwType) { case XFA_VT_DATE: - pLocale->GetDatePattern(FX_LOCALEDATETIMESUBCATEGORY_Medium, - wsPicture); + wsPicture = + pLocale->GetDatePattern(FX_LOCALEDATETIMESUBCATEGORY_Medium); break; case XFA_VT_TIME: - pLocale->GetTimePattern(FX_LOCALEDATETIMESUBCATEGORY_Medium, - wsPicture); + wsPicture = + pLocale->GetTimePattern(FX_LOCALEDATETIMESUBCATEGORY_Medium); break; case XFA_VT_DATETIME: - pLocale->GetDatePattern(FX_LOCALEDATETIMESUBCATEGORY_Medium, - wsDataPicture); - pLocale->GetTimePattern(FX_LOCALEDATETIMESUBCATEGORY_Medium, - wsTimePicture); - wsPicture = wsDataPicture + L"T" + wsTimePicture; + wsPicture = + pLocale->GetDatePattern(FX_LOCALEDATETIMESUBCATEGORY_Medium) + + L"T" + + pLocale->GetTimePattern(FX_LOCALEDATETIMESUBCATEGORY_Medium); break; case XFA_VT_DECIMAL: case XFA_VT_FLOAT: @@ -1578,7 +1517,6 @@ bool CXFA_WidgetData::GetPictureContent(CFX_WideString& wsPicture, } return true; } - case XFA_VALUEPICTURE_Edit: { CXFA_Node* pUI = m_pNode->GetChild(0, XFA_Element::Ui); if (pUI) { @@ -1587,32 +1525,29 @@ bool CXFA_WidgetData::GetPictureContent(CFX_WideString& wsPicture, return true; } } - { - CFX_WideString wsDataPicture, wsTimePicture; - IFX_Locale* pLocale = GetLocal(); - if (!pLocale) { - return false; - } - uint32_t dwType = widgetValue.GetType(); - switch (dwType) { - case XFA_VT_DATE: - pLocale->GetDatePattern(FX_LOCALEDATETIMESUBCATEGORY_Short, - wsPicture); - break; - case XFA_VT_TIME: - pLocale->GetTimePattern(FX_LOCALEDATETIMESUBCATEGORY_Short, - wsPicture); - break; - case XFA_VT_DATETIME: - pLocale->GetDatePattern(FX_LOCALEDATETIMESUBCATEGORY_Short, - wsDataPicture); - pLocale->GetTimePattern(FX_LOCALEDATETIMESUBCATEGORY_Short, - wsTimePicture); - wsPicture = wsDataPicture + L"T" + wsTimePicture; - break; - default: - break; - } + + IFX_Locale* pLocale = GetLocal(); + if (!pLocale) + return false; + + uint32_t dwType = widgetValue.GetType(); + switch (dwType) { + case XFA_VT_DATE: + wsPicture = + pLocale->GetDatePattern(FX_LOCALEDATETIMESUBCATEGORY_Short); + break; + case XFA_VT_TIME: + wsPicture = + pLocale->GetTimePattern(FX_LOCALEDATETIMESUBCATEGORY_Short); + break; + case XFA_VT_DATETIME: + wsPicture = + pLocale->GetDatePattern(FX_LOCALEDATETIMESUBCATEGORY_Short) + + L"T" + + pLocale->GetTimePattern(FX_LOCALEDATETIMESUBCATEGORY_Short); + break; + default: + break; } return true; } @@ -1659,7 +1594,7 @@ bool CXFA_WidgetData::GetValue(CFX_WideString& wsValue, if (eValueType == XFA_VALUEPICTURE_Display) { int32_t iSelItemIndex = GetSelectedItem(0); if (iSelItemIndex >= 0) { - GetChoiceListItem(wsValue, iSelItemIndex); + GetChoiceListItem(wsValue, iSelItemIndex, false); wsPicture.clear(); } } @@ -1845,8 +1780,8 @@ void CXFA_WidgetData::FormatNumStr(const CFX_WideString& wsValue, return; CFX_WideString wsSrcNum = wsValue; - CFX_WideString wsGroupSymbol; - pLocale->GetNumbericSymbol(FX_LOCALENUMSYMBOL_Grouping, wsGroupSymbol); + CFX_WideString wsGroupSymbol = + pLocale->GetNumbericSymbol(FX_LOCALENUMSYMBOL_Grouping); bool bNeg = false; if (wsSrcNum[0] == '-') { bNeg = true; @@ -1868,15 +1803,12 @@ void CXFA_WidgetData::FormatNumStr(const CFX_WideString& wsValue, wsOutput += wsSrcNum[i]; } if (dot_index < len) { - CFX_WideString wsSymbol; - pLocale->GetNumbericSymbol(FX_LOCALENUMSYMBOL_Decimal, wsSymbol); - wsOutput += wsSymbol; + wsOutput += pLocale->GetNumbericSymbol(FX_LOCALENUMSYMBOL_Decimal); wsOutput += wsSrcNum.Right(len - dot_index - 1); } if (bNeg) { - CFX_WideString wsMinusymbol; - pLocale->GetNumbericSymbol(FX_LOCALENUMSYMBOL_Minus, wsMinusymbol); - wsOutput = wsMinusymbol + wsOutput; + wsOutput = + pLocale->GetNumbericSymbol(FX_LOCALENUMSYMBOL_Minus) + wsOutput; } } } @@ -1919,7 +1851,7 @@ CFX_WideString CXFA_WidgetData::NumericLimit(const CFX_WideString& wsValue, i++; } for (; i < iCount; i++) { - FX_WCHAR wc = wsValue[i]; + wchar_t wc = wsValue[i]; if (FXSYS_isDecimalDigit(wc)) { if (iLead >= 0) { iLead_++; diff --git a/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_widgetdata.h b/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_widgetdata.h index 4f5db3bad6d..fb44745ad9f 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_widgetdata.h +++ b/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_widgetdata.h @@ -9,6 +9,7 @@ #include <vector> +#include "core/fxcrt/fx_coordinates.h" #include "core/fxcrt/fx_string.h" #include "core/fxcrt/fx_system.h" #include "xfa/fxfa/parser/cxfa_assist.h" @@ -21,7 +22,6 @@ #include "xfa/fxfa/parser/cxfa_margin.h" #include "xfa/fxfa/parser/cxfa_para.h" #include "xfa/fxfa/parser/cxfa_validate.h" -#include "xfa/fxfa/parser/xfa_object.h" enum XFA_CHECKSTATE { XFA_CHECKSTATE_On = 0, @@ -53,22 +53,21 @@ class CXFA_WidgetData : public CXFA_Data { CXFA_Font GetFont(bool bModified = false); CXFA_Margin GetMargin(bool bModified = false); CXFA_Para GetPara(bool bModified = false); - void GetEventList(CXFA_NodeArray& events); - int32_t GetEventByActivity(int32_t iActivity, - CXFA_NodeArray& events, - bool bIsFormReady = false); + std::vector<CXFA_Node*> GetEventList(); + std::vector<CXFA_Node*> GetEventByActivity(int32_t iActivity, + bool bIsFormReady = false); CXFA_Value GetDefaultValue(bool bModified = false); CXFA_Value GetFormValue(bool bModified = false); CXFA_Calculate GetCalculate(bool bModified = false); CXFA_Validate GetValidate(bool bModified = false); CXFA_Bind GetBind(bool bModified = false); CXFA_Assist GetAssist(bool bModified = false); - bool GetWidth(FX_FLOAT& fWidth); - bool GetHeight(FX_FLOAT& fHeight); - bool GetMinWidth(FX_FLOAT& fMinWidth); - bool GetMinHeight(FX_FLOAT& fMinHeight); - bool GetMaxWidth(FX_FLOAT& fMaxWidth); - bool GetMaxHeight(FX_FLOAT& fMaxHeight); + bool GetWidth(float& fWidth); + bool GetHeight(float& fHeight); + bool GetMinWidth(float& fMinWidth); + bool GetMinHeight(float& fMinHeight); + bool GetMaxWidth(float& fMaxWidth); + bool GetMaxHeight(float& fMaxHeight); CXFA_Border GetUIBorder(); CFX_RectF GetUIMargin(); int32_t GetButtonHighlight(); @@ -76,7 +75,7 @@ class CXFA_WidgetData : public CXFA_Data { bool GetButtonDown(CFX_WideString& wsDown, bool& bRichText); int32_t GetCheckButtonShape(); int32_t GetCheckButtonMark(); - FX_FLOAT GetCheckButtonSize(); + float GetCheckButtonSize(); bool IsAllowNeutral(); bool IsRadioButton(); XFA_CHECKSTATE GetCheckState(); @@ -94,23 +93,22 @@ class CXFA_WidgetData : public CXFA_Data { bool IsChoiceListAllowTextEntry(); int32_t GetChoiceListOpen(); bool IsListBox(); - int32_t CountChoiceListItems(bool bSaveValue = false); + int32_t CountChoiceListItems(bool bSaveValue); bool GetChoiceListItem(CFX_WideString& wsText, int32_t nIndex, - bool bSaveValue = false); - void GetChoiceListItems(std::vector<CFX_WideString>& wsTextArray, - bool bSaveValue = false); + bool bSaveValue); + std::vector<CFX_WideString> GetChoiceListItems(bool bSaveValue); int32_t CountSelectedItems(); int32_t GetSelectedItem(int32_t nIndex = 0); - void GetSelectedItems(CFX_ArrayTemplate<int32_t>& iSelArray); - void GetSelectedItemsValue(std::vector<CFX_WideString>& wsSelTextArray); + std::vector<int32_t> GetSelectedItems(); + std::vector<CFX_WideString> GetSelectedItemsValue(); bool GetItemState(int32_t nIndex); void SetItemState(int32_t nIndex, bool bSelected, bool bNotify, bool bScriptModify, bool bSyncData); - void SetSelectedItems(CFX_ArrayTemplate<int32_t>& iSelArray, + void SetSelectedItems(const std::vector<int32_t>& iSelArray, bool bNotify, bool bScriptModify, bool bSyncData); @@ -140,15 +138,15 @@ class CXFA_WidgetData : public CXFA_Data { bool GetBarcodeAttribute_CharEncoding(int32_t& val); bool GetBarcodeAttribute_Checksum(bool& val); bool GetBarcodeAttribute_DataLength(int32_t& val); - bool GetBarcodeAttribute_StartChar(FX_CHAR& val); - bool GetBarcodeAttribute_EndChar(FX_CHAR& val); + bool GetBarcodeAttribute_StartChar(char& val); + bool GetBarcodeAttribute_EndChar(char& val); bool GetBarcodeAttribute_ECLevel(int32_t& val); bool GetBarcodeAttribute_ModuleWidth(int32_t& val); bool GetBarcodeAttribute_ModuleHeight(int32_t& val); bool GetBarcodeAttribute_PrintChecksum(bool& val); bool GetBarcodeAttribute_TextLocation(int32_t& val); bool GetBarcodeAttribute_Truncate(bool& val); - bool GetBarcodeAttribute_WideNarrowRatio(FX_FLOAT& val); + bool GetBarcodeAttribute_WideNarrowRatio(float& val); void GetPasswordChar(CFX_WideString& wsPassWord); bool IsMultiLine(); int32_t GetVerticalScrollPolicy(); @@ -163,7 +161,7 @@ class CXFA_WidgetData : public CXFA_Data { bool m_bIsNull; bool m_bPreNull; - protected: + private: void SyncValue(const CFX_WideString& wsValue, bool bNotify); void InsertListTextItem(CXFA_Node* pItems, const CFX_WideString& wsText, diff --git a/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_xml_parser.cpp b/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_xml_parser.cpp deleted file mode 100644 index b2020225168..00000000000 --- a/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_xml_parser.cpp +++ /dev/null @@ -1,172 +0,0 @@ -// Copyright 2016 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#include "xfa/fxfa/parser/cxfa_xml_parser.h" - -CXFA_XMLParser::CXFA_XMLParser(CFDE_XMLNode* pRoot, - const CFX_RetainPtr<IFGAS_Stream>& pStream) - : m_nElementStart(0), - m_dwCheckStatus(0), - m_dwCurrentCheckStatus(0), - m_pRoot(pRoot), - m_pStream(pStream), - m_pParser(new CFDE_XMLSyntaxParser), - m_pParent(pRoot), - m_pChild(nullptr), - m_NodeStack(16), - m_syntaxParserResult(FDE_XmlSyntaxResult::None) { - ASSERT(m_pParent && m_pStream); - m_NodeStack.Push(m_pParent); - m_pParser->Init(m_pStream, 32 * 1024, 1024 * 1024); -} - -CXFA_XMLParser::~CXFA_XMLParser() { - m_NodeStack.RemoveAll(false); - m_ws1.clear(); - m_ws2.clear(); -} - -int32_t CXFA_XMLParser::DoParser(IFX_Pause* pPause) { - if (m_syntaxParserResult == FDE_XmlSyntaxResult::Error) - return -1; - if (m_syntaxParserResult == FDE_XmlSyntaxResult::EndOfString) - return 100; - - int32_t iCount = 0; - while (true) { - m_syntaxParserResult = m_pParser->DoSyntaxParse(); - switch (m_syntaxParserResult) { - case FDE_XmlSyntaxResult::InstructionOpen: - break; - case FDE_XmlSyntaxResult::InstructionClose: - if (m_pChild) { - if (m_pChild->GetType() != FDE_XMLNODE_Instruction) { - m_syntaxParserResult = FDE_XmlSyntaxResult::Error; - break; - } - } - m_pChild = m_pParent; - break; - case FDE_XmlSyntaxResult::ElementOpen: - if (m_dwCheckStatus != 0x03 && m_NodeStack.GetSize() == 2) { - m_nElementStart = m_pParser->GetCurrentPos() - 1; - } - break; - case FDE_XmlSyntaxResult::ElementBreak: - break; - case FDE_XmlSyntaxResult::ElementClose: - if (m_pChild->GetType() != FDE_XMLNODE_Element) { - m_syntaxParserResult = FDE_XmlSyntaxResult::Error; - break; - } - m_pParser->GetTagName(m_ws1); - static_cast<CFDE_XMLElement*>(m_pChild)->GetTagName(m_ws2); - if (m_ws1.GetLength() > 0 && m_ws1 != m_ws2) { - m_syntaxParserResult = FDE_XmlSyntaxResult::Error; - break; - } - m_NodeStack.Pop(); - if (m_NodeStack.GetSize() < 1) { - m_syntaxParserResult = FDE_XmlSyntaxResult::Error; - break; - } else if (m_dwCurrentCheckStatus != 0 && m_NodeStack.GetSize() == 2) { - m_nSize[m_dwCurrentCheckStatus - 1] = - m_pParser->GetCurrentBinaryPos() - - m_nStart[m_dwCurrentCheckStatus - 1]; - m_dwCurrentCheckStatus = 0; - } - - m_pParent = static_cast<CFDE_XMLNode*>(*m_NodeStack.GetTopElement()); - m_pChild = m_pParent; - iCount++; - break; - case FDE_XmlSyntaxResult::TargetName: - m_pParser->GetTargetName(m_ws1); - if (m_ws1 == L"originalXFAVersion" || m_ws1 == L"acrobat") { - m_pChild = new CFDE_XMLInstruction(m_ws1); - m_pParent->InsertChildNode(m_pChild); - } else { - m_pChild = nullptr; - } - m_ws1.clear(); - break; - case FDE_XmlSyntaxResult::TagName: - m_pParser->GetTagName(m_ws1); - m_pChild = new CFDE_XMLElement(m_ws1); - m_pParent->InsertChildNode(m_pChild); - m_NodeStack.Push(m_pChild); - m_pParent = m_pChild; - - if (m_dwCheckStatus != 0x03 && m_NodeStack.GetSize() == 3) { - CFX_WideString wsTag; - static_cast<CFDE_XMLElement*>(m_pChild)->GetLocalTagName(wsTag); - if (wsTag == L"template") { - m_dwCheckStatus |= 0x01; - m_dwCurrentCheckStatus = 0x01; - m_nStart[0] = m_pParser->GetCurrentBinaryPos() - - (m_pParser->GetCurrentPos() - m_nElementStart); - } else if (wsTag == L"datasets") { - m_dwCheckStatus |= 0x02; - m_dwCurrentCheckStatus = 0x02; - m_nStart[1] = m_pParser->GetCurrentBinaryPos() - - (m_pParser->GetCurrentPos() - m_nElementStart); - } - } - break; - case FDE_XmlSyntaxResult::AttriName: - m_pParser->GetAttributeName(m_ws1); - break; - case FDE_XmlSyntaxResult::AttriValue: - if (m_pChild) { - m_pParser->GetAttributeName(m_ws2); - if (m_pChild->GetType() == FDE_XMLNODE_Element) { - static_cast<CFDE_XMLElement*>(m_pChild)->SetString(m_ws1, m_ws2); - } - } - m_ws1.clear(); - break; - case FDE_XmlSyntaxResult::Text: - m_pParser->GetTextData(m_ws1); - m_pChild = new CFDE_XMLText(m_ws1); - m_pParent->InsertChildNode(m_pChild); - m_pChild = m_pParent; - break; - case FDE_XmlSyntaxResult::CData: - m_pParser->GetTextData(m_ws1); - m_pChild = new CFDE_XMLCharData(m_ws1); - m_pParent->InsertChildNode(m_pChild); - m_pChild = m_pParent; - break; - case FDE_XmlSyntaxResult::TargetData: - if (m_pChild) { - if (m_pChild->GetType() != FDE_XMLNODE_Instruction) { - m_syntaxParserResult = FDE_XmlSyntaxResult::Error; - break; - } - if (!m_ws1.IsEmpty()) { - static_cast<CFDE_XMLInstruction*>(m_pChild)->AppendData(m_ws1); - } - m_pParser->GetTargetData(m_ws1); - static_cast<CFDE_XMLInstruction*>(m_pChild)->AppendData(m_ws1); - } - m_ws1.clear(); - break; - default: - break; - } - if (m_syntaxParserResult == FDE_XmlSyntaxResult::Error || - m_syntaxParserResult == FDE_XmlSyntaxResult::EndOfString) { - break; - } - if (pPause && iCount > 500 && pPause->NeedToPauseNow()) { - break; - } - } - return (m_syntaxParserResult == FDE_XmlSyntaxResult::Error || - m_NodeStack.GetSize() != 1) - ? -1 - : m_pParser->GetStatus(); -} diff --git a/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_xml_parser.h b/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_xml_parser.h deleted file mode 100644 index 9393b7e597e..00000000000 --- a/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_xml_parser.h +++ /dev/null @@ -1,44 +0,0 @@ -// Copyright 2016 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#ifndef XFA_FXFA_PARSER_CXFA_XML_PARSER_H_ -#define XFA_FXFA_PARSER_CXFA_XML_PARSER_H_ - -#include <memory> - -#include "xfa/fde/xml/fde_xml_imp.h" - -class IFGAS_Stream; -class IFX_Pause; - -class CXFA_XMLParser : public IFDE_XMLParser { - public: - CXFA_XMLParser(CFDE_XMLNode* pRoot, - const CFX_RetainPtr<IFGAS_Stream>& pStream); - ~CXFA_XMLParser() override; - - // IFDE_XMLParser - int32_t DoParser(IFX_Pause* pPause) override; - - FX_FILESIZE m_nStart[2]; - size_t m_nSize[2]; - FX_FILESIZE m_nElementStart; - uint16_t m_dwCheckStatus; - uint16_t m_dwCurrentCheckStatus; - - protected: - CFDE_XMLNode* m_pRoot; - CFX_RetainPtr<IFGAS_Stream> m_pStream; - std::unique_ptr<CFDE_XMLSyntaxParser> m_pParser; - CFDE_XMLNode* m_pParent; - CFDE_XMLNode* m_pChild; - CFX_StackTemplate<CFDE_XMLNode*> m_NodeStack; - CFX_WideString m_ws1; - CFX_WideString m_ws2; - FDE_XmlSyntaxResult m_syntaxParserResult; -}; - -#endif // XFA_FXFA_PARSER_CXFA_XML_PARSER_H_ diff --git a/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_xmllocale.cpp b/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_xmllocale.cpp new file mode 100644 index 00000000000..dd1d7cd1b81 --- /dev/null +++ b/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_xmllocale.cpp @@ -0,0 +1,194 @@ +// Copyright 2017 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#include "xfa/fxfa/parser/cxfa_xmllocale.h" + +#include <utility> + +#include "core/fxcrt/xml/cxml_element.h" +#include "xfa/fxfa/parser/cxfa_document.h" +#include "xfa/fxfa/parser/cxfa_localemgr.h" +#include "xfa/fxfa/parser/cxfa_nodelocale.h" +#include "xfa/fxfa/parser/cxfa_timezoneprovider.h" +#include "xfa/fxfa/parser/xfa_utils.h" + +CXFA_XMLLocale::CXFA_XMLLocale(std::unique_ptr<CXML_Element> pLocaleData) + : m_pLocaleData(std::move(pLocaleData)) {} + +CXFA_XMLLocale::~CXFA_XMLLocale() {} + +CFX_WideString CXFA_XMLLocale::GetName() const { + return m_pLocaleData ? m_pLocaleData->GetAttrValue("name") : CFX_WideString(); +} + +CFX_WideString CXFA_XMLLocale::GetNumbericSymbol( + FX_LOCALENUMSYMBOL eType) const { + CFX_ByteString bsSymbols; + CFX_WideString wsName; + switch (eType) { + case FX_LOCALENUMSYMBOL_Decimal: + bsSymbols = "numberSymbols"; + wsName = L"decimal"; + break; + case FX_LOCALENUMSYMBOL_Grouping: + bsSymbols = "numberSymbols"; + wsName = L"grouping"; + break; + case FX_LOCALENUMSYMBOL_Percent: + bsSymbols = "numberSymbols"; + wsName = L"percent"; + break; + case FX_LOCALENUMSYMBOL_Minus: + bsSymbols = "numberSymbols"; + wsName = L"minus"; + break; + case FX_LOCALENUMSYMBOL_Zero: + bsSymbols = "numberSymbols"; + wsName = L"zero"; + break; + case FX_LOCALENUMSYMBOL_CurrencySymbol: + bsSymbols = "currencySymbols"; + wsName = L"symbol"; + break; + case FX_LOCALENUMSYMBOL_CurrencyName: + bsSymbols = "currencySymbols"; + wsName = L"isoname"; + break; + default: + return CFX_WideString(); + } + CXML_Element* pElement = m_pLocaleData->GetElement("", bsSymbols.AsStringC()); + if (!pElement) + return CFX_WideString(); + + return GetPattern( + pElement, CFX_ByteStringC(bsSymbols.c_str(), bsSymbols.GetLength() - 1), + wsName.AsStringC()); +} + +CFX_WideString CXFA_XMLLocale::GetDateTimeSymbols() const { + if (!m_pLocaleData) + return CFX_WideString(); + + CFX_ByteString bsSpace; + CXML_Element* pNumberSymbols = + m_pLocaleData->GetElement(bsSpace.AsStringC(), "dateTimeSymbols"); + return pNumberSymbols ? pNumberSymbols->GetContent(0) : CFX_WideString(); +} + +CFX_WideString CXFA_XMLLocale::GetMonthName(int32_t nMonth, bool bAbbr) const { + return GetCalendarSymbol("month", nMonth, bAbbr); +} + +CFX_WideString CXFA_XMLLocale::GetDayName(int32_t nWeek, bool bAbbr) const { + return GetCalendarSymbol("day", nWeek, bAbbr); +} + +CFX_WideString CXFA_XMLLocale::GetMeridiemName(bool bAM) const { + return GetCalendarSymbol("meridiem", bAM ? 0 : 1, false); +} + +FX_TIMEZONE CXFA_XMLLocale::GetTimeZone() const { + return CXFA_TimeZoneProvider().GetTimeZone(); +} + +CFX_WideString CXFA_XMLLocale::GetEraName(bool bAD) const { + return GetCalendarSymbol("era", bAD ? 1 : 0, false); +} + +CFX_WideString CXFA_XMLLocale::GetCalendarSymbol(const CFX_ByteStringC& symbol, + int index, + bool bAbbr) const { + if (!m_pLocaleData) + return CFX_WideString(); + + CXML_Element* pChild = m_pLocaleData->GetElement("", "calendarSymbols"); + if (!pChild) + return CFX_WideString(); + + CFX_ByteString pstrSymbolNames = symbol + "Names"; + CXML_Element* pSymbolNames = + pChild->GetElement("", pstrSymbolNames.AsStringC()); + if (!pSymbolNames) + return CFX_WideString(); + if ((!!pSymbolNames->GetAttrInteger("abbr")) != bAbbr) + pSymbolNames = pChild->GetElement("", pstrSymbolNames.AsStringC(), 1); + + if (!pSymbolNames || (!!pSymbolNames->GetAttrInteger("abbr")) != bAbbr) + return CFX_WideString(); + + CXML_Element* pSymbolName = pSymbolNames->GetElement("", symbol, index); + return pSymbolName ? pSymbolName->GetContent(0) : CFX_WideString(); +} + +CFX_WideString CXFA_XMLLocale::GetDatePattern( + FX_LOCALEDATETIMESUBCATEGORY eType) const { + CXML_Element* pElement = m_pLocaleData->GetElement("", "datePatterns"); + if (!pElement) + return CFX_WideString(); + + CFX_WideString wsName; + switch (eType) { + case FX_LOCALEDATETIMESUBCATEGORY_Short: + wsName = L"short"; + break; + case FX_LOCALEDATETIMESUBCATEGORY_Default: + case FX_LOCALEDATETIMESUBCATEGORY_Medium: + wsName = L"med"; + break; + case FX_LOCALEDATETIMESUBCATEGORY_Full: + wsName = L"full"; + break; + case FX_LOCALEDATETIMESUBCATEGORY_Long: + wsName = L"long"; + break; + } + return GetPattern(pElement, "datePattern", wsName.AsStringC()); +} + +CFX_WideString CXFA_XMLLocale::GetTimePattern( + FX_LOCALEDATETIMESUBCATEGORY eType) const { + CXML_Element* pElement = m_pLocaleData->GetElement("", "timePatterns"); + if (!pElement) + return CFX_WideString(); + + CFX_WideString wsName; + switch (eType) { + case FX_LOCALEDATETIMESUBCATEGORY_Short: + wsName = L"short"; + break; + case FX_LOCALEDATETIMESUBCATEGORY_Default: + case FX_LOCALEDATETIMESUBCATEGORY_Medium: + wsName = L"med"; + break; + case FX_LOCALEDATETIMESUBCATEGORY_Full: + wsName = L"full"; + break; + case FX_LOCALEDATETIMESUBCATEGORY_Long: + wsName = L"long"; + break; + } + return GetPattern(pElement, "timePattern", wsName.AsStringC()); +} + +CFX_WideString CXFA_XMLLocale::GetNumPattern( + FX_LOCALENUMSUBCATEGORY eType) const { + return m_pLocaleData->GetElement("", "numberPatterns") + ? XFA_PatternToString(eType) + : CFX_WideString(); +} + +CFX_WideString CXFA_XMLLocale::GetPattern(CXML_Element* pElement, + const CFX_ByteStringC& bsTag, + const CFX_WideStringC& wsName) const { + int32_t iCount = pElement->CountElements("", bsTag); + for (int32_t i = 0; i < iCount; i++) { + CXML_Element* pChild = pElement->GetElement("", bsTag, i); + if (pChild->GetAttrValue("name") == wsName) + return pChild->GetContent(0); + } + return CFX_WideString(); +} diff --git a/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_xmllocale.h b/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_xmllocale.h new file mode 100644 index 00000000000..a58385601cb --- /dev/null +++ b/chromium/third_party/pdfium/xfa/fxfa/parser/cxfa_xmllocale.h @@ -0,0 +1,49 @@ +// Copyright 2014 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#ifndef XFA_FXFA_PARSER_CXFA_XMLLOCALE_H_ +#define XFA_FXFA_PARSER_CXFA_XMLLOCALE_H_ + +#include <memory> + +#include "core/fxcrt/ifx_locale.h" + +class CXML_Element; + +class CXFA_XMLLocale : public IFX_Locale { + public: + explicit CXFA_XMLLocale(std::unique_ptr<CXML_Element> pLocaleData); + ~CXFA_XMLLocale() override; + + // IFX_Locale + CFX_WideString GetName() const override; + CFX_WideString GetNumbericSymbol(FX_LOCALENUMSYMBOL eType) const override; + + CFX_WideString GetDateTimeSymbols() const override; + CFX_WideString GetMonthName(int32_t nMonth, bool bAbbr) const override; + CFX_WideString GetDayName(int32_t nWeek, bool bAbbr) const override; + CFX_WideString GetMeridiemName(bool bAM) const override; + FX_TIMEZONE GetTimeZone() const override; + CFX_WideString GetEraName(bool bAD) const override; + + CFX_WideString GetDatePattern( + FX_LOCALEDATETIMESUBCATEGORY eType) const override; + CFX_WideString GetTimePattern( + FX_LOCALEDATETIMESUBCATEGORY eType) const override; + CFX_WideString GetNumPattern(FX_LOCALENUMSUBCATEGORY eType) const override; + + private: + CFX_WideString GetPattern(CXML_Element* pElement, + const CFX_ByteStringC& bsTag, + const CFX_WideStringC& wsName) const; + CFX_WideString GetCalendarSymbol(const CFX_ByteStringC& symbol, + int index, + bool bAbbr) const; + + std::unique_ptr<CXML_Element> m_pLocaleData; +}; + +#endif // XFA_FXFA_PARSER_CXFA_XMLLOCALE_H_ diff --git a/chromium/third_party/pdfium/xfa/fxfa/parser/xfa_basic_data.cpp b/chromium/third_party/pdfium/xfa/fxfa/parser/xfa_basic_data.cpp index fecc942c7db..8e2986fecf0 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/parser/xfa_basic_data.cpp +++ b/chromium/third_party/pdfium/xfa/fxfa/parser/xfa_basic_data.cpp @@ -7,7 +7,7 @@ #include "xfa/fxfa/parser/xfa_basic_data.h" #include "xfa/fxfa/fxfa_basic.h" -#include "xfa/fxfa/parser/xfa_object.h" +#include "xfa/fxfa/parser/cxfa_object.h" const XFA_ELEMENTINFO g_XFAElementData[] = { {0x23ee3, L"ps", XFA_Element::Ps, XFA_XDPPACKET_Config, diff --git a/chromium/third_party/pdfium/xfa/fxfa/parser/xfa_basic_data_element_script.cpp b/chromium/third_party/pdfium/xfa/fxfa/parser/xfa_basic_data_element_script.cpp index 675fb8a39a9..bb8a9857406 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/parser/xfa_basic_data_element_script.cpp +++ b/chromium/third_party/pdfium/xfa/fxfa/parser/xfa_basic_data_element_script.cpp @@ -13,6 +13,8 @@ #include "xfa/fxfa/parser/cscript_layoutpseudomodel.h" #include "xfa/fxfa/parser/cscript_logpseudomodel.h" #include "xfa/fxfa/parser/cscript_signaturepseudomodel.h" +#include "xfa/fxfa/parser/cxfa_node.h" +#include "xfa/fxfa/parser/cxfa_nodelist.h" const XFA_SCRIPTHIERARCHY g_XFAScriptIndex[] = { {0, 0, 0, 2, 316}, {0, 0, 2, 2, 316}, {0, 0, 4, 2, 316}, diff --git a/chromium/third_party/pdfium/xfa/fxfa/parser/xfa_document_datamerger_imp.cpp b/chromium/third_party/pdfium/xfa/fxfa/parser/xfa_document_datamerger_imp.cpp index 03ab81e39f2..82aec1f00d5 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/parser/xfa_document_datamerger_imp.cpp +++ b/chromium/third_party/pdfium/xfa/fxfa/parser/xfa_document_datamerger_imp.cpp @@ -11,13 +11,16 @@ #include "core/fxcrt/fx_ext.h" #include "third_party/base/stl_util.h" -#include "xfa/fde/xml/fde_xml_imp.h" +#include "xfa/fde/xml/cfde_xmlelement.h" +#include "xfa/fde/xml/cfde_xmlnode.h" #include "xfa/fxfa/parser/cxfa_document.h" #include "xfa/fxfa/parser/cxfa_layoutprocessor.h" +#include "xfa/fxfa/parser/cxfa_localemgr.h" +#include "xfa/fxfa/parser/cxfa_node.h" #include "xfa/fxfa/parser/cxfa_occur.h" #include "xfa/fxfa/parser/cxfa_scriptcontext.h" -#include "xfa/fxfa/parser/xfa_localemgr.h" -#include "xfa/fxfa/parser/xfa_object.h" +#include "xfa/fxfa/parser/cxfa_traversestrategy_xfacontainernode.h" +#include "xfa/fxfa/parser/cxfa_traversestrategy_xfanode.h" #include "xfa/fxfa/parser/xfa_resolvenode_rs.h" #include "xfa/fxfa/parser/xfa_utils.h" @@ -153,17 +156,16 @@ void CreateDataBinding(CXFA_Node* pFormNode, case XFA_Element::ChoiceList: defValue.GetChildValueContent(wsValue); if (pWidgetData->GetChoiceListOpen() == XFA_ATTRIBUTEENUM_MultiSelect) { - std::vector<CFX_WideString> wsSelTextArray; - pWidgetData->GetSelectedItemsValue(wsSelTextArray); - int32_t iSize = pdfium::CollectionSize<int32_t>(wsSelTextArray); - if (iSize >= 1) { - CXFA_Node* pValue = nullptr; - for (int32_t i = 0; i < iSize; i++) { - pValue = pDataNode->CreateSamePacketNode(XFA_Element::DataValue); + std::vector<CFX_WideString> wsSelTextArray = + pWidgetData->GetSelectedItemsValue(); + if (!wsSelTextArray.empty()) { + for (const auto& text : wsSelTextArray) { + CXFA_Node* pValue = + pDataNode->CreateSamePacketNode(XFA_Element::DataValue); pValue->SetCData(XFA_ATTRIBUTE_Name, L"value"); pValue->CreateXMLMappingNode(); pDataNode->InsertChild(pValue); - pValue->SetCData(XFA_ATTRIBUTE_Value, wsSelTextArray[i]); + pValue->SetCData(XFA_ATTRIBUTE_Value, text); } } else { CFDE_XMLNode* pXMLNode = pDataNode->GetXMLMappingNode(); @@ -282,14 +284,15 @@ void CreateDataBinding(CXFA_Node* pFormNode, CFDE_XMLElement* pXMLDataElement = static_cast<CFDE_XMLElement*>(pDataNode->GetXMLMappingNode()); ASSERT(pXMLDataElement); - CFX_WideString wsContentType; - CFX_WideString wsHref; - pXMLDataElement->GetString(L"xfa:contentType", wsContentType); + + CFX_WideString wsContentType = + pXMLDataElement->GetString(L"xfa:contentType"); if (!wsContentType.IsEmpty()) { pDataNode->SetCData(XFA_ATTRIBUTE_ContentType, wsContentType); image.SetContentType(wsContentType); } - pXMLDataElement->GetString(L"href", wsHref); + + CFX_WideString wsHref = pXMLDataElement->GetString(L"href"); if (!wsHref.IsEmpty()) image.SetHref(wsHref); } @@ -297,20 +300,19 @@ void CreateDataBinding(CXFA_Node* pFormNode, } case XFA_Element::ChoiceList: if (pWidgetData->GetChoiceListOpen() == XFA_ATTRIBUTEENUM_MultiSelect) { - CXFA_NodeArray items; - pDataNode->GetNodeList(items); - int32_t iCounts = items.GetSize(); - if (iCounts > 0) { + std::vector<CXFA_Node*> items = pDataNode->GetNodeList(); + if (!items.empty()) { + bool single = items.size() == 1; wsNormalizeValue.clear(); CFX_WideString wsItem; - for (int32_t i = 0; i < iCounts; i++) { - items[i]->TryContent(wsItem); - wsItem = (iCounts == 1) ? wsItem : wsItem + L"\n"; + for (CXFA_Node* pNode : items) { + pNode->TryContent(wsItem); + wsItem = single ? wsItem : wsItem + L"\n"; wsNormalizeValue += wsItem; } CXFA_ExData exData = defValue.GetExData(); ASSERT(exData); - exData.SetContentType(iCounts == 1 ? L"text/plain" : L"text/xml"); + exData.SetContentType(single ? L"text/plain" : L"text/xml"); } FormValueNode_SetChildContent(defValue.GetNode(), wsNormalizeValue, XFA_Element::ExData); @@ -464,12 +466,12 @@ CXFA_Node* FindDataRefDataNode(CXFA_Document* pDocument, pTemplateNode); if (rs.dwFlags == XFA_RESOLVENODE_RSTYPE_CreateNodeAll || rs.dwFlags == XFA_RESOLVENODE_RSTYPE_CreateNodeMidAll || - rs.nodes.GetSize() > 1) { - return pDocument->GetNotBindNode(rs.nodes); + rs.objects.size() > 1) { + return pDocument->GetNotBindNode(rs.objects); } if (rs.dwFlags == XFA_RESOLVENODE_RSTYPE_CreateNodeOne) { - CXFA_Object* pObject = (rs.nodes.GetSize() > 0) ? rs.nodes[0] : nullptr; + CXFA_Object* pObject = !rs.objects.empty() ? rs.objects.front() : nullptr; CXFA_Node* pNode = ToNode(pObject); return (bForceBind || !pNode || !pNode->HasBindItem()) ? pNode : nullptr; } @@ -492,7 +494,7 @@ bool NeedGenerateForm(CXFA_Node* pTemplateChild, bool bUseInstanceManager) { CXFA_Node* CloneOrMergeInstanceManager(CXFA_Document* pDocument, CXFA_Node* pFormParent, CXFA_Node* pTemplateNode, - CXFA_NodeArray& subforms) { + std::vector<CXFA_Node*>* subforms) { CFX_WideStringC wsSubformName = pTemplateNode->GetCData(XFA_ATTRIBUTE_Name); CFX_WideString wsInstMgrNodeName = L"_" + wsSubformName; uint32_t dwInstNameHash = @@ -518,7 +520,7 @@ CXFA_Node* CloneOrMergeInstanceManager(CXFA_Document* pDocument, CXFA_Node* pNextNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling); pFormParent->RemoveChild(pNode); - subforms.Add(pNode); + subforms->push_back(pNode); pNode = pNextNode; } pFormParent->RemoveChild(pExistingNode); @@ -653,39 +655,31 @@ CXFA_Node* FindMatchingDataNode( return pResult; } -void SortRecurseRecord(CFX_ArrayTemplate<RecurseRecord>& rgRecords, +void SortRecurseRecord(std::vector<RecurseRecord>* rgRecords, CXFA_Node* pDataScope, bool bChoiceMode) { - int32_t iCount = rgRecords.GetSize(); - CFX_ArrayTemplate<RecurseRecord> rgResultRecord; - for (CXFA_Node* pChildNode = pDataScope->GetNodeItem(XFA_NODEITEM_FirstChild); - pChildNode; - pChildNode = pChildNode->GetNodeItem(XFA_NODEITEM_NextSibling)) { - for (int32_t i = 0; i < iCount; i++) { - CXFA_Node* pNode = rgRecords[i].pDataChild; - if (pChildNode == pNode) { - RecurseRecord sNewRecord = {rgRecords[i].pTemplateChild, pNode}; - rgResultRecord.Add(sNewRecord); - rgRecords.RemoveAt(i); - iCount--; + std::vector<RecurseRecord> rgResultRecord; + for (CXFA_Node* pNode = pDataScope->GetNodeItem(XFA_NODEITEM_FirstChild); + pNode; pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) { + auto it = std::find_if(rgRecords->begin(), rgRecords->end(), + [pNode](const RecurseRecord& record) { + return pNode == record.pDataChild; + }); + if (it != rgRecords->end()) { + rgResultRecord.push_back(*it); + rgRecords->erase(it); + if (bChoiceMode) break; - } } - if (bChoiceMode && rgResultRecord.GetSize() > 0) - break; } + if (rgResultRecord.empty()) + return; - if (rgResultRecord.GetSize() > 0) { - if (!bChoiceMode) { - for (int32_t i = 0; i < iCount; i++) { - RecurseRecord sNewRecord = {rgRecords[i].pTemplateChild, - rgRecords[i].pDataChild}; - rgResultRecord.Add(sNewRecord); - } - } - rgRecords.RemoveAll(); - rgRecords.Copy(rgResultRecord); + if (!bChoiceMode) { + rgResultRecord.insert(rgResultRecord.end(), rgRecords->begin(), + rgRecords->end()); } + *rgRecords = rgResultRecord; } CXFA_Node* CopyContainer_SubformSet(CXFA_Document* pDocument, @@ -700,13 +694,13 @@ CXFA_Node* CopyContainer_SubformSet(CXFA_Document* pDocument, bool bUseInstanceManager = pFormParentNode->GetElementType() != XFA_Element::Area; CXFA_Node* pInstMgrNode = nullptr; - CXFA_NodeArray subformArray; - CXFA_NodeArray* pSearchArray = nullptr; + std::vector<CXFA_Node*> subformArray; + std::vector<CXFA_Node*>* pSearchArray = nullptr; if (!bOneInstance && (eType == XFA_Element::SubformSet || eType == XFA_Element::Subform)) { pInstMgrNode = bUseInstanceManager ? CloneOrMergeInstanceManager( pDocument, pFormParentNode, - pTemplateNode, subformArray) + pTemplateNode, &subformArray) : nullptr; if (CXFA_Node* pOccurTemplateNode = pTemplateNode->GetFirstChildByClass(XFA_Element::Occur)) { @@ -724,10 +718,9 @@ CXFA_Node* CopyContainer_SubformSet(CXFA_Document* pDocument, pSearchArray = &subformArray; if (pFormParentNode->GetElementType() == XFA_Element::PageArea) { bOneInstance = true; - if (subformArray.GetSize() < 1) + if (subformArray.empty()) pSearchArray = nullptr; - } else if ((pTemplateNode->GetNameHash() == 0) && - (subformArray.GetSize() < 1)) { + } else if (pTemplateNode->GetNameHash() == 0 && subformArray.empty()) { pSearchArray = nullptr; } } @@ -753,7 +746,7 @@ CXFA_Node* CopyContainer_SubformSet(CXFA_Document* pDocument, sNodeIterator.MoveToNext(); } else { std::map<CXFA_Node*, CXFA_Node*> subformMapArray; - CXFA_NodeArray nodeArray; + std::vector<CXFA_Node*> nodeArray; for (; iMax < 0 || iCurRepeatIndex < iMax; iCurRepeatIndex++) { bool bSelfMatch = false; XFA_ATTRIBUTEENUM eBindMatch = XFA_ATTRIBUTEENUM_None; @@ -772,11 +765,10 @@ CXFA_Node* CopyContainer_SubformSet(CXFA_Document* pDocument, CreateDataBinding(pSubformNode, pDataNode, true); ASSERT(pSubformNode); subformMapArray[pSubformNode] = pDataNode; - nodeArray.Add(pSubformNode); + nodeArray.push_back(pSubformNode); } - for (int32_t iIndex = 0; iIndex < nodeArray.GetSize(); iIndex++) { - CXFA_Node* pSubform = nodeArray[iIndex]; + for (CXFA_Node* pSubform : nodeArray) { CXFA_Node* pDataNode = nullptr; auto it = subformMapArray.find(pSubform); if (it != subformMapArray.end()) @@ -818,8 +810,8 @@ CXFA_Node* CopyContainer_SubformSet(CXFA_Document* pDocument, if (!pFirstInstance) pFirstInstance = pSubformSetNode; - CFX_ArrayTemplate<RecurseRecord> rgItemMatchList; - CFX_ArrayTemplate<CXFA_Node*> rgItemUnmatchList; + std::vector<RecurseRecord> rgItemMatchList; + std::vector<CXFA_Node*> rgItemUnmatchList; for (CXFA_Node* pTemplateChild = pTemplateNode->GetNodeItem(XFA_NODEITEM_FirstChild); pTemplateChild; pTemplateChild = pTemplateChild->GetNodeItem( @@ -837,42 +829,39 @@ CXFA_Node* CopyContainer_SubformSet(CXFA_Document* pDocument, if (pDataMatch) { RecurseRecord sNewRecord = {pTemplateChild, pDataMatch}; if (bSelfMatch) - rgItemMatchList.InsertAt(0, sNewRecord); + rgItemMatchList.insert(rgItemMatchList.begin(), sNewRecord); else - rgItemMatchList.Add(sNewRecord); + rgItemMatchList.push_back(sNewRecord); } else { - rgItemUnmatchList.Add(pTemplateChild); + rgItemUnmatchList.push_back(pTemplateChild); } } else { - rgItemUnmatchList.Add(pTemplateChild); + rgItemUnmatchList.push_back(pTemplateChild); } } } switch (eRelation) { case XFA_ATTRIBUTEENUM_Choice: { - ASSERT(rgItemMatchList.GetSize()); - SortRecurseRecord(rgItemMatchList, pDataScope, true); + ASSERT(!rgItemMatchList.empty()); + SortRecurseRecord(&rgItemMatchList, pDataScope, true); pDocument->DataMerge_CopyContainer( - rgItemMatchList[0].pTemplateChild, pSubformSetNode, pDataScope, - false, true, true); + rgItemMatchList.front().pTemplateChild, pSubformSetNode, + pDataScope, false, true, true); break; } case XFA_ATTRIBUTEENUM_Unordered: { - if (rgItemMatchList.GetSize()) { - SortRecurseRecord(rgItemMatchList, pDataScope, false); - for (int32_t i = 0, count = rgItemMatchList.GetSize(); i < count; - i++) { - pDocument->DataMerge_CopyContainer( - rgItemMatchList[i].pTemplateChild, pSubformSetNode, - pDataScope, false, true, true); + if (!rgItemMatchList.empty()) { + SortRecurseRecord(&rgItemMatchList, pDataScope, false); + for (const auto& matched : rgItemMatchList) { + pDocument->DataMerge_CopyContainer(matched.pTemplateChild, + pSubformSetNode, pDataScope, + false, true, true); } } - for (int32_t i = 0, count = rgItemUnmatchList.GetSize(); i < count; - i++) { - pDocument->DataMerge_CopyContainer(rgItemUnmatchList[i], - pSubformSetNode, pDataScope, - false, true, true); + for (auto* unmatched : rgItemUnmatchList) { + pDocument->DataMerge_CopyContainer(unmatched, pSubformSetNode, + pDataScope, false, true, true); } break; } @@ -904,14 +893,14 @@ CXFA_Node* CopyContainer_SubformSet(CXFA_Document* pDocument, if (iCurRepeatIndex == 0 && bAccessedDataDOM == false) { int32_t iLimit = iMax; if (pInstMgrNode && pTemplateNode->GetNameHash() == 0) { - iLimit = subformArray.GetSize(); + iLimit = pdfium::CollectionSize<int32_t>(subformArray); if (iLimit < iMin) iLimit = iInit; } for (; (iLimit < 0 || iCurRepeatIndex < iLimit); iCurRepeatIndex++) { if (pInstMgrNode) { - if (pSearchArray && pSearchArray->GetSize() < 1) { + if (pSearchArray && pSearchArray->empty()) { if (pTemplateNode->GetNameHash() != 0) break; pSearchArray = nullptr; @@ -1158,7 +1147,7 @@ void UpdateBindingRelations(CXFA_Document* pDocument, pDocument->GetScriptContext()->ResolveObjects(pDataScope, wsRef, rs, dFlags, pTemplateNode); CXFA_Object* pObject = - (rs.nodes.GetSize() > 0) ? rs.nodes[0] : nullptr; + !rs.objects.empty() ? rs.objects.front() : nullptr; pDataNode = ToNode(pObject); if (pDataNode) { CreateDataBinding(pFormNode, pDataNode, @@ -1247,21 +1236,21 @@ CXFA_Node* XFA_DataMerge_FindFormDOMInstance(CXFA_Document* pDocument, return nullptr; } -CXFA_Node* XFA_NodeMerge_CloneOrMergeContainer(CXFA_Document* pDocument, - CXFA_Node* pFormParent, - CXFA_Node* pTemplateNode, - bool bRecursive, - CXFA_NodeArray* pSubformArray) { +CXFA_Node* XFA_NodeMerge_CloneOrMergeContainer( + CXFA_Document* pDocument, + CXFA_Node* pFormParent, + CXFA_Node* pTemplateNode, + bool bRecursive, + std::vector<CXFA_Node*>* pSubformArray) { CXFA_Node* pExistingNode = nullptr; if (!pSubformArray) { pExistingNode = XFA_DataMerge_FindFormDOMInstance( pDocument, pTemplateNode->GetElementType(), pTemplateNode->GetNameHash(), pFormParent); - } else if (pSubformArray->GetSize() > 0) { - pExistingNode = pSubformArray->GetAt(0); - pSubformArray->RemoveAt(0); + } else if (!pSubformArray->empty()) { + pExistingNode = pSubformArray->front(); + pSubformArray->erase(pSubformArray->begin()); } - if (pExistingNode) { if (pSubformArray) { pFormParent->InsertChild(pExistingNode); @@ -1354,9 +1343,10 @@ void CXFA_Document::DataMerge_UpdateBindingRelations( UpdateBindingRelations(this, pFormUpdateRoot, pDataScope, true, false); } -CXFA_Node* CXFA_Document::GetNotBindNode(CXFA_ObjArray& arrayNodes) { - for (int32_t i = 0; i < arrayNodes.GetSize(); i++) { - CXFA_Node* pNode = arrayNodes[i]->AsNode(); +CXFA_Node* CXFA_Document::GetNotBindNode( + const std::vector<CXFA_Object*>& arrayObjects) { + for (CXFA_Object* pObject : arrayObjects) { + CXFA_Node* pNode = pObject->AsNode(); if (pNode && !pNode->HasBindItem()) return pNode; } @@ -1482,7 +1472,7 @@ void CXFA_Document::DoDataMerge() { CXFA_Node* pPageSetNode = pSubformSetNode->GetFirstChildByClass(XFA_Element::PageSet); while (pPageSetNode) { - m_pPendingPageSet.Add(pPageSetNode); + m_pPendingPageSet.push_back(pPageSetNode); CXFA_Node* pNextPageSetNode = pPageSetNode->GetNextSameClassSibling(XFA_Element::PageSet); pSubformSetNode->RemoveChild(pPageSetNode); diff --git a/chromium/third_party/pdfium/xfa/fxfa/parser/xfa_document_datamerger_imp.h b/chromium/third_party/pdfium/xfa/fxfa/parser/xfa_document_datamerger_imp.h index f9ea087731c..9e58678867b 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/parser/xfa_document_datamerger_imp.h +++ b/chromium/third_party/pdfium/xfa/fxfa/parser/xfa_document_datamerger_imp.h @@ -7,13 +7,19 @@ #ifndef XFA_FXFA_PARSER_XFA_DOCUMENT_DATAMERGER_IMP_H_ #define XFA_FXFA_PARSER_XFA_DOCUMENT_DATAMERGER_IMP_H_ -#include "xfa/fxfa/parser/xfa_object.h" +#include <vector> -CXFA_Node* XFA_NodeMerge_CloneOrMergeContainer(CXFA_Document* pDocument, - CXFA_Node* pFormParent, - CXFA_Node* pTemplateNode, - bool bRecursive, - CXFA_NodeArray* pSubformArray); +#include "xfa/fxfa/fxfa_basic.h" + +class CXFA_Document; +class CXFA_Node; + +CXFA_Node* XFA_NodeMerge_CloneOrMergeContainer( + CXFA_Document* pDocument, + CXFA_Node* pFormParent, + CXFA_Node* pTemplateNode, + bool bRecursive, + std::vector<CXFA_Node*>* pSubformArray); CXFA_Node* XFA_DataMerge_FindDataScope(CXFA_Node* pParentFormNode); CXFA_Node* XFA_DataMerge_FindFormDOMInstance(CXFA_Document* pDocument, XFA_Element eType, diff --git a/chromium/third_party/pdfium/xfa/fxfa/parser/xfa_locale.cpp b/chromium/third_party/pdfium/xfa/fxfa/parser/xfa_locale.cpp deleted file mode 100644 index d835eb2bc7c..00000000000 --- a/chromium/third_party/pdfium/xfa/fxfa/parser/xfa_locale.cpp +++ /dev/null @@ -1,394 +0,0 @@ -// Copyright 2014 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#include "xfa/fxfa/parser/xfa_locale.h" - -#include <utility> - -#include "core/fxcrt/fx_xml.h" -#include "xfa/fxfa/parser/cxfa_document.h" -#include "xfa/fxfa/parser/xfa_localemgr.h" -#include "xfa/fxfa/parser/xfa_object.h" -#include "xfa/fxfa/parser/xfa_utils.h" - -static const FX_WCHAR g_FX_Percent[] = L"z,zzz,zzz,zzz,zzz,zzz%"; -static const FX_WCHAR g_FX_Currency[] = L"$z,zzz,zzz,zzz,zzz,zz9.99"; -static const FX_WCHAR g_FX_Decimal[] = L"z,zzz,zzz,zzz,zzz,zz9.zzz"; -static const FX_WCHAR g_FX_Integer[] = L"z,zzz,zzz,zzz,zzz,zzz"; - -CXFA_XMLLocale::CXFA_XMLLocale(std::unique_ptr<CXML_Element> pLocaleData) - : m_pLocaleData(std::move(pLocaleData)) {} - -CXFA_XMLLocale::~CXFA_XMLLocale() {} - -CFX_WideString CXFA_XMLLocale::GetName() const { - return m_pLocaleData ? m_pLocaleData->GetAttrValue("name") : CFX_WideString(); -} - -void CXFA_XMLLocale::GetNumbericSymbol(FX_LOCALENUMSYMBOL eType, - CFX_WideString& wsNumSymbol) const { - CFX_ByteString bsSymbols; - CFX_WideString wsName; - switch (eType) { - case FX_LOCALENUMSYMBOL_Decimal: - bsSymbols = "numberSymbols"; - wsName = L"decimal"; - break; - case FX_LOCALENUMSYMBOL_Grouping: - bsSymbols = "numberSymbols"; - wsName = L"grouping"; - break; - case FX_LOCALENUMSYMBOL_Percent: - bsSymbols = "numberSymbols"; - wsName = L"percent"; - break; - case FX_LOCALENUMSYMBOL_Minus: - bsSymbols = "numberSymbols"; - wsName = L"minus"; - break; - case FX_LOCALENUMSYMBOL_Zero: - bsSymbols = "numberSymbols"; - wsName = L"zero"; - break; - case FX_LOCALENUMSYMBOL_CurrencySymbol: - bsSymbols = "currencySymbols"; - wsName = L"symbol"; - break; - case FX_LOCALENUMSYMBOL_CurrencyName: - bsSymbols = "currencySymbols"; - wsName = L"isoname"; - break; - default: - return; - } - CXML_Element* pElement = m_pLocaleData->GetElement("", bsSymbols.AsStringC()); - if (!pElement) { - return; - } - GetPattern(pElement, - CFX_ByteStringC(bsSymbols.c_str(), bsSymbols.GetLength() - 1), - wsName.AsStringC(), wsNumSymbol); -} - -void CXFA_XMLLocale::GetDateTimeSymbols(CFX_WideString& wsDtSymbol) const { - if (!m_pLocaleData) { - return; - } - CFX_ByteString bsSpace; - CXML_Element* pNumberSymbols = - m_pLocaleData->GetElement(bsSpace.AsStringC(), "dateTimeSymbols"); - if (!pNumberSymbols) { - return; - } - wsDtSymbol = pNumberSymbols->GetContent(0); -} - -void CXFA_XMLLocale::GetMonthName(int32_t nMonth, - CFX_WideString& wsMonthName, - bool bAbbr) const { - wsMonthName = GetCalendarSymbol("month", nMonth, bAbbr); -} - -void CXFA_XMLLocale::GetDayName(int32_t nWeek, - CFX_WideString& wsDayName, - bool bAbbr) const { - wsDayName = GetCalendarSymbol("day", nWeek, bAbbr); -} - -void CXFA_XMLLocale::GetMeridiemName(CFX_WideString& wsMeridiemName, - bool bAM) const { - wsMeridiemName = GetCalendarSymbol("meridiem", bAM ? 0 : 1, false); -} - -void CXFA_XMLLocale::GetTimeZone(FX_TIMEZONE* tz) const { - CXFA_TimeZoneProvider provider; - provider.GetTimeZone(tz); -} - -void CXFA_XMLLocale::GetEraName(CFX_WideString& wsEraName, bool bAD) const { - wsEraName = GetCalendarSymbol("era", bAD ? 1 : 0, false); -} - -CFX_WideString CXFA_XMLLocale::GetCalendarSymbol(const CFX_ByteStringC& symbol, - int index, - bool bAbbr) const { - CFX_ByteString pstrSymbolNames = symbol + "Names"; - CFX_WideString wsSymbolName = L""; - if (m_pLocaleData) { - CXML_Element* pChild = m_pLocaleData->GetElement("", "calendarSymbols"); - if (pChild) { - CXML_Element* pSymbolNames = - pChild->GetElement("", pstrSymbolNames.AsStringC()); - if (pSymbolNames) { - if ((!!pSymbolNames->GetAttrInteger("abbr")) != bAbbr) { - pSymbolNames = pChild->GetElement("", pstrSymbolNames.AsStringC(), 1); - } - if (pSymbolNames && (!!pSymbolNames->GetAttrInteger("abbr")) == bAbbr) { - CXML_Element* pSymbolName = - pSymbolNames->GetElement("", symbol, index); - if (pSymbolName) { - wsSymbolName = pSymbolName->GetContent(0); - } - } - } - } - } - return wsSymbolName; -} - -void CXFA_XMLLocale::GetDatePattern(FX_LOCALEDATETIMESUBCATEGORY eType, - CFX_WideString& wsPattern) const { - CXML_Element* pElement = m_pLocaleData->GetElement("", "datePatterns"); - if (!pElement) { - return; - } - CFX_WideString wsName; - switch (eType) { - case FX_LOCALEDATETIMESUBCATEGORY_Short: - wsName = L"short"; - break; - case FX_LOCALEDATETIMESUBCATEGORY_Default: - case FX_LOCALEDATETIMESUBCATEGORY_Medium: - wsName = L"med"; - break; - case FX_LOCALEDATETIMESUBCATEGORY_Full: - wsName = L"full"; - break; - case FX_LOCALEDATETIMESUBCATEGORY_Long: - wsName = L"long"; - break; - } - GetPattern(pElement, "datePattern", wsName.AsStringC(), wsPattern); -} - -void CXFA_XMLLocale::GetTimePattern(FX_LOCALEDATETIMESUBCATEGORY eType, - CFX_WideString& wsPattern) const { - CXML_Element* pElement = m_pLocaleData->GetElement("", "timePatterns"); - if (!pElement) { - return; - } - CFX_WideString wsName; - switch (eType) { - case FX_LOCALEDATETIMESUBCATEGORY_Short: - wsName = L"short"; - break; - case FX_LOCALEDATETIMESUBCATEGORY_Default: - case FX_LOCALEDATETIMESUBCATEGORY_Medium: - wsName = L"med"; - break; - case FX_LOCALEDATETIMESUBCATEGORY_Full: - wsName = L"full"; - break; - case FX_LOCALEDATETIMESUBCATEGORY_Long: - wsName = L"long"; - break; - } - GetPattern(pElement, "timePattern", wsName.AsStringC(), wsPattern); -} - -void CXFA_XMLLocale::GetNumPattern(FX_LOCALENUMSUBCATEGORY eType, - CFX_WideString& wsPattern) const { - CXML_Element* pElement = m_pLocaleData->GetElement("", "numberPatterns"); - if (!pElement) { - return; - } - switch (eType) { - case FX_LOCALENUMPATTERN_Percent: - wsPattern = g_FX_Percent; - break; - case FX_LOCALENUMPATTERN_Currency: - wsPattern = g_FX_Currency; - break; - case FX_LOCALENUMPATTERN_Decimal: - wsPattern = g_FX_Decimal; - break; - case FX_LOCALENUMPATTERN_Integer: - wsPattern = g_FX_Integer; - break; - } -} - -void CXFA_XMLLocale::GetPattern(CXML_Element* pElement, - const CFX_ByteStringC& bsTag, - const CFX_WideStringC& wsName, - CFX_WideString& wsPattern) const { - int32_t iCount = pElement->CountElements("", bsTag); - for (int32_t i = 0; i < iCount; i++) { - CXML_Element* pChild = pElement->GetElement("", bsTag, i); - if (pChild->GetAttrValue("name") == wsName) { - wsPattern = pChild->GetContent(0); - return; - } - } -} - -CXFA_NodeLocale::CXFA_NodeLocale(CXFA_Node* pLocale) : m_pLocale(pLocale) {} - -CXFA_NodeLocale::~CXFA_NodeLocale() {} - -CFX_WideString CXFA_NodeLocale::GetName() const { - return CFX_WideString(m_pLocale ? m_pLocale->GetCData(XFA_ATTRIBUTE_Name) - : nullptr); -} - -void CXFA_NodeLocale::GetNumbericSymbol(FX_LOCALENUMSYMBOL eType, - CFX_WideString& wsNumSymbol) const { - switch (eType) { - case FX_LOCALENUMSYMBOL_Decimal: - wsNumSymbol = GetSymbol(XFA_Element::NumberSymbols, L"decimal"); - break; - case FX_LOCALENUMSYMBOL_Grouping: - wsNumSymbol = GetSymbol(XFA_Element::NumberSymbols, L"grouping"); - break; - case FX_LOCALENUMSYMBOL_Percent: - wsNumSymbol = GetSymbol(XFA_Element::NumberSymbols, L"percent"); - break; - case FX_LOCALENUMSYMBOL_Minus: - wsNumSymbol = GetSymbol(XFA_Element::NumberSymbols, L"minus"); - break; - case FX_LOCALENUMSYMBOL_Zero: - wsNumSymbol = GetSymbol(XFA_Element::NumberSymbols, L"zero"); - break; - case FX_LOCALENUMSYMBOL_CurrencySymbol: - wsNumSymbol = GetSymbol(XFA_Element::CurrencySymbols, L"symbol"); - break; - case FX_LOCALENUMSYMBOL_CurrencyName: - wsNumSymbol = GetSymbol(XFA_Element::CurrencySymbols, L"isoname"); - break; - } -} - -void CXFA_NodeLocale::GetDateTimeSymbols(CFX_WideString& wsDtSymbol) const { - CXFA_Node* pSymbols = - m_pLocale ? m_pLocale->GetChild(0, XFA_Element::DateTimeSymbols) - : nullptr; - wsDtSymbol = pSymbols ? pSymbols->GetContent() : CFX_WideString(); -} - -void CXFA_NodeLocale::GetMonthName(int32_t nMonth, - CFX_WideString& wsMonthName, - bool bAbbr) const { - wsMonthName = GetCalendarSymbol(XFA_Element::MonthNames, nMonth, bAbbr); -} - -void CXFA_NodeLocale::GetDayName(int32_t nWeek, - CFX_WideString& wsDayName, - bool bAbbr) const { - wsDayName = GetCalendarSymbol(XFA_Element::DayNames, nWeek, bAbbr); -} - -void CXFA_NodeLocale::GetMeridiemName(CFX_WideString& wsMeridiemName, - bool bAM) const { - wsMeridiemName = - GetCalendarSymbol(XFA_Element::MeridiemNames, bAM ? 0 : 1, false); -} - -void CXFA_NodeLocale::GetTimeZone(FX_TIMEZONE* tz) const { - CXFA_TimeZoneProvider provider; - provider.GetTimeZone(tz); -} - -void CXFA_NodeLocale::GetEraName(CFX_WideString& wsEraName, bool bAD) const { - wsEraName = GetCalendarSymbol(XFA_Element::EraNames, bAD ? 1 : 0, false); -} - -void CXFA_NodeLocale::GetDatePattern(FX_LOCALEDATETIMESUBCATEGORY eType, - CFX_WideString& wsPattern) const { - switch (eType) { - case FX_LOCALEDATETIMESUBCATEGORY_Short: - wsPattern = GetSymbol(XFA_Element::DatePatterns, L"short"); - break; - case FX_LOCALEDATETIMESUBCATEGORY_Medium: - case FX_LOCALEDATETIMESUBCATEGORY_Default: - wsPattern = GetSymbol(XFA_Element::DatePatterns, L"med"); - break; - case FX_LOCALEDATETIMESUBCATEGORY_Full: - wsPattern = GetSymbol(XFA_Element::DatePatterns, L"full"); - break; - case FX_LOCALEDATETIMESUBCATEGORY_Long: - wsPattern = GetSymbol(XFA_Element::DatePatterns, L"long"); - break; - } -} - -void CXFA_NodeLocale::GetTimePattern(FX_LOCALEDATETIMESUBCATEGORY eType, - CFX_WideString& wsPattern) const { - switch (eType) { - case FX_LOCALEDATETIMESUBCATEGORY_Short: - wsPattern = GetSymbol(XFA_Element::TimePatterns, L"short"); - break; - case FX_LOCALEDATETIMESUBCATEGORY_Medium: - case FX_LOCALEDATETIMESUBCATEGORY_Default: - wsPattern = GetSymbol(XFA_Element::TimePatterns, L"med"); - break; - case FX_LOCALEDATETIMESUBCATEGORY_Full: - wsPattern = GetSymbol(XFA_Element::TimePatterns, L"full"); - break; - case FX_LOCALEDATETIMESUBCATEGORY_Long: - wsPattern = GetSymbol(XFA_Element::TimePatterns, L"long"); - break; - } -} - -void CXFA_NodeLocale::GetNumPattern(FX_LOCALENUMSUBCATEGORY eType, - CFX_WideString& wsPattern) const { - switch (eType) { - case FX_LOCALENUMPATTERN_Percent: - wsPattern = g_FX_Percent; - break; - case FX_LOCALENUMPATTERN_Currency: - wsPattern = g_FX_Currency; - break; - case FX_LOCALENUMPATTERN_Decimal: - wsPattern = g_FX_Decimal; - break; - case FX_LOCALENUMPATTERN_Integer: - wsPattern = g_FX_Integer; - break; - } -} - -CXFA_Node* CXFA_NodeLocale::GetNodeByName(CXFA_Node* pParent, - const CFX_WideStringC& wsName) const { - CXFA_Node* pChild = - pParent ? pParent->GetNodeItem(XFA_NODEITEM_FirstChild) : nullptr; - while (pChild) { - CFX_WideString wsChild; - if (pChild->GetAttribute(XFA_ATTRIBUTE_Name, wsChild)) { - if (wsChild == wsName) { - return pChild; - } - } - pChild = pChild->GetNodeItem(XFA_NODEITEM_NextSibling); - } - return nullptr; -} - -CFX_WideString CXFA_NodeLocale::GetSymbol( - XFA_Element eElement, - const CFX_WideStringC& symbol_type) const { - CXFA_Node* pSymbols = m_pLocale ? m_pLocale->GetChild(0, eElement) : nullptr; - CXFA_Node* pSymbol = GetNodeByName(pSymbols, symbol_type); - return pSymbol ? pSymbol->GetContent() : CFX_WideString(); -} - -CFX_WideString CXFA_NodeLocale::GetCalendarSymbol(XFA_Element eElement, - int index, - bool bAbbr) const { - CXFA_Node* pCalendar = - m_pLocale ? m_pLocale->GetChild(0, XFA_Element::CalendarSymbols) - : nullptr; - if (pCalendar) { - CXFA_Node* pNode = pCalendar->GetFirstChildByClass(eElement); - for (; pNode; pNode = pNode->GetNextSameClassSibling(eElement)) { - if (pNode->GetBoolean(XFA_ATTRIBUTE_Abbr) == bAbbr) { - CXFA_Node* pSymbol = pNode->GetChild(index, XFA_Element::Unknown); - return pSymbol ? pSymbol->GetContent() : CFX_WideString(); - } - } - } - return CFX_WideString(); -} diff --git a/chromium/third_party/pdfium/xfa/fxfa/parser/xfa_locale.h b/chromium/third_party/pdfium/xfa/fxfa/parser/xfa_locale.h deleted file mode 100644 index 5326f513c1e..00000000000 --- a/chromium/third_party/pdfium/xfa/fxfa/parser/xfa_locale.h +++ /dev/null @@ -1,98 +0,0 @@ -// Copyright 2014 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#ifndef XFA_FXFA_PARSER_XFA_LOCALE_H_ -#define XFA_FXFA_PARSER_XFA_LOCALE_H_ - -#include <memory> - -#include "xfa/fgas/localization/fgas_locale.h" -#include "xfa/fxfa/parser/xfa_object.h" - -class CXFA_XMLLocale : public IFX_Locale { - public: - explicit CXFA_XMLLocale(std::unique_ptr<CXML_Element> pLocaleData); - ~CXFA_XMLLocale() override; - - // IFX_Locale - CFX_WideString GetName() const override; - void GetNumbericSymbol(FX_LOCALENUMSYMBOL eType, - CFX_WideString& wsNumSymbol) const override; - - void GetDateTimeSymbols(CFX_WideString& wsDtSymbol) const override; - void GetMonthName(int32_t nMonth, - CFX_WideString& wsMonthName, - bool bAbbr = true) const override; - void GetDayName(int32_t nWeek, - CFX_WideString& wsDayName, - bool bAbbr = true) const override; - void GetMeridiemName(CFX_WideString& wsMeridiemName, - bool bAM = true) const override; - void GetTimeZone(FX_TIMEZONE* tz) const override; - void GetEraName(CFX_WideString& wsEraName, bool bAD = true) const override; - - void GetDatePattern(FX_LOCALEDATETIMESUBCATEGORY eType, - CFX_WideString& wsPattern) const override; - void GetTimePattern(FX_LOCALEDATETIMESUBCATEGORY eType, - CFX_WideString& wsPattern) const override; - void GetNumPattern(FX_LOCALENUMSUBCATEGORY eType, - CFX_WideString& wsPattern) const override; - - protected: - void GetPattern(CXML_Element* pElement, - const CFX_ByteStringC& bsTag, - const CFX_WideStringC& wsName, - CFX_WideString& wsPattern) const; - CFX_WideString GetCalendarSymbol(const CFX_ByteStringC& symbol, - int index, - bool bAbbr) const; - - private: - std::unique_ptr<CXML_Element> m_pLocaleData; -}; - -class CXFA_NodeLocale : public IFX_Locale { - public: - explicit CXFA_NodeLocale(CXFA_Node* pLocale); - ~CXFA_NodeLocale() override; - - // IFX_Locale - CFX_WideString GetName() const override; - void GetNumbericSymbol(FX_LOCALENUMSYMBOL eType, - CFX_WideString& wsNumSymbol) const override; - - void GetDateTimeSymbols(CFX_WideString& wsDtSymbol) const override; - void GetMonthName(int32_t nMonth, - CFX_WideString& wsMonthName, - bool bAbbr = true) const override; - void GetDayName(int32_t nWeek, - CFX_WideString& wsDayName, - bool bAbbr = true) const override; - void GetMeridiemName(CFX_WideString& wsMeridiemName, - bool bAM = true) const override; - void GetTimeZone(FX_TIMEZONE* tz) const override; - void GetEraName(CFX_WideString& wsEraName, bool bAD = true) const override; - - void GetDatePattern(FX_LOCALEDATETIMESUBCATEGORY eType, - CFX_WideString& wsPattern) const override; - void GetTimePattern(FX_LOCALEDATETIMESUBCATEGORY eType, - CFX_WideString& wsPattern) const override; - void GetNumPattern(FX_LOCALENUMSUBCATEGORY eType, - CFX_WideString& wsPattern) const override; - - protected: - CXFA_Node* GetNodeByName(CXFA_Node* pParent, - const CFX_WideStringC& wsName) const; - CFX_WideString GetSymbol(XFA_Element eElement, - const CFX_WideStringC& symbol_type) const; - CFX_WideString GetCalendarSymbol(XFA_Element eElement, - int index, - bool bAbbr) const; - - CXFA_Node* const m_pLocale; -}; - -#endif // XFA_FXFA_PARSER_XFA_LOCALE_H_ diff --git a/chromium/third_party/pdfium/xfa/fxfa/parser/xfa_resolvenode_rs.h b/chromium/third_party/pdfium/xfa/fxfa/parser/xfa_resolvenode_rs.h index 7ad218efe8c..a30d540ef05 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/parser/xfa_resolvenode_rs.h +++ b/chromium/third_party/pdfium/xfa/fxfa/parser/xfa_resolvenode_rs.h @@ -8,8 +8,11 @@ #define XFA_FXFA_PARSER_XFA_RESOLVENODE_RS_H_ #include <memory> +#include <utility> +#include <vector> #include "fxjs/cfxjse_value.h" +#include "third_party/base/ptr_util.h" #include "xfa/fxfa/fxfa.h" #include "xfa/fxfa/parser/cxfa_valuearray.h" @@ -43,20 +46,20 @@ struct XFA_RESOLVENODE_RS { XFA_RESOLVENODE_RS(); ~XFA_RESOLVENODE_RS(); - int32_t GetAttributeResult(CXFA_ValueArray& valueArray) const { + size_t GetAttributeResult(CXFA_ValueArray* valueArray) const { if (pScriptAttribute && pScriptAttribute->eValueType == XFA_SCRIPT_Object) { - v8::Isolate* pIsolate = valueArray.m_pIsolate; - for (int32_t i = 0; i < nodes.GetSize(); i++) { - std::unique_ptr<CFXJSE_Value> pValue(new CFXJSE_Value(pIsolate)); - (nodes[i]->*(pScriptAttribute->lpfnCallback))( - pValue.get(), false, (XFA_ATTRIBUTE)pScriptAttribute->eAttribute); - valueArray.Add(pValue.release()); + for (CXFA_Object* pObject : objects) { + auto pValue = pdfium::MakeUnique<CFXJSE_Value>(valueArray->m_pIsolate); + (pObject->*(pScriptAttribute->lpfnCallback))( + pValue.get(), false, + static_cast<XFA_ATTRIBUTE>(pScriptAttribute->eAttribute)); + valueArray->m_Values.push_back(std::move(pValue)); } } - return valueArray.GetSize(); + return valueArray->m_Values.size(); } - CXFA_ObjArray nodes; + std::vector<CXFA_Object*> objects; // Not owned. XFA_RESOVENODE_RSTYPE dwFlags; const XFA_SCRIPTATTRIBUTEINFO* pScriptAttribute; }; @@ -64,7 +67,6 @@ struct XFA_RESOLVENODE_RS { inline XFA_RESOLVENODE_RS::XFA_RESOLVENODE_RS() : dwFlags(XFA_RESOVENODE_RSTYPE_Nodes), pScriptAttribute(nullptr) {} -inline XFA_RESOLVENODE_RS::~XFA_RESOLVENODE_RS() { - nodes.RemoveAll(); -} +inline XFA_RESOLVENODE_RS::~XFA_RESOLVENODE_RS() {} + #endif // XFA_FXFA_PARSER_XFA_RESOLVENODE_RS_H_ diff --git a/chromium/third_party/pdfium/xfa/fxfa/parser/xfa_utils.cpp b/chromium/third_party/pdfium/xfa/fxfa/parser/xfa_utils.cpp index 6f54c0e5fe4..6bd04c322fc 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/parser/xfa_utils.cpp +++ b/chromium/third_party/pdfium/xfa/fxfa/parser/xfa_utils.cpp @@ -7,34 +7,37 @@ #include "xfa/fxfa/parser/xfa_utils.h" #include "core/fxcrt/fx_ext.h" -#include "xfa/fde/xml/fde_xml_imp.h" +#include "xfa/fde/xml/cfde_xmlchardata.h" +#include "xfa/fde/xml/cfde_xmlelement.h" +#include "xfa/fde/xml/cfde_xmlnode.h" +#include "xfa/fde/xml/cfde_xmltext.h" #include "xfa/fxfa/parser/cxfa_document.h" +#include "xfa/fxfa/parser/cxfa_localemgr.h" +#include "xfa/fxfa/parser/cxfa_localevalue.h" #include "xfa/fxfa/parser/cxfa_measurement.h" +#include "xfa/fxfa/parser/cxfa_node.h" #include "xfa/fxfa/parser/xfa_basic_data.h" -#include "xfa/fxfa/parser/xfa_localemgr.h" -#include "xfa/fxfa/parser/xfa_localevalue.h" -#include "xfa/fxfa/parser/xfa_object.h" namespace { -const FX_DOUBLE fraction_scales[] = {0.1, - 0.01, - 0.001, - 0.0001, - 0.00001, - 0.000001, - 0.0000001, - 0.00000001, - 0.000000001, - 0.0000000001, - 0.00000000001, - 0.000000000001, - 0.0000000000001, - 0.00000000000001, - 0.000000000000001, - 0.0000000000000001}; - -FX_DOUBLE WideStringToDouble(const CFX_WideString& wsStringVal) { +const double fraction_scales[] = {0.1, + 0.01, + 0.001, + 0.0001, + 0.00001, + 0.000001, + 0.0000001, + 0.00000001, + 0.000000001, + 0.0000000001, + 0.00000000001, + 0.000000000001, + 0.0000000000001, + 0.00000000000001, + 0.000000000000001, + 0.0000000000000001}; + +double WideStringToDouble(const CFX_WideString& wsStringVal) { CFX_WideString wsValue = wsStringVal; wsValue.TrimLeft(); wsValue.TrimRight(); @@ -44,7 +47,7 @@ FX_DOUBLE WideStringToDouble(const CFX_WideString& wsStringVal) { int32_t cc = 0; bool bNegative = false; bool bExpSign = false; - const FX_WCHAR* str = wsValue.c_str(); + const wchar_t* str = wsValue.c_str(); int32_t len = wsValue.GetLength(); if (str[0] == '+') { cc++; @@ -67,25 +70,23 @@ FX_DOUBLE WideStringToDouble(const CFX_WideString& wsStringVal) { } nIntegral = bNegative ? -nIntegral : nIntegral; int32_t scale = 0; - FX_DOUBLE fraction = 0.0; + double fraction = 0.0; if (cc < len && str[cc] == '.') { cc++; while (cc < len) { - fraction += fraction_scales[scale] * (str[cc] - '0'); + fraction += XFA_GetFractionalScale(scale) * (str[cc] - '0'); scale++; cc++; - if (cc == len) { + if (cc == len) break; - } - if (scale == sizeof(fraction_scales) / sizeof(FX_DOUBLE) || - str[cc] == 'E' || str[cc] == 'e') { + if (scale == XFA_GetMaxFractionalScale() || str[cc] == 'E' || + str[cc] == 'e') { break; } - if (!FXSYS_isDecimalDigit(str[cc])) { + if (!FXSYS_isDecimalDigit(str[cc])) return 0; - } } - dwFractional = (uint32_t)(fraction * 4294967296.0); + dwFractional = static_cast<uint32_t>(fraction * 4294967296.0); } if (cc < len && (str[cc] == 'E' || str[cc] == 'e')) { cc++; @@ -98,24 +99,33 @@ FX_DOUBLE WideStringToDouble(const CFX_WideString& wsStringVal) { } } while (cc < len) { - if (str[cc] == '.' || !FXSYS_isDecimalDigit(str[cc])) { + if (str[cc] == '.' || !FXSYS_isDecimalDigit(str[cc])) return 0; - } + nExponent = nExponent * 10 + str[cc] - '0'; cc++; } nExponent = bExpSign ? -nExponent : nExponent; } - FX_DOUBLE dValue = (dwFractional / 4294967296.0); + + double dValue = dwFractional / 4294967296.0; dValue = nIntegral + (nIntegral >= 0 ? dValue : -dValue); - if (nExponent != 0) { - dValue *= FXSYS_pow(10, (FX_FLOAT)nExponent); - } + if (nExponent != 0) + dValue *= FXSYS_pow(10, static_cast<float>(nExponent)); + return dValue; } } // namespace +double XFA_GetFractionalScale(uint32_t idx) { + return fraction_scales[idx]; +} + +int XFA_GetMaxFractionalScale() { + return FX_ArraySize(fraction_scales); +} + CXFA_LocaleValue XFA_GetLocaleValue(CXFA_WidgetData* pWidgetData) { CXFA_Node* pNodeValue = pWidgetData->GetNode()->GetChild(0, XFA_Element::Value); @@ -167,8 +177,7 @@ void XFA_GetPlainTextFromRichText(CFDE_XMLNode* pXMLNode, switch (pXMLNode->GetType()) { case FDE_XMLNODE_Element: { CFDE_XMLElement* pXMLElement = static_cast<CFDE_XMLElement*>(pXMLNode); - CFX_WideString wsTag; - pXMLElement->GetLocalTagName(wsTag); + CFX_WideString wsTag = pXMLElement->GetLocalTagName(); uint32_t uTag = FX_HashCode_GetW(wsTag.AsStringC(), true); if (uTag == 0x0001f714) { wsPlainText += L"\n"; @@ -182,17 +191,15 @@ void XFA_GetPlainTextFromRichText(CFDE_XMLNode* pXMLNode, wsPlainText += L"\n"; } } - } break; - case FDE_XMLNODE_Text: { - CFX_WideString wsContent; - static_cast<CFDE_XMLText*>(pXMLNode)->GetText(wsContent); - wsPlainText += wsContent; - } break; + break; + } + case FDE_XMLNODE_Text: case FDE_XMLNODE_CharData: { - CFX_WideString wsCharData; - static_cast<CFDE_XMLCharData*>(pXMLNode)->GetCharData(wsCharData); - wsPlainText += wsCharData; - } break; + CFX_WideString wsContent = + static_cast<CFDE_XMLText*>(pXMLNode)->GetText(); + wsPlainText += wsContent; + break; + } default: break; } @@ -221,7 +228,7 @@ bool XFA_FieldIsMultiListBox(CXFA_Node* pFieldNode) { return bRet; } -FX_DOUBLE XFA_ByteStringToDouble(const CFX_ByteStringC& szStringVal) { +double XFA_ByteStringToDouble(const CFX_ByteStringC& szStringVal) { CFX_WideString wsValue = CFX_WideString::FromUTF8(szStringVal); return WideStringToDouble(wsValue); } @@ -328,10 +335,10 @@ const XFA_PROPERTY* XFA_GetPropertyOfElement(XFA_Element eElement, if (!pProperties || iCount < 1) return nullptr; - auto it = std::find_if(pProperties, pProperties + iCount, - [eProperty](const XFA_PROPERTY& prop) { - return prop.eName == eProperty; - }); + auto* it = std::find_if(pProperties, pProperties + iCount, + [eProperty](const XFA_PROPERTY& prop) { + return prop.eName == eProperty; + }); if (it == pProperties + iCount) return nullptr; @@ -375,10 +382,11 @@ XFA_Element XFA_GetElementTypeForName(const CFX_WideStringC& wsName) { uint32_t uHash = FX_HashCode_GetW(wsName, false); const XFA_ELEMENTINFO* pEnd = g_XFAElementData + g_iXFAElementCount; - auto pInfo = std::lower_bound(g_XFAElementData, pEnd, uHash, - [](const XFA_ELEMENTINFO& info, uint32_t hash) { - return info.uHash < hash; - }); + auto* pInfo = + std::lower_bound(g_XFAElementData, pEnd, uHash, + [](const XFA_ELEMENTINFO& info, uint32_t hash) { + return info.uHash < hash; + }); if (pInfo < pEnd && pInfo->uHash == uHash) return pInfo->eName; return XFA_Element::Unknown; diff --git a/chromium/third_party/pdfium/xfa/fxfa/parser/xfa_utils.h b/chromium/third_party/pdfium/xfa/fxfa/parser/xfa_utils.h index d09afda0f95..36d62c76023 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/parser/xfa_utils.h +++ b/chromium/third_party/pdfium/xfa/fxfa/parser/xfa_utils.h @@ -7,9 +7,7 @@ #ifndef XFA_FXFA_PARSER_XFA_UTILS_H_ #define XFA_FXFA_PARSER_XFA_UTILS_H_ -#include "xfa/fde/xml/fde_xml.h" -#include "xfa/fgas/crt/fgas_stream.h" -#include "xfa/fgas/crt/fgas_utils.h" +#include "xfa/fgas/crt/ifgas_stream.h" #include "xfa/fxfa/fxfa_basic.h" class CFDE_XMLElement; @@ -18,152 +16,135 @@ class CXFA_LocaleValue; class CXFA_Node; class CXFA_WidgetData; +double XFA_GetFractionalScale(uint32_t idx); +int XFA_GetMaxFractionalScale(); + bool XFA_FDEExtension_ResolveNamespaceQualifier( CFDE_XMLElement* pNode, const CFX_WideStringC& wsQualifier, - CFX_WideString& wsNamespaceURI); + CFX_WideString* wsNamespaceURI); template <class NodeType, class TraverseStrategy> class CXFA_NodeIteratorTemplate { public: - explicit CXFA_NodeIteratorTemplate(NodeType* pRootNode = nullptr) - : m_pRoot(pRootNode), m_NodeStack(100) { - if (pRootNode) { - m_NodeStack.Push(pRootNode); - } - } - bool Init(NodeType* pRootNode) { - if (!pRootNode) { + explicit CXFA_NodeIteratorTemplate(NodeType* pRoot) + : m_pRoot(pRoot), m_pCurrent(pRoot) {} + + NodeType* GetRoot() const { return m_pRoot; } + NodeType* GetCurrent() const { return m_pCurrent; } + + void Reset() { m_pCurrent = m_pRoot; } + bool SetCurrent(NodeType* pNode) { + if (!RootReachableFromNode(pNode)) { + m_pCurrent = nullptr; return false; } - m_pRoot = pRootNode; - m_NodeStack.RemoveAll(false); - m_NodeStack.Push(pRootNode); - return true; - } - void Clear() { m_NodeStack.RemoveAll(false); } - void Reset() { - Clear(); - if (m_pRoot) { - m_NodeStack.Push(m_pRoot); - } - } - bool SetCurrent(NodeType* pCurNode) { - m_NodeStack.RemoveAll(false); - if (pCurNode) { - CFX_StackTemplate<NodeType*> revStack(100); - NodeType* pNode; - for (pNode = pCurNode; pNode && pNode != m_pRoot; - pNode = TraverseStrategy::GetParent(pNode)) { - revStack.Push(pNode); - } - if (!pNode) { - return false; - } - revStack.Push(m_pRoot); - while (revStack.GetSize()) { - m_NodeStack.Push(*revStack.GetTopElement()); - revStack.Pop(); - } - } + m_pCurrent = pNode; return true; } - NodeType* GetCurrent() const { - return m_NodeStack.GetSize() ? *m_NodeStack.GetTopElement() : nullptr; - } - NodeType* GetRoot() const { return m_pRoot; } + NodeType* MoveToPrev() { - int32_t nStackLength = m_NodeStack.GetSize(); - if (nStackLength == 1) { + if (!m_pRoot) return nullptr; - } else if (nStackLength > 1) { - NodeType* pCurItem = *m_NodeStack.GetTopElement(); - m_NodeStack.Pop(); - NodeType* pParentItem = *m_NodeStack.GetTopElement(); - NodeType* pParentFirstChildItem = - TraverseStrategy::GetFirstChild(pParentItem); - if (pCurItem == pParentFirstChildItem) { - return pParentItem; - } - NodeType *pPrevItem = pParentFirstChildItem, *pPrevItemNext = nullptr; - for (; pPrevItem; pPrevItem = pPrevItemNext) { - pPrevItemNext = TraverseStrategy::GetNextSibling(pPrevItem); - if (!pPrevItemNext || pPrevItemNext == pCurItem) { - break; - } - } - m_NodeStack.Push(pPrevItem); - } else { - m_NodeStack.RemoveAll(false); - if (m_pRoot) { - m_NodeStack.Push(m_pRoot); - } + if (!m_pCurrent) { + m_pCurrent = LastDescendant(m_pRoot); + return m_pCurrent; } - if (m_NodeStack.GetSize() > 0) { - NodeType* pChildItem = *m_NodeStack.GetTopElement(); - while ((pChildItem = TraverseStrategy::GetFirstChild(pChildItem)) != - nullptr) { - while (NodeType* pNextItem = - TraverseStrategy::GetNextSibling(pChildItem)) { - pChildItem = pNextItem; - } - m_NodeStack.Push(pChildItem); - } - return *m_NodeStack.GetTopElement(); + NodeType* pSibling = PreviousSiblingWithinSubtree(m_pCurrent); + if (pSibling) { + m_pCurrent = LastDescendant(pSibling); + return m_pCurrent; + } + NodeType* pParent = ParentWithinSubtree(m_pCurrent); + if (pParent) { + m_pCurrent = pParent; + return m_pCurrent; } return nullptr; } + NodeType* MoveToNext() { - NodeType** ppNode = nullptr; - NodeType* pCurrent = GetCurrent(); - while (m_NodeStack.GetSize() > 0) { - while ((ppNode = m_NodeStack.GetTopElement()) != nullptr) { - if (pCurrent != *ppNode) { - return *ppNode; - } - NodeType* pChild = TraverseStrategy::GetFirstChild(*ppNode); - if (!pChild) { - break; - } - m_NodeStack.Push(pChild); - } - while ((ppNode = m_NodeStack.GetTopElement()) != nullptr) { - NodeType* pNext = TraverseStrategy::GetNextSibling(*ppNode); - m_NodeStack.Pop(); - if (m_NodeStack.GetSize() == 0) { - break; - } - if (pNext) { - m_NodeStack.Push(pNext); - break; - } - } + if (!m_pRoot || !m_pCurrent) + return nullptr; + NodeType* pChild = TraverseStrategy::GetFirstChild(m_pCurrent); + if (pChild) { + m_pCurrent = pChild; + return m_pCurrent; } - return nullptr; + return SkipChildrenAndMoveToNext(); } + NodeType* SkipChildrenAndMoveToNext() { - NodeType** ppNode = nullptr; - while ((ppNode = m_NodeStack.GetTopElement()) != nullptr) { - NodeType* pNext = TraverseStrategy::GetNextSibling(*ppNode); - m_NodeStack.Pop(); - if (m_NodeStack.GetSize() == 0) { - break; - } - if (pNext) { - m_NodeStack.Push(pNext); - break; + if (!m_pRoot) + return nullptr; + NodeType* pNode = m_pCurrent; + while (pNode) { + NodeType* pSibling = NextSiblingWithinSubtree(pNode); + if (pSibling) { + m_pCurrent = pSibling; + return m_pCurrent; } + pNode = ParentWithinSubtree(pNode); + } + m_pCurrent = nullptr; + return m_pCurrent; + } + + private: + bool RootReachableFromNode(NodeType* pNode) { + if (!pNode) + return false; + if (pNode == m_pRoot) + return true; + return RootReachableFromNode(TraverseStrategy::GetParent(pNode)); + } + + NodeType* ParentWithinSubtree(NodeType* pNode) { + if (!pNode || pNode == m_pRoot) + return nullptr; + return TraverseStrategy::GetParent(pNode); + } + + NodeType* NextSiblingWithinSubtree(NodeType* pNode) { + if (pNode == m_pRoot) + return nullptr; + return TraverseStrategy::GetNextSibling(pNode); + } + + NodeType* PreviousSiblingWithinSubtree(NodeType* pNode) { + NodeType* pParent = ParentWithinSubtree(pNode); + if (!pParent) + return nullptr; + NodeType* pCurrent = TraverseStrategy::GetFirstChild(pParent); + NodeType* pPrevious = nullptr; + while (pCurrent != pNode) { + pPrevious = pCurrent; + pCurrent = TraverseStrategy::GetNextSibling(pCurrent); + } + return pPrevious; + } + + NodeType* LastChild(NodeType* pNode) { + NodeType* pPrevious = nullptr; + NodeType* pChild = TraverseStrategy::GetFirstChild(pNode); + while (pChild) { + pPrevious = pChild; + pChild = NextSiblingWithinSubtree(pChild); } - return GetCurrent(); + return pPrevious; + } + + NodeType* LastDescendant(NodeType* pNode) { + NodeType* pChild = LastChild(pNode); + return pChild ? LastDescendant(pChild) : pNode; } - protected: NodeType* m_pRoot; - CFX_StackTemplate<NodeType*> m_NodeStack; + NodeType* m_pCurrent; }; CXFA_LocaleValue XFA_GetLocaleValue(CXFA_WidgetData* pWidgetData); -FX_DOUBLE XFA_ByteStringToDouble(const CFX_ByteStringC& szStringVal); +double XFA_ByteStringToDouble(const CFX_ByteStringC& szStringVal); int32_t XFA_MapRotation(int32_t nRotation); bool XFA_RecognizeRichText(CFDE_XMLElement* pRichTextXMLNode); @@ -175,7 +156,7 @@ void XFA_DataExporter_DealWithDataGroupNode(CXFA_Node* pDataNode); void XFA_DataExporter_RegenerateFormFile( CXFA_Node* pNode, const CFX_RetainPtr<IFGAS_Stream>& pStream, - const FX_CHAR* pChecksum = nullptr, + const char* pChecksum = nullptr, bool bSaveXML = false); const XFA_NOTSUREATTRIBUTE* XFA_GetNotsureAttribute( diff --git a/chromium/third_party/pdfium/xfa/fxfa/parser/xfa_utils_unittest.cpp b/chromium/third_party/pdfium/xfa/fxfa/parser/xfa_utils_unittest.cpp index 93ee3b94aa9..e4dd09419e3 100644 --- a/chromium/third_party/pdfium/xfa/fxfa/parser/xfa_utils_unittest.cpp +++ b/chromium/third_party/pdfium/xfa/fxfa/parser/xfa_utils_unittest.cpp @@ -2,10 +2,18 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "testing/gtest/include/gtest/gtest.h" #include "xfa/fxfa/parser/xfa_utils.h" -TEST(XfaUtilsImp, XFA_MapRotation) { +#include <memory> +#include <vector> + +#include "testing/gtest/include/gtest/gtest.h" +#include "testing/test_support.h" +#include "third_party/base/ptr_util.h" + +class XfaUtilsImpTest : public pdfium::FPDF_Test {}; + +TEST_F(XfaUtilsImpTest, XFA_MapRotation) { struct TestCase { int input; int expected_output; @@ -20,3 +28,248 @@ TEST(XfaUtilsImp, XFA_MapRotation) { XFA_MapRotation(TestCases[i].input)); } } + +class XFANodeIteratorTest : public pdfium::FPDF_Test { + public: + class Node { + public: + class Strategy { + public: + static Node* GetFirstChild(Node* pNode) { + return pNode && !pNode->children_.empty() ? pNode->children_.front() + : nullptr; + } + static Node* GetNextSibling(Node* pNode) { + return pNode ? pNode->next_sibling_ : nullptr; + } + static Node* GetParent(Node* pNode) { + return pNode ? pNode->parent_ : nullptr; + } + }; + + explicit Node(Node* parent) : parent_(parent), next_sibling_(nullptr) { + if (parent) { + if (!parent->children_.empty()) + parent->children_.back()->next_sibling_ = this; + parent->children_.push_back(this); + } + } + + private: + Node* parent_; + Node* next_sibling_; + std::vector<Node*> children_; + }; + + using Iterator = CXFA_NodeIteratorTemplate<Node, Node::Strategy>; + + // Builds a tree along the lines of: + // + // root + // | + // child1--child2 + // | + // child3------------child7--child9 + // | | + // child4--child6 child8 + // | + // child5 + // + void SetUp() override { + root_ = pdfium::MakeUnique<Node>(nullptr); + child1_ = pdfium::MakeUnique<Node>(root_.get()); + child2_ = pdfium::MakeUnique<Node>(root_.get()); + child3_ = pdfium::MakeUnique<Node>(child2_.get()); + child4_ = pdfium::MakeUnique<Node>(child3_.get()); + child5_ = pdfium::MakeUnique<Node>(child4_.get()); + child6_ = pdfium::MakeUnique<Node>(child3_.get()); + child7_ = pdfium::MakeUnique<Node>(child2_.get()); + child8_ = pdfium::MakeUnique<Node>(child7_.get()); + child9_ = pdfium::MakeUnique<Node>(child2_.get()); + } + + Node* root() const { return root_.get(); } + Node* child1() const { return child1_.get(); } + Node* child2() const { return child2_.get(); } + Node* child3() const { return child3_.get(); } + Node* child4() const { return child4_.get(); } + Node* child5() const { return child5_.get(); } + Node* child6() const { return child6_.get(); } + Node* child7() const { return child7_.get(); } + Node* child8() const { return child8_.get(); } + Node* child9() const { return child9_.get(); } + + protected: + std::unique_ptr<Node> root_; + std::unique_ptr<Node> child1_; + std::unique_ptr<Node> child2_; + std::unique_ptr<Node> child3_; + std::unique_ptr<Node> child4_; + std::unique_ptr<Node> child5_; + std::unique_ptr<Node> child6_; + std::unique_ptr<Node> child7_; + std::unique_ptr<Node> child8_; + std::unique_ptr<Node> child9_; +}; + +TEST_F(XFANodeIteratorTest, Empty) { + Iterator iter(nullptr); + EXPECT_EQ(nullptr, iter.GetRoot()); + EXPECT_EQ(nullptr, iter.GetCurrent()); + EXPECT_EQ(nullptr, iter.MoveToNext()); + EXPECT_EQ(nullptr, iter.MoveToPrev()); + EXPECT_EQ(nullptr, iter.SkipChildrenAndMoveToNext()); +} + +TEST_F(XFANodeIteratorTest, Root) { + Iterator iter(root()); + EXPECT_EQ(root(), iter.GetRoot()); + EXPECT_EQ(root(), iter.GetCurrent()); +} + +TEST_F(XFANodeIteratorTest, Current) { + Iterator iter(root()); + iter.SetCurrent(child1()); + EXPECT_EQ(root(), iter.GetRoot()); + EXPECT_EQ(child1(), iter.GetCurrent()); +} + +TEST_F(XFANodeIteratorTest, CurrentOutsideRootDisallowed) { + Iterator iter(child1()); + iter.SetCurrent(root()); + EXPECT_EQ(child1(), iter.GetRoot()); + EXPECT_EQ(nullptr, iter.GetCurrent()); +} + +TEST_F(XFANodeIteratorTest, CurrentNull) { + Iterator iter(root()); + EXPECT_EQ(child1(), iter.MoveToNext()); + + iter.SetCurrent(nullptr); + EXPECT_EQ(nullptr, iter.GetCurrent()); + + EXPECT_EQ(nullptr, iter.MoveToNext()); + EXPECT_EQ(nullptr, iter.GetCurrent()); +} + +TEST_F(XFANodeIteratorTest, MoveToPrev) { + Iterator iter(root()); + iter.SetCurrent(child9()); + + EXPECT_EQ(child8(), iter.MoveToPrev()); + EXPECT_EQ(child8(), iter.GetCurrent()); + + EXPECT_EQ(child7(), iter.MoveToPrev()); + EXPECT_EQ(child7(), iter.GetCurrent()); + + EXPECT_EQ(child6(), iter.MoveToPrev()); + EXPECT_EQ(child6(), iter.GetCurrent()); + + EXPECT_EQ(child5(), iter.MoveToPrev()); + EXPECT_EQ(child5(), iter.GetCurrent()); + + EXPECT_EQ(child4(), iter.MoveToPrev()); + EXPECT_EQ(child4(), iter.GetCurrent()); + + EXPECT_EQ(child3(), iter.MoveToPrev()); + EXPECT_EQ(child3(), iter.GetCurrent()); + + EXPECT_EQ(child2(), iter.MoveToPrev()); + EXPECT_EQ(child2(), iter.GetCurrent()); + + EXPECT_EQ(child1(), iter.MoveToPrev()); + EXPECT_EQ(child1(), iter.GetCurrent()); + + EXPECT_EQ(root(), iter.MoveToPrev()); + EXPECT_EQ(root(), iter.GetCurrent()); + + EXPECT_EQ(nullptr, iter.MoveToPrev()); + EXPECT_EQ(root(), iter.GetCurrent()); + + EXPECT_EQ(nullptr, iter.MoveToPrev()); + EXPECT_EQ(root(), iter.GetCurrent()); +} + +TEST_F(XFANodeIteratorTest, MoveToNext) { + Iterator iter(root()); + iter.SetCurrent(child2()); + + EXPECT_EQ(child3(), iter.MoveToNext()); + EXPECT_EQ(child3(), iter.GetCurrent()); + + EXPECT_EQ(child4(), iter.MoveToNext()); + EXPECT_EQ(child4(), iter.GetCurrent()); + + EXPECT_EQ(child5(), iter.MoveToNext()); + EXPECT_EQ(child5(), iter.GetCurrent()); + + EXPECT_EQ(child6(), iter.MoveToNext()); + EXPECT_EQ(child6(), iter.GetCurrent()); + + EXPECT_EQ(child7(), iter.MoveToNext()); + EXPECT_EQ(child7(), iter.GetCurrent()); + + EXPECT_EQ(child8(), iter.MoveToNext()); + EXPECT_EQ(child8(), iter.GetCurrent()); + + EXPECT_EQ(child9(), iter.MoveToNext()); + EXPECT_EQ(child9(), iter.GetCurrent()); + + EXPECT_EQ(nullptr, iter.MoveToNext()); + EXPECT_EQ(nullptr, iter.GetCurrent()); + + EXPECT_EQ(nullptr, iter.MoveToNext()); + EXPECT_EQ(nullptr, iter.GetCurrent()); +} + +TEST_F(XFANodeIteratorTest, SkipChildrenAndMoveToNext) { + Iterator iter(root()); + iter.SetCurrent(child3()); + EXPECT_EQ(child7(), iter.SkipChildrenAndMoveToNext()); + EXPECT_EQ(child9(), iter.SkipChildrenAndMoveToNext()); + EXPECT_EQ(nullptr, iter.SkipChildrenAndMoveToNext()); +} + +TEST_F(XFANodeIteratorTest, BackAndForth) { + Iterator iter(root()); + EXPECT_EQ(child1(), iter.MoveToNext()); + EXPECT_EQ(child2(), iter.MoveToNext()); + EXPECT_EQ(child3(), iter.MoveToNext()); + EXPECT_EQ(child4(), iter.MoveToNext()); + EXPECT_EQ(child5(), iter.MoveToNext()); + EXPECT_EQ(child4(), iter.MoveToPrev()); + EXPECT_EQ(child3(), iter.MoveToPrev()); + EXPECT_EQ(child2(), iter.MoveToPrev()); + EXPECT_EQ(child1(), iter.MoveToPrev()); +} + +TEST_F(XFANodeIteratorTest, NextFromBeforeTheBeginning) { + Iterator iter(root()); + EXPECT_EQ(nullptr, iter.MoveToPrev()); + EXPECT_EQ(root(), iter.GetCurrent()); + EXPECT_EQ(child1(), iter.MoveToNext()); +} + +TEST_F(XFANodeIteratorTest, PrevFromAfterTheEnd) { + Iterator iter(root()); + iter.SetCurrent(child9()); + EXPECT_EQ(nullptr, iter.MoveToNext()); + EXPECT_EQ(child9(), iter.MoveToPrev()); +} + +TEST_F(XFANodeIteratorTest, ChildAsRootPrev) { + Iterator iter(child3()); + EXPECT_EQ(nullptr, iter.MoveToPrev()); + + iter.SetCurrent(child4()); + EXPECT_EQ(child3(), iter.MoveToPrev()); + EXPECT_EQ(nullptr, iter.MoveToPrev()); +} + +TEST_F(XFANodeIteratorTest, ChildAsRootNext) { + Iterator iter(child3()); + iter.SetCurrent(child4()); + EXPECT_EQ(child5(), iter.MoveToNext()); + EXPECT_EQ(child6(), iter.MoveToNext()); + EXPECT_EQ(nullptr, iter.MoveToNext()); +} diff --git a/chromium/third_party/pdfium/xfa/fxfa/xfa_checksum.h b/chromium/third_party/pdfium/xfa/fxfa/xfa_checksum.h deleted file mode 100644 index 31cf1015535..00000000000 --- a/chromium/third_party/pdfium/xfa/fxfa/xfa_checksum.h +++ /dev/null @@ -1,80 +0,0 @@ -// Copyright 2014 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#ifndef XFA_FXFA_XFA_CHECKSUM_H_ -#define XFA_FXFA_XFA_CHECKSUM_H_ - -#include <memory> - -#include "core/fdrm/crypto/fx_crypt.h" -#include "xfa/fde/xml/cfx_saxreader.h" -#include "xfa/fxfa/fxfa.h" - -class CXFA_SAXReaderHandler; -class CXFA_ChecksumContext; - -class CXFA_SAXContext { - public: - CXFA_SAXContext() : m_eNode(CFX_SAXItem::Type::Unknown) {} - - CFX_ByteTextBuf m_TextBuf; - CFX_ByteString m_bsTagName; - CFX_SAXItem::Type m_eNode; -}; - -class CXFA_SAXReaderHandler { - public: - explicit CXFA_SAXReaderHandler(CXFA_ChecksumContext* pContext); - ~CXFA_SAXReaderHandler(); - - CXFA_SAXContext* OnTagEnter(const CFX_ByteStringC& bsTagName, - CFX_SAXItem::Type eType, - uint32_t dwStartPos); - void OnTagAttribute(CXFA_SAXContext* pTag, - const CFX_ByteStringC& bsAttri, - const CFX_ByteStringC& bsValue); - void OnTagBreak(CXFA_SAXContext* pTag); - void OnTagData(CXFA_SAXContext* pTag, - CFX_SAXItem::Type eType, - const CFX_ByteStringC& bsData, - uint32_t dwStartPos); - void OnTagClose(CXFA_SAXContext* pTag, uint32_t dwEndPos); - void OnTagEnd(CXFA_SAXContext* pTag, - const CFX_ByteStringC& bsTagName, - uint32_t dwEndPos); - - void OnTargetData(CXFA_SAXContext* pTag, - CFX_SAXItem::Type eType, - const CFX_ByteStringC& bsData, - uint32_t dwStartPos); - - protected: - void UpdateChecksum(bool bCheckSpace); - - CXFA_ChecksumContext* m_pContext; - CXFA_SAXContext m_SAXContext; -}; - -class CXFA_ChecksumContext { - public: - CXFA_ChecksumContext(); - ~CXFA_ChecksumContext(); - - void StartChecksum(); - void Update(const CFX_ByteStringC& bsText); - bool UpdateChecksum(const CFX_RetainPtr<IFX_SeekableReadStream>& pSrcFile, - FX_FILESIZE offset = 0, - size_t size = 0); - void FinishChecksum(); - CFX_ByteString GetChecksum() const; - - protected: - std::unique_ptr<CFX_SAXReader> m_pSAXReader; - std::unique_ptr<CRYPT_sha1_context> m_pByteContext; - CFX_ByteString m_bsChecksum; -}; - -#endif // XFA_FXFA_XFA_CHECKSUM_H_ diff --git a/chromium/third_party/pdfium/xfa/fxfa/xfa_fontmgr.h b/chromium/third_party/pdfium/xfa/fxfa/xfa_fontmgr.h deleted file mode 100644 index f00b069ef03..00000000000 --- a/chromium/third_party/pdfium/xfa/fxfa/xfa_fontmgr.h +++ /dev/null @@ -1,103 +0,0 @@ -// Copyright 2014 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#ifndef XFA_FXFA_XFA_FONTMGR_H_ -#define XFA_FXFA_XFA_FONTMGR_H_ - -#include <map> -#include <memory> -#include <vector> - -#include "core/fxcrt/cfx_retain_ptr.h" -#include "core/fxcrt/fx_ext.h" -#include "core/fxcrt/fx_system.h" -#include "xfa/fgas/font/cfgas_fontmgr.h" -#include "xfa/fxfa/fxfa.h" - -class CPDF_Font; - -struct XFA_FONTINFO { - uint32_t dwFontNameHash; - const FX_WCHAR* pPsName; - const FX_WCHAR* pReplaceFont; - uint16_t dwStyles; - uint16_t wCodePage; -}; - -class CXFA_DefFontMgr { - public: - CXFA_DefFontMgr(); - ~CXFA_DefFontMgr(); - - CFX_RetainPtr<CFGAS_GEFont> GetFont(CXFA_FFDoc* hDoc, - const CFX_WideStringC& wsFontFamily, - uint32_t dwFontStyles, - uint16_t wCodePage = 0xFFFF); - CFX_RetainPtr<CFGAS_GEFont> GetDefaultFont( - CXFA_FFDoc* hDoc, - const CFX_WideStringC& wsFontFamily, - uint32_t dwFontStyles, - uint16_t wCodePage = 0xFFFF); - - protected: - std::vector<CFX_RetainPtr<CFGAS_GEFont>> m_CacheFonts; -}; - -class CXFA_PDFFontMgr { - public: - explicit CXFA_PDFFontMgr(CXFA_FFDoc* pDoc); - ~CXFA_PDFFontMgr(); - - CFX_RetainPtr<CFGAS_GEFont> GetFont(const CFX_WideStringC& wsFontFamily, - uint32_t dwFontStyles, - CPDF_Font** pPDFFont, - bool bStrictMatch); - bool GetCharWidth(const CFX_RetainPtr<CFGAS_GEFont>& pFont, - FX_WCHAR wUnicode, - bool bCharCode, - int32_t* pWidth); - void SetFont(const CFX_RetainPtr<CFGAS_GEFont>& pFont, CPDF_Font* pPDFFont); - - protected: - CFX_RetainPtr<CFGAS_GEFont> FindFont(const CFX_ByteString& strFamilyName, - bool bBold, - bool bItalic, - CPDF_Font** pPDFFont, - bool bStrictMatch); - CFX_ByteString PsNameToFontName(const CFX_ByteString& strPsName, - bool bBold, - bool bItalic); - bool PsNameMatchDRFontName(const CFX_ByteStringC& bsPsName, - bool bBold, - bool bItalic, - const CFX_ByteString& bsDRFontName, - bool bStrictMatch); - - CXFA_FFDoc* const m_pDoc; - std::map<CFX_RetainPtr<CFGAS_GEFont>, CPDF_Font*> m_FDE2PDFFont; - std::map<CFX_ByteString, CFX_RetainPtr<CFGAS_GEFont>> m_FontMap; -}; - -class CXFA_FontMgr { - public: - CXFA_FontMgr(); - ~CXFA_FontMgr(); - - CFX_RetainPtr<CFGAS_GEFont> GetFont(CXFA_FFDoc* hDoc, - const CFX_WideStringC& wsFontFamily, - uint32_t dwFontStyles, - uint16_t wCodePage = 0xFFFF); - void LoadDocFonts(CXFA_FFDoc* hDoc); - void ReleaseDocFonts(CXFA_FFDoc* hDoc); - void SetDefFontMgr(std::unique_ptr<CXFA_DefFontMgr> pFontMgr); - - protected: - std::unique_ptr<CXFA_DefFontMgr> m_pDefFontMgr; - std::map<CXFA_FFDoc*, std::unique_ptr<CXFA_PDFFontMgr>> m_PDFFontMgrMap; - std::map<CFX_ByteString, CFX_RetainPtr<CFGAS_GEFont>> m_FontMap; -}; - -#endif // XFA_FXFA_XFA_FONTMGR_H_ |