1 //========================================================================
5 // Copyright 1996 Derek B. Noonburg
7 //========================================================================
10 #pragma implementation
23 //------------------------------------------------------------------------
25 static GString *getFileSpecName(Object *fileSpecObj);
27 //------------------------------------------------------------------------
29 //------------------------------------------------------------------------
31 LinkDest::LinkDest(Array *a, GBool pageIsRef1) {
35 pageIsRef = pageIsRef1;
36 left = bottom = right = top = zoom = 0;
41 if (!a->getNF(0, &obj1)->isRef()) {
42 error(-1, "Bad annotation destination");
45 pageRef.num = obj1.getRefNum();
46 pageRef.gen = obj1.getRefGen();
49 if (!a->get(0, &obj1)->isInt()) {
50 error(-1, "Bad annotation destination");
53 pageNum = obj1.getInt() + 1;
57 // get destination type
61 if (obj1.isName("XYZ")) {
66 } else if (obj2.isNum()) {
70 error(-1, "Bad annotation destination position");
77 } else if (obj2.isNum()) {
81 error(-1, "Bad annotation destination position");
88 } else if (obj2.isNum()) {
92 error(-1, "Bad annotation destination position");
98 } else if (obj1.isName("Fit")) {
102 } else if (obj1.isName("FitH")) {
104 if (!a->get(2, &obj2)->isNum()) {
105 error(-1, "Bad annotation destination position");
112 } else if (obj1.isName("FitV")) {
114 if (!a->get(2, &obj2)->isNum()) {
115 error(-1, "Bad annotation destination position");
118 left = obj2.getNum();
122 } else if (obj1.isName("FitR")) {
124 if (!a->get(2, &obj2)->isNum()) {
125 error(-1, "Bad annotation destination position");
128 left = obj2.getNum();
130 if (!a->get(3, &obj2)->isNum()) {
131 error(-1, "Bad annotation destination position");
134 bottom = obj2.getNum();
136 if (!a->get(4, &obj2)->isNum()) {
137 error(-1, "Bad annotation destination position");
140 right = obj2.getNum();
142 if (!a->get(5, &obj2)->isNum()) {
143 error(-1, "Bad annotation destination position");
150 } else if (obj1.isName("FitB")) {
154 } else if (obj1.isName("FitBH")) {
156 if (!a->get(2, &obj2)->isNum()) {
157 error(-1, "Bad annotation destination position");
164 } else if (obj1.isName("FitBV")) {
166 if (!a->get(2, &obj2)->isNum()) {
167 error(-1, "Bad annotation destination position");
170 left = obj2.getNum();
175 error(-1, "Unknown annotation destination type");
189 LinkDest::LinkDest(LinkDest *dest) {
191 pageIsRef = dest->pageIsRef;
193 pageRef = dest->pageRef;
195 pageNum = dest->pageNum;
197 bottom = dest->bottom;
201 changeLeft = dest->changeLeft;
202 changeTop = dest->changeTop;
203 changeZoom = dest->changeZoom;
207 //------------------------------------------------------------------------
209 //------------------------------------------------------------------------
211 LinkGoTo::LinkGoTo(Object *destObj) {
216 if (destObj->isName()) {
217 namedDest = new GString(destObj->getName());
218 } else if (destObj->isString()) {
219 namedDest = destObj->getString()->copy();
221 // destination dictionary
222 } else if (destObj->isArray()) {
223 dest = new LinkDest(destObj->getArray(), gTrue);
231 error(-1, "Illegal annotation destination");
235 LinkGoTo::~LinkGoTo() {
242 //------------------------------------------------------------------------
244 //------------------------------------------------------------------------
246 LinkGoToR::LinkGoToR(Object *fileSpecObj, Object *destObj) {
251 fileName = getFileSpecName(fileSpecObj);
254 if (destObj->isName()) {
255 namedDest = new GString(destObj->getName());
256 } else if (destObj->isString()) {
257 namedDest = destObj->getString()->copy();
259 // destination dictionary
260 } else if (destObj->isArray()) {
261 dest = new LinkDest(destObj->getArray(), gFalse);
269 error(-1, "Illegal annotation destination");
273 LinkGoToR::~LinkGoToR() {
283 //------------------------------------------------------------------------
285 //------------------------------------------------------------------------
287 LinkLaunch::LinkLaunch(Object *actionObj) {
293 if (actionObj->isDict()) {
294 if (!actionObj->dictLookup("F", &obj1)->isNull()) {
295 fileName = getFileSpecName(&obj1);
298 //~ This hasn't been defined by Adobe yet, so assume it looks
299 //~ just like the Win dictionary until they say otherwise.
300 if (actionObj->dictLookup("Unix", &obj1)->isDict()) {
301 obj1.dictLookup("F", &obj2);
302 fileName = getFileSpecName(&obj2);
304 if (obj1.dictLookup("P", &obj2)->isString())
305 params = obj2.getString()->copy();
308 error(-1, "Bad launch-type link action");
315 LinkLaunch::~LinkLaunch() {
322 //------------------------------------------------------------------------
324 //------------------------------------------------------------------------
326 LinkURI::LinkURI(Object *uriObj) {
328 if (uriObj->isString())
329 uri = uriObj->getString()->copy();
331 error(-1, "Illegal URI-type link");
334 LinkURI::~LinkURI() {
339 //------------------------------------------------------------------------
341 //------------------------------------------------------------------------
343 LinkUnknown::LinkUnknown(char *action1) {
344 action = new GString(action1);
347 LinkUnknown::~LinkUnknown() {
351 //------------------------------------------------------------------------
353 //------------------------------------------------------------------------
355 Link::Link(Dict *dict) {
356 Object obj1, obj2, obj3, obj4;
363 if (!dict->lookup("Rect", &obj1)->isArray()) {
364 error(-1, "Annotation rectangle is wrong type");
367 if (!obj1.arrayGet(0, &obj2)->isNum()) {
368 error(-1, "Bad annotation rectangle");
373 if (!obj1.arrayGet(1, &obj2)->isNum()) {
374 error(-1, "Bad annotation rectangle");
379 if (!obj1.arrayGet(2, &obj2)->isNum()) {
380 error(-1, "Bad annotation rectangle");
385 if (!obj1.arrayGet(3, &obj2)->isNum()) {
386 error(-1, "Bad annotation rectangle");
405 if (!dict->lookup("Border", &obj1)->isNull()) {
406 if (obj1.isArray() && obj1.arrayGet(2, &obj2)->isNum())
407 borderW = obj2.getNum();
409 error(-1, "Bad annotation border");
414 // look for destination
415 if (!dict->lookup("Dest", &obj1)->isNull()) {
416 action = new LinkGoTo(&obj1);
421 if (dict->lookup("A", &obj1)->isDict()) {
422 obj1.dictLookup("S", &obj2);
425 if (obj2.isName("GoTo")) {
426 obj1.dictLookup("D", &obj3);
427 action = new LinkGoTo(&obj3);
431 } else if (obj2.isName("GoToR")) {
432 obj1.dictLookup("F", &obj3);
433 obj1.dictLookup("D", &obj4);
434 action = new LinkGoToR(&obj3, &obj4);
439 } else if (obj2.isName("Launch")) {
440 action = new LinkLaunch(&obj1);
443 } else if (obj2.isName("URI")) {
444 obj1.dictLookup("URI", &obj3);
445 action = new LinkURI(&obj3);
449 } else if (obj2.isName()) {
450 action = new LinkUnknown(obj2.getName());
452 // action is missing or wrong type
454 error(-1, "Bad annotation action");
461 error(-1, "Missing annotation destination/action");
467 // check for bad action
468 if (action && action->isOk())
484 //------------------------------------------------------------------------
486 //------------------------------------------------------------------------
488 Links::Links(Object *annots) {
498 if (annots->isArray()) {
499 for (i = 0; i < annots->arrayGetLength(); ++i) {
500 if (annots->arrayGet(i, &obj1)->isDict()) {
501 if (obj1.dictLookup("Subtype", &obj2)->isName("Link")) {
502 link = new Link(obj1.getDict());
504 if (numLinks >= size) {
506 links = (Link **)grealloc(links, size * sizeof(Link *));
508 links[numLinks++] = link;
523 for (i = 0; i < numLinks; ++i)
528 LinkAction *Links::find(double x, double y) {
531 for (i = 0; i < numLinks; ++i) {
532 if (links[i]->inRect(x, y)) {
533 if (links[i]->getAction())
534 return links[i]->getAction();
541 GBool Links::onLink(double x, double y) {
544 for (i = 0; i < numLinks; ++i) {
545 if (links[i]->inRect(x, y))
551 //------------------------------------------------------------------------
553 // Extract a file name from a file specification (string or dictionary).
554 static GString *getFileSpecName(Object *fileSpecObj) {
561 if (fileSpecObj->isString()) {
562 name = fileSpecObj->getString()->copy();
565 } else if (fileSpecObj->isDict()) {
566 if (!fileSpecObj->dictLookup("Unix", &obj1)->isString()) {
568 fileSpecObj->dictLookup("F", &obj1);
571 name = obj1.getString()->copy();
573 error(-1, "Illegal file spec in link");
577 error(-1, "Illegal file spec in link");