1 /* Copyright (C) 1994, 1995, 1997 Artifex Software, Inc. 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 license and may not be copied, 7 modified or distributed except as expressly authorized under the terms 8 of the license contained in the file LICENSE in this distribution. 9 10 For more information about licensing, please refer to 11 http://www.ghostscript.com/licensing/. For information on 12 commercial licensing, go to http://www.artifex.com/licensing/ or 13 contact Artifex Software, Inc., 101 Lucas Valley Road #110, 14 San Rafael, CA 94903, U.S.A., +1(415)492-9861. 15 */ 16 17 /* $Id: gdevmac.h,v 1.5 2002/11/26 14:38:43 giles Exp $ */ 18 19 #ifndef gdevmac_INCLUDED 20 # define gdevmac_INCLUDED 21 22 #include <stdlib.h> 23 #include "math_.h" 24 #include "string_.h" 25 26 #include "gdevmacpictop.h" 27 28 #include <Fonts.h> 29 #include <FixMath.h> 30 #include <Resources.h> 31 32 #include "gx.h" 33 #include "gxdevice.h" 34 #include "gp.h" 35 #include "gp_mac.h" 36 #include "gsdll.h" 37 38 #include "gsutil.h" 39 #include "gxxfont.h" 40 #include "gsstruct.h" 41 #include "gserrors.h" 42 43 44 45 /* Default device settings */ 46 47 #define DEFAULT_PAGE_SIZE_H 8.5 48 #define DEFAULT_PAGE_SIZE_V 11.0 49 #define DEFAULT_DEV_DPI 72.0 50 #define DEFAULT_PAGE_DPI 72.0 51 52 #define DEFAULT_DEV_WIDTH (DEFAULT_PAGE_SIZE_H * DEFAULT_DEV_DPI) 53 #define DEFAULT_DEV_HEIGHT (DEFAULT_PAGE_SIZE_V * DEFAULT_DEV_DPI) 54 #define DEFAULT_PAGE_WIDTH (DEFAULT_PAGE_SIZE_H * DEFAULT_PAGE_DPI) 55 #define DEFAULT_PAGE_HEIGHT (DEFAULT_PAGE_SIZE_V * DEFAULT_PAGE_DPI) 56 57 58 /* Define the Macintosh device */ 59 60 typedef struct gx_device_macos_s 61 { 62 gx_device_common; 63 char outputFileName[gp_file_name_sizeof]; 64 FILE *outputFile; 65 PicHandle pic; 66 short *currPicPos; 67 bool outputPage; 68 bool useXFonts; 69 FMFontStyle lastFontFace; 70 FMFontSize lastFontSize; 71 FMFontFamily lastFontID; 72 int numUsedFonts; 73 FMFontFamily usedFontIDs[256]; 74 } gx_device_macos; 75 76 #define DEV_MAC_NAME "macos" 77 78 79 /* Device Procedures */ 80 81 dev_proc_open_device(mac_open); 82 dev_proc_get_initial_matrix(mac_get_initial_matrix); 83 dev_proc_sync_output(mac_sync_output); 84 dev_proc_output_page(mac_output_page); 85 dev_proc_get_params(mac_get_params); 86 dev_proc_put_params(mac_put_params); 87 dev_proc_close_device(mac_close); 88 dev_proc_fill_rectangle(mac_fill_rectangle); 89 dev_proc_strip_tile_rectangle(mac_strip_tile_rectangle); 90 dev_proc_copy_mono(mac_copy_mono); 91 dev_proc_copy_color(mac_copy_color); 92 dev_proc_draw_line(mac_draw_line); 93 dev_proc_copy_alpha(mac_copy_alpha); 94 dev_proc_get_xfont_procs(mac_get_xfont_procs); 95 96 /* Declare the xfont procedures */ 97 private xfont_proc_lookup_font(mac_lookup_font); 98 private xfont_proc_char_xglyph(mac_char_xglyph); 99 private xfont_proc_char_metrics(mac_char_metrics); 100 private xfont_proc_render_char(mac_render_char); 101 private xfont_proc_release(mac_release); 102 103 104 /* Define a MacOS xfont. */ 105 106 typedef struct mac_xfont_s mac_xfont; 107 struct mac_xfont_s { 108 gx_xfont_common common; 109 gx_device *dev; 110 Str255 fontName; 111 FMFontFamily fontID; 112 FMFontStyle fontFace; 113 FMFontSize fontSize; 114 int fontEncoding; 115 FMetricRec fontMetrics; 116 }; 117 118 119 /* Memory handling macros */ 120 121 #define CheckMem(a,b) \ 122 { \ 123 long offset = (long) mdev->currPicPos - (long) *mdev->pic; \ 124 long len = GetHandleSize((Handle) mdev->pic); \ 125 if (len - offset < a) { \ 126 HUnlock((Handle) mdev->pic); \ 127 SetHandleSize((Handle) mdev->pic, len + b); \ 128 if (MemError() != noErr) return gs_error_VMerror; \ 129 HLockHi((Handle) mdev->pic); \ 130 mdev->currPicPos = (short*) ((long) *mdev->pic + offset); \ 131 } \ 132 } 133 134 #define ResetPage() \ 135 { \ 136 if (mdev->outputPage) { \ 137 mdev->outputPage = false; \ 138 mdev->currPicPos = (short*) *mdev->pic; \ 139 mdev->currPicPos += 42; /* header len */ \ 140 mdev->lastFontID = mdev->lastFontSize = mdev->lastFontFace = -1; \ 141 mdev->numUsedFonts = 0; \ 142 } \ 143 } 144 145 146 /* Other datatypes */ 147 148 typedef struct { 149 unsigned short red; 150 unsigned short green; 151 unsigned short blue; 152 } colorRGB; 153 154 typedef struct { 155 float h; 156 float s; 157 float v; 158 } colorHSV; 159 160 161 /* Helper function definitions */ 162 163 private int mac_save_pict(gx_device * dev); 164 private void mac_convert_rgb_hsv(colorRGB *inRGB, colorHSV *HSV); 165 private void mac_convert_hsv_rgb(colorHSV *inHSV, colorRGB *RGB); 166 167 private void mac_find_font_family(ConstStringPtr fname, int len, 168 FMFontFamily *fontFamilyID, FMFontStyle *fontFace); 169 private int mac_get_font_encoding(mac_xfont *macxf); 170 private void mac_get_font_resource(mac_xfont *macxf, ResType *resType, short *resID); 171 172 private int mac_set_colordepth(gx_device *dev, int depth); 173 174 175 /* additional DLL function definition */ 176 177 #pragma export on 178 179 int GSDLLAPI gsdll_get_pict(unsigned char *, PicHandle *); 180 typedef int (GSDLLAPI * PFN_gsdll_get_pict) (unsigned char *, PicHandle *); 181 182 #pragma export off 183 184 #endif /* gdevmac_INCLUDED */ 185