From 0d86ecb08e1b2c204333b1f1f6b0b014e5b2971c Mon Sep 17 00:00:00 2001 From: Dan Sinclair Date: Wed, 19 Apr 2017 09:19:57 -0400 Subject: Move fde XML parser to core MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This CL moves the XML parser from FDE into FXCRT and renames to CFX_ from CFDE_. Change-Id: I21a9590bf74daf5517df630d7e7a5de89da99ea4 Reviewed-on: https://pdfium-review.googlesource.com/4312 Commit-Queue: dsinclair Reviewed-by: Tom Sepez Reviewed-by: Nicolás Peña --- xfa/fxfa/app/cxfa_loadercontext.h | 4 +-- xfa/fxfa/app/cxfa_textlayout.cpp | 59 +++++++++++++++++++-------------------- xfa/fxfa/app/cxfa_textlayout.h | 8 +++--- xfa/fxfa/app/cxfa_textparser.cpp | 35 +++++++++++------------ xfa/fxfa/app/cxfa_textparser.h | 18 ++++++------ xfa/fxfa/app/xfa_ffwidgetacc.cpp | 16 +++++------ 6 files changed, 69 insertions(+), 71 deletions(-) (limited to 'xfa/fxfa/app') diff --git a/xfa/fxfa/app/cxfa_loadercontext.h b/xfa/fxfa/app/cxfa_loadercontext.h index 16d9608bac..553252e200 100644 --- a/xfa/fxfa/app/cxfa_loadercontext.h +++ b/xfa/fxfa/app/cxfa_loadercontext.h @@ -13,7 +13,7 @@ #include "core/fxcrt/fx_system.h" #include "xfa/fde/css/cfde_csscomputedstyle.h" -class CFDE_XMLNode; +class CFX_XMLNode; class CXFA_Node; class CXFA_LoaderContext { @@ -30,7 +30,7 @@ class CXFA_LoaderContext { int32_t m_iLines; int32_t m_iTotalLines; uint32_t m_dwFlags; - CFDE_XMLNode* m_pXMLNode; + CFX_XMLNode* m_pXMLNode; CXFA_Node* m_pNode; CFX_RetainPtr m_pParentStyle; std::vector m_lineHeights; diff --git a/xfa/fxfa/app/cxfa_textlayout.cpp b/xfa/fxfa/app/cxfa_textlayout.cpp index 880bdf4585..69f5f53db3 100644 --- a/xfa/fxfa/app/cxfa_textlayout.cpp +++ b/xfa/fxfa/app/cxfa_textlayout.cpp @@ -9,6 +9,9 @@ #include #include +#include "core/fxcrt/xml/cfx_xmlelement.h" +#include "core/fxcrt/xml/cfx_xmlnode.h" +#include "core/fxcrt/xml/cfx_xmltext.h" #include "third_party/base/ptr_util.h" #include "third_party/base/stl_util.h" #include "xfa/fde/cfde_brush.h" @@ -17,9 +20,6 @@ #include "xfa/fde/cfde_renderdevice.h" #include "xfa/fde/css/cfde_csscomputedstyle.h" #include "xfa/fde/css/cfde_cssstyleselector.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" @@ -66,21 +66,20 @@ void CXFA_TextLayout::GetTextDataNode() { m_pTextDataNode = pNode; } -CFDE_XMLNode* CXFA_TextLayout::GetXMLContainerNode() { +CFX_XMLNode* CXFA_TextLayout::GetXMLContainerNode() { if (!m_bRichText) return nullptr; - CFDE_XMLNode* pXMLRoot = m_pTextDataNode->GetXMLMappingNode(); + CFX_XMLNode* pXMLRoot = m_pTextDataNode->GetXMLMappingNode(); if (!pXMLRoot) return nullptr; - CFDE_XMLNode* pXMLContainer = nullptr; - for (CFDE_XMLNode* pXMLChild = - pXMLRoot->GetNodeItem(CFDE_XMLNode::FirstChild); + CFX_XMLNode* pXMLContainer = nullptr; + for (CFX_XMLNode* pXMLChild = pXMLRoot->GetNodeItem(CFX_XMLNode::FirstChild); pXMLChild; - pXMLChild = pXMLChild->GetNodeItem(CFDE_XMLNode::NextSibling)) { - if (pXMLChild->GetType() == FDE_XMLNODE_Element) { - CFDE_XMLElement* pXMLElement = static_cast(pXMLChild); + pXMLChild = pXMLChild->GetNodeItem(CFX_XMLNode::NextSibling)) { + if (pXMLChild->GetType() == FX_XMLNODE_Element) { + CFX_XMLElement* pXMLElement = static_cast(pXMLChild); CFX_WideString wsTag = pXMLElement->GetLocalTagName(); if (wsTag == L"body" || wsTag == L"html") { pXMLContainer = pXMLChild; @@ -159,7 +158,7 @@ void CXFA_TextLayout::InitBreak(float fLineWidth) { void CXFA_TextLayout::InitBreak(CFDE_CSSComputedStyle* pStyle, FDE_CSSDisplay eDisplay, float fLineWidth, - CFDE_XMLNode* pXMLNode, + CFX_XMLNode* pXMLNode, CFDE_CSSComputedStyle* pParentStyle) { if (!pStyle) { InitBreak(fLineWidth); @@ -460,24 +459,24 @@ bool CXFA_TextLayout::Layout(int32_t iBlock) { m_pBreak->Reset(); if (m_bRichText) { - CFDE_XMLNode* pContainerNode = GetXMLContainerNode(); + CFX_XMLNode* pContainerNode = GetXMLContainerNode(); if (!pContainerNode) return true; - CFDE_XMLNode* pXMLNode = m_pLoader->m_pXMLNode; + CFX_XMLNode* pXMLNode = m_pLoader->m_pXMLNode; if (!pXMLNode) return true; - CFDE_XMLNode* pSaveXMLNode = m_pLoader->m_pXMLNode; + CFX_XMLNode* pSaveXMLNode = m_pLoader->m_pXMLNode; for (; pXMLNode; - pXMLNode = pXMLNode->GetNodeItem(CFDE_XMLNode::NextSibling)) { + pXMLNode = pXMLNode->GetNodeItem(CFX_XMLNode::NextSibling)) { if (!LoadRichText(pXMLNode, szText, fLinePos, m_pLoader->m_pParentStyle, true, nullptr)) { break; } } while (!pXMLNode) { - pXMLNode = pSaveXMLNode->GetNodeItem(CFDE_XMLNode::Parent); + pXMLNode = pSaveXMLNode->GetNodeItem(CFX_XMLNode::Parent); if (pXMLNode == pContainerNode) break; if (!LoadRichText(pXMLNode, szText, fLinePos, m_pLoader->m_pParentStyle, @@ -485,11 +484,11 @@ bool CXFA_TextLayout::Layout(int32_t iBlock) { break; } pSaveXMLNode = pXMLNode; - pXMLNode = pXMLNode->GetNodeItem(CFDE_XMLNode::NextSibling); + pXMLNode = pXMLNode->GetNodeItem(CFX_XMLNode::NextSibling); if (!pXMLNode) continue; for (; pXMLNode; - pXMLNode = pXMLNode->GetNodeItem(CFDE_XMLNode::NextSibling)) { + pXMLNode = pXMLNode->GetNodeItem(CFX_XMLNode::NextSibling)) { if (!LoadRichText(pXMLNode, szText, fLinePos, m_pLoader->m_pParentStyle, true, nullptr)) { break; @@ -645,7 +644,7 @@ bool CXFA_TextLayout::Loader(const CFX_SizeF& szText, return true; if (m_bRichText) { - CFDE_XMLNode* pXMLContainer = GetXMLContainerNode(); + CFX_XMLNode* pXMLContainer = GetXMLContainerNode(); if (pXMLContainer) { if (!m_textParser.IsParsed()) m_textParser.DoParse(pXMLContainer, m_pTextProvider); @@ -694,7 +693,7 @@ void CXFA_TextLayout::LoadText(CXFA_Node* pNode, } bool CXFA_TextLayout::LoadRichText( - CFDE_XMLNode* pXMLNode, + CFX_XMLNode* pXMLNode, const CFX_SizeF& szText, float& fLinePos, const CFX_RetainPtr& pParentStyle, @@ -716,16 +715,16 @@ bool CXFA_TextLayout::LoadRichText( if (bEndBreak) { bool bCurOl = false; bool bCurLi = false; - CFDE_XMLElement* pElement = nullptr; + CFX_XMLElement* pElement = nullptr; if (pContext) { if (m_bBlockContinue || (m_pLoader && pXMLNode == m_pLoader->m_pXMLNode)) { m_bBlockContinue = true; } - if (pXMLNode->GetType() == FDE_XMLNODE_Text) { + if (pXMLNode->GetType() == FX_XMLNODE_Text) { bContentNode = true; - } else if (pXMLNode->GetType() == FDE_XMLNODE_Element) { - pElement = static_cast(pXMLNode); + } else if (pXMLNode->GetType() == FX_XMLNODE_Element) { + pElement = static_cast(pXMLNode); wsName = pElement->GetLocalTagName(); } if (wsName == L"ol") { @@ -771,7 +770,7 @@ bool CXFA_TextLayout::LoadRichText( bContentNode ? pParentStyle.Get() : pStyle.Get()); CFX_WideString wsText; if (bContentNode && iTabCount == 0) { - wsText = static_cast(pXMLNode)->GetText(); + wsText = static_cast(pXMLNode)->GetText(); } else if (wsName == L"br") { wsText = L'\n'; } else if (wsName == L"li") { @@ -834,10 +833,10 @@ bool CXFA_TextLayout::LoadRichText( } } - for (CFDE_XMLNode* pChildNode = - pXMLNode->GetNodeItem(CFDE_XMLNode::FirstChild); + for (CFX_XMLNode* pChildNode = + pXMLNode->GetNodeItem(CFX_XMLNode::FirstChild); pChildNode; - pChildNode = pChildNode->GetNodeItem(CFDE_XMLNode::NextSibling)) { + pChildNode = pChildNode->GetNodeItem(CFX_XMLNode::NextSibling)) { if (bCurOl) iLiCount++; @@ -872,7 +871,7 @@ bool CXFA_TextLayout::LoadRichText( if (IsEnd(bSavePieces)) { if (m_pLoader && m_pLoader->m_iTotalLines > -1) { m_pLoader->m_pXMLNode = - pXMLNode->GetNodeItem(CFDE_XMLNode::NextSibling); + pXMLNode->GetNodeItem(CFX_XMLNode::NextSibling); m_pLoader->m_pParentStyle = pParentStyle; } return false; diff --git a/xfa/fxfa/app/cxfa_textlayout.h b/xfa/fxfa/app/cxfa_textlayout.h index 5bce1c9ab2..75c2d56324 100644 --- a/xfa/fxfa/app/cxfa_textlayout.h +++ b/xfa/fxfa/app/cxfa_textlayout.h @@ -21,7 +21,7 @@ class CFDE_Brush; class CFDE_CSSComputedStyle; class CFDE_Pen; class CFDE_RenderDevice; -class CFDE_XMLNode; +class CFX_XMLNode; class CFX_RTFBreak; class CXFA_LoaderContext; class CXFA_LinkUserData; @@ -64,13 +64,13 @@ class CXFA_TextLayout { private: void GetTextDataNode(); - CFDE_XMLNode* GetXMLContainerNode(); + CFX_XMLNode* GetXMLContainerNode(); std::unique_ptr CreateBreak(bool bDefault); void InitBreak(float fLineWidth); void InitBreak(CFDE_CSSComputedStyle* pStyle, FDE_CSSDisplay eDisplay, float fLineWidth, - CFDE_XMLNode* pXMLNode, + CFX_XMLNode* pXMLNode, CFDE_CSSComputedStyle* pParentStyle = nullptr); bool Loader(const CFX_SizeF& szText, float& fLinePos, @@ -79,7 +79,7 @@ class CXFA_TextLayout { const CFX_SizeF& szText, float& fLinePos, bool bSavePieces); - bool LoadRichText(CFDE_XMLNode* pXMLNode, + bool LoadRichText(CFX_XMLNode* pXMLNode, const CFX_SizeF& szText, float& fLinePos, const CFX_RetainPtr& pParentStyle, diff --git a/xfa/fxfa/app/cxfa_textparser.cpp b/xfa/fxfa/app/cxfa_textparser.cpp index 1243f5b7ea..33bd2b9deb 100644 --- a/xfa/fxfa/app/cxfa_textparser.cpp +++ b/xfa/fxfa/app/cxfa_textparser.cpp @@ -11,13 +11,13 @@ #include #include "core/fxcrt/fx_codepage.h" +#include "core/fxcrt/xml/cfx_xmlelement.h" +#include "core/fxcrt/xml/cfx_xmlnode.h" #include "third_party/base/ptr_util.h" #include "xfa/fde/css/cfde_csscomputedstyle.h" #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/font/cfgas_fontmgr.h" #include "xfa/fxfa/app/cxfa_csstagprovider.h" #include "xfa/fxfa/app/cxfa_textparsecontext.h" @@ -175,7 +175,7 @@ CFX_RetainPtr CXFA_TextParser::CreateStyle( } CFX_RetainPtr CXFA_TextParser::ComputeStyle( - CFDE_XMLNode* pXMLNode, + CFX_XMLNode* pXMLNode, CFDE_CSSComputedStyle* pParentStyle) { auto it = m_mapXMLNodeToParseContext.find(pXMLNode); if (it == m_mapXMLNodeToParseContext.end()) @@ -198,7 +198,7 @@ CFX_RetainPtr CXFA_TextParser::ComputeStyle( return pStyle; } -void CXFA_TextParser::DoParse(CFDE_XMLNode* pXMLContainer, +void CXFA_TextParser::DoParse(CFX_XMLNode* pXMLContainer, CXFA_TextProvider* pTextProvider) { if (!pXMLContainer || !pTextProvider || m_bParsed) return; @@ -209,7 +209,7 @@ void CXFA_TextParser::DoParse(CFDE_XMLNode* pXMLContainer, ParseRichText(pXMLContainer, pRootStyle.Get()); } -void CXFA_TextParser::ParseRichText(CFDE_XMLNode* pXMLNode, +void CXFA_TextParser::ParseRichText(CFX_XMLNode* pXMLNode, CFDE_CSSComputedStyle* pParentStyle) { if (!pXMLNode) return; @@ -240,10 +240,9 @@ void CXFA_TextParser::ParseRichText(CFDE_XMLNode* pXMLNode, m_mapXMLNodeToParseContext[pXMLNode] = std::move(pTextContext); } - for (CFDE_XMLNode* pXMLChild = - pXMLNode->GetNodeItem(CFDE_XMLNode::FirstChild); + for (CFX_XMLNode* pXMLChild = pXMLNode->GetNodeItem(CFX_XMLNode::FirstChild); pXMLChild; - pXMLChild = pXMLChild->GetNodeItem(CFDE_XMLNode::NextSibling)) { + pXMLChild = pXMLChild->GetNodeItem(CFX_XMLNode::NextSibling)) { ParseRichText(pXMLChild, pNewStyle.Get()); } } @@ -271,12 +270,12 @@ bool CXFA_TextParser::TagValidate(const CFX_WideString& wsName) const { } std::unique_ptr CXFA_TextParser::ParseTagInfo( - CFDE_XMLNode* pXMLNode) { + CFX_XMLNode* pXMLNode) { auto tagProvider = pdfium::MakeUnique(); CFX_WideString wsName; - if (pXMLNode->GetType() == FDE_XMLNODE_Element) { - CFDE_XMLElement* pXMLElement = static_cast(pXMLNode); + if (pXMLNode->GetType() == FX_XMLNODE_Element) { + CFX_XMLElement* pXMLElement = static_cast(pXMLNode); wsName = pXMLElement->GetLocalTagName(); tagProvider->SetTagName(wsName); tagProvider->m_bTagAvailable = TagValidate(wsName); @@ -284,7 +283,7 @@ std::unique_ptr CXFA_TextParser::ParseTagInfo( CFX_WideString wsValue = pXMLElement->GetString(L"style"); if (!wsValue.IsEmpty()) tagProvider->SetAttribute(L"style", wsValue); - } else if (pXMLNode->GetType() == FDE_XMLNODE_Text) { + } else if (pXMLNode->GetType() == FX_XMLNODE_Text) { tagProvider->m_bTagAvailable = true; tagProvider->m_bContent = true; } @@ -363,7 +362,7 @@ float CXFA_TextParser::GetFontSize(CXFA_TextProvider* pTextProvider, int32_t CXFA_TextParser::GetHorScale(CXFA_TextProvider* pTextProvider, CFDE_CSSComputedStyle* pStyle, - CFDE_XMLNode* pXMLNode) const { + CFX_XMLNode* pXMLNode) const { if (pStyle) { CFX_WideString wsValue; if (pStyle->GetCustomStyle(L"xfa-font-horizontal-scale", wsValue)) @@ -379,7 +378,7 @@ int32_t CXFA_TextParser::GetHorScale(CXFA_TextProvider* pTextProvider, return wsValue.GetInteger(); } } - pXMLNode = pXMLNode->GetNodeItem(CFDE_XMLNode::Parent); + pXMLNode = pXMLNode->GetNodeItem(CFX_XMLNode::Parent); } } @@ -490,15 +489,15 @@ float CXFA_TextParser::GetLineHeight(CXFA_TextProvider* pTextProvider, } bool CXFA_TextParser::GetEmbbedObj(CXFA_TextProvider* pTextProvider, - CFDE_XMLNode* pXMLNode, + CFX_XMLNode* pXMLNode, CFX_WideString& wsValue) { wsValue.clear(); if (!pXMLNode) return false; bool bRet = false; - if (pXMLNode->GetType() == FDE_XMLNODE_Element) { - CFDE_XMLElement* pElement = static_cast(pXMLNode); + if (pXMLNode->GetType() == FX_XMLNODE_Element) { + CFX_XMLElement* pElement = static_cast(pXMLNode); CFX_WideString wsAttr = pElement->GetString(L"xfa:embed"); if (wsAttr.IsEmpty()) return false; @@ -531,7 +530,7 @@ bool CXFA_TextParser::GetEmbbedObj(CXFA_TextProvider* pTextProvider, } CXFA_TextParseContext* CXFA_TextParser::GetParseContextFromMap( - CFDE_XMLNode* pXMLNode) { + CFX_XMLNode* pXMLNode) { auto it = m_mapXMLNodeToParseContext.find(pXMLNode); return it != m_mapXMLNodeToParseContext.end() ? it->second.get() : nullptr; } diff --git a/xfa/fxfa/app/cxfa_textparser.h b/xfa/fxfa/app/cxfa_textparser.h index 29f03a8dea..04bd51fafe 100644 --- a/xfa/fxfa/app/cxfa_textparser.h +++ b/xfa/fxfa/app/cxfa_textparser.h @@ -19,7 +19,7 @@ class CFDE_CSSComputedStyle; class CFDE_CSSStyleSelector; class CFDE_CSSStyleSheet; -class CFDE_XMLNode; +class CFX_XMLNode; class CXFA_CSSTagProvider; class CXFA_TextParseContext; class CXFA_TextProvider; @@ -31,12 +31,12 @@ class CXFA_TextParser { virtual ~CXFA_TextParser(); void Reset(); - void DoParse(CFDE_XMLNode* pXMLContainer, CXFA_TextProvider* pTextProvider); + void DoParse(CFX_XMLNode* pXMLContainer, CXFA_TextProvider* pTextProvider); CFX_RetainPtr CreateRootStyle( CXFA_TextProvider* pTextProvider); CFX_RetainPtr ComputeStyle( - CFDE_XMLNode* pXMLNode, + CFX_XMLNode* pXMLNode, CFDE_CSSComputedStyle* pParentStyle); bool IsParsed() const { return m_bParsed; } @@ -57,7 +57,7 @@ class CXFA_TextParser { int32_t GetHorScale(CXFA_TextProvider* pTextProvider, CFDE_CSSComputedStyle* pStyle, - CFDE_XMLNode* pXMLNode) const; + CFX_XMLNode* pXMLNode) const; int32_t GetVerScale(CXFA_TextProvider* pTextProvider, CFDE_CSSComputedStyle* pStyle) const; @@ -78,18 +78,18 @@ class CXFA_TextParser { float fVerScale) const; bool GetEmbbedObj(CXFA_TextProvider* pTextProvider, - CFDE_XMLNode* pXMLNode, + CFX_XMLNode* pXMLNode, CFX_WideString& wsValue); - CXFA_TextParseContext* GetParseContextFromMap(CFDE_XMLNode* pXMLNode); + CXFA_TextParseContext* GetParseContextFromMap(CFX_XMLNode* pXMLNode); protected: bool TagValidate(const CFX_WideString& str) const; private: void InitCSSData(CXFA_TextProvider* pTextProvider); - void ParseRichText(CFDE_XMLNode* pXMLNode, + void ParseRichText(CFX_XMLNode* pXMLNode, CFDE_CSSComputedStyle* pParentStyle); - std::unique_ptr ParseTagInfo(CFDE_XMLNode* pXMLNode); + std::unique_ptr ParseTagInfo(CFX_XMLNode* pXMLNode); std::unique_ptr LoadDefaultSheetStyle(); CFX_RetainPtr CreateStyle( CFDE_CSSComputedStyle* pParentStyle); @@ -97,7 +97,7 @@ class CXFA_TextParser { bool m_bParsed; bool m_cssInitialized; std::unique_ptr m_pSelector; - std::map> + std::map> m_mapXMLNodeToParseContext; }; diff --git a/xfa/fxfa/app/xfa_ffwidgetacc.cpp b/xfa/fxfa/app/xfa_ffwidgetacc.cpp index 760def2759..7f53027e5c 100644 --- a/xfa/fxfa/app/xfa_ffwidgetacc.cpp +++ b/xfa/fxfa/app/xfa_ffwidgetacc.cpp @@ -10,12 +10,12 @@ #include #include +#include "core/fxcrt/xml/cfx_xmlelement.h" +#include "core/fxcrt/xml/cfx_xmlnode.h" #include "fxjs/cfxjse_value.h" #include "third_party/base/ptr_util.h" #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/xfa_ffcheckbutton.h" #include "xfa/fxfa/app/xfa_ffchoicelist.h" #include "xfa/fxfa/app/xfa_fffield.h" @@ -63,14 +63,14 @@ CXFA_Node* CXFA_TextProvider::GetTextNode(bool& bRichText) { return pChildNode; } else if (m_eType == XFA_TEXTPROVIDERTYPE_Datasets) { CXFA_Node* pBind = m_pWidgetAcc->GetDatasets(); - CFDE_XMLNode* pXMLNode = pBind->GetXMLMappingNode(); + CFX_XMLNode* pXMLNode = pBind->GetXMLMappingNode(); ASSERT(pXMLNode); - for (CFDE_XMLNode* pXMLChild = - pXMLNode->GetNodeItem(CFDE_XMLNode::FirstChild); + for (CFX_XMLNode* pXMLChild = + pXMLNode->GetNodeItem(CFX_XMLNode::FirstChild); pXMLChild; - pXMLChild = pXMLChild->GetNodeItem(CFDE_XMLNode::NextSibling)) { - if (pXMLChild->GetType() == FDE_XMLNODE_Element) { - CFDE_XMLElement* pElement = static_cast(pXMLChild); + pXMLChild = pXMLChild->GetNodeItem(CFX_XMLNode::NextSibling)) { + if (pXMLChild->GetType() == FX_XMLNODE_Element) { + CFX_XMLElement* pElement = static_cast(pXMLChild); if (XFA_RecognizeRichText(pElement)) { bRichText = true; } -- cgit v1.2.3