void pdf_print_token(fz_context *ctx, fz_buffer *fzbuf, int tok, pdf_lexbuf *buf) { switch (tok) { case PDF_TOK_NAME: fz_buffer_printf(ctx, fzbuf, "/%s", buf->scratch); break; case PDF_TOK_STRING: if (buf->len >= buf->size) pdf_lexbuf_grow(buf); buf->scratch[buf->len] = 0; fz_buffer_cat_pdf_string(ctx, fzbuf, buf->scratch); break; case PDF_TOK_OPEN_DICT: fz_buffer_printf(ctx, fzbuf, "<<"); break; case PDF_TOK_CLOSE_DICT: fz_buffer_printf(ctx, fzbuf, ">>"); break; case PDF_TOK_OPEN_ARRAY: fz_buffer_printf(ctx, fzbuf, "["); break; case PDF_TOK_CLOSE_ARRAY: fz_buffer_printf(ctx, fzbuf, "]"); break; case PDF_TOK_OPEN_BRACE: fz_buffer_printf(ctx, fzbuf, "{"); break; case PDF_TOK_CLOSE_BRACE: fz_buffer_printf(ctx, fzbuf, "}"); break; case PDF_TOK_INT: fz_buffer_printf(ctx, fzbuf, "%d", buf->i); break; case PDF_TOK_REAL: { char sbuf[256]; sprintf(sbuf, "%g", buf->f); if (strchr(sbuf, 'e')) /* bad news! */ sprintf(sbuf, fabsf(buf->f) > 1 ? "%1.1f" : "%1.8f", buf->f); fz_buffer_printf(ctx, fzbuf, "%s", sbuf); } break; default: fz_buffer_printf(ctx, fzbuf, "%s", buf->scratch); break; } }
void pdf_print_token(fz_context *ctx, fz_buffer *fzbuf, int tok, pdf_lexbuf *buf) { switch (tok) { case PDF_TOK_NAME: fz_buffer_printf(ctx, fzbuf, "/%s", buf->scratch); break; case PDF_TOK_STRING: if (buf->len >= buf->size) pdf_lexbuf_grow(buf); buf->scratch[buf->len] = 0; fz_buffer_cat_pdf_string(ctx, fzbuf, buf->scratch); break; case PDF_TOK_OPEN_DICT: fz_buffer_printf(ctx, fzbuf, "<<"); break; case PDF_TOK_CLOSE_DICT: fz_buffer_printf(ctx, fzbuf, ">>"); break; case PDF_TOK_OPEN_ARRAY: fz_buffer_printf(ctx, fzbuf, "["); break; case PDF_TOK_CLOSE_ARRAY: fz_buffer_printf(ctx, fzbuf, "]"); break; case PDF_TOK_OPEN_BRACE: fz_buffer_printf(ctx, fzbuf, "{"); break; case PDF_TOK_CLOSE_BRACE: fz_buffer_printf(ctx, fzbuf, "}"); break; case PDF_TOK_INT: fz_buffer_printf(ctx, fzbuf, "%d", buf->i); break; case PDF_TOK_REAL: { fz_buffer_printf(ctx, fzbuf, "%g", buf->f); } break; default: fz_buffer_printf(ctx, fzbuf, "%s", buf->scratch); break; } }
static int lex_hex_string(fz_stream *f, pdf_lexbuf *lb) { char *s = lb->scratch; char *e = s + lb->size; int a = 0, x = 0; int c; while (1) { if (s == e) { s += pdf_lexbuf_grow(lb); e = lb->scratch + lb->size; } c = fz_read_byte(f); switch (c) { case IS_WHITE: break; case IS_HEX: if (x) { *s++ = a * 16 + unhex(c); x = !x; } else { a = unhex(c); x = !x; } break; case '>': case EOF: goto end; default: fz_warn(f->ctx, "ignoring invalid character in hex string"); } } end: lb->len = s - lb->scratch; return PDF_TOK_STRING; }
static int lex_string(fz_stream *f, pdf_lexbuf *lb) { char *s = lb->scratch; char *e = s + lb->size; int bal = 1; int oct; int c; while (1) { if (s == e) { s += pdf_lexbuf_grow(lb); e = lb->scratch + lb->size; } c = fz_read_byte(f); switch (c) { case EOF: goto end; case '(': bal++; *s++ = c; break; case ')': bal --; if (bal == 0) goto end; *s++ = c; break; case '\\': c = fz_read_byte(f); switch (c) { case EOF: goto end; case 'n': *s++ = '\n'; break; case 'r': *s++ = '\r'; break; case 't': *s++ = '\t'; break; case 'b': *s++ = '\b'; break; case 'f': *s++ = '\f'; break; case '(': *s++ = '('; break; case ')': *s++ = ')'; break; case '\\': *s++ = '\\'; break; case RANGE_0_7: oct = c - '0'; c = fz_read_byte(f); if (c >= '0' && c <= '7') { oct = oct * 8 + (c - '0'); c = fz_read_byte(f); if (c >= '0' && c <= '7') oct = oct * 8 + (c - '0'); else if (c != EOF) fz_unread_byte(f); } else if (c != EOF) fz_unread_byte(f); *s++ = oct; break; case '\n': break; case '\r': c = fz_read_byte(f); if ((c != '\n') && (c != EOF)) fz_unread_byte(f); break; default: *s++ = c; } break; default: *s++ = c; break; } } end: lb->len = s - lb->scratch; return PDF_TOK_STRING; }