| 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 <limits.h> | 7 #include <limits.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 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 190 CPDF_Array* pWidthArray) { | 190 CPDF_Array* pWidthArray) { |
| 191 int size = end - start + 1; | 191 int size = end - start + 1; |
| 192 int* widths = FX_Alloc(int, size); | 192 int* widths = FX_Alloc(int, size); |
| 193 GetCharWidth(hDC, start, end, widths); | 193 GetCharWidth(hDC, start, end, widths); |
| 194 int i; | 194 int i; |
| 195 for (i = 1; i < size; i++) | 195 for (i = 1; i < size; i++) |
| 196 if (widths[i] != *widths) { | 196 if (widths[i] != *widths) { |
| 197 break; | 197 break; |
| 198 } | 198 } |
| 199 if (i == size) { | 199 if (i == size) { |
| 200 int first = pWidthArray->GetInteger(pWidthArray->GetCount() - 1); | 200 int first = pWidthArray->GetIntegerAt(pWidthArray->GetCount() - 1); |
| 201 pWidthArray->AddInteger(first + size - 1); | 201 pWidthArray->AddInteger(first + size - 1); |
| 202 pWidthArray->AddInteger(*widths); | 202 pWidthArray->AddInteger(*widths); |
| 203 } else { | 203 } else { |
| 204 CPDF_Array* pWidthArray1 = new CPDF_Array; | 204 CPDF_Array* pWidthArray1 = new CPDF_Array; |
| 205 pWidthArray->Add(pWidthArray1); | 205 pWidthArray->Add(pWidthArray1); |
| 206 for (i = 0; i < size; i++) { | 206 for (i = 0; i < size; i++) { |
| 207 pWidthArray1->AddInteger(widths[i]); | 207 pWidthArray1->AddInteger(widths[i]); |
| 208 } | 208 } |
| 209 } | 209 } |
| 210 FX_Free(widths); | 210 FX_Free(widths); |
| (...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 526 CPDF_Array* pWidthArray) { | 526 CPDF_Array* pWidthArray) { |
| 527 int size = end - start + 1; | 527 int size = end - start + 1; |
| 528 int* widths = FX_Alloc(int, size); | 528 int* widths = FX_Alloc(int, size); |
| 529 FX_GetCharWidth(font, start, end, widths); | 529 FX_GetCharWidth(font, start, end, widths); |
| 530 int i; | 530 int i; |
| 531 for (i = 1; i < size; i++) | 531 for (i = 1; i < size; i++) |
| 532 if (widths[i] != *widths) { | 532 if (widths[i] != *widths) { |
| 533 break; | 533 break; |
| 534 } | 534 } |
| 535 if (i == size) { | 535 if (i == size) { |
| 536 int first = pWidthArray->GetInteger(pWidthArray->GetCount() - 1); | 536 int first = pWidthArray->GetIntegerAt(pWidthArray->GetCount() - 1); |
| 537 pWidthArray->AddInteger(first + size - 1); | 537 pWidthArray->AddInteger(first + size - 1); |
| 538 pWidthArray->AddInteger(*widths); | 538 pWidthArray->AddInteger(*widths); |
| 539 } else { | 539 } else { |
| 540 CPDF_Array* pWidthArray1 = new CPDF_Array; | 540 CPDF_Array* pWidthArray1 = new CPDF_Array; |
| 541 pWidthArray->Add(pWidthArray1); | 541 pWidthArray->Add(pWidthArray1); |
| 542 for (i = 0; i < size; i++) { | 542 for (i = 0; i < size; i++) { |
| 543 pWidthArray1->AddInteger(widths[i]); | 543 pWidthArray1->AddInteger(widths[i]); |
| 544 } | 544 } |
| 545 } | 545 } |
| 546 FX_Free(widths); | 546 FX_Free(widths); |
| (...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 804 int i; | 804 int i; |
| 805 for (i = 0; i < size; i++) { | 805 for (i = 0; i < size; i++) { |
| 806 int glyph_index = pEncoding->GlyphFromCharCode(start + i); | 806 int glyph_index = pEncoding->GlyphFromCharCode(start + i); |
| 807 widths[i] = pFont->GetGlyphWidth(glyph_index); | 807 widths[i] = pFont->GetGlyphWidth(glyph_index); |
| 808 } | 808 } |
| 809 for (i = 1; i < size; i++) | 809 for (i = 1; i < size; i++) |
| 810 if (widths[i] != *widths) { | 810 if (widths[i] != *widths) { |
| 811 break; | 811 break; |
| 812 } | 812 } |
| 813 if (i == size) { | 813 if (i == size) { |
| 814 int first = pWidthArray->GetInteger(pWidthArray->GetCount() - 1); | 814 int first = pWidthArray->GetIntegerAt(pWidthArray->GetCount() - 1); |
| 815 pWidthArray->AddInteger(first + size - 1); | 815 pWidthArray->AddInteger(first + size - 1); |
| 816 pWidthArray->AddInteger(*widths); | 816 pWidthArray->AddInteger(*widths); |
| 817 } else { | 817 } else { |
| 818 CPDF_Array* pWidthArray1 = new CPDF_Array; | 818 CPDF_Array* pWidthArray1 = new CPDF_Array; |
| 819 pWidthArray->Add(pWidthArray1); | 819 pWidthArray->Add(pWidthArray1); |
| 820 for (i = 0; i < size; i++) { | 820 for (i = 0; i < size; i++) { |
| 821 pWidthArray1->AddInteger(widths[i]); | 821 pWidthArray1->AddInteger(widths[i]); |
| 822 } | 822 } |
| 823 } | 823 } |
| 824 FX_Free(widths); | 824 FX_Free(widths); |
| (...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1011 AddIndirectObject(pFontDesc); | 1011 AddIndirectObject(pFontDesc); |
| 1012 pFontDict->SetAtReference("FontDescriptor", this, pFontDesc); | 1012 pFontDict->SetAtReference("FontDescriptor", this, pFontDesc); |
| 1013 return LoadFont(pBaseDict); | 1013 return LoadFont(pBaseDict); |
| 1014 } | 1014 } |
| 1015 static int InsertDeletePDFPage(CPDF_Document* pDoc, | 1015 static int InsertDeletePDFPage(CPDF_Document* pDoc, |
| 1016 CPDF_Dictionary* pPages, | 1016 CPDF_Dictionary* pPages, |
| 1017 int nPagesToGo, | 1017 int nPagesToGo, |
| 1018 CPDF_Dictionary* pPage, | 1018 CPDF_Dictionary* pPage, |
| 1019 FX_BOOL bInsert, | 1019 FX_BOOL bInsert, |
| 1020 CFX_ArrayTemplate<CPDF_Dictionary*>& stackList) { | 1020 CFX_ArrayTemplate<CPDF_Dictionary*>& stackList) { |
| 1021 CPDF_Array* pKidList = pPages->GetArray("Kids"); | 1021 CPDF_Array* pKidList = pPages->GetArrayBy("Kids"); |
| 1022 if (!pKidList) { | 1022 if (!pKidList) { |
| 1023 return -1; | 1023 return -1; |
| 1024 } | 1024 } |
| 1025 int nKids = pKidList->GetCount(); | 1025 int nKids = pKidList->GetCount(); |
| 1026 for (int i = 0; i < nKids; i++) { | 1026 for (int i = 0; i < nKids; i++) { |
| 1027 CPDF_Dictionary* pKid = pKidList->GetDict(i); | 1027 CPDF_Dictionary* pKid = pKidList->GetDictAt(i); |
| 1028 if (pKid->GetString("Type") == "Page") { | 1028 if (pKid->GetStringBy("Type") == "Page") { |
| 1029 if (nPagesToGo == 0) { | 1029 if (nPagesToGo == 0) { |
| 1030 if (bInsert) { | 1030 if (bInsert) { |
| 1031 pKidList->InsertAt(i, new CPDF_Reference(pDoc, pPage->GetObjNum())); | 1031 pKidList->InsertAt(i, new CPDF_Reference(pDoc, pPage->GetObjNum())); |
| 1032 pPage->SetAtReference("Parent", pDoc, pPages->GetObjNum()); | 1032 pPage->SetAtReference("Parent", pDoc, pPages->GetObjNum()); |
| 1033 } else { | 1033 } else { |
| 1034 pKidList->RemoveAt(i); | 1034 pKidList->RemoveAt(i); |
| 1035 } | 1035 } |
| 1036 pPages->SetAtInteger("Count", | 1036 pPages->SetAtInteger( |
| 1037 pPages->GetInteger("Count") + (bInsert ? 1 : -1)); | 1037 "Count", pPages->GetIntegerBy("Count") + (bInsert ? 1 : -1)); |
| 1038 return 1; | 1038 return 1; |
| 1039 } | 1039 } |
| 1040 nPagesToGo--; | 1040 nPagesToGo--; |
| 1041 } else { | 1041 } else { |
| 1042 int nPages = pKid->GetInteger("Count"); | 1042 int nPages = pKid->GetIntegerBy("Count"); |
| 1043 if (nPagesToGo < nPages) { | 1043 if (nPagesToGo < nPages) { |
| 1044 int stackCount = stackList.GetSize(); | 1044 int stackCount = stackList.GetSize(); |
| 1045 for (int j = 0; j < stackCount; ++j) { | 1045 for (int j = 0; j < stackCount; ++j) { |
| 1046 if (pKid == stackList[j]) { | 1046 if (pKid == stackList[j]) { |
| 1047 return -1; | 1047 return -1; |
| 1048 } | 1048 } |
| 1049 } | 1049 } |
| 1050 stackList.Add(pKid); | 1050 stackList.Add(pKid); |
| 1051 if (InsertDeletePDFPage(pDoc, pKid, nPagesToGo, pPage, bInsert, | 1051 if (InsertDeletePDFPage(pDoc, pKid, nPagesToGo, pPage, bInsert, |
| 1052 stackList) < 0) { | 1052 stackList) < 0) { |
| 1053 return -1; | 1053 return -1; |
| 1054 } | 1054 } |
| 1055 stackList.RemoveAt(stackCount); | 1055 stackList.RemoveAt(stackCount); |
| 1056 pPages->SetAtInteger("Count", | 1056 pPages->SetAtInteger( |
| 1057 pPages->GetInteger("Count") + (bInsert ? 1 : -1)); | 1057 "Count", pPages->GetIntegerBy("Count") + (bInsert ? 1 : -1)); |
| 1058 return 1; | 1058 return 1; |
| 1059 } | 1059 } |
| 1060 nPagesToGo -= nPages; | 1060 nPagesToGo -= nPages; |
| 1061 } | 1061 } |
| 1062 } | 1062 } |
| 1063 return 0; | 1063 return 0; |
| 1064 } | 1064 } |
| 1065 static int InsertNewPage(CPDF_Document* pDoc, | 1065 static int InsertNewPage(CPDF_Document* pDoc, |
| 1066 int iPage, | 1066 int iPage, |
| 1067 CPDF_Dictionary* pPageDict, | 1067 CPDF_Dictionary* pPageDict, |
| 1068 CFX_DWordArray& pageList) { | 1068 CFX_DWordArray& pageList) { |
| 1069 CPDF_Dictionary* pRoot = pDoc->GetRoot(); | 1069 CPDF_Dictionary* pRoot = pDoc->GetRoot(); |
| 1070 if (!pRoot) { | 1070 if (!pRoot) { |
| 1071 return -1; | 1071 return -1; |
| 1072 } | 1072 } |
| 1073 CPDF_Dictionary* pPages = pRoot->GetDict("Pages"); | 1073 CPDF_Dictionary* pPages = pRoot->GetDictBy("Pages"); |
| 1074 if (!pPages) { | 1074 if (!pPages) { |
| 1075 return -1; | 1075 return -1; |
| 1076 } | 1076 } |
| 1077 int nPages = pDoc->GetPageCount(); | 1077 int nPages = pDoc->GetPageCount(); |
| 1078 if (iPage < 0 || iPage > nPages) { | 1078 if (iPage < 0 || iPage > nPages) { |
| 1079 return -1; | 1079 return -1; |
| 1080 } | 1080 } |
| 1081 if (iPage == nPages) { | 1081 if (iPage == nPages) { |
| 1082 CPDF_Array* pPagesList = pPages->GetArray("Kids"); | 1082 CPDF_Array* pPagesList = pPages->GetArrayBy("Kids"); |
| 1083 if (!pPagesList) { | 1083 if (!pPagesList) { |
| 1084 pPagesList = new CPDF_Array; | 1084 pPagesList = new CPDF_Array; |
| 1085 pPages->SetAt("Kids", pPagesList); | 1085 pPages->SetAt("Kids", pPagesList); |
| 1086 } | 1086 } |
| 1087 pPagesList->Add(pPageDict, pDoc); | 1087 pPagesList->Add(pPageDict, pDoc); |
| 1088 pPages->SetAtInteger("Count", nPages + 1); | 1088 pPages->SetAtInteger("Count", nPages + 1); |
| 1089 pPageDict->SetAtReference("Parent", pDoc, pPages->GetObjNum()); | 1089 pPageDict->SetAtReference("Parent", pDoc, pPages->GetObjNum()); |
| 1090 } else { | 1090 } else { |
| 1091 CFX_ArrayTemplate<CPDF_Dictionary*> stack; | 1091 CFX_ArrayTemplate<CPDF_Dictionary*> stack; |
| 1092 stack.Add(pPages); | 1092 stack.Add(pPages); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 1114 if (PDF_GetStandardFontName(&name) < 0) | 1114 if (PDF_GetStandardFontName(&name) < 0) |
| 1115 return nullptr; | 1115 return nullptr; |
| 1116 return GetPageData()->GetStandardFont(name, pEncoding); | 1116 return GetPageData()->GetStandardFont(name, pEncoding); |
| 1117 } | 1117 } |
| 1118 | 1118 |
| 1119 void CPDF_Document::DeletePage(int iPage) { | 1119 void CPDF_Document::DeletePage(int iPage) { |
| 1120 CPDF_Dictionary* pRoot = GetRoot(); | 1120 CPDF_Dictionary* pRoot = GetRoot(); |
| 1121 if (!pRoot) { | 1121 if (!pRoot) { |
| 1122 return; | 1122 return; |
| 1123 } | 1123 } |
| 1124 CPDF_Dictionary* pPages = pRoot->GetDict("Pages"); | 1124 CPDF_Dictionary* pPages = pRoot->GetDictBy("Pages"); |
| 1125 if (!pPages) { | 1125 if (!pPages) { |
| 1126 return; | 1126 return; |
| 1127 } | 1127 } |
| 1128 int nPages = pPages->GetInteger("Count"); | 1128 int nPages = pPages->GetIntegerBy("Count"); |
| 1129 if (iPage < 0 || iPage >= nPages) { | 1129 if (iPage < 0 || iPage >= nPages) { |
| 1130 return; | 1130 return; |
| 1131 } | 1131 } |
| 1132 CFX_ArrayTemplate<CPDF_Dictionary*> stack; | 1132 CFX_ArrayTemplate<CPDF_Dictionary*> stack; |
| 1133 stack.Add(pPages); | 1133 stack.Add(pPages); |
| 1134 if (InsertDeletePDFPage(this, pPages, iPage, NULL, FALSE, stack) < 0) { | 1134 if (InsertDeletePDFPage(this, pPages, iPage, NULL, FALSE, stack) < 0) { |
| 1135 return; | 1135 return; |
| 1136 } | 1136 } |
| 1137 m_PageList.RemoveAt(iPage); | 1137 m_PageList.RemoveAt(iPage); |
| 1138 } | 1138 } |
| 1139 CPDF_Object* FPDFAPI_GetPageAttr(CPDF_Dictionary* pPageDict, | 1139 CPDF_Object* FPDFAPI_GetPageAttr(CPDF_Dictionary* pPageDict, |
| 1140 const CFX_ByteStringC& name); | 1140 const CFX_ByteStringC& name); |
| 1141 void FPDFAPI_FlatPageAttr(CPDF_Dictionary* pPageDict, | 1141 void FPDFAPI_FlatPageAttr(CPDF_Dictionary* pPageDict, |
| 1142 const CFX_ByteStringC& name) { | 1142 const CFX_ByteStringC& name) { |
| 1143 if (pPageDict->KeyExist(name)) { | 1143 if (pPageDict->KeyExist(name)) { |
| 1144 return; | 1144 return; |
| 1145 } | 1145 } |
| 1146 CPDF_Object* pObj = FPDFAPI_GetPageAttr(pPageDict, name); | 1146 CPDF_Object* pObj = FPDFAPI_GetPageAttr(pPageDict, name); |
| 1147 if (pObj) { | 1147 if (pObj) { |
| 1148 pPageDict->SetAt(name, pObj->Clone()); | 1148 pPageDict->SetAt(name, pObj->Clone()); |
| 1149 } | 1149 } |
| 1150 } | 1150 } |
| OLD | NEW |