📄 htmloutputdev.cc
字号:
pages->clear(); if(!noframes) { if (fContentsFrame) { if (complexMode) fprintf(fContentsFrame,"<A href=\"%s-%d.html\"",str->getCString(),pageNum); else fprintf(fContentsFrame,"<A href=\"%ss.html#%d\"",str->getCString(),pageNum); fprintf(fContentsFrame," target=\"contents\" >Page %d</a><br>\n",pageNum); } } pages->pageWidth=static_cast<int>(state->getPageWidth()); pages->pageHeight=static_cast<int>(state->getPageHeight()); delete str;} void HtmlOutputDev::endPage() { pages->conv(); pages->coalesce(); pages->dump(page, pageNum); // I don't yet know what to do in the case when there are pages of different // sizes and we want complex output: running ghostscript many times // seems very inefficient. So for now I'll just use last page's size maxPageWidth = pages->pageWidth; maxPageHeight = pages->pageHeight; //if(!noframes&&!xml) fputs("<br>\n", fContentsFrame); if(!stout && !globalParams->getErrQuiet()) printf("Page-%d\n",(pageNum));}void HtmlOutputDev::updateFont(GfxState *state) { pages->updateFont(state);}void HtmlOutputDev::beginString(GfxState *state, GString *s) { pages->beginString(state, s);}void HtmlOutputDev::endString(GfxState *state) { pages->endString();}void HtmlOutputDev::drawChar(GfxState *state, double x, double y, double dx, double dy, double originX, double originY, CharCode code, int nBytes, Unicode *u, int uLen) { if ( !showHidden && (state->getRender() & 3) == 3) { return; } pages->addChar(state, x, y, dx, dy, originX, originY, u, uLen);}void HtmlOutputDev::drawImageMask(GfxState *state, Object *ref, Stream *str, int width, int height, GBool invert, GBool inlineImg) { int i, j; if (ignore||complexMode) { OutputDev::drawImageMask(state, ref, str, width, height, invert, inlineImg); return; } FILE *f1; int c; int x0, y0; // top left corner of image int w0, h0, w1, h1; // size of image double xt, yt, wt, ht; GBool rotate, xFlip, yFlip; GBool dither; int x, y; int ix, iy; int px1, px2, qx, dx; int py1, py2, qy, dy; Gulong pixel; int nComps, nVals, nBits; double r1, g1, b1; // get image position and size state->transform(0, 0, &xt, &yt); state->transformDelta(1, 1, &wt, &ht); if (wt > 0) { x0 = xoutRound(xt); w0 = xoutRound(wt); } else { x0 = xoutRound(xt + wt); w0 = xoutRound(-wt); } if (ht > 0) { y0 = xoutRound(yt); h0 = xoutRound(ht); } else { y0 = xoutRound(yt + ht); h0 = xoutRound(-ht); } state->transformDelta(1, 0, &xt, &yt); rotate = fabs(xt) < fabs(yt); if (rotate) { w1 = h0; h1 = w0; xFlip = ht < 0; yFlip = wt > 0; } else { w1 = w0; h1 = h0; xFlip = wt < 0; yFlip = ht > 0; } // dump JPEG file if (dumpJPEG && str->getKind() == strDCT) { GString *fName=new GString(Docname); fName->append("-"); GString *pgNum=GString::fromInt(pageNum); GString *imgnum=GString::fromInt(imgNum); // open the image file fName->append(pgNum)->append("_")->append(imgnum)->append(".jpg"); ++imgNum; if (!(f1 = fopen(fName->getCString(), "wb"))) { error(-1, "Couldn't open image file '%s'", fName->getCString()); return; } // initialize stream str = ((DCTStream *)str)->getRawStream(); str->reset(); // copy the stream while ((c = str->getChar()) != EOF) fputc(c, f1); fclose(f1); if (pgNum) delete pgNum; if (imgnum) delete imgnum; if (fName) delete fName; } else { OutputDev::drawImageMask(state, ref, str, width, height, invert, inlineImg); }}void HtmlOutputDev::drawImage(GfxState *state, Object *ref, Stream *str, int width, int height, GfxImageColorMap *colorMap, int *maskColors, GBool inlineImg) { int i, j; if (ignore||complexMode) { OutputDev::drawImage(state, ref, str, width, height, colorMap, maskColors, inlineImg); return; } FILE *f1; ImageStream *imgStr; Guchar pixBuf[4]; GfxColor color; int c; int x0, y0; // top left corner of image int w0, h0, w1, h1; // size of image double xt, yt, wt, ht; GBool rotate, xFlip, yFlip; GBool dither; int x, y; int ix, iy; int px1, px2, qx, dx; int py1, py2, qy, dy; Gulong pixel; int nComps, nVals, nBits; double r1, g1, b1; // get image position and size state->transform(0, 0, &xt, &yt); state->transformDelta(1, 1, &wt, &ht); if (wt > 0) { x0 = xoutRound(xt); w0 = xoutRound(wt); } else { x0 = xoutRound(xt + wt); w0 = xoutRound(-wt); } if (ht > 0) { y0 = xoutRound(yt); h0 = xoutRound(ht); } else { y0 = xoutRound(yt + ht); h0 = xoutRound(-ht); } state->transformDelta(1, 0, &xt, &yt); rotate = fabs(xt) < fabs(yt); if (rotate) { w1 = h0; h1 = w0; xFlip = ht < 0; yFlip = wt > 0; } else { w1 = w0; h1 = h0; xFlip = wt < 0; yFlip = ht > 0; } /*if( !globalParams->getErrQuiet() ) printf("image stream of kind %d\n", str->getKind());*/ // dump JPEG file if (dumpJPEG && str->getKind() == strDCT) { GString *fName=new GString(Docname); fName->append("-"); GString *pgNum= GString::fromInt(pageNum); GString *imgnum= GString::fromInt(imgNum); // open the image file fName->append(pgNum)->append("_")->append(imgnum)->append(".jpg"); ++imgNum; if (!(f1 = fopen(fName->getCString(), "wb"))) { error(-1, "Couldn't open image file '%s'", fName->getCString()); return; } // initialize stream str = ((DCTStream *)str)->getRawStream(); str->reset(); // copy the stream while ((c = str->getChar()) != EOF) fputc(c, f1); fclose(f1); delete fName; delete pgNum; delete imgnum; } else { OutputDev::drawImage(state, ref, str, width, height, colorMap, maskColors, inlineImg); }}void HtmlOutputDev::drawLink(Link* link,Catalog *cat){ double _x1,_y1,_x2,_y2,w; int x1,y1,x2,y2; link->getBorder(&_x1,&_y1,&_x2,&_y2,&w); cvtUserToDev(_x1,_y1,&x1,&y1); cvtUserToDev(_x2,_y2,&x2,&y2); GString* _dest=getLinkDest(link,cat); HtmlLink t((double) x1,(double) y2,(double) x2,(double) y1,_dest); pages->AddLink(t); delete _dest;}GString* HtmlOutputDev::getLinkDest(Link *link,Catalog* catalog){ char *p; switch(link->getAction()->getKind()) { case actionGoTo: { GString* file=basename(Docname); int page=1; LinkGoTo *ha=(LinkGoTo *)link->getAction(); LinkDest *dest=NULL; if (ha->getDest()==NULL) dest=catalog->findDest(ha->getNamedDest()); else dest=ha->getDest()->copy(); if (dest){ if (dest->isPageRef()){ Ref pageref=dest->getPageRef(); page=catalog->findPage(pageref.num,pageref.gen); } else { page=dest->getPageNum(); } delete dest; GString *str=GString::fromInt(page); /* complex simple frames file-4.html files.html#4 noframes file.html#4 file.html#4 */ if (noframes) { file->append(".html#"); file->append(str); } else { if( complexMode ) { file->append("-"); file->append(str); file->append(".html"); } else { file->append("s.html#"); file->append(str); } } if (printCommands) printf(" link to page %d ",page); delete str; return file; } else { return new GString(); } } case actionGoToR: { LinkGoToR *ha=(LinkGoToR *) link->getAction(); LinkDest *dest=NULL; int page=1; GString *file=new GString(); if (ha->getFileName()){ delete file; file=new GString(ha->getFileName()->getCString()); } if (ha->getDest()!=NULL) dest=ha->getDest()->copy(); if (dest&&file){ if (!(dest->isPageRef())) page=dest->getPageNum(); delete dest; if (printCommands) printf(" link to page %d ",page); if (printHtml){ p=file->getCString()+file->getLength()-4; if (!strcmp(p, ".pdf") || !strcmp(p, ".PDF")){ file->del(file->getLength()-4,4); file->append(".html"); } file->append('#'); file->append(GString::fromInt(page)); } } if (printCommands) printf("filename %s\n",file->getCString()); return file; } case actionURI: { LinkURI *ha=(LinkURI *) link->getAction(); GString* file=new GString(ha->getURI()->getCString()); // printf("uri : %s\n",file->getCString()); return file; } case actionLaunch: { LinkLaunch *ha=(LinkLaunch *) link->getAction(); GString* file=new GString(ha->getFileName()->getCString()); if (printHtml) { p=file->getCString()+file->getLength()-4; if (!strcmp(p, ".pdf") || !strcmp(p, ".PDF")){ file->del(file->getLength()-4,4); file->append(".html"); } if (printCommands) printf("filename %s",file->getCString()); return file; } } default: return new GString(); }}void HtmlOutputDev::dumpMetaVars(FILE *file){ GString *var; for(int i = 0; i < glMetaVars->getLength(); i++) { HtmlMetaVar *t = (HtmlMetaVar*)glMetaVars->get(i); var = t->toString(); fprintf(file, "%s\n", var->getCString()); delete var; }}GBool HtmlOutputDev::dumpDocOutline(Catalog* catalog){ FILE * output; GBool bClose = gFalse; if (!ok || xml) return gFalse; Object *outlines = catalog->getOutline(); if (!outlines->isDict()) return gFalse; if (!complexMode && !xml) { output = page; } else if (complexMode && !xml) { if (noframes) { output = page; fputs("<hr>\n", output); } else { GString *str = basename(Docname); str->append("-outline.html"); output = fopen(str->getCString(), "w"); if (output == NULL) return gFalse; delete str; bClose = gTrue; fputs("<HTML>\n<HEAD>\n<TITLE>Document Outline</TITLE>\n</HEAD>\n<BODY>\n", output); } } GBool done = newOutlineLevel(output, outlines, catalog); if (done && !complexMode) fputs("<hr>\n", output); if (bClose) { fputs("</BODY>\n</HTML>\n", output); fclose(output); } return done;}GBool HtmlOutputDev::newOutlineLevel(FILE *output, Object *node, Catalog* catalog, int level){ Object curr, next; GBool atLeastOne = gFalse; if (node->dictLookup("First", &curr)->isDict()) { if (level == 1) { fputs("<A name=\"outline\"></a>", output); fputs("<h1>Document Outline</h1>\n", output); } fputs("<ul>",output); do { // get title, give up if not found Object title; if (curr.dictLookup("Title", &title)->isNull()) { title.free(); break; } GString *titleStr = new GString(title.getString()); title.free(); // get corresponding link // Note: some code duplicated from HtmlOutputDev::getLinkDest(). GString *linkName = NULL;; Object dest; if (!curr.dictLookup("Dest", &dest)->isNull()) { LinkGoTo *link = new LinkGoTo(&dest); LinkDest *linkdest=NULL; if (link->getDest()==NULL) linkdest=catalog->findDest(link->getNamedDest()); else linkdest=link->getDest()->copy(); delete link; if (linkdest) { int page; if (linkdest->isPageRef()) { Ref pageref=linkdest->getPageRef(); page=catalog->findPage(pageref.num,pageref.gen); } else { page=linkdest->getPageNum(); } delete linkdest; /* complex simple frames file-4.html files.html#4 noframes file.html#4 file.html#4 */ linkName=basename(Docname); GString *str=GString::fromInt(page); if (noframes) { linkName->append(".html#"); linkName->append(str); } else { if( complexMode ) { linkName->append("-"); linkName->append(str); linkName->append(".html"); } else { linkName->append("s.html#"); linkName->append(str); } } delete str; } } dest.free(); fputs("<li>",output); if (linkName) fprintf(output,"<A href=\"%s\">", linkName->getCString()); fputs(titleStr->getCString(),output); if (linkName) { fputs("</A>",output); delete linkName; } fputs("\n",output); delete titleStr; atLeastOne = gTrue; newOutlineLevel(output, &curr, catalog, level+1); curr.dictLookup("Next", &next); curr.free(); curr = next; } while(curr.isDict()); fputs("</ul>",output); } curr.free(); return atLeastOne;}void HtmlOutputDev::updateCharSpace(GfxState *state){ pages->updateCharSpace(state);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -