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

📄 gvcmisc.c

📁 GSview 4.6 PostScript previewer。Ghostscript在MS-Windows, OS/2 and Unix下的图形化接口
💻 C
📖 第 1 页 / 共 2 页
字号:
/* 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.
*/

/* gvcmisc.c */
/* Miscellaneous GSview routines common to Windows and PM */

#include "gvc.h"

int read_usermedia_profile(PROFILE *prf);

/* returns error code from GS */
void
gs_addmessf(const char *fmt, ...)
{
va_list args;
int count;
char buf[1024];
	va_start(args,fmt);
	count = vsprintf(buf,fmt,args);
        gs_addmess(buf);
	va_end(args);
}

void
make_cwd(const char *filename)
{
    char temp[MAXSTR];
    int i;
    strncpy(temp, filename, sizeof(temp)-1);
    for (i=strlen(temp)-1; i>=0; i--) {
	if ((temp[i]=='\\') || (temp[i]=='/'))
	    break;
    }
    
    if (i > 0) {
	temp[i] = '\0';
	gs_chdir(temp);
    }
    else {
	if (strlen(temp) > 2) {
	    if (isalpha((int)(temp[0])) && (temp[1]==':')) {
		temp[2] = '\0';
		gs_chdir(temp);
	    }
	}
    }
}


/* display error message and exit Ghostscript message */
void 
error_message(char *str)
{
    message_box_a(str, MB_ICONHAND);
    post_img_message(WM_CLOSE, 0);
}

#if defined(_Windows) || defined(OS2)
void
info_init(HWND hwnd)
{
    CDSC *dsc = psfile.dsc;
    char buf[MAXSTR];
    TCHAR wbuf[MAXSTR];
    TCHAR *p;
    int n;
    if (psfile.name[0] != '\0') {
	SetDlgItemTextA(hwnd, INFO_FILE, psfile.name);
	if (dsc) {
	    p = wbuf;
	    *p = '\0';
	    if (psfile.gzip) {
		lstrcpy(p, TEXT("gzip "));
	        p += lstrlen(p);
	    }
	    if (psfile.bzip2) {
		lstrcpy(p, TEXT("bzip2 "));
	        p += lstrlen(p);
	    }
	    if (psfile.ctrld)
		load_string(IDS_CTRLD, p, sizeof(wbuf)/sizeof(TCHAR)-1);
	    if (psfile.pjl)
		load_string(IDS_PJL, p, sizeof(wbuf)/sizeof(TCHAR)-1);
	    p += lstrlen(p);
	    if (psfile.ispdf) {
		load_string(IDS_PDF, p, 
			sizeof(wbuf)/sizeof(TCHAR)-1-lstrlen(wbuf));
	    }
	    else if (dsc->epsf) {
		switch (psfile.preview) {
		    case IDS_EPSI:
		      load_string(IDS_EPSI, p, 
			sizeof(wbuf)/sizeof(TCHAR)-1-lstrlen(wbuf));
		      break;
		    case IDS_EPST:
		      load_string(IDS_EPST, p, 
			sizeof(wbuf)/sizeof(TCHAR)-1-lstrlen(wbuf));
		      break;
		    case IDS_EPSW:
		      load_string(IDS_EPSW, p, 
			sizeof(wbuf)/sizeof(TCHAR)-1-lstrlen(wbuf));
		      break;
		    default:
		      load_string(IDS_EPSF, p, 
			sizeof(wbuf)/sizeof(TCHAR)-1-lstrlen(wbuf));
		}
	    }
	    else
		load_string(IDS_DSC, p, 
		    sizeof(wbuf)/sizeof(TCHAR)-1-lstrlen(wbuf));
	    SetDlgItemText(hwnd, INFO_TYPE, wbuf);
	    SetDlgItemTextA(hwnd, INFO_TITLE, 
		dsc->dsc_title ? dsc->dsc_title : "");
	    SetDlgItemTextA(hwnd, INFO_DATE, 
		dsc->dsc_date ? dsc->dsc_date : "");
	    if (dsc->bbox)
		sprintf(buf, "%d %d %d %d", dsc->bbox->llx, dsc->bbox->lly, 
		    dsc->bbox->urx, dsc->bbox->ury);
	    else
		buf[0]='\0';
	    SetDlgItemTextA(hwnd, INFO_BBOX, buf);
	    switch(dsc->page_orientation) {
		case CDSC_LANDSCAPE:
			load_string(IDS_LANDSCAPE, wbuf, 
			    sizeof(wbuf)/sizeof(TCHAR)-1);
			break;
		case CDSC_PORTRAIT:
			load_string(IDS_PORTRAIT, wbuf, 
			    sizeof(wbuf)/sizeof(TCHAR)-1);
			break;
		default:
			wbuf[0] = '\0';
	    }
	    SetDlgItemText(hwnd, INFO_ORIENT, wbuf);
	    switch(dsc->page_order) {
		case CDSC_ASCEND: 
			load_string(IDS_ASCEND, wbuf, 
			    sizeof(wbuf)/sizeof(TCHAR)-1);
			break;
		case CDSC_DESCEND: 
			load_string(IDS_DESCEND, wbuf, 
			    sizeof(wbuf)/sizeof(TCHAR)-1);
			break;
		case CDSC_SPECIAL:
			load_string(IDS_SPECIAL, wbuf, 
			    sizeof(wbuf)/sizeof(TCHAR)-1);
			break;
		default:
			wbuf[0] = '\0';
	    }
	    SetDlgItemText(hwnd, INFO_ORDER, wbuf);
	    if (dsc->page_media && dsc->page_media->name) {
		sprintf(buf,"%.200s %g %g",dsc->page_media->name,
		    dsc->page_media->width, dsc->page_media->height);
	    }
	    else {
		buf[0] = '\0';
	    }
	    SetDlgItemTextA(hwnd, INFO_DEFMEDIA, buf);
	    sprintf(buf, "%d", dsc->page_count);
	    SetDlgItemTextA(hwnd, INFO_NUMPAGES, buf);
	    n = map_page(psfile.pagenum - 1);
	    if (dsc->page_count)
		    sprintf(buf, "\"%.200s\"   %d", dsc->page[n].label ? dsc->page[n].label : "", psfile.pagenum);
	    else
		    buf[0] = '\0';
	    SetDlgItemTextA(hwnd, INFO_PAGE, buf);
	
	}
	else {
	    if (option.ignore_dsc)
	        load_string(IDS_IGNOREDSC, wbuf, sizeof(wbuf)/sizeof(TCHAR)-1);
	    else
	        load_string(IDS_NOTDSC, wbuf, sizeof(wbuf)/sizeof(TCHAR)-1);
	    SetDlgItemText(hwnd, INFO_TYPE, wbuf);
	}
	sprintf(buf, "%d x %d", view.img->width, view.img->height);
	SetDlgItemTextA(hwnd, INFO_BITMAP, buf);
    }
    else {
	load_string(IDS_NOFILE, wbuf, sizeof(wbuf)/sizeof(TCHAR)-1);
	SetDlgItemText(hwnd, INFO_FILE, wbuf);
    }
}
#endif

int
read_usermedia_profile(PROFILE *prf)
{
    const char *section = "UserMedia";
    char *entries, *p;
    int i, numentry;
    int width, height;
    char buf[MAXSTR];
    entries = (char *)malloc(PROFILE_SIZE);
    if (entries == (char *)NULL)
       return 0;
    profile_read_string(prf, section, NULL, "", entries, PROFILE_SIZE);
    p = entries;
    for (numentry=0; p!=(char *)NULL && strlen(p)!=0; numentry++)
	p += strlen(p) + 1;
    numentry = min(numentry, (int)(sizeof(usermedia)/sizeof(USERMEDIA)));
    p = entries;
    for (i=0; i<numentry; i++) {
	profile_read_string(prf, section, p, "", buf, sizeof(buf));
	if (sscanf(buf, "%d,%d", &width, &height) == 2) {
	    strncpy(usermedia[i].name, p, sizeof(usermedia[i].name)-1);
	    usermedia[i].id = i + IDM_USERSIZE1;
	    usermedia[i].width = width;
	    usermedia[i].height = height;
	}
	p += strlen(p) + 1;
    }
    free(entries);
    return numentry;
}


/* read settings fron INI file */
void
read_profile(const char *ininame)
{
int i, j;
char profile[MAXSTR];
const char *section = INISECTION;
char secver[MAXSTR];
PROFILE *prf;
    if (debug & DEBUG_GENERAL)
	gs_addmessf("Reading profile \042%s\042\n", ininame);
    prf = profile_open(ininame);

    /* GSview-N.N */
    sprintf(secver, "GSview-%s", GSVIEW_DOT_VERSION);
    profile_read_string(prf, secver, "Configured", "", profile, sizeof(profile));
    if (sscanf(profile,"%d", &i) == 1)
	option.configured = i;
    else
	option.configured = FALSE;
    profile_read_string(prf, secver, "GSversion", "", profile, sizeof(profile));
    if (sscanf(profile,"%d", &i) == 1)
	option.gsversion = i;
    else
	option.gsversion = GS_REVISION;
    if ( (option.gsversion < GS_REVISION_MIN) ||
	 (option.gsversion > GS_REVISION_MAX) )
	option.gsversion = GS_REVISION;
    profile_read_string(prf, secver, "Version", "", profile, sizeof(profile));
    if (strcmp(profile, GSVIEW_DOT_VERSION)!=0)
	option.configured = FALSE;
    profile_read_string(prf, secver, "GhostscriptDLL", "", profile, sizeof(profile));
    if (profile[0] != '\0')	/* don't copy a default - assume already set */
	    strncpy(option.gsdll, profile, MAXSTR-1);
    profile_read_string(prf, secver, "GhostscriptEXE", "", profile, sizeof(profile));
    if (profile[0] != '\0')	/* don't copy a default - assume already set */
	    strncpy(option.gsexe, profile, MAXSTR-1);
    profile_read_string(prf, secver, "GhostscriptInclude", "", profile, sizeof(profile));
    if (profile[0] != '\0')	/* don't copy a default - assume already set */
	    strncpy(option.gsinclude, profile, MAXSTR-1);
    profile_read_string(prf, secver, "GhostscriptOther", "", profile, sizeof(profile));
    if (profile[0] != '\0')	/* don't copy a default - assume already set */
	    strncpy(option.gsother, profile, MAXSTR-1);

    /* Options */
    profile_read_string(prf, section, "Language", "", profile, sizeof(profile));
    option.language = language_id(profile);
    if (option.language == 0)
	option.language = IDM_LANGEN;
    profile_read_string(prf, section, "HelpCmd", "", profile, sizeof(profile));
    if (profile[0] != '\0')	/* don't copy a default - assume already set */
	    strncpy(option.helpcmd, profile, MAXSTR-1);
    profile_read_string(prf, section, "Origin", "", profile, sizeof(profile));
    option.img_origin.x = option.img_origin.y = CW_USEDEFAULT;
    if (sscanf(profile,"%d %d", &i, &j) == 2) {
	    option.img_origin.x = i;
	    option.img_origin.y = j;
    }
    profile_read_string(prf, section, "Size", "", profile, sizeof(profile));
    option.img_size.x = option.img_size.y = CW_USEDEFAULT;
    if (sscanf(profile,"%d %d", &i, &j) == 2) {
	    option.img_size.x = i;
	    option.img_size.y = j;
    }
    if ((option.img_size.x<32) || (option.img_size.y<32))
	    option.img_size.x = option.img_size.y = CW_USEDEFAULT;
    profile_read_string(prf, section, "Maximized", "", profile, sizeof(profile));
    option.img_max = 0;
    if (sscanf(profile,"%d", &i) == 1)
	    option.img_max = i;
    profile_read_string(prf, section, "SaveSettings", "", profile, sizeof(profile));
    if (sscanf(profile,"%d", &i) == 1)
	    option.settings = i;
    profile_read_string(prf, section, "ButtonBar", "", profile, sizeof(profile));
    if (sscanf(profile,"%d", &i) == 1)
	    option.button_show = i;
    profile_read_string(prf, section, "FitWindowToPage", "", profile, sizeof(profile));
    if (sscanf(profile,"%d", &i) == 1)
	    option.fit_page = i;
    profile_read_string(prf, section, "Resolution", "", profile, sizeof(profile));
    if (sscanf(profile,"%f %f", &option.xdpi, &option.ydpi) != 2) {
	    option.xdpi = option.ydpi = DEFAULT_RESOLUTION;
    }
    profile_read_string(prf, section, "ZoomResolution", "", profile, sizeof(profile));
    if (sscanf(profile,"%f %f", &option.zoom_xdpi, &option.zoom_ydpi) != 2) {
	    option.zoom_xdpi = option.zoom_ydpi = DEFAULT_ZOOMRES;
    }
    profile_read_string(prf, section, "Depth", "", profile, sizeof(profile));
    if (sscanf(profile,"%d", &i) == 1)
	    option.depth = i;
    profile_read_string(prf, section, "TextAlphaBits", "", profile, sizeof(profile));
    if (sscanf(profile,"%d", &i) == 1)
	    option.alpha_text = i;
    if (option.alpha_text <= 0)
	    option.alpha_text = 1;
    profile_read_string(prf, section, "GraphicsAlphaBits", "", profile, sizeof(profile));
    if (sscanf(profile,"%d", &i) == 1)
	    option.alpha_graphics = i;
    if (option.alpha_graphics <= 0)
	    option.alpha_graphics = 1;
    profile_read_string(prf, section, "Media", "", profile, sizeof(profile));
    if (strlen(profile)!=0)
	strncpy(option.medianame, profile, sizeof(option.medianame));
    profile_read_string(prf, section, "MediaRotate", "", profile, sizeof(profile));
    if (sscanf(profile,"%d", &i) == 1)
	    option.media_rotate = i;
    profile_read_string(prf, section, "UserSize", "", profile, sizeof(profile));
    if (sscanf(profile,"%d %d", &option.user_width, &option.user_height) != 2) {
	    /* this gives 640x480 pixels at 96dpi */
	    option.user_width = 480;
	    option.user_height = 360;
    }
    gsview_check_usersize();
    profile_read_string(prf, section, "EpsfClip", "", profile, sizeof(profile));
    if (sscanf(profile,"%d", &i) == 1)
	    option.epsf_clip = i;
    profile_read_string(prf, section, "EpsfWarn", "", profile, sizeof(profile));
    if (sscanf(profile,"%d", &i) == 1)
	    option.epsf_warn = i;
    profile_read_string(prf, section, "IgnoreDSC", "", profile, sizeof(profile));
    if (sscanf(profile,"%d", &i) == 1)
	    option.ignore_dsc = i;
    profile_read_string(prf, section, "DSCWarn", "", profile, sizeof(profile));
    if (sscanf(profile,"%d", &i) == 1)
	    option.dsc_warn = i+IDM_DSC_OFF;
    profile_read_string(prf, section, "ShowBBox", "", profile, sizeof(profile));
    if (sscanf(profile,"%d", &i) == 1)
	    option.show_bbox = i;
    profile_read_string(prf, section, "AutoOrientation", "", profile, sizeof(profile));
    if (sscanf(profile,"%d", &i) == 1)
	    option.auto_orientation = i;
    profile_read_string(prf, section, "Orientation", "", profile, sizeof(profile));
    if (sscanf(profile,"%d", &i) == 1)
	    option.orientation = i+IDM_PORTRAIT;
    profile_read_string(prf, section, "SwapLandscape", "", profile, sizeof(profile));
    if (sscanf(profile,"%d", &i) == 1)
	    option.swap_landscape = i;
    profile_read_string(prf, section, "Unit", "", profile, sizeof(profile));
    if (sscanf(profile,"%d", &i) == 1)
	    option.unit = i+IDM_UNITPT;
    if ((option.unit < IDM_UNITPT) || (option.unit > IDM_UNITINCH))
	    option.unit = IDM_UNITPT;
    profile_read_string(prf, section, "UnitFine", "", profile, sizeof(profile));
    if (sscanf(profile,"%d", &i) == 1)
	    option.unitfine = i;
    profile_read_string(prf, section, "PStoText", "", profile, sizeof(profile));
    if (sscanf(profile,"%d", &i) == 1)
	    option.pstotext = i;
    profile_read_string(prf, section, "Safer", "", profile, sizeof(profile));
    if (sscanf(profile,"%d", &i) == 1)
	    option.safer = i;
    profile_read_string(prf, section, "AutoRedisplay", "", profile, sizeof(profile));
    if (sscanf(profile,"%d", &i) == 1)
	    option.redisplay = i;
    profile_read_string(prf, section, "AutoBoundingBox", "", profile, sizeof(profile));
    if (sscanf(profile,"%d", &i) == 1)
	    option.auto_bbox = i;
    profile_read_string(prf, section, "SaveLastDir", "", profile, sizeof(profile));
    if (sscanf(profile,"%d", &i) == 1)
	    option.save_dir = i;

⌨️ 快捷键说明

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