| 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 "core/include/fpdfapi/fpdf_objects.h" | 7 #include "core/include/fpdfapi/fpdf_objects.h" |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 | 10 |
| 11 #include "core/include/fpdfapi/fpdf_parser.h" | 11 #include "core/include/fpdfapi/fpdf_parser.h" |
| 12 #include "core/include/fxcrt/fx_string.h" | 12 #include "core/include/fxcrt/fx_string.h" |
| 13 #include "third_party/base/stl_util.h" | 13 #include "third_party/base/stl_util.h" |
| 14 | 14 |
| 15 namespace { | 15 namespace { |
| 16 | 16 |
| 17 const FX_DWORD kBlockSize = 1024; | 17 const FX_DWORD kBlockSize = 1024; |
| 18 | 18 |
| 19 } // namespace | 19 } // namespace |
| 20 | 20 |
| 21 void CPDF_Object::Release() { | 21 void CPDF_Object::Release() { |
| 22 if (m_ObjNum) { | 22 if (m_ObjNum) { |
| 23 return; | 23 return; |
| 24 } | 24 } |
| 25 Destroy(); | 25 Destroy(); |
| 26 } | 26 } |
| 27 void CPDF_Object::Destroy() { | 27 void CPDF_Object::Destroy() { |
| 28 switch (m_Type) { | 28 switch (m_Type) { |
| 29 case PDFOBJ_STRING: | 29 case STRING: |
| 30 delete AsString(); | 30 delete AsString(); |
| 31 break; | 31 break; |
| 32 case PDFOBJ_NAME: | 32 case NAME: |
| 33 delete AsName(); | 33 delete AsName(); |
| 34 break; | 34 break; |
| 35 case PDFOBJ_ARRAY: | 35 case ARRAY: |
| 36 delete AsArray(); | 36 delete AsArray(); |
| 37 break; | 37 break; |
| 38 case PDFOBJ_DICTIONARY: | 38 case DICTIONARY: |
| 39 delete AsDictionary(); | 39 delete AsDictionary(); |
| 40 break; | 40 break; |
| 41 case PDFOBJ_STREAM: | 41 case STREAM: |
| 42 delete AsStream(); | 42 delete AsStream(); |
| 43 break; | 43 break; |
| 44 default: | 44 default: |
| 45 delete this; | 45 delete this; |
| 46 } | 46 } |
| 47 } | 47 } |
| 48 | 48 |
| 49 const CPDF_Object* CPDF_Object::GetBasicObject() const { | 49 const CPDF_Object* CPDF_Object::GetBasicObject() const { |
| 50 const CPDF_Reference* pRef = AsReference(); | 50 const CPDF_Reference* pRef = AsReference(); |
| 51 if (!pRef) { | 51 if (!pRef) { |
| 52 // This is not an indirect reference. | 52 // This is not an indirect reference. |
| 53 return this; | 53 return this; |
| 54 } | 54 } |
| 55 if (!pRef->m_pObjList) | 55 if (!pRef->m_pObjList) |
| 56 return nullptr; | 56 return nullptr; |
| 57 return pRef->m_pObjList->GetIndirectObject(pRef->GetRefObjNum()); | 57 return pRef->m_pObjList->GetIndirectObject(pRef->GetRefObjNum()); |
| 58 } | 58 } |
| 59 | 59 |
| 60 CFX_ByteString CPDF_Object::GetString() const { | 60 CFX_ByteString CPDF_Object::GetString() const { |
| 61 const CPDF_Object* obj = GetBasicObject(); | 61 const CPDF_Object* obj = GetBasicObject(); |
| 62 if (obj) { | 62 if (obj) { |
| 63 switch (obj->GetType()) { | 63 switch (obj->GetType()) { |
| 64 case PDFOBJ_BOOLEAN: | 64 case BOOLEAN: |
| 65 return obj->AsBoolean()->GetString(); | 65 return obj->AsBoolean()->GetString(); |
| 66 case PDFOBJ_NUMBER: | 66 case NUMBER: |
| 67 return obj->AsNumber()->GetString(); | 67 return obj->AsNumber()->GetString(); |
| 68 case PDFOBJ_STRING: | 68 case STRING: |
| 69 return obj->AsString()->GetString(); | 69 return obj->AsString()->GetString(); |
| 70 case PDFOBJ_NAME: | 70 case NAME: |
| 71 return obj->AsName()->GetString(); | 71 return obj->AsName()->GetString(); |
| 72 default: |
| 73 break; |
| 72 } | 74 } |
| 73 } | 75 } |
| 74 return CFX_ByteString(); | 76 return CFX_ByteString(); |
| 75 } | 77 } |
| 76 | 78 |
| 77 CFX_ByteStringC CPDF_Object::GetConstString() const { | 79 CFX_ByteStringC CPDF_Object::GetConstString() const { |
| 78 const CPDF_Object* obj = GetBasicObject(); | 80 const CPDF_Object* obj = GetBasicObject(); |
| 79 if (obj) { | 81 if (obj) { |
| 80 FX_DWORD type = obj->GetType(); | 82 FX_DWORD type = obj->GetType(); |
| 81 if (type == PDFOBJ_STRING) { | 83 if (type == STRING) { |
| 82 CFX_ByteString str = obj->AsString()->GetString(); | 84 CFX_ByteString str = obj->AsString()->GetString(); |
| 83 return CFX_ByteStringC(str); | 85 return CFX_ByteStringC(str); |
| 84 } | 86 } |
| 85 if (type == PDFOBJ_NAME) { | 87 if (type == NAME) { |
| 86 CFX_ByteString name = obj->AsName()->GetString(); | 88 CFX_ByteString name = obj->AsName()->GetString(); |
| 87 return CFX_ByteStringC(name); | 89 return CFX_ByteStringC(name); |
| 88 } | 90 } |
| 89 } | 91 } |
| 90 return CFX_ByteStringC(); | 92 return CFX_ByteStringC(); |
| 91 } | 93 } |
| 92 | 94 |
| 93 FX_FLOAT CPDF_Object::GetNumber() const { | 95 FX_FLOAT CPDF_Object::GetNumber() const { |
| 94 const CPDF_Object* obj = GetBasicObject(); | 96 const CPDF_Object* obj = GetBasicObject(); |
| 95 if (obj && obj->GetType() == PDFOBJ_NUMBER) | 97 if (obj && obj->GetType() == NUMBER) |
| 96 return obj->AsNumber()->GetNumber(); | 98 return obj->AsNumber()->GetNumber(); |
| 97 return 0; | 99 return 0; |
| 98 } | 100 } |
| 99 | 101 |
| 100 FX_FLOAT CPDF_Object::GetNumber16() const { | 102 FX_FLOAT CPDF_Object::GetNumber16() const { |
| 101 return GetNumber(); | 103 return GetNumber(); |
| 102 } | 104 } |
| 103 | 105 |
| 104 int CPDF_Object::GetInteger() const { | 106 int CPDF_Object::GetInteger() const { |
| 105 const CPDF_Object* obj = GetBasicObject(); | 107 const CPDF_Object* obj = GetBasicObject(); |
| 106 if (obj) { | 108 if (obj) { |
| 107 FX_DWORD type = obj->GetType(); | 109 FX_DWORD type = obj->GetType(); |
| 108 if (type == PDFOBJ_BOOLEAN) | 110 if (type == BOOLEAN) |
| 109 return obj->AsBoolean()->GetValue(); | 111 return obj->AsBoolean()->GetValue(); |
| 110 if (type == PDFOBJ_NUMBER) | 112 if (type == NUMBER) |
| 111 return obj->AsNumber()->GetInteger(); | 113 return obj->AsNumber()->GetInteger(); |
| 112 } | 114 } |
| 113 return 0; | 115 return 0; |
| 114 } | 116 } |
| 115 | 117 |
| 116 CPDF_Dictionary* CPDF_Object::GetDict() const { | 118 CPDF_Dictionary* CPDF_Object::GetDict() const { |
| 117 const CPDF_Object* obj = GetBasicObject(); | 119 const CPDF_Object* obj = GetBasicObject(); |
| 118 if (obj) { | 120 if (obj) { |
| 119 FX_DWORD type = obj->GetType(); | 121 FX_DWORD type = obj->GetType(); |
| 120 if (type == PDFOBJ_DICTIONARY) { | 122 if (type == DICTIONARY) { |
| 121 // The method should be made non-const if we want to not be const. | 123 // The method should be made non-const if we want to not be const. |
| 122 // See bug #234. | 124 // See bug #234. |
| 123 return const_cast<CPDF_Dictionary*>(obj->AsDictionary()); | 125 return const_cast<CPDF_Dictionary*>(obj->AsDictionary()); |
| 124 } | 126 } |
| 125 if (type == PDFOBJ_STREAM) | 127 if (type == STREAM) |
| 126 return obj->AsStream()->GetDict(); | 128 return obj->AsStream()->GetDict(); |
| 127 } | 129 } |
| 128 return nullptr; | 130 return nullptr; |
| 129 } | 131 } |
| 130 | 132 |
| 131 CPDF_Array* CPDF_Object::GetArray() const { | 133 CPDF_Array* CPDF_Object::GetArray() const { |
| 132 // The method should be made non-const if we want to not be const. | 134 // The method should be made non-const if we want to not be const. |
| 133 // See bug #234. | 135 // See bug #234. |
| 134 return const_cast<CPDF_Array*>(AsArray()); | 136 return const_cast<CPDF_Array*>(AsArray()); |
| 135 } | 137 } |
| 136 | 138 |
| 137 void CPDF_Object::SetString(const CFX_ByteString& str) { | 139 void CPDF_Object::SetString(const CFX_ByteString& str) { |
| 138 switch (m_Type) { | 140 switch (m_Type) { |
| 139 case PDFOBJ_BOOLEAN: | 141 case BOOLEAN: |
| 140 AsBoolean()->m_bValue = (str == "true"); | 142 AsBoolean()->m_bValue = (str == "true"); |
| 141 return; | 143 return; |
| 142 case PDFOBJ_NUMBER: | 144 case NUMBER: |
| 143 AsNumber()->SetString(str); | 145 AsNumber()->SetString(str); |
| 144 return; | 146 return; |
| 145 case PDFOBJ_STRING: | 147 case STRING: |
| 146 AsString()->m_String = str; | 148 AsString()->m_String = str; |
| 147 return; | 149 return; |
| 148 case PDFOBJ_NAME: | 150 case NAME: |
| 149 AsName()->m_Name = str; | 151 AsName()->m_Name = str; |
| 150 return; | 152 return; |
| 153 default: |
| 154 break; |
| 151 } | 155 } |
| 152 ASSERT(FALSE); | 156 ASSERT(FALSE); |
| 153 } | 157 } |
| 154 FX_BOOL CPDF_Object::IsIdentical(CPDF_Object* pOther) const { | 158 FX_BOOL CPDF_Object::IsIdentical(CPDF_Object* pOther) const { |
| 155 if (this == pOther) | 159 if (this == pOther) |
| 156 return TRUE; | 160 return TRUE; |
| 157 if (!pOther) | 161 if (!pOther) |
| 158 return FALSE; | 162 return FALSE; |
| 159 if (pOther->m_Type != m_Type) { | 163 if (pOther->m_Type != m_Type) { |
| 160 if (IsReference() && GetDirect()) | 164 if (IsReference() && GetDirect()) |
| 161 return GetDirect()->IsIdentical(pOther); | 165 return GetDirect()->IsIdentical(pOther); |
| 162 if (pOther->IsReference()) | 166 if (pOther->IsReference()) |
| 163 return IsIdentical(pOther->GetDirect()); | 167 return IsIdentical(pOther->GetDirect()); |
| 164 return FALSE; | 168 return FALSE; |
| 165 } | 169 } |
| 166 switch (m_Type) { | 170 switch (m_Type) { |
| 167 case PDFOBJ_BOOLEAN: | 171 case BOOLEAN: |
| 168 return AsBoolean()->Identical(pOther->AsBoolean()); | 172 return AsBoolean()->Identical(pOther->AsBoolean()); |
| 169 case PDFOBJ_NUMBER: | 173 case NUMBER: |
| 170 return AsNumber()->Identical(pOther->AsNumber()); | 174 return AsNumber()->Identical(pOther->AsNumber()); |
| 171 case PDFOBJ_STRING: | 175 case STRING: |
| 172 return AsString()->Identical(pOther->AsString()); | 176 return AsString()->Identical(pOther->AsString()); |
| 173 case PDFOBJ_NAME: | 177 case NAME: |
| 174 return AsName()->Identical(pOther->AsName()); | 178 return AsName()->Identical(pOther->AsName()); |
| 175 case PDFOBJ_ARRAY: | 179 case ARRAY: |
| 176 return AsArray()->Identical(pOther->AsArray()); | 180 return AsArray()->Identical(pOther->AsArray()); |
| 177 case PDFOBJ_DICTIONARY: | 181 case DICTIONARY: |
| 178 return AsDictionary()->Identical(pOther->AsDictionary()); | 182 return AsDictionary()->Identical(pOther->AsDictionary()); |
| 179 case PDFOBJ_NULL: | 183 case NULLOBJ: |
| 180 return TRUE; | 184 return TRUE; |
| 181 case PDFOBJ_STREAM: | 185 case STREAM: |
| 182 return AsStream()->Identical(pOther->AsStream()); | 186 return AsStream()->Identical(pOther->AsStream()); |
| 183 case PDFOBJ_REFERENCE: | 187 case REFERENCE: |
| 184 return AsReference()->Identical(pOther->AsReference()); | 188 return AsReference()->Identical(pOther->AsReference()); |
| 185 } | 189 } |
| 186 return FALSE; | 190 return FALSE; |
| 187 } | 191 } |
| 188 | 192 |
| 189 CPDF_Object* CPDF_Object::GetDirect() const { | 193 CPDF_Object* CPDF_Object::GetDirect() const { |
| 190 const CPDF_Reference* pRef = AsReference(); | 194 const CPDF_Reference* pRef = AsReference(); |
| 191 if (!pRef) | 195 if (!pRef) |
| 192 return const_cast<CPDF_Object*>(this); | 196 return const_cast<CPDF_Object*>(this); |
| 193 if (!pRef->m_pObjList) | 197 if (!pRef->m_pObjList) |
| 194 return nullptr; | 198 return nullptr; |
| 195 return pRef->m_pObjList->GetIndirectObject(pRef->GetRefObjNum()); | 199 return pRef->m_pObjList->GetIndirectObject(pRef->GetRefObjNum()); |
| 196 } | 200 } |
| 197 | 201 |
| 198 CPDF_Object* CPDF_Object::Clone(FX_BOOL bDirect) const { | 202 CPDF_Object* CPDF_Object::Clone(FX_BOOL bDirect) const { |
| 199 std::set<FX_DWORD> visited; | 203 std::set<FX_DWORD> visited; |
| 200 return CloneInternal(bDirect, &visited); | 204 return CloneInternal(bDirect, &visited); |
| 201 } | 205 } |
| 202 CPDF_Object* CPDF_Object::CloneInternal(FX_BOOL bDirect, | 206 CPDF_Object* CPDF_Object::CloneInternal(FX_BOOL bDirect, |
| 203 std::set<FX_DWORD>* visited) const { | 207 std::set<FX_DWORD>* visited) const { |
| 204 switch (m_Type) { | 208 switch (m_Type) { |
| 205 case PDFOBJ_BOOLEAN: | 209 case BOOLEAN: |
| 206 return new CPDF_Boolean(AsBoolean()->m_bValue); | 210 return new CPDF_Boolean(AsBoolean()->m_bValue); |
| 207 case PDFOBJ_NUMBER: { | 211 case NUMBER: { |
| 208 const CPDF_Number* pThis = AsNumber(); | 212 const CPDF_Number* pThis = AsNumber(); |
| 209 return new CPDF_Number(pThis->m_bInteger ? pThis->m_Integer | 213 return new CPDF_Number(pThis->m_bInteger ? pThis->m_Integer |
| 210 : pThis->m_Float); | 214 : pThis->m_Float); |
| 211 } | 215 } |
| 212 case PDFOBJ_STRING: { | 216 case STRING: { |
| 213 const CPDF_String* pString = AsString(); | 217 const CPDF_String* pString = AsString(); |
| 214 return new CPDF_String(pString->m_String, pString->IsHex()); | 218 return new CPDF_String(pString->m_String, pString->IsHex()); |
| 215 } | 219 } |
| 216 case PDFOBJ_NAME: | 220 case NAME: |
| 217 return new CPDF_Name(AsName()->m_Name); | 221 return new CPDF_Name(AsName()->m_Name); |
| 218 case PDFOBJ_ARRAY: { | 222 case ARRAY: { |
| 219 CPDF_Array* pCopy = new CPDF_Array(); | 223 CPDF_Array* pCopy = new CPDF_Array(); |
| 220 const CPDF_Array* pThis = AsArray(); | 224 const CPDF_Array* pThis = AsArray(); |
| 221 int n = pThis->GetCount(); | 225 int n = pThis->GetCount(); |
| 222 for (int i = 0; i < n; i++) { | 226 for (int i = 0; i < n; i++) { |
| 223 CPDF_Object* value = pThis->m_Objects.GetAt(i); | 227 CPDF_Object* value = pThis->m_Objects.GetAt(i); |
| 224 pCopy->m_Objects.Add(value->CloneInternal(bDirect, visited)); | 228 pCopy->m_Objects.Add(value->CloneInternal(bDirect, visited)); |
| 225 } | 229 } |
| 226 return pCopy; | 230 return pCopy; |
| 227 } | 231 } |
| 228 case PDFOBJ_DICTIONARY: { | 232 case DICTIONARY: { |
| 229 CPDF_Dictionary* pCopy = new CPDF_Dictionary(); | 233 CPDF_Dictionary* pCopy = new CPDF_Dictionary(); |
| 230 const CPDF_Dictionary* pThis = AsDictionary(); | 234 const CPDF_Dictionary* pThis = AsDictionary(); |
| 231 for (const auto& it : *pThis) { | 235 for (const auto& it : *pThis) { |
| 232 pCopy->m_Map.insert(std::make_pair( | 236 pCopy->m_Map.insert(std::make_pair( |
| 233 it.first, it.second->CloneInternal(bDirect, visited))); | 237 it.first, it.second->CloneInternal(bDirect, visited))); |
| 234 } | 238 } |
| 235 return pCopy; | 239 return pCopy; |
| 236 } | 240 } |
| 237 case PDFOBJ_NULL: { | 241 case NULLOBJ: { |
| 238 return new CPDF_Null; | 242 return new CPDF_Null; |
| 239 } | 243 } |
| 240 case PDFOBJ_STREAM: { | 244 case STREAM: { |
| 241 const CPDF_Stream* pThis = AsStream(); | 245 const CPDF_Stream* pThis = AsStream(); |
| 242 CPDF_StreamAcc acc; | 246 CPDF_StreamAcc acc; |
| 243 acc.LoadAllData(pThis, TRUE); | 247 acc.LoadAllData(pThis, TRUE); |
| 244 FX_DWORD streamSize = acc.GetSize(); | 248 FX_DWORD streamSize = acc.GetSize(); |
| 245 CPDF_Dictionary* pDict = pThis->GetDict(); | 249 CPDF_Dictionary* pDict = pThis->GetDict(); |
| 246 if (pDict) { | 250 if (pDict) { |
| 247 pDict = ToDictionary(pDict->CloneInternal(bDirect, visited)); | 251 pDict = ToDictionary(pDict->CloneInternal(bDirect, visited)); |
| 248 } | 252 } |
| 249 return new CPDF_Stream(acc.DetachData(), streamSize, pDict); | 253 return new CPDF_Stream(acc.DetachData(), streamSize, pDict); |
| 250 } | 254 } |
| 251 case PDFOBJ_REFERENCE: { | 255 case REFERENCE: { |
| 252 const CPDF_Reference* pRef = AsReference(); | 256 const CPDF_Reference* pRef = AsReference(); |
| 253 FX_DWORD obj_num = pRef->GetRefObjNum(); | 257 FX_DWORD obj_num = pRef->GetRefObjNum(); |
| 254 if (bDirect && !pdfium::ContainsKey(*visited, obj_num)) { | 258 if (bDirect && !pdfium::ContainsKey(*visited, obj_num)) { |
| 255 visited->insert(obj_num); | 259 visited->insert(obj_num); |
| 256 auto* pDirect = pRef->GetDirect(); | 260 auto* pDirect = pRef->GetDirect(); |
| 257 return pDirect ? pDirect->CloneInternal(TRUE, visited) : nullptr; | 261 return pDirect ? pDirect->CloneInternal(TRUE, visited) : nullptr; |
| 258 } | 262 } |
| 259 return new CPDF_Reference(pRef->m_pObjList, obj_num); | 263 return new CPDF_Reference(pRef->m_pObjList, obj_num); |
| 260 } | 264 } |
| 261 } | 265 } |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 350 | 354 |
| 351 CPDF_String* CPDF_Object::AsString() { | 355 CPDF_String* CPDF_Object::AsString() { |
| 352 return IsString() ? static_cast<CPDF_String*>(this) : nullptr; | 356 return IsString() ? static_cast<CPDF_String*>(this) : nullptr; |
| 353 } | 357 } |
| 354 | 358 |
| 355 const CPDF_String* CPDF_Object::AsString() const { | 359 const CPDF_String* CPDF_Object::AsString() const { |
| 356 return IsString() ? static_cast<const CPDF_String*>(this) : nullptr; | 360 return IsString() ? static_cast<const CPDF_String*>(this) : nullptr; |
| 357 } | 361 } |
| 358 | 362 |
| 359 CPDF_Number::CPDF_Number(int value) | 363 CPDF_Number::CPDF_Number(int value) |
| 360 : CPDF_Object(PDFOBJ_NUMBER), m_bInteger(TRUE), m_Integer(value) {} | 364 : CPDF_Object(NUMBER), m_bInteger(TRUE), m_Integer(value) {} |
| 361 | 365 |
| 362 CPDF_Number::CPDF_Number(FX_FLOAT value) | 366 CPDF_Number::CPDF_Number(FX_FLOAT value) |
| 363 : CPDF_Object(PDFOBJ_NUMBER), m_bInteger(FALSE), m_Float(value) {} | 367 : CPDF_Object(NUMBER), m_bInteger(FALSE), m_Float(value) {} |
| 364 | 368 |
| 365 CPDF_Number::CPDF_Number(const CFX_ByteStringC& str) | 369 CPDF_Number::CPDF_Number(const CFX_ByteStringC& str) : CPDF_Object(NUMBER) { |
| 366 : CPDF_Object(PDFOBJ_NUMBER) { | |
| 367 FX_atonum(str, m_bInteger, &m_Integer); | 370 FX_atonum(str, m_bInteger, &m_Integer); |
| 368 } | 371 } |
| 369 | 372 |
| 370 void CPDF_Number::SetString(const CFX_ByteStringC& str) { | 373 void CPDF_Number::SetString(const CFX_ByteStringC& str) { |
| 371 FX_atonum(str, m_bInteger, &m_Integer); | 374 FX_atonum(str, m_bInteger, &m_Integer); |
| 372 } | 375 } |
| 373 FX_BOOL CPDF_Number::Identical(CPDF_Number* pOther) const { | 376 FX_BOOL CPDF_Number::Identical(CPDF_Number* pOther) const { |
| 374 return m_bInteger == pOther->m_bInteger && m_Integer == pOther->m_Integer; | 377 return m_bInteger == pOther->m_bInteger && m_Integer == pOther->m_Integer; |
| 375 } | 378 } |
| 376 CFX_ByteString CPDF_Number::GetString() const { | 379 CFX_ByteString CPDF_Number::GetString() const { |
| 377 return m_bInteger ? CFX_ByteString::FormatInteger(m_Integer, FXFORMAT_SIGNED) | 380 return m_bInteger ? CFX_ByteString::FormatInteger(m_Integer, FXFORMAT_SIGNED) |
| 378 : CFX_ByteString::FormatFloat(m_Float); | 381 : CFX_ByteString::FormatFloat(m_Float); |
| 379 } | 382 } |
| 380 void CPDF_Number::SetNumber(FX_FLOAT value) { | 383 void CPDF_Number::SetNumber(FX_FLOAT value) { |
| 381 m_bInteger = FALSE; | 384 m_bInteger = FALSE; |
| 382 m_Float = value; | 385 m_Float = value; |
| 383 } | 386 } |
| 384 CPDF_String::CPDF_String(const CFX_WideString& str) | 387 CPDF_String::CPDF_String(const CFX_WideString& str) |
| 385 : CPDF_Object(PDFOBJ_STRING), m_bHex(FALSE) { | 388 : CPDF_Object(STRING), m_bHex(FALSE) { |
| 386 m_String = PDF_EncodeText(str); | 389 m_String = PDF_EncodeText(str); |
| 387 } | 390 } |
| 388 CPDF_Array::~CPDF_Array() { | 391 CPDF_Array::~CPDF_Array() { |
| 389 int size = m_Objects.GetSize(); | 392 int size = m_Objects.GetSize(); |
| 390 CPDF_Object** pList = m_Objects.GetData(); | 393 CPDF_Object** pList = m_Objects.GetData(); |
| 391 for (int i = 0; i < size; i++) { | 394 for (int i = 0; i < size; i++) { |
| 392 if (pList[i]) | 395 if (pList[i]) |
| 393 pList[i]->Release(); | 396 pList[i]->Release(); |
| 394 } | 397 } |
| 395 } | 398 } |
| (...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 668 if (it->second == pObj) | 671 if (it->second == pObj) |
| 669 return; | 672 return; |
| 670 it->second->Release(); | 673 it->second->Release(); |
| 671 | 674 |
| 672 if (pObj) | 675 if (pObj) |
| 673 it->second = pObj; | 676 it->second = pObj; |
| 674 else | 677 else |
| 675 m_Map.erase(it); | 678 m_Map.erase(it); |
| 676 } | 679 } |
| 677 void CPDF_Dictionary::RemoveAt(const CFX_ByteStringC& key) { | 680 void CPDF_Dictionary::RemoveAt(const CFX_ByteStringC& key) { |
| 678 ASSERT(m_Type == PDFOBJ_DICTIONARY); | 681 ASSERT(m_Type == DICTIONARY); |
| 679 auto it = m_Map.find(key); | 682 auto it = m_Map.find(key); |
| 680 if (it == m_Map.end()) | 683 if (it == m_Map.end()) |
| 681 return; | 684 return; |
| 682 | 685 |
| 683 it->second->Release(); | 686 it->second->Release(); |
| 684 m_Map.erase(it); | 687 m_Map.erase(it); |
| 685 } | 688 } |
| 686 void CPDF_Dictionary::ReplaceKey(const CFX_ByteStringC& oldkey, | 689 void CPDF_Dictionary::ReplaceKey(const CFX_ByteStringC& oldkey, |
| 687 const CFX_ByteStringC& newkey) { | 690 const CFX_ByteStringC& newkey) { |
| 688 ASSERT(m_Type == PDFOBJ_DICTIONARY); | 691 ASSERT(m_Type == DICTIONARY); |
| 689 auto old_it = m_Map.find(oldkey); | 692 auto old_it = m_Map.find(oldkey); |
| 690 if (old_it == m_Map.end()) | 693 if (old_it == m_Map.end()) |
| 691 return; | 694 return; |
| 692 | 695 |
| 693 // Avoid 2 constructions of CFX_ByteString. | 696 // Avoid 2 constructions of CFX_ByteString. |
| 694 CFX_ByteString newkey_bytestring = newkey; | 697 CFX_ByteString newkey_bytestring = newkey; |
| 695 auto new_it = m_Map.find(newkey_bytestring); | 698 auto new_it = m_Map.find(newkey_bytestring); |
| 696 if (new_it == old_it) | 699 if (new_it == old_it) |
| 697 return; | 700 return; |
| 698 | 701 |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 761 CPDF_Array* pArray = new CPDF_Array; | 764 CPDF_Array* pArray = new CPDF_Array; |
| 762 pArray->AddNumber16(matrix.a); | 765 pArray->AddNumber16(matrix.a); |
| 763 pArray->AddNumber16(matrix.b); | 766 pArray->AddNumber16(matrix.b); |
| 764 pArray->AddNumber16(matrix.c); | 767 pArray->AddNumber16(matrix.c); |
| 765 pArray->AddNumber16(matrix.d); | 768 pArray->AddNumber16(matrix.d); |
| 766 pArray->AddNumber(matrix.e); | 769 pArray->AddNumber(matrix.e); |
| 767 pArray->AddNumber(matrix.f); | 770 pArray->AddNumber(matrix.f); |
| 768 SetAt(key, pArray); | 771 SetAt(key, pArray); |
| 769 } | 772 } |
| 770 CPDF_Stream::CPDF_Stream(uint8_t* pData, FX_DWORD size, CPDF_Dictionary* pDict) | 773 CPDF_Stream::CPDF_Stream(uint8_t* pData, FX_DWORD size, CPDF_Dictionary* pDict) |
| 771 : CPDF_Object(PDFOBJ_STREAM), | 774 : CPDF_Object(STREAM), |
| 772 m_pDict(pDict), | 775 m_pDict(pDict), |
| 773 m_dwSize(size), | 776 m_dwSize(size), |
| 774 m_GenNum(kMemoryBasedGenNum), | 777 m_GenNum(kMemoryBasedGenNum), |
| 775 m_pDataBuf(pData) {} | 778 m_pDataBuf(pData) {} |
| 776 | 779 |
| 777 CPDF_Stream::~CPDF_Stream() { | 780 CPDF_Stream::~CPDF_Stream() { |
| 778 if (IsMemoryBased()) | 781 if (IsMemoryBased()) |
| 779 FX_Free(m_pDataBuf); | 782 FX_Free(m_pDataBuf); |
| 780 | 783 |
| 781 if (m_pDict) | 784 if (m_pDict) |
| (...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1077 pObj->Destroy(); | 1080 pObj->Destroy(); |
| 1078 return FALSE; | 1081 return FALSE; |
| 1079 } | 1082 } |
| 1080 it->second->Destroy(); | 1083 it->second->Destroy(); |
| 1081 } | 1084 } |
| 1082 pObj->m_ObjNum = objnum; | 1085 pObj->m_ObjNum = objnum; |
| 1083 m_IndirectObjs[objnum] = pObj; | 1086 m_IndirectObjs[objnum] = pObj; |
| 1084 m_LastObjNum = std::max(m_LastObjNum, objnum); | 1087 m_LastObjNum = std::max(m_LastObjNum, objnum); |
| 1085 return TRUE; | 1088 return TRUE; |
| 1086 } | 1089 } |
| OLD | NEW |