removed experimental splash code (not compatible with current xpdf 3.02)
[swftools.git] / lib / pdf / InfoOutputDev.cc
1 #include "SplashTypes.h"
2 #include "SplashOutputDev.h"
3 #include "InfoOutputDev.h"
4 #include "GfxState.h"
5 #include "../log.h"
6 #include <math.h>
7
8 InfoOutputDev::InfoOutputDev(XRef*xref) 
9 {
10     num_links = 0;
11     num_images = 0;
12     num_fonts = 0;
13     id2font = new GHash();
14     SplashColor white = {255,255,255};
15     //splash = new SplashOutputDev(splashModeRGB8,320,0,white,0,0);
16     //splash->startDoc(xref);
17 }
18 InfoOutputDev::~InfoOutputDev() 
19 {
20     delete id2font;
21 }
22 GBool InfoOutputDev::upsideDown() {return gTrue;}
23 GBool InfoOutputDev::useDrawChar() {return gTrue;}
24 GBool InfoOutputDev::interpretType3Chars() {return gTrue;}
25 void InfoOutputDev::startPage(int pageNum, GfxState *state, double crop_x1, double crop_y1, double crop_x2, double crop_y2)
26 {
27     double x1,y1,x2,y2;
28     state->transform(crop_x1,crop_y1,&x1,&y1);
29     state->transform(crop_x2,crop_y2,&x2,&y2);
30     if(x2<x1) {double x3=x1;x1=x2;x2=x3;}
31     if(y2<y1) {double y3=y1;y1=y2;y2=y3;}
32     this->x1 = (int)x1;
33     this->y1 = (int)y1;
34     this->x2 = (int)x2;
35     this->y2 = (int)y2;
36     msg("<verbose> Generating info structure for page %d", pageNum);
37 }
38 void InfoOutputDev::drawLink(Link *link, Catalog *catalog) 
39 {
40     num_links++;
41 }
42 double InfoOutputDev::getMaximumFontSize(char*id)
43 {
44     FontInfo*info = (FontInfo*)id2font->lookup(id);
45     if(!info) {
46         msg("<error> Unknown font id: %s", id);
47         return 0.0;
48     }
49     return info->max_size;
50 }
51
52 static char*getFontID(GfxFont*font)
53 {
54     Ref*ref = font->getID();
55     GString*gstr = font->getName();
56     char* fname = gstr==0?0:gstr->getCString();
57     char buf[128];
58     if(fname==0) {
59         sprintf(buf, "font-%d-%d", ref->num, ref->gen);
60     } else {
61         sprintf(buf, "%s-%d-%d", fname, ref->num, ref->gen);
62     }
63     return strdup(buf);
64 }
65
66 void InfoOutputDev::updateFont(GfxState *state) 
67 {
68     GfxFont*font = state->getFont();
69     if(!font)
70         return;
71     char*id = getFontID(font);
72     
73     FontInfo*info = (FontInfo*)id2font->lookup(id);
74     if(!info) {
75       GString* idStr = new GString(id);
76       info = new FontInfo;
77       info->font = font;
78       info->max_size = 0;
79       id2font->add(idStr, (void*)info);
80       free(id);
81       num_fonts++;
82     }
83     currentfont = info;
84
85     //splash->doUpdateFont(state);
86     //SplashFont* splash_font = splash->getCurrentFont();
87
88     //printf("%s: %d chars\n", id, splash_font->getNumChars());
89 }
90
91 void InfoOutputDev::drawChar(GfxState *state, double x, double y,
92                       double dx, double dy,
93                       double originX, double originY,
94                       CharCode code, int nBytes, Unicode *u, int uLen)
95 {
96     int render = state->getRender();
97     if (render == 3)
98         return;
99     double m11,m21,m12,m22;
100     state->getFontTransMat(&m11, &m12, &m21, &m22);
101     m11 *= state->getHorizScaling();
102     m21 *= state->getHorizScaling();
103     double lenx = sqrt(m11*m11 + m12*m12);
104     double leny = sqrt(m21*m21 + m22*m22);
105     double len = lenx>leny?lenx:leny;
106     if(currentfont && currentfont->max_size < len) {
107         currentfont->max_size = len;
108     }
109 }
110 void InfoOutputDev::drawImageMask(GfxState *state, Object *ref, Stream *str,
111                            int width, int height, GBool invert,
112                            GBool inlineImg) 
113 {
114     num_images++;
115     OutputDev::drawImageMask(state,ref,str,width,height,invert,inlineImg);
116 }
117 void InfoOutputDev::drawImage(GfxState *state, Object *ref, Stream *str,
118                        int width, int height, GfxImageColorMap *colorMap,
119                        int *maskColors, GBool inlineImg)
120 {
121     num_images++;
122     OutputDev::drawImage(state,ref,str,width,height,colorMap,maskColors,inlineImg);
123 }
124 void InfoOutputDev::drawMaskedImage(GfxState *state, Object *ref, Stream *str,
125                                 int width, int height,
126                                 GfxImageColorMap *colorMap,
127                                 Stream *maskStr,
128                                 int maskWidth, int maskHeight,
129                                 GBool maskInvert) 
130 {
131     OutputDev::drawMaskedImage(state,ref,str,width,height,colorMap,maskStr,maskWidth,maskHeight,maskInvert);
132 }
133
134 void InfoOutputDev::drawSoftMaskedImage(GfxState *state, Object *ref, Stream *str,
135                                     int width, int height,
136                                     GfxImageColorMap *colorMap,
137                                     Stream *maskStr,
138                                     int maskWidth, int maskHeight,
139                                     GfxImageColorMap *maskColorMap) 
140 {
141     OutputDev::drawSoftMaskedImage(state,ref,str,width,height,colorMap,maskStr,maskWidth,maskHeight,maskColorMap);
142 }