1 #include "SplashTypes.h"
2 #include "SplashOutputDev.h"
3 #include "SplashPath.h"
4 #include "InfoOutputDev.h"
9 InfoOutputDev::InfoOutputDev(XRef*xref)
14 id2font = new GHash(1);
15 SplashColor white = {255,255,255};
16 splash = new SplashOutputDev(splashModeRGB8,320,0,white,0,0);
17 splash->startDoc(xref);
19 InfoOutputDev::~InfoOutputDev()
22 id2font->startIter(&i);
25 while(id2font->getNext(&i, &key, (void**)&fontinfo)) {
28 id2font->killIter(&i);
33 void FontInfo::grow(int size)
35 if(size >= this->num_glyphs) {
36 this->glyphs = (GlyphInfo**)realloc(this->glyphs, sizeof(GlyphInfo*)*(size));
37 memset(&this->glyphs[this->num_glyphs], 0, sizeof(SplashPath*)*((size)-this->num_glyphs));
38 this->num_glyphs = size;
43 this->charid2glyph = 0;
51 if(this->charid2glyph) {
52 free(this->charid2glyph);
53 this->charid2glyph = 0;
56 for(t=0;t<num_glyphs;t++) {
58 delete glyphs[t]->path;glyphs[t]->path = 0;
64 GBool InfoOutputDev::upsideDown() {return gTrue;}
65 GBool InfoOutputDev::useDrawChar() {return gTrue;}
66 GBool InfoOutputDev::interpretType3Chars() {return gTrue;}
67 GBool InfoOutputDev::useTilingPatternFill() {return gTrue;}
69 void InfoOutputDev::startPage(int pageNum, GfxState *state, double crop_x1, double crop_y1, double crop_x2, double crop_y2)
72 state->transform(crop_x1,crop_y1,&x1,&y1);
73 state->transform(crop_x2,crop_y2,&x2,&y2);
74 if(x2<x1) {double x3=x1;x1=x2;x2=x3;}
75 if(y2<y1) {double y3=y1;y1=y2;y2=y3;}
80 msg("<verbose> Generating info structure for page %d", pageNum);
82 void InfoOutputDev::drawLink(Link *link, Catalog *catalog)
86 double InfoOutputDev::getMaximumFontSize(char*id)
88 FontInfo*info = (FontInfo*)id2font->lookup(id);
90 msg("<error> Unknown font id: %s", id);
93 return info->max_size;
96 char*getFontID(GfxFont*font)
98 Ref*ref = font->getID();
99 GString*gstr = font->getName();
100 char* fname = gstr==0?0:gstr->getCString();
103 if(font->getType() == fontType3) {
104 sprintf(buf, "t3font-%d-%d", ref->num, ref->gen);
106 sprintf(buf, "font-%d-%d", ref->num, ref->gen);
109 sprintf(buf, "%s-%d-%d", fname, ref->num, ref->gen);
114 void InfoOutputDev::updateFont(GfxState *state)
116 GfxFont*font = state->getFont();
119 if(font->getType() == fontType3) {
122 char*id = getFontID(font);
124 FontInfo*info = (FontInfo*)id2font->lookup(id);
126 /* font already known */
136 state->setCTM(1.0,0,0,1.0,0,0);
137 splash->updateCTM(state, 0,0,0,0,0,0);
138 state->setTextMat(1.0,0,0,-1.0,0,0);
139 state->setFont(font, 1024.0);
140 splash->doUpdateFont(state);
141 info->splash_font = splash->getCurrentFont();
143 if(!info->splash_font) {
148 GString* idStr = new GString(id);
149 id2font->add(idStr, (void*)info);
154 FontInfo* InfoOutputDev::getFont(char*id)
156 return (FontInfo*)id2font->lookup(id);
159 void InfoOutputDev::drawChar(GfxState *state, double x, double y,
160 double dx, double dy,
161 double originX, double originY,
162 CharCode code, int nBytes, Unicode *u, int uLen)
164 double m11,m21,m12,m22;
165 state->getFontTransMat(&m11, &m12, &m21, &m22);
166 m11 *= state->getHorizScaling();
167 m21 *= state->getHorizScaling();
168 double lenx = sqrt(m11*m11 + m12*m12);
169 double leny = sqrt(m21*m21 + m22*m22);
170 double len = lenx>leny?lenx:leny;
171 if(currentfont && currentfont->max_size < len) {
172 currentfont->max_size = len;
174 currentfont->grow(code+1);
175 GlyphInfo*g = currentfont->glyphs[code];
177 g = currentfont->glyphs[code] = new GlyphInfo();
178 g->path = currentfont->splash_font->getGlyphPath(code);
181 if(uLen && (u[0]>=32 && u[0]<g->unicode || !g->unicode)) {
187 GBool InfoOutputDev::beginType3Char(GfxState *state, double x, double y, double dx, double dy, CharCode code, Unicode *u, int uLen)
189 GfxFont*font = state->getFont();
192 if(font->getType() != fontType3)
195 char*id = getFontID(font);
196 currentfont = (FontInfo*)id2font->lookup(id);
198 currentfont = new FontInfo;
199 currentfont->font = font;
200 GString* idStr = new GString(id);
201 id2font->add(idStr, (void*)currentfont);
204 currentfont = currentfont;
207 currentfont->grow(code+1);
208 if(!currentfont->glyphs[code]) {
209 currentglyph = currentfont->glyphs[code] = new GlyphInfo();
210 currentglyph->unicode = uLen?u[0]:0;
211 currentglyph->path = new SplashPath();
215 currentglyph->y2=-dy;
222 void InfoOutputDev::type3D0(GfxState *state, double wx, double wy)
227 currentglyph->y2=-wy;
230 void InfoOutputDev::type3D1(GfxState *state, double wx, double wy, double llx, double lly, double urx, double ury)
232 currentglyph->x1=llx;
233 currentglyph->y1=-lly;
234 currentglyph->x2=urx;
235 currentglyph->y2=-ury;
238 void InfoOutputDev::endType3Char(GfxState *state)
240 double x1 = currentglyph->x1;
241 double y1 = currentglyph->y1;
242 double x2 = currentglyph->x2;
243 double y2 = currentglyph->y2;
244 currentglyph->path->moveTo(x1,y1);
245 currentglyph->path->lineTo(x2,y1);
246 currentglyph->path->lineTo(x2,y2);
247 currentglyph->path->lineTo(x1,y2);
248 currentglyph->path->close();
251 void InfoOutputDev::drawImageMask(GfxState *state, Object *ref, Stream *str,
252 int width, int height, GBool invert,
256 OutputDev::drawImageMask(state,ref,str,width,height,invert,inlineImg);
258 void InfoOutputDev::drawImage(GfxState *state, Object *ref, Stream *str,
259 int width, int height, GfxImageColorMap *colorMap,
260 int *maskColors, GBool inlineImg)
263 OutputDev::drawImage(state,ref,str,width,height,colorMap,maskColors,inlineImg);
265 void InfoOutputDev::drawMaskedImage(GfxState *state, Object *ref, Stream *str,
266 int width, int height,
267 GfxImageColorMap *colorMap,
269 int maskWidth, int maskHeight,
272 OutputDev::drawMaskedImage(state,ref,str,width,height,colorMap,maskStr,maskWidth,maskHeight,maskInvert);
275 void InfoOutputDev::drawSoftMaskedImage(GfxState *state, Object *ref, Stream *str,
276 int width, int height,
277 GfxImageColorMap *colorMap,
279 int maskWidth, int maskHeight,
280 GfxImageColorMap *maskColorMap)
282 OutputDev::drawSoftMaskedImage(state,ref,str,width,height,colorMap,maskStr,maskWidth,maskHeight,maskColorMap);