1 //========================================================================
5 // Copyright 1996 Derek B. Noonburg
7 //========================================================================
10 #pragma implementation
18 #include "OutputDev.h"
19 #ifndef PDF_PARSER_ONLY
27 //------------------------------------------------------------------------
29 //------------------------------------------------------------------------
31 PageAttrs::PageAttrs(PageAttrs *attrs, Dict *dict) {
35 // get old/default values
41 cropX1 = attrs->cropX1;
42 cropY1 = attrs->cropY1;
43 cropX2 = attrs->cropX2;
44 cropY2 = attrs->cropY2;
45 rotate = attrs->rotate;
46 attrs->resources.copy(&resources);
48 // set default MediaBox to 8.5" x 11" -- this shouldn't be necessary
49 // but some (non-compliant) PDF files don't specify a MediaBox
54 cropX1 = cropY1 = cropX2 = cropY2 = 0;
60 dict->lookup("MediaBox", &obj1);
61 if (obj1.isArray() && obj1.arrayGetLength() == 4) {
62 obj1.arrayGet(0, &obj2);
66 obj1.arrayGet(1, &obj2);
70 obj1.arrayGet(2, &obj2);
74 obj1.arrayGet(3, &obj2);
82 dict->lookup("CropBox", &obj1);
83 if (obj1.isArray() && obj1.arrayGetLength() == 4) {
84 obj1.arrayGet(0, &obj2);
86 cropX1 = obj2.getNum();
88 obj1.arrayGet(1, &obj2);
90 cropY1 = obj2.getNum();
92 obj1.arrayGet(2, &obj2);
94 cropX2 = obj2.getNum();
96 obj1.arrayGet(3, &obj2);
98 cropY2 = obj2.getNum();
103 // if the MediaBox is excessively larger than the CropBox,
104 // just use the CropBox
105 limitToCropBox = gFalse;
106 w = 0.25 * (cropX2 - cropX1);
107 h = 0.25 * (cropY2 - cropY1);
108 if (cropX2 > cropX1 &&
109 (cropX1 - x1 > w || x2 - cropX2 > w ||
110 cropY1 - y1 > h || y2 - cropY2 > h)) {
111 limitToCropBox = gTrue;
115 dict->lookup("Rotate", &obj1);
117 rotate = obj1.getInt();
121 while (rotate >= 360)
124 // resource dictionary
125 dict->lookup("Resources", &obj1);
128 obj1.copy(&resources);
133 PageAttrs::~PageAttrs() {
137 //------------------------------------------------------------------------
139 //------------------------------------------------------------------------
141 Page::Page(int num1, Dict *pageDict, PageAttrs *attrs1) {
150 pageDict->lookupNF("Annots", &annots);
151 if (!(annots.isRef() || annots.isArray() || annots.isNull())) {
152 error(-1, "Page annotations object (page %d) is wrong type (%s)",
153 num, annots.getTypeName());
159 pageDict->lookupNF("Contents", &contents);
160 if (!(contents.isRef() || contents.isArray() ||
161 contents.isNull())) {
162 error(-1, "Page contents object (page %d) is wrong type (%s)",
163 num, contents.getTypeName());
183 void Page::display(OutputDev *out, int dpi, int rotate) {
184 #ifndef PDF_PARSER_ONLY
189 printf("***** MediaBox = ll:%g,%g ur:%g,%g\n",
190 getX1(), getY1(), getX2(), getY2());
192 printf("***** CropBox = ll:%g,%g ur:%g,%g\n",
193 getCropX1(), getCropY1(), getCropX2(), getCropY2());
195 printf("***** Rotate = %d\n", attrs->getRotate());
197 rotate += getRotate();
202 gfx = new Gfx(out, num, attrs->getResourceDict(),
203 dpi, getX1(), getY1(), getX2(), getY2(), isCropped(),
204 getCropX1(), getCropY1(), getCropX2(), getCropY2(), rotate);
205 contents.fetch(&obj);