04e98f71ac28ea3d8f3860adcbf60b6b5b5cb658
[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 #include "../gfxdevice.h"
45 #include "../gfxtools.h"
46 #include "../gfxfont.h"
47
48 #define INTERNAL_FONT_SIZE 1024.0
49 #define GLYPH_IS_SPACE(g) ((!(g)->line || ((g)->line->type==gfx_moveTo && !(g)->line->next)) && (g)->advance)
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 advance_max;
60 };
61
62 class FontInfo
63 {
64     gfxfont_t*gfxfont;
65
66     char*id;
67 public:
68     FontInfo(char*id);
69     ~FontInfo();
70
71     gfxfont_t* getGfxFont();
72
73     double lastx,lasty;
74     int lastchar;
75
76     double ascender,descender;
77
78     void grow(int size);
79
80     GfxFont*font;
81     double max_size;
82     int num_glyphs;
83     GlyphInfo**glyphs;
84     int*charid2glyph;
85     SplashFont*splash_font;
86     char seen;
87     int space_char;
88 };
89
90 extern char*getFontID(GfxFont*font);
91
92 class InfoOutputDev: public OutputDev 
93 {
94     GHash* id2font;
95     FontInfo* currentfont;
96     GlyphInfo* currentglyph;
97     SplashOutputDev*splash;
98
99     public:
100     int x1,y1,x2,y2;
101     int num_links;
102     int num_ppm_images;
103     int num_jpeg_images;
104     int num_fonts;
105     int num_polygons;
106     int num_textfields;
107
108     void finish();
109     void dumpfonts(gfxdevice_t*dev);
110
111     InfoOutputDev(XRef*xref);
112     virtual ~InfoOutputDev(); 
113     virtual GBool useTilingPatternFill();
114     virtual GBool upsideDown();
115     virtual GBool useDrawChar();
116     virtual GBool interpretType3Chars();
117     virtual void startPage(int pageNum, GfxState *state, double crop_x1, double crop_y1, double crop_x2, double crop_y2);
118     virtual void endPage();
119     virtual void drawLink(Link *link, Catalog *catalog);
120     virtual double getMaximumFontSize(char*id);
121     virtual void updateFont(GfxState *state);
122
123     virtual GBool beginType3Char(GfxState *state, double x, double y, double dx, double dy, CharCode code, Unicode *u, int uLen);
124     virtual void type3D0(GfxState *state, double wx, double wy);
125     virtual void type3D1(GfxState *state, double wx, double wy, double llx, double lly, double urx, double ury);
126     virtual void endType3Char(GfxState *state);
127   
128     virtual void fill(GfxState *state);
129     virtual void eoFill(GfxState *state);
130
131     virtual void drawChar(GfxState *state, double x, double y,
132                           double dx, double dy,
133                           double originX, double originY,
134                           CharCode code, int nBytes, Unicode *u, int uLen);
135     virtual void drawImageMask(GfxState *state, Object *ref, Stream *str,
136                                int width, int height, GBool invert,
137                                GBool inlineImg);
138     virtual void drawImage(GfxState *state, Object *ref, Stream *str,
139                            int width, int height, GfxImageColorMap *colorMap,
140                            int *maskColors, GBool inlineImg);
141     virtual void drawMaskedImage(GfxState *state, Object *ref, Stream *str,
142                                   int width, int height,
143                                   GfxImageColorMap *colorMap,
144                                   Stream *maskStr,
145                                   int maskWidth, int maskHeight,
146                                   GBool maskInvert);
147     virtual void drawSoftMaskedImage(GfxState *state, Object *ref, Stream *str,
148                                       int width, int height,
149                                       GfxImageColorMap *colorMap,
150                                       Stream *maskStr,
151                                       int maskWidth, int maskHeight,
152                                       GfxImageColorMap *maskColorMap);
153
154     virtual FontInfo* getFont(char*id);
155 };
156
157 #endif //__infooutputdev_h__