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"
22 #include "XMLOutputDev.h"
24 #include "popplercompat.h"
29 XMLOutputDev::XMLOutputDev(char*filename)
30 :TextOutputDev(mktmpname(0), false, false, false)
32 out = fopen(filename, "wb");
37 fprintf(out, "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n");
38 fprintf(out, "<document>\n");
41 XMLOutputDev::~XMLOutputDev()
43 fprintf(out, "</document>\n");
47 void XMLOutputDev::startPage(int pageNum, GfxState *state)
49 TextOutputDev::startPage(pageNum, state);
50 fprintf(out, "<page nr=\"%d\" width=\"%.0f\" height=\"%.0f\">\n", pageNum,
51 state->getPageWidth(), state->getPageHeight());
54 void XMLOutputDev::endPage()
56 TextOutputDev::endPage();
57 TextWordList* list = makeWordList();
58 int len = list->getLength();
62 GString*fontname = new GString();
63 double fontsize = -99999;
69 TextWord*word = list->get(i);
70 GString*newfont = word->getFontName();
71 double newsize = word->getFontSize();
73 double newbase = word->getBaseline();
75 double newbase = word->base;
80 word->getColor(&newcolor_r, &newcolor_g, &newcolor_b);
82 if((newfont && newfont->cmp(fontname)) ||
83 newsize != fontsize ||
85 newcolor_r != color_r ||
86 newcolor_g != color_g ||
90 TextFontInfo*info = word->getFontInfo();
92 fprintf(out, "</t>\n");
94 GBool italic = gFalse;
98 if(info->isItalic()) italic = gTrue;
99 if(info->isBold()) bold = gTrue;
100 if(info->isSerif()) serif = gTrue;
101 char*name = (char*)"";
103 name = newfont->lowerCase()->getCString();
104 if(strlen(name)>7 && name[6]=='+')
106 if(strstr(name, "ital")) italic = gTrue;
107 if(strstr(name, "slan")) italic = gTrue;
108 if(strstr(name, "obli")) italic = gTrue;
109 if(strstr(name, "bold")) bold = gTrue;
110 if(strstr(name, "heav")) bold = gTrue;
111 if(strstr(name, "medi")) bold = gTrue;
112 if(strstr(name, "serif")) serif = gTrue;
115 double xMin,yMin,xMax,yMax;
116 word->getBBox(&xMin, &yMin, &xMax, &yMax);
118 int rot = word->getRotation();
120 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\">",
128 info->isFixedWidth()?"fixed;":"",
133 ((int)(newcolor_r*255))&0xff,
134 ((int)(newcolor_g*255))&0xff,
135 ((int)(newcolor_b*255))&0xff
137 fontname = newfont->copy();
140 color_r = newcolor_r;
141 color_g = newcolor_g;
142 color_b = newcolor_b;
144 char*s = word->getText()->getCString();
147 case '<': fprintf(out, "<");break;
148 case '>': fprintf(out, ">");break;
149 case '&': fprintf(out, "&");break;
150 default: fwrite(s, 1, 1, out);
154 if(word->getSpaceAfter())
157 if(textTag) fprintf(out, "</t>\n");
158 fprintf(out, "</page>\n");