2 #include "SplashTypes.h"
3 #include "SplashOutputDev.h"
4 #include "SplashPath.h"
5 #include "SplashFontFile.h"
6 #include "InfoOutputDev.h"
11 InfoOutputDev::InfoOutputDev(XRef*xref)
19 id2font = new GHash(1);
20 SplashColor white = {255,255,255};
21 splash = new SplashOutputDev(splashModeRGB8,320,0,white,0,0);
22 splash->startDoc(xref);
24 InfoOutputDev::~InfoOutputDev()
27 id2font->startIter(&i);
30 while(id2font->getNext(&i, &key, (void**)&fontinfo)) {
33 id2font->killIter(&i);
35 delete id2font;id2font=0;
36 delete splash;splash=0;
38 void FontInfo::grow(int size)
40 if(size >= this->num_glyphs) {
41 this->glyphs = (GlyphInfo**)realloc(this->glyphs, sizeof(GlyphInfo*)*(size));
42 memset(&this->glyphs[this->num_glyphs], 0, sizeof(SplashPath*)*((size)-this->num_glyphs));
43 this->num_glyphs = size;
48 this->charid2glyph = 0;
52 this->splash_font = 0;
57 if(this->charid2glyph) {
58 free(this->charid2glyph);
59 this->charid2glyph = 0;
62 for(t=0;t<num_glyphs;t++) {
64 delete glyphs[t]->path;glyphs[t]->path = 0;
69 free(glyphs);glyphs=0;
71 GBool InfoOutputDev::upsideDown() {return gTrue;}
72 GBool InfoOutputDev::useDrawChar() {return gTrue;}
73 GBool InfoOutputDev::interpretType3Chars() {return gTrue;}
74 GBool InfoOutputDev::useTilingPatternFill() {return gTrue;}
76 void InfoOutputDev::startPage(int pageNum, GfxState *state, double crop_x1, double crop_y1, double crop_x2, double crop_y2)
79 state->transform(crop_x1,crop_y1,&x1,&y1);
80 state->transform(crop_x2,crop_y2,&x2,&y2);
81 if(x2<x1) {double x3=x1;x1=x2;x2=x3;}
82 if(y2<y1) {double y3=y1;y1=y2;y2=y3;}
87 msg("<verbose> Generating info structure for page %d", pageNum);
89 void InfoOutputDev::endPage()
92 void InfoOutputDev::drawLink(Link *link, Catalog *catalog)
96 double InfoOutputDev::getMaximumFontSize(char*id)
98 FontInfo*info = (FontInfo*)id2font->lookup(id);
100 msg("<error> Unknown font id: %s", id);
103 return info->max_size;
106 char*getFontID(GfxFont*font)
108 Ref*ref = font->getID();
109 GString*gstr = font->getName();
110 char* fname = gstr==0?0:gstr->getCString();
113 if(font->getType() == fontType3) {
114 sprintf(buf, "t3font-%d-%d", ref->num, ref->gen);
116 sprintf(buf, "font-%d-%d", ref->num, ref->gen);
119 sprintf(buf, "%s-%d-%d", fname, ref->num, ref->gen);
124 void InfoOutputDev::updateFont(GfxState *state)
126 GfxFont*font = state->getFont();
131 if(font->getType() == fontType3) {
135 char*id = getFontID(font);
138 currentfont->splash_font = 0;
140 currentfont = (FontInfo*)id2font->lookup(id);
142 currentfont = new FontInfo;
143 currentfont->font = font;
144 currentfont->max_size = 0;
145 GString* idStr = new GString(id);
146 id2font->add(idStr, (void*)currentfont);
150 state->setCTM(1.0,0,0,1.0,0,0);
151 splash->updateCTM(state, 0,0,0,0,0,0);
152 state->setTextMat(1.0,0,0,1.0,0,0);
153 state->setFont(font, 1024.0);
154 splash->doUpdateFont(state);
155 currentfont->splash_font = splash->getCurrentFont();
159 void InfoOutputDev::fill(GfxState *state)
164 void InfoOutputDev::eoFill(GfxState *state)
169 FontInfo* InfoOutputDev::getFont(char*id)
171 return (FontInfo*)id2font->lookup(id);
174 void InfoOutputDev::drawChar(GfxState *state, double x, double y,
175 double dx, double dy,
176 double originX, double originY,
177 CharCode code, int nBytes, Unicode *u, int uLen)
179 double m11,m21,m12,m22;
180 state->getFontTransMat(&m11, &m12, &m21, &m22);
181 m11 *= state->getHorizScaling();
182 m21 *= state->getHorizScaling();
183 double lenx = sqrt(m11*m11 + m12*m12);
184 double leny = sqrt(m21*m21 + m22*m22);
185 double len = lenx>leny?lenx:leny;
186 if(!currentfont || !currentfont->splash_font) {
189 if(currentfont && currentfont->max_size < len) {
190 currentfont->max_size = len;
192 currentfont->grow(code+1);
193 GlyphInfo*g = currentfont->glyphs[code];
195 g = currentfont->glyphs[code] = new GlyphInfo();
196 g->path = currentfont->splash_font->getGlyphPath(code);
199 if(uLen && (u[0]>=32 && u[0]<g->unicode || !g->unicode)) {
205 GBool InfoOutputDev::beginType3Char(GfxState *state, double x, double y, double dx, double dy, CharCode code, Unicode *u, int uLen)
207 GfxFont*font = state->getFont();
210 if(font->getType() != fontType3)
213 char*id = getFontID(font);
214 currentfont = (FontInfo*)id2font->lookup(id);
216 currentfont = new FontInfo;
217 currentfont->font = font;
218 GString* idStr = new GString(id);
219 id2font->add(idStr, (void*)currentfont);
222 currentfont = currentfont;
225 currentfont->grow(code+1);
226 if(!currentfont->glyphs[code]) {
227 currentglyph = currentfont->glyphs[code] = new GlyphInfo();
228 currentglyph->unicode = uLen?u[0]:0;
229 currentglyph->path = new SplashPath();
240 void InfoOutputDev::type3D0(GfxState *state, double wx, double wy)
248 void InfoOutputDev::type3D1(GfxState *state, double wx, double wy, double llx, double lly, double urx, double ury)
250 currentglyph->x1=llx;
251 currentglyph->y1=lly;
252 currentglyph->x2=urx;
253 currentglyph->y2=ury;
256 void InfoOutputDev::endType3Char(GfxState *state)
258 double x1 = currentglyph->x1;
259 double y1 = currentglyph->y1;
260 double x2 = currentglyph->x2;
261 double y2 = currentglyph->y2;
262 currentglyph->path->moveTo(x1,y1);
263 currentglyph->path->lineTo(x2,y1);
264 currentglyph->path->lineTo(x2,y2);
265 currentglyph->path->lineTo(x1,y2);
266 currentglyph->path->close();
269 void InfoOutputDev::drawImageMask(GfxState *state, Object *ref, Stream *str,
270 int width, int height, GBool invert,
274 OutputDev::drawImageMask(state,ref,str,width,height,invert,inlineImg);
276 void InfoOutputDev::drawImage(GfxState *state, Object *ref, Stream *str,
277 int width, int height, GfxImageColorMap *colorMap,
278 int *maskColors, GBool inlineImg)
281 OutputDev::drawImage(state,ref,str,width,height,colorMap,maskColors,inlineImg);
283 void InfoOutputDev::drawMaskedImage(GfxState *state, Object *ref, Stream *str,
284 int width, int height,
285 GfxImageColorMap *colorMap,
287 int maskWidth, int maskHeight,
290 OutputDev::drawMaskedImage(state,ref,str,width,height,colorMap,maskStr,maskWidth,maskHeight,maskInvert);
293 void InfoOutputDev::drawSoftMaskedImage(GfxState *state, Object *ref, Stream *str,
294 int width, int height,
295 GfxImageColorMap *colorMap,
297 int maskWidth, int maskHeight,
298 GfxImageColorMap *maskColorMap)
300 OutputDev::drawSoftMaskedImage(state,ref,str,width,height,colorMap,maskStr,maskWidth,maskHeight,maskColorMap);