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

📄 pdf_interpret.c

📁 SumatraPDF是一款小型开源的pdf阅读工具。虽然玲珑小巧(只有800多KB)
💻 C
📖 第 1 页 / 共 3 页
字号:
						istransparency = 1;				}				error = runxobject(csi, xref, xobj, istransparency);				if (error)					return fz_rethrow(error, "cannot draw xobject");			}		}		else if (!strcmp(buf, "sh"))		{			fz_obj *dict;			fz_obj *obj;			fz_shade *shd;			if (csi->top != 1)				goto syntaxerror;			dict = fz_dictgets(rdb, "Shading");			if (!dict)				return fz_throw("cannot find Shading dictionary");			obj = fz_dictget(dict, csi->stack[csi->top - 1]);			if (!obj)				return fz_throw("cannot find shade resource: %s", fz_toname(csi->stack[csi->top - 1]));			shd = pdf_finditem(xref->store, PDF_KSHADE, obj);			if (!shd)				return fz_throw("cannot find shade in store");			error = pdf_addshade(gstate, shd);			if (error) return fz_rethrow(error, "cannot draw shade");		}		else if (!strcmp(buf, "d0"))		{			fz_warn("unimplemented: d0 charprocs");		}		else if (!strcmp(buf, "d1"))		{		}		else		{			/* don't fail on unknown keywords if braced by BX/EX */			if (!csi->xbalance)				fz_warn("unknown keyword: %s", buf);		}	}	else switch (buf[0])	{	case 'q':		if (csi->top != 0)			goto syntaxerror;		error = gsave(csi);		if (error)			return fz_rethrow(error, "cannot gsave");		break;	case 'Q':		if (csi->top != 0)			goto syntaxerror;		error = grestore(csi);		if (error)			return fz_rethrow(error, "cannot grestore");		break;	case 'w':		if (csi->top != 1)			goto syntaxerror;		gstate->linewidth = fz_toreal(csi->stack[0]);		break;	case 'J':		if (csi->top != 1)			goto syntaxerror;		gstate->linecap = fz_toint(csi->stack[0]);		break;	case 'j':		if (csi->top != 1)			goto syntaxerror;		gstate->linejoin = fz_toint(csi->stack[0]);		break;	case 'M':		if (csi->top != 1)			goto syntaxerror;		gstate->miterlimit = fz_toreal(csi->stack[0]);		break;	case 'd':		if (csi->top != 2)			goto syntaxerror;		{			int i;			fz_obj *array = csi->stack[0];			gstate->dashlen = fz_arraylen(array);			if (gstate->dashlen > 32)				return fz_throw("assert: dash pattern too big");			for (i = 0; i < gstate->dashlen; i++)				gstate->dashlist[i] = fz_toreal(fz_arrayget(array, i));			gstate->dashphase = fz_toreal(csi->stack[1]);		}		break;	case 'i':		if (csi->top != 1)			goto syntaxerror;		/* flatness */		break;	case 'm':		if (csi->top != 2)			goto syntaxerror;		a = fz_toreal(csi->stack[0]);		b = fz_toreal(csi->stack[1]);		error = fz_moveto(csi->path, a, b);		if (error) return fz_rethrow(error, "cannot create path node");		break;	case 'l':		if (csi->top != 2)			goto syntaxerror;		a = fz_toreal(csi->stack[0]);		b = fz_toreal(csi->stack[1]);		error = fz_lineto(csi->path, a, b);		if (error) return fz_rethrow(error, "cannot create path node");		break;	case 'c':		if (csi->top != 6)			goto syntaxerror;		a = fz_toreal(csi->stack[0]);		b = fz_toreal(csi->stack[1]);		c = fz_toreal(csi->stack[2]);		d = fz_toreal(csi->stack[3]);		e = fz_toreal(csi->stack[4]);		f = fz_toreal(csi->stack[5]);		error = fz_curveto(csi->path, a, b, c, d, e, f);		if (error) return fz_rethrow(error, "cannot create path node");		break;	case 'v':		if (csi->top != 4)			goto syntaxerror;		a = fz_toreal(csi->stack[0]);		b = fz_toreal(csi->stack[1]);		c = fz_toreal(csi->stack[2]);		d = fz_toreal(csi->stack[3]);		error = fz_curvetov(csi->path, a, b, c, d);		if (error) return fz_rethrow(error, "cannot create path node");		break;	case 'y':		if (csi->top != 4)			goto syntaxerror;		a = fz_toreal(csi->stack[0]);		b = fz_toreal(csi->stack[1]);		c = fz_toreal(csi->stack[2]);		d = fz_toreal(csi->stack[3]);		error = fz_curvetoy(csi->path, a, b, c, d);		if (error) return fz_rethrow(error, "cannot create path node");		break;	case 'h':		if (csi->top != 0)			goto syntaxerror;		error = fz_closepath(csi->path);		if (error) return fz_rethrow(error, "cannot create path node");		break;	case 'S':		if (csi->top != 0)			goto syntaxerror;		error = pdf_showpath(csi, 0, 0, 1, 0);		if (error) return fz_rethrow(error, "cannot draw path");		break;	case 's':		if (csi->top != 0)			goto syntaxerror;		error = pdf_showpath(csi, 1, 0, 1, 0);		if (error) return fz_rethrow(error, "cannot draw path");		break;	case 'F':	case 'f':		if (csi->top != 0)			goto syntaxerror;		error = pdf_showpath(csi, 0, 1, 0, 0);		if (error) return fz_rethrow(error, "cannot draw path");		break;	case 'B':		if (csi->top != 0)			goto syntaxerror;		error = pdf_showpath(csi, 0, 1, 1, 0);		if (error) return fz_rethrow(error, "cannot draw path");		break;	case 'b':		if (csi->top != 0)			goto syntaxerror;		error = pdf_showpath(csi, 1, 1, 1, 0);		if (error) return fz_rethrow(error, "cannot draw path");		break;	case 'n':		if (csi->top != 0)			goto syntaxerror;		error = pdf_showpath(csi, 0, 0, 0, csi->clipevenodd);		if (error) return fz_rethrow(error, "cannot draw path");		break;	case 'W':		if (csi->top != 0)			goto syntaxerror;		csi->clip = 1;		csi->clipevenodd = 0;		break;	case 'g':			if (csi->top != 1)			goto syntaxerror;		v[0] = fz_toreal(csi->stack[0]);		error = pdf_setcolorspace(csi, PDF_MFILL, pdf_devicegray);		if (error) return fz_rethrow(error, "cannot set gray colorspace");		error = pdf_setcolor(csi, PDF_MFILL, v);		if (error) return fz_rethrow(error, "cannot set gray color");		break;	case 'G':		if (csi->top != 1)			goto syntaxerror;		v[0] = fz_toreal(csi->stack[0]);		error = pdf_setcolorspace(csi, PDF_MSTROKE, pdf_devicegray);		if (error) return fz_rethrow(error, "cannot set gray colorspace");		error = pdf_setcolor(csi, PDF_MSTROKE, v);		if (error) return fz_rethrow(error, "cannot set gray color");		break;	case 'k':		if (csi->top != 4)			goto syntaxerror;		v[0] = fz_toreal(csi->stack[0]);		v[1] = fz_toreal(csi->stack[1]);		v[2] = fz_toreal(csi->stack[2]);		v[3] = fz_toreal(csi->stack[3]);		error = pdf_setcolorspace(csi, PDF_MFILL, pdf_devicecmyk);		if (error) return fz_rethrow(error, "cannot set cmyk colorspace");		error = pdf_setcolor(csi, PDF_MFILL, v);		if (error) return fz_rethrow(error, "cannot set cmyk color");		break;	case 'K':		if (csi->top != 4)			goto syntaxerror;		v[0] = fz_toreal(csi->stack[0]);		v[1] = fz_toreal(csi->stack[1]);		v[2] = fz_toreal(csi->stack[2]);		v[3] = fz_toreal(csi->stack[3]);		error = pdf_setcolorspace(csi, PDF_MSTROKE, pdf_devicecmyk);		if (error) return fz_rethrow(error, "cannot set cmyk colorspace");		error = pdf_setcolor(csi, PDF_MSTROKE, v);		if (error) return fz_rethrow(error, "cannot set cmyk color");		break;	case '\'':		if (csi->top != 1)			goto syntaxerror;		m = fz_translate(0, -gstate->leading);		csi->tlm = fz_concat(m, csi->tlm);		csi->tm = csi->tlm;		error = pdf_showtext(csi, csi->stack[0]);		if (error) return fz_rethrow(error, "cannot draw text");		break;	case '"':		if (csi->top != 3)			goto syntaxerror;		gstate->wordspace = fz_toreal(csi->stack[0]);		gstate->charspace = fz_toreal(csi->stack[1]);		m = fz_translate(0, -gstate->leading);		csi->tlm = fz_concat(m, csi->tlm);		csi->tm = csi->tlm;		error = pdf_showtext(csi, csi->stack[2]);		if (error) return fz_rethrow(error, "cannot draw text");		break;	default:		/* don't fail on unknown keywords if braced by BX/EX */		if (!csi->xbalance)			fz_warn("unknown keyword: %s", buf);	}	return fz_okay;syntaxerror:	return fz_throw("syntaxerror near '%s'", buf);}fz_error *pdf_runcsi(pdf_csi *csi, pdf_xref *xref, fz_obj *rdb, fz_stream *file){	fz_error *error;	char buf[65536];	pdf_token_e tok;	int len;	fz_obj *obj;	while (1)	{		if (csi->top == 31)			return fz_throw("stack overflow");		error = pdf_lex(&tok, file, buf, sizeof buf, &len);		if (error)			return fz_rethrow(error, "lexical error in content stream");		if (csi->array)		{			if (tok == PDF_TCARRAY)			{				csi->stack[csi->top] = csi->array;				csi->array = nil;				csi->top ++;			}			else if (tok == PDF_TINT || tok == PDF_TREAL)			{				error = fz_newreal(&obj, atof(buf));				if (error) return fz_rethrow(error, "cannot create number");				error = fz_arraypush(csi->array, obj);				fz_dropobj(obj);				if (error) return fz_rethrow(error, "cannot add number to array");			}			else if (tok == PDF_TSTRING)			{				error = fz_newstring(&obj, buf, len);				if (error) return fz_rethrow(error, "cannot create string");				error = fz_arraypush(csi->array, obj);				fz_dropobj(obj);				if (error) return fz_rethrow(error, "cannot add string to array");			}			else if (tok == PDF_TEOF)			{				return fz_okay;			}			else			{				clearstack(csi);				return fz_throw("syntaxerror in array");			}		}		else switch (tok)		{		case PDF_TEOF:			return fz_okay;			/* optimize text-object array parsing */		case PDF_TOARRAY:			error = fz_newarray(&csi->array, 8);			if (error) return fz_rethrow(error, "cannot create array");			break;		case PDF_TODICT:			error = pdf_parsedict(&csi->stack[csi->top], file, buf, sizeof buf);			if (error) return fz_rethrow(error, "cannot parse dictionary");			csi->top ++;			break;		case PDF_TNAME:			error = fz_newname(&csi->stack[csi->top], buf);			if (error) return fz_rethrow(error, "cannot create name");			csi->top ++;			break;		case PDF_TINT:			error = fz_newint(&csi->stack[csi->top], atoi(buf));			if (error) return fz_rethrow(error, "cannot create integer");			csi->top ++;			break;		case PDF_TREAL:			error = fz_newreal(&csi->stack[csi->top], atof(buf));			if (error) return fz_rethrow(error, "cannot create real");			csi->top ++;			break;		case PDF_TSTRING:			error = fz_newstring(&csi->stack[csi->top], buf, len);			if (error) return fz_rethrow(error, "cannot create string");			csi->top ++;			break;		case PDF_TTRUE:			error = fz_newbool(&csi->stack[csi->top], 1);			if (error) return fz_rethrow(error, "cannot create true");			csi->top ++;			break;		case PDF_TFALSE:			error = fz_newbool(&csi->stack[csi->top], 0);			if (error) return fz_rethrow(error, "cannot create false");			csi->top ++;			break;		case PDF_TNULL:			error = fz_newnull(&csi->stack[csi->top]);			if (error) return fz_rethrow(error, "cannot create null");			csi->top ++;			break;		case PDF_TKEYWORD:			if (!strcmp(buf, "BI"))			{				fz_obj *obj;				error = pdf_parsedict(&obj, file, buf, sizeof buf);				if (error)					return fz_rethrow(error, "cannot parse inline image dictionary");				/* read whitespace after ID keyword */				fz_readbyte(file);				error = fz_readerror(file);				if (error)					return fz_rethrow(error, "cannot parse whitespace before inline image");				error = runinlineimage(csi, xref, rdb, file, obj);				fz_dropobj(obj);				if (error)					return fz_rethrow(error, "cannot parse inline image");			}			else			{				error = runkeyword(csi, xref, rdb, buf);				if (error)					return fz_rethrow(error, "cannot run '%s'", buf);				clearstack(csi);			}			break;		default:			clearstack(csi);			return fz_throw("syntaxerror in content stream");		}	}}

⌨️ 快捷键说明

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