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