]> www.fi.muni.cz Git - evince.git/blob - pdf/xpdf/TextOutputDev.h
change (disabled) font embedding code
[evince.git] / pdf / xpdf / TextOutputDev.h
1 //========================================================================
2 //
3 // TextOutputDev.h
4 //
5 // Copyright 1997-2002 Glyph & Cog, LLC
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
26 typedef void (*TextOutputFunc)(void *stream, char *text, int len);
27
28 //------------------------------------------------------------------------
29 // TextString
30 //------------------------------------------------------------------------
31
32 class TextString {
33 public:
34
35   // Constructor.
36   TextString(GfxState *state, double fontSize);
37
38   // Destructor.
39   ~TextString();
40
41   // Add a character to the string.
42   void addChar(GfxState *state, double x, double y,
43                double dx, double dy, Unicode u);
44
45 private:
46
47   double xMin, xMax;            // bounding box x coordinates
48   double yMin, yMax;            // bounding box y coordinates
49   int col;                      // starting column
50   Unicode *text;                // the text
51   double *xRight;               // right-hand x coord of each char
52   int len;                      // length of text and xRight
53   int size;                     // size of text and xRight arrays
54   TextString *yxNext;           // next string in y-major order
55   TextString *xyNext;           // next string in x-major order
56
57   friend class TextPage;
58 };
59
60 //------------------------------------------------------------------------
61 // TextPage
62 //------------------------------------------------------------------------
63
64 class TextPage {
65 public:
66
67   // Constructor.
68   TextPage(GBool rawOrderA);
69
70   // Destructor.
71   ~TextPage();
72
73   // Update the current font.
74   void updateFont(GfxState *state);
75
76   // Begin a new string.
77   void beginString(GfxState *state);
78
79   // Add a character to the current string.
80   void addChar(GfxState *state, double x, double y,
81                double dx, double dy, Unicode *u, int uLen);
82
83   // End the current string, sorting it into the list of strings.
84   void endString();
85
86   // Coalesce strings that look like parts of the same line.
87   void coalesce();
88
89   // Find a string.  If <top> is true, starts looking at top of page;
90   // otherwise starts looking at <xMin>,<yMin>.  If <bottom> is true,
91   // stops looking at bottom of page; otherwise stops looking at
92   // <xMax>,<yMax>.  If found, sets the text bounding rectange and
93   // returns true; otherwise returns false.
94   GBool findText(Unicode *s, int len,
95                  GBool top, GBool bottom,
96                  double *xMin, double *yMin,
97                  double *xMax, double *yMax);
98
99   // Get the text which is inside the specified rectangle.
100   GString *getText(double xMin, double yMin,
101                    double xMax, double yMax);
102
103   // Dump contents of page to a file.
104   void dump(void *outputStream, TextOutputFunc outputFunc);
105
106   // Clear the page.
107   void clear();
108
109 private:
110
111   GBool rawOrder;               // keep strings in content stream order
112
113   TextString *curStr;           // currently active string
114   double fontSize;              // current font size
115
116   TextString *yxStrings;        // strings in y-major order
117   TextString *xyStrings;        // strings in x-major order
118   TextString *yxCur1, *yxCur2;  // cursors for yxStrings list
119
120   int nest;                     // current nesting level (for Type 3 fonts)
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
131   // written (this is useful, e.g., for searching text).  If
132   // <rawOrder> is true, the text is kept in content stream order.
133   TextOutputDev(char *fileName, GBool rawOrderA, GBool append);
134
135   // Create a TextOutputDev which will write to a generic stream.  If
136   // <rawOrder> is true, the text is kept in content stream order.
137   TextOutputDev(TextOutputFunc func, void *stream, GBool rawOrderA);
138
139   // Destructor.
140   virtual ~TextOutputDev();
141
142   // Check if file was successfully created.
143   virtual GBool isOk() { return ok; }
144
145   //---- get info about output device
146
147   // Does this device use upside-down coordinates?
148   // (Upside-down means (0,0) is the top left corner of the page.)
149   virtual GBool upsideDown() { return gTrue; }
150
151   // Does this device use drawChar() or drawString()?
152   virtual GBool useDrawChar() { return gTrue; }
153
154   // Does this device use beginType3Char/endType3Char?  Otherwise,
155   // text in Type 3 fonts will be drawn with drawChar/drawString.
156   virtual GBool interpretType3Chars() { return gFalse; }
157
158   // Does this device need non-text content?
159   virtual GBool needNonText() { return gFalse; }
160
161   //----- initialization and control
162
163   // Start a page.
164   virtual void startPage(int pageNum, GfxState *state);
165
166   // End a page.
167   virtual void endPage();
168
169   //----- update text state
170   virtual void updateFont(GfxState *state);
171
172   //----- text drawing
173   virtual void beginString(GfxState *state, GString *s);
174   virtual void endString(GfxState *state);
175   virtual void drawChar(GfxState *state, double x, double y,
176                         double dx, double dy,
177                         double originX, double originY,
178                         CharCode c, Unicode *u, int uLen);
179
180   //----- special access
181
182   // Find a string.  If <top> is true, starts looking at top of page;
183   // otherwise starts looking at <xMin>,<yMin>.  If <bottom> is true,
184   // stops looking at bottom of page; otherwise stops looking at
185   // <xMax>,<yMax>.  If found, sets the text bounding rectange and
186   // returns true; otherwise returns false.
187   GBool findText(Unicode *s, int len,
188                  GBool top, GBool bottom,
189                  double *xMin, double *yMin,
190                  double *xMax, double *yMax);
191
192 private:
193
194   TextOutputFunc outputFunc;    // output function
195   void *outputStream;           // output stream
196   GBool needClose;              // need to close the output file?
197                                 //   (only if outputStream is a FILE*)
198   TextPage *text;               // text for the current page
199   GBool rawOrder;               // keep text in content stream order
200   GBool ok;                     // set up ok?
201 };
202
203 #endif