diff options
Diffstat (limited to 'core')
-rw-r--r-- | core/include/fpdfapi/fpdf_parser.h | 97 | ||||
-rw-r--r-- | core/include/fpdfdoc/fpdf_ap.h | 21 | ||||
-rw-r--r-- | core/src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp | 124 | ||||
-rw-r--r-- | core/src/fpdfdoc/doc_ap.cpp | 51 |
4 files changed, 126 insertions, 167 deletions
diff --git a/core/include/fpdfapi/fpdf_parser.h b/core/include/fpdfapi/fpdf_parser.h index f0b50f8638..294c0c5f4a 100644 --- a/core/include/fpdfapi/fpdf_parser.h +++ b/core/include/fpdfapi/fpdf_parser.h @@ -328,52 +328,40 @@ class CPDF_SyntaxParser { FX_DWORD gennum); FX_FILESIZE m_Pos; - int m_MetadataObjnum; - IFX_FileRead* m_pFileAccess; - FX_DWORD m_HeaderOffset; - FX_FILESIZE m_FileLen; - uint8_t* m_pFileBuf; - FX_DWORD m_BufSize; - FX_FILESIZE m_BufOffset; - std::unique_ptr<CPDF_CryptoHandler> m_pCryptoHandler; - uint8_t m_WordBuffer[257]; - FX_DWORD m_WordSize; }; -#define PDFPARSE_ERROR_SUCCESS 0 -#define PDFPARSE_ERROR_FILE 1 -#define PDFPARSE_ERROR_FORMAT 2 -#define PDFPARSE_ERROR_PASSWORD 3 -#define PDFPARSE_ERROR_HANDLER 4 -#define PDFPARSE_ERROR_CERT 5 - class CPDF_Parser { public: + enum Error { + SUCCESS = 0, + FILE_ERROR, + FORMAT_ERROR, + PASSWORD_ERROR, + HANDLER_ERROR + }; + CPDF_Parser(); ~CPDF_Parser(); - FX_DWORD StartParse(IFX_FileRead* pFile, - FX_BOOL bReParse = FALSE, - FX_BOOL bOwnFileRead = TRUE); - + Error StartParse(IFX_FileRead* pFile, + FX_BOOL bReParse = FALSE, + FX_BOOL bOwnFileRead = TRUE); void CloseParser(FX_BOOL bReParse = FALSE); FX_DWORD GetPermissions(FX_BOOL bCheckRevision = FALSE); - FX_BOOL IsOwner(); void SetPassword(const FX_CHAR* password) { m_Password = password; } - CFX_ByteString GetPassword() { return m_Password; } CPDF_CryptoHandler* GetCryptoHandler() { @@ -383,17 +371,15 @@ class CPDF_Parser { void SetSecurityHandler(CPDF_SecurityHandler* pSecurityHandler, FX_BOOL bForced = FALSE); - CPDF_Dictionary* GetTrailer() { return m_pTrailer; } - - FX_FILESIZE GetLastXRefOffset() { return m_LastXRefOffset; } - - CPDF_Document* GetDocument() { return m_pDocument; } + CPDF_Dictionary* GetTrailer() const { return m_pTrailer; } + FX_FILESIZE GetLastXRefOffset() const { return m_LastXRefOffset; } + CPDF_Document* GetDocument() const { return m_pDocument; } FX_DWORD GetRootObjNum(); FX_DWORD GetInfoObjNum(); CPDF_Array* GetIDArray(); - CPDF_Dictionary* GetEncryptDict() { return m_pEncryptDict; } + CPDF_Dictionary* GetEncryptDict() const { return m_pEncryptDict; } CPDF_Object* ParseIndirectObject(CPDF_IndirectObjectHolder* pObjList, FX_DWORD objnum); @@ -403,16 +389,13 @@ class CPDF_Parser { FX_BOOL IsFormStream(FX_DWORD objnum, FX_BOOL& bForm); FX_FILESIZE GetObjectOffset(FX_DWORD objnum) const; - FX_FILESIZE GetObjectSize(FX_DWORD objnum) const; void GetIndirectBinary(FX_DWORD objnum, uint8_t*& pBuffer, FX_DWORD& size); - IFX_FileRead* GetFileAccess() const { return m_Syntax.m_pFileAccess; } - int GetFileVersion() const { return m_FileVersion; } - FX_BOOL IsXRefStream() const { return m_bXRefStream; } + CPDF_Object* ParseIndirectObjectAt(CPDF_IndirectObjectHolder* pObjList, FX_FILESIZE pos, FX_DWORD objnum); @@ -423,72 +406,45 @@ class CPDF_Parser { FX_DWORD objnum, FX_FILESIZE* pResultPos); - FX_DWORD StartAsynParse(IFX_FileRead* pFile, - FX_BOOL bReParse = FALSE, - FX_BOOL bOwnFileRead = TRUE); + Error StartAsynParse(IFX_FileRead* pFile, + FX_BOOL bReParse = FALSE, + FX_BOOL bOwnFileRead = TRUE); - FX_DWORD GetFirstPageNo() { return m_dwFirstPageNo; } + FX_DWORD GetFirstPageNo() const { return m_dwFirstPageNo; } protected: CPDF_Object* ParseDirect(CPDF_Object* pObj); - FX_BOOL LoadAllCrossRefV4(FX_FILESIZE pos); - FX_BOOL LoadAllCrossRefV5(FX_FILESIZE pos); - bool LoadCrossRefV4(FX_FILESIZE pos, FX_FILESIZE streampos, FX_BOOL bSkip); - FX_BOOL LoadCrossRefV5(FX_FILESIZE* pos, FX_BOOL bMainXRef); - CPDF_Dictionary* LoadTrailerV4(); - FX_BOOL RebuildCrossRef(); - - FX_DWORD SetEncryptHandler(); - + Error SetEncryptHandler(); void ReleaseEncryptHandler(); - FX_BOOL LoadLinearizedAllCrossRefV4(FX_FILESIZE pos, FX_DWORD dwObjCount); - FX_BOOL LoadLinearizedCrossRefV4(FX_FILESIZE pos, FX_DWORD dwObjCount); - FX_BOOL LoadLinearizedAllCrossRefV5(FX_FILESIZE pos); - - FX_DWORD LoadLinearizedMainXRefTable(); - + Error LoadLinearizedMainXRefTable(); CPDF_StreamAcc* GetObjectStream(FX_DWORD number); - FX_BOOL IsLinearizedFile(IFX_FileRead* pFileAccess, FX_DWORD offset); - bool FindPosInOffsets(FX_FILESIZE pos) const; - void SetEncryptDictionary(CPDF_Dictionary* pDict); - FX_FILESIZE GetObjectPositionOrZero(FX_DWORD objnum) const; void ShrinkObjectMap(FX_DWORD size); CPDF_Document* m_pDocument; - CPDF_SyntaxParser m_Syntax; FX_BOOL m_bOwnFileRead; int m_FileVersion; - CPDF_Dictionary* m_pTrailer; - CPDF_Dictionary* m_pEncryptDict; - FX_FILESIZE m_LastXRefOffset; - FX_BOOL m_bXRefStream; - std::unique_ptr<CPDF_SecurityHandler> m_pSecurityHandler; - FX_BOOL m_bForceUseSecurityHandler; - CFX_ByteString m_bsRecipient; - CFX_ByteString m_FilePath; - CFX_ByteString m_Password; struct ObjectInfo { @@ -505,17 +461,11 @@ class CPDF_Parser { CFX_ByteArray m_V5Type; CFX_WordArray m_ObjVersion; - CFX_FileSizeArray m_SortedOffset; - CFX_ArrayTemplate<CPDF_Dictionary*> m_Trailers; - FX_BOOL m_bVersionUpdated; - CPDF_Object* m_pLinearized; - FX_DWORD m_dwFirstPageNo; - FX_DWORD m_dwXrefStartObjNum; // A map of object numbers to indirect streams. Map owns the streams. @@ -667,6 +617,9 @@ class CPDF_StandardSecurityHandler : public CPDF_SecurityHandler { int m_KeyLen; }; + +CPDF_SecurityHandler* FPDF_CreateStandardSecurityHandler(); + class CPDF_CryptoHandler { public: virtual ~CPDF_CryptoHandler() {} diff --git a/core/include/fpdfdoc/fpdf_ap.h b/core/include/fpdfdoc/fpdf_ap.h index 6d0478c23f..510b39cb9b 100644 --- a/core/include/fpdfdoc/fpdf_ap.h +++ b/core/include/fpdfdoc/fpdf_ap.h @@ -16,22 +16,20 @@ class IPVT_FontMap { virtual CPDF_Font* GetPDFFont(int32_t nFontIndex) = 0; virtual CFX_ByteString GetPDFFontAlias(int32_t nFontIndex) = 0; }; + struct CPVT_Dash { CPVT_Dash(int32_t dash, int32_t gap, int32_t phase) : nDash(dash), nGap(gap), nPhase(phase) {} int32_t nDash; - int32_t nGap; - int32_t nPhase; }; -#define CT_TRANSPARENT 0 -#define CT_GRAY 1 -#define CT_RGB 2 -#define CT_CMYK 3 + struct CPVT_Color { - CPVT_Color(int32_t type = 0, + enum Type { kTransparent = 0, kGray, kRGB, kCMYK }; + + CPVT_Color(Type type = kTransparent, FX_FLOAT color1 = 0.0f, FX_FLOAT color2 = 0.0f, FX_FLOAT color3 = 0.0f, @@ -42,12 +40,13 @@ struct CPVT_Color { fColor3(color3), fColor4(color4) {} - int32_t nColorType; + Type nColorType; FX_FLOAT fColor1; FX_FLOAT fColor2; FX_FLOAT fColor3; FX_FLOAT fColor4; }; + class CPVT_Provider : public IPDF_VariableText_Provider { public: CPVT_Provider(IPVT_FontMap* pFontMap); @@ -68,11 +67,7 @@ class CPVT_Provider : public IPDF_VariableText_Provider { private: IPVT_FontMap* m_pFontMap; }; -#define PBS_SOLID 0 -#define PBS_DASH 1 -#define PBS_BEVELED 2 -#define PBS_INSET 3 -#define PBS_UNDERLINED 4 + class CPVT_GenerateAP { public: static FX_BOOL GenerateTextFieldAP(CPDF_Document* pDoc, diff --git a/core/src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp b/core/src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp index 8c2bad4acd..a62018d0cd 100644 --- a/core/src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp +++ b/core/src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp @@ -179,11 +179,10 @@ void CPDF_Parser::CloseParser(FX_BOOL bReParse) { m_pLinearized = NULL; } } -CPDF_SecurityHandler* FPDF_CreateStandardSecurityHandler(); -CPDF_SecurityHandler* FPDF_CreatePubKeyHandler(void*); -FX_DWORD CPDF_Parser::StartParse(IFX_FileRead* pFileAccess, - FX_BOOL bReParse, - FX_BOOL bOwnFileRead) { + +CPDF_Parser::Error CPDF_Parser::StartParse(IFX_FileRead* pFileAccess, + FX_BOOL bReParse, + FX_BOOL bOwnFileRead) { CloseParser(bReParse); m_bXRefStream = FALSE; m_LastXRefOffset = 0; @@ -193,23 +192,23 @@ FX_DWORD CPDF_Parser::StartParse(IFX_FileRead* pFileAccess, if (offset == -1) { if (bOwnFileRead && pFileAccess) pFileAccess->Release(); - return PDFPARSE_ERROR_FORMAT; + return FORMAT_ERROR; } m_Syntax.InitParser(pFileAccess, offset); uint8_t ch; if (!m_Syntax.GetCharAt(5, ch)) - return PDFPARSE_ERROR_FORMAT; + return FORMAT_ERROR; if (std::isdigit(ch)) m_FileVersion = FXSYS_toDecimalDigit(ch) * 10; if (!m_Syntax.GetCharAt(7, ch)) - return PDFPARSE_ERROR_FORMAT; + return FORMAT_ERROR; if (std::isdigit(ch)) m_FileVersion += FXSYS_toDecimalDigit(ch); if (m_Syntax.m_FileLen < m_Syntax.m_HeaderOffset + 9) - return PDFPARSE_ERROR_FORMAT; + return FORMAT_ERROR; m_Syntax.RestorePos(m_Syntax.m_FileLen - m_Syntax.m_HeaderOffset - 9); if (!bReParse) @@ -228,54 +227,54 @@ FX_DWORD CPDF_Parser::StartParse(IFX_FileRead* pFileAccess, bool bNumber; CFX_ByteString xrefpos_str = m_Syntax.GetNextWord(&bNumber); if (!bNumber) - return PDFPARSE_ERROR_FORMAT; + return FORMAT_ERROR; m_LastXRefOffset = (FX_FILESIZE)FXSYS_atoi64(xrefpos_str); if (!LoadAllCrossRefV4(m_LastXRefOffset) && !LoadAllCrossRefV5(m_LastXRefOffset)) { if (!RebuildCrossRef()) - return PDFPARSE_ERROR_FORMAT; + return FORMAT_ERROR; bXRefRebuilt = TRUE; m_LastXRefOffset = 0; } } else { if (!RebuildCrossRef()) - return PDFPARSE_ERROR_FORMAT; + return FORMAT_ERROR; bXRefRebuilt = TRUE; } - FX_DWORD dwRet = SetEncryptHandler(); - if (dwRet != PDFPARSE_ERROR_SUCCESS) - return dwRet; + Error eRet = SetEncryptHandler(); + if (eRet != SUCCESS) + return eRet; m_pDocument->LoadDoc(); if (!m_pDocument->GetRoot() || m_pDocument->GetPageCount() == 0) { if (bXRefRebuilt) - return PDFPARSE_ERROR_FORMAT; + return FORMAT_ERROR; ReleaseEncryptHandler(); if (!RebuildCrossRef()) - return PDFPARSE_ERROR_FORMAT; + return FORMAT_ERROR; - dwRet = SetEncryptHandler(); - if (dwRet != PDFPARSE_ERROR_SUCCESS) - return dwRet; + eRet = SetEncryptHandler(); + if (eRet != SUCCESS) + return eRet; m_pDocument->LoadDoc(); if (!m_pDocument->GetRoot()) - return PDFPARSE_ERROR_FORMAT; + return FORMAT_ERROR; } FXSYS_qsort(m_SortedOffset.GetData(), m_SortedOffset.GetSize(), sizeof(FX_FILESIZE), CompareFileSize); if (GetRootObjNum() == 0) { ReleaseEncryptHandler(); if (!RebuildCrossRef() || GetRootObjNum() == 0) - return PDFPARSE_ERROR_FORMAT; + return FORMAT_ERROR; - dwRet = SetEncryptHandler(); - if (dwRet != PDFPARSE_ERROR_SUCCESS) - return dwRet; + eRet = SetEncryptHandler(); + if (eRet != SUCCESS) + return eRet; } if (m_pSecurityHandler && !m_pSecurityHandler->IsMetadataEncrypted()) { CPDF_Reference* pMetadata = @@ -283,13 +282,13 @@ FX_DWORD CPDF_Parser::StartParse(IFX_FileRead* pFileAccess, if (pMetadata) m_Syntax.m_MetadataObjnum = pMetadata->GetRefObjNum(); } - return PDFPARSE_ERROR_SUCCESS; + return SUCCESS; } -FX_DWORD CPDF_Parser::SetEncryptHandler() { +CPDF_Parser::Error CPDF_Parser::SetEncryptHandler() { ReleaseEncryptHandler(); SetEncryptDictionary(NULL); if (!m_pTrailer) { - return PDFPARSE_ERROR_FORMAT; + return FORMAT_ERROR; } CPDF_Object* pEncryptObj = m_pTrailer->GetElement("Encrypt"); if (pEncryptObj) { @@ -302,29 +301,28 @@ FX_DWORD CPDF_Parser::SetEncryptHandler() { } } if (m_bForceUseSecurityHandler) { - FX_DWORD err = PDFPARSE_ERROR_HANDLER; if (!m_pSecurityHandler) { - return PDFPARSE_ERROR_HANDLER; + return HANDLER_ERROR; } if (!m_pSecurityHandler->OnInit(this, m_pEncryptDict)) { - return err; + return HANDLER_ERROR; } std::unique_ptr<CPDF_CryptoHandler> pCryptoHandler( m_pSecurityHandler->CreateCryptoHandler()); if (!pCryptoHandler->Init(m_pEncryptDict, m_pSecurityHandler.get())) { - return PDFPARSE_ERROR_HANDLER; + return HANDLER_ERROR; } m_Syntax.SetEncrypt(pCryptoHandler.release()); } else if (m_pEncryptDict) { CFX_ByteString filter = m_pEncryptDict->GetString("Filter"); std::unique_ptr<CPDF_SecurityHandler> pSecurityHandler; - FX_DWORD err = PDFPARSE_ERROR_HANDLER; + Error err = HANDLER_ERROR; if (filter == "Standard") { pSecurityHandler.reset(FPDF_CreateStandardSecurityHandler()); - err = PDFPARSE_ERROR_PASSWORD; + err = PASSWORD_ERROR; } if (!pSecurityHandler) { - return PDFPARSE_ERROR_HANDLER; + return HANDLER_ERROR; } if (!pSecurityHandler->OnInit(this, m_pEncryptDict)) { return err; @@ -333,11 +331,11 @@ FX_DWORD CPDF_Parser::SetEncryptHandler() { std::unique_ptr<CPDF_CryptoHandler> pCryptoHandler( m_pSecurityHandler->CreateCryptoHandler()); if (!pCryptoHandler->Init(m_pEncryptDict, m_pSecurityHandler.get())) { - return PDFPARSE_ERROR_HANDLER; + return HANDLER_ERROR; } m_Syntax.SetEncrypt(pCryptoHandler.release()); } - return PDFPARSE_ERROR_SUCCESS; + return SUCCESS; } void CPDF_Parser::ReleaseEncryptHandler() { m_Syntax.m_pCryptoHandler.reset(); @@ -1562,16 +1560,16 @@ FX_BOOL CPDF_Parser::IsLinearizedFile(IFX_FileRead* pFileAccess, m_pLinearized = NULL; return FALSE; } -FX_DWORD CPDF_Parser::StartAsynParse(IFX_FileRead* pFileAccess, - FX_BOOL bReParse, - FX_BOOL bOwnFileRead) { +CPDF_Parser::Error CPDF_Parser::StartAsynParse(IFX_FileRead* pFileAccess, + FX_BOOL bReParse, + FX_BOOL bOwnFileRead) { CloseParser(bReParse); m_bXRefStream = FALSE; m_LastXRefOffset = 0; m_bOwnFileRead = bOwnFileRead; int32_t offset = GetHeaderOffset(pFileAccess); if (offset == -1) { - return PDFPARSE_ERROR_FORMAT; + return FORMAT_ERROR; } if (!IsLinearizedFile(pFileAccess, offset)) { m_Syntax.m_pFileAccess = NULL; @@ -1586,7 +1584,7 @@ FX_DWORD CPDF_Parser::StartAsynParse(IFX_FileRead* pFileAccess, if (!(bLoadV4 = LoadCrossRefV4(dwFirstXRefOffset, 0, FALSE)) && !LoadCrossRefV5(&dwFirstXRefOffset, TRUE)) { if (!RebuildCrossRef()) { - return PDFPARSE_ERROR_FORMAT; + return FORMAT_ERROR; } bXRefRebuilt = TRUE; m_LastXRefOffset = 0; @@ -1594,7 +1592,7 @@ FX_DWORD CPDF_Parser::StartAsynParse(IFX_FileRead* pFileAccess, if (bLoadV4) { m_pTrailer = LoadTrailerV4(); if (!m_pTrailer) { - return PDFPARSE_ERROR_SUCCESS; + return SUCCESS; } int32_t xrefsize = GetDirectInteger(m_pTrailer, "Size"); @@ -1603,26 +1601,26 @@ FX_DWORD CPDF_Parser::StartAsynParse(IFX_FileRead* pFileAccess, m_V5Type.SetSize(xrefsize); } } - FX_DWORD dwRet = SetEncryptHandler(); - if (dwRet != PDFPARSE_ERROR_SUCCESS) { - return dwRet; + Error eRet = SetEncryptHandler(); + if (eRet != SUCCESS) { + return eRet; } m_pDocument->LoadAsynDoc(m_pLinearized->GetDict()); if (!m_pDocument->GetRoot() || m_pDocument->GetPageCount() == 0) { if (bXRefRebuilt) { - return PDFPARSE_ERROR_FORMAT; + return FORMAT_ERROR; } ReleaseEncryptHandler(); if (!RebuildCrossRef()) { - return PDFPARSE_ERROR_FORMAT; + return FORMAT_ERROR; } - dwRet = SetEncryptHandler(); - if (dwRet != PDFPARSE_ERROR_SUCCESS) { - return dwRet; + eRet = SetEncryptHandler(); + if (eRet != SUCCESS) { + return eRet; } m_pDocument->LoadAsynDoc(m_pLinearized->GetDict()); if (!m_pDocument->GetRoot()) { - return PDFPARSE_ERROR_FORMAT; + return FORMAT_ERROR; } } FXSYS_qsort(m_SortedOffset.GetData(), m_SortedOffset.GetSize(), @@ -1630,11 +1628,11 @@ FX_DWORD CPDF_Parser::StartAsynParse(IFX_FileRead* pFileAccess, if (GetRootObjNum() == 0) { ReleaseEncryptHandler(); if (!RebuildCrossRef() || GetRootObjNum() == 0) - return PDFPARSE_ERROR_FORMAT; + return FORMAT_ERROR; - dwRet = SetEncryptHandler(); - if (dwRet != PDFPARSE_ERROR_SUCCESS) { - return dwRet; + eRet = SetEncryptHandler(); + if (eRet != SUCCESS) { + return eRet; } } if (m_pSecurityHandler && m_pSecurityHandler->IsMetadataEncrypted()) { @@ -1642,7 +1640,7 @@ FX_DWORD CPDF_Parser::StartAsynParse(IFX_FileRead* pFileAccess, ToReference(m_pDocument->GetRoot()->GetElement("Metadata"))) m_Syntax.m_MetadataObjnum = pMetadata->GetRefObjNum(); } - return PDFPARSE_ERROR_SUCCESS; + return SUCCESS; } FX_BOOL CPDF_Parser::LoadLinearizedAllCrossRefV5(FX_FILESIZE xrefpos) { if (!LoadCrossRefV5(&xrefpos, FALSE)) { @@ -1663,7 +1661,8 @@ FX_BOOL CPDF_Parser::LoadLinearizedAllCrossRefV5(FX_FILESIZE xrefpos) { m_bXRefStream = TRUE; return TRUE; } -FX_DWORD CPDF_Parser::LoadLinearizedMainXRefTable() { + +CPDF_Parser::Error CPDF_Parser::LoadLinearizedMainXRefTable() { FX_DWORD dwSaveMetadataObjnum = m_Syntax.m_MetadataObjnum; m_Syntax.m_MetadataObjnum = 0; if (m_pTrailer) { @@ -1690,12 +1689,12 @@ FX_DWORD CPDF_Parser::LoadLinearizedMainXRefTable() { !LoadLinearizedAllCrossRefV5(m_LastXRefOffset)) { m_LastXRefOffset = 0; m_Syntax.m_MetadataObjnum = dwSaveMetadataObjnum; - return PDFPARSE_ERROR_FORMAT; + return FORMAT_ERROR; } FXSYS_qsort(m_SortedOffset.GetData(), m_SortedOffset.GetSize(), sizeof(FX_FILESIZE), CompareFileSize); m_Syntax.m_MetadataObjnum = dwSaveMetadataObjnum; - return PDFPARSE_ERROR_SUCCESS; + return SUCCESS; } // static @@ -4208,9 +4207,10 @@ IPDF_DataAvail::DocAvailStatus CPDF_DataAvail::CheckLinearizedData( pHints->AddSegment(m_dwLastXRefOffset, data_size.ValueOrDie()); return DataNotAvailable; } - FX_DWORD dwRet = m_pDocument->GetParser()->LoadLinearizedMainXRefTable(); + CPDF_Parser::Error eRet = + m_pDocument->GetParser()->LoadLinearizedMainXRefTable(); m_bMainXRefLoadTried = TRUE; - if (dwRet != PDFPARSE_ERROR_SUCCESS) { + if (eRet != CPDF_Parser::SUCCESS) { return DataError; } if (!PreparePageItem()) { diff --git a/core/src/fpdfdoc/doc_ap.cpp b/core/src/fpdfdoc/doc_ap.cpp index d0adc06691..15576965b1 100644 --- a/core/src/fpdfdoc/doc_ap.cpp +++ b/core/src/fpdfdoc/doc_ap.cpp @@ -10,6 +10,12 @@ #include "doc_utils.h" #include "pdf_vt.h" +#define PBS_SOLID 0 +#define PBS_DASH 1 +#define PBS_BEVELED 2 +#define PBS_INSET 3 +#define PBS_UNDERLINED 4 + FX_BOOL FPDF_GenerateAP(CPDF_Document* pDoc, CPDF_Dictionary* pAnnotDict) { if (!pAnnotDict || pAnnotDict->GetConstString("Subtype") != "Widget") { return FALSE; @@ -224,14 +230,14 @@ static CPVT_Color ParseColor(const CFX_ByteString& str) { CPDF_SimpleParser syntax(str); syntax.SetPos(0); if (syntax.FindTagParam("g", 1)) { - return CPVT_Color(CT_GRAY, FX_atof(syntax.GetWord())); + return CPVT_Color(CPVT_Color::kGray, FX_atof(syntax.GetWord())); } syntax.SetPos(0); if (syntax.FindTagParam("rg", 3)) { FX_FLOAT f1 = FX_atof(syntax.GetWord()); FX_FLOAT f2 = FX_atof(syntax.GetWord()); FX_FLOAT f3 = FX_atof(syntax.GetWord()); - return CPVT_Color(CT_RGB, f1, f2, f3); + return CPVT_Color(CPVT_Color::kRGB, f1, f2, f3); } syntax.SetPos(0); if (syntax.FindTagParam("k", 4)) { @@ -239,22 +245,22 @@ static CPVT_Color ParseColor(const CFX_ByteString& str) { FX_FLOAT f2 = FX_atof(syntax.GetWord()); FX_FLOAT f3 = FX_atof(syntax.GetWord()); FX_FLOAT f4 = FX_atof(syntax.GetWord()); - return CPVT_Color(CT_CMYK, f1, f2, f3, f4); + return CPVT_Color(CPVT_Color::kCMYK, f1, f2, f3, f4); } - return CPVT_Color(CT_TRANSPARENT); + return CPVT_Color(CPVT_Color::kTransparent); } static CPVT_Color ParseColor(const CPDF_Array& array) { CPVT_Color rt; switch (array.GetCount()) { case 1: - rt = CPVT_Color(CT_GRAY, array.GetFloat(0)); + rt = CPVT_Color(CPVT_Color::kGray, array.GetFloat(0)); break; case 3: - rt = CPVT_Color(CT_RGB, array.GetFloat(0), array.GetFloat(1), + rt = CPVT_Color(CPVT_Color::kRGB, array.GetFloat(0), array.GetFloat(1), array.GetFloat(2)); break; case 4: - rt = CPVT_Color(CT_CMYK, array.GetFloat(0), array.GetFloat(1), + rt = CPVT_Color(CPVT_Color::kCMYK, array.GetFloat(0), array.GetFloat(1), array.GetFloat(2), array.GetFloat(3)); break; } @@ -374,14 +380,14 @@ static FX_BOOL GenerateWidgetAP(CPDF_Document* pDoc, case 'B': nBorderStyle = PBS_BEVELED; fBorderWidth *= 2; - crLeftTop = CPVT_Color(CT_GRAY, 1); - crRightBottom = CPVT_Color(CT_GRAY, 0.5); + crLeftTop = CPVT_Color(CPVT_Color::kGray, 1); + crRightBottom = CPVT_Color(CPVT_Color::kGray, 0.5); break; case 'I': nBorderStyle = PBS_INSET; fBorderWidth *= 2; - crLeftTop = CPVT_Color(CT_GRAY, 0.5); - crRightBottom = CPVT_Color(CT_GRAY, 0.75); + crLeftTop = CPVT_Color(CPVT_Color::kGray, 0.5); + crRightBottom = CPVT_Color(CPVT_Color::kGray, 0.75); break; case 'U': nBorderStyle = PBS_UNDERLINED; @@ -555,7 +561,8 @@ static FX_BOOL GenerateWidgetAP(CPDF_Document* pDoc, << "Q\nEMC\n"; } CFX_ByteString sButton = CPVT_GenerateAP::GenerateColorAP( - CPVT_Color(CT_RGB, 220.0f / 255.0f, 220.0f / 255.0f, 220.0f / 255.0f), + CPVT_Color(CPVT_Color::kRGB, 220.0f / 255.0f, 220.0f / 255.0f, + 220.0f / 255.0f), TRUE); if (sButton.GetLength() > 0 && !rcButton.IsEmpty()) { sAppStream << "q\n" << sButton; @@ -563,8 +570,10 @@ static FX_BOOL GenerateWidgetAP(CPDF_Document* pDoc, << rcButton.Width() << " " << rcButton.Height() << " re f\n"; sAppStream << "Q\n"; CFX_ByteString sButtonBorder = CPVT_GenerateAP::GenerateBorderAP( - rcButton, 2, CPVT_Color(CT_GRAY, 0), CPVT_Color(CT_GRAY, 1), - CPVT_Color(CT_GRAY, 0.5), PBS_BEVELED, CPVT_Dash(3, 0, 0)); + rcButton, 2, CPVT_Color(CPVT_Color::kGray, 0), + CPVT_Color(CPVT_Color::kGray, 1), + CPVT_Color(CPVT_Color::kGray, 0.5), PBS_BEVELED, + CPVT_Dash(3, 0, 0)); if (sButtonBorder.GetLength() > 0) { sAppStream << "q\n" << sButtonBorder << "Q\n"; } @@ -635,14 +644,14 @@ static FX_BOOL GenerateWidgetAP(CPDF_Document* pDoc, CPDF_Rect rcItem = CPDF_Rect(rcBody.left, fy - fItemHeight, rcBody.right, fy); sBody << "q\n" << CPVT_GenerateAP::GenerateColorAP( - CPVT_Color(CT_RGB, 0, 51.0f / 255.0f, - 113.0f / 255.0f), + CPVT_Color(CPVT_Color::kRGB, 0, + 51.0f / 255.0f, 113.0f / 255.0f), TRUE) << rcItem.left << " " << rcItem.bottom << " " << rcItem.Width() << " " << rcItem.Height() << " re f\n" << "Q\n"; sBody << "BT\n" << CPVT_GenerateAP::GenerateColorAP( - CPVT_Color(CT_GRAY, 1), TRUE) + CPVT_Color(CPVT_Color::kGray, 1), TRUE) << CPVT_GenerateAP::GenerateEditAP(&map, vt.GetIterator(), CPDF_Point(0.0f, fy), TRUE, 0) @@ -903,20 +912,22 @@ CFX_ByteString CPVT_GenerateAP::GenerateColorAP(const CPVT_Color& color, const FX_BOOL& bFillOrStroke) { CFX_ByteTextBuf sColorStream; switch (color.nColorType) { - case CT_RGB: + case CPVT_Color::kRGB: sColorStream << color.fColor1 << " " << color.fColor2 << " " << color.fColor3 << " " << (bFillOrStroke ? "rg" : "RG") << "\n"; break; - case CT_GRAY: + case CPVT_Color::kGray: sColorStream << color.fColor1 << " " << (bFillOrStroke ? "g" : "G") << "\n"; break; - case CT_CMYK: + case CPVT_Color::kCMYK: sColorStream << color.fColor1 << " " << color.fColor2 << " " << color.fColor3 << " " << color.fColor4 << " " << (bFillOrStroke ? "k" : "K") << "\n"; break; + case CPVT_Color::kTransparent: + break; } return sColorStream.GetByteString(); } |