Coverage Report

Created: 2026-04-04 06:06

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/xpdf-4.06/xpdf/XFAScanner.h
Line
Count
Source
1
//========================================================================
2
//
3
// XFAScanner.h
4
//
5
// Copyright 2020 Glyph & Cog, LLC
6
//
7
//========================================================================
8
9
#ifndef XFASCANNER_H
10
#define XFASCANNER_H
11
12
#include <aconf.h>
13
14
class GHash;
15
class ZxElement;
16
17
//------------------------------------------------------------------------
18
19
enum XFAFieldLayoutHAlign {
20
  xfaFieldLayoutHAlignLeft,
21
  xfaFieldLayoutHAlignCenter,
22
  xfaFieldLayoutHAlignRight
23
};
24
25
enum XFAFieldLayoutVAlign {
26
  xfaFieldLayoutVAlignTop,
27
  xfaFieldLayoutVAlignMiddle,
28
  xfaFieldLayoutVAlignBottom
29
};
30
31
class XFAFieldLayoutInfo {
32
public:
33
34
  XFAFieldLayoutInfo(XFAFieldLayoutHAlign hAlignA,
35
         XFAFieldLayoutVAlign vAlignA,
36
         double marginLeftA,
37
         double marginRightA);
38
39
  XFAFieldLayoutHAlign hAlign;
40
  XFAFieldLayoutVAlign vAlign;
41
  double marginLeft;
42
  double marginRight;
43
};
44
45
//------------------------------------------------------------------------
46
47
enum XFAFieldPictureSubtype {
48
  xfaFieldPictureDateTime,
49
  xfaFieldPictureNumeric,
50
  xfaFieldPictureText
51
};
52
53
class XFAFieldPictureInfo {
54
public:
55
56
  XFAFieldPictureInfo(XFAFieldPictureSubtype subtypeA, GString *formatA);
57
  ~XFAFieldPictureInfo();
58
59
  XFAFieldPictureSubtype subtype;
60
  GString *format;    // picture format string
61
};
62
63
//------------------------------------------------------------------------
64
65
class XFAFieldBarcodeInfo {
66
public:
67
68
  XFAFieldBarcodeInfo(GString *barcodeTypeA, double wideNarrowRatioA,
69
          double moduleWidthA, double moduleHeightA,
70
          int dataLengthA, int errorCorrectionLevelA,
71
          GString *textLocationA);
72
  ~XFAFieldBarcodeInfo();
73
74
  GString *barcodeType;
75
  double wideNarrowRatio;
76
  double moduleWidth;
77
  double moduleHeight;
78
  int dataLength;
79
  int errorCorrectionLevel;
80
  GString *textLocation;
81
};
82
83
//------------------------------------------------------------------------
84
85
class XFAField {
86
public:
87
88
  XFAField(GString *nameA, GString *fullNameA, GString *valueA,
89
     XFAFieldLayoutInfo *layoutInfoA,
90
     XFAFieldPictureInfo *pictureInfoA,
91
     XFAFieldBarcodeInfo *barcodeInfoA);
92
  ~XFAField();
93
94
  // Get the field's value, or NULL if it doesn't have a value.  Sets
95
  // *[length] to the length of the Unicode string.
96
1.21k
  GString *getValue() { return value; }
97
98
  // Return a pointer to the field's picture formatting info object,
99
  // or NULL if the field doesn't have picture formatting.
100
353
  XFAFieldPictureInfo *getPictureInfo() { return pictureInfo; }
101
102
  // Return a pointer to the field's layout info object, or NULL if
103
  // the field doesn't have layout info.
104
401
  XFAFieldLayoutInfo *getLayoutInfo() { return layoutInfo; }
105
106
  // Return a pointer to the field's barcode info object, or NULL if
107
  // the field isn't a barcode.
108
880
  XFAFieldBarcodeInfo *getBarcodeInfo() { return barcodeInfo; }
109
110
private:
111
112
  friend class XFAScanner;
113
114
  GString *name;    // UTF-8
115
  GString *fullName;    // UTF-8
116
  GString *value;   // UTF-8
117
  XFAFieldLayoutInfo *layoutInfo;
118
  XFAFieldPictureInfo *pictureInfo;
119
  XFAFieldBarcodeInfo *barcodeInfo;
120
};
121
122
//------------------------------------------------------------------------
123
124
class XFAScanner {
125
public:
126
127
  static XFAScanner *load(Object *xfaObj);
128
129
  virtual ~XFAScanner();
130
131
  // Find an XFA field matching the specified AcroForm field name.
132
  // Returns NULL if there is no matching field.
133
  XFAField *findField(GString *acroFormFieldName);
134
135
private:
136
137
  XFAScanner();
138
  static GString *readXFAStreams(Object *xfaObj);
139
  GHash *scanFormValues(ZxElement *xmlRoot);
140
  void scanFormNode(ZxElement *elem, GString *fullName,
141
        GHash *formValues);
142
  void scanNode(ZxElement *elem,
143
    GString *parentName, GString *parentFullName,
144
    GHash *nameIdx, GHash *fullNameIdx,
145
    GString *exclGroupName, ZxElement *xmlRoot,
146
    GHash *formValues);
147
  void scanField(ZxElement *elem, GString *name, GString *fullName,
148
     GString *exclGroupName, ZxElement *xmlRoot,
149
     GHash *formValues);
150
  GString *getFieldValue(ZxElement *elem, GString *name,
151
       GString *fullName, GString *exclGroupName,
152
       ZxElement *xmlRoot, GHash *formValues);
153
  GString *getDatasetsValue(char *partName, ZxElement *elem);
154
  XFAFieldLayoutInfo *getFieldLayoutInfo(ZxElement *elem);
155
  XFAFieldPictureInfo *getFieldPictureInfo(ZxElement *elem);
156
  XFAFieldBarcodeInfo *getFieldBarcodeInfo(ZxElement *elem);
157
  double getMeasurement(GString *s);
158
  GString *getNodeName(ZxElement *elem);
159
  GString *getNodeFullName(ZxElement *elem);
160
  GBool nodeIsBindGlobal(ZxElement *elem);
161
  GBool nodeIsBindNone(ZxElement *elem);
162
163
  GHash *fields;    // [XFAField]
164
};
165
166
#endif