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