OLD | NEW |
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 <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "../../include/formfiller/FormFiller.h" | 9 #include "../../include/formfiller/FormFiller.h" |
10 #include "../../include/formfiller/FFL_Utils.h" | 10 #include "../../include/formfiller/FFL_Utils.h" |
11 | 11 |
12 CPDF_Rect CFFL_Utils::MaxRect(const CPDF_Rect & rect1,const CPDF_Rect & rect2) | 12 CPDF_Rect CFFL_Utils::MaxRect(const CPDF_Rect& rect1, const CPDF_Rect& rect2) { |
13 { | 13 CPDF_Rect rcRet; |
14 » CPDF_Rect rcRet; | |
15 | 14 |
16 » rcRet.left = std::min(rect1.left, rect2.left); | 15 rcRet.left = std::min(rect1.left, rect2.left); |
17 » rcRet.bottom = std::min(rect1.bottom, rect2.bottom); | 16 rcRet.bottom = std::min(rect1.bottom, rect2.bottom); |
18 » rcRet.right = std::max(rect1.right, rect2.right); | 17 rcRet.right = std::max(rect1.right, rect2.right); |
19 » rcRet.top = std::max(rect1.top, rect2.top); | 18 rcRet.top = std::max(rect1.top, rect2.top); |
20 | 19 |
21 » return rcRet; | 20 return rcRet; |
22 } | 21 } |
23 | 22 |
24 CPDF_Rect CFFL_Utils::InflateRect(const CPDF_Rect & crRect,const FX_FLOAT & fSiz
e) | 23 CPDF_Rect CFFL_Utils::InflateRect(const CPDF_Rect& crRect, |
25 { | 24 const FX_FLOAT& fSize) { |
26 » CPDF_Rect crNew(crRect.left - fSize, | 25 CPDF_Rect crNew(crRect.left - fSize, crRect.bottom - fSize, |
27 » » » » » crRect.bottom - fSize, | 26 crRect.right + fSize, crRect.top + fSize); |
28 » » » » » crRect.right + fSize, | 27 crNew.Normalize(); |
29 » » » » » crRect.top + fSize); | 28 return crNew; |
30 » crNew.Normalize(); | |
31 » return crNew; | |
32 } | 29 } |
33 | 30 |
34 CPDF_Rect CFFL_Utils::DeflateRect(const CPDF_Rect & crRect,const FX_FLOAT & fSiz
e) | 31 CPDF_Rect CFFL_Utils::DeflateRect(const CPDF_Rect& crRect, |
35 { | 32 const FX_FLOAT& fSize) { |
36 » CPDF_Rect crNew(crRect.left + fSize, | 33 CPDF_Rect crNew(crRect.left + fSize, crRect.bottom + fSize, |
37 » » » » » crRect.bottom + fSize, | 34 crRect.right - fSize, crRect.top - fSize); |
38 » » » » » crRect.right - fSize, | 35 crNew.Normalize(); |
39 » » » » » crRect.top - fSize); | 36 return crNew; |
40 » crNew.Normalize(); | |
41 » return crNew; | |
42 } | 37 } |
43 | 38 |
44 FX_BOOL CFFL_Utils::TraceObject(CPDF_Object* pObj) | 39 FX_BOOL CFFL_Utils::TraceObject(CPDF_Object* pObj) { |
45 { | 40 if (!pObj) |
46 » if (!pObj) return FALSE; | 41 return FALSE; |
47 | 42 |
48 » FX_DWORD» dwObjNum = pObj->GetObjNum(); | 43 FX_DWORD dwObjNum = pObj->GetObjNum(); |
49 » switch (pObj->GetType()) | 44 switch (pObj->GetType()) { |
50 » { | 45 case PDFOBJ_ARRAY: { |
51 » case PDFOBJ_ARRAY: | 46 CPDF_Array* pArray = (CPDF_Array*)pObj; |
52 » » { | 47 for (FX_DWORD i = 0; i < pArray->GetCount(); i++) { |
53 » » » CPDF_Array* pArray = (CPDF_Array*)pObj; | 48 CPDF_Object* pElement = pArray->GetElementValue(i); |
54 » » » for (FX_DWORD i = 0; i < pArray->GetCount(); i ++) | 49 TraceObject(pElement); |
55 » » » { | 50 } |
56 » » » » CPDF_Object* pElement = pArray->GetElementValue(
i); | 51 } break; |
57 » » » » TraceObject(pElement); | |
58 » » » } | |
59 » » } | |
60 » » break; | |
61 | 52 |
62 » case PDFOBJ_DICTIONARY: | 53 case PDFOBJ_DICTIONARY: { |
63 » » { | 54 CPDF_Dictionary* pDict = (CPDF_Dictionary*)pObj; |
64 » » » CPDF_Dictionary* pDict = (CPDF_Dictionary*)pObj; | |
65 | 55 |
66 » » » FX_POSITION fPos = pDict->GetStartPos(); | 56 FX_POSITION fPos = pDict->GetStartPos(); |
67 » » » CFX_ByteString csKey; | 57 CFX_ByteString csKey; |
68 » » » do | 58 do { |
69 » » » { | 59 CPDF_Object* pElement = pDict->GetNextElement(fPos, csKey); |
70 » » » » CPDF_Object* pElement = pDict->GetNextElement(fP
os, csKey); | 60 // TRACE(csKey + "\n"); |
71 » » » » //TRACE(csKey + "\n"); | 61 if (!pElement) |
72 » » » » if (!pElement) break; | 62 break; |
73 » » » » TraceObject(pElement); | 63 TraceObject(pElement); |
74 » » » }while (TRUE); | 64 } while (TRUE); |
75 » » } | 65 } break; |
76 » » break; | |
77 | 66 |
78 » case PDFOBJ_STREAM: | 67 case PDFOBJ_STREAM: { |
79 » » { | 68 CPDF_Stream* pStream = (CPDF_Stream*)pObj; |
80 » » » CPDF_Stream* pStream = (CPDF_Stream*)pObj; | 69 CPDF_Dictionary* pDict = pStream->GetDict(); |
81 » » » CPDF_Dictionary* pDict = pStream->GetDict(); | 70 TraceObject(pDict); |
82 » » » TraceObject(pDict); | 71 } break; |
83 » » } | |
84 » » break; | |
85 | 72 |
86 » case PDFOBJ_REFERENCE: | 73 case PDFOBJ_REFERENCE: { |
87 » » { | 74 CPDF_Object* pDirectObj = pObj->GetDirect(); |
88 » » » CPDF_Object* pDirectObj = pObj->GetDirect(); | 75 TraceObject(pDirectObj); |
89 » » » TraceObject(pDirectObj); | 76 } break; |
90 » » } | |
91 » » break; | |
92 | 77 |
93 » case PDFOBJ_BOOLEAN: | 78 case PDFOBJ_BOOLEAN: |
94 » » break; | 79 break; |
95 » case PDFOBJ_NUMBER: | 80 case PDFOBJ_NUMBER: |
96 » » //TRACE("%d\n",(int32_t)pObj); | 81 // TRACE("%d\n",(int32_t)pObj); |
97 » » break; | 82 break; |
98 » case PDFOBJ_STRING: | 83 case PDFOBJ_STRING: |
99 » » //TRACE(((CPDF_String*)pObj)->GetString() + "\n"); | 84 // TRACE(((CPDF_String*)pObj)->GetString() + "\n"); |
100 » » break; | 85 break; |
101 » case PDFOBJ_NAME: | 86 case PDFOBJ_NAME: |
102 » » //TRACE(((CPDF_Name*)pObj)->GetString() + "\n"); | 87 // TRACE(((CPDF_Name*)pObj)->GetString() + "\n"); |
103 » » break; | 88 break; |
104 » case PDFOBJ_NULL: | 89 case PDFOBJ_NULL: |
105 //» case PDFOBJ_KEYWORD: | 90 //» case PDFOBJ_KEYWORD: |
106 //» case PDFOBJ_EOF: | 91 //» case PDFOBJ_EOF: |
107 » default: | 92 default: |
108 » » break; | 93 break; |
109 » } | 94 } |
110 » if (dwObjNum == 0) return FALSE; | 95 if (dwObjNum == 0) |
| 96 return FALSE; |
111 | 97 |
112 » return TRUE; | 98 return TRUE; |
113 } | 99 } |
114 | |
OLD | NEW |