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)
18 id2font = new GHash(1);
19 SplashColor white = {255,255,255};
20 splash = new SplashOutputDev(splashModeRGB8,320,0,white,0,0);
21 splash->startDoc(xref);
23 InfoOutputDev::~InfoOutputDev()
26 id2font->startIter(&i);
29 while(id2font->getNext(&i, &key, (void**)&fontinfo)) {
32 id2font->killIter(&i);
34 delete id2font;id2font=0;
35 delete splash;splash=0;
37 void FontInfo::grow(int size)
39 if(size >= this->num_glyphs) {
40 this->glyphs = (GlyphInfo**)realloc(this->glyphs, sizeof(GlyphInfo*)*(size));
41 memset(&this->glyphs[this->num_glyphs], 0, sizeof(SplashPath*)*((size)-this->num_glyphs));
42 this->num_glyphs = size;
47 this->charid2glyph = 0;
51 this->splash_font = 0;
56 if(this->charid2glyph) {
57 free(this->charid2glyph);
58 this->charid2glyph = 0;
61 for(t=0;t<num_glyphs;t++) {
63 delete glyphs[t]->path;glyphs[t]->path = 0;
68 free(glyphs);glyphs=0;
70 GBool InfoOutputDev::upsideDown() {return gTrue;}
71 GBool InfoOutputDev::useDrawChar() {return gTrue;}
72 GBool InfoOutputDev::interpretType3Chars() {return gTrue;}
73 GBool InfoOutputDev::useTilingPatternFill() {return gTrue;}
75 void InfoOutputDev::startPage(int pageNum, GfxState *state, double crop_x1, double crop_y1, double crop_x2, double crop_y2)
78 state->transform(crop_x1,crop_y1,&x1,&y1);
79 state->transform(crop_x2,crop_y2,&x2,&y2);
80 if(x2<x1) {double x3=x1;x1=x2;x2=x3;}
81 if(y2<y1) {double y3=y1;y1=y2;y2=y3;}
86 msg("<verbose> Generating info structure for page %d", pageNum);
88 void InfoOutputDev::endPage()
91 void InfoOutputDev::drawLink(Link *link, Catalog *catalog)
95 double InfoOutputDev::getMaximumFontSize(char*id)
97 FontInfo*info = (FontInfo*)id2font->lookup(id);
99 msg("<error> Unknown font id: %s", id);
102 return info->max_size;
105 char*getFontID(GfxFont*font)
107 Ref*ref = font->getID();
108 GString*gstr = font->getName();
109 char* fname = gstr==0?0:gstr->getCString();
112 if(font->getType() == fontType3) {
113 sprintf(buf, "t3font-%d-%d", ref->num, ref->gen);
115 sprintf(buf, "font-%d-%d", ref->num, ref->gen);
118 sprintf(buf, "%s-%d-%d", fname, ref->num, ref->gen);
123 void InfoOutputDev::updateFont(GfxState *state)
125 GfxFont*font = state->getFont();
130 if(font->getType() == fontType3) {
134 char*id = getFontID(font);
137 currentfont->splash_font = 0;
139 currentfont = (FontInfo*)id2font->lookup(id);
141 currentfont = new FontInfo;
142 currentfont->font = font;
143 currentfont->max_size = 0;
144 GString* idStr = new GString(id);
145 id2font->add(idStr, (void*)currentfont);
149 state->setCTM(1.0,0,0,1.0,0,0);
150 splash->updateCTM(state, 0,0,0,0,0,0);
151 state->setTextMat(1.0,0,0,1.0,0,0);
152 state->setFont(font, 1024.0);
153 splash->doUpdateFont(state);
154 currentfont->splash_font = splash->getCurrentFont();
157 FontInfo* InfoOutputDev::getFont(char*id)
159 return (FontInfo*)id2font->lookup(id);
162 void InfoOutputDev::drawChar(GfxState *state, double x, double y,
163 double dx, double dy,
164 double originX, double originY,
165 CharCode code, int nBytes, Unicode *u, int uLen)
167 double m11,m21,m12,m22;
168 state->getFontTransMat(&m11, &m12, &m21, &m22);
169 m11 *= state->getHorizScaling();
170 m21 *= state->getHorizScaling();
171 double lenx = sqrt(m11*m11 + m12*m12);
172 double leny = sqrt(m21*m21 + m22*m22);
173 double len = lenx>leny?lenx:leny;
174 if(!currentfont || !currentfont->splash_font) {
177 if(currentfont && currentfont->max_size < len) {
178 currentfont->max_size = len;
180 currentfont->grow(code+1);
181 GlyphInfo*g = currentfont->glyphs[code];
183 g = currentfont->glyphs[code] = new GlyphInfo();
184 g->path = currentfont->splash_font->getGlyphPath(code);
187 if(uLen && (u[0]>=32 && u[0]<g->unicode || !g->unicode)) {
193 GBool InfoOutputDev::beginType3Char(GfxState *state, double x, double y, double dx, double dy, CharCode code, Unicode *u, int uLen)
195 GfxFont*font = state->getFont();
198 if(font->getType() != fontType3)
201 char*id = getFontID(font);
202 currentfont = (FontInfo*)id2font->lookup(id);
204 currentfont = new FontInfo;
205 currentfont->font = font;
206 GString* idStr = new GString(id);
207 id2font->add(idStr, (void*)currentfont);
210 currentfont = currentfont;
213 currentfont->grow(code+1);
214 if(!currentfont->glyphs[code]) {
215 currentglyph = currentfont->glyphs[code] = new GlyphInfo();
216 currentglyph->unicode = uLen?u[0]:0;
217 currentglyph->path = new SplashPath();
228 void InfoOutputDev::type3D0(GfxState *state, double wx, double wy)
236 void InfoOutputDev::type3D1(GfxState *state, double wx, double wy, double llx, double lly, double urx, double ury)
238 currentglyph->x1=llx;
239 currentglyph->y1=lly;
240 currentglyph->x2=urx;
241 currentglyph->y2=ury;
244 void InfoOutputDev::endType3Char(GfxState *state)
246 double x1 = currentglyph->x1;
247 double y1 = currentglyph->y1;
248 double x2 = currentglyph->x2;
249 double y2 = currentglyph->y2;
250 currentglyph->path->moveTo(x1,y1);
251 currentglyph->path->lineTo(x2,y1);
252 currentglyph->path->lineTo(x2,y2);
253 currentglyph->path->lineTo(x1,y2);
254 currentglyph->path->close();
257 void InfoOutputDev::drawImageMask(GfxState *state, Object *ref, Stream *str,
258 int width, int height, GBool invert,
262 OutputDev::drawImageMask(state,ref,str,width,height,invert,inlineImg);
264 void InfoOutputDev::drawImage(GfxState *state, Object *ref, Stream *str,
265 int width, int height, GfxImageColorMap *colorMap,
266 int *maskColors, GBool inlineImg)
269 OutputDev::drawImage(state,ref,str,width,height,colorMap,maskColors,inlineImg);
271 void InfoOutputDev::drawMaskedImage(GfxState *state, Object *ref, Stream *str,
272 int width, int height,
273 GfxImageColorMap *colorMap,
275 int maskWidth, int maskHeight,
278 OutputDev::drawMaskedImage(state,ref,str,width,height,colorMap,maskStr,maskWidth,maskHeight,maskInvert);
281 void InfoOutputDev::drawSoftMaskedImage(GfxState *state, Object *ref, Stream *str,
282 int width, int height,
283 GfxImageColorMap *colorMap,
285 int maskWidth, int maskHeight,
286 GfxImageColorMap *maskColorMap)
288 OutputDev::drawSoftMaskedImage(state,ref,str,width,height,colorMap,maskStr,maskWidth,maskHeight,maskColorMap);