]> www.fi.muni.cz Git - evince.git/blob - pdf/xpdf/TextOutputDev.h
Replace exit() with gtk_main_quit()
[evince.git] / pdf / xpdf / TextOutputDev.h
1 //========================================================================
2 //
3 // TextOutputDev.h
4 //
5 // Copyright 1997 Derek B. Noonburg
6 //
7 //========================================================================
8
9 #ifndef TEXTOUTPUTDEV_H
10 #define TEXTOUTPUTDEV_H
11
12 #ifdef __GNUC__
13 #pragma interface
14 #endif
15
16 #include <stdio.h>
17 #include "gtypes.h"
18 #include "GfxFont.h"
19 #include "OutputDev.h"
20
21 class GfxState;
22 class GString;
23
24 //------------------------------------------------------------------------
25 // TextString
26 //------------------------------------------------------------------------
27
28 class TextString {
29 public:
30
31   // Constructor.
32   TextString(GfxState *state, GBool hexCodes1);
33
34   // Destructor.
35   ~TextString();
36
37   // Add a character to the string.
38   void addChar(GfxState *state, double x, double y,
39                double dx, double dy,
40                Guchar c, GBool useASCII7);
41
42   // Add a 16-bit character to the string.
43   void addChar16(GfxState *state, double x, double y,
44                  double dx, double dy,
45                  int c, GfxFontCharSet16 charSet);
46
47 private:
48
49   double xMin, xMax;            // bounding box x coordinates
50   double yMin, yMax;            // bounding box y coordinates
51   int col;                      // starting column
52   GString *text;                // the text
53   double *xRight;               // right-hand x coord of each char
54   TextString *yxNext;           // next string in y-major order
55   TextString *xyNext;           // next string in x-major order
56   GBool hexCodes;               // subsetted font with hex char codes
57
58   friend class TextPage;
59 };
60
61 //------------------------------------------------------------------------
62 // TextPage
63 //------------------------------------------------------------------------
64
65 class TextPage {
66 public:
67
68   // Constructor.
69   TextPage(GBool useASCII7, GBool rawOrder);
70
71   // Destructor.
72   ~TextPage();
73
74   // Begin a new string.
75   void beginString(GfxState *state, GString *s, GBool hex1);
76
77   // Add a character to the current string.
78   void addChar(GfxState *state, double x, double y,
79                double dx, double dy, Guchar c);
80
81   // Add a 16-bit character to the current string.
82   void addChar16(GfxState *state, double x, double y,
83                  double dx, double dy, int c,
84                  GfxFontCharSet16 charSet);
85
86   // End the current string, sorting it into the list of strings.
87   void endString();
88
89   // Coalesce strings that look like parts of the same line.
90   void coalesce();
91
92   // Find a string.  If <top> is true, starts looking at top of page;
93   // otherwise starts looking at <xMin>,<yMin>.  If <bottom> is true,
94   // stops looking at bottom of page; otherwise stops looking at
95   // <xMax>,<yMax>.  If found, sets the text bounding rectange and
96   // returns true; otherwise returns false.
97   GBool findText(char *s, GBool top, GBool bottom,
98                  double *xMin, double *yMin,
99                  double *xMax, double *yMax);
100
101   // Get the text which is inside the specified rectangle.
102   GString *getText(double xMin, double yMin,
103                    double xMax, double yMax);
104
105   // Dump contents of page to a file.
106   void dump(FILE *f);
107
108   // Clear the page.
109   void clear();
110
111 private:
112
113   GBool useASCII7;              // use 7-bit ASCII?
114   GBool rawOrder;               // keep strings in content stream order
115
116   TextString *curStr;           // currently active string
117
118   TextString *yxStrings;        // strings in y-major order
119   TextString *xyStrings;        // strings in x-major order
120   TextString *yxCur1, *yxCur2;  // cursors for yxStrings list
121 };
122
123 //------------------------------------------------------------------------
124 // TextOutputDev
125 //------------------------------------------------------------------------
126
127 class TextOutputDev: public OutputDev {
128 public:
129
130   // Open a text output file.  If <fileName> is NULL, no file is written
131   // (this is useful, e.g., for searching text).  If <useASCII7> is true,
132   // text is converted to 7-bit ASCII; otherwise, text is converted to
133   // 8-bit ISO Latin-1.  <useASCII7> should also be set for Japanese
134   // (EUC-JP) text.  If <rawOrder> is true, the text is kept in content
135   // stream order.
136   TextOutputDev(char *fileName, GBool useASCII7, GBool rawOrder);
137
138   // Destructor.
139   virtual ~TextOutputDev();
140
141   // Check if file was successfully created.
142   virtual GBool isOk() { return ok; }
143
144   //---- get info about output device
145
146   // Does this device use upside-down coordinates?
147   // (Upside-down means (0,0) is the top left corner of the page.)
148   virtual GBool upsideDown() { return gTrue; }
149
150   // Does this device use drawChar() or drawString()?
151   virtual GBool useDrawChar() { return gTrue; }
152
153   //----- initialization and control
154
155   // Start a page.
156   virtual void startPage(int pageNum, GfxState *state);
157
158   // End a page.
159   virtual void endPage();
160
161   //----- update text state
162   virtual void updateFont(GfxState *state);
163
164   //----- text drawing
165   virtual void beginString(GfxState *state, GString *s);
166   virtual void endString(GfxState *state);
167   virtual void drawChar(GfxState *state, double x, double y,
168                         double dx, double dy, Guchar c);
169   virtual void drawChar16(GfxState *state, double x, double y,
170                           double dx, double dy, int c);
171
172   //----- special access
173
174   // Find a string.  If <top> is true, starts looking at top of page;
175   // otherwise starts looking at <xMin>,<yMin>.  If <bottom> is true,
176   // stops looking at bottom of page; otherwise stops looking at
177   // <xMax>,<yMax>.  If found, sets the text bounding rectange and
178   // returns true; otherwise returns false.
179   GBool findText(char *s, GBool top, GBool bottom,
180                  double *xMin, double *yMin,
181                  double *xMax, double *yMax);
182
183 private:
184
185   FILE *f;                      // text file
186   GBool needClose;              // need to close the file?
187   TextPage *text;               // text for the current page
188   GBool rawOrder;               // keep text in content stream order
189   GBool hexCodes;               // subsetted font with hex char codes
190   GBool ok;                     // set up ok?
191 };
192
193 #endif