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/javascript/JavaScript.h" | 7 #include "../../include/javascript/JavaScript.h" |
8 #include "../../include/javascript/IJavaScript.h" | 8 #include "../../include/javascript/IJavaScript.h" |
9 #include "../../include/javascript/JS_Define.h" | 9 #include "../../include/javascript/JS_Define.h" |
10 #include "../../include/javascript/JS_Object.h" | 10 #include "../../include/javascript/JS_Object.h" |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
135 } | 135 } |
136 | 136 |
137 return -1; | 137 return -1; |
138 } | 138 } |
139 | 139 |
140 FX_BOOL util::printf(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value&
vRet, CFX_WideString& sError) | 140 FX_BOOL util::printf(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value&
vRet, CFX_WideString& sError) |
141 { | 141 { |
142 int iSize = params.size(); | 142 int iSize = params.size(); |
143 if (iSize < 1) | 143 if (iSize < 1) |
144 return FALSE; | 144 return FALSE; |
145 » std::wstring c_ConvChar((const wchar_t*)(FX_LPCWSTR)params[0].operator
CFX_WideString()); | 145 » std::wstring c_ConvChar(params[0].ToCFXWideString().c_str()); |
146 std::vector<std::wstring> c_strConvers; | 146 std::vector<std::wstring> c_strConvers; |
147 int iOffset = 0; | 147 int iOffset = 0; |
148 int iOffend = 0; | 148 int iOffend = 0; |
149 c_ConvChar.insert(c_ConvChar.begin(),L'S'); | 149 c_ConvChar.insert(c_ConvChar.begin(),L'S'); |
150 while(iOffset != -1) | 150 while(iOffset != -1) |
151 { | 151 { |
152 iOffend = c_ConvChar.find(L"%",iOffset+1); | 152 iOffend = c_ConvChar.find(L"%",iOffset+1); |
153 std::wstring strSub; | 153 std::wstring strSub; |
154 if (iOffend == -1) | 154 if (iOffend == -1) |
155 strSub = c_ConvChar.substr(iOffset); | 155 strSub = c_ConvChar.substr(iOffset); |
(...skipping 19 matching lines...) Expand all Loading... |
175 | 175 |
176 CFX_WideString strSegment; | 176 CFX_WideString strSegment; |
177 if (iIndex >= iSize) { | 177 if (iIndex >= iSize) { |
178 c_strResult += c_strFormat; | 178 c_strResult += c_strFormat; |
179 continue; | 179 continue; |
180 } | 180 } |
181 | 181 |
182 switch (ParstDataType(&c_strFormat)) | 182 switch (ParstDataType(&c_strFormat)) |
183 { | 183 { |
184 case UTIL_INT: | 184 case UTIL_INT: |
185 » » » » strSegment.Format(c_strFormat.c_str(),(int)param
s[iIndex]); | 185 » » » » strSegment.Format(c_strFormat.c_str(), params[iI
ndex].ToInt()); |
186 break; | 186 break; |
187 case UTIL_DOUBLE: | 187 case UTIL_DOUBLE: |
188 » » » » strSegment.Format(c_strFormat.c_str(),(double)pa
rams[iIndex]); | 188 » » » » strSegment.Format(c_strFormat.c_str(), params[iI
ndex].ToDouble()); |
189 break; | 189 break; |
190 case UTIL_STRING: | 190 case UTIL_STRING: |
191 » » » » strSegment.Format(c_strFormat.c_str(),(FX_LPCWST
R)params[iIndex].operator CFX_WideString()); | 191 » » » » strSegment.Format(c_strFormat.c_str(), params[iI
ndex].ToCFXWideString().c_str()); |
192 break; | 192 break; |
193 default: | 193 default: |
194 strSegment.Format(L"%S", c_strFormat.c_str()); | 194 strSegment.Format(L"%S", c_strFormat.c_str()); |
195 break; | 195 break; |
196 } | 196 } |
197 c_strResult += strSegment.GetBuffer(strSegment.GetLength()+1); | 197 c_strResult += strSegment.GetBuffer(strSegment.GetLength()+1); |
198 } | 198 } |
199 | 199 |
200 c_strResult.erase(c_strResult.begin()); | 200 c_strResult.erase(c_strResult.begin()); |
201 vRet = c_strResult.c_str(); | 201 vRet = c_strResult.c_str(); |
(...skipping 20 matching lines...) Expand all Loading... |
222 } | 222 } |
223 | 223 |
224 if (!jsDate.IsValidDate()) | 224 if (!jsDate.IsValidDate()) |
225 { | 225 { |
226 sError = JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSPRINT2
); | 226 sError = JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSPRINT2
); |
227 return FALSE; | 227 return FALSE; |
228 } | 228 } |
229 | 229 |
230 if (p1.GetType() == VT_number) | 230 if (p1.GetType() == VT_number) |
231 { | 231 { |
232 » » int nFormat = p1; | 232 » » int nFormat = p1.ToInt(); |
233 | |
234 CFX_WideString swResult; | 233 CFX_WideString swResult; |
235 | 234 |
236 switch (nFormat) | 235 switch (nFormat) |
237 { | 236 { |
238 case 0: | 237 case 0: |
239 swResult.Format(L"D:%04d%02d%02d%02d%02d%02d", | 238 swResult.Format(L"D:%04d%02d%02d%02d%02d%02d", |
240 jsDate.GetYear(), | 239 jsDate.GetYear(), |
241 jsDate.GetMonth() + 1, | 240 jsDate.GetMonth() + 1, |
242 jsDate.GetDay(), | 241 jsDate.GetDay(), |
243 jsDate.GetHours(), | 242 jsDate.GetHours(), |
(...skipping 20 matching lines...) Expand all Loading... |
264 break; | 263 break; |
265 default: | 264 default: |
266 return FALSE; | 265 return FALSE; |
267 } | 266 } |
268 | 267 |
269 vRet = swResult; | 268 vRet = swResult; |
270 return TRUE; | 269 return TRUE; |
271 } | 270 } |
272 else if (p1.GetType() == VT_string) | 271 else if (p1.GetType() == VT_string) |
273 { | 272 { |
274 » » std::basic_string<wchar_t> cFormat = (FX_LPCWSTR)p1.operator CFX
_WideString();» » | 273 » » std::basic_string<wchar_t> cFormat = p1.ToCFXWideString().c_str(
); |
275 | 274 |
276 bool bXFAPicture = false; | 275 bool bXFAPicture = false; |
277 if (iSize > 2) | 276 if (iSize > 2) |
278 { | 277 { |
279 » » » //CJS_Value value; | 278 » » » bXFAPicture = params[2].ToBool(); |
280 » » » bXFAPicture = params[2]; | |
281 } | 279 } |
282 | 280 |
283 if (bXFAPicture) | 281 if (bXFAPicture) |
284 { | 282 { |
285 return FALSE; //currently, it doesn't support XFAPicture
. | 283 return FALSE; //currently, it doesn't support XFAPicture
. |
286 } | 284 } |
287 | 285 |
288 int iIndex; | 286 int iIndex; |
289 for(iIndex = 0;iIndex<sizeof(fcTable)/sizeof(stru_TbConvert);iIn
dex++) | 287 for(iIndex = 0;iIndex<sizeof(fcTable)/sizeof(stru_TbConvert);iIn
dex++) |
290 { | 288 { |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
460 strFormat = wcsftime(buf, 64, cFormat.c_str(), &time); | 458 strFormat = wcsftime(buf, 64, cFormat.c_str(), &time); |
461 cFormat = buf; | 459 cFormat = buf; |
462 cPurpose = cFormat; | 460 cPurpose = cFormat; |
463 } | 461 } |
464 | 462 |
465 FX_BOOL util::printx(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value&
vRet, CFX_WideString& sError) | 463 FX_BOOL util::printx(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value&
vRet, CFX_WideString& sError) |
466 { | 464 { |
467 int iSize = params.size(); | 465 int iSize = params.size(); |
468 if (iSize<2) | 466 if (iSize<2) |
469 return FALSE; | 467 return FALSE; |
470 » CFX_WideString sFormat = params[0].operator CFX_WideString(); | 468 » CFX_WideString sFormat = params[0].ToCFXWideString(); |
471 » CFX_WideString sSource = params[1].operator CFX_WideString(); | 469 » CFX_WideString sSource = params[1].ToCFXWideString(); |
472 std::string cFormat = CFX_ByteString::FromUnicode(sFormat).c_str(); | 470 std::string cFormat = CFX_ByteString::FromUnicode(sFormat).c_str(); |
473 std::string cSource = CFX_ByteString::FromUnicode(sSource).c_str(); | 471 std::string cSource = CFX_ByteString::FromUnicode(sSource).c_str(); |
474 std::string cDest; | 472 std::string cDest; |
475 printx(cFormat,cSource,cDest); | 473 printx(cFormat,cSource,cDest); |
476 vRet = cDest.c_str(); | 474 vRet = cDest.c_str(); |
477 return TRUE; | 475 return TRUE; |
478 } | 476 } |
479 | 477 |
480 void util::printx(const std::string &cFormat,const std::string &cSource2,std::st
ring &cPurpose) | 478 void util::printx(const std::string &cFormat,const std::string &cSource2,std::st
ring &cPurpose) |
481 { | 479 { |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
575 } | 573 } |
576 } | 574 } |
577 } | 575 } |
578 | 576 |
579 FX_BOOL util::scand(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value&
vRet, CFX_WideString& sError) | 577 FX_BOOL util::scand(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value&
vRet, CFX_WideString& sError) |
580 { | 578 { |
581 v8::Isolate* isolate = GetIsolate(cc); | 579 v8::Isolate* isolate = GetIsolate(cc); |
582 int iSize = params.size(); | 580 int iSize = params.size(); |
583 if (iSize < 2) | 581 if (iSize < 2) |
584 return FALSE; | 582 return FALSE; |
585 CFX_WideString sFormat = params[0].operator CFX_WideString(); | |
586 CFX_WideString sDate = params[1].operator CFX_WideString(); | |
587 | 583 |
| 584 CFX_WideString sFormat = params[0].ToCFXWideString(); |
| 585 CFX_WideString sDate = params[1].ToCFXWideString(); |
588 double dDate = JS_GetDateTime(); | 586 double dDate = JS_GetDateTime(); |
589 if (sDate.GetLength() > 0) | 587 if (sDate.GetLength() > 0) |
590 { | 588 { |
591 FX_BOOL bWrongFormat = FALSE; | 589 FX_BOOL bWrongFormat = FALSE; |
592 dDate = CJS_PublicMethods::MakeRegularDate(sDate,sFormat,bWrongF
ormat); | 590 dDate = CJS_PublicMethods::MakeRegularDate(sDate,sFormat,bWrongF
ormat); |
593 } | 591 } |
594 | 592 |
595 if (!JS_PortIsNan(dDate)) | 593 if (!JS_PortIsNan(dDate)) |
596 { | 594 { |
597 CJS_Date date(isolate,dDate); | 595 CJS_Date date(isolate,dDate); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
631 return -total; | 629 return -total; |
632 else | 630 else |
633 return total; /* return result, negated if necessary */ | 631 return total; /* return result, negated if necessary */ |
634 } | 632 } |
635 | 633 |
636 FX_BOOL util::byteToChar(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Va
lue& vRet, CFX_WideString& sError) | 634 FX_BOOL util::byteToChar(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Va
lue& vRet, CFX_WideString& sError) |
637 { | 635 { |
638 int iSize = params.size(); | 636 int iSize = params.size(); |
639 if (iSize == 0) | 637 if (iSize == 0) |
640 return FALSE; | 638 return FALSE; |
641 » int nByte = (int)params[0]; | 639 » int nByte = params[0].ToInt(); |
642 unsigned char cByte = (unsigned char)nByte; | 640 unsigned char cByte = (unsigned char)nByte; |
643 CFX_WideString csValue; | 641 CFX_WideString csValue; |
644 csValue.Format(L"%c", cByte); | 642 csValue.Format(L"%c", cByte); |
645 vRet = csValue; | 643 vRet = csValue; |
646 return TRUE; | 644 return TRUE; |
647 } | 645 } |
OLD | NEW |