]> www.fi.muni.cz Git - evince.git/blob - pdf/xpdf/TextOutputDev.h
Initial revision
[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 "OutputDev.h"
19
20 class GfxState;
21 class GfxFont;
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 private:
43
44   double xMin, xMax;            // bounding box x coordinates
45   double yMin, yMax;            // bounding box y coordinates
46   int col;                      // starting column
47   GString *text;                // the text
48   double *xRight;               // right-hand x coord of each char
49   TextString *yxNext;           // next string in y-major order
50   TextString *xyNext;           // next string in x-major order
51   GBool hexCodes;               // subsetted font with hex char codes
52
53   friend class TextPage;
54 };
55
56 //------------------------------------------------------------------------
57 // TextPage
58 //------------------------------------------------------------------------
59
60 class TextPage {
61 public:
62
63   // Constructor.
64   TextPage(GBool useASCII71);
65
66   // Destructor.
67   ~TextPage();
68
69   // Begin a new string.
70   void beginString(GfxState *state, GString *s, GBool hex1);
71
72   // Add a character to the current string.
73   void addChar(GfxState *state, double x, double y,
74                double dx, double dy, Guchar c);
75
76   // End the current string, sorting it into the list of strings.
77   void endString();
78
79   // Coalesce strings that look like parts of the same line.
80   void coalesce();
81
82   // Find a string.  If <top> is true, starts looking at top of page;
83   // otherwise starts looking at <xMin>,<yMin>.  If <bottom> is true,
84   // stops looking at bottom of page; otherwise stops looking at
85   // <xMax>,<yMax>.  If found, sets the text bounding rectange and
86   // returns true; otherwise returns false.
87   GBool findText(char *s, GBool top, GBool bottom,
88                  double *xMin, double *yMin,
89                  double *xMax, double *yMax);
90
91   // Get the text which is inside the specified rectangle.
92   GString *getText(double xMin, double yMin,
93                    double xMax, double yMax);
94
95   // Dump contents of page to a file.
96   void dump(FILE *f);
97
98   // Clear the page.
99   void clear();
100
101 private:
102
103   GBool useASCII7;              // use 7-bit ASCII?
104
105   TextString *curStr;           // currently active string
106
107   TextString *yxStrings;        // strings in y-major order
108   TextString *xyStrings;        // strings in x-major order
109 };
110
111 //------------------------------------------------------------------------
112 // TextOutputDev
113 //------------------------------------------------------------------------
114
115 class TextOutputDev: public OutputDev {
116 public:
117
118   // Open a text output file.  If <fileName> is NULL, no file is written
119   // (this is useful, e.g., for searching text).  If <useASCII7> is true,
120   // text is converted to 7-bit ASCII; otherwise, text is converted to
121   // 8-bit ISO Latin-1.
122   TextOutputDev(char *fileName, GBool useASCII7);
123
124   // Destructor.
125   virtual ~TextOutputDev();
126
127   // Check if file was successfully created.
128   virtual GBool isOk() { return ok; }
129
130   //---- get info about output device
131
132   // Does this device use upside-down coordinates?
133   // (Upside-down means (0,0) is the top left corner of the page.)
134   virtual GBool upsideDown() { return gTrue; }
135
136   // Does this device use drawChar() or drawString()?
137   virtual GBool useDrawChar() { return gTrue; }
138
139   //----- initialization and control
140
141   // Start a page.
142   virtual void startPage(int pageNum, GfxState *state);
143
144   // End a page.
145   virtual void endPage();
146
147   //----- update text state
148   virtual void updateFont(GfxState *state);
149
150   //----- text drawing
151   virtual void beginString(GfxState *state, GString *s);
152   virtual void endString(GfxState *state);
153   virtual void drawChar(GfxState *state, double x, double y,
154                         double dx, double dy, Guchar c);
155
156   //----- special access
157
158   // Find a string.  If <top> is true, starts looking at top of page;
159   // otherwise starts looking at <xMin>,<yMin>.  If <bottom> is true,
160   // stops looking at bottom of page; otherwise stops looking at
161   // <xMax>,<yMax>.  If found, sets the text bounding rectange and
162   // returns true; otherwise returns false.
163   GBool findText(char *s, GBool top, GBool bottom,
164                  double *xMin, double *yMin,
165                  double *xMax, double *yMax);
166
167 private:
168
169   FILE *f;                      // text file
170   GBool needClose;              // need to close the file?
171   TextPage *text;               // text for the current page
172   GBool hexCodes;               // subsetted font with hex char codes
173   GBool ok;                     // set up ok?
174 };
175
176 #endif