Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(114)

Side by Side Diff: xfa/fxfa/app/xfa_ffdoc.cpp

Issue 1992033002: fgas/ code cleanup. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 PDFium Authors. All rights reserved. 1 // Copyright 2014 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6 6
7 #include "xfa/fxfa/include/xfa_ffdoc.h" 7 #include "xfa/fxfa/include/xfa_ffdoc.h"
8 8
9 #include <algorithm> 9 #include <algorithm>
10 10
11 #include "core/fpdfapi/fpdf_parser/include/cpdf_array.h" 11 #include "core/fpdfapi/fpdf_parser/include/cpdf_array.h"
12 #include "core/fpdfapi/fpdf_parser/include/cpdf_document.h" 12 #include "core/fpdfapi/fpdf_parser/include/cpdf_document.h"
13 #include "core/fpdfdoc/include/fpdf_doc.h" 13 #include "core/fpdfdoc/include/fpdf_doc.h"
14 #include "core/fxcrt/include/fx_ext.h" 14 #include "core/fxcrt/include/fx_ext.h"
15 #include "core/fxcrt/include/fx_memory.h" 15 #include "core/fxcrt/include/fx_memory.h"
16 #include "xfa/fde/xml/fde_xml_imp.h" 16 #include "xfa/fde/xml/fde_xml_imp.h"
17 #include "xfa/fgas/crt/fgas_algorithm.h"
18 #include "xfa/fwl/core/fwl_noteimp.h" 17 #include "xfa/fwl/core/fwl_noteimp.h"
19 #include "xfa/fxfa/app/xfa_ffnotify.h" 18 #include "xfa/fxfa/app/xfa_ffnotify.h"
20 #include "xfa/fxfa/include/xfa_checksum.h" 19 #include "xfa/fxfa/include/xfa_checksum.h"
21 #include "xfa/fxfa/include/xfa_ffapp.h" 20 #include "xfa/fxfa/include/xfa_ffapp.h"
22 #include "xfa/fxfa/include/xfa_ffdocview.h" 21 #include "xfa/fxfa/include/xfa_ffdocview.h"
23 #include "xfa/fxfa/include/xfa_ffwidget.h" 22 #include "xfa/fxfa/include/xfa_ffwidget.h"
24 #include "xfa/fxfa/include/xfa_fontmgr.h" 23 #include "xfa/fxfa/include/xfa_fontmgr.h"
25 #include "xfa/fxfa/parser/xfa_document.h" 24 #include "xfa/fxfa/parser/xfa_document.h"
26 #include "xfa/fxfa/parser/xfa_document_serialize.h" 25 #include "xfa/fxfa/parser/xfa_document_serialize.h"
27 #include "xfa/fxfa/parser/xfa_parser.h" 26 #include "xfa/fxfa/parser/xfa_parser.h"
28 #include "xfa/fxfa/parser/xfa_parser_imp.h" 27 #include "xfa/fxfa/parser/xfa_parser_imp.h"
29 #include "xfa/fxfa/parser/xfa_parser_imp.h" 28 #include "xfa/fxfa/parser/xfa_parser_imp.h"
30 29
30 namespace {
31
32 struct FX_BASE64DATA {
dsinclair 2016/05/18 21:15:35 This struct is duplicated, but given what it conta
Tom Sepez 2016/05/18 22:01:21 Acknowledged.
33 uint32_t data1 : 2;
34 uint32_t data2 : 6;
35 uint32_t data3 : 4;
36 uint32_t data4 : 4;
37 uint32_t data5 : 6;
38 uint32_t data6 : 2;
39 uint32_t data7 : 8;
40 };
41
42 const uint8_t g_FXBase64DecoderMap[256] = {
43 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
44 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
45 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
46 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x3E, 0xFF, 0xFF, 0xFF, 0x3F,
47 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, 0x3B, 0x3C, 0x3D, 0xFF, 0xFF,
48 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06,
49 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10, 0x11, 0x12,
50 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
51 0xFF, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, 0x20, 0x21, 0x22, 0x23, 0x24,
52 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x2E, 0x2F, 0x30,
53 0x31, 0x32, 0x33, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
54 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
55 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
Tom Sepez 2016/05/18 22:01:21 Again, we could probably save 128 bytes here.
dsinclair 2016/05/19 14:24:44 Done. Please check my numbers are right.
56 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
57 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
58 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
59 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
60 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
61 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
62 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
63 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
64 0xFF, 0xFF, 0xFF, 0xFF,
65 };
66
67 void Base64DecodePiece(const FX_CHAR src[4],
68 int32_t iChars,
69 FX_BASE64DATA& dst,
70 int32_t& iBytes) {
71 ASSERT(iChars > 0 && iChars < 5);
72 iBytes = 1;
73 dst.data2 = g_FXBase64DecoderMap[(uint8_t)src[0]];
74 if (iChars > 1) {
75 uint8_t b = g_FXBase64DecoderMap[(uint8_t)src[1]];
76 dst.data1 = b >> 4;
77 dst.data4 = b;
78 if (iChars > 2) {
79 iBytes = 2;
80 b = g_FXBase64DecoderMap[(uint8_t)src[2]];
81 dst.data3 = b >> 2;
82 dst.data6 = b;
83 if (iChars > 3) {
84 iBytes = 3;
85 dst.data5 = g_FXBase64DecoderMap[(uint8_t)src[3]];
86 } else {
87 dst.data5 = 0;
88 }
89 } else {
90 dst.data3 = 0;
91 }
92 } else {
93 dst.data1 = 0;
94 }
95 }
96
97 int32_t Base64DecodeW(const FX_WCHAR* pSrc, int32_t iSrcLen, uint8_t* pDst) {
98 ASSERT(pSrc != NULL);
99 if (iSrcLen < 1) {
100 return 0;
101 }
102 while (iSrcLen > 0 && pSrc[iSrcLen - 1] == '=') {
103 iSrcLen--;
104 }
105 if (iSrcLen < 1) {
106 return 0;
107 }
108 if (pDst == NULL) {
109 int32_t iDstLen = iSrcLen / 4 * 3;
110 iSrcLen %= 4;
111 if (iSrcLen == 1) {
112 iDstLen += 1;
113 } else if (iSrcLen == 2) {
114 iDstLen += 1;
115 } else if (iSrcLen == 3) {
116 iDstLen += 2;
117 }
118 return iDstLen;
119 }
120 FX_CHAR srcData[4];
121 FX_BASE64DATA dstData;
122 int32_t iChars = 4, iBytes;
123 uint8_t* pDstEnd = pDst;
124 while (iSrcLen > 0) {
125 if (iSrcLen > 3) {
126 srcData[0] = (FX_CHAR)*pSrc++;
127 srcData[1] = (FX_CHAR)*pSrc++;
128 srcData[2] = (FX_CHAR)*pSrc++;
129 srcData[3] = (FX_CHAR)*pSrc++;
130 iSrcLen -= 4;
131 } else {
132 *((uint32_t*)&dstData) = 0;
133 *((uint32_t*)srcData) = 0;
134 srcData[0] = (FX_CHAR)*pSrc++;
135 if (iSrcLen > 1) {
136 srcData[1] = (FX_CHAR)*pSrc++;
137 }
138 if (iSrcLen > 2) {
139 srcData[2] = (FX_CHAR)*pSrc++;
140 }
141 iChars = iSrcLen;
142 iSrcLen = 0;
143 }
144 Base64DecodePiece(srcData, iChars, dstData, iBytes);
145 *pDstEnd++ = ((uint8_t*)&dstData)[0];
146 if (iBytes > 1) {
147 *pDstEnd++ = ((uint8_t*)&dstData)[1];
148 }
149 if (iBytes > 2) {
150 *pDstEnd++ = ((uint8_t*)&dstData)[2];
151 }
152 }
153 return pDstEnd - pDst;
154 }
155
156 } // namespace
157
31 CXFA_FFDoc::CXFA_FFDoc(CXFA_FFApp* pApp, IXFA_DocProvider* pDocProvider) 158 CXFA_FFDoc::CXFA_FFDoc(CXFA_FFApp* pApp, IXFA_DocProvider* pDocProvider)
32 : m_pDocProvider(pDocProvider), 159 : m_pDocProvider(pDocProvider),
33 m_pDocument(nullptr), 160 m_pDocument(nullptr),
34 m_pStream(nullptr), 161 m_pStream(nullptr),
35 m_pApp(pApp), 162 m_pApp(pApp),
36 m_pNotify(nullptr), 163 m_pNotify(nullptr),
37 m_pPDFDoc(nullptr), 164 m_pPDFDoc(nullptr),
38 m_dwDocType(XFA_DOCTYPE_Static), 165 m_dwDocType(XFA_DOCTYPE_Static),
39 m_bOwnStream(TRUE) {} 166 m_bOwnStream(TRUE) {}
40 CXFA_FFDoc::~CXFA_FFDoc() { 167 CXFA_FFDoc::~CXFA_FFDoc() {
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 break; 210 break;
84 } 211 }
85 } 212 }
86 } 213 }
87 if (!pChunkElement) { 214 if (!pChunkElement) {
88 return FALSE; 215 return FALSE;
89 } 216 }
90 CFX_WideString wsPDFContent; 217 CFX_WideString wsPDFContent;
91 pChunkElement->GetTextData(wsPDFContent); 218 pChunkElement->GetTextData(wsPDFContent);
92 iBufferSize = 219 iBufferSize =
93 FX_Base64DecodeW(wsPDFContent.c_str(), wsPDFContent.GetLength(), NULL); 220 Base64DecodeW(wsPDFContent.c_str(), wsPDFContent.GetLength(), NULL);
Tom Sepez 2016/05/18 22:01:21 nit: nullptr
dsinclair 2016/05/19 14:24:44 Done.
94 pByteBuffer = FX_Alloc(uint8_t, iBufferSize + 1); 221 pByteBuffer = FX_Alloc(uint8_t, iBufferSize + 1);
95 pByteBuffer[iBufferSize] = '0'; // FIXME: I bet this is wrong. 222 pByteBuffer[iBufferSize] = '0'; // FIXME: I bet this is wrong.
96 FX_Base64DecodeW(wsPDFContent.c_str(), wsPDFContent.GetLength(), pByteBuffer); 223 Base64DecodeW(wsPDFContent.c_str(), wsPDFContent.GetLength(), pByteBuffer);
97 return TRUE; 224 return TRUE;
98 } 225 }
99 void XFA_XPDPacket_MergeRootNode(CXFA_Node* pOriginRoot, CXFA_Node* pNewRoot) { 226 void XFA_XPDPacket_MergeRootNode(CXFA_Node* pOriginRoot, CXFA_Node* pNewRoot) {
100 CXFA_Node* pChildNode = pNewRoot->GetNodeItem(XFA_NODEITEM_FirstChild); 227 CXFA_Node* pChildNode = pNewRoot->GetNodeItem(XFA_NODEITEM_FirstChild);
101 while (pChildNode) { 228 while (pChildNode) {
102 CXFA_Node* pOriginChild = 229 CXFA_Node* pOriginChild =
103 pOriginRoot->GetFirstChildByName(pChildNode->GetNameHash()); 230 pOriginRoot->GetFirstChildByName(pChildNode->GetNameHash());
104 if (pOriginChild) { 231 if (pOriginChild) {
105 pChildNode = pChildNode->GetNodeItem(XFA_NODEITEM_NextSibling); 232 pChildNode = pChildNode->GetNodeItem(XFA_NODEITEM_NextSibling);
106 } else { 233 } else {
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after
381 508
382 return pExport->Export(pFile, pNode, 0, 509 return pExport->Export(pFile, pNode, 0,
383 bsChecksum.GetLength() ? bsChecksum.c_str() : nullptr); 510 bsChecksum.GetLength() ? bsChecksum.c_str() : nullptr);
384 } 511 }
385 512
386 FX_BOOL CXFA_FFDoc::ImportData(IFX_FileRead* pStream, FX_BOOL bXDP) { 513 FX_BOOL CXFA_FFDoc::ImportData(IFX_FileRead* pStream, FX_BOOL bXDP) {
387 std::unique_ptr<CXFA_DataImporter> importer( 514 std::unique_ptr<CXFA_DataImporter> importer(
388 new CXFA_DataImporter(m_pDocument)); 515 new CXFA_DataImporter(m_pDocument));
389 return importer->ImportData(pStream); 516 return importer->ImportData(pStream);
390 } 517 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698