1 //========================================================================
5 // Copyright 1997 Derek B. Noonburg
7 //========================================================================
9 #ifndef TEXTOUTPUTDEV_H
10 #define TEXTOUTPUTDEV_H
19 #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);
42 // Add a 16-bit character to the string.
43 void addChar16(GfxState *state, double x, double y,
45 int c, GfxFontCharSet16 charSet);
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
58 friend class TextPage;
61 //------------------------------------------------------------------------
63 //------------------------------------------------------------------------
69 TextPage(GBool useASCII7, GBool rawOrder);
74 // Begin a new string.
75 void beginString(GfxState *state, GString *s, GBool hex1);
77 // Add a character to the current string.
78 void addChar(GfxState *state, double x, double y,
79 double dx, double dy, Guchar c);
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);
86 // End the current string, sorting it into the list of strings.
89 // Coalesce strings that look like parts of the same line.
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);
101 // Get the text which is inside the specified rectangle.
102 GString *getText(double xMin, double yMin,
103 double xMax, double yMax);
105 // Dump contents of page to a file.
113 GBool useASCII7; // use 7-bit ASCII?
114 GBool rawOrder; // keep strings in content stream order
116 TextString *curStr; // currently active string
118 TextString *yxStrings; // strings in y-major order
119 TextString *xyStrings; // strings in x-major order
120 TextString *yxCur1, *yxCur2; // cursors for yxStrings list
123 //------------------------------------------------------------------------
125 //------------------------------------------------------------------------
127 class TextOutputDev: public OutputDev {
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
136 TextOutputDev(char *fileName, GBool useASCII7, GBool rawOrder);
139 virtual ~TextOutputDev();
141 // Check if file was successfully created.
142 virtual GBool isOk() { return ok; }
144 //---- get info about output device
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; }
150 // Does this device use drawChar() or drawString()?
151 virtual GBool useDrawChar() { return gTrue; }
153 //----- initialization and control
156 virtual void startPage(int pageNum, GfxState *state);
159 virtual void endPage();
161 //----- update text state
162 virtual void updateFont(GfxState *state);
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);
172 //----- special access
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);
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?