author | sandman <sandman> | 2002-04-13 00:47:20 (UTC) |
---|---|---|
committer | sandman <sandman> | 2002-04-13 00:47:20 (UTC) |
commit | 98a1e3f36567639344f12932b629e526a8783aa8 (patch) (unidiff) | |
tree | 0433d296857faceeafc54f7deabddb621f45a933 /noncore/unsupported/qpdf/xpdf/FormWidget.cc | |
parent | 7e31b1fba119f69929d6744d7295555ff1727f4f (diff) | |
download | opie-98a1e3f36567639344f12932b629e526a8783aa8.zip opie-98a1e3f36567639344f12932b629e526a8783aa8.tar.gz opie-98a1e3f36567639344f12932b629e526a8783aa8.tar.bz2 |
CVS import of QPdf
Diffstat (limited to 'noncore/unsupported/qpdf/xpdf/FormWidget.cc') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/unsupported/qpdf/xpdf/FormWidget.cc | 139 |
1 files changed, 139 insertions, 0 deletions
diff --git a/noncore/unsupported/qpdf/xpdf/FormWidget.cc b/noncore/unsupported/qpdf/xpdf/FormWidget.cc new file mode 100644 index 0000000..05c67a4 --- a/dev/null +++ b/noncore/unsupported/qpdf/xpdf/FormWidget.cc | |||
@@ -0,0 +1,139 @@ | |||
1 | //======================================================================== | ||
2 | // | ||
3 | // FormWidget.cc | ||
4 | // | ||
5 | // Copyright 2000 Derek B. Noonburg | ||
6 | // | ||
7 | //======================================================================== | ||
8 | |||
9 | #ifdef __GNUC__ | ||
10 | #pragma implementation | ||
11 | #endif | ||
12 | |||
13 | #include <aconf.h> | ||
14 | #include "gmem.h" | ||
15 | #include "Object.h" | ||
16 | #include "Gfx.h" | ||
17 | #include "FormWidget.h" | ||
18 | |||
19 | //------------------------------------------------------------------------ | ||
20 | // FormWidget | ||
21 | //------------------------------------------------------------------------ | ||
22 | |||
23 | FormWidget::FormWidget(XRef *xrefA, Dict *dict) { | ||
24 | Object apObj, asObj, obj1, obj2; | ||
25 | fouble t; | ||
26 | |||
27 | ok = gFalse; | ||
28 | xref = xrefA; | ||
29 | |||
30 | if (dict->lookup("AP", &apObj)->isDict()) { | ||
31 | if (dict->lookup("AS", &asObj)->isName()) { | ||
32 | if (apObj.dictLookup("N", &obj1)->isDict()) { | ||
33 | if (obj1.dictLookupNF(asObj.getName(), &obj2)->isRef()) { | ||
34 | obj2.copy(&appearance); | ||
35 | ok = gTrue; | ||
36 | } | ||
37 | obj2.free(); | ||
38 | } | ||
39 | obj1.free(); | ||
40 | } else { | ||
41 | if (apObj.dictLookupNF("N", &obj1)->isRef()) { | ||
42 | obj1.copy(&appearance); | ||
43 | ok = gTrue; | ||
44 | } | ||
45 | obj1.free(); | ||
46 | } | ||
47 | asObj.free(); | ||
48 | } | ||
49 | apObj.free(); | ||
50 | |||
51 | if (dict->lookup("Rect", &obj1)->isArray() && | ||
52 | obj1.arrayGetLength() == 4) { | ||
53 | //~ should check object types here | ||
54 | obj1.arrayGet(0, &obj2); | ||
55 | xMin = obj2.getNum(); | ||
56 | obj2.free(); | ||
57 | obj1.arrayGet(1, &obj2); | ||
58 | yMin = obj2.getNum(); | ||
59 | obj2.free(); | ||
60 | obj1.arrayGet(2, &obj2); | ||
61 | xMax = obj2.getNum(); | ||
62 | obj2.free(); | ||
63 | obj1.arrayGet(3, &obj2); | ||
64 | yMax = obj2.getNum(); | ||
65 | obj2.free(); | ||
66 | if (xMin > xMax) { | ||
67 | t = xMin; xMin = xMax; xMax = t; | ||
68 | } | ||
69 | if (yMin > yMax) { | ||
70 | t = yMin; yMin = yMax; yMax = t; | ||
71 | } | ||
72 | } else { | ||
73 | //~ this should return an error | ||
74 | xMin = yMin = 0; | ||
75 | xMax = yMax = 1; | ||
76 | } | ||
77 | obj1.free(); | ||
78 | } | ||
79 | |||
80 | FormWidget::~FormWidget() { | ||
81 | appearance.free(); | ||
82 | } | ||
83 | |||
84 | void FormWidget::draw(Gfx *gfx) { | ||
85 | Object obj; | ||
86 | |||
87 | if (appearance.fetch(xref, &obj)->isStream()) { | ||
88 | gfx->doWidgetForm(&obj, xMin, yMin, xMax, yMax); | ||
89 | } | ||
90 | obj.free(); | ||
91 | } | ||
92 | |||
93 | //------------------------------------------------------------------------ | ||
94 | // FormWidgets | ||
95 | //------------------------------------------------------------------------ | ||
96 | |||
97 | FormWidgets::FormWidgets(XRef *xref, Object *annots) { | ||
98 | FormWidget *widget; | ||
99 | Object obj1, obj2; | ||
100 | int size; | ||
101 | int i; | ||
102 | |||
103 | widgets = NULL; | ||
104 | size = 0; | ||
105 | nWidgets = 0; | ||
106 | |||
107 | if (annots->isArray()) { | ||
108 | for (i = 0; i < annots->arrayGetLength(); ++i) { | ||
109 | if (annots->arrayGet(i, &obj1)->isDict()) { | ||
110 | obj1.dictLookup("Subtype", &obj2); | ||
111 | if (obj2.isName("Widget") || | ||
112 | obj2.isName("Stamp")) { | ||
113 | widget = new FormWidget(xref, obj1.getDict()); | ||
114 | if (widget->isOk()) { | ||
115 | if (nWidgets >= size) { | ||
116 | size += 16; | ||
117 | widgets = (FormWidget **)grealloc(widgets, | ||
118 | size * sizeof(FormWidget *)); | ||
119 | } | ||
120 | widgets[nWidgets++] = widget; | ||
121 | } else { | ||
122 | delete widget; | ||
123 | } | ||
124 | } | ||
125 | obj2.free(); | ||
126 | } | ||
127 | obj1.free(); | ||
128 | } | ||
129 | } | ||
130 | } | ||
131 | |||
132 | FormWidgets::~FormWidgets() { | ||
133 | int i; | ||
134 | |||
135 | for (i = 0; i < nWidgets; ++i) { | ||
136 | delete widgets[i]; | ||
137 | } | ||
138 | gfree(widgets); | ||
139 | } | ||