Merge to master: Kill off some dodgy JS callbacks
[pdfium.git] / fpdfsdk / src / javascript / Consts.cpp
1 // 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.
4  
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6
7 #include "../../include/javascript/JavaScript.h"
8 #include "../../include/javascript/IJavaScript.h"
9 #include "../../include/javascript/JS_Define.h"
10 #include "../../include/javascript/JS_Object.h"
11 #include "../../include/javascript/JS_Value.h"
12 #include "../../include/javascript/Consts.h"
13
14 /* ------------------------------ border ------------------------------ */
15
16 BEGIN_JS_STATIC_CONST(CJS_Border)
17         JS_STATIC_CONST_ENTRY_STRING(s, solid)
18         JS_STATIC_CONST_ENTRY_STRING(b, beveled)
19         JS_STATIC_CONST_ENTRY_STRING(d, dashed)
20         JS_STATIC_CONST_ENTRY_STRING(i, inset)
21         JS_STATIC_CONST_ENTRY_STRING(u, underline)
22 END_JS_STATIC_CONST()
23
24 IMPLEMENT_JS_CLASS_CONST(CJS_Border,border)
25
26 /* ------------------------------ display ------------------------------ */
27
28 BEGIN_JS_STATIC_CONST(CJS_Display)
29         JS_STATIC_CONST_ENTRY_NUMBER(visible,   0)
30         JS_STATIC_CONST_ENTRY_NUMBER(hidden,    1)
31         JS_STATIC_CONST_ENTRY_NUMBER(noPrint,   2)
32         JS_STATIC_CONST_ENTRY_NUMBER(noView,    3)
33 END_JS_STATIC_CONST()
34
35 IMPLEMENT_JS_CLASS_CONST(CJS_Display,display)
36
37 /* ------------------------------ font ------------------------------ */
38
39 BEGIN_JS_STATIC_CONST(CJS_Font)
40         JS_STATIC_CONST_ENTRY_STRING(Times,             Times-Roman)
41         JS_STATIC_CONST_ENTRY_STRING(TimesB,    Times-Bold)
42         JS_STATIC_CONST_ENTRY_STRING(TimesI,    Times-Italic)
43         JS_STATIC_CONST_ENTRY_STRING(TimesBI,   Times-BoldItalic)
44         JS_STATIC_CONST_ENTRY_STRING(Helv,              Helvetica)
45         JS_STATIC_CONST_ENTRY_STRING(HelvB,             Helvetica-Bold)
46         JS_STATIC_CONST_ENTRY_STRING(HelvI,             Helvetica-Oblique)
47         JS_STATIC_CONST_ENTRY_STRING(HelvBI,    Helvetica-BoldOblique)
48         JS_STATIC_CONST_ENTRY_STRING(Cour,              Courier)
49         JS_STATIC_CONST_ENTRY_STRING(CourB,             Courier-Bold)
50         JS_STATIC_CONST_ENTRY_STRING(CourI,             Courier-Oblique)
51         JS_STATIC_CONST_ENTRY_STRING(CourBI,    Courier-BoldOblique)
52         JS_STATIC_CONST_ENTRY_STRING(Symbol,    Symbol)
53         JS_STATIC_CONST_ENTRY_STRING(ZapfD,             ZapfDingbats)
54 END_JS_STATIC_CONST()
55
56 IMPLEMENT_JS_CLASS_CONST(CJS_Font,font)
57
58 /* ------------------------------ highlight ------------------------------ */
59
60 BEGIN_JS_STATIC_CONST(CJS_Highlight)
61         JS_STATIC_CONST_ENTRY_STRING(n, none)
62         JS_STATIC_CONST_ENTRY_STRING(i, invert)
63         JS_STATIC_CONST_ENTRY_STRING(p, push)
64         JS_STATIC_CONST_ENTRY_STRING(o, outline)
65 END_JS_STATIC_CONST()
66
67 IMPLEMENT_JS_CLASS_CONST(CJS_Highlight,highlight)
68
69 /* ------------------------------ position ------------------------------ */
70
71 BEGIN_JS_STATIC_CONST(CJS_Position)
72         JS_STATIC_CONST_ENTRY_NUMBER(textOnly,          0)
73         JS_STATIC_CONST_ENTRY_NUMBER(iconOnly,          1)
74         JS_STATIC_CONST_ENTRY_NUMBER(iconTextV,         2)
75         JS_STATIC_CONST_ENTRY_NUMBER(textIconV,         3)
76         JS_STATIC_CONST_ENTRY_NUMBER(iconTextH,         4)
77         JS_STATIC_CONST_ENTRY_NUMBER(textIconH,         5)
78         JS_STATIC_CONST_ENTRY_NUMBER(overlay,           6)
79 END_JS_STATIC_CONST()
80
81 IMPLEMENT_JS_CLASS_CONST(CJS_Position,position)
82
83 /* ------------------------------ scaleHow ------------------------------ */
84
85 BEGIN_JS_STATIC_CONST(CJS_ScaleHow)
86         JS_STATIC_CONST_ENTRY_NUMBER(proportional,      0)
87         JS_STATIC_CONST_ENTRY_NUMBER(anamorphic,        1)
88 END_JS_STATIC_CONST()
89
90 IMPLEMENT_JS_CLASS_CONST(CJS_ScaleHow,scaleHow)
91
92 /* ------------------------------ scaleWhen ------------------------------ */
93
94 BEGIN_JS_STATIC_CONST(CJS_ScaleWhen)
95         JS_STATIC_CONST_ENTRY_NUMBER(always,    0)
96         JS_STATIC_CONST_ENTRY_NUMBER(never,             1)
97         JS_STATIC_CONST_ENTRY_NUMBER(tooBig,    2)
98         JS_STATIC_CONST_ENTRY_NUMBER(tooSmall,  3)
99 END_JS_STATIC_CONST()
100
101 IMPLEMENT_JS_CLASS_CONST(CJS_ScaleWhen,scaleWhen)
102
103 /* ------------------------------ style ------------------------------ */
104
105 BEGIN_JS_STATIC_CONST(CJS_Style)
106         JS_STATIC_CONST_ENTRY_STRING(ch,        check)
107         JS_STATIC_CONST_ENTRY_STRING(cr,        cross)
108         JS_STATIC_CONST_ENTRY_STRING(di,        diamond)
109         JS_STATIC_CONST_ENTRY_STRING(ci,        circle)
110         JS_STATIC_CONST_ENTRY_STRING(st,        star)
111         JS_STATIC_CONST_ENTRY_STRING(sq,        square)
112 END_JS_STATIC_CONST()
113
114 IMPLEMENT_JS_CLASS_CONST(CJS_Style,style)
115
116
117 /* ------------------------------ zoomtype ------------------------------ */
118
119 BEGIN_JS_STATIC_CONST(CJS_Zoomtype)
120         JS_STATIC_CONST_ENTRY_STRING(none,      NoVary)
121         JS_STATIC_CONST_ENTRY_STRING(fitP,      FitPage)
122         JS_STATIC_CONST_ENTRY_STRING(fitW,      FitWidth)
123         JS_STATIC_CONST_ENTRY_STRING(fitH,      FitHeight)
124         JS_STATIC_CONST_ENTRY_STRING(fitV,      FitVisibleWidth)
125         JS_STATIC_CONST_ENTRY_STRING(pref,      Preferred)
126         JS_STATIC_CONST_ENTRY_STRING(refW,      ReflowWidth)
127 END_JS_STATIC_CONST()
128
129 IMPLEMENT_JS_CLASS_CONST(CJS_Zoomtype,zoomtype)
130
131 /* ------------------------------ CJS_GlobalConsts ------------------------------ */
132
133 int     CJS_GlobalConsts::Init(IJS_Runtime* pRuntime)
134 {
135         DEFINE_GLOBAL_CONST(pRuntime, IDS_GREATER_THAN , Invalid value: must be greater than or equal to %s.);
136         DEFINE_GLOBAL_CONST(pRuntime, IDS_GT_AND_LT,Invalid value: must be greater than or equal to %s and less than or equal to %s.);
137         DEFINE_GLOBAL_CONST(pRuntime, IDS_LESS_THAN,Invalid value: must be less than or equal to %s.);
138         DEFINE_GLOBAL_CONST(pRuntime, IDS_INVALID_MONTH,** Invalid **);
139         DEFINE_GLOBAL_CONST(pRuntime, IDS_INVALID_DATE,Invalid date/time: please ensure that the date/time exists. Field);
140         DEFINE_GLOBAL_CONST(pRuntime, IDS_INVALID_VALUE,The value entered does not match the format of the field);
141         DEFINE_GLOBAL_CONST(pRuntime, IDS_AM,am);
142         DEFINE_GLOBAL_CONST(pRuntime, IDS_PM,pm);
143         DEFINE_GLOBAL_CONST(pRuntime, IDS_MONTH_INFO,January[1]February[2]March[3]April[4]May[5]June[6]July[7]August[8]September[9]October[10]November[11]December[12]Sept[9]Jan[1]Feb[2]Mar[3]Apr[4]Jun[6]Jul[7]Aug[8]Sep[9]Oct[10]Nov[11]Dec[12]);
144         DEFINE_GLOBAL_CONST(pRuntime, IDS_STARTUP_CONSOLE_MSG, ** ^_^ **);
145
146         return 0;
147 }
148
149 /* ------------------------------ CJS_GlobalArrays ------------------------------ */
150
151 int     CJS_GlobalArrays::Init(IJS_Runtime* pRuntime)
152 {
153         {
154                 FX_LPCWSTR ArrayName = L"RE_NUMBER_ENTRY_DOT_SEP";
155                 FX_LPCWSTR ArrayContent[] = {L"[+-]?\\d*\\.?\\d*"};
156                 DEFINE_GLOBAL_ARRAY(pRuntime);
157         }
158
159         {
160                 FX_LPCWSTR ArrayName = L"RE_NUMBER_COMMIT_DOT_SEP";
161                 FX_LPCWSTR ArrayContent[] = { L"[+-]?\\d+(\\.\\d+)?",                /* -1.0 or -1 */
162                                                                           L"[+-]?\\.\\d+",                       /* -.1 */
163                                                                           L"[+-]?\\d+\\."                        /* -1. */
164                                                                         };
165                 DEFINE_GLOBAL_ARRAY(pRuntime);
166         }
167
168         {
169                 FX_LPCWSTR ArrayName = L"RE_NUMBER_ENTRY_COMMA_SEP";
170                 FX_LPCWSTR ArrayContent[] = {L"[+-]?\\d*,?\\d*"};
171                 
172                 DEFINE_GLOBAL_ARRAY(pRuntime);
173         }
174
175         {
176                 FX_LPCWSTR ArrayName = L"RE_NUMBER_COMMIT_COMMA_SEP";
177                 FX_LPCWSTR ArrayContent[] = { L"[+-]?\\d+([.,]\\d+)?",               /* -1,0 or -1 */
178                                                                           L"[+-]?[.,]\\d+",                   /* -,1 */
179                                       L"[+-]?\\d+[.,]"                            /* -1, */
180                                     };
181                 DEFINE_GLOBAL_ARRAY(pRuntime);
182         }
183
184         {
185                 FX_LPCWSTR ArrayName = L"RE_ZIP_ENTRY";
186         FX_LPCWSTR ArrayContent[] = {L"\\d{0,5}"};
187                 DEFINE_GLOBAL_ARRAY(pRuntime);
188         }
189
190         {
191                 FX_LPCWSTR ArrayName = L"RE_ZIP_COMMIT";
192                 FX_LPCWSTR ArrayContent[] = {L"\\d{5}"};
193                 DEFINE_GLOBAL_ARRAY(pRuntime);
194         }
195
196         {
197                 FX_LPCWSTR ArrayName = L"RE_ZIP4_ENTRY";
198                 FX_LPCWSTR ArrayContent[] = {L"\\d{0,5}(\\.|[- ])?\\d{0,4}"};
199                 DEFINE_GLOBAL_ARRAY(pRuntime);
200         }
201
202         {
203                 FX_LPCWSTR ArrayName = L"RE_ZIP4_COMMIT";
204                 FX_LPCWSTR ArrayContent[] = {L"\\d{5}(\\.|[- ])?\\d{4}"};
205                 DEFINE_GLOBAL_ARRAY(pRuntime);
206         }
207
208         {
209                 FX_LPCWSTR ArrayName = L"RE_PHONE_ENTRY";
210                 FX_LPCWSTR ArrayContent[] = {
211                                 L"\\d{0,3}(\\.|[- ])?\\d{0,3}(\\.|[- ])?\\d{0,4}",              /* 555-1234 or 408 555-1234 */
212                                 L"\\(\\d{0,3}",                                                                                 /* (408 */
213                                 L"\\(\\d{0,3}\\)(\\.|[- ])?\\d{0,3}(\\.|[- ])?\\d{0,4}",        /* (408) 555-1234 */
214                                         /* (allow the addition of parens as an afterthought) */
215                                 L"\\(\\d{0,3}(\\.|[- ])?\\d{0,3}(\\.|[- ])?\\d{0,4}",   /* (408 555-1234 */
216                                 L"\\d{0,3}\\)(\\.|[- ])?\\d{0,3}(\\.|[- ])?\\d{0,4}",   /* 408) 555-1234 */
217                                 L"011(\\.|[- \\d])*"                                                                            /* international */
218                         };
219                 DEFINE_GLOBAL_ARRAY(pRuntime);
220         }
221
222         {
223                 FX_LPCWSTR ArrayName = L"RE_PHONE_COMMIT";
224                 FX_LPCWSTR ArrayContent[] = {
225                                         L"\\d{3}(\\.|[- ])?\\d{4}",                                                     /* 555-1234 */
226                                         L"\\d{3}(\\.|[- ])?\\d{3}(\\.|[- ])?\\d{4}",                    /* 408 555-1234 */
227                                         L"\\(\\d{3}\\)(\\.|[- ])?\\d{3}(\\.|[- ])?\\d{4}",      /* (408) 555-1234 */
228                                         L"011(\\.|[- \\d])*"                                                                    /* international */
229                                 };
230                 DEFINE_GLOBAL_ARRAY(pRuntime);
231         }
232
233         {
234                 FX_LPCWSTR ArrayName = L"RE_SSN_ENTRY";
235                 FX_LPCWSTR ArrayContent[] = {L"\\d{0,3}(\\.|[- ])?\\d{0,2}(\\.|[- ])?\\d{0,4}"};
236                 DEFINE_GLOBAL_ARRAY(pRuntime);
237         }
238
239         {
240                 FX_LPCWSTR ArrayName = L"RE_SSN_COMMIT";
241                 FX_LPCWSTR ArrayContent[] = {L"\\d{3}(\\.|[- ])?\\d{2}(\\.|[- ])?\\d{4}"};
242                 DEFINE_GLOBAL_ARRAY(pRuntime);
243         }
244
245         return 0;
246 }
247