Diffstat (limited to 'noncore/unsupported/qpdf/xpdf/TextOutputDev.h') (more/less context) (show whitespace changes)
-rw-r--r-- | noncore/unsupported/qpdf/xpdf/TextOutputDev.h | 189 |
1 files changed, 189 insertions, 0 deletions
diff --git a/noncore/unsupported/qpdf/xpdf/TextOutputDev.h b/noncore/unsupported/qpdf/xpdf/TextOutputDev.h new file mode 100644 index 0000000..4c71e5e --- a/dev/null +++ b/noncore/unsupported/qpdf/xpdf/TextOutputDev.h | |||
@@ -0,0 +1,189 @@ | |||
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, fouble fontSize); | ||
33 | |||
34 | // Destructor. | ||
35 | ~TextString(); | ||
36 | |||
37 | // Add a character to the string. | ||
38 | void addChar(GfxState *state, fouble x, fouble y, | ||
39 | fouble dx, fouble dy, Unicode u); | ||
40 | |||
41 | private: | ||
42 | |||
43 | fouble xMin, xMax; // bounding box x coordinates | ||
44 | fouble yMin, yMax; // bounding box y coordinates | ||
45 | int col; // starting column | ||
46 | Unicode *text; // the text | ||
47 | fouble *xRight; // right-hand x coord of each char | ||
48 | int len; // length of text and xRight | ||
49 | int size; // size of text and xRight arrays | ||
50 | TextString *yxNext; // next string in y-major order | ||
51 | TextString *xyNext; // next string in x-major order | ||
52 | |||
53 | friend class TextPage; | ||
54 | }; | ||
55 | |||
56 | //------------------------------------------------------------------------ | ||
57 | // TextPage | ||
58 | //------------------------------------------------------------------------ | ||
59 | |||
60 | class TextPage { | ||
61 | public: | ||
62 | |||
63 | // Constructor. | ||
64 | TextPage(GBool rawOrderA); | ||
65 | |||
66 | // Destructor. | ||
67 | ~TextPage(); | ||
68 | |||
69 | // Update the current font. | ||
70 | void updateFont(GfxState *state); | ||
71 | |||
72 | // Begin a new string. | ||
73 | void beginString(GfxState *state); | ||
74 | |||
75 | // Add a character to the current string. | ||
76 | void addChar(GfxState *state, fouble x, fouble y, | ||
77 | fouble dx, fouble dy, Unicode *u, int uLen); | ||
78 | |||
79 | // End the current string, sorting it into the list of strings. | ||
80 | void endString(); | ||
81 | |||
82 | // Coalesce strings that look like parts of the same line. | ||
83 | void coalesce(); | ||
84 | |||
85 | // Find a string. If <top> is true, starts looking at top of page; | ||
86 | // otherwise starts looking at <xMin>,<yMin>. If <bottom> is true, | ||
87 | // stops looking at bottom of page; otherwise stops looking at | ||
88 | // <xMax>,<yMax>. If found, sets the text bounding rectange and | ||
89 | // returns true; otherwise returns false. | ||
90 | GBool findText(Unicode *s, int len, | ||
91 | GBool top, GBool bottom, | ||
92 | fouble *xMin, fouble *yMin, | ||
93 | fouble *xMax, fouble *yMax); | ||
94 | |||
95 | // Get the text which is inside the specified rectangle. | ||
96 | GString *getText(fouble xMin, fouble yMin, | ||
97 | fouble xMax, fouble yMax); | ||
98 | |||
99 | // Dump contents of page to a file. | ||
100 | void dump(FILE *f); | ||
101 | |||
102 | // Clear the page. | ||
103 | void clear(); | ||
104 | |||
105 | private: | ||
106 | |||
107 | GBool rawOrder; // keep strings in content stream order | ||
108 | |||
109 | TextString *curStr; // currently active string | ||
110 | fouble fontSize; // current font size | ||
111 | |||
112 | TextString *yxStrings;// strings in y-major order | ||
113 | TextString *xyStrings;// strings in x-major order | ||
114 | TextString *yxCur1, *yxCur2;// cursors for yxStrings list | ||
115 | |||
116 | int nest; // current nesting level (for Type 3 fonts) | ||
117 | }; | ||
118 | |||
119 | //------------------------------------------------------------------------ | ||
120 | // TextOutputDev | ||
121 | //------------------------------------------------------------------------ | ||
122 | |||
123 | class TextOutputDev: public OutputDev { | ||
124 | public: | ||
125 | |||
126 | // Open a text output file. If <fileName> is NULL, no file is | ||
127 | // written (this is useful, e.g., for searching text). If | ||
128 | // <rawOrder> is true, the text is kept in content stream order. | ||
129 | TextOutputDev(char *fileName, GBool rawOrderA, GBool append); | ||
130 | |||
131 | // Destructor. | ||
132 | virtual ~TextOutputDev(); | ||
133 | |||
134 | // Check if file was successfully created. | ||
135 | virtual GBool isOk() { return ok; } | ||
136 | |||
137 | //---- get info about output device | ||
138 | |||
139 | // Does this device use upside-down coordinates? | ||
140 | // (Upside-down means (0,0) is the top left corner of the page.) | ||
141 | virtual GBool upsideDown() { return gTrue; } | ||
142 | |||
143 | // Does this device use drawChar() or drawString()? | ||
144 | virtual GBool useDrawChar() { return gTrue; } | ||
145 | |||
146 | // Does this device need non-text content? | ||
147 | virtual GBool needNonText() { return gFalse; } | ||
148 | |||
149 | //----- initialization and control | ||
150 | |||
151 | // Start a page. | ||
152 | virtual void startPage(int pageNum, GfxState *state); | ||
153 | |||
154 | // End a page. | ||
155 | virtual void endPage(); | ||
156 | |||
157 | //----- update text state | ||
158 | virtual void updateFont(GfxState *state); | ||
159 | |||
160 | //----- text drawing | ||
161 | virtual void beginString(GfxState *state, GString *s); | ||
162 | virtual void endString(GfxState *state); | ||
163 | virtual void drawChar(GfxState *state, fouble x, fouble y, | ||
164 | fouble dx, fouble dy, | ||
165 | fouble originX, fouble originY, | ||
166 | CharCode c, Unicode *u, int uLen); | ||
167 | |||
168 | //----- special access | ||
169 | |||
170 | // Find a string. If <top> is true, starts looking at top of page; | ||
171 | // otherwise starts looking at <xMin>,<yMin>. If <bottom> is true, | ||
172 | // stops looking at bottom of page; otherwise stops looking at | ||
173 | // <xMax>,<yMax>. If found, sets the text bounding rectange and | ||
174 | // returns true; otherwise returns false. | ||
175 | GBool findText(Unicode *s, int len, | ||
176 | GBool top, GBool bottom, | ||
177 | fouble *xMin, fouble *yMin, | ||
178 | fouble *xMax, fouble *yMax); | ||
179 | |||
180 | private: | ||
181 | |||
182 | FILE *f; // text file | ||
183 | GBool needClose; // need to close the file? | ||
184 | TextPage *text; // text for the current page | ||
185 | GBool rawOrder; // keep text in content stream order | ||
186 | GBool ok; // set up ok? | ||
187 | }; | ||
188 | |||
189 | #endif | ||