X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=lib%2Fpdf%2FXMLOutputDev.cc;fp=lib%2Fpdf%2FXMLOutputDev.cc;h=d6f1d2d5c1f186b4cae85a80f1352c750b209c67;hb=753c672c453d65155923a539472414a26ea4e445;hp=0000000000000000000000000000000000000000;hpb=3e8c263456822a1f6d47ac7ac2133b2d631f2431;p=swftools.git diff --git a/lib/pdf/XMLOutputDev.cc b/lib/pdf/XMLOutputDev.cc new file mode 100644 index 0000000..d6f1d2d --- /dev/null +++ b/lib/pdf/XMLOutputDev.cc @@ -0,0 +1,126 @@ +/* XMLOutputDev.cc + + This file is part of swftools. + + Swftools is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + Swftools is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with swftools; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ + +#include "../../config.h" +#include +#include +#include "gfile.h" +#include "XMLOutputDev.h" +#include "GfxState.h" + +XMLOutputDev::XMLOutputDev(char*filename) +:TextOutputDev(mktmpname(0), false, false, false) +{ + out = fopen(filename, "wb"); + if(!out) { + perror(filename); + exit(-1); + } + fprintf(out, "\n"); + fprintf(out, "\n"); +} + +XMLOutputDev::~XMLOutputDev() +{ + fprintf(out, "\n"); + fclose(out); +} + +void XMLOutputDev::startPage(int pageNum, GfxState *state, double x1,double y1,double x2,double y2) +{ + TextOutputDev::startPage(pageNum, state, x1, y1, x2, y2); + fprintf(out, "\n", pageNum, + state->getPageWidth(), state->getPageHeight()); +} + +void XMLOutputDev::endPage() +{ + TextOutputDev::endPage(); + TextWordList* list = makeWordList(); + int len = list->getLength(); + int i; + + char textTag = 0; + GString*fontname = new GString(); + double fontsize = -99999; + double base = -9999; + for(i=0;iget(i); + GString*newfont = word->getFontName(); + double newsize = word->getFontSize(); + double newbase = word->base; + + if((newfont && newfont->cmp(fontname)) || + newsize != fontsize || + newbase != base) + { + TextFontInfo*info = word->getFontInfo(); + if(textTag) + fprintf(out, "\n"); + textTag = 1; + GBool italic = gFalse; + GBool bold = gFalse; + GBool serif = gFalse; + + if(info->isItalic()) italic = gTrue; + if(info->isBold()) bold = gTrue; + if(info->isSerif()) serif = gTrue; + char*name = (char*)""; + if(newfont) { + name = newfont->lowerCase()->getCString(); + if(strlen(name)>7 && name[6]=='+') + name += 7; + if(strstr(name, "ital")) italic = gTrue; + if(strstr(name, "slan")) italic = gTrue; + if(strstr(name, "obli")) italic = gTrue; + if(strstr(name, "bold")) bold = gTrue; + if(strstr(name, "heav")) bold = gTrue; + if(strstr(name, "medi")) bold = gTrue; + if(strstr(name, "serif")) serif = gTrue; + } + + fprintf(out, "", + name, + newbase, + (word->rot&1)?word->yMin:word->xMin, + info->isFixedWidth()?"fixed;":"", + serif?"serif;":"", + italic?"italic;":"", + bold?"bold;":"", + newsize); + fontname = newfont->copy(); + fontsize = newsize; + base = newbase; + } + char*s = word->getText()->getCString(); + while(*s) { + switch(*s) { + case '<': fprintf(out, "<");break; + case '>': fprintf(out, ">");break; + case '&': fprintf(out, "&");break; + default: fwrite(s, 1, 1, out); + } + s++; + } + if(word->spaceAfter) + fprintf(out, " "); + } + if(textTag) fprintf(out, "\n"); + fprintf(out, "\n"); +} +