diff options
author | Vincent Sanders <vince@kyllikki.org> | 2018-01-08 23:09:23 +0000 |
---|---|---|
committer | Vincent Sanders <vince@kyllikki.org> | 2018-01-08 23:09:23 +0000 |
commit | b668680da5aa0930820df70f1b182243a7a8cde4 (patch) | |
tree | a45cb44b96341971ee1e7ace312bcec284f1dd72 | |
parent | 615323e574ffcecd8525711c39beffcac4156624 (diff) | |
download | libnspdf-b668680da5aa0930820df70f1b182243a7a8cde4.tar.gz libnspdf-b668680da5aa0930820df70f1b182243a7a8cde4.tar.bz2 |
split out stream filtering
-rw-r--r-- | src/Makefile | 2 | ||||
-rw-r--r-- | src/cos_parse.c | 13 | ||||
-rw-r--r-- | src/cos_stream_filter.c | 33 | ||||
-rw-r--r-- | src/pdf_doc.h | 10 |
4 files changed, 54 insertions, 4 deletions
diff --git a/src/Makefile b/src/Makefile index a2d1ae8..35576c2 100644 --- a/src/Makefile +++ b/src/Makefile @@ -1,3 +1,3 @@ -DIR_SOURCES := document.c byte_class.c cos_parse.c cos_object.c pdf_doc.c meta.c page.c xref.c +DIR_SOURCES := document.c byte_class.c cos_parse.c cos_object.c pdf_doc.c meta.c page.c xref.c cos_stream_filter.c include $(NSBUILD)/Makefile.subdir diff --git a/src/cos_parse.c b/src/cos_parse.c index 5448ad4..de85b0c 100644 --- a/src/cos_parse.c +++ b/src/cos_parse.c @@ -27,6 +27,7 @@ /** Maximum length of cos name */ #define NAME_MAX_LENGTH 127 + static nspdferror cos_string_append(struct cos_string *s, uint8_t c) { @@ -717,8 +718,16 @@ cos_parse_stream(struct nspdf_doc *doc, /* optional filter */ res = cos_get_dictionary_value(doc, stream_dict, "Filter", &stream_filter); if (res == NSPDFERROR_OK) { - /** \todo filter stream */ - printf("applying filter %s\n", stream_filter->u.n); + const char *filter_name; + res = cos_get_name(doc, stream_filter, &filter_name); + if (res == NSPDFERROR_OK) { + res = nspdf__cos_stream_filter(doc, filter_name, &stream); + if (res != NSPDFERROR_OK) { + return res; + } + } else { + /** \todo array of filter stream */ + } } /* allocate stream object */ diff --git a/src/cos_stream_filter.c b/src/cos_stream_filter.c new file mode 100644 index 0000000..6f407de --- /dev/null +++ b/src/cos_stream_filter.c @@ -0,0 +1,33 @@ +/* + * Copyright 2018 Vincent Sanders <vince@netsurf-browser.org> + * + * This file is part of libnspdf. + * + * Licensed under the MIT License, + * http://www.opensource.org/licenses/mit-license.php + */ + +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include <stdlib.h> +#include <stdio.h> +#include <string.h> + +#include <nspdf/errors.h> + +#include "cos_object.h" +#include "pdf_doc.h" + +nspdferror +nspdf__cos_stream_filter(struct nspdf_doc *doc, + const char *filter_name, + struct cos_stream **stream_out) +{ + struct cos_stream *stream_in; + + stream_in = *stream_out; + + printf("applying filter %s\n", filter_name); + return NSPDFERROR_OK; +} diff --git a/src/pdf_doc.h b/src/pdf_doc.h index b7e6546..e362ea6 100644 --- a/src/pdf_doc.h +++ b/src/pdf_doc.h @@ -46,16 +46,18 @@ struct nspdf_doc { /* byte data acessory, allows for more complex buffer handling in future */ #define DOC_BYTE(doc, offset) (doc->start[(offset)]) -/* helpers in pdf_doc.h */ +/* helpers in pdf_doc.c */ nspdferror doc_skip_ws(struct nspdf_doc *doc, uint64_t *offset); nspdferror doc_skip_eol(struct nspdf_doc *doc, uint64_t *offset); nspdferror doc_read_uint(struct nspdf_doc *doc, uint64_t *offset_out, uint64_t *result_out); +/* cross reference table handlers */ /** * parse xref from file */ nspdferror nspdf__xref_parse(struct nspdf_doc *doc, uint64_t *offset_out); + /** * get an object dereferencing through xref table if necessary */ @@ -65,4 +67,10 @@ nspdferror nspdf__xref_allocate(struct nspdf_doc *doc, int64_t size); nspdferror nspdf__decode_page_tree(struct nspdf_doc *doc, struct cos_object *page_tree_node, unsigned int *page_index); +/* cos stream filters */ +nspdferror +nspdf__cos_stream_filter(struct nspdf_doc *doc, + const char *filter_name, + struct cos_stream **stream_out); + #endif |