blob: a9fe01dadc09da601c3ef13bb0a58c16bc8deb7e [file] [log] [blame]
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001// Copyright 2014 PDFium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
Lei Zhanga6d9f0e2015-06-13 00:48:38 -07004
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07005// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6
Dan Sinclairf766ad22016-03-14 13:51:24 -04007#include "fpdfsdk/javascript/Consts.h"
Tom Sepez37458412015-10-06 11:33:46 -07008
Dan Sinclairf766ad22016-03-14 13:51:24 -04009#include "fpdfsdk/javascript/JS_Define.h"
10#include "fpdfsdk/javascript/JS_Object.h"
11#include "fpdfsdk/javascript/JS_Value.h"
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070012
Tom Sepez04557b82017-02-16 09:43:10 -080013JSConstSpec CJS_Border::ConstSpecs[] = {
14 {L"s", JSConstSpec::String, 0, L"solid"},
15 {L"b", JSConstSpec::String, 0, L"beveled"},
16 {L"d", JSConstSpec::String, 0, L"dashed"},
17 {L"i", JSConstSpec::String, 0, L"inset"},
18 {L"u", JSConstSpec::String, 0, L"underline"},
19 {0, JSConstSpec::Number, 0, 0}};
Nico Weber9d8ec5a2015-08-04 13:00:21 -070020IMPLEMENT_JS_CLASS_CONST(CJS_Border, border)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070021
Tom Sepez04557b82017-02-16 09:43:10 -080022JSConstSpec CJS_Display::ConstSpecs[] = {
23 {L"visible", JSConstSpec::Number, 0, 0},
24 {L"hidden", JSConstSpec::Number, 1, 0},
25 {L"noPrint", JSConstSpec::Number, 2, 0},
26 {L"noView", JSConstSpec::Number, 3, 0},
27 {0, JSConstSpec::Number, 0, 0}};
Nico Weber9d8ec5a2015-08-04 13:00:21 -070028IMPLEMENT_JS_CLASS_CONST(CJS_Display, display)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070029
Tom Sepez04557b82017-02-16 09:43:10 -080030JSConstSpec CJS_Font::ConstSpecs[] = {
31 {L"Times", JSConstSpec::String, 0, L"Times-Roman"},
32 {L"TimesB", JSConstSpec::String, 0, L"Times-Bold"},
33 {L"TimesI", JSConstSpec::String, 0, L"Times-Italic"},
34 {L"TimesBI", JSConstSpec::String, 0, L"Times-BoldItalic"},
35 {L"Helv", JSConstSpec::String, 0, L"Helvetica"},
36 {L"HelvB", JSConstSpec::String, 0, L"Helvetica-Bold"},
37 {L"HelvI", JSConstSpec::String, 0, L"Helvetica-Oblique"},
38 {L"HelvBI", JSConstSpec::String, 0, L"Helvetica-BoldOblique"},
39 {L"Cour", JSConstSpec::String, 0, L"Courier"},
40 {L"CourB", JSConstSpec::String, 0, L"Courier-Bold"},
41 {L"CourI", JSConstSpec::String, 0, L"Courier-Oblique"},
42 {L"CourBI", JSConstSpec::String, 0, L"Courier-BoldOblique"},
43 {L"Symbol", JSConstSpec::String, 0, L"Symbol"},
44 {L"ZapfD", JSConstSpec::String, 0, L"ZapfDingbats"},
45 {0, JSConstSpec::Number, 0, 0}};
Nico Weber9d8ec5a2015-08-04 13:00:21 -070046IMPLEMENT_JS_CLASS_CONST(CJS_Font, font)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070047
Tom Sepez04557b82017-02-16 09:43:10 -080048JSConstSpec CJS_Highlight::ConstSpecs[] = {
49 {L"n", JSConstSpec::String, 0, L"none"},
50 {L"i", JSConstSpec::String, 0, L"invert"},
51 {L"p", JSConstSpec::String, 0, L"push"},
52 {L"o", JSConstSpec::String, 0, L"outline"},
53 {0, JSConstSpec::Number, 0, 0}};
Nico Weber9d8ec5a2015-08-04 13:00:21 -070054IMPLEMENT_JS_CLASS_CONST(CJS_Highlight, highlight)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070055
Tom Sepez04557b82017-02-16 09:43:10 -080056JSConstSpec CJS_Position::ConstSpecs[] = {
57 {L"textOnly", JSConstSpec::Number, 0, 0},
58 {L"iconOnly", JSConstSpec::Number, 1, 0},
59 {L"iconTextV", JSConstSpec::Number, 2, 0},
60 {L"textIconV", JSConstSpec::Number, 3, 0},
61 {L"iconTextH", JSConstSpec::Number, 4, 0},
62 {L"textIconH", JSConstSpec::Number, 5, 0},
63 {L"overlay", JSConstSpec::Number, 6, 0},
64 {0, JSConstSpec::Number, 0, 0}};
Nico Weber9d8ec5a2015-08-04 13:00:21 -070065IMPLEMENT_JS_CLASS_CONST(CJS_Position, position)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070066
Tom Sepez04557b82017-02-16 09:43:10 -080067JSConstSpec CJS_ScaleHow::ConstSpecs[] = {
68 {L"proportional", JSConstSpec::Number, 0, 0},
69 {L"anamorphic", JSConstSpec::Number, 1, 0},
70 {0, JSConstSpec::Number, 0, 0}};
Nico Weber9d8ec5a2015-08-04 13:00:21 -070071IMPLEMENT_JS_CLASS_CONST(CJS_ScaleHow, scaleHow)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070072
Tom Sepez04557b82017-02-16 09:43:10 -080073JSConstSpec CJS_ScaleWhen::ConstSpecs[] = {
74 {L"always", JSConstSpec::Number, 0, 0},
75 {L"never", JSConstSpec::Number, 1, 0},
76 {L"tooBig", JSConstSpec::Number, 2, 0},
77 {L"tooSmall", JSConstSpec::Number, 3, 0},
78 {0, JSConstSpec::Number, 0, 0}};
Nico Weber9d8ec5a2015-08-04 13:00:21 -070079IMPLEMENT_JS_CLASS_CONST(CJS_ScaleWhen, scaleWhen)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070080
Tom Sepez04557b82017-02-16 09:43:10 -080081JSConstSpec CJS_Style::ConstSpecs[] = {
82 {L"ch", JSConstSpec::String, 0, L"check"},
83 {L"cr", JSConstSpec::String, 0, L"cross"},
84 {L"di", JSConstSpec::String, 0, L"diamond"},
85 {L"ci", JSConstSpec::String, 0, L"circle"},
86 {L"st", JSConstSpec::String, 0, L"star"},
87 {L"sq", JSConstSpec::String, 0, L"square"},
88 {0, JSConstSpec::Number, 0, 0}};
Nico Weber9d8ec5a2015-08-04 13:00:21 -070089IMPLEMENT_JS_CLASS_CONST(CJS_Style, style)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070090
Tom Sepez04557b82017-02-16 09:43:10 -080091JSConstSpec CJS_Zoomtype::ConstSpecs[] = {
92 {L"none", JSConstSpec::String, 0, L"NoVary"},
93 {L"fitP", JSConstSpec::String, 0, L"FitPage"},
94 {L"fitW", JSConstSpec::String, 0, L"FitWidth"},
95 {L"fitH", JSConstSpec::String, 0, L"FitHeight"},
96 {L"fitV", JSConstSpec::String, 0, L"FitVisibleWidth"},
97 {L"pref", JSConstSpec::String, 0, L"Preferred"},
98 {L"refW", JSConstSpec::String, 0, L"ReflowWidth"},
99 {0, JSConstSpec::Number, 0, 0}};
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700100IMPLEMENT_JS_CLASS_CONST(CJS_Zoomtype, zoomtype)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700101
tsepezb4694242016-08-15 16:44:55 -0700102#define GLOBAL_STRING(rt, name, value) \
103 (rt)->DefineGlobalConst( \
104 (name), [](const v8::FunctionCallbackInfo<v8::Value>& info) { \
105 info.GetReturnValue().Set( \
106 CFXJS_Engine::CurrentEngineFromIsolate(info.GetIsolate()) \
107 ->NewString(value)); \
Tom Sepez297b5152016-03-04 13:43:46 -0800108 })
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700109
Tom Sepez1a35d552016-03-04 12:33:33 -0800110void CJS_GlobalConsts::DefineJSObjects(CJS_Runtime* pRuntime) {
Tom Sepez297b5152016-03-04 13:43:46 -0800111 GLOBAL_STRING(pRuntime, L"IDS_GREATER_THAN",
112 L"Invalid value: must be greater than or equal to % s.");
113
114 GLOBAL_STRING(pRuntime, L"IDS_GT_AND_LT",
115 L"Invalid value: must be greater than or equal to % s "
116 L"and less than or equal to % s.");
117
118 GLOBAL_STRING(pRuntime, L"IDS_LESS_THAN",
119 L"Invalid value: must be less than or equal to % s.");
120
121 GLOBAL_STRING(pRuntime, L"IDS_INVALID_MONTH", L"**Invalid**");
122 GLOBAL_STRING(
Tom Sepez1a35d552016-03-04 12:33:33 -0800123 pRuntime, L"IDS_INVALID_DATE",
124 L"Invalid date / time: please ensure that the date / time exists.Field");
Tom Sepez297b5152016-03-04 13:43:46 -0800125
126 GLOBAL_STRING(pRuntime, L"IDS_INVALID_VALUE",
127 L"The value entered does not match the format of the field");
128
129 GLOBAL_STRING(pRuntime, L"IDS_AM", L"am");
130 GLOBAL_STRING(pRuntime, L"IDS_PM", L"pm");
131 GLOBAL_STRING(pRuntime, L"IDS_MONTH_INFO",
132 L"January[1] February[2] March[3] April[4] May[5] "
133 L"June[6] July[7] August[8] September[9] October[10] "
134 L"November[11] December[12] Sept[9] Jan[1] Feb[2] Mar[3] "
135 L"Apr[4] Jun[6] Jul[7] Aug[8] Sep[9] Oct[10] Nov[11] "
136 L"Dec[12]");
137
138 GLOBAL_STRING(pRuntime, L"IDS_STARTUP_CONSOLE_MSG", L"** ^ _ ^ **");
Tom Sepez1a35d552016-03-04 12:33:33 -0800139}
140
tsepezb4694242016-08-15 16:44:55 -0700141#define GLOBAL_ARRAY(rt, name, ...) \
142 { \
143 const FX_WCHAR* values[] = {__VA_ARGS__}; \
144 v8::Local<v8::Array> array = (rt)->NewArray(); \
145 for (size_t i = 0; i < FX_ArraySize(values); ++i) \
146 array->Set(i, (rt)->NewString(values[i])); \
147 (rt)->SetConstArray((name), array); \
148 (rt)->DefineGlobalConst( \
149 (name), [](const v8::FunctionCallbackInfo<v8::Value>& info) { \
150 CJS_Runtime* pCurrentRuntime = \
151 CJS_Runtime::CurrentRuntimeFromIsolate(info.GetIsolate()); \
152 if (pCurrentRuntime) \
153 info.GetReturnValue().Set(pCurrentRuntime->GetConstArray(name)); \
154 }); \
Tom Sepez570875c2015-09-11 08:35:03 -0700155 }
156
Tom Sepez67fd5df2015-10-08 12:24:19 -0700157void CJS_GlobalArrays::DefineJSObjects(CJS_Runtime* pRuntime) {
Tom Sepez297b5152016-03-04 13:43:46 -0800158 GLOBAL_ARRAY(pRuntime, L"RE_NUMBER_ENTRY_DOT_SEP", L"[+-]?\\d*\\.?\\d*");
159 GLOBAL_ARRAY(pRuntime, L"RE_NUMBER_COMMIT_DOT_SEP",
160 L"[+-]?\\d+(\\.\\d+)?", // -1.0 or -1
161 L"[+-]?\\.\\d+", // -.1
162 L"[+-]?\\d+\\."); // -1.
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700163
Tom Sepez297b5152016-03-04 13:43:46 -0800164 GLOBAL_ARRAY(pRuntime, L"RE_NUMBER_ENTRY_COMMA_SEP", L"[+-]?\\d*,?\\d*");
165 GLOBAL_ARRAY(pRuntime, L"RE_NUMBER_COMMIT_COMMA_SEP",
166 L"[+-]?\\d+([.,]\\d+)?", // -1,0 or -1
167 L"[+-]?[.,]\\d+", // -,1
168 L"[+-]?\\d+[.,]"); // -1,
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700169
Tom Sepez297b5152016-03-04 13:43:46 -0800170 GLOBAL_ARRAY(pRuntime, L"RE_ZIP_ENTRY", L"\\d{0,5}");
171 GLOBAL_ARRAY(pRuntime, L"RE_ZIP_COMMIT", L"\\d{5}");
172 GLOBAL_ARRAY(pRuntime, L"RE_ZIP4_ENTRY", L"\\d{0,5}(\\.|[- ])?\\d{0,4}");
173 GLOBAL_ARRAY(pRuntime, L"RE_ZIP4_COMMIT", L"\\d{5}(\\.|[- ])?\\d{4}");
174 GLOBAL_ARRAY(pRuntime, L"RE_PHONE_ENTRY",
175 // 555-1234 or 408 555-1234
176 L"\\d{0,3}(\\.|[- ])?\\d{0,3}(\\.|[- ])?\\d{0,4}",
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700177
Tom Sepez297b5152016-03-04 13:43:46 -0800178 // (408
179 L"\\(\\d{0,3}",
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700180
Tom Sepez297b5152016-03-04 13:43:46 -0800181 // (408) 555-1234
182 // (allow the addition of parens as an afterthought)
183 L"\\(\\d{0,3}\\)(\\.|[- ])?\\d{0,3}(\\.|[- ])?\\d{0,4}",
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700184
Tom Sepez297b5152016-03-04 13:43:46 -0800185 // (408 555-1234
186 L"\\(\\d{0,3}(\\.|[- ])?\\d{0,3}(\\.|[- ])?\\d{0,4}",
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700187
Tom Sepez297b5152016-03-04 13:43:46 -0800188 // 408) 555-1234
189 L"\\d{0,3}\\)(\\.|[- ])?\\d{0,3}(\\.|[- ])?\\d{0,4}",
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700190
Tom Sepez297b5152016-03-04 13:43:46 -0800191 // international
192 L"011(\\.|[- \\d])*");
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700193
Tom Sepez297b5152016-03-04 13:43:46 -0800194 GLOBAL_ARRAY(
195 pRuntime, L"RE_PHONE_COMMIT", L"\\d{3}(\\.|[- ])?\\d{4}", // 555-1234
196 L"\\d{3}(\\.|[- ])?\\d{3}(\\.|[- ])?\\d{4}", // 408 555-1234
197 L"\\(\\d{3}\\)(\\.|[- ])?\\d{3}(\\.|[- ])?\\d{4}", // (408) 555-1234
198 L"011(\\.|[- \\d])*"); // international
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700199
Tom Sepez297b5152016-03-04 13:43:46 -0800200 GLOBAL_ARRAY(pRuntime, L"RE_SSN_ENTRY",
201 L"\\d{0,3}(\\.|[- ])?\\d{0,2}(\\.|[- ])?\\d{0,4}");
Dan Sinclair738b08c2016-03-01 14:45:20 -0500202
Tom Sepez297b5152016-03-04 13:43:46 -0800203 GLOBAL_ARRAY(pRuntime, L"RE_SSN_COMMIT",
204 L"\\d{3}(\\.|[- ])?\\d{2}(\\.|[- ])?\\d{4}");
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700205}