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

📄 pdf_interpret.c

📁 SumatraPDF是一款小型开源的pdf阅读工具。虽然玲珑小巧(只有800多KB)
💻 C
📖 第 1 页 / 共 3 页
字号:
			error = pdf_addtransform(gstate, transform);			if (error)				return fz_rethrow(error, "cannot concatenate matrix");		}		else if (!strcmp(buf, "ri"))		{			if (csi->top != 1)				goto syntaxerror;		}		else if (!strcmp(buf, "gs"))		{			fz_obj *dict;			fz_obj *obj;			if (csi->top != 1)				goto syntaxerror;			dict = fz_dictgets(rdb, "ExtGState");			if (!dict)				return fz_throw("cannot find ExtGState dictionary");			obj = fz_dictget(dict, csi->stack[0]);			if (!obj)				return fz_throw("cannot find extgstate resource /%s", fz_toname(csi->stack[0]));			error = runextgstate(gstate, xref, obj);			if (error)				return fz_rethrow(error, "cannot set ExtGState");		}		else if (!strcmp(buf, "re"))		{			if (csi->top != 4)				goto syntaxerror;			x = fz_toreal(csi->stack[0]);			y = fz_toreal(csi->stack[1]);			w = fz_toreal(csi->stack[2]);			h = fz_toreal(csi->stack[3]);			error = fz_moveto(csi->path, x, y);			if (error) return fz_rethrow(error, "cannot draw rectangle");			error = fz_lineto(csi->path, x + w, y);			if (error) return fz_rethrow(error, "cannot draw rectangle");			error = fz_lineto(csi->path, x + w, y + h);			if (error) return fz_rethrow(error, "cannot draw rectangle");			error = fz_lineto(csi->path, x, y + h);			if (error) return fz_rethrow(error, "cannot draw rectangle");			error = fz_closepath(csi->path);			if (error) return fz_rethrow(error, "cannot draw rectangle");		}		else if (!strcmp(buf, "f*"))		{			if (csi->top != 0)				goto syntaxerror;			error = pdf_showpath(csi, 0, 1, 0, 1);			if (error) return fz_rethrow(error, "cannot draw path");		}		else if (!strcmp(buf, "B*"))		{			if (csi->top != 0)				goto syntaxerror;			error = pdf_showpath(csi, 0, 1, 1, 1);			if (error) return fz_rethrow(error, "cannot draw path");		}		else if (!strcmp(buf, "b*"))		{			if (csi->top != 0)				goto syntaxerror;			error = pdf_showpath(csi, 1, 1, 1, 1);			if (error) return fz_rethrow(error, "cannot draw path");		}		else if (!strcmp(buf, "W*"))		{			if (csi->top != 0)				goto syntaxerror;			csi->clip = 1;			csi->clipevenodd = 1;		}		else if (!strcmp(buf, "cs"))		{			what = PDF_MFILL;			goto Lsetcolorspace;		}		else if (!strcmp(buf, "CS"))		{			fz_colorspace *cs;			fz_obj *obj;			what = PDF_MSTROKE;Lsetcolorspace:			if (csi->top != 1)				goto syntaxerror;			obj = csi->stack[0];			if (!strcmp(fz_toname(obj), "Pattern"))			{				error = pdf_setpattern(csi, what, nil, nil);				if (error) return fz_rethrow(error, "cannot set pattern");			}			else 			{				if (!strcmp(fz_toname(obj), "DeviceGray"))					cs = pdf_devicegray;				else if (!strcmp(fz_toname(obj), "DeviceRGB"))					cs = pdf_devicergb;				else if (!strcmp(fz_toname(obj), "DeviceCMYK"))					cs = pdf_devicecmyk;				else				{					fz_obj *dict = fz_dictgets(rdb, "ColorSpace");					if (!dict)						return fz_throw("cannot find ColorSpace dictionary");					obj = fz_dictget(dict, obj);					if (!obj)						return fz_throw("cannot find colorspace resource /%s", fz_toname(csi->stack[0]));					cs = pdf_finditem(xref->store, PDF_KCOLORSPACE, obj);					if (!cs)						return fz_throw("cannot find colorspace in store");				}				error = pdf_setcolorspace(csi, what, cs);				if (error) return fz_rethrow(error, "cannot set colorspace");			}		}		else if (!strcmp(buf, "sc") || !strcmp(buf, "scn"))		{			what = PDF_MFILL;			goto Lsetcolor;		}		else if (!strcmp(buf, "SC") || !strcmp(buf, "SCN"))		{			pdf_material *mat;			pdf_pattern *pat;			fz_shade *shd;			fz_obj *dict;			fz_obj *obj;			int kind;			what = PDF_MSTROKE;Lsetcolor:			mat = what == PDF_MSTROKE ? &gstate->stroke : &gstate->fill;			kind = mat->kind;			if (fz_isname(csi->stack[csi->top - 1]))				kind = PDF_MPATTERN;			switch (kind)			{			case PDF_MNONE:				return fz_throw("cannot set color in mask objects");			case PDF_MINDEXED:				if (csi->top != 1)					goto syntaxerror;				v[0] = fz_toreal(csi->stack[0]);				error = pdf_setcolor(csi, what, v);				if (error) return fz_rethrow(error, "cannot set indexed color");				break;			case PDF_MCOLOR:			case PDF_MLAB:				if (csi->top != mat->cs->n)					goto syntaxerror;				for (i = 0; i < csi->top; i++)					v[i] = fz_toreal(csi->stack[i]);				error = pdf_setcolor(csi, what, v);				if (error) return fz_rethrow(error, "cannot set color");				break;			case PDF_MPATTERN:				for (i = 0; i < csi->top - 1; i++)					v[i] = fz_toreal(csi->stack[i]);				dict = fz_dictgets(rdb, "Pattern");				if (!dict)					return fz_throw("cannot find Pattern dictionary");				obj = fz_dictget(dict, csi->stack[csi->top - 1]);				if (!obj)					return fz_throw("cannot find pattern resource /%s",							fz_toname(csi->stack[csi->top - 1]));				pat = pdf_finditem(xref->store, PDF_KPATTERN, obj);				if (pat)				{					error = pdf_setpattern(csi, what, pat, csi->top == 1 ? nil : v);					if (error) return fz_rethrow(error, "cannot set pattern");				}				shd = pdf_finditem(xref->store, PDF_KSHADE, obj);				if (shd)				{					error = pdf_setshade(csi, what, shd);					if (error) return fz_rethrow(error, "cannot set shade");				}				if (!pat && !shd)					return fz_throw("cannot find pattern or shade in store");				break;			case PDF_MSHADE:				return fz_throw("cannot set color in shade objects");			}		}		else if (!strcmp(buf, "rg"))		{			if (csi->top != 3)				goto syntaxerror;			v[0] = fz_toreal(csi->stack[0]);			v[1] = fz_toreal(csi->stack[1]);			v[2] = fz_toreal(csi->stack[2]);			error = pdf_setcolorspace(csi, PDF_MFILL, pdf_devicergb);			if (error) return fz_rethrow(error, "cannot set rgb colorspace");			error = pdf_setcolor(csi, PDF_MFILL, v);			if (error) return fz_rethrow(error, "cannot set rgb color");		}		else if (!strcmp(buf, "RG"))		{			if (csi->top != 3)				goto syntaxerror;			v[0] = fz_toreal(csi->stack[0]);			v[1] = fz_toreal(csi->stack[1]);			v[2] = fz_toreal(csi->stack[2]);			error = pdf_setcolorspace(csi, PDF_MSTROKE, pdf_devicergb);			if (error) return fz_rethrow(error, "cannot set rgb colorspace");			error = pdf_setcolor(csi, PDF_MSTROKE, v);			if (error) return fz_rethrow(error, "cannot set rgb color");		}		else if (!strcmp(buf, "BT"))		{			if (csi->top != 0)				goto syntaxerror;			csi->tm = fz_identity();			csi->tlm = fz_identity();		}		else if (!strcmp(buf, "ET"))		{			if (csi->top != 0)				goto syntaxerror;			error = pdf_flushtext(csi);			if (error)				return fz_rethrow(error, "cannot finish text object (ET)");			if (csi->textclip)			{				error = pdf_addclipmask(gstate, csi->textclip);				if (error) return fz_rethrow(error, "cannot add text clip mask");				csi->textclip = nil;			}		}		else if (!strcmp(buf, "Tc"))		{			if (csi->top != 1)				goto syntaxerror;			gstate->charspace = fz_toreal(csi->stack[0]);		}		else if (!strcmp(buf, "Tw"))		{			if (csi->top != 1)				goto syntaxerror;			gstate->wordspace = fz_toreal(csi->stack[0]);		}		else if (!strcmp(buf, "Tz"))		{			if (csi->top != 1)				goto syntaxerror;			error = pdf_flushtext(csi);			if (error)				return fz_rethrow(error, "cannot finish text object (state change)");			gstate->scale = fz_toreal(csi->stack[0]) / 100.0;		}		else if (!strcmp(buf, "TL"))		{			if (csi->top != 1)				goto syntaxerror;			gstate->leading = fz_toreal(csi->stack[0]);		}		else if (!strcmp(buf, "Tf"))		{			fz_obj *dict;			fz_obj *obj;			if (csi->top != 2)				goto syntaxerror;			dict = fz_dictgets(rdb, "Font");			if (!dict)				return fz_throw("cannot find Font dictionary");			obj = fz_dictget(dict, csi->stack[0]);			if (!obj)				return fz_throw("cannot find font resource: %s", fz_toname(csi->stack[0]));			gstate->font = pdf_finditem(xref->store, PDF_KFONT, obj);			if (!gstate->font)				return fz_throw("cannot find font in store");			gstate->size = fz_toreal(csi->stack[1]);			if (gstate->size <= 0.0)			{				gstate->size = 1.0;				fz_warn("font size negative, capping to %g", gstate->size);			}			if (gstate->size > 1000.0)			{				gstate->size = 1000.0;				fz_warn("font size too large, capping to %g", gstate->size);			}		}		else if (!strcmp(buf, "Tr"))		{			if (csi->top != 1)				goto syntaxerror;			gstate->render = fz_toint(csi->stack[0]);		}		else if (!strcmp(buf, "Ts"))		{			if (csi->top != 1)				goto syntaxerror;			gstate->rise = fz_toreal(csi->stack[0]);		}		else if (!strcmp(buf, "Td"))		{			if (csi->top != 2)				goto syntaxerror;			m = fz_translate(fz_toreal(csi->stack[0]), fz_toreal(csi->stack[1]));			csi->tlm = fz_concat(m, csi->tlm);			csi->tm = csi->tlm;		}		else if (!strcmp(buf, "TD"))		{			if (csi->top != 2)				goto syntaxerror;			gstate->leading = -fz_toreal(csi->stack[1]);			m = fz_translate(fz_toreal(csi->stack[0]), fz_toreal(csi->stack[1]));			csi->tlm = fz_concat(m, csi->tlm);			csi->tm = csi->tlm;		}		else if (!strcmp(buf, "Tm"))		{			if (csi->top != 6)				goto syntaxerror;			error = pdf_flushtext(csi);			if (error)				return fz_rethrow(error, "cannot finish text object (state change)");			csi->tm.a = fz_toreal(csi->stack[0]);			csi->tm.b = fz_toreal(csi->stack[1]);			csi->tm.c = fz_toreal(csi->stack[2]);			csi->tm.d = fz_toreal(csi->stack[3]);			csi->tm.e = fz_toreal(csi->stack[4]);			csi->tm.f = fz_toreal(csi->stack[5]);			csi->tlm = csi->tm;		}		else if (!strcmp(buf, "T*"))		{			if (csi->top != 0)				goto syntaxerror;			m = fz_translate(0, -gstate->leading);			csi->tlm = fz_concat(m, csi->tlm);			csi->tm = csi->tlm;		}		else if (!strcmp(buf, "Tj"))		{			if (csi->top != 1)				goto syntaxerror;			error = pdf_showtext(csi, csi->stack[0]);			if (error) return fz_rethrow(error, "cannot draw text");		}		else if (!strcmp(buf, "TJ"))		{			if (csi->top != 1)				goto syntaxerror;			error = pdf_showtext(csi, csi->stack[0]);			if (error) return fz_rethrow(error, "cannot draw text");		}		else if (!strcmp(buf, "Do"))		{			fz_obj *dict;			fz_obj *obj;			pdf_image *img;			pdf_xobject *xobj;			if (csi->top != 1)				goto syntaxerror;			dict = fz_dictgets(rdb, "XObject");			if (!dict)				return fz_throw("cannot find XObject dictionary");			obj = fz_dictget(dict, csi->stack[0]);			if (!obj)				return fz_throw("cannot find xobject resource: %s", fz_toname(csi->stack[0]));			img = pdf_finditem(xref->store, PDF_KIMAGE, obj);			xobj = pdf_finditem(xref->store, PDF_KXOBJECT, obj);			if (!img && !xobj)				return fz_throw("cannot find image or xobject in store");			if (img)			{				error = pdf_showimage(csi, img);				if (error)					return fz_rethrow(error, "cannot draw image");			}			if (xobj)			{				int istransparency = 0;				/* Inherit parent resources, in case this one was empty */				if (!xobj->resources)					xobj->resources = fz_keepobj(rdb);				clearstack(csi);				/* check if it is a Transparency group */				obj = fz_dictgets(dict, "Group");				if (obj) {					obj = fz_dictgets(obj, "S");					if (!strcmp(fz_toname(obj), "Transparency"))

⌨️ 快捷键说明

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