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);
35 this->charid2glyph = 0;
40 if(this->charid2glyph) {
41 free(this->charid2glyph);
42 this->charid2glyph = 0;
45 for(t=0;t<num_glyphs;t++) {
47 delete glyphs[t]->path;glyphs[t]->path = 0;
53 GBool InfoOutputDev::upsideDown() {return gTrue;}
54 GBool InfoOutputDev::useDrawChar() {return gTrue;}
55 GBool InfoOutputDev::interpretType3Chars() {return gTrue;}
56 GBool InfoOutputDev::useTilingPatternFill() {return gTrue;}
57 void InfoOutputDev::startPage(int pageNum, GfxState *state, double crop_x1, double crop_y1, double crop_x2, double crop_y2)
60 state->transform(crop_x1,crop_y1,&x1,&y1);
61 state->transform(crop_x2,crop_y2,&x2,&y2);
62 if(x2<x1) {double x3=x1;x1=x2;x2=x3;}
63 if(y2<y1) {double y3=y1;y1=y2;y2=y3;}
68 msg("<verbose> Generating info structure for page %d", pageNum);
70 void InfoOutputDev::drawLink(Link *link, Catalog *catalog)
74 double InfoOutputDev::getMaximumFontSize(char*id)
76 FontInfo*info = (FontInfo*)id2font->lookup(id);
78 msg("<error> Unknown font id: %s", id);
81 return info->max_size;
84 char*getFontID(GfxFont*font)
86 Ref*ref = font->getID();
87 GString*gstr = font->getName();
88 char* fname = gstr==0?0:gstr->getCString();
91 sprintf(buf, "font-%d-%d", ref->num, ref->gen);
93 sprintf(buf, "%s-%d-%d", fname, ref->num, ref->gen);
98 void InfoOutputDev::updateFont(GfxState *state)
100 GfxFont*font = state->getFont();
103 if(font->getType() == fontType3) {
106 char*id = getFontID(font);
108 FontInfo*info = (FontInfo*)id2font->lookup(id);
110 /* font already known */
120 state->setCTM(1.0,0,0,1.0,0,0);
121 splash->updateCTM(state, 0,0,0,0,0,0);
122 state->setTextMat(1.0,0,0,-1.0,0,0);
123 state->setFont(font, 1024.0);
124 splash->doUpdateFont(state);
125 info->splash_font = splash->getCurrentFont();
126 info->num_glyphs = 0;
129 if(!info->splash_font) {
134 GString* idStr = new GString(id);
135 id2font->add(idStr, (void*)info);
140 FontInfo* InfoOutputDev::getFont(char*id)
142 return (FontInfo*)id2font->lookup(id);
145 void InfoOutputDev::drawChar(GfxState *state, double x, double y,
146 double dx, double dy,
147 double originX, double originY,
148 CharCode code, int nBytes, Unicode *u, int uLen)
150 double m11,m21,m12,m22;
151 state->getFontTransMat(&m11, &m12, &m21, &m22);
152 m11 *= state->getHorizScaling();
153 m21 *= state->getHorizScaling();
154 double lenx = sqrt(m11*m11 + m12*m12);
155 double leny = sqrt(m21*m21 + m22*m22);
156 double len = lenx>leny?lenx:leny;
157 if(currentfont && currentfont->max_size < len) {
158 currentfont->max_size = len;
160 if(code >= currentfont->num_glyphs) {
161 currentfont->glyphs = (GlyphInfo**)realloc(currentfont->glyphs, sizeof(GlyphInfo*)*(code+1));
162 memset(¤tfont->glyphs[currentfont->num_glyphs], 0, sizeof(SplashPath*)*((code+1)-currentfont->num_glyphs));
163 currentfont->num_glyphs = code+1;
165 GlyphInfo*g = currentfont->glyphs[code];
167 g = currentfont->glyphs[code] = new GlyphInfo();
168 g->path = currentfont->splash_font->getGlyphPath(code);
171 if(uLen && (u[0]>=32 && u[0]<g->unicode || !g->unicode)) {
176 void InfoOutputDev::drawImageMask(GfxState *state, Object *ref, Stream *str,
177 int width, int height, GBool invert,
181 OutputDev::drawImageMask(state,ref,str,width,height,invert,inlineImg);
183 void InfoOutputDev::drawImage(GfxState *state, Object *ref, Stream *str,
184 int width, int height, GfxImageColorMap *colorMap,
185 int *maskColors, GBool inlineImg)
188 OutputDev::drawImage(state,ref,str,width,height,colorMap,maskColors,inlineImg);
190 void InfoOutputDev::drawMaskedImage(GfxState *state, Object *ref, Stream *str,
191 int width, int height,
192 GfxImageColorMap *colorMap,
194 int maskWidth, int maskHeight,
197 OutputDev::drawMaskedImage(state,ref,str,width,height,colorMap,maskStr,maskWidth,maskHeight,maskInvert);
200 void InfoOutputDev::drawSoftMaskedImage(GfxState *state, Object *ref, Stream *str,
201 int width, int height,
202 GfxImageColorMap *colorMap,
204 int maskWidth, int maskHeight,
205 GfxImageColorMap *maskColorMap)
207 OutputDev::drawSoftMaskedImage(state,ref,str,width,height,colorMap,maskStr,maskWidth,maskHeight,maskColorMap);