]> gitweb.factorcode.org Git - factor.git/blob - unmaintained/pdf/libhpdf/libhpdf.factor
f01feb494df0308d88f464a3635fd85b12c6248b
[factor.git] / unmaintained / pdf / libhpdf / libhpdf.factor
1 ! Copyright (C) 2007 Elie CHAFTARI
2 ! See http://factorcode.org/license.txt for BSD license.
3 !
4 ! Tested with libharu2 2.0.8 on Mac OS X 10.4.9 PowerPC
5 !
6 ! export LD_LIBRARY_PATH=/opt/local/lib
7
8 USING: alien alien.syntax combinators system ;
9
10 IN: pdf.libhpdf
11
12 << "libhpdf" {
13     { [ win32? ] [ "libhpdf.dll" stdcall ] }
14     { [ macosx? ] [ "libhpdf.dylib" cdecl ] }
15     { [ unix? ] [ "$LD_LIBRARY_PATH/libhpdf.so" cdecl ] }
16 } cond add-library >>
17
18 ! compression mode
19 : HPDF_COMP_NONE      HEX: 00 ; inline ! No contents are compressed
20 : HPDF_COMP_TEXT      HEX: 01 ; inline ! Compress contents stream of page
21 : HPDF_COMP_IMAGE     HEX: 02 ; inline ! Compress streams of image objects
22 : HPDF_COMP_METADATA  HEX: 04 ; inline ! Compress other data (fonts, cmaps...)
23 : HPDF_COMP_ALL       HEX: 0F ; inline ! All stream data are compressed
24 : HPDF_COMP_MASK      HEX: FF ; inline
25
26 ! page mode
27 C-ENUM: f
28     HPDF_PAGE_MODE_USE_NONE
29     HPDF_PAGE_MODE_USE_OUTLINE
30     HPDF_PAGE_MODE_USE_THUMBS
31     HPDF_PAGE_MODE_FULL_SCREEN
32     HPDF_PAGE_MODE_EOF
33 ;
34
35 : error-code ( -- seq ) {
36      { HEX: 1001  "HPDF_ARRAY_COUNT_ERR\nInternal error. The consistency of the data was lost." }
37      { HEX: 1002  "HPDF_ARRAY_ITEM_NOT_FOUND\nInternal error. The consistency of the data was lost." }
38      { HEX: 1003  "HPDF_ARRAY_ITEM_UNEXPECTED_TYPE\nInternal error. The consistency of the data was lost." }
39      { HEX: 1004  "HPDF_BINARY_LENGTH_ERR\nThe length of the data exceeds HPDF_LIMIT_MAX_STRING_LEN." }
40      { HEX: 1005  "HPDF_CANNOT_GET_PALLET\nCannot get a pallet data from PNG image." }
41      { HEX: 1007  "HPDF_DICT_COUNT_ERR\nThe count of elements of a dictionary exceeds HPDF_LIMIT_MAX_DICT_ELEMENT" }
42      { HEX: 1008  "HPDF_DICT_ITEM_NOT_FOUND\nInternal error. The consistency of the data was lost." }
43      { HEX: 1009  "HPDF_DICT_ITEM_UNEXPECTED_TYPE\nInternal error. The consistency of the data was lost." }  
44      { HEX: 100A  "HPDF_DICT_STREAM_LENGTH_NOT_FOUND\nInternal error. The consistency of the data was lost." }  
45      { HEX: 100B  "HPDF_DOC_ENCRYPTDICT_NOT_FOUND\nHPDF_SetPermission() OR HPDF_SetEncryptMode() was called before a password is set." }
46      { HEX: 100C  "HPDF_DOC_INVALID_OBJECT\nInternal error. The consistency of the data was lost." }
47      { HEX: 100E  "HPDF_DUPLICATE_REGISTRATION\nTried to register a font that has been registered." }
48      { HEX: 100F  "HPDF_EXCEED_JWW_CODE_NUM_LIMIT\nCannot register a character to the japanese word wrap characters list." }
49      { HEX: 1011  "HPDF_ENCRYPT_INVALID_PASSWORD\nTried to set the owner password to NULL. owner password and user password is the same." }
50      { HEX: 1013  "HPDF_ERR_UNKNOWN_CLASS\nInternal error. The consistency of the data was lost." }
51      { HEX: 1014  "HPDF_EXCEED_GSTATE_LIMIT\nThe depth of the stack exceeded HPDF_LIMIT_MAX_GSTATE." }
52      { HEX: 1015  "HPDF_FAILED_TO_ALLOC_MEM\nMemory allocation failed." }
53      { HEX: 1016  "HPDF_FILE_IO_ERROR\nFile processing failed. (A detailed code is set.)" }
54      { HEX: 1017  "HPDF_FILE_OPEN_ERROR\nCannot open a file. (A detailed code is set.)" }
55      { HEX: 1019  "HPDF_FONT_EXISTS\nTried to load a font that has already been registered." }
56      { HEX: 101A  "HPDF_FONT_INVALID_WIDTHS_TABLE\nThe format of a font-file is invalid . Internal error. The consistency of the data was lost." }
57      { HEX: 101B  "HPDF_INVALID_AFM_HEADER\nCannot recognize a header of an afm file." }
58      { HEX: 101C  "HPDF_INVALID_ANNOTATION\nThe specified annotation handle is invalid." }
59      { HEX: 101E  "HPDF_INVALID_BIT_PER_COMPONENT\nBit-per-component of a image which was set as mask-image is invalid." }
60      { HEX: 101F  "HPDF_INVALID_CHAR_MATRICS_DATA\nCannot recognize char-matrics-data  of an afm file." }
61      { HEX: 1020  "HPDF_INVALID_COLOR_SPACE\n1. The color_space parameter of HPDF_LoadRawImage is invalid.\n2. Color-space of a image which was set as mask-image is invalid.\n3. The function which is invalid in the present color-space was invoked." }
62      { HEX: 1021  "HPDF_INVALID_COMPRESSION_MODE\nInvalid value was set when invoking HPDF_SetCommpressionMode()." }
63      { HEX: 1022  "HPDF_INVALID_DATE_TIME\nAn invalid date-time value was set." }
64      { HEX: 1023  "HPDF_INVALID_DESTINATION\nAn invalid destination handle was set." }
65      { HEX: 1025  "HPDF_INVALID_DOCUMENT\nAn invalid document handle is set." }
66      { HEX: 1026  "HPDF_INVALID_DOCUMENT_STATE\nThe function which is invalid in the present state was invoked." }
67      { HEX: 1027  "HPDF_INVALID_ENCODER\nAn invalid encoder handle was set." }
68      { HEX: 1028  "HPDF_INVALID_ENCODER_TYPE\nA combination between font and encoder is wrong." }
69      { HEX: 102B  "HPDF_INVALID_ENCODING_NAME\nAn Invalid encoding name is specified." }
70      { HEX: 102C  "HPDF_INVALID_ENCRYPT_KEY_LEN\nThe lengh of the key of encryption is invalid." }
71      { HEX: 102D  "HPDF_INVALID_FONTDEF_DATA\n1. An invalid font handle was set.\n2. Unsupported font format." }
72      { HEX: 102E  "HPDF_INVALID_FONTDEF_TYPE\nInternal error. The consistency of the data was lost." }
73      { HEX: 102F  "HPDF_INVALID_FONT_NAME\nA font which has the specified name is not found." }
74      { HEX: 1030  "HPDF_INVALID_IMAGE\nUnsupported image format." }
75      { HEX: 1031  "HPDF_INVALID_JPEG_DATA\nUnsupported image format." }
76      { HEX: 1032  "HPDF_INVALID_N_DATA\nCannot read a postscript-name from an afm file." }
77      { HEX: 1033  "HPDF_INVALID_OBJECT\n1. An invalid object is set.\n2. Internal error. The consistency of the data was lost." }
78      { HEX: 1034  "HPDF_INVALID_OBJ_ID\nInternal error. The consistency of the data was lost." }
79      { HEX: 1035  "HPDF_INVALID_OPERATION\nInvoked HPDF_Image_SetColorMask() against the image-object which was set a mask-image." }
80      { HEX: 1036  "HPDF_INVALID_OUTLINE\nAn invalid outline-handle was specified." }
81      { HEX: 1037  "HPDF_INVALID_PAGE\nAn invalid page-handle was specified." }
82      { HEX: 1038  "HPDF_INVALID_PAGES\nAn invalid pages-handle was specified. (internal error)" }
83      { HEX: 1039  "HPDF_INVALID_PARAMETER\nAn invalid value is set." }
84      { HEX: 103B  "HPDF_INVALID_PNG_IMAGE\nInvalid PNG image format." }
85      { HEX: 103C  "HPDF_INVALID_STREAM\nInternal error. The consistency of the data was lost." }
86      { HEX: 103D  "HPDF_MISSING_FILE_NAME_ENTRY\nInternal error. The \"_FILE_NAME\" entry for delayed loading is missing." }
87      { HEX: 103F  "HPDF_INVALID_TTC_FILE\nInvalid .TTC file format." }
88      { HEX: 1040  "HPDF_INVALID_TTC_INDEX\nThe index parameter was exceed the number of included fonts" }
89      { HEX: 1041  "HPDF_INVALID_WX_DATA\nCannot read a width-data from an afm file." }
90      { HEX: 1042  "HPDF_ITEM_NOT_FOUND\nInternal error. The consistency of the data was lost." }
91      { HEX: 1043  "HPDF_LIBPNG_ERROR\nAn error has returned from PNGLIB while loading an image." }
92      { HEX: 1044  "HPDF_NAME_INVALID_VALUE\nInternal error. The consistency of the data was lost." }
93      { HEX: 1045  "HPDF_NAME_OUT_OF_RANGE\nInternal error. The consistency of the data was lost." }
94      { HEX: 1049  "HPDF_PAGES_MISSING_KIDS_ENTRY\nInternal error. The consistency of the data was lost." }
95      { HEX: 104A  "HPDF_PAGE_CANNOT_FIND_OBJECT\nInternal error. The consistency of the data was lost." }
96      { HEX: 104B  "HPDF_PAGE_CANNOT_GET_ROOT_PAGES\nInternal error. The consistency of the data was lost." }
97      { HEX: 104C  "HPDF_PAGE_CANNOT_RESTORE_GSTATE\nThere are no graphics-states to be restored." }
98      { HEX: 104D  "HPDF_PAGE_CANNOT_SET_PARENT\nInternal error. The consistency of the data was lost." }
99      { HEX: 104E  "HPDF_PAGE_FONT_NOT_FOUND\nThe current font is not set." }
100      { HEX: 104F  "HPDF_PAGE_INVALID_FONT\nAn invalid font-handle was specified." }
101      { HEX: 1050  "HPDF_PAGE_INVALID_FONT_SIZE\nAn invalid font-size was set." }
102      { HEX: 1051  "HPDF_PAGE_INVALID_GMODE\nSee Graphics mode." }
103      { HEX: 1052  "HPDF_PAGE_INVALID_INDEX\nInternal error. The consistency of the data was lost." }
104      { HEX: 1053  "HPDF_PAGE_INVALID_ROTATE_VALUE\nThe specified value is not a multiple of 90." }
105      { HEX: 1054  "HPDF_PAGE_INVALID_SIZE\nAn invalid page-size was set." }
106      { HEX: 1055  "HPDF_PAGE_INVALID_XOBJECT\nAn invalid image-handle was set." }
107      { HEX: 1056  "HPDF_PAGE_OUT_OF_RANGE\nThe specified value is out of range." }
108      { HEX: 1057  "HPDF_REAL_OUT_OF_RANGE\nThe specified value is out of range." }
109      { HEX: 1058  "HPDF_STREAM_EOF\nUnexpected EOF marker was detected." }
110      { HEX: 1059  "HPDF_STREAM_READLN_CONTINUE\nInternal error. The consistency of the data was lost." }
111      { HEX: 105B  "HPDF_STRING_OUT_OF_RANGE\nThe length of the specified text is too long." }
112      { HEX: 105C  "HPDF_THIS_FUNC_WAS_SKIPPED\nThe execution of a function was skipped because of other errors." }
113      { HEX: 105D  "HPDF_TTF_CANNOT_EMBEDDING_FONT\nThis font cannot be embedded. (restricted by license.)" }
114      { HEX: 105E  "HPDF_TTF_INVALID_CMAP\nUnsupported ttf format. (cannot find unicode cmap.)" }
115      { HEX: 105F  "HPDF_TTF_INVALID_FOMAT\nUnsupported ttf format." }
116      { HEX: 1060  "HPDF_TTF_MISSING_TABLE\nUnsupported ttf format. (cannot find a necessary table.)" }
117      { HEX: 1061  "HPDF_UNSUPPORTED_FONT_TYPE\nInternal error. The consistency of the data was lost." }
118      { HEX: 1062  "HPDF_UNSUPPORTED_FUNC\n1. The library is not configured to use PNGLIB.\n2. Internal error. The consistency of the data was lost." }
119      { HEX: 1063  "HPDF_UNSUPPORTED_JPEG_FORMAT\nUnsupported Jpeg format." }
120      { HEX: 1064  "HPDF_UNSUPPORTED_TYPE1_FONT\nFailed to parse .PFB file." }
121      { HEX: 1065  "HPDF_XREF_COUNT_ERR\nInternal error. The consistency of the data was lost." }
122      { HEX: 1066  "HPDF_ZLIB_ERROR\nAn error has occurred while executing a function of Zlib." }
123      { HEX: 1067  "HPDF_INVALID_PAGE_INDEX\nAn error returned from Zlib." }
124      { HEX: 1068  "HPDF_INVALID_URI\nAn invalid URI was set." }
125      { HEX: 1069  "HPDF_PAGELAYOUT_OUT_OF_RANGE\nAn invalid page-layout was set." }
126      { HEX: 1070  "HPDF_PAGEMODE_OUT_OF_RANGE\nAn invalid page-mode was set." }
127      { HEX: 1071  "HPDF_PAGENUM_STYLE_OUT_OF_RANGE\nAn invalid page-num-style was set." }
128      { HEX: 1072  "HPDF_ANNOT_INVALID_ICON\nAn invalid icon was set." }
129      { HEX: 1073  "HPDF_ANNOT_INVALID_BORDER_STYLE\nAn invalid border-style was set." }
130      { HEX: 1074  "HPDF_PAGE_INVALID_DIRECTION\nAn invalid page-direction was set." }
131      { HEX: 1075  "HPDF_INVALID_FONT\nAn invalid font-handle was specified." }
132 } ;
133
134 LIBRARY: libhpdf
135
136 ! ===============================================
137 ! hpdf.h
138 ! ===============================================
139
140 FUNCTION: void* HPDF_New ( void* user_error_fn, void* user_data ) ;
141
142 FUNCTION: void* HPDF_Free ( void* pdf ) ;
143
144 FUNCTION: ulong HPDF_SetCompressionMode ( void* pdf, uint mode ) ;
145
146 FUNCTION: ulong HPDF_SetPageMode ( void* pdf, uint mode ) ;
147
148 FUNCTION: void* HPDF_AddPage ( void* pdf ) ;
149
150 FUNCTION: ulong HPDF_SaveToFile ( void* pdf, char* file_name ) ;
151
152 FUNCTION: float HPDF_Page_GetHeight ( void* page ) ;
153
154 FUNCTION: float HPDF_Page_GetWidth ( void* page ) ;
155
156 FUNCTION: ulong HPDF_Page_SetLineWidth ( void* page, float line_width ) ;
157
158 FUNCTION: ulong HPDF_Page_Rectangle ( void* page, float x, float y,
159                                       float width, float height ) ;
160
161 FUNCTION: ulong HPDF_Page_Stroke ( void* page ) ;
162
163 FUNCTION: void* HPDF_GetFont ( void* pdf, char* font_name,
164                                char* encoding_name ) ;
165
166 FUNCTION: ulong HPDF_Page_SetFontAndSize ( void* page, void* font,
167                                            float size ) ;
168
169 FUNCTION: float HPDF_Page_TextWidth ( void* page, char* text ) ;
170
171 FUNCTION: ulong HPDF_Page_BeginText ( void* page ) ;
172
173 FUNCTION: ulong HPDF_Page_TextOut ( void* page, float xpos, float ypos,
174                                     char* text ) ;
175
176 FUNCTION: ulong HPDF_Page_EndText ( void*  page ) ;
177
178 FUNCTION: ulong HPDF_Page_MoveTextPos ( void* page, float x, float y ) ;
179
180 FUNCTION: ulong HPDF_Page_ShowText ( void* page, char* text ) ;