int epdf_index_item_page_get (const Epdf_Document *document, const Epdf_Index_Item *item) { bool delete_dest = false; if (!item || !item->action || !item->action->isOk ()) return -1; if (item->action->getKind () != actionGoTo) return -1; GooString *named_dest = ((LinkGoTo *)item->action)->getNamedDest (); LinkDest *dest = ((LinkGoTo *)item->action)->getDest (); if (!dest && named_dest) { dest = document->pdfdoc->findDest (named_dest); if (dest) delete_dest = true; } // we really can't find a destination if (!dest || !dest->isOk ()) return -1; if (dest->isPageRef ()) { int page = document->pdfdoc->findPage (dest->getPageRef ().num, dest->getPageRef ().gen) - 1; if (delete_dest) delete dest; return page; } int page = dest->getPageNum () - 1; if (delete_dest) delete dest; return page; }
static void update_toc(GooList* items, int level) { unsigned short ucs[256]; char label[256]; int i, j; if (! items) return; if (items->getLength() < 1) return; for (i = 0; i < items->getLength(); i++) { OutlineItem* outlineItem = (OutlineItem*)items->get(i); Unicode* title = outlineItem->getTitle(); int tlen = outlineItem->getTitleLength(); if (tlen > sizeof(ucs) - 1) tlen = sizeof(ucs) - 1; for (j = 0; j < tlen; j++) ucs[j] = (unsigned short)title[j]; ucs[j] = 0; ucs2utf(ucs, label, sizeof(label)); LinkAction* a = outlineItem->getAction(); if (a && (a->getKind() == actionGoTo)) { // page number is contained/referenced in a LinkGoTo LinkGoTo* g = static_cast< LinkGoTo* >(a); LinkDest* destination = g->getDest(); if (!destination && g->getNamedDest()) { GooString* s = g->getNamedDest(); if (named_size <= named_count + 1) { named_size += 64; named_dest = (char**) realloc(named_dest, named_size * sizeof(char*)); } named_dest[named_count] = strdup(s->getCString()); add_toc_item(level, label, -1, 100000 + named_count); named_count++; } else if (destination && destination->isOk() && destination->isPageRef()) { Ref page_ref = destination->getPageRef(); int num = doc->findPage(page_ref.num, page_ref.gen); add_toc_item(level, label, num, num); } else { add_toc_item(level, label, -1, -1); } } else { add_toc_item(level, label, -1, -1); } outlineItem->open(); GooList* children = outlineItem->getKids(); if (children) update_toc(children, level + 1); outlineItem->close(); } }
//----------------------------------------------------------------------------- Link::Link(const DRect &rect, LinkAction &action, Catalog &catalog) : _rect(rect) { switch ( action.getKind() ) { case actionGoTo: { LinkGoTo &lgoto = static_cast<LinkGoTo &>(action); LinkDest *dest = (lgoto.getDest() ? lgoto.getDest()->copy() : catalog.findDest( lgoto.getNamedDest() )); int page = 1; if (dest) { if ( dest->isPageRef() ) { Ref pageref = dest->getPageRef(); page = catalog.findPage(pageref.num, pageref.gen); } else page = dest->getPageNum(); delete dest; } _href = QString("bkm://") + pageLinkName(page); // kdDebug(30516) << "link to page " << page << endl; break; } case actionGoToR: { LinkGoToR &lgotor = static_cast<LinkGoToR &>(action); _href = "file://"; if ( lgotor.getFileName() ) _href += lgotor.getFileName()->getCString(); int page = 1; if ( lgotor.getDest() ) { LinkDest *dest = lgotor.getDest()->copy(); if ( !dest->isPageRef() ) page = dest->getPageNum(); delete dest; } kdDebug(30516) << "link to filename \"" << _href << "\" (page " << page << ")" <<endl; break; } case actionLaunch: { LinkLaunch &llaunch = static_cast<LinkLaunch &>(action); _href = "file://"; if ( llaunch.getFileName() ) _href += llaunch.getFileName()->getCString(); kdDebug(30516) << "link to launch/open \"" << _href << "\"" << endl; break; } case actionURI: { LinkURI &luri = static_cast<LinkURI &>(action); if ( luri.getURI() ) _href = luri.getURI()->getCString(); kdDebug(30516) << "link to URI \"" << _href << "\"" << endl; break; } case actionMovie: case actionNamed: case actionUnknown: kdDebug(30516) << "unsupported link=" << action.getKind() << endl; break; } }