new parameter -s textonly
[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 #include "Page.h"
28 #ifdef HAVE_POPPLER
29 #include <splash/SplashTypes.h>
30 #include <splash/SplashPath.h>
31 #include <splash/SplashFont.h>
32 #include <splash/SplashFontFile.h>
33 #else
34 #include "SplashTypes.h"
35 #include "SplashPath.h"
36 #include "SplashFont.h"
37 #include "SplashFontFile.h"
38 #endif
39
40 #ifdef HAVE_POPPLER
41 #include <goo/GooHash.h>
42 #else
43 #include "GHash.h"
44 #endif
45 #include "../gfxdevice.h"
46 #include "../gfxtools.h"
47 #include "../gfxfont.h"
48 #include "../q.h"
49
50 #define INTERNAL_FONT_SIZE 1024.0
51 #define GLYPH_IS_SPACE(g) ((!(g)->line || ((g)->line->type==gfx_moveTo && !(g)->line->next)) && (g)->advance)
52
53 struct GlyphInfo
54 {
55     SplashPath*path;
56     int unicode;
57     int glyphid;
58     double advance;
59     double x1,y1,x2,y2;
60
61     double advance_max;
62 };
63
64 class FontInfo
65 {
66     gfxfont_t*gfxfont;
67
68     char*id;
69 public:
70     FontInfo(char*id);
71     ~FontInfo();
72
73     gfxfont_t* getGfxFont();
74
75     double lastx,lasty;
76     int lastchar;
77     int lastadvance;
78
79     double ascender,descender;
80
81     void grow(int size);
82
83     GfxFont*font;
84     double max_size;
85     int num_glyphs;
86     GlyphInfo**glyphs;
87     dict_t**kerning;
88
89     SplashFont*splash_font;
90     char seen;
91     int space_char;
92     float average_advance;
93 };
94
95 extern char*getFontID(GfxFont*font);
96
97 class InfoOutputDev: public OutputDev 
98 {
99     GHash* id2font;
100     FontInfo* currentfont;
101     GlyphInfo* currentglyph;
102     SplashOutputDev*splash;
103     Page *page;
104
105     public:
106     int x1,y1,x2,y2;
107     int num_links;
108     int num_ppm_images;
109     int num_jpeg_images;
110     int num_fonts;
111     int num_polygons;
112     int num_textfields;
113
114     void dumpfonts(gfxdevice_t*dev);
115
116     InfoOutputDev(XRef*xref);
117     virtual ~InfoOutputDev(); 
118     virtual GBool useTilingPatternFill();
119     virtual GBool upsideDown();
120     virtual GBool useDrawChar();
121     virtual GBool interpretType3Chars();
122     virtual GBool checkPageSlice(Page *page, double hDPI, double vDPI,
123                                int rotate, GBool useMediaBox, GBool crop,
124                                int sliceX, int sliceY, int sliceW, int sliceH,
125                                GBool printing, Catalog *catalog,
126                                GBool (*abortCheckCbk)(void *data) = NULL,
127                                void *abortCheckCbkData = NULL);
128     virtual void startPage(int pageNum, GfxState *state);
129     virtual void endPage();
130     virtual void drawLink(Link *link, Catalog *catalog);
131     virtual double getMaximumFontSize(char*id);
132     virtual void updateFont(GfxState *state);
133   
134     virtual void saveState(GfxState *state);
135     virtual void restoreState(GfxState *state);
136
137     virtual GBool beginType3Char(GfxState *state, double x, double y, double dx, double dy, CharCode code, Unicode *u, int uLen);
138     virtual void type3D0(GfxState *state, double wx, double wy);
139     virtual void type3D1(GfxState *state, double wx, double wy, double llx, double lly, double urx, double ury);
140     virtual void endType3Char(GfxState *state);
141   
142     virtual void fill(GfxState *state);
143     virtual void eoFill(GfxState *state);
144
145     virtual void 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);
149     virtual void drawImageMask(GfxState *state, Object *ref, Stream *str,
150                                int width, int height, GBool invert,
151                                GBool inlineImg);
152     virtual void drawImage(GfxState *state, Object *ref, Stream *str,
153                            int width, int height, GfxImageColorMap *colorMap,
154                            int *maskColors, GBool inlineImg);
155     virtual void drawMaskedImage(GfxState *state, Object *ref, Stream *str,
156                                   int width, int height,
157                                   GfxImageColorMap *colorMap,
158                                   Stream *maskStr,
159                                   int maskWidth, int maskHeight,
160                                   GBool maskInvert);
161     virtual void drawSoftMaskedImage(GfxState *state, Object *ref, Stream *str,
162                                       int width, int height,
163                                       GfxImageColorMap *colorMap,
164                                       Stream *maskStr,
165                                       int maskWidth, int maskHeight,
166                                       GfxImageColorMap *maskColorMap);
167
168     virtual FontInfo* getFont(char*id);
169 };
170
171 #endif //__infooutputdev_h__