Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(14)

Side by Side Diff: xfa/fxfa/parser/xfa_utils_imp.cpp

Issue 2132513003: Cleanup redundant method names. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "xfa/fxfa/parser/xfa_utils.h" 7 #include "xfa/fxfa/parser/xfa_utils.h"
8 8
9 #include "core/fxcrt/include/fx_ext.h" 9 #include "core/fxcrt/include/fx_ext.h"
10 #include "xfa/fde/xml/fde_xml_imp.h" 10 #include "xfa/fde/xml/fde_xml_imp.h"
11 #include "xfa/fxfa/parser/xfa_doclayout.h" 11 #include "xfa/fxfa/parser/xfa_doclayout.h"
12 #include "xfa/fxfa/parser/xfa_document.h" 12 #include "xfa/fxfa/parser/xfa_document.h"
13 #include "xfa/fxfa/parser/xfa_localemgr.h" 13 #include "xfa/fxfa/parser/xfa_localemgr.h"
14 #include "xfa/fxfa/parser/xfa_localevalue.h" 14 #include "xfa/fxfa/parser/xfa_localevalue.h"
15 #include "xfa/fxfa/parser/xfa_object.h" 15 #include "xfa/fxfa/parser/xfa_object.h"
16 #include "xfa/fxfa/parser/xfa_parser.h" 16 #include "xfa/fxfa/parser/xfa_parser.h"
17 #include "xfa/fxfa/parser/xfa_script.h" 17 #include "xfa/fxfa/parser/xfa_script.h"
18 18
19 CXFA_Node* XFA_CreateUIChild(CXFA_Node* pNode, XFA_Element& eWidgetType) { 19 namespace {
20 XFA_Element eType = pNode->GetElementType(); 20
21 eWidgetType = eType; 21 const FX_DOUBLE fraction_scales[] = {0.1,
Lei Zhang 2016/07/07 19:36:18 Needs Mario ASCII art.
dsinclair 2016/07/07 19:47:49 Acknowledged.
22 if (eType != XFA_Element::Field && eType != XFA_Element::Draw) { 22 0.01,
23 return nullptr; 23 0.001,
24 0.0001,
25 0.00001,
26 0.000001,
27 0.0000001,
28 0.00000001,
29 0.000000001,
30 0.0000000001,
31 0.00000000001,
32 0.000000000001,
33 0.0000000000001,
34 0.00000000000001,
35 0.000000000000001,
36 0.0000000000000001};
37
38 FX_DOUBLE WideStringToDouble(const CFX_WideString& wsStringVal) {
39 CFX_WideString wsValue = wsStringVal;
40 wsValue.TrimLeft();
41 wsValue.TrimRight();
42 int64_t nIntegral = 0;
43 uint32_t dwFractional = 0;
44 int32_t nExponent = 0;
45 int32_t cc = 0;
46 FX_BOOL bNegative = FALSE, bExpSign = FALSE;
Lei Zhang 2016/07/07 20:24:06 One per line, bool.
dsinclair 2016/07/11 13:22:39 Done.
47 const FX_WCHAR* str = wsValue.c_str();
48 int32_t len = wsValue.GetLength();
49 if (str[0] == '+') {
50 cc++;
51 } else if (str[0] == '-') {
52 bNegative = TRUE;
53 cc++;
24 } 54 }
25 eWidgetType = XFA_Element::Unknown; 55 int32_t nIntegralLen = 0;
26 XFA_Element eUIType = XFA_Element::Unknown; 56 while (cc < len) {
27 CXFA_Value defValue(pNode->GetProperty(0, XFA_Element::Value, TRUE)); 57 if (str[cc] == '.' || str[cc] == 'E' || str[cc] == 'e' ||
28 XFA_Element eValueType = defValue.GetChildValueClassID(); 58 nIntegralLen > 17) {
29 switch (eValueType) {
30 case XFA_Element::Boolean:
31 eUIType = XFA_Element::CheckButton;
32 break;
33 case XFA_Element::Integer:
34 case XFA_Element::Decimal:
35 case XFA_Element::Float:
36 eUIType = XFA_Element::NumericEdit;
37 break;
38 case XFA_Element::ExData:
39 case XFA_Element::Text:
40 eUIType = XFA_Element::TextEdit;
41 eWidgetType = XFA_Element::Text;
42 break;
43 case XFA_Element::Date:
44 case XFA_Element::Time:
45 case XFA_Element::DateTime:
46 eUIType = XFA_Element::DateTimeEdit;
47 break;
48 case XFA_Element::Image:
49 eUIType = XFA_Element::ImageEdit;
50 eWidgetType = XFA_Element::Image;
51 break;
52 case XFA_Element::Arc:
53 case XFA_Element::Line:
54 case XFA_Element::Rectangle:
55 eUIType = XFA_Element::DefaultUi;
56 eWidgetType = eValueType;
57 break;
58 default:
59 break;
60 }
61 CXFA_Node* pUIChild = nullptr;
62 CXFA_Node* pUI = pNode->GetProperty(0, XFA_Element::Ui, TRUE);
63 CXFA_Node* pChild = pUI->GetNodeItem(XFA_NODEITEM_FirstChild);
64 for (; pChild; pChild = pChild->GetNodeItem(XFA_NODEITEM_NextSibling)) {
65 XFA_Element eChildType = pChild->GetElementType();
66 if (eChildType == XFA_Element::Extras ||
67 eChildType == XFA_Element::Picture) {
68 continue;
69 }
70 const XFA_PROPERTY* pProperty = XFA_GetPropertyOfElement(
71 XFA_Element::Ui, eChildType, XFA_XDPPACKET_Form);
72 if (pProperty && (pProperty->uFlags & XFA_PROPERTYFLAG_OneOf)) {
73 pUIChild = pChild;
74 break; 59 break;
75 } 60 }
61 if (!FXSYS_isDecimalDigit(str[cc])) {
62 return 0;
63 }
64 nIntegral = nIntegral * 10 + str[cc] - '0';
65 cc++;
66 nIntegralLen++;
76 } 67 }
77 if (eType == XFA_Element::Draw) { 68 nIntegral = bNegative ? -nIntegral : nIntegral;
78 XFA_Element eDraw = 69 int32_t scale = 0;
79 pUIChild ? pUIChild->GetElementType() : XFA_Element::Unknown; 70 FX_DOUBLE fraction = 0.0;
80 switch (eDraw) { 71 if (cc < len && str[cc] == '.') {
81 case XFA_Element::TextEdit: 72 cc++;
82 eWidgetType = XFA_Element::Text; 73 while (cc < len) {
74 fraction += fraction_scales[scale] * (str[cc] - '0');
75 scale++;
76 cc++;
77 if (cc == len) {
83 break; 78 break;
84 case XFA_Element::ImageEdit: 79 }
85 eWidgetType = XFA_Element::Image; 80 if (scale == sizeof(fraction_scales) / sizeof(FX_DOUBLE) ||
81 str[cc] == 'E' || str[cc] == 'e') {
86 break; 82 break;
87 default: 83 }
88 eWidgetType = eWidgetType == XFA_Element::Unknown ? XFA_Element::Text 84 if (!FXSYS_isDecimalDigit(str[cc])) {
89 : eWidgetType; 85 return 0;
90 break; 86 }
91 } 87 }
92 } else { 88 dwFractional = (uint32_t)(fraction * 4294967296.0);
93 if (pUIChild && pUIChild->GetElementType() == XFA_Element::DefaultUi) { 89 }
94 eWidgetType = XFA_Element::TextEdit; 90 if (cc < len && (str[cc] == 'E' || str[cc] == 'e')) {
95 } else { 91 cc++;
96 eWidgetType = 92 if (cc < len) {
97 pUIChild ? pUIChild->GetElementType() 93 if (str[cc] == '+') {
98 : (eUIType == XFA_Element::Unknown ? XFA_Element::TextEdit 94 cc++;
99 : eUIType); 95 } else if (str[cc] == '-') {
96 bExpSign = TRUE;
97 cc++;
98 }
100 } 99 }
100 while (cc < len) {
101 if (str[cc] == '.' || !FXSYS_isDecimalDigit(str[cc])) {
102 return 0;
103 }
104 nExponent = nExponent * 10 + str[cc] - '0';
105 cc++;
106 }
107 nExponent = bExpSign ? -nExponent : nExponent;
101 } 108 }
102 if (!pUIChild) { 109 FX_DOUBLE dValue = (dwFractional / 4294967296.0);
103 if (eUIType == XFA_Element::Unknown) { 110 dValue = nIntegral + (nIntegral >= 0 ? dValue : -dValue);
104 eUIType = XFA_Element::TextEdit; 111 if (nExponent != 0) {
105 defValue.GetNode()->GetProperty(0, XFA_Element::Text, TRUE); 112 dValue *= FXSYS_pow(10, (FX_FLOAT)nExponent);
106 }
107 pUIChild = pUI->GetProperty(0, eUIType, TRUE);
108 } else if (eUIType == XFA_Element::Unknown) {
109 switch (pUIChild->GetElementType()) {
110 case XFA_Element::CheckButton: {
111 eValueType = XFA_Element::Text;
112 if (CXFA_Node* pItems = pNode->GetChild(0, XFA_Element::Items)) {
113 if (CXFA_Node* pItem = pItems->GetChild(0, XFA_Element::Unknown)) {
114 eValueType = pItem->GetElementType();
115 }
116 }
117 } break;
118 case XFA_Element::DateTimeEdit:
119 eValueType = XFA_Element::DateTime;
120 break;
121 case XFA_Element::ImageEdit:
122 eValueType = XFA_Element::Image;
123 break;
124 case XFA_Element::NumericEdit:
125 eValueType = XFA_Element::Float;
126 break;
127 case XFA_Element::ChoiceList: {
128 eValueType = (pUIChild->GetEnum(XFA_ATTRIBUTE_Open) ==
129 XFA_ATTRIBUTEENUM_MultiSelect)
130 ? XFA_Element::ExData
131 : XFA_Element::Text;
132 } break;
133 case XFA_Element::Barcode:
134 case XFA_Element::Button:
135 case XFA_Element::PasswordEdit:
136 case XFA_Element::Signature:
137 case XFA_Element::TextEdit:
138 default:
139 eValueType = XFA_Element::Text;
140 break;
141 }
142 defValue.GetNode()->GetProperty(0, eValueType, TRUE);
143 } 113 }
144 return pUIChild; 114 return dValue;
145 } 115 }
116
117 } // namespace
118
146 CXFA_LocaleValue XFA_GetLocaleValue(CXFA_WidgetData* pWidgetData) { 119 CXFA_LocaleValue XFA_GetLocaleValue(CXFA_WidgetData* pWidgetData) {
147 CXFA_Node* pNodeValue = 120 CXFA_Node* pNodeValue =
148 pWidgetData->GetNode()->GetChild(0, XFA_Element::Value); 121 pWidgetData->GetNode()->GetChild(0, XFA_Element::Value);
149 if (!pNodeValue) { 122 if (!pNodeValue) {
150 return CXFA_LocaleValue(); 123 return CXFA_LocaleValue();
151 } 124 }
152 CXFA_Node* pValueChild = pNodeValue->GetNodeItem(XFA_NODEITEM_FirstChild); 125 CXFA_Node* pValueChild = pNodeValue->GetNodeItem(XFA_NODEITEM_FirstChild);
153 if (!pValueChild) { 126 if (!pValueChild) {
154 return CXFA_LocaleValue(); 127 return CXFA_LocaleValue();
155 } 128 }
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
239 if (pUIChild) { 212 if (pUIChild) {
240 CXFA_Node* pFirstChild = pUIChild->GetNodeItem(XFA_NODEITEM_FirstChild); 213 CXFA_Node* pFirstChild = pUIChild->GetNodeItem(XFA_NODEITEM_FirstChild);
241 if (pFirstChild && 214 if (pFirstChild &&
242 pFirstChild->GetElementType() == XFA_Element::ChoiceList) { 215 pFirstChild->GetElementType() == XFA_Element::ChoiceList) {
243 bRet = pFirstChild->GetEnum(XFA_ATTRIBUTE_Open) == 216 bRet = pFirstChild->GetEnum(XFA_ATTRIBUTE_Open) ==
244 XFA_ATTRIBUTEENUM_MultiSelect; 217 XFA_ATTRIBUTEENUM_MultiSelect;
245 } 218 }
246 } 219 }
247 return bRet; 220 return bRet;
248 } 221 }
249 FX_BOOL XFA_IsLayoutElement(XFA_Element eElement, FX_BOOL bLayoutContainer) {
250 switch (eElement) {
251 case XFA_Element::Draw:
252 case XFA_Element::Field:
253 case XFA_Element::InstanceManager:
254 return !bLayoutContainer;
255 case XFA_Element::Area:
256 case XFA_Element::Subform:
257 case XFA_Element::ExclGroup:
258 case XFA_Element::SubformSet:
259 case XFA_Element::PageArea:
260 case XFA_Element::Form:
261 return TRUE;
262 default:
263 return FALSE;
264 }
265 }
266
267 static const FX_DOUBLE fraction_scales[] = {0.1,
268 0.01,
269 0.001,
270 0.0001,
271 0.00001,
272 0.000001,
273 0.0000001,
274 0.00000001,
275 0.000000001,
276 0.0000000001,
277 0.00000000001,
278 0.000000000001,
279 0.0000000000001,
280 0.00000000000001,
281 0.000000000000001,
282 0.0000000000000001};
283 FX_DOUBLE XFA_WideStringToDouble(const CFX_WideString& wsStringVal) {
284 CFX_WideString wsValue = wsStringVal;
285 wsValue.TrimLeft();
286 wsValue.TrimRight();
287 int64_t nIntegral = 0;
288 uint32_t dwFractional = 0;
289 int32_t nExponent = 0;
290 int32_t cc = 0;
291 FX_BOOL bNegative = FALSE, bExpSign = FALSE;
292 const FX_WCHAR* str = wsValue.c_str();
293 int32_t len = wsValue.GetLength();
294 if (str[0] == '+') {
295 cc++;
296 } else if (str[0] == '-') {
297 bNegative = TRUE;
298 cc++;
299 }
300 int32_t nIntegralLen = 0;
301 while (cc < len) {
302 if (str[cc] == '.' || str[cc] == 'E' || str[cc] == 'e' ||
303 nIntegralLen > 17) {
304 break;
305 }
306 if (!FXSYS_isDecimalDigit(str[cc])) {
307 return 0;
308 }
309 nIntegral = nIntegral * 10 + str[cc] - '0';
310 cc++;
311 nIntegralLen++;
312 }
313 nIntegral = bNegative ? -nIntegral : nIntegral;
314 int32_t scale = 0;
315 FX_DOUBLE fraction = 0.0;
316 if (cc < len && str[cc] == '.') {
317 cc++;
318 while (cc < len) {
319 fraction += fraction_scales[scale] * (str[cc] - '0');
320 scale++;
321 cc++;
322 if (cc == len) {
323 break;
324 }
325 if (scale == sizeof(fraction_scales) / sizeof(FX_DOUBLE) ||
326 str[cc] == 'E' || str[cc] == 'e') {
327 break;
328 }
329 if (!FXSYS_isDecimalDigit(str[cc])) {
330 return 0;
331 }
332 }
333 dwFractional = (uint32_t)(fraction * 4294967296.0);
334 }
335 if (cc < len && (str[cc] == 'E' || str[cc] == 'e')) {
336 cc++;
337 if (cc < len) {
338 if (str[cc] == '+') {
339 cc++;
340 } else if (str[cc] == '-') {
341 bExpSign = TRUE;
342 cc++;
343 }
344 }
345 while (cc < len) {
346 if (str[cc] == '.' || !FXSYS_isDecimalDigit(str[cc])) {
347 return 0;
348 }
349 nExponent = nExponent * 10 + str[cc] - '0';
350 cc++;
351 }
352 nExponent = bExpSign ? -nExponent : nExponent;
353 }
354 FX_DOUBLE dValue = (dwFractional / 4294967296.0);
355 dValue = nIntegral + (nIntegral >= 0 ? dValue : -dValue);
356 if (nExponent != 0) {
357 dValue *= FXSYS_pow(10, (FX_FLOAT)nExponent);
358 }
359 return dValue;
360 }
361 222
362 FX_DOUBLE XFA_ByteStringToDouble(const CFX_ByteStringC& szStringVal) { 223 FX_DOUBLE XFA_ByteStringToDouble(const CFX_ByteStringC& szStringVal) {
363 CFX_WideString wsValue = CFX_WideString::FromUTF8(szStringVal); 224 CFX_WideString wsValue = CFX_WideString::FromUTF8(szStringVal);
364 return XFA_WideStringToDouble(wsValue); 225 return WideStringToDouble(wsValue);
365 } 226 }
366 227
367 int32_t XFA_MapRotation(int32_t nRotation) { 228 int32_t XFA_MapRotation(int32_t nRotation) {
368 nRotation = nRotation % 360; 229 nRotation = nRotation % 360;
369 nRotation = nRotation < 0 ? nRotation + 360 : nRotation; 230 nRotation = nRotation < 0 ? nRotation + 360 : nRotation;
370 return nRotation; 231 return nRotation;
371 } 232 }
OLDNEW
« xfa/fxfa/parser/xfa_script_resolveprocessor.h ('K') | « xfa/fxfa/parser/xfa_utils.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698