00001
00002
00003
00004
00005
00006
00007
00008
00009 #ifndef TEXTOUTPUTDEV_H
00010 #define TEXTOUTPUTDEV_H
00011
00012 #ifdef __GNUC__
00013 #pragma interface
00014 #endif
00015
00016 #include <stdio.h>
00017 #include "gtypes.h"
00018 #include "GfxFont.h"
00019 #include "OutputDev.h"
00020
00021 class GfxState;
00022 class GString;
00023
00024
00025
00026 typedef void (*TextOutputFunc)(void *stream, char *text, int len);
00027
00028
00029
00030
00031
00032 class TextString {
00033 public:
00034
00035
00036 TextString(GfxState *state, fouble fontSize);
00037
00038
00039 ~TextString();
00040
00041
00042 void addChar(GfxState *state, fouble x, fouble y,
00043 fouble dx, fouble dy, Unicode u);
00044
00045 private:
00046
00047 fouble xMin, xMax;
00048 fouble yMin, yMax;
00049 int col;
00050 Unicode *text;
00051 fouble *xRight;
00052 int len;
00053 int size;
00054 TextString *yxNext;
00055 TextString *xyNext;
00056
00057 friend class TextPage;
00058 };
00059
00060
00061
00062
00063
00064 class TextPage {
00065 public:
00066
00067
00068 TextPage(GBool rawOrderA);
00069
00070
00071 ~TextPage();
00072
00073
00074 void updateFont(GfxState *state);
00075
00076
00077 void beginString(GfxState *state);
00078
00079
00080 void addChar(GfxState *state, fouble x, fouble y,
00081 fouble dx, fouble dy, Unicode *u, int uLen);
00082
00083
00084 void endString();
00085
00086
00087 void coalesce();
00088
00089
00090
00091
00092
00093
00094 GBool findText(Unicode *s, int len,
00095 GBool top, GBool bottom,
00096 fouble *xMin, fouble *yMin,
00097 fouble *xMax, fouble *yMax);
00098
00099
00100 GString *getText(fouble xMin, fouble yMin,
00101 fouble xMax, fouble yMax);
00102
00103
00104 void dump(void *outputStream, TextOutputFunc outputFunc);
00105
00106
00107 void clear();
00108
00109 private:
00110
00111 GBool rawOrder;
00112
00113 TextString *curStr;
00114 fouble fontSize;
00115
00116 TextString *yxStrings;
00117 TextString *xyStrings;
00118 TextString *yxCur1, *yxCur2;
00119
00120 int nest;
00121 };
00122
00123
00124
00125
00126
00127 class TextOutputDev: public OutputDev {
00128 public:
00129
00130
00131
00132
00133 TextOutputDev(char *fileName, GBool rawOrderA, GBool append);
00134
00135
00136
00137 TextOutputDev(TextOutputFunc func, void *stream, GBool rawOrderA);
00138
00139
00140 virtual ~TextOutputDev();
00141
00142
00143 virtual GBool isOk() { return ok; }
00144
00145
00146
00147
00148
00149 virtual GBool upsideDown() { return gTrue; }
00150
00151
00152 virtual GBool useDrawChar() { return gTrue; }
00153
00154
00155
00156 virtual GBool interpretType3Chars() { return gFalse; }
00157
00158
00159 virtual GBool needNonText() { return gFalse; }
00160
00161
00162
00163
00164 virtual void startPage(int pageNum, GfxState *state);
00165
00166
00167 virtual void endPage();
00168
00169
00170 virtual void updateFont(GfxState *state);
00171
00172
00173 virtual void beginString(GfxState *state, GString *s);
00174 virtual void endString(GfxState *state);
00175 virtual void drawChar(GfxState *state, fouble x, fouble y,
00176 fouble dx, fouble dy,
00177 fouble originX, fouble originY,
00178 CharCode c, Unicode *u, int uLen);
00179
00180
00181
00182
00183
00184
00185
00186
00187 GBool findText(Unicode *s, int len,
00188 GBool top, GBool bottom,
00189 fouble *xMin, fouble *yMin,
00190 fouble *xMax, fouble *yMax);
00191
00192 private:
00193
00194 TextOutputFunc outputFunc;
00195 void *outputStream;
00196 GBool needClose;
00197
00198 TextPage *text;
00199 GBool rawOrder;
00200 GBool ok;
00201 };
00202
00203 #endif