📄 htmloutputdev.cc
字号:
{ str1->htext->append(fntFix); } for (i = 0; i < str2->len; ++i) { str1->text[str1->len] = str2->text[i]; str1->xRight[str1->len] = str2->xRight[i]; ++str1->len; } if( !hlink1 || !hlink2 || !hlink1->isEqualDest(*hlink2) ) { if(hlink1 != NULL ) str1->htext->append("</a>"); if(hlink2 != NULL ) { GString *ls = hlink2->getLinkStart(); str1->htext->append(ls); delete ls; } } str1->htext->append(str2->htext); sSize = str1->htext2->getLength(); pxSize = xoutRoundLower(hfont1->getSize()/scale); strSize = (pxSize*(sSize-2)); cspace = (diff / strSize);//(strSize-pxSize)); // we check if the fonts are the same and create a new font to ajust the text// double diff = str2->xMin - str1->xMin;// printf("%s\n",str1->htext2->getCString()); // str1 now contains href for link of str2 (if it is defined) str1->link = str2->link; HtmlFont *newfnt = new HtmlFont(*hfont1); newfnt->setCharSpace(cspace); //newfnt->setLineSize(curLineSize); str1->fontpos = fonts->AddFont(*newfnt); delete newfnt; hfont1 = getFont(str1); // we have to reget hfont2 because it's location could have // changed on resize GStri;ng *iStr=GString::fromInt(i); hfont2 = getFont(str2); hfont1 = hfont2; if (str2->xMax > str1->xMax) { str1->xMax = str2->xMax; } if (str2->yMax > str1->yMax) { str1->yMax = str2->yMax; } str1->yxNext = str2->yxNext; delete str2; } else { // printf("startX = %f, endX = %f, diff = %f, fontsize = %d, pxSize = %f, stringSize = %d, cspace = %f, strSize = %f\n",str1->xMin,str1->xMax,diff,hfont1->getSize(),pxSize,sSize,cspace,strSize);// keep strings separate// printf("no\n"); // if( hfont1->isBold() ) if(str1->getLink() != NULL ) str1->htext->append("</a>"); str1->xMin = curX; str1->yMin = curY; str1 = str2; curX = str1->xMin; curY = str1->yMin; hfont1 = hfont2; if( str1->getLink() != NULL ) { GString *ls = str1->getLink()->getLinkStart(); str1->htext->insert(0, ls); delete ls; } } } str1->xMin = curX; str1->yMin = curY; if(str1->getLink() != NULL ) str1->htext->append("</a>");#if 0 //~ for debugging for (str1 = yxStrings; str1; str1 = str1->yxNext) { printf("x=%3d..%3d y=%3d..%3d size=%2d ", (int)str1->xMin, (int)str1->xMax, (int)str1->yMin, (int)str1->yMax, (int)(str1->yMax - str1->yMin)); printf("'%s'\n", str1->htext->getCString()); } printf("\n------------------------------------------------------------\n\n");#endif}void HtmlPage::dumpAsXML(FILE* f,int page){ fprintf(f, "<page number=\"%d\" position=\"absolute\"", page); fprintf(f," top=\"0\" left=\"0\" height=\"%d\" width=\"%d\">\n", pageHeight,pageWidth); for(int i=fontsPageMarker;i < fonts->size();i++) { GString *fontCSStyle = fonts->CSStyle(i); fprintf(f,"\t%s\n",fontCSStyle->getCString()); delete fontCSStyle; } GString *str, *str1; for(HtmlString *tmp=yxStrings;tmp;tmp=tmp->yxNext){ if (tmp->htext){ str=new GString(tmp->htext); fprintf(f,"<text top=\"%d\" left=\"%d\" ",xoutRound(tmp->yMin),xoutRound(tmp->xMin)); fprintf(f,"width=\"%d\" height=\"%d\" ",xoutRound(tmp->xMax-tmp->xMin),xoutRound(tmp->yMax-tmp->yMin)); fprintf(f,"font=\"%d\">", tmp->fontpos); if (tmp->fontpos!=-1){ str1=fonts->getCSStyle(tmp->fontpos, str); } fputs(str1->getCString(),f); delete str; delete str1; fputs("</text>\n",f); } } fputs("</page>\n",f);}void HtmlPage::dumpComplex(FILE *file, int page){ FILE* pageFile; GString* tmp; char* htmlEncoding; if( firstPage == -1 ) firstPage = page; if( !noframes ) { GString* pgNum=GString::fromInt(page); tmp = new GString(DocName); tmp->append('-')->append(pgNum)->append(".html"); delete pgNum; if (!(pageFile = fopen(tmp->getCString(), "w"))) { error(-1, "Couldn't open html file '%s'", tmp->getCString()); delete tmp; return; } delete tmp; fprintf(pageFile,"%s\n<HTML>\n<HEAD>\n<TITLE>Page %d</TITLE>\n\n", DOCTYPE, page); htmlEncoding = HtmlOutputDev::mapEncodingToHtml (globalParams->getTextEncodingName()); fprintf(pageFile, "<META http-equiv=\"Content-Type\" content=\"text/html; charset=%s\">\n", htmlEncoding); } else { pageFile = file; fprintf(pageFile,"<!-- Page %d -->\n", page); fprintf(pageFile,"<a name=\"%d\"></a>\n", page); } fprintf(pageFile,"<DIV style=\"position:relative;width:%d;height:%d;\">\n", pageWidth, pageHeight); tmp=basename(DocName); fputs("<STYLE type=\"text/css\">\n<!--\n",pageFile); for(int i=fontsPageMarker;i!=fonts->size();i++) { GString *fontCSStyle = fonts->CSStyle(i); fprintf(pageFile,"\t%s\n",fontCSStyle->getCString()); delete fontCSStyle; } fputs("-->\n</STYLE>\n",pageFile); if( !noframes ) { fputs("</HEAD>\n<BODY bgcolor=\"#A0A0A0\" vlink=\"blue\" link=\"blue\">\n",pageFile); } if( !ignore ) { fprintf(pageFile, "<IMG width=\"%d\" height=\"%d\" src=\"%s%03d.%s\" alt=\"background image\">\n", pageWidth, pageHeight, tmp->getCString(), (page-firstPage+1), imgExt->getCString()); } delete tmp; GString *str, *str1; for(HtmlString *tmp1=yxStrings;tmp1;tmp1=tmp1->yxNext){ if (tmp1->htext){ str=new GString(tmp1->htext); fprintf(pageFile, "<DIV style=\"position:absolute;top:%d;left:%d\">", xoutRound(tmp1->yMin), xoutRound(tmp1->xMin)); fputs("<nobr>",pageFile); if (tmp1->fontpos!=-1){ str1=fonts->getCSStyle(tmp1->fontpos, str); } //printf("%s\n", str1->getCString()); fputs(str1->getCString(),pageFile); delete str; delete str1; fputs("</nobr></DIV>\n",pageFile); } } fputs("</DIV>\n", pageFile); if( !noframes ) { fputs("</BODY>\n</HTML>\n",pageFile); fclose(pageFile); }}void HtmlPage::dump(FILE *f, int pageNum) { if (complexMode) { if (xml) dumpAsXML(f, pageNum); if (!xml) dumpComplex(f, pageNum); } else { fprintf(f,"<A name=%d></a>",pageNum); GString* fName=basename(DocName); for (int i=1;i<HtmlOutputDev::imgNum;i++) fprintf(f,"<IMG src=\"%s-%d_%d.jpg\"><br>\n",fName->getCString(),pageNum,i); HtmlOutputDev::imgNum=1; delete fName; GString* str; for(HtmlString *tmp=yxStrings;tmp;tmp=tmp->yxNext){ if (tmp->htext){ str=new GString(tmp->htext); fputs(str->getCString(),f); delete str; fputs("<br>\n",f); } } fputs("<hr>\n",f); }}void HtmlPage::clear() { HtmlString *p1, *p2; if (curStr) { delete curStr; curStr = NULL; } for (p1 = yxStrings; p1; p1 = p2) { p2 = p1->yxNext; delete p1; } yxStrings = NULL; xyStrings = NULL; yxCur1 = yxCur2 = NULL; if( !noframes ) { delete fonts; fonts=new HtmlFontAccu(); fontsPageMarker = 0; } else { fontsPageMarker = fonts->size(); } delete links; links=new HtmlLinks(); }void HtmlPage::setDocName(char *fname){ DocName=new GString(fname);}void HtmlPage::updateCharSpace(GfxState *state){ charspace = state->getCharSpace();}//------------------------------------------------------------------------// HtmlMetaVar//------------------------------------------------------------------------HtmlMetaVar::HtmlMetaVar(char *_name, char *_content){ name = new GString(_name); content = new GString(_content);}HtmlMetaVar::~HtmlMetaVar(){ delete name; delete content;} GString* HtmlMetaVar::toString() { GString *result = new GString("<META name=\""); result->append(name); result->append("\" content=\""); result->append(content); result->append("\">"); return result;}//------------------------------------------------------------------------// HtmlOutputDev//------------------------------------------------------------------------static char* HtmlEncodings[][2] = { {"Latin1", "ISO-8859-1"}, {NULL, NULL}};char* HtmlOutputDev::mapEncodingToHtml(GString* encoding){ char* enc = encoding->getCString(); for(int i = 0; HtmlEncodings[i][0] != NULL; i++) { if( strcmp(enc, HtmlEncodings[i][0]) == 0 ) { return HtmlEncodings[i][1]; } } return enc; }void HtmlOutputDev::doFrame(int firstPage){ GString* fName=new GString(Docname); char* htmlEncoding; fName->append(".html"); if (!(fContentsFrame = fopen(fName->getCString(), "w"))){ delete fName; error(-1, "Couldn't open html file '%s'", fName->getCString()); return; } delete fName; fName=basename(Docname); fputs(DOCTYPE_FRAMES, fContentsFrame); fputs("\n<HTML>",fContentsFrame); fputs("\n<HEAD>",fContentsFrame); fprintf(fContentsFrame,"\n<TITLE>%s</TITLE>",docTitle->getCString()); htmlEncoding = mapEncodingToHtml(globalParams->getTextEncodingName()); fprintf(fContentsFrame, "\n<META http-equiv=\"Content-Type\" content=\"text/html; charset=%s\">\n", htmlEncoding); dumpMetaVars(fContentsFrame); fprintf(fContentsFrame, "</HEAD>\n"); fputs("<FRAMESET cols=\"100,*\">\n",fContentsFrame); fprintf(fContentsFrame,"<FRAME name=\"links\" src=\"%s_ind.html\">\n",fName->getCString()); fputs("<FRAME name=\"contents\" src=",fContentsFrame); if (complexMode) fprintf(fContentsFrame,"\"%s-%d.html\"",fName->getCString(), firstPage); else fprintf(fContentsFrame,"\"%ss.html\"",fName->getCString()); fputs(">\n</FRAMESET>\n</HTML>\n",fContentsFrame); delete fName; fclose(fContentsFrame); }HtmlOutputDev::HtmlOutputDev(char *fileName, char *title, char *author, char *keywords, char *subject, char *date, char *extension, GBool rawOrder, int firstPage, GBool outline) { char *htmlEncoding; fContentsFrame = NULL; docTitle = new GString(title); pages = NULL; dumpJPEG=gTrue; //write = gTrue; this->rawOrder = rawOrder; this->doOutline = outline; ok = gFalse; imgNum=1; //this->firstPage = firstPage; //pageNum=firstPage; // open file needClose = gFalse; pages = new HtmlPage(rawOrder, extension); glMetaVars = new GList(); glMetaVars->append(new HtmlMetaVar("generator", "pdftohtml 0.40")); if( author ) glMetaVars->append(new HtmlMetaVar("author", author)); if( keywords ) glMetaVars->append(new HtmlMetaVar("keywords", keywords)); if( date ) glMetaVars->append(new HtmlMetaVar("date", date)); if( subject ) glMetaVars->append(new HtmlMetaVar("subject", subject)); maxPageWidth = 0; maxPageHeight = 0; pages->setDocName(fileName); Docname=new GString (fileName); // for non-xml output (complex or simple) with frames generate the left frame if(!xml && !noframes) { GString* left=new GString(fileName); left->append("_ind.html"); doFrame(firstPage); if (!(fContentsFrame = fopen(left->getCString(), "w"))) { error(-1, "Couldn't open html file '%s'", left->getCString()); delete left; return; } delete left; fputs(DOCTYPE, fContentsFrame); fputs("<HTML>\n<HEAD>\n<TITLE></TITLE>\n</HEAD>\n<BODY>\n",fContentsFrame); if (doOutline) { GString *str = basename(Docname); fprintf(fContentsFrame, "<A href=\"%s%s\" target=\"contents\">Outline</a><br>", str->getCString(), complexMode ? "-outline.html" : "s.html#outline"); delete str; } if (!complexMode) { /* not in complex mode */ GString* right=new GString(fileName); right->append("s.html"); if (!(page=fopen(right->getCString(),"w"))){ error(-1, "Couldn't open html file '%s'", right->getCString()); delete right; return; } delete right; fputs(DOCTYPE, page); fputs("<HTML>\n<HEAD>\n<TITLE></TITLE>\n</HEAD>\n<BODY>\n",page); } } if (noframes) { if (stout) page=stdout; else { GString* right=new GString(fileName); if (!xml) right->append(".html"); if (xml) right->append(".xml"); if (!(page=fopen(right->getCString(),"w"))){ delete right; error(-1, "Couldn't open html file '%s'", right->getCString()); return; } delete right; } htmlEncoding = mapEncodingToHtml(globalParams->getTextEncodingName()); if (xml) { fprintf(page, "<?xml version=\"1.0\" encoding=\"%s\"?>\n", htmlEncoding); fputs("<!DOCTYPE pdf2xml SYSTEM \"pdf2xml.dtd\">\n\n", page); fputs("<pdf2xml>\n",page); } else { fprintf(page,"%s\n<HTML>\n<HEAD>\n<TITLE>%s</TITLE>\n", DOCTYPE, docTitle->getCString()); fprintf(page, "<META http-equiv=\"Content-Type\" content=\"text/html; charset=%s\">\n", htmlEncoding); dumpMetaVars(page); fprintf(page,"</HEAD>\n"); fprintf(page,"<BODY bgcolor=\"#A0A0A0\" vlink=\"blue\" link=\"blue\">\n"); } } ok = gTrue; }HtmlOutputDev::~HtmlOutputDev() { /*if (mode&&!xml){ int h=xoutRound(pages->pageHeight/scale); int w=xoutRound(pages->pageWidth/scale); fprintf(tin,"%s=%03d\n","PAPER_WIDTH",w); fprintf(tin,"%s=%03d\n","PAPER_HEIGHT",h); fclose(tin); }*/ HtmlFont::clear(); delete Docname; delete docTitle; deleteGList(glMetaVars, HtmlMetaVar); if (fContentsFrame){ fputs("</BODY>\n</HTML>\n",fContentsFrame); fclose(fContentsFrame); } if (xml) { fputs("</pdf2xml>\n",page); fclose(page); } else if ( !complexMode || xml || noframes ) { fputs("</BODY>\n</HTML>\n",page); fclose(page); } if (pages) delete pages;}void HtmlOutputDev::startPage(int pageNum, GfxState *state) { /*if (mode&&!xml){ if (write){ write=gFalse; GString* fname=Dirname(Docname); fname->append("image.log"); if((tin=fopen(fname->getCString(),"w"))==NULL){ printf("Error : can not open %s",fname); exit(1); } delete fname; // if(state->getRotation()!=0) // fprintf(tin,"ROTATE=%d rotate %d neg %d neg translate\n",state->getRotation(),state->getX1(),-state->getY1()); // else fprintf(tin,"ROTATE=%d neg %d neg translate\n",state->getX1(),state->getY1()); } }*/ this->pageNum = pageNum; GString *str=basename(Docname);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -