added kerning to fonts
[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 #include "../q.h"
48
49 #define INTERNAL_FONT_SIZE 1024.0
50 #define GLYPH_IS_SPACE(g) ((!(g)->line || ((g)->line->type==gfx_moveTo && !(g)->line->next)) && (g)->advance)
51
52 struct GlyphInfo
53 {
54     SplashPath*path;
55     int unicode;
56     int glyphid;
57     double advance;
58     double x1,y1,x2,y2;
59
60     double advance_max;
61 };
62
63 class FontInfo
64 {
65     gfxfont_t*gfxfont;
66
67     char*id;
68 public:
69     FontInfo(char*id);
70     ~FontInfo();
71
72     gfxfont_t* getGfxFont();
73
74     double lastx,lasty;
75     int lastchar;
76     int lastadvance;
77
78     double ascender,descender;
79
80     void grow(int size);
81
82     GfxFont*font;
83     double max_size;
84     int num_glyphs;
85     GlyphInfo**glyphs;
86     dict_t**kerning;
87
88     int*charid2glyph;
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
104     public:
105     int x1,y1,x2,y2;
106     int num_links;
107     int num_ppm_images;
108     int num_jpeg_images;
109     int num_fonts;
110     int num_polygons;
111     int num_textfields;
112
113     void dumpfonts(gfxdevice_t*dev);
114
115     InfoOutputDev(XRef*xref);
116     virtual ~InfoOutputDev(); 
117     virtual GBool useTilingPatternFill();
118     virtual GBool upsideDown();
119     virtual GBool useDrawChar();
120     virtual GBool interpretType3Chars();
121     virtual void startPage(int pageNum, GfxState *state, double crop_x1, double crop_y1, double crop_x2, double crop_y2);
122     virtual void endPage();
123     virtual void drawLink(Link *link, Catalog *catalog);
124     virtual double getMaximumFontSize(char*id);
125     virtual void updateFont(GfxState *state);
126
127     virtual GBool beginType3Char(GfxState *state, double x, double y, double dx, double dy, CharCode code, Unicode *u, int uLen);
128     virtual void type3D0(GfxState *state, double wx, double wy);
129     virtual void type3D1(GfxState *state, double wx, double wy, double llx, double lly, double urx, double ury);
130     virtual void endType3Char(GfxState *state);
131   
132     virtual void fill(GfxState *state);
133     virtual void eoFill(GfxState *state);
134
135     virtual void drawChar(GfxState *state, double x, double y,
136                           double dx, double dy,
137                           double originX, double originY,
138                           CharCode code, int nBytes, Unicode *u, int uLen);
139     virtual void drawImageMask(GfxState *state, Object *ref, Stream *str,
140                                int width, int height, GBool invert,
141                                GBool inlineImg);
142     virtual void drawImage(GfxState *state, Object *ref, Stream *str,
143                            int width, int height, GfxImageColorMap *colorMap,
144                            int *maskColors, GBool inlineImg);
145     virtual void drawMaskedImage(GfxState *state, Object *ref, Stream *str,
146                                   int width, int height,
147                                   GfxImageColorMap *colorMap,
148                                   Stream *maskStr,
149                                   int maskWidth, int maskHeight,
150                                   GBool maskInvert);
151     virtual void drawSoftMaskedImage(GfxState *state, Object *ref, Stream *str,
152                                       int width, int height,
153                                       GfxImageColorMap *colorMap,
154                                       Stream *maskStr,
155                                       int maskWidth, int maskHeight,
156                                       GfxImageColorMap *maskColorMap);
157
158     virtual FontInfo* getFont(char*id);
159 };
160
161 #endif //__infooutputdev_h__