⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gvcdisp.c

📁 GSview 4.6 PostScript previewer。Ghostscript在MS-Windows, OS/2 and Unix下的图形化接口
💻 C
📖 第 1 页 / 共 3 页
字号:
    if (line) {        load_string_a(IDS_DSC_LINEFMT, linefmt, sizeof(linefmt));        sprintf(p, linefmt, title, dsc->line_count);	strcat(p, "\n   ");	len = strlen(p);	count = min((int)line_len, MSGBUFLEN-len-2);	strncpy(p+len, line, count);        p[len+count] = '\0';    }    else {	strcpy(p, title);	strcat(p, "\n");    }    len = strlen(p);    load_string_a(CDSC_RESOURCE_BASE+(explanation*4), p+len, 4096-len);    len = strlen(p);    load_string_a(CDSC_RESOURCE_BASE+(explanation*4)+1, p+len, 4096-len);    len = strlen(p);    load_string_a(CDSC_RESOURCE_BASE+(explanation*4)+2, p+len, 4096-len);        response = get_dsc_response(p);    free(p);    if (dsc->debug_print_fn) {	switch (response) {	    case CDSC_RESPONSE_OK:		dsc_debug_print(dsc, "Response = OK\n");		break;	    case CDSC_RESPONSE_CANCEL:		dsc_debug_print(dsc, "Response = Cancel\n");		break;	    case CDSC_RESPONSE_IGNORE_ALL:		dsc_debug_print(dsc, "Response = Ignore All DSC\n");		break;	}    }    return response;}void dsc_addmess(void *caller_data, const char *str){    gs_addmess(str);}/* scan file for PostScript Document Structuring Conventions *//* return FALSE if error *//* On return, psf->dsc is non-zero if DSC */BOOLdsc_scan(PSFILE *psf){char line[MAXSTR];unsigned long file_length;CDSC *dsc = NULL;	if (psf->file) {	    message_box(TEXT("dsc_scan: file is open but shouldn't be"), 0);	    gfile_close(psf->file);	    psf->file = NULL;	}	if (psf->locked) {	    TCHAR buf[MAXSTR];	    load_string(IDS_DEBUG_DFISLOCKED, buf, sizeof(buf));	    message_box(buf, 0);	    return FALSE;	}	psf->locked = TRUE;	/* stop others using it */	if ( (psf->file = gfile_open(psf->name, gfile_modeRead)) == NULL) {	    char buf[MAXSTR+MAXSTR];	    sprintf(buf, "File '%.200s' does not exist", psf->name);	    message_box_a(buf, 0);	    psf->locked = FALSE;	    return FALSE;	}	/* these shouldn't be needed */	if (psf->page_list.select)	    free(psf->page_list.select);	psf->page_list.select = NULL;	if (psf->dsc)	    dsc_free(psf->dsc);	psf->preview = 0;		/* get first line to look for magic numbers */	gfile_read(psf->file, line, sizeof(line)-1);	gfile_seek(psf->file, 0, gfile_begin);#ifndef VIEWONLY	/* check for gzip */	psf->gzip = FALSE;	psf->bzip2 = FALSE;	if ( (line[0]=='\037') && (line[1]=='\213') ) { /* 1F 8B */	    psf->gzip = TRUE;	    gfile_close(psf->file);	    psf->file = NULL;	    if (!dsc_gunzip(psf)) {/* ENGLISH */		message_box(TEXT("Failed to gunzip file"), 0);		psf->locked = FALSE;		return FALSE;	    }	    if ( (psf->file = gfile_open(psfile_name(psf), gfile_modeRead)) 		== NULL) {		char buf[MAXSTR+MAXSTR];		sprintf(buf, "File '%.200s' does not exist", psfile_name(psf));		message_box_a(buf, 0);		psf->locked = FALSE;		return FALSE;	    }	    gfile_read(psf->file, line, sizeof(line)-1);	    gfile_seek(psf->file, 0, gfile_begin);	}	/* check for bzip2 */	if ( (line[0]=='B') && (line[1]=='Z') && (line[2]=='h')) { /* "BZh */	    psf->bzip2 = TRUE;	    gfile_close(psf->file);	    psf->file = NULL;#if defined(_Windows) || defined(UNIX)	    if (!dsc_bunzip2(psf)) {/* ENGLISH */		message_box(TEXT("Failed to uncompress bzip2 file"), 0);		psf->locked = FALSE;		return FALSE;	    }#else	    message_box(TEXT("This is a bzip2 file.  Please uncompress it first."), 0);	    psf->locked = FALSE;	    return FALSE;#endif	    if ( (psf->file = gfile_open(psfile_name(psf), gfile_modeRead)) 		== NULL) {		char buf[MAXSTR+MAXSTR];		sprintf(buf, "File '%.200s' does not exist", psfile_name(psf));		message_box_a(buf, 0);		psf->locked = FALSE;		return FALSE;	    }	    gfile_read(psf->file, line, sizeof(line)-1);	    gfile_seek(psf->file, 0, gfile_begin);	}#endif /* !VIEWONLY */	/* save file date and length */	psf->length = gfile_get_length(psf->file);	gfile_get_datetime(psf->file, &psf->filetimel, &psf->filetimeh);	/* check for PDF */	psf->ispdf = FALSE;	if ( strncmp("%PDF-", line, 5) == 0 ) {	    gfile_close(psf->file);	    psf->file = NULL;	    psf->locked = FALSE;	    psf->ispdf = TRUE;	    return TRUE;	/* we don't know how many pages yet */	}	/* check for PCL */	if ((line[0]=='\033') && (line[1]=='E') && (line[2]=='\033')) {	    TCHAR buf[MAXSTR];	    load_string(IDS_PROBABLY_PCL, buf, sizeof(buf));	    if (message_box(buf, MB_ICONEXCLAMATION | MB_YESNO) != IDYES) {		gfile_close(psf->file);		psf->file = NULL;		psf->locked = FALSE;		return FALSE;	    }	}	/* check for documents that start with Ctrl-D */	psf->ctrld = (line[0] == '\004');	/* check for HP LaserJet prologue */	psf->pjl = FALSE;	if (strncmp("\033%-12345X", line, 9) == 0)	    psf->pjl = TRUE;	if (option.ignore_dsc)	    psf->dsc = (CDSC *)NULL;	else  {	    int code = 0;	    int count;	    char *d;	    psf->dsc = NULL;	    if ( (d = (char *) malloc(COPY_BUF_SIZE)) == NULL)		return FALSE;   	    gfile_seek(psf->file, 0, gfile_begin);	    psf->dsc = dsc_init(NULL);	    dsc_set_debug_function(psf->dsc, dsc_addmess);	    dsc_set_error_function(psf->dsc, show_dsc_error);	    dsc_set_length(psf->dsc, gfile_get_length(psf->file));	    while ((count = gfile_read(psf->file, d, COPY_BUF_SIZE))!=0) {		code = dsc_scan_data(psf->dsc, d, count);	 	if ((code == CDSC_ERROR) || (code == CDSC_NOTDSC)) {		    /* not DSC or an error */		    break;		}	    }	    free(d);	    d = NULL;	    if ((code == CDSC_ERROR) || (code == CDSC_NOTDSC)) {		dsc_free(psf->dsc);		psf->dsc = NULL;	    }	    else {		dsc_fixup(psf->dsc);		if (debug & DEBUG_GENERAL)		    dsc_display(psf->dsc, dsc_addmess);	    }	}	file_length = gfile_get_length(psf->file);	gfile_close(psf->file);	psf->file = NULL;	psf->locked = FALSE;	/* check for DSC comments */	dsc = psf->dsc;	if (dsc == (CDSC *)NULL)	    return TRUE;	/* OK, but not DSC */	if (dsc->doseps) {	    BOOL bad_header = FALSE;	    /* check what sort of preview is present */	    if (dsc->doseps->tiff_begin)		psf->preview = IDS_EPST;	    if (dsc->doseps->wmf_begin)		psf->preview = IDS_EPSW;	    /* check for errors in header */	    if (dsc->doseps->ps_begin > file_length)		bad_header = TRUE;	    if (dsc->doseps->ps_begin + dsc->doseps->ps_length > file_length)		bad_header = TRUE;	    if (dsc->doseps->wmf_begin > file_length)		bad_header = TRUE;	    if (dsc->doseps->wmf_begin + dsc->doseps->wmf_length > file_length)		bad_header = TRUE;	    if (dsc->doseps->tiff_begin > file_length)		bad_header = TRUE;	    if (dsc->doseps->tiff_begin + dsc->doseps->tiff_length > file_length)		bad_header = TRUE;	    if (bad_header) {		TCHAR buf[MAXSTR];	        load_string(IDS_BAD_DOSEPS_HEADER, buf, sizeof(buf));	        message_box(buf, 0);		/* Ignore the bad information */		dsc_free(psf->dsc);		psf->dsc = (CDSC *)NULL;		return FALSE;	    }	}	if (!psf->preview && (dsc->beginpreview != dsc->endpreview))	    psf->preview = IDS_EPSI;	if (dsc->page_count) {	    psf->page_list.select = 		(BOOL *)malloc(dsc->page_count * sizeof(BOOL));	    if (psf->page_list.select)	        memset(psf->page_list.select, 0, 			dsc->page_count * sizeof(BOOL));	}	if (dsc->epsf) {	    /* warn if bounding box off the page */	    int width, height;	    width = get_paper_width();	    height = get_paper_height();	    if ( !option.epsf_clip &&		(dsc->bbox != (CDSCBBOX *)NULL) &&	        ((dsc->bbox->llx > width) || 		 (dsc->bbox->lly > height) ||	         (dsc->bbox->urx < 0) || 		 (dsc->bbox->ury < 0)) )	    {		TCHAR buf[MAXSTR];	        load_string(IDS_EPS_OFF_PAGE, buf, sizeof(buf));	        message_box(buf, 0);	    }	    if ( option.epsf_clip && 		((dsc->bbox == (CDSCBBOX *)NULL) || 		 (dsc->bbox->llx > dsc->bbox->urx) || 		 (dsc->bbox->lly > dsc->bbox->ury))	       )	    {		TCHAR buf[MAXSTR];	        load_string(IDS_EPS_BAD_BBOX, buf, sizeof(buf));	        message_box(buf, 0);	    }	}	if (debug)	    dsc_dump(psf);	return TRUE;}/* reverse zero based page number if needed */intmap_page(int page){    if (psfile.dsc != (CDSC *)NULL)        if (psfile.dsc->page_order == CDSC_DESCEND) 	    return (psfile.dsc->page_count - 1) - page;    return page;}/* Generate string for page list box, as either *   ordinal *   ordinal    "label" */voidpage_ordlabel(char *buf, int page_number){    const char *label;    int ordinal;    label = psfile.dsc->page[map_page(page_number)].label;    ordinal = psfile.dsc->page[map_page(page_number)].ordinal;    sprintf(buf, "%d", ordinal);    if (strcmp(buf, label) != 0) {	/* label and ordinal don't match, so use composite */	sprintf(buf, "%d  \042%s\042", ordinal, label);    }}voidpsfile_free(PSFILE *psf){    if (psf == (PSFILE *)NULL)	return;    psf->name[0] = '\0';    /* same as dfclose() */    if (psf->file)	gfile_close(psf->file);    psf->file = NULL;    psf->locked = FALSE;    if ((psf->tname[0] != '\0') && (!debug))	unlink(psf->tname);    psf->tname[0] = '\0';    if (psf->page_list.select)	free(psf->page_list.select);    psf->page_list.select = NULL;    if (psf->dsc)	dsc_free(psf->dsc);    psf->dsc = (CDSC *)NULL;#ifndef VIEWONLY    if (psf->text_name) {	if (!debug)	    unlink(psf->text_name);        psf->text_name[0] = '\0';	free_text_index();    }#endif}char *psfile_name(PSFILE *psf){    /* if original file was gzipped, give name of gunzipped file */    if ((psf->tname[0]!='\0') && ((psf->gzip) || psf->bzip2))	return psf->tname;    /* otherwise return original file name */    return psf->name;}/* #define DEBUG_HISTORY */#ifdef DEBUG_HISTORYvoid history_debug(void){char buf[256];int i;    gs_addmess("history_debug: ");    for (i=0; i<history.count; i++) {	if (i == history.index)	    gs_addmess("[");        sprintf(buf, "%d", history.pages[i]);	gs_addmess(buf);	if (i == history.index)	    gs_addmess("]");	gs_addmess(" ");    }    gs_addmess("\n");}#define HISTORY_DEBUG history_debug()#else#define HISTORY_DEBUG#endifvoidhistory_add(int pagenum){    /* scroll if history full */    if (history.index >= HISTORY_MAX) {	memmove(&history.pages[0], &history.pages[1],  	    (HISTORY_MAX-1)*sizeof(history.pages[0]));	history.index--;	history.count = history.index;    }    if ((history.index > 1) && (history.pages[history.index -1] == pagenum)) {	/* Don't insert duplicate page */	return;    }    if (history.pages[history.index] != pagenum) {	/* If we are following a different path to last time,	 * truncate history	 */ 	history.count = history.index;    }    history.pages[history.index] = pagenum;    history.index++;    if (history.index > history.count)	history.count = history.index;    HISTORY_DEBUG;}voidhistory_reset(void){    history.index = history.count = 0;    HISTORY_DEBUG;}voidhistory_back(void){    if (history.index < 2)	return;	/* can't do anything */    history.index--;	/* point to current page */    request_mutex();    pending.pagenum = history.pages[history.index - 1];    if (pending.pagenum > (int)psfile.dsc->page_count)	 pending.pagenum = psfile.dsc->page_count;    if (pending.pagenum < 1)	pending.pagenum = 1;    gsview_unzoom();    pending.now = TRUE;    release_mutex();    HISTORY_DEBUG;}voidhistory_forward(void){    if (history.index >= history.count) {	gs_page_skip(1);	return;    }    request_mutex();    pending.pagenum = history.pages[history.index];    if (pending.pagenum > (int)psfile.dsc->page_count)	 pending.pagenum = psfile.dsc->page_count;    if (pending.pagenum < 1)	pending.pagenum = 1;    gsview_unzoom();    pending.now = TRUE;    release_mutex();    history.index++;    HISTORY_DEBUG;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -