1 /*
2  * Author:      William Chia-Wei Cheng (bill.cheng@acm.org)
3  *
4  * Copyright (C) 2001-2009, William Chia-Wei Cheng.
5  *
6  * This file may be distributed under the terms of the Q Public License
7  * as defined by Trolltech AS of Norway and appearing in the file
8  * LICENSE.QPL included in the packaging of this file.
9  *
10  * THIS FILE IS PROVIDED AS IS WITH NO WARRANTY OF ANY KIND, INCLUDING
11  * THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
12  * PURPOSE.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL,
13  * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
14  * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
15  * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
16  * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17  *
18  * @(#)$Header: /mm2/home/cvs/bc-src/tgif/expfdefs.h,v 1.6 2011/05/16 16:21:57 william Exp $
19  */
20 
21 #ifndef _EXPFDEFS_H_
22 #define _EXPFDEFS_H_
23 
24 /*
25  * A tgif export filter is a shared library having a name like
26  *     lib<name>.so.<ver> where <name> names the export filter type
27  *     and <ver> is a ``protocol version''.
28  *
29  * The main entry point of the shared library must be:
30  *
31  *         long TgifExportFilterMain(
32  *                 TGEF_USER_INFO *ppUserInfo;
33  *                 int nMsg;
34  *                 int nArg;
35  *                 void *pvArg
36  *         );
37  *
38  *     *ppUserInfo is a place to hang internal data for the export filter
39  *     nMsg is the message type, which is one of TGEF_MSG_*
40  *     nArg and pvArg are arguments for a message
41  */
42 
43 #include "tgifdefs.h"
44 
45 #ifdef _DL_EXPORT_UNDERSCORE
46 #define TGEF_MAIN_NAME "_TgifExportFilterMain"
47 #else /* ~_DL_EXPORT_UNDERSCORE */
48 #define TGEF_MAIN_NAME "TgifExportFilterMain"
49 #endif /* _DL_EXPORT_UNDERSCORE */
50 
51 typedef void *TGEF_USER_INFO;
52 typedef long (TGEF_MAIN)ARGS_DECL((TGEF_USER_INFO*, int, int, void*));
53 
54 typedef int   (MsgBoxFunc)ARGS_DECL((char*, char*, int));
55 typedef int   (DialogFunc)ARGS_DECL((char*, char*, char*));
56 typedef int   (FailAllocMessageFunc)ARGS_DECL((void));
57 typedef int   (UtilCopyFileFunc)ARGS_DECL((char *pszFromFile, char *pszToFile));
58 typedef int   (ObjInVisibleLayerFunc)ARGS_DECL((struct ObjRec *));
59 typedef char *(UtilStrDupFunc)ARGS_DECL((char*));
60 typedef void  (UtilFreeFunc)ARGS_DECL((char*));
61 typedef void  (MsgFunc)ARGS_DECL((char*));
62 typedef void  (SetStringStatusFunc)ARGS_DECL((char*));
63 typedef void  (UtilTrimBlanksFunc)ARGS_DECL((char*));
64 typedef void  (DynStrSetFunc)ARGS_DECL((struct DynStrRec *, char*));
65 
66 typedef struct tagTgEFProtocolInfo_1 {
67    /* in  */ Display *dpy;
68    /* in  */ Window win;
69    /* in  */ char sz_sl_path[MAXPATHLENGTH];
70    /* in  */ NLFN *pfnMsgBox;
71    /* in  */ NLFN *pfnDialog;
72    /* in  */ NLFN *pfnFailAllocMessage;
73    /* in  */ NLFN *pfnUtilCopyFile;
74    /* in  */ NLFN *pfnObjInVisibleLayer;
75    /* in  */ NLFN *pfnUtilStrDup;
76    /* in  */ VDFN *pfnUtilFree;
77    /* in  */ VDFN *pfnMsg;
78    /* in  */ VDFN *pfnSetStringStatus;
79    /* in  */ VDFN *pfnUtilTrimBlanks;
80    /* in  */ VDFN *pfnDynStrSet;
81 
82    /* Must fill in the following information in response to TGEF_MSG_LOAD: */
83       /* out */ char *bm_bits;
84       /* out */ int bm_width;
85       /* out */ int bm_height;
86       /* out */ char color_format_name[14]; /* format name */
87       /* out */ char bw_format_name[14]; /* format name */
88       /* out */ char color_ext[14]; /* file extension */
89       /* out */ char bw_ext[14]; /* file extension */
90       /* out */ int capability; /* TGEF_CAP_* */
91 
92    /* These are filled in when TGEF_MSG_DO_EXPORT is sent */
93       /* in  */ FILE *fp;
94       /* in  */ int color_dump;
95       /* in  */ int color_layers;
96       /* in  */ int printing_page_num;
97       /* in  */ int printing_first_page_num;
98       /* in  */ int printing_page_row;
99       /* in  */ int printing_page_col;
100       /* in  */ int page_layout_mode;
101       /* in  */ int last_page_num;
102       /* in  */ struct ObjRec *top_obj;
103       /* in  */ struct ObjRec *bot_obj;
104       /* out */ int write_file_failed;
105 } TgEFProtocolInfo_1;
106 
107 typedef struct tagTgEFInfo {
108    TGEF_USER_INFO pTgEFUserInfo;
109    TGEF_MAIN *pfnTgEFMain;
110    void *pSharedLibHandle;
111    char *pszSharedLibPath;
112    int nSharedLibVersion;
113    union {
114       TgEFProtocolInfo_1 stProtocolInfo_1;
115    } detail;
116 } TgEFInfo; /* Used by tgif only.  Not to be used by any export filter. */
117 
118 #define TGEF_STATUS_OK 0
119 #define TGEF_STATUS_UNKNOWN 1
120 #define TGEF_STATUS_INVALID_ARGS 2
121 #define TGEF_STATUS_MALLOC 3
122 
123 /*
124  * capability
125  *
126  *     Use TGEF_CAP_SINGLE_PAGE if the file format is EPS-like where
127  *         it doesn't make sense to have a multi-page output.
128  *     Otherwise, use TGEF_CAP_MULTI_PAGE.
129  */
130 
131 #define TGEF_CAP_SINGLE_PAGE 0x0000 /* cannot handle multi-pg drawing */
132 #define TGEF_CAP_MULTI_PAGE  0x0001 /* handle multi-pg drawing */
133 
134 /*
135  * message types
136  */
137 
138 #define TGEF_MSG_INIT 0
139 #define TGEF_MSG_GET_PROTOCOL_VERSION 1
140 #define TGEF_MSG_LOAD 2
141 #define TGEF_MSG_UNLOAD 3
142 #define TGEF_MSG_CLEANUP 4
143 
144 #define TGEF_MSG_DO_EXPORT 10
145 
146 /*
147  * Basic messages:
148  *
149  *     TGEF_MSG_INIT, TGEF_MSG_GET_PROTOCOL_VERSION, TGEF_MSG_LOAD,
150  *         TGEF_MSG_UNLOAD, and TGEF_MSG_CLEANUP are basic messages.
151  *
152  *     They are called in the following sequence:
153  *
154  *         In InitExportFilters() of "xprtfltr.c":
155  *
156  *             TGEF_MSG_INIT
157  *             TGEF_MSG_GET_PROTOCOL_VERSION
158  *             TGEF_MSG_LOAD
159  *
160  *         In DoGenDump() of "file.c":
161  *
162  *             Other non-basic messages are sent to do the actual exporting.
163  *
164  *         In CleanUpExportFilters() of "xprtfltr.c":
165  *
166  *             TGEF_MSG_UNLOAD
167  *             TGEF_MSG_CLEANUP
168  *
169  * TGEF_MSG_INIT:
170  *     On entry:
171  *         *ppUserInfo is set to NULL, nArg = 0, pvArg = NULL
172  *     On return:
173  *         If returns anything other than TGEF_STATUS_OK, the shared
174  *             library is unloaded.
175  *     Note:
176  *         No memory allocation should be performed in the message
177  *             handler of this message!  If you want to allocate memory,
178  *             do it in TGEF_MSG_LOAD.
179  *
180  * TGEF_MSG_GET_PROTOCOL_VERSION:
181  *     On entry:
182  *         nArg = 0, pvArg = NULL
183  *     On return:
184  *         The returned value should be an integer specifying the
185  *             protocol version this export filter implements.  Please
186  *             note that if the returned value is different from the
187  *             <ver> part of the "lib<name>.so.<ver>", TGEF_MSG_CLEANUP
188  *             will be sent immediately.
189  *
190  * TGEF_MSG_LOAD:
191  *     On entry:
192  *         *ppUserInfo is set to NULL, nArg = 0, pvArg is a pointer to
193  *             TgEFProtocolInfo_<ver> where <ver> is the returned value
194  *             of the TGEF_MSG_GET_PROTOCOL_VERSION message.
195  *     On return:
196  *         If returns anything other than TGEF_STATUS_OK, the shared
197  *             library is unloaded.
198  *         If returns TGEF_STATUS_OK, *ppUserInfo can be used to hang
199  *             internal data for the export filter.  Tgif will not
200  *             touch *ppUserInfo from this point on until after the
201  *             call with message type TGEF_MSG_UNLOAD.
202  *
203  * TGEF_MSG_UNLOAD:
204  *     On entry:
205  *         ppUserInfo = what's set in TGEF_MSG_LOAD, nArg = 0, pvArg = NULL
206  *     On return:
207  *         *ppUserInfo will be set to NULL immediately afterwards.
208  *     Note:
209  *         The message handler should free up allocated memory.
210  *
211  * TGEF_MSG_CLEANUP:
212  *     On entry:
213  *         ppUserInfo = NULL, nArg = 0, pvArg = NULL
214  *     On return:
215  *         The shared library is unloaded and the returned value is ignored.
216  *     Note:
217  *         No memory deallocation should be performed in the message
218  *             handler of this message!  If you want to deallocate memory,
219  *             do it in TGEF_MSG_UNLOAD.
220  *         Usually, there's no need to handle this message if the shared
221  *             library can be simply unloaded.
222  *
223  */
224 
225 /*
226  * TGEF_MSG_DO_EXPORT:
227  *     On entry:
228  *         ppUserInfo = what's set in TGEF_MSG_LOAD, nArg = 0, pvArg is a
229  *             pointer to TgEFProtocolInfo_<ver> where <ver> is the returned
230  *             value of the TGEF_MSG_GET_PROTOCOL_VERSION message.
231  *     On return:
232  *         Should return TGEF_STATUS_OK if everything is okay.
233  */
234 
235 #endif /*_EXPFDEFS_H_*/
236