diff options
author | Paul Gardiner <paul@glidos.net> | 2012-05-07 14:35:01 +0100 |
---|---|---|
committer | Paul Gardiner <paul@glidos.net> | 2012-05-07 14:35:01 +0100 |
commit | 994bd7d7a1cf652cffa313c10466abe0165448b3 (patch) | |
tree | 870b0c23766256e53c45603ef9f2b9d280f29470 /pdf/pdf_lex.c | |
parent | 63fc310d23f3fd3b54739a44208f3317add18caf (diff) | |
download | mupdf-994bd7d7a1cf652cffa313c10466abe0165448b3.tar.xz |
A few general utility functions added for the sake of the forms work
Diffstat (limited to 'pdf/pdf_lex.c')
-rw-r--r-- | pdf/pdf_lex.c | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/pdf/pdf_lex.c b/pdf/pdf_lex.c index 6774167a..c6ab6604 100644 --- a/pdf/pdf_lex.c +++ b/pdf/pdf_lex.c @@ -461,3 +461,55 @@ pdf_lex(fz_stream *f, pdf_lexbuf *buf) } } } + +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: + { + int i; + fz_buffer_printf(ctx, fzbuf, "<"); + for (i = 0; i < buf->len; i++) + fz_buffer_printf(ctx, fzbuf, "%02X", buf->scratch[i]); + fz_buffer_printf(ctx, fzbuf, ">"); + } + 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; + } +} |