1 // Copyright 2014 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
17 // Function: FPDFText_LoadPage
18 // Prepare information about all characters in a page.
20 // page - Handle to the page. Returned by FPDF_LoadPage function (in FPDFVIEW module).
22 // A handle to the text page information structure.
23 // NULL if something goes wrong.
25 // Application must call FPDFText_ClosePage to release the text page information.
27 DLLEXPORT FPDF_TEXTPAGE STDCALL FPDFText_LoadPage(FPDF_PAGE page);
29 // Function: FPDFText_ClosePage
30 // Release all resources allocated for a text page information structure.
32 // text_page - Handle to a text page information structure. Returned by FPDFText_LoadPage function.
36 DLLEXPORT void STDCALL FPDFText_ClosePage(FPDF_TEXTPAGE text_page);
38 // Function: FPDFText_CountChars
39 // Get number of characters in a page.
41 // text_page - Handle to a text page information structure. Returned by FPDFText_LoadPage function.
43 // Number of characters in the page. Return -1 for error.
44 // Generated characters, like additional space characters, new line characters, are also counted.
46 // Characters in a page form a "stream", inside the stream, each character has an index.
47 // We will use the index parameters in many of FPDFTEXT functions. The first character in the page
48 // has an index value of zero.
50 DLLEXPORT int STDCALL FPDFText_CountChars(FPDF_TEXTPAGE text_page);
52 // Function: FPDFText_GetUnicode
53 // Get Unicode of a character in a page.
55 // text_page - Handle to a text page information structure. Returned by FPDFText_LoadPage function.
56 // index - Zero-based index of the character.
58 // The Unicode of the particular character.
59 // If a character is not encoded in Unicode and Foxit engine can't convert to Unicode,
60 // the return value will be zero.
62 DLLEXPORT unsigned int STDCALL FPDFText_GetUnicode(FPDF_TEXTPAGE text_page, int index);
64 // Function: FPDFText_GetFontSize
65 // Get the font size of a particular character.
67 // text_page - Handle to a text page information structure. Returned by FPDFText_LoadPage function.
68 // index - Zero-based index of the character.
70 // The font size of the particular character, measured in points (about 1/72 inch).
71 // This is the typographic size of the font (so called "em size").
73 DLLEXPORT double STDCALL FPDFText_GetFontSize(FPDF_TEXTPAGE text_page, int index);
75 // Function: FPDFText_GetCharBox
76 // Get bounding box of a particular character.
78 // text_page - Handle to a text page information structure. Returned by FPDFText_LoadPage function.
79 // index - Zero-based index of the character.
80 // left - Pointer to a double number receiving left position of the character box.
81 // right - Pointer to a double number receiving right position of the character box.
82 // bottom - Pointer to a double number receiving bottom position of the character box.
83 // top - Pointer to a double number receiving top position of the character box.
87 // All positions are measured in PDF "user space".
89 DLLEXPORT void STDCALL FPDFText_GetCharBox(FPDF_TEXTPAGE text_page, int index, double* left,
90 double* right, double* bottom, double* top);
92 // Function: FPDFText_GetCharIndexAtPos
93 // Get the index of a character at or nearby a certain position on the page.
95 // text_page - Handle to a text page information structure. Returned by FPDFText_LoadPage function.
96 // x - X position in PDF "user space".
97 // y - Y position in PDF "user space".
98 // xTolerance - An x-axis tolerance value for character hit detection, in point unit.
99 // yTolerance - A y-axis tolerance value for character hit detection, in point unit.
101 // The zero-based index of the character at, or nearby the point (x,y).
102 // If there is no character at or nearby the point, return value will be -1.
103 // If an error occurs, -3 will be returned.
105 DLLEXPORT int STDCALL FPDFText_GetCharIndexAtPos(FPDF_TEXTPAGE text_page,
106 double x, double y, double xTorelance, double yTolerance);
108 // Function: FPDFText_GetText
109 // Extract unicode text string from the page.
111 // text_page - Handle to a text page information structure. Returned by FPDFText_LoadPage function.
112 // start_index - Index for the start characters.
113 // count - Number of characters to be extracted.
114 // result - A buffer (allocated by application) receiving the extracted unicodes.
115 // The size of the buffer must be able to hold the number of characters plus a terminator.
117 // Number of characters written into the result buffer, including the trailing terminator.
119 // This function ignores characters without unicode information.
121 DLLEXPORT int STDCALL FPDFText_GetText(FPDF_TEXTPAGE text_page, int start_index, int count, unsigned short* result);
123 // Function: FPDFText_CountRects
124 // Count number of rectangular areas occupied by a segment of texts.
126 // text_page - Handle to a text page information structure. Returned by FPDFText_LoadPage function.
127 // start_index - Index for the start characters.
128 // count - Number of characters.
130 // Number of rectangles. Zero for error.
132 // This function, along with FPDFText_GetRect can be used by applications to detect the position
133 // on the page for a text segment, so proper areas can be highlighted or something.
134 // FPDFTEXT will automatically merge small character boxes into bigger one if those characters
135 // are on the same line and use same font settings.
137 DLLEXPORT int STDCALL FPDFText_CountRects(FPDF_TEXTPAGE text_page, int start_index, int count);
139 // Function: FPDFText_GetRect
140 // Get a rectangular area from the result generated by FPDFText_CountRects.
142 // text_page - Handle to a text page information structure. Returned by FPDFText_LoadPage function.
143 // rect_index - Zero-based index for the rectangle.
144 // left - Pointer to a double value receiving the rectangle left boundary.
145 // top - Pointer to a double value receiving the rectangle top boundary.
146 // right - Pointer to a double value receiving the rectangle right boundary.
147 // bottom - Pointer to a double value receiving the rectangle bottom boundary.
151 DLLEXPORT void STDCALL FPDFText_GetRect(FPDF_TEXTPAGE text_page, int rect_index, double* left, double* top,
152 double* right, double* bottom);
154 // Function: FPDFText_GetBoundedText
155 // Extract unicode text within a rectangular boundary on the page.
157 // text_page - Handle to a text page information structure. Returned by FPDFText_LoadPage function.
158 // left - Left boundary.
159 // top - Top boundary.
160 // right - Right boundary.
161 // bottom - Bottom boundary.
162 // buffer - A unicode buffer.
163 // buflen - Number of characters (not bytes) for the buffer, excluding an additional terminator.
165 // If buffer is NULL or buflen is zero, return number of characters (not bytes) of text present within
166 // the rectangle, excluding a terminating NUL. Generally you should pass a buffer at least one larger
167 // than this if you want a terminating NUL, which will be provided if space is available.
168 // Otherwise, return number of characters copied into the buffer, including the terminating NUL
169 // when space for it is available.
171 // If the buffer is too small, as much text as will fit is copied into it.
173 DLLEXPORT int STDCALL FPDFText_GetBoundedText(FPDF_TEXTPAGE text_page,double left, double top,
174 double right, double bottom,unsigned short* buffer,int buflen);
177 // Flags used by FPDFText_FindStart function.
178 #define FPDF_MATCHCASE 0x00000001 //If not set, it will not match case by default.
179 #define FPDF_MATCHWHOLEWORD 0x00000002 //If not set, it will not match the whole word by default.
181 // Function: FPDFText_FindStart
184 // text_page - Handle to a text page information structure. Returned by FPDFText_LoadPage function.
185 // findwhat - A unicode match pattern.
186 // flags - Option flags.
187 // start_index - Start from this character. -1 for end of the page.
189 // A handle for the search context. FPDFText_FindClose must be called to release this handle.
191 DLLEXPORT FPDF_SCHHANDLE STDCALL FPDFText_FindStart(FPDF_TEXTPAGE text_page, FPDF_WIDESTRING findwhat,
192 unsigned long flags, int start_index);
194 // Function: FPDFText_FindNext
195 // Search in the direction from page start to end.
197 // handle - A search context handle returned by FPDFText_FindStart.
199 // Whether a match is found.
201 DLLEXPORT FPDF_BOOL STDCALL FPDFText_FindNext(FPDF_SCHHANDLE handle);
203 // Function: FPDFText_FindPrev
204 // Search in the direction from page end to start.
206 // handle - A search context handle returned by FPDFText_FindStart.
208 // Whether a match is found.
210 DLLEXPORT FPDF_BOOL STDCALL FPDFText_FindPrev(FPDF_SCHHANDLE handle);
212 // Function: FPDFText_GetSchResultIndex
213 // Get the starting character index of the search result.
215 // handle - A search context handle returned by FPDFText_FindStart.
217 // Index for the starting character.
219 DLLEXPORT int STDCALL FPDFText_GetSchResultIndex(FPDF_SCHHANDLE handle);
221 // Function: FPDFText_GetSchCount
222 // Get the number of matched characters in the search result.
224 // handle - A search context handle returned by FPDFText_FindStart.
226 // Number of matched characters.
228 DLLEXPORT int STDCALL FPDFText_GetSchCount(FPDF_SCHHANDLE handle);
230 // Function: FPDFText_FindClose
231 // Release a search context.
233 // handle - A search context handle returned by FPDFText_FindStart.
237 DLLEXPORT void STDCALL FPDFText_FindClose(FPDF_SCHHANDLE handle);
239 // Function: FPDFLink_LoadWebLinks
240 // Prepare information about weblinks in a page.
242 // text_page - Handle to a text page information structure. Returned by FPDFText_LoadPage function.
244 // A handle to the page's links information structure.
245 // NULL if something goes wrong.
247 // Weblinks are those links implicitly embedded in PDF pages. PDF also has a type of
248 // annotation called "link", FPDFTEXT doesn't deal with that kind of link.
249 // FPDFTEXT weblink feature is useful for automatically detecting links in the page
250 // contents. For example, things like "http://www.foxitsoftware.com" will be detected,
251 // so applications can allow user to click on those characters to activate the link,
252 // even the PDF doesn't come with link annotations.
254 // FPDFLink_CloseWebLinks must be called to release resources.
256 DLLEXPORT FPDF_PAGELINK STDCALL FPDFLink_LoadWebLinks(FPDF_TEXTPAGE text_page);
258 // Function: FPDFLink_CountWebLinks
259 // Count number of detected web links.
261 // link_page - Handle returned by FPDFLink_LoadWebLinks.
263 // Number of detected web links.
265 DLLEXPORT int STDCALL FPDFLink_CountWebLinks(FPDF_PAGELINK link_page);
267 // Function: FPDFLink_GetURL
268 // Fetch the URL information for a detected web link.
270 // link_page - Handle returned by FPDFLink_LoadWebLinks.
271 // link_index - Zero-based index for the link.
272 // buffer - A unicode buffer.
273 // buflen - Number of characters (not bytes) for the buffer, including an additional terminator.
275 // If buffer is NULL or buflen is zero, return number of characters (not bytes and an additional terminator is also counted) needed,
276 // otherwise, return number of characters copied into the buffer.
278 DLLEXPORT int STDCALL FPDFLink_GetURL(FPDF_PAGELINK link_page, int link_index, unsigned short* buffer,int buflen);
280 // Function: FPDFLink_CountRects
281 // Count number of rectangular areas for the link.
283 // link_page - Handle returned by FPDFLink_LoadWebLinks.
284 // link_index - Zero-based index for the link.
286 // Number of rectangular areas for the link.
288 DLLEXPORT int STDCALL FPDFLink_CountRects(FPDF_PAGELINK link_page, int link_index);
290 // Function: FPDFLink_GetRect
291 // Fetch the boundaries of a rectangle for a link.
293 // link_page - Handle returned by FPDFLink_LoadWebLinks.
294 // link_index - Zero-based index for the link.
295 // rect_index - Zero-based index for a rectangle.
296 // left - Pointer to a double value receiving the rectangle left boundary.
297 // top - Pointer to a double value receiving the rectangle top boundary.
298 // right - Pointer to a double value receiving the rectangle right boundary.
299 // bottom - Pointer to a double value receiving the rectangle bottom boundary.
303 DLLEXPORT void STDCALL FPDFLink_GetRect(FPDF_PAGELINK link_page, int link_index, int rect_index,
304 double* left, double* top,double* right, double* bottom);
306 // Function: FPDFLink_CloseWebLinks
307 // Release resources used by weblink feature.
309 // link_page - Handle returned by FPDFLink_LoadWebLinks.
313 DLLEXPORT void STDCALL FPDFLink_CloseWebLinks(FPDF_PAGELINK link_page);