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"
28 XMLOutputDev::XMLOutputDev(char*filename)
29 :TextOutputDev(mktmpname(0), false, false, false)
31 out = fopen(filename, "wb");
36 fprintf(out, "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n");
37 fprintf(out, "<document>\n");
40 XMLOutputDev::~XMLOutputDev()
42 fprintf(out, "</document>\n");
46 void XMLOutputDev::startPage(int pageNum, GfxState *state)
48 TextOutputDev::startPage(pageNum, state);
49 fprintf(out, "<page nr=\"%d\" width=\"%.0f\" height=\"%.0f\">\n", pageNum,
50 state->getPageWidth(), state->getPageHeight());
53 void XMLOutputDev::endPage()
55 TextOutputDev::endPage();
56 TextWordList* list = makeWordList();
57 int len = list->getLength();
61 GString*fontname = new GString();
62 double fontsize = -99999;
68 TextWord*word = list->get(i);
69 GString*newfont = word->getFontName();
70 double newsize = word->getFontSize();
72 double newbase = word->getBaseline();
74 double newbase = word->base;
79 word->getColor(&newcolor_r, &newcolor_g, &newcolor_b);
81 if((newfont && newfont->cmp(fontname)) ||
82 newsize != fontsize ||
84 newcolor_r != color_r ||
85 newcolor_g != color_g ||
89 TextFontInfo*info = word->getFontInfo();
91 fprintf(out, "</t>\n");
93 GBool italic = gFalse;
97 if(info->isItalic()) italic = gTrue;
98 if(info->isBold()) bold = gTrue;
99 if(info->isSerif()) serif = gTrue;
100 char*name = (char*)"";
102 name = newfont->lowerCase()->getCString();
103 if(strlen(name)>7 && name[6]=='+')
105 if(strstr(name, "ital")) italic = gTrue;
106 if(strstr(name, "slan")) italic = gTrue;
107 if(strstr(name, "obli")) italic = gTrue;
108 if(strstr(name, "bold")) bold = gTrue;
109 if(strstr(name, "heav")) bold = gTrue;
110 if(strstr(name, "medi")) bold = gTrue;
111 if(strstr(name, "serif")) serif = gTrue;
114 double xMin,yMin,xMax,yMax;
115 word->getBBox(&xMin, &yMin, &xMax, &yMax);
117 int rot = word->getRotation();
119 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\">",
127 info->isFixedWidth()?"fixed;":"",
132 ((int)(newcolor_r*255))&0xff,
133 ((int)(newcolor_g*255))&0xff,
134 ((int)(newcolor_b*255))&0xff
136 fontname = newfont->copy();
139 color_r = newcolor_r;
140 color_g = newcolor_g;
141 color_b = newcolor_b;
143 char*s = word->getText()->getCString();
146 case '<': fprintf(out, "<");break;
147 case '>': fprintf(out, ">");break;
148 case '&': fprintf(out, "&");break;
149 default: fwrite(s, 1, 1, out);
153 if(word->getSpaceAfter())
156 if(textTag) fprintf(out, "</t>\n");
157 fprintf(out, "</page>\n");