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();
101 // if the MediaBox is excessively larger than the CropBox,
102 // just use the CropBox
103 w = 0.25 * (cropX2 - cropX1);
104 h = 0.25 * (cropY2 - cropY1);
105 if (cropX1 - x1 > w || x2 - cropX2 > w ||
106 cropY1 - y1 > h || y2 - cropY2 > h) {
113 cropX1 = cropX2 = cropY1 = cropY2 = 0;
118 dict->lookup("Rotate", &obj1);
120 rotate = obj1.getInt();
124 while (rotate >= 360)
127 // resource dictionary
128 dict->lookup("Resources", &obj1);
131 obj1.copy(&resources);
136 PageAttrs::~PageAttrs() {
140 //------------------------------------------------------------------------
142 //------------------------------------------------------------------------
144 Page::Page(int num1, Dict *pageDict, PageAttrs *attrs1) {
153 pageDict->lookupNF("Annots", &annots);
154 if (!(annots.isRef() || annots.isArray() || annots.isNull())) {
155 error(-1, "Page annotations object (page %d) is wrong type (%s)",
156 num, annots.getTypeName());
162 pageDict->lookupNF("Contents", &contents);
163 if (!(contents.isRef() || contents.isArray() ||
164 contents.isNull())) {
165 error(-1, "Page contents object (page %d) is wrong type (%s)",
166 num, contents.getTypeName());
186 void Page::display(OutputDev *out, int dpi, int rotate) {
187 #ifndef PDF_PARSER_ONLY
192 printf("***** MediaBox = ll:%g,%g ur:%g,%g\n",
193 getX1(), getY1(), getX2(), getY2());
195 printf("***** CropBox = ll:%g,%g ur:%g,%g\n",
196 getCropX1(), getCropY1(), getCropX2(), getCropY2());
198 printf("***** Rotate = %d\n", attrs->getRotate());
200 rotate += getRotate();
205 gfx = new Gfx(out, num, attrs->getResourceDict(),
206 dpi, getX1(), getY1(), getX2(), getY2(), isCropped(),
207 getCropX1(), getCropY1(), getCropX2(), getCropY2(), rotate);
208 contents.fetch(&obj);