📄 gvcdisp.c
字号:
/* Copyright (C) 1993-2002, Ghostgum Software Pty Ltd. All rights reserved. This file is part of GSview. This program is distributed with NO WARRANTY OF ANY KIND. No author or distributor accepts any responsibility for the consequences of using it, or for whether it serves any particular purpose or works at all, unless he or she says so in writing. Refer to the GSview Licence (the "Licence") for full details. Every copy of GSview must include a copy of the Licence, normally in a plain ASCII text file named LICENCE. The Licence grants you the right to copy, modify and redistribute GSview, but only under certain conditions described in the Licence. Among other things, the Licence requires that the copyright notice and this notice be preserved on all copies.*//* gvcdisp.c *//* Display GSview routines common to Windows and PM */#include "gvc.h"FILE *debug_file;void gs_puts(char *str, FILE *f);void gs_copy(FILE *from, FILE *to, long begin, long end);int get_paper_size_index(void);int get_paper_user_size_index(void);void rotate_last_files(int count);void update_last_files(char *filename);BOOL dsc_gunzip(PSFILE *psf);BOOL dsc_bunzip2(PSFILE *psf);void dsc_dump(PSFILE *psf);int show_dsc_error(void *caller_data, CDSC *dsc, unsigned int explanation, const char *line, unsigned int line_len);voidgs_puts(char *str, FILE *f){ if (str != NULL) { fputs(str, f); if (debug_file != (FILE *)NULL) fputs(str, debug_file); }}void gs_copy(FILE *from, FILE *to, long begin, long end){ char *buf; int count; buf = (char *)malloc(COPY_BUF_SIZE); if (buf == (char *)NULL) return; if (begin >= end) return; if (begin >= 0) fseek(from, begin, SEEK_SET); begin = ftell(from); while (begin < end) { count = min(end-begin, COPY_BUF_SIZE); if ((count = fread(buf, 1, count, from)) > 0) { fwrite(buf, 1, count, to); if (debug_file != (FILE *)NULL) fwrite(buf, 1, count, debug_file); begin += count; } else begin = end; /* EOF or error */ } free(buf);}/* transform cursor position from device coordinates to points *//* taking into account rotated pages */voidtransform_cursorpos(float *x, float *y){ if (zoom) { /* first figure out number of pixels to zoom origin point */ *x = (float)(*x * 72.0/option.xdpi); *y = (float)(*y * 72.0/option.ydpi); transform_point(x,y); *x = (float)(*x * option.xdpi/72); *y = (float)(*y * option.ydpi/72); /* now convert to pts and offset it */ *x = (float)(*x * 72/option.zoom_xdpi + display.zoom_xoffset); *y = (float)(*y * 72/option.zoom_ydpi + display.zoom_yoffset); } else { int xoffset = (int)(display.xoffset * 72.0 / display.xdpi); int yoffset = (int)(display.yoffset * 72.0 / display.ydpi); *x = (float)(*x * 72.0/option.xdpi); *y = (float)(*y * 72.0/option.ydpi); transform_point(x,y); *x = (float)(*x + xoffset); *y = (float)(*y + yoffset); }}/* transform point from coordinates relative to bottom left * corner of paper to bottom left corner of rotated coordinate * system */voidtransform_point(float *x, float *y){float oldx, oldy;int real_orientation;int width, height; oldx = *x; oldy = *y; width = (unsigned int)(display.width * 72.0 / option.xdpi); height = (unsigned int)(display.height * 72.0 / option.ydpi); switch(d_orientation(psfile.pagenum)) { default: case 0: real_orientation = IDM_PORTRAIT; break; case 1: real_orientation = IDM_SEASCAPE; break; case 2: real_orientation = IDM_UPSIDEDOWN; break; case 3: real_orientation = IDM_LANDSCAPE; break; } switch (real_orientation) { case IDM_PORTRAIT: break; case IDM_LANDSCAPE: *x = width - oldy; /* display.width = bitmap.height */ *y = oldx; break; case IDM_UPSIDEDOWN: *x = width - oldx; *y = height - oldy; break; case IDM_SEASCAPE: *x = oldy; *y = height - oldx; break; } return;}/* inverse transform point from coordinates relative * to bottom left corner of rotated coordinate system * to bottom left corner of paper */voiditransform_point(float *x, float *y){float oldx, oldy;int real_orientation;int width, height; oldx = *x; oldy = *y; width = (unsigned int)(display.width * 72.0 / option.xdpi); height = (unsigned int)(display.height * 72.0 / option.ydpi); switch(d_orientation(psfile.pagenum)) { default: case 0: real_orientation = IDM_PORTRAIT; break; case 1: real_orientation = IDM_SEASCAPE; break; case 2: real_orientation = IDM_UPSIDEDOWN; break; case 3: real_orientation = IDM_LANDSCAPE; break; } switch (real_orientation) { case IDM_PORTRAIT: break; case IDM_LANDSCAPE: *y = width - oldx; *x = oldy; break; case IDM_UPSIDEDOWN: *x = width - oldx; *y = height - oldy; break; case IDM_SEASCAPE: *y = oldx; *x = height - oldy; break; } return;}/* calculate depth */intreal_depth(int depth){ if (depth == 0) depth = display.planes * display.bitcount; if (depth > 8) depth = 24; else if (depth >=8) depth = 8; else if (depth >=4) depth = 4; else depth = 1; return depth;}/* get current media index to dsc_known_media[], or -1 if no match */intget_paper_size_index(void){int i; for (i=0; dsc_known_media[i].name != (char *)NULL; i++) { if (!stricmp(dsc_known_media[i].name, option.medianame)) return i; } return -1;}/* get current media index to usermedia, or -1 if no match *//* usermedia is initialised from the INI file */int get_paper_user_size_index(void){int i; for (i=0; i <= (int)(sizeof(usermedia)/sizeof(USERMEDIA)); i++) { if (!stricmp(usermedia[i].name, option.medianame)) return i; } return -1;}int get_paper_width(void){ int width; int i = get_paper_size_index(); if (i < 0) { i = get_paper_user_size_index(); if (i < 0) { if (option.media_rotate) width = option.user_height; else width = option.user_width; } else { if (option.media_rotate) width = (int)usermedia[i].height; else width = (int)usermedia[i].width; } } else { if (option.media_rotate) width = (int)dsc_known_media[i].height; else width = (int)dsc_known_media[i].width; } return width;}int get_paper_height(void){ int height; int i = get_paper_size_index(); if (i < 0) { i = get_paper_user_size_index(); if (i < 0) { if (option.media_rotate) height = option.user_width; else height = option.user_height; } else { if (option.media_rotate) height = (int)usermedia[i].width; else height = (int)usermedia[i].height; } } else { if (option.media_rotate) height = (int)dsc_known_media[i].width; else height = (int)dsc_known_media[i].height; } return height;}/* change the size of the gs image if open */voidgs_resize(void){ pending.resize = TRUE; if ( gsdll.hmodule && (psfile.dsc==(CDSC *)NULL) && (gsdll.state != GS_IDLE) ) /* don't know where we are so close and reopen */ pending.abort = TRUE; if (option.redisplay && (gsdll.state == GS_PAGE)) { if (psfile.dsc != (CDSC *)NULL) pending.now = TRUE; else { pending.abort = TRUE; /* must restart from page 1 */ pending.now = TRUE; } } if (option.redisplay && (gsdll.state == GS_IDLE) && (psfile.dsc != (CDSC *)NULL)) { /* zero page EPS file */ pending.now = TRUE; }}voidgs_magnify(float scale){int xtemp, ytemp; xtemp = (int)(option.xdpi * scale + 0.5); ytemp = (int)(option.ydpi * scale + 0.5); if ( (xtemp == option.xdpi) && (scale > 1.0) ) { option.xdpi++; /* force magnification if requested */ option.ydpi++; } else { option.xdpi = (float)xtemp; option.ydpi = (float)ytemp; } zoom = FALSE; gs_resize();}voidgsview_orientation(int new_orientation){ if (new_orientation == IDM_AUTOORIENT) { check_menu_item(IDM_ORIENTMENU, option.orientation, option.auto_orientation); option.auto_orientation = !option.auto_orientation; check_menu_item(IDM_ORIENTMENU, IDM_AUTOORIENT, option.auto_orientation); zoom = FALSE; gs_resize(); return; } if (option.auto_orientation && (new_orientation != IDM_SWAPLANDSCAPE)) { option.auto_orientation = FALSE; check_menu_item(IDM_ORIENTMENU, IDM_AUTOORIENT, option.auto_orientation); } else if (new_orientation == option.orientation) return; if (new_orientation == IDM_SWAPLANDSCAPE) { option.swap_landscape = !option.swap_landscape; if (option.swap_landscape) check_menu_item(IDM_ORIENTMENU, IDM_SWAPLANDSCAPE, TRUE); else check_menu_item(IDM_ORIENTMENU, IDM_SWAPLANDSCAPE, FALSE); if ((option.orientation != IDM_LANDSCAPE) && (option.orientation != IDM_SEASCAPE) && (option.auto_orientation == FALSE)) return; } else { check_menu_item(IDM_ORIENTMENU, option.orientation, FALSE); option.orientation = new_orientation; check_menu_item(IDM_ORIENTMENU, option.orientation, TRUE); } zoom = FALSE; gs_resize(); return;}voidgsview_media(int new_media){ char *d, *s; if ( (new_media == option.media) && (new_media != IDM_USERSIZE) ) return; check_menu_item(IDM_MEDIAMENU, option.media, FALSE); option.media = new_media; check_menu_item(IDM_MEDIAMENU, option.media, TRUE); get_menu_string(IDM_MEDIAMENU, option.media, option.medianame, sizeof(option.medianame)); for (d=s=option.medianame; *s; s++) { /* Get rid of shortcut characters */ *d = *s; if ((*s != '_') && (*s != '&') && (*s !='~')) d++; } *d = '\0'; gs_resize(); zoom = FALSE; return;}voidgsview_unit(int new_unit){ check_menu_item(IDM_UNITMENU, option.unit, FALSE); option.unit = new_unit; check_menu_item(IDM_UNITMENU, option.unit, TRUE); return;}/* free a PSFILE and contents *//* Do NOT use this if you have just copied PSFILE to psfile */voide_free_psfile(PSFILE *ppsfile){ psfile_free(ppsfile); free(ppsfile);}/* open a new document */PSFILE *gsview_openfile(char *filename){int i;PSFILE *tpsfile; history_reset(); tpsfile = (PSFILE *)malloc(sizeof(PSFILE)); if (tpsfile == NULL) return NULL; memset((char *)tpsfile, 0, sizeof(PSFILE)); strncpy(tpsfile->name, filename, MAXSTR-1); tpsfile->pagenum = 1; info_wait(IDS_WAITREAD); if (dsc_scan(tpsfile)) { if ((tpsfile->dsc != (CDSC *)NULL) && !tpsfile->ispdf){ CDSC *dsc = tpsfile->dsc; /* found DSC comments */ if (dsc->page_media != (CDSCMEDIA *)NULL) { char thismedia[20]; int found = 0; for (i=0; i<(int)(sizeof(usermedia)/sizeof(USERMEDIA)); i++) { if (!stricmp(usermedia[i].name, dsc->page_media->name)) { gsview_media(i+IDM_USERSIZE1); found = 1; break; } } if (!found) { for (i=IDM_MEDIAFIRST; i<IDM_MEDIALAST; i++) { get_menu_string(IDM_MEDIAMENU, i, thismedia, sizeof(thismedia)); if (!stricmp(thismedia, dsc->page_media->name)) { gsview_media(i); found = 1; break; } } } if (!found) { gsview_media(IDM_USERSIZE); option.user_width = (int)dsc->page_media->width; option.user_height = (int)dsc->page_media->height; gsview_check_usersize(); } } } } else { /* failed to open file */ e_free_psfile(tpsfile); info_wait(IDS_NOWAIT); return NULL;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -