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

📄 dscparse.cpp

📁 okular
💻 CPP
📖 第 1 页 / 共 5 页
字号:
	    case CDSC_RESPONSE_OK:	    case CDSC_RESPONSE_CANCEL:		return CDSC_OK;	/* ignore duplicate comments in header */	    case CDSC_RESPONSE_IGNORE_ALL:		return CDSC_NOTDSC;	}    }    if ((*pbbox != NULL) && (dsc->scan_section == scan_pages)) {	int rc = dsc_error(dsc, CDSC_MESSAGE_DUP_COMMENT, dsc->line, 		dsc->line_length);	switch (rc) {	    case CDSC_RESPONSE_OK:	    case CDSC_RESPONSE_CANCEL:		return CDSC_OK;	/* ignore duplicate comments in header */	    case CDSC_RESPONSE_IGNORE_ALL:		return CDSC_NOTDSC;	}    }    if ((*pbbox != NULL) && (dsc->scan_section == scan_trailer)) {	int rc = dsc_error(dsc, CDSC_MESSAGE_DUP_TRAILER, dsc->line, 		dsc->line_length);	switch (rc) {	    case CDSC_RESPONSE_OK:	    case CDSC_RESPONSE_CANCEL:		break;		/* use duplicate comments in trailer */	    case CDSC_RESPONSE_IGNORE_ALL:		return CDSC_NOTDSC;	}    }    if (*pbbox != NULL) {	dsc_memfree(dsc, *pbbox);	*pbbox = NULL;    }    /* should only process first %%BoundingBox: */    while (IS_WHITE(dsc->line[offset]))	offset++;    p = dsc->line + offset;        if (COMPARE(p, "atend")) {	int rc = dsc_error(dsc, CDSC_MESSAGE_ATEND, dsc->line, 		dsc->line_length);	switch (rc) {	    case CDSC_RESPONSE_OK:		/* assume (atend) */		/* we should mark it as deferred */		break;	    case CDSC_RESPONSE_CANCEL:		/* ignore it */		break;	    case CDSC_RESPONSE_IGNORE_ALL:		return CDSC_NOTDSC;	}    }    else if (COMPARE(p, "(atend)")) {	/* do nothing */	/* we should mark it as deferred */    }    else {	/* fllx = */ flly = furx = fury = 0.0;	n = offset;	fllx = dsc_get_real(dsc->line+n, dsc->line_length-n, &i);	n += i;	if (i)	    flly = dsc_get_real(dsc->line+n, dsc->line_length-n, &i);	n += i;	if (i)	    furx = dsc_get_real(dsc->line+n, dsc->line_length-n, &i);	n += i;	if (i)	    fury = dsc_get_real(dsc->line+n, dsc->line_length-n, &i);	if (i) {	    *pbbox = (CDSCFBBOX *)dsc_memalloc(dsc, sizeof(CDSCFBBOX));	    if (*pbbox == NULL)		return CDSC_ERROR;	/* no memory */	    (*pbbox)->fllx = fllx;	    (*pbbox)->flly = flly;	    (*pbbox)->furx = furx;	    (*pbbox)->fury = fury;	}    }    return CDSC_OK;}dsc_private int dsc_parse_orientation(CDSC *dsc, unsigned int *porientation, int offset){    char *p;    if ((dsc->page_orientation != CDSC_ORIENT_UNKNOWN) && 	(dsc->scan_section == scan_comments)) {	int rc = dsc_error(dsc, CDSC_MESSAGE_DUP_COMMENT, dsc->line, 		dsc->line_length);	switch (rc) {	    case CDSC_RESPONSE_OK:	    case CDSC_RESPONSE_CANCEL:		return CDSC_OK;	/* ignore duplicate comments in header */	    case CDSC_RESPONSE_IGNORE_ALL:		return CDSC_NOTDSC;	}    }    if ((dsc->page_orientation != CDSC_ORIENT_UNKNOWN) && 	(dsc->scan_section == scan_trailer)) {	int rc = dsc_error(dsc, CDSC_MESSAGE_DUP_TRAILER, dsc->line, 		dsc->line_length);	switch (rc) {	    case CDSC_RESPONSE_OK:	    case CDSC_RESPONSE_CANCEL:		break;		/* use duplicate comments in header; */	    case CDSC_RESPONSE_IGNORE_ALL:		return CDSC_NOTDSC;	}    }    p = dsc->line + offset;    while (IS_WHITE(*p))	p++;    if (COMPARE(p, "atend")) {	int rc = dsc_error(dsc, CDSC_MESSAGE_ATEND, dsc->line, dsc->line_length);	switch (rc) {	    case CDSC_RESPONSE_OK:		/* assume (atend) */		/* we should mark it as deferred */		break;	    case CDSC_RESPONSE_CANCEL:		/* ignore it */		break;	    case CDSC_RESPONSE_IGNORE_ALL:		return CDSC_NOTDSC;	}    }    else if (COMPARE(p, "(atend)")) {	/* do nothing */	/* we should mark it as deferred */    }    else if (COMPARE(p, "Portrait")) {	*porientation = CDSC_PORTRAIT;    }    else if (COMPARE(p, "Landscape")) {	*porientation = CDSC_LANDSCAPE;    }    else {	dsc_unknown(dsc);    }    return CDSC_OK;}dsc_private int dsc_parse_order(CDSC *dsc){    char *p;    if ((dsc->page_order != CDSC_ORDER_UNKNOWN) && 	(dsc->scan_section == scan_comments)) {	int rc = dsc_error(dsc, CDSC_MESSAGE_DUP_COMMENT, dsc->line, 		dsc->line_length);	switch (rc) {	    case CDSC_RESPONSE_OK:	    case CDSC_RESPONSE_CANCEL:		return CDSC_OK;	/* ignore duplicate comments in header */	    case CDSC_RESPONSE_IGNORE_ALL:		return CDSC_NOTDSC;	}    }    if ((dsc->page_order != CDSC_ORDER_UNKNOWN) && 	(dsc->scan_section == scan_trailer)) {	int rc = dsc_error(dsc, CDSC_MESSAGE_DUP_TRAILER, dsc->line, 		dsc->line_length);	switch (rc) {	    case CDSC_RESPONSE_OK:	    case CDSC_RESPONSE_CANCEL:		break;		/* use duplicate comments in trailer */	    case CDSC_RESPONSE_IGNORE_ALL:		return CDSC_NOTDSC;	}    }    p = dsc->line + (IS_DSC(dsc->line, "%%+") ? 3 : 13);    while (IS_WHITE(*p))	p++;    if (COMPARE(p, "atend")) {	int rc = dsc_error(dsc, CDSC_MESSAGE_ATEND, dsc->line, 		dsc->line_length);	switch (rc) {	    case CDSC_RESPONSE_OK:		/* assume (atend) */		/* we should mark it as deferred */		break;	    case CDSC_RESPONSE_CANCEL:		/* ignore it */		break;	    case CDSC_RESPONSE_IGNORE_ALL:		return CDSC_NOTDSC;	}    }    else if (COMPARE(p, "(atend)")) {	/* do nothing */	/* we should mark it as deferred */    }    else if (COMPARE(p, "Ascend")) {	dsc->page_order = CDSC_ASCEND;    }    else if (COMPARE(p, "Descend")) {	dsc->page_order = CDSC_DESCEND;    }    else if (COMPARE(p, "Special")) {	dsc->page_order = CDSC_SPECIAL;    }    else {	dsc_unknown(dsc);    }    return CDSC_OK;}dsc_private int dsc_parse_media(CDSC *dsc, const CDSCMEDIA **page_media){    char media_name[MAXSTR];    int n = IS_DSC(dsc->line, "%%+") ? 3 : 12; /* %%PageMedia: */    unsigned int i;    if (dsc_copy_string(media_name, sizeof(media_name)-1, 	dsc->line+n, dsc->line_length-n, NULL)) {	for (i=0; i<dsc->media_count; i++) {	    if (dsc->media[i]->name && 		(dsc_stricmp(media_name, dsc->media[i]->name) == 0)) {		*page_media = dsc->media[i];		return CDSC_OK;	    }	}    }    dsc_unknown(dsc);        return CDSC_OK;}dsc_private int dsc_parse_document_media(CDSC *dsc){    unsigned int i, n;    CDSCMEDIA lmedia;    GSBOOL blank_line;    if (IS_DSC(dsc->line, "%%DocumentMedia:"))	n = 16;    else if (IS_DSC(dsc->line, "%%+"))	n = 3;    else	return CDSC_ERROR;	/* error */    /* check for blank remainder of line */    blank_line = TRUE;    for (i=n; i<dsc->line_length; i++) {	if (!IS_WHITE_OR_EOL(dsc->line[i])) {	    blank_line = FALSE;	    break;	}    }    if (!blank_line) {	char name[MAXSTR];	char colour[MAXSTR];	char type[MAXSTR];	lmedia.name = lmedia.colour = lmedia.type = (char *)NULL;	lmedia.width = lmedia.height = lmedia.weight = 0;	lmedia.mediabox = (CDSCBBOX *)NULL;	lmedia.name = dsc_copy_string(name, sizeof(name),		dsc->line+n, dsc->line_length-n, &i);	n+=i;	if (i)	    lmedia.width = dsc_get_real(dsc->line+n, dsc->line_length-n, &i);	n+=i;	if (i)	    lmedia.height = dsc_get_real(dsc->line+n, dsc->line_length-n, &i);	n+=i;	if (i)	    lmedia.weight = dsc_get_real(dsc->line+n, dsc->line_length-n, &i);	n+=i;	if (i)	    lmedia.colour = dsc_copy_string(colour, sizeof(colour),		dsc->line+n, dsc->line_length-n, &i);	n+=i;	if (i)	    lmedia.type = dsc_copy_string(type, sizeof(type),		dsc->line+n, dsc->line_length-n, &i);	if (i==0)	    dsc_unknown(dsc); /* we didn't get all fields */	else {	    if (dsc_add_media(dsc, &lmedia))		return CDSC_ERROR;	/* out of memory */	}    }    return CDSC_OK;}/* viewing orientation is believed to be the first four elements of * a CTM matrix */dsc_private int dsc_parse_viewing_orientation(CDSC *dsc, CDSCCTM **pctm){    CDSCCTM ctm;    unsigned int i, n;    if (*pctm != NULL) {	dsc_memfree(dsc, *pctm);	*pctm = NULL;    }    n = IS_DSC(dsc->line, "%%+") ? 3 : 21;  /* %%ViewingOrientation: */    while (IS_WHITE(dsc->line[n]))	n++;    /* ctm.xx = */ ctm.xy = ctm.yx = ctm.yy = 0.0;    ctm.xx = dsc_get_real(dsc->line+n, dsc->line_length-n, &i);    n += i;    if (i)        ctm.xy = dsc_get_real(dsc->line+n, dsc->line_length-n, &i);    n += i;    if (i)        ctm.yx = dsc_get_real(dsc->line+n, dsc->line_length-n, &i);    n += i;    if (i)        ctm.yy = dsc_get_real(dsc->line+n, dsc->line_length-n, &i);    if (i==0) {	dsc_unknown(dsc); /* we didn't get all fields */    }    else {	*pctm = (CDSCCTM *)dsc_memalloc(dsc, sizeof(CDSCCTM));	if (*pctm == NULL)	    return CDSC_ERROR;	/* no memory */	**pctm = ctm;    }    return CDSC_OK;}   /* This is called before dsc_read_line(), since we may * need to skip a binary header which contains a new line * character */dsc_private int dsc_scan_type(CDSC *dsc){    unsigned char *p;    unsigned char *line = (unsigned char *)(dsc->data + dsc->data_index);    int length = dsc->data_length - dsc->data_index;    /* Types that should be known:     *   DSC     *   EPSF     *   PJL + any of above     *   ^D + any of above     *   DOS EPS     *   PDF     *   non-DSC     */    /* First process any non PostScript headers */    /* At this stage we do not have a complete line */    if (length == 0)	return CDSC_NEEDMORE;    if (dsc->skip_pjl) {	/* skip until first PostScript comment */	while (length >= 2) {	    while (length && !IS_EOL(line[0])) {		/* skip until EOL character */		line++;		dsc->data_index++;		length--;	    }	    while ((length >= 2) && IS_EOL(line[0]) && IS_EOL(line[1])) {		/* skip until EOL followed by non-EOL */		line++;		dsc->data_index++;		length--;	    }	    if (length < 2)		return CDSC_NEEDMORE;	    if (IS_EOL(line[0]) && line[1]=='%') {		line++;		dsc->data_index++;		length--;		dsc->skip_pjl = FALSE;		break;	    }	    else {		/* line++; */		dsc->data_index++;		/* length--; */		return CDSC_NEEDMORE;	    }	}	if (dsc->skip_pjl)	    return CDSC_NEEDMORE;    }    if (length == 0)	return CDSC_NEEDMORE;    if (line[0] == '\004') {	line++;	dsc->data_index++;	length--;	dsc->ctrld = TRUE;    }    if (line[0] == '\033') {	/* possibly PJL */	if (length < 9)	    return CDSC_NEEDMORE;	if (COMPARE(line, "\033%-12345X")) {	    dsc->skip_pjl = TRUE;  /* skip until first PostScript comment */	    dsc->pjl = TRUE;	    dsc->data_index += 9;	    return dsc_scan_type(dsc);	}    }    if ((line[0]==0xc5) && (length < 4))	return CDSC_NEEDMORE;    if ((line[0]==0xc5) && (line[1]==0xd0) && 	 (line[2]==0xd3) && (line[3]==0xc6) ) {	/* id is "EPSF" with bit 7 set */	/* read DOS EPS header, then ignore all bytes until the PS section */	if (length < 30)	    return CDSC_NEEDMORE;	dsc->line = (char *)line;	if (dsc_read_doseps(dsc))	    return CDSC_ERROR;    }    else {	if (length < 2)	    return CDSC_NEEDMORE;	if ((line[0] == '%') && (line[1] == 'P')) {	    if (length < 5)	        return CDSC_NEEDMORE;	    if (COMPARE(line, "%PDF-")) {		dsc->pdf = TRUE;		dsc->scan_section = scan_comments;		return CDSC_OK;	    }	}    }    /* Finally process PostScript headers */    if (dsc_read_line(dsc) <= 0)	return CDSC_NEEDMORE;	    dsc->dsc_version = dsc_add_line(dsc, dsc->line, dsc->line_length);    if (COMPARE(dsc->line, "%!PS-Adobe")) {	dsc->dsc = TRUE;	dsc->begincomments = DSC_START(dsc);	if (dsc->dsc_version == NULL)	    return CDSC_ERROR;	/* no memory */	p = (unsigned char *)dsc->line + 14;	while (IS_WHITE(*p))	    p++;	if (COMPARE(p, "EPSF-"))	    dsc->epsf = TRUE;	dsc->scan_section = scan_comments;	return CDSC_PSADOBE;    }    if (COMPARE(dsc->line, "%!")) {	dsc->scan_section = scan_comments;	return CDSC_NOTDSC;    }    dsc->scan_section = scan_comments;    return CDSC_NOTDSC;	/* unrecognised */}

⌨️ 快捷键说明

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