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);
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;
69 GBool InfoOutputDev::upsideDown() {return gTrue;}
70 GBool InfoOutputDev::useDrawChar() {return gTrue;}
71 GBool InfoOutputDev::interpretType3Chars() {return gTrue;}
72 GBool InfoOutputDev::useTilingPatternFill() {return gTrue;}
74 void InfoOutputDev::startPage(int pageNum, GfxState *state, double crop_x1, double crop_y1, double crop_x2, double crop_y2)
77 state->transform(crop_x1,crop_y1,&x1,&y1);
78 state->transform(crop_x2,crop_y2,&x2,&y2);
79 if(x2<x1) {double x3=x1;x1=x2;x2=x3;}
80 if(y2<y1) {double y3=y1;y1=y2;y2=y3;}
85 msg("<verbose> Generating info structure for page %d", pageNum);
87 void InfoOutputDev::endPage()
90 void InfoOutputDev::drawLink(Link *link, Catalog *catalog)
94 double InfoOutputDev::getMaximumFontSize(char*id)
96 FontInfo*info = (FontInfo*)id2font->lookup(id);
98 msg("<error> Unknown font id: %s", id);
101 return info->max_size;
104 char*getFontID(GfxFont*font)
106 Ref*ref = font->getID();
107 GString*gstr = font->getName();
108 char* fname = gstr==0?0:gstr->getCString();
111 if(font->getType() == fontType3) {
112 sprintf(buf, "t3font-%d-%d", ref->num, ref->gen);
114 sprintf(buf, "font-%d-%d", ref->num, ref->gen);
117 sprintf(buf, "%s-%d-%d", fname, ref->num, ref->gen);
122 void InfoOutputDev::updateFont(GfxState *state)
124 GfxFont*font = state->getFont();
129 if(font->getType() == fontType3) {
133 char*id = getFontID(font);
136 currentfont->splash_font = 0;
138 currentfont = (FontInfo*)id2font->lookup(id);
140 currentfont = new FontInfo;
141 currentfont->font = font;
142 currentfont->max_size = 0;
143 GString* idStr = new GString(id);
144 id2font->add(idStr, (void*)currentfont);
148 state->setCTM(1.0,0,0,1.0,0,0);
149 splash->updateCTM(state, 0,0,0,0,0,0);
150 state->setTextMat(1.0,0,0,1.0,0,0);
151 state->setFont(font, 1024.0);
152 splash->doUpdateFont(state);
153 currentfont->splash_font = splash->getCurrentFont();
156 FontInfo* InfoOutputDev::getFont(char*id)
158 return (FontInfo*)id2font->lookup(id);
161 void InfoOutputDev::drawChar(GfxState *state, double x, double y,
162 double dx, double dy,
163 double originX, double originY,
164 CharCode code, int nBytes, Unicode *u, int uLen)
166 double m11,m21,m12,m22;
167 state->getFontTransMat(&m11, &m12, &m21, &m22);
168 m11 *= state->getHorizScaling();
169 m21 *= state->getHorizScaling();
170 double lenx = sqrt(m11*m11 + m12*m12);
171 double leny = sqrt(m21*m21 + m22*m22);
172 double len = lenx>leny?lenx:leny;
173 if(!currentfont || !currentfont->splash_font) {
176 if(currentfont && currentfont->max_size < len) {
177 currentfont->max_size = len;
179 currentfont->grow(code+1);
180 GlyphInfo*g = currentfont->glyphs[code];
182 g = currentfont->glyphs[code] = new GlyphInfo();
183 g->path = currentfont->splash_font->getGlyphPath(code);
186 if(uLen && (u[0]>=32 && u[0]<g->unicode || !g->unicode)) {
192 GBool InfoOutputDev::beginType3Char(GfxState *state, double x, double y, double dx, double dy, CharCode code, Unicode *u, int uLen)
194 GfxFont*font = state->getFont();
197 if(font->getType() != fontType3)
200 char*id = getFontID(font);
201 currentfont = (FontInfo*)id2font->lookup(id);
203 currentfont = new FontInfo;
204 currentfont->font = font;
205 GString* idStr = new GString(id);
206 id2font->add(idStr, (void*)currentfont);
209 currentfont = currentfont;
212 currentfont->grow(code+1);
213 if(!currentfont->glyphs[code]) {
214 currentglyph = currentfont->glyphs[code] = new GlyphInfo();
215 currentglyph->unicode = uLen?u[0]:0;
216 currentglyph->path = new SplashPath();
227 void InfoOutputDev::type3D0(GfxState *state, double wx, double wy)
235 void InfoOutputDev::type3D1(GfxState *state, double wx, double wy, double llx, double lly, double urx, double ury)
237 currentglyph->x1=llx;
238 currentglyph->y1=lly;
239 currentglyph->x2=urx;
240 currentglyph->y2=ury;
243 void InfoOutputDev::endType3Char(GfxState *state)
245 double x1 = currentglyph->x1;
246 double y1 = currentglyph->y1;
247 double x2 = currentglyph->x2;
248 double y2 = currentglyph->y2;
249 currentglyph->path->moveTo(x1,y1);
250 currentglyph->path->lineTo(x2,y1);
251 currentglyph->path->lineTo(x2,y2);
252 currentglyph->path->lineTo(x1,y2);
253 currentglyph->path->close();
256 void InfoOutputDev::drawImageMask(GfxState *state, Object *ref, Stream *str,
257 int width, int height, GBool invert,
261 OutputDev::drawImageMask(state,ref,str,width,height,invert,inlineImg);
263 void InfoOutputDev::drawImage(GfxState *state, Object *ref, Stream *str,
264 int width, int height, GfxImageColorMap *colorMap,
265 int *maskColors, GBool inlineImg)
268 OutputDev::drawImage(state,ref,str,width,height,colorMap,maskColors,inlineImg);
270 void InfoOutputDev::drawMaskedImage(GfxState *state, Object *ref, Stream *str,
271 int width, int height,
272 GfxImageColorMap *colorMap,
274 int maskWidth, int maskHeight,
277 OutputDev::drawMaskedImage(state,ref,str,width,height,colorMap,maskStr,maskWidth,maskHeight,maskInvert);
280 void InfoOutputDev::drawSoftMaskedImage(GfxState *state, Object *ref, Stream *str,
281 int width, int height,
282 GfxImageColorMap *colorMap,
284 int maskWidth, int maskHeight,
285 GfxImageColorMap *maskColorMap)
287 OutputDev::drawSoftMaskedImage(state,ref,str,width,height,colorMap,maskStr,maskWidth,maskHeight,maskColorMap);