| 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 "../include/fpdfdoc.h" | 8 #include "../include/fpdfdoc.h" |
| 9 | 9 |
| 10 static int this_module = 0; | 10 static int THISMODULE = 0; |
| 11 | 11 |
| 12 static CPDF_Bookmark FindBookmark(CPDF_BookmarkTree& tree, CPDF_Bookmark This, c
onst CFX_WideString& title) | 12 static CPDF_Bookmark FindBookmark(const CPDF_BookmarkTree& tree, CPDF_Bookmark b
ookmark, const CFX_WideString& title) |
| 13 { | 13 { |
| 14 » if (This != NULL) { | 14 » if (bookmark && bookmark.GetTitle().CompareNoCase(title) == 0) { |
| 15 // First check this item | 15 // First check this item |
| 16 » » CFX_WideString this_title = This.GetTitle(); | 16 » » return bookmark; |
| 17 » » if (this_title.CompareNoCase(title) == 0) | |
| 18 » » » return This; | |
| 19 } | 17 } |
| 20 // go into children items | 18 // go into children items |
| 21 » CPDF_Bookmark Child = tree.GetFirstChild(This); | 19 » CPDF_Bookmark child = tree.GetFirstChild(bookmark); |
| 22 » while (Child != NULL) { | 20 » while (child) { |
| 23 // check if this item | 21 // check if this item |
| 24 » » CPDF_Bookmark Found = FindBookmark(tree, Child, title); | 22 » » CPDF_Bookmark found = FindBookmark(tree, child, title); |
| 25 » » if (Found) return Found; | 23 » » if (found) |
| 26 » » Child = tree.GetNextSibling(Child); | 24 » » » return found; |
| 25 » » child = tree.GetNextSibling(child); |
| 27 } | 26 } |
| 28 » return NULL; | 27 » return CPDF_Bookmark(); |
| 29 } | 28 } |
| 30 | 29 |
| 31 DLLEXPORT FPDF_BOOKMARK STDCALL FPDFBookmark_Find(FPDF_DOCUMENT document, FPDF_W
IDESTRING title) | 30 DLLEXPORT FPDF_BOOKMARK STDCALL FPDFBookmark_Find(FPDF_DOCUMENT document, FPDF_W
IDESTRING title) |
| 32 { | 31 { |
| 33 » if (document == NULL) return NULL; | 32 » if (!document) |
| 34 » if (title == NULL || title[0] == 0) return NULL; | 33 » » return NULL; |
| 35 | 34 » if (!title || title[0] == 0) |
| 35 » » return NULL; |
| 36 CPDF_Document* pDoc = (CPDF_Document*)document; | 36 CPDF_Document* pDoc = (CPDF_Document*)document; |
| 37 CPDF_BookmarkTree tree(pDoc); | 37 CPDF_BookmarkTree tree(pDoc); |
| 38 | |
| 39 FX_STRSIZE len = CFX_WideString::WStringLength(title); | 38 FX_STRSIZE len = CFX_WideString::WStringLength(title); |
| 40 » CFX_WideString wstr = CFX_WideString::FromUTF16LE(title, len); | 39 » CFX_WideString encodedTitle = CFX_WideString::FromUTF16LE(title, len); |
| 41 » return FindBookmark(tree, NULL, wstr); | 40 » return FindBookmark(tree, CPDF_Bookmark(), encodedTitle).GetDict(); |
| 42 } | 41 } |
| 43 | 42 |
| 44 DLLEXPORT FPDF_DEST STDCALL FPDFBookmark_GetDest(FPDF_DOCUMENT document, FPDF_BO
OKMARK bookmark) | 43 DLLEXPORT FPDF_DEST STDCALL FPDFBookmark_GetDest(FPDF_DOCUMENT document, FPDF_BO
OKMARK pDict) |
| 45 { | 44 { |
| 46 » if (document == NULL) return NULL; | 45 » if (!document) |
| 47 » if (bookmark == NULL) return NULL; | 46 » » return NULL; |
| 48 | 47 » if (!pDict) |
| 49 » CPDF_Bookmark Bookmark = (CPDF_Dictionary*)bookmark; | 48 » » return NULL; |
| 49 » CPDF_Bookmark bookmark((CPDF_Dictionary*)pDict); |
| 50 CPDF_Document* pDoc = (CPDF_Document*)document; | 50 CPDF_Document* pDoc = (CPDF_Document*)document; |
| 51 » CPDF_Dest dest = Bookmark.GetDest(pDoc); | 51 » CPDF_Dest dest = bookmark.GetDest(pDoc); |
| 52 » if (dest != NULL) return dest; | 52 » if (dest) |
| 53 | 53 » » return dest; |
| 54 // If this bookmark is not directly associated with a dest, we try to ge
t action | 54 // If this bookmark is not directly associated with a dest, we try to ge
t action |
| 55 » CPDF_Action Action = Bookmark.GetAction(); | 55 » CPDF_Action action = bookmark.GetAction(); |
| 56 » if (Action == NULL) return NULL; | 56 » if (!action) |
| 57 » return Action.GetDest(pDoc); | 57 » » return NULL; |
| 58 » return action.GetDest(pDoc); |
| 58 } | 59 } |
| 59 | 60 |
| 60 DLLEXPORT FPDF_ACTION STDCALL FPDFBookmark_GetAction(FPDF_BOOKMARK bookmark) | 61 DLLEXPORT FPDF_ACTION STDCALL FPDFBookmark_GetAction(FPDF_BOOKMARK pDict) |
| 61 { | 62 { |
| 62 » if (bookmark == NULL) return NULL; | 63 » if (!pDict) |
| 63 | 64 » » return NULL; |
| 64 » CPDF_Bookmark Bookmark = (CPDF_Dictionary*)bookmark; | 65 » CPDF_Bookmark bookmark((CPDF_Dictionary*)pDict); |
| 65 » return Bookmark.GetAction(); | 66 » return bookmark.GetAction(); |
| 66 } | 67 } |
| 67 | 68 |
| 68 DLLEXPORT unsigned long STDCALL FPDFAction_GetType(FPDF_ACTION action) | 69 DLLEXPORT unsigned long STDCALL FPDFAction_GetType(FPDF_ACTION pDict) |
| 69 { | 70 { |
| 70 » if (action == NULL) return 0; | 71 » if (!pDict) |
| 71 | 72 » » return 0; |
| 72 » CPDF_Action Action = (CPDF_Dictionary*)action; | 73 » CPDF_Action action = (CPDF_Dictionary*)pDict; |
| 73 » CPDF_Action::ActionType type = Action.GetType(); | 74 » CPDF_Action::ActionType type = action.GetType(); |
| 74 switch (type) { | 75 switch (type) { |
| 75 » case CPDF_Action::GoTo: | 76 » » case CPDF_Action::GoTo: |
| 76 » » return PDFACTION_GOTO; | 77 » » » return PDFACTION_GOTO; |
| 77 » case CPDF_Action::GoToR: | 78 » » case CPDF_Action::GoToR: |
| 78 » » return PDFACTION_REMOTEGOTO; | 79 » » » return PDFACTION_REMOTEGOTO; |
| 79 » case CPDF_Action::URI: | 80 » » case CPDF_Action::URI: |
| 80 » » return PDFACTION_URI; | 81 » » » return PDFACTION_URI; |
| 81 » case CPDF_Action::Launch: | 82 » » case CPDF_Action::Launch: |
| 82 » » return PDFACTION_LAUNCH; | 83 » » » return PDFACTION_LAUNCH; |
| 83 » default: | 84 » » default: |
| 84 » » return PDFACTION_UNSUPPORTED; | 85 » » » return PDFACTION_UNSUPPORTED; |
| 85 } | 86 } |
| 86 return PDFACTION_UNSUPPORTED; | 87 return PDFACTION_UNSUPPORTED; |
| 87 } | 88 } |
| 88 | 89 |
| 89 DLLEXPORT FPDF_DEST STDCALL FPDFAction_GetDest(FPDF_DOCUMENT document, FPDF_ACTI
ON action) | 90 DLLEXPORT FPDF_DEST STDCALL FPDFAction_GetDest(FPDF_DOCUMENT document, FPDF_ACTI
ON pDict) |
| 90 { | 91 { |
| 91 » if (document == NULL) return NULL; | 92 » if (!document) |
| 92 » if (action == NULL) return NULL; | 93 » » return NULL; |
| 94 » if (!pDict) |
| 95 » » return NULL; |
| 93 CPDF_Document* pDoc = (CPDF_Document*)document; | 96 CPDF_Document* pDoc = (CPDF_Document*)document; |
| 94 » CPDF_Action Action = (CPDF_Dictionary*)action; | 97 » CPDF_Action action = (CPDF_Dictionary*)pDict; |
| 95 | 98 » return action.GetDest(pDoc); |
| 96 » return Action.GetDest(pDoc); | |
| 97 } | 99 } |
| 98 | 100 |
| 99 DLLEXPORT unsigned long STDCALL FPDFAction_GetURIPath(FPDF_DOCUMENT document, FP
DF_ACTION action, | 101 DLLEXPORT unsigned long STDCALL FPDFAction_GetURIPath(FPDF_DOCUMENT document, FP
DF_ACTION pDict, |
| 100
void* buffer, unsigned long buflen) | 102
void* buffer, unsigned long buflen) |
| 101 { | 103 { |
| 102 » if (document == NULL) return 0; | 104 » if (!document) |
| 103 » if (action == NULL) return 0; | 105 » » return 0; |
| 106 » if (!pDict) |
| 107 » » return 0; |
| 104 CPDF_Document* pDoc = (CPDF_Document*)document; | 108 CPDF_Document* pDoc = (CPDF_Document*)document; |
| 105 » CPDF_Action Action = (CPDF_Dictionary*)action; | 109 » CPDF_Action action = (CPDF_Dictionary*)pDict; |
| 106 | 110 » CFX_ByteString path = action.GetURI(pDoc); |
| 107 » CFX_ByteString path = Action.GetURI(pDoc); | |
| 108 unsigned long len = path.GetLength() + 1; | 111 unsigned long len = path.GetLength() + 1; |
| 109 if (buffer != NULL && buflen >= len) | 112 if (buffer != NULL && buflen >= len) |
| 110 FXSYS_memcpy(buffer, path.c_str(), len); | 113 FXSYS_memcpy(buffer, path.c_str(), len); |
| 111 return len; | 114 return len; |
| 112 } | 115 } |
| 113 | 116 |
| 114 DLLEXPORT unsigned long STDCALL FPDFDest_GetPageIndex(FPDF_DOCUMENT document, FP
DF_DEST dest) | 117 DLLEXPORT unsigned long STDCALL FPDFDest_GetPageIndex(FPDF_DOCUMENT document, FP
DF_DEST pDict) |
| 115 { | 118 { |
| 116 » if (document == NULL) return 0; | 119 » if (!document) |
| 117 » if (dest == NULL) return 0; | 120 » » return 0; |
| 121 » if (!pDict) |
| 122 » » return 0; |
| 118 CPDF_Document* pDoc = (CPDF_Document*)document; | 123 CPDF_Document* pDoc = (CPDF_Document*)document; |
| 119 » CPDF_Dest Dest = (CPDF_Array*)dest; | 124 » CPDF_Dest dest = (CPDF_Array*)pDict; |
| 120 | 125 » return dest.GetPageIndex(pDoc); |
| 121 » return Dest.GetPageIndex(pDoc); | |
| 122 } | 126 } |
| 123 | 127 |
| 124 static void ReleaseLinkList(FX_LPVOID data) | 128 static void ReleaseLinkList(FX_LPVOID data) |
| 125 { | 129 { |
| 126 delete (CPDF_LinkList*)data; | 130 delete (CPDF_LinkList*)data; |
| 127 } | 131 } |
| 128 | 132 |
| 129 DLLEXPORT FPDF_LINK STDCALL FPDFLink_GetLinkAtPoint(FPDF_PAGE page, double x, do
uble y) | 133 DLLEXPORT FPDF_LINK STDCALL FPDFLink_GetLinkAtPoint(FPDF_PAGE page, double x, do
uble y) |
| 130 { | 134 { |
| 131 » if (page == NULL) return NULL; | 135 » if (!page) |
| 136 » » return NULL; |
| 132 CPDF_Page* pPage = (CPDF_Page*)page; | 137 CPDF_Page* pPage = (CPDF_Page*)page; |
| 133 | |
| 134 // Link list is stored with the document | 138 // Link list is stored with the document |
| 135 CPDF_Document* pDoc = pPage->m_pDocument; | 139 CPDF_Document* pDoc = pPage->m_pDocument; |
| 136 » CPDF_LinkList* pLinkList = (CPDF_LinkList*)pDoc->GetPrivateData(&this_mo
dule); | 140 » CPDF_LinkList* pLinkList = (CPDF_LinkList*)pDoc->GetPrivateData(&THISMOD
ULE); |
| 137 » if (pLinkList == NULL) { | 141 » if (!pLinkList) { |
| 138 pLinkList = FX_NEW CPDF_LinkList(pDoc); | 142 pLinkList = FX_NEW CPDF_LinkList(pDoc); |
| 139 » » pDoc->SetPrivateData(&this_module, pLinkList, ReleaseLinkList); | 143 » » pDoc->SetPrivateData(&THISMODULE, pLinkList, ReleaseLinkList); |
| 140 } | 144 } |
| 141 | |
| 142 return pLinkList->GetLinkAtPoint(pPage, (FX_FLOAT)x, (FX_FLOAT)y); | 145 return pLinkList->GetLinkAtPoint(pPage, (FX_FLOAT)x, (FX_FLOAT)y); |
| 143 } | 146 } |
| 144 | 147 |
| 145 DLLEXPORT FPDF_DEST STDCALL FPDFLink_GetDest(FPDF_DOCUMENT document, FPDF_LINK l
ink) | 148 DLLEXPORT FPDF_DEST STDCALL FPDFLink_GetDest(FPDF_DOCUMENT document, FPDF_LINK p
Dict) |
| 146 { | 149 { |
| 147 » if (document == NULL) return NULL; | 150 » if (!document) |
| 151 » » return NULL; |
| 148 CPDF_Document* pDoc = (CPDF_Document*)document; | 152 CPDF_Document* pDoc = (CPDF_Document*)document; |
| 149 » if (link == NULL) return NULL; | 153 » if (!pDict) |
| 150 » CPDF_Link Link = (CPDF_Dictionary*)link; | 154 » » return NULL; |
| 155 » CPDF_Link link = (CPDF_Dictionary*)pDict; |
| 151 | 156 |
| 152 » FPDF_DEST dest = Link.GetDest(pDoc); | 157 » FPDF_DEST dest = link.GetDest(pDoc); |
| 153 » if (dest) return dest; | 158 » if (dest) |
| 154 | 159 » » return dest; |
| 155 // If this link is not directly associated with a dest, we try to get ac
tion | 160 // If this link is not directly associated with a dest, we try to get ac
tion |
| 156 » CPDF_Action Action = Link.GetAction(); | 161 » CPDF_Action action = link.GetAction(); |
| 157 » if (Action == NULL) return NULL; | 162 » if (!action) |
| 158 » return Action.GetDest(pDoc); | 163 » » return NULL; |
| 164 » return action.GetDest(pDoc); |
| 159 } | 165 } |
| 160 | 166 |
| 161 DLLEXPORT FPDF_ACTION STDCALL FPDFLink_GetAction(FPDF_LINK link) | 167 DLLEXPORT FPDF_ACTION STDCALL FPDFLink_GetAction(FPDF_LINK pDict) |
| 162 { | 168 { |
| 163 » if (link == NULL) return NULL; | 169 » if (!pDict) |
| 164 » CPDF_Link Link = (CPDF_Dictionary*)link; | 170 » » return NULL; |
| 165 | 171 » CPDF_Link link = (CPDF_Dictionary*)pDict; |
| 166 » return Link.GetAction(); | 172 » return link.GetAction(); |
| 167 } | 173 } |
| 168 | 174 |
| 169 DLLEXPORT FPDF_BOOL STDCALL FPDFLink_Enumerate(FPDF_PAGE page, int* startPos, FP
DF_LINK* linkAnnot) | 175 DLLEXPORT FPDF_BOOL STDCALL FPDFLink_Enumerate(FPDF_PAGE page, int* startPos, FP
DF_LINK* linkAnnot) |
| 170 { | 176 { |
| 171 if(!page || !startPos || !linkAnnot) | 177 if(!page || !startPos || !linkAnnot) |
| 172 return FALSE; | 178 return FALSE; |
| 173 CPDF_Page* pPage = (CPDF_Page*)page; | 179 CPDF_Page* pPage = (CPDF_Page*)page; |
| 174 » if(!pPage->m_pFormDict) return FALSE; | 180 » if(!pPage->m_pFormDict) |
| 181 » » return FALSE; |
| 175 CPDF_Array* pAnnots = pPage->m_pFormDict->GetArray("Annots"); | 182 CPDF_Array* pAnnots = pPage->m_pFormDict->GetArray("Annots"); |
| 176 » if(!pAnnots) return FALSE; | 183 » if(!pAnnots) |
| 177 » for (int i = *startPos; i < (int)pAnnots->GetCount(); i ++) { | 184 » » return FALSE; |
| 185 » for (int i = *startPos; i < (int)pAnnots->GetCount(); i++) { |
| 178 CPDF_Dictionary* pDict = (CPDF_Dictionary*)pAnnots->GetElementVa
lue(i); | 186 CPDF_Dictionary* pDict = (CPDF_Dictionary*)pAnnots->GetElementVa
lue(i); |
| 179 » » if (pDict == NULL || pDict->GetType() != PDFOBJ_DICTIONARY) cont
inue; | 187 » » if (!pDict || pDict->GetType() != PDFOBJ_DICTIONARY) |
| 180 » » if(pDict->GetString(FX_BSTRC("Subtype")).Equal(FX_BSTRC("Link"))
) | 188 » » » continue; |
| 181 » » { | 189 » » if(pDict->GetString(FX_BSTRC("Subtype")).Equal(FX_BSTRC("Link"))
) { |
| 182 » » » *startPos = i+1; | 190 » » » *startPos = i + 1; |
| 183 *linkAnnot = (FPDF_LINK)pDict; | 191 *linkAnnot = (FPDF_LINK)pDict; |
| 184 return TRUE; | 192 return TRUE; |
| 185 } | 193 } |
| 186 } | 194 } |
| 187 return FALSE; | 195 return FALSE; |
| 188 } | 196 } |
| 189 | 197 |
| 190 DLLEXPORT FPDF_BOOL STDCALL FPDFLink_GetAnnotRect(FPDF_LINK linkAnnot, FS_RECTF*
rect) | 198 DLLEXPORT FPDF_BOOL STDCALL FPDFLink_GetAnnotRect(FPDF_LINK linkAnnot, FS_RECTF*
rect) |
| 191 { | 199 { |
| 192 if(!linkAnnot || !rect) | 200 if(!linkAnnot || !rect) |
| 193 return FALSE; | 201 return FALSE; |
| 194 CPDF_Dictionary* pAnnotDict = (CPDF_Dictionary*)linkAnnot; | 202 CPDF_Dictionary* pAnnotDict = (CPDF_Dictionary*)linkAnnot; |
| 195 CPDF_Rect rt = pAnnotDict->GetRect(FX_BSTRC("Rect")); | 203 CPDF_Rect rt = pAnnotDict->GetRect(FX_BSTRC("Rect")); |
| 196 rect->left = rt.left; | 204 rect->left = rt.left; |
| 197 rect->bottom = rt.bottom; | 205 rect->bottom = rt.bottom; |
| 198 rect->right = rt.right; | 206 rect->right = rt.right; |
| 199 rect->top = rt.top; | 207 rect->top = rt.top; |
| 200 return TRUE; | 208 return TRUE; |
| 201 } | 209 } |
| 202 | 210 |
| 203 DLLEXPORT int STDCALL FPDFLink_CountQuadPoints(FPDF_LINK linkAnnot) | 211 DLLEXPORT int STDCALL FPDFLink_CountQuadPoints(FPDF_LINK linkAnnot) |
| 204 { | 212 { |
| 205 if(!linkAnnot) | 213 if(!linkAnnot) |
| 206 return 0; | 214 return 0; |
| 207 CPDF_Dictionary* pAnnotDict = (CPDF_Dictionary*)linkAnnot; | 215 CPDF_Dictionary* pAnnotDict = (CPDF_Dictionary*)linkAnnot; |
| 208 CPDF_Array* pArray = pAnnotDict->GetArray(FX_BSTRC("QuadPoints")); | 216 CPDF_Array* pArray = pAnnotDict->GetArray(FX_BSTRC("QuadPoints")); |
| 209 » if (pArray == NULL) | 217 » if (!pArray) |
| 210 return 0; | 218 return 0; |
| 211 else | 219 else |
| 212 return pArray->GetCount() / 8; | 220 return pArray->GetCount() / 8; |
| 213 } | 221 } |
| 214 | 222 |
| 215 DLLEXPORT FPDF_BOOL STDCALL FPDFLink_GetQuadPoints(FPDF_LINK linkAnnot, int quad
Index, FS_QUADPOINTSF* quadPoints) | 223 DLLEXPORT FPDF_BOOL STDCALL FPDFLink_GetQuadPoints(FPDF_LINK linkAnnot, int quad
Index, FS_QUADPOINTSF* quadPoints) |
| 216 { | 224 { |
| 217 if(!linkAnnot || !quadPoints) | 225 if(!linkAnnot || !quadPoints) |
| 218 return FALSE; | 226 return FALSE; |
| 219 CPDF_Dictionary* pAnnotDict = (CPDF_Dictionary*)linkAnnot; | 227 CPDF_Dictionary* pAnnotDict = (CPDF_Dictionary*)linkAnnot; |
| 220 CPDF_Array* pArray = pAnnotDict->GetArray(FX_BSTRC("QuadPoints")); | 228 CPDF_Array* pArray = pAnnotDict->GetArray(FX_BSTRC("QuadPoints")); |
| 221 if (pArray) { | 229 if (pArray) { |
| 222 » » if (0 > quadIndex || quadIndex >= (int)pArray->GetCount()/8 || | 230 » » if (quadIndex < 0 || quadIndex >= (int)pArray->GetCount()/8 || (
(quadIndex*8+7) >= (int)pArray->GetCount())) |
| 223 » » » ((quadIndex*8+7) >= (int)pArray->GetCount())) return FAL
SE; | 231 » » » return FALSE; |
| 224 quadPoints->x1 = pArray->GetNumber(quadIndex*8); | 232 quadPoints->x1 = pArray->GetNumber(quadIndex*8); |
| 225 quadPoints->y1 = pArray->GetNumber(quadIndex*8+1); | 233 quadPoints->y1 = pArray->GetNumber(quadIndex*8+1); |
| 226 quadPoints->x2 = pArray->GetNumber(quadIndex*8+2); | 234 quadPoints->x2 = pArray->GetNumber(quadIndex*8+2); |
| 227 quadPoints->y2 = pArray->GetNumber(quadIndex*8+3); | 235 quadPoints->y2 = pArray->GetNumber(quadIndex*8+3); |
| 228 quadPoints->x3 = pArray->GetNumber(quadIndex*8+4); | 236 quadPoints->x3 = pArray->GetNumber(quadIndex*8+4); |
| 229 quadPoints->y3 = pArray->GetNumber(quadIndex*8+5); | 237 quadPoints->y3 = pArray->GetNumber(quadIndex*8+5); |
| 230 quadPoints->x4 = pArray->GetNumber(quadIndex*8+6); | 238 quadPoints->x4 = pArray->GetNumber(quadIndex*8+6); |
| 231 quadPoints->y4 = pArray->GetNumber(quadIndex*8+7); | 239 quadPoints->y4 = pArray->GetNumber(quadIndex*8+7); |
| 232 return TRUE; | 240 return TRUE; |
| 233 } | 241 } |
| 234 return FALSE; | 242 return FALSE; |
| 235 } | 243 } |
| 236 | 244 |
| 237 | |
| 238 DLLEXPORT unsigned long STDCALL FPDF_GetMetaText(FPDF_DOCUMENT doc, FPDF_BYTESTR
ING tag, | 245 DLLEXPORT unsigned long STDCALL FPDF_GetMetaText(FPDF_DOCUMENT doc, FPDF_BYTESTR
ING tag, |
| 239
void* buffer, unsigned long buflen) | 246
void* buffer, unsigned long buflen) |
| 240 { | 247 { |
| 241 » if (doc == NULL || tag == NULL) return 0; | 248 » if (!doc || !tag) |
| 242 | 249 » » return 0; |
| 243 CPDF_Document* pDoc = (CPDF_Document*)doc; | 250 CPDF_Document* pDoc = (CPDF_Document*)doc; |
| 244 // Get info dictionary | 251 // Get info dictionary |
| 245 CPDF_Dictionary* pInfo = pDoc->GetInfo(); | 252 CPDF_Dictionary* pInfo = pDoc->GetInfo(); |
| 246 » if (pInfo == NULL) return 0; | 253 » if (!pInfo) |
| 247 | 254 » » return 0; |
| 248 CFX_WideString text = pInfo->GetUnicodeText(tag); | 255 CFX_WideString text = pInfo->GetUnicodeText(tag); |
| 249 | |
| 250 // Use UTF-16LE encoding | 256 // Use UTF-16LE encoding |
| 251 » CFX_ByteString bstr = text.UTF16LE_Encode(); | 257 » CFX_ByteString encodedText = text.UTF16LE_Encode(); |
| 252 » unsigned long len = bstr.GetLength(); | 258 » unsigned long len = encodedText.GetLength(); |
| 253 » if (buffer != NULL && buflen >= len+2) { | 259 » if (buffer && buflen >= len + 2) { |
| 254 » » FXSYS_memcpy(buffer, bstr.c_str(), len); | 260 » » FXSYS_memcpy(buffer, encodedText.c_str(), len); |
| 255 // use double zero as trailer | 261 // use double zero as trailer |
| 256 » » ((FX_BYTE*)buffer)[len] = ((FX_BYTE*)buffer)[len+1] = 0; | 262 » » ((FX_BYTE*)buffer)[len] = 0; |
| 263 » » ((FX_BYTE*)buffer)[len + 1] = 0; |
| 257 } | 264 } |
| 258 return len+2; | 265 return len+2; |
| 259 } | 266 } |
| 260 | |
| OLD | NEW |