summaryrefslogtreecommitdiff
path: root/Build/source/libs/xpdf/xpdf-src/xpdf/Form.cc
blob: 681401ad5dee9bdb64dcbff9e682b19e230b3b37 (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
//========================================================================
//
// Form.cc
//
// Copyright 2012 Glyph & Cog, LLC
//
//========================================================================

#include <aconf.h>

#ifdef USE_GCC_PRAGMAS
#pragma implementation
#endif

#include "gmempp.h"
#include "GlobalParams.h"
#include "Error.h"
#include "Object.h"
#include "PDFDoc.h"
#include "AcroForm.h"
#include "XFAForm.h"
#include "Form.h"

//------------------------------------------------------------------------
// Form
//------------------------------------------------------------------------

Form *Form::load(PDFDoc *docA, Catalog *catalog, Object *acroFormObj) {
  Form *form;
  Object xfaObj;

  if (acroFormObj->isDict()) {
    //~ temporary: create an XFAForm only for XFAF, not for dynamic XFA
    acroFormObj->dictLookup("XFA", &xfaObj);
    if (globalParams->getEnableXFA() &&
	!xfaObj.isNull() &&
	!catalog->getNeedsRendering()) {
      form = XFAForm::load(docA, catalog, acroFormObj, &xfaObj);
      xfaObj.free();
      return form;
    }
    xfaObj.free();
  }

  // if acroFormObj is a null object, this will still create an
  // AcroForm if there are unattached Widget-type annots
  return AcroForm::load(docA, catalog, acroFormObj);
}

Form::Form(PDFDoc *docA) {
  doc = docA;
}

Form::~Form() {
}

FormField *Form::findField(int pg, double x, double y) {
  FormField *field;
  double llx, lly, urx, ury;
  int i;

  for (i = 0; i < getNumFields(); ++i) {
    field = getField(i);
    if (field->getPageNum() == pg) {
      field->getBBox(&llx, &lly, &urx, &ury);
      if (llx <= x && x <= urx && lly <= y && y <= ury) {
	return field;
      }
    }
  }
  return NULL;
}

int Form::findFieldIdx(int pg, double x, double y) {
  FormField *field;
  double llx, lly, urx, ury;
  int i;

  for (i = 0; i < getNumFields(); ++i) {
    field = getField(i);
    if (field->getPageNum() == pg) {
      field->getBBox(&llx, &lly, &urx, &ury);
      if (llx <= x && x <= urx && lly <= y && y <= ury) {
	return i;
      }
    }
  }
  return -1;
}

//------------------------------------------------------------------------
// FormField
//------------------------------------------------------------------------

FormField::FormField() {
}

FormField::~FormField() {
}