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