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)
46 TextOutputDev::startPage(pageNum, state);
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;
66 TextWord*word = list->get(i);
67 GString*newfont = word->getFontName();
68 double newsize = word->getFontSize();
69 double newbase = word->base;
70 double newcolor_r = word->colorR;
71 double newcolor_g = word->colorG;
72 double newcolor_b = word->colorB;
74 if((newfont && newfont->cmp(fontname)) ||
75 newsize != fontsize ||
77 newcolor_r != color_r ||
78 newcolor_g != color_g ||
82 TextFontInfo*info = word->getFontInfo();
84 fprintf(out, "</t>\n");
86 GBool italic = gFalse;
90 if(info->isItalic()) italic = gTrue;
91 if(info->isBold()) bold = gTrue;
92 if(info->isSerif()) serif = gTrue;
93 char*name = (char*)"";
95 name = newfont->lowerCase()->getCString();
96 if(strlen(name)>7 && name[6]=='+')
98 if(strstr(name, "ital")) italic = gTrue;
99 if(strstr(name, "slan")) italic = gTrue;
100 if(strstr(name, "obli")) italic = gTrue;
101 if(strstr(name, "bold")) bold = gTrue;
102 if(strstr(name, "heav")) bold = gTrue;
103 if(strstr(name, "medi")) bold = gTrue;
104 if(strstr(name, "serif")) serif = gTrue;
107 fprintf(out, "<t font=\"%s\" y=\"%f\" x=\"%f\" bbox=\"%f:%f:%f:%f\" style=\"%s%s%s%s\" fontsize=\"%.0fpt\" color=\"%02x%02x%02x\">",
110 (word->rot&1)?word->yMin:word->xMin,
111 (word->rot&1)?word->yMin:word->xMin,
112 (word->rot&1)?word->xMin:word->yMin,
113 (word->rot&1)?word->yMax:word->xMax,
114 (word->rot&1)?word->xMax:word->yMax,
115 info->isFixedWidth()?"fixed;":"",
120 ((int)(newcolor_r*255))&0xff,
121 ((int)(newcolor_g*255))&0xff,
122 ((int)(newcolor_b*255))&0xff
124 fontname = newfont->copy();
127 color_r = newcolor_r;
128 color_g = newcolor_g;
129 color_b = newcolor_b;
131 char*s = word->getText()->getCString();
134 case '<': fprintf(out, "<");break;
135 case '>': fprintf(out, ">");break;
136 case '&': fprintf(out, "&");break;
137 default: fwrite(s, 1, 1, out);
144 if(textTag) fprintf(out, "</t>\n");
145 fprintf(out, "</page>\n");