OLD | NEW |
1 // Copyright 2015 PDFium Authors. All rights reserved. | 1 // Copyright 2015 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 #include "testing/test_support.h" | 5 #include "testing/test_support.h" |
6 | 6 |
7 #include <stdio.h> | 7 #include <stdio.h> |
8 #include <string.h> | 8 #include <string.h> |
9 | 9 |
10 #include "testing/utils/path_service.h" | 10 #include "testing/utils/path_service.h" |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 (void)fclose(file); | 91 (void)fclose(file); |
92 if (bytes_read != file_length) { | 92 if (bytes_read != file_length) { |
93 fprintf(stderr, "Failed to read: %s\n", filename); | 93 fprintf(stderr, "Failed to read: %s\n", filename); |
94 free(buffer); | 94 free(buffer); |
95 return nullptr; | 95 return nullptr; |
96 } | 96 } |
97 *retlen = bytes_read; | 97 *retlen = bytes_read; |
98 return buffer; | 98 return buffer; |
99 } | 99 } |
100 | 100 |
101 std::wstring GetWideString(FPDF_WIDESTRING wstr) { | 101 std::wstring GetPlatformWString(FPDF_WIDESTRING wstr) { |
102 if (!wstr) | 102 if (!wstr) |
103 return nullptr; | 103 return nullptr; |
104 | 104 |
105 size_t characters = 0; | 105 size_t characters = 0; |
106 while (wstr[characters]) | 106 while (wstr[characters]) |
107 ++characters; | 107 ++characters; |
108 | 108 |
109 std::wstring platform_string(characters, L'\0'); | 109 std::wstring platform_string(characters, L'\0'); |
110 for (size_t i = 0; i < characters + 1; ++i) { | 110 for (size_t i = 0; i < characters + 1; ++i) { |
111 const unsigned char* ptr = reinterpret_cast<const unsigned char*>(&wstr[i]); | 111 const unsigned char* ptr = reinterpret_cast<const unsigned char*>(&wstr[i]); |
112 platform_string[i] = ptr[0] + 256 * ptr[1]; | 112 platform_string[i] = ptr[0] + 256 * ptr[1]; |
113 } | 113 } |
114 return platform_string; | 114 return platform_string; |
115 } | 115 } |
116 | 116 |
| 117 FPDF_WIDESTRING GetFPDFWideString(const std::wstring& wstr) { |
| 118 size_t length = sizeof(uint16_t) * (wstr.length() + 1); |
| 119 unsigned char* ptr = static_cast<unsigned char*>(malloc(length)); |
| 120 size_t i = 0; |
| 121 for (wchar_t w : wstr) { |
| 122 ptr[i++] = w & 0xff; |
| 123 ptr[i++] = (w >> 8) & 0xff; |
| 124 } |
| 125 ptr[i++] = 0; |
| 126 ptr[i] = 0; |
| 127 return reinterpret_cast<FPDF_WIDESTRING>(ptr); |
| 128 } |
| 129 |
117 #ifdef PDF_ENABLE_V8 | 130 #ifdef PDF_ENABLE_V8 |
118 #ifdef V8_USE_EXTERNAL_STARTUP_DATA | 131 #ifdef V8_USE_EXTERNAL_STARTUP_DATA |
119 bool InitializeV8ForPDFium(const std::string& exe_path, | 132 bool InitializeV8ForPDFium(const std::string& exe_path, |
120 const std::string& bin_dir, | 133 const std::string& bin_dir, |
121 v8::StartupData* natives_blob, | 134 v8::StartupData* natives_blob, |
122 v8::StartupData* snapshot_blob, | 135 v8::StartupData* snapshot_blob, |
123 v8::Platform** platform) { | 136 v8::Platform** platform) { |
124 InitializeV8Common(platform); | 137 InitializeV8Common(platform); |
125 if (!GetExternalData(exe_path, bin_dir, "natives_blob.bin", natives_blob)) | 138 if (!GetExternalData(exe_path, bin_dir, "natives_blob.bin", natives_blob)) |
126 return false; | 139 return false; |
(...skipping 20 matching lines...) Expand all Loading... |
147 unsigned long pos, | 160 unsigned long pos, |
148 unsigned char* pBuf, | 161 unsigned char* pBuf, |
149 unsigned long size) { | 162 unsigned long size) { |
150 TestLoader* pLoader = static_cast<TestLoader*>(param); | 163 TestLoader* pLoader = static_cast<TestLoader*>(param); |
151 if (pos + size < pos || pos + size > pLoader->m_Len) | 164 if (pos + size < pos || pos + size > pLoader->m_Len) |
152 return 0; | 165 return 0; |
153 | 166 |
154 memcpy(pBuf, pLoader->m_pBuf + pos, size); | 167 memcpy(pBuf, pLoader->m_pBuf + pos, size); |
155 return 1; | 168 return 1; |
156 } | 169 } |
OLD | NEW |