Beispiel #1
0
int WINAPI
WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
{
	int argc;
	LPWSTR *wargv = CommandLineToArgvW(GetCommandLineW(), &argc);
	char **argv;
	char argv0[256];
	MSG msg;
	int code;
	fz_context *ctx;
	int bps = 0;
	int displayRes = get_system_dpi();
	int c;
	char *layout_css = NULL;

	ctx = fz_new_context(NULL, NULL, FZ_STORE_DEFAULT);
	if (!ctx)
	{
		fprintf(stderr, "cannot initialise context\n");
		exit(1);
	}
	pdfapp_init(ctx, &gapp);

	argv = fz_argv_from_wargv(argc, wargv);

	while ((c = fz_getopt(argc, argv, "p:r:A:C:W:H:S:U:b:")) != -1)
	{
		switch (c)
		{
		case 'C':
			c = strtol(fz_optarg, NULL, 16);
			gapp.tint = 1;
			gapp.tint_r = (c >> 16) & 255;
			gapp.tint_g = (c >> 8) & 255;
			gapp.tint_b = (c) & 255;
			break;
		case 'p': password = fz_optarg; break;
		case 'r': displayRes = fz_atoi(fz_optarg); break;
		case 'A': fz_set_aa_level(ctx, fz_atoi(fz_optarg)); break;
		case 'W': gapp.layout_w = fz_atoi(fz_optarg); break;
		case 'H': gapp.layout_h = fz_atoi(fz_optarg); break;
		case 'S': gapp.layout_em = fz_atoi(fz_optarg); break;
		case 'b': bps = (fz_optarg && *fz_optarg) ? fz_atoi(fz_optarg) : 4096; break;
		case 'U': layout_css = fz_optarg; break;
		default: usage();
		}
	}

	pdfapp_setresolution(&gapp, displayRes);

	GetModuleFileNameA(NULL, argv0, sizeof argv0);
	install_app(argv0);

	winopen();

	if (fz_optind < argc)
	{
		strcpy(filename, argv[fz_optind]);
	}
	else
	{
		if (!winfilename(wbuf, nelem(wbuf)))
			exit(0);
		code = WideCharToMultiByte(CP_UTF8, 0, wbuf, -1, filename, sizeof filename, NULL, NULL);
		if (code == 0)
			winerror(&gapp, "cannot convert filename to utf-8");
	}

	if (layout_css)
	{
		fz_buffer *buf = fz_read_file(ctx, layout_css);
		fz_set_user_css(ctx, fz_string_from_buffer(ctx, buf));
		fz_drop_buffer(ctx, buf);
	}

	if (bps)
		pdfapp_open_progressive(&gapp, filename, 0, bps);
	else
		pdfapp_open(&gapp, filename, 0);

	while (GetMessage(&msg, NULL, 0, 0))
	{
		TranslateMessage(&msg);
		DispatchMessage(&msg);
	}

	fz_free_argv(argc, argv);

	do_close(&gapp);

	return 0;
}
Beispiel #2
0
	SIZE GetSystemDpiCached()
	{
		static const SIZE size = get_system_dpi();
		return size;
	}