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.
4 
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6 
7 // NOTE: External docs refer to this file as "fpdfview.h", so do not rename
8 // despite lack of consitency with other public files.
9 
10 #ifndef PUBLIC_FPDFVIEW_H_
11 #define PUBLIC_FPDFVIEW_H_
12 
13 #if defined(_WIN32) && !defined(__WINDOWS__)
14 #include <windows.h>
15 #endif
16 
17 #ifdef PDF_ENABLE_XFA
18 //  TODO: remove the #define when XFA is officially in pdfium
19 #define PDF_USE_XFA
20 #endif  // PDF_ENABLE_XFA
21 
22 // PDF types
23 typedef void* FPDF_ACTION;
24 typedef void* FPDF_BITMAP;
25 typedef void* FPDF_BOOKMARK;
26 typedef void* FPDF_CLIPPATH;
27 typedef void* FPDF_DEST;
28 typedef void* FPDF_DOCSCHHANDLE;
29 typedef void* FPDF_DOCUMENT;
30 typedef void* FPDF_FONT;
31 typedef void* FPDF_HMODULE;
32 typedef void* FPDF_LINK;
33 typedef void* FPDF_MODULEMGR;
34 typedef void* FPDF_PAGE;
35 typedef void* FPDF_PAGELINK;
36 typedef void* FPDF_PAGEOBJECT;  // Page object(text, path, etc)
37 typedef void* FPDF_PAGERANGE;
38 typedef void* FPDF_PATH;
39 typedef void* FPDF_SCHHANDLE;
40 typedef void* FPDF_TEXTPAGE;
41 
42 #ifdef PDF_ENABLE_XFA
43 typedef void* FPDF_STRINGHANDLE;
44 typedef void* FPDF_WIDGET;
45 #endif  // PDF_ENABLE_XFA
46 
47 // Basic data types
48 typedef int FPDF_BOOL;
49 typedef int FPDF_ERROR;
50 typedef unsigned long FPDF_DWORD;
51 typedef float FS_FLOAT;
52 
53 #ifdef PDF_ENABLE_XFA
54 typedef void* FPDF_LPVOID;
55 typedef void const* FPDF_LPCVOID;
56 typedef char const* FPDF_LPCSTR;
57 typedef int FPDF_RESULT;
58 #endif
59 
60 // Duplex types
61 typedef enum _FPDF_DUPLEXTYPE_ {
62   DuplexUndefined = 0,
63   Simplex,
64   DuplexFlipShortEdge,
65   DuplexFlipLongEdge
66 } FPDF_DUPLEXTYPE;
67 
68 // String types
69 typedef unsigned short FPDF_WCHAR;
70 typedef unsigned char const* FPDF_LPCBYTE;
71 
72 // FPDFSDK may use three types of strings: byte string, wide string (UTF-16LE
73 // encoded), and platform dependent string
74 typedef const char* FPDF_BYTESTRING;
75 
76 // FPDFSDK always uses UTF-16LE encoded wide strings, each character uses 2
77 // bytes (except surrogation), with the low byte first.
78 typedef const unsigned short* FPDF_WIDESTRING;
79 
80 #ifdef PDF_ENABLE_XFA
81 // Structure for a byte string.
82 // Note, a byte string commonly means a UTF-16LE formated string.
83 typedef struct _FPDF_BSTR {
84   // String buffer.
85   char* str;
86   // Length of the string, in bytes.
87   int len;
88 } FPDF_BSTR;
89 #endif  // PDF_ENABLE_XFA
90 
91 // For Windows programmers: In most cases it's OK to treat FPDF_WIDESTRING as a
92 // Windows unicode string, however, special care needs to be taken if you
93 // expect to process Unicode larger than 0xffff.
94 //
95 // For Linux/Unix programmers: most compiler/library environments use 4 bytes
96 // for a Unicode character, and you have to convert between FPDF_WIDESTRING and
97 // system wide string by yourself.
98 #ifdef _WIN32_WCE
99 typedef const unsigned short* FPDF_STRING;
100 #else
101 typedef const char* FPDF_STRING;
102 #endif
103 
104 // Matrix for transformation.
105 typedef struct _FS_MATRIX_ {
106   float a;
107   float b;
108   float c;
109   float d;
110   float e;
111   float f;
112 } FS_MATRIX;
113 
114 // Rectangle area(float) in device or page coordinate system.
115 typedef struct _FS_RECTF_ {
116   // The x-coordinate of the left-top corner.
117   float left;
118   // The y-coordinate of the left-top corner.
119   float top;
120   // The x-coordinate of the right-bottom corner.
121   float right;
122   // The y-coordinate of the right-bottom corner.
123   float bottom;
124 } * FS_LPRECTF, FS_RECTF;
125 
126 // Const Pointer to FS_RECTF structure.
127 typedef const FS_RECTF* FS_LPCRECTF;
128 
129 #if defined(_WIN32) && defined(FPDFSDK_EXPORTS)
130 // On Windows system, functions are exported in a DLL
131 #define DLLEXPORT __declspec(dllexport)
132 #define STDCALL __stdcall
133 #else
134 #define DLLEXPORT
135 #define STDCALL
136 #endif
137 
138 // Exported Functions
139 #ifdef __cplusplus
140 extern "C" {
141 #endif
142 
143 // Function: FPDF_InitLibrary
144 //          Initialize the FPDFSDK library
145 // Parameters:
146 //          None
147 // Return value:
148 //          None.
149 // Comments:
150 //          Convenience function to call FPDF_InitLibraryWithConfig() for
151 //          backwards comatibility purposes.
152 DLLEXPORT void STDCALL FPDF_InitLibrary();
153 
154 // Process-wide options for initializing the library.
155 typedef struct FPDF_LIBRARY_CONFIG_ {
156   // Version number of the interface. Currently must be 2.
157   int version;
158 
159   // Array of paths to scan in place of the defaults when using built-in
160   // FXGE font loading code. The array is terminated by a NULL pointer.
161   // The Array may be NULL itself to use the default paths. May be ignored
162   // entirely depending upon the platform.
163   const char** m_pUserFontPaths;
164 
165   // Version 2.
166 
167   // pointer to the v8::Isolate to use, or NULL to force PDFium to create one.
168   void* m_pIsolate;
169 
170   // The embedder data slot to use in the v8::Isolate to store PDFium's
171   // per-isolate data. The value needs to be between 0 and
172   // v8::Internals::kNumIsolateDataLots (exclusive). Note that 0 is fine
173   // for most embedders.
174   unsigned int m_v8EmbedderSlot;
175 } FPDF_LIBRARY_CONFIG;
176 
177 // Function: FPDF_InitLibraryWithConfig
178 //          Initialize the FPDFSDK library
179 // Parameters:
180 //          config - configuration information as above.
181 // Return value:
182 //          None.
183 // Comments:
184 //          You have to call this function before you can call any PDF
185 //          processing functions.
186 DLLEXPORT void STDCALL FPDF_InitLibraryWithConfig(
187     const FPDF_LIBRARY_CONFIG* config);
188 
189 // Function: FPDF_DestroyLibary
190 //          Release all resources allocated by the FPDFSDK library.
191 // Parameters:
192 //          None.
193 // Return value:
194 //          None.
195 // Comments:
196 //          You can call this function to release all memory blocks allocated by
197 //          the library.
198 //          After this function is called, you should not call any PDF
199 //          processing functions.
200 DLLEXPORT void STDCALL FPDF_DestroyLibrary();
201 
202 // Policy for accessing the local machine time.
203 #define FPDF_POLICY_MACHINETIME_ACCESS 0
204 
205 // Function: FPDF_SetSandBoxPolicy
206 //          Set the policy for the sandbox environment.
207 // Parameters:
208 //          policy -   The specified policy for setting, for example:
209 //                     FPDF_POLICY_MACHINETIME_ACCESS.
210 //          enable -   True to enable, false to disable the policy.
211 // Return value:
212 //          None.
213 DLLEXPORT void STDCALL FPDF_SetSandBoxPolicy(FPDF_DWORD policy,
214                                              FPDF_BOOL enable);
215 
216 // Function: FPDF_LoadDocument
217 //          Open and load a PDF document.
218 // Parameters:
219 //          file_path -  Path to the PDF file (including extension).
220 //          password  -  A string used as the password for the PDF file.
221 //                       If no password is needed, empty or NULL can be used.
222 // Return value:
223 //          A handle to the loaded document, or NULL on failure.
224 // Comments:
225 //          Loaded document can be closed by FPDF_CloseDocument().
226 //          If this function fails, you can use FPDF_GetLastError() to retrieve
227 //          the reason why it failed.
228 DLLEXPORT FPDF_DOCUMENT STDCALL FPDF_LoadDocument(FPDF_STRING file_path,
229                                                   FPDF_BYTESTRING password);
230 
231 // Function: FPDF_LoadMemDocument
232 //          Open and load a PDF document from memory.
233 // Parameters:
234 //          data_buf    -   Pointer to a buffer containing the PDF document.
235 //          size        -   Number of bytes in the PDF document.
236 //          password    -   A string used as the password for the PDF file.
237 //                          If no password is needed, empty or NULL can be used.
238 // Return value:
239 //          A handle to the loaded document, or NULL on failure.
240 // Comments:
241 //          The memory buffer must remain valid when the document is open.
242 //          The loaded document can be closed by FPDF_CloseDocument.
243 //          If this function fails, you can use FPDF_GetLastError() to retrieve
244 //          the reason why it failed.
245 // Notes:
246 //          If PDFium is built with the XFA module, the application should call
247 //          FPDF_LoadXFA() function after the PDF document loaded to support XFA
248 //          fields defined in the fpdfformfill.h file.
249 DLLEXPORT FPDF_DOCUMENT STDCALL FPDF_LoadMemDocument(const void* data_buf,
250                                                      int size,
251                                                      FPDF_BYTESTRING password);
252 
253 // Structure for custom file access.
254 typedef struct {
255   // File length, in bytes.
256   unsigned long m_FileLen;
257 
258   // A function pointer for getting a block of data from a specific position.
259   // Position is specified by byte offset from the beginning of the file.
260   // The position and size will never go out of range of the file length.
261   // It may be possible for FPDFSDK to call this function multiple times for
262   // the same position.
263   // Return value: should be non-zero if successful, zero for error.
264   int (*m_GetBlock)(void* param,
265                     unsigned long position,
266                     unsigned char* pBuf,
267                     unsigned long size);
268 
269   // A custom pointer for all implementation specific data.  This pointer will
270   // be used as the first parameter to the m_GetBlock callback.
271   void* m_Param;
272 } FPDF_FILEACCESS;
273 
274 #ifdef PDF_ENABLE_XFA
275 /**
276  * @brief Structure for file reading or writing (I/O).
277  *
278  * @note This is a handler and should be implemented by callers.
279  */
280 typedef struct _FPDF_FILEHANDLER {
281   /**
282    * @brief User-defined data.
283    * @note Callers can use this field to track controls.
284    */
285   FPDF_LPVOID clientData;
286   /**
287    * @brief Callback function to release the current file stream object.
288    *
289    * @param[in] clientData    Pointer to user-defined data.
290    *
291    * @return None.
292    */
293   void (*Release)(FPDF_LPVOID clientData);
294   /**
295    * @brief Callback function to retrieve the current file stream size.
296    *
297    * @param[in] clientData    Pointer to user-defined data.
298    *
299    * @return Size of file stream.
300    */
301   FPDF_DWORD (*GetSize)(FPDF_LPVOID clientData);
302   /**
303    * @brief Callback function to read data from the current file stream.
304    *
305    * @param[in]   clientData  Pointer to user-defined data.
306    * @param[in]   offset      Offset position starts from the beginning of file
307    * stream. This parameter indicates reading position.
308    * @param[in]   buffer      Memory buffer to store data which are read from
309    * file stream. This parameter should not be <b>NULL</b>.
310    * @param[in]   size        Size of data which should be read from file
311    * stream, in bytes. The buffer indicated by the parameter <i>buffer</i>
312    * should be enough to store specified data.
313    *
314    * @return 0 for success, other value for failure.
315    */
316   FPDF_RESULT (*ReadBlock)(FPDF_LPVOID clientData, FPDF_DWORD offset, FPDF_LPVOID buffer, FPDF_DWORD size);
317   /**
318    * @brief   Callback function to write data into the current file stream.
319    *
320    * @param[in]   clientData  Pointer to user-defined data.
321    * @param[in]   offset      Offset position starts from the beginning of file
322    * stream. This parameter indicates writing position.
323    * @param[in]   buffer      Memory buffer contains data which is written into
324    * file stream. This parameter should not be <b>NULL</b>.
325    * @param[in]   size        Size of data which should be written into file
326    * stream, in bytes.
327    *
328    * @return 0 for success, other value for failure.
329    */
330   FPDF_RESULT (*WriteBlock)(FPDF_LPVOID clientData, FPDF_DWORD offset, FPDF_LPCVOID buffer, FPDF_DWORD size);
331   /**
332    * @brief   Callback function to flush all internal accessing buffers.
333    *
334    * @param[in]   clientData  Pointer to user-defined data.
335    *
336    * @return 0 for success, other value for failure.
337    */
338   FPDF_RESULT (*Flush)(FPDF_LPVOID clientData);
339   /**
340    * @brief   Callback function to change file size.
341    *
342    * @details This function is called under writing mode usually. Implementer
343    * can determine whether to realize it based on application requests.
344    *
345    * @param[in]   clientData  Pointer to user-defined data.
346    * @param[in]   size        New size of file stream, in bytes.
347    *
348    * @return 0 for success, other value for failure.
349    */
350   FPDF_RESULT (*Truncate)(FPDF_LPVOID clientData, FPDF_DWORD size);
351 
352 } FPDF_FILEHANDLER, *FPDF_LPFILEHANDLER;
353 
354 #endif
355 // Function: FPDF_LoadCustomDocument
356 //          Load PDF document from a custom access descriptor.
357 // Parameters:
358 //          pFileAccess -   A structure for accessing the file.
359 //          password    -   Optional password for decrypting the PDF file.
360 // Return value:
361 //          A handle to the loaded document, or NULL on failure.
362 // Comments:
363 //          The application must keep the file resources valid until the PDF
364 //          document is closed.
365 //
366 //          The loaded document can be closed with FPDF_CloseDocument.
367 // Notes:
368 //          If PDFium is built with the XFA module, the application should call
369 //          FPDF_LoadXFA() function after the PDF document loaded to support XFA
370 //          fields defined in the fpdfformfill.h file.
371 DLLEXPORT FPDF_DOCUMENT STDCALL
372 FPDF_LoadCustomDocument(FPDF_FILEACCESS* pFileAccess, FPDF_BYTESTRING password);
373 
374 // Function: FPDF_GetFileVersion
375 //          Get the file version of the given PDF document.
376 // Parameters:
377 //          doc         -   Handle to a document.
378 //          fileVersion -   The PDF file version. File version: 14 for 1.4, 15
379 //                          for 1.5, ...
380 // Return value:
381 //          True if succeeds, false otherwise.
382 // Comments:
383 //          If the document was created by FPDF_CreateNewDocument,
384 //          then this function will always fail.
385 DLLEXPORT FPDF_BOOL STDCALL FPDF_GetFileVersion(FPDF_DOCUMENT doc,
386                                                 int* fileVersion);
387 
388 #define FPDF_ERR_SUCCESS 0    // No error.
389 #define FPDF_ERR_UNKNOWN 1    // Unknown error.
390 #define FPDF_ERR_FILE 2       // File not found or could not be opened.
391 #define FPDF_ERR_FORMAT 3     // File not in PDF format or corrupted.
392 #define FPDF_ERR_PASSWORD 4   // Password required or incorrect password.
393 #define FPDF_ERR_SECURITY 5   // Unsupported security scheme.
394 #define FPDF_ERR_PAGE 6       // Page not found or content error.
395 #ifdef PDF_ENABLE_XFA
396 #define FPDF_ERR_XFALOAD 7    // Load XFA error.
397 #define FPDF_ERR_XFALAYOUT 8  // Layout XFA error.
398 #endif  // PDF_ENABLE_XFA
399 
400 // Function: FPDF_GetLastError
401 //          Get last error code when a function fails.
402 // Parameters:
403 //          None.
404 // Return value:
405 //          A 32-bit integer indicating error code as defined above.
406 // Comments:
407 //          If the previous SDK call succeeded, the return value of this
408 //          function is not defined.
409 DLLEXPORT unsigned long STDCALL FPDF_GetLastError();
410 
411 // Function: FPDF_GetDocPermission
412 //          Get file permission flags of the document.
413 // Parameters:
414 //          document    -   Handle to a document. Returned by FPDF_LoadDocument.
415 // Return value:
416 //          A 32-bit integer indicating permission flags. Please refer to the
417 //          PDF Reference for detailed descriptions. If the document is not
418 //          protected, 0xffffffff will be returned.
419 DLLEXPORT unsigned long STDCALL FPDF_GetDocPermissions(FPDF_DOCUMENT document);
420 
421 // Function: FPDF_GetSecurityHandlerRevision
422 //          Get the revision for the security handler.
423 // Parameters:
424 //          document    -   Handle to a document. Returned by FPDF_LoadDocument.
425 // Return value:
426 //          The security handler revision number. Please refer to the PDF
427 //          Reference for a detailed description. If the document is not
428 //          protected, -1 will be returned.
429 DLLEXPORT int STDCALL FPDF_GetSecurityHandlerRevision(FPDF_DOCUMENT document);
430 
431 // Function: FPDF_GetPageCount
432 //          Get total number of pages in the document.
433 // Parameters:
434 //          document    -   Handle to document. Returned by FPDF_LoadDocument.
435 // Return value:
436 //          Total number of pages in the document.
437 DLLEXPORT int STDCALL FPDF_GetPageCount(FPDF_DOCUMENT document);
438 
439 // Function: FPDF_LoadPage
440 //          Load a page inside the document.
441 // Parameters:
442 //          document    -   Handle to document. Returned by FPDF_LoadDocument
443 //          page_index  -   Index number of the page. 0 for the first page.
444 // Return value:
445 //          A handle to the loaded page, or NULL if page load fails.
446 // Comments:
447 //          The loaded page can be rendered to devices using FPDF_RenderPage.
448 //          The loaded page can be closed using FPDF_ClosePage.
449 DLLEXPORT FPDF_PAGE STDCALL FPDF_LoadPage(FPDF_DOCUMENT document,
450                                           int page_index);
451 
452 // Function: FPDF_GetPageWidth
453 //          Get page width.
454 // Parameters:
455 //          page        -   Handle to the page. Returned by FPDF_LoadPage.
456 // Return value:
457 //          Page width (excluding non-displayable area) measured in points.
458 //          One point is 1/72 inch (around 0.3528 mm).
459 DLLEXPORT double STDCALL FPDF_GetPageWidth(FPDF_PAGE page);
460 
461 // Function: FPDF_GetPageHeight
462 //          Get page height.
463 // Parameters:
464 //          page        -   Handle to the page. Returned by FPDF_LoadPage.
465 // Return value:
466 //          Page height (excluding non-displayable area) measured in points.
467 //          One point is 1/72 inch (around 0.3528 mm)
468 DLLEXPORT double STDCALL FPDF_GetPageHeight(FPDF_PAGE page);
469 
470 // Function: FPDF_GetPageSizeByIndex
471 //          Get the size of the page at the given index.
472 // Parameters:
473 //          document    -   Handle to document. Returned by FPDF_LoadDocument.
474 //          page_index  -   Page index, zero for the first page.
475 //          width       -   Pointer to a double to receive the page width
476 //                          (in points).
477 //          height      -   Pointer to a double to receive the page height
478 //                          (in points).
479 // Return value:
480 //          Non-zero for success. 0 for error (document or page not found).
481 DLLEXPORT int STDCALL FPDF_GetPageSizeByIndex(FPDF_DOCUMENT document,
482                                               int page_index,
483                                               double* width,
484                                               double* height);
485 
486 // Page rendering flags. They can be combined with bit-wise OR.
487 //
488 // Set if annotations are to be rendered.
489 #define FPDF_ANNOT 0x01
490 // Set if using text rendering optimized for LCD display.
491 #define FPDF_LCD_TEXT 0x02
492 // Don't use the native text output available on some platforms
493 #define FPDF_NO_NATIVETEXT 0x04
494 // Grayscale output.
495 #define FPDF_GRAYSCALE 0x08
496 // Set if you want to get some debug info.
497 #define FPDF_DEBUG_INFO 0x80
498 // Set if you don't want to catch exceptions.
499 #define FPDF_NO_CATCH 0x100
500 // Limit image cache size.
501 #define FPDF_RENDER_LIMITEDIMAGECACHE 0x200
502 // Always use halftone for image stretching.
503 #define FPDF_RENDER_FORCEHALFTONE 0x400
504 // Render for printing.
505 #define FPDF_PRINTING 0x800
506 // Set to disable anti-aliasing on text.
507 #define FPDF_RENDER_NO_SMOOTHTEXT 0x1000
508 // Set to disable anti-aliasing on images.
509 #define FPDF_RENDER_NO_SMOOTHIMAGE 0x2000
510 // Set to disable anti-aliasing on paths.
511 #define FPDF_RENDER_NO_SMOOTHPATH 0x4000
512 // Set whether to render in a reverse Byte order, this flag is only used when
513 // rendering to a bitmap.
514 #define FPDF_REVERSE_BYTE_ORDER 0x10
515 
516 #ifdef _WIN32
517 // Function: FPDF_RenderPage
518 //          Render contents of a page to a device (screen, bitmap, or printer).
519 //          This function is only supported on Windows.
520 // Parameters:
521 //          dc          -   Handle to the device context.
522 //          page        -   Handle to the page. Returned by FPDF_LoadPage.
523 //          start_x     -   Left pixel position of the display area in
524 //                          device coordinates.
525 //          start_y     -   Top pixel position of the display area in device
526 //                          coordinates.
527 //          size_x      -   Horizontal size (in pixels) for displaying the page.
528 //          size_y      -   Vertical size (in pixels) for displaying the page.
529 //          rotate      -   Page orientation:
530 //                            0 (normal)
531 //                            1 (rotated 90 degrees clockwise)
532 //                            2 (rotated 180 degrees)
533 //                            3 (rotated 90 degrees counter-clockwise)
534 //          flags       -   0 for normal display, or combination of flags
535 //                          defined above.
536 // Return value:
537 //          None.
538 DLLEXPORT void STDCALL FPDF_RenderPage(HDC dc,
539                                        FPDF_PAGE page,
540                                        int start_x,
541                                        int start_y,
542                                        int size_x,
543                                        int size_y,
544                                        int rotate,
545                                        int flags);
546 #endif
547 
548 // Function: FPDF_RenderPageBitmap
549 //          Render contents of a page to a device independent bitmap.
550 // Parameters:
551 //          bitmap      -   Handle to the device independent bitmap (as the
552 //                          output buffer). The bitmap handle can be created
553 //                          by FPDFBitmap_Create.
554 //          page        -   Handle to the page. Returned by FPDF_LoadPage
555 //          start_x     -   Left pixel position of the display area in
556 //                          bitmap coordinates.
557 //          start_y     -   Top pixel position of the display area in bitmap
558 //                          coordinates.
559 //          size_x      -   Horizontal size (in pixels) for displaying the page.
560 //          size_y      -   Vertical size (in pixels) for displaying the page.
561 //          rotate      -   Page orientation:
562 //                            0 (normal)
563 //                            1 (rotated 90 degrees clockwise)
564 //                            2 (rotated 180 degrees)
565 //                            3 (rotated 90 degrees counter-clockwise)
566 //          flags       -   0 for normal display, or combination of flags
567 //                          defined above.
568 // Return value:
569 //          None.
570 DLLEXPORT void STDCALL FPDF_RenderPageBitmap(FPDF_BITMAP bitmap,
571                                              FPDF_PAGE page,
572                                              int start_x,
573                                              int start_y,
574                                              int size_x,
575                                              int size_y,
576                                              int rotate,
577                                              int flags);
578 
579 // Function: FPDF_ClosePage
580 //          Close a loaded PDF page.
581 // Parameters:
582 //          page        -   Handle to the loaded page.
583 // Return value:
584 //          None.
585 DLLEXPORT void STDCALL FPDF_ClosePage(FPDF_PAGE page);
586 
587 // Function: FPDF_CloseDocument
588 //          Close a loaded PDF document.
589 // Parameters:
590 //          document    -   Handle to the loaded document.
591 // Return value:
592 //          None.
593 DLLEXPORT void STDCALL FPDF_CloseDocument(FPDF_DOCUMENT document);
594 
595 // Function: FPDF_DeviceToPage
596 //          Convert the screen coordinates of a point to page coordinates.
597 // Parameters:
598 //          page        -   Handle to the page. Returned by FPDF_LoadPage.
599 //          start_x     -   Left pixel position of the display area in
600 //                          device coordinates.
601 //          start_y     -   Top pixel position of the display area in device
602 //                          coordinates.
603 //          size_x      -   Horizontal size (in pixels) for displaying the page.
604 //          size_y      -   Vertical size (in pixels) for displaying the page.
605 //          rotate      -   Page orientation:
606 //                            0 (normal)
607 //                            1 (rotated 90 degrees clockwise)
608 //                            2 (rotated 180 degrees)
609 //                            3 (rotated 90 degrees counter-clockwise)
610 //          device_x    -   X value in device coordinates to be converted.
611 //          device_y    -   Y value in device coordinates to be converted.
612 //          page_x      -   A pointer to a double receiving the converted X
613 //                          value in page coordinates.
614 //          page_y      -   A pointer to a double receiving the converted Y
615 //                          value in page coordinates.
616 // Return value:
617 //          None.
618 // Comments:
619 //          The page coordinate system has its origin at the left-bottom corner
620 //          of the page, with the X-axis on the bottom going to the right, and
621 //          the Y-axis on the left side going up.
622 //
623 //          NOTE: this coordinate system can be altered when you zoom, scroll,
624 //          or rotate a page, however, a point on the page should always have
625 //          the same coordinate values in the page coordinate system.
626 //
627 //          The device coordinate system is device dependent. For screen device,
628 //          its origin is at the left-top corner of the window. However this
629 //          origin can be altered by the Windows coordinate transformation
630 //          utilities.
631 //
632 //          You must make sure the start_x, start_y, size_x, size_y
633 //          and rotate parameters have exactly same values as you used in
634 //          the FPDF_RenderPage() function call.
635 DLLEXPORT void STDCALL FPDF_DeviceToPage(FPDF_PAGE page,
636                                          int start_x,
637                                          int start_y,
638                                          int size_x,
639                                          int size_y,
640                                          int rotate,
641                                          int device_x,
642                                          int device_y,
643                                          double* page_x,
644                                          double* page_y);
645 
646 // Function: FPDF_PageToDevice
647 //          Convert the page coordinates of a point to screen coordinates.
648 // Parameters:
649 //          page        -   Handle to the page. Returned by FPDF_LoadPage.
650 //          start_x     -   Left pixel position of the display area in
651 //                          device coordinates.
652 //          start_y     -   Top pixel position of the display area in device
653 //                          coordinates.
654 //          size_x      -   Horizontal size (in pixels) for displaying the page.
655 //          size_y      -   Vertical size (in pixels) for displaying the page.
656 //          rotate      -   Page orientation:
657 //                            0 (normal)
658 //                            1 (rotated 90 degrees clockwise)
659 //                            2 (rotated 180 degrees)
660 //                            3 (rotated 90 degrees counter-clockwise)
661 //          page_x      -   X value in page coordinates.
662 //          page_y      -   Y value in page coordinate.
663 //          device_x    -   A pointer to an integer receiving the result X
664 //                          value in device coordinates.
665 //          device_y    -   A pointer to an integer receiving the result Y
666 //                          value in device coordinates.
667 // Return value:
668 //          None.
669 // Comments:
670 //          See comments for FPDF_DeviceToPage().
671 DLLEXPORT void STDCALL FPDF_PageToDevice(FPDF_PAGE page,
672                                          int start_x,
673                                          int start_y,
674                                          int size_x,
675                                          int size_y,
676                                          int rotate,
677                                          double page_x,
678                                          double page_y,
679                                          int* device_x,
680                                          int* device_y);
681 
682 // Function: FPDFBitmap_Create
683 //          Create a device independent bitmap (FXDIB).
684 // Parameters:
685 //          width       -   The number of pixels in width for the bitmap.
686 //                          Must be greater than 0.
687 //          height      -   The number of pixels in height for the bitmap.
688 //                          Must be greater than 0.
689 //          alpha       -   A flag indicating whether the alpha channel is used.
690 //                          Non-zero for using alpha, zero for not using.
691 // Return value:
692 //          The created bitmap handle, or NULL if a parameter error or out of
693 //          memory.
694 // Comments:
695 //          The bitmap always uses 4 bytes per pixel. The first byte is always
696 //          double word aligned.
697 //
698 //          The byte order is BGRx (the last byte unused if no alpha channel) or
699 //          BGRA.
700 //
701 //          The pixels in a horizontal line are stored side by side, with the
702 //          left most pixel stored first (with lower memory address).
703 //          Each line uses width * 4 bytes.
704 //
705 //          Lines are stored one after another, with the top most line stored
706 //          first. There is no gap between adjacent lines.
707 //
708 //          This function allocates enough memory for holding all pixels in the
709 //          bitmap, but it doesn't initialize the buffer. Applications can use
710 //          FPDFBitmap_FillRect to fill the bitmap using any color.
711 DLLEXPORT FPDF_BITMAP STDCALL FPDFBitmap_Create(int width,
712                                                 int height,
713                                                 int alpha);
714 
715 // More DIB formats
716 // Gray scale bitmap, one byte per pixel.
717 #define FPDFBitmap_Gray 1
718 // 3 bytes per pixel, byte order: blue, green, red.
719 #define FPDFBitmap_BGR 2
720 // 4 bytes per pixel, byte order: blue, green, red, unused.
721 #define FPDFBitmap_BGRx 3
722 // 4 bytes per pixel, byte order: blue, green, red, alpha.
723 #define FPDFBitmap_BGRA 4
724 
725 // Function: FPDFBitmap_CreateEx
726 //          Create a device independent bitmap (FXDIB)
727 // Parameters:
728 //          width       -   The number of pixels in width for the bitmap.
729 //                          Must be greater than 0.
730 //          height      -   The number of pixels in height for the bitmap.
731 //                          Must be greater than 0.
732 //          format      -   A number indicating for bitmap format, as defined
733 //                          above.
734 //          first_scan  -   A pointer to the first byte of the first line if
735 //                          using an external buffer. If this parameter is NULL,
736 //                          then the a new buffer will be created.
737 //          stride      -   Number of bytes for each scan line, for external
738 //                          buffer only.
739 // Return value:
740 //          The bitmap handle, or NULL if parameter error or out of memory.
741 // Comments:
742 //          Similar to FPDFBitmap_Create function, but allows for more formats
743 //          and an external buffer is supported. The bitmap created by this
744 //          function can be used in any place that a FPDF_BITMAP handle is
745 //          required.
746 //
747 //          If an external buffer is used, then the application should destroy
748 //          the buffer by itself. FPDFBitmap_Destroy function will not destroy
749 //          the buffer.
750 DLLEXPORT FPDF_BITMAP STDCALL FPDFBitmap_CreateEx(int width,
751                                                   int height,
752                                                   int format,
753                                                   void* first_scan,
754                                                   int stride);
755 
756 // Function: FPDFBitmap_FillRect
757 //          Fill a rectangle in a bitmap.
758 // Parameters:
759 //          bitmap      -   The handle to the bitmap. Returned by
760 //                          FPDFBitmap_Create.
761 //          left        -   The left position. Starting from 0 at the
762 //                          left-most pixel.
763 //          top         -   The top position. Starting from 0 at the
764 //                          top-most line.
765 //          width       -   Width in pixels to be filled.
766 //          height      -   Height in pixels to be filled.
767 //          color       -   A 32-bit value specifing the color, in 8888 ARGB
768 //                          format.
769 // Return value:
770 //          None.
771 // Comments:
772 //          This function sets the color and (optionally) alpha value in the
773 //          specified region of the bitmap.
774 //
775 //          NOTE: If the alpha channel is used, this function does NOT
776 //          composite the background with the source color, instead the
777 //          background will be replaced by the source color and the alpha.
778 //
779 //          If the alpha channel is not used, the alpha parameter is ignored.
780 DLLEXPORT void STDCALL FPDFBitmap_FillRect(FPDF_BITMAP bitmap,
781                                            int left,
782                                            int top,
783                                            int width,
784                                            int height,
785                                            FPDF_DWORD color);
786 
787 // Function: FPDFBitmap_GetBuffer
788 //          Get data buffer of a bitmap.
789 // Parameters:
790 //          bitmap      -   Handle to the bitmap. Returned by FPDFBitmap_Create.
791 // Return value:
792 //          The pointer to the first byte of the bitmap buffer.
793 // Comments:
794 //          The stride may be more than width * number of bytes per pixel
795 //
796 //          Applications can use this function to get the bitmap buffer pointer,
797 //          then manipulate any color and/or alpha values for any pixels in the
798 //          bitmap.
799 //
800 //          The data is in BGRA format. Where the A maybe unused if alpha was
801 //          not specified.
802 DLLEXPORT void* STDCALL FPDFBitmap_GetBuffer(FPDF_BITMAP bitmap);
803 
804 // Function: FPDFBitmap_GetWidth
805 //          Get width of a bitmap.
806 // Parameters:
807 //          bitmap      -   Handle to the bitmap. Returned by FPDFBitmap_Create.
808 // Return value:
809 //          The width of the bitmap in pixels.
810 DLLEXPORT int STDCALL FPDFBitmap_GetWidth(FPDF_BITMAP bitmap);
811 
812 // Function: FPDFBitmap_GetHeight
813 //          Get height of a bitmap.
814 // Parameters:
815 //          bitmap      -   Handle to the bitmap. Returned by FPDFBitmap_Create.
816 // Return value:
817 //          The height of the bitmap in pixels.
818 DLLEXPORT int STDCALL FPDFBitmap_GetHeight(FPDF_BITMAP bitmap);
819 
820 // Function: FPDFBitmap_GetStride
821 //          Get number of bytes for each line in the bitmap buffer.
822 // Parameters:
823 //          bitmap      -   Handle to the bitmap. Returned by FPDFBitmap_Create.
824 // Return value:
825 //          The number of bytes for each line in the bitmap buffer.
826 // Comments:
827 //          The stride may be more than width * number of bytes per pixel.
828 DLLEXPORT int STDCALL FPDFBitmap_GetStride(FPDF_BITMAP bitmap);
829 
830 // Function: FPDFBitmap_Destroy
831 //          Destroy a bitmap and release all related buffers.
832 // Parameters:
833 //          bitmap      -   Handle to the bitmap. Returned by FPDFBitmap_Create.
834 // Return value:
835 //          None.
836 // Comments:
837 //          This function will not destroy any external buffers provided when
838 //          the bitmap was created.
839 DLLEXPORT void STDCALL FPDFBitmap_Destroy(FPDF_BITMAP bitmap);
840 
841 // Function: FPDF_VIEWERREF_GetPrintScaling
842 //          Whether the PDF document prefers to be scaled or not.
843 // Parameters:
844 //          document    -   Handle to the loaded document.
845 // Return value:
846 //          None.
847 DLLEXPORT FPDF_BOOL STDCALL
848 FPDF_VIEWERREF_GetPrintScaling(FPDF_DOCUMENT document);
849 
850 // Function: FPDF_VIEWERREF_GetNumCopies
851 //          Returns the number of copies to be printed.
852 // Parameters:
853 //          document    -   Handle to the loaded document.
854 // Return value:
855 //          The number of copies to be printed.
856 DLLEXPORT int STDCALL FPDF_VIEWERREF_GetNumCopies(FPDF_DOCUMENT document);
857 
858 // Function: FPDF_VIEWERREF_GetPrintPageRange
859 //          Page numbers to initialize print dialog box when file is printed.
860 // Parameters:
861 //          document    -   Handle to the loaded document.
862 // Return value:
863 //          The print page range to be used for printing.
864 DLLEXPORT FPDF_PAGERANGE STDCALL
865 FPDF_VIEWERREF_GetPrintPageRange(FPDF_DOCUMENT document);
866 
867 // Function: FPDF_VIEWERREF_GetDuplex
868 //          Returns the paper handling option to be used when printing from
869 //          the print dialog.
870 // Parameters:
871 //          document    -   Handle to the loaded document.
872 // Return value:
873 //          The paper handling option to be used when printing.
874 DLLEXPORT FPDF_DUPLEXTYPE STDCALL
875 FPDF_VIEWERREF_GetDuplex(FPDF_DOCUMENT document);
876 
877 // Function: FPDF_CountNamedDests
878 //          Get the count of named destinations in the PDF document.
879 // Parameters:
880 //          document    -   Handle to a document
881 // Return value:
882 //          The count of named destinations.
883 DLLEXPORT FPDF_DWORD STDCALL FPDF_CountNamedDests(FPDF_DOCUMENT document);
884 
885 // Function: FPDF_GetNamedDestByName
886 //          Get a the destination handle for the given name.
887 // Parameters:
888 //          document    -   Handle to the loaded document.
889 //          name        -   The name of a destination.
890 // Return value:
891 //          The handle to the destination.
892 DLLEXPORT FPDF_DEST STDCALL FPDF_GetNamedDestByName(FPDF_DOCUMENT document,
893                                                     FPDF_BYTESTRING name);
894 
895 // Function: FPDF_GetNamedDest
896 //          Get the named destination by index.
897 // Parameters:
898 //          document        -   Handle to a document
899 //          index           -   The index of a named destination.
900 //          buffer          -   The buffer to store the destination name,
901 //                              used as wchar_t*.
902 //          buflen [in/out] -   Size of the buffer in bytes on input,
903 //                              length of the result in bytes on output
904 //                              or -1 if the buffer is too small.
905 // Return value:
906 //          The destination handle for a given index, or NULL if there is no
907 //          named destination corresponding to |index|.
908 // Comments:
909 //          Call this function twice to get the name of the named destination:
910 //            1) First time pass in |buffer| as NULL and get buflen.
911 //            2) Second time pass in allocated |buffer| and buflen to retrieve
912 //               |buffer|, which should be used as wchar_t*.
913 //
914 //         If buflen is not sufficiently large, it will be set to -1 upon
915 //         return.
916 DLLEXPORT FPDF_DEST STDCALL FPDF_GetNamedDest(FPDF_DOCUMENT document,
917                                               int index,
918                                               void* buffer,
919                                               long* buflen);
920 
921 #ifdef PDF_ENABLE_XFA
922 // Function: FPDF_BStr_Init
923 //          Helper function to initialize a byte string.
924 DLLEXPORT FPDF_RESULT STDCALL FPDF_BStr_Init(FPDF_BSTR* str);
925 
926 // Function: FPDF_BStr_Set
927 //          Helper function to set string data.
928 DLLEXPORT FPDF_RESULT STDCALL FPDF_BStr_Set(FPDF_BSTR* str,
929                                             FPDF_LPCSTR bstr,
930                                             int length);
931 
932 // Function: FPDF_BStr_Clear
933 //          Helper function to clear a byte string.
934 DLLEXPORT FPDF_RESULT STDCALL FPDF_BStr_Clear(FPDF_BSTR* str);
935 #endif  // PDF_ENABLE_XFA
936 
937 #ifdef __cplusplus
938 }
939 #endif
940 
941 #endif  // PUBLIC_FPDFVIEW_H_
942