only detect spaces if we know the font doesn't use spaces on its own
[swftools.git] / lib / pdf / InfoOutputDev.h
blob07fd2e78ef04cc36a39a901b65304e697c426481
1 /* InfoOutputDev.h
2 A special output device which collects information about a PDF file,
3 like fonts, Type3 glyphs and so on.
5 This file is part of swftools.
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.
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.
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 */
21 #ifndef __infooutputdev_h__
22 #define __infooutputdev_h__
24 #include "popplercompat.h"
25 #include "GfxFont.h"
26 #include "OutputDev.h"
27 #include "SplashOutputDev.h"
28 #include "Page.h"
30 #ifdef HAVE_POPPLER
31 #include <splash/SplashTypes.h>
32 #include <splash/SplashPath.h>
33 #include <splash/SplashFont.h>
34 #include <splash/SplashFontFile.h>
35 #else
36 #include "xpdf/config.h"
37 #include "SplashTypes.h"
38 #include "SplashPath.h"
39 #include "SplashFont.h"
40 #include "SplashFontFile.h"
41 #endif
43 #ifdef HAVE_POPPLER
44 #include <goo/GooHash.h>
45 #else
46 #include "GHash.h"
47 #endif
48 #include "../gfxdevice.h"
49 #include "../gfxtools.h"
50 #include "../gfxfont.h"
51 #include "../q.h"
53 #define INTERNAL_FONT_SIZE 1024.0
54 #define GLYPH_IS_SPACE(g) ((!(g)->line || ((g)->line->type==gfx_moveTo && !(g)->line->next)) && (g)->advance)
56 struct GlyphInfo
58 SplashPath*path;
59 int unicode;
60 int glyphid;
61 double advance;
62 double x1,y1,x2,y2;
64 double advance_max;
67 typedef struct _fontclass {
68 float m00,m01,m10,m11;
69 char*id;
70 unsigned char alpha;
71 } fontclass_t;
73 class FontInfo
75 gfxfont_t*gfxfont;
77 char*id;
78 double scale;
80 gfxfont_t* createGfxFont();
81 public:
82 fontclass_t*fontclass;
83 FontInfo(fontclass_t*fontclass);
84 ~FontInfo();
86 gfxmatrix_t get_gfxmatrix(GfxState*state);
87 gfxfont_t* getGfxFont();
89 char usesSpaces();
91 double lastx,lasty;
92 int lastchar;
93 double lastadvance;
95 double ascender,descender;
97 void grow(int size);
98 void resetPositioning();
100 GfxFont*font;
101 double max_size;
102 int num_glyphs;
103 GlyphInfo**glyphs;
105 char seen;
106 int space_char;
107 float average_advance;
109 int num_chars;
110 int num_spaces;
113 extern char*getFontID(GfxFont*font);
114 extern gfxmatrix_t gfxmatrix_from_state(GfxState*state);
116 class InfoOutputDev: public OutputDev
118 GlyphInfo* currentglyph;
119 SplashOutputDev*splash;
120 char previous_was_char;
121 Page *page;
123 dict_t*fontcache;
124 FontInfo*last_font;
125 FontInfo*current_type3_font;
126 SplashFont*current_splash_font;
128 public:
129 int x1,y1,x2,y2;
130 int num_links;
131 int num_ppm_images;
132 int num_jpeg_images;
133 int num_fonts;
134 int num_polygons;
135 int num_chars;
136 int num_layers;
137 int num_text_breaks;
138 double average_char_size;
140 void dumpfonts(gfxdevice_t*dev);
141 FontInfo* getFontInfo(GfxState*state);
143 InfoOutputDev(XRef*xref);
144 virtual ~InfoOutputDev();
145 virtual GBool useTilingPatternFill();
146 virtual GBool upsideDown();
147 virtual GBool needNonText();
148 virtual GBool useDrawChar();
149 virtual GBool interpretType3Chars();
150 virtual GBool checkPageSlice(Page *page, double hDPI, double vDPI,
151 int rotate, GBool useMediaBox, GBool crop,
152 int sliceX, int sliceY, int sliceW, int sliceH,
153 GBool printing, Catalog *catalog,
154 GBool (*abortCheckCbk)(void *data) = NULL,
155 void *abortCheckCbkData = NULL);
156 virtual void startPage(int pageNum, GfxState *state);
157 virtual void endPage();
158 virtual void drawLink(Link *link, Catalog *catalog);
159 virtual void updateFont(GfxState *state);
161 virtual void saveState(GfxState *state);
162 virtual void restoreState(GfxState *state);
164 virtual GBool beginType3Char(GfxState *state, double x, double y, double dx, double dy, CharCode code, Unicode *u, int uLen);
165 virtual void type3D0(GfxState *state, double wx, double wy);
166 virtual void type3D1(GfxState *state, double wx, double wy, double llx, double lly, double urx, double ury);
167 virtual void endType3Char(GfxState *state);
169 virtual void fill(GfxState *state);
170 virtual void eoFill(GfxState *state);
172 virtual void drawChar(GfxState *state, double x, double y,
173 double dx, double dy,
174 double originX, double originY,
175 CharCode code, int nBytes, Unicode *u, int uLen);
177 virtual void updateTextMat(GfxState*state);
179 virtual void drawImageMask(GfxState *state, Object *ref, Stream *str,
180 int width, int height, GBool invert,
181 POPPLER_INTERPOLATE
182 GBool inlineImg);
183 virtual void drawImage(GfxState *state, Object *ref, Stream *str,
184 int width, int height, GfxImageColorMap *colorMap,
185 POPPLER_INTERPOLATE
186 int *maskColors, GBool inlineImg);
187 virtual void drawMaskedImage(GfxState *state, Object *ref, Stream *str,
188 int width, int height,
189 GfxImageColorMap *colorMap,
190 POPPLER_INTERPOLATE
191 Stream *maskStr,
192 int maskWidth, int maskHeight,
193 GBool maskInvert
194 POPPLER_MASK_INTERPOLATE);
195 virtual void drawSoftMaskedImage(GfxState *state, Object *ref, Stream *str,
196 int width, int height,
197 GfxImageColorMap *colorMap,
198 POPPLER_INTERPOLATE
199 Stream *maskStr,
200 int maskWidth, int maskHeight,
201 GfxImageColorMap *maskColorMap
202 POPPLER_MASK_INTERPOLATE);
203 private:
205 FontInfo* getOrCreateFontInfo(GfxState*state);
208 #endif //__infooutputdev_h__