summaryrefslogtreecommitdiff
path: root/Build/source/libs/xpdf/xpdf-src/xpdf/XFAScanner.h
blob: 00ee6f7fcee49a2641a466152228ac4f8b74a359 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
//========================================================================
//
// XFAScanner.h
//
// Copyright 2020 Glyph & Cog, LLC
//
//========================================================================

#ifndef XFASCANNER_H
#define XFASCANNER_H

#include <aconf.h>

#ifdef USE_GCC_PRAGMAS
#pragma interface
#endif

class GHash;
class ZxElement;

//------------------------------------------------------------------------

enum XFAFieldLayoutHAlign {
  xfaFieldLayoutHAlignLeft,
  xfaFieldLayoutHAlignCenter,
  xfaFieldLayoutHAlignRight
};

enum XFAFieldLayoutVAlign {
  xfaFieldLayoutVAlignTop,
  xfaFieldLayoutVAlignMiddle,
  xfaFieldLayoutVAlignBottom
};

class XFAFieldLayoutInfo {
public:

  XFAFieldLayoutInfo(XFAFieldLayoutHAlign hAlignA,
		     XFAFieldLayoutVAlign vAlignA);

  XFAFieldLayoutHAlign hAlign;
  XFAFieldLayoutVAlign vAlign;
};

//------------------------------------------------------------------------

enum XFAFieldPictureSubtype {
  xfaFieldPictureDateTime,
  xfaFieldPictureNumeric,
  xfaFieldPictureText
};

class XFAFieldPictureInfo {
public:

  XFAFieldPictureInfo(XFAFieldPictureSubtype subtypeA, GString *formatA);
  ~XFAFieldPictureInfo();

  XFAFieldPictureSubtype subtype;
  GString *format;		// picture format string
};

//------------------------------------------------------------------------

class XFAFieldBarcodeInfo {
public:

  XFAFieldBarcodeInfo(GString *barcodeTypeA, double wideNarrowRatioA,
		      double moduleWidthA, double moduleHeightA,
		      int dataLengthA, int errorCorrectionLevelA,
		      GString *textLocationA);
  ~XFAFieldBarcodeInfo();

  GString *barcodeType;
  double wideNarrowRatio;
  double moduleWidth;
  double moduleHeight;
  int dataLength;
  int errorCorrectionLevel;
  GString *textLocation;
};

//------------------------------------------------------------------------

class XFAField {
public:

  XFAField(GString *nameA, GString *fullNameA, GString *valueA,
	   XFAFieldLayoutInfo *layoutInfoA,
	   XFAFieldPictureInfo *pictureInfoA,
	   XFAFieldBarcodeInfo *barcodeInfoA);
  ~XFAField();

  // Get the field's value, or NULL if it doesn't have a value.  Sets
  // *[length] to the length of the Unicode string.
  GString *getValue() { return value; }

  // Return a pointer to the field's picture formatting info object,
  // or NULL if the field doesn't have picture formatting.
  XFAFieldPictureInfo *getPictureInfo() { return pictureInfo; }

  // Return a pointer to the field's layout info object, or NULL if
  // the field doesn't have layout info.
  XFAFieldLayoutInfo *getLayoutInfo() { return layoutInfo; }

  // Return a pointer to the field's barcode info object, or NULL if
  // the field isn't a barcode.
  XFAFieldBarcodeInfo *getBarcodeInfo() { return barcodeInfo; }

private:

  friend class XFAScanner;

  GString *name;		// UTF-8
  GString *fullName;		// UTF-8
  GString *value;		// UTF-8
  XFAFieldLayoutInfo *layoutInfo;
  XFAFieldPictureInfo *pictureInfo;
  XFAFieldBarcodeInfo *barcodeInfo;
};

//------------------------------------------------------------------------

class XFAScanner {
public:

  static XFAScanner *load(Object *xfaObj);

  virtual ~XFAScanner();

  // Find an XFA field matchined the specified AcroForm field name.
  // Returns NULL if there is no matching field.
  XFAField *findField(GString *acroFormFieldName);

private:

  XFAScanner();
  static GString *readXFAStreams(Object *xfaObj);
  GHash *scanFormValues(ZxElement *xmlRoot);
  void scanFormNode(ZxElement *elem, GString *fullName,
		    GHash *formValues);
  void scanNode(ZxElement *elem,
		GString *parentName, GString *parentFullName,
		GHash *nameIdx, GHash *fullNameIdx,
		GString *exclGroupName, ZxElement *xmlRoot,
		GHash *formValues);
  void scanField(ZxElement *elem, GString *name, GString *fullName,
		 GString *exclGroupName, ZxElement *xmlRoot,
		 GHash *formValues);
  GString *getFieldValue(ZxElement *elem, GString *name,
			 GString *fullName, GString *exclGroupName,
			 ZxElement *xmlRoot, GHash *formValues);
  GString *getDatasetsValue(char *partName, ZxElement *elem);
  XFAFieldLayoutInfo *getFieldLayoutInfo(ZxElement *elem);
  XFAFieldPictureInfo *getFieldPictureInfo(ZxElement *elem);
  XFAFieldBarcodeInfo *getFieldBarcodeInfo(ZxElement *elem);
  double getMeasurement(GString *s);
  GString *getNodeName(ZxElement *elem);
  GString *getNodeFullName(ZxElement *elem);
  GBool nodeIsBindGlobal(ZxElement *elem);
  GBool nodeIsBindNone(ZxElement *elem);

  GHash *fields;		// [XFAField]
};

#endif