don't split tiling pattern fills
[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 GBool InfoOutputDev::useTilingPatternFill() {return gTrue;}
26 void InfoOutputDev::startPage(int pageNum, GfxState *state, double crop_x1, double crop_y1, double crop_x2, double crop_y2)
27 {
28     double x1,y1,x2,y2;
29     state->transform(crop_x1,crop_y1,&x1,&y1);
30     state->transform(crop_x2,crop_y2,&x2,&y2);
31     if(x2<x1) {double x3=x1;x1=x2;x2=x3;}
32     if(y2<y1) {double y3=y1;y1=y2;y2=y3;}
33     this->x1 = (int)x1;
34     this->y1 = (int)y1;
35     this->x2 = (int)x2;
36     this->y2 = (int)y2;
37     msg("<verbose> Generating info structure for page %d", pageNum);
38 }
39 void InfoOutputDev::drawLink(Link *link, Catalog *catalog) 
40 {
41     num_links++;
42 }
43 double InfoOutputDev::getMaximumFontSize(char*id)
44 {
45     FontInfo*info = (FontInfo*)id2font->lookup(id);
46     if(!info) {
47         msg("<error> Unknown font id: %s", id);
48         return 0.0;
49     }
50     return info->max_size;
51 }
52
53 static char*getFontID(GfxFont*font)
54 {
55     Ref*ref = font->getID();
56     GString*gstr = font->getName();
57     char* fname = gstr==0?0:gstr->getCString();
58     char buf[128];
59     if(fname==0) {
60         sprintf(buf, "font-%d-%d", ref->num, ref->gen);
61     } else {
62         sprintf(buf, "%s-%d-%d", fname, ref->num, ref->gen);
63     }
64     return strdup(buf);
65 }
66
67 void InfoOutputDev::updateFont(GfxState *state) 
68 {
69     GfxFont*font = state->getFont();
70     if(!font)
71         return;
72     char*id = getFontID(font);
73     
74     FontInfo*info = (FontInfo*)id2font->lookup(id);
75     if(!info) {
76       GString* idStr = new GString(id);
77       info = new FontInfo;
78       info->font = font;
79       info->max_size = 0;
80       id2font->add(idStr, (void*)info);
81       free(id);
82       num_fonts++;
83     }
84     currentfont = info;
85
86     //splash->doUpdateFont(state);
87     //SplashFont* splash_font = splash->getCurrentFont();
88
89     //printf("%s: %d chars\n", id, splash_font->getNumChars());
90 }
91
92 void InfoOutputDev::drawChar(GfxState *state, double x, double y,
93                       double dx, double dy,
94                       double originX, double originY,
95                       CharCode code, int nBytes, Unicode *u, int uLen)
96 {
97     int render = state->getRender();
98     if (render == 3)
99         return;
100     double m11,m21,m12,m22;
101     state->getFontTransMat(&m11, &m12, &m21, &m22);
102     m11 *= state->getHorizScaling();
103     m21 *= state->getHorizScaling();
104     double lenx = sqrt(m11*m11 + m12*m12);
105     double leny = sqrt(m21*m21 + m22*m22);
106     double len = lenx>leny?lenx:leny;
107     if(currentfont && currentfont->max_size < len) {
108         currentfont->max_size = len;
109     }
110 }
111 void InfoOutputDev::drawImageMask(GfxState *state, Object *ref, Stream *str,
112                            int width, int height, GBool invert,
113                            GBool inlineImg) 
114 {
115     num_images++;
116     OutputDev::drawImageMask(state,ref,str,width,height,invert,inlineImg);
117 }
118 void InfoOutputDev::drawImage(GfxState *state, Object *ref, Stream *str,
119                        int width, int height, GfxImageColorMap *colorMap,
120                        int *maskColors, GBool inlineImg)
121 {
122     num_images++;
123     OutputDev::drawImage(state,ref,str,width,height,colorMap,maskColors,inlineImg);
124 }
125 void InfoOutputDev::drawMaskedImage(GfxState *state, Object *ref, Stream *str,
126                                 int width, int height,
127                                 GfxImageColorMap *colorMap,
128                                 Stream *maskStr,
129                                 int maskWidth, int maskHeight,
130                                 GBool maskInvert) 
131 {
132     OutputDev::drawMaskedImage(state,ref,str,width,height,colorMap,maskStr,maskWidth,maskHeight,maskInvert);
133 }
134
135 void InfoOutputDev::drawSoftMaskedImage(GfxState *state, Object *ref, Stream *str,
136                                     int width, int height,
137                                     GfxImageColorMap *colorMap,
138                                     Stream *maskStr,
139                                     int maskWidth, int maskHeight,
140                                     GfxImageColorMap *maskColorMap) 
141 {
142     OutputDev::drawSoftMaskedImage(state,ref,str,width,height,colorMap,maskStr,maskWidth,maskHeight,maskColorMap);
143 }