"Fossies" - the Fresh Open Source Software Archive

Member "epstool-3.08/src/common.h" (10 Jun 2005, 7030 Bytes) of package /linux/misc/old/ghost/ghostgum/epstool-3.08.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 /* Copyright (C) 2001-2005 Ghostgum Software Pty Ltd.  All rights reserved.
    2 
    3   This software is provided AS-IS with no warranty, either express or
    4   implied.
    5 
    6   This software is distributed under licence and may not be copied,
    7   modified or distributed except as expressly authorised under the terms
    8   of the licence contained in the file LICENCE in this distribution.
    9 
   10   For more information about licensing, please refer to
   11   http://www.ghostgum.com.au/ or contact Ghostsgum Software Pty Ltd, 
   12   218 Gallaghers Rd, Glen Waverley VIC 3150, AUSTRALIA, 
   13   Fax +61 3 9886 6616.
   14 */
   15 
   16 /* $Id: common.h,v 1.15 2005/06/10 09:39:24 ghostgum Exp $ */
   17 /* Common header */
   18 
   19 #include <stdio.h>
   20 #include <stdlib.h>
   21 #include <string.h>
   22 #include <stdarg.h>
   23 #include <ctype.h>
   24 #include "cplat.h"
   25 #include "cfile.h"
   26 
   27 #define __PROTOTYPES__
   28 
   29 #define MAXSTR 256
   30 #define COPY_BUF_SIZE 4096
   31 
   32 #define GS_REVISION_MIN 704
   33 #define GS_REVISION     704
   34 #define GS_REVISION_MAX 899
   35 
   36 #define return_error(val) return val
   37 
   38 #ifndef min
   39 #define min(a,b) ((a) < (b) ? (a) : (b))
   40 #endif
   41 #ifndef max
   42 #define max(a,b) ((a) > (b) ? (a) : (b))
   43 #endif
   44 
   45 /* Opaque types */
   46 
   47 #ifndef CDSC_TYPEDEF
   48 #define CDSC_TYPEDEF
   49 typedef struct CDSC_s CDSC;
   50 #endif
   51 
   52 #ifndef Doc_TYPEDEF
   53 #define Doc_TYPEDEF
   54 typedef struct Doc_s Doc;
   55 #endif
   56 
   57 #ifndef GSDLL_TYPEDEF
   58 #define GSDLL_TYPEDEF
   59 typedef struct GSDLL_s GSDLL;
   60 #endif
   61 
   62 #ifndef PLDLL_TYPEDEF
   63 #define PLDLL_TYPEDEF
   64 typedef struct PLDLL_s PLDLL;
   65 #endif
   66 
   67 #ifndef GSIMAGE_TYPEDEF
   68 #define GSIMAGE_TYPEDEF
   69 typedef struct GSIMAGE_s GSIMAGE;
   70 #endif
   71 
   72 #ifndef GSREQ_TYPEDEF
   73 #define GSREQ_TYPEDEF
   74 typedef struct GSREQ_s GSREQ;
   75 #endif
   76 
   77 #ifndef GSSRV_TYPEDEF
   78 #define GSSRV_TYPEDEF
   79 typedef struct GSSRV_s GSSRV;
   80 #endif
   81 
   82 #ifndef GSview_TYPEDEF
   83 #define GSview_TYPEDEF
   84 typedef struct GSview_s GSview;
   85 #endif
   86 
   87 #ifndef HISTORY_TYPEDEF
   88 #define HISTORY_TYPEDEF
   89 typedef struct HISTORY_s HISTORY;
   90 #endif
   91 
   92 #ifndef IMAGE_TYPEDEF
   93 #define IMAGE_TYPEDEF
   94 typedef struct IMAGE_s IMAGE;
   95 #endif
   96 
   97 #ifndef MEDIA_TYPEDEF
   98 #define MEDIA_TYPEDEF
   99 typedef struct MEDIA_s MEDIA;
  100 #endif
  101 
  102 #ifndef OPTION_TYPEDEF
  103 #define OPTION_TYPEDEF
  104 typedef struct OPTION_s OPTION;
  105 #endif
  106 
  107 #ifndef PAGECACHE_TYPEDEF
  108 #define PAGECACHE_TYPEDEF
  109 typedef struct PAGECACHE_s PAGECACHE;
  110 #endif
  111 
  112 #ifndef PDFLINK_TYPEDEF
  113 #define PDFLINK_TYPEDEF
  114 typedef struct PDFLINK_s PDFLINK;
  115 #endif
  116 
  117 #ifndef View_TYPEDEF
  118 #define View_TYPEDEF
  119 typedef struct View_s View;
  120 #endif
  121 
  122 
  123 /* Public functions */
  124 
  125 /***************************************/
  126 /* Unicode, Multiple Byte Character Set and narrow strings. */
  127 
  128 #ifdef UNICODE
  129 #define CHARNEXT(x) ((x)+1)
  130 #else
  131 #define CHARNEXT(x) (global_codepage == CODEPAGE_SBCS ? ((x)+1) : ((x)+char_next(x)))
  132 
  133 typedef enum {
  134     CODEPAGE_SBCS = 0,  /* single byte character set */
  135     CODEPAGE_UTF8 = 1,
  136     CODEPAGE_EUC = 2,
  137     CODEPAGE_SJIS = 3
  138 } CODEPAGE;
  139 
  140 extern CODEPAGE global_codepage;    /* GLOBAL */
  141 int char_next(const char *str);
  142 #endif
  143 
  144 /* convert between cs (wide or multibyte) and narrow strings */
  145 int cs_to_narrow(char *nstr, int nlen, LPCTSTR wstr, int wlen);
  146 int narrow_to_cs(TCHAR *wstr, int wlen, const char *nstr, int nlen);
  147 
  148 /* Implementation that just copies the string */
  149 int char_to_narrow(char *nstr, int nlen, LPCTSTR wstr, int wlen);
  150 int narrow_to_char(TCHAR *wstr, int wlen, const char *nstr, int nlen);
  151 
  152 /* Convert ISO-Latin1 to UTF-8 */
  153 /* Used where unknown text is passed to gtk+ GUI */
  154 int latin1_to_utf8(char *ustr, int ulen, const char *str, int slen);
  155 
  156 /***************************************/
  157 /* Debugging flags */
  158 
  159 #define DEBUG_GENERAL   0x01
  160 #define DEBUG_GDI   0x02    /* GDI printing */
  161 #define DEBUG_MEM   0x04    /* memory allocation */
  162 #define DEBUG_LOG   0x08    /* write gs_addmess() to file c:\gsview.txt */
  163 #define DEBUG_GSINPUT   0x10    /* log all input written to GS */
  164 #define DEBUG_DEV   0x80    /* For debugging */
  165 
  166 extern int debug;           /* GLOBAL */
  167 
  168 /***************************************/
  169 /* Debugging malloc */
  170 /*
  171 #define DEBUG_MALLOC
  172 */
  173 #ifdef DEBUG_MALLOC
  174 # define malloc(x) debug_malloc(x,__FILE__,__LINE__)
  175 # define calloc debug_calloc
  176 # define realloc debug_realloc
  177 # define free debug_free
  178 void * debug_malloc(size_t size, const char *file, int line);
  179 void * debug_realloc(void *block, size_t size);
  180 void debug_free(void *block);
  181 void debug_memory_report(void);
  182 #endif
  183 
  184 
  185 /***************************************/
  186 
  187 /* should put this in cpagelst.h */
  188 
  189 typedef struct PAGELIST_s {
  190     int current;    /* index of current selection */
  191     BOOL multiple;  /* true if multiple selection allowed */
  192     int page_count; /* number of entries in select */
  193     BOOL *select;   /* array of selection flags */
  194     BOOL reverse;   /* reverse pages when extracting or printing */
  195 } PAGELIST;
  196 
  197 void page_list_free(PAGELIST *page_list);
  198 void page_list_copy(PAGELIST *newlist, PAGELIST *oldlist);
  199 void page_list_init(PAGELIST *page_list, int pages);
  200 
  201 
  202 /***************************************/
  203 
  204 typedef enum ORIENT_e {
  205     ORIENT_DEFAULT = -1,    /* use PDF/DSC default */
  206     /* following values match setpagedevice /Orientation */
  207     ORIENT_PORTRAIT = 0,
  208     ORIENT_LANDSCAPE = 3,
  209     ORIENT_UPSIDEDOWN = 2,
  210     ORIENT_SEASCAPE = 1
  211 } ORIENT;
  212 
  213 
  214 typedef enum DISPLAY_FORMAT_e {
  215     DISPLAY_FORMAT_AUTO = 0,
  216     DISPLAY_FORMAT_GREY_1 = 1,
  217     DISPLAY_FORMAT_GREY_8 = 2,
  218     DISPLAY_FORMAT_COLOUR_4 = 3,
  219     DISPLAY_FORMAT_COLOUR_8 = 4,
  220     DISPLAY_FORMAT_COLOUR_24 = 5,
  221     DISPLAY_FORMAT_CMYK_32 = 6,
  222     DISPLAY_FORMAT_COUNT = 7
  223 } DISPLAY_FORMAT;
  224 
  225 /***************************************/
  226 /* PAGESPEC is used in rendering requests, and to describe
  227  * the results of a render.
  228  */
  229 typedef struct PAGESPEC_s PAGESPEC;
  230 
  231 typedef enum PAGESIZE_METHOD_e {
  232     PAGESIZE_GIVEN = 0,     /* use llx,lly,urx,ury */
  233     PAGESIZE_CROPBOX = 1,   /* use PDF crop box */
  234     PAGESIZE_MEDIABOX = 2,  /* use PDF media box */
  235     PAGESIZE_VARIABLE = 3   /* default is llx,lly,urx,ury, but allow */
  236                 /* user PostScript to change page size */
  237 } PAGESIZE_METHOD;
  238 
  239 struct PAGESPEC_s {
  240     TCHAR filename[MAXSTR];
  241     int page;           /* page number */
  242     PAGESIZE_METHOD pagesize;
  243     /* If pagesize is not PAGESIZE_GIVEN, then the following dimensions
  244      * do not need to be specified on request, but will be filled
  245      * in just before rendering.  This is because we don't know th
  246      * PDF page size until we start rendering.
  247      */
  248     float llx;  /* Points */
  249     float lly;  /* Points */
  250     float urx;  /* Points */
  251     float ury;  /* Points */
  252 
  253     float xddpi;    /* display dpi */
  254     float yddpi;    /* display dpi */
  255     float xrdpi;    /* render dpi */
  256     float yrdpi;    /* render dpi */
  257     /* On request, set both req_orient and orient to the desired orientation
  258      * After rendering, orient will be set to the actual orientation,
  259      * while orient_request may be left as ORIENT_DEFAULT.
  260      * This is needed because we don't know the actual PDF orientation 
  261      * until we start rendering.
  262      */
  263     ORIENT orient_request;
  264     ORIENT orient;
  265     unsigned int format;    /* display device format */
  266     int alpha_text;     /* 1, 2 or 4 */
  267     int alpha_graphics;     /* 1, 2 or 4 */
  268 };
  269 
  270