added median advance detection
[swftools.git] / lib / pdf / InfoOutputDev.h
1 /* InfoOutputDev.h
2    A special output device which collects information about a PDF file,
3    like fonts, Type3 glyphs and so on.
4
5    This file is part of swftools.
6
7    Swftools is free software; you can redistribute it and/or modify
8    it under the terms of the GNU General Public License as published by
9    the Free Software Foundation; either version 2 of the License, or
10    (at your option) any later version.
11
12    Swftools is distributed in the hope that it will be useful,
13    but WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15    GNU General Public License for more details.
16
17    You should have received a copy of the GNU General Public License
18    along with swftools; if not, write to the Free Software
19    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
20
21 #ifndef __infooutputdev_h__
22 #define __infooutputdev_h__
23
24 #include "GfxFont.h"
25 #include "OutputDev.h"
26 #include "SplashOutputDev.h"
27 #ifdef HAVE_POPPLER
28 #include <splash/SplashTypes.h>
29 #include <splash/SplashPath.h>
30 #include <splash/SplashFont.h>
31 #include <splash/SplashFontFile.h>
32 #else
33 #include "SplashTypes.h"
34 #include "SplashPath.h"
35 #include "SplashFont.h"
36 #include "SplashFontFile.h"
37 #endif
38
39 #ifdef HAVE_POPPLER
40 #include <goo/GooHash.h>
41 #else
42 #include "GHash.h"
43 #endif
44
45 struct AdvanceSample
46 {
47     double advance;
48     struct AdvanceSample*next;
49 };
50
51 struct GlyphInfo
52 {
53     SplashPath*path;
54     int unicode;
55     int glyphid;
56     double advance;
57     double x1,y1,x2,y2;
58
59     double estimateAdvance();
60
61     AdvanceSample*advance_samples;
62 };
63
64 struct FontInfo
65 {
66     FontInfo();
67     ~FontInfo();
68
69     double lastx,lasty;
70     int lastchar;
71
72     double ascender,descender;
73
74     void grow(int size);
75
76     GfxFont*font;
77     double max_size;
78     int num_glyphs;
79     GlyphInfo**glyphs;
80     int*charid2glyph;
81     SplashFont*splash_font;
82     char seen;
83 };
84
85 extern char*getFontID(GfxFont*font);
86
87 class InfoOutputDev: public OutputDev 
88 {
89     GHash* id2font;
90     FontInfo* currentfont;
91     GlyphInfo* currentglyph;
92     SplashOutputDev*splash;
93
94     public:
95     int x1,y1,x2,y2;
96     int num_links;
97     int num_images;
98     int num_fonts;
99     int num_polygons;
100
101     InfoOutputDev(XRef*xref);
102     virtual ~InfoOutputDev(); 
103     virtual GBool useTilingPatternFill();
104     virtual GBool upsideDown();
105     virtual GBool useDrawChar();
106     virtual GBool interpretType3Chars();
107     virtual void startPage(int pageNum, GfxState *state, double crop_x1, double crop_y1, double crop_x2, double crop_y2);
108     virtual void endPage();
109     virtual void drawLink(Link *link, Catalog *catalog);
110     virtual double getMaximumFontSize(char*id);
111     virtual void updateFont(GfxState *state);
112
113     virtual GBool beginType3Char(GfxState *state, double x, double y, double dx, double dy, CharCode code, Unicode *u, int uLen);
114     virtual void type3D0(GfxState *state, double wx, double wy);
115     virtual void type3D1(GfxState *state, double wx, double wy, double llx, double lly, double urx, double ury);
116     virtual void endType3Char(GfxState *state);
117   
118     virtual void fill(GfxState *state);
119     virtual void eoFill(GfxState *state);
120
121     virtual void drawChar(GfxState *state, double x, double y,
122                           double dx, double dy,
123                           double originX, double originY,
124                           CharCode code, int nBytes, Unicode *u, int uLen);
125     virtual void drawImageMask(GfxState *state, Object *ref, Stream *str,
126                                int width, int height, GBool invert,
127                                GBool inlineImg);
128     virtual void drawImage(GfxState *state, Object *ref, Stream *str,
129                            int width, int height, GfxImageColorMap *colorMap,
130                            int *maskColors, GBool inlineImg);
131     virtual void drawMaskedImage(GfxState *state, Object *ref, Stream *str,
132                                   int width, int height,
133                                   GfxImageColorMap *colorMap,
134                                   Stream *maskStr,
135                                   int maskWidth, int maskHeight,
136                                   GBool maskInvert);
137     virtual void drawSoftMaskedImage(GfxState *state, Object *ref, Stream *str,
138                                       int width, int height,
139                                       GfxImageColorMap *colorMap,
140                                       Stream *maskStr,
141                                       int maskWidth, int maskHeight,
142                                       GfxImageColorMap *maskColorMap);
143     virtual FontInfo* getFont(char*id);
144 };
145
146 #endif //__infooutputdev_h__