3 #include "InfoOutputDev.h"
4 #include "SplashOutputDev.h"
6 #include <splash/SplashTypes.h>
7 #include <splash/SplashPath.h>
8 #include <splash/SplashFont.h>
9 #include <splash/SplashFontFile.h>
11 #include "SplashTypes.h"
12 #include "SplashPath.h"
13 #include "SplashFont.h"
14 #include "SplashFontFile.h"
20 InfoOutputDev::InfoOutputDev(XRef*xref)
28 id2font = new GHash(1);
29 SplashColor white = {255,255,255};
30 splash = new SplashOutputDev(splashModeRGB8,320,0,white,0,0);
31 splash->startDoc(xref);
33 InfoOutputDev::~InfoOutputDev()
36 id2font->startIter(&i);
39 while(id2font->getNext(&i, &key, (void**)&fontinfo)) {
42 id2font->killIter(&i);
44 delete id2font;id2font=0;
45 delete splash;splash=0;
47 void FontInfo::grow(int size)
49 if(size >= this->num_glyphs) {
50 this->glyphs = (GlyphInfo**)realloc(this->glyphs, sizeof(GlyphInfo*)*(size));
51 memset(&this->glyphs[this->num_glyphs], 0, sizeof(SplashPath*)*((size)-this->num_glyphs));
52 this->num_glyphs = size;
57 this->charid2glyph = 0;
61 this->splash_font = 0;
69 if(this->charid2glyph) {
70 free(this->charid2glyph);
71 this->charid2glyph = 0;
74 for(t=0;t<num_glyphs;t++) {
76 delete glyphs[t]->path;glyphs[t]->path = 0;
81 free(glyphs);glyphs=0;
83 GBool InfoOutputDev::upsideDown() {return gTrue;}
84 GBool InfoOutputDev::useDrawChar() {return gTrue;}
85 GBool InfoOutputDev::interpretType3Chars() {return gTrue;}
86 GBool InfoOutputDev::useTilingPatternFill() {return gTrue;}
88 void InfoOutputDev::startPage(int pageNum, GfxState *state, double crop_x1, double crop_y1, double crop_x2, double crop_y2)
91 state->transform(crop_x1,crop_y1,&x1,&y1);
92 state->transform(crop_x2,crop_y2,&x2,&y2);
93 if(x2<x1) {double x3=x1;x1=x2;x2=x3;}
94 if(y2<y1) {double y3=y1;y1=y2;y2=y3;}
99 msg("<verbose> Generating info structure for page %d", pageNum);
101 void InfoOutputDev::endPage()
104 void InfoOutputDev::drawLink(Link *link, Catalog *catalog)
108 double InfoOutputDev::getMaximumFontSize(char*id)
110 FontInfo*info = (FontInfo*)id2font->lookup(id);
112 msg("<error> Unknown font id: %s", id);
115 return info->max_size;
118 char*getFontID(GfxFont*font)
120 Ref*ref = font->getID();
121 GString*gstr = font->getName();
122 char* fname = gstr==0?0:gstr->getCString();
125 if(font->getType() == fontType3) {
126 sprintf(buf, "t3font-%d-%d", ref->num, ref->gen);
128 sprintf(buf, "font-%d-%d", ref->num, ref->gen);
131 sprintf(buf, "%s-%d-%d", fname, ref->num, ref->gen);
136 void InfoOutputDev::updateFont(GfxState *state)
138 GfxFont*font = state->getFont();
143 if(font->getType() == fontType3) {
147 char*id = getFontID(font);
150 currentfont->splash_font = 0;
152 currentfont = (FontInfo*)id2font->lookup(id);
154 currentfont = new FontInfo;
155 currentfont->font = font;
156 currentfont->max_size = 0;
157 GString* idStr = new GString(id);
158 id2font->add(idStr, (void*)currentfont);
162 state->setCTM(1.0,0,0,1.0,0,0);
163 splash->updateCTM(state, 0,0,0,0,0,0);
164 state->setTextMat(1.0,0,0,1.0,0,0);
165 state->setFont(font, 1024.0);
166 splash->doUpdateFont(state);
167 currentfont->splash_font = splash->getCurrentFont();
168 currentfont->ascender = currentfont->splash_font->ascender;
169 currentfont->descender = currentfont->splash_font->descender;
173 void InfoOutputDev::fill(GfxState *state)
178 void InfoOutputDev::eoFill(GfxState *state)
183 FontInfo* InfoOutputDev::getFont(char*id)
185 return (FontInfo*)id2font->lookup(id);
188 void InfoOutputDev::drawChar(GfxState *state, double x, double y,
189 double dx, double dy,
190 double originX, double originY,
191 CharCode code, int nBytes, Unicode *u, int uLen)
193 double m11,m21,m12,m22;
194 state->getFontTransMat(&m11, &m12, &m21, &m22);
195 m11 *= state->getHorizScaling();
196 m21 *= state->getHorizScaling();
197 double lenx = sqrt(m11*m11 + m12*m12);
198 double leny = sqrt(m21*m21 + m22*m22);
199 double len = lenx>leny?lenx:leny;
200 if(!currentfont || !currentfont->splash_font) {
203 if(currentfont && currentfont->max_size < len) {
204 currentfont->max_size = len;
206 currentfont->grow(code+1);
207 GlyphInfo*g = currentfont->glyphs[code];
209 g = currentfont->glyphs[code] = new GlyphInfo();
211 currentfont->splash_font->last_advance = -1;
212 g->path = currentfont->splash_font->getGlyphPath(code);
213 g->advance = currentfont->splash_font->last_advance;
216 if(uLen && (u[0]>=32 && u[0]<g->unicode || !g->unicode)) {
219 if(currentfont->lastchar>=0 && currentfont->lasty == y) {
220 double xshift = x - currentfont->lastx;
221 if(xshift>=0 && xshift > g->advance_max) {
222 g->advance_max = xshift;
226 currentfont->lastx = x;
227 currentfont->lasty = y;
228 currentfont->lastchar = code;
231 GBool InfoOutputDev::beginType3Char(GfxState *state, double x, double y, double dx, double dy, CharCode code, Unicode *u, int uLen)
233 GfxFont*font = state->getFont();
236 if(font->getType() != fontType3)
239 char*id = getFontID(font);
240 currentfont = (FontInfo*)id2font->lookup(id);
242 currentfont = new FontInfo;
243 currentfont->font = font;
244 GString* idStr = new GString(id);
245 id2font->add(idStr, (void*)currentfont);
248 currentfont = currentfont;
251 currentfont->grow(code+1);
252 if(!currentfont->glyphs[code]) {
253 currentglyph = currentfont->glyphs[code] = new GlyphInfo();
254 currentglyph->unicode = uLen?u[0]:0;
255 currentglyph->path = new SplashPath();
266 void InfoOutputDev::type3D0(GfxState *state, double wx, double wy)
274 void InfoOutputDev::type3D1(GfxState *state, double wx, double wy, double llx, double lly, double urx, double ury)
276 currentglyph->x1=llx;
277 currentglyph->y1=lly;
278 currentglyph->x2=urx;
279 currentglyph->y2=ury;
282 void InfoOutputDev::endType3Char(GfxState *state)
284 double x1 = currentglyph->x1;
285 double y1 = currentglyph->y1;
286 double x2 = currentglyph->x2;
287 double y2 = currentglyph->y2;
288 currentglyph->path->moveTo(x1,y1);
289 currentglyph->path->lineTo(x2,y1);
290 currentglyph->path->lineTo(x2,y2);
291 currentglyph->path->lineTo(x1,y2);
292 currentglyph->path->close();
295 void InfoOutputDev::drawImageMask(GfxState *state, Object *ref, Stream *str,
296 int width, int height, GBool invert,
300 OutputDev::drawImageMask(state,ref,str,width,height,invert,inlineImg);
302 void InfoOutputDev::drawImage(GfxState *state, Object *ref, Stream *str,
303 int width, int height, GfxImageColorMap *colorMap,
304 int *maskColors, GBool inlineImg)
307 OutputDev::drawImage(state,ref,str,width,height,colorMap,maskColors,inlineImg);
309 void InfoOutputDev::drawMaskedImage(GfxState *state, Object *ref, Stream *str,
310 int width, int height,
311 GfxImageColorMap *colorMap,
313 int maskWidth, int maskHeight,
316 OutputDev::drawMaskedImage(state,ref,str,width,height,colorMap,maskStr,maskWidth,maskHeight,maskInvert);
319 void InfoOutputDev::drawSoftMaskedImage(GfxState *state, Object *ref, Stream *str,
320 int width, int height,
321 GfxImageColorMap *colorMap,
323 int maskWidth, int maskHeight,
324 GfxImageColorMap *maskColorMap)
326 OutputDev::drawSoftMaskedImage(state,ref,str,width,height,colorMap,maskStr,maskWidth,maskHeight,maskColorMap);