summaryrefslogtreecommitdiff
path: root/Build/source/libs/xpdf/xpdf-src/xpdf/XFAForm.h
blob: 2f56e728a98ef9580d3406f6319327af4cacc492 (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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
//========================================================================
//
// XFAForm.h
//
// Copyright 2012 Glyph & Cog, LLC
//
//========================================================================

#ifndef XFAFORM_H
#define XFAFORM_H

#include <aconf.h>

#ifdef USE_GCC_PRAGMAS
#pragma interface
#endif

#include "Form.h"

class GHash;
class XFATableInfo;
class ZxDoc;
class ZxElement;
class ZxAttr;

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

enum XFAHorizAlign {
  xfaHAlignLeft,
  xfaHAlignCenter,
  xfaHAlignRight
};

enum XFAVertAlign {
  xfaVAlignTop,
  xfaVAlignBottom,
  xfaVAlignMiddle
};

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

class XFAForm: public Form {
public:

  static XFAForm *load(PDFDoc *docA, Catalog *catalog,
		       Object *acroFormObj, Object *xfaObj);

  virtual ~XFAForm();

  virtual const char *getType() { return "XFA"; }

  virtual void draw(int pageNum, Gfx *gfx, GBool printing);

  virtual int getNumFields();
  virtual FormField *getField(int idx);

private:

  XFAForm(PDFDoc *docA, int nPagesA, ZxDoc *xmlA,
	  Object *resourceDictA, GBool fullXFAA);
  void scanNode(ZxElement *elem,
		GString *parentName, GString *parentFullName,
		GBool inPageSet, XFATableInfo *tableInfo,
		GHash *nameCount, GHash *nameIdx,
		GHash *fullNameCount, GHash *fullNameIdx,
		GString *exclGroupName, Catalog *catalog);
  void scanNames(ZxElement *elem, GHash *nameCount);
  void scanFullNames(ZxElement *elem, GHash *fullNameCount);
  void scanField(ZxElement *elem, GString *name, GString *fullName,
		 GString *exclGroupName, GBool inPageSet,
		 XFATableInfo *tableInfo, int colSpan,
		 Catalog *catalog);
  void scanNonField(ZxElement *elem, GString *name, GString *fullName,
		    GBool inPageSet,
		    XFATableInfo *tableInfo, int colSpan,
		    GHash *nameCount, GHash *nameIdx,
		    GHash *fullNameCount, GHash *fullNameIdx,
		    Catalog *catalog);
  GString *getNodeName(ZxElement *elem);
  GString *getNodeFullName(ZxElement *elem);
  GBool nodeIsBindGlobal(ZxElement *elem);

  ZxDoc *xml;
  GList *fields;		// [XFAFormField]
  Object resourceDict;
  GBool fullXFA;		// true for "Full XFA", false for
				//   "XFA Foreground"
  int nPages;			// number of pages in PDF file
  double *pageOffsetX,		// x,y offset for each page
         *pageOffsetY;
  int pageSetNPages;		// number of pages in pageSet element
  int curPageNum;		// current page number - used by scanFields()
  double curXOffset,		// current x,y offset - used by scanFields()
         curYOffset;

  friend class XFAFormField;
};

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

class XFAFormField: public FormField {
public:

  XFAFormField(XFAForm *xfaFormA, ZxElement *xmlA,
	       GString *nameA, GString *fullNameA, GString *exclGroupNameA,
	       int pageNumA, double xOffsetA, double yOffsetA,
	       double columnWidthA, double rowHeightA);

  virtual ~XFAFormField();

  virtual int getPageNum();
  virtual const char *getType();
  virtual Unicode *getName(int *length);
  virtual Unicode *getValue(int *length);
  virtual void getBBox(double *llx, double *lly, double *urx, double *ury);
  virtual void getFont(Ref *fontID, double *fontSize);
  virtual void getColor(double *red, double *green, double *blue);

  virtual Object *getResources(Object *res);

private:

  Unicode *utf8ToUnicode(GString *s, int *length);
  void draw(int pageNumA, Gfx *gfx, GBool printing, GfxFontDict *fontDict);
  void getRectangle(double *xfaX, double *xfaY,
		    double *xfaW, double *xfaH,
		    double *pdfX, double *pdfY,
		    double *pdfW, double *pdfH,
		    int *pdfRot);
  void drawTextEdit(GfxFontDict *fontDict,
		    double w, double h, int rot,
		    GString *appearBuf);
  void drawCheckButton(GfxFontDict *fontDict,
		       double w, double h, int rot,
		       GString *appearBuf);
  void drawBarCode(GfxFontDict *fontDict,
		   double w, double h, int rot,
		   GString *appearBuf);
  static double getMeasurement(ZxAttr *attr, double defaultVal);
  static double getMeasurement(GString *s, int begin);
  GString *getFieldValue(const char *valueChildType);
  ZxElement *findFieldInDatasets(ZxElement *elem, char *partName);
  ZxElement *findFieldInFormElem(ZxElement *elem, char *partName);
  void transform(int rot, double w, double h,
		 double *wNew, double *hNew, GString *appearBuf);
  void drawText(GString *text, GBool multiLine, int combCells,
		GString *fontName, GBool bold,
		GBool italic, double fontSize,
		XFAHorizAlign hAlign, XFAVertAlign vAlign,
		double x, double y, double w, double h,
		GBool whiteBackground,
		GfxFontDict *fontDict, GString *appearBuf);
  GfxFont *findFont(GfxFontDict *fontDict, GString *fontName,
		    GBool bold, GBool italic);
  Ref findFontName(GString *name, GBool bold, GBool italic);
  void getNextLine(GString *text, int start,
		   GfxFont *font, double fontSize, double wMax,
		   int *end, double *width, int *next);
  GString *pictureFormatDateTime(GString *value, GString *picture);
  GString *pictureFormatNumber(GString *value, GString *picture);
  GString *pictureFormatText(GString *value, GString *picture);
  GBool isValidInt(GString *s, int start, int len);
  int convertInt(GString *s, int start, int len);

  XFAForm *xfaForm;
  ZxElement *xml;
  GString *name;
  GString *fullName;
  GString *exclGroupName;
  int pageNum;
  double xOffset, yOffset;
  double columnWidth;		// column width, if this field is in a
				//   table; otherwise zero
  double rowHeight;		// row height, if this field is in a
				//   table; otherwise zero

  friend class XFAForm;
  friend class XFATableInfo;
};

#endif