📄 dscparse.c
字号:
for (i=0; i<(int)entries; i++) {
index = 26 + i * 12;
EntryID = dsc_get_bigendian_dword(line+index);
Offset = dsc_get_bigendian_dword(line+index+4);
Length = dsc_get_bigendian_dword(line+index+8);
if (EntryID == 1) {
/* data fork */
dsc->macbin->data_begin = Offset;
dsc->macbin->data_length = Length;
}
else if (EntryID == 2) {
/* resource fork */
dsc->macbin->resource_begin = Offset;
dsc->macbin->resource_length = Length;
}
}
if (dsc->file_length &&
(dsc->macbin->resource_begin + dsc->macbin->resource_length
> dsc->file_length)) {
return CDSC_ERROR;
}
if (dsc->file_length &&
(dsc->macbin->data_begin + dsc->macbin->data_length
> dsc->file_length)) {
return CDSC_ERROR;
}
dsc->doseps_end = dsc->macbin->data_begin + dsc->macbin->data_length;
header = 26 + entries * 12;
/* move data_index to byte after AppleSingle/AppleDouble header */
dsc->data_index -= dsc->line_length - header;
/* we haven't read a line of PostScript code yet */
dsc->line_count = 0;
/* skip from current position to start of PostScript section */
dsc->skip_bytes = dsc->macbin->data_begin - header;
dsc->preview = CDSC_PICT;
return CDSC_OK;
}
dsc_private int
dsc_parse_pages(CDSC *dsc)
{
int ip, io;
unsigned int i;
char *p;
int n;
if ((dsc->page_pages != 0) && (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_pages != 0) && (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;
}
}
n = IS_DSC(dsc->line, "%%+") ? 3 : 8;
while (IS_WHITE(dsc->line[n]))
n++;
p = dsc->line + n;
if (COMPARE(p, "atend")) {
if (dsc->scan_section != scan_comments)
dsc_unknown(dsc);
else {
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)")) {
if (dsc->scan_section != scan_comments)
dsc_unknown(dsc);
/* do nothing */
/* we should mark it as deferred */
}
else {
ip = dsc_get_int(dsc->line+n, dsc->line_length-n, &i);
if (i) {
n+=i;
dsc->page_pages = ip;
io = dsc_get_int(dsc->line+n, dsc->line_length-n, &i);
if (i) {
/* DSC 2 uses extra integer to indicate page order */
/* DSC 3 uses %%PageOrder: */
if (dsc->page_order == CDSC_ORDER_UNKNOWN)
switch (io) {
case -1:
dsc->page_order = CDSC_DESCEND;
break;
case 0:
dsc->page_order = CDSC_SPECIAL;
break;
case 1:
dsc->page_order = CDSC_ASCEND;
break;
}
}
}
else {
int rc = dsc_error(dsc, CDSC_MESSAGE_INCORRECT_USAGE, dsc->line,
dsc->line_length);
switch (rc) {
case CDSC_RESPONSE_OK:
case CDSC_RESPONSE_CANCEL:
/* ignore it */
break;
case CDSC_RESPONSE_IGNORE_ALL:
return CDSC_NOTDSC;
}
}
}
return CDSC_OK;
}
dsc_private int
dsc_parse_bounding_box(CDSC *dsc, CDSCBBOX** pbbox, int offset)
{
unsigned int i, n;
int llx, lly, urx, ury;
float fllx, flly, furx, fury;
char *p;
/* Process first %%BoundingBox: in comments, and last in trailer */
if ((*pbbox != NULL) && (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 ((*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")) {
if (dsc->scan_section == scan_trailer)
dsc_unknown(dsc);
else {
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)")) {
if (dsc->scan_section == scan_trailer)
dsc_unknown(dsc);
/* do nothing */
/* we should mark it as deferred */
}
else {
/* llx = */ lly = urx = ury = 0;
n = offset;
llx = dsc_get_int(dsc->line+n, dsc->line_length-n, &i);
n += i;
if (i)
lly = dsc_get_int(dsc->line+n, dsc->line_length-n, &i);
n += i;
if (i)
urx = dsc_get_int(dsc->line+n, dsc->line_length-n, &i);
n += i;
if (i)
ury = dsc_get_int(dsc->line+n, dsc->line_length-n, &i);
if (i) {
*pbbox = (CDSCBBOX *)dsc_memalloc(dsc, sizeof(CDSCBBOX));
if (*pbbox == NULL)
return CDSC_ERROR; /* no memory */
(*pbbox)->llx = llx;
(*pbbox)->lly = lly;
(*pbbox)->urx = urx;
(*pbbox)->ury = ury;
}
else {
int rc = dsc_error(dsc, CDSC_MESSAGE_BBOX, dsc->line,
dsc->line_length);
switch (rc) {
case CDSC_RESPONSE_OK:
/* fllx = */ flly = furx = fury = 0.0;
n = offset;
n += i;
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 = (CDSCBBOX *)dsc_memalloc(dsc, sizeof(CDSCBBOX));
if (*pbbox == NULL)
return CDSC_ERROR; /* no memory */
(*pbbox)->llx = (int)fllx;
(*pbbox)->lly = (int)flly;
(*pbbox)->urx = (int)(furx+0.999);
(*pbbox)->ury = (int)(fury+0.999);
}
return CDSC_OK;
case CDSC_RESPONSE_CANCEL:
return CDSC_OK;
case CDSC_RESPONSE_IGNORE_ALL:
return CDSC_NOTDSC;
}
}
}
return CDSC_OK;
}
dsc_private int
dsc_parse_float_bounding_box(CDSC *dsc, CDSCFBBOX** pbbox, int offset)
{
unsigned int i, n;
float fllx, flly, furx, fury;
char *p;
/* Process first %%HiResBoundingBox: or %%CropBox: in comments,
* and last in trailer.
*/
if ((*pbbox != NULL) && (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 ((*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")) {
if (dsc->scan_section == scan_trailer)
dsc_unknown(dsc);
else {
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)")) {
if (dsc->scan_section == scan_trailer)
dsc_unknown(dsc);
/* 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")) {
if (dsc->scan_section == scan_trailer)
dsc_unknown(dsc);
else {
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)")) {
if (dsc->scan_section == scan_trailer)
dsc_unknown(dsc);
/* 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:
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -