| 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/src/fpdfapi/fpdf_page/pageint.h" | 7 #include "core/src/fpdfapi/fpdf_page/pageint.h" |
| 8 | 8 |
| 9 #include "core/include/fpdfapi/fpdf_module.h" | 9 #include "core/include/fpdfapi/fpdf_module.h" |
| 10 #include "core/include/fpdfapi/fpdf_page.h" | 10 #include "core/include/fpdfapi/fpdf_page.h" |
| (...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 202 return index; | 202 return index; |
| 203 } | 203 } |
| 204 | 204 |
| 205 void CPDF_StreamContentParser::AddNameParam(const FX_CHAR* name, int len) { | 205 void CPDF_StreamContentParser::AddNameParam(const FX_CHAR* name, int len) { |
| 206 int index = GetNextParamPos(); | 206 int index = GetNextParamPos(); |
| 207 if (len > 32) { | 207 if (len > 32) { |
| 208 m_ParamBuf1[index].m_Type = 0; | 208 m_ParamBuf1[index].m_Type = 0; |
| 209 m_ParamBuf1[index].m_pObject = | 209 m_ParamBuf1[index].m_pObject = |
| 210 new CPDF_Name(PDF_NameDecode(CFX_ByteStringC(name, len))); | 210 new CPDF_Name(PDF_NameDecode(CFX_ByteStringC(name, len))); |
| 211 } else { | 211 } else { |
| 212 m_ParamBuf1[index].m_Type = PDFOBJ_NAME; | 212 m_ParamBuf1[index].m_Type = CPDF_Object::NAME; |
| 213 if (!FXSYS_memchr(name, '#', len)) { | 213 if (!FXSYS_memchr(name, '#', len)) { |
| 214 FXSYS_memcpy(m_ParamBuf1[index].m_Name.m_Buffer, name, len); | 214 FXSYS_memcpy(m_ParamBuf1[index].m_Name.m_Buffer, name, len); |
| 215 m_ParamBuf1[index].m_Name.m_Len = len; | 215 m_ParamBuf1[index].m_Name.m_Len = len; |
| 216 } else { | 216 } else { |
| 217 CFX_ByteString str = PDF_NameDecode(CFX_ByteStringC(name, len)); | 217 CFX_ByteString str = PDF_NameDecode(CFX_ByteStringC(name, len)); |
| 218 FXSYS_memcpy(m_ParamBuf1[index].m_Name.m_Buffer, str.c_str(), | 218 FXSYS_memcpy(m_ParamBuf1[index].m_Name.m_Buffer, str.c_str(), |
| 219 str.GetLength()); | 219 str.GetLength()); |
| 220 m_ParamBuf1[index].m_Name.m_Len = str.GetLength(); | 220 m_ParamBuf1[index].m_Name.m_Len = str.GetLength(); |
| 221 } | 221 } |
| 222 } | 222 } |
| 223 } | 223 } |
| 224 | 224 |
| 225 void CPDF_StreamContentParser::AddNumberParam(const FX_CHAR* str, int len) { | 225 void CPDF_StreamContentParser::AddNumberParam(const FX_CHAR* str, int len) { |
| 226 int index = GetNextParamPos(); | 226 int index = GetNextParamPos(); |
| 227 m_ParamBuf1[index].m_Type = PDFOBJ_NUMBER; | 227 m_ParamBuf1[index].m_Type = CPDF_Object::NUMBER; |
| 228 FX_atonum(CFX_ByteStringC(str, len), m_ParamBuf1[index].m_Number.m_bInteger, | 228 FX_atonum(CFX_ByteStringC(str, len), m_ParamBuf1[index].m_Number.m_bInteger, |
| 229 &m_ParamBuf1[index].m_Number.m_Integer); | 229 &m_ParamBuf1[index].m_Number.m_Integer); |
| 230 } | 230 } |
| 231 void CPDF_StreamContentParser::AddObjectParam(CPDF_Object* pObj) { | 231 void CPDF_StreamContentParser::AddObjectParam(CPDF_Object* pObj) { |
| 232 int index = GetNextParamPos(); | 232 int index = GetNextParamPos(); |
| 233 m_ParamBuf1[index].m_Type = 0; | 233 m_ParamBuf1[index].m_Type = 0; |
| 234 m_ParamBuf1[index].m_pObject = pObj; | 234 m_ParamBuf1[index].m_pObject = pObj; |
| 235 } | 235 } |
| 236 void CPDF_StreamContentParser::ClearAllParams() { | 236 void CPDF_StreamContentParser::ClearAllParams() { |
| 237 FX_DWORD index = m_ParamStartPos; | 237 FX_DWORD index = m_ParamStartPos; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 251 | 251 |
| 252 CPDF_Object* CPDF_StreamContentParser::GetObject(FX_DWORD index) { | 252 CPDF_Object* CPDF_StreamContentParser::GetObject(FX_DWORD index) { |
| 253 if (index >= m_ParamCount) { | 253 if (index >= m_ParamCount) { |
| 254 return NULL; | 254 return NULL; |
| 255 } | 255 } |
| 256 int real_index = m_ParamStartPos + m_ParamCount - index - 1; | 256 int real_index = m_ParamStartPos + m_ParamCount - index - 1; |
| 257 if (real_index >= PARAM_BUF_SIZE) { | 257 if (real_index >= PARAM_BUF_SIZE) { |
| 258 real_index -= PARAM_BUF_SIZE; | 258 real_index -= PARAM_BUF_SIZE; |
| 259 } | 259 } |
| 260 ContentParam& param = m_ParamBuf1[real_index]; | 260 ContentParam& param = m_ParamBuf1[real_index]; |
| 261 if (param.m_Type == PDFOBJ_NUMBER) { | 261 if (param.m_Type == CPDF_Object::NUMBER) { |
| 262 CPDF_Number* pNumber = param.m_Number.m_bInteger | 262 CPDF_Number* pNumber = param.m_Number.m_bInteger |
| 263 ? new CPDF_Number(param.m_Number.m_Integer) | 263 ? new CPDF_Number(param.m_Number.m_Integer) |
| 264 : new CPDF_Number(param.m_Number.m_Float); | 264 : new CPDF_Number(param.m_Number.m_Float); |
| 265 | 265 |
| 266 param.m_Type = 0; | 266 param.m_Type = 0; |
| 267 param.m_pObject = pNumber; | 267 param.m_pObject = pNumber; |
| 268 return pNumber; | 268 return pNumber; |
| 269 } | 269 } |
| 270 if (param.m_Type == PDFOBJ_NAME) { | 270 if (param.m_Type == CPDF_Object::NAME) { |
| 271 CPDF_Name* pName = new CPDF_Name( | 271 CPDF_Name* pName = new CPDF_Name( |
| 272 CFX_ByteString(param.m_Name.m_Buffer, param.m_Name.m_Len)); | 272 CFX_ByteString(param.m_Name.m_Buffer, param.m_Name.m_Len)); |
| 273 param.m_Type = 0; | 273 param.m_Type = 0; |
| 274 param.m_pObject = pName; | 274 param.m_pObject = pName; |
| 275 return pName; | 275 return pName; |
| 276 } | 276 } |
| 277 if (param.m_Type == 0) { | 277 if (param.m_Type == 0) { |
| 278 return param.m_pObject; | 278 return param.m_pObject; |
| 279 } | 279 } |
| 280 ASSERT(FALSE); | 280 ASSERT(FALSE); |
| 281 return NULL; | 281 return NULL; |
| 282 } | 282 } |
| 283 | 283 |
| 284 CFX_ByteString CPDF_StreamContentParser::GetString(FX_DWORD index) { | 284 CFX_ByteString CPDF_StreamContentParser::GetString(FX_DWORD index) { |
| 285 if (index >= m_ParamCount) { | 285 if (index >= m_ParamCount) { |
| 286 return CFX_ByteString(); | 286 return CFX_ByteString(); |
| 287 } | 287 } |
| 288 int real_index = m_ParamStartPos + m_ParamCount - index - 1; | 288 int real_index = m_ParamStartPos + m_ParamCount - index - 1; |
| 289 if (real_index >= PARAM_BUF_SIZE) { | 289 if (real_index >= PARAM_BUF_SIZE) { |
| 290 real_index -= PARAM_BUF_SIZE; | 290 real_index -= PARAM_BUF_SIZE; |
| 291 } | 291 } |
| 292 ContentParam& param = m_ParamBuf1[real_index]; | 292 ContentParam& param = m_ParamBuf1[real_index]; |
| 293 if (param.m_Type == PDFOBJ_NAME) { | 293 if (param.m_Type == CPDF_Object::NAME) { |
| 294 return CFX_ByteString(param.m_Name.m_Buffer, param.m_Name.m_Len); | 294 return CFX_ByteString(param.m_Name.m_Buffer, param.m_Name.m_Len); |
| 295 } | 295 } |
| 296 if (param.m_Type == 0 && param.m_pObject) { | 296 if (param.m_Type == 0 && param.m_pObject) { |
| 297 return param.m_pObject->GetString(); | 297 return param.m_pObject->GetString(); |
| 298 } | 298 } |
| 299 return CFX_ByteString(); | 299 return CFX_ByteString(); |
| 300 } | 300 } |
| 301 | 301 |
| 302 FX_FLOAT CPDF_StreamContentParser::GetNumber(FX_DWORD index) { | 302 FX_FLOAT CPDF_StreamContentParser::GetNumber(FX_DWORD index) { |
| 303 if (index >= m_ParamCount) { | 303 if (index >= m_ParamCount) { |
| 304 return 0; | 304 return 0; |
| 305 } | 305 } |
| 306 int real_index = m_ParamStartPos + m_ParamCount - index - 1; | 306 int real_index = m_ParamStartPos + m_ParamCount - index - 1; |
| 307 if (real_index >= PARAM_BUF_SIZE) { | 307 if (real_index >= PARAM_BUF_SIZE) { |
| 308 real_index -= PARAM_BUF_SIZE; | 308 real_index -= PARAM_BUF_SIZE; |
| 309 } | 309 } |
| 310 ContentParam& param = m_ParamBuf1[real_index]; | 310 ContentParam& param = m_ParamBuf1[real_index]; |
| 311 if (param.m_Type == PDFOBJ_NUMBER) { | 311 if (param.m_Type == CPDF_Object::NUMBER) { |
| 312 return param.m_Number.m_bInteger ? (FX_FLOAT)param.m_Number.m_Integer | 312 return param.m_Number.m_bInteger ? (FX_FLOAT)param.m_Number.m_Integer |
| 313 : param.m_Number.m_Float; | 313 : param.m_Number.m_Float; |
| 314 } | 314 } |
| 315 if (param.m_Type == 0 && param.m_pObject) { | 315 if (param.m_Type == 0 && param.m_pObject) { |
| 316 return param.m_pObject->GetNumber(); | 316 return param.m_pObject->GetNumber(); |
| 317 } | 317 } |
| 318 return 0; | 318 return 0; |
| 319 } | 319 } |
| 320 | 320 |
| 321 FX_FLOAT CPDF_StreamContentParser::GetNumber16(FX_DWORD index) { | 321 FX_FLOAT CPDF_StreamContentParser::GetNumber16(FX_DWORD index) { |
| (...skipping 1430 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1752 } | 1752 } |
| 1753 if (!bProcessed) { | 1753 if (!bProcessed) { |
| 1754 m_pSyntax->SetPos(last_pos); | 1754 m_pSyntax->SetPos(last_pos); |
| 1755 return; | 1755 return; |
| 1756 } | 1756 } |
| 1757 } | 1757 } |
| 1758 } | 1758 } |
| 1759 | 1759 |
| 1760 void PDF_ReplaceAbbr(CPDF_Object* pObj) { | 1760 void PDF_ReplaceAbbr(CPDF_Object* pObj) { |
| 1761 switch (pObj->GetType()) { | 1761 switch (pObj->GetType()) { |
| 1762 case PDFOBJ_DICTIONARY: { | 1762 case CPDF_Object::DICTIONARY: { |
| 1763 CPDF_Dictionary* pDict = pObj->AsDictionary(); | 1763 CPDF_Dictionary* pDict = pObj->AsDictionary(); |
| 1764 std::vector<AbbrReplacementOp> replacements; | 1764 std::vector<AbbrReplacementOp> replacements; |
| 1765 for (const auto& it : *pDict) { | 1765 for (const auto& it : *pDict) { |
| 1766 CFX_ByteString key = it.first; | 1766 CFX_ByteString key = it.first; |
| 1767 CPDF_Object* value = it.second; | 1767 CPDF_Object* value = it.second; |
| 1768 CFX_ByteStringC fullname = PDF_FindFullName( | 1768 CFX_ByteStringC fullname = PDF_FindFullName( |
| 1769 PDF_InlineKeyAbbr, FX_ArraySize(PDF_InlineKeyAbbr), key); | 1769 PDF_InlineKeyAbbr, FX_ArraySize(PDF_InlineKeyAbbr), key); |
| 1770 if (!fullname.IsEmpty()) { | 1770 if (!fullname.IsEmpty()) { |
| 1771 AbbrReplacementOp op; | 1771 AbbrReplacementOp op; |
| 1772 op.is_replace_key = true; | 1772 op.is_replace_key = true; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 1792 } | 1792 } |
| 1793 } | 1793 } |
| 1794 for (const auto& op : replacements) { | 1794 for (const auto& op : replacements) { |
| 1795 if (op.is_replace_key) | 1795 if (op.is_replace_key) |
| 1796 pDict->ReplaceKey(op.key, op.replacement); | 1796 pDict->ReplaceKey(op.key, op.replacement); |
| 1797 else | 1797 else |
| 1798 pDict->SetAtName(op.key, op.replacement); | 1798 pDict->SetAtName(op.key, op.replacement); |
| 1799 } | 1799 } |
| 1800 break; | 1800 break; |
| 1801 } | 1801 } |
| 1802 case PDFOBJ_ARRAY: { | 1802 case CPDF_Object::ARRAY: { |
| 1803 CPDF_Array* pArray = pObj->AsArray(); | 1803 CPDF_Array* pArray = pObj->AsArray(); |
| 1804 for (FX_DWORD i = 0; i < pArray->GetCount(); i++) { | 1804 for (FX_DWORD i = 0; i < pArray->GetCount(); i++) { |
| 1805 CPDF_Object* pElement = pArray->GetElement(i); | 1805 CPDF_Object* pElement = pArray->GetElement(i); |
| 1806 if (pElement->IsName()) { | 1806 if (pElement->IsName()) { |
| 1807 CFX_ByteString name = pElement->GetString(); | 1807 CFX_ByteString name = pElement->GetString(); |
| 1808 CFX_ByteStringC fullname = PDF_FindFullName( | 1808 CFX_ByteStringC fullname = PDF_FindFullName( |
| 1809 PDF_InlineValueAbbr, FX_ArraySize(PDF_InlineValueAbbr), name); | 1809 PDF_InlineValueAbbr, FX_ArraySize(PDF_InlineValueAbbr), name); |
| 1810 if (!fullname.IsEmpty()) { | 1810 if (!fullname.IsEmpty()) { |
| 1811 pArray->SetAt(i, new CPDF_Name(fullname)); | 1811 pArray->SetAt(i, new CPDF_Name(fullname)); |
| 1812 } | 1812 } |
| 1813 } else { | 1813 } else { |
| 1814 PDF_ReplaceAbbr(pElement); | 1814 PDF_ReplaceAbbr(pElement); |
| 1815 } | 1815 } |
| 1816 } | 1816 } |
| 1817 break; | 1817 break; |
| 1818 } | 1818 } |
| 1819 default: |
| 1820 break; |
| 1819 } | 1821 } |
| 1820 } | 1822 } |
| OLD | NEW |