From 303e525325904cd9b6a847f48951510e7dd8a45e Mon Sep 17 00:00:00 2001 From: dsinclair Date: Wed, 27 Apr 2016 12:47:01 -0700 Subject: More IFX_ interface cleanup. Remove IFX_FontProvider, IFX_FontSourceEnum, IFX_SAXReader and IFX_SAXReaderHandler. Review-Url: https://codereview.chromium.org/1930533002 --- BUILD.gn | 3 +- core/fxcrt/include/fx_stream.h | 2 +- xfa.gyp | 3 +- xfa/fgas/font/fgas_font.h | 23 +- xfa/fgas/font/fgas_gefont.cpp | 1 + xfa/fgas/font/fgas_gefont.h | 6 +- xfa/fgas/font/fgas_stdfontmgr.cpp | 20 +- xfa/fgas/font/fgas_stdfontmgr.h | 16 +- xfa/fgas/xml/fgas_sax.cpp | 688 ++++++++++++++++++++++++++++++++++++++ xfa/fgas/xml/fgas_sax.h | 159 +++++++-- xfa/fgas/xml/fgas_sax_imp.cpp | 688 -------------------------------------- xfa/fgas/xml/fgas_sax_imp.h | 141 -------- xfa/fwl/theme/cfwl_widgettp.cpp | 3 +- xfa/fwl/theme/cfwl_widgettp.h | 4 +- xfa/fxfa/app/xfa_checksum.cpp | 21 +- xfa/fxfa/app/xfa_ffapp.cpp | 3 +- xfa/fxfa/app/xfa_fontmgr.cpp | 8 +- xfa/fxfa/include/xfa_checksum.h | 50 +-- xfa/fxfa/include/xfa_ffapp.h | 2 +- xfa/fxfa/include/xfa_fontmgr.h | 3 +- 20 files changed, 899 insertions(+), 945 deletions(-) create mode 100644 xfa/fgas/xml/fgas_sax.cpp delete mode 100644 xfa/fgas/xml/fgas_sax_imp.cpp delete mode 100644 xfa/fgas/xml/fgas_sax_imp.h diff --git a/BUILD.gn b/BUILD.gn index 747c6305bd..b4a6771344 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -969,9 +969,8 @@ if (pdf_enable_xfa) { "xfa/fgas/localization/fgas_localeimp.h", "xfa/fgas/localization/fgas_localemgr.cpp", "xfa/fgas/localization/fgas_localemgr.h", + "xfa/fgas/xml/fgas_sax.cpp", "xfa/fgas/xml/fgas_sax.h", - "xfa/fgas/xml/fgas_sax_imp.cpp", - "xfa/fgas/xml/fgas_sax_imp.h", "xfa/fwl/basewidget/fwl_barcodeimp.cpp", "xfa/fwl/basewidget/fwl_barcodeimp.h", "xfa/fwl/basewidget/fwl_caretimp.cpp", diff --git a/core/fxcrt/include/fx_stream.h b/core/fxcrt/include/fx_stream.h index ba72994f36..a91b59f285 100644 --- a/core/fxcrt/include/fx_stream.h +++ b/core/fxcrt/include/fx_stream.h @@ -79,7 +79,7 @@ class IFX_StreamRead { virtual size_t ReadBlock(void* buffer, size_t size) = 0; }; -class IFX_FileRead : IFX_StreamRead { +class IFX_FileRead : public IFX_StreamRead { public: // IFX_StreamRead: void Release() override = 0; diff --git a/xfa.gyp b/xfa.gyp index f3781a044a..72d2c8f5b4 100644 --- a/xfa.gyp +++ b/xfa.gyp @@ -126,9 +126,8 @@ "xfa/fgas/localization/fgas_localeimp.h", "xfa/fgas/localization/fgas_localemgr.cpp", "xfa/fgas/localization/fgas_localemgr.h", + "xfa/fgas/xml/fgas_sax.cpp", "xfa/fgas/xml/fgas_sax.h", - "xfa/fgas/xml/fgas_sax_imp.cpp", - "xfa/fgas/xml/fgas_sax_imp.h", "xfa/fwl/basewidget/fwl_barcodeimp.cpp", "xfa/fwl/basewidget/fwl_barcodeimp.h", "xfa/fwl/basewidget/fwl_caretimp.cpp", diff --git a/xfa/fgas/font/fgas_font.h b/xfa/fgas/font/fgas_font.h index db964b06ca..406c6f96a8 100644 --- a/xfa/fgas/font/fgas_font.h +++ b/xfa/fgas/font/fgas_font.h @@ -15,6 +15,8 @@ #include "xfa/fgas/crt/fgas_utils.h" #endif // _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ +class CFX_FontSourceEnum_File; +class CXFA_PDFFontMgr; class IFX_Font; class IFX_FontMgr; @@ -48,15 +50,6 @@ class IFX_FontMgr; #define FX_BOUNDINGSHAPE_Triangle 3 #define FX_BOUNDINGSHAPE_Diamond 4 -class IFX_FontProvider { - public: - virtual ~IFX_FontProvider() {} - virtual FX_BOOL GetCharWidth(IFX_Font* pFont, - FX_WCHAR wUnicode, - int32_t& iWidth, - FX_BOOL bCharCode = FALSE) = 0; -}; - class IFX_Font { public: static IFX_Font* LoadFont(const FX_WCHAR* pszFontFamily, @@ -96,7 +89,7 @@ class IFX_Font { virtual void Reset() = 0; virtual IFX_Font* GetSubstFont(int32_t iGlyphIndex) const = 0; virtual void* GetDevFont() const = 0; - virtual void SetFontProvider(IFX_FontProvider* pProvider) = 0; + virtual void SetFontProvider(CXFA_PDFFontMgr* pProvider) = 0; #if _FXM_PLATFORM_ != _FXM_PLATFORM_WINDOWS_ virtual void SetLogicalFontStyle(uint32_t dwLogFontStyle) = 0; #endif @@ -192,17 +185,9 @@ class IFX_FontMgr { #else // _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ -class IFX_FontSourceEnum { - public: - virtual ~IFX_FontSourceEnum() {} - virtual void Release() = 0; - virtual FX_POSITION GetStartPosition() = 0; - virtual IFX_FileAccess* GetNext(FX_POSITION& pos) = 0; -}; -IFX_FontSourceEnum* FX_CreateDefaultFontSourceEnum(); class IFX_FontMgr { public: - static IFX_FontMgr* Create(IFX_FontSourceEnum* pFontEnum); + static IFX_FontMgr* Create(CFX_FontSourceEnum_File* pFontEnum); virtual ~IFX_FontMgr() {} virtual void Release() = 0; virtual IFX_Font* GetDefFontByCodePage( diff --git a/xfa/fgas/font/fgas_gefont.cpp b/xfa/fgas/font/fgas_gefont.cpp index 7bf877f8c2..495ac7d69d 100644 --- a/xfa/fgas/font/fgas_gefont.cpp +++ b/xfa/fgas/font/fgas_gefont.cpp @@ -8,6 +8,7 @@ #include "xfa/fgas/crt/fgas_codepage.h" #include "xfa/fgas/font/fgas_fontutils.h" +#include "xfa/fxfa/include/xfa_fontmgr.h" IFX_Font* IFX_Font::LoadFont(const FX_WCHAR* pszFontFamily, uint32_t dwFontStyles, diff --git a/xfa/fgas/font/fgas_gefont.h b/xfa/fgas/font/fgas_gefont.h index 044acdeb7f..43b5c5876e 100644 --- a/xfa/fgas/font/fgas_gefont.h +++ b/xfa/fgas/font/fgas_gefont.h @@ -12,6 +12,8 @@ #define FXFONT_SUBST_ITALIC 0x02 +class CXFA_PDFFontMgr; + class CFX_GEFont : public IFX_Font { public: CFX_GEFont(const CFX_GEFont& src, uint32_t dwFontStyles); @@ -45,7 +47,7 @@ class CFX_GEFont : public IFX_Font { virtual void Reset(); virtual IFX_Font* GetSubstFont(int32_t iGlyphIndex) const; virtual void* GetDevFont() const { return (void*)m_pFont; } - virtual void SetFontProvider(IFX_FontProvider* pProvider) { + virtual void SetFontProvider(CXFA_PDFFontMgr* pProvider) { m_pProvider = pProvider; } #if _FXM_PLATFORM_ != _FXM_PLATFORM_WINDOWS_ @@ -70,7 +72,7 @@ class CFX_GEFont : public IFX_Font { CFX_WordDiscreteArray* m_pCharWidthMap; CFX_RectMassArray* m_pRectArray; CFX_MapPtrToPtr* m_pBBoxMap; - IFX_FontProvider* m_pProvider; + CXFA_PDFFontMgr* m_pProvider; uint16_t m_wCharSet; CFX_PtrArray m_SubstFonts; CFX_MapPtrToPtr m_FontMapper; diff --git a/xfa/fgas/font/fgas_stdfontmgr.cpp b/xfa/fgas/font/fgas_stdfontmgr.cpp index dedc8b0ad2..a3964d2bb8 100644 --- a/xfa/fgas/font/fgas_stdfontmgr.cpp +++ b/xfa/fgas/font/fgas_stdfontmgr.cpp @@ -555,21 +555,19 @@ IFX_FileAccess* CFX_FontSourceEnum_File::GetNext(FX_POSITION& pos) { pos = 0 != m_wsNext.GetLength() ? pAccess : NULL; return (IFX_FileAccess*)pAccess; } -IFX_FontSourceEnum* FX_CreateDefaultFontSourceEnum() { - return (IFX_FontSourceEnum*)new CFX_FontSourceEnum_File; -} -IFX_FontMgr* IFX_FontMgr::Create(IFX_FontSourceEnum* pFontEnum) { - if (NULL == pFontEnum) { - return NULL; - } + +IFX_FontMgr* IFX_FontMgr::Create(CFX_FontSourceEnum_File* pFontEnum) { + if (!pFontEnum) + return nullptr; + CFX_FontMgrImp* pFontMgr = new CFX_FontMgrImp(pFontEnum); - if (pFontMgr->EnumFonts()) { + if (pFontMgr->EnumFonts()) return pFontMgr; - } + delete pFontMgr; - return NULL; + return nullptr; } -CFX_FontMgrImp::CFX_FontMgrImp(IFX_FontSourceEnum* pFontEnum) +CFX_FontMgrImp::CFX_FontMgrImp(CFX_FontSourceEnum_File* pFontEnum) : m_pFontSource(pFontEnum) {} FX_BOOL CFX_FontMgrImp::EnumFontsFromFontMapper() { diff --git a/xfa/fgas/font/fgas_stdfontmgr.h b/xfa/fgas/font/fgas_stdfontmgr.h index 6b1f9c8a8f..cc11517e34 100644 --- a/xfa/fgas/font/fgas_stdfontmgr.h +++ b/xfa/fgas/font/fgas_stdfontmgr.h @@ -126,19 +126,22 @@ struct FX_HandleParentPath { CFX_ByteString bsParentPath; }; -class CFX_FontSourceEnum_File : public IFX_FontSourceEnum { +class CFX_FontSourceEnum_File { public: CFX_FontSourceEnum_File(); - virtual void Release() { delete this; } - virtual FX_POSITION GetStartPosition(); - virtual IFX_FileAccess* GetNext(FX_POSITION& pos); + + void Release() { delete this; } + FX_POSITION GetStartPosition(); + IFX_FileAccess* GetNext(FX_POSITION& pos); private: CFX_ByteString GetNextFile(); + CFX_WideString m_wsNext; CFX_ObjectArray m_FolderQueue; CFX_ByteStringArray m_FolderPaths; }; + typedef CFX_MapPtrTemplate CFX_HashFileMap; typedef CFX_MapPtrTemplate CFX_HashFontMap; typedef CFX_MapPtrTemplate @@ -152,7 +155,8 @@ typedef CFX_MapPtrTemplate CFX_FonStreamtMap; class CFX_FontMgrImp : public IFX_FontMgr { public: - CFX_FontMgrImp(IFX_FontSourceEnum* pFontEnum); + CFX_FontMgrImp(CFX_FontSourceEnum_File* pFontEnum); + virtual void Release(); virtual IFX_Font* GetDefFontByCodePage(uint16_t wCodePage, uint32_t dwFontStyles, @@ -239,7 +243,7 @@ class CFX_FontMgrImp : public IFX_FontMgr { CFX_HashFontMap m_FileAccess2IFXFont; CFX_FonStreamtMap m_IFXFont2FileRead; CFX_UnicodeFontMap m_FailedUnicodes2NULL; - IFX_FontSourceEnum* m_pFontSource; + CFX_FontSourceEnum_File* m_pFontSource; }; #endif diff --git a/xfa/fgas/xml/fgas_sax.cpp b/xfa/fgas/xml/fgas_sax.cpp new file mode 100644 index 0000000000..b97aeb0a7c --- /dev/null +++ b/xfa/fgas/xml/fgas_sax.cpp @@ -0,0 +1,688 @@ +// 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/fgas/xml/fgas_sax.h" + +#include + +#include "xfa/fxfa/include/xfa_checksum.h" + +namespace { + +const uint32_t kSaxFileBufSize = 32768; + +} // namespace + +CFX_SAXFile::CFX_SAXFile() + : m_pFile(NULL), + m_dwStart(0), + m_dwEnd(0), + m_dwCur(0), + m_pBuf(NULL), + m_dwBufSize(0), + m_dwBufIndex(0) {} +FX_BOOL CFX_SAXFile::StartFile(IFX_FileRead* pFile, + uint32_t dwStart, + uint32_t dwLen) { + ASSERT(m_pFile == NULL && pFile != NULL); + uint32_t dwSize = pFile->GetSize(); + if (dwStart >= dwSize) { + return FALSE; + } + if (dwLen == -1 || dwStart + dwLen > dwSize) { + dwLen = dwSize - dwStart; + } + if (dwLen == 0) { + return FALSE; + } + m_dwBufSize = std::min(dwLen, kSaxFileBufSize); + m_pBuf = FX_Alloc(uint8_t, m_dwBufSize); + if (!pFile->ReadBlock(m_pBuf, dwStart, m_dwBufSize)) { + return FALSE; + } + m_dwStart = dwStart; + m_dwEnd = dwStart + dwLen; + m_dwCur = dwStart; + m_pFile = pFile; + m_dwBufIndex = 0; + return TRUE; +} +FX_BOOL CFX_SAXFile::ReadNextBlock() { + ASSERT(m_pFile != NULL); + uint32_t dwSize = m_dwEnd - m_dwCur; + if (dwSize == 0) { + return FALSE; + } + m_dwBufSize = std::min(dwSize, kSaxFileBufSize); + if (!m_pFile->ReadBlock(m_pBuf, m_dwCur, m_dwBufSize)) { + return FALSE; + } + m_dwBufIndex = 0; + return TRUE; +} +void CFX_SAXFile::Reset() { + if (m_pBuf) { + FX_Free(m_pBuf); + m_pBuf = NULL; + } + m_pFile = NULL; +} +CFX_SAXReader::CFX_SAXReader() + : m_File(), + m_pHandler(nullptr), + m_iState(-1), + m_pRoot(nullptr), + m_pCurItem(nullptr), + m_dwItemID(0), + m_iDataSize(256), + m_iNameSize(256), + m_dwParseMode(0), + m_pCommentContext(nullptr) { + m_pszData = FX_Alloc(uint8_t, m_iDataSize); + m_pszName = FX_Alloc(uint8_t, m_iNameSize); +} +CFX_SAXReader::~CFX_SAXReader() { + Reset(); + if (m_pszData) { + FX_Free(m_pszData); + m_pszData = NULL; + } + if (m_pszName) { + FX_Free(m_pszName); + m_pszName = NULL; + } +} +void CFX_SAXReader::Reset() { + m_File.Reset(); + CFX_SAXItem* pItem = m_pRoot; + while (pItem) { + CFX_SAXItem* pNext = pItem->m_pNext; + delete pItem; + pItem = pNext; + } + m_pRoot = NULL; + m_pCurItem = NULL; + m_dwItemID = 0; + m_SkipStack.RemoveAll(); + m_SkipChar = 0; + m_iDataLength = 0; + m_iEntityStart = -1; + m_iNameLength = 0; + m_iDataPos = 0; + if (m_pCommentContext) { + delete m_pCommentContext; + m_pCommentContext = NULL; + } +} +inline void CFX_SAXReader::Push() { + CFX_SAXItem* pNew = new CFX_SAXItem; + pNew->m_dwID = ++m_dwItemID; + pNew->m_bSkip = m_pCurItem->m_bSkip; + pNew->m_pPrev = m_pCurItem; + m_pCurItem->m_pNext = pNew; + m_pCurItem = pNew; +} +inline void CFX_SAXReader::Pop() { + if (!m_pCurItem) { + return; + } + CFX_SAXItem* pPrev = m_pCurItem->m_pPrev; + pPrev->m_pNext = NULL; + delete m_pCurItem; + m_pCurItem = pPrev; +} +inline void CFX_SAXReader::AppendData(uint8_t ch) { + ReallocDataBuffer(); + m_pszData[m_iDataPos++] = ch; +} +inline void CFX_SAXReader::AppendName(uint8_t ch) { + ReallocNameBuffer(); + m_pszName[m_iDataPos++] = ch; +} +void CFX_SAXReader::ReallocDataBuffer() { + if (m_iDataPos < m_iDataSize) { + return; + } + if (m_iDataSize <= 1024 * 1024) { + m_iDataSize *= 2; + } else { + m_iDataSize += 1024 * 1024; + } + m_pszData = (uint8_t*)FX_Realloc(uint8_t, m_pszData, m_iDataSize); +} +void CFX_SAXReader::ReallocNameBuffer() { + if (m_iDataPos < m_iNameSize) { + return; + } + if (m_iNameSize <= 1024 * 1024) { + m_iNameSize *= 2; + } else { + m_iNameSize += 1024 * 1024; + } + m_pszName = (uint8_t*)FX_Realloc(uint8_t, m_pszName, m_iNameSize); +} +inline FX_BOOL CFX_SAXReader::SkipSpace(uint8_t ch) { + return (m_dwParseMode & FX_SAXPARSEMODE_NotSkipSpace) == 0 && ch < 0x21; +} +int32_t CFX_SAXReader::StartParse(IFX_FileRead* pFile, + uint32_t dwStart, + uint32_t dwLen, + uint32_t dwParseMode) { + m_iState = -1; + Reset(); + if (!m_File.StartFile(pFile, dwStart, dwLen)) { + return -1; + } + m_iState = 0; + m_eMode = FX_SAXMODE_Text; + m_ePrevMode = FX_SAXMODE_Text; + m_bCharData = FALSE; + m_dwDataOffset = 0; + m_pRoot = m_pCurItem = new CFX_SAXItem; + m_pCurItem->m_dwID = ++m_dwItemID; + m_dwParseMode = dwParseMode; + return 0; +} +typedef void (CFX_SAXReader::*FX_SAXReader_LPFParse)(); +static const FX_SAXReader_LPFParse g_FX_SAXReader_LPFParse[FX_SAXMODE_MAX] = { + &CFX_SAXReader::ParseText, + &CFX_SAXReader::ParseNodeStart, + &CFX_SAXReader::ParseDeclOrComment, + &CFX_SAXReader::ParseDeclNode, + &CFX_SAXReader::ParseComment, + &CFX_SAXReader::ParseCommentContent, + &CFX_SAXReader::ParseTagName, + &CFX_SAXReader::ParseTagAttributeName, + &CFX_SAXReader::ParseTagAttributeEqual, + &CFX_SAXReader::ParseTagAttributeValue, + &CFX_SAXReader::ParseMaybeClose, + &CFX_SAXReader::ParseTagClose, + &CFX_SAXReader::ParseTagEnd, + &CFX_SAXReader::ParseTargetData, +}; +int32_t CFX_SAXReader::ContinueParse(IFX_Pause* pPause) { + if (m_iState < 0 || m_iState > 99) { + return m_iState; + } + while (m_File.m_dwCur < m_File.m_dwEnd) { + uint32_t& index = m_File.m_dwBufIndex; + uint32_t size = m_File.m_dwBufSize; + const uint8_t* pBuf = m_File.m_pBuf; + while (index < size) { + m_CurByte = pBuf[index]; + (this->*g_FX_SAXReader_LPFParse[m_eMode])(); + index++; + } + m_File.m_dwCur += index; + m_iState = (m_File.m_dwCur - m_File.m_dwStart) * 100 / + (m_File.m_dwEnd - m_File.m_dwStart); + if (m_File.m_dwCur >= m_File.m_dwEnd) { + break; + } + if (!m_File.ReadNextBlock()) { + m_iState = -2; + break; + } + m_dwDataOffset = 0; + if (pPause && pPause->NeedToPauseNow()) { + break; + } + } + return m_iState; +} +void CFX_SAXReader::ParseChar(uint8_t ch) { + ReallocDataBuffer(); + m_pszData[m_iDataPos] = ch; + if (m_iEntityStart > -1 && ch == ';') { + int32_t iSaveEntityStart = m_iEntityStart; + CFX_ByteString csEntity(m_pszData + m_iEntityStart + 1, + m_iDataPos - m_iEntityStart - 1); + int32_t iLen = csEntity.GetLength(); + if (iLen > 0) { + if (csEntity[0] == '#') { + if ((m_dwParseMode & FX_SAXPARSEMODE_NotConvert_sharp) == 0) { + ch = 0; + uint8_t w; + if (iLen > 1 && csEntity[1] == 'x') { + for (int32_t i = 2; i < iLen; i++) { + w = csEntity[i]; + if (w >= '0' && w <= '9') { + ch = (ch << 4) + w - '0'; + } else if (w >= 'A' && w <= 'F') { + ch = (ch << 4) + w - 55; + } else if (w >= 'a' && w <= 'f') { + ch = (ch << 4) + w - 87; + } else { + break; + } + } + } else { + for (int32_t i = 1; i < iLen; i++) { + w = csEntity[i]; + if (w < '0' || w > '9') { + break; + } + ch = ch * 10 + w - '0'; + } + } + if (ch != 0) { + m_pszData[m_iEntityStart++] = ch; + } + } + } else { + if (csEntity.Compare("amp") == 0) { + if ((m_dwParseMode & FX_SAXPARSEMODE_NotConvert_amp) == 0) { + m_pszData[m_iEntityStart++] = '&'; + } + } else if (csEntity.Compare("lt") == 0) { + if ((m_dwParseMode & FX_SAXPARSEMODE_NotConvert_lt) == 0) { + m_pszData[m_iEntityStart++] = '<'; + } + } else if (csEntity.Compare("gt") == 0) { + if ((m_dwParseMode & FX_SAXPARSEMODE_NotConvert_gt) == 0) { + m_pszData[m_iEntityStart++] = '>'; + } + } else if (csEntity.Compare("apos") == 0) { + if ((m_dwParseMode & FX_SAXPARSEMODE_NotConvert_apos) == 0) { + m_pszData[m_iEntityStart++] = '\''; + } + } else if (csEntity.Compare("quot") == 0) { + if ((m_dwParseMode & FX_SAXPARSEMODE_NotConvert_quot) == 0) { + m_pszData[m_iEntityStart++] = '\"'; + } + } + } + } + if (iSaveEntityStart != m_iEntityStart) { + m_iDataPos = m_iEntityStart; + m_iEntityStart = -1; + } else { + m_iDataPos++; + m_iEntityStart = -1; + } + } else { + if (m_iEntityStart < 0 && ch == '&') { + m_iEntityStart = m_iDataPos; + } + m_iDataPos++; + } +} +void CFX_SAXReader::ParseText() { + if (m_CurByte == '<') { + if (m_iDataPos > 0) { + m_iDataLength = m_iDataPos; + m_iDataPos = 0; + if (m_pHandler) { + NotifyData(); + } + } + Push(); + m_dwNodePos = m_File.m_dwCur + m_File.m_dwBufIndex; + m_eMode = FX_SAXMODE_NodeStart; + return; + } + if (m_iDataPos < 1 && SkipSpace(m_CurByte)) { + return; + } + ParseChar(m_CurByte); +} +void CFX_SAXReader::ParseNodeStart() { + if (m_CurByte == '?') { + m_pCurItem->m_eNode = FX_SAXNODE_Instruction; + m_eMode = FX_SAXMODE_TagName; + return; + } + if (m_CurByte == '!') { + m_eMode = FX_SAXMODE_DeclOrComment; + return; + } + if (m_CurByte == '/') { + m_eMode = FX_SAXMODE_TagEnd; + return; + } + if (m_CurByte == '>') { + Pop(); + m_eMode = FX_SAXMODE_Text; + return; + } + if (m_CurByte > 0x20) { + m_dwDataOffset = m_File.m_dwBufIndex; + m_pCurItem->m_eNode = FX_SAXNODE_Tag; + m_eMode = FX_SAXMODE_TagName; + AppendData(m_CurByte); + } +} +void CFX_SAXReader::ParseDeclOrComment() { + if (m_CurByte == '-') { + m_eMode = FX_SAXMODE_Comment; + m_pCurItem->m_eNode = FX_SAXNODE_Comment; + if (m_pCommentContext == NULL) { + m_pCommentContext = new CFX_SAXCommentContext; + } + m_pCommentContext->m_iHeaderCount = 1; + m_pCommentContext->m_iTailCount = 0; + } else { + m_eMode = FX_SAXMODE_DeclNode; + m_dwDataOffset = m_File.m_dwBufIndex; + m_SkipChar = '>'; + m_SkipStack.Add('>'); + SkipNode(); + } +} +void CFX_SAXReader::ParseComment() { + m_pCommentContext->m_iHeaderCount = 2; + m_dwNodePos = m_File.m_dwCur + m_File.m_dwBufIndex; + m_eMode = FX_SAXMODE_CommentContent; +} +void CFX_SAXReader::ParseCommentContent() { + if (m_CurByte == '-') { + m_pCommentContext->m_iTailCount++; + } else if (m_CurByte == '>' && m_pCommentContext->m_iTailCount == 2) { + m_iDataLength = m_iDataPos; + m_iDataPos = 0; + if (m_pHandler) { + NotifyTargetData(); + } + Pop(); + m_eMode = FX_SAXMODE_Text; + } else { + while (m_pCommentContext->m_iTailCount > 0) { + AppendData('-'); + m_pCommentContext->m_iTailCount--; + } + AppendData(m_CurByte); + } +} +void CFX_SAXReader::ParseDeclNode() { + SkipNode(); +} +void CFX_SAXReader::ParseTagName() { + if (m_CurByte < 0x21 || m_CurByte == '/' || m_CurByte == '>' || + m_CurByte == '?') { + m_iDataLength = m_iDataPos; + m_iDataPos = 0; + if (m_pHandler) { + NotifyEnter(); + } + if (m_CurByte < 0x21) { + m_eMode = FX_SAXMODE_TagAttributeName; + } else if (m_CurByte == '/' || m_CurByte == '?') { + m_ePrevMode = m_eMode; + m_eMode = FX_SAXMODE_TagMaybeClose; + } else { + if (m_pHandler) { + NotifyBreak(); + } + m_eMode = FX_SAXMODE_Text; + } + } else { + AppendData(m_CurByte); + } +} +void CFX_SAXReader::ParseTagAttributeName() { + if (m_CurByte < 0x21 || m_CurByte == '=') { + if (m_iDataPos < 1 && m_CurByte < 0x21) { + return; + } + m_iNameLength = m_iDataPos; + m_iDataPos = 0; + m_SkipChar = 0; + m_eMode = m_CurByte == '=' ? FX_SAXMODE_TagAttributeValue + : FX_SAXMODE_TagAttributeEqual; + return; + } + if (m_CurByte == '/' || m_CurByte == '>' || m_CurByte == '?') { + if (m_CurByte == '/' || m_CurByte == '?') { + m_ePrevMode = m_eMode; + m_eMode = FX_SAXMODE_TagMaybeClose; + } else { + if (m_pHandler) { + NotifyBreak(); + } + m_eMode = FX_SAXMODE_Text; + } + return; + } + if (m_iDataPos < 1) { + m_dwDataOffset = m_File.m_dwBufIndex; + } + AppendName(m_CurByte); +} +void CFX_SAXReader::ParseTagAttributeEqual() { + if (m_CurByte == '=') { + m_SkipChar = 0; + m_eMode = FX_SAXMODE_TagAttributeValue; + return; + } else if (m_pCurItem->m_eNode == FX_SAXNODE_Instruction) { + m_iDataPos = m_iNameLength; + AppendName(0x20); + m_eMode = FX_SAXMODE_TargetData; + ParseTargetData(); + } +} +void CFX_SAXReader::ParseTagAttributeValue() { + if (m_SkipChar) { + if (m_SkipChar == m_CurByte) { + { + m_iDataLength = m_iDataPos; + m_iDataPos = 0; + if (m_pHandler) { + NotifyAttribute(); + } + } + m_SkipChar = 0; + m_eMode = FX_SAXMODE_TagAttributeName; + return; + } + ParseChar(m_CurByte); + return; + } + if (m_CurByte < 0x21) { + return; + } + if (m_iDataPos < 1) { + if (m_CurByte == '\'' || m_CurByte == '\"') { + m_SkipChar = m_CurByte; + } + } +} +void CFX_SAXReader::ParseMaybeClose() { + if (m_CurByte == '>') { + if (m_pCurItem->m_eNode == FX_SAXNODE_Instruction) { + m_iNameLength = m_iDataPos; + m_iDataPos = 0; + if (m_pHandler) { + NotifyTargetData(); + } + } + ParseTagClose(); + m_eMode = FX_SAXMODE_Text; + } else if (m_ePrevMode == FX_SAXMODE_TagName) { + AppendData('/'); + m_eMode = FX_SAXMODE_TagName; + m_ePrevMode = FX_SAXMODE_Text; + ParseTagName(); + } else if (m_ePrevMode == FX_SAXMODE_TagAttributeName) { + AppendName('/'); + m_eMode = FX_SAXMODE_TagAttributeName; + m_ePrevMode = FX_SAXMODE_Text; + ParseTagAttributeName(); + } else if (m_ePrevMode == FX_SAXMODE_TargetData) { + AppendName('?'); + m_eMode = FX_SAXMODE_TargetData; + m_ePrevMode = FX_SAXMODE_Text; + ParseTargetData(); + } +} +void CFX_SAXReader::ParseTagClose() { + m_dwNodePos = m_File.m_dwCur + m_File.m_dwBufIndex; + if (m_pHandler) { + NotifyClose(); + } + Pop(); +} +void CFX_SAXReader::ParseTagEnd() { + if (m_CurByte < 0x21) { + return; + } + if (m_CurByte == '>') { + Pop(); + m_dwNodePos = m_File.m_dwCur + m_File.m_dwBufIndex; + m_iDataLength = m_iDataPos; + m_iDataPos = 0; + if (m_pHandler) { + NotifyEnd(); + } + Pop(); + m_eMode = FX_SAXMODE_Text; + } else { + ParseChar(m_CurByte); + } +} +void CFX_SAXReader::ParseTargetData() { + if (m_CurByte == '?') { + m_ePrevMode = m_eMode; + m_eMode = FX_SAXMODE_TagMaybeClose; + } else { + AppendName(m_CurByte); + } +} +void CFX_SAXReader::SkipNode() { + int32_t iLen = m_SkipStack.GetSize(); + if (m_SkipChar == '\'' || m_SkipChar == '\"') { + if (m_CurByte != m_SkipChar) { + return; + } + iLen--; + ASSERT(iLen > -1); + m_SkipStack.RemoveAt(iLen, 1); + m_SkipChar = iLen ? m_SkipStack[iLen - 1] : 0; + return; + } + switch (m_CurByte) { + case '<': + m_SkipChar = '>'; + m_SkipStack.Add('>'); + break; + case '[': + m_SkipChar = ']'; + m_SkipStack.Add(']'); + break; + case '(': + m_SkipChar = ')'; + m_SkipStack.Add(')'); + break; + case '\'': + m_SkipChar = '\''; + m_SkipStack.Add('\''); + break; + case '\"': + m_SkipChar = '\"'; + m_SkipStack.Add('\"'); + break; + default: + if (m_CurByte == m_SkipChar) { + iLen--; + m_SkipStack.RemoveAt(iLen, 1); + m_SkipChar = iLen ? m_SkipStack[iLen - 1] : 0; + if (iLen == 0 && m_CurByte == '>') { + m_iDataLength = m_iDataPos; + m_iDataPos = 0; + if (m_iDataLength >= 9 && + FXSYS_memcmp(m_pszData, "[CDATA[", 7 * sizeof(uint8_t)) == 0 && + FXSYS_memcmp(m_pszData + m_iDataLength - 2, "]]", + 2 * sizeof(uint8_t)) == 0) { + Pop(); + m_iDataLength -= 9; + m_dwDataOffset += 7; + FXSYS_memmove(m_pszData, m_pszData + 7, + m_iDataLength * sizeof(uint8_t)); + m_bCharData = TRUE; + if (m_pHandler) { + NotifyData(); + } + m_bCharData = FALSE; + } else { + Pop(); + } + m_eMode = FX_SAXMODE_Text; + } + } + break; + } + if (iLen > 0) { + ParseChar(m_CurByte); + } +} + +void CFX_SAXReader::NotifyData() { + if (m_pCurItem->m_eNode == FX_SAXNODE_Tag) + m_pHandler->OnTagData(m_pCurItem->m_pNode, + m_bCharData ? FX_SAXNODE_CharData : FX_SAXNODE_Text, + CFX_ByteStringC(m_pszData, m_iDataLength), + m_File.m_dwCur + m_dwDataOffset); +} + +void CFX_SAXReader::NotifyEnter() { + if (m_pCurItem->m_eNode == FX_SAXNODE_Tag || + m_pCurItem->m_eNode == FX_SAXNODE_Instruction) { + m_pCurItem->m_pNode = + m_pHandler->OnTagEnter(CFX_ByteStringC(m_pszData, m_iDataLength), + m_pCurItem->m_eNode, m_dwNodePos); + } +} + +void CFX_SAXReader::NotifyAttribute() { + if (m_pCurItem->m_eNode == FX_SAXNODE_Tag || + m_pCurItem->m_eNode == FX_SAXNODE_Instruction) { + m_pHandler->OnTagAttribute(m_pCurItem->m_pNode, + CFX_ByteStringC(m_pszName, m_iNameLength), + CFX_ByteStringC(m_pszData, m_iDataLength)); + } +} + +void CFX_SAXReader::NotifyBreak() { + if (m_pCurItem->m_eNode == FX_SAXNODE_Tag) + m_pHandler->OnTagBreak(m_pCurItem->m_pNode); +} + +void CFX_SAXReader::NotifyClose() { + if (m_pCurItem->m_eNode == FX_SAXNODE_Tag || + m_pCurItem->m_eNode == FX_SAXNODE_Instruction) { + m_pHandler->OnTagClose(m_pCurItem->m_pNode, m_dwNodePos); + } +} + +void CFX_SAXReader::NotifyEnd() { + if (m_pCurItem->m_eNode != FX_SAXNODE_Tag) + return; + + m_pHandler->OnTagEnd(m_pCurItem->m_pNode, + CFX_ByteStringC(m_pszData, m_iDataLength), m_dwNodePos); +} + +void CFX_SAXReader::NotifyTargetData() { + if (m_pCurItem->m_eNode == FX_SAXNODE_Instruction) { + m_pHandler->OnTargetData(m_pCurItem->m_pNode, m_pCurItem->m_eNode, + CFX_ByteStringC(m_pszName, m_iNameLength), + m_dwNodePos); + } else if (m_pCurItem->m_eNode == FX_SAXNODE_Comment) { + m_pHandler->OnTargetData(m_pCurItem->m_pNode, m_pCurItem->m_eNode, + CFX_ByteStringC(m_pszData, m_iDataLength), + m_dwNodePos); + } +} + +void CFX_SAXReader::SkipCurrentNode() { + if (!m_pCurItem) + return; + + m_pCurItem->m_bSkip = TRUE; +} + +void CFX_SAXReader::SetHandler(CXFA_SAXReaderHandler* pHandler) { + m_pHandler = pHandler; +} diff --git a/xfa/fgas/xml/fgas_sax.h b/xfa/fgas/xml/fgas_sax.h index 501c358e0f..57ff6b2470 100644 --- a/xfa/fgas/xml/fgas_sax.h +++ b/xfa/fgas/xml/fgas_sax.h @@ -27,42 +27,137 @@ enum FX_SAXNODE { FX_SAXNODE_CharData, }; -class IFX_SAXReaderHandler { +enum FX_SAXMODE { + FX_SAXMODE_Text = 0, + FX_SAXMODE_NodeStart, + FX_SAXMODE_DeclOrComment, + FX_SAXMODE_DeclNode, + FX_SAXMODE_Comment, + FX_SAXMODE_CommentContent, + FX_SAXMODE_TagName, + FX_SAXMODE_TagAttributeName, + FX_SAXMODE_TagAttributeEqual, + FX_SAXMODE_TagAttributeValue, + FX_SAXMODE_TagMaybeClose, + FX_SAXMODE_TagClose, + FX_SAXMODE_TagEnd, + FX_SAXMODE_TargetData, + FX_SAXMODE_MAX, +}; + +class CXFA_SAXReaderHandler; + +class CFX_SAXFile { + public: + CFX_SAXFile(); + FX_BOOL StartFile(IFX_FileRead* pFile, uint32_t dwStart, uint32_t dwLen); + FX_BOOL ReadNextBlock(); + void Reset(); + IFX_FileRead* m_pFile; + uint32_t m_dwStart; + uint32_t m_dwEnd; + uint32_t m_dwCur; + uint8_t* m_pBuf; + uint32_t m_dwBufSize; + uint32_t m_dwBufIndex; +}; + +class CFX_SAXItem { public: - virtual ~IFX_SAXReaderHandler() {} - virtual void* OnTagEnter(const CFX_ByteStringC& bsTagName, - FX_SAXNODE eType, - uint32_t dwStartPos) = 0; - virtual void OnTagAttribute(void* pTag, - const CFX_ByteStringC& bsAttri, - const CFX_ByteStringC& bsValue) = 0; - virtual void OnTagBreak(void* pTag) = 0; - virtual void OnTagData(void* pTag, - FX_SAXNODE eType, - const CFX_ByteStringC& bsData, - uint32_t dwStartPos) = 0; - virtual void OnTagClose(void* pTag, uint32_t dwEndPos) = 0; - virtual void OnTagEnd(void* pTag, - const CFX_ByteStringC& bsTagName, - uint32_t dwEndPos) = 0; - virtual void OnTargetData(void* pTag, - FX_SAXNODE eType, - const CFX_ByteStringC& bsData, - uint32_t dwStartPos) = 0; + CFX_SAXItem() + : m_pNode(NULL), + m_eNode(FX_SAXNODE_Unknown), + m_dwID(0), + m_bSkip(FALSE), + m_pPrev(NULL), + m_pNext(NULL) {} + void* m_pNode; + FX_SAXNODE m_eNode; + uint32_t m_dwID; + FX_BOOL m_bSkip; + CFX_SAXItem* m_pPrev; + CFX_SAXItem* m_pNext; }; -class IFX_SAXReader { +class CFX_SAXCommentContext { public: - virtual ~IFX_SAXReader() {} - virtual void Release() = 0; - virtual int32_t StartParse(IFX_FileRead* pFile, - uint32_t dwStart = 0, - uint32_t dwLen = -1, - uint32_t dwParseMode = 0) = 0; - virtual int32_t ContinueParse(IFX_Pause* pPause = NULL) = 0; - virtual void SkipCurrentNode() = 0; - virtual void SetHandler(IFX_SAXReaderHandler* pHandler) = 0; + CFX_SAXCommentContext() : m_iHeaderCount(0), m_iTailCount(0) {} + int32_t m_iHeaderCount; + int32_t m_iTailCount; +}; + +class CFX_SAXReader { + public: + CFX_SAXReader(); + ~CFX_SAXReader(); + + void Release() { delete this; } + int32_t StartParse(IFX_FileRead* pFile, + uint32_t dwStart = 0, + uint32_t dwLen = -1, + uint32_t dwParseMode = 0); + int32_t ContinueParse(IFX_Pause* pPause = NULL); + void SkipCurrentNode(); + void SetHandler(CXFA_SAXReaderHandler* pHandler); + void AppendData(uint8_t ch); + void AppendName(uint8_t ch); + void ParseText(); + void ParseNodeStart(); + void ParseInstruction(); + void ParseDeclOrComment(); + void ParseDeclNode(); + void ParseComment(); + void ParseCommentContent(); + void ParseTagName(); + void ParseTagAttributeName(); + void ParseTagAttributeEqual(); + void ParseTagAttributeValue(); + void ParseMaybeClose(); + void ParseTagClose(); + void ParseTagEnd(); + void ParseTargetData(); + + protected: + void Reset(); + void Push(); + void Pop(); + FX_BOOL SkipSpace(uint8_t ch); + void SkipNode(); + void NotifyData(); + void NotifyEnter(); + void NotifyAttribute(); + void NotifyBreak(); + void NotifyClose(); + void NotifyEnd(); + void NotifyTargetData(); + void ReallocDataBuffer(); + void ReallocNameBuffer(); + void ParseChar(uint8_t ch); + + CFX_SAXFile m_File; + CXFA_SAXReaderHandler* m_pHandler; + int32_t m_iState; + CFX_SAXItem* m_pRoot; + CFX_SAXItem* m_pCurItem; + uint32_t m_dwItemID; + FX_SAXMODE m_eMode; + FX_SAXMODE m_ePrevMode; + FX_BOOL m_bCharData; + uint8_t m_CurByte; + uint32_t m_dwDataOffset; + CFX_ByteArray m_SkipStack; + uint8_t m_SkipChar; + uint32_t m_dwNodePos; + uint8_t* m_pszData; + int32_t m_iDataSize; + int32_t m_iDataLength; + int32_t m_iEntityStart; + int32_t m_iDataPos; + uint8_t* m_pszName; + int32_t m_iNameSize; + int32_t m_iNameLength; + uint32_t m_dwParseMode; + CFX_SAXCommentContext* m_pCommentContext; }; -IFX_SAXReader* FX_SAXReader_Create(); #endif // XFA_FGAS_XML_FGAS_SAX_H_ diff --git a/xfa/fgas/xml/fgas_sax_imp.cpp b/xfa/fgas/xml/fgas_sax_imp.cpp deleted file mode 100644 index d47bc44000..0000000000 --- a/xfa/fgas/xml/fgas_sax_imp.cpp +++ /dev/null @@ -1,688 +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/fgas/xml/fgas_sax_imp.h" - -#include - -namespace { - -const uint32_t kSaxFileBufSize = 32768; - -} // namespace - -IFX_SAXReader* FX_SAXReader_Create() { - return new CFX_SAXReader; -} -CFX_SAXFile::CFX_SAXFile() - : m_pFile(NULL), - m_dwStart(0), - m_dwEnd(0), - m_dwCur(0), - m_pBuf(NULL), - m_dwBufSize(0), - m_dwBufIndex(0) {} -FX_BOOL CFX_SAXFile::StartFile(IFX_FileRead* pFile, - uint32_t dwStart, - uint32_t dwLen) { - ASSERT(m_pFile == NULL && pFile != NULL); - uint32_t dwSize = pFile->GetSize(); - if (dwStart >= dwSize) { - return FALSE; - } - if (dwLen == -1 || dwStart + dwLen > dwSize) { - dwLen = dwSize - dwStart; - } - if (dwLen == 0) { - return FALSE; - } - m_dwBufSize = std::min(dwLen, kSaxFileBufSize); - m_pBuf = FX_Alloc(uint8_t, m_dwBufSize); - if (!pFile->ReadBlock(m_pBuf, dwStart, m_dwBufSize)) { - return FALSE; - } - m_dwStart = dwStart; - m_dwEnd = dwStart + dwLen; - m_dwCur = dwStart; - m_pFile = pFile; - m_dwBufIndex = 0; - return TRUE; -} -FX_BOOL CFX_SAXFile::ReadNextBlock() { - ASSERT(m_pFile != NULL); - uint32_t dwSize = m_dwEnd - m_dwCur; - if (dwSize == 0) { - return FALSE; - } - m_dwBufSize = std::min(dwSize, kSaxFileBufSize); - if (!m_pFile->ReadBlock(m_pBuf, m_dwCur, m_dwBufSize)) { - return FALSE; - } - m_dwBufIndex = 0; - return TRUE; -} -void CFX_SAXFile::Reset() { - if (m_pBuf) { - FX_Free(m_pBuf); - m_pBuf = NULL; - } - m_pFile = NULL; -} -CFX_SAXReader::CFX_SAXReader() - : m_File(), - m_pHandler(nullptr), - m_iState(-1), - m_pRoot(nullptr), - m_pCurItem(nullptr), - m_dwItemID(0), - m_iDataSize(256), - m_iNameSize(256), - m_dwParseMode(0), - m_pCommentContext(nullptr) { - m_pszData = FX_Alloc(uint8_t, m_iDataSize); - m_pszName = FX_Alloc(uint8_t, m_iNameSize); -} -CFX_SAXReader::~CFX_SAXReader() { - Reset(); - if (m_pszData) { - FX_Free(m_pszData); - m_pszData = NULL; - } - if (m_pszName) { - FX_Free(m_pszName); - m_pszName = NULL; - } -} -void CFX_SAXReader::Reset() { - m_File.Reset(); - CFX_SAXItem* pItem = m_pRoot; - while (pItem) { - CFX_SAXItem* pNext = pItem->m_pNext; - delete pItem; - pItem = pNext; - } - m_pRoot = NULL; - m_pCurItem = NULL; - m_dwItemID = 0; - m_SkipStack.RemoveAll(); - m_SkipChar = 0; - m_iDataLength = 0; - m_iEntityStart = -1; - m_iNameLength = 0; - m_iDataPos = 0; - if (m_pCommentContext) { - delete m_pCommentContext; - m_pCommentContext = NULL; - } -} -inline void CFX_SAXReader::Push() { - CFX_SAXItem* pNew = new CFX_SAXItem; - pNew->m_dwID = ++m_dwItemID; - pNew->m_bSkip = m_pCurItem->m_bSkip; - pNew->m_pPrev = m_pCurItem; - m_pCurItem->m_pNext = pNew; - m_pCurItem = pNew; -} -inline void CFX_SAXReader::Pop() { - if (!m_pCurItem) { - return; - } - CFX_SAXItem* pPrev = m_pCurItem->m_pPrev; - pPrev->m_pNext = NULL; - delete m_pCurItem; - m_pCurItem = pPrev; -} -inline void CFX_SAXReader::AppendData(uint8_t ch) { - ReallocDataBuffer(); - m_pszData[m_iDataPos++] = ch; -} -inline void CFX_SAXReader::AppendName(uint8_t ch) { - ReallocNameBuffer(); - m_pszName[m_iDataPos++] = ch; -} -void CFX_SAXReader::ReallocDataBuffer() { - if (m_iDataPos < m_iDataSize) { - return; - } - if (m_iDataSize <= 1024 * 1024) { - m_iDataSize *= 2; - } else { - m_iDataSize += 1024 * 1024; - } - m_pszData = (uint8_t*)FX_Realloc(uint8_t, m_pszData, m_iDataSize); -} -void CFX_SAXReader::ReallocNameBuffer() { - if (m_iDataPos < m_iNameSize) { - return; - } - if (m_iNameSize <= 1024 * 1024) { - m_iNameSize *= 2; - } else { - m_iNameSize += 1024 * 1024; - } - m_pszName = (uint8_t*)FX_Realloc(uint8_t, m_pszName, m_iNameSize); -} -inline FX_BOOL CFX_SAXReader::SkipSpace(uint8_t ch) { - return (m_dwParseMode & FX_SAXPARSEMODE_NotSkipSpace) == 0 && ch < 0x21; -} -int32_t CFX_SAXReader::StartParse(IFX_FileRead* pFile, - uint32_t dwStart, - uint32_t dwLen, - uint32_t dwParseMode) { - m_iState = -1; - Reset(); - if (!m_File.StartFile(pFile, dwStart, dwLen)) { - return -1; - } - m_iState = 0; - m_eMode = FX_SAXMODE_Text; - m_ePrevMode = FX_SAXMODE_Text; - m_bCharData = FALSE; - m_dwDataOffset = 0; - m_pRoot = m_pCurItem = new CFX_SAXItem; - m_pCurItem->m_dwID = ++m_dwItemID; - m_dwParseMode = dwParseMode; - return 0; -} -typedef void (CFX_SAXReader::*FX_SAXReader_LPFParse)(); -static const FX_SAXReader_LPFParse g_FX_SAXReader_LPFParse[FX_SAXMODE_MAX] = { - &CFX_SAXReader::ParseText, - &CFX_SAXReader::ParseNodeStart, - &CFX_SAXReader::ParseDeclOrComment, - &CFX_SAXReader::ParseDeclNode, - &CFX_SAXReader::ParseComment, - &CFX_SAXReader::ParseCommentContent, - &CFX_SAXReader::ParseTagName, - &CFX_SAXReader::ParseTagAttributeName, - &CFX_SAXReader::ParseTagAttributeEqual, - &CFX_SAXReader::ParseTagAttributeValue, - &CFX_SAXReader::ParseMaybeClose, - &CFX_SAXReader::ParseTagClose, - &CFX_SAXReader::ParseTagEnd, - &CFX_SAXReader::ParseTargetData, -}; -int32_t CFX_SAXReader::ContinueParse(IFX_Pause* pPause) { - if (m_iState < 0 || m_iState > 99) { - return m_iState; - } - while (m_File.m_dwCur < m_File.m_dwEnd) { - uint32_t& index = m_File.m_dwBufIndex; - uint32_t size = m_File.m_dwBufSize; - const uint8_t* pBuf = m_File.m_pBuf; - while (index < size) { - m_CurByte = pBuf[index]; - (this->*g_FX_SAXReader_LPFParse[m_eMode])(); - index++; - } - m_File.m_dwCur += index; - m_iState = (m_File.m_dwCur - m_File.m_dwStart) * 100 / - (m_File.m_dwEnd - m_File.m_dwStart); - if (m_File.m_dwCur >= m_File.m_dwEnd) { - break; - } - if (!m_File.ReadNextBlock()) { - m_iState = -2; - break; - } - m_dwDataOffset = 0; - if (pPause && pPause->NeedToPauseNow()) { - break; - } - } - return m_iState; -} -void CFX_SAXReader::ParseChar(uint8_t ch) { - ReallocDataBuffer(); - m_pszData[m_iDataPos] = ch; - if (m_iEntityStart > -1 && ch == ';') { - int32_t iSaveEntityStart = m_iEntityStart; - CFX_ByteString csEntity(m_pszData + m_iEntityStart + 1, - m_iDataPos - m_iEntityStart - 1); - int32_t iLen = csEntity.GetLength(); - if (iLen > 0) { - if (csEntity[0] == '#') { - if ((m_dwParseMode & FX_SAXPARSEMODE_NotConvert_sharp) == 0) { - ch = 0; - uint8_t w; - if (iLen > 1 && csEntity[1] == 'x') { - for (int32_t i = 2; i < iLen; i++) { - w = csEntity[i]; - if (w >= '0' && w <= '9') { - ch = (ch << 4) + w - '0'; - } else if (w >= 'A' && w <= 'F') { - ch = (ch << 4) + w - 55; - } else if (w >= 'a' && w <= 'f') { - ch = (ch << 4) + w - 87; - } else { - break; - } - } - } else { - for (int32_t i = 1; i < iLen; i++) { - w = csEntity[i]; - if (w < '0' || w > '9') { - break; - } - ch = ch * 10 + w - '0'; - } - } - if (ch != 0) { - m_pszData[m_iEntityStart++] = ch; - } - } - } else { - if (csEntity.Compare("amp") == 0) { - if ((m_dwParseMode & FX_SAXPARSEMODE_NotConvert_amp) == 0) { - m_pszData[m_iEntityStart++] = '&'; - } - } else if (csEntity.Compare("lt") == 0) { - if ((m_dwParseMode & FX_SAXPARSEMODE_NotConvert_lt) == 0) { - m_pszData[m_iEntityStart++] = '<'; - } - } else if (csEntity.Compare("gt") == 0) { - if ((m_dwParseMode & FX_SAXPARSEMODE_NotConvert_gt) == 0) { - m_pszData[m_iEntityStart++] = '>'; - } - } else if (csEntity.Compare("apos") == 0) { - if ((m_dwParseMode & FX_SAXPARSEMODE_NotConvert_apos) == 0) { - m_pszData[m_iEntityStart++] = '\''; - } - } else if (csEntity.Compare("quot") == 0) { - if ((m_dwParseMode & FX_SAXPARSEMODE_NotConvert_quot) == 0) { - m_pszData[m_iEntityStart++] = '\"'; - } - } - } - } - if (iSaveEntityStart != m_iEntityStart) { - m_iDataPos = m_iEntityStart; - m_iEntityStart = -1; - } else { - m_iDataPos++; - m_iEntityStart = -1; - } - } else { - if (m_iEntityStart < 0 && ch == '&') { - m_iEntityStart = m_iDataPos; - } - m_iDataPos++; - } -} -void CFX_SAXReader::ParseText() { - if (m_CurByte == '<') { - if (m_iDataPos > 0) { - m_iDataLength = m_iDataPos; - m_iDataPos = 0; - if (m_pHandler) { - NotifyData(); - } - } - Push(); - m_dwNodePos = m_File.m_dwCur + m_File.m_dwBufIndex; - m_eMode = FX_SAXMODE_NodeStart; - return; - } - if (m_iDataPos < 1 && SkipSpace(m_CurByte)) { - return; - } - ParseChar(m_CurByte); -} -void CFX_SAXReader::ParseNodeStart() { - if (m_CurByte == '?') { - m_pCurItem->m_eNode = FX_SAXNODE_Instruction; - m_eMode = FX_SAXMODE_TagName; - return; - } - if (m_CurByte == '!') { - m_eMode = FX_SAXMODE_DeclOrComment; - return; - } - if (m_CurByte == '/') { - m_eMode = FX_SAXMODE_TagEnd; - return; - } - if (m_CurByte == '>') { - Pop(); - m_eMode = FX_SAXMODE_Text; - return; - } - if (m_CurByte > 0x20) { - m_dwDataOffset = m_File.m_dwBufIndex; - m_pCurItem->m_eNode = FX_SAXNODE_Tag; - m_eMode = FX_SAXMODE_TagName; - AppendData(m_CurByte); - } -} -void CFX_SAXReader::ParseDeclOrComment() { - if (m_CurByte == '-') { - m_eMode = FX_SAXMODE_Comment; - m_pCurItem->m_eNode = FX_SAXNODE_Comment; - if (m_pCommentContext == NULL) { - m_pCommentContext = new CFX_SAXCommentContext; - } - m_pCommentContext->m_iHeaderCount = 1; - m_pCommentContext->m_iTailCount = 0; - } else { - m_eMode = FX_SAXMODE_DeclNode; - m_dwDataOffset = m_File.m_dwBufIndex; - m_SkipChar = '>'; - m_SkipStack.Add('>'); - SkipNode(); - } -} -void CFX_SAXReader::ParseComment() { - m_pCommentContext->m_iHeaderCount = 2; - m_dwNodePos = m_File.m_dwCur + m_File.m_dwBufIndex; - m_eMode = FX_SAXMODE_CommentContent; -} -void CFX_SAXReader::ParseCommentContent() { - if (m_CurByte == '-') { - m_pCommentContext->m_iTailCount++; - } else if (m_CurByte == '>' && m_pCommentContext->m_iTailCount == 2) { - m_iDataLength = m_iDataPos; - m_iDataPos = 0; - if (m_pHandler) { - NotifyTargetData(); - } - Pop(); - m_eMode = FX_SAXMODE_Text; - } else { - while (m_pCommentContext->m_iTailCount > 0) { - AppendData('-'); - m_pCommentContext->m_iTailCount--; - } - AppendData(m_CurByte); - } -} -void CFX_SAXReader::ParseDeclNode() { - SkipNode(); -} -void CFX_SAXReader::ParseTagName() { - if (m_CurByte < 0x21 || m_CurByte == '/' || m_CurByte == '>' || - m_CurByte == '?') { - m_iDataLength = m_iDataPos; - m_iDataPos = 0; - if (m_pHandler) { - NotifyEnter(); - } - if (m_CurByte < 0x21) { - m_eMode = FX_SAXMODE_TagAttributeName; - } else if (m_CurByte == '/' || m_CurByte == '?') { - m_ePrevMode = m_eMode; - m_eMode = FX_SAXMODE_TagMaybeClose; - } else { - if (m_pHandler) { - NotifyBreak(); - } - m_eMode = FX_SAXMODE_Text; - } - } else { - AppendData(m_CurByte); - } -} -void CFX_SAXReader::ParseTagAttributeName() { - if (m_CurByte < 0x21 || m_CurByte == '=') { - if (m_iDataPos < 1 && m_CurByte < 0x21) { - return; - } - m_iNameLength = m_iDataPos; - m_iDataPos = 0; - m_SkipChar = 0; - m_eMode = m_CurByte == '=' ? FX_SAXMODE_TagAttributeValue - : FX_SAXMODE_TagAttributeEqual; - return; - } - if (m_CurByte == '/' || m_CurByte == '>' || m_CurByte == '?') { - if (m_CurByte == '/' || m_CurByte == '?') { - m_ePrevMode = m_eMode; - m_eMode = FX_SAXMODE_TagMaybeClose; - } else { - if (m_pHandler) { - NotifyBreak(); - } - m_eMode = FX_SAXMODE_Text; - } - return; - } - if (m_iDataPos < 1) { - m_dwDataOffset = m_File.m_dwBufIndex; - } - AppendName(m_CurByte); -} -void CFX_SAXReader::ParseTagAttributeEqual() { - if (m_CurByte == '=') { - m_SkipChar = 0; - m_eMode = FX_SAXMODE_TagAttributeValue; - return; - } else if (m_pCurItem->m_eNode == FX_SAXNODE_Instruction) { - m_iDataPos = m_iNameLength; - AppendName(0x20); - m_eMode = FX_SAXMODE_TargetData; - ParseTargetData(); - } -} -void CFX_SAXReader::ParseTagAttributeValue() { - if (m_SkipChar) { - if (m_SkipChar == m_CurByte) { - { - m_iDataLength = m_iDataPos; - m_iDataPos = 0; - if (m_pHandler) { - NotifyAttribute(); - } - } - m_SkipChar = 0; - m_eMode = FX_SAXMODE_TagAttributeName; - return; - } - ParseChar(m_CurByte); - return; - } - if (m_CurByte < 0x21) { - return; - } - if (m_iDataPos < 1) { - if (m_CurByte == '\'' || m_CurByte == '\"') { - m_SkipChar = m_CurByte; - } - } -} -void CFX_SAXReader::ParseMaybeClose() { - if (m_CurByte == '>') { - if (m_pCurItem->m_eNode == FX_SAXNODE_Instruction) { - m_iNameLength = m_iDataPos; - m_iDataPos = 0; - if (m_pHandler) { - NotifyTargetData(); - } - } - ParseTagClose(); - m_eMode = FX_SAXMODE_Text; - } else if (m_ePrevMode == FX_SAXMODE_TagName) { - AppendData('/'); - m_eMode = FX_SAXMODE_TagName; - m_ePrevMode = FX_SAXMODE_Text; - ParseTagName(); - } else if (m_ePrevMode == FX_SAXMODE_TagAttributeName) { - AppendName('/'); - m_eMode = FX_SAXMODE_TagAttributeName; - m_ePrevMode = FX_SAXMODE_Text; - ParseTagAttributeName(); - } else if (m_ePrevMode == FX_SAXMODE_TargetData) { - AppendName('?'); - m_eMode = FX_SAXMODE_TargetData; - m_ePrevMode = FX_SAXMODE_Text; - ParseTargetData(); - } -} -void CFX_SAXReader::ParseTagClose() { - m_dwNodePos = m_File.m_dwCur + m_File.m_dwBufIndex; - if (m_pHandler) { - NotifyClose(); - } - Pop(); -} -void CFX_SAXReader::ParseTagEnd() { - if (m_CurByte < 0x21) { - return; - } - if (m_CurByte == '>') { - Pop(); - m_dwNodePos = m_File.m_dwCur + m_File.m_dwBufIndex; - m_iDataLength = m_iDataPos; - m_iDataPos = 0; - if (m_pHandler) { - NotifyEnd(); - } - Pop(); - m_eMode = FX_SAXMODE_Text; - } else { - ParseChar(m_CurByte); - } -} -void CFX_SAXReader::ParseTargetData() { - if (m_CurByte == '?') { - m_ePrevMode = m_eMode; - m_eMode = FX_SAXMODE_TagMaybeClose; - } else { - AppendName(m_CurByte); - } -} -void CFX_SAXReader::SkipNode() { - int32_t iLen = m_SkipStack.GetSize(); - if (m_SkipChar == '\'' || m_SkipChar == '\"') { - if (m_CurByte != m_SkipChar) { - return; - } - iLen--; - ASSERT(iLen > -1); - m_SkipStack.RemoveAt(iLen, 1); - m_SkipChar = iLen ? m_SkipStack[iLen - 1] : 0; - return; - } - switch (m_CurByte) { - case '<': - m_SkipChar = '>'; - m_SkipStack.Add('>'); - break; - case '[': - m_SkipChar = ']'; - m_SkipStack.Add(']'); - break; - case '(': - m_SkipChar = ')'; - m_SkipStack.Add(')'); - break; - case '\'': - m_SkipChar = '\''; - m_SkipStack.Add('\''); - break; - case '\"': - m_SkipChar = '\"'; - m_SkipStack.Add('\"'); - break; - default: - if (m_CurByte == m_SkipChar) { - iLen--; - m_SkipStack.RemoveAt(iLen, 1); - m_SkipChar = iLen ? m_SkipStack[iLen - 1] : 0; - if (iLen == 0 && m_CurByte == '>') { - m_iDataLength = m_iDataPos; - m_iDataPos = 0; - if (m_iDataLength >= 9 && - FXSYS_memcmp(m_pszData, "[CDATA[", 7 * sizeof(uint8_t)) == 0 && - FXSYS_memcmp(m_pszData + m_iDataLength - 2, "]]", - 2 * sizeof(uint8_t)) == 0) { - Pop(); - m_iDataLength -= 9; - m_dwDataOffset += 7; - FXSYS_memmove(m_pszData, m_pszData + 7, - m_iDataLength * sizeof(uint8_t)); - m_bCharData = TRUE; - if (m_pHandler) { - NotifyData(); - } - m_bCharData = FALSE; - } else { - Pop(); - } - m_eMode = FX_SAXMODE_Text; - } - } - break; - } - if (iLen > 0) { - ParseChar(m_CurByte); - } -} -void CFX_SAXReader::NotifyData() { - ASSERT(m_pHandler != NULL); - if (m_pCurItem->m_eNode == FX_SAXNODE_Tag) - m_pHandler->OnTagData(m_pCurItem->m_pNode, - m_bCharData ? FX_SAXNODE_CharData : FX_SAXNODE_Text, - CFX_ByteStringC(m_pszData, m_iDataLength), - m_File.m_dwCur + m_dwDataOffset); -} -void CFX_SAXReader::NotifyEnter() { - ASSERT(m_pHandler != NULL); - if (m_pCurItem->m_eNode == FX_SAXNODE_Tag || - m_pCurItem->m_eNode == FX_SAXNODE_Instruction) { - m_pCurItem->m_pNode = - m_pHandler->OnTagEnter(CFX_ByteStringC(m_pszData, m_iDataLength), - m_pCurItem->m_eNode, m_dwNodePos); - } -} -void CFX_SAXReader::NotifyAttribute() { - ASSERT(m_pHandler != NULL); - if (m_pCurItem->m_eNode == FX_SAXNODE_Tag || - m_pCurItem->m_eNode == FX_SAXNODE_Instruction) { - m_pHandler->OnTagAttribute(m_pCurItem->m_pNode, - CFX_ByteStringC(m_pszName, m_iNameLength), - CFX_ByteStringC(m_pszData, m_iDataLength)); - } -} -void CFX_SAXReader::NotifyBreak() { - ASSERT(m_pHandler != NULL); - if (m_pCurItem->m_eNode == FX_SAXNODE_Tag) { - m_pHandler->OnTagBreak(m_pCurItem->m_pNode); - } -} -void CFX_SAXReader::NotifyClose() { - ASSERT(m_pHandler != NULL); - if (m_pCurItem->m_eNode == FX_SAXNODE_Tag || - m_pCurItem->m_eNode == FX_SAXNODE_Instruction) { - m_pHandler->OnTagClose(m_pCurItem->m_pNode, m_dwNodePos); - } -} -void CFX_SAXReader::NotifyEnd() { - ASSERT(m_pHandler != NULL); - if (m_pCurItem->m_eNode == FX_SAXNODE_Tag) { - m_pHandler->OnTagEnd(m_pCurItem->m_pNode, - CFX_ByteStringC(m_pszData, m_iDataLength), - m_dwNodePos); - } -} -void CFX_SAXReader::NotifyTargetData() { - ASSERT(m_pHandler != NULL); - if (m_pCurItem->m_eNode == FX_SAXNODE_Instruction) { - m_pHandler->OnTargetData(m_pCurItem->m_pNode, m_pCurItem->m_eNode, - CFX_ByteStringC(m_pszName, m_iNameLength), - m_dwNodePos); - } else if (m_pCurItem->m_eNode == FX_SAXNODE_Comment) { - m_pHandler->OnTargetData(m_pCurItem->m_pNode, m_pCurItem->m_eNode, - CFX_ByteStringC(m_pszData, m_iDataLength), - m_dwNodePos); - } -} -void CFX_SAXReader::SkipCurrentNode() { - if (!m_pCurItem) { - return; - } - m_pCurItem->m_bSkip = TRUE; -} -void CFX_SAXReader::SetHandler(IFX_SAXReaderHandler* pHandler) { - m_pHandler = pHandler; -} diff --git a/xfa/fgas/xml/fgas_sax_imp.h b/xfa/fgas/xml/fgas_sax_imp.h deleted file mode 100644 index a52d8356ee..0000000000 --- a/xfa/fgas/xml/fgas_sax_imp.h +++ /dev/null @@ -1,141 +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_FGAS_XML_FGAS_SAX_IMP_H_ -#define XFA_FGAS_XML_FGAS_SAX_IMP_H_ - -#include "xfa/fgas/xml/fgas_sax.h" - -class CFX_SAXFile { - public: - CFX_SAXFile(); - FX_BOOL StartFile(IFX_FileRead* pFile, uint32_t dwStart, uint32_t dwLen); - FX_BOOL ReadNextBlock(); - void Reset(); - IFX_FileRead* m_pFile; - uint32_t m_dwStart; - uint32_t m_dwEnd; - uint32_t m_dwCur; - uint8_t* m_pBuf; - uint32_t m_dwBufSize; - uint32_t m_dwBufIndex; -}; - -enum FX_SAXMODE { - FX_SAXMODE_Text = 0, - FX_SAXMODE_NodeStart, - FX_SAXMODE_DeclOrComment, - FX_SAXMODE_DeclNode, - FX_SAXMODE_Comment, - FX_SAXMODE_CommentContent, - FX_SAXMODE_TagName, - FX_SAXMODE_TagAttributeName, - FX_SAXMODE_TagAttributeEqual, - FX_SAXMODE_TagAttributeValue, - FX_SAXMODE_TagMaybeClose, - FX_SAXMODE_TagClose, - FX_SAXMODE_TagEnd, - FX_SAXMODE_TargetData, - FX_SAXMODE_MAX, -}; - -class CFX_SAXItem { - public: - CFX_SAXItem() - : m_pNode(NULL), - m_eNode(FX_SAXNODE_Unknown), - m_dwID(0), - m_bSkip(FALSE), - m_pPrev(NULL), - m_pNext(NULL) {} - void* m_pNode; - FX_SAXNODE m_eNode; - uint32_t m_dwID; - FX_BOOL m_bSkip; - CFX_SAXItem* m_pPrev; - CFX_SAXItem* m_pNext; -}; - -class CFX_SAXCommentContext { - public: - CFX_SAXCommentContext() : m_iHeaderCount(0), m_iTailCount(0) {} - int32_t m_iHeaderCount; - int32_t m_iTailCount; -}; - -class CFX_SAXReader : public IFX_SAXReader { - public: - CFX_SAXReader(); - ~CFX_SAXReader(); - virtual void Release() { delete this; } - virtual int32_t StartParse(IFX_FileRead* pFile, - uint32_t dwStart = 0, - uint32_t dwLen = -1, - uint32_t dwParseMode = 0); - virtual int32_t ContinueParse(IFX_Pause* pPause = NULL); - virtual void SkipCurrentNode(); - virtual void SetHandler(IFX_SAXReaderHandler* pHandler); - void AppendData(uint8_t ch); - void AppendName(uint8_t ch); - void ParseText(); - void ParseNodeStart(); - void ParseInstruction(); - void ParseDeclOrComment(); - void ParseDeclNode(); - void ParseComment(); - void ParseCommentContent(); - void ParseTagName(); - void ParseTagAttributeName(); - void ParseTagAttributeEqual(); - void ParseTagAttributeValue(); - void ParseMaybeClose(); - void ParseTagClose(); - void ParseTagEnd(); - void ParseTargetData(); - - protected: - CFX_SAXFile m_File; - IFX_SAXReaderHandler* m_pHandler; - int32_t m_iState; - CFX_SAXItem* m_pRoot; - CFX_SAXItem* m_pCurItem; - uint32_t m_dwItemID; - FX_SAXMODE m_eMode; - FX_SAXMODE m_ePrevMode; - FX_BOOL m_bCharData; - uint8_t m_CurByte; - uint32_t m_dwDataOffset; - CFX_ByteArray m_SkipStack; - uint8_t m_SkipChar; - uint32_t m_dwNodePos; - uint8_t* m_pszData; - int32_t m_iDataSize; - int32_t m_iDataLength; - int32_t m_iEntityStart; - int32_t m_iDataPos; - uint8_t* m_pszName; - int32_t m_iNameSize; - int32_t m_iNameLength; - uint32_t m_dwParseMode; - CFX_SAXCommentContext* m_pCommentContext; - void Reset(); - void Push(); - void Pop(); - FX_BOOL SkipSpace(uint8_t ch); - void SkipNode(); - void NotifyData(); - void NotifyEnter(); - void NotifyAttribute(); - void NotifyBreak(); - void NotifyClose(); - void NotifyEnd(); - void NotifyTargetData(); - void ReallocDataBuffer(); - void ReallocNameBuffer(); - void ParseChar(uint8_t ch); -}; - -#endif // XFA_FGAS_XML_FGAS_SAX_IMP_H_ diff --git a/xfa/fwl/theme/cfwl_widgettp.cpp b/xfa/fwl/theme/cfwl_widgettp.cpp index 2fc8036763..5332b3bebd 100644 --- a/xfa/fwl/theme/cfwl_widgettp.cpp +++ b/xfa/fwl/theme/cfwl_widgettp.cpp @@ -9,6 +9,7 @@ #include #include "xfa/fde/tto/fde_textout.h" +#include "xfa/fgas/font/fgas_stdfontmgr.h" #include "xfa/fwl/core/cfwl_themebackground.h" #include "xfa/fwl/core/cfwl_themepart.h" #include "xfa/fwl/core/cfwl_themetext.h" @@ -690,7 +691,7 @@ FX_BOOL CFWL_FontData::LoadFont(const CFX_WideStringC& wsFontFamily, #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ m_pFontMgr = IFX_FontMgr::Create(FX_GetDefFontEnumerator()); #else - m_pFontSource = FX_CreateDefaultFontSourceEnum(); + m_pFontSource = new CFX_FontSourceEnum_File; m_pFontMgr = IFX_FontMgr::Create(m_pFontSource); #endif } diff --git a/xfa/fwl/theme/cfwl_widgettp.h b/xfa/fwl/theme/cfwl_widgettp.h index 4e640370b8..8e5c8ba283 100644 --- a/xfa/fwl/theme/cfwl_widgettp.h +++ b/xfa/fwl/theme/cfwl_widgettp.h @@ -101,7 +101,7 @@ class CFWL_ThemePart; class CFWL_ThemeText; #if _FXM_PLATFORM_ != _FXM_PLATFORM_WINDOWS_ -class IFX_FontSourceEnum; +class CFX_FontSourceEnum_File; #endif class CFWL_WidgetTP { @@ -270,7 +270,7 @@ class CFWL_FontData { IFX_Font* m_pFont; IFX_FontMgr* m_pFontMgr; #if _FXM_PLATFORM_ != _FXM_PLATFORM_WINDOWS_ - IFX_FontSourceEnum* m_pFontSource; + CFX_FontSourceEnum_File* m_pFontSource; #endif }; diff --git a/xfa/fxfa/app/xfa_checksum.cpp b/xfa/fxfa/app/xfa_checksum.cpp index 59bf37b6a5..195033bfab 100644 --- a/xfa/fxfa/app/xfa_checksum.cpp +++ b/xfa/fxfa/app/xfa_checksum.cpp @@ -126,30 +126,28 @@ void CXFA_SAXReaderHandler::UpdateChecksum(FX_BOOL bCheckSpace) { } CXFA_ChecksumContext::CXFA_ChecksumContext() - : m_pSAXReader(NULL), m_pByteContext(NULL) {} + : m_pSAXReader(nullptr), m_pByteContext(nullptr) {} + CXFA_ChecksumContext::~CXFA_ChecksumContext() { FinishChecksum(); } -FX_BOOL CXFA_ChecksumContext::StartChecksum() { + +void CXFA_ChecksumContext::StartChecksum() { FinishChecksum(); m_pByteContext = FX_Alloc(uint8_t, 128); CRYPT_SHA1Start(m_pByteContext); m_bsChecksum.clear(); - m_pSAXReader = FX_SAXReader_Create(); - return m_pSAXReader != NULL; + m_pSAXReader = new CFX_SAXReader; } + FX_BOOL CXFA_ChecksumContext::UpdateChecksum(IFX_FileRead* pSrcFile, FX_FILESIZE offset, size_t size) { - if (m_pSAXReader == NULL) { - return FALSE; - } - if (pSrcFile == NULL) { + if (!m_pSAXReader || !pSrcFile) return FALSE; - } - if (size < 1) { + if (size < 1) size = pSrcFile->GetSize(); - } + CXFA_SAXReaderHandler handler(this); m_pSAXReader->SetHandler(&handler); if (m_pSAXReader->StartParse( @@ -161,6 +159,7 @@ FX_BOOL CXFA_ChecksumContext::UpdateChecksum(IFX_FileRead* pSrcFile, } return m_pSAXReader->ContinueParse(NULL) > 99; } + void CXFA_ChecksumContext::FinishChecksum() { if (m_pSAXReader) { m_pSAXReader->Release(); diff --git a/xfa/fxfa/app/xfa_ffapp.cpp b/xfa/fxfa/app/xfa_ffapp.cpp index 71b8fc44b1..987b3e8efd 100644 --- a/xfa/fxfa/app/xfa_ffapp.cpp +++ b/xfa/fxfa/app/xfa_ffapp.cpp @@ -8,6 +8,7 @@ #include +#include "xfa/fgas/font/fgas_stdfontmgr.h" #include "xfa/fwl/core/ifwl_widgetmgrdelegate.h" #include "xfa/fxfa/app/xfa_fwladapter.h" #include "xfa/fxfa/app/xfa_fwltheme.h" @@ -146,7 +147,7 @@ IFX_FontMgr* CXFA_FFApp::GetFDEFontMgr() { #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ m_pFDEFontMgr = IFX_FontMgr::Create(FX_GetDefFontEnumerator()); #else - m_pFontSource = FX_CreateDefaultFontSourceEnum(); + m_pFontSource = new CFX_FontSourceEnum_File; m_pFDEFontMgr = IFX_FontMgr::Create(m_pFontSource); #endif } diff --git a/xfa/fxfa/app/xfa_fontmgr.cpp b/xfa/fxfa/app/xfa_fontmgr.cpp index 7c6d5cddec..69883674e5 100644 --- a/xfa/fxfa/app/xfa_fontmgr.cpp +++ b/xfa/fxfa/app/xfa_fontmgr.cpp @@ -1874,6 +1874,7 @@ IFX_Font* CXFA_PDFFontMgr::FindFont(CFX_ByteString strPsName, } return NULL; } + IFX_Font* CXFA_PDFFontMgr::GetFont(const CFX_WideStringC& wsFontFamily, uint32_t dwFontStyles, CPDF_Font** pPDFFont, @@ -1894,6 +1895,7 @@ IFX_Font* CXFA_PDFFontMgr::GetFont(const CFX_WideStringC& wsFontFamily, m_FontMap[strKey] = pFont; return pFont; } + CFX_ByteString CXFA_PDFFontMgr::PsNameToFontName( const CFX_ByteString& strPsName, FX_BOOL bBold, @@ -1907,6 +1909,7 @@ CFX_ByteString CXFA_PDFFontMgr::PsNameToFontName( } return strPsName; } + FX_BOOL CXFA_PDFFontMgr::PsNameMatchDRFontName( const CFX_ByteStringC& bsPsName, FX_BOOL bBold, @@ -1996,10 +1999,13 @@ FX_BOOL CXFA_PDFFontMgr::GetCharWidth(IFX_Font* pFont, iWidth = pPDFFont->GetCharWidthF(wUnicode); return TRUE; } -CXFA_FontMgr::CXFA_FontMgr() : m_pDefFontMgr(NULL) {} + +CXFA_FontMgr::CXFA_FontMgr() : m_pDefFontMgr(nullptr) {} + CXFA_FontMgr::~CXFA_FontMgr() { DelAllMgrMap(); } + IFX_Font* CXFA_FontMgr::GetFont(CXFA_FFDoc* hDoc, const CFX_WideStringC& wsFontFamily, uint32_t dwFontStyles, diff --git a/xfa/fxfa/include/xfa_checksum.h b/xfa/fxfa/include/xfa_checksum.h index 6c24b2a5af..6c7ea7a04c 100644 --- a/xfa/fxfa/include/xfa_checksum.h +++ b/xfa/fxfa/include/xfa_checksum.h @@ -16,37 +16,41 @@ class CXFA_ChecksumContext; class CXFA_SAXContext { public: CXFA_SAXContext() : m_eNode(FX_SAXNODE_Unknown) {} + CFX_ByteTextBuf m_TextBuf; CFX_ByteString m_bsTagName; FX_SAXNODE m_eNode; }; -class CXFA_SAXReaderHandler : public IFX_SAXReaderHandler { + +class CXFA_SAXReaderHandler { public: CXFA_SAXReaderHandler(CXFA_ChecksumContext* pContext); - virtual ~CXFA_SAXReaderHandler(); - virtual void* OnTagEnter(const CFX_ByteStringC& bsTagName, - FX_SAXNODE eType, - uint32_t dwStartPos); - virtual void OnTagAttribute(void* pTag, - const CFX_ByteStringC& bsAttri, - const CFX_ByteStringC& bsValue); - virtual void OnTagBreak(void* pTag); - virtual void OnTagData(void* pTag, - FX_SAXNODE eType, - const CFX_ByteStringC& bsData, - uint32_t dwStartPos); - virtual void OnTagClose(void* pTag, uint32_t dwEndPos); - virtual void OnTagEnd(void* pTag, - const CFX_ByteStringC& bsTagName, - uint32_t dwEndPos); + ~CXFA_SAXReaderHandler(); - virtual void OnTargetData(void* pTag, - FX_SAXNODE eType, - const CFX_ByteStringC& bsData, - uint32_t dwStartPos); + void* OnTagEnter(const CFX_ByteStringC& bsTagName, + FX_SAXNODE eType, + uint32_t dwStartPos); + void OnTagAttribute(void* pTag, + const CFX_ByteStringC& bsAttri, + const CFX_ByteStringC& bsValue); + void OnTagBreak(void* pTag); + void OnTagData(void* pTag, + FX_SAXNODE eType, + const CFX_ByteStringC& bsData, + uint32_t dwStartPos); + void OnTagClose(void* pTag, uint32_t dwEndPos); + void OnTagEnd(void* pTag, + const CFX_ByteStringC& bsTagName, + uint32_t dwEndPos); + + void OnTargetData(void* pTag, + FX_SAXNODE eType, + const CFX_ByteStringC& bsData, + uint32_t dwStartPos); protected: void UpdateChecksum(FX_BOOL bCheckSpace); + CXFA_ChecksumContext* m_pContext; CXFA_SAXContext m_SAXContext; }; @@ -57,7 +61,7 @@ class CXFA_ChecksumContext { ~CXFA_ChecksumContext(); void Release() { delete this; } - FX_BOOL StartChecksum(); + void StartChecksum(); FX_BOOL UpdateChecksum(IFX_FileRead* pSrcFile, FX_FILESIZE offset = 0, size_t size = 0); @@ -66,7 +70,7 @@ class CXFA_ChecksumContext { void Update(const CFX_ByteStringC& bsText); protected: - IFX_SAXReader* m_pSAXReader; + CFX_SAXReader* m_pSAXReader; uint8_t* m_pByteContext; CFX_ByteString m_bsChecksum; }; diff --git a/xfa/fxfa/include/xfa_ffapp.h b/xfa/fxfa/include/xfa_ffapp.h index cad4e88e58..8ecc89df13 100644 --- a/xfa/fxfa/include/xfa_ffapp.h +++ b/xfa/fxfa/include/xfa_ffapp.h @@ -67,7 +67,7 @@ class CXFA_FFApp : public IFWL_AdapterNative { IXFA_AppProvider* m_pProvider; CXFA_FontMgr* m_pFontMgr; #if _FXM_PLATFORM_ != _FXM_PLATFORM_WINDOWS_ - IFX_FontSourceEnum* m_pFontSource; + CFX_FontSourceEnum_File* m_pFontSource; #endif CXFA_FWLAdapterWidgetMgr* m_pAdapterWidgetMgr; IFWL_WidgetMgrDelegate* m_pWidgetMgrDelegate; diff --git a/xfa/fxfa/include/xfa_fontmgr.h b/xfa/fxfa/include/xfa_fontmgr.h index cab3cfb219..8b3e20f5e3 100644 --- a/xfa/fxfa/include/xfa_fontmgr.h +++ b/xfa/fxfa/include/xfa_fontmgr.h @@ -42,10 +42,11 @@ class CXFA_DefFontMgr { CFX_PtrArray m_CacheFonts; }; -class CXFA_PDFFontMgr : public IFX_FontProvider { +class CXFA_PDFFontMgr { public: CXFA_PDFFontMgr(CXFA_FFDoc* pDoc); ~CXFA_PDFFontMgr(); + IFX_Font* GetFont(const CFX_WideStringC& wsFontFamily, uint32_t dwFontStyles, CPDF_Font** pPDFFont, -- cgit v1.2.3