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/fsdk_define.h" | 7 #include "../include/fsdk_define.h" |
| 8 #include "../../public/fpdf_doc.h" | 8 #include "../../public/fpdf_doc.h" |
| 9 | 9 |
| 10 namespace { | 10 namespace { |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 119 | 119 |
| 120 DLLEXPORT FPDF_ACTION STDCALL FPDFBookmark_GetAction(FPDF_BOOKMARK pDict) { | 120 DLLEXPORT FPDF_ACTION STDCALL FPDFBookmark_GetAction(FPDF_BOOKMARK pDict) { |
| 121 if (!pDict) | 121 if (!pDict) |
| 122 return NULL; | 122 return NULL; |
| 123 CPDF_Bookmark bookmark((CPDF_Dictionary*)pDict); | 123 CPDF_Bookmark bookmark((CPDF_Dictionary*)pDict); |
| 124 return bookmark.GetAction().GetDict(); | 124 return bookmark.GetAction().GetDict(); |
| 125 } | 125 } |
| 126 | 126 |
| 127 DLLEXPORT unsigned long STDCALL FPDFAction_GetType(FPDF_ACTION pDict) { | 127 DLLEXPORT unsigned long STDCALL FPDFAction_GetType(FPDF_ACTION pDict) { |
| 128 if (!pDict) | 128 if (!pDict) |
| 129 return 0; | 129 return PDFACTION_UNSUPPORTED; |
| 130 | |
| 130 CPDF_Action action((CPDF_Dictionary*)pDict); | 131 CPDF_Action action((CPDF_Dictionary*)pDict); |
| 131 CPDF_Action::ActionType type = action.GetType(); | 132 CPDF_Action::ActionType type = action.GetType(); |
| 132 switch (type) { | 133 switch (type) { |
| 133 case CPDF_Action::GoTo: | 134 case CPDF_Action::GoTo: |
| 134 return PDFACTION_GOTO; | 135 return PDFACTION_GOTO; |
| 135 case CPDF_Action::GoToR: | 136 case CPDF_Action::GoToR: |
| 136 return PDFACTION_REMOTEGOTO; | 137 return PDFACTION_REMOTEGOTO; |
| 137 case CPDF_Action::URI: | 138 case CPDF_Action::URI: |
| 138 return PDFACTION_URI; | 139 return PDFACTION_URI; |
| 139 case CPDF_Action::Launch: | 140 case CPDF_Action::Launch: |
| 140 return PDFACTION_LAUNCH; | 141 return PDFACTION_LAUNCH; |
| 141 default: | 142 default: |
| 142 return PDFACTION_UNSUPPORTED; | 143 return PDFACTION_UNSUPPORTED; |
| 143 } | 144 } |
| 144 return PDFACTION_UNSUPPORTED; | |
| 145 } | 145 } |
| 146 | 146 |
| 147 DLLEXPORT FPDF_DEST STDCALL FPDFAction_GetDest(FPDF_DOCUMENT document, | 147 DLLEXPORT FPDF_DEST STDCALL FPDFAction_GetDest(FPDF_DOCUMENT document, |
| 148 FPDF_ACTION pDict) { | 148 FPDF_ACTION pDict) { |
| 149 if (!document) | 149 if (!document) |
|
jun_fang
2015/09/14 14:18:57
if (!document || !pDict)
return NULL;
Lei Zhang
2015/09/15 08:24:50
Done. (note this is existing code that I didn't wr
| |
| 150 return NULL; | 150 return NULL; |
| 151 if (!pDict) | 151 if (!pDict) |
| 152 return NULL; | 152 return NULL; |
| 153 CPDF_Document* pDoc = (CPDF_Document*)document; | 153 CPDF_Document* pDoc = (CPDF_Document*)document; |
| 154 CPDF_Action action((CPDF_Dictionary*)pDict); | 154 CPDF_Action action((CPDF_Dictionary*)pDict); |
| 155 return action.GetDest(pDoc).GetObject(); | 155 return action.GetDest(pDoc).GetObject(); |
| 156 } | 156 } |
| 157 | 157 |
| 158 DLLEXPORT unsigned long STDCALL | |
| 159 FPDFAction_GetFilePath(FPDF_ACTION pDict, void* buffer, unsigned long buflen) { | |
| 160 unsigned long type = FPDFAction_GetType(pDict); | |
| 161 if (type != PDFACTION_REMOTEGOTO && type != PDFACTION_LAUNCH) | |
| 162 return 0; | |
| 163 | |
| 164 CPDF_Action action((CPDF_Dictionary*)pDict); | |
| 165 CFX_ByteString path = action.GetFilePath().UTF8Encode(); | |
| 166 unsigned long len = path.GetLength() + 1; | |
| 167 if (buffer && buflen >= len) | |
|
jun_fang
2015/09/14 12:10:43
it should return 0 in 'else' rather than len.
Lei Zhang
2015/09/15 08:24:50
Are you saying I should write the following?
if (
jun_fang
2015/09/15 08:35:03
yes. For else cases, when buffer is null or buflen
Lei Zhang
2015/09/15 08:50:57
But returning 0 contradicts the comments section o
| |
| 168 FXSYS_memcpy(buffer, path.c_str(), len); | |
| 169 return len; | |
| 170 } | |
| 171 | |
| 158 DLLEXPORT unsigned long STDCALL FPDFAction_GetURIPath(FPDF_DOCUMENT document, | 172 DLLEXPORT unsigned long STDCALL FPDFAction_GetURIPath(FPDF_DOCUMENT document, |
| 159 FPDF_ACTION pDict, | 173 FPDF_ACTION pDict, |
| 160 void* buffer, | 174 void* buffer, |
| 161 unsigned long buflen) { | 175 unsigned long buflen) { |
| 162 if (!document) | 176 if (!document) |
|
jun_fang
2015/09/14 14:18:57
if (!document || !pDict)
return 0;
Lei Zhang
2015/09/15 08:24:50
Done.
| |
| 163 return 0; | 177 return 0; |
| 164 if (!pDict) | 178 if (!pDict) |
| 165 return 0; | 179 return 0; |
| 166 CPDF_Document* pDoc = (CPDF_Document*)document; | 180 CPDF_Document* pDoc = (CPDF_Document*)document; |
| 167 CPDF_Action action((CPDF_Dictionary*)pDict); | 181 CPDF_Action action((CPDF_Dictionary*)pDict); |
| 168 CFX_ByteString path = action.GetURI(pDoc); | 182 CFX_ByteString path = action.GetURI(pDoc); |
| 169 unsigned long len = path.GetLength() + 1; | 183 unsigned long len = path.GetLength() + 1; |
| 170 if (buffer != NULL && buflen >= len) | 184 if (buffer != NULL && buflen >= len) |
|
jun_fang
2015/09/14 14:18:57
if (!buffer && buflen >= len)
jun_fang
2015/09/14 14:18:57
It should return 0 in 'else'.
Lei Zhang
2015/09/15 08:24:50
Done.
| |
| 171 FXSYS_memcpy(buffer, path.c_str(), len); | 185 FXSYS_memcpy(buffer, path.c_str(), len); |
| 172 return len; | 186 return len; |
| 173 } | 187 } |
| 174 | 188 |
| 175 DLLEXPORT unsigned long STDCALL FPDFDest_GetPageIndex(FPDF_DOCUMENT document, | 189 DLLEXPORT unsigned long STDCALL FPDFDest_GetPageIndex(FPDF_DOCUMENT document, |
| 176 FPDF_DEST pDict) { | 190 FPDF_DEST pDict) { |
| 177 if (!document) | 191 if (!document) |
|
jun_fang
2015/09/14 14:18:57
The same as above.
Lei Zhang
2015/09/15 08:24:50
Done.
| |
| 178 return 0; | 192 return 0; |
| 179 if (!pDict) | 193 if (!pDict) |
| 180 return 0; | 194 return 0; |
| 181 CPDF_Document* pDoc = (CPDF_Document*)document; | 195 CPDF_Document* pDoc = (CPDF_Document*)document; |
| 182 CPDF_Dest dest((CPDF_Array*)pDict); | 196 CPDF_Dest dest((CPDF_Array*)pDict); |
| 183 return dest.GetPageIndex(pDoc); | 197 return dest.GetPageIndex(pDoc); |
| 184 } | 198 } |
| 185 | 199 |
| 186 DLLEXPORT FPDF_LINK STDCALL | 200 DLLEXPORT FPDF_LINK STDCALL |
| 187 FPDFLink_GetLinkAtPoint(FPDF_PAGE page, double x, double y) { | 201 FPDFLink_GetLinkAtPoint(FPDF_PAGE page, double x, double y) { |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 201 if (!pLinkList) | 215 if (!pLinkList) |
| 202 return -1; | 216 return -1; |
| 203 | 217 |
| 204 int z_order = -1; | 218 int z_order = -1; |
| 205 pLinkList->GetLinkAtPoint(pPage, (FX_FLOAT)x, (FX_FLOAT)y, &z_order); | 219 pLinkList->GetLinkAtPoint(pPage, (FX_FLOAT)x, (FX_FLOAT)y, &z_order); |
| 206 return z_order; | 220 return z_order; |
| 207 } | 221 } |
| 208 | 222 |
| 209 DLLEXPORT FPDF_DEST STDCALL FPDFLink_GetDest(FPDF_DOCUMENT document, | 223 DLLEXPORT FPDF_DEST STDCALL FPDFLink_GetDest(FPDF_DOCUMENT document, |
| 210 FPDF_LINK pDict) { | 224 FPDF_LINK pDict) { |
| 211 if (!document) | 225 if (!document) |
|
jun_fang
2015/09/14 14:18:57
The same as above.
Lei Zhang
2015/09/15 08:24:50
Done.
| |
| 212 return NULL; | 226 return NULL; |
| 213 if (!pDict) | 227 if (!pDict) |
| 214 return NULL; | 228 return NULL; |
| 215 CPDF_Document* pDoc = (CPDF_Document*)document; | 229 CPDF_Document* pDoc = (CPDF_Document*)document; |
| 216 CPDF_Link link((CPDF_Dictionary*)pDict); | 230 CPDF_Link link((CPDF_Dictionary*)pDict); |
| 217 FPDF_DEST dest = link.GetDest(pDoc).GetObject(); | 231 FPDF_DEST dest = link.GetDest(pDoc).GetObject(); |
| 218 if (dest) | 232 if (dest) |
| 219 return dest; | 233 return dest; |
| 220 // If this link is not directly associated with a dest, we try to get action | 234 // If this link is not directly associated with a dest, we try to get action |
| 221 CPDF_Action action = link.GetAction(); | 235 CPDF_Action action = link.GetAction(); |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 315 return 0; | 329 return 0; |
| 316 CFX_WideString text = pInfo->GetUnicodeText(tag); | 330 CFX_WideString text = pInfo->GetUnicodeText(tag); |
| 317 // Use UTF-16LE encoding | 331 // Use UTF-16LE encoding |
| 318 CFX_ByteString encodedText = text.UTF16LE_Encode(); | 332 CFX_ByteString encodedText = text.UTF16LE_Encode(); |
| 319 unsigned long len = encodedText.GetLength(); | 333 unsigned long len = encodedText.GetLength(); |
| 320 if (buffer && buflen >= len) { | 334 if (buffer && buflen >= len) { |
| 321 FXSYS_memcpy(buffer, encodedText.c_str(), len); | 335 FXSYS_memcpy(buffer, encodedText.c_str(), len); |
| 322 } | 336 } |
| 323 return len; | 337 return len; |
| 324 } | 338 } |
| OLD | NEW |