diff options
author | Tor Andersson <tor.andersson@artifex.com> | 2011-04-19 23:49:56 +0200 |
---|---|---|
committer | Tor Andersson <tor.andersson@artifex.com> | 2011-04-19 23:49:56 +0200 |
commit | 781969994b5381ba4bed03beef217f9bde6e7c58 (patch) | |
tree | aede27c7532f0fbe82f03dc0c04c9316be510fd5 /pl | |
parent | 0b17959f31afe3baffbc328e7f92e88e634ad8b8 (diff) |
Indent with spaces and strip trailing whitespace.
Diffstat (limited to 'pl')
-rw-r--r-- | pl/dwimg.c | 1976 | ||||
-rw-r--r-- | pl/dwimg.h | 2 | ||||
-rw-r--r-- | pl/dwmainc.c | 232 | ||||
-rw-r--r-- | pl/dwreg.c | 53 | ||||
-rw-r--r-- | pl/dwreg.h | 2 | ||||
-rw-r--r-- | pl/dwres.h | 2 | ||||
-rw-r--r-- | pl/pjparse.c | 852 | ||||
-rw-r--r-- | pl/pjparse.h | 12 | ||||
-rw-r--r-- | pl/pjparsei.c | 164 | ||||
-rw-r--r-- | pl/pjtop.c | 40 | ||||
-rw-r--r-- | pl/pjtop.h | 17 | ||||
-rw-r--r-- | pl/plalloc.c | 4 | ||||
-rw-r--r-- | pl/plalloc.h | 2 | ||||
-rw-r--r-- | pl/plapi.h | 15 | ||||
-rw-r--r-- | pl/plchar.c | 357 | ||||
-rw-r--r-- | pl/pldict.c | 256 | ||||
-rw-r--r-- | pl/pldict.h | 4 | ||||
-rw-r--r-- | pl/pldraw.c | 14 | ||||
-rw-r--r-- | pl/plfont.c | 916 | ||||
-rw-r--r-- | pl/plfont.h | 22 | ||||
-rw-r--r-- | pl/plftable.c | 97 | ||||
-rw-r--r-- | pl/plht.c | 2 | ||||
-rw-r--r-- | pl/plimpl.c | 14 | ||||
-rw-r--r-- | pl/pllfont.c | 4 | ||||
-rw-r--r-- | pl/plmain.c | 105 | ||||
-rw-r--r-- | pl/plplatf.c | 4 | ||||
-rw-r--r-- | pl/plplatf.h | 2 | ||||
-rw-r--r-- | pl/plplatfps.c | 4 | ||||
-rw-r--r-- | pl/plsrgb.c | 54 | ||||
-rw-r--r-- | pl/plsymbol.c | 22 | ||||
-rw-r--r-- | pl/plsymbol.h | 4 | ||||
-rw-r--r-- | pl/pltop.c | 105 | ||||
-rw-r--r-- | pl/pltop.h | 11 | ||||
-rw-r--r-- | pl/pltoputl.c | 70 | ||||
-rw-r--r-- | pl/pltoputl.h | 8 | ||||
-rw-r--r-- | pl/pluchar.c | 43 | ||||
-rw-r--r-- | pl/plufont.c | 14 | ||||
-rw-r--r-- | pl/plulfont.c | 45 | ||||
-rw-r--r-- | pl/plvocab.c | 12 |
39 files changed, 2730 insertions, 2832 deletions
diff --git a/pl/dwimg.c b/pl/dwimg.c index d6d10ef96..e168aa62d 100644 --- a/pl/dwimg.c +++ b/pl/dwimg.c @@ -41,7 +41,6 @@ #include "dwreg.h" #include "gdevdsp.h" - static const char szImgName2[] = "Ghostscript Image"; static const char szTrcName2[] = "Ghostscript Graphical Trace"; @@ -70,7 +69,6 @@ static void create_window(IMAGE *img); # define max(a, b) (((a) > (b)) ? (a) : (b)) #endif - /* GUI thread only */ void image_color(unsigned int format, int index, unsigned char *r, unsigned char *g, unsigned char *b); @@ -90,14 +88,13 @@ void image_32CMYK_to_24BGR(int width, unsigned char *dest, void image_devicen_to_24BGR(int width, unsigned char *dest, unsigned char *source, IMAGE_DEVICEN *devicen, int devicen_gray); - /****************************************************************/ /* These functions are only accessed by the main thread */ IMAGE *first_image = NULL; static HWND img_hwndtext = (HWND)0; -void +void image_textwindow(HWND hwnd) { /* Save the handle to the text window in a global variable @@ -115,8 +112,8 @@ image_find(void *handle, void *device) { IMAGE *img; for (img = first_image; img!=0; img=img->next) { - if ((img->handle == handle) && (img->device == device)) - return img; + if ((img->handle == handle) && (img->device == device)) + return img; } return NULL; } @@ -129,20 +126,20 @@ image_new(void *handle, void *device) IMAGE *img = (IMAGE *)malloc(sizeof(IMAGE)); if (img) { memset(img, 0, sizeof(IMAGE)); - /* remember device and handle */ - img->handle = handle; - img->device = device; - img->hwndtext = img_hwndtext; + /* remember device and handle */ + img->handle = handle; + img->device = device; + img->hwndtext = img_hwndtext; - img->update_tick = 100; /* milliseconds */ - img->update_interval = 1; /* 1 tick */ - img->update_count = 0; + img->update_tick = 100; /* milliseconds */ + img->update_interval = 1; /* 1 tick */ + img->update_count = 0; img->hmutex = INVALID_HANDLE_VALUE; - /* add to list */ - img->next = first_image; - first_image = img; + /* add to list */ + img->next = first_image; + first_image = img; } return img; } @@ -154,19 +151,18 @@ image_delete(IMAGE *img) { /* remove from list */ if (img == first_image) { - first_image = img->next; + first_image = img->next; } else { - IMAGE *tmp; - for (tmp = first_image; tmp!=0; tmp=tmp->next) { - if (img == tmp->next) - tmp->next = img->next; - } + IMAGE *tmp; + for (tmp = first_image; tmp!=0; tmp=tmp->next) { + if (img == tmp->next) + tmp->next = img->next; + } } /* Note: img is freed by image_close, not image_delete */ } - /* resize image */ /* valid for main thread */ int @@ -186,134 +182,134 @@ image_size(IMAGE *img, int new_width, int new_height, int new_raster, /* Reset separations */ for (i=0; i<IMAGE_DEVICEN_MAX; i++) { - img->devicen[i].used = 0; - img->devicen[i].visible = 1; - memset(img->devicen[i].name, 0, sizeof(img->devicen[i].name)); - img->devicen[i].cyan = 0; - img->devicen[i].magenta = 0; - img->devicen[i].yellow = 0; - img->devicen[i].black = 0; + img->devicen[i].used = 0; + img->devicen[i].visible = 1; + memset(img->devicen[i].name, 0, sizeof(img->devicen[i].name)); + img->devicen[i].cyan = 0; + img->devicen[i].magenta = 0; + img->devicen[i].yellow = 0; + img->devicen[i].black = 0; } switch (img->format & DISPLAY_COLORS_MASK) { - case DISPLAY_COLORS_NATIVE: - switch (img->format & DISPLAY_DEPTH_MASK) { - case DISPLAY_DEPTH_1: - img->bmih.biBitCount = 1; - img->bmih.biClrUsed = 2; - img->bmih.biClrImportant = 2; - break; - case DISPLAY_DEPTH_4: - /* Fixed color palette */ - img->bmih.biBitCount = 4; - img->bmih.biClrUsed = 16; - img->bmih.biClrImportant = 16; - break; - case DISPLAY_DEPTH_8: - /* Fixed color palette */ - img->bmih.biBitCount = 8; - img->bmih.biClrUsed = 96; - img->bmih.biClrImportant = 96; - break; - case DISPLAY_DEPTH_16: - /* RGB bitfields */ - /* Bit fields */ - if ((img->format & DISPLAY_ENDIAN_MASK) - == DISPLAY_BIGENDIAN) { - /* convert to 24BGR */ - img->bmih.biBitCount = 24; - img->bmih.biClrUsed = 0; - img->bmih.biClrImportant = 0; - } - else { - img->bmih.biBitCount = 16; - img->bmih.biClrUsed = 0; - img->bmih.biClrImportant = 0; - } - break; - default: - return DISPLAY_ERROR; - } - break; - case DISPLAY_COLORS_GRAY: - switch (img->format & DISPLAY_DEPTH_MASK) { - case DISPLAY_DEPTH_1: - img->bmih.biBitCount = 1; - img->bmih.biClrUsed = 2; - img->bmih.biClrImportant = 2; - break; - case DISPLAY_DEPTH_4: - /* Fixed gray palette */ - img->bmih.biBitCount = 4; - img->bmih.biClrUsed = 16; - img->bmih.biClrImportant = 16; - break; - case DISPLAY_DEPTH_8: - /* Fixed gray palette */ - img->bmih.biBitCount = 8; - img->bmih.biClrUsed = 256; - img->bmih.biClrImportant = 256; - break; - default: - return DISPLAY_ERROR; - } - break; - case DISPLAY_COLORS_RGB: - if ((img->format & DISPLAY_DEPTH_MASK) != DISPLAY_DEPTH_8) - return DISPLAY_ERROR; - if (((img->format & DISPLAY_ALPHA_MASK) == DISPLAY_UNUSED_LAST) && - ((img->format & DISPLAY_ENDIAN_MASK) == DISPLAY_LITTLEENDIAN)) { - /* use bitfields to display this */ - img->bmih.biBitCount = 32; - img->bmih.biClrUsed = 0; - img->bmih.biClrImportant = 0; - } - else { - /* either native BGR, or we need to convert it */ - img->bmih.biBitCount = 24; - img->bmih.biClrUsed = 0; - img->bmih.biClrImportant = 0; - } - break; - case DISPLAY_COLORS_CMYK: - switch (img->format & DISPLAY_DEPTH_MASK) { - case DISPLAY_DEPTH_1: - case DISPLAY_DEPTH_8: - /* we can convert these formats */ - break; - default: - return DISPLAY_ERROR; - } - /* we can't display this natively */ - /* we will convert it just before displaying */ - img->bmih.biBitCount = 24; - img->bmih.biClrUsed = 0; - img->bmih.biClrImportant = 0; - img->devicen[0].used = 1; - img->devicen[0].cyan = 65535; - /* We already know about the CMYK components */ - strncpy(img->devicen[0].name, "Cyan", - sizeof(img->devicen[0].name)); - img->devicen[1].used = 1; - img->devicen[1].magenta = 65535; - strncpy(img->devicen[1].name, "Magenta", - sizeof(img->devicen[1].name)); - img->devicen[2].used = 1; - img->devicen[2].yellow = 65535; - strncpy(img->devicen[2].name, "Yellow", - sizeof(img->devicen[2].name)); - img->devicen[3].used = 1; - img->devicen[3].black = 65535; - strncpy(img->devicen[3].name, "Black", - sizeof(img->devicen[3].name)); - break; - case DISPLAY_COLORS_SEPARATION: - /* we can't display this natively */ - /* we will convert it just before displaying */ - img->bmih.biBitCount = 24; - img->bmih.biClrUsed = 0; - img->bmih.biClrImportant = 0; - break; + case DISPLAY_COLORS_NATIVE: + switch (img->format & DISPLAY_DEPTH_MASK) { + case DISPLAY_DEPTH_1: + img->bmih.biBitCount = 1; + img->bmih.biClrUsed = 2; + img->bmih.biClrImportant = 2; + break; + case DISPLAY_DEPTH_4: + /* Fixed color palette */ + img->bmih.biBitCount = 4; + img->bmih.biClrUsed = 16; + img->bmih.biClrImportant = 16; + break; + case DISPLAY_DEPTH_8: + /* Fixed color palette */ + img->bmih.biBitCount = 8; + img->bmih.biClrUsed = 96; + img->bmih.biClrImportant = 96; + break; + case DISPLAY_DEPTH_16: + /* RGB bitfields */ + /* Bit fields */ + if ((img->format & DISPLAY_ENDIAN_MASK) + == DISPLAY_BIGENDIAN) { + /* convert to 24BGR */ + img->bmih.biBitCount = 24; + img->bmih.biClrUsed = 0; + img->bmih.biClrImportant = 0; + } + else { + img->bmih.biBitCount = 16; + img->bmih.biClrUsed = 0; + img->bmih.biClrImportant = 0; + } + break; + default: + return DISPLAY_ERROR; + } + break; + case DISPLAY_COLORS_GRAY: + switch (img->format & DISPLAY_DEPTH_MASK) { + case DISPLAY_DEPTH_1: + img->bmih.biBitCount = 1; + img->bmih.biClrUsed = 2; + img->bmih.biClrImportant = 2; + break; + case DISPLAY_DEPTH_4: + /* Fixed gray palette */ + img->bmih.biBitCount = 4; + img->bmih.biClrUsed = 16; + img->bmih.biClrImportant = 16; + break; + case DISPLAY_DEPTH_8: + /* Fixed gray palette */ + img->bmih.biBitCount = 8; + img->bmih.biClrUsed = 256; + img->bmih.biClrImportant = 256; + break; + default: + return DISPLAY_ERROR; + } + break; + case DISPLAY_COLORS_RGB: + if ((img->format & DISPLAY_DEPTH_MASK) != DISPLAY_DEPTH_8) + return DISPLAY_ERROR; + if (((img->format & DISPLAY_ALPHA_MASK) == DISPLAY_UNUSED_LAST) && + ((img->format & DISPLAY_ENDIAN_MASK) == DISPLAY_LITTLEENDIAN)) { + /* use bitfields to display this */ + img->bmih.biBitCount = 32; + img->bmih.biClrUsed = 0; + img->bmih.biClrImportant = 0; + } + else { + /* either native BGR, or we need to convert it */ + img->bmih.biBitCount = 24; + img->bmih.biClrUsed = 0; + img->bmih.biClrImportant = 0; + } + break; + case DISPLAY_COLORS_CMYK: + switch (img->format & DISPLAY_DEPTH_MASK) { + case DISPLAY_DEPTH_1: + case DISPLAY_DEPTH_8: + /* we can convert these formats */ + break; + default: + return DISPLAY_ERROR; + } + /* we can't display this natively */ + /* we will convert it just before displaying */ + img->bmih.biBitCount = 24; + img->bmih.biClrUsed = 0; + img->bmih.biClrImportant = 0; + img->devicen[0].used = 1; + img->devicen[0].cyan = 65535; + /* We already know about the CMYK components */ + strncpy(img->devicen[0].name, "Cyan", + sizeof(img->devicen[0].name)); + img->devicen[1].used = 1; + img->devicen[1].magenta = 65535; + strncpy(img->devicen[1].name, "Magenta", + sizeof(img->devicen[1].name)); + img->devicen[2].used = 1; + img->devicen[2].yellow = 65535; + strncpy(img->devicen[2].name, "Yellow", + sizeof(img->devicen[2].name)); + img->devicen[3].used = 1; + img->devicen[3].black = 65535; + strncpy(img->devicen[3].name, "Black", + sizeof(img->devicen[3].name)); + break; + case DISPLAY_COLORS_SEPARATION: + /* we can't display this natively */ + /* we will convert it just before displaying */ + img->bmih.biBitCount = 24; + img->bmih.biClrUsed = 0; + img->bmih.biClrImportant = 0; + break; } img->bmih.biCompression = 0; @@ -323,7 +319,7 @@ image_size(IMAGE *img, int new_width, int new_height, int new_raster, img->bytewidth = ((img->bmih.biWidth * img->bmih.biBitCount + 31 ) & ~31) >> 3; if (img->palette) - DeleteObject(img->palette); + DeleteObject(img->palette); img->palette = create_palette(img); return 0; @@ -336,10 +332,10 @@ image_separation(IMAGE *img, unsigned short y, unsigned short k) { if ((comp_num < 0) || (comp_num > IMAGE_DEVICEN_MAX)) - return DISPLAY_ERROR; + return DISPLAY_ERROR; img->devicen[comp_num].used = 1; strncpy(img->devicen[comp_num].name, name, - sizeof(img->devicen[comp_num].name)-1); + sizeof(img->devicen[comp_num].name)-1); img->devicen[comp_num].cyan = c; img->devicen[comp_num].magenta = m; img->devicen[comp_num].yellow = y; @@ -347,7 +343,6 @@ image_separation(IMAGE *img, return 0; } - /****************************************************************/ /* These functions are only accessed by the GUI thread */ @@ -370,17 +365,16 @@ image_close(IMAGE *img) img->hwnd = NULL; if (img->palette) - DeleteObject(img->palette); + DeleteObject(img->palette); img->palette = NULL; if (img->hBrush) - DeleteObject(img->hBrush); + DeleteObject(img->hBrush); img->hBrush = NULL; free(img); } - void register_class(void) { @@ -410,36 +404,36 @@ void image_separations(IMAGE *img) HMENU sysmenu = GetSystemMenu(img->hwnd, FALSE); if (((img->format & DISPLAY_COLORS_MASK) == DISPLAY_COLORS_CMYK) || ((img->format & DISPLAY_COLORS_MASK) == DISPLAY_COLORS_SEPARATION)) { - /* Add menus if needed */ - for (i=0; i<IMAGE_DEVICEN_MAX; i++) { - exist = 0; - if (img->devicen[i].menu) - exist = GetMenuString(sysmenu, M_SEPARATION+i, - buf, sizeof(buf)-1, MF_BYCOMMAND) != 0; - if (exist && (strcmp(img->devicen[i].name, buf) != 0)) { - /* remove it because name changed */ - RemoveMenu(sysmenu, M_SEPARATION+i, MF_BYCOMMAND); - img->devicen[i].menu = 0; - } - if (img->devicen[i].name[0] && !img->devicen[i].menu) { - AppendMenu(sysmenu, MF_STRING | MF_CHECKED, - M_SEPARATION+i, img->devicen[i].name); - img->devicen[i].menu = 1; - } - if (img->devicen[i].used && img->devicen[i].visible) - num_visible++; - } - EnableMenuItem(sysmenu, M_DEVICEN_GRAY, - MF_BYCOMMAND | ((num_visible <= 1) ? MF_ENABLED : MF_GRAYED)); + /* Add menus if needed */ + for (i=0; i<IMAGE_DEVICEN_MAX; i++) { + exist = 0; + if (img->devicen[i].menu) + exist = GetMenuString(sysmenu, M_SEPARATION+i, + buf, sizeof(buf)-1, MF_BYCOMMAND) != 0; + if (exist && (strcmp(img->devicen[i].name, buf) != 0)) { + /* remove it because name changed */ + RemoveMenu(sysmenu, M_SEPARATION+i, MF_BYCOMMAND); + img->devicen[i].menu = 0; + } + if (img->devicen[i].name[0] && !img->devicen[i].menu) { + AppendMenu(sysmenu, MF_STRING | MF_CHECKED, + M_SEPARATION+i, img->devicen[i].name); + img->devicen[i].menu = 1; + } + if (img->devicen[i].used && img->devicen[i].visible) + num_visible++; + } + EnableMenuItem(sysmenu, M_DEVICEN_GRAY, + MF_BYCOMMAND | ((num_visible <= 1) ? MF_ENABLED : MF_GRAYED)); } else { - for (i=0; i<IMAGE_DEVICEN_MAX; i++) { - if (img->devicen[i].menu) { - RemoveMenu(sysmenu, M_SEPARATION+i, MF_BYCOMMAND); - img->devicen[i].menu = 0; - } - } - EnableMenuItem(sysmenu, M_DEVICEN_GRAY, MF_BYCOMMAND | MF_GRAYED); + for (i=0; i<IMAGE_DEVICEN_MAX; i++) { + if (img->devicen[i].menu) { + RemoveMenu(sysmenu, M_SEPARATION+i, MF_BYCOMMAND); + img->devicen[i].menu = 0; + } + } + EnableMenuItem(sysmenu, M_DEVICEN_GRAY, MF_BYCOMMAND | MF_GRAYED); } } @@ -449,18 +443,17 @@ void sep_menu(IMAGE *img, int component) int num_visible = 0; img->devicen[component].visible = !img->devicen[component].visible; CheckMenuItem(GetSystemMenu(img->hwnd, FALSE), - M_SEPARATION+component, - (img->devicen[component].visible ? MF_CHECKED : MF_UNCHECKED)); + M_SEPARATION+component, + (img->devicen[component].visible ? MF_CHECKED : MF_UNCHECKED)); for (i=0; i<IMAGE_DEVICEN_MAX; i++) if (img->devicen[i].used && img->devicen[i].visible) - num_visible++; + num_visible++; EnableMenuItem(GetSystemMenu(img->hwnd, FALSE), M_DEVICEN_GRAY, - MF_BYCOMMAND | ((num_visible <= 1) ? MF_ENABLED : MF_GRAYED)); + MF_BYCOMMAND | ((num_visible <= 1) ? MF_ENABLED : MF_GRAYED)); InvalidateRect(img->hwnd, NULL, 0); UpdateWindow(img->hwnd); } - static void create_window(IMAGE *img) { @@ -475,11 +468,11 @@ create_window(IMAGE *img) lb.lbHatch = 0; lb.lbColor = GetSysColor(COLOR_WINDOW); if (lb.lbColor = RGB(255,255,255)) /* Don't allow white */ - lb.lbColor = GetSysColor(COLOR_MENU); + lb.lbColor = GetSysColor(COLOR_MENU); if (lb.lbColor = RGB(255,255,255)) /* Don't allow white */ - lb.lbColor = GetSysColor(COLOR_APPWORKSPACE); + lb.lbColor = GetSysColor(COLOR_APPWORKSPACE); if (lb.lbColor = RGB(255,255,255)) /* Don't allow white */ - lb.lbColor = RGB(192,192,192); + lb.lbColor = RGB(192,192,192); img->hBrush = CreateBrushIndirect(&lb); img->cxClient = img->cyClient = 0; @@ -487,54 +480,54 @@ create_window(IMAGE *img) img->nHscrollPos = img->nHscrollMax = 0; img->x = img->y = img->cx = img->cy = CW_USEDEFAULT; if (win_get_reg_value((img->device != NULL ? "Image" : "Tracer"), winposbuf, &len) == 0) { - int x, y, cx, cy; - - if (sscanf(winposbuf, "%d %d %d %d", &x, &y, &cx, &cy) == 4) { - img->x = x; - img->y = y; - img->cx = cx; - img->cy = cy; - } + int x, y, cx, cy; + + if (sscanf(winposbuf, "%d %d %d %d", &x, &y, &cx, &cy) == 4) { + img->x = x; + img->y = y; + img->cx = cx; + img->cy = cy; + } } strcpy(window_title, (img->device != NULL ? (LPSTR)szImgName2 : (LPSTR)szTrcName2)); { /* * This section is for debug purpose only. - * It allows to replace window title so that user can identify window - * when multiple instances of the application run in same time. - * Create gs\bin\gswin32.ini or gs\bin\gswin32c.ini and - * put an identifier to there like this : - * - * [Window] - * Title=Current Revision - * - * It is useful to compare images generated with different revisions. - */ + * It allows to replace window title so that user can identify window + * when multiple instances of the application run in same time. + * Create gs\bin\gswin32.ini or gs\bin\gswin32c.ini and + * put an identifier to there like this : + * + * [Window] + * Title=Current Revision + * + * It is useful to compare images generated with different revisions. + */ char ini_path[MAX_PATH]; - DWORD ini_path_length; - - ini_path_length = GetModuleFileName(NULL, ini_path, sizeof(ini_path)); - if (ini_path_length > 0) { - int i = ini_path_length - 1; - for (; i>=0; i--) - if(ini_path[i] == '.') - break; - if (i < sizeof(ini_path) - 4) { - strcpy(ini_path + i, ".ini"); - GetPrivateProfileString("Window", "Title", - (img->device != NULL ? (LPSTR)szImgName2 : (LPSTR)szTrcName2), - window_title, sizeof(window_title), ini_path); - } - } + DWORD ini_path_length; + + ini_path_length = GetModuleFileName(NULL, ini_path, sizeof(ini_path)); + if (ini_path_length > 0) { + int i = ini_path_length - 1; + for (; i>=0; i--) + if(ini_path[i] == '.') + break; + if (i < sizeof(ini_path) - 4) { + strcpy(ini_path + i, ".ini"); + GetPrivateProfileString("Window", "Title", + (img->device != NULL ? (LPSTR)szImgName2 : (LPSTR)szTrcName2), + window_title, sizeof(window_title), ini_path); + } + } } /* create window */ img->hwnd = CreateWindow(szImgName2, window_title, - WS_OVERLAPPEDWINDOW, - img->x, img->y, img->cx, img->cy, - NULL, NULL, GetModuleHandle(NULL), (void *)img); + WS_OVERLAPPEDWINDOW, + img->x, img->y, img->cx, img->cy, + NULL, NULL, GetModuleHandle(NULL), (void *)img); if (img->device == NULL && img->x != CW_USEDEFAULT && - img->y != CW_USEDEFAULT && - img->cx != CW_USEDEFAULT && - img->cy != CW_USEDEFAULT) + img->y != CW_USEDEFAULT && + img->cx != CW_USEDEFAULT && + img->cy != CW_USEDEFAULT) MoveWindow(img->hwnd, img->x, img->y, img->cx, img->cy, FALSE); ShowWindow(img->hwnd, (img->device != NULL ? SW_SHOWMINNOACTIVE : SW_SHOW)); @@ -548,17 +541,16 @@ create_window(IMAGE *img) image_separations(img); } - void image_poll(IMAGE *img) { if ((img->bmih.biWidth == 0) || (img->bmih.biHeight == 0)) - return; + return; img->pending_update = 1; if (img->update_timer == 0) { - img->update_timer = 1; - img->update_count = 0; - SetTimer(img->hwnd, img->update_timer, img->update_tick, NULL); + img->update_timer = 1; + img->update_count = 0; + SetTimer(img->hwnd, img->update_timer, img->update_tick, NULL); } } @@ -570,37 +562,36 @@ image_update_now(IMAGE *img) SYSTEMTIME t2; int delta; if ( !IsWindow(img->hwnd) ) /* some clod closed the window */ - create_window(img); + create_window(img); if ( !IsIconic(img->hwnd) ) { /* redraw window */ - GetSystemTime(&t1); - InvalidateRect(img->hwnd, NULL, 1); - UpdateWindow(img->hwnd); - GetSystemTime(&t2); - /* Make sure the update interval is at least 10 times - * what it takes to paint the window - */ - delta = (t2.wSecond - t1.wSecond)*1000 + - (t2.wMilliseconds - t1.wMilliseconds); - if (delta < 0) - delta += 60000; - delta = 10 * delta / img->update_tick + 1; - if (delta > img->update_interval) - img->update_interval = delta; - else if ((delta >= 2) && - (delta < img->update_interval / 4)) - img->update_interval = delta/2; + GetSystemTime(&t1); + InvalidateRect(img->hwnd, NULL, 1); + UpdateWindow(img->hwnd); + GetSystemTime(&t2); + /* Make sure the update interval is at least 10 times + * what it takes to paint the window + */ + delta = (t2.wSecond - t1.wSecond)*1000 + + (t2.wMilliseconds - t1.wMilliseconds); + if (delta < 0) + delta += 60000; + delta = 10 * delta / img->update_tick + 1; + if (delta > img->update_interval) + img->update_interval = delta; + else if ((delta >= 2) && + (delta < img->update_interval / 4)) + img->update_interval = delta/2; } img->update_count = 0; } - void image_sync(IMAGE *img) { if (img->update_timer) { - /* stop timer when nothing is happening */ - KillTimer(img->hwnd, img->update_timer); + /* stop timer when nothing is happening */ + KillTimer(img->hwnd, img->update_timer); img->update_timer = 0; } img->pending_sync = 0; @@ -609,18 +600,16 @@ image_sync(IMAGE *img) img->pending_update = 0; } - void image_page(IMAGE *img) { if (IsIconic(img->hwnd)) /* useless as an Icon so fix it */ - ShowWindow(img->hwnd, SW_SHOWNORMAL); + ShowWindow(img->hwnd, SW_SHOWNORMAL); BringWindowToTop(img->hwnd); image_sync(img); } - /* GUI thread */ void image_updatesize(IMAGE *img) @@ -630,13 +619,13 @@ image_updatesize(IMAGE *img) image_separations(img); /* update scroll bars */ if (!IsIconic(img->hwnd)) { - if (IsZoomed(img->hwnd)) - nSizeType = SIZE_MAXIMIZED; - else - nSizeType = SIZE_RESTORED; - GetClientRect(img->hwnd, &rect); - SendMessage(img->hwnd, WM_SIZE, nSizeType, - MAKELONG(rect.right, rect.bottom)); + if (IsZoomed(img->hwnd)) + nSizeType = SIZE_MAXIMIZED; + else + nSizeType = SIZE_RESTORED; + GetClientRect(img->hwnd, &rect); + SendMessage(img->hwnd, WM_SIZE, nSizeType, + MAKELONG(rect.right, rect.bottom)); } } @@ -645,56 +634,55 @@ image_color(unsigned int format, int index, unsigned char *r, unsigned char *g, unsigned char *b) { switch (format & DISPLAY_COLORS_MASK) { - case DISPLAY_COLORS_NATIVE: - switch (format & DISPLAY_DEPTH_MASK) { - case DISPLAY_DEPTH_1: - *r = *g = *b = (index ? 0 : 255); - break; - case DISPLAY_DEPTH_4: - if (index == 7) - *r = *g = *b = 170; - else if (index == 8) - *r = *g = *b = 85; - else { - int one = index & 8 ? 255 : 128; - *r = (index & 4 ? one : 0); - *g = (index & 2 ? one : 0); - *b = (index & 1 ? one : 0); - } - break; - case DISPLAY_DEPTH_8: - /* palette of 96 colors */ - /* 0->63 = 00RRGGBB, 64->95 = 010YYYYY */ - if (index < 64) { - int one = 255 / 3; - *r = ((index & 0x30) >> 4) * one; - *g = ((index & 0x0c) >> 2) * one; - *b = (index & 0x03) * one; - } - else { - int val = index & 0x1f; - *r = *g = *b = (val << 3) + (val >> 2); - } - break; - } - break; - case DISPLAY_COLORS_GRAY: - switch (format & DISPLAY_DEPTH_MASK) { - case DISPLAY_DEPTH_1: - *r = *g = *b = (index ? 255 : 0); - break; - case DISPLAY_DEPTH_4: - *r = *g = *b = (unsigned char)((index<<4) + index); - break; - case DISPLAY_DEPTH_8: - *r = *g = *b = (unsigned char)index; - break; - } - break; + case DISPLAY_COLORS_NATIVE: + switch (format & DISPLAY_DEPTH_MASK) { + case DISPLAY_DEPTH_1: + *r = *g = *b = (index ? 0 : 255); + break; + case DISPLAY_DEPTH_4: + if (index == 7) + *r = *g = *b = 170; + else if (index == 8) + *r = *g = *b = 85; + else { + int one = index & 8 ? 255 : 128; + *r = (index & 4 ? one : 0); + *g = (index & 2 ? one : 0); + *b = (index & 1 ? one : 0); + } + break; + case DISPLAY_DEPTH_8: + /* palette of 96 colors */ + /* 0->63 = 00RRGGBB, 64->95 = 010YYYYY */ + if (index < 64) { + int one = 255 / 3; + *r = ((index & 0x30) >> 4) * one; + *g = ((index & 0x0c) >> 2) * one; + *b = (index & 0x03) * one; + } + else { + int val = index & 0x1f; + *r = *g = *b = (val << 3) + (val >> 2); + } + break; + } + break; + case DISPLAY_COLORS_GRAY: + switch (format & DISPLAY_DEPTH_MASK) { + case DISPLAY_DEPTH_1: + *r = *g = *b = (index ? 255 : 0); + break; + case DISPLAY_DEPTH_4: + *r = *g = *b = (unsigned char)((index<<4) + index); + break; + case DISPLAY_DEPTH_8: + *r = *g = *b = (unsigned char)index; + break; + } + break; } } - /* convert one line of 16BGR555 to 24BGR */ /* byte0=GGGBBBBB byte1=0RRRRRGG */ void @@ -704,14 +692,14 @@ image_16BGR555_to_24BGR(int width, unsigned char *dest, unsigned char *source) WORD w; unsigned char value; for (i=0; i<width; i++) { - w = source[0] + (source[1] << 8); - value = w & 0x1f; /* blue */ - *dest++ = (value << 3) + (value >> 2); - value = (w >> 5) & 0x1f; /* green */ - *dest++ = (value << 3) + (value >> 2); - value = (w >> 10) & 0x1f; /* red */ - *dest++ = (value << 3) + (value >> 2); - source += 2; + w = source[0] + (source[1] << 8); + value = w & 0x1f; /* blue */ + *dest++ = (value << 3) + (value >> 2); + value = (w >> 5) & 0x1f; /* green */ + *dest++ = (value << 3) + (value >> 2); + value = (w >> 10) & 0x1f; /* red */ + *dest++ = (value << 3) + (value >> 2); + source += 2; } } @@ -724,14 +712,14 @@ image_16BGR565_to_24BGR(int width, unsigned char *dest, unsigned char *source) WORD w; unsigned char value; for (i=0; i<width; i++) { - w = source[0] + (source[1] << 8); - value = w & 0x1f; /* blue */ - *dest++ = (value << 3) + (value >> 2); - value = (w >> 5) & 0x3f; /* green */ - *dest++ = (value << 2) + (value >> 4); - value = (w >> 11) & 0x1f; /* red */ - *dest++ = (value << 3) + (value >> 2); - source += 2; + w = source[0] + (source[1] << 8); + value = w & 0x1f; /* blue */ + *dest++ = (value << 3) + (value >> 2); + value = (w >> 5) & 0x3f; /* green */ + *dest++ = (value << 2) + (value >> 4); + value = (w >> 11) & 0x1f; /* red */ + *dest++ = (value << 3) + (value >> 2); + source += 2; } } @@ -744,14 +732,14 @@ image_16RGB555_to_24BGR(int width, unsigned char *dest, unsigned char *source) WORD w; unsigned char value; for (i=0; i<width; i++) { - w = (source[0] << 8) + source[1]; - value = w & 0x1f; /* blue */ - *dest++ = (value << 3) + (value >> 2); - value = (w >> 5) & 0x1f; /* green */ - *dest++ = (value << 3) + (value >> 2); - value = (w >> 10) & 0x1f; /* red */ - *dest++ = (value << 3) + (value >> 2); - source += 2; + w = (source[0] << 8) + source[1]; + value = w & 0x1f; /* blue */ + *dest++ = (value << 3) + (value >> 2); + value = (w >> 5) & 0x1f; /* green */ + *dest++ = (value << 3) + (value >> 2); + value = (w >> 10) & 0x1f; /* red */ + *dest++ = (value << 3) + (value >> 2); + source += 2; } } @@ -764,14 +752,14 @@ image_16RGB565_to_24BGR(int width, unsigned char *dest, unsigned char *source) WORD w; unsigned char value; for (i=0; i<width; i++) { - w = (source[0] << 8) + source[1]; - value = w & 0x1f; /* blue */ - *dest++ = (value << 3) + (value >> 2); - value = (w >> 5) & 0x3f; /* green */ - *dest++ = (value << 2) + (value >> 4); - value = (w >> 11) & 0x1f; /* red */ - *dest++ = (value << 3) + (value >> 2); - source += 2; + w = (source[0] << 8) + source[1]; + value = w & 0x1f; /* blue */ + *dest++ = (value << 3) + (value >> 2); + value = (w >> 5) & 0x3f; /* green */ + *dest++ = (value << 2) + (value >> 4); + value = (w >> 11) & 0x1f; /* red */ + *dest++ = (value << 3) + (value >> 2); + source += 2; } } @@ -790,29 +778,29 @@ image_4CMYK_to_24BGR(int width, unsigned char *dest, unsigned char *source, int value; for (i=0; i<width; i++) { value = source[i/2]; - if (i & 0) - value >>= 4; - cyan = ((value >> 3) & 1) * 255; - magenta = ((value >> 2) & 1) * 255; - yellow = ((value >> 1) & 1) * 255; - black = (value & 1) * 255; - if (!vall) { - if (!vc) - cyan = 0; - if (!vm) - magenta = 0; - if (!vy) - yellow = 0; - if (!vk) - black = 0; - if (show_gray) { - black += cyan + magenta + yellow; - cyan = magenta = yellow = 0; - } - } - *dest++ = (255 - yellow) * (255 - black)/255; /* blue */ - *dest++ = (255 - magenta) * (255 - black)/255; /* green */ - *dest++ = (255 - cyan) * (255 - black)/255; /* red */ + if (i & 0) + value >>= 4; + cyan = ((value >> 3) & 1) * 255; + magenta = ((value >> 2) & 1) * 255; + yellow = ((value >> 1) & 1) * 255; + black = (value & 1) * 255; + if (!vall) { + if (!vc) + cyan = 0; + if (!vm) + magenta = 0; + if (!vy) + yellow = 0; + if (!vk) + black = 0; + if (show_gray) { + black += cyan + magenta + yellow; + cyan = magenta = yellow = 0; + } + } + *dest++ = (255 - yellow) * (255 - black)/255; /* blue */ + *dest++ = (255 - magenta) * (255 - black)/255; /* green */ + *dest++ = (255 - cyan) * (255 - black)/255; /* red */ } } @@ -830,28 +818,28 @@ image_32CMYK_to_24BGR(int width, unsigned char *dest, unsigned char *source, int vall = vc && vm && vy && vk; int show_gray = (vc + vm + vy + vk == 1) && devicen_gray; for (i=0; i<width; i++) { - cyan = source[0]; - magenta = source[1]; - yellow = source[2]; - black = source[3]; - if (!vall) { - if (!vc) - cyan = 0; - if (!vm) - magenta = 0; - if (!vy) - yellow = 0; - if (!vk) - black = 0; - if (show_gray) { - black += cyan + magenta + yellow; - cyan = magenta = yellow = 0; - } - } - *dest++ = (255 - yellow) * (255 - black)/255; /* blue */ - *dest++ = (255 - magenta) * (255 - black)/255; /* green */ - *dest++ = (255 - cyan) * (255 - black)/255; /* red */ - source += 4; + cyan = source[0]; + magenta = source[1]; + yellow = source[2]; + black = source[3]; + if (!vall) { + if (!vc) + cyan = 0; + if (!vm) + magenta = 0; + if (!vy) + yellow = 0; + if (!vk) + black = 0; + if (show_gray) { + black += cyan + magenta + yellow; + cyan = magenta = yellow = 0; + } + } + *dest++ = (255 - yellow) * (255 - black)/255; /* blue */ + *dest++ = (255 - magenta) * (255 - black)/255; /* green */ + *dest++ = (255 - cyan) * (255 - black)/255; /* red */ + source += 4; } } @@ -866,42 +854,42 @@ image_devicen_to_24BGR(int width, unsigned char *dest, unsigned char *source, int num_visible = 0; int show_gray = 0; for (j=0; j<IMAGE_DEVICEN_MAX; j++) { - if (devicen[j].used) { - num_comp = j+1; - if (devicen[j].visible) - num_visible++; - } + if (devicen[j].used) { + num_comp = j+1; + if (devicen[j].visible) + num_visible++; + } } if ((num_visible == 1) && devicen_gray) - show_gray = 1; + show_gray = 1; for (i=0; i<width; i++) { - cyan = magenta = yellow = black = 0; - for (j=0; j<num_comp; j++) { - if (devicen[j].visible && devicen[j].used) { - value = source[j]; - if (show_gray) - black += value; - else { - cyan += value * devicen[j].cyan / 65535; - magenta += value * devicen[j].magenta / 65535; - yellow += value * devicen[j].yellow / 65535; - black += value * devicen[j].black / 65535; - } - } - } - if (cyan > 255) - cyan = 255; - if (magenta > 255) - magenta = 255; - if (yellow > 255) - yellow = 255; - if (black > 255) - black = 255; - *dest++ = (255 - yellow) * (255 - black)/255; /* blue */ - *dest++ = (255 - magenta) * (255 - black)/255; /* green */ - *dest++ = (255 - cyan) * (255 - black)/255; /* red */ - source += 8; + cyan = magenta = yellow = black = 0; + for (j=0; j<num_comp; j++) { + if (devicen[j].visible && devicen[j].used) { + value = source[j]; + if (show_gray) + black += value; + else { + cyan += value * devicen[j].cyan / 65535; + magenta += value * devicen[j].magenta / 65535; + yellow += value * devicen[j].yellow / 65535; + black += value * devicen[j].black / 65535; + } + } + } + if (cyan > 255) + cyan = 255; + if (magenta > 255) + magenta = 255; + if (yellow > 255) + yellow = 255; + if (black > 255) + black = 255; + *dest++ = (255 - yellow) * (255 - black)/255; /* blue */ + *dest++ = (255 - magenta) * (255 - black)/255; /* green */ + *dest++ = (255 - cyan) * (255 - black)/255; /* red */ + source += 8; } } @@ -916,73 +904,73 @@ image_convert_line(IMAGE *img, unsigned char *dest, unsigned char *source) int i; switch (img->format & DISPLAY_COLORS_MASK) { - case DISPLAY_COLORS_NATIVE: - if ((img->format & DISPLAY_DEPTH_MASK) == DISPLAY_DEPTH_16) { - if (bigendian) { - if ((img->format & DISPLAY_555_MASK) - == DISPLAY_NATIVE_555) - image_16RGB555_to_24BGR(img->bmih.biWidth, - dest, source); - else - image_16RGB565_to_24BGR(img->bmih.biWidth, - dest, source); - } - else { - if ((img->format & DISPLAY_555_MASK) - == DISPLAY_NATIVE_555) { - image_16BGR555_to_24BGR(img->bmih.biWidth, - dest, source); - } - else - image_16BGR565_to_24BGR(img->bmih.biWidth, - dest, source); - } - } - break; - case DISPLAY_COLORS_RGB: - if ((img->format & DISPLAY_DEPTH_MASK) != DISPLAY_DEPTH_8) - return; - for (i=0; i<width; i++) { - if ((alpha == DISPLAY_ALPHA_FIRST) || - (alpha == DISPLAY_UNUSED_FIRST)) - s++; - if (bigendian) { - *d++ = s[2]; - *d++ = s[1]; - *d++ = s[0]; - s+=3; - } - else { - *d++ = *s++; - *d++ = *s++; - *d++ = *s++; - } - if ((alpha == DISPLAY_ALPHA_LAST) || - (alpha == DISPLAY_UNUSED_LAST)) - s++; - } + case DISPLAY_COLORS_NATIVE: + if ((img->format & DISPLAY_DEPTH_MASK) == DISPLAY_DEPTH_16) { + if (bigendian) { + if ((img->format & DISPLAY_555_MASK) + == DISPLAY_NATIVE_555) + image_16RGB555_to_24BGR(img->bmih.biWidth, + dest, source); + else + image_16RGB565_to_24BGR(img->bmih.biWidth, + dest, source); + } + else { + if ((img->format & DISPLAY_555_MASK) + == DISPLAY_NATIVE_555) { + image_16BGR555_to_24BGR(img->bmih.biWidth, + dest, source); + } + else + image_16BGR565_to_24BGR(img->bmih.biWidth, + dest, source); + } + } + break; + case DISPLAY_COLORS_RGB: + if ((img->format & DISPLAY_DEPTH_MASK) != DISPLAY_DEPTH_8) + return; + for (i=0; i<width; i++) { + if ((alpha == DISPLAY_ALPHA_FIRST) || + (alpha == DISPLAY_UNUSED_FIRST)) + s++; + if (bigendian) { + *d++ = s[2]; + *d++ = s[1]; + *d++ = s[0]; + s+=3; + } + else { + *d++ = *s++; + *d++ = *s++; + *d++ = *s++; + } + if ((alpha == DISPLAY_ALPHA_LAST) || + (alpha == DISPLAY_UNUSED_LAST)) + s++; + } /* printf("rgb, width=%d alpha=%d d=0x%x s=0x%x\n", width, alpha, (int)d, (int)s); printf(" d=0x%x s=0x%x\n", (int)d, (int)s); */ - break; - case DISPLAY_COLORS_CMYK: - if ((img->format & DISPLAY_DEPTH_MASK) == DISPLAY_DEPTH_8) - image_32CMYK_to_24BGR(width, dest, source, - img->devicen, img->devicen_gray); - else if ((img->format & DISPLAY_DEPTH_MASK) == DISPLAY_DEPTH_1) { - image_4CMYK_to_24BGR(width, dest, source, - img->devicen, img->devicen_gray); - } - else - return; - break; - case DISPLAY_COLORS_SEPARATION: - if ((img->format & DISPLAY_DEPTH_MASK) != DISPLAY_DEPTH_8) - return; - image_devicen_to_24BGR(width, dest, source, - img->devicen, img->devicen_gray); - break; + break; + case DISPLAY_COLORS_CMYK: + if ((img->format & DISPLAY_DEPTH_MASK) == DISPLAY_DEPTH_8) + image_32CMYK_to_24BGR(width, dest, source, + img->devicen, img->devicen_gray); + else if ((img->format & DISPLAY_DEPTH_MASK) == DISPLAY_DEPTH_1) { + image_4CMYK_to_24BGR(width, dest, source, + img->devicen, img->devicen_gray); + } + else + return; + break; + case DISPLAY_COLORS_SEPARATION: + if ((img->format & DISPLAY_DEPTH_MASK) != DISPLAY_DEPTH_8) + return; + image_devicen_to_24BGR(width, dest, source, + img->devicen, img->devicen_gray); + break; } } @@ -1007,28 +995,27 @@ copy_dib(IMAGE *img) /* Allocates memory for the clipboard bitmap */ if (img->bmih.biBitCount <= 1) - bitsperpixel = 1; + bitsperpixel = 1; else if (img->bmih.biBitCount <= 4) - bitsperpixel = 4; + bitsperpixel = 4; else if (img->bmih.biBitCount <= 8) - bitsperpixel = 8; + bitsperpixel = 8; else - bitsperpixel = 24; + bitsperpixel = 24; bytewidth = ((img->bmih.biWidth * bitsperpixel + 31 ) & ~31) >> 3; bitmapsize = bytewidth * img->bmih.biHeight; if (bitsperpixel > 8) - palcount = 0; /* 24-bit BGR */ + palcount = 0; /* 24-bit BGR */ else - palcount = img->bmih.biClrUsed; + palcount = img->bmih.biClrUsed; hglobal = GlobalAlloc(GHND | GMEM_SHARE, sizeof(BITMAPINFOHEADER) - + sizeof(RGBQUAD) * palcount + bitmapsize); + + sizeof(RGBQUAD) * palcount + bitmapsize); if (hglobal == (HGLOBAL) NULL) - return (HGLOBAL) NULL; + return (HGLOBAL) NULL; pDIB = (BYTE *) GlobalLock(hglobal); if (pDIB == (BYTE *) NULL) - return (HGLOBAL) NULL; - + return (HGLOBAL) NULL; /* initialize the clipboard bitmap */ pbmih = (BITMAPINFOHEADER *) (pDIB); @@ -1047,49 +1034,49 @@ copy_dib(IMAGE *img) pbmih->biClrImportant = palcount; for (i = 0; i < palcount; i++) { - image_color(img->format, i, &pColors[i].rgbRed, - &pColors[i].rgbGreen, &pColors[i].rgbBlue); - pColors[i].rgbReserved = 0; + image_color(img->format, i, &pColors[i].rgbRed, + &pColors[i].rgbGreen, &pColors[i].rgbBlue); + pColors[i].rgbReserved = 0; } /* find out if the format needs to be converted */ switch (img->format & DISPLAY_COLORS_MASK) { - case DISPLAY_COLORS_NATIVE: - switch (img->format & DISPLAY_DEPTH_MASK) { - case DISPLAY_DEPTH_1: - case DISPLAY_DEPTH_4: - case DISPLAY_DEPTH_8: - directcopy = TRUE; - } - break; - case DISPLAY_COLORS_GRAY: - switch (img->format & DISPLAY_DEPTH_MASK) { - case DISPLAY_DEPTH_1: - case DISPLAY_DEPTH_4: - case DISPLAY_DEPTH_8: - directcopy = TRUE; - } - break; - case DISPLAY_COLORS_RGB: - if (((img->format & DISPLAY_DEPTH_MASK) == DISPLAY_DEPTH_8) && - ((img->format & DISPLAY_ALPHA_MASK) == DISPLAY_ALPHA_NONE) && - ((img->format & DISPLAY_ENDIAN_MASK) == DISPLAY_LITTLEENDIAN)) - directcopy = TRUE; + case DISPLAY_COLORS_NATIVE: + switch (img->format & DISPLAY_DEPTH_MASK) { + case DISPLAY_DEPTH_1: + case DISPLAY_DEPTH_4: + case DISPLAY_DEPTH_8: + directcopy = TRUE; + } + break; + case DISPLAY_COLORS_GRAY: + switch (img->format & DISPLAY_DEPTH_MASK) { + case DISPLAY_DEPTH_1: + case DISPLAY_DEPTH_4: + case DISPLAY_DEPTH_8: + directcopy = TRUE; + } + break; + case DISPLAY_COLORS_RGB: + if (((img->format & DISPLAY_DEPTH_MASK) == DISPLAY_DEPTH_8) && + ((img->format & DISPLAY_ALPHA_MASK) == DISPLAY_ALPHA_NONE) && + ((img->format & DISPLAY_ENDIAN_MASK) == DISPLAY_LITTLEENDIAN)) + directcopy = TRUE; } pLine = pBits; if (directcopy) { - for (i = 0; i < img->bmih.biHeight; i++) { - memcpy(pLine, img->image + i * img->raster, bytewidth); - pLine += bytewidth; - } + for (i = 0; i < img->bmih.biHeight; i++) { + memcpy(pLine, img->image + i * img->raster, bytewidth); + pLine += bytewidth; + } } else { - /* we need to convert the format to 24BGR */ - for (i = 0; i < img->bmih.biHeight; i++) { - image_convert_line(img, pLine, img->image + i * img->raster); - pLine += bytewidth; - } + /* we need to convert the format to 24BGR */ + for (i = 0; i < img->bmih.biHeight; i++) { + image_convert_line(img, pLine, img->image + i * img->raster); + pLine += bytewidth; + } } GlobalUnlock(hglobal); @@ -1106,22 +1093,22 @@ create_palette(IMAGE *img) nColors = img->bmih.biClrUsed; if (nColors) { - LPLOGPALETTE logpalette; - logpalette = (LPLOGPALETTE) malloc(sizeof(LOGPALETTE) + - nColors * sizeof(PALETTEENTRY)); - if (logpalette == (LPLOGPALETTE) NULL) - return (HPALETTE)0; - logpalette->palVersion = 0x300; - logpalette->palNumEntries = img->bmih.biClrUsed; - for (i = 0; i < nColors; i++) { - logpalette->palPalEntry[i].peFlags = 0; - image_color(img->format, i, - &logpalette->palPalEntry[i].peRed, - &logpalette->palPalEntry[i].peGreen, - &logpalette->palPalEntry[i].peBlue); - } - palette = CreatePalette(logpalette); - free(logpalette); + LPLOGPALETTE logpalette; + logpalette = (LPLOGPALETTE) malloc(sizeof(LOGPALETTE) + + nColors * sizeof(PALETTEENTRY)); + if (logpalette == (LPLOGPALETTE) NULL) + return (HPALETTE)0; + logpalette->palVersion = 0x300; + logpalette->palNumEntries = img->bmih.biClrUsed; + for (i = 0; i < nColors; i++) { + logpalette->palPalEntry[i].peFlags = 0; + image_color(img->format, i, + &logpalette->palPalEntry[i].peRed, + &logpalette->palPalEntry[i].peGreen, + &logpalette->palPalEntry[i].peBlue); + } + palette = CreatePalette(logpalette); + free(logpalette); } return palette; } @@ -1138,361 +1125,359 @@ WndImg2Proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) IMAGE *img; if (message == WM_CREATE) { - /* Object is stored in window extra data. - * Nothing must try to use the object before WM_CREATE - * initializes it here. - */ - img = (IMAGE *)(((CREATESTRUCT *)lParam)->lpCreateParams); - SetWindowLong(hwnd, 0, (LONG)img); + /* Object is stored in window extra data. + * Nothing must try to use the object before WM_CREATE + * initializes it here. + */ + img = (IMAGE *)(((CREATESTRUCT *)lParam)->lpCreateParams); + SetWindowLong(hwnd, 0, (LONG)img); } img = (IMAGE *)GetWindowLong(hwnd, 0); - switch(message) { - case WM_SYSCOMMAND: - /* copy to clipboard */ - if (LOWORD(wParam) == M_COPY_CLIP) { - HGLOBAL hglobal; - HPALETTE hpalette; - if (img->hmutex != INVALID_HANDLE_VALUE) - WaitForSingleObject(img->hmutex, 120000); - hglobal = copy_dib(img); - if (hglobal == (HGLOBAL)NULL) { - if (img->hmutex != INVALID_HANDLE_VALUE) - ReleaseMutex(img->hmutex); - MessageBox(hwnd, "Not enough memory to Copy to Clipboard", - szImgName2, MB_OK | MB_ICONEXCLAMATION); - return 0; - } - OpenClipboard(hwnd); - EmptyClipboard(); - SetClipboardData(CF_DIB, hglobal); - hpalette = create_palette(img); - if (hpalette) - SetClipboardData(CF_PALETTE, hpalette); - CloseClipboard(); - if (img->hmutex != INVALID_HANDLE_VALUE) - ReleaseMutex(img->hmutex); - return 0; - } - else if ((LOWORD(wParam) >= M_SEPARATION) && - (LOWORD(wParam) < M_SEPARATION+IMAGE_DEVICEN_MAX)) { - sep_menu(img, LOWORD(wParam) - M_SEPARATION); - } - else if (LOWORD(wParam) == M_DEVICEN_GRAY) { - img->devicen_gray = !img->devicen_gray; - CheckMenuItem(GetSystemMenu(img->hwnd, FALSE), M_DEVICEN_GRAY, - (img->devicen_gray ? MF_CHECKED : MF_UNCHECKED)); - InvalidateRect(img->hwnd, NULL, 0); - UpdateWindow(img->hwnd); - } - break; - case WM_CREATE: - /* enable drag-drop */ - DragAcceptFiles(hwnd, TRUE); - break; - case WM_MOVE: - if (!IsIconic(hwnd) && !IsZoomed(hwnd)) { - GetWindowRect(hwnd, &rect); - img->x = rect.left; - img->y = rect.top; - } - break; - case WM_SIZE: - if (wParam == SIZE_MINIMIZED) - return(0); - - /* remember current window size */ - if (wParam != SIZE_MAXIMIZED) { - GetWindowRect(hwnd, &rect); - img->cx = rect.right - rect.left; - img->cy = rect.bottom - rect.top; - img->x = rect.left; - img->y = rect.top; - } - - if (img->hmutex != INVALID_HANDLE_VALUE) - WaitForSingleObject(img->hmutex, 120000); - img->cyClient = HIWORD(lParam); - img->cxClient = LOWORD(lParam); - - img->cyAdjust = min(img->bmih.biHeight, img->cyClient) - img->cyClient; - img->cyClient += img->cyAdjust; - - img->nVscrollMax = max(0, img->bmih.biHeight - img->cyClient); - img->nVscrollPos = min(img->nVscrollPos, img->nVscrollMax); - - SetScrollRange(hwnd, SB_VERT, 0, img->nVscrollMax, FALSE); - SetScrollPos(hwnd, SB_VERT, img->nVscrollPos, TRUE); - - img->cxAdjust = min(img->bmih.biWidth, img->cxClient) - img->cxClient; - img->cxClient += img->cxAdjust; - - img->nHscrollMax = max(0, img->bmih.biWidth - img->cxClient); - img->nHscrollPos = min(img->nHscrollPos, img->nHscrollMax); - - SetScrollRange(hwnd, SB_HORZ, 0, img->nHscrollMax, FALSE); - SetScrollPos(hwnd, SB_HORZ, img->nHscrollPos, TRUE); - - if ((wParam==SIZENORMAL) - && (img->cxAdjust!=0 || img->cyAdjust!=0)) { - GetWindowRect(GetParent(hwnd),&rect); - MoveWindow(GetParent(hwnd),rect.left,rect.top, - rect.right-rect.left+img->cxAdjust, - rect.bottom-rect.top+img->cyAdjust, TRUE); - img->cxAdjust = img->cyAdjust = 0; - } - if (img->hmutex != INVALID_HANDLE_VALUE) - ReleaseMutex(img->hmutex); - return(0); - case WM_VSCROLL: - switch(LOWORD(wParam)) { - case SB_TOP: - nVscrollInc = -img->nVscrollPos; - break; - case SB_BOTTOM: - nVscrollInc = img->nVscrollMax - img->nVscrollPos; - break; - case SB_LINEUP: - nVscrollInc = -img->cyClient/16; - break; - case SB_LINEDOWN: - nVscrollInc = img->cyClient/16; - break; - case SB_PAGEUP: - nVscrollInc = min(-1,-img->cyClient); - break; - case SB_PAGEDOWN: - nVscrollInc = max(1,img->cyClient); - break; - case SB_THUMBTRACK: - case SB_THUMBPOSITION: - nVscrollInc = HIWORD(wParam) - img->nVscrollPos; - break; - default: - nVscrollInc = 0; - } - if ((nVscrollInc = max(-img->nVscrollPos, - min(nVscrollInc, img->nVscrollMax - img->nVscrollPos)))!=0) { - img->nVscrollPos += nVscrollInc; - ScrollWindow(hwnd,0,-nVscrollInc,NULL,NULL); - SetScrollPos(hwnd,SB_VERT,img->nVscrollPos,TRUE); - UpdateWindow(hwnd); - } - return(0); - case WM_HSCROLL: - switch(LOWORD(wParam)) { - case SB_LINEUP: - nHscrollInc = -img->cxClient/16; - break; - case SB_LINEDOWN: - nHscrollInc = img->cyClient/16; - break; - case SB_PAGEUP: - nHscrollInc = min(-1,-img->cxClient); - break; - case SB_PAGEDOWN: - nHscrollInc = max(1,img->cxClient); - break; - case SB_THUMBTRACK: - case SB_THUMBPOSITION: - nHscrollInc = HIWORD(wParam) - img->nHscrollPos; - break; - default: - nHscrollInc = 0; - } - if ((nHscrollInc = max(-img->nHscrollPos, - min(nHscrollInc, img->nHscrollMax - img->nHscrollPos)))!=0) { - img->nHscrollPos += nHscrollInc; - ScrollWindow(hwnd,-nHscrollInc,0,NULL,NULL); - SetScrollPos(hwnd,SB_HORZ,img->nHscrollPos,TRUE); - UpdateWindow(hwnd); - } - return(0); - case WM_KEYDOWN: - switch(LOWORD(wParam)) { - case VK_HOME: - SendMessage(hwnd,WM_VSCROLL,SB_TOP,0L); - break; - case VK_END: - SendMessage(hwnd,WM_VSCROLL,SB_BOTTOM,0L); - break; - case VK_PRIOR: - SendMessage(hwnd,WM_VSCROLL,SB_PAGEUP,0L); - break; - case VK_NEXT: - SendMessage(hwnd,WM_VSCROLL,SB_PAGEDOWN,0L); - break; - case VK_UP: - SendMessage(hwnd,WM_VSCROLL,SB_LINEUP,0L); - break; - case VK_DOWN: - SendMessage(hwnd,WM_VSCROLL,SB_LINEDOWN,0L); - break; - case VK_LEFT: - SendMessage(hwnd,WM_HSCROLL,SB_PAGEUP,0L); - break; - case VK_RIGHT: - SendMessage(hwnd,WM_HSCROLL,SB_PAGEDOWN,0L); - break; - case VK_RETURN: - if (img->hwndtext) - BringWindowToTop(img->hwndtext); - break; - } - return(0); - case WM_CHAR: - /* send on all characters to text window */ - if (img->hwndtext) - SendMessage(img->hwndtext, message, wParam, lParam); - else { - /* assume we have a console */ - INPUT_RECORD ir; - HANDLE hStdin = GetStdHandle(STD_INPUT_HANDLE); - DWORD dwWritten = 0; - DWORD cks = 0; - ir.EventType = KEY_EVENT; - ir.Event.KeyEvent.bKeyDown = TRUE; - ir.Event.KeyEvent.wRepeatCount = lParam & 0xffff; - ir.Event.KeyEvent.wVirtualKeyCode = VkKeyScan((TCHAR)wParam) & 0xff; - ir.Event.KeyEvent.wVirtualScanCode = - (lParam >> 16) & 0xff; - ir.Event.KeyEvent.uChar.AsciiChar = wParam; - if (GetKeyState(VK_CAPITAL)) - cks |= CAPSLOCK_ON; - /* ENHANCED_KEY unimplemented */ - if (GetKeyState(VK_LMENU)) - cks |= LEFT_ALT_PRESSED; - if (GetKeyState(VK_LCONTROL)) - cks |= LEFT_CTRL_PRESSED; - if (GetKeyState(VK_NUMLOCK)) - cks |= NUMLOCK_ON; - if (GetKeyState(VK_RMENU)) - cks |= RIGHT_ALT_PRESSED; - if (GetKeyState(VK_RCONTROL)) - cks |= RIGHT_CTRL_PRESSED; - if (GetKeyState(VK_SCROLL)) - cks |= SCROLLLOCK_ON; - if (GetKeyState(VK_SHIFT)) - cks |= SHIFT_PRESSED; - ir.Event.KeyEvent.dwControlKeyState = cks; - if (ir.Event.KeyEvent.uChar.AsciiChar == 3) - GenerateConsoleCtrlEvent(CTRL_C_EVENT, 0L); - else if (hStdin != INVALID_HANDLE_VALUE) - WriteConsoleInput(hStdin, &ir, 1, &dwWritten); - } - return 0; - case WM_TIMER: - img->update_count++; - if (img->update_count >= img->update_interval) - image_update_now(img); - return 0; - case WM_PAINT: - { - int sx,sy,wx,wy,dx,dy; - RECT fillrect; - hdc = BeginPaint(hwnd, &ps); - if (img->hmutex != INVALID_HANDLE_VALUE) - WaitForSingleObject(img->hmutex, 120000); - SetMapMode(hdc, MM_TEXT); - SetBkMode(hdc,OPAQUE); - rect = ps.rcPaint; - dx = rect.left; /* destination */ - dy = rect.top; - wx = rect.right-rect.left; /* width */ - wy = rect.bottom-rect.top; - sx = rect.left; /* source */ - sy = rect.top; - sx += img->nHscrollPos; /* scrollbars */ - sy += img->nVscrollPos; - if (sx+wx > img->bmih.biWidth) - wx = img->bmih.biWidth - sx; - if (sy+wy > img->bmih.biHeight) - wy = img->bmih.biHeight - sy; - - draw(img, hdc, dx, dy, wx, wy, sx, sy); - - /* fill areas around page */ - if (rect.right > img->bmih.biWidth) { - fillrect.top = rect.top; - fillrect.left = img->bmih.biWidth; - fillrect.bottom = rect.bottom; - fillrect.right = rect.right; - FillRect(hdc, &fillrect, img->hBrush); - } - if (rect.bottom > img->bmih.biHeight) { - fillrect.top = img->bmih.biHeight; - fillrect.left = rect.left; - fillrect.bottom = rect.bottom; - fillrect.right = rect.right; - FillRect(hdc, &fillrect, img->hBrush); - } - - if (img->hmutex != INVALID_HANDLE_VALUE) - ReleaseMutex(img->hmutex); - EndPaint(hwnd, &ps); - return 0; - } - case WM_DROPFILES: - if (img->hwndtext) - SendMessage(img->hwndtext, message, wParam, lParam); - else { - char *szFile; - int i, cFiles; - unsigned int Len, error; - const char *p; - const char *szDragPre = "\r("; - const char *szDragPost = ") run\r"; - HDROP hdrop = (HDROP)wParam; - cFiles = DragQueryFile(hdrop, (UINT)(-1), (LPSTR)NULL, 0); - for (i=0; i<cFiles; i++) { - Len = DragQueryFile(hdrop, i, NULL, 0); - szFile = malloc(Len+1); - if (szFile != 0) { - error = DragQueryFile(hdrop, i, szFile, Len+1); - if (error != 0) { - for (p=szDragPre; *p; p++) - SendMessage(hwnd,WM_CHAR,*p,1L); - for (p=szFile; *p; p++) { - if (*p == '\\') - SendMessage(hwnd,WM_CHAR,'/',1L); - else - SendMessage(hwnd,WM_CHAR,*p,1L); - } - for (p=szDragPost; *p; p++) - SendMessage(hwnd,WM_CHAR,*p,1L); - } - free(szFile); - } - } - DragFinish(hdrop); - } - break; - case WM_DESTROY: - { /* Save the text window size */ - char winposbuf[64]; - sprintf(winposbuf, "%d %d %d %d", img->x, img->y, - img->cx, img->cy); - win_set_reg_value((img->device != NULL ? "Image" : "Tracer"), winposbuf); - } - DragAcceptFiles(hwnd, FALSE); - break; + case WM_SYSCOMMAND: + /* copy to clipboard */ + if (LOWORD(wParam) == M_COPY_CLIP) { + HGLOBAL hglobal; + HPALETTE hpalette; + if (img->hmutex != INVALID_HANDLE_VALUE) + WaitForSingleObject(img->hmutex, 120000); + hglobal = copy_dib(img); + if (hglobal == (HGLOBAL)NULL) { + if (img->hmutex != INVALID_HANDLE_VALUE) + ReleaseMutex(img->hmutex); + MessageBox(hwnd, "Not enough memory to Copy to Clipboard", + szImgName2, MB_OK | MB_ICONEXCLAMATION); + return 0; + } + OpenClipboard(hwnd); + EmptyClipboard(); + SetClipboardData(CF_DIB, hglobal); + hpalette = create_palette(img); + if (hpalette) + SetClipboardData(CF_PALETTE, hpalette); + CloseClipboard(); + if (img->hmutex != INVALID_HANDLE_VALUE) + ReleaseMutex(img->hmutex); + return 0; + } + else if ((LOWORD(wParam) >= M_SEPARATION) && + (LOWORD(wParam) < M_SEPARATION+IMAGE_DEVICEN_MAX)) { + sep_menu(img, LOWORD(wParam) - M_SEPARATION); + } + else if (LOWORD(wParam) == M_DEVICEN_GRAY) { + img->devicen_gray = !img->devicen_gray; + CheckMenuItem(GetSystemMenu(img->hwnd, FALSE), M_DEVICEN_GRAY, + (img->devicen_gray ? MF_CHECKED : MF_UNCHECKED)); + InvalidateRect(img->hwnd, NULL, 0); + UpdateWindow(img->hwnd); + } + break; + case WM_CREATE: + /* enable drag-drop */ + DragAcceptFiles(hwnd, TRUE); + break; + case WM_MOVE: + if (!IsIconic(hwnd) && !IsZoomed(hwnd)) { + GetWindowRect(hwnd, &rect); + img->x = rect.left; + img->y = rect.top; + } + break; + case WM_SIZE: + if (wParam == SIZE_MINIMIZED) + return(0); + + /* remember current window size */ + if (wParam != SIZE_MAXIMIZED) { + GetWindowRect(hwnd, &rect); + img->cx = rect.right - rect.left; + img->cy = rect.bottom - rect.top; + img->x = rect.left; + img->y = rect.top; + } + + if (img->hmutex != INVALID_HANDLE_VALUE) + WaitForSingleObject(img->hmutex, 120000); + img->cyClient = HIWORD(lParam); + img->cxClient = LOWORD(lParam); + + img->cyAdjust = min(img->bmih.biHeight, img->cyClient) - img->cyClient; + img->cyClient += img->cyAdjust; + + img->nVscrollMax = max(0, img->bmih.biHeight - img->cyClient); + img->nVscrollPos = min(img->nVscrollPos, img->nVscrollMax); + + SetScrollRange(hwnd, SB_VERT, 0, img->nVscrollMax, FALSE); + SetScrollPos(hwnd, SB_VERT, img->nVscrollPos, TRUE); + + img->cxAdjust = min(img->bmih.biWidth, img->cxClient) - img->cxClient; + img->cxClient += img->cxAdjust; + + img->nHscrollMax = max(0, img->bmih.biWidth - img->cxClient); + img->nHscrollPos = min(img->nHscrollPos, img->nHscrollMax); + + SetScrollRange(hwnd, SB_HORZ, 0, img->nHscrollMax, FALSE); + SetScrollPos(hwnd, SB_HORZ, img->nHscrollPos, TRUE); + + if ((wParam==SIZENORMAL) + && (img->cxAdjust!=0 || img->cyAdjust!=0)) { + GetWindowRect(GetParent(hwnd),&rect); + MoveWindow(GetParent(hwnd),rect.left,rect.top, + rect.right-rect.left+img->cxAdjust, + rect.bottom-rect.top+img->cyAdjust, TRUE); + img->cxAdjust = img->cyAdjust = 0; + } + if (img->hmutex != INVALID_HANDLE_VALUE) + ReleaseMutex(img->hmutex); + return(0); + case WM_VSCROLL: + switch(LOWORD(wParam)) { + case SB_TOP: + nVscrollInc = -img->nVscrollPos; + break; + case SB_BOTTOM: + nVscrollInc = img->nVscrollMax - img->nVscrollPos; + break; + case SB_LINEUP: + nVscrollInc = -img->cyClient/16; + break; + case SB_LINEDOWN: + nVscrollInc = img->cyClient/16; + break; + case SB_PAGEUP: + nVscrollInc = min(-1,-img->cyClient); + break; + case SB_PAGEDOWN: + nVscrollInc = max(1,img->cyClient); + break; + case SB_THUMBTRACK: + case SB_THUMBPOSITION: + nVscrollInc = HIWORD(wParam) - img->nVscrollPos; + break; + default: + nVscrollInc = 0; + } + if ((nVscrollInc = max(-img->nVscrollPos, + min(nVscrollInc, img->nVscrollMax - img->nVscrollPos)))!=0) { + img->nVscrollPos += nVscrollInc; + ScrollWindow(hwnd,0,-nVscrollInc,NULL,NULL); + SetScrollPos(hwnd,SB_VERT,img->nVscrollPos,TRUE); + UpdateWindow(hwnd); + } + return(0); + case WM_HSCROLL: + switch(LOWORD(wParam)) { + case SB_LINEUP: + nHscrollInc = -img->cxClient/16; + break; + case SB_LINEDOWN: + nHscrollInc = img->cyClient/16; + break; + case SB_PAGEUP: + nHscrollInc = min(-1,-img->cxClient); + break; + case SB_PAGEDOWN: + nHscrollInc = max(1,img->cxClient); + break; + case SB_THUMBTRACK: + case SB_THUMBPOSITION: + nHscrollInc = HIWORD(wParam) - img->nHscrollPos; + break; + default: + nHscrollInc = 0; + } + if ((nHscrollInc = max(-img->nHscrollPos, + min(nHscrollInc, img->nHscrollMax - img->nHscrollPos)))!=0) { + img->nHscrollPos += nHscrollInc; + ScrollWindow(hwnd,-nHscrollInc,0,NULL,NULL); + SetScrollPos(hwnd,SB_HORZ,img->nHscrollPos,TRUE); + UpdateWindow(hwnd); + } + return(0); + case WM_KEYDOWN: + switch(LOWORD(wParam)) { + case VK_HOME: + SendMessage(hwnd,WM_VSCROLL,SB_TOP,0L); + break; + case VK_END: + SendMessage(hwnd,WM_VSCROLL,SB_BOTTOM,0L); + break; + case VK_PRIOR: + SendMessage(hwnd,WM_VSCROLL,SB_PAGEUP,0L); + break; + case VK_NEXT: + SendMessage(hwnd,WM_VSCROLL,SB_PAGEDOWN,0L); + break; + case VK_UP: + SendMessage(hwnd,WM_VSCROLL,SB_LINEUP,0L); + break; + case VK_DOWN: + SendMessage(hwnd,WM_VSCROLL,SB_LINEDOWN,0L); + break; + case VK_LEFT: + SendMessage(hwnd,WM_HSCROLL,SB_PAGEUP,0L); + break; + case VK_RIGHT: + SendMessage(hwnd,WM_HSCROLL,SB_PAGEDOWN,0L); + break; + case VK_RETURN: + if (img->hwndtext) + BringWindowToTop(img->hwndtext); + break; + } + return(0); + case WM_CHAR: + /* send on all characters to text window */ + if (img->hwndtext) + SendMessage(img->hwndtext, message, wParam, lParam); + else { + /* assume we have a console */ + INPUT_RECORD ir; + HANDLE hStdin = GetStdHandle(STD_INPUT_HANDLE); + DWORD dwWritten = 0; + DWORD cks = 0; + ir.EventType = KEY_EVENT; + ir.Event.KeyEvent.bKeyDown = TRUE; + ir.Event.KeyEvent.wRepeatCount = lParam & 0xffff; + ir.Event.KeyEvent.wVirtualKeyCode = VkKeyScan((TCHAR)wParam) & 0xff; + ir.Event.KeyEvent.wVirtualScanCode = + (lParam >> 16) & 0xff; + ir.Event.KeyEvent.uChar.AsciiChar = wParam; + if (GetKeyState(VK_CAPITAL)) + cks |= CAPSLOCK_ON; + /* ENHANCED_KEY unimplemented */ + if (GetKeyState(VK_LMENU)) + cks |= LEFT_ALT_PRESSED; + if (GetKeyState(VK_LCONTROL)) + cks |= LEFT_CTRL_PRESSED; + if (GetKeyState(VK_NUMLOCK)) + cks |= NUMLOCK_ON; + if (GetKeyState(VK_RMENU)) + cks |= RIGHT_ALT_PRESSED; + if (GetKeyState(VK_RCONTROL)) + cks |= RIGHT_CTRL_PRESSED; + if (GetKeyState(VK_SCROLL)) + cks |= SCROLLLOCK_ON; + if (GetKeyState(VK_SHIFT)) + cks |= SHIFT_PRESSED; + ir.Event.KeyEvent.dwControlKeyState = cks; + if (ir.Event.KeyEvent.uChar.AsciiChar == 3) + GenerateConsoleCtrlEvent(CTRL_C_EVENT, 0L); + else if (hStdin != INVALID_HANDLE_VALUE) + WriteConsoleInput(hStdin, &ir, 1, &dwWritten); + } + return 0; + case WM_TIMER: + img->update_count++; + if (img->update_count >= img->update_interval) + image_update_now(img); + return 0; + case WM_PAINT: + { + int sx,sy,wx,wy,dx,dy; + RECT fillrect; + hdc = BeginPaint(hwnd, &ps); + if (img->hmutex != INVALID_HANDLE_VALUE) + WaitForSingleObject(img->hmutex, 120000); + SetMapMode(hdc, MM_TEXT); + SetBkMode(hdc,OPAQUE); + rect = ps.rcPaint; + dx = rect.left; /* destination */ + dy = rect.top; + wx = rect.right-rect.left; /* width */ + wy = rect.bottom-rect.top; + sx = rect.left; /* source */ + sy = rect.top; + sx += img->nHscrollPos; /* scrollbars */ + sy += img->nVscrollPos; + if (sx+wx > img->bmih.biWidth) + wx = img->bmih.biWidth - sx; + if (sy+wy > img->bmih.biHeight) + wy = img->bmih.biHeight - sy; + + draw(img, hdc, dx, dy, wx, wy, sx, sy); + + /* fill areas around page */ + if (rect.right > img->bmih.biWidth) { + fillrect.top = rect.top; + fillrect.left = img->bmih.biWidth; + fillrect.bottom = rect.bottom; + fillrect.right = rect.right; + FillRect(hdc, &fillrect, img->hBrush); + } + if (rect.bottom > img->bmih.biHeight) { + fillrect.top = img->bmih.biHeight; + fillrect.left = rect.left; + fillrect.bottom = rect.bottom; + fillrect.right = rect.right; + FillRect(hdc, &fillrect, img->hBrush); + } + + if (img->hmutex != INVALID_HANDLE_VALUE) + ReleaseMutex(img->hmutex); + EndPaint(hwnd, &ps); + return 0; + } + case WM_DROPFILES: + if (img->hwndtext) + SendMessage(img->hwndtext, message, wParam, lParam); + else { + char *szFile; + int i, cFiles; + unsigned int Len, error; + const char *p; + const char *szDragPre = "\r("; + const char *szDragPost = ") run\r"; + HDROP hdrop = (HDROP)wParam; + cFiles = DragQueryFile(hdrop, (UINT)(-1), (LPSTR)NULL, 0); + for (i=0; i<cFiles; i++) { + Len = DragQueryFile(hdrop, i, NULL, 0); + szFile = malloc(Len+1); + if (szFile != 0) { + error = DragQueryFile(hdrop, i, szFile, Len+1); + if (error != 0) { + for (p=szDragPre; *p; p++) + SendMessage(hwnd,WM_CHAR,*p,1L); + for (p=szFile; *p; p++) { + if (*p == '\\') + SendMessage(hwnd,WM_CHAR,'/',1L); + else + SendMessage(hwnd,WM_CHAR,*p,1L); + } + for (p=szDragPost; *p; p++) + SendMessage(hwnd,WM_CHAR,*p,1L); + } + free(szFile); + } + } + DragFinish(hdrop); + } + break; + case WM_DESTROY: + { /* Save the text window size */ + char winposbuf[64]; + sprintf(winposbuf, "%d %d %d %d", img->x, img->y, + img->cx, img->cy); + win_set_reg_value((img->device != NULL ? "Image" : "Tracer"), winposbuf); + } + DragAcceptFiles(hwnd, FALSE); + break; } - return DefWindowProc(hwnd, message, wParam, lParam); + return DefWindowProc(hwnd, message, wParam, lParam); } - /* Repaint a section of the window. */ static void draw(IMAGE *img, HDC hdc, int dx, int dy, int wx, int wy, - int sx, int sy) + int sx, int sy) { HPALETTE oldpalette; struct bmi_s { - BITMAPINFOHEADER h; - unsigned short pal_index[256]; + BITMAPINFOHEADER h; + unsigned short pal_index[256]; } bmi; int i; UINT which_colors; @@ -1519,117 +1504,115 @@ draw(IMAGE *img, HDC hdc, int dx, int dy, int wx, int wy, bmi.h.biClrImportant = img->bmih.biClrImportant; if (img->bmih.biClrUsed) { - /* palette colors */ - for (i = 0; i < img->bmih.biClrUsed; i++) - bmi.pal_index[i] = i; - which_colors = DIB_PAL_COLORS; + /* palette colors */ + for (i = 0; i < img->bmih.biClrUsed; i++) + bmi.pal_index[i] = i; + which_colors = DIB_PAL_COLORS; } else if (bmi.h.biBitCount == 16) { - DWORD* bmi_colors = (DWORD*)(&bmi.pal_index[0]); - bmi.h.biCompression = BI_BITFIELDS; - which_colors = DIB_RGB_COLORS; - if ((img->format & DISPLAY_555_MASK) == DISPLAY_NATIVE_555) { - /* 5-5-5 RGB mode */ - bmi_colors[0] = 0x7c00; - bmi_colors[1] = 0x03e0; - bmi_colors[2] = 0x001f; - } - else { - /* 5-6-5 RGB mode */ - bmi_colors[0] = 0xf800; - bmi_colors[1] = 0x07e0; - bmi_colors[2] = 0x001f; - } + DWORD* bmi_colors = (DWORD*)(&bmi.pal_index[0]); + bmi.h.biCompression = BI_BITFIELDS; + which_colors = DIB_RGB_COLORS; + if ((img->format & DISPLAY_555_MASK) == DISPLAY_NATIVE_555) { + /* 5-5-5 RGB mode */ + bmi_colors[0] = 0x7c00; + bmi_colors[1] = 0x03e0; + bmi_colors[2] = 0x001f; + } + else { + /* 5-6-5 RGB mode */ + bmi_colors[0] = 0xf800; + bmi_colors[1] = 0x07e0; + bmi_colors[2] = 0x001f; + } } else if (bmi.h.biBitCount == 32) { - unsigned int alpha = img->format & DISPLAY_ALPHA_MASK; - DWORD* bmi_colors = (DWORD*)(&bmi.pal_index[0]); - bmi.h.biCompression = BI_BITFIELDS; - which_colors = DIB_RGB_COLORS; - if ((img->format & DISPLAY_ENDIAN_MASK) == DISPLAY_BIGENDIAN) { - if ((alpha == DISPLAY_ALPHA_FIRST) || - (alpha == DISPLAY_UNUSED_FIRST)) { - /* Mac mode */ - bmi_colors[0] = 0x0000ff00; - bmi_colors[1] = 0x00ff0000; - bmi_colors[2] = 0xff000000; - } - else { - bmi_colors[0] = 0x000000ff; - bmi_colors[1] = 0x0000ff00; - bmi_colors[2] = 0x00ff0000; - } - } - else { - if ((alpha == DISPLAY_ALPHA_FIRST) || - (alpha == DISPLAY_UNUSED_FIRST)) { - /* ignore alpha */ - bmi_colors[0] = 0xff000000; - bmi_colors[1] = 0x00ff0000; - bmi_colors[2] = 0x0000ff00; - } - else { - /* Windows mode */ - /* ignore alpha */ - bmi_colors[0] = 0x00ff0000; - bmi_colors[1] = 0x0000ff00; - bmi_colors[2] = 0x000000ff; - } - } + unsigned int alpha = img->format & DISPLAY_ALPHA_MASK; + DWORD* bmi_colors = (DWORD*)(&bmi.pal_index[0]); + bmi.h.biCompression = BI_BITFIELDS; + which_colors = DIB_RGB_COLORS; + if ((img->format & DISPLAY_ENDIAN_MASK) == DISPLAY_BIGENDIAN) { + if ((alpha == DISPLAY_ALPHA_FIRST) || + (alpha == DISPLAY_UNUSED_FIRST)) { + /* Mac mode */ + bmi_colors[0] = 0x0000ff00; + bmi_colors[1] = 0x00ff0000; + bmi_colors[2] = 0xff000000; + } + else { + bmi_colors[0] = 0x000000ff; + bmi_colors[1] = 0x0000ff00; + bmi_colors[2] = 0x00ff0000; + } + } + else { + if ((alpha == DISPLAY_ALPHA_FIRST) || + (alpha == DISPLAY_UNUSED_FIRST)) { + /* ignore alpha */ + bmi_colors[0] = 0xff000000; + bmi_colors[1] = 0x00ff0000; + bmi_colors[2] = 0x0000ff00; + } + else { + /* Windows mode */ + /* ignore alpha */ + bmi_colors[0] = 0x00ff0000; + bmi_colors[1] = 0x0000ff00; + bmi_colors[2] = 0x000000ff; + } + } } else { - bmi.h.biClrUsed = 0; - bmi.h.biClrImportant = 0; - which_colors = DIB_RGB_COLORS; + bmi.h.biClrUsed = 0; + bmi.h.biClrImportant = 0; + which_colors = DIB_RGB_COLORS; } if (img->raster <= 0) - return; + return; if (img->bytewidth <= 0) - return; + return; /* Determine if the format is native and we can do a direct copy */ switch (img->format & DISPLAY_COLORS_MASK) { - case DISPLAY_COLORS_NATIVE: - switch (img->format & DISPLAY_DEPTH_MASK) { - case DISPLAY_DEPTH_1: - case DISPLAY_DEPTH_4: - case DISPLAY_DEPTH_8: - directcopy = TRUE; - break; - case DISPLAY_DEPTH_16: - if ((img->format & DISPLAY_ENDIAN_MASK) - == DISPLAY_LITTLEENDIAN) - directcopy = TRUE; - break; - } - break; - case DISPLAY_COLORS_GRAY: - switch (img->format & DISPLAY_DEPTH_MASK) { - case DISPLAY_DEPTH_1: - case DISPLAY_DEPTH_4: - case DISPLAY_DEPTH_8: - directcopy = TRUE; - } - break; - case DISPLAY_COLORS_RGB: - if (((img->format & DISPLAY_DEPTH_MASK) == DISPLAY_DEPTH_8) && - ((img->format & DISPLAY_ENDIAN_MASK) == DISPLAY_LITTLEENDIAN) && - ((img->format & DISPLAY_ALPHA_MASK) == DISPLAY_ALPHA_NONE)) - directcopy = TRUE; /* BGR24 */ - if (((img->format & DISPLAY_DEPTH_MASK) == DISPLAY_DEPTH_8) && - ((img->format & DISPLAY_ENDIAN_MASK) == DISPLAY_LITTLEENDIAN) && - ((img->format & DISPLAY_ALPHA_MASK) == DISPLAY_UNUSED_LAST)) - directcopy = TRUE; /* 32-bit */ - break; + case DISPLAY_COLORS_NATIVE: + switch (img->format & DISPLAY_DEPTH_MASK) { + case DISPLAY_DEPTH_1: + case DISPLAY_DEPTH_4: + case DISPLAY_DEPTH_8: + directcopy = TRUE; + break; + case DISPLAY_DEPTH_16: + if ((img->format & DISPLAY_ENDIAN_MASK) + == DISPLAY_LITTLEENDIAN) + directcopy = TRUE; + break; + } + break; + case DISPLAY_COLORS_GRAY: + switch (img->format & DISPLAY_DEPTH_MASK) { + case DISPLAY_DEPTH_1: + case DISPLAY_DEPTH_4: + case DISPLAY_DEPTH_8: + directcopy = TRUE; + } + break; + case DISPLAY_COLORS_RGB: + if (((img->format & DISPLAY_DEPTH_MASK) == DISPLAY_DEPTH_8) && + ((img->format & DISPLAY_ENDIAN_MASK) == DISPLAY_LITTLEENDIAN) && + ((img->format & DISPLAY_ALPHA_MASK) == DISPLAY_ALPHA_NONE)) + directcopy = TRUE; /* BGR24 */ + if (((img->format & DISPLAY_DEPTH_MASK) == DISPLAY_DEPTH_8) && + ((img->format & DISPLAY_ENDIAN_MASK) == DISPLAY_LITTLEENDIAN) && + ((img->format & DISPLAY_ALPHA_MASK) == DISPLAY_UNUSED_LAST)) + directcopy = TRUE; /* 32-bit */ + break; } - if (which_colors == DIB_PAL_COLORS) { - oldpalette = SelectPalette(hdc, img->palette, FALSE); - RealizePalette(hdc); + oldpalette = SelectPalette(hdc, img->palette, FALSE); + RealizePalette(hdc); } - /* * Windows apparently limits the size of a single transfer * to 2 Mb, which can be exceeded on 24-bit displays. @@ -1637,35 +1620,34 @@ draw(IMAGE *img, HDC hdc, int dx, int dy, int wx, int wy, ny = 2000000 / img->raster; if (img->raster != img->bytewidth) /* not 32-bit architecture */ - ny = 1; + ny = 1; /* If color format not native, convert it line by line */ /* This is slow, but these formats aren't normally used */ if (!directcopy) { - ny = 1; - line = (unsigned char *)malloc(img->bytewidth); - if (line == NULL) - return; + ny = 1; + line = (unsigned char *)malloc(img->bytewidth); + if (line == NULL) + return; } for (; wy; dy += ny, wy -= ny, sy += ny) { - ny = min(ny, wy); - if (directcopy) { - bits = img->image + img->raster * (img->bmih.biHeight - (sy + ny)); - } - else { - image_convert_line(img, line, - img->image + img->raster * (img->bmih.biHeight - (sy + ny))); - bits = line; - } - SetDIBitsToDevice(hdc, dx, dy, wx, ny, sx, 0, 0, ny, bits, - (BITMAPINFO *) & bmi, which_colors); + ny = min(ny, wy); + if (directcopy) { + bits = img->image + img->raster * (img->bmih.biHeight - (sy + ny)); + } + else { + image_convert_line(img, line, + img->image + img->raster * (img->bmih.biHeight - (sy + ny))); + bits = line; + } + SetDIBitsToDevice(hdc, dx, dy, wx, ny, sx, 0, 0, ny, bits, + (BITMAPINFO *) & bmi, which_colors); } if (which_colors == DIB_PAL_COLORS) - SelectPalette(hdc, oldpalette, FALSE); + SelectPalette(hdc, oldpalette, FALSE); if (line) - free(line); + free(line); } - diff --git a/pl/dwimg.h b/pl/dwimg.h index 2ebee84fa..9d5e8a41f 100644 --- a/pl/dwimg.h +++ b/pl/dwimg.h @@ -15,7 +15,6 @@ #ifndef dwimg_INCLUDED # define dwimg_INCLUDED - /* Windows Image Window structure */ typedef struct IMAGE_DEVICEN_S IMAGE_DEVICEN; @@ -94,5 +93,4 @@ void image_updatesize(IMAGE *img); /* To be called during initialization after the text window has been created */ void image_textwindow(HWND hwnd); - #endif /* dwimg_INCLUDED */ diff --git a/pl/dwmainc.c b/pl/dwmainc.c index bbca9ab98..ca1ad742d 100644 --- a/pl/dwmainc.c +++ b/pl/dwmainc.c @@ -10,7 +10,7 @@ /*$Id: dwmain.c 11973 2010-12-22 19:16:02Z robin $ */ /* dwmain.c */ -/* Windows version of the main program command-line interpreter for PCL interpreters +/* Windows version of the main program command-line interpreter for PCL interpreters */ #include "string_.h" #include "gdebug.h" @@ -82,7 +82,6 @@ HANDLE hthread; DWORD thread_id; HWND hwndforeground; /* our best guess for our console window handle */ - /* This section copied in large part from the Ghostscript Windows client, to * support the Windows display device. */ @@ -114,39 +113,38 @@ static void winthread(void *arg) hthread = GetCurrentThread(); while (!quitnow && GetMessage(&msg, (HWND)NULL, 0, 0)) { - switch (msg.message) { - case DISPLAY_OPEN: - image_open((IMAGE *)msg.lParam); - break; - case DISPLAY_CLOSE: - { - HANDLE hmutex; - IMAGE *img = (IMAGE *)msg.lParam; - hmutex = img->hmutex; - image_close(img); - CloseHandle(hmutex); - } - break; - case DISPLAY_SIZE: - image_updatesize((IMAGE *)msg.lParam); - break; - case DISPLAY_SYNC: - image_sync((IMAGE *)msg.lParam); - break; - case DISPLAY_PAGE: - image_page((IMAGE *)msg.lParam); - break; - case DISPLAY_UPDATE: - image_poll((IMAGE *)msg.lParam); - break; - default: - TranslateMessage(&msg); - DispatchMessage(&msg); - } + switch (msg.message) { + case DISPLAY_OPEN: + image_open((IMAGE *)msg.lParam); + break; + case DISPLAY_CLOSE: + { + HANDLE hmutex; + IMAGE *img = (IMAGE *)msg.lParam; + hmutex = img->hmutex; + image_close(img); + CloseHandle(hmutex); + } + break; + case DISPLAY_SIZE: + image_updatesize((IMAGE *)msg.lParam); + break; + case DISPLAY_SYNC: + image_sync((IMAGE *)msg.lParam); + break; + case DISPLAY_PAGE: + image_page((IMAGE *)msg.lParam); + break; + case DISPLAY_UPDATE: + image_poll((IMAGE *)msg.lParam); + break; + default: + TranslateMessage(&msg); + DispatchMessage(&msg); + } } } - /* New device has been opened */ /* Tell user to use another device */ int display_open(void *handle, void *device) @@ -158,7 +156,7 @@ int display_open(void *handle, void *device) img = image_new(handle, device); /* create and add to list */ img->hmutex = CreateMutex(NULL, FALSE, NULL); if (img) - PostThreadMessage(thread_id, DISPLAY_OPEN, 0, (LPARAM)img); + PostThreadMessage(thread_id, DISPLAY_OPEN, 0, (LPARAM)img); return 0; } @@ -170,8 +168,8 @@ int display_preclose(void *handle, void *device) #endif img = image_find(handle, device); if (img) { - /* grab mutex to stop other thread using bitmap */ - WaitForSingleObject(img->hmutex, 120000); + /* grab mutex to stop other thread using bitmap */ + WaitForSingleObject(img->hmutex, 120000); } return 0; } @@ -184,50 +182,50 @@ int display_close(void *handle, void *device) #endif img = image_find(handle, device); if (img) { - /* This is a hack to pass focus from image window to console */ - if (GetForegroundWindow() == img->hwnd) - SetForegroundWindow(hwndforeground); + /* This is a hack to pass focus from image window to console */ + if (GetForegroundWindow() == img->hwnd) + SetForegroundWindow(hwndforeground); - image_delete(img); /* remove from list, but don't free */ - PostThreadMessage(thread_id, DISPLAY_CLOSE, 0, (LPARAM)img); + image_delete(img); /* remove from list, but don't free */ + PostThreadMessage(thread_id, DISPLAY_CLOSE, 0, (LPARAM)img); } return 0; } -int display_presize(void *handle, void *device, int width, int height, - int raster, unsigned int format) +int display_presize(void *handle, void *device, int width, int height, + int raster, unsigned int format) { IMAGE *img; #ifdef DISPLAY_DEBUG fprintf(stdout, "display_presize(0x%x 0x%x, %d, %d, %d, %d, %ld)\n", - handle, device, width, height, raster, format); + handle, device, width, height, raster, format); #endif img = image_find(handle, device); if (img) { - /* grab mutex to stop other thread using bitmap */ - WaitForSingleObject(img->hmutex, 120000); + /* grab mutex to stop other thread using bitmap */ + WaitForSingleObject(img->hmutex, 120000); } return 0; } - -int display_size(void *handle, void *device, int width, int height, - int raster, unsigned int format, unsigned char *pimage) + +int display_size(void *handle, void *device, int width, int height, + int raster, unsigned int format, unsigned char *pimage) { IMAGE *img; #ifdef DISPLAY_DEBUG fprintf(stdout, "display_size(0x%x 0x%x, %d, %d, %d, %d, %ld, 0x%x)\n", - handle, device, width, height, raster, format, pimage); + handle, device, width, height, raster, format, pimage); #endif img = image_find(handle, device); if (img) { - image_size(img, width, height, raster, format, pimage); - /* release mutex to allow other thread to use bitmap */ - ReleaseMutex(img->hmutex); - PostThreadMessage(thread_id, DISPLAY_SIZE, 0, (LPARAM)img); + image_size(img, width, height, raster, format, pimage); + /* release mutex to allow other thread to use bitmap */ + ReleaseMutex(img->hmutex); + PostThreadMessage(thread_id, DISPLAY_SIZE, 0, (LPARAM)img); } return 0; } - + int display_sync(void *handle, void *device) { IMAGE *img; @@ -236,8 +234,8 @@ int display_sync(void *handle, void *device) #endif img = image_find(handle, device); if (img && !img->pending_sync) { - img->pending_sync = 1; - PostThreadMessage(thread_id, DISPLAY_SYNC, 0, (LPARAM)img); + img->pending_sync = 1; + PostThreadMessage(thread_id, DISPLAY_SYNC, 0, (LPARAM)img); } return 0; } @@ -246,23 +244,23 @@ int display_page(void *handle, void *device, int copies, int flush) { IMAGE *img; #ifdef DISPLAY_DEBUG - fprintf(stdout, "display_page(0x%x, 0x%x, copies=%d, flush=%d)\n", - handle, device, copies, flush); + fprintf(stdout, "display_page(0x%x, 0x%x, copies=%d, flush=%d)\n", + handle, device, copies, flush); #endif img = image_find(handle, device); if (img) - PostThreadMessage(thread_id, DISPLAY_PAGE, 0, (LPARAM)img); + PostThreadMessage(thread_id, DISPLAY_PAGE, 0, (LPARAM)img); return 0; } -int display_update(void *handle, void *device, +int display_update(void *handle, void *device, int x, int y, int w, int h) { IMAGE *img; img = image_find(handle, device); if (img && !img->pending_update && !img->pending_sync) { - img->pending_update = 1; - PostThreadMessage(thread_id, DISPLAY_UPDATE, 0, (LPARAM)img); + img->pending_update = 1; + PostThreadMessage(thread_id, DISPLAY_UPDATE, 0, (LPARAM)img); } return 0; } @@ -276,8 +274,8 @@ void *display_memalloc(void *handle, void *device, unsigned long size) { void *mem; #ifdef DISPLAY_DEBUG - fprintf(stdout, "display_memalloc(0x%x 0x%x %d)\n", - handle, device, size); + fprintf(stdout, "display_memalloc(0x%x 0x%x %d)\n", + handle, device, size); #endif mem = malloc(size); #ifdef DISPLAY_DEBUG @@ -289,23 +287,23 @@ void *display_memalloc(void *handle, void *device, unsigned long size) int display_memfree(void *handle, void *device, void *mem) { #ifdef DISPLAY_DEBUG - fprintf(stdout, "display_memfree(0x%x, 0x%x, 0x%x)\n", - handle, device, mem); + fprintf(stdout, "display_memfree(0x%x, 0x%x, 0x%x)\n", + handle, device, mem); #endif free(mem); return 0; } #endif -int display_separation(void *handle, void *device, +int display_separation(void *handle, void *device, int comp_num, const char *name, unsigned short c, unsigned short m, unsigned short y, unsigned short k) { IMAGE *img; #ifdef DISPLAY_DEBUG - fprintf(stdout, "display_separation(0x%x, 0x%x, %d '%s' %d,%d,%d,%d)\n", - handle, device, comp_num, name, (int)c, (int)m, (int)y, (int)k); + fprintf(stdout, "display_separation(0x%x, 0x%x, %d '%s' %d,%d,%d,%d)\n", + handle, device, comp_num, name, (int)c, (int)m, (int)y, (int)k); #endif img = image_find(handle, device); if (img) @@ -313,8 +311,7 @@ int display_separation(void *handle, void *device, return 0; } - -display_callback display = { +display_callback display = { sizeof(display_callback), DISPLAY_VERSION_MAJOR, DISPLAY_VERSION_MINOR, @@ -340,10 +337,9 @@ display_callback display = { * device */ - /*********************************************************************/ -/* Our 'main' routine sets up the separate thread to look after the +/* Our 'main' routine sets up the separate thread to look after the * display window, and inserts the relevant defaults for the display device. * If the user specifies a different device, or different parameters to * the display device, the later ones should take precedence. @@ -363,46 +359,46 @@ int main(int argc, char *argv[]) memset(buf, 0, sizeof(buf)); if (_beginthread(winthread, 65535, NULL) == -1) { - wprintf(L"GUI thread creation failed\n"); + wprintf(L"GUI thread creation failed\n"); } else { - int n = 30; - /* wait for thread to start */ - Sleep(0); - while (n && (hthread == INVALID_HANDLE_VALUE)) { - n--; - Sleep(100); + int n = 30; + /* wait for thread to start */ + Sleep(0); + while (n && (hthread == INVALID_HANDLE_VALUE)) { + n--; + Sleep(100); + } + while (n && (PostThreadMessage(thread_id, WM_USER, 0, 0) == 0)) { + n--; + Sleep(100); } - while (n && (PostThreadMessage(thread_id, WM_USER, 0, 0) == 0)) { - n--; - Sleep(100); - } - if (n == 0) - wprintf(L"Can't post message to GUI thread\n"); + if (n == 0) + wprintf(L"Can't post message to GUI thread\n"); } - { int format = DISPLAY_COLORS_NATIVE | DISPLAY_ALPHA_NONE | - DISPLAY_DEPTH_1 | DISPLAY_BIGENDIAN | DISPLAY_BOTTOMFIRST; - HDC hdc = GetDC(NULL); /* get hdc for desktop */ - int depth = GetDeviceCaps(hdc, PLANES) * GetDeviceCaps(hdc, BITSPIXEL); - sprintf(ddpi, "-dDisplayResolution=%d", GetDeviceCaps(hdc, LOGPIXELSY)); + { int format = DISPLAY_COLORS_NATIVE | DISPLAY_ALPHA_NONE | + DISPLAY_DEPTH_1 | DISPLAY_BIGENDIAN | DISPLAY_BOTTOMFIRST; + HDC hdc = GetDC(NULL); /* get hdc for desktop */ + int depth = GetDeviceCaps(hdc, PLANES) * GetDeviceCaps(hdc, BITSPIXEL); + sprintf(ddpi, "-dDisplayResolution=%d", GetDeviceCaps(hdc, LOGPIXELSY)); ReleaseDC(NULL, hdc); - if (depth == 32) - format = DISPLAY_COLORS_RGB | DISPLAY_UNUSED_LAST | - DISPLAY_DEPTH_8 | DISPLAY_BIGENDIAN | DISPLAY_BOTTOMFIRST; - else if (depth == 16) - format = DISPLAY_COLORS_NATIVE | DISPLAY_ALPHA_NONE | - DISPLAY_DEPTH_16 | DISPLAY_BIGENDIAN | DISPLAY_BOTTOMFIRST | - DISPLAY_NATIVE_555; - else if (depth > 8) - format = DISPLAY_COLORS_RGB | DISPLAY_ALPHA_NONE | - DISPLAY_DEPTH_8 | DISPLAY_BIGENDIAN | DISPLAY_BOTTOMFIRST; - else if (depth >= 8) - format = DISPLAY_COLORS_NATIVE | DISPLAY_ALPHA_NONE | - DISPLAY_DEPTH_8 | DISPLAY_BIGENDIAN | DISPLAY_BOTTOMFIRST; - else if (depth >= 4) - format = DISPLAY_COLORS_NATIVE | DISPLAY_ALPHA_NONE | - DISPLAY_DEPTH_4 | DISPLAY_BIGENDIAN | DISPLAY_BOTTOMFIRST; + if (depth == 32) + format = DISPLAY_COLORS_RGB | DISPLAY_UNUSED_LAST | + DISPLAY_DEPTH_8 | DISPLAY_BIGENDIAN | DISPLAY_BOTTOMFIRST; + else if (depth == 16) + format = DISPLAY_COLORS_NATIVE | DISPLAY_ALPHA_NONE | + DISPLAY_DEPTH_16 | DISPLAY_BIGENDIAN | DISPLAY_BOTTOMFIRST | + DISPLAY_NATIVE_555; + else if (depth > 8) + format = DISPLAY_COLORS_RGB | DISPLAY_ALPHA_NONE | + DISPLAY_DEPTH_8 | DISPLAY_BIGENDIAN | DISPLAY_BOTTOMFIRST; + else if (depth >= 8) + format = DISPLAY_COLORS_NATIVE | DISPLAY_ALPHA_NONE | + DISPLAY_DEPTH_8 | DISPLAY_BIGENDIAN | DISPLAY_BOTTOMFIRST; + else if (depth >= 4) + format = DISPLAY_COLORS_NATIVE | DISPLAY_ALPHA_NONE | + DISPLAY_DEPTH_4 | DISPLAY_BIGENDIAN | DISPLAY_BOTTOMFIRST; sprintf(dformat, "-dDisplayFormat=%d", format); } nargc = argc + 2; @@ -417,24 +413,22 @@ int main(int argc, char *argv[]) free(nargv); /* close other thread */ - quitnow = TRUE; + quitnow = TRUE; PostThreadMessage(thread_id, WM_QUIT, 0, (LPARAM)0); Sleep(0); exit_status = 0; switch (code) { - case 0: - case e_Info: - case e_Quit: - break; - case e_Fatal: - exit_status = 1; - break; - default: - exit_status = 255; + case 0: + case e_Info: + case e_Quit: + break; + case e_Fatal: + exit_status = 1; + break; + default: + exit_status = 255; } - return exit_status; } - diff --git a/pl/dwreg.c b/pl/dwreg.c index 18936f8d3..051bdc1cc 100644 --- a/pl/dwreg.c +++ b/pl/dwreg.c @@ -1,6 +1,6 @@ /* Copyright (C) 2001-2006 Artifex Software, Inc. All Rights Reserved. - + This software is provided AS-IS with no warranty, either express or implied. @@ -20,7 +20,7 @@ #include <string.h> #include "gscdefs.h" /* for gs_productfamily and gs_revision */ -/* We store registry named values under the key +/* We store registry named values under the key * "Software\\GPL Ghostscript" * where "GPL Ghostscript" is actually gs_productfamily. * Either HKEY_LOCAL_MACHINE or HKEY_CURRENT_USER will be used. @@ -30,7 +30,7 @@ win_registry_key(char *buf, int len) { const char *software = "Software"; if (strlen(software) + 1 + strlen(gs_productfamily) >= len) - return -1; + return -1; strcpy(buf, software); strcat(buf, "\\"); @@ -42,7 +42,7 @@ win_registry_key(char *buf, int len) * Get a named registry value from HKCU. * name, ptr, plen and return values are the same as in gp_getenv(); */ -int +int win_get_reg_value(const char *name, char *ptr, int *plen) { HKEY hkey; @@ -54,22 +54,22 @@ win_get_reg_value(const char *name, char *ptr, int *plen) win_registry_key(key, sizeof(key)); if (RegOpenKeyEx(HKEY_CURRENT_USER, key, 0, KEY_READ, &hkey) - == ERROR_SUCCESS) { - keytype = REG_SZ; - cbData = *plen; - if (bptr == (char *)NULL) - bptr = &b; /* Registry API won't return ERROR_MORE_DATA */ - /* if ptr is NULL */ - rc = RegQueryValueEx(hkey, (char *)name, 0, &keytype, bptr, &cbData); - RegCloseKey(hkey); - if (rc == ERROR_SUCCESS) { - *plen = cbData; - return 0; /* found environment variable and copied it */ - } else if (rc == ERROR_MORE_DATA) { - /* buffer wasn't large enough */ - *plen = cbData; - return -1; - } + == ERROR_SUCCESS) { + keytype = REG_SZ; + cbData = *plen; + if (bptr == (char *)NULL) + bptr = &b; /* Registry API won't return ERROR_MORE_DATA */ + /* if ptr is NULL */ + rc = RegQueryValueEx(hkey, (char *)name, 0, &keytype, bptr, &cbData); + RegCloseKey(hkey); + if (rc == ERROR_SUCCESS) { + *plen = cbData; + return 0; /* found environment variable and copied it */ + } else if (rc == ERROR_MORE_DATA) { + /* buffer wasn't large enough */ + *plen = cbData; + return -1; + } } return 1; /* not found */ } @@ -80,7 +80,7 @@ win_get_reg_value(const char *name, char *ptr, int *plen) * str = value of named value * Returns 0 on success. */ -int +int win_set_reg_value(const char *name, const char *value) { HKEY hkey; @@ -91,14 +91,13 @@ win_set_reg_value(const char *name, const char *value) win_registry_key(key, sizeof(key)); rc = RegOpenKeyEx(HKEY_CURRENT_USER, key, 0, KEY_WRITE, &hkey); if (rc != ERROR_SUCCESS) - rc = RegCreateKeyEx(HKEY_CURRENT_USER, key, 0, "", 0, - KEY_ALL_ACCESS, NULL, &hkey, &dwDisposition); + rc = RegCreateKeyEx(HKEY_CURRENT_USER, key, 0, "", 0, + KEY_ALL_ACCESS, NULL, &hkey, &dwDisposition); if (rc == ERROR_SUCCESS) { - rc = RegSetValueEx(hkey, name, 0, REG_SZ, - (CONST BYTE *)value, strlen(value)+1); - RegCloseKey(hkey); + rc = RegSetValueEx(hkey, name, 0, REG_SZ, + (CONST BYTE *)value, strlen(value)+1); + RegCloseKey(hkey); } return rc == ERROR_SUCCESS ? 0 : -1; } - diff --git a/pl/dwreg.h b/pl/dwreg.h index 56929d4bc..b2bf20c8a 100644 --- a/pl/dwreg.h +++ b/pl/dwreg.h @@ -1,6 +1,6 @@ /* Copyright (C) 2001-2006 Artifex Software, Inc. All Rights Reserved. - + This software is provided AS-IS with no warranty, either express or implied. diff --git a/pl/dwres.h b/pl/dwres.h index a6ac671c6..c09646235 100644 --- a/pl/dwres.h +++ b/pl/dwres.h @@ -1,6 +1,6 @@ /* Copyright (C) 2001-2006 Artifex Software, Inc. All Rights Reserved. - + This software is provided AS-IS with no warranty, either express or implied. diff --git a/pl/pjparse.c b/pl/pjparse.c index 40fd89ba4..a6e1365c3 100644 --- a/pl/pjparse.c +++ b/pl/pjparse.c @@ -32,10 +32,9 @@ #define PJL_PATH_NAME_LENGTH (256) #define MAXPATHLEN 1024 - /* definitions for fontsource and font number table entries */ typedef struct pjl_fontsource { - char designator[2]; + char designator[2]; char pathname[PJL_PATH_NAME_LENGTH+1]; char fontnumber[PJL_STRING_LENGTH+1]; } pjl_fontsource_t; @@ -61,8 +60,8 @@ typedef struct pjl_parser_state_s { pjl_fontsource_t *font_defaults; pjl_fontsource_t *font_envir; char *environment_font_path; /* if there is an operating sytem env - var it is used instead of the - default pjl fontsource */ + var it is used instead of the + default pjl fontsource */ gs_memory_t *mem; } pjl_parser_state_t; @@ -76,9 +75,9 @@ static const pjl_envir_var_t pjl_factory_defaults[] = { {"fontnumber", "0"}, {"pitch", "10.00"}, {"ptsize", "12.00"}, - /* NB pc8 is used on 6mp, clj4550, clj4600 + /* NB pc8 is used on 6mp, clj4550, clj4600 roman8 is used on most other HP devices */ - {"symset", "pc8"}, + {"symset", "pc8"}, {"copies", "1"}, {"paper", "letter"}, {"orientation", "portrait"}, @@ -104,7 +103,6 @@ static const pjl_envir_var_t pjl_factory_defaults[] = { should probably have index definitions for each variable */ #define FDEF_PAPER_INDX 8 - /* FONTS I (Internal Fonts) C, C1, C2 (Cartridge Fonts) S (Permanent Soft Fonts) M1, M2, M3, M4 (fonts stored in one of the printer's ROM SIMM slots). Simulate cartridge, permanent soft fonts, and @@ -137,7 +135,7 @@ typedef enum { UNIDENTIFIED, /* NB not used */ LPARM, /* NB not used */ PREFIX, /* @PJL */ - INITIALIZE, + INITIALIZE, RESET, INQUIRE, DINQUIRE, @@ -155,7 +153,7 @@ typedef enum { FSQUERY, FSUPLOAD, FORMATBINARY, /* this nonsense is ignored. - all data is treated as binary */ + all data is treated as binary */ NAME, /* used for pathnames */ SIZE, /* size of data */ VOLUME, /* volume indicator for filesystem initialization */ @@ -187,7 +185,7 @@ static const pjl_lookup_table_t pjl_table[] = { { "FSQUERY", FSQUERY }, { "FSUPLOAD", FSUPLOAD }, { "FORMAT:BINARY", FORMATBINARY }, /* this nonsense is ignored. - all data is treated as binary */ + all data is treated as binary */ { "NAME", NAME }, /* used for pathnames */ { "SIZE", SIZE }, /* size of data */ { "VOLUME", VOLUME }, /* used for volume name */ @@ -208,7 +206,7 @@ static const pjl_lookup_table_t pjl_table[] = { } pjl_media[] = { px_enumerate_media(PJLMEDIA) }; - + /* permenant soft font slots - bit n is the n'th font number. */ #define MAX_PERMANENT_FONTS 256 /* multiple of 8 */ unsigned char pjl_permanent_soft_fonts[MAX_PERMANENT_FONTS / 8]; @@ -250,15 +248,14 @@ pjl_calc_formlines_new_page_size(int page_length) floatp formlines = (page_length - 300.0)/50.0; return (int)(formlines + 0.5); -} - +} /* handle pjl variables which affect the state of other variables - we don't handle all of these yet. NB not complete. */ static void pjl_side_effects(pjl_parser_state_t *pst, char *variable, char *value, bool defaults) { - if (!pjl_compare(variable, "PAPER") || + if (!pjl_compare(variable, "PAPER") || !pjl_compare(variable, "ORIENTATION")) { pjl_envir_var_t *table = (defaults ? pst->defaults : pst->envir); @@ -270,7 +267,7 @@ pjl_side_effects(pjl_parser_state_t *pst, char *variable, char *value, bool defa int formlines = pjl_calc_formlines_new_page_size(page_length); pjl_envir_var_t var; sprintf(var.value, "%d", formlines); - pjl_set(pst, (char *)"FORMLINES", var.value, defaults); + pjl_set(pst, (char *)"FORMLINES", var.value, defaults); } /* fill in other side effects here */ return; @@ -284,20 +281,20 @@ pjl_set(pjl_parser_state_t *pst, char *variable, char *value, bool defaults) int i; if (defaults) /* default also sets current environment. */ - pjl_set( pst, variable, value, false ); + pjl_set( pst, variable, value, false ); for (i = 0; table[i].var[0]; i++) - if (!pjl_compare(table[i].var, variable)) { - /* set the value */ - strcpy(table[i].value, value); - /* set any side effects of setting the value */ - pjl_side_effects(pst, variable, value, defaults); - return 1; - } + if (!pjl_compare(table[i].var, variable)) { + /* set the value */ + strcpy(table[i].value, value); + /* set any side effects of setting the value */ + pjl_side_effects(pst, variable, value, defaults); + return 1; + } /* didn't find variable */ return 0; } - + /* get next token from the command line buffer */ static pjl_token_type_t pjl_get_token(pjl_parser_state_t *pst, char token[]) @@ -311,8 +308,8 @@ pjl_get_token(pjl_parser_state_t *pst, char token[]) /* special case to allow = with no intevervening spaces between lhs and rhs */ if ( c == '=' ) { - pst->pos++; - return EQUAL; + pst->pos++; + return EQUAL; } /* set the starting position */ @@ -320,57 +317,57 @@ pjl_get_token(pjl_parser_state_t *pst, char token[]) /* end of line reached; null shouldn't happen but we check anyway */ if ( c == '\0' || c == '\n' ) - return DONE; + return DONE; /* check for a quoted string. It should not span a line */ if ( c == '"' ) { - c = pst->line[pst->pos++]; - while ((c = pst->line[pst->pos]) != '"' && - c != '\0' && - c != '\n') - pst->pos++; - /* this routine doesn't yet support real error handling - here + c = pst->line[pst->pos++]; + while ((c = pst->line[pst->pos]) != '"' && + c != '\0' && + c != '\n') + pst->pos++; + /* this routine doesn't yet support real error handling - here we should check if c == '"' */ - if ( c == '"' ) - pst->pos++; - else - return DONE; + if ( c == '"' ) + pst->pos++; + else + return DONE; } else { - /* set the ptr to the next delimeter. */ - while((c = pst->line[pst->pos]) != ' ' && - c != '\t' && - c != '\r' && - c != '\n' && - c != '=' && - c != '\0') - pst->pos++; + /* set the ptr to the next delimeter. */ + while((c = pst->line[pst->pos]) != ' ' && + c != '\t' && + c != '\r' && + c != '\n' && + c != '=' && + c != '\0') + pst->pos++; } /* build the token */ { - int slength = pst->pos - start_pos; - int i; - /* we allow = to special case for allowing - token doesn't fit or is empty */ - if (( slength > PJL_STRING_LENGTH) || slength == 0) - return DONE; - /* now the string can be safely copied */ - strncpy(token, &pst->line[start_pos], slength); - token[slength] = '\0'; - - /* for known tokens */ - for (i = 0; pjl_table[i].pjl_string[0]; i++) - if (!pjl_compare(pjl_table[i].pjl_string, token)) - return pjl_table[i].pjl_token; - - /* NB add other cases here */ - /* check for variables that we support */ - for (i = 0; pst->envir[i].var[0]; i++) - if (!pjl_compare(pst->envir[i].var, token)) - return VARIABLE; - - /* NB assume this is a setting yuck */ - return SETTING; + int slength = pst->pos - start_pos; + int i; + /* we allow = to special case for allowing + token doesn't fit or is empty */ + if (( slength > PJL_STRING_LENGTH) || slength == 0) + return DONE; + /* now the string can be safely copied */ + strncpy(token, &pst->line[start_pos], slength); + token[slength] = '\0'; + + /* for known tokens */ + for (i = 0; pjl_table[i].pjl_string[0]; i++) + if (!pjl_compare(pjl_table[i].pjl_string, token)) + return pjl_table[i].pjl_token; + + /* NB add other cases here */ + /* check for variables that we support */ + for (i = 0; pst->envir[i].var[0]; i++) + if (!pjl_compare(pst->envir[i].var, token)) + return VARIABLE; + + /* NB assume this is a setting yuck */ + return SETTING; } /* shouldn't happen */ return DONE; @@ -394,29 +391,29 @@ pjl_check_font_path(char *path_list, gs_memory_t *mem) check if the directory resource has files without checking if the files are indeed fonts. */ while ( (dirname = strtok(tmp_pathp, ";")) != NULL ) { - file_enum *fe; - strcpy(tmp_path_and_pattern, dirname); - strcat(tmp_path_and_pattern, pattern); - - fe = gs_enumerate_files_init(tmp_path_and_pattern, strlen(tmp_path_and_pattern), mem); - if ( fe == NULL || (gs_enumerate_files_next(fe, fontfilename, PJL_PATH_NAME_LENGTH) ) == -1 ) { - tmp_pathp = NULL; - } else { - /* wind through the rest of the files. This should close + file_enum *fe; + strcpy(tmp_path_and_pattern, dirname); + strcat(tmp_path_and_pattern, pattern); + + fe = gs_enumerate_files_init(tmp_path_and_pattern, strlen(tmp_path_and_pattern), mem); + if ( fe == NULL || (gs_enumerate_files_next(fe, fontfilename, PJL_PATH_NAME_LENGTH) ) == -1 ) { + tmp_pathp = NULL; + } else { + /* wind through the rest of the files. This should close things up as well. All we need to do is clean up but gs_enumerate_files_close() does not close the current directory */ - while ( 1 ) { - int fstatus = (int)gs_enumerate_files_next(fe, fontfilename, PJL_PATH_NAME_LENGTH); - /* we don't care if the file does not fit (return +1) */ - if ( fstatus == -1 ) - break; - } - /* NB fix me - replace : separated path with real path. + while ( 1 ) { + int fstatus = (int)gs_enumerate_files_next(fe, fontfilename, PJL_PATH_NAME_LENGTH); + /* we don't care if the file does not fit (return +1) */ + if ( fstatus == -1 ) + break; + } + /* NB fix me - replace : separated path with real path. We should do this elsewhere */ - strcpy(path_list, dirname); - return path_list; - } + strcpy(path_list, dirname); + return path_list; + } } return NULL; } @@ -434,18 +431,17 @@ pjl_reset_fontsource_fontnumbers(pjl_parser_state_t* pst) int i; for (i = 0; pst->font_defaults[i].designator[0]; i++) { - if ( pjl_check_font_path(pst->font_defaults[i].pathname, mem) ) - strcpy(pst->font_defaults[i].fontnumber, default_font_number); - if ( pjl_check_font_path(pst->font_envir[i].pathname, mem) ) - strcpy(pst->font_envir[i].fontnumber, default_font_number); + if ( pjl_check_font_path(pst->font_defaults[i].pathname, mem) ) + strcpy(pst->font_defaults[i].fontnumber, default_font_number); + if ( pjl_check_font_path(pst->font_envir[i].pathname, mem) ) + strcpy(pst->font_envir[i].fontnumber, default_font_number); } } - /* Strips off extra quotes '"' - * and changes pjl volume from 0: to makefile specifed PJL_VOLUME_0 directory - * and translates '\\' to '/' - * result in fnamep, + * and changes pjl volume from 0: to makefile specifed PJL_VOLUME_0 directory + * and translates '\\' to '/' + * result in fnamep, * ie: ""0:\\dir\subdir\file"" --> "PJL_VOLUME_0/dir/subdir/file" */ static void @@ -453,34 +449,34 @@ pjl_parsed_filename_to_string(char *fnamep, const char *pathname) { int i; int size; - + *fnamep = 0; /* in case of bad input */ - if (pathname == 0 || pathname[0] != '"' || strlen(pathname) < 3) - return; /* bad input pjl file */ - + if (pathname == 0 || pathname[0] != '"' || strlen(pathname) < 3) + return; /* bad input pjl file */ + if ( pathname[1] == '0' && pathname[2] == ':') { - /* copy pjl_volume string in */ - strncpy(fnamep, PJL_VOLUME_0, strlen(PJL_VOLUME_0)); - fnamep += strlen(PJL_VOLUME_0); + /* copy pjl_volume string in */ + strncpy(fnamep, PJL_VOLUME_0, strlen(PJL_VOLUME_0)); + fnamep += strlen(PJL_VOLUME_0); } else if ( pathname[1] == '1' && pathname[2] == ':') { - /* copy pjl_volume string in */ - strncpy(fnamep, PJL_VOLUME_1, strlen(PJL_VOLUME_1)); - fnamep += strlen(PJL_VOLUME_1); + /* copy pjl_volume string in */ + strncpy(fnamep, PJL_VOLUME_1, strlen(PJL_VOLUME_1)); + fnamep += strlen(PJL_VOLUME_1); } - else - return; /* bad input pjl file */ - - /* the pathname parsed has whatever quoting mechanism was used + else + return; /* bad input pjl file */ + + /* the pathname parsed has whatever quoting mechanism was used * remove quotes, use forward slash, copy rest. */ size = strlen(pathname); - + for( i = 3; i < size; i++ ) { - if ( pathname[i] == '\\') - *fnamep++ = '/'; - else if ( pathname[i] != '"') - *fnamep++ = pathname[i]; + if ( pathname[i] == '\\') + *fnamep++ = '/'; + else if ( pathname[i] != '"') + *fnamep++ = pathname[i]; /* else it is a quote skip it */ } /* NULL terminate */ @@ -495,31 +491,31 @@ pjl_verify_file_operation(pjl_parser_state_t *pst, char *fname) { /* make sure we are playing in the pjl sandbox */ if ( 0 != strncmp(PJL_VOLUME_0, fname, strlen(PJL_VOLUME_0)) - && 0 != strncmp(PJL_VOLUME_1, fname, strlen(PJL_VOLUME_1)) ) { - dprintf1("illegal path name %s\n", fname); - return -1; + && 0 != strncmp(PJL_VOLUME_1, fname, strlen(PJL_VOLUME_1)) ) { + dprintf1("illegal path name %s\n", fname); + return -1; } /* make sure we are not currently writing to a file. Simultaneously file writing is not supported */ if ( pst->bytes_to_write || pst->fp ) - return -1; + return -1; /* no operation if disklocak is enabled */ if ( !pjl_compare(pjl_get_envvar(pst, "disklock"), "on") ) - return -1; + return -1; /* ok */ return 0; } /* debugging procedure to warn about writing to an extant file */ static void -pjl_warn_exists(const gs_memory_t *mem, char *fname) +pjl_warn_exists(const gs_memory_t *mem, char *fname) { FILE *fpdownload; /* issue a warning if the file exists */ if ( (fpdownload = fopen(fname, gp_fmode_rb) ) != NULL ) { - fclose(fpdownload); - dprintf1("warning file exists overwriting %s\n", fname); + fclose(fpdownload); + dprintf1("warning file exists overwriting %s\n", fname); } } @@ -532,17 +528,17 @@ pjl_setup_file_for_writing(pjl_parser_state_t *pst, char *pathname, int size, bo pjl_parsed_filename_to_string(fname, pathname); if ( pjl_verify_file_operation(pst, fname) < 0 ) - return NULL; + return NULL; pjl_warn_exists(pst->mem, fname); { - char fmode[4]; - strcpy(fmode, gp_fmode_wb); - if (append) - strcat(fmode, "+"); - if ( (fp = fopen(fname, gp_fmode_wb)) == NULL) { - dprintf("warning file open for writing failed\n" ); - return NULL; - } + char fmode[4]; + strcpy(fmode, gp_fmode_wb); + if (append) + strcat(fmode, "+"); + if ( (fp = fopen(fname, gp_fmode_wb)) == NULL) { + dprintf("warning file open for writing failed\n" ); + return NULL; + } } return fp; } @@ -552,9 +548,9 @@ static int pjl_set_fs_download_state(pjl_parser_state_t *pst, char *pathname, int size) { /* somethink is wrong if the state indicates we are already writing to a file */ - FILE *fp = pjl_setup_file_for_writing(pst, pathname, size, false /* append */); + FILE *fp = pjl_setup_file_for_writing(pst, pathname, size, false /* append */); if ( fp == NULL ) - return -1; + return -1; pst->fp = fp; pst->bytes_to_write = size; return 0; @@ -565,9 +561,9 @@ pjl_set_fs_download_state(pjl_parser_state_t *pst, char *pathname, int size) static int pjl_set_append_state(pjl_parser_state_t *pst, char *pathname, int size) { - FILE *fp = pjl_setup_file_for_writing(pst, pathname, size, true /* append */); + FILE *fp = pjl_setup_file_for_writing(pst, pathname, size, true /* append */); if ( fp == NULL ) - return -1; + return -1; pst->fp = fp; pst->bytes_to_write = size; return 0; @@ -581,7 +577,7 @@ pjl_fsinit(pjl_parser_state_t *pst, char *pathname) char fname[MAXPATHLEN]; pjl_parsed_filename_to_string(fname, pathname); if ( pjl_verify_file_operation(pst, fname) < 0 ) - return -1; + return -1; return mkdir(fname, 0777); } @@ -592,7 +588,7 @@ pjl_fsmkdir(pjl_parser_state_t *pst, char *pathname) char fname[MAXPATHLEN]; pjl_parsed_filename_to_string(fname, pathname); if ( pjl_verify_file_operation(pst, fname) < 0 ) - return -1; + return -1; return mkdir(fname, 0777); } @@ -612,7 +608,6 @@ pjl_fsupload(pjl_parser_state_t *pst, char *pathname, int offset, int size) return -1; } - /* search pathname for filename return a match in result. result should be a 0 length string upon calling this routine. If a match is found result will hold the matching path and filename. Thie @@ -630,22 +625,22 @@ pjl_search_for_file(pjl_parser_state_t *pst, char *pathname, char *filename, cha strcat(fontfilename, "/*"); fe = gs_enumerate_files_init(fontfilename, strlen(fontfilename), pst->mem); if ( fe ) { - do { - uint fstatus = gs_enumerate_files_next(fe, fontfilename, PJL_PATH_NAME_LENGTH); - /* done */ - if ( fstatus == ~(uint)0 ) - return 0; - fontfilename[fstatus] = '\0'; - if (fontfilename[fstatus-1] != '.') { /* skip over . and .. */ - /* a directory */ - if ( ( stat(fontfilename, &stbuf) >= 0 ) && stat_is_dir(stbuf) ) - pjl_search_for_file(pst, fontfilename, filename, result); - else /* a file */ - if ( !strcmp(strrchr( fontfilename, '/' ) + 1, filename) ) - strcpy(result, fontfilename); - } - - } while (1); + do { + uint fstatus = gs_enumerate_files_next(fe, fontfilename, PJL_PATH_NAME_LENGTH); + /* done */ + if ( fstatus == ~(uint)0 ) + return 0; + fontfilename[fstatus] = '\0'; + if (fontfilename[fstatus-1] != '.') { /* skip over . and .. */ + /* a directory */ + if ( ( stat(fontfilename, &stbuf) >= 0 ) && stat_is_dir(stbuf) ) + pjl_search_for_file(pst, fontfilename, filename, result); + else /* a file */ + if ( !strcmp(strrchr( fontfilename, '/' ) + 1, filename) ) + strcpy(result, fontfilename); + } + + } while (1); } /* not implemented */ return -1; @@ -661,15 +656,15 @@ pjl_fsdirlist(pjl_parser_state_t *pst, char *pathname, int entry, int count) strcat(fontfilename, "/*"); fe = gs_enumerate_files_init(fontfilename, strlen(fontfilename), pst->mem); if ( fe ) { - do { - uint fstatus = gs_enumerate_files_next(fe, fontfilename, PJL_PATH_NAME_LENGTH); - /* done */ - if ( fstatus == ~(uint)0 ) - return 0; - fontfilename[fstatus] = '\0'; - /* NB - debugging output only */ - dprintf1("%s\n", fontfilename); - } while (1); + do { + uint fstatus = gs_enumerate_files_next(fe, fontfilename, PJL_PATH_NAME_LENGTH); + /* done */ + if ( fstatus == ~(uint)0 ) + return 0; + fontfilename[fstatus] = '\0'; + /* NB - debugging output only */ + dprintf1("%s\n", fontfilename); + } while (1); } /* should not get here */ return -1; @@ -684,14 +679,14 @@ pjl_write_remaining_data(pjl_parser_state_t *pst, const byte **pptr, const byte uint avail = plimit - ptr; uint bytes_written = min( avail, pst->bytes_to_write ); if ( fwrite( ptr, 1, bytes_written, pst->fp ) != bytes_written ) { - /* try to close the file before failing */ - fclose(pst->fp); + /* try to close the file before failing */ + fclose(pst->fp); pst->fp = NULL; - return -1; + return -1; } pst->bytes_to_write -= bytes_written; if ( pst->bytes_to_write == 0 ) { /* done */ - fclose(pst->fp); + fclose(pst->fp); pst->fp = NULL; } /* update stream pointer */ @@ -705,7 +700,7 @@ pjl_delete_file(pjl_parser_state_t *pst, char *pathname) char fname[MAXPATHLEN]; pjl_parsed_filename_to_string(fname, pathname); if ( pjl_verify_file_operation(pst, fname) < 0 ) - return -1; + return -1; return unlink(fname); } @@ -717,14 +712,14 @@ pjl_get_setting(pjl_parser_state_t *pst, pjl_token_type_t tok, char *token) { pjl_token_type_t lhs = pjl_get_token(pst, token); if ( lhs != tok ) - return -1; + return -1; if ( (tok = pjl_get_token(pst, token) ) != EQUAL ) - return -1; + return -1; if ( (tok = pjl_get_token(pst, token) ) != SETTING ) - return -1; + return -1; return 0; } - + /* parse and set up state for one line of pjl commands */ static int pjl_parse_and_process_line(pjl_parser_state_t *pst) @@ -736,125 +731,125 @@ pjl_parse_and_process_line(pjl_parser_state_t *pst) pst->pos = 0; /* all pjl commands start with the pjl prefix @PJL */ if ( (tok = pjl_get_token(pst, token)) != PREFIX ) - return -1; + return -1; /* NB we should check for required and optional used of whitespace but we don't see PJLTRM 2-6 PJL Command Syntax and Format. */ while( (tok = pjl_get_token(pst, token)) != DONE ) { - switch( tok ) { - case SET: - case DEFAULT: - { - bool defaults; -var: defaults = (tok == DEFAULT); - /* NB we skip over lparm and search for the variable */ - while( (tok = pjl_get_token(pst, token)) != DONE ) - if ( tok == VARIABLE ) { - char variable[PJL_STRING_LENGTH+1]; - strcpy(variable, token); - if (((tok = pjl_get_token(pst, token)) == EQUAL) && - (tok = pjl_get_token(pst, token)) == SETTING) { - return pjl_set(pst, variable, token, defaults); - } else - return -1; /* syntax error */ - } else - continue; - return 0; - } - case INITIALIZE: - /* set the user default environment to the factory default environment */ - memcpy(pst->defaults, &pjl_factory_defaults, sizeof(pjl_factory_defaults)); - memcpy(pst->font_defaults, &pjl_fontsource_table, sizeof(pjl_fontsource_table)); - pjl_reset_fontsource_fontnumbers(pst); - return 0; - /* set the current environment to the user default environment */ - case RESET: - memcpy(pst->envir, pst->defaults, sizeof(pjl_factory_defaults)); - memcpy(pst->font_envir, pst->font_defaults, sizeof(pjl_fontsource_table)); - return 0; - case ENTER: - /* there is no setting for the default language */ - tok = SET; - goto var; - case FSDOWNLOAD: { - /* consume and ignore FORMAT:BINARY foolishness. if it is + switch( tok ) { + case SET: + case DEFAULT: + { + bool defaults; +var: defaults = (tok == DEFAULT); + /* NB we skip over lparm and search for the variable */ + while( (tok = pjl_get_token(pst, token)) != DONE ) + if ( tok == VARIABLE ) { + char variable[PJL_STRING_LENGTH+1]; + strcpy(variable, token); + if (((tok = pjl_get_token(pst, token)) == EQUAL) && + (tok = pjl_get_token(pst, token)) == SETTING) { + return pjl_set(pst, variable, token, defaults); + } else + return -1; /* syntax error */ + } else + continue; + return 0; + } + case INITIALIZE: + /* set the user default environment to the factory default environment */ + memcpy(pst->defaults, &pjl_factory_defaults, sizeof(pjl_factory_defaults)); + memcpy(pst->font_defaults, &pjl_fontsource_table, sizeof(pjl_fontsource_table)); + pjl_reset_fontsource_fontnumbers(pst); + return 0; + /* set the current environment to the user default environment */ + case RESET: + memcpy(pst->envir, pst->defaults, sizeof(pjl_factory_defaults)); + memcpy(pst->font_envir, pst->font_defaults, sizeof(pjl_fontsource_table)); + return 0; + case ENTER: + /* there is no setting for the default language */ + tok = SET; + goto var; + case FSDOWNLOAD: { + /* consume and ignore FORMAT:BINARY foolishness. if it is present or search for the name */ - int size; - /* ignore format binary stuff */ - if ( ( tok = pjl_get_token(pst, token) ) == FORMATBINARY ) - ; - if ( pjl_get_setting(pst, NAME, token) < 0 ) - return -1; - strcpy(pathname, token); - if ( pjl_get_setting(pst, SIZE, token) < 0 ) - return -1; - size = pjl_vartoi(token); - return pjl_set_fs_download_state(pst, pathname, size); - } - case FSAPPEND: { - int size; - if ( ( tok = pjl_get_token(pst, token) ) == FORMATBINARY ) - ; - if ( pjl_get_setting(pst, NAME, token) < 0 ) - return -1; - strcpy(pathname, token); - if ( pjl_get_setting(pst, SIZE, token) < 0 ) - return -1; - size = pjl_vartoi(token); - return pjl_set_append_state(pst, pathname, size); - } - case FSDELETE: - if ( pjl_get_setting(pst, NAME, token) < 0 ) - return -1; - strcpy(pathname, token); - return pjl_delete_file(pst, pathname); - case FSDIRLIST: { - int entry; - int count; - if ( pjl_get_setting(pst, NAME, token) < 0 ) - return -1; - strcpy(pathname, token); - if ( pjl_get_setting(pst, ENTRY, token) < 0 ) - return -1; - entry = pjl_vartoi(token); - if ( pjl_get_setting(pst, COUNT, token) < 0 ) - return -1; - count = pjl_vartoi(token); - return pjl_fsdirlist(pst, pathname, entry, count); - } - case FSINIT: - if ( pjl_get_setting(pst, VOLUME, token) < 0 ) - return -1; - strcpy(pathname, token); - return pjl_fsinit(pst, pathname); - case FSMKDIR: - if ( pjl_get_setting(pst, NAME, token) < 0 ) - return -1; - strcpy(pathname, token); - return pjl_fsmkdir(pst, pathname); - case FSQUERY: - if ( pjl_get_setting(pst, NAME, token) < 0 ) - return -1; - strcpy(pathname, token); - return pjl_fsquery(pst, pathname); - case FSUPLOAD: { - int size; - int offset; - if ( ( tok = pjl_get_token(pst, token) ) == FORMATBINARY ) - ; - if ( pjl_get_setting(pst, NAME, token) < 0 ) - return -1; - strcpy(pathname, token); - if ( pjl_get_setting(pst, OFFSET, token) < 0 ) - return -1; - offset = pjl_vartoi(token); - if ( pjl_get_setting(pst, SIZE, token) < 0 ) - return -1; - size = pjl_vartoi(token); - return pjl_fsupload(pst, pathname, size, offset); - } - default: - return -1; - } + int size; + /* ignore format binary stuff */ + if ( ( tok = pjl_get_token(pst, token) ) == FORMATBINARY ) + ; + if ( pjl_get_setting(pst, NAME, token) < 0 ) + return -1; + strcpy(pathname, token); + if ( pjl_get_setting(pst, SIZE, token) < 0 ) + return -1; + size = pjl_vartoi(token); + return pjl_set_fs_download_state(pst, pathname, size); + } + case FSAPPEND: { + int size; + if ( ( tok = pjl_get_token(pst, token) ) == FORMATBINARY ) + ; + if ( pjl_get_setting(pst, NAME, token) < 0 ) + return -1; + strcpy(pathname, token); + if ( pjl_get_setting(pst, SIZE, token) < 0 ) + return -1; + size = pjl_vartoi(token); + return pjl_set_append_state(pst, pathname, size); + } + case FSDELETE: + if ( pjl_get_setting(pst, NAME, token) < 0 ) + return -1; + strcpy(pathname, token); + return pjl_delete_file(pst, pathname); + case FSDIRLIST: { + int entry; + int count; + if ( pjl_get_setting(pst, NAME, token) < 0 ) + return -1; + strcpy(pathname, token); + if ( pjl_get_setting(pst, ENTRY, token) < 0 ) + return -1; + entry = pjl_vartoi(token); + if ( pjl_get_setting(pst, COUNT, token) < 0 ) + return -1; + count = pjl_vartoi(token); + return pjl_fsdirlist(pst, pathname, entry, count); + } + case FSINIT: + if ( pjl_get_setting(pst, VOLUME, token) < 0 ) + return -1; + strcpy(pathname, token); + return pjl_fsinit(pst, pathname); + case FSMKDIR: + if ( pjl_get_setting(pst, NAME, token) < 0 ) + return -1; + strcpy(pathname, token); + return pjl_fsmkdir(pst, pathname); + case FSQUERY: + if ( pjl_get_setting(pst, NAME, token) < 0 ) + return -1; + strcpy(pathname, token); + return pjl_fsquery(pst, pathname); + case FSUPLOAD: { + int size; + int offset; + if ( ( tok = pjl_get_token(pst, token) ) == FORMATBINARY ) + ; + if ( pjl_get_setting(pst, NAME, token) < 0 ) + return -1; + strcpy(pathname, token); + if ( pjl_get_setting(pst, OFFSET, token) < 0 ) + return -1; + offset = pjl_vartoi(token); + if ( pjl_get_setting(pst, SIZE, token) < 0 ) + return -1; + size = pjl_vartoi(token); + return pjl_fsupload(pst, pathname, size, offset); + } + default: + return -1; + } } return (tok == DONE ? 0 : -1); } @@ -864,19 +859,19 @@ static FILE * get_fp(pjl_parser_state_t *pst, char *name) { char result[MAXPATHLEN]; - + /* 0: */ result[0] = '\0'; pjl_search_for_file(pst, (char *)PJL_VOLUME_0, name, result); if ( result[0] == '\0' ) { - /* try 1: */ - pjl_search_for_file(pst, (char *)PJL_VOLUME_1, name, result); - if ( result[0] == '\0' ) - return 0; + /* try 1: */ + pjl_search_for_file(pst, (char *)PJL_VOLUME_1, name, result); + if ( result[0] == '\0' ) + return 0; } return fopen(result, gp_fmode_rb); } - + /* scan for a named resoource in the pcl sandbox 0: or 1: and return the size of the object. We do not distinguish between empty and non-existant files */ @@ -886,7 +881,7 @@ pjl_get_named_resource_size(pjl_parser_state_t *pst, char *name) long int size; FILE *fp = get_fp(pst, name); if ( fp == NULL ) - return 0; + return 0; fseek(fp, 0L, SEEK_END); size = ftell(fp); fclose(fp); @@ -901,13 +896,13 @@ pjl_get_named_resource(pjl_parser_state *pst, char *name, byte *data) long int size; FILE *fp = get_fp(pst, name); if ( fp == NULL ) - return 0; + return 0; fseek(fp, 0L, SEEK_END); size = ftell(fp); rewind(fp); if ( size != fread(data, 1, size, fp) ) { - fclose(fp); - return -1; + fclose(fp); + return -1; } return 0; } @@ -961,9 +956,9 @@ pjl_get_envvar(pjl_parser_state *pst, const char *pjl_var) pjl_envir_var_t *env = pst->envir; /* lookup up the value */ for (i = 0; env[i].var[0]; i++) - if (!pjl_compare(env[i].var, pjl_var)) { - return env[i].value; - } + if (!pjl_compare(env[i].var, pjl_var)) { + return env[i].value; + } return NULL; } @@ -980,49 +975,49 @@ pjl_process(pjl_parser_state* pst, void *pstate, stream_cursor_read * pr) file system commands */ while (p < rlimit) { - if ( pst->bytes_to_write != 0 ) { - p++; - if (pjl_write_remaining_data(pst, &p, &rlimit) == 0 ) { - p--; - continue; - } - else - return -1; - } - - if (pst->pos == 0) { /* Look ahead for the @PJL prefix or a UEL. */ - uint avail = rlimit - p; - - if (!memcmp(p + 1, "\033%-12345X", min(avail, 9))) { /* Might be a UEL. */ - if (avail < 9) { /* Not enough data to know yet. */ - break; - } - /* Skip the UEL and continue. */ - p += 9; - continue; - } else if (!memcmp(p + 1, "@PJL", min(avail, 4))) { /* Might be PJL. */ - if (avail < 4) { /* Not enough data to know yet. */ - break; - } - /* Definitely a PJL command. */ - } else { /* Definitely not PJL. */ - code = 1; - break; - } - } - if (p[1] == '\n') { - ++p; - /* null terminate, parse and set the pjl state */ - pst->line[pst->pos] = '\0'; - pjl_parse_and_process_line(pst); - pst->pos = 0; - continue; - } - /* Copy the PJL line into the parser's line buffer. */ - /* Always leave room for a terminator. */ - if (pst->pos < countof(pst->line) - 1) - pst->line[pst->pos] = p[1], pst->pos++; - ++p; + if ( pst->bytes_to_write != 0 ) { + p++; + if (pjl_write_remaining_data(pst, &p, &rlimit) == 0 ) { + p--; + continue; + } + else + return -1; + } + + if (pst->pos == 0) { /* Look ahead for the @PJL prefix or a UEL. */ + uint avail = rlimit - p; + + if (!memcmp(p + 1, "\033%-12345X", min(avail, 9))) { /* Might be a UEL. */ + if (avail < 9) { /* Not enough data to know yet. */ + break; + } + /* Skip the UEL and continue. */ + p += 9; + continue; + } else if (!memcmp(p + 1, "@PJL", min(avail, 4))) { /* Might be PJL. */ + if (avail < 4) { /* Not enough data to know yet. */ + break; + } + /* Definitely a PJL command. */ + } else { /* Definitely not PJL. */ + code = 1; + break; + } + } + if (p[1] == '\n') { + ++p; + /* null terminate, parse and set the pjl state */ + pst->line[pst->pos] = '\0'; + pjl_parse_and_process_line(pst); + pst->pos = 0; + continue; + } + /* Copy the PJL line into the parser's line buffer. */ + /* Always leave room for a terminator. */ + if (pst->pos < countof(pst->line) - 1) + pst->line[pst->pos] = p[1], pst->pos++; + ++p; } pr->ptr = p; return code; @@ -1037,16 +1032,16 @@ pjl_skip_to_uel(stream_cursor_read * pr) const byte *rlimit = pr->limit; for (; p < rlimit; ++p) - if (p[1] == '\033') { - uint avail = rlimit - p; - - if (memcmp(p + 1, "\033%-12345X", min(avail, 9))) - continue; - if (avail < 9) - break; - pr->ptr = p + 9; - return true; - } + if (p[1] == '\033') { + uint avail = rlimit - p; + + if (memcmp(p + 1, "\033%-12345X", min(avail, 9))) + continue; + if (avail < 9) + break; + pr->ptr = p + 9; + return true; + } pr->ptr = p; return false; } @@ -1099,35 +1094,34 @@ pjl_map_pjl_sym_to_pcl_sym(const char *symname) { int i; for (i = 0; symbol_sets[i].symname; i++) - if (!pjl_compare(symname, symbol_sets[i].symname)) { - /* convert the character code to it's integer + if (!pjl_compare(symname, symbol_sets[i].symname)) { + /* convert the character code to it's integer representation. NB peculiar code! */ - char pcl_symbol[4], chr; - int char_pos; - strcpy(pcl_symbol, symbol_sets[i].pcl_selectcode); - char_pos = strlen(pcl_symbol) - 1; - chr = pcl_symbol[char_pos]; - pcl_symbol[char_pos] = '\0'; - return (atoi(pcl_symbol) << 5) + chr - 64; - } + char pcl_symbol[4], chr; + int char_pos; + strcpy(pcl_symbol, symbol_sets[i].pcl_selectcode); + char_pos = strlen(pcl_symbol) - 1; + chr = pcl_symbol[char_pos]; + pcl_symbol[char_pos] = '\0'; + return (atoi(pcl_symbol) << 5) + chr - 64; + } return -1; } /* environment variable to integer */ - int + int pjl_vartoi(const pjl_envvar_t *s) { return atoi(s); } /* environment variable to float */ - floatp + floatp pjl_vartof(const pjl_envvar_t *s) { return atof(s); } - /* convert a pjl font source to a pathname */ char * pjl_fontsource_to_path(const pjl_parser_state *pjls, const pjl_envvar_t *fontsource) @@ -1136,10 +1130,10 @@ pjl_fontsource_to_path(const pjl_parser_state *pjls, const pjl_envvar_t *fontsou /* if an environment variable is set we use it, otherwise use the PJL machinery */ if ( pjls->environment_font_path != NULL ) - return pjl_check_font_path(pjls->environment_font_path, pjls->mem); + return pjl_check_font_path(pjls->environment_font_path, pjls->mem); for (i = 0; pjls->font_envir[i].designator[0]; i++) - if (!pjl_compare(pjls->font_envir[i].designator, fontsource)) - return pjl_check_font_path(pjls->font_envir[i].pathname, pjls->mem); + if (!pjl_compare(pjls->font_envir[i].designator, fontsource)) + return pjl_check_font_path(pjls->font_envir[i].pathname, pjls->mem); return NULL; } @@ -1148,43 +1142,43 @@ pjl_fontsource_to_path(const pjl_parser_state *pjls, const pjl_envvar_t *fontsou pjl_process_init(gs_memory_t *mem) { pjl_parser_state_t *pjlstate = - (pjl_parser_state *)gs_alloc_bytes(mem, - sizeof(pjl_parser_state_t), "pjl_state" ); + (pjl_parser_state *)gs_alloc_bytes(mem, + sizeof(pjl_parser_state_t), "pjl_state" ); pjl_envir_var_t *pjl_env = - (pjl_envir_var_t *)gs_alloc_bytes(mem, + (pjl_envir_var_t *)gs_alloc_bytes(mem, sizeof(pjl_factory_defaults), "pjl_envir" ); pjl_envir_var_t *pjl_def = - (pjl_envir_var_t *)gs_alloc_bytes(mem, + (pjl_envir_var_t *)gs_alloc_bytes(mem, sizeof(pjl_factory_defaults), "pjl_defaults" ); pjl_fontsource_t *pjl_fontenv = - (pjl_fontsource_t *)gs_alloc_bytes(mem, + (pjl_fontsource_t *)gs_alloc_bytes(mem, sizeof(pjl_fontsource_table), "pjl_font_envir" ); pjl_fontsource_t *pjl_fontdef = - (pjl_fontsource_t *)gs_alloc_bytes(mem, + (pjl_fontsource_t *)gs_alloc_bytes(mem, sizeof(pjl_fontsource_table), "pjl_font_defaults" ); if ( pjlstate == NULL || pjl_env == NULL || pjl_def == NULL ) - return NULL; /* should be fatal so we don't bother piecemeal frees */ + return NULL; /* should be fatal so we don't bother piecemeal frees */ /* check for an environment variable */ { - int pathlen, code; - /* The environment variable exists if the function fails to + int pathlen, code; + /* The environment variable exists if the function fails to fit in the null - odd but it works. We allow an environment variable to override the font default PJL font path for desktop setups */ - pathlen = 0; - if ( (code = gp_getenv( "PCLFONTSOURCE", (char *)0, &pathlen)) < 0 ) { - char *path = (char *)gs_alloc_bytes(mem, pathlen, "pjl_font_path"); - /* if the allocation fails we use the pjl fontsource */ - if ( path == NULL ) - pjlstate->environment_font_path = NULL; - else { - gp_getenv("PCLFONTSOURCE", path, &pathlen); /* can't fail */ - pjlstate->environment_font_path = path; - } - } else /* environmet variable does not exist use pjl fontsource */ - pjlstate->environment_font_path = NULL; + pathlen = 0; + if ( (code = gp_getenv( "PCLFONTSOURCE", (char *)0, &pathlen)) < 0 ) { + char *path = (char *)gs_alloc_bytes(mem, pathlen, "pjl_font_path"); + /* if the allocation fails we use the pjl fontsource */ + if ( path == NULL ) + pjlstate->environment_font_path = NULL; + else { + gp_getenv("PCLFONTSOURCE", path, &pathlen); /* can't fail */ + pjlstate->environment_font_path = path; + } + } else /* environmet variable does not exist use pjl fontsource */ + pjlstate->environment_font_path = NULL; } pjlstate->defaults = pjl_def; pjlstate->envir = pjl_env; @@ -1207,9 +1201,9 @@ pjl_process_init(gs_memory_t *mem) /* initialize available font sources */ pjl_reset_fontsource_fontnumbers(pjlstate); { - int i; - for (i = 0; i < countof(pjl_permanent_soft_fonts); i++) - pjl_permanent_soft_fonts[i] = 0; + int i; + for (i = 0; i < countof(pjl_permanent_soft_fonts); i++) + pjl_permanent_soft_fonts[i] = 0; } return (pjl_parser_state *)pjlstate; } @@ -1219,8 +1213,8 @@ pjl_process_init(gs_memory_t *mem) pjl_compare(const pjl_envvar_t *s1, const char *s2) { for (; toupper(*s1) == toupper(*s2); ++s1, ++s2) - if (*s1 == '\0') - return(0); + if (*s1 == '\0') + return(0); return 1; } @@ -1233,7 +1227,7 @@ pjl_process_destroy(pjl_parser_state *pst, gs_memory_t *mem) gs_free_object(mem, pst->defaults, "pjl_defaults"); gs_free_object(mem, pst->envir, "pjl_envir"); if ( pst->environment_font_path ) - gs_free_object(mem, pst->environment_font_path, "pjl_state"); + gs_free_object(mem, pst->environment_font_path, "pjl_state"); gs_free_object(mem, pst, "pjl_state"); } @@ -1242,38 +1236,38 @@ pjl_process_destroy(pjl_parser_state *pst, gs_memory_t *mem) pjl_register_permanent_soft_font_deletion(pjl_parser_state *pst, int font_number) { if ( (font_number > MAX_PERMANENT_FONTS - 1) || (font_number < 0) ) { - dprintf("pjparse.c:pjl_register_permanent_soft_font_deletion() bad font number\n"); - return 0; + dprintf("pjparse.c:pjl_register_permanent_soft_font_deletion() bad font number\n"); + return 0; } /* if the font is present. */ if ( (pjl_permanent_soft_fonts[font_number >> 3]) & (128 >> (font_number & 7)) ) { - /* set the bit to zero to indicate the fontnumber has been deleted */ - pjl_permanent_soft_fonts[font_number >> 3] &= ~(128 >> (font_number & 7)); - /* if the current font source is 'S' and the current font number - is the highest number, and *any* soft font was deleted or if - the last font has been removed, set the stage for changing to - the next priority font source. BLAME HP not me. */ - { - bool is_S = !pjl_compare(pjl_get_envvar(pst, "fontsource"), "S"); - bool empty = true; - int highest_fontnumber = -1; - int current_fontnumber = pjl_vartoi(pjl_get_envvar(pst, "fontnumber")); - int i; - /* check for no more fonts and the highest font number. - NB should look at longs not bits in the loop */ - for ( i = 0; i < MAX_PERMANENT_FONTS; i++ ) - if ( (pjl_permanent_soft_fonts[i >> 3]) & (128 >> (i & 7)) ) { - empty = false; - highest_fontnumber = i; - } - if ( is_S && ((highest_fontnumber == current_fontnumber) || empty) ) { + /* set the bit to zero to indicate the fontnumber has been deleted */ + pjl_permanent_soft_fonts[font_number >> 3] &= ~(128 >> (font_number & 7)); + /* if the current font source is 'S' and the current font number + is the highest number, and *any* soft font was deleted or if + the last font has been removed, set the stage for changing to + the next priority font source. BLAME HP not me. */ + { + bool is_S = !pjl_compare(pjl_get_envvar(pst, "fontsource"), "S"); + bool empty = true; + int highest_fontnumber = -1; + int current_fontnumber = pjl_vartoi(pjl_get_envvar(pst, "fontnumber")); + int i; + /* check for no more fonts and the highest font number. + NB should look at longs not bits in the loop */ + for ( i = 0; i < MAX_PERMANENT_FONTS; i++ ) + if ( (pjl_permanent_soft_fonts[i >> 3]) & (128 >> (i & 7)) ) { + empty = false; + highest_fontnumber = i; + } + if ( is_S && ((highest_fontnumber == current_fontnumber) || empty) ) { #define SINDEX 4 - pst->font_defaults[SINDEX].fontnumber[0] = '\0'; - pst->font_envir[SINDEX].fontnumber[0] = '\0'; - return 1; + pst->font_defaults[SINDEX].fontnumber[0] = '\0'; + pst->font_envir[SINDEX].fontnumber[0] = '\0'; + return 1; #undef SINDEX - } - } + } + } } return 0; } @@ -1288,15 +1282,15 @@ pjl_register_permanent_soft_font_addition(pjl_parser_state *pst) int font_num; bool slot_found; for ( font_num = 0; font_num < MAX_PERMANENT_FONTS; font_num++ ) - if ( !((pjl_permanent_soft_fonts[font_num >> 3]) & (128 >> (font_num & 7))) ) { - slot_found = true; - break; - } + if ( !((pjl_permanent_soft_fonts[font_num >> 3]) & (128 >> (font_num & 7))) ) { + slot_found = true; + break; + } /* yikes, shouldn't happen */ if ( !slot_found ) { - dprintf("pjparse.c:pjl_register_permanent_soft_font_addition()\ + dprintf("pjparse.c:pjl_register_permanent_soft_font_addition()\ font table full recycling font number 0\n"); - font_num = 0; + font_num = 0; } /* set the bit to 1 to indicate the fontnumber has been added */ pjl_permanent_soft_fonts[font_num >> 3] |= (128 >> (font_num & 7)); diff --git a/pl/pjparse.h b/pl/pjparse.h index 33c8b2112..8576657e4 100644 --- a/pl/pjparse.h +++ b/pl/pjparse.h @@ -55,13 +55,13 @@ int pjl_process(pjl_parser_state *pst, void *pstate, bool pjl_skip_to_uel(stream_cursor_read *pr); /* return the current setting of a pjl environment variable. The input parameter should be the exact string used in PJLTRM. - Sample Usage: + Sample Usage: char *formlines = pjl_get_envvar(pst, "formlines"); - if (formlines) { - int fl = atoi(formlines); - . - . - } + if (formlines) { + int fl = atoi(formlines); + . + . + } Both variables and values are case insensitive. */ pjl_envvar_t *pjl_get_envvar(pjl_parser_state *pst, const char *pjl_var); diff --git a/pl/pjparsei.c b/pl/pjparsei.c index f0b5eb574..8f45b1344 100644 --- a/pl/pjparsei.c +++ b/pl/pjparsei.c @@ -37,7 +37,6 @@ typedef struct pjl_interp_instance_s { pjl_parser_state *state; /* parser's state */ } pjl_interp_instance_t; - /* Get implemtation's characteristics */ const pl_interp_characteristics_t * /* always returns a descriptor */ pjl_impl_characteristics( @@ -63,17 +62,17 @@ pjl_impl_allocate_interp( gs_memory_t *mem /* allocator to allocate interp from */ ) { - /* Allocate an interpreter */ - pjl_interp_t *pjl /****** SHOULD HAVE A STRUCT DESCRIPTOR ******/ - = (pjl_interp_t *)gs_alloc_bytes( mem, - sizeof(pjl_interp_t), - "pjl_impl_allocate_interp(pjl_interp_t)" - ); - if (pjl == 0) - return gs_error_VMerror; - pjl->memory = mem; - *interp = (pl_interp_t *)pjl; - return 0; /* success */ + /* Allocate an interpreter */ + pjl_interp_t *pjl /****** SHOULD HAVE A STRUCT DESCRIPTOR ******/ + = (pjl_interp_t *)gs_alloc_bytes( mem, + sizeof(pjl_interp_t), + "pjl_impl_allocate_interp(pjl_interp_t)" + ); + if (pjl == 0) + return gs_error_VMerror; + pjl->memory = mem; + *interp = (pl_interp_t *)pjl; + return 0; /* success */ } /* Do per-instance interpreter allocation/init. No device is set yet */ @@ -84,25 +83,25 @@ pjl_impl_allocate_interp_instance( gs_memory_t *mem /* allocator to allocate instance from */ ) { - /* Allocate everything up front */ - pjl_interp_instance_t *pjli /****** SHOULD HAVE A STRUCT DESCRIPTOR ******/ - = (pjl_interp_instance_t *)gs_alloc_bytes( mem, - sizeof(pjl_interp_instance_t), - "pjl_impl_allocate_interp_instance(pjl_interp_instance_t)" + /* Allocate everything up front */ + pjl_interp_instance_t *pjli /****** SHOULD HAVE A STRUCT DESCRIPTOR ******/ + = (pjl_interp_instance_t *)gs_alloc_bytes( mem, + sizeof(pjl_interp_instance_t), + "pjl_impl_allocate_interp_instance(pjl_interp_instance_t)" ); - pjl_parser_state *pjls = pjl_process_init(mem); + pjl_parser_state *pjls = pjl_process_init(mem); - /* If any allocation error simply return */ - if (!pjli || !pjls) - return gs_error_VMerror; + /* If any allocation error simply return */ + if (!pjli || !pjls) + return gs_error_VMerror; - /* Setup pointers to allocated mem within instance */ - pjli->state = pjls; - pjli->memory = mem; + /* Setup pointers to allocated mem within instance */ + pjli->state = pjls; + pjli->memory = mem; - /* Return success */ - *instance = (pl_interp_instance_t *)pjli; - return 0; + /* Return success */ + *instance = (pl_interp_instance_t *)pjli; + return 0; } /* Set a client language into an interperter instance */ @@ -113,7 +112,7 @@ pjl_impl_set_client_instance( pl_interp_instance_clients_t which_client ) { - return 0; + return 0; } /* Set a device into an interperter instance */ @@ -123,7 +122,7 @@ pjl_impl_set_device( gx_device *device /* device to set (open or closed) */ ) { - return gs_error_undefined; /* this operation is undefined for PJL */ + return gs_error_undefined; /* this operation is undefined for PJL */ } /* Set an interpreter instance's pre-page action */ @@ -134,7 +133,7 @@ pjl_impl_set_pre_page_action( void *closure /* closure to call action with */ ) { - return gs_error_undefined; /* this operation is undefined for PJL */ + return gs_error_undefined; /* this operation is undefined for PJL */ } /* Set an interpreter instance's post-page action */ @@ -145,10 +144,10 @@ pjl_impl_set_post_page_action( void *closure /* closure to call action with */ ) { - return gs_error_undefined; /* this operation is undefined for PJL */ + return gs_error_undefined; /* this operation is undefined for PJL */ } -static int +static int pjl_impl_get_device_memory( pl_interp_instance_t *instance, /* interp instance to use */ gs_memory_t **pmem) @@ -156,20 +155,19 @@ pjl_impl_get_device_memory( return 0; } - /* Prepare interp instance for the next "job" */ int /* ret 0 ok, else -ve error code */ pjl_impl_init_job( - pl_interp_instance_t *instance /* interp instance to start job in */ + pl_interp_instance_t *instance /* interp instance to start job in */ ) { - int code = 0; - pjl_interp_instance_t *pjli = (pjl_interp_instance_t *)instance; - if (pjli->state == 0) - code = gs_error_VMerror; - /* copy the default state to the initial state */ - pjl_set_init_from_defaults(pjli->state); - return code; + int code = 0; + pjl_interp_instance_t *pjli = (pjl_interp_instance_t *)instance; + if (pjli->state == 0) + code = gs_error_VMerror; + /* copy the default state to the initial state */ + pjl_set_init_from_defaults(pjli->state); + return code; } /* Parse a cursor-full of data */ @@ -180,54 +178,54 @@ int /* The parser reads data from the input * <0 value - an error was detected. */ pjl_impl_process( - pl_interp_instance_t *instance, /* interp instance to process data job in */ - stream_cursor_read *cursor /* data to process */ + pl_interp_instance_t *instance, /* interp instance to process data job in */ + stream_cursor_read *cursor /* data to process */ ) { - pjl_interp_instance_t *pjli = (pjl_interp_instance_t *)instance; - int code = pjl_process(pjli->state, NULL, cursor); - return code == 1 ? e_ExitLanguage : code; + pjl_interp_instance_t *pjli = (pjl_interp_instance_t *)instance; + int code = pjl_process(pjli->state, NULL, cursor); + return code == 1 ? e_ExitLanguage : code; } /* Skip to end of job ret 1 if done, 0 ok but EOJ not found, else -ve error code */ int pjl_impl_flush_to_eoj( - pl_interp_instance_t *instance, /* interp instance to flush for */ - stream_cursor_read *cursor /* data to process */ + pl_interp_instance_t *instance, /* interp instance to flush for */ + stream_cursor_read *cursor /* data to process */ ) { - return pjl_skip_to_uel(cursor) ? 1 : 0; + return pjl_skip_to_uel(cursor) ? 1 : 0; } /* Parser action for end-of-file */ int /* ret 0 or +ve if ok, else -ve error code */ pjl_impl_process_eof( - pl_interp_instance_t *instance /* interp instance to process data job in */ + pl_interp_instance_t *instance /* interp instance to process data job in */ ) { - return 0; + return 0; } /* Report any errors after running a job */ int /* ret 0 ok, else -ve error code */ pjl_impl_report_errors( - pl_interp_instance_t *instance, /* interp instance to wrap up job in */ + pl_interp_instance_t *instance, /* interp instance to wrap up job in */ int code, /* prev termination status */ long file_position, /* file position of error, -1 if unknown */ - bool force_to_cout /* force errors to cout */ + bool force_to_cout /* force errors to cout */ ) { - return 0; + return 0; } /* Wrap up interp instance after a "job" */ int /* ret 0 ok, else -ve error code */ pjl_impl_dnit_job( - pl_interp_instance_t *instance /* interp instance to wrap up job in */ + pl_interp_instance_t *instance /* interp instance to wrap up job in */ ) { - int code = 0; - return code; + int code = 0; + return code; } /* Remove a device from an interperter instance */ @@ -236,7 +234,7 @@ pjl_impl_remove_device( pl_interp_instance_t *instance /* interp instance to use */ ) { - return gs_error_undefined; /* this operation is undefined for PJL */ + return gs_error_undefined; /* this operation is undefined for PJL */ } /* Deallocate a interpreter instance */ @@ -245,13 +243,13 @@ pjl_impl_deallocate_interp_instance( pl_interp_instance_t *instance /* instance to dealloc */ ) { - pjl_interp_instance_t *pjli = (pjl_interp_instance_t *)instance; - gs_memory_t *mem = pjli->memory; + pjl_interp_instance_t *pjli = (pjl_interp_instance_t *)instance; + gs_memory_t *mem = pjli->memory; - pjl_process_destroy(pjli->state, mem); - gs_free_object(mem, pjli, "pjl_impl_deallocate_interp_instance(pjl_interp_instance_t)"); + pjl_process_destroy(pjli->state, mem); + gs_free_object(mem, pjli, "pjl_impl_deallocate_interp_instance(pjl_interp_instance_t)"); - return 0; + return 0; } /* Do static deinit of PJL interpreter */ @@ -260,11 +258,11 @@ pjl_impl_deallocate_interp( pl_interp_t *interp /* interpreter to deallocate */ ) { - pjl_interp_t *pi = (pjl_interp_t *)interp; - gs_memory_t *mem = pi->memory; - gs_free_object(mem, pi, "pjl_impl_deallocte_interp(pjl_interp_t)"); - - return 0; + pjl_interp_t *pi = (pjl_interp_t *)interp; + gs_memory_t *mem = pi->memory; + gs_free_object(mem, pi, "pjl_impl_deallocte_interp(pjl_interp_t)"); + + return 0; } /* return the current setting of a pjl environment variable. */ @@ -274,8 +272,8 @@ pjl_impl_get_envvar( const char *pjl_var ) { - pjl_interp_instance_t *pjli = (pjl_interp_instance_t *)pli; - return pjl_get_envvar(pjli->state, pjl_var); + pjl_interp_instance_t *pjli = (pjl_interp_instance_t *)pli; + return pjl_get_envvar(pjli->state, pjl_var); } /* compare a pjl environment variable to a string values. */ @@ -286,7 +284,7 @@ pjl_impl_compare( const char *s2 ) { - return pjl_compare(s1, s2); + return pjl_compare(s1, s2); } /* map a pjl symbol set name to a pcl integer */ @@ -296,7 +294,7 @@ pjl_impl_map_pjl_sym_to_pcl_sym( const pjl_envvar_t *symname ) { - return pjl_map_pjl_sym_to_pcl_sym(symname); + return pjl_map_pjl_sym_to_pcl_sym(symname); } /* pjl environment variable to integer. */ @@ -306,7 +304,7 @@ pjl_impl_vartoi( const pjl_envvar_t *s ) { - return pjl_vartoi(s); + return pjl_vartoi(s); } /* pjl envioronment variable to float. */ @@ -316,7 +314,7 @@ pjl_impl_vartof( const pjl_envvar_t *s ) { - return pjl_vartof(s); + return pjl_vartof(s); } /* convert a pjl designated fontsource to a subdirectory pathname. */ @@ -326,8 +324,8 @@ pjl_impl_fontsource_to_path( const pjl_envvar_t *fontsource ) { - pjl_interp_instance_t *pjli = (pjl_interp_instance_t *)pli; - return pjl_fontsource_to_path(pjli->state, fontsource); + pjl_interp_instance_t *pjli = (pjl_interp_instance_t *)pli; + return pjl_fontsource_to_path(pjli->state, fontsource); } /* Change to next highest priority font source. */ @@ -336,8 +334,8 @@ pjl_impl_set_next_fontsource( pl_interp_instance_t *pli ) { - pjl_interp_instance_t *pjli = (pjl_interp_instance_t *)pli; - pjl_set_next_fontsource(pjli->state); + pjl_interp_instance_t *pjli = (pjl_interp_instance_t *)pli; + pjl_set_next_fontsource(pjli->state); } /* tell pjl that a soft font is being deleted. */ @@ -347,19 +345,18 @@ pjl_impl_register_permanent_soft_font_deletion( int font_number ) { - pjl_interp_instance_t *pjli = (pjl_interp_instance_t *)pli; - return pjl_register_permanent_soft_font_deletion(pjli->state, font_number); + pjl_interp_instance_t *pjli = (pjl_interp_instance_t *)pli; + return pjl_register_permanent_soft_font_deletion(pjli->state, font_number); } - /* request that pjl add a soft font and return a pjl font number for the font. */ int pjl_impl_register_permanent_soft_font_addition( pl_interp_instance_t *pli ) { - pjl_interp_instance_t *pjli = (pjl_interp_instance_t *)pli; - return pjl_register_permanent_soft_font_addition(pjli->state); + pjl_interp_instance_t *pjli = (pjl_interp_instance_t *)pli; + return pjl_register_permanent_soft_font_addition(pjli->state); } long int @@ -376,7 +373,6 @@ pjl_impl_get_named_resource(pl_interp_instance_t *pli, char *name, unsigned char return pjl_get_named_resource(pjli->state, name, data); } - /* Parser implementation descriptor */ pjl_implementation_t pjl_implementation = { /* Generic language parser portion */ diff --git a/pl/pjtop.c b/pl/pjtop.c index 30c93df66..ea1dd002e 100644 --- a/pl/pjtop.c +++ b/pl/pjtop.c @@ -24,8 +24,8 @@ pjl_proc_get_envvar( const char *pjl_var ) { - return ((pjl_implementation_t *)pli->interp->implementation) - ->proc_get_envvar(pli, pjl_var); + return ((pjl_implementation_t *)pli->interp->implementation) + ->proc_get_envvar(pli, pjl_var); } /* compare a pjl environment variable to a string values. */ @@ -36,8 +36,8 @@ pjl_proc_compare( const char *s2 ) { - return ((pjl_implementation_t *)pli->interp->implementation) - ->proc_compare(pli, s1, s2); + return ((pjl_implementation_t *)pli->interp->implementation) + ->proc_compare(pli, s1, s2); } /* map a pjl symbol set name to a pcl integer */ @@ -47,8 +47,8 @@ pjl_proc_map_pjl_sym_to_pcl_sym( const pjl_envvar_t *symname ) { - return ((pjl_implementation_t *)pli->interp->implementation) - ->proc_map_pjl_sym_to_pcl_sym(pli, symname); + return ((pjl_implementation_t *)pli->interp->implementation) + ->proc_map_pjl_sym_to_pcl_sym(pli, symname); } /* pjl environment variable to integer. */ @@ -58,8 +58,8 @@ pjl_proc_vartoi( const pjl_envvar_t *s ) { - return ((pjl_implementation_t *)pli->interp->implementation) - ->proc_vartoi(pli, s); + return ((pjl_implementation_t *)pli->interp->implementation) + ->proc_vartoi(pli, s); } /* pjl envioronment variable to float. */ @@ -69,8 +69,8 @@ pjl_proc_vartof( const pjl_envvar_t *s ) { - return ((pjl_implementation_t *)pli->interp->implementation) - ->proc_vartof(pli, s); + return ((pjl_implementation_t *)pli->interp->implementation) + ->proc_vartof(pli, s); } /* convert a pjl designated fontsource to a subdirectory pathname. */ @@ -80,8 +80,8 @@ pjl_proc_fontsource_to_path( const pjl_envvar_t *fontsource ) { - return ((pjl_implementation_t *)pli->interp->implementation) - ->proc_fontsource_to_path(pli, fontsource); + return ((pjl_implementation_t *)pli->interp->implementation) + ->proc_fontsource_to_path(pli, fontsource); } /* Change to next highest priority font source. */ @@ -90,8 +90,8 @@ pjl_proc_set_next_fontsource( pl_interp_instance_t *pli ) { - ((pjl_implementation_t *)pli->interp->implementation) - ->proc_set_next_fontsource(pli); + ((pjl_implementation_t *)pli->interp->implementation) + ->proc_set_next_fontsource(pli); } /* tell pjl that a soft font is being deleted. */ @@ -101,8 +101,8 @@ pjl_proc_register_permanent_soft_font_deletion( int font_number ) { - return ((pjl_implementation_t *)pli->interp->implementation) - ->proc_register_permanent_soft_font_deletion(pli, font_number); + return ((pjl_implementation_t *)pli->interp->implementation) + ->proc_register_permanent_soft_font_deletion(pli, font_number); } /* request that pjl add a soft font and return a pjl font number for the font. */ @@ -111,20 +111,20 @@ pjl_proc_register_permanent_soft_font_addition( pl_interp_instance_t *pli ) { - return ((pjl_implementation_t *)pli->interp->implementation) - ->proc_register_permanent_soft_font_addition(pli); + return ((pjl_implementation_t *)pli->interp->implementation) + ->proc_register_permanent_soft_font_addition(pli); } long int pjl_proc_get_named_resource_size(pl_interp_instance_t *pli, char *name) { return ((pjl_implementation_t *)pli->interp->implementation) - ->proc_get_named_resource_size(pli, name); + ->proc_get_named_resource_size(pli, name); } int pjl_proc_get_named_resource(pl_interp_instance_t *pli, char *name, byte *data) { return ((pjl_implementation_t *)pli->interp->implementation) - ->proc_get_named_resource(pli, name, data); + ->proc_get_named_resource(pli, name, data); } diff --git a/pl/pjtop.h b/pl/pjtop.h index 1c396794f..26f9e0dbf 100644 --- a/pl/pjtop.h +++ b/pl/pjtop.h @@ -34,13 +34,13 @@ typedef char pjl_envvar_t; /* opaque decl */ */ /* return the current setting of a pjl environment variable. The input parameter should be the exact string used in PJLTRM. - Sample Usage: + Sample Usage: char *formlines = pjl_get_envvar(pst, "formlines"); - if (formlines) { - int fl = atoi(formlines); - . - . - } + if (formlines) { + int fl = atoi(formlines); + . + . + } Both variables and values are case insensitive. */ typedef pjl_envvar_t * (*pjl_proc_get_envvar_t)(pl_interp_instance_t *pli, const char *pjl_var); @@ -107,7 +107,7 @@ int pjl_proc_get_named_resource(pl_interp_instance_t *pli, char *name, byte *dat * Define a generic interpreter implementation */ typedef struct pjl_implementation_s { - pl_interp_implementation_t pl; /* MUST BE FIRST generic impl */ + pl_interp_implementation_t pl; /* MUST BE FIRST generic impl */ /* PJL-specific procedure vector */ pjl_proc_get_envvar_t proc_get_envvar; @@ -122,9 +122,6 @@ typedef struct pjl_implementation_s { pjl_proc_get_named_resource_size_t proc_get_named_resource_size; pjl_proc_get_named_resource_t proc_get_named_resource; - } pjl_implementation_t; - #endif /* pjtop_INCLUDED */ - diff --git a/pl/plalloc.c b/pl/plalloc.c index d7604989a..61f7f15e8 100644 --- a/pl/plalloc.c +++ b/pl/plalloc.c @@ -1,5 +1,5 @@ /* Allocator for languages (pcl, xps, etc.), simply uses the chunk - memory manager see gsmchunk.c */ + memory manager see gsmchunk.c */ /*$Id$*/ @@ -16,7 +16,7 @@ pl_alloc_init() gs_memory_t *pl_mem; int code; - if (mem == NULL) + if (mem == NULL) return NULL; #ifdef HEAP_ALLOCATOR_ONLY diff --git a/pl/plalloc.h b/pl/plalloc.h index 71d8bbfa3..a0398e086 100644 --- a/pl/plalloc.h +++ b/pl/plalloc.h @@ -13,5 +13,3 @@ /* initialize the gs allocator. */ gs_memory_t *pl_alloc_init(void); - - diff --git a/pl/plapi.h b/pl/plapi.h index 59ec2610e..0833d312d 100644 --- a/pl/plapi.h +++ b/pl/plapi.h @@ -18,17 +18,17 @@ # define plapi_INCLUDED /* - * This API level is intended to hide everything behind + * This API level is intended to hide everything behind * a simple main_like argc, argv interface */ /* Exported functions may need different prefix * GSDLLEXPORT marks functions as exported - * GSDLLAPI is the calling convention used on functions exported + * GSDLLAPI is the calling convention used on functions exported * When you include this header file in the caller, you may * need to change the definitions by defining these * before including this header file. - * Make sure you get the calling convention correct, otherwise your + * Make sure you get the calling convention correct, otherwise your * program will crash soon after returning due to stack corruption. */ @@ -68,16 +68,15 @@ # define GSDLLAPIPTR GSDLLAPI * #endif - /* Run this just like you would pcl6 on the command line. * - * Returns: 0 success - * < 0 error code + * Returns: 0 success + * < 0 error code */ -GSDLLEXPORT int GSDLLAPI +GSDLLEXPORT int GSDLLAPI pl_main(int argc, char *argv[]); -GSDLLEXPORT int GSDLLAPI +GSDLLEXPORT int GSDLLAPI pl_main_aux(int argc, char *argv[], void *disp); #endif /* plapi_INCLUDED */ diff --git a/pl/plchar.c b/pl/plchar.c index 86424f632..bd2c7a0d4 100644 --- a/pl/plchar.c +++ b/pl/plchar.c @@ -105,17 +105,17 @@ pl_bitmap_encode_char(gs_font *pfont, gs_char chr, gs_glyph not_used) /* This is simple for the same reason. */ static int pl_bitmap_char_width(const pl_font_t *plfont, const void *pgs, uint char_code, gs_point *pwidth) -{ +{ const byte *cdata = pl_font_lookup_glyph(plfont, char_code)->data; pwidth->x = pwidth->y = 0; if ( !pwidth ) { -#ifdef DEBUG +#ifdef DEBUG dprintf("Warning should not call width function without width\n" ); #endif return (cdata == 0 ? 1 : 0); } - if ( cdata == 0 ) { + if ( cdata == 0 ) { return 1; } if ( cdata[0] == 0 ) { /* PCL XL characters don't have an escapement. */ @@ -123,7 +123,7 @@ pl_bitmap_char_width(const pl_font_t *plfont, const void *pgs, uint char_code, g return 0; } - { + { const byte *params = cdata + 6; pwidth->x = (plfont->header[13] ? /* variable pitch */ pl_get_int16(params + 8) * 0.25 : @@ -145,7 +145,7 @@ pl_bitmap_char_metrics(const pl_font_t *plfont, const void *pgs, uint char_code, /* We are not concerned about PCL XL characters */ if ( cdata[0] == 0 ) return 0; - + metrics[0] = pl_get_int16(cdata + 6); pl_bitmap_char_width(plfont, pgs, char_code, &width); metrics[2] = width.x; @@ -208,7 +208,7 @@ bits_smear_horizontally(byte *dest, const byte *src, uint width, sdmask = 0x80, *dp++ = dbyte, dbyte = sbyte = *++sp; } } - + /* Process all but the last smear_width bits. */ { for ( ; i < width; ++i ) { if ( sbyte & sdmask ) @@ -344,7 +344,6 @@ image_bitmap_char(gs_image_enum *ienum, const gs_image_t *pim, } } - code = (*dev_proc(dev, image_data)) (dev, iinfo, planes, 0, dest_bytes, 1); if ( code != 0 ) @@ -362,7 +361,6 @@ image_bitmap_char(gs_image_enum *ienum, const gs_image_t *pim, return code; } - /* Render a character for a bitmap font. */ /* This handles both format 0 (PCL XL) and format 4 (PCL5 bitmap). */ static int @@ -409,7 +407,7 @@ pl_bitmap_build_char(gs_show_enum *penum, gs_state *pgs, gs_font *pfont, image.Width = pl_get_uint16(params + 4); image.Height = pl_get_uint16(params + 6); /* Determine the amount of pseudo-bolding. */ - if ( plfont->bold_fraction != 0 ) { + if ( plfont->bold_fraction != 0 ) { bold = (uint)(2 * image.Height * plfont->bold_fraction + 0.5); bold_lines = alloc_bold_lines(pgs->memory, image.Width, bold, "pl_bitmap_build_char(bold_line)"); @@ -443,7 +441,7 @@ pl_bitmap_build_char(gs_show_enum *penum, gs_state *pgs, gs_font *pfont, } if ( code < 0 ) return code; -#ifdef DEBUG +#ifdef DEBUG if ( gs_debug_c('B') ) { int i; int pixels = round_up(image.Width,8) * image.Height; @@ -524,25 +522,25 @@ pl_font_vertical_glyph(gs_glyph glyph, const pl_font_t *plfont) return gs_no_glyph; } -/* get metrics with support for XL tt class 1 and 2 - * pl overrides gstype42_default_get_metrics +/* get metrics with support for XL tt class 1 and 2 + * pl overrides gstype42_default_get_metrics */ int pl_tt_get_metrics(gs_font_type42 * pfont, uint glyph_index, gs_type42_metrics_options_t options, float *sbw) -{ +{ pl_font_t *plfont = pfont->client_data; const pl_font_glyph_t *pfg = 0; const byte *cdata = 0; int wmode = gs_type42_metrics_options_wmode(options); if ( plfont->glyphs.table != 0 ) { - /* at least one caller calls before the glyph.table is valid, no chars yet + /* at least one caller calls before the glyph.table is valid, no chars yet * test routes caller to gs_type42_default_get_metrics */ pfg = pl_font_lookup_glyph(plfont, glyph_index); - cdata = pfg->data; + cdata = pfg->data; if (cdata && (cdata[1] == 1 || cdata[1] == 2)) { double factor = 1.0 / pfont->data.unitsPerEm; @@ -564,7 +562,7 @@ pl_tt_get_metrics(gs_font_type42 * pfont, uint glyph_index, } else { sbw[0] = lsb * factor, sbw[1] = 0; sbw[2] = width * factor, sbw[3] = 0; - } + } return 0; /* tt class 1,2 */ } } @@ -600,43 +598,42 @@ pl_tt_get_metrics(gs_font_type42 * pfont, uint glyph_index, return gs_type42_default_get_metrics(pfont, glyph_index, wmode, sbw); } - /* Get the outline data for a glyph in a downloaded TrueType font. */ int pl_tt_get_outline(gs_font_type42 *pfont, uint index, gs_glyph_data_t *pdata) -{ +{ pl_font_t *plfont = pfont->client_data; const pl_font_glyph_t *pfg = pl_font_lookup_glyph(plfont, index); const byte *cdata = pfg->data; - if ( cdata == 0 ) { + if ( cdata == 0 ) { /* undefined glyph */ gs_glyph_data_from_null(pdata); } - else { + else { uint desc_size = (*cdata == 15 ? cdata[2] /* PCL5 */ : 0 /* PCL XL */); uint data_size = pl_get_uint16(cdata + 2 + desc_size); - if ( data_size <= 4 ) { + if ( data_size <= 4 ) { /* empty outline */ gs_glyph_data_from_null(pdata); - } else if ( cdata[1] == 0) { - gs_glyph_data_from_bytes(pdata, + } else if ( cdata[1] == 0) { + gs_glyph_data_from_bytes(pdata, cdata, - 6 + desc_size, - data_size - 4, + 6 + desc_size, + data_size - 4, NULL); - } else if ( cdata[1] == 1) { - gs_glyph_data_from_bytes(pdata, + } else if ( cdata[1] == 1) { + gs_glyph_data_from_bytes(pdata, cdata, - 10, - data_size - 8, + 10, + data_size - 8, NULL); - } else if ( cdata[1] == 2) { - gs_glyph_data_from_bytes(pdata, + } else if ( cdata[1] == 2) { + gs_glyph_data_from_bytes(pdata, cdata, - 12, - data_size - 10, + 12, + data_size - 10, NULL); } } @@ -849,11 +846,11 @@ gs_char last_char = 0; /* we may return either gs_no_glyph or 0 for an undefined character. */ gs_glyph pl_tt_encode_char(gs_font *pfont_generic, gs_char chr, gs_glyph not_used) -{ +{ gs_font_type42 *pfont = (gs_font_type42 *)pfont_generic; uint cmap_len; ulong cmap_offset = tt_find_table(pfont, "cmap", &cmap_len); - gs_glyph glyph = + gs_glyph glyph = (cmap_offset == 0 ? /* This is a downloaded font with no cmap. */ pl_tt_dynamic_encode_char(pfont, chr) : @@ -882,7 +879,6 @@ pl_tt_encode_char(gs_font *pfont_generic, gs_char chr, gs_glyph not_used) return glyph; /* no substitute */ } - /* Get metrics */ static int pl_tt_char_metrics(const pl_font_t *plfont, const void *pgs, uint char_code, float metrics[4]) @@ -905,7 +901,7 @@ pl_tt_char_width(const pl_font_t *plfont, const void *pgs, uint char_code, gs_po gs_glyph glyph = pl_tt_encode_char(pfont, chr, unused_glyph); int code; float sbw[4]; - + pwidth->x = pwidth->y = 0; /* Check for a vertical substitute. */ @@ -927,7 +923,6 @@ pl_tt_char_width(const pl_font_t *plfont, const void *pgs, uint char_code, gs_po return 0; } - /* Render a TrueType character. */ static int pl_tt_build_char(gs_show_enum *penum, gs_state *pgs, gs_font *pfont, @@ -1009,7 +1004,6 @@ pl_tt_build_char(gs_show_enum *penum, gs_state *pgs, gs_font *pfont, } } - /* * If we want pseudo-bold, render untransformed to an intermediate * bitmap, smear it, and then transform it to produce the output. @@ -1196,7 +1190,7 @@ pl_intelli_merge_box(float wbox[6], const pl_font_t *plfont, gs_glyph glyph) /* The caller has done the setcachedevice. */ static int pl_intelli_show_char(gs_state *pgs, const pl_font_t *plfont, gs_glyph glyph) -{ +{ int code; const byte *cdata; pl_font_glyph_t *font_glyph; @@ -1207,78 +1201,78 @@ pl_intelli_show_char(gs_state *pgs, const pl_font_t *plfont, gs_glyph glyph) cdata = font_glyph->data; if ( cdata == 0 ) { - if_debug1('1', "[1] no character data for glyph %ld\n",glyph); - return 0; + if_debug1('1', "[1] no character data for glyph %ld\n",glyph); + return 0; } if ( cdata[3] == 4 ) { /* Compound character */ - gs_matrix save_ctm; - int i; - gs_currentmatrix(pgs, &save_ctm); - for ( i = 0; i < cdata[6]; ++i ) { - const byte *edata = cdata + 8 + i * 6; - floatp x_offset = pl_get_int16(edata + 2); - floatp y_offset = pl_get_int16(edata + 4); - gs_translate(pgs, x_offset, y_offset); - code = pl_intelli_show_char(pgs, plfont, pl_get_uint16(edata)); - gs_setmatrix(pgs, &save_ctm); - if ( code < 0 ) - return code; - } - return 0; + gs_matrix save_ctm; + int i; + gs_currentmatrix(pgs, &save_ctm); + for ( i = 0; i < cdata[6]; ++i ) { + const byte *edata = cdata + 8 + i * 6; + floatp x_offset = pl_get_int16(edata + 2); + floatp y_offset = pl_get_int16(edata + 4); + gs_translate(pgs, x_offset, y_offset); + code = pl_intelli_show_char(pgs, plfont, pl_get_uint16(edata)); + gs_setmatrix(pgs, &save_ctm); + if ( code < 0 ) + return code; + } + return 0; } /* compound character */ /* not compound character */ { - const byte *outlines; - uint num_loops; - uint i; - cdata += 4; /* skip PCL character header */ - outlines = cdata + pl_get_uint16(cdata + 6); - num_loops = pl_get_uint16(outlines); + const byte *outlines; + uint num_loops; + uint i; + cdata += 4; /* skip PCL character header */ + outlines = cdata + pl_get_uint16(cdata + 6); + num_loops = pl_get_uint16(outlines); - if_debug2('1', "[1]ifont glyph %lu: loops=%u\n",(ulong)glyph, num_loops); + if_debug2('1', "[1]ifont glyph %lu: loops=%u\n",(ulong)glyph, num_loops); if (num_loops == 0) return -1; - for ( i = 0; i < num_loops; ++i ) { - const byte *xyc = cdata + pl_get_uint16(outlines + 4 + i * 8); - uint num_points; - uint num_aux_points; - const byte *x_coords, *y_coords, *x_coords_last; - const byte *x_aux_coords, *y_aux_coords, *x_aux_coords_last; - int llx, lly, urx, ury; /* character bounding box */ - int x, y; - int xAux, yAux; - int *xLimit, *yLimit, *xScan, *yScan, *xLast; - int pointBufferSize; + for ( i = 0; i < num_loops; ++i ) { + const byte *xyc = cdata + pl_get_uint16(outlines + 4 + i * 8); + uint num_points; + uint num_aux_points; + const byte *x_coords, *y_coords, *x_coords_last; + const byte *x_aux_coords, *y_aux_coords, *x_aux_coords_last; + int llx, lly, urx, ury; /* character bounding box */ + int x, y; + int xAux, yAux; + int *xLimit, *yLimit, *xScan, *yScan, *xLast; + int pointBufferSize; uint sz; - num_points = pl_get_uint16(xyc); - num_aux_points = pl_get_uint16(xyc + 2); - - x_coords = xyc + 4; - y_coords = x_coords + num_points * 2; - x_coords_last = y_coords; - - metrics = (const intelli_metrics_t *)(cdata + pl_get_uint16(cdata + 2)); - llx = pl_get_int16(metrics->charSymbolBox[0]); - lly = pl_get_int16(metrics->charSymbolBox[1]); - urx = pl_get_int16(metrics->charSymbolBox[2]); - ury = pl_get_int16(metrics->charSymbolBox[3]); - - pointBufferSize = num_points; /* allocate enough to hold all points */ - if ( num_aux_points != 0xffff ) { - pointBufferSize += num_aux_points; - x_aux_coords = y_coords + num_points * 2; - y_aux_coords = x_aux_coords + num_aux_points; - x_aux_coords_last = y_coords; - } - else { - x_aux_coords = NULL; - y_aux_coords = NULL; - x_aux_coords_last = NULL; - } + num_points = pl_get_uint16(xyc); + num_aux_points = pl_get_uint16(xyc + 2); + + x_coords = xyc + 4; + y_coords = x_coords + num_points * 2; + x_coords_last = y_coords; + + metrics = (const intelli_metrics_t *)(cdata + pl_get_uint16(cdata + 2)); + llx = pl_get_int16(metrics->charSymbolBox[0]); + lly = pl_get_int16(metrics->charSymbolBox[1]); + urx = pl_get_int16(metrics->charSymbolBox[2]); + ury = pl_get_int16(metrics->charSymbolBox[3]); + + pointBufferSize = num_points; /* allocate enough to hold all points */ + if ( num_aux_points != 0xffff ) { + pointBufferSize += num_aux_points; + x_aux_coords = y_coords + num_points * 2; + y_aux_coords = x_aux_coords + num_aux_points; + x_aux_coords_last = y_coords; + } + else { + x_aux_coords = NULL; + y_aux_coords = NULL; + x_aux_coords_last = NULL; + } sz = pointBufferSize * sizeof(int); @@ -1291,82 +1285,82 @@ pl_intelli_show_char(gs_state *pgs, const pl_font_t *plfont, gs_glyph glyph) yBuffer = (int *)gs_resize_object(pgs->memory, yBuffer, sz, cname); } - if (xBuffer == NULL || yBuffer == NULL) { - if( xBuffer != NULL) - gs_free_object(pgs->memory, xBuffer, "x point buffer"); - if( yBuffer != NULL) - gs_free_object(pgs->memory, yBuffer, "y point buffer"); - if_debug1('1', "[1]cannot allocate point buffers %i\n",pointBufferSize * sizeof(int)); - return_error(gs_error_VMerror); - } - - xLimit = xBuffer + pointBufferSize; - yLimit = yBuffer + pointBufferSize; - xLast = NULL; - - if_debug2('1', "[1]num_points=%u num_aux_points=%u\n", num_points, num_aux_points); - - /* collect the points in the buffers, since we need to clean them up later */ - /* only points inside the bounding box are allowed */ - /* aux points are points inserted between two points, making the outline smoother */ - /* the aux points could be used for curve fitting, but we add line segments */ - for ( xScan = xBuffer, yScan = yBuffer; x_coords < x_coords_last; x_coords += 2, y_coords += 2 ) { - x = pl_get_uint16(x_coords) & 0x3fff; - y = pl_get_uint16(y_coords) & 0x3fff; - - if_debug4('1', "[1]%s (%d,%d) %s\n", - (*x_coords & 0x80 ? " line" : "curve"), x, y, - (*y_coords & 0x80 ? " line" : "curve")); - - if (xScan > xBuffer) { /* not first point, therefore aux is possible */ - if ( x_aux_coords < x_aux_coords_last &&!(*x_coords & 0x80) ) { /* use an aux point */ - /* The auxiliary dx and dy values are signed. */ - int dx = (*x_aux_coords++ ^ 0x80) - 0x80; - int dy = (*y_aux_coords++ ^ 0x80) - 0x80; - - if_debug2('1', "[1]... aux (%d,%d)\n", dx, dy); - - xAux = (x + *(xScan-1)) / 2 + dx; - yAux = (y + *(yScan-1)) / 2 + dy; - if ((xAux >= llx && xAux <= urx) && (yAux >= lly && yAux <= ury)) { /* aux point is inside bounding box */ - *xScan++ = xAux; - *yScan++ = yAux; - } /* end point inside bounding box */ - /* what do points outside the bounding box mean? */ - } /* use an aux point */ - } /* not first point */ - - if ( (x >= llx && x <= urx) && (y >= lly && y <= ury) ) { /* point inside bounding box */ - *xScan++ = x; - *yScan++ = y; - } /* point inside bounding box */ - } /* for num_points - first time through */ - - if ( num_aux_points != 0xffff ) - xLast = xScan; - else - xLast = xScan - 1; /* discard the last point */ - - xScan = xBuffer; - yScan = yBuffer; - if (xLast > xBuffer) { - code = gs_moveto(pgs, (floatp)*xScan++, (floatp)*yScan++); - if ( code < 0 ) - goto cleanup; - } - - for (; xScan < xLast; ) { - code = gs_lineto(pgs, (floatp)*xScan++, (floatp)*yScan++); - if ( code < 0 ) - goto cleanup; - } - /* close the path of this loop */ - code = gs_closepath(pgs); - if ( code < 0 ) + if (xBuffer == NULL || yBuffer == NULL) { + if( xBuffer != NULL) + gs_free_object(pgs->memory, xBuffer, "x point buffer"); + if( yBuffer != NULL) + gs_free_object(pgs->memory, yBuffer, "y point buffer"); + if_debug1('1', "[1]cannot allocate point buffers %i\n",pointBufferSize * sizeof(int)); + return_error(gs_error_VMerror); + } + + xLimit = xBuffer + pointBufferSize; + yLimit = yBuffer + pointBufferSize; + xLast = NULL; + + if_debug2('1', "[1]num_points=%u num_aux_points=%u\n", num_points, num_aux_points); + + /* collect the points in the buffers, since we need to clean them up later */ + /* only points inside the bounding box are allowed */ + /* aux points are points inserted between two points, making the outline smoother */ + /* the aux points could be used for curve fitting, but we add line segments */ + for ( xScan = xBuffer, yScan = yBuffer; x_coords < x_coords_last; x_coords += 2, y_coords += 2 ) { + x = pl_get_uint16(x_coords) & 0x3fff; + y = pl_get_uint16(y_coords) & 0x3fff; + + if_debug4('1', "[1]%s (%d,%d) %s\n", + (*x_coords & 0x80 ? " line" : "curve"), x, y, + (*y_coords & 0x80 ? " line" : "curve")); + + if (xScan > xBuffer) { /* not first point, therefore aux is possible */ + if ( x_aux_coords < x_aux_coords_last &&!(*x_coords & 0x80) ) { /* use an aux point */ + /* The auxiliary dx and dy values are signed. */ + int dx = (*x_aux_coords++ ^ 0x80) - 0x80; + int dy = (*y_aux_coords++ ^ 0x80) - 0x80; + + if_debug2('1', "[1]... aux (%d,%d)\n", dx, dy); + + xAux = (x + *(xScan-1)) / 2 + dx; + yAux = (y + *(yScan-1)) / 2 + dy; + if ((xAux >= llx && xAux <= urx) && (yAux >= lly && yAux <= ury)) { /* aux point is inside bounding box */ + *xScan++ = xAux; + *yScan++ = yAux; + } /* end point inside bounding box */ + /* what do points outside the bounding box mean? */ + } /* use an aux point */ + } /* not first point */ + + if ( (x >= llx && x <= urx) && (y >= lly && y <= ury) ) { /* point inside bounding box */ + *xScan++ = x; + *yScan++ = y; + } /* point inside bounding box */ + } /* for num_points - first time through */ + + if ( num_aux_points != 0xffff ) + xLast = xScan; + else + xLast = xScan - 1; /* discard the last point */ + + xScan = xBuffer; + yScan = yBuffer; + if (xLast > xBuffer) { + code = gs_moveto(pgs, (floatp)*xScan++, (floatp)*yScan++); + if ( code < 0 ) + goto cleanup; + } + + for (; xScan < xLast; ) { + code = gs_lineto(pgs, (floatp)*xScan++, (floatp)*yScan++); + if ( code < 0 ) + goto cleanup; + } + /* close the path of this loop */ + code = gs_closepath(pgs); + if ( code < 0 ) break; - } /* for num_loops */ - + } /* for num_loops */ + cleanup: gs_free_object(pgs->memory, xBuffer, "x point buffer"); gs_free_object(pgs->memory, yBuffer, "y point buffer"); @@ -1377,7 +1371,7 @@ cleanup: /* Get character existence and escapement for an Intellifont. */ static int pl_intelli_char_width(const pl_font_t *plfont, const void *pgs, uint char_code, gs_point *pwidth) -{ +{ const byte *cdata = pl_font_lookup_glyph(plfont, char_code)->data; int wx; @@ -1426,7 +1420,7 @@ pl_intelli_char_metrics(const pl_font_t *plfont, const void *pgs, uint char_code metrics[0] = metrics[1] = metrics[2] = metrics[3] = 0; - if ( cdata == 0 ) { + if ( cdata == 0 ) { return 1; } @@ -1437,7 +1431,7 @@ pl_intelli_char_metrics(const pl_font_t *plfont, const void *pgs, uint char_code } cdata += 4; - + { const intelli_metrics_t *intelli_metrics = (const intelli_metrics_t *)(cdata + pl_get_uint16(cdata + 2)); @@ -1480,7 +1474,6 @@ pl_intelli_build_char(gs_show_enum *penum, gs_state *pgs, gs_font *pfont, return (code < 0 ? code : 0); } - /* ---------------- Internal initialization ---------------- */ /* Initialize the procedures for a bitmap font. */ @@ -1497,7 +1490,7 @@ pl_bitmap_init_procs(gs_font_base *pfont) /* Initialize the procedures for a TrueType font. */ void pl_tt_init_procs(gs_font_type42 *pfont) -{ +{ pfont->procs.encode_char = (void *)pl_tt_encode_char; /* FIX ME (void *) */ pfont->procs.build_char = (void *)pl_tt_build_char; /* FIX ME (void *) */ pfont->data.string_proc = pl_tt_string_proc; @@ -1690,11 +1683,11 @@ tcg: if ( plfont->char_glyphs.table ) } /* get glyph id from character download */ if ( cdata[0] == 1 ) - /* pxl truetype format 1, + /* pxl truetype format 1, * class 0 at offset 4, class 1 at offset 8 or class 2 at 10 */ key = pl_get_uint16(cdata + ((cdata[1] == 0) ? 4 : ((cdata[1] == 1) ? 8 : 10))); else - /* pcl truetype format 15 */ + /* pcl truetype format 15 */ key = pl_get_uint16(cdata + cdata[2] + 4); } fg: pfg = pl_font_lookup_glyph(plfont, key); @@ -1752,7 +1745,7 @@ pl_font_disable_composite_metrics(pl_font_t *plfont, gs_glyph glyph) font wrapper format. It is documented in several other places in this file. If a char_glyphs table is not available it is not a downloadedd TT font wrapper so we do nothing. */ - if (plfont->char_glyphs.table) { + if (plfont->char_glyphs.table) { pl_tt_char_glyph_t *ptcg = pl_tt_lookup_char(plfont, key); if ( ptcg->chr == gs_no_char ) return 0; @@ -1770,7 +1763,7 @@ pl_font_disable_composite_metrics(pl_font_t *plfont, gs_glyph glyph) /* null glyph */ if (glyph_data.bits.data == 0) return 0; - + /* the glyph is guaranteed by the langauges to be have a reasonable header (enough to test for a composite glyph and do the tests below for components) so a UMR or overflow is not possible but diff --git a/pl/pldict.c b/pl/pldict.c index 437d6aa4b..37540e604 100644 --- a/pl/pldict.c +++ b/pl/pldict.c @@ -43,15 +43,15 @@ gs_private_st_composite(st_pl_dict_entry, pl_dict_entry_t, "pl_dict_entry_t", #define pde ((pl_dict_entry_t *)vptr) static ENUM_PTRS_BEGIN(pl_dict_entry_enum_ptrs) return 0; /* ENUM_CONST_STRING_PTR(0, pl_dict_entry_t, key); */ - ENUM_PTR(1, pl_dict_entry_t, value); - ENUM_PTR(2, pl_dict_entry_t, next); - ENUM_PTR(3, pl_dict_entry_t, link); + ENUM_PTR(1, pl_dict_entry_t, value); + ENUM_PTR(2, pl_dict_entry_t, next); + ENUM_PTR(3, pl_dict_entry_t, link); ENUM_PTRS_END static RELOC_PTRS_BEGIN(pl_dict_entry_reloc_ptrs) { /* RELOC_CONST_STRING_PTR(pl_dict_entry_t, key); */ - RELOC_PTR(pl_dict_entry_t, value); - RELOC_PTR(pl_dict_entry_t, next); - RELOC_PTR(pl_dict_entry_t, link); + RELOC_PTR(pl_dict_entry_t, value); + RELOC_PTR(pl_dict_entry_t, next); + RELOC_PTR(pl_dict_entry_t, link); } RELOC_PTRS_END #undef pde @@ -70,29 +70,29 @@ pl_dict_value_free(gs_memory_t *mem, void *value, client_name_t cname) static pl_dict_entry_t ** pl_dict_lookup_entry(pl_dict_t *pdict, const byte *kdata, uint ksize) { pl_dict_entry_t **ppde = &pdict->entries; - pl_dict_entry_t *pde; - for ( ; (pde = *ppde) != 0; ppde = &pde->next ) - { if ( pde->key.size == ksize && - !memcmp(entry_key_data(pde), kdata, ksize) - ) - return ppde; - } - return 0; + pl_dict_entry_t *pde; + for ( ; (pde = *ppde) != 0; ppde = &pde->next ) + { if ( pde->key.size == ksize && + !memcmp(entry_key_data(pde), kdata, ksize) + ) + return ppde; + } + return 0; } /* Delete a dictionary entry. */ static void pl_dict_free(pl_dict_t *pdict, pl_dict_entry_t **ppde, client_name_t cname) { pl_dict_entry_t *pde = *ppde; - gs_memory_t *mem = pdict->memory; + gs_memory_t *mem = pdict->memory; - *ppde = pde->next; - if ( !pde->link ) /* values are not freed for links */ - (*pdict->free_proc)(mem, pde->value, cname); - if ( pde->key.size > pl_dict_max_short_key ) - gs_free_string(mem, (byte *)pde->key.data, pde->key.size, cname); - gs_free_object(mem, pde, cname); - pdict->entry_count--; + *ppde = pde->next; + if ( !pde->link ) /* values are not freed for links */ + (*pdict->free_proc)(mem, pde->value, cname); + if ( pde->key.size > pl_dict_max_short_key ) + gs_free_string(mem, (byte *)pde->key.data, pde->key.size, cname); + gs_free_object(mem, pde, cname); + pdict->entry_count--; } /* ---------------- API procedures ---------------- */ @@ -102,10 +102,10 @@ void pl_dict_init(pl_dict_t *pdict, gs_memory_t *mem, pl_dict_value_free_proc_t free_proc) { pdict->memory = mem; - pdict->free_proc = (free_proc ? free_proc : pl_dict_value_free); - pdict->entries = 0; - pdict->entry_count = 0; - pdict->parent = 0; + pdict->free_proc = (free_proc ? free_proc : pl_dict_value_free); + pdict->entries = 0; + pdict->entry_count = 0; + pdict->parent = 0; } /* @@ -119,16 +119,16 @@ bool pl_dict_lookup(pl_dict_t *pdict, const byte *kdata, uint ksize, void **pvalue, bool with_stack, pl_dict_t **ppdict) { pl_dict_t *pdcur = pdict; - pl_dict_entry_t **ppde; + pl_dict_entry_t **ppde; - while ( (ppde = pl_dict_lookup_entry(pdcur, kdata, ksize)) == 0 ) - { if ( !with_stack || (pdcur = pdcur->parent) == 0 ) - return false; - } - *pvalue = (*ppde)->value; - if ( ppdict ) - *ppdict = pdcur; - return true; + while ( (ppde = pl_dict_lookup_entry(pdcur, kdata, ksize)) == 0 ) + { if ( !with_stack || (pdcur = pdcur->parent) == 0 ) + return false; + } + *pvalue = (*ppde)->value; + if ( ppdict ) + *ppdict = pdcur; + return true; } /* @@ -136,30 +136,30 @@ pl_dict_lookup(pl_dict_t *pdict, const byte *kdata, uint ksize, void **pvalue, */ static int pl_dict_build_new_entry(pl_dict_t *pdict, const byte *kdata, uint ksize, - void *value, pl_dict_entry_t *link) + void *value, pl_dict_entry_t *link) { /* Make a new entry. */ byte *kstr; - gs_memory_t *mem = pdict->memory; - pl_dict_entry_t *pde; - pde = gs_alloc_struct(mem, pl_dict_entry_t, &st_pl_dict_entry, - "pl_dict_put(entry)"); - kstr = (ksize <= pl_dict_max_short_key ? pde->short_key : - gs_alloc_string(mem, ksize, "pl_dict_put(key)")); - if ( pde == 0 || kstr == 0 ) - { if ( kstr && kstr != pde->short_key ) - gs_free_string(mem, kstr, ksize, "pl_dict_put(key)"); - gs_free_object(mem, pde, "pl_dict_put(entry)"); - return -1; - } - memcpy(kstr, kdata, ksize); - pde->key.data = (ksize <= pl_dict_max_short_key ? 0 : kstr); - pde->key.size = ksize; - pde->link = link; - pde->value = value; - pde->next = pdict->entries; - pdict->entries = pde; - pdict->entry_count++; - return 0; + gs_memory_t *mem = pdict->memory; + pl_dict_entry_t *pde; + pde = gs_alloc_struct(mem, pl_dict_entry_t, &st_pl_dict_entry, + "pl_dict_put(entry)"); + kstr = (ksize <= pl_dict_max_short_key ? pde->short_key : + gs_alloc_string(mem, ksize, "pl_dict_put(key)")); + if ( pde == 0 || kstr == 0 ) + { if ( kstr && kstr != pde->short_key ) + gs_free_string(mem, kstr, ksize, "pl_dict_put(key)"); + gs_free_object(mem, pde, "pl_dict_put(entry)"); + return -1; + } + memcpy(kstr, kdata, ksize); + pde->key.data = (ksize <= pl_dict_max_short_key ? 0 : kstr); + pde->key.size = ksize; + pde->link = link; + pde->value = value; + pde->next = pdict->entries; + pdict->entries = pde; + pdict->entry_count++; + return 0; } /* @@ -171,19 +171,19 @@ pl_dict_build_new_entry(pl_dict_t *pdict, const byte *kdata, uint ksize, int pl_dict_put(pl_dict_t *pdict, const byte *kdata, uint ksize, void *value) { pl_dict_entry_t **ppde = pl_dict_lookup_entry(pdict, kdata, ksize); - if ( !ppde ) - { void *link = 0; - return pl_dict_build_new_entry(pdict, kdata, ksize, value, link); - } - else - { /* Replace the value in an existing entry. */ - pl_dict_entry_t *pde; - pde = *ppde; - (*pdict->free_proc)(pdict->memory, pde->value, - "pl_dict_put(old value)"); - pde->value = value; - return 1; - } + if ( !ppde ) + { void *link = 0; + return pl_dict_build_new_entry(pdict, kdata, ksize, value, link); + } + else + { /* Replace the value in an existing entry. */ + pl_dict_entry_t *pde; + pde = *ppde; + (*pdict->free_proc)(pdict->memory, pde->value, + "pl_dict_put(old value)"); + pde->value = value; + return 1; + } } /* @@ -191,23 +191,23 @@ pl_dict_put(pl_dict_t *pdict, const byte *kdata, uint ksize, void *value) */ int pl_dict_put_synonym(pl_dict_t *pdict, const byte *old_kdata, uint old_ksize, - const byte *new_kdata, uint new_ksize) + const byte *new_kdata, uint new_ksize) { pl_dict_entry_t **old_ppde = pl_dict_lookup_entry(pdict, old_kdata, old_ksize); - pl_dict_entry_t *old_pde; - pl_dict_entry_t **new_ppde = pl_dict_lookup_entry(pdict, new_kdata, new_ksize); - /* old value doesn't exist or new value does exist */ - if ( !old_ppde || new_ppde ) - return -1; - /* find the original data if this is a link to a link */ - old_pde = *old_ppde; - if ( old_pde->link != 0 ) - old_pde = old_pde->link; + pl_dict_entry_t *old_pde; + pl_dict_entry_t **new_ppde = pl_dict_lookup_entry(pdict, new_kdata, new_ksize); + /* old value doesn't exist or new value does exist */ + if ( !old_ppde || new_ppde ) + return -1; + /* find the original data if this is a link to a link */ + old_pde = *old_ppde; + if ( old_pde->link != 0 ) + old_pde = old_pde->link; - return pl_dict_build_new_entry(pdict, new_kdata, new_ksize, - old_pde->value, old_pde); + return pl_dict_build_new_entry(pdict, new_kdata, new_ksize, + old_pde->value, old_pde); } -/* +/* * Purge alias entries. A bit tricky but this doesn't fowl the * enumeration code since links are always prior to their entries. We * insert at the head of the list and a real entry must be present to @@ -217,28 +217,28 @@ pl_dict_put_synonym(pl_dict_t *pdict, const byte *old_kdata, uint old_ksize, void pl_dict_undef_purge_synonyms(pl_dict_t *pdict, const byte *kdata, uint ksize) { pl_dict_entry_t **ppde = &pdict->entries; - pl_dict_entry_t **pptarget = pl_dict_lookup_entry(pdict, kdata, ksize); - pl_dict_entry_t *pde; - pl_dict_entry_t *ptarget; + pl_dict_entry_t **pptarget = pl_dict_lookup_entry(pdict, kdata, ksize); + pl_dict_entry_t *pde; + pl_dict_entry_t *ptarget; - if ( !pptarget ) - return; - ptarget = *pptarget; - /* get the real entry if this is a link. */ - if ( ptarget->link ) - ptarget = ptarget->link; + if ( !pptarget ) + return; + ptarget = *pptarget; + /* get the real entry if this is a link. */ + if ( ptarget->link ) + ptarget = ptarget->link; #define dict_get_key_data(entry) ((entry)->key.size > pl_dict_max_short_key ?\ (entry)->key.data : (entry)->short_key) - pl_dict_undef(pdict, dict_get_key_data(ptarget), ptarget->key.size); - /* delete links to the target */ - pde = *ppde; - while ( pde ) - { - pl_dict_entry_t *npde = pde->next; /* next entry */ - if ( pde->link && pde->link == ptarget ) - pl_dict_undef(pdict, dict_get_key_data(pde), pde->key.size); - pde = npde; - } + pl_dict_undef(pdict, dict_get_key_data(ptarget), ptarget->key.size); + /* delete links to the target */ + pde = *ppde; + while ( pde ) + { + pl_dict_entry_t *npde = pde->next; /* next entry */ + if ( pde->link && pde->link == ptarget ) + pl_dict_undef(pdict, dict_get_key_data(pde), pde->key.size); + pde = npde; + } #undef dict_get_key_data } @@ -249,10 +249,10 @@ bool pl_dict_undef(pl_dict_t *pdict, const byte *kdata, uint ksize) { pl_dict_entry_t **ppde = pl_dict_lookup_entry(pdict, kdata, ksize); - if ( !ppde ) - return false; - pl_dict_free(pdict, ppde, "pl_dict_undef"); - return true; + if ( !ppde ) + return false; + pl_dict_free(pdict, ppde, "pl_dict_undef"); + return true; } /* @@ -262,12 +262,12 @@ uint pl_dict_length(const pl_dict_t *pdict, bool with_stack) { uint count = pdict->entry_count; - if ( with_stack ) - { const pl_dict_t *pdcur; - for ( pdcur = pdict->parent; pdcur != 0; pdcur = pdcur->parent ) - count += pdcur->entry_count; - } - return count; + if ( with_stack ) + { const pl_dict_t *pdcur; + for ( pdcur = pdict->parent; pdcur != 0; pdcur = pdcur->parent ) + count += pdcur->entry_count; + } + return count; } /* @@ -278,27 +278,27 @@ void pl_dict_enum_stack_begin(const pl_dict_t *pdict, pl_dict_enum_t *penum, bool with_stack) { penum->pdict = pdict; - penum->next = 0; - penum->first = true; - penum->next_dict = (with_stack ? pdict->parent : 0); + penum->next = 0; + penum->first = true; + penum->next_dict = (with_stack ? pdict->parent : 0); } bool pl_dict_enum_next(pl_dict_enum_t *penum, gs_const_string *pkey, void **pvalue) { pl_dict_entry_t *pde; - while ( (pde = (penum->first ? penum->pdict->entries : penum->next)) == 0 ) - { if ( penum->next_dict == 0 ) - return false; - penum->next_dict = (penum->pdict = penum->next_dict)->parent; - penum->first = true; - } - pkey->data = entry_key_data(pde); - pkey->size = pde->key.size; - *pvalue = pde->value; - penum->next = pde->next; - penum->first = false; - return true; + while ( (pde = (penum->first ? penum->pdict->entries : penum->next)) == 0 ) + { if ( penum->next_dict == 0 ) + return false; + penum->next_dict = (penum->pdict = penum->next_dict)->parent; + penum->first = true; + } + pkey->data = entry_key_data(pde); + pkey->size = pde->key.size; + *pvalue = pde->value; + penum->next = pde->next; + penum->first = false; + return true; } /* @@ -307,5 +307,5 @@ pl_dict_enum_next(pl_dict_enum_t *penum, gs_const_string *pkey, void pl_dict_release(pl_dict_t *pdict) { while ( pdict->entries ) - pl_dict_free(pdict, &pdict->entries, "pl_dict_release"); + pl_dict_free(pdict, &pdict->entries, "pl_dict_release"); } diff --git a/pl/pldict.h b/pl/pldict.h index b18da8902..ef0be4b6a 100644 --- a/pl/pldict.h +++ b/pl/pldict.h @@ -84,7 +84,7 @@ bool pl_dict_lookup(pl_dict_t *pdict, const byte *kdata, uint ksize, int pl_dict_put(pl_dict_t *pdict, const byte *kdata, uint ksize, void *value); -/* +/* * When a dictionary entry is created, it can be designated as being a * synonym or alias of an existing entry, rather than having a value * of its own. All entries in a synonym group are equivalent: there @@ -153,7 +153,7 @@ bool pl_dict_enum_next(pl_dict_enum_t *penum, gs_const_string *pkey, */ void pl_dict_release(pl_dict_t *pdict); -/* +/* * Delete an entry that is a synonym or a canonical entry that has * related synonyms. The entire group of entries is deleted. Note * that this routine should be used in liueu of pl_dict_undef() if diff --git a/pl/pldraw.c b/pl/pldraw.c index b6408afb5..397dc401f 100644 --- a/pl/pldraw.c +++ b/pl/pldraw.c @@ -26,11 +26,11 @@ pl_begin_image(gs_state *pgs, const gs_image_t *pim, void **pinfo) { gx_device *dev = pgs->device; - if ( pim->ImageMask | pim->CombineWithColor ) - gx_set_dev_color(pgs); - return (*dev_proc(dev, begin_image)) - (dev, (const gs_imager_state *)pgs, pim, - gs_image_format_chunky, (const gs_int_rect *)0, - gs_currentdevicecolor_inline(pgs), pgs->clip_path, pgs->memory, - (gx_image_enum_common_t **)pinfo); + if ( pim->ImageMask | pim->CombineWithColor ) + gx_set_dev_color(pgs); + return (*dev_proc(dev, begin_image)) + (dev, (const gs_imager_state *)pgs, pim, + gs_image_format_chunky, (const gs_int_rect *)0, + gs_currentdevicecolor_inline(pgs), pgs->clip_path, pgs->memory, + (gx_image_enum_common_t **)pinfo); } diff --git a/pl/plfont.c b/pl/plfont.c index dd609acdf..b6373e9e9 100644 --- a/pl/plfont.c +++ b/pl/plfont.c @@ -47,32 +47,32 @@ private_st_pl_font(); void pl_free_font(gs_memory_t *mem, void *plf, client_name_t cname) { pl_font_t *plfont = plf; - /* Free the characters. */ + /* Free the characters. */ if ( !plfont->data_are_permanent ) - { if ( plfont->glyphs.table ) - { uint i; - for ( i = plfont->glyphs.size; i > 0; ) + { if ( plfont->glyphs.table ) + { uint i; + for ( i = plfont->glyphs.size; i > 0; ) { void *data = (void *)plfont->glyphs.table[--i].data; - if ( data ) - gs_free_object(mem, data, cname); - } - } - gs_free_object(mem, (void *)plfont->header, cname); - plfont->header = 0; /* see hack note above */ - } - /* Free the font data itself. */ - gs_free_object(mem, (void *)plfont->char_glyphs.table, cname); - gs_free_object(mem, (void *)plfont->glyphs.table, cname); - if ( plfont->pfont ) { /* might be only partially constructed */ + if ( data ) + gs_free_object(mem, data, cname); + } + } + gs_free_object(mem, (void *)plfont->header, cname); + plfont->header = 0; /* see hack note above */ + } + /* Free the font data itself. */ + gs_free_object(mem, (void *)plfont->char_glyphs.table, cname); + gs_free_object(mem, (void *)plfont->glyphs.table, cname); + if ( plfont->pfont ) { /* might be only partially constructed */ gs_purge_font_from_char_caches_completely(plfont->pfont); - gs_purge_font(plfont->pfont); - gs_free_object(mem, plfont->pfont, cname); - } - if ( plfont->font_file ) { - gs_free_object(mem, plfont->font_file, cname); - plfont->font_file = 0; - } - gs_free_object(mem, plf, cname); + gs_purge_font(plfont->pfont); + gs_free_object(mem, plfont->pfont, cname); + } + if ( plfont->font_file ) { + gs_free_object(mem, plfont->font_file, cname); + plfont->font_file = 0; + } + gs_free_object(mem, plf, cname); } /* ---------------- Library callbacks ---------------- */ @@ -342,7 +342,7 @@ extern ulong tt_find_table(gs_font_type42 *pfont, const char *tname, uint *plen) static int pl_glyph_name(gs_font *pfont, gs_glyph glyph, gs_const_string *pstr) -{ +{ uint table_length; ulong table_offset; /* guess if the font type is not truetype */ @@ -353,11 +353,11 @@ pl_glyph_name(gs_font *pfont, gs_glyph glyph, gs_const_string *pstr) pstr->size = strlen(pstr->data); return 0; } else { - dprintf1("glyph index %lx out of range\n", (ulong)glyph); - return -1; + dprintf1("glyph index %lx out of range\n", (ulong)glyph); + return -1; } } - + table_offset = tt_find_table((gs_font_type42 *)pfont, "post", &table_length); /* no post table */ if ( table_offset == 0 ) @@ -365,13 +365,13 @@ pl_glyph_name(gs_font *pfont, gs_glyph glyph, gs_const_string *pstr) /* this shoudn't happen but... */ if ( table_length == 0 ) return -1; - + { ulong format; uint numGlyphs; uint glyph_name_index; const byte *postp; /* post table pointer */ - + ((gs_font_type42 *)pfont)->data.string_proc((gs_font_type42 *)pfont, table_offset, table_length, &postp); format = u32(postp); @@ -395,7 +395,7 @@ pl_glyph_name(gs_font *pfont, gs_glyph glyph, gs_const_string *pstr) return -1; /* mac easy */ if ( glyph_name_index < 258 ) { - + pstr->data = pl_mac_names[glyph_name_index]; pstr->size = strlen(pstr->data); return 0; @@ -403,7 +403,7 @@ pl_glyph_name(gs_font *pfont, gs_glyph glyph, gs_const_string *pstr) } else { char *mydata; /* and here's the tricky part */ - const byte *pascal_stringp = + const byte *pascal_stringp = postp + 34 + (numGlyphs * 2); /* 0 - 257 lives in the mac table above */ glyph_name_index -= 258; @@ -441,7 +441,7 @@ extern gs_char last_char; /* Get the unicode valude for a glyph */ static gs_char pl_decode_glyph(gs_font *font, gs_glyph glyph, int ch) -{ +{ return last_char; } @@ -463,26 +463,26 @@ int pl_font_char_metrics(const pl_font_t *plfont, const void *pgs, uint char_cod pl_font_t * pl_alloc_font(gs_memory_t *mem, client_name_t cname) { pl_font_t *plfont = - gs_alloc_struct(mem, pl_font_t, &st_pl_font, cname); + gs_alloc_struct(mem, pl_font_t, &st_pl_font, cname); - if ( plfont ) - { /* Initialize pointers. */ - plfont->pfont = 0; - plfont->header = 0; - plfont->glyphs.table = 0; - plfont->char_glyphs.table = 0; - /* Initialize other defaults. */ - plfont->orient = 0; + if ( plfont ) + { /* Initialize pointers. */ + plfont->pfont = 0; + plfont->header = 0; + plfont->glyphs.table = 0; + plfont->char_glyphs.table = 0; + /* Initialize other defaults. */ + plfont->orient = 0; plfont->allow_vertical_substitutes = false; - plfont->bold_fraction = 0; - plfont->font_file = 0; - plfont->resolution.x = plfont->resolution.y = 0; - plfont->params.proportional_spacing = true; - memset(plfont->character_complement, 0xff, 8); - plfont->offsets.GC = plfont->offsets.GT = plfont->offsets.VT = -1; - plfont->pts_per_inch = 72.0; /* normal value */ - } - return plfont; + plfont->bold_fraction = 0; + plfont->font_file = 0; + plfont->resolution.x = plfont->resolution.y = 0; + plfont->params.proportional_spacing = true; + memset(plfont->character_complement, 0xff, 8); + plfont->offsets.GC = plfont->offsets.GT = plfont->offsets.VT = -1; + plfont->pts_per_inch = 72.0; /* normal value */ + } + return plfont; } /* import from plchar.c - used to determine if this is a downloaded true type font or a resident font - yuck. */ @@ -498,251 +498,251 @@ gs_private_st_element(st_pl_font_glyph_element_f, pl_font_glyph_t, pl_font_t * pl_clone_font(const pl_font_t *src, gs_memory_t *mem, client_name_t cname) { - pl_font_t *plfont = - gs_alloc_struct(mem, pl_font_t, &st_pl_font, cname); - if ( plfont == 0 ) - return 0; - /* copy technology common parts */ - plfont->storage = src->storage; - plfont->header_size = src->header_size; - plfont->scaling_technology = src->scaling_technology; + pl_font_t *plfont = + gs_alloc_struct(mem, pl_font_t, &st_pl_font, cname); + if ( plfont == 0 ) + return 0; + /* copy technology common parts */ + plfont->storage = src->storage; + plfont->header_size = src->header_size; + plfont->scaling_technology = src->scaling_technology; plfont->is_xl_format = src->is_xl_format; plfont->allow_vertical_substitutes = src->allow_vertical_substitutes; - plfont->font_type = src->font_type; - plfont->char_width = src->char_width; - plfont->char_metrics = src->char_metrics; - plfont->large_sizes = src->large_sizes; - plfont->resolution = src->resolution; - plfont->params = src->params; + plfont->font_type = src->font_type; + plfont->char_width = src->char_width; + plfont->char_metrics = src->char_metrics; + plfont->large_sizes = src->large_sizes; + plfont->resolution = src->resolution; + plfont->params = src->params; plfont->pts_per_inch = src->pts_per_inch; - plfont->font_file_loaded = src->font_file_loaded; - plfont->orient = src->orient; - plfont->bold_fraction = src->bold_fraction; - { - int i; - for (i = 0; i < sizeof(src->character_complement); i++ ) - plfont->character_complement[i] = src->character_complement[i]; - } - plfont->offsets = src->offsets; - plfont->header = gs_alloc_bytes(mem, src->header_size, cname); - if ( plfont->header == 0 ) - return 0; - memcpy(plfont->header, src->header, src->header_size); - - if ( src->font_file ) { - plfont->font_file = gs_alloc_bytes(mem, strlen(src->font_file) + 1, - "pl_clone_font"); - if ( plfont->font_file == 0 ) - return 0; /* #NB errors!!! */ - strcpy(plfont->font_file, src->font_file); - } - else - plfont->font_file = 0; - /* technology specific setup */ - switch ( plfont->scaling_technology ) - { - case plfst_bitmap: - { - gs_font_base *pfont = - gs_alloc_struct(mem, gs_font_base, &st_gs_font_base, cname); - if ( pfont == 0 ) - return 0; - pl_fill_in_font((gs_font *)pfont, plfont, src->pfont->dir, mem, "nameless_font"); - pl_fill_in_bitmap_font(pfont, gs_next_ids(mem, 1)); - break; - } - case plfst_Intellifont: - { - gs_font_base *pfont = - gs_alloc_struct(mem, gs_font_base, &st_gs_font_base, cname); - if ( pfont == 0 ) - return 0; - pl_fill_in_font((gs_font *)pfont, plfont, src->pfont->dir, mem, "nameless_font"); - pl_fill_in_intelli_font(pfont, gs_next_ids(mem, 1)); - break; - } - case plfst_TrueType: - { - { - gs_font_type42 *pfont = - gs_alloc_struct(mem, gs_font_type42, &st_gs_font_type42, cname); - /* detect if a truetype font is downloaded or + plfont->font_file_loaded = src->font_file_loaded; + plfont->orient = src->orient; + plfont->bold_fraction = src->bold_fraction; + { + int i; + for (i = 0; i < sizeof(src->character_complement); i++ ) + plfont->character_complement[i] = src->character_complement[i]; + } + plfont->offsets = src->offsets; + plfont->header = gs_alloc_bytes(mem, src->header_size, cname); + if ( plfont->header == 0 ) + return 0; + memcpy(plfont->header, src->header, src->header_size); + + if ( src->font_file ) { + plfont->font_file = gs_alloc_bytes(mem, strlen(src->font_file) + 1, + "pl_clone_font"); + if ( plfont->font_file == 0 ) + return 0; /* #NB errors!!! */ + strcpy(plfont->font_file, src->font_file); + } + else + plfont->font_file = 0; + /* technology specific setup */ + switch ( plfont->scaling_technology ) + { + case plfst_bitmap: + { + gs_font_base *pfont = + gs_alloc_struct(mem, gs_font_base, &st_gs_font_base, cname); + if ( pfont == 0 ) + return 0; + pl_fill_in_font((gs_font *)pfont, plfont, src->pfont->dir, mem, "nameless_font"); + pl_fill_in_bitmap_font(pfont, gs_next_ids(mem, 1)); + break; + } + case plfst_Intellifont: + { + gs_font_base *pfont = + gs_alloc_struct(mem, gs_font_base, &st_gs_font_base, cname); + if ( pfont == 0 ) + return 0; + pl_fill_in_font((gs_font *)pfont, plfont, src->pfont->dir, mem, "nameless_font"); + pl_fill_in_intelli_font(pfont, gs_next_ids(mem, 1)); + break; + } + case plfst_TrueType: + { + { + gs_font_type42 *pfont = + gs_alloc_struct(mem, gs_font_type42, &st_gs_font_type42, cname); + /* detect if a truetype font is downloaded or internal. There must be a better way... */ - gs_font_type42 *pfont_src = (gs_font_type42 *)src->pfont; - bool downloaded = (pfont_src->data.get_outline == pl_tt_get_outline); - if ( pfont == 0 ) - return 0; - pl_fill_in_font((gs_font *)pfont, plfont, src->pfont->dir, mem, "nameless_font"); - pl_fill_in_tt_font(pfont, downloaded ? NULL : src->header, gs_next_ids(mem, 1)); - } - break; - } + gs_font_type42 *pfont_src = (gs_font_type42 *)src->pfont; + bool downloaded = (pfont_src->data.get_outline == pl_tt_get_outline); + if ( pfont == 0 ) + return 0; + pl_fill_in_font((gs_font *)pfont, plfont, src->pfont->dir, mem, "nameless_font"); + pl_fill_in_tt_font(pfont, downloaded ? NULL : src->header, gs_next_ids(mem, 1)); + } + break; + } default: return 0; - } - if ( src->char_glyphs.table != 0 ) - { - /* HAS may gs_alloc_struct_array() here but this is - consistant with pl_tt_alloc_char_glyphs() */ - pl_tt_char_glyph_t *char_glyphs = - (pl_tt_char_glyph_t *) gs_alloc_byte_array(mem, - src->char_glyphs.size, - sizeof(pl_tt_char_glyph_t), cname); - int i; - if ( char_glyphs == 0 ) - return 0; - for ( i = 0; i < src->char_glyphs.size; i++ ) - char_glyphs[i] = src->char_glyphs.table[i]; - /* once again a copy struct shortcut and then are restore + } + if ( src->char_glyphs.table != 0 ) + { + /* HAS may gs_alloc_struct_array() here but this is + consistant with pl_tt_alloc_char_glyphs() */ + pl_tt_char_glyph_t *char_glyphs = + (pl_tt_char_glyph_t *) gs_alloc_byte_array(mem, + src->char_glyphs.size, + sizeof(pl_tt_char_glyph_t), cname); + int i; + if ( char_glyphs == 0 ) + return 0; + for ( i = 0; i < src->char_glyphs.size; i++ ) + char_glyphs[i] = src->char_glyphs.table[i]; + /* once again a copy struct shortcut and then are restore of the char_glyphs.table pointer */ - plfont->char_glyphs = src->char_glyphs; - plfont->char_glyphs.table = char_glyphs; - } - else /* no character glyph table data */ - plfont->char_glyphs = src->char_glyphs; + plfont->char_glyphs = src->char_glyphs; + plfont->char_glyphs.table = char_glyphs; + } + else /* no character glyph table data */ + plfont->char_glyphs = src->char_glyphs; - if ( src->glyphs.table != 0 ) - { - int i; - plfont->glyphs.table = - gs_alloc_struct_array(mem, src->glyphs.size, pl_font_glyph_t, - &st_pl_font_glyph_element_f, cname); - plfont->glyphs.used = src->glyphs.used; - plfont->glyphs.limit = src->glyphs.limit; - plfont->glyphs.size = src->glyphs.size; - plfont->glyphs.skip = src->glyphs.skip; - for ( i = 0; i < src->glyphs.size; i++ ) - { - const byte *data = src->glyphs.table[i].data; - byte *char_data; - plfont->glyphs.table[i].glyph = - src->glyphs.table[i].glyph; - plfont->glyphs.table[i].data = 0; - if ( data ) - { /* ARGH --- */ - uint size; - if ( plfont->scaling_technology == plfst_bitmap ) - { - size = 16 + - ((pl_get_uint16(data + 10) + 7) >> 3) * - pl_get_uint16(data + 12); - } - else if ( plfont->scaling_technology == plfst_Intellifont ) { - /* non compound characters */ - if ( data[3] == 3 ) - size = 6 + pl_get_uint16(data + 4); - else /* assume data[3] == 4 (compound) */ - size = 8 + data[6] * 6 + 2; - } - else /* truetype */ - size = 2 + 2 + data[2] + - pl_get_uint16(data + 2 + data[2]); - char_data = gs_alloc_bytes(mem, size, cname); - if ( char_data == 0 ) - return 0; - memcpy(char_data, data, size); - plfont->glyphs.table[i].data = char_data; - } + if ( src->glyphs.table != 0 ) + { + int i; + plfont->glyphs.table = + gs_alloc_struct_array(mem, src->glyphs.size, pl_font_glyph_t, + &st_pl_font_glyph_element_f, cname); + plfont->glyphs.used = src->glyphs.used; + plfont->glyphs.limit = src->glyphs.limit; + plfont->glyphs.size = src->glyphs.size; + plfont->glyphs.skip = src->glyphs.skip; + for ( i = 0; i < src->glyphs.size; i++ ) + { + const byte *data = src->glyphs.table[i].data; + byte *char_data; + plfont->glyphs.table[i].glyph = + src->glyphs.table[i].glyph; + plfont->glyphs.table[i].data = 0; + if ( data ) + { /* ARGH --- */ + uint size; + if ( plfont->scaling_technology == plfst_bitmap ) + { + size = 16 + + ((pl_get_uint16(data + 10) + 7) >> 3) * + pl_get_uint16(data + 12); + } + else if ( plfont->scaling_technology == plfst_Intellifont ) { + /* non compound characters */ + if ( data[3] == 3 ) + size = 6 + pl_get_uint16(data + 4); + else /* assume data[3] == 4 (compound) */ + size = 8 + data[6] * 6 + 2; + } + else /* truetype */ + size = 2 + 2 + data[2] + + pl_get_uint16(data + 2 + data[2]); + char_data = gs_alloc_bytes(mem, size, cname); + if ( char_data == 0 ) + return 0; + memcpy(char_data, data, size); + plfont->glyphs.table[i].data = char_data; + } - } - } - else /* no glyph table */ - plfont->glyphs = src->glyphs; - return plfont; + } + } + else /* no glyph table */ + plfont->glyphs = src->glyphs; + return plfont; } - + /* Fill in generic font boilerplate. NB TODO examine duplication with gs_font_alloc() */ int pl_fill_in_font(gs_font *pfont, pl_font_t *plfont, gs_font_dir *pdir, gs_memory_t *mem, const char *font_name) -{ +{ int i; - plfont->pfont = pfont; - /* Initialize generic font data. */ + plfont->pfont = pfont; + /* Initialize generic font data. */ gs_make_identity(&pfont->orig_FontMatrix); - pfont->next = pfont->prev = 0; - pfont->memory = mem; - pfont->dir = pdir; - pfont->is_resource = false; - gs_notify_init(&pfont->notify_list, gs_memory_stable(mem)); - pfont->base = pfont; - pfont->client_data = plfont; - pfont->WMode = 0; - pfont->PaintType = 0; - pfont->StrokeWidth = 0; + pfont->next = pfont->prev = 0; + pfont->memory = mem; + pfont->dir = pdir; + pfont->is_resource = false; + gs_notify_init(&pfont->notify_list, gs_memory_stable(mem)); + pfont->base = pfont; + pfont->client_data = plfont; + pfont->WMode = 0; + pfont->PaintType = 0; + pfont->StrokeWidth = 0; pfont->is_cached = 0; - pfont->procs.init_fstack = gs_default_init_fstack; - pfont->procs.next_char_glyph = gs_default_next_char_glyph; + pfont->procs.init_fstack = gs_default_init_fstack; + pfont->procs.next_char_glyph = gs_default_next_char_glyph; - pfont->procs.glyph_name = pl_glyph_name; - pfont->procs.decode_glyph = pl_decode_glyph; - /* NB pfont->procs.callbacks.known_encode = pl_known_encode; */ - pfont->procs.define_font = gs_no_define_font; - pfont->procs.make_font = gs_no_make_font; - pfont->procs.font_info = gs_default_font_info; + pfont->procs.glyph_name = pl_glyph_name; + pfont->procs.decode_glyph = pl_decode_glyph; + /* NB pfont->procs.callbacks.known_encode = pl_known_encode; */ + pfont->procs.define_font = gs_no_define_font; + pfont->procs.make_font = gs_no_make_font; + pfont->procs.font_info = gs_default_font_info; pfont->procs.glyph_info = gs_default_glyph_info; pfont->procs.glyph_outline = gs_no_glyph_outline; - pfont->id = gs_next_ids(mem, 1); - pfont->font_name.size = strlen(font_name); - strncpy(pfont->font_name.chars, font_name, pfont->font_name.size); - /* replace spaces with '-', seems acrobat doesn't like spaces. */ - for (i = 0; i < pfont->font_name.size; i++) { - if (pfont->font_name.chars[i] == ' ') - pfont->font_name.chars[i] = '-'; - } - strncpy(pfont->key_name.chars, font_name, sizeof(pfont->font_name.chars)); - pfont->key_name.size = strlen(font_name); - return 0; + pfont->id = gs_next_ids(mem, 1); + pfont->font_name.size = strlen(font_name); + strncpy(pfont->font_name.chars, font_name, pfont->font_name.size); + /* replace spaces with '-', seems acrobat doesn't like spaces. */ + for (i = 0; i < pfont->font_name.size; i++) { + if (pfont->font_name.chars[i] == ' ') + pfont->font_name.chars[i] = '-'; + } + strncpy(pfont->key_name.chars, font_name, sizeof(pfont->font_name.chars)); + pfont->key_name.size = strlen(font_name); + return 0; } /* Fill in bitmap font boilerplate. */ void pl_fill_in_bitmap_font(gs_font_base *pfont, long unique_id) { pfont->FontType = ft_user_defined; - pfont->BitmapWidths = true; - pfont->ExactSize = fbit_use_bitmaps; - pfont->InBetweenSize = fbit_use_bitmaps; - pfont->TransformedChar = fbit_transform_bitmaps; - pl_bitmap_init_procs(pfont); - /* We have no idea what the FontBBox should be. */ - pfont->FontBBox.p.x = pfont->FontBBox.p.y = - pfont->FontBBox.q.x = pfont->FontBBox.q.y = 0; - uid_set_UniqueID(&pfont->UID, unique_id); - pfont->encoding_index = 1; /****** WRONG ******/ - pfont->nearest_encoding_index = 1; /****** WRONG ******/ + pfont->BitmapWidths = true; + pfont->ExactSize = fbit_use_bitmaps; + pfont->InBetweenSize = fbit_use_bitmaps; + pfont->TransformedChar = fbit_transform_bitmaps; + pl_bitmap_init_procs(pfont); + /* We have no idea what the FontBBox should be. */ + pfont->FontBBox.p.x = pfont->FontBBox.p.y = + pfont->FontBBox.q.x = pfont->FontBBox.q.y = 0; + uid_set_UniqueID(&pfont->UID, unique_id); + pfont->encoding_index = 1; /****** WRONG ******/ + pfont->nearest_encoding_index = 1; /****** WRONG ******/ } /* Fill in TrueType font boilerplate. */ int pl_fill_in_tt_font(gs_font_type42 *pfont, void *data, long unique_id) { pfont->FontType = ft_TrueType; - pfont->BitmapWidths = true; - pfont->ExactSize = fbit_use_outlines; - pfont->InBetweenSize = fbit_use_outlines; - pfont->TransformedChar = fbit_use_outlines; - /* Initialize base font data. */ - /* - * We can't set the FontBBox correctly until we've initialized the - * Type 42 specific data, but we need to set it to an empty box now - * for the sake of gs_type42_font_init. - */ - pfont->FontBBox.p.x = pfont->FontBBox.p.y = - pfont->FontBBox.q.x = pfont->FontBBox.q.y = 0; - uid_set_UniqueID(&pfont->UID, unique_id); - pfont->encoding_index = 1; /****** WRONG ******/ - pfont->nearest_encoding_index = 1; /****** WRONG ******/ - /* Initialize Type 42 specific data. */ - pfont->data.proc_data = data; - pl_tt_init_procs(pfont); + pfont->BitmapWidths = true; + pfont->ExactSize = fbit_use_outlines; + pfont->InBetweenSize = fbit_use_outlines; + pfont->TransformedChar = fbit_use_outlines; + /* Initialize base font data. */ + /* + * We can't set the FontBBox correctly until we've initialized the + * Type 42 specific data, but we need to set it to an empty box now + * for the sake of gs_type42_font_init. + */ + pfont->FontBBox.p.x = pfont->FontBBox.p.y = + pfont->FontBBox.q.x = pfont->FontBBox.q.y = 0; + uid_set_UniqueID(&pfont->UID, unique_id); + pfont->encoding_index = 1; /****** WRONG ******/ + pfont->nearest_encoding_index = 1; /****** WRONG ******/ + /* Initialize Type 42 specific data. */ + pfont->data.proc_data = data; + pl_tt_init_procs(pfont); { int code = gs_type42_font_init(pfont, 0); if (code < 0) return code; } - /* disable unused FAPI */ - pfont->FAPI = 0; - pfont->FAPI_font_data = 0; - pl_tt_finish_init(pfont, !data); + /* disable unused FAPI */ + pfont->FAPI = 0; + pfont->FAPI_font_data = 0; + pl_tt_finish_init(pfont, !data); return 0; } @@ -750,22 +750,22 @@ pl_fill_in_tt_font(gs_font_type42 *pfont, void *data, long unique_id) void pl_fill_in_intelli_font(gs_font_base *pfont, long unique_id) { /* Intellifonts have an 8782-unit design space. */ - { gs_matrix mat; - gs_make_scaling(1.0/8782, 1.0/8782, &mat); - gs_matrix_translate(&mat, -2980.0, -5380.0, &pfont->orig_FontMatrix); - } - pfont->FontType = ft_MicroType; - pfont->BitmapWidths = true; - pfont->ExactSize = fbit_use_outlines; - pfont->InBetweenSize = fbit_use_outlines; - pfont->TransformedChar = fbit_use_outlines; - /* We have no idea what the FontBBox should be. */ - pfont->FontBBox.p.x = pfont->FontBBox.p.y = - pfont->FontBBox.q.x = pfont->FontBBox.q.y = 0; - uid_set_UniqueID(&pfont->UID, unique_id); - pfont->encoding_index = 1; /****** WRONG ******/ - pfont->nearest_encoding_index = 1; /****** WRONG ******/ - pl_intelli_init_procs(pfont); + { gs_matrix mat; + gs_make_scaling(1.0/8782, 1.0/8782, &mat); + gs_matrix_translate(&mat, -2980.0, -5380.0, &pfont->orig_FontMatrix); + } + pfont->FontType = ft_MicroType; + pfont->BitmapWidths = true; + pfont->ExactSize = fbit_use_outlines; + pfont->InBetweenSize = fbit_use_outlines; + pfont->TransformedChar = fbit_use_outlines; + /* We have no idea what the FontBBox should be. */ + pfont->FontBBox.p.x = pfont->FontBBox.p.y = + pfont->FontBBox.q.x = pfont->FontBBox.q.y = 0; + uid_set_UniqueID(&pfont->UID, unique_id); + pfont->encoding_index = 1; /****** WRONG ******/ + pfont->nearest_encoding_index = 1; /****** WRONG ******/ + pl_intelli_init_procs(pfont); } /* @@ -779,139 +779,139 @@ pl_fill_in_intelli_font(gs_font_base *pfont, long unique_id) */ int pl_font_scan_segments(const gs_memory_t *mem, - pl_font_t *plfont, int fst_offset, int start_offset, + pl_font_t *plfont, int fst_offset, int start_offset, long end_offset, bool large_sizes, const pl_font_offset_errors_t *pfoe) { const byte *header = plfont->header; - pl_font_scaling_technology_t fst = header[fst_offset]; - int wsize = (large_sizes ? 4 : 2); - const byte *segment = header + start_offset; - const byte *end = header + end_offset; - const byte *null_segment = end - (2 + wsize); - bool found = false; - ulong seg_size; - int illegal_font_data = pfoe->illegal_font_data; + pl_font_scaling_technology_t fst = header[fst_offset]; + int wsize = (large_sizes ? 4 : 2); + const byte *segment = header + start_offset; + const byte *end = header + end_offset; + const byte *null_segment = end - (2 + wsize); + bool found = false; + ulong seg_size; + int illegal_font_data = pfoe->illegal_font_data; #define return_scan_error(err)\ return_error((err) ? (err) : illegal_font_data); - if ( memcmp(null_segment, "\377\377", 2) /* NULL segment header */ ) - return_scan_error(pfoe->missing_required_segment); - if ( memcmp(null_segment + 2, "\0\0\0\0", wsize) /* NULL segment size */ ) - return_scan_error(pfoe->illegal_null_segment_size); - switch ( fst ) - { - case plfst_bitmap: - case plfst_TrueType: - break; - default: - return_scan_error(pfoe->illegal_font_header_fields); - } - if ( header[fst_offset + 1] ) /* variety, must be 0 */ - return_scan_error(pfoe->illegal_font_header_fields); - /* Scan the segments. */ - for ( ; end - segment >= 2 + wsize; segment += 2 + wsize + seg_size ) - { uint seg_id = u16(segment); - const byte *sdata = segment + 2 + wsize; + if ( memcmp(null_segment, "\377\377", 2) /* NULL segment header */ ) + return_scan_error(pfoe->missing_required_segment); + if ( memcmp(null_segment + 2, "\0\0\0\0", wsize) /* NULL segment size */ ) + return_scan_error(pfoe->illegal_null_segment_size); + switch ( fst ) + { + case plfst_bitmap: + case plfst_TrueType: + break; + default: + return_scan_error(pfoe->illegal_font_header_fields); + } + if ( header[fst_offset + 1] ) /* variety, must be 0 */ + return_scan_error(pfoe->illegal_font_header_fields); + /* Scan the segments. */ + for ( ; end - segment >= 2 + wsize; segment += 2 + wsize + seg_size ) + { uint seg_id = u16(segment); + const byte *sdata = segment + 2 + wsize; #define id2(c1,c2) (((uint)(c1) << 8) + (c2)) - seg_size = (large_sizes ? u32(segment + 2) : u16(segment + 2)); - if ( seg_size + 2 + wsize > end - segment ) - return_error(illegal_font_data); - /* Handle segments common to all fonts. */ - switch ( seg_id ) - { - case 0xffff: /* NULL segment ID */ - if ( segment != null_segment ) - return_error(illegal_font_data); - continue; - case id2('V','I'): - continue; - case id2('C', 'C'): - if ( seg_size != 8 ) - return_error(illegal_font_data); - memcpy(plfont->character_complement, sdata, 8); - continue; - default: - ; - } - /* Handle segments specific to the scaling technology. */ - if ( fst == plfst_bitmap ) - switch ( seg_id ) - { - case id2('B','R'): - if ( seg_size != 4 ) - return_scan_error(pfoe->illegal_BR_segment); - { uint xres = pl_get_uint16(sdata); - uint yres = pl_get_uint16(sdata + 2); - if ( xres == 0 || yres == 0 ) - return_scan_error(pfoe->illegal_BR_segment); - plfont->resolution.x = xres; - plfont->resolution.y = yres; - } - found = true; - break; - default: - if ( pfoe->illegal_font_segment < 0 ) - return_error(pfoe->illegal_font_segment); - } - else /* fst == plfst_TrueType */ - switch ( seg_id ) - { - case id2('G','T'): - /* - * We don't do much checking here, but we do check that - * the segment starts with a table directory that - * includes at least 3 elements (gdir, head, - * maxp -- but we don't check the actual names). - */ - if ( seg_size < 12 + 5 * 16 || - /* memcmp(sdata, "\000\001\000\000", 4) || */ - u16(sdata + 4) < 3 - ) - return_scan_error(pfoe->illegal_GT_segment); - plfont->offsets.GT = segment - header; - found = true; - break; - case id2('G','C'): - if ( seg_size < 6 || u16(sdata) != 0 || - seg_size != u16(sdata + 4) * 6 + 6 - ) - return_scan_error(pfoe->illegal_GC_segment); - plfont->offsets.GC = segment - header; - break; - case id2('V','T'): - /* Check for end of table mark */ - if ( (seg_size & 3) != 0 || seg_size < 4 || - u16(sdata + seg_size - 4) != 0xffff - ) - return_scan_error(pfoe->illegal_VT_segment); - /* Check for table sorted by horizontal glyph ID */ - { uint i; - for ( i = 0; i < seg_size - 4; i += 4 ) - if ( u16(sdata + i) > u16(sdata + i + 4) ) - return_scan_error(pfoe->illegal_VT_segment); - } - plfont->offsets.VT = segment - header; - break; + seg_size = (large_sizes ? u32(segment + 2) : u16(segment + 2)); + if ( seg_size + 2 + wsize > end - segment ) + return_error(illegal_font_data); + /* Handle segments common to all fonts. */ + switch ( seg_id ) + { + case 0xffff: /* NULL segment ID */ + if ( segment != null_segment ) + return_error(illegal_font_data); + continue; + case id2('V','I'): + continue; + case id2('C', 'C'): + if ( seg_size != 8 ) + return_error(illegal_font_data); + memcpy(plfont->character_complement, sdata, 8); + continue; + default: + ; + } + /* Handle segments specific to the scaling technology. */ + if ( fst == plfst_bitmap ) + switch ( seg_id ) + { + case id2('B','R'): + if ( seg_size != 4 ) + return_scan_error(pfoe->illegal_BR_segment); + { uint xres = pl_get_uint16(sdata); + uint yres = pl_get_uint16(sdata + 2); + if ( xres == 0 || yres == 0 ) + return_scan_error(pfoe->illegal_BR_segment); + plfont->resolution.x = xres; + plfont->resolution.y = yres; + } + found = true; + break; + default: + if ( pfoe->illegal_font_segment < 0 ) + return_error(pfoe->illegal_font_segment); + } + else /* fst == plfst_TrueType */ + switch ( seg_id ) + { + case id2('G','T'): + /* + * We don't do much checking here, but we do check that + * the segment starts with a table directory that + * includes at least 3 elements (gdir, head, + * maxp -- but we don't check the actual names). + */ + if ( seg_size < 12 + 5 * 16 || + /* memcmp(sdata, "\000\001\000\000", 4) || */ + u16(sdata + 4) < 3 + ) + return_scan_error(pfoe->illegal_GT_segment); + plfont->offsets.GT = segment - header; + found = true; + break; + case id2('G','C'): + if ( seg_size < 6 || u16(sdata) != 0 || + seg_size != u16(sdata + 4) * 6 + 6 + ) + return_scan_error(pfoe->illegal_GC_segment); + plfont->offsets.GC = segment - header; + break; + case id2('V','T'): + /* Check for end of table mark */ + if ( (seg_size & 3) != 0 || seg_size < 4 || + u16(sdata + seg_size - 4) != 0xffff + ) + return_scan_error(pfoe->illegal_VT_segment); + /* Check for table sorted by horizontal glyph ID */ + { uint i; + for ( i = 0; i < seg_size - 4; i += 4 ) + if ( u16(sdata + i) > u16(sdata + i + 4) ) + return_scan_error(pfoe->illegal_VT_segment); + } + plfont->offsets.VT = segment - header; + break; case id2('V', 'E'): /* nb unimplemented */ break; case id2('V', 'R'): /* nb unimplemented */ break; case id2('C', 'E'): /* nb unimplemented */ break; - default: - if ( pfoe->illegal_font_segment < 0 ) - return_error(pfoe->illegal_font_segment); - } + default: + if ( pfoe->illegal_font_segment < 0 ) + return_error(pfoe->illegal_font_segment); + } #undef id2 - } - if ( !found ) - return_scan_error(pfoe->missing_required_segment); - if ( segment != end ) - return_error(illegal_font_data); - plfont->large_sizes = large_sizes; - plfont->scaling_technology = fst; - return 0; + } + if ( !found ) + return_scan_error(pfoe->missing_required_segment); + if ( segment != end ) + return_error(illegal_font_data); + plfont->large_sizes = large_sizes; + plfont->scaling_technology = fst; + return 0; #undef return_scan_error } @@ -922,25 +922,25 @@ pl_free_tt_fontfile_buffer(gs_memory_t *mem, byte *ptt_font_data) return 0; } -int +int pl_alloc_tt_fontfile_buffer(stream *in, gs_memory_t *mem, byte **pptt_font_data, ulong *size) { ulong len = (sfseek(in, 0L, SEEK_END), sftell(in)); *size = 6 + len; /* leave room for segment header */ - if ( *size != (uint)(*size) ) { - /* - * The font is too big to load in a single piece -- punt. - * The error message is bogus, but there isn't any more - * appropriate one. - */ - sfclose(in); - return_error(gs_error_VMerror); + if ( *size != (uint)(*size) ) { + /* + * The font is too big to load in a single piece -- punt. + * The error message is bogus, but there isn't any more + * appropriate one. + */ + sfclose(in); + return_error(gs_error_VMerror); } srewind(in); *pptt_font_data = gs_alloc_bytes(mem, *size, "pl_tt_load_font data"); if ( *pptt_font_data == 0 ) { - sfclose(in); - return_error(gs_error_VMerror); + sfclose(in); + return_error(gs_error_VMerror); } sfread(*pptt_font_data + 6, 1, len, in); sfclose(in); @@ -951,7 +951,7 @@ pl_alloc_tt_fontfile_buffer(stream *in, gs_memory_t *mem, byte **pptt_font_data, int pl_load_tt_font(stream *in, gs_font_dir *pdir, gs_memory_t *mem, long unique_id, pl_font_t **pplfont, char *font_name) -{ +{ byte *tt_font_datap; ulong size; int code; @@ -960,33 +960,33 @@ pl_load_tt_font(stream *in, gs_font_dir *pdir, gs_memory_t *mem, /* get the data from the file */ code = pl_alloc_tt_fontfile_buffer(in, mem, &tt_font_datap, &size); if ( code < 0 ) - return_error(gs_error_VMerror); + return_error(gs_error_VMerror); /* Make a Type 42 font out of the TrueType data. */ pfont = gs_alloc_struct(mem, gs_font_type42, &st_gs_font_type42, - "pl_tt_load_font(gs_font_type42)"); + "pl_tt_load_font(gs_font_type42)"); plfont = pl_alloc_font(mem, "pl_tt_load_font(pl_font_t)"); if ( pfont == 0 || plfont == 0 ) - code = gs_note_error(gs_error_VMerror); + code = gs_note_error(gs_error_VMerror); else { /* Initialize general font boilerplate. */ - code = pl_fill_in_font((gs_font *)pfont, plfont, pdir, mem, font_name); - if ( code >= 0 ) { /* Initialize TrueType font boilerplate. */ - plfont->header = tt_font_datap; - plfont->header_size = size; - plfont->scaling_technology = plfst_TrueType; - plfont->font_type = plft_Unicode; - plfont->large_sizes = true; - plfont->offsets.GT = 0; + code = pl_fill_in_font((gs_font *)pfont, plfont, pdir, mem, font_name); + if ( code >= 0 ) { /* Initialize TrueType font boilerplate. */ + plfont->header = tt_font_datap; + plfont->header_size = size; + plfont->scaling_technology = plfst_TrueType; + plfont->font_type = plft_Unicode; + plfont->large_sizes = true; + plfont->offsets.GT = 0; plfont->is_xl_format = false; - pl_fill_in_tt_font(pfont, tt_font_datap, unique_id); - code = gs_definefont(pdir, (gs_font *)pfont); - } + pl_fill_in_tt_font(pfont, tt_font_datap, unique_id); + code = gs_definefont(pdir, (gs_font *)pfont); + } } - if ( code < 0 ) { - gs_free_object(mem, plfont, "pl_tt_load_font(pl_font_t)"); - gs_free_object(mem, pfont, "pl_tt_load_font(gs_font_type42)"); - pl_free_tt_fontfile_buffer(mem, tt_font_datap); - return code; + if ( code < 0 ) { + gs_free_object(mem, plfont, "pl_tt_load_font(pl_font_t)"); + gs_free_object(mem, pfont, "pl_tt_load_font(gs_font_type42)"); + pl_free_tt_fontfile_buffer(mem, tt_font_datap); + return code; } *pplfont = plfont; return 0; @@ -1000,33 +1000,33 @@ pl_load_resident_font_data_from_file(gs_memory_t *mem, pl_font_t *plfont) ulong len, size; byte *data; if (plfont->font_file && !plfont->font_file_loaded) { - stream *in = sfopen(plfont->font_file, gp_fmode_rb, mem); - if ( in == NULL ) - return -1; - /* note this is exactly the same as the code in pl_load_tt_font */ - len = (sfseek(in, 0L, SEEK_END), sftell(in)); - size = 6 + len; /* leave room for segment header */ + stream *in = sfopen(plfont->font_file, gp_fmode_rb, mem); + if ( in == NULL ) + return -1; + /* note this is exactly the same as the code in pl_load_tt_font */ + len = (sfseek(in, 0L, SEEK_END), sftell(in)); + size = 6 + len; /* leave room for segment header */ - if ( size != (uint)size ) { - /* - * The font is too big to load in a single piece -- punt. - * The error message is bogus, but there isn't any more - * appropriate one. - */ - sfclose(in); - return_error(gs_error_VMerror); - } - srewind(in); - data = gs_alloc_bytes(mem, size, "pl_tt_load_font data"); - if ( data == 0 ) { - sfclose(in); - return_error(gs_error_VMerror); - } - sfread(data + 6, 1, len, in); - sfclose(in); - plfont->header = data; - plfont->header_size = size; - plfont->font_file_loaded = true; + if ( size != (uint)size ) { + /* + * The font is too big to load in a single piece -- punt. + * The error message is bogus, but there isn't any more + * appropriate one. + */ + sfclose(in); + return_error(gs_error_VMerror); + } + srewind(in); + data = gs_alloc_bytes(mem, size, "pl_tt_load_font data"); + if ( data == 0 ) { + sfclose(in); + return_error(gs_error_VMerror); + } + sfread(data + 6, 1, len, in); + sfclose(in); + plfont->header = data; + plfont->header_size = size; + plfont->font_file_loaded = true; } return 0; } @@ -1037,20 +1037,20 @@ pl_store_resident_font_data_in_file(char *font_file, gs_memory_t *mem, pl_font_t { /* Free the header data */ if ( plfont->header ) { - gs_free_object(mem, plfont->header, "pl_store_resident_font_data_in_file"); - plfont->header = 0; - plfont->header_size = 0; + gs_free_object(mem, plfont->header, "pl_store_resident_font_data_in_file"); + plfont->header = 0; + plfont->header_size = 0; } else { - /* nothing to do */ - return 0; + /* nothing to do */ + return 0; } /* we don't yet have a filename for this font object. create one and store it in the font. */ if ( !plfont->font_file ) { - plfont->font_file = gs_alloc_bytes(mem, strlen(font_file) + 1, "pl_store_resident_font_data_in_file"); - if ( plfont->font_file == 0 ) - return -1; - strcpy(plfont->font_file, font_file); + plfont->font_file = gs_alloc_bytes(mem, strlen(font_file) + 1, "pl_store_resident_font_data_in_file"); + if ( plfont->font_file == 0 ) + return -1; + strcpy(plfont->font_file, font_file); } /* designate that the font data is not in RAM */ plfont->font_file_loaded = false; diff --git a/pl/plfont.h b/pl/plfont.h index 94933adb7..70e8387fe 100644 --- a/pl/plfont.h +++ b/pl/plfont.h @@ -150,13 +150,13 @@ struct pl_font_s { int storage; /* where the font is stored */ bool data_are_permanent; /* glyph data stored in rom */ char *font_file; /* non null only if data is stored in a - file only relevant to pcl resident - fonts. NB this should be done - dynamically */ + file only relevant to pcl resident + fonts. NB this should be done + dynamically */ bool font_file_loaded; /* contents of the font file have be read into memory */ byte *header; /* downloaded header, or built-in font data */ ulong header_size; - /* Information extracted from the font or supplied by the client. */ + /* Information extracted from the font or supplied by the client. */ pl_font_scaling_technology_t scaling_technology; bool is_xl_format; /* this is required for the agfa ufst scaler */ pl_font_type_t font_type; @@ -165,7 +165,7 @@ struct pl_font_s { int (*char_width)(const pl_font_t *plfont, const void *pgs, uint char_code, gs_point *pwidth); int (*char_metrics)(const pl_font_t *plfont, const void *pgs, uint char_code, float metrics[4]); bool large_sizes; /* segment sizes are 32 bits if true, 16 if false */ - /* (for segmented fonts only) */ + /* (for segmented fonts only) */ struct { uint x, y; } resolution; /* resolution (for bitmap fonts) */ float bold_fraction; /* for PXL algorithmic bolding */ int orient; /* true if pcl bitmap font designed in landscape */ @@ -176,9 +176,9 @@ struct pl_font_s { long GT; /* Global TrueType data (required, for TT fonts) */ long VT; /* VerTical substitution (optional) */ } offsets; /* segment offsets, -1 if segment missing */ - /* Glyph table for downloaded fonts. */ + /* Glyph table for downloaded fonts. */ pl_glyph_table_t glyphs; - /* Character to glyph map for downloaded TrueType fonts. */ + /* Character to glyph map for downloaded TrueType fonts. */ pl_tt_char_glyph_table_t char_glyphs; float pts_per_inch; /* either 72 or 72.307 (for Intellifont) */ @@ -207,7 +207,7 @@ int pl_tt_alloc_char_glyphs(pl_font_t *plfont, uint num_chars, /* Fill in generic gs_font boilerplate. */ #ifndef gs_font_dir_DEFINED -# define gs_font_dir_DEFINED +# define gs_font_dir_DEFINED typedef struct gs_font_dir_s gs_font_dir; #endif int pl_fill_in_font(gs_font *pfont, pl_font_t *plfont, gs_font_dir *pdir, @@ -259,8 +259,8 @@ typedef struct pl_font_offset_errors_s { int illegal_VT_segment; int illegal_BR_segment; } pl_font_offset_errors_t; -int pl_font_scan_segments(const gs_memory_t *mem, - pl_font_t *plfont, int fst_offset, +int pl_font_scan_segments(const gs_memory_t *mem, + pl_font_t *plfont, int fst_offset, int start_offset, long end_offset, bool large_sizes, const pl_font_offset_errors_t *pfoe); @@ -273,7 +273,6 @@ int pl_load_tt_font(stream *in, gs_font_dir *pdir, gs_memory_t *mem, int pl_alloc_tt_fontfile_buffer(stream *in, gs_memory_t *mem, byte **pptt_font_data, ulong *size); int pl_free_tt_fontfile_buffer(gs_memory_t *mem, byte *ptt_font_data); - /* Add a glyph to a font. Return -1 if the table is full. */ int pl_font_add_glyph(pl_font_t *plfont, gs_glyph glyph, const byte *data); @@ -288,7 +287,6 @@ int pl_font_char_width(const pl_font_t *plfont, const void *pgs, uint char_code, lsb and metrics 2 = width. The same rules for character width apply */ int pl_font_char_metrics(const pl_font_t *plfont, const void *pgs, uint char_code, float metrics[4]); - /* Look up a glyph in a font. Return a pointer to the glyph's slot */ /* (data != 0) or where it should be added (data == 0). */ pl_font_glyph_t *pl_font_lookup_glyph(const pl_font_t *plfont, diff --git a/pl/plftable.c b/pl/plftable.c index f180030ba..db7737480 100644 --- a/pl/plftable.c +++ b/pl/plftable.c @@ -38,15 +38,14 @@ #define fontnames(agfascreenfontname, agfaname, urwname) urwname #endif - const font_resident_t resident_table[] = { #define C(b) ((byte)((b) ^ 0xff)) #define cc_alphabetic\ - { C(0), C(0), C(0), C(0), C(0xff), C(0xc0), C(0), C(plgv_Unicode) } + { C(0), C(0), C(0), C(0), C(0xff), C(0xc0), C(0), C(plgv_Unicode) } #define cc_symbol\ - { C(0), C(0), C(0), C(4), C(0), C(0), C(0), C(plgv_Unicode) } + { C(0), C(0), C(0), C(4), C(0), C(0), C(0), C(plgv_Unicode) } #define cc_dingbats\ - { C(0), C(0), C(0), C(1), C(0), C(0), C(0), C(plgv_Unicode) } + { C(0), C(0), C(0), C(1), C(0), C(0), C(0), C(plgv_Unicode) } /* * Per TRM 23-87, PCL5 printers are supposed to have Univers * and CG Times fonts. Substitute Arial for Univers and @@ -56,7 +55,7 @@ const font_resident_t resident_table[] = { #define agfa (4096) /* definition for style word as defined on 11-19 PCLTRM */ #define style_word(posture, width, structure) \ - ((posture) + (4 * (width)) + (32 * (structure))) + ((posture) + (4 * (width)) + (32 * (structure))) #define REGULAR (style_word(0, 0, 0)) #define ITALIC (style_word(1, 0, 0)) #define CONDENSEDITALIC (style_word(1, 1, 0)) @@ -146,21 +145,21 @@ const font_resident_t resident_table[] = { }, { - fontnames("UniversMedium", "Univers-Medium", "U001-Reg"), + fontnames("UniversMedium", "Univers-Medium", "U001-Reg"), {'U','n','i','v','e','r','s',' ',' ',' ',' ',' ',' ',' ','M','d'}, {0, 1, {332.0, 720000.0/332.0}, 0, REGULAR, NOBOLD, 4148, 11}, cc_alphabetic, plft_Unicode }, { - fontnames("UniversBold", "Univers-Bold", "U001-Bol"), + fontnames("UniversBold", "Univers-Bold", "U001-Bol"), {'U','n','i','v','e','r','s',' ',' ',' ',' ',' ',' ',' ','B','d'}, {0, 1, {332.0, 720000.0/332.0}, 0, REGULAR, BOLD, 4148, 12}, cc_alphabetic, plft_Unicode }, { - fontnames("UniversMediumItalic", "Univers-MediumItalic", "U001-Ita"), + fontnames("UniversMediumItalic", "Univers-MediumItalic", "U001-Ita"), {'U','n','i','v','e','r','s',' ',' ',' ',' ',' ','M','d','I','t'}, {0, 1, {332.0, 720000.0/332.0}, 0, ITALIC, NOBOLD, 4148, 13}, cc_alphabetic, plft_Unicode @@ -172,9 +171,9 @@ const font_resident_t resident_table[] = { {0, 1, {332.0, 720000.0/332.0}, 0, ITALIC, BOLD, 4148, 14}, cc_alphabetic, plft_Unicode }, - + { - fontnames("UniversCondensedMedium", "Univers-Condensed-Medium", "U001Con-Reg"), + fontnames("UniversCondensedMedium", "Univers-Condensed-Medium", "U001Con-Reg"), {'U','n','i','v','e','r','s',' ',' ',' ',' ',' ','C','d','M','d'}, {0, 1, {221.0, 720000.0/221.0}, 0, CONDENSED, NOBOLD, 4148, 15}, cc_alphabetic, plft_Unicode @@ -188,33 +187,33 @@ const font_resident_t resident_table[] = { }, { - fontnames("UniversCondensedMediumItalic", "Univers-Condensed-MediumItalic", "U001Con-Ita"), + fontnames("UniversCondensedMediumItalic", "Univers-Condensed-MediumItalic", "U001Con-Ita"), {'U','n','i','v','e','r','s',' ',' ',' ','C','d','M','d','I','t'}, {0, 1, {221.0, 720000.0/221.0}, 0, CONDENSEDITALIC, NOBOLD, 4148, 17}, cc_alphabetic, plft_Unicode }, - + { - fontnames("UniversCondensedBoldItalic", "Univers-Condensed-BoldItalic", "U001Con-BolIta"), + fontnames("UniversCondensedBoldItalic", "Univers-Condensed-BoldItalic", "U001Con-BolIta"), {'U','n','i','v','e','r','s',' ',' ',' ','C','d','B','d','I','t'}, {0, 1, {221.0, 720000.0/221.0}, 0, CONDENSEDITALIC, BOLD, 4148, 18}, cc_alphabetic, plft_Unicode }, { - fontnames("AntiqueOlive", "AntiqueOlive", "AntiqueOlive-Reg"), + fontnames("AntiqueOlive", "AntiqueOlive", "AntiqueOlive-Reg"), {'A','n','t','i','q','O','l','i','v','e',' ',' ',' ',' ',' ',' '}, {0, 1, {295.0, 720000.0/295.0}, 0, REGULAR, NOBOLD, 4168, 19}, cc_alphabetic, plft_Unicode }, { - fontnames("AntiqueOliveBold", "AntiqueOlive-Bold", "AntiqueOlive-Bol"), + fontnames("AntiqueOliveBold", "AntiqueOlive-Bold", "AntiqueOlive-Bol"), {'A','n','t','i','q','O','l','i','v','e',' ',' ',' ',' ','B','d'}, {0, 1, {332.0, 720000.0/332.0}, 0, REGULAR, BOLD, 4168, 20}, cc_alphabetic, plft_Unicode }, - + { fontnames("AntiqueOliveItalic", "AntiqueOlive-Italic", "AntiqueOlive-Ita"), {'A','n','t','i','q','O','l','i','v','e',' ',' ',' ',' ','I','t'}, @@ -223,7 +222,7 @@ const font_resident_t resident_table[] = { }, { - fontnames("GaramondAntiqua", "Garamond-Antiqua", "GaramondNo8-Reg"), + fontnames("GaramondAntiqua", "Garamond-Antiqua", "GaramondNo8-Reg"), {'G','a','r','a','m','o','n','d',' ','A','n','t','i','q','u','a'}, {0, 1, {258.0, 720000.0/258.0}, 0, REGULAR, NOBOLD, 4197, 22}, cc_alphabetic, plft_Unicode @@ -244,49 +243,49 @@ const font_resident_t resident_table[] = { }, { - fontnames("GaramondKursivHalbfett", "Garamond-KursivHalbfett", "GaramondNo8-MedIta"), + fontnames("GaramondKursivHalbfett", "Garamond-KursivHalbfett", "GaramondNo8-MedIta"), {'G','a','r','a','m','o','n','d',' ','K','r','s','v','H','l','b'}, {0, 1, {258.0, 720000.0/258.0}, 0, ITALIC, BOLD, 4197, 25}, cc_alphabetic, plft_Unicode }, { - fontnames("Marigold", "Marigold", "Mauritius-Reg"), + fontnames("Marigold", "Marigold", "Mauritius-Reg"), {'M','a','r','i','g','o','l','d',' ',' ',' ',' ',' ',' ',' ',' '}, {0, 1, {221.0, 720000.0/221.0}, 0, REGULAR, NOBOLD, 4297, 26}, cc_alphabetic, plft_Unicode }, { - fontnames("AlbertusMedium", "Albertus-Medium", "A028-Med"), + fontnames("AlbertusMedium", "Albertus-Medium", "A028-Med"), {'A','l','b','e','r','t','u','s',' ',' ',' ',' ',' ',' ','M','d'}, {0, 1, {313.0, 720000.0/313.0}, 0, REGULAR, MEDIUMBOLD, 4362, 27}, cc_alphabetic, plft_Unicode }, { - fontnames("AlbertusExtraBold", "Albertus-ExtraBold", "A028-Ext"), + fontnames("AlbertusExtraBold", "Albertus-ExtraBold", "A028-Ext"), {'A','l','b','e','r','t','u','s',' ',' ',' ',' ',' ',' ','X','b'}, {0, 1, {369.0, 720000.0/369.0}, 0, REGULAR, EXBOLD, 4362, 28}, cc_alphabetic, plft_Unicode }, { - fontnames("Arial", "Arial", "A030-Reg"), + fontnames("Arial", "Arial", "A030-Reg"), {'A','r','i','a','l',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' '}, {0, 1, {278.0, 720000.0/278.0}, 0, REGULAR, NOBOLD, 16602, 29}, cc_alphabetic, plft_Unicode }, { - fontnames("Arial-BoldMT", "Arial-Bold", "A030-Bol"), + fontnames("Arial-BoldMT", "Arial-Bold", "A030-Bol"), {'A','r','i','a','l',' ',' ',' ',' ',' ',' ',' ',' ',' ','B','d'}, {0, 1, {278.0, 720000.0/278.0}, 0, REGULAR, BOLD, 16602, 30}, cc_alphabetic, plft_Unicode }, { - fontnames("Arial-ItalicMT", "Arial-Italic", "A030-Ita"), + fontnames("Arial-ItalicMT", "Arial-Italic", "A030-Ita"), {'A','r','i','a','l',' ',' ',' ',' ',' ',' ',' ',' ',' ','I','t'}, {0, 1, {278.0, 720000.0/278.0}, 0, ITALIC, NOBOLD, 16602, 31}, cc_alphabetic, plft_Unicode @@ -300,7 +299,7 @@ const font_resident_t resident_table[] = { }, { - fontnames("TimesNewRoman", "TimesNewRoman", "NimbusRomanNo9-Reg"), + fontnames("TimesNewRoman", "TimesNewRoman", "NimbusRomanNo9-Reg"), {'T','i','m','e','s','N','e','w','R','m','n',' ',' ',' ',' ',' '}, {0, 1, {250.0, 720000.0/250.0}, 0, REGULAR, NOBOLD, 16901, 33}, cc_alphabetic, plft_Unicode @@ -321,21 +320,21 @@ const font_resident_t resident_table[] = { }, { - fontnames("TimesNewRoman-BoldItalic", "TimesNewRoman-BoldItalic", "NimbusRomanNo9-MedIta"), + fontnames("TimesNewRoman-BoldItalic", "TimesNewRoman-BoldItalic", "NimbusRomanNo9-MedIta"), {'T','i','m','e','s','N','e','w','R','m','n',' ','B','d','I','t'}, {0, 1, {250.0, 720000.0/250.0}, 0, ITALIC, BOLD, 16901, 35}, cc_alphabetic, plft_Unicode }, { - fontnames("Helvetica", "Helvetica", "NimbusSanL-Regu"), + fontnames("Helvetica", "Helvetica", "NimbusSanL-Regu"), {'H','e','l','v','e','t','i','c','a',' ',' ',' ',' ',' ',' ',' '}, {0, 1, {278.0, 720000.0/278.0}, 0, REGULAR, NOBOLD, 24580, 37}, cc_alphabetic, plft_Unicode }, { - fontnames("Helvetica-Bold", "Helvetica-Bold", "NimbusSanL-Bold"), + fontnames("Helvetica-Bold", "Helvetica-Bold", "NimbusSanL-Bold"), {'H','e','l','v','e','t','i','c','a',' ',' ',' ',' ',' ','B','d'}, {0, 1, {278.0, 720000.0/278.0}, 0, REGULAR, BOLD, 24580, 38}, cc_alphabetic, plft_Unicode @@ -363,14 +362,14 @@ const font_resident_t resident_table[] = { }, { - fontnames("Helvetica-Narrow-BoldOblique", "Helvetica-Narrow-BoldOblique", "NimbusSanL-BoldCondItal"), + fontnames("Helvetica-Narrow-BoldOblique", "Helvetica-Narrow-BoldOblique", "NimbusSanL-BoldCondItal"), {'H','e','l','v','e','t','i','c','a',' ','N','r','B','d','O','b'}, {0, 1, {228.0, 720000.0/228.0}, 0, CONDENSEDITALIC, BOLD, 24580, 44}, cc_alphabetic, plft_Unicode }, { - fontnames("Helvetica-Narrow-Oblique", "Helvetica-Narrow-Oblique", "NimbusSanL-ReguCondItal"), + fontnames("Helvetica-Narrow-Oblique", "Helvetica-Narrow-Oblique", "NimbusSanL-ReguCondItal"), {'H','e','l','v','e','t','i','c','a',' ',' ',' ','N','r','O','b'}, {0, 1, {228.0, 720000.0/228.0}, 0, CONDENSEDITALIC, NOBOLD, 24580, 43}, cc_alphabetic, plft_Unicode @@ -391,21 +390,21 @@ const font_resident_t resident_table[] = { }, { - fontnames("Palatino-Italic", "Palatino-Italic", "URWPalladioL-Ital"), + fontnames("Palatino-Italic", "Palatino-Italic", "URWPalladioL-Ital"), {'P','a','l','a','t','i','n','o',' ',' ',' ',' ',' ',' ','I','t'}, {0, 1, {250.0, 720000.0/250.0}, 0, ITALIC, NOBOLD, 24591, 47}, cc_alphabetic, plft_Unicode }, { - fontnames("Palatino-Bold", "Palatino-Bold", "URWPalladioL-Bold"), + fontnames("Palatino-Bold", "Palatino-Bold", "URWPalladioL-Bold"), {'P','a','l','a','t','i','n','o',' ',' ',' ',' ',' ',' ','B','d'}, {0, 1, {250.0, 720000.0/250.0}, 0, REGULAR, BOLD, 24591, 46}, cc_alphabetic, plft_Unicode }, { - fontnames("Palatino-BoldItalic", "Palatino-BoldItalic", "URWPalladioL-BoldItal"), + fontnames("Palatino-BoldItalic", "Palatino-BoldItalic", "URWPalladioL-BoldItal"), {'P','a','l','a','t','i','n','o',' ',' ',' ',' ','B','d','I','t'}, {0, 1, {250.0, 720000.0/250.0}, 0, ITALIC, BOLD, 24591, 48}, cc_alphabetic, plft_Unicode @@ -468,28 +467,28 @@ const font_resident_t resident_table[] = { }, { - fontnames("NewCenturySchlbk-Bold", "NewCenturySchlbk-Bold", "CenturySchL-Bold"), + fontnames("NewCenturySchlbk-Bold", "NewCenturySchlbk-Bold", "CenturySchL-Bold"), {'N','w','C','e','n','t','S','c','h','l','b','k',' ',' ','B','d'}, {0, 1, {287.0, 720000.0/287.0}, 0, REGULAR, BOLD, 24703, 58}, cc_alphabetic, plft_Unicode }, { - fontnames("NewCenturySchlbk-BoldItalic", "NewCenturySchlbk-BoldItalic", "CenturySchL-BoldItal"), + fontnames("NewCenturySchlbk-BoldItalic", "NewCenturySchlbk-BoldItalic", "CenturySchL-BoldItal"), {'N','w','C','e','n','t','S','c','h','l','b','k','B','d','I','t'}, {0, 1, {287.0, 720000.0/287.0}, 0, ITALIC, BOLD, 24703, 60}, cc_alphabetic, plft_Unicode }, { - fontnames("NewCenturySchlbk-Italic", "NewCenturySchlbk-Italic", "CenturySchL-Ital"), + fontnames("NewCenturySchlbk-Italic", "NewCenturySchlbk-Italic", "CenturySchL-Ital"), {'N','w','C','e','n','t','S','c','h','l','b','k',' ',' ','I','t'}, {0, 1, {278.0, 720000.0/278.0}, 0, ITALIC, NOBOLD, 24703, 59}, cc_alphabetic, plft_Unicode }, { - fontnames("NewCenturySchlbk-Roman", "NewCenturySchlbk-Roman", "CenturySchL-Roma"), + fontnames("NewCenturySchlbk-Roman", "NewCenturySchlbk-Roman", "CenturySchL-Roma"), {'N','w','C','e','n','t','S','c','h','l','b','k',' ','R','m','n'}, {0, 1, {278.0, 720000.0/278.0}, 0, REGULAR, NOBOLD, 24703, 57}, cc_alphabetic, plft_Unicode @@ -510,14 +509,14 @@ const font_resident_t resident_table[] = { }, { - fontnames("Times-Italic", "Times-Italic", "NimbusRomNo9L-ReguItal"), + fontnames("Times-Italic", "Times-Italic", "NimbusRomNo9L-ReguItal"), {'T','i','m','e','s',' ',' ',' ',' ',' ',' ',' ',' ',' ','I','t'}, {0, 1, {250.0, 720000.0/250.0}, 0, ITALIC, NOBOLD, 25093, 63}, cc_alphabetic, plft_Unicode }, { - fontnames("Times-BoldItalic", "Times-BoldItalic", "NimbusRomNo9L-MediItal"), + fontnames("Times-BoldItalic", "Times-BoldItalic", "NimbusRomNo9L-MediItal"), {'T','i','m','e','s',' ',' ',' ',' ',' ',' ',' ','B','d','I','t'}, {0, 1, {250.0, 720000.0/250.0}, 0, ITALIC, BOLD, 25093, 64}, cc_alphabetic, plft_Unicode @@ -526,10 +525,10 @@ const font_resident_t resident_table[] = { { fontnames("ZapfChancery-MediumItalic", "ZapfChancery-MediumItalic", "URWChanceryL-MediItal"), {'Z','a','p','f','C','h','a','n','c','e','r','y','M','d','I','t'}, - {0, 1, {220.0, 720000.0/220.0},0, ITALIC, NOBOLD, 45099, 65}, + {0, 1, {220.0, 720000.0/220.0},0, ITALIC, NOBOLD, 45099, 65}, cc_alphabetic, plft_Unicode }, - + { fontnames("SymbolMT", "Symbol", "StandardSymL"), {'S','y','m','b','o','l',' ',' ',' ',' ',' ',' ',' ',' ',' ',' '}, @@ -555,25 +554,24 @@ const font_resident_t resident_table[] = { }, { - fontnames("ZapfDingbats", "ZapfDingbats", "Dingbats"), + fontnames("ZapfDingbats", "ZapfDingbats", "Dingbats"), {'Z','a','p','f','D','i','n','g','b','a','t','s',' ',' ',' ',' '}, {460, 1, {280.0, 720000.0/280.0},0, REGULAR, NOBOLD, 45101, 69}, cc_dingbats, plft_8bit }, { - fontnames("CourierBold", "CourierMT-Bold", "NimbusMono-Bol"), + fontnames("CourierBold", "CourierMT-Bold", "NimbusMono-Bol"), {'C','o','u','r','i','e','r',' ',' ',' ',' ',' ',' ',' ','B','d'}, - {0, 0, {600.0, 720000.0/600.0}, 0, REGULAR, BOLD, 4099, 70}, - cc_alphabetic, plft_Unicode + {0, 0, {600.0, 720000.0/600.0}, 0, REGULAR, BOLD, 4099, 70}, + cc_alphabetic, plft_Unicode }, - { fontnames("CourierItalic", "CourierMT-Italic", "NimbusMono-Ita"), {'C','o','u','r','i','e','r',' ',' ',' ',' ',' ',' ',' ','I','t'}, {0, 0, {600.0, 720000.0/600.0}, 0, ITALIC, NOBOLD, 4099, 71}, - cc_alphabetic, plft_Unicode + cc_alphabetic, plft_Unicode }, { @@ -584,12 +582,12 @@ const font_resident_t resident_table[] = { }, { - fontnames("LetterGothic", "LetterGothic", "LetterGothic-Reg"), + fontnames("LetterGothic", "LetterGothic", "LetterGothic-Reg"), {'L','e','t','t','e','r','G','o','t','h','i','c',' ',' ',' ',' '}, {0, 0, {500.0, 720000.0/500.0}, 0, REGULAR, NOBOLD, 4102, 73}, cc_alphabetic, plft_Unicode }, - + { fontnames("LetterGothicBold", "LetterGothic-Bold", "LetterGothic-Bol"), {'L','e','t','t','e','r','G','o','t','h','i','c',' ',' ','B','d'}, @@ -604,7 +602,6 @@ const font_resident_t resident_table[] = { cc_alphabetic, plft_Unicode }, - { fontnames("Courier", "Courier", "NimbusMonL-Regu"), {'C','o','u','r','i','e','r','P','S',' ',' ',' ',' ',' ',' ',' '}, @@ -26,7 +26,7 @@ typedef struct gs_state_s gs_state; #include "gxdevice.h" #include "plht.h" -int +int pl_set_pcl_halftone(gs_state *pgs, gs_mapping_proc transfer_proc, int width, int height, gs_string threshold_data, diff --git a/pl/plimpl.c b/pl/plimpl.c index e92dae23b..392535f89 100644 --- a/pl/plimpl.c +++ b/pl/plimpl.c @@ -30,19 +30,17 @@ extern pl_interp_implementation_t ps_implementation; /* Zero-terminated list of pointers to implementations */ pl_interp_implementation_t const * const pdl_implementation[] = { #ifdef XPS_INCLUDED - &xps_implementation, + &xps_implementation, #endif #ifdef SVG_INCLUDED - &svg_implementation, + &svg_implementation, #endif #ifdef PCL_INCLUDED - &pcl_implementation, - &pxl_implementation, + &pcl_implementation, + &pxl_implementation, #endif #ifdef PSI_INCLUDED - &ps_implementation, + &ps_implementation, #endif - 0 + 0 }; - - diff --git a/pl/pllfont.c b/pl/pllfont.c index 3afed1fa2..5712f2386 100644 --- a/pl/pllfont.c +++ b/pl/pllfont.c @@ -168,8 +168,8 @@ check_resident_fonts(pl_dict_t *pfontdict, gs_memory_t *mem) int j; dprintf2("%s (entry %d) not found\n", resident_table[i].full_font_name, i); dprintf("pxl unicode name:"); - for (j = 0; - j < countof(resident_table[i].unicode_fontname); + for (j = 0; + j < countof(resident_table[i].unicode_fontname); j++) dprintf1("'%c'", resident_table[i].unicode_fontname[j]); dprintf("\n"); diff --git a/pl/plmain.c b/pl/plmain.c index c196fe1e5..74a778c39 100644 --- a/pl/plmain.c +++ b/pl/plmain.c @@ -66,7 +66,6 @@ typedef struct pl_main_universe_s { gx_device *curr_device; } pl_main_universe_t; - /* Include the extern for the device list. */ extern_gs_lib_device_list(); @@ -138,7 +137,6 @@ pl_select_implementation( pl_top_cursor_t r ); - /* Process the options on the command line. */ static FILE *pl_main_arg_fopen(const char *fname, void *ignore_data); @@ -187,7 +185,6 @@ long pl_main_cursor_position(pl_top_cursor_t *cursor); /* Close read cursor */ void pl_main_cursor_close(pl_top_cursor_t *cursor); - /* return index in gs device list -1 if not found */ static inline int get_device_index(const gs_memory_t *mem, const char *value) @@ -239,7 +236,6 @@ pl_main_aux( pl_platform_init(mem->gs_lib_ctx->fstdout); - pjl_mem = mem; gs_lib_init1(pjl_mem); @@ -262,7 +258,6 @@ pl_main_aux( pl_main_init_instance(&inst, mem); arg_init(&args, (const char **)argv, argc, pl_main_arg_fopen, NULL); - /* Create PJL instance */ if ( pl_allocate_interp(&pjl_interp, &pjl_implementation, pjl_mem) < 0 || pl_allocate_interp_instance(&pjl_instance, pjl_interp, pjl_mem) < 0 ) { @@ -282,7 +277,6 @@ pl_main_aux( pl_print_usage(&inst, "Start"); #endif - /* ------ Begin Main LOOP ------- */ for (;;) { /* Process one input file. */ @@ -298,7 +292,6 @@ pl_main_aux( bool in_pjl = true; bool new_job = false; - if ( pl_init_job(pjl_instance) < 0 ) { errprintf(mem, "Unable to init PJL job.\n"); return -1; @@ -337,18 +330,18 @@ pl_main_aux( if (!filename) break; /* no nore files to process */ - /* If the display device is selected (default), set up the callback */ - if (strcmp(inst.device->dname, "display") == 0) { - gx_device_display *ddev; - if (!disp) { - errprintf(mem, "Display device selected, but no display device configured.\n"); - return -1; - } - ddev = (gx_device_display *)inst.device; - ddev->callback = (display_callback *)disp; - } - - /* open file for reading - NB we should respect the minimum + /* If the display device is selected (default), set up the callback */ + if (strcmp(inst.device->dname, "display") == 0) { + gx_device_display *ddev; + if (!disp) { + errprintf(mem, "Display device selected, but no display device configured.\n"); + return -1; + } + ddev = (gx_device_display *)inst.device; + ddev->callback = (display_callback *)disp; + } + + /* open file for reading - NB we should respect the minimum requirements specified by each implementation in the characteristics structure */ if (pl_main_cursor_open(mem, &r, filename, buf, sizeof(buf)) < 0) { @@ -597,7 +590,6 @@ pl_interp_instance_t *get_interpreter_from_memory( const gs_memory_t *mem ) return universe->curr_instance; } - /* Undo pl_main_universe_init */ int /* 0 ok, else -1 error */ pl_main_universe_dnit( @@ -833,7 +825,6 @@ pl_top_create_device(pl_main_instance_t *pti, int index, bool is_default) return code; } - /* Process the options on the command line. */ static FILE * pl_main_arg_fopen(const char *fname, void *ignore_data) @@ -904,38 +895,38 @@ pl_main_process_options(pl_main_instance_t *pmi, arg_list *pal, code = param_write_bool((gs_param_list *)params, arg_heap_copy(arg), &bval); continue; } - /* Search for a non-decimal 'radix' number */ - if ( strchr(value, '#') ) { - int base, number = 0; - char *val = strchr(value, '#'); - - *val++ = 0x00; - sscanf(value, "%d", &base); - if (base < 2 || base > 36) { - dprintf1("Value out of range %s", value); - return -1; - } - while(*val) { - if (*val >= '0' && *val <= '9') { - number = number * base + (*val - '0'); - } else { - if (*val >= 'A' && *val <= 'Z') { - number = number * base + (*val - 'A'); - } else { - if (*val >= 'a' && *val <= 'z') { - number = number * base + (*val - 'a'); - } else { - dprintf1("Value out of range %s", val); - return -1; - } - } - } - val++; - } + /* Search for a non-decimal 'radix' number */ + if ( strchr(value, '#') ) { + int base, number = 0; + char *val = strchr(value, '#'); + + *val++ = 0x00; + sscanf(value, "%d", &base); + if (base < 2 || base > 36) { + dprintf1("Value out of range %s", value); + return -1; + } + while(*val) { + if (*val >= '0' && *val <= '9') { + number = number * base + (*val - '0'); + } else { + if (*val >= 'A' && *val <= 'Z') { + number = number * base + (*val - 'A'); + } else { + if (*val >= 'a' && *val <= 'z') { + number = number * base + (*val - 'a'); + } else { + dprintf1("Value out of range %s", val); + return -1; + } + } + } + val++; + } strncpy(buffer, arg, eqp - arg); buffer[eqp - arg] = '\0'; code = param_write_int((gs_param_list *)params, arg_heap_copy(buffer), &number); - } else if ( ( !strchr(value, '.' ) ) && + } else if ( ( !strchr(value, '.' ) ) && /* search for an int (no decimal), if fail try a float */ ( sscanf(value, "%d", &vi) == 1 ) ) { if ( !strncmp(arg, "FirstPage", 9) ) @@ -1028,7 +1019,7 @@ pl_main_process_options(pl_main_instance_t *pmi, arg_list *pal, #ifdef HEAP_ALLOCATOR_ONLY gs_malloc_memory_t *rawheap = (gs_malloc_memory_t *)gs_malloc_wrapped_contents(pmi->memory); -#else +#else gs_malloc_memory_t *rawheap = (gs_malloc_memory_t *)gs_memory_chunk_target(pmi->memory)->non_gc_memory; #endif @@ -1044,13 +1035,13 @@ pl_main_process_options(pl_main_instance_t *pmi, arg_list *pal, const char *adef; gs_param_string str; - if (arg[0] == 0) { - adef = arg_next(pal, &code); - if (code < 0) + if (arg[0] == 0) { + adef = arg_next(pal, &code); + if (code < 0) break; - } else - adef = arg; - param_string_from_transient_string(str, adef); + } else + adef = arg; + param_string_from_transient_string(str, adef); code = param_write_string((gs_param_list *)params, "OutputFile", &str); pmi->pause=false; break; diff --git a/pl/plplatf.c b/pl/plplatf.c index da4ecd47b..7fb8732be 100644 --- a/pl/plplatf.c +++ b/pl/plplatf.c @@ -23,7 +23,6 @@ #include "gslib.h" #include "plplatf.h" - /* ------------- Platform de/init --------- */ void pl_platform_init(FILE *debug_out) @@ -66,6 +65,5 @@ gs_reloc_const_string(gs_const_string *sptr, gc_state_t *gcst) void gs_exit(int exit_status) { pl_platform_dnit(exit_status); - pl_exit(exit_status); /* must be implemeted by caller */ + pl_exit(exit_status); /* must be implemeted by caller */ } - diff --git a/pl/plplatf.h b/pl/plplatf.h index f218eeadf..703a213a0 100644 --- a/pl/plplatf.h +++ b/pl/plplatf.h @@ -23,10 +23,8 @@ pl_platform_init(FILE *debug_out); void pl_platform_dnit(int exit_status); - /*----- The following is declared here, but must be implemented by client ----*/ /* Terminate execution */ void pl_exit(int exit_status); #endif /* plplatf_INCLUDED */ - diff --git a/pl/plplatfps.c b/pl/plplatfps.c index ba3d34dd7..fb3411e47 100644 --- a/pl/plplatfps.c +++ b/pl/plplatfps.c @@ -23,7 +23,6 @@ #include "gslib.h" #include "plplatf.h" - /* ------------- Platform de/init --------- */ void pl_platform_init(FILE *debug_out) @@ -39,7 +38,7 @@ pl_platform_init(FILE *debug_out) void pl_platform_dnit(int exit_status) { - // hack + // hack // fflush(gs_stderr); /* in case of error exit */ /* Do platform-specific cleanup. */ gp_exit(exit_status, 0); @@ -65,4 +64,3 @@ gp_check_interrupts(void) { return 0; } - diff --git a/pl/plsrgb.c b/pl/plsrgb.c index 251f9aee6..42253b004 100644 --- a/pl/plsrgb.c +++ b/pl/plsrgb.c @@ -46,8 +46,7 @@ pl_device_does_color_conversion() return true; #endif return false; -} - +} /* shared language (pcl and pclxl) for setting up sRGB to XYZ and an associated default CRD to be used. The code will request a crd @@ -56,11 +55,11 @@ pl_device_does_color_conversion() definitions are repeated here [ /CIEBasedABC << - % sRGB gamma transform + % sRGB gamma transform /DecodeLMN [ {dup 0.03928 le {12.92321 div}{0.055 add 1.055 div 2.4 exp}ifelse} bind dup dup ] - + % sRGB to XYZ (D65) matrix (ITU-R BT.709-2 Primaries) /MatrixLMN [ 0.412457 0.212673 0.019334 @@ -68,51 +67,49 @@ pl_device_does_color_conversion() 0.180437 0.072175 0.950301 ] /WhitePoint [ 0.9505 1 1.0890 ] % D65 /BlackPoint[0 0 0] - >> ] setcolorspace - + >> ] setcolorspace + << % sRGB output CRD, D65 white point /ColorRenderingType 1 - /RangePQR [ -0.5 2 -0.5 2 -0.5 2 ] - + /RangePQR [ -0.5 2 -0.5 2 -0.5 2 ] + % Bradford Cone Space /MatrixPQR [0.8951 -0.7502 0.0389 0.2664 1.7135 -0.0685 - -0.1614 0.0367 1.0296] - + -0.1614 0.0367 1.0296] + % VonKries-like transform in Bradford Cone Space /TransformPQR [{exch pop exch 3 get mul exch pop exch 3 get div} bind {exch pop exch 4 get mul exch pop exch 4 get div} bind - {exch pop exch 5 get mul exch pop exch 5 get div} bind] - + {exch pop exch 5 get mul exch pop exch 5 get div} bind] + /MatrixLMN [3.240449 -0.969265 0.055643 -1.537136 1.876011 -0.204026 - -0.498531 0.041556 1.057229] - + -0.498531 0.041556 1.057229] + % Inverse sRGB gamma transform /EncodeABC [{dup 0.00304 le {12.92321 mul} {1 2.4 div exp 1.055 mul 0.055 sub}ifelse} - bind dup dup] - + bind dup dup] + /WhitePoint[0.9505 1 1.0890] % D65 /BlackPoint [0 0 0] >> setcolorrendering */ - /* CIEBasedABC definitions */ /* Decode LMN procedures for srgb color spaces or sRGB gamma transform. */ inline static float pl_decodeLMN(floatp val, const gs_cie_common *pcie) { if ( val <= 0.03928 ) - return (float)(val / 12.92321); + return (float)(val / 12.92321); else - return (float)pow((val + 0.055) / 1.055, (double)2.4); + return (float)pow((val + 0.055) / 1.055, (double)2.4); } - static float pl_DecodeLMN_0(floatp val, const gs_cie_common *pcie) { @@ -169,7 +166,6 @@ static const gs_range3 pl_RangePQR = { {-0.5, 2.0}} }; - /* tranform pqr */ static int pl_TransformPQR_proc(int indx, floatp val, const gs_cie_wbsd *cs_wbsd, @@ -188,7 +184,6 @@ static const gs_cie_transform_proc3 pl_TransformPQR = { NULL }; - /* ABC - inverse srgb gamma transform */ inline static float pl_encodeABC(floatp in, const gs_cie_render * pcrd) @@ -284,13 +279,11 @@ pl_read_device_CRD(gs_cie_render *pcrd, gs_state *pgs) return (code == 0); } - /* statics to see if the crd has been built, in practice the crd is a singleton. */ gs_cie_render *pl_pcrd; bool pl_pcrd_built = false; /* the crd has been built */ - static int pl_build_crd(gs_state *pgs) { @@ -301,7 +294,7 @@ pl_build_crd(gs_state *pgs) code = gs_cie_render1_build(&pl_pcrd, gs_state_memory(pgs), "build_crd"); if ( code < 0 ) - return code; + return code; pl_pcrd_built = true; if ( pl_read_device_CRD(pl_pcrd, pgs) ) { @@ -309,8 +302,8 @@ pl_build_crd(gs_state *pgs) return 0; } - code = gs_cie_render1_initialize(pgs->memory, - pl_pcrd, + code = gs_cie_render1_initialize(pgs->memory, + pl_pcrd, NULL, &pl_WhitePoint, &pl_BlackPoint, @@ -325,12 +318,11 @@ pl_build_crd(gs_state *pgs) NULL, NULL); if ( code < 0 ) - return code; /* should not fail */ + return code; /* should not fail */ code = gs_setcolorrendering(pgs, pl_pcrd); return code; } - /* return SRGB color space to the client */ int pl_cspace_init_SRGB(gs_color_space **ppcs, const gs_state *pgs) @@ -347,8 +339,6 @@ pl_cspace_init_SRGB(gs_color_space **ppcs, const gs_state *pgs) if ( code < 0 ) return code; - - code = gs_cspace_build_CIEABC(ppcs, NULL, gs_state_memory(pgs)); if ( code < 0 ) return code; @@ -392,7 +382,7 @@ pl_setSRGBcolor(gs_state *pgs, float r, float g, float b) code = pl_setSRGB(pgs); if ( code < 0 ) return code; - + /* set the color */ color.paint.values[0] = r; color.paint.values[1] = g; diff --git a/pl/plsymbol.c b/pl/plsymbol.c index 7baf70757..b58800fe5 100644 --- a/pl/plsymbol.c +++ b/pl/plsymbol.c @@ -681,7 +681,6 @@ static const pl_symbol_map_t map_9J_unicode = { } }; - /************************************** * ISO 8859/1 Latin 1 Unicode mapping * **************************************/ @@ -856,7 +855,7 @@ static const pl_symbol_map_t map_10U_unicode = { 0x03b1, 0x00df, 0x0393, 0x03c0, 0x03a3, 0x03c3, 0x00b5, 0x03c4, 0x03a6, 0x0398, 0x03a9, 0x03b4, 0x221e, 0x03c6, 0x03b5, 0x2229, /*0xf0*/ - 0x2261, 0x00b1, 0x2265, 0x2264, 0x2320, 0x2321, 0x00f7, 0x2248, + 0x2261, 0x00b1, 0x2265, 0x2264, 0x2320, 0x2321, 0x00f7, 0x2248, 0x00b0, 0x2219, 0x00b7, 0x221a, 0x207f, 0x00b2, 0x25aa, 0x00a0 } }; @@ -1321,7 +1320,6 @@ static const pl_symbol_map_t map_17U_unicode = { } }; - /************************************ * PC-Turkish (PT) Unicode mapping * ************************************/ @@ -1374,7 +1372,7 @@ static const pl_symbol_map_t map_9T_unicode = { 0x03b1, 0x00df, 0x0393, 0x03c0, 0x03a3, 0x03c3, 0x00b5, 0x03c4, 0x03a6, 0x0398, 0x03a9, 0x03b4, 0x221e, 0x03c6, 0x03b5, 0x2229, /*0xf0*/ - 0x2261, 0x00b1, 0x2265, 0x2264, 0x2320, 0x2321, 0x00f7, 0x2248, + 0x2261, 0x00b1, 0x2265, 0x2264, 0x2320, 0x2321, 0x00f7, 0x2248, 0x00b0, 0x2219, 0x2219, 0x221a, 0x207f, 0x00b2, 0x25aa, 0x00a0 } }; @@ -1494,7 +1492,6 @@ static const pl_symbol_map_t map_9E_unicode = { } }; - /* NB The following 3 symbols sets need to be formatted consistently with the other symbol sets. */ @@ -2023,7 +2020,7 @@ static const pl_symbol_map_t map_9G_unicode = { 0x03cc, 0x03cd, 0x03ce, - 0xffff + 0xffff } }; /******************************************** @@ -2032,7 +2029,7 @@ static const pl_symbol_map_t map_9G_unicode = { static const pl_symbol_map_t map_9V_unicode = { map_header(9, 'V', plgv_Unicode, 2, 0, 0, 0, 0, 0xc0, 0, 0, 0, PLGV_U2M_MAPPING), { - 0x0000, + 0x0000, 0x0001, 0x0002, 0x0003, @@ -2287,7 +2284,7 @@ static const pl_symbol_map_t map_9V_unicode = { 0x00fc, 0x200e, 0x200f, - 0x06d2 + 0x06d2 } }; @@ -3567,7 +3564,6 @@ const pl_symbol_map_t *pl_built_in_symbol_maps[] = { const int pl_built_in_symbol_map_count = countof(pl_built_in_symbol_maps) - 1; - ulong pl_map_symbol(const pl_symbol_map_t *psm, uint chr, bool is_resident_font, bool is_MSL, @@ -3586,12 +3582,12 @@ pl_map_symbol(const pl_symbol_map_t *psm, */ if (psm == 0) { - if (is_resident_font && !is_590) - return chr + 0xf000; + if (is_resident_font && !is_590) + return chr + 0xf000; else return chr; } - + if (pl_get_uint16(psm->id) == 590) { return chr; } @@ -3599,7 +3595,7 @@ pl_map_symbol(const pl_symbol_map_t *psm, first_code = pl_get_uint16(psm->first_code); last_code = pl_get_uint16(psm->last_code); if ((chr < first_code) || (chr > last_code)) - code = ((last_code <= 0xff) && (chr > 0xff) ? chr : 0xffff); + code = ((last_code <= 0xff) && (chr > 0xff) ? chr : 0xffff); else code = psm->codes[chr - first_code]; /* we do not provide many of the symbol sets in MSL format. diff --git a/pl/plsymbol.h b/pl/plsymbol.h index e41a0a544..5ce52e8b6 100644 --- a/pl/plsymbol.h +++ b/pl/plsymbol.h @@ -39,7 +39,7 @@ typedef enum { * the mapping function defined in pl/plvocab.h to map to and from msl * and unicode. There are 3 mutually exclusive possibilities: (1) a * unicode symbol set that can be mapped to msl, (2) an msl symbol set - * that can be mapped to unicode and (3) neither (1) or (2). + * that can be mapped to unicode and (3) neither (1) or (2). */ #define PLGV_M2U_MAPPING 1 @@ -82,7 +82,7 @@ extern const int pl_built_in_symbol_map_count; if the symbol set in null. We cheat here and use a ulong instead of gs_char to avoid pulling in all the gs_char graphics library dependencies. */ -ulong pl_map_symbol(const pl_symbol_map_t *psm, uint chr, bool is_resident_font, +ulong pl_map_symbol(const pl_symbol_map_t *psm, uint chr, bool is_resident_font, bool is_MSL, bool is_590); /* supported pcl and xl wide encodings - 4 Asian encodings and an an diff --git a/pl/pltop.c b/pl/pltop.c index bed6c8c56..0e421415c 100644 --- a/pl/pltop.c +++ b/pl/pltop.c @@ -23,13 +23,12 @@ #include "gsdevice.h" #include "pltop.h" - /* Get implemtation's characteristics */ const pl_interp_characteristics_t * /* always returns a descriptor */ pl_characteristics( const pl_interp_implementation_t *impl /* implementation of interpereter to alloc */ ) -{ +{ return impl->proc_characteristics(impl); } @@ -41,11 +40,11 @@ pl_allocate_interp( gs_memory_t *mem /* allocator to allocate interp from */ ) { - int code = impl->proc_allocate_interp(interp, impl, mem); - if (code < 0) - return code; - (*interp)->implementation = impl; - return code; + int code = impl->proc_allocate_interp(interp, impl, mem); + if (code < 0) + return code; + (*interp)->implementation = impl; + return code; } /* Do per-instance interpreter allocation/init. No device is set yet */ @@ -56,15 +55,15 @@ pl_allocate_interp_instance( gs_memory_t *mem /* allocator to allocate instance from */ ) { - pl_interp_instance_t *pli; - int code - = interp->implementation->proc_allocate_interp_instance(instance, interp, mem); - if (code < 0) - return code; - pli = *instance; - pli->interp = interp; + pl_interp_instance_t *pli; + int code + = interp->implementation->proc_allocate_interp_instance(instance, interp, mem); + if (code < 0) + return code; + pli = *instance; + pli->interp = interp; - return code; + return code; } /* Set a client language into an interperter instance */ @@ -75,8 +74,8 @@ pl_set_client_instance( pl_interp_instance_clients_t which_client ) { - return instance->interp->implementation->proc_set_client_instance - (instance, client, which_client); + return instance->interp->implementation->proc_set_client_instance + (instance, client, which_client); } /* Set an interpreter instance's pre-page action */ @@ -87,8 +86,8 @@ pl_set_pre_page_action( void *closure /* closure to call action with */ ) { - return instance->interp->implementation->proc_set_pre_page_action - (instance, action, closure); + return instance->interp->implementation->proc_set_pre_page_action + (instance, action, closure); } /* Set an interpreter instance's post-page action */ @@ -99,18 +98,17 @@ pl_set_post_page_action( void *closure /* closure to call action with */ ) { - return instance->interp->implementation->proc_set_post_page_action - (instance, action, closure); + return instance->interp->implementation->proc_set_post_page_action + (instance, action, closure); } - int /* ret 0 ok, else -ve err */ pl_get_device_memory( pl_interp_instance_t *instance, /* interp instance to use */ gs_memory_t **memory ) { - return instance->interp->implementation->proc_get_device_memory(instance, memory); + return instance->interp->implementation->proc_get_device_memory(instance, memory); } /* Get and interpreter prefered device memory allocator if any */ @@ -120,16 +118,16 @@ pl_set_device( gx_device *device /* device to set (open or closed) */ ) { - return instance->interp->implementation->proc_set_device(instance, device); + return instance->interp->implementation->proc_set_device(instance, device); } /* Prepare interp instance for the next "job" */ int /* ret 0 ok, else -ve error code */ pl_init_job( - pl_interp_instance_t *instance /* interp instance to start job in */ + pl_interp_instance_t *instance /* interp instance to start job in */ ) { - return instance->interp->implementation->proc_init_job(instance); + return instance->interp->implementation->proc_init_job(instance); } /* Parse a random access seekable file. @@ -139,8 +137,8 @@ pl_init_job( */ int pl_process_file( - pl_interp_instance_t *instance, - char *filename + pl_interp_instance_t *instance, + char *filename ) { return instance->interp->implementation->proc_process_file(instance, filename); @@ -155,54 +153,54 @@ int /* The parser reads data from the input * other <0 value - an error was detected. */ pl_process( - pl_interp_instance_t *instance, /* interp instance to process data job in */ - stream_cursor_read *cursor /* data to process */ + pl_interp_instance_t *instance, /* interp instance to process data job in */ + stream_cursor_read *cursor /* data to process */ ) { - return instance->interp->implementation->proc_process(instance, cursor); + return instance->interp->implementation->proc_process(instance, cursor); } /* Skip to end of job ret 1 if done, 0 ok but EOJ not found, else -ve error code */ int pl_flush_to_eoj( - pl_interp_instance_t *instance, /* interp instance to flush for */ - stream_cursor_read *cursor /* data to process */ + pl_interp_instance_t *instance, /* interp instance to flush for */ + stream_cursor_read *cursor /* data to process */ ) { - return instance->interp->implementation->proc_flush_to_eoj(instance, cursor); + return instance->interp->implementation->proc_flush_to_eoj(instance, cursor); } /* Parser action for end-of-file (also resets after unexpected EOF) */ int /* ret 0 or +ve if ok, else -ve error code */ pl_process_eof( - pl_interp_instance_t *instance /* interp instance to process data job in */ + pl_interp_instance_t *instance /* interp instance to process data job in */ ) { - return instance->interp->implementation->proc_process_eof(instance); + return instance->interp->implementation->proc_process_eof(instance); } /* Report any errors after running a job */ int /* ret 0 ok, else -ve error code */ pl_report_errors(pl_interp_instance_t *instance, /* interp instance to wrap up job in */ - int code, /* prev termination status */ - long file_position, /* file position of error, -1 if unknown */ - bool force_to_cout /* force errors to cout */ + int code, /* prev termination status */ + long file_position, /* file position of error, -1 if unknown */ + bool force_to_cout /* force errors to cout */ ) { - return instance->interp->implementation->proc_report_errors - (instance, code, file_position, force_to_cout); + return instance->interp->implementation->proc_report_errors + (instance, code, file_position, force_to_cout); } /* Wrap up interp instance after a "job" */ int /* ret 0 ok, else -ve error code */ pl_dnit_job( - pl_interp_instance_t *instance /* interp instance to wrap up job in */ + pl_interp_instance_t *instance /* interp instance to wrap up job in */ ) { - if ( instance ) - return instance->interp->implementation->proc_dnit_job(instance); + if ( instance ) + return instance->interp->implementation->proc_dnit_job(instance); else - return 0; + return 0; } /* Remove a device from an interperter instance */ @@ -211,8 +209,8 @@ pl_remove_device( pl_interp_instance_t *instance /* interp instance to use */ ) { - int code = instance->interp->implementation->proc_remove_device(instance); - return code; + int code = instance->interp->implementation->proc_remove_device(instance); + return code; } /* Deallocate a interpreter instance */ @@ -221,9 +219,9 @@ pl_deallocate_interp_instance( pl_interp_instance_t *instance /* instance to dealloc */ ) { - int code - = instance->interp->implementation->proc_deallocate_interp_instance(instance); - return code; + int code + = instance->interp->implementation->proc_deallocate_interp_instance(instance); + return code; } /* Do static deinit of interpreter */ @@ -232,8 +230,7 @@ pl_deallocate_interp( pl_interp_t *interp /* interpreter to deallocate */ ) { - int code - = interp->implementation->proc_deallocate_interp(interp); - return code; + int code + = interp->implementation->proc_deallocate_interp(interp); + return code; } - diff --git a/pl/pltop.h b/pl/pltop.h index f0d33c641..cca93ae63 100644 --- a/pl/pltop.h +++ b/pl/pltop.h @@ -33,7 +33,7 @@ typedef struct gx_device_s gx_device; */ typedef struct pl_interp_implementation_s pl_interp_implementation_t; /* fwd decl */ typedef struct pl_interp_s { - const struct pl_interp_implementation_s *implementation; /* implementation of actual interp */ + const struct pl_interp_implementation_s *implementation; /* implementation of actual interp */ } pl_interp_t; typedef struct pl_interp_instance_s { @@ -51,7 +51,7 @@ typedef int (*pl_page_action_t)(pl_interp_instance_t *, void *); */ typedef struct pl_interp_characteristics_s { const char* language; /* generic language should correspond with - HP documented PJL name */ + HP documented PJL name */ const char* auto_sense_string; /* string used to detect language */ const char* manufacturer; /* manuf str */ const char* version; /* version str */ @@ -61,7 +61,7 @@ typedef struct pl_interp_characteristics_s { /* * The pl_interp_t and pl_interp_instance are intended to provide a generic - * front end for language interpreters, in tandem with a + * front end for language interpreters, in tandem with a * pl_interp_implementation_t. pl_interp_t and pl_interp_impmementation_t * together are used to describe a particular implementation. An implementation * can then generate one or more instances, which are more-or-less @@ -111,14 +111,13 @@ int pl_allocate_interp_instance(pl_interp_instance_t **, pl_interp_t *, gs_memor typedef int (*pl_interp_proc_allocate_interp_instance_t)(pl_interp_instance_t **, pl_interp_t *, gs_memory_t *); /* clients that can be set into an interpreter's state */ -typedef enum { +typedef enum { /* needed to access the pcl interpreter in pxl (passthrough mode) */ PCL_CLIENT, /* needed by all interpreters to query pjl state */ PJL_CLIENT } pl_interp_instance_clients_t; - int pl_set_client_instance(pl_interp_instance_t *, pl_interp_instance_t *, pl_interp_instance_clients_t client); typedef int (*pl_interp_proc_set_client_instance_t)(pl_interp_instance_t *, pl_interp_instance_t *, pl_interp_instance_clients_t client); @@ -175,7 +174,7 @@ pl_interp_instance_t *get_interpreter_from_memory( const gs_memory_t *mem ); * Define a generic interpreter implementation */ struct pl_interp_implementation_s { - /* Procedure vector */ + /* Procedure vector */ pl_interp_proc_characteristics_t proc_characteristics; pl_interp_proc_allocate_interp_t proc_allocate_interp; pl_interp_proc_allocate_interp_instance_t proc_allocate_interp_instance; diff --git a/pl/pltoputl.c b/pl/pltoputl.c index a2e62d010..bf1657d33 100644 --- a/pl/pltoputl.c +++ b/pl/pltoputl.c @@ -23,21 +23,21 @@ /* Initialize cursor */ int /* returns 0 ok, else -ve error code */ pl_top_cursor_init( - pl_top_cursor_t *cursor, /* cursor to init/open */ - FILE *strm, /* open stream to read from */ - byte *buffer, /* buffer to use for reading */ - unsigned buffer_length /* length of *buffer */ + pl_top_cursor_t *cursor, /* cursor to init/open */ + FILE *strm, /* open stream to read from */ + byte *buffer, /* buffer to use for reading */ + unsigned buffer_length /* length of *buffer */ ) { - int status; - cursor->strm = strm; - cursor->buffer = buffer; - cursor->buffer_length = buffer_length; - cursor->cursor.limit = cursor->cursor.ptr = buffer - 1; - cursor->status = 1; /* non-status */ + int status; + cursor->strm = strm; + cursor->buffer = buffer; + cursor->buffer_length = buffer_length; + cursor->cursor.limit = cursor->cursor.ptr = buffer - 1; + cursor->status = 1; /* non-status */ - status = pl_top_cursor_next(cursor); - return status < 0 ? status : 0; /* report errors, not EOF */ + status = pl_top_cursor_next(cursor); + return status < 0 ? status : 0; /* report errors, not EOF */ } /* End of data condition. */ @@ -55,45 +55,45 @@ pl_renew_cursor_status(pl_top_cursor_t *cursor) if (pl_cursor_EOD(cursor)) { cursor->status = 1; } -} +} /* Refill from input */ int /* rets 1 ok, else 0 EOF, -ve error */ pl_top_cursor_next( - pl_top_cursor_t *cursor /* cursor to operate on */ + pl_top_cursor_t *cursor /* cursor to operate on */ ) { - int len; + int len; - /* Declare EOF even if chars left in buffer if no chars were consumed */ - if (pl_cursor_EOD(cursor)) + /* Declare EOF even if chars left in buffer if no chars were consumed */ + if (pl_cursor_EOD(cursor)) return cursor->status; - /* Copy any remaining bytes to head of buffer */ - len = cursor->cursor.limit - cursor->cursor.ptr; - if (len > 0) - memmove(cursor->buffer, cursor->cursor.ptr + 1, len); - cursor->cursor.ptr = cursor->buffer - 1; - cursor->cursor.limit = cursor->buffer + (len - 1); + /* Copy any remaining bytes to head of buffer */ + len = cursor->cursor.limit - cursor->cursor.ptr; + if (len > 0) + memmove(cursor->buffer, cursor->cursor.ptr + 1, len); + cursor->cursor.ptr = cursor->buffer - 1; + cursor->cursor.limit = cursor->buffer + (len - 1); - /* Top off rest of buffer by reading stream */ - if (cursor->status > 0 && len < cursor->buffer_length) { - cursor->status = fread((byte *)(cursor->cursor.limit + 1), - 1, cursor->buffer_length - len, - cursor->strm); - if (cursor->status > 0) - cursor->cursor.limit += cursor->status; - } + /* Top off rest of buffer by reading stream */ + if (cursor->status > 0 && len < cursor->buffer_length) { + cursor->status = fread((byte *)(cursor->cursor.limit + 1), + 1, cursor->buffer_length - len, + cursor->strm); + if (cursor->status > 0) + cursor->cursor.limit += cursor->status; + } - /* Return success if there's anything in the buffer */ - return cursor->cursor.limit == cursor->cursor.ptr ? cursor->status : 1; + /* Return success if there's anything in the buffer */ + return cursor->cursor.limit == cursor->cursor.ptr ? cursor->status : 1; } /* Deinit a read cursor */ void pl_top_cursor_dnit( - pl_top_cursor_t *cursor /* cursor to operate on */ + pl_top_cursor_t *cursor /* cursor to operate on */ ) { - return; + return; } diff --git a/pl/pltoputl.h b/pl/pltoputl.h index aeb90634e..ecaddeee3 100644 --- a/pl/pltoputl.h +++ b/pl/pltoputl.h @@ -23,11 +23,11 @@ * Stream-driven reading cursor */ typedef struct pl_top_cursor_s { - stream_cursor_read cursor; /* cursor actually used to read */ - FILE *strm; /* stream that data comes from */ - unsigned char *buffer; /* buffer to use */ + stream_cursor_read cursor; /* cursor actually used to read */ + FILE *strm; /* stream that data comes from */ + unsigned char *buffer; /* buffer to use */ unsigned buffer_length; /* # bytes in buffer */ - int status; /* if <=0, status to report to caller */ + int status; /* if <=0, status to report to caller */ } pl_top_cursor_t; /* Init a read cursor w/specified open stream */ diff --git a/pl/pluchar.c b/pl/pluchar.c index 6f6aebf4a..c107b2c85 100644 --- a/pl/pluchar.c +++ b/pl/pluchar.c @@ -55,7 +55,6 @@ #include "shareinc.h" #include "gxfapiu.h" - /* ---------------- UFST utilities ---------------- */ #define UFST_SCALE 16 @@ -138,9 +137,9 @@ pl_init_fc( pfc->ExtndFlags |= EF_VERTSUBS_TYPE; } else if (plfont->scaling_technology == plfst_TrueType && plfont->large_sizes) { - pfc->ExtndFlags = EF_FORMAT16_TYPE | EF_GALLEYSEG_TYPE; - if ((pfont->WMode & 0x1) != 0) /* vertical substitution */ - pfc->ExtndFlags |= EF_VERTSUBS_TYPE; + pfc->ExtndFlags = EF_FORMAT16_TYPE | EF_GALLEYSEG_TYPE; + if ((pfont->WMode & 0x1) != 0) /* vertical substitution */ + pfc->ExtndFlags |= EF_VERTSUBS_TYPE; } pfc->ExtndFlags |= EF_NOUSBOUNDBOX; /* UFST 5.0+ addition */ @@ -231,13 +230,13 @@ image_outline_char( pt[0].x, pt[0].y, pt[1].x, pt[1].y, pt[2].x, pt[2].y ); - } + } if (code < 0) return code; } if ((code = gx_path_close_subpath(ppath)) < 0) return code; - } + } return 0; } @@ -252,7 +251,7 @@ pl_ufst_char_width( gs_point * pwidth, FONTCONTEXT * pfc ) { - + UW16 chIdloc = char_code; UW16 fontWidth[2]; int status; @@ -287,7 +286,7 @@ pl_ufst_make_char( gs_font * pfont, gs_char chr, FONTCONTEXT * pfc ) -{ +{ gs_imager_state * pis = (gs_imager_state *)pgs; MEM_HANDLE memhdl; UW16 status, chIdloc = chr; @@ -350,11 +349,11 @@ pl_ufst_make_char( wbox[4] = psbm->black_width + wbox[2]; wbox[5] = psbm->black_depth + wbox[3]; - /* if (status == ERR_fixed_space) - * we are relying on ufst to - * send a zero sized image; we then cache the escapements of the space character - * psbm->bm = psbm->width = psbm->height = 0; - * note that the outline code can't be reached on ERR_fixed_space + /* if (status == ERR_fixed_space) + * we are relying on ufst to + * send a zero sized image; we then cache the escapements of the space character + * psbm->bm = psbm->width = psbm->height = 0; + * note that the outline code can't be reached on ERR_fixed_space */ if ((code = gs_setcachedevice(penum, pgs, wbox)) < 0) { @@ -426,10 +425,9 @@ pl_ufst_make_char( MEMfree(FSA CACHE_POOL, memhdl); gs_setmatrix(pgs, &sv_ctm); return (code < 0 ? code : 0); - } + } } - /* ---------------- MicroType font support ---------------- */ /* * MicroType accepts unicode values a glyph identifiers, so no explicit @@ -441,7 +439,6 @@ pl_mt_encode_char(gs_font * pfont, gs_char pchr, gs_glyph_space_t not_used) return (gs_glyph)pchr; } - /* * Set the current UFST font to be a MicroType font. */ @@ -496,10 +493,10 @@ struct pl_glyph_width_node_s { pl_glyph_width_node_t *head = NULL; /* add at the front of the list */ -int +int pl_glyph_width_cache_node_add(gs_memory_t *mem, gs_id font_id, uint char_code, gs_point *pwidth) { - pl_glyph_width_node_t *node = + pl_glyph_width_node_t *node = (pl_glyph_width_node_t *)gs_alloc_bytes(mem, sizeof(pl_glyph_width_node_t), "pl_glyph_width_cache_node_add"); @@ -512,7 +509,7 @@ pl_glyph_width_cache_node_add(gs_memory_t *mem, gs_id font_id, uint char_code, g node->next = head; head = node; } - + head->char_code = char_code; head->font_id = font_id; head->width = *pwidth; @@ -548,7 +545,6 @@ pl_glyph_width_list_remove(gs_memory_t *mem) return; } - /* Get character existence and escapement for an MicroType font. */ static int pl_mt_char_width( @@ -568,7 +564,7 @@ pl_mt_char_width( return 0; code = pl_ufst_char_width(char_code, pgs, pwidth, &fc); if ( code == 0 ) - code = pl_glyph_width_cache_node_add(plfont->pfont->memory, + code = pl_glyph_width_cache_node_add(plfont->pfont->memory, plfont->pfont->id, char_code, pwidth); } @@ -581,7 +577,7 @@ pl_mt_char_metrics(const pl_font_t *plfont, const void *pgs, uint char_code, flo gs_point width; metrics[0] = metrics[1] = metrics[2] = metrics[3] = 0; if ( 0 == pl_mt_char_width(plfont, pgs, char_code, &width) ) { - /* width is correct, + /* width is correct, stefan foo: lsb is missing. */ metrics[2] = width.x; /* metrics[0] = left_side_bearing; @@ -641,7 +637,7 @@ LPUB8 pl_PCLEO_charptr(LPUB8 pfont_hdr, UW16 char_code) return pl_PCLchId2ptr(FSA char_code); } -void plu_set_callbacks() +void plu_set_callbacks() { gx_set_UFST_Callbacks(pl_PCLEO_charptr, pl_PCLchId2ptr, pl_PCLglyphID2Ptr); /* nothing */ @@ -656,4 +652,3 @@ pl_mt_init_procs(gs_font_base *pfont) plfont->char_metrics = pl_mt_char_metrics; #undef plfont } - diff --git a/pl/plufont.c b/pl/plufont.c index e8591a20e..9030df894 100644 --- a/pl/plufont.c +++ b/pl/plufont.c @@ -56,7 +56,7 @@ extern void pl_init_fc( bool width_request); /* ---------------- Library callbacks ---------------- */ - + /* Fill in AGFA MicroType font boilerplate. */ void pl_fill_in_mt_font(gs_font_base *pfont, SW16 data, long unique_id) @@ -79,14 +79,14 @@ pl_fill_in_mt_font(gs_font_base *pfont, SW16 data, long unique_id) int pl_load_mt_font(SW16 handle, gs_font_dir *pdir, gs_memory_t *mem, long unique_id, pl_font_t **pplfont) -{ - gs_font_base *pfont = gs_alloc_struct(mem, gs_font_base, - &st_gs_font_base, "pl_mt_load_font(gs_font_base)"); - pl_font_t *plfont = pl_alloc_font(mem, "pl_mt_load_font(pl_font_t)"); +{ + gs_font_base *pfont = gs_alloc_struct(mem, gs_font_base, + &st_gs_font_base, "pl_mt_load_font(gs_font_base)"); + pl_font_t *plfont = pl_alloc_font(mem, "pl_mt_load_font(pl_font_t)"); int code; - if ( pfont == 0 || plfont == 0 ) - code = gs_note_error(gs_error_VMerror); + if ( pfont == 0 || plfont == 0 ) + code = gs_note_error(gs_error_VMerror); else { /* Initialize general font boilerplate. */ code = pl_fill_in_font((gs_font *)pfont, plfont, pdir, mem, "illegal font"); diff --git a/pl/plulfont.c b/pl/plulfont.c index 31c57c4a9..faa0f7389 100644 --- a/pl/plulfont.c +++ b/pl/plulfont.c @@ -38,14 +38,12 @@ #include "shareinc.h" #include "gxfapiu.h" - /* the line printer font NB FIXME use a header file. */ #include "plulp.c" /* global warning. ufst state structure passed to each ufst function */ IF_STATE IFS; PIF_STATE pIFS = &IFS; - /* GLOBAL Warning! NB fix me */ /* * fco and plugin handles which must be freed when the interpreter shuts down @@ -56,7 +54,6 @@ static bool plugins_opened = false; /* NB fixme - we might as well require an environment variable for the fco names and plugins, these change every UFST release */ - /* defaults for locations of font collection objects (fco's) and plugins the root data directory. These are internally separated with ':' but environment variable use the gp separator */ @@ -71,7 +68,7 @@ const char *UFSTPLUGINS="mtfonts/pcl45/mt3/plug__xi.fco"; /* return a null terminated array of strings on the heap from str0:str1:str:. Use gs separator */ -static +static char **build_strs(gs_memory_t *mem, char *str, char separator) { int i; @@ -90,7 +87,7 @@ char **build_strs(gs_memory_t *mem, char *str, char separator) /* reallocate the list that holds the string pointers */ if ( i == 0 ) /* first time */ - list = + list = (char **)gs_alloc_bytes(mem, ((i+1) + 1) /* terminating null */ * sizeof(char *), "build_strs"); @@ -107,10 +104,10 @@ char **build_strs(gs_memory_t *mem, char *str, char separator) /* terminate the list of strings */ list[i + 1] = (char *)NULL; /* allocate space for the string */ - list[i] = gs_alloc_bytes(mem, + list[i] = gs_alloc_bytes(mem, end_path - start_path + 1 /* NULL term */, "build_strs"); - + if ( list[i] == NULL ) { /* NB no fall back or freeing of memory already consumed */ dprintf("Fatal System Failure\n" ); @@ -148,7 +145,6 @@ free_strs(gs_memory_t *mem, char **str_of_strs) #define MAXPATHLEN 1024 - /* these are lists of fco's and plugins relative to the root directory they can be set by an environment variable or defaults. */ static char ** @@ -190,8 +186,8 @@ pl_check_fonts(pl_dict_t *pfontdict, bool use_unicode_names_for_keys) &value, true, NULL) /* return data ignored */ ) { int i; dprintf("Font with unicode key: "); - for (i = 0; - i < sizeof(resident_table[j].unicode_fontname)/sizeof(resident_table[j].unicode_fontname[0]); + for (i = 0; + i < sizeof(resident_table[j].unicode_fontname)/sizeof(resident_table[j].unicode_fontname[0]); i++) { dprintf1("%c", (char)resident_table[j].unicode_fontname[i]); } @@ -215,7 +211,7 @@ pl_check_fonts(pl_dict_t *pfontdict, bool use_unicode_names_for_keys) int pl_load_built_in_fonts(const char *pathname, gs_memory_t *mem, pl_dict_t *pfontdict, - gs_font_dir *pdir, int storage, bool use_unicode_names_for_keys) + gs_font_dir *pdir, int storage, bool use_unicode_names_for_keys) { int i, k; UW16 bSize, status = 0; @@ -226,7 +222,7 @@ pl_load_built_in_fonts(const char *pathname, gs_memory_t *mem, pl_dict_t *pfontd char **plugins; /* don't load fonts more than once */ if (pl_dict_length(pfontdict, true) > 0) - return true; + return true; pl_ufst_root_dir(ufst_root_dir, sizeof(ufst_root_dir)); @@ -234,7 +230,7 @@ pl_load_built_in_fonts(const char *pathname, gs_memory_t *mem, pl_dict_t *pfontd if (!plugins_opened) { - gx_UFST_close_static_fcos(); + gx_UFST_close_static_fcos(); plugins = pl_ufst_get_list(mem, "UFSTPLUGINS", UFSTPLUGINS); for (k = 0; plugins[k]; k++) { strcpy((char *)pthnm, ufst_root_dir); @@ -265,15 +261,15 @@ pl_load_built_in_fonts(const char *pathname, gs_memory_t *mem, pl_dict_t *pfontd */ fcos = pl_ufst_get_list(mem, "UFSTFCOS", UFSTFCOS); for (k = 0; fcos[k]; k++) { - SW16 fcoHandle; + SW16 fcoHandle; /* build and open (get handle) for the k'th fco file name */ strcpy((char *)pthnm, ufst_root_dir); strcat((char *)pthnm, fcos[k]); - - fcoHandle = gx_UFST_find_fco_handle_by_name(pthnm); - if (fcoHandle == 0 && - (status = gx_UFST_open_static_fco(pthnm, &fcoHandle)) != 0) { + fcoHandle = gx_UFST_find_fco_handle_by_name(pthnm); + + if (fcoHandle == 0 && + (status = gx_UFST_open_static_fco(pthnm, &fcoHandle)) != 0) { dprintf2("CGIFfco_Open error %d for %s\n", status, pthnm); continue; } @@ -324,7 +320,7 @@ pl_load_built_in_fonts(const char *pathname, gs_memory_t *mem, pl_dict_t *pfontd #endif /* Record the differing points per inch value for Intellifont derived fonts. */ - + if (pfDesc->scaleFactor == 8782) { plfont->pts_per_inch = 72.307; pitch_cp = (pfDesc->spaceBand * 100 * 72.0) @@ -372,9 +368,9 @@ pl_load_built_in_fonts(const char *pathname, gs_memory_t *mem, pl_dict_t *pfontd #endif return TRUE; } - + int -pl_load_ufst_lineprinter(gs_memory_t *mem, pl_dict_t *pfontdict, gs_font_dir *pdir, +pl_load_ufst_lineprinter(gs_memory_t *mem, pl_dict_t *pfontdict, gs_font_dir *pdir, int storage, bool use_unicode_names_for_keys) { int i; @@ -392,12 +388,11 @@ pl_load_ufst_lineprinter(gs_memory_t *mem, pl_dict_t *pfontdict, gs_font_dir *pd return -1; if (pl_fill_in_font(pfont, pplfont, pdir, mem, "lineprinter fonts") < 0) return -1; - + pl_fill_in_bitmap_font(pfont, gs_next_ids(mem, 1)); pplfont->params = resident_table[i].params; memcpy(pplfont->character_complement, resident_table[i].character_complement, 8); - if ( use_unicode_names_for_keys ) pl_dict_put(pfontdict, resident_table[i].unicode_fontname, 32, pplfont ); else { @@ -414,13 +409,13 @@ pl_load_ufst_lineprinter(gs_memory_t *mem, pl_dict_t *pfontdict, gs_font_dir *pd pplfont->is_xl_format = false; pplfont->resolution.x = pplfont->resolution.y = 300; - code = pl_font_alloc_glyph_table(pplfont, 256, mem, + code = pl_font_alloc_glyph_table(pplfont, 256, mem, "pl_load_ufst_lineprinter pplfont (glyph table)"); if ( code < 0 ) return code; while (1) { - + uint width = pl_get_uint16(char_data + 12); uint height = pl_get_uint16(char_data + 14); uint ccode_plus_header_plus_data = 2 + 16 + (((width + 7) >> 3) * height); diff --git a/pl/plvocab.c b/pl/plvocab.c index 471a17285..9d68636a9 100644 --- a/pl/plvocab.c +++ b/pl/plvocab.c @@ -234,7 +234,7 @@ static const pl_glyph_mapping_t pl_map_m2u[] = { {206, 0x2666}, /* Solid Diamond */ {207, 0x2663}, /* Solid Club */ {208, 0x2660}, /* Solid Spade */ - {209, 0x2022}, /* Medium Solid Bullet */ /* (PC), 0x25CF (other) */ + {209, 0x2022}, /* Medium Solid Bullet */ /* (PC), 0x25CF (other) */ {210, 0x25D8}, /* Large Solid Sq/Open Dot */ {211, 0x25CB}, /* Large Open Bullet */ /* (PC only) */ {212, 0x25D9}, /* Large Solid Sq/Open Ring */ @@ -344,7 +344,7 @@ static const pl_glyph_mapping_t pl_map_m2u[] = { {317, 0x02CA}, /* Uppercase Acute */ {318, 0x02CB}, /* Uppercase Grave */ {319, 0x02C6}, /* Uppercase Circumflex */ - {320, 0x00A8}, /* Uppercase Dieresis */ + {320, 0x00A8}, /* Uppercase Dieresis */ {321, 0x02DC}, /* Uppercase Tilde */ {322, 0x02C7}, /* Uppercase Hacek */ {323, 0x02DA}, /* Uppercase Ring */ @@ -500,7 +500,7 @@ static const pl_glyph_mapping_t pl_map_m2u[] = { {555, 0x21D5}, /* Up/Dn Arrow Dbl Stroke */ {556, 0x21D4}, /* Lft/Rt Arrow Dbl Stroke */ {557, 0x21C4}, /* Right Over Left Arrow */ - {558, 0x21C6}, /* Left Over Right Arrow */ + {558, 0x21C6}, /* Left Over Right Arrow */ {559, 0xEFE9}, /* Vector Symbol */ {560, 0xEFEA}, /* Overline, Composite */ {561, 0x2200}, /* For All Symbol */ @@ -641,7 +641,7 @@ static const pl_glyph_mapping_t pl_map_m2u[] = { {1036, 0x211E}, /* Prescription Sign */ {1040, 0xF001}, /* Lowercase FI Ligature */ /* u */ {1041, 0xF002}, /* Lowercase FL Ligature */ /* u */ - {1042, 0xFB00}, /* Lowercase FF Ligature */ + {1042, 0xFB00}, /* Lowercase FF Ligature */ {1043, 0xFB03}, /* Lowercase FFI Ligature */ {1044, 0xFB04}, /* Lowercase ffl Ligature */ {1045, 0x02DD}, /* Uppercase Dbl Acute */ @@ -1157,7 +1157,7 @@ static const pl_glyph_mapping_t pl_map_u2m[] = { {0x0143, 446}, /* Nacute */ {0x0144, 447}, /* nacute */ {0x0145, 450}, /* Ncomma (NEW) */ - {0x0146, 451}, /* ncomma (NEW) */ + {0x0146, 451}, /* ncomma (NEW) */ {0x0147, 448}, /* Ncaron */ {0x0148, 449}, /* ncaron */ {0x0149, 309}, /* apostrophe_n */ @@ -1679,7 +1679,6 @@ static const pl_glyph_mapping_t pl_map_u2m[] = { {0x27BD, 2104}, /* a190 */ {0x27BE, 2212}, /* a191 */ - {0x301A, 643}, /* (NEW) */ {0x301B, 645}, /* (NEW) */ @@ -1769,7 +1768,6 @@ static const pl_glyph_mapping_t pl_map_u2m[] = { {0xEFFC, 653}, /* (NEW) */ {0xEFFD, 211}, /* (NEW) */ - {0xEFFE, 640}, /* (NEW) */ {0xEFFF, 623}, /* (NEW) */ |