1 //========================================================================
2 //
3 // XFAForm.h
4 //
5 // Copyright 2012 Glyph & Cog, LLC
6 //
7 //========================================================================
8 
9 #ifndef XFAFORM_H
10 #define XFAFORM_H
11 
12 #include <aconf.h>
13 
14 #ifdef USE_GCC_PRAGMAS
15 #pragma interface
16 #endif
17 
18 #include "Form.h"
19 
20 class ZxDoc;
21 class ZxElement;
22 class ZxAttr;
23 
24 //------------------------------------------------------------------------
25 
26 enum XFAHorizAlign {
27   xfaHAlignLeft,
28   xfaHAlignCenter,
29   xfaHAlignRight
30 };
31 
32 enum XFAVertAlign {
33   xfaVAlignTop,
34   xfaVAlignBottom,
35   xfaVAlignMiddle
36 };
37 
38 //------------------------------------------------------------------------
39 
40 class XFAForm: public Form {
41 public:
42 
43   static XFAForm *load(PDFDoc *docA, Object *acroFormObj, Object *xfaObj);
44 
45   virtual ~XFAForm();
46 
getType()47   virtual const char *getType() { return "XFA"; }
48 
49   virtual void draw(int pageNum, Gfx *gfx, GBool printing);
50 
51   virtual int getNumFields();
52   virtual FormField *getField(int idx);
53 
54 private:
55 
56   XFAForm(PDFDoc *docA, ZxDoc *xmlA, Object *resourceDictA, GBool fullXFAA);
57   void scanFields(ZxElement *elem, GString *name, GString *dataName);
58 
59   ZxDoc *xml;
60   GList *fields;		// [XFAFormField]
61   Object resourceDict;
62   GBool fullXFA;		// true for "Full XFA", false for
63 				//   "XFA Foreground"
64   int curPageNum;		// current page number - used by scanFields()
65   double curXOffset,		// current x,y offset - used by scanFields()
66          curYOffset;
67 
68   friend class XFAFormField;
69 };
70 
71 //------------------------------------------------------------------------
72 
73 class XFAFormField: public FormField {
74 public:
75 
76   XFAFormField(XFAForm *xfaFormA, ZxElement *xmlA, GString *nameA,
77 	       GString *dataNameA, int pageNumA,
78 	       double xOffsetA, double yOffsetA);
79 
80   virtual ~XFAFormField();
81 
82   virtual const char *getType();
83   virtual Unicode *getName(int *length);
84   virtual Unicode *getValue(int *length);
85 
86   virtual Object *getResources(Object *res);
87 
88 private:
89 
90   Unicode *utf8ToUnicode(GString *s, int *length);
91   void draw(int pageNumA, Gfx *gfx, GBool printing, GfxFontDict *fontDict);
92   void drawTextEdit(GfxFontDict *fontDict,
93 		    double w, double h, int rot,
94 		    GString *appearBuf);
95   void drawBarCode(GfxFontDict *fontDict,
96 		   double w, double h, int rot,
97 		   GString *appearBuf);
98   static double getMeasurement(ZxAttr *attr, double defaultVal);
99   GString *getFieldValue(const char *valueChildType);
100   ZxElement *findFieldData(ZxElement *elem, char *partName);
101   void transform(int rot, double w, double h,
102 		 double *wNew, double *hNew, GString *appearBuf);
103   void drawText(GString *text, GBool multiLine, int combCells,
104 		GString *fontName, GBool bold,
105 		GBool italic, double fontSize,
106 		XFAHorizAlign hAlign, XFAVertAlign vAlign,
107 		double x, double y, double w, double h,
108 		GBool whiteBackground,
109 		GfxFontDict *fontDict, GString *appearBuf);
110   GfxFont *findFont(GfxFontDict *fontDict, GString *fontName,
111 		    GBool bold, GBool italic);
112   void getNextLine(GString *text, int start,
113 		   GfxFont *font, double fontSize, double wMax,
114 		   int *end, double *width, int *next);
115 
116   XFAForm *xfaForm;
117   ZxElement *xml;
118   GString *name;
119   GString *dataName;
120   int pageNum;
121   double xOffset, yOffset;
122 
123   friend class XFAForm;
124 };
125 
126 #endif
127