00001
00002
00003
00004
00005
00006
00007
00008
00009 #ifndef TEXTOUTPUTDEV_H
00010 #define TEXTOUTPUTDEV_H
00011
00012 #include <aconf.h>
00013
00014 #ifdef USE_GCC_PRAGMAS
00015 #pragma interface
00016 #endif
00017
00018 #include <stdio.h>
00019 #include "gtypes.h"
00020 #include "GfxFont.h"
00021 #include "OutputDev.h"
00022
00023 class GfxState;
00024 class GString;
00025 class TextBlock;
00026 class TextLine;
00027
00028 #undef TEXTOUT_DO_SYMBOLS
00029
00030
00031
00032 typedef void (*TextOutputFunc)(void *stream, char *text, int len);
00033
00034
00035
00036
00037
00038 namespace PDFImport {
00039 class String;
00040 class Page;
00041 }
00042
00043 class TextString {
00044 public:
00045
00046
00047 TextString(GfxState *state, double x0, double y0,
00048 double fontSize);
00049
00050
00051
00052 virtual ~TextString();
00053
00054
00055 virtual void addChar(GfxState *state, double x, double y,
00056 double dx, double dy, Unicode u);
00057
00058 protected:
00059 double xMin, xMax;
00060 double yMin, yMax;
00061 union {
00062 GBool marked;
00063 GBool spaceAfter;
00064 };
00065 Unicode *text;
00066 double *xRight;
00067 int len;
00068 int size;
00069 TextString *next;
00070
00071 friend class TextPage;
00072 friend class TextBlock;
00073 friend class PDFImport::String;
00074 friend class PDFImport::Page;
00075 };
00076
00077
00078
00079
00080
00081
00082 class TextBlock {
00083 public:
00084
00085 TextBlock();
00086 ~TextBlock();
00087
00088 double xMin, xMax;
00089 double yMin, yMax;
00090 TextString *strings;
00091 TextBlock *next;
00092 TextBlock *xyNext;
00093 Unicode *text;
00094
00095 double *xRight;
00096 int len;
00097 int convertedLen;
00098 int *col;
00099
00100 };
00101
00102
00103
00104
00105
00106 class TextLine {
00107 public:
00108
00109 TextLine();
00110 ~TextLine();
00111
00112 TextBlock *blocks;
00113 TextLine *next;
00114 double yMin, yMax;
00115 };
00116
00117
00118
00119
00120
00121 class TextPage {
00122 public:
00123
00124
00125 TextPage(GBool rawOrderA);
00126
00127
00128 virtual ~TextPage();
00129
00130
00131 void updateFont(GfxState *state);
00132
00133
00134
00135 virtual void beginString(GfxState *state, double x0, double y0);
00136
00137
00138 void addChar(GfxState *state, double x, double y,
00139 double dx, double dy, Unicode *u, int uLen);
00140
00141
00142 virtual void endString();
00143
00144
00145 virtual void addString(TextString *str);
00146
00147
00148
00149 void coalesce();
00150
00151
00152
00153
00154
00155
00156 GBool findText(Unicode *s, int len,
00157 GBool top, GBool bottom,
00158 double *xMin, double *yMin,
00159 double *xMax, double *yMax);
00160
00161
00162 GString *getText(double xMin, double yMin,
00163 double xMax, double yMax);
00164
00165
00166 void dump(void *outputStream, TextOutputFunc outputFunc);
00167
00168
00169 virtual void clear();
00170
00171 private:
00172
00173 GBool xyBefore(TextString *str1, TextString *str2);
00174 GBool xyBefore(TextBlock *blk1, TextBlock *blk2);
00175 GBool yxBefore(TextBlock *blk1, TextBlock *blk2);
00176 double coalesceFit(TextString *str1, TextString *str2);
00177
00178 GBool rawOrder;
00179
00180 TextString *curStr;
00181 double fontSize;
00182
00183 TextString *xyStrings;
00184
00185 TextString *xyCur1, *xyCur2;
00186 TextLine *lines;
00187
00188 int nest;
00189
00190 int nTinyChars;
00191
00192 friend class PDFImport::Page;
00193 };
00194
00195
00196
00197
00198
00199 class TextOutputDev: public OutputDev {
00200 public:
00201
00202
00203
00204
00205 TextOutputDev(char *fileName, GBool rawOrderA, GBool append);
00206
00207
00208
00209 TextOutputDev(TextOutputFunc func, void *stream, GBool rawOrderA);
00210
00211
00212 virtual ~TextOutputDev();
00213
00214
00215 virtual GBool isOk() { return ok; }
00216
00217
00218
00219
00220
00221 virtual GBool upsideDown() { return gTrue; }
00222
00223
00224 virtual GBool useDrawChar() { return gTrue; }
00225
00226
00227
00228 virtual GBool interpretType3Chars() { return gFalse; }
00229
00230
00231 virtual GBool needNonText() { return gFalse; }
00232
00233
00234
00235
00236 virtual void startPage(int pageNum, GfxState *state);
00237
00238
00239 virtual void endPage();
00240
00241
00242 virtual void updateFont(GfxState *state);
00243
00244
00245 virtual void beginString(GfxState *state, GString *s);
00246 virtual void endString(GfxState *state);
00247 virtual void drawChar(GfxState *state, double x, double y,
00248 double dx, double dy,
00249 double originX, double originY,
00250 CharCode c, Unicode *u, int uLen);
00251
00252
00253
00254
00255
00256
00257
00258
00259
00260
00261 GBool findText(Unicode *s, int len,
00262 GBool top, GBool bottom,
00263 double *xMin, double *yMin,
00264 double *xMax, double *yMax);
00265
00266
00267 GString *getText(double xMin, double yMin,
00268 double xMax, double yMax);
00269
00270 private:
00271
00272 TextOutputFunc outputFunc;
00273 void *outputStream;
00274 GBool needClose;
00275
00276 TextPage *text;
00277 GBool rawOrder;
00278 GBool ok;
00279
00280 };
00281
00282 #endif