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;
66 if(this->charid2glyph) {
67 free(this->charid2glyph);
68 this->charid2glyph = 0;
71 for(t=0;t<num_glyphs;t++) {
73 delete glyphs[t]->path;glyphs[t]->path = 0;
78 free(glyphs);glyphs=0;
80 GBool InfoOutputDev::upsideDown() {return gTrue;}
81 GBool InfoOutputDev::useDrawChar() {return gTrue;}
82 GBool InfoOutputDev::interpretType3Chars() {return gTrue;}
83 GBool InfoOutputDev::useTilingPatternFill() {return gTrue;}
85 void InfoOutputDev::startPage(int pageNum, GfxState *state, double crop_x1, double crop_y1, double crop_x2, double crop_y2)
88 state->transform(crop_x1,crop_y1,&x1,&y1);
89 state->transform(crop_x2,crop_y2,&x2,&y2);
90 if(x2<x1) {double x3=x1;x1=x2;x2=x3;}
91 if(y2<y1) {double y3=y1;y1=y2;y2=y3;}
96 msg("<verbose> Generating info structure for page %d", pageNum);
98 void InfoOutputDev::endPage()
101 void InfoOutputDev::drawLink(Link *link, Catalog *catalog)
105 double InfoOutputDev::getMaximumFontSize(char*id)
107 FontInfo*info = (FontInfo*)id2font->lookup(id);
109 msg("<error> Unknown font id: %s", id);
112 return info->max_size;
115 char*getFontID(GfxFont*font)
117 Ref*ref = font->getID();
118 GString*gstr = font->getName();
119 char* fname = gstr==0?0:gstr->getCString();
122 if(font->getType() == fontType3) {
123 sprintf(buf, "t3font-%d-%d", ref->num, ref->gen);
125 sprintf(buf, "font-%d-%d", ref->num, ref->gen);
128 sprintf(buf, "%s-%d-%d", fname, ref->num, ref->gen);
133 void InfoOutputDev::updateFont(GfxState *state)
135 GfxFont*font = state->getFont();
140 if(font->getType() == fontType3) {
144 char*id = getFontID(font);
147 currentfont->splash_font = 0;
149 currentfont = (FontInfo*)id2font->lookup(id);
151 currentfont = new FontInfo;
152 currentfont->font = font;
153 currentfont->max_size = 0;
154 GString* idStr = new GString(id);
155 id2font->add(idStr, (void*)currentfont);
159 state->setCTM(1.0,0,0,1.0,0,0);
160 splash->updateCTM(state, 0,0,0,0,0,0);
161 state->setTextMat(1.0,0,0,1.0,0,0);
162 state->setFont(font, 1024.0);
163 splash->doUpdateFont(state);
164 currentfont->splash_font = splash->getCurrentFont();
168 void InfoOutputDev::fill(GfxState *state)
173 void InfoOutputDev::eoFill(GfxState *state)
178 FontInfo* InfoOutputDev::getFont(char*id)
180 return (FontInfo*)id2font->lookup(id);
183 void InfoOutputDev::drawChar(GfxState *state, double x, double y,
184 double dx, double dy,
185 double originX, double originY,
186 CharCode code, int nBytes, Unicode *u, int uLen)
188 double m11,m21,m12,m22;
189 state->getFontTransMat(&m11, &m12, &m21, &m22);
190 m11 *= state->getHorizScaling();
191 m21 *= state->getHorizScaling();
192 double lenx = sqrt(m11*m11 + m12*m12);
193 double leny = sqrt(m21*m21 + m22*m22);
194 double len = lenx>leny?lenx:leny;
195 if(!currentfont || !currentfont->splash_font) {
198 if(currentfont && currentfont->max_size < len) {
199 currentfont->max_size = len;
201 currentfont->grow(code+1);
202 GlyphInfo*g = currentfont->glyphs[code];
204 g = currentfont->glyphs[code] = new GlyphInfo();
205 g->path = currentfont->splash_font->getGlyphPath(code);
208 if(uLen && (u[0]>=32 && u[0]<g->unicode || !g->unicode)) {
214 GBool InfoOutputDev::beginType3Char(GfxState *state, double x, double y, double dx, double dy, CharCode code, Unicode *u, int uLen)
216 GfxFont*font = state->getFont();
219 if(font->getType() != fontType3)
222 char*id = getFontID(font);
223 currentfont = (FontInfo*)id2font->lookup(id);
225 currentfont = new FontInfo;
226 currentfont->font = font;
227 GString* idStr = new GString(id);
228 id2font->add(idStr, (void*)currentfont);
231 currentfont = currentfont;
234 currentfont->grow(code+1);
235 if(!currentfont->glyphs[code]) {
236 currentglyph = currentfont->glyphs[code] = new GlyphInfo();
237 currentglyph->unicode = uLen?u[0]:0;
238 currentglyph->path = new SplashPath();
249 void InfoOutputDev::type3D0(GfxState *state, double wx, double wy)
257 void InfoOutputDev::type3D1(GfxState *state, double wx, double wy, double llx, double lly, double urx, double ury)
259 currentglyph->x1=llx;
260 currentglyph->y1=lly;
261 currentglyph->x2=urx;
262 currentglyph->y2=ury;
265 void InfoOutputDev::endType3Char(GfxState *state)
267 double x1 = currentglyph->x1;
268 double y1 = currentglyph->y1;
269 double x2 = currentglyph->x2;
270 double y2 = currentglyph->y2;
271 currentglyph->path->moveTo(x1,y1);
272 currentglyph->path->lineTo(x2,y1);
273 currentglyph->path->lineTo(x2,y2);
274 currentglyph->path->lineTo(x1,y2);
275 currentglyph->path->close();
278 void InfoOutputDev::drawImageMask(GfxState *state, Object *ref, Stream *str,
279 int width, int height, GBool invert,
283 OutputDev::drawImageMask(state,ref,str,width,height,invert,inlineImg);
285 void InfoOutputDev::drawImage(GfxState *state, Object *ref, Stream *str,
286 int width, int height, GfxImageColorMap *colorMap,
287 int *maskColors, GBool inlineImg)
290 OutputDev::drawImage(state,ref,str,width,height,colorMap,maskColors,inlineImg);
292 void InfoOutputDev::drawMaskedImage(GfxState *state, Object *ref, Stream *str,
293 int width, int height,
294 GfxImageColorMap *colorMap,
296 int maskWidth, int maskHeight,
299 OutputDev::drawMaskedImage(state,ref,str,width,height,colorMap,maskStr,maskWidth,maskHeight,maskInvert);
302 void InfoOutputDev::drawSoftMaskedImage(GfxState *state, Object *ref, Stream *str,
303 int width, int height,
304 GfxImageColorMap *colorMap,
306 int maskWidth, int maskHeight,
307 GfxImageColorMap *maskColorMap)
309 OutputDev::drawSoftMaskedImage(state,ref,str,width,height,colorMap,maskStr,maskWidth,maskHeight,maskColorMap);