1 //========================================================================
5 // Copyright 1997 Derek B. Noonburg
7 //========================================================================
9 #ifndef TEXTOUTPUTDEV_H
10 #define TEXTOUTPUTDEV_H
18 #include "OutputDev.h"
24 //------------------------------------------------------------------------
26 //------------------------------------------------------------------------
32 TextString(GfxState *state, GBool hexCodes1);
37 // Add a character to the string.
38 void addChar(GfxState *state, double x, double y,
40 Guchar c, GBool useASCII7);
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
53 friend class TextPage;
56 //------------------------------------------------------------------------
58 //------------------------------------------------------------------------
64 TextPage(GBool useASCII71);
69 // Begin a new string.
70 void beginString(GfxState *state, GString *s, GBool hex1);
72 // Add a character to the current string.
73 void addChar(GfxState *state, double x, double y,
74 double dx, double dy, Guchar c);
76 // End the current string, sorting it into the list of strings.
79 // Coalesce strings that look like parts of the same line.
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);
91 // Get the text which is inside the specified rectangle.
92 GString *getText(double xMin, double yMin,
93 double xMax, double yMax);
95 // Dump contents of page to a file.
103 GBool useASCII7; // use 7-bit ASCII?
105 TextString *curStr; // currently active string
107 TextString *yxStrings; // strings in y-major order
108 TextString *xyStrings; // strings in x-major order
111 //------------------------------------------------------------------------
113 //------------------------------------------------------------------------
115 class TextOutputDev: public OutputDev {
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);
125 virtual ~TextOutputDev();
127 // Check if file was successfully created.
128 virtual GBool isOk() { return ok; }
130 //---- get info about output device
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; }
136 // Does this device use drawChar() or drawString()?
137 virtual GBool useDrawChar() { return gTrue; }
139 //----- initialization and control
142 virtual void startPage(int pageNum, GfxState *state);
145 virtual void endPage();
147 //----- update text state
148 virtual void updateFont(GfxState *state);
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);
156 //----- special access
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);
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?