1 //========================================================================
5 // Copyright 1996 Derek B. Noonburg
7 //========================================================================
10 #pragma implementation
19 #include "OutputDev.h"
20 #ifndef PDF_PARSER_ONLY
22 #include "FormWidget.h"
29 //------------------------------------------------------------------------
31 //------------------------------------------------------------------------
33 PageAttrs::PageAttrs(PageAttrs *attrs, Dict *dict) {
37 // get old/default values
43 cropX1 = attrs->cropX1;
44 cropY1 = attrs->cropY1;
45 cropX2 = attrs->cropX2;
46 cropY2 = attrs->cropY2;
47 rotate = attrs->rotate;
48 attrs->resources.copy(&resources);
50 // set default MediaBox to 8.5" x 11" -- this shouldn't be necessary
51 // but some (non-compliant) PDF files don't specify a MediaBox
56 cropX1 = cropY1 = cropX2 = cropY2 = 0;
62 dict->lookup("MediaBox", &obj1);
63 if (obj1.isArray() && obj1.arrayGetLength() == 4) {
64 obj1.arrayGet(0, &obj2);
68 obj1.arrayGet(1, &obj2);
72 obj1.arrayGet(2, &obj2);
76 obj1.arrayGet(3, &obj2);
84 dict->lookup("CropBox", &obj1);
85 if (obj1.isArray() && obj1.arrayGetLength() == 4) {
86 obj1.arrayGet(0, &obj2);
88 cropX1 = obj2.getNum();
90 obj1.arrayGet(1, &obj2);
92 cropY1 = obj2.getNum();
94 obj1.arrayGet(2, &obj2);
96 cropX2 = obj2.getNum();
98 obj1.arrayGet(3, &obj2);
100 cropY2 = obj2.getNum();
105 // if the MediaBox is excessively larger than the CropBox,
106 // just use the CropBox
107 limitToCropBox = gFalse;
108 w = 0.25 * (cropX2 - cropX1);
109 h = 0.25 * (cropY2 - cropY1);
110 if (cropX2 > cropX1 &&
111 ((cropX1 - x1) + (x2 - cropX2) > w ||
112 (cropY1 - y1) + (y2 - cropY2) > h)) {
113 limitToCropBox = gTrue;
117 dict->lookup("Rotate", &obj1);
119 rotate = obj1.getInt();
123 while (rotate >= 360)
126 // resource dictionary
127 dict->lookup("Resources", &obj1);
130 obj1.copy(&resources);
135 PageAttrs::~PageAttrs() {
139 //------------------------------------------------------------------------
141 //------------------------------------------------------------------------
143 Page::Page(int num1, Dict *pageDict, PageAttrs *attrs1) {
152 pageDict->lookupNF("Annots", &annots);
153 if (!(annots.isRef() || annots.isArray() || annots.isNull())) {
154 error(-1, "Page annotations object (page %d) is wrong type (%s)",
155 num, annots.getTypeName());
161 pageDict->lookupNF("Contents", &contents);
162 if (!(contents.isRef() || contents.isArray() ||
163 contents.isNull())) {
164 error(-1, "Page contents object (page %d) is wrong type (%s)",
165 num, contents.getTypeName());
185 void Page::display(OutputDev *out, double dpi, int rotate,
186 Links *links, Catalog *catalog) {
187 #ifndef PDF_PARSER_ONLY
192 FormWidgets *formWidgets;
195 printf("***** MediaBox = ll:%g,%g ur:%g,%g\n",
196 getX1(), getY1(), getX2(), getY2());
198 printf("***** CropBox = ll:%g,%g ur:%g,%g\n",
199 getCropX1(), getCropY1(), getCropX2(), getCropY2());
201 printf("***** Rotate = %d\n", attrs->getRotate());
204 rotate += getRotate();
207 } else if (rotate < 0) {
210 gfx = new Gfx(out, num, attrs->getResourceDict(),
211 dpi, getX1(), getY1(), getX2(), getY2(), isCropped(),
212 getCropX1(), getCropY1(), getCropX2(), getCropY2(), rotate);
213 contents.fetch(&obj);
221 for (i = 0; i < links->getNumLinks(); ++i) {
222 link = links->getLink(i);
223 out->drawLink(link, catalog);
228 // draw AcroForm widgets
229 //~ need to reset CTM ???
230 formWidgets = new FormWidgets(annots.fetch(&obj));
232 if (printCommands && formWidgets->getNumWidgets() > 0) {
233 printf("***** AcroForm widgets\n");
235 for (i = 0; i < formWidgets->getNumWidgets(); ++i) {
236 formWidgets->getWidget(i)->draw(gfx);
238 if (formWidgets->getNumWidgets() > 0) {