Chromium Code Reviews| 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 "../../../include/fpdfapi/fpdf_parser.h" | 7 #include "../../../include/fpdfapi/fpdf_parser.h" |
| 8 void CPDF_Object::Release() | 8 void CPDF_Object::Release() |
| 9 { | 9 { |
| 10 if (this == NULL) { | |
| 11 return; | |
| 12 } | |
| 13 if (m_ObjNum) { | 10 if (m_ObjNum) { |
| 14 return; | 11 return; |
| 15 } | 12 } |
| 16 Destroy(); | 13 Destroy(); |
| 17 } | 14 } |
| 18 void CPDF_Object::Destroy() | 15 void CPDF_Object::Destroy() |
| 19 { | 16 { |
| 20 switch (m_Type) { | 17 switch (m_Type) { |
| 21 case PDFOBJ_STRING: | 18 case PDFOBJ_STRING: |
| 22 delete (CPDF_String*)this; | 19 delete (CPDF_String*)this; |
| 23 break; | 20 break; |
| 24 case PDFOBJ_NAME: | 21 case PDFOBJ_NAME: |
| 25 delete (CPDF_Name*)this; | 22 delete (CPDF_Name*)this; |
| 26 break; | 23 break; |
| 27 case PDFOBJ_ARRAY: | 24 case PDFOBJ_ARRAY: |
| 28 delete (CPDF_Array*)this; | 25 delete (CPDF_Array*)this; |
| 29 break; | 26 break; |
| 30 case PDFOBJ_DICTIONARY: | 27 case PDFOBJ_DICTIONARY: |
| 31 delete (CPDF_Dictionary*)this; | 28 delete (CPDF_Dictionary*)this; |
| 32 break; | 29 break; |
| 33 case PDFOBJ_STREAM: | 30 case PDFOBJ_STREAM: |
| 34 delete (CPDF_Stream*)this; | 31 delete (CPDF_Stream*)this; |
| 35 break; | 32 break; |
| 36 default: | 33 default: |
| 37 delete this; | 34 delete this; |
| 38 } | 35 } |
| 39 } | 36 } |
| 40 CFX_ByteString CPDF_Object::GetString() const | 37 CFX_ByteString CPDF_Object::GetString() const |
| 41 { | 38 { |
| 42 if (this == NULL) { | |
| 43 return CFX_ByteString(); | |
| 44 } | |
| 45 switch (m_Type) { | 39 switch (m_Type) { |
| 46 case PDFOBJ_BOOLEAN: | 40 case PDFOBJ_BOOLEAN: |
| 47 return ((CPDF_Boolean*)this)->m_bValue ? "true" : "false"; | 41 return ((CPDF_Boolean*)this)->m_bValue ? "true" : "false"; |
| 48 case PDFOBJ_NUMBER: | 42 case PDFOBJ_NUMBER: |
| 49 return ((CPDF_Number*)this)->GetString(); | 43 return ((CPDF_Number*)this)->GetString(); |
| 50 case PDFOBJ_STRING: | 44 case PDFOBJ_STRING: |
| 51 return ((CPDF_String*)this)->m_String; | 45 return ((CPDF_String*)this)->m_String; |
| 52 case PDFOBJ_NAME: | 46 case PDFOBJ_NAME: |
| 53 return ((CPDF_Name*)this)->m_Name; | 47 return ((CPDF_Name*)this)->m_Name; |
| 54 case PDFOBJ_REFERENCE: { | 48 case PDFOBJ_REFERENCE: { |
| 55 CPDF_Reference* pRef = (CPDF_Reference*)(FX_LPVOID)this; | 49 CPDF_Reference* pRef = (CPDF_Reference*)(FX_LPVOID)this; |
| 56 if (pRef->m_pObjList == NULL) { | 50 if (pRef->m_pObjList == NULL) { |
| 57 break; | 51 break; |
| 58 } | 52 } |
| 59 CPDF_Object* pObj = pRef->m_pObjList->GetIndirectObject(pRef->m_ RefObjNum); | 53 CPDF_Object* pObj = pRef->m_pObjList->GetIndirectObject(pRef->m_ RefObjNum); |
| 60 if (pObj == NULL) { | 54 if (pObj == NULL) { |
| 61 return CFX_ByteString(); | 55 return CFX_ByteString(); |
| 62 } | 56 } |
| 63 return pObj->GetString(); | 57 return pObj->GetString(); |
| 64 } | 58 } |
| 65 } | 59 } |
| 66 return CFX_ByteString(); | 60 return CFX_ByteString(); |
| 67 } | 61 } |
| 68 CFX_ByteStringC CPDF_Object::GetConstString() const | 62 CFX_ByteStringC CPDF_Object::GetConstString() const |
| 69 { | 63 { |
| 70 if (this == NULL) { | |
| 71 return CFX_ByteStringC(); | |
| 72 } | |
| 73 switch (m_Type) { | 64 switch (m_Type) { |
| 74 case PDFOBJ_STRING: | 65 case PDFOBJ_STRING: |
| 75 return CFX_ByteStringC((FX_LPCBYTE)((CPDF_String*)this)->m_String, ( (CPDF_String*)this)->m_String.GetLength()); | 66 return CFX_ByteStringC((FX_LPCBYTE)((CPDF_String*)this)->m_String, ( (CPDF_String*)this)->m_String.GetLength()); |
| 76 case PDFOBJ_NAME: | 67 case PDFOBJ_NAME: |
| 77 return CFX_ByteStringC((FX_LPCBYTE)((CPDF_Name*)this)->m_Name, ((CPD F_Name*)this)->m_Name.GetLength()); | 68 return CFX_ByteStringC((FX_LPCBYTE)((CPDF_Name*)this)->m_Name, ((CPD F_Name*)this)->m_Name.GetLength()); |
| 78 case PDFOBJ_REFERENCE: { | 69 case PDFOBJ_REFERENCE: { |
| 79 CPDF_Reference* pRef = (CPDF_Reference*)(FX_LPVOID)this; | 70 CPDF_Reference* pRef = (CPDF_Reference*)(FX_LPVOID)this; |
| 80 if (pRef->m_pObjList == NULL) { | 71 if (pRef->m_pObjList == NULL) { |
| 81 break; | 72 break; |
| 82 } | 73 } |
| 83 CPDF_Object* pObj = pRef->m_pObjList->GetIndirectObject(pRef->m_ RefObjNum); | 74 CPDF_Object* pObj = pRef->m_pObjList->GetIndirectObject(pRef->m_ RefObjNum); |
| 84 if (pObj == NULL) { | 75 if (pObj == NULL) { |
| 85 return CFX_ByteStringC(); | 76 return CFX_ByteStringC(); |
| 86 } | 77 } |
| 87 return pObj->GetConstString(); | 78 return pObj->GetConstString(); |
| 88 } | 79 } |
| 89 } | 80 } |
| 90 return CFX_ByteStringC(); | 81 return CFX_ByteStringC(); |
| 91 } | 82 } |
| 92 FX_FLOAT CPDF_Object::GetNumber() const | 83 FX_FLOAT CPDF_Object::GetNumber() const |
| 93 { | 84 { |
| 94 if (this == NULL) { | |
| 95 return 0; | |
| 96 } | |
| 97 switch (m_Type) { | 85 switch (m_Type) { |
| 98 case PDFOBJ_NUMBER: | 86 case PDFOBJ_NUMBER: |
| 99 return ((CPDF_Number*)this)->GetNumber(); | 87 return ((CPDF_Number*)this)->GetNumber(); |
| 100 case PDFOBJ_REFERENCE: { | 88 case PDFOBJ_REFERENCE: { |
| 101 CPDF_Reference* pRef = (CPDF_Reference*)(FX_LPVOID)this; | 89 CPDF_Reference* pRef = (CPDF_Reference*)(FX_LPVOID)this; |
| 102 if (pRef->m_pObjList == NULL) { | 90 if (pRef->m_pObjList == NULL) { |
| 103 break; | 91 break; |
| 104 } | 92 } |
| 105 CPDF_Object* pObj = pRef->m_pObjList->GetIndirectObject(pRef->m_ RefObjNum); | 93 CPDF_Object* pObj = pRef->m_pObjList->GetIndirectObject(pRef->m_ RefObjNum); |
| 106 if (pObj == NULL) { | 94 if (pObj == NULL) { |
| 107 return 0; | 95 return 0; |
| 108 } | 96 } |
| 109 return pObj->GetNumber(); | 97 return pObj->GetNumber(); |
| 110 } | 98 } |
| 111 } | 99 } |
| 112 return 0; | 100 return 0; |
| 113 } | 101 } |
| 114 FX_FLOAT CPDF_Object::GetNumber16() const | 102 FX_FLOAT CPDF_Object::GetNumber16() const |
| 115 { | 103 { |
| 116 return GetNumber(); | 104 return GetNumber(); |
| 117 } | 105 } |
| 118 int CPDF_Object::GetInteger() const | 106 int CPDF_Object::GetInteger() const |
| 119 { | 107 { |
| 120 if (this == NULL) { | |
| 121 return 0; | |
| 122 } | |
| 123 switch (m_Type) { | 108 switch (m_Type) { |
| 124 case PDFOBJ_BOOLEAN: | 109 case PDFOBJ_BOOLEAN: |
| 125 return ((CPDF_Boolean*)this)->m_bValue; | 110 return ((CPDF_Boolean*)this)->m_bValue; |
| 126 case PDFOBJ_NUMBER: | 111 case PDFOBJ_NUMBER: |
| 127 return ((CPDF_Number*)this)->GetInteger(); | 112 return ((CPDF_Number*)this)->GetInteger(); |
| 128 case PDFOBJ_REFERENCE: { | 113 case PDFOBJ_REFERENCE: { |
| 129 CPDF_Reference* pRef = (CPDF_Reference*)(FX_LPVOID)this; | 114 CPDF_Reference* pRef = (CPDF_Reference*)(FX_LPVOID)this; |
| 130 PARSE_CONTEXT context; | 115 PARSE_CONTEXT context; |
| 131 FXSYS_memset32(&context, 0, sizeof(PARSE_CONTEXT)); | 116 FXSYS_memset32(&context, 0, sizeof(PARSE_CONTEXT)); |
| 132 if (pRef->m_pObjList == NULL) { | 117 if (pRef->m_pObjList == NULL) { |
| 133 return 0; | 118 return 0; |
| 134 } | 119 } |
| 135 CPDF_Object* pObj = pRef->m_pObjList->GetIndirectObject(pRef->m_ RefObjNum, &context); | 120 CPDF_Object* pObj = pRef->m_pObjList->GetIndirectObject(pRef->m_ RefObjNum, &context); |
| 136 if (pObj == NULL) { | 121 if (pObj == NULL) { |
| 137 return 0; | 122 return 0; |
| 138 } | 123 } |
| 139 return pObj->GetInteger(); | 124 return pObj->GetInteger(); |
| 140 } | 125 } |
| 141 } | 126 } |
| 142 return 0; | 127 return 0; |
| 143 } | 128 } |
| 144 CPDF_Dictionary* CPDF_Object::GetDict() const | 129 CPDF_Dictionary* CPDF_Object::GetDict() const |
| 145 { | 130 { |
| 146 if (this == NULL) { | |
| 147 return NULL; | |
| 148 } | |
| 149 switch (m_Type) { | 131 switch (m_Type) { |
| 150 case PDFOBJ_DICTIONARY: | 132 case PDFOBJ_DICTIONARY: |
| 151 return (CPDF_Dictionary*)this; | 133 return (CPDF_Dictionary*)this; |
| 152 case PDFOBJ_STREAM: | 134 case PDFOBJ_STREAM: |
| 153 return ((CPDF_Stream*)this)->GetDict(); | 135 return ((CPDF_Stream*)this)->GetDict(); |
| 154 case PDFOBJ_REFERENCE: { | 136 case PDFOBJ_REFERENCE: { |
| 155 CPDF_Reference* pRef = (CPDF_Reference*)this; | 137 CPDF_Reference* pRef = (CPDF_Reference*)this; |
| 156 if (pRef->m_pObjList == NULL) { | 138 if (pRef->m_pObjList == NULL) { |
| 157 break; | 139 break; |
| 158 } | 140 } |
| 159 CPDF_Object* pObj = pRef->m_pObjList->GetIndirectObject(pRef->m_ RefObjNum); | 141 CPDF_Object* pObj = pRef->m_pObjList->GetIndirectObject(pRef->m_ RefObjNum); |
| 160 if (pObj == NULL) { | 142 if (pObj == NULL) { |
| 161 return NULL; | 143 return NULL; |
| 162 } | 144 } |
| 163 return pObj->GetDict(); | 145 return pObj->GetDict(); |
| 164 } | 146 } |
| 165 } | 147 } |
| 166 return NULL; | 148 return NULL; |
| 167 } | 149 } |
| 168 CPDF_Array* CPDF_Object::GetArray() const | 150 CPDF_Array* CPDF_Object::GetArray() const |
| 169 { | 151 { |
| 170 if (this == NULL) { | 152 if (m_Type == PDFOBJ_ARRAY) |
| 153 return (CPDF_Array*)this; | |
| 154 else | |
| 171 return NULL; | 155 return NULL; |
| 172 } | |
| 173 if (m_Type == PDFOBJ_ARRAY) { | |
| 174 return (CPDF_Array*)this; | |
| 175 } | |
| 176 return NULL; | |
| 177 } | 156 } |
| 178 void CPDF_Object::SetString(const CFX_ByteString& str) | 157 void CPDF_Object::SetString(const CFX_ByteString& str) |
| 179 { | 158 { |
| 180 ASSERT(this != NULL); | 159 ASSERT(this != NULL); |
| 181 switch (m_Type) { | 160 switch (m_Type) { |
| 182 case PDFOBJ_BOOLEAN: | 161 case PDFOBJ_BOOLEAN: |
| 183 ((CPDF_Boolean*)this)->m_bValue = str == FX_BSTRC("true") ? 1 : 0; | 162 ((CPDF_Boolean*)this)->m_bValue = str == FX_BSTRC("true") ? 1 : 0; |
| 184 return; | 163 return; |
| 185 case PDFOBJ_NUMBER: | 164 case PDFOBJ_NUMBER: |
| 186 ((CPDF_Number*)this)->SetString(str); | 165 ((CPDF_Number*)this)->SetString(str); |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 200 return m_Type; | 179 return m_Type; |
| 201 } | 180 } |
| 202 CPDF_Reference* pRef = (CPDF_Reference*)this; | 181 CPDF_Reference* pRef = (CPDF_Reference*)this; |
| 203 return pRef->m_pObjList->GetIndirectType(pRef->m_RefObjNum); | 182 return pRef->m_pObjList->GetIndirectType(pRef->m_RefObjNum); |
| 204 } | 183 } |
| 205 FX_BOOL CPDF_Object::IsIdentical(CPDF_Object* pOther) const | 184 FX_BOOL CPDF_Object::IsIdentical(CPDF_Object* pOther) const |
| 206 { | 185 { |
| 207 if (this == pOther) { | 186 if (this == pOther) { |
| 208 return TRUE; | 187 return TRUE; |
| 209 } | 188 } |
| 210 if (this == NULL || pOther == NULL) { | 189 if (pOther == NULL) { |
| 211 return FALSE; | 190 return FALSE; |
| 212 } | 191 } |
| 213 if (pOther->m_Type != m_Type) { | 192 if (pOther->m_Type != m_Type) { |
| 214 if (m_Type == PDFOBJ_REFERENCE) { | 193 if (m_Type == PDFOBJ_REFERENCE && GetDirect()) { |
| 215 return GetDirect()->IsIdentical(pOther); | 194 return GetDirect()->IsIdentical(pOther); |
| 216 } else if (pOther->m_Type == PDFOBJ_REFERENCE) { | 195 } else if (pOther->m_Type == PDFOBJ_REFERENCE) { |
| 217 return IsIdentical(pOther->GetDirect()); | 196 return IsIdentical(pOther->GetDirect()); |
| 218 } | 197 } |
| 219 return FALSE; | 198 return FALSE; |
| 220 } | 199 } |
| 221 switch (m_Type) { | 200 switch (m_Type) { |
| 222 case PDFOBJ_BOOLEAN: | 201 case PDFOBJ_BOOLEAN: |
| 223 return (((CPDF_Boolean*)this)->Identical((CPDF_Boolean*)pOther)); | 202 return (((CPDF_Boolean*)this)->Identical((CPDF_Boolean*)pOther)); |
| 224 case PDFOBJ_NUMBER: | 203 case PDFOBJ_NUMBER: |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 235 return TRUE; | 214 return TRUE; |
| 236 case PDFOBJ_STREAM: | 215 case PDFOBJ_STREAM: |
| 237 return (((CPDF_Stream*)this)->Identical((CPDF_Stream*)pOther)); | 216 return (((CPDF_Stream*)this)->Identical((CPDF_Stream*)pOther)); |
| 238 case PDFOBJ_REFERENCE: | 217 case PDFOBJ_REFERENCE: |
| 239 return (((CPDF_Reference*)this)->Identical((CPDF_Reference*)pOther)) ; | 218 return (((CPDF_Reference*)this)->Identical((CPDF_Reference*)pOther)) ; |
| 240 } | 219 } |
| 241 return FALSE; | 220 return FALSE; |
| 242 } | 221 } |
| 243 CPDF_Object* CPDF_Object::GetDirect() const | 222 CPDF_Object* CPDF_Object::GetDirect() const |
| 244 { | 223 { |
| 245 if (this == NULL) { | |
| 246 return NULL; | |
| 247 } | |
| 248 if (m_Type != PDFOBJ_REFERENCE) { | 224 if (m_Type != PDFOBJ_REFERENCE) { |
| 249 return (CPDF_Object*)this; | 225 return (CPDF_Object*)this; |
| 250 } | 226 } |
| 251 CPDF_Reference* pRef = (CPDF_Reference*)(FX_LPVOID)this; | 227 CPDF_Reference* pRef = (CPDF_Reference*)(FX_LPVOID)this; |
| 252 if (pRef->m_pObjList == NULL) { | 228 if (pRef->m_pObjList == NULL) { |
| 253 return NULL; | 229 return NULL; |
| 254 } | 230 } |
| 255 return pRef->m_pObjList->GetIndirectObject(pRef->m_RefObjNum); | 231 return pRef->m_pObjList->GetIndirectObject(pRef->m_RefObjNum); |
| 256 } | 232 } |
| 257 CPDF_Object* CPDF_Object::Clone(FX_BOOL bDirect) const | 233 CPDF_Object* CPDF_Object::Clone(FX_BOOL bDirect) const |
| 258 { | 234 { |
| 259 CFX_MapPtrToPtr visited; | 235 CFX_MapPtrToPtr visited; |
| 260 return CloneInternal(bDirect, &visited); | 236 return CloneInternal(bDirect, &visited); |
| 261 } | 237 } |
| 262 CPDF_Object* CPDF_Object::CloneInternal(FX_BOOL bDirect, CFX_MapPtrToPtr* visite d) const | 238 CPDF_Object* CPDF_Object::CloneInternal(FX_BOOL bDirect, CFX_MapPtrToPtr* visite d) const |
| 263 { | 239 { |
| 264 if (this == NULL) { | |
| 265 return NULL; | |
| 266 } | |
| 267 switch (m_Type) { | 240 switch (m_Type) { |
| 268 case PDFOBJ_BOOLEAN: | 241 case PDFOBJ_BOOLEAN: |
| 269 return FX_NEW CPDF_Boolean(((CPDF_Boolean*)this)->m_bValue); | 242 return FX_NEW CPDF_Boolean(((CPDF_Boolean*)this)->m_bValue); |
| 270 case PDFOBJ_NUMBER: | 243 case PDFOBJ_NUMBER: |
| 271 return FX_NEW CPDF_Number(((CPDF_Number*)this)->m_bInteger, &((CPDF_ Number*)this)->m_Integer); | 244 return FX_NEW CPDF_Number(((CPDF_Number*)this)->m_bInteger, &((CPDF_ Number*)this)->m_Integer); |
| 272 case PDFOBJ_STRING: | 245 case PDFOBJ_STRING: |
| 273 return FX_NEW CPDF_String(((CPDF_String*)this)->m_String, ((CPDF_Str ing*)this)->IsHex()); | 246 return FX_NEW CPDF_String(((CPDF_String*)this)->m_String, ((CPDF_Str ing*)this)->IsHex()); |
| 274 case PDFOBJ_NAME: | 247 case PDFOBJ_NAME: |
| 275 return FX_NEW CPDF_Name(((CPDF_Name*)this)->m_Name); | 248 return FX_NEW CPDF_Name(((CPDF_Name*)this)->m_Name); |
| 276 case PDFOBJ_ARRAY: { | 249 case PDFOBJ_ARRAY: { |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 296 return pCopy; | 269 return pCopy; |
| 297 } | 270 } |
| 298 case PDFOBJ_NULL: { | 271 case PDFOBJ_NULL: { |
| 299 return FX_NEW CPDF_Null; | 272 return FX_NEW CPDF_Null; |
| 300 } | 273 } |
| 301 case PDFOBJ_STREAM: { | 274 case PDFOBJ_STREAM: { |
| 302 CPDF_Stream* pThis = (CPDF_Stream*)this; | 275 CPDF_Stream* pThis = (CPDF_Stream*)this; |
| 303 CPDF_StreamAcc acc; | 276 CPDF_StreamAcc acc; |
| 304 acc.LoadAllData(pThis, TRUE); | 277 acc.LoadAllData(pThis, TRUE); |
| 305 FX_DWORD streamSize = acc.GetSize(); | 278 FX_DWORD streamSize = acc.GetSize(); |
| 306 CPDF_Stream* pObj = FX_NEW CPDF_Stream(acc.DetachData(), streamS ize, (CPDF_Dictionary*)((CPDF_Object*)pThis->GetDict())->CloneInternal(bDirect, visited)); | 279 CPDF_Stream* pObj; |
| 280 if (pThis->GetDict()) | |
| 281 pObj = FX_NEW CPDF_Stream(acc.DetachData(), streamSize, (CPD F_Dictionary*)((CPDF_Object*)pThis->GetDict())->CloneInternal(bDirect, visited)) ; | |
| 282 else | |
| 283 pObj = FX_NEW CPDF_Stream(acc.DetachData(), streamSize, NULL ); | |
| 307 return pObj; | 284 return pObj; |
| 308 } | 285 } |
| 309 case PDFOBJ_REFERENCE: { | 286 case PDFOBJ_REFERENCE: { |
| 310 CPDF_Reference* pRef = (CPDF_Reference*)this; | 287 CPDF_Reference* pRef = (CPDF_Reference*)this; |
| 311 FX_DWORD obj_num = pRef->m_RefObjNum; | 288 FX_DWORD obj_num = pRef->m_RefObjNum; |
| 312 if (bDirect && !visited->GetValueAt((void*)(FX_UINTPTR)obj_num)) { | 289 if (bDirect && !visited->GetValueAt((void*)(FX_UINTPTR)obj_num)) { |
| 313 visited->SetAt((void*)(FX_UINTPTR)obj_num, (void*)1); | 290 visited->SetAt((void*)(FX_UINTPTR)obj_num, (void*)1); |
| 314 CPDF_Object* ret = pRef->GetDirect()->CloneInternal(TRUE, vi sited); | 291 CPDF_Object* ret; |
| 292 if (pRef->GetDirect()) | |
| 293 ret = pRef->GetDirect()->CloneInternal(TRUE, visited); | |
| 294 else | |
| 295 ret = NULL; | |
| 315 return ret; | 296 return ret; |
| 316 } else { | 297 } else { |
| 317 return FX_NEW CPDF_Reference(pRef->m_pObjList, obj_num); | 298 return FX_NEW CPDF_Reference(pRef->m_pObjList, obj_num); |
| 318 } | 299 } |
| 319 } | 300 } |
| 320 } | 301 } |
| 321 return NULL; | 302 return NULL; |
| 322 } | 303 } |
| 323 CPDF_Object* CPDF_Object::CloneRef(CPDF_IndirectObjects* pDoc) const | 304 CPDF_Object* CPDF_Object::CloneRef(CPDF_IndirectObjects* pDoc) const |
| 324 { | 305 { |
| 325 if (this == NULL) { | |
| 326 return NULL; | |
| 327 } | |
| 328 if (m_ObjNum) { | 306 if (m_ObjNum) { |
| 329 return FX_NEW CPDF_Reference(pDoc, m_ObjNum); | 307 return FX_NEW CPDF_Reference(pDoc, m_ObjNum); |
| 330 } | 308 } |
| 331 return Clone(); | 309 return Clone(); |
| 332 } | 310 } |
| 333 CFX_WideString CPDF_Object::GetUnicodeText(CFX_CharMap* pCharMap) const | 311 CFX_WideString CPDF_Object::GetUnicodeText(CFX_CharMap* pCharMap) const |
| 334 { | 312 { |
| 335 if (this == NULL) { | |
| 336 return CFX_WideString(); | |
| 337 } | |
| 338 if (m_Type == PDFOBJ_STRING) { | 313 if (m_Type == PDFOBJ_STRING) { |
| 339 return PDF_DecodeText(((CPDF_String*)this)->m_String, pCharMap); | 314 return PDF_DecodeText(((CPDF_String*)this)->m_String, pCharMap); |
| 340 } else if (m_Type == PDFOBJ_STREAM) { | 315 } else if (m_Type == PDFOBJ_STREAM) { |
| 341 CPDF_StreamAcc stream; | 316 CPDF_StreamAcc stream; |
| 342 stream.LoadAllData((CPDF_Stream*)this, FALSE); | 317 stream.LoadAllData((CPDF_Stream*)this, FALSE); |
| 343 CFX_WideString result = PDF_DecodeText(stream.GetData(), stream.GetSize( ), pCharMap); | 318 CFX_WideString result = PDF_DecodeText(stream.GetData(), stream.GetSize( ), pCharMap); |
| 344 return result; | 319 return result; |
| 345 } else if (m_Type == PDFOBJ_NAME) { | 320 } else if (m_Type == PDFOBJ_NAME) { |
| 346 return PDF_DecodeText(((CPDF_Name*)this)->m_Name, pCharMap); | 321 return PDF_DecodeText(((CPDF_Name*)this)->m_Name, pCharMap); |
| 347 } | 322 } |
| 348 return CFX_WideString(); | 323 return CFX_WideString(); |
| 349 } | 324 } |
| 350 void CPDF_Object::SetUnicodeText(FX_LPCWSTR pUnicodes, int len) | 325 void CPDF_Object::SetUnicodeText(FX_LPCWSTR pUnicodes, int len) |
| 351 { | 326 { |
| 352 if (this == NULL) { | |
| 353 return; | |
| 354 } | |
| 355 if (m_Type == PDFOBJ_STRING) { | 327 if (m_Type == PDFOBJ_STRING) { |
| 356 ((CPDF_String*)this)->m_String = PDF_EncodeText(pUnicodes, len); | 328 ((CPDF_String*)this)->m_String = PDF_EncodeText(pUnicodes, len); |
| 357 } else if (m_Type == PDFOBJ_STREAM) { | 329 } else if (m_Type == PDFOBJ_STREAM) { |
| 358 CFX_ByteString result = PDF_EncodeText(pUnicodes, len); | 330 CFX_ByteString result = PDF_EncodeText(pUnicodes, len); |
| 359 ((CPDF_Stream*)this)->SetData((FX_LPBYTE)(FX_LPCSTR)result, result.GetLe ngth(), FALSE, FALSE); | 331 ((CPDF_Stream*)this)->SetData((FX_LPBYTE)(FX_LPCSTR)result, result.GetLe ngth(), FALSE, FALSE); |
| 360 } | 332 } |
| 361 } | 333 } |
| 362 CPDF_Number::CPDF_Number(int value) | 334 CPDF_Number::CPDF_Number(int value) |
| 363 { | 335 { |
| 364 m_Type = PDFOBJ_NUMBER; | 336 m_Type = PDFOBJ_NUMBER; |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 404 { | 376 { |
| 405 m_Type = PDFOBJ_STRING; | 377 m_Type = PDFOBJ_STRING; |
| 406 m_String = PDF_EncodeText(str, str.GetLength()); | 378 m_String = PDF_EncodeText(str, str.GetLength()); |
| 407 m_bHex = FALSE; | 379 m_bHex = FALSE; |
| 408 } | 380 } |
| 409 CPDF_Array::~CPDF_Array() | 381 CPDF_Array::~CPDF_Array() |
| 410 { | 382 { |
| 411 int size = m_Objects.GetSize(); | 383 int size = m_Objects.GetSize(); |
| 412 CPDF_Object** pList = (CPDF_Object**)m_Objects.GetData(); | 384 CPDF_Object** pList = (CPDF_Object**)m_Objects.GetData(); |
| 413 for (int i = 0; i < size; i ++) { | 385 for (int i = 0; i < size; i ++) { |
| 414 pList[i]->Release(); | 386 if (pList[i]) |
| 387 pList[i]->Release(); | |
| 415 } | 388 } |
| 416 } | 389 } |
| 417 CFX_FloatRect CPDF_Array::GetRect() | 390 CFX_FloatRect CPDF_Array::GetRect() |
| 418 { | 391 { |
| 419 CFX_FloatRect rect; | 392 CFX_FloatRect rect; |
| 420 if (this == NULL || m_Type != PDFOBJ_ARRAY || m_Objects.GetSize() != 4) { | 393 if (m_Type != PDFOBJ_ARRAY || m_Objects.GetSize() != 4) { |
| 421 return rect; | 394 return rect; |
| 422 } | 395 } |
| 423 rect.left = GetNumber(0); | 396 rect.left = GetNumber(0); |
| 424 rect.bottom = GetNumber(1); | 397 rect.bottom = GetNumber(1); |
| 425 rect.right = GetNumber(2); | 398 rect.right = GetNumber(2); |
| 426 rect.top = GetNumber(3); | 399 rect.top = GetNumber(3); |
| 427 return rect; | 400 return rect; |
| 428 } | 401 } |
| 429 CFX_AffineMatrix CPDF_Array::GetMatrix() | 402 CFX_AffineMatrix CPDF_Array::GetMatrix() |
| 430 { | 403 { |
| 431 CFX_AffineMatrix matrix; | 404 CFX_AffineMatrix matrix; |
| 432 if (this == NULL || m_Type != PDFOBJ_ARRAY || m_Objects.GetSize() != 6) { | 405 if (m_Type != PDFOBJ_ARRAY || m_Objects.GetSize() != 6) { |
| 433 return matrix; | 406 return matrix; |
| 434 } | 407 } |
| 435 matrix.Set(GetNumber(0), GetNumber(1), GetNumber(2), GetNumber(3), GetNumber (4), GetNumber(5)); | 408 matrix.Set(GetNumber(0), GetNumber(1), GetNumber(2), GetNumber(3), GetNumber (4), GetNumber(5)); |
| 436 return matrix; | 409 return matrix; |
| 437 } | 410 } |
| 438 CPDF_Object* CPDF_Array::GetElement(FX_DWORD i) const | 411 CPDF_Object* CPDF_Array::GetElement(FX_DWORD i) const |
| 439 { | 412 { |
| 440 if (this == NULL) { | |
| 441 return NULL; | |
| 442 } | |
| 443 if (i >= (FX_DWORD)m_Objects.GetSize()) { | 413 if (i >= (FX_DWORD)m_Objects.GetSize()) { |
| 444 return NULL; | 414 return NULL; |
| 445 } | 415 } |
| 446 return (CPDF_Object*)m_Objects.GetAt(i); | 416 return (CPDF_Object*)m_Objects.GetAt(i); |
| 447 } | 417 } |
| 448 CPDF_Object* CPDF_Array::GetElementValue(FX_DWORD i) const | 418 CPDF_Object* CPDF_Array::GetElementValue(FX_DWORD i) const |
| 449 { | 419 { |
| 450 if (this == NULL) { | |
| 451 return NULL; | |
| 452 } | |
| 453 if (i >= (FX_DWORD)m_Objects.GetSize()) { | 420 if (i >= (FX_DWORD)m_Objects.GetSize()) { |
| 454 return NULL; | 421 return NULL; |
| 455 } | 422 } |
| 456 return ((CPDF_Object*)m_Objects.GetAt(i))->GetDirect(); | 423 return ((CPDF_Object*)m_Objects.GetAt(i))->GetDirect(); |
| 457 } | 424 } |
| 458 CFX_ByteString CPDF_Array::GetString(FX_DWORD i) const | 425 CFX_ByteString CPDF_Array::GetString(FX_DWORD i) const |
| 459 { | 426 { |
| 460 if (this && i < (FX_DWORD)m_Objects.GetSize()) { | 427 if (i < (FX_DWORD)m_Objects.GetSize()) { |
| 461 CPDF_Object* p = (CPDF_Object*)m_Objects.GetAt(i); | 428 CPDF_Object* p = (CPDF_Object*)m_Objects.GetAt(i); |
| 462 return p->GetString(); | 429 return p->GetString(); |
| 463 } | 430 } |
| 464 return CFX_ByteString(); | 431 else |
| 432 return CFX_ByteString(); | |
| 465 } | 433 } |
| 466 CFX_ByteStringC CPDF_Array::GetConstString(FX_DWORD i) const | 434 CFX_ByteStringC CPDF_Array::GetConstString(FX_DWORD i) const |
| 467 { | 435 { |
| 468 if (this && i < (FX_DWORD)m_Objects.GetSize()) { | 436 if (i < (FX_DWORD)m_Objects.GetSize()) { |
| 469 CPDF_Object* p = (CPDF_Object*)m_Objects.GetAt(i); | 437 CPDF_Object* p = (CPDF_Object*)m_Objects.GetAt(i); |
| 470 return p->GetConstString(); | 438 return p->GetConstString(); |
| 471 } | 439 } |
| 472 return CFX_ByteStringC(); | 440 else |
| 441 return CFX_ByteStringC(); | |
| 473 } | 442 } |
| 474 int CPDF_Array::GetInteger(FX_DWORD i) const | 443 int CPDF_Array::GetInteger(FX_DWORD i) const |
| 475 { | 444 { |
| 476 if (this == NULL || i >= (FX_DWORD)m_Objects.GetSize()) { | 445 if (i >= (FX_DWORD)m_Objects.GetSize()) { |
| 477 return 0; | 446 return 0; |
| 478 } | 447 } |
| 479 CPDF_Object* p = (CPDF_Object*)m_Objects.GetAt(i); | 448 CPDF_Object* p = (CPDF_Object*)m_Objects.GetAt(i); |
| 480 return p->GetInteger(); | 449 return p->GetInteger(); |
| 481 } | 450 } |
| 482 FX_FLOAT CPDF_Array::GetNumber(FX_DWORD i) const | 451 FX_FLOAT CPDF_Array::GetNumber(FX_DWORD i) const |
| 483 { | 452 { |
| 484 if (this == NULL || i >= (FX_DWORD)m_Objects.GetSize()) { | 453 if (i >= (FX_DWORD)m_Objects.GetSize()) { |
| 485 return 0; | 454 return 0; |
| 486 } | 455 } |
| 487 CPDF_Object* p = (CPDF_Object*)m_Objects.GetAt(i); | 456 CPDF_Object* p = (CPDF_Object*)m_Objects.GetAt(i); |
| 488 return p->GetNumber(); | 457 return p->GetNumber(); |
| 489 } | 458 } |
| 490 CPDF_Dictionary* CPDF_Array::GetDict(FX_DWORD i) const | 459 CPDF_Dictionary* CPDF_Array::GetDict(FX_DWORD i) const |
| 491 { | 460 { |
| 492 CPDF_Object* p = GetElementValue(i); | 461 CPDF_Object* p = GetElementValue(i); |
| 493 if (p == NULL) { | 462 if (p == NULL) { |
| 494 return NULL; | 463 return NULL; |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 510 CPDF_Array* CPDF_Array::GetArray(FX_DWORD i) const | 479 CPDF_Array* CPDF_Array::GetArray(FX_DWORD i) const |
| 511 { | 480 { |
| 512 CPDF_Object* p = GetElementValue(i); | 481 CPDF_Object* p = GetElementValue(i); |
| 513 if (p == NULL || p->GetType() != PDFOBJ_ARRAY) { | 482 if (p == NULL || p->GetType() != PDFOBJ_ARRAY) { |
| 514 return NULL; | 483 return NULL; |
| 515 } | 484 } |
| 516 return (CPDF_Array*)p; | 485 return (CPDF_Array*)p; |
| 517 } | 486 } |
| 518 void CPDF_Array::RemoveAt(FX_DWORD i) | 487 void CPDF_Array::RemoveAt(FX_DWORD i) |
| 519 { | 488 { |
| 520 ASSERT(this != NULL && m_Type == PDFOBJ_ARRAY); | 489 ASSERT(m_Type == PDFOBJ_ARRAY); |
| 521 if (i >= (FX_DWORD)m_Objects.GetSize()) { | 490 if (i >= (FX_DWORD)m_Objects.GetSize()) { |
| 522 return; | 491 return; |
| 523 } | 492 } |
| 524 CPDF_Object* p = (CPDF_Object*)m_Objects.GetAt(i); | 493 CPDF_Object* p = (CPDF_Object*)m_Objects.GetAt(i); |
| 525 p->Release(); | 494 if (p) |
| 495 p->Release(); | |
| 526 m_Objects.RemoveAt(i); | 496 m_Objects.RemoveAt(i); |
| 527 } | 497 } |
| 528 void CPDF_Array::SetAt(FX_DWORD i, CPDF_Object* pObj, CPDF_IndirectObjects* pObj s) | 498 void CPDF_Array::SetAt(FX_DWORD i, CPDF_Object* pObj, CPDF_IndirectObjects* pObj s) |
| 529 { | 499 { |
| 530 ASSERT(this != NULL && m_Type == PDFOBJ_ARRAY); | 500 ASSERT(m_Type == PDFOBJ_ARRAY); |
| 531 ASSERT(i < (FX_DWORD)m_Objects.GetSize()); | 501 ASSERT(i < (FX_DWORD)m_Objects.GetSize()); |
| 532 if (i >= (FX_DWORD)m_Objects.GetSize()) { | 502 if (i >= (FX_DWORD)m_Objects.GetSize()) { |
| 533 return; | 503 return; |
| 534 } | 504 } |
| 535 CPDF_Object* pOld = (CPDF_Object*)m_Objects.GetAt(i); | 505 CPDF_Object* pOld = (CPDF_Object*)m_Objects.GetAt(i); |
| 536 pOld->Release(); | 506 if (pOld) |
| 507 pOld->Release(); | |
| 537 if (pObj->GetObjNum()) { | 508 if (pObj->GetObjNum()) { |
| 538 ASSERT(pObjs != NULL); | 509 ASSERT(pObjs != NULL); |
| 539 pObj = CPDF_Reference::Create(pObjs, pObj->GetObjNum()); | 510 pObj = CPDF_Reference::Create(pObjs, pObj->GetObjNum()); |
| 540 } | 511 } |
| 541 m_Objects.SetAt(i, pObj); | 512 m_Objects.SetAt(i, pObj); |
| 542 } | 513 } |
| 543 void CPDF_Array::InsertAt(FX_DWORD index, CPDF_Object* pObj, CPDF_IndirectObject s* pObjs) | 514 void CPDF_Array::InsertAt(FX_DWORD index, CPDF_Object* pObj, CPDF_IndirectObject s* pObjs) |
| 544 { | 515 { |
| 545 ASSERT(pObj != NULL); | 516 ASSERT(pObj != NULL); |
| 546 if (pObj->GetObjNum()) { | 517 if (pObj->GetObjNum()) { |
| 547 ASSERT(pObjs != NULL); | 518 ASSERT(pObjs != NULL); |
| 548 pObj = CPDF_Reference::Create(pObjs, pObj->GetObjNum()); | 519 pObj = CPDF_Reference::Create(pObjs, pObj->GetObjNum()); |
| 549 } | 520 } |
| 550 m_Objects.InsertAt(index, pObj); | 521 m_Objects.InsertAt(index, pObj); |
| 551 } | 522 } |
| 552 void CPDF_Array::Add(CPDF_Object* pObj, CPDF_IndirectObjects* pObjs) | 523 void CPDF_Array::Add(CPDF_Object* pObj, CPDF_IndirectObjects* pObjs) |
| 553 { | 524 { |
| 554 ASSERT(pObj != NULL); | 525 ASSERT(pObj != NULL); |
| 555 if (pObj->GetObjNum()) { | 526 if (pObj->GetObjNum()) { |
| 556 ASSERT(pObjs != NULL); | 527 ASSERT(pObjs != NULL); |
| 557 pObj = CPDF_Reference::Create(pObjs, pObj->GetObjNum()); | 528 pObj = CPDF_Reference::Create(pObjs, pObj->GetObjNum()); |
| 558 } | 529 } |
| 559 m_Objects.Add(pObj); | 530 m_Objects.Add(pObj); |
| 560 } | 531 } |
| 561 void CPDF_Array::AddName(const CFX_ByteString& str) | 532 void CPDF_Array::AddName(const CFX_ByteString& str) |
| 562 { | 533 { |
| 563 ASSERT(this != NULL && m_Type == PDFOBJ_ARRAY); | 534 ASSERT(m_Type == PDFOBJ_ARRAY); |
| 564 Add(FX_NEW CPDF_Name(str)); | 535 Add(FX_NEW CPDF_Name(str)); |
| 565 } | 536 } |
| 566 void CPDF_Array::AddString(const CFX_ByteString& str) | 537 void CPDF_Array::AddString(const CFX_ByteString& str) |
| 567 { | 538 { |
| 568 ASSERT(this != NULL && m_Type == PDFOBJ_ARRAY); | 539 ASSERT(m_Type == PDFOBJ_ARRAY); |
| 569 Add(FX_NEW CPDF_String(str)); | 540 Add(FX_NEW CPDF_String(str)); |
| 570 } | 541 } |
| 571 void CPDF_Array::AddInteger(int i) | 542 void CPDF_Array::AddInteger(int i) |
| 572 { | 543 { |
| 573 ASSERT(this != NULL && m_Type == PDFOBJ_ARRAY); | 544 ASSERT(m_Type == PDFOBJ_ARRAY); |
| 574 Add(FX_NEW CPDF_Number(i)); | 545 Add(FX_NEW CPDF_Number(i)); |
| 575 } | 546 } |
| 576 void CPDF_Array::AddNumber(FX_FLOAT f) | 547 void CPDF_Array::AddNumber(FX_FLOAT f) |
| 577 { | 548 { |
| 578 ASSERT(this != NULL && m_Type == PDFOBJ_ARRAY); | 549 ASSERT(m_Type == PDFOBJ_ARRAY); |
| 579 CPDF_Number* pNumber = FX_NEW CPDF_Number; | 550 CPDF_Number* pNumber = FX_NEW CPDF_Number; |
| 580 pNumber->SetNumber(f); | 551 pNumber->SetNumber(f); |
| 581 Add(pNumber); | 552 Add(pNumber); |
| 582 } | 553 } |
| 583 void CPDF_Array::AddReference(CPDF_IndirectObjects* pDoc, FX_DWORD objnum) | 554 void CPDF_Array::AddReference(CPDF_IndirectObjects* pDoc, FX_DWORD objnum) |
| 584 { | 555 { |
| 585 ASSERT(this != NULL && m_Type == PDFOBJ_ARRAY); | 556 ASSERT(m_Type == PDFOBJ_ARRAY); |
| 586 Add(FX_NEW CPDF_Reference(pDoc, objnum)); | 557 Add(FX_NEW CPDF_Reference(pDoc, objnum)); |
| 587 } | 558 } |
| 588 FX_BOOL CPDF_Array::Identical(CPDF_Array* pOther) const | 559 FX_BOOL CPDF_Array::Identical(CPDF_Array* pOther) const |
| 589 { | 560 { |
| 590 if (m_Objects.GetSize() != pOther->m_Objects.GetSize()) { | 561 if (m_Objects.GetSize() != pOther->m_Objects.GetSize()) { |
| 591 return FALSE; | 562 return FALSE; |
| 592 } | 563 } |
| 593 for (int i = 0; i < m_Objects.GetSize(); i ++) | 564 for (int i = 0; i < m_Objects.GetSize(); i ++) |
| 594 if (!((CPDF_Object*)m_Objects[i])->IsIdentical((CPDF_Object*)pOther->m_O bjects[i])) { | 565 if (!((CPDF_Object*)m_Objects[i])->IsIdentical((CPDF_Object*)pOther->m_O bjects[i])) { |
| 595 return FALSE; | 566 return FALSE; |
| 596 } | 567 } |
| 597 return TRUE; | 568 return TRUE; |
| 598 } | 569 } |
| 599 CPDF_Dictionary::~CPDF_Dictionary() | 570 CPDF_Dictionary::~CPDF_Dictionary() |
| 600 { | 571 { |
| 601 FX_POSITION pos = m_Map.GetStartPosition(); | 572 FX_POSITION pos = m_Map.GetStartPosition(); |
| 602 while (pos) { | 573 while (pos) { |
| 603 FX_LPVOID value = m_Map.GetNextValue(pos); | 574 FX_LPVOID value = m_Map.GetNextValue(pos); |
| 604 ((CPDF_Object*)value)->Release(); | 575 if (value) |
| 576 ((CPDF_Object*)value)->Release(); | |
| 605 } | 577 } |
| 606 } | 578 } |
| 607 FX_POSITION CPDF_Dictionary::GetStartPos() const | 579 FX_POSITION CPDF_Dictionary::GetStartPos() const |
| 608 { | 580 { |
| 609 return m_Map.GetStartPosition(); | 581 return m_Map.GetStartPosition(); |
| 610 } | 582 } |
| 611 CPDF_Object* CPDF_Dictionary::GetNextElement(FX_POSITION& pos, CFX_ByteString& k ey) const | 583 CPDF_Object* CPDF_Dictionary::GetNextElement(FX_POSITION& pos, CFX_ByteString& k ey) const |
| 612 { | 584 { |
| 613 if (pos == NULL) { | 585 if (pos == NULL) { |
| 614 return NULL; | 586 return NULL; |
| 615 } | 587 } |
| 616 CPDF_Object* p; | 588 CPDF_Object* p; |
| 617 m_Map.GetNextAssoc(pos, key, (FX_LPVOID&)p); | 589 m_Map.GetNextAssoc(pos, key, (FX_LPVOID&)p); |
| 618 return p; | 590 return p; |
| 619 } | 591 } |
| 620 CPDF_Object* CPDF_Dictionary::GetElement(FX_BSTR key) const | 592 CPDF_Object* CPDF_Dictionary::GetElement(FX_BSTR key) const |
| 621 { | 593 { |
| 622 if (this == NULL) { | |
| 623 return NULL; | |
| 624 } | |
| 625 CPDF_Object* p = NULL; | 594 CPDF_Object* p = NULL; |
| 626 m_Map.Lookup(key, (void*&)p); | 595 m_Map.Lookup(key, (void*&)p); |
| 627 return p; | 596 return p; |
| 628 } | 597 } |
| 629 CPDF_Object* CPDF_Dictionary::GetElementValue(FX_BSTR key) const | 598 CPDF_Object* CPDF_Dictionary::GetElementValue(FX_BSTR key) const |
| 630 { | 599 { |
| 631 if (this == NULL) { | |
| 632 return NULL; | |
| 633 } | |
| 634 CPDF_Object* p = NULL; | 600 CPDF_Object* p = NULL; |
| 635 m_Map.Lookup(key, (void*&)p); | 601 m_Map.Lookup(key, (void*&)p); |
| 636 return p->GetDirect(); | 602 return p ? p->GetDirect() : NULL; |
| 637 } | 603 } |
| 638 CFX_ByteString CPDF_Dictionary::GetString(FX_BSTR key) const | 604 CFX_ByteString CPDF_Dictionary::GetString(FX_BSTR key) const |
| 639 { | 605 { |
| 640 if (this) { | 606 CPDF_Object* p = NULL; |
| 641 CPDF_Object* p = NULL; | 607 m_Map.Lookup(key, (void*&)p); |
| 642 m_Map.Lookup(key, (void*&)p); | 608 if (p) |
| 643 if (p) { | 609 return p->GetString(); |
| 644 return p->GetString(); | 610 else |
| 645 } | 611 return CFX_ByteString(); |
| 646 } | |
| 647 return CFX_ByteString(); | |
| 648 } | 612 } |
| 649 CFX_ByteStringC CPDF_Dictionary::GetConstString(FX_BSTR key) const | 613 CFX_ByteStringC CPDF_Dictionary::GetConstString(FX_BSTR key) const |
| 650 { | 614 { |
| 651 if (this) { | 615 CPDF_Object* p = NULL; |
| 652 CPDF_Object* p = NULL; | 616 m_Map.Lookup(key, (void*&)p); |
| 653 m_Map.Lookup(key, (void*&)p); | 617 if (p) |
| 654 if (p) { | 618 return p->GetConstString(); |
| 655 return p->GetConstString(); | 619 else |
| 656 } | 620 return CFX_ByteStringC(); |
| 657 } | |
| 658 return CFX_ByteStringC(); | |
| 659 } | 621 } |
| 660 CFX_WideString CPDF_Dictionary::GetUnicodeText(FX_BSTR key, CFX_CharMap* pCharMa p) const | 622 CFX_WideString CPDF_Dictionary::GetUnicodeText(FX_BSTR key, CFX_CharMap* pCharMa p) const |
| 661 { | 623 { |
| 662 if (this) { | 624 CPDF_Object* p = NULL; |
| 663 CPDF_Object* p = NULL; | 625 m_Map.Lookup(key, (void*&)p); |
| 664 m_Map.Lookup(key, (void*&)p); | 626 if (p) { |
| 665 if (p) { | 627 if(p->GetType() == PDFOBJ_REFERENCE) { |
| 666 if(p->GetType() == PDFOBJ_REFERENCE) { | 628 p = ((CPDF_Reference*)p)->GetDirect(); |
| 667 p = ((CPDF_Reference*)p)->GetDirect(); | 629 return p->GetUnicodeText(pCharMap); |
| 668 return p->GetUnicodeText(pCharMap); | 630 } else { |
| 669 } else { | 631 return p->GetUnicodeText(pCharMap); |
| 670 return p->GetUnicodeText(pCharMap); | |
| 671 } | |
| 672 } | 632 } |
| 673 } | 633 } |
| 674 return CFX_WideString(); | 634 return CFX_WideString(); |
| 675 } | 635 } |
| 676 CFX_ByteString CPDF_Dictionary::GetString(FX_BSTR key, FX_BSTR def) const | 636 CFX_ByteString CPDF_Dictionary::GetString(FX_BSTR key, FX_BSTR def) const |
| 677 { | 637 { |
| 678 if (this) { | 638 CPDF_Object* p = NULL; |
| 679 CPDF_Object* p = NULL; | 639 m_Map.Lookup(key, (void*&)p); |
| 680 m_Map.Lookup(key, (void*&)p); | 640 if (p) { |
| 681 if (p) { | 641 return p->GetString(); |
| 682 return p->GetString(); | |
| 683 } | |
| 684 } | 642 } |
| 685 return CFX_ByteString(def); | 643 return CFX_ByteString(def); |
| 686 } | 644 } |
| 687 CFX_ByteStringC CPDF_Dictionary::GetConstString(FX_BSTR key, FX_BSTR def) const | 645 CFX_ByteStringC CPDF_Dictionary::GetConstString(FX_BSTR key, FX_BSTR def) const |
| 688 { | 646 { |
| 689 if (this) { | 647 CPDF_Object* p = NULL; |
| 690 CPDF_Object* p = NULL; | 648 m_Map.Lookup(key, (void*&)p); |
| 691 m_Map.Lookup(key, (void*&)p); | 649 if (p) |
| 692 if (p) { | 650 return p->GetConstString(); |
| 693 return p->GetConstString(); | 651 else |
| 694 } | 652 return CFX_ByteStringC(def); |
| 695 } | |
| 696 return CFX_ByteStringC(def); | |
| 697 } | 653 } |
| 698 int CPDF_Dictionary::GetInteger(FX_BSTR key) const | 654 int CPDF_Dictionary::GetInteger(FX_BSTR key) const |
| 699 { | 655 { |
| 700 if (this) { | 656 CPDF_Object* p = NULL; |
| 701 CPDF_Object* p = NULL; | 657 m_Map.Lookup(key, (void*&)p); |
| 702 m_Map.Lookup(key, (void*&)p); | 658 if (p) { |
| 703 if (p) { | 659 return p->GetInteger(); |
| 704 return p->GetInteger(); | |
| 705 } | |
| 706 } | 660 } |
| 707 return 0; | 661 return 0; |
| 708 } | 662 } |
| 709 int CPDF_Dictionary::GetInteger(FX_BSTR key, int def) const | 663 int CPDF_Dictionary::GetInteger(FX_BSTR key, int def) const |
| 710 { | 664 { |
| 711 if (this) { | 665 CPDF_Object* p = NULL; |
| 712 CPDF_Object* p = NULL; | 666 m_Map.Lookup(key, (void*&)p); |
| 713 m_Map.Lookup(key, (void*&)p); | 667 if (p) { |
| 714 if (p) { | 668 return p->GetInteger(); |
| 715 return p->GetInteger(); | |
| 716 } | |
| 717 } | 669 } |
| 718 return def; | 670 return def; |
| 719 } | 671 } |
| 720 FX_FLOAT CPDF_Dictionary::GetNumber(FX_BSTR key) const | 672 FX_FLOAT CPDF_Dictionary::GetNumber(FX_BSTR key) const |
| 721 { | 673 { |
| 722 if (this) { | 674 CPDF_Object* p = NULL; |
| 723 CPDF_Object* p = NULL; | 675 m_Map.Lookup(key, (void*&)p); |
| 724 m_Map.Lookup(key, (void*&)p); | 676 if (p) { |
| 725 if (p) { | 677 return p->GetNumber(); |
| 726 return p->GetNumber(); | |
| 727 } | |
| 728 } | 678 } |
| 729 return 0; | 679 return 0; |
| 730 } | 680 } |
| 731 FX_BOOL CPDF_Dictionary::GetBoolean(FX_BSTR key, FX_BOOL bDefault) const | 681 FX_BOOL CPDF_Dictionary::GetBoolean(FX_BSTR key, FX_BOOL bDefault) const |
| 732 { | 682 { |
| 733 if (this) { | 683 CPDF_Object* p = NULL; |
| 734 CPDF_Object* p = NULL; | 684 m_Map.Lookup(key, (void*&)p); |
| 735 m_Map.Lookup(key, (void*&)p); | 685 if (p && p->GetType() == PDFOBJ_BOOLEAN) { |
| 736 if (p && p->GetType() == PDFOBJ_BOOLEAN) { | 686 return p->GetInteger(); |
| 737 return p->GetInteger(); | |
| 738 } | |
| 739 } | 687 } |
| 740 return bDefault; | 688 return bDefault; |
| 741 } | 689 } |
| 742 CPDF_Dictionary* CPDF_Dictionary::GetDict(FX_BSTR key) const | 690 CPDF_Dictionary* CPDF_Dictionary::GetDict(FX_BSTR key) const |
| 743 { | 691 { |
| 744 CPDF_Object* p = GetElementValue(key); | 692 CPDF_Object* p = GetElementValue(key); |
| 745 if (p == NULL) { | 693 if (p == NULL) { |
| 746 return NULL; | 694 return NULL; |
| 747 } else if (p->GetType() == PDFOBJ_DICTIONARY) { | 695 } else if (p->GetType() == PDFOBJ_DICTIONARY) { |
| 748 return (CPDF_Dictionary*)p; | 696 return (CPDF_Dictionary*)p; |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 780 { | 728 { |
| 781 CFX_AffineMatrix matrix; | 729 CFX_AffineMatrix matrix; |
| 782 CPDF_Array* pArray = GetArray(key); | 730 CPDF_Array* pArray = GetArray(key); |
| 783 if (pArray) { | 731 if (pArray) { |
| 784 matrix = pArray->GetMatrix(); | 732 matrix = pArray->GetMatrix(); |
| 785 } | 733 } |
| 786 return matrix; | 734 return matrix; |
| 787 } | 735 } |
| 788 FX_BOOL CPDF_Dictionary::KeyExist(FX_BSTR key) const | 736 FX_BOOL CPDF_Dictionary::KeyExist(FX_BSTR key) const |
| 789 { | 737 { |
| 790 if (this == NULL) { | |
| 791 return FALSE; | |
| 792 } | |
| 793 FX_LPVOID value; | 738 FX_LPVOID value; |
| 794 return m_Map.Lookup(key, value); | 739 return m_Map.Lookup(key, value); |
| 795 } | 740 } |
| 796 void CPDF_Dictionary::SetAt(FX_BSTR key, CPDF_Object* pObj, CPDF_IndirectObjects * pObjs) | 741 void CPDF_Dictionary::SetAt(FX_BSTR key, CPDF_Object* pObj, CPDF_IndirectObjects * pObjs) |
| 797 { | 742 { |
| 798 ASSERT(this != NULL && m_Type == PDFOBJ_DICTIONARY); | 743 ASSERT(m_Type == PDFOBJ_DICTIONARY); |
| 799 CPDF_Object* p = NULL; | 744 CPDF_Object* p = NULL; |
| 800 m_Map.Lookup(key, (void*&)p); | 745 m_Map.Lookup(key, (void*&)p); |
| 801 if (p == pObj) { | 746 if (p == pObj) { |
| 802 return; | 747 return; |
| 803 } | 748 } |
| 804 if (p) { | 749 if (p) |
| 805 p->Release(); | 750 p->Release(); |
| 806 } | |
| 807 if (pObj) { | 751 if (pObj) { |
| 808 if (pObj->GetObjNum()) { | 752 if (pObj->GetObjNum()) { |
| 809 ASSERT(pObjs != NULL); | 753 ASSERT(pObjs != NULL); |
| 810 pObj = CPDF_Reference::Create(pObjs, pObj->GetObjNum()); | 754 pObj = CPDF_Reference::Create(pObjs, pObj->GetObjNum()); |
| 811 } | 755 } |
| 812 m_Map.SetAt(key, pObj); | 756 m_Map.SetAt(key, pObj); |
| 813 } else { | 757 } else { |
| 814 m_Map.RemoveKey(key); | 758 m_Map.RemoveKey(key); |
| 815 } | 759 } |
| 816 } | 760 } |
| 817 void CPDF_Dictionary::AddValue(FX_BSTR key, CPDF_Object* pObj) | 761 void CPDF_Dictionary::AddValue(FX_BSTR key, CPDF_Object* pObj) |
| 818 { | 762 { |
| 819 ASSERT(this != NULL && m_Type == PDFOBJ_DICTIONARY); | 763 ASSERT(m_Type == PDFOBJ_DICTIONARY); |
| 820 m_Map.AddValue(key, pObj); | 764 m_Map.AddValue(key, pObj); |
| 821 } | 765 } |
| 822 void CPDF_Dictionary::RemoveAt(FX_BSTR key) | 766 void CPDF_Dictionary::RemoveAt(FX_BSTR key) |
| 823 { | 767 { |
| 824 ASSERT(this != NULL && m_Type == PDFOBJ_DICTIONARY); | 768 ASSERT(m_Type == PDFOBJ_DICTIONARY); |
| 825 CPDF_Object* p = NULL; | 769 CPDF_Object* p = NULL; |
| 826 m_Map.Lookup(key, (void*&)p); | 770 m_Map.Lookup(key, (void*&)p); |
| 827 if (p == NULL) { | 771 if (p == NULL) { |
| 828 return; | 772 return; |
| 829 } | 773 } |
| 830 p->Release(); | 774 p->Release(); |
| 831 m_Map.RemoveKey(key); | 775 m_Map.RemoveKey(key); |
| 832 } | 776 } |
| 833 void CPDF_Dictionary::ReplaceKey(FX_BSTR oldkey, FX_BSTR newkey) | 777 void CPDF_Dictionary::ReplaceKey(FX_BSTR oldkey, FX_BSTR newkey) |
| 834 { | 778 { |
| 835 ASSERT(this != NULL && m_Type == PDFOBJ_DICTIONARY); | 779 ASSERT(m_Type == PDFOBJ_DICTIONARY); |
| 836 CPDF_Object* p = NULL; | 780 CPDF_Object* p = NULL; |
| 837 m_Map.Lookup(oldkey, (void*&)p); | 781 m_Map.Lookup(oldkey, (void*&)p); |
| 838 if (p == NULL) { | 782 if (p == NULL) { |
| 839 return; | 783 return; |
| 840 } | 784 } |
| 841 m_Map.RemoveKey(oldkey); | 785 m_Map.RemoveKey(oldkey); |
| 842 m_Map.SetAt(newkey, p); | 786 m_Map.SetAt(newkey, p); |
| 843 } | 787 } |
| 844 FX_BOOL CPDF_Dictionary::Identical(CPDF_Dictionary* pOther) const | 788 FX_BOOL CPDF_Dictionary::Identical(CPDF_Dictionary* pOther) const |
| 845 { | 789 { |
| 846 if (this == NULL) { | |
| 847 if (pOther == NULL) { | |
| 848 return TRUE; | |
| 849 } | |
| 850 return FALSE; | |
| 851 } | |
| 852 if (pOther == NULL) { | 790 if (pOther == NULL) { |
| 853 return FALSE; | 791 return FALSE; |
| 854 } | 792 } |
| 855 if (m_Map.GetCount() != pOther->m_Map.GetCount()) { | 793 if (m_Map.GetCount() != pOther->m_Map.GetCount()) { |
| 856 return FALSE; | 794 return FALSE; |
| 857 } | 795 } |
| 858 FX_POSITION pos = m_Map.GetStartPosition(); | 796 FX_POSITION pos = m_Map.GetStartPosition(); |
| 859 while (pos) { | 797 while (pos) { |
| 860 CFX_ByteString key; | 798 CFX_ByteString key; |
| 861 FX_LPVOID value; | 799 FX_LPVOID value; |
| 862 m_Map.GetNextAssoc(pos, key, value); | 800 m_Map.GetNextAssoc(pos, key, value); |
| 801 if (!value) | |
| 802 return FALSE; | |
| 863 if (!((CPDF_Object*)value)->IsIdentical(pOther->GetElement(key))) { | 803 if (!((CPDF_Object*)value)->IsIdentical(pOther->GetElement(key))) { |
| 864 return FALSE; | 804 return FALSE; |
| 865 } | 805 } |
| 866 } | 806 } |
| 867 return TRUE; | 807 return TRUE; |
| 868 } | 808 } |
| 869 void CPDF_Dictionary::SetAtInteger(FX_BSTR key, int i) | 809 void CPDF_Dictionary::SetAtInteger(FX_BSTR key, int i) |
| 870 { | 810 { |
| 871 SetAt(key, FX_NEW CPDF_Number(i)); | 811 SetAt(key, FX_NEW CPDF_Number(i)); |
| 872 } | 812 } |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1007 { | 947 { |
| 1008 InitStream(pDict); | 948 InitStream(pDict); |
| 1009 m_pFile = pFile; | 949 m_pFile = pFile; |
| 1010 m_dwSize = (FX_DWORD)pFile->GetSize(); | 950 m_dwSize = (FX_DWORD)pFile->GetSize(); |
| 1011 if (m_pDict) { | 951 if (m_pDict) { |
| 1012 m_pDict->SetAtInteger(FX_BSTRC("Length"), m_dwSize); | 952 m_pDict->SetAtInteger(FX_BSTRC("Length"), m_dwSize); |
| 1013 } | 953 } |
| 1014 } | 954 } |
| 1015 FX_BOOL CPDF_Stream::Identical(CPDF_Stream* pOther) const | 955 FX_BOOL CPDF_Stream::Identical(CPDF_Stream* pOther) const |
| 1016 { | 956 { |
| 957 if (!m_pDict) | |
| 958 return pOther ? FALSE : TRUE; | |
|
Nico
2014/06/28 01:01:07
You want pOther->m_pDict here, not pOther I think.
| |
| 959 | |
| 1017 if (!m_pDict->Identical(pOther->m_pDict)) { | 960 if (!m_pDict->Identical(pOther->m_pDict)) { |
| 1018 return FALSE; | 961 return FALSE; |
| 1019 } | 962 } |
| 1020 if (m_dwSize != pOther->m_dwSize) { | 963 if (m_dwSize != pOther->m_dwSize) { |
| 1021 return FALSE; | 964 return FALSE; |
| 1022 } | 965 } |
| 1023 if (m_GenNum != (FX_DWORD) - 1 && pOther->m_GenNum != (FX_DWORD) - 1) { | 966 if (m_GenNum != (FX_DWORD) - 1 && pOther->m_GenNum != (FX_DWORD) - 1) { |
| 1024 if (m_pFile == pOther->m_pFile && m_pFile == NULL) { | 967 if (m_pFile == pOther->m_pFile && m_pFile == NULL) { |
| 1025 return TRUE; | 968 return TRUE; |
| 1026 } | 969 } |
| (...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1335 pObj->m_ObjNum = objnum; | 1278 pObj->m_ObjNum = objnum; |
| 1336 m_IndirectObjs.SetAt((FX_LPVOID)(FX_UINTPTR)objnum, pObj); | 1279 m_IndirectObjs.SetAt((FX_LPVOID)(FX_UINTPTR)objnum, pObj); |
| 1337 if (m_LastObjNum < objnum) { | 1280 if (m_LastObjNum < objnum) { |
| 1338 m_LastObjNum = objnum; | 1281 m_LastObjNum = objnum; |
| 1339 } | 1282 } |
| 1340 } | 1283 } |
| 1341 FX_DWORD CPDF_IndirectObjects::GetLastObjNum() const | 1284 FX_DWORD CPDF_IndirectObjects::GetLastObjNum() const |
| 1342 { | 1285 { |
| 1343 return m_LastObjNum; | 1286 return m_LastObjNum; |
| 1344 } | 1287 } |
| OLD | NEW |