3 This file is part of swftools.
5 Swftools is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 Swftools is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with swftools; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
19 #include "../../config.h"
23 #include "XMLOutputDev.h"
26 XMLOutputDev::XMLOutputDev(char*filename)
27 :TextOutputDev(mktmpname(0), false, false, false)
29 out = fopen(filename, "wb");
34 fprintf(out, "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n");
35 fprintf(out, "<document>\n");
38 XMLOutputDev::~XMLOutputDev()
40 fprintf(out, "</document>\n");
44 void XMLOutputDev::startPage(int pageNum, GfxState *state, double x1,double y1,double x2,double y2)
46 TextOutputDev::startPage(pageNum, state, x1, y1, x2, y2);
47 fprintf(out, "<page nr=\"%d\" width=\"%.0f\" height=\"%.0f\">\n", pageNum,
48 state->getPageWidth(), state->getPageHeight());
51 void XMLOutputDev::endPage()
53 TextOutputDev::endPage();
54 TextWordList* list = makeWordList();
55 int len = list->getLength();
59 GString*fontname = new GString();
60 double fontsize = -99999;
63 TextWord*word = list->get(i);
64 GString*newfont = word->getFontName();
65 double newsize = word->getFontSize();
66 double newbase = word->base;
68 if((newfont && newfont->cmp(fontname)) ||
69 newsize != fontsize ||
72 TextFontInfo*info = word->getFontInfo();
74 fprintf(out, "</t>\n");
76 GBool italic = gFalse;
80 if(info->isItalic()) italic = gTrue;
81 if(info->isBold()) bold = gTrue;
82 if(info->isSerif()) serif = gTrue;
83 char*name = (char*)"";
85 name = newfont->lowerCase()->getCString();
86 if(strlen(name)>7 && name[6]=='+')
88 if(strstr(name, "ital")) italic = gTrue;
89 if(strstr(name, "slan")) italic = gTrue;
90 if(strstr(name, "obli")) italic = gTrue;
91 if(strstr(name, "bold")) bold = gTrue;
92 if(strstr(name, "heav")) bold = gTrue;
93 if(strstr(name, "medi")) bold = gTrue;
94 if(strstr(name, "serif")) serif = gTrue;
97 fprintf(out, "<t font=\"%s\" y=\"%f\" x=\"%f\" style=\"%s%s%s%s\" fontsize=\"%.0fpt\">",
100 (word->rot&1)?word->yMin:word->xMin,
101 info->isFixedWidth()?"fixed;":"",
106 fontname = newfont->copy();
110 char*s = word->getText()->getCString();
113 case '<': fprintf(out, "<");break;
114 case '>': fprintf(out, ">");break;
115 case '&': fprintf(out, "&");break;
116 default: fwrite(s, 1, 1, out);
123 if(textTag) fprintf(out, "</t>\n");
124 fprintf(out, "</page>\n");