void toc_item_private::load_children(const std::vector<OutlineItem*> *items) { const int num_items = items->size(); children.resize(num_items); for (int i = 0; i < num_items; ++i) { OutlineItem *item = (*items)[i]; toc_item *new_item = new toc_item(); new_item->d->load(item); children[i] = new_item; item->open(); const std::vector<OutlineItem*> *item_children = item->getKids(); if (item_children) { new_item->d->load_children(item_children); } } }
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(); } }
static void epdf_index_fill (Ecore_List *items, GooList *gitems) { if (!items || !gitems) return; for (int i = 0; i < gitems->getLength (); i++) { Epdf_Index_Item *item; OutlineItem *oitem = (OutlineItem *)gitems->get (i); Unicode *utitle = oitem->getTitle (); item = epdf_index_item_new (); item->title = unicode_to_char (utitle, oitem->getTitleLength ()); item->action = oitem->getAction (); oitem->open (); if (oitem->hasKids () && oitem->getKids ()) { item->children = ecore_list_new (); epdf_index_fill (item->children, oitem->getKids ()); } ecore_list_append (items, item); } }
int main(int argc, char** argv) { argc_main = argc; argv_main = argv; SplashColor paperColor; GooString* filename, *password; char* spwd; FILE* f = NULL; bookinfo* bi; char buf[1024]; int i; mkdir(CACHEDIR, 0777); chmod(CACHEDIR, 0777); spwd = GetDeviceKey(); if (setgid(102) != 0) fprintf(stderr, "warning: cannot set gid\n"); if (setuid(102) != 0) fprintf(stderr, "warning: cannot set uid\n"); if (spwd) { //fprintf(stderr, "password: %s\n", spwd); password = new GooString(spwd); } else { fprintf(stderr, "warning: cannot read password\n"); password = NULL; } OpenScreen(); signal(SIGFPE, sigfpe_handler); signal(SIGSEGV, sigsegv_handler); clock_left = GetThemeInt("panel.clockleft", 0); bmk_flag = GetResource("bmk_flag", NULL); if (argc < 2) { Message(ICON_WARNING, "PDF Viewer", "@Cant_open_file", 2000); return 0; } OriginalName = FileName = argv[1]; bi = GetBookInfo(FileName); if (bi->title) book_title = strdup(bi->title); // read config file globalParams = new GlobalParams(); globalParams->setEnableFreeType("yes"); globalParams->setAntialias((char*)(ivstate.antialiasing ? "yes" : "no")); globalParams->setVectorAntialias("no"); filename = new GooString(FileName); doc = new PDFDoc(filename, NULL, NULL); if (!doc->isOk()) { int err = doc->getErrorCode(); delete doc; if (err == 4) // encrypted file { filename = new GooString(FileName); doc = new PDFDoc(filename, NULL, password); if (!doc->isOk()) { delete doc; spwd = query_password(); password = new GooString(spwd); filename = new GooString(FileName); doc = new PDFDoc(filename, NULL, password); if (!doc->isOk()) { Message(ICON_WARNING, "PDF Viewer", "@Cant_open_file", 2000); return 0; } } } else { Message(ICON_WARNING, "PDF Viewer", "@Cant_open_file", 2000); return 0; } } npages = doc->getNumPages(); paperColor[0] = 255; paperColor[1] = 255; paperColor[2] = 255; splashOut = new MySplashOutputDev(USE4 ? splashModeMono4 : splashModeMono8, 4, gFalse, paperColor); splashOut->startDoc(doc->getXRef()); Outline* outline = doc->getOutline(); if (outline && outline->getItems()) { GooList* items = outline->getItems(); if (items->getLength() == 1) { OutlineItem* first = (OutlineItem*)items->get(0); first->open(); items = first->getKids(); update_toc(items, 0); first->close(); } else if (items->getLength() > 1) { update_toc(items, 0); } } DataFile = GetAssociatedFile(FileName, 0); f = fopen(DataFile, "rb"); if (f == NULL || fread(&docstate, 1, sizeof(tdocstate), f) != sizeof(tdocstate) || docstate.magic != 0x9751) { docstate.magic = 0x9751; docstate.page = 1; docstate.offx = 0; docstate.offy = 0; docstate.scale = 100; docstate.rscale = 150; docstate.orient = 0; docstate.nbmk = 0; } if (f != NULL) fclose(f); cpage = docstate.page; subpage = docstate.subpage; offx = docstate.offx; offy = docstate.offy; if (docstate.scale == 0) { scale = get_fit_scale(); ScaleZoomType = ZoomTypeFitWidth; } else { scale = docstate.scale; } rscale = docstate.rscale; reflow_mode = (docstate.orient & 0x80) ? 1 : 0; gcfg = GetGlobalConfig(); // ko = ReadInt(gcfg, "keeporient", 0); ko = -1; if (GetGlobalOrientation() == -1 || ko == 0) { orient = GetOrientation(); } else { orient = docstate.orient & 0x7f; SetOrientation(orient); } if (argc >= 3) { if (argv[2][0] == '=') { #ifdef USESYNOPSIS long long position; TSynopsisItem::PositionToLong(argv[2] + 1, &position); cpage = position_to_page(position >> 40); #else // cpage = atoi(position_to_page(argv[2] + 1)); cpage = atoi(argv[2] + 1); #endif } else {