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/fpdfapi/fpdf_serial.h" | 7 #include "../../../include/fpdfapi/fpdf_serial.h" |
| 8 CFDF_Document::CFDF_Document() : CPDF_IndirectObjects(NULL) { | 8 CFDF_Document::CFDF_Document() : CPDF_IndirectObjects(NULL) { |
| 9 m_pRootDict = NULL; | 9 m_pRootDict = NULL; |
| 10 m_pFile = NULL; | 10 m_pFile = NULL; |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 93 << FX_BSTRC("\r\nendobj\r\n\r\n"); | 93 << FX_BSTRC("\r\nendobj\r\n\r\n"); |
| 94 } | 94 } |
| 95 buf << FX_BSTRC("trailer\r\n<</Root ") << m_pRootDict->GetObjNum() | 95 buf << FX_BSTRC("trailer\r\n<</Root ") << m_pRootDict->GetObjNum() |
| 96 << FX_BSTRC(" 0 R>>\r\n%%EOF\r\n"); | 96 << FX_BSTRC(" 0 R>>\r\n%%EOF\r\n"); |
| 97 return TRUE; | 97 return TRUE; |
| 98 } | 98 } |
| 99 CFX_WideString CFDF_Document::GetWin32Path() const { | 99 CFX_WideString CFDF_Document::GetWin32Path() const { |
| 100 CPDF_Dictionary* pDict = | 100 CPDF_Dictionary* pDict = |
| 101 m_pRootDict ? m_pRootDict->GetDict(FX_BSTRC("FDF")) : NULL; | 101 m_pRootDict ? m_pRootDict->GetDict(FX_BSTRC("FDF")) : NULL; |
| 102 CPDF_Object* pFileSpec = pDict ? pDict->GetElementValue(FX_BSTRC("F")) : NULL; | 102 CPDF_Object* pFileSpec = pDict ? pDict->GetElementValue(FX_BSTRC("F")) : NULL; |
| 103 if (pFileSpec == NULL) { | 103 if (!pFileSpec) |
| 104 return CFX_WideString(); | 104 return CFX_WideString(); |
| 105 } | 105 if (pFileSpec->IsString()) |
| 106 if (pFileSpec->GetType() == PDFOBJ_STRING) { | |
| 107 return FPDF_FileSpec_GetWin32Path(m_pRootDict->GetDict(FX_BSTRC("FDF"))); | 106 return FPDF_FileSpec_GetWin32Path(m_pRootDict->GetDict(FX_BSTRC("FDF"))); |
| 108 } | |
| 109 return FPDF_FileSpec_GetWin32Path(pFileSpec); | 107 return FPDF_FileSpec_GetWin32Path(pFileSpec); |
| 110 } | 108 } |
| 111 static CFX_WideString ChangeSlash(const FX_WCHAR* str) { | 109 static CFX_WideString ChangeSlash(const FX_WCHAR* str) { |
| 112 CFX_WideString result; | 110 CFX_WideString result; |
| 113 while (*str) { | 111 while (*str) { |
| 114 if (*str == '\\') { | 112 if (*str == '\\') { |
| 115 result += '/'; | 113 result += '/'; |
| 116 } else if (*str == '/') { | 114 } else if (*str == '/') { |
| 117 result += '\\'; | 115 result += '\\'; |
| 118 } else { | 116 } else { |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 131 if (filepath[2] != '\\') { | 129 if (filepath[2] != '\\') { |
| 132 result += '/'; | 130 result += '/'; |
| 133 } | 131 } |
| 134 result += ChangeSlash(filepath.c_str() + 2); | 132 result += ChangeSlash(filepath.c_str() + 2); |
| 135 } else if (filepath.GetLength() > 1 && filepath[0] == '\\' && | 133 } else if (filepath.GetLength() > 1 && filepath[0] == '\\' && |
| 136 filepath[1] == '\\') { | 134 filepath[1] == '\\') { |
| 137 result = ChangeSlash(filepath.c_str() + 1); | 135 result = ChangeSlash(filepath.c_str() + 1); |
| 138 } else { | 136 } else { |
| 139 result = ChangeSlash(filepath.c_str()); | 137 result = ChangeSlash(filepath.c_str()); |
| 140 } | 138 } |
| 141 if (pFileSpec->GetType() == PDFOBJ_STRING) { | 139 |
| 140 if (pFileSpec->IsString()) { | |
| 142 pFileSpec->SetString(CFX_ByteString::FromUnicode(result)); | 141 pFileSpec->SetString(CFX_ByteString::FromUnicode(result)); |
| 142 | |
|
Lei Zhang
2015/10/21 16:55:56
no trailing blank line
dsinclair
2015/10/21 17:08:05
Done.
| |
| 143 } else if (CPDF_Dictionary* pFileDict = pFileSpec->AsDictionary()) { | 143 } else if (CPDF_Dictionary* pFileDict = pFileSpec->AsDictionary()) { |
| 144 pFileDict->SetAtString(FX_BSTRC("F"), CFX_ByteString::FromUnicode(result)); | 144 pFileDict->SetAtString(FX_BSTRC("F"), CFX_ByteString::FromUnicode(result)); |
| 145 pFileDict->SetAtString(FX_BSTRC("UF"), PDF_EncodeText(result)); | 145 pFileDict->SetAtString(FX_BSTRC("UF"), PDF_EncodeText(result)); |
| 146 pFileDict->RemoveAt(FX_BSTRC("FS")); | 146 pFileDict->RemoveAt(FX_BSTRC("FS")); |
| 147 } | 147 } |
| 148 } | 148 } |
| 149 CFX_WideString FPDF_FileSpec_GetWin32Path(const CPDF_Object* pFileSpec) { | 149 CFX_WideString FPDF_FileSpec_GetWin32Path(const CPDF_Object* pFileSpec) { |
| 150 CFX_WideString wsFileName; | 150 CFX_WideString wsFileName; |
| 151 if (!pFileSpec) { | 151 if (!pFileSpec) { |
| 152 wsFileName = CFX_WideString(); | 152 wsFileName = CFX_WideString(); |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 172 result += wsFileName[1]; | 172 result += wsFileName[1]; |
| 173 result += ':'; | 173 result += ':'; |
| 174 result += ChangeSlash(wsFileName.c_str() + 2); | 174 result += ChangeSlash(wsFileName.c_str() + 2); |
| 175 return result; | 175 return result; |
| 176 } | 176 } |
| 177 CFX_WideString result; | 177 CFX_WideString result; |
| 178 result += '\\'; | 178 result += '\\'; |
| 179 result += ChangeSlash(wsFileName.c_str()); | 179 result += ChangeSlash(wsFileName.c_str()); |
| 180 return result; | 180 return result; |
| 181 } | 181 } |
| OLD | NEW |