summaryrefslogtreecommitdiff
path: root/src/cos_object.c
diff options
context:
space:
mode:
authorVincent Sanders <vince@kyllikki.org>2017-12-28 17:18:10 +0000
committerVincent Sanders <vince@kyllikki.org>2017-12-28 17:18:10 +0000
commit5422dd50a49fe1a282271f22cd324f815e592e07 (patch)
tree99c0760ab8318b7e9d8e8190886affad0b8e4e70 /src/cos_object.c
parent7da4a1d7b029ab640a9ae2b95e745d29c998a7b0 (diff)
downloadlibnspdf-5422dd50a49fe1a282271f22cd324f815e592e07.tar.gz
libnspdf-5422dd50a49fe1a282271f22cd324f815e592e07.tar.bz2
decode page tree
Diffstat (limited to 'src/cos_object.c')
-rw-r--r--src/cos_object.c148
1 files changed, 148 insertions, 0 deletions
diff --git a/src/cos_object.c b/src/cos_object.c
index a5bd738..5bfd423 100644
--- a/src/cos_object.c
+++ b/src/cos_object.c
@@ -188,6 +188,59 @@ cos_get_dictionary_dictionary(struct pdf_doc *doc,
}
nspdferror
+cos_heritable_dictionary_dictionary(struct pdf_doc *doc,
+ struct cos_object *dict,
+ const char *key,
+ struct cos_object **value_out)
+{
+ nspdferror res;
+ struct cos_object *dict_value;
+ res = cos_get_dictionary_value(doc, dict, key, &dict_value);
+ if (res == NSPDFERROR_NOTFOUND) {
+ /* \todo get parent entry and extract key from that dictionary instead */
+ }
+ if (res != NSPDFERROR_OK) {
+ return res;
+ }
+ return cos_get_dictionary(doc, dict_value, value_out);
+}
+
+nspdferror
+cos_get_dictionary_array(struct pdf_doc *doc,
+ struct cos_object *dict,
+ const char *key,
+ struct cos_object **value_out)
+{
+ nspdferror res;
+ struct cos_object *dict_value;
+
+ res = cos_get_dictionary_value(doc, dict, key, &dict_value);
+ if (res != NSPDFERROR_OK) {
+ return res;
+ }
+ return cos_get_array(doc, dict_value, value_out);
+}
+
+nspdferror
+cos_heritable_dictionary_array(struct pdf_doc *doc,
+ struct cos_object *dict,
+ const char *key,
+ struct cos_object **value_out)
+{
+ nspdferror res;
+ struct cos_object *dict_value;
+
+ res = cos_get_dictionary_value(doc, dict, key, &dict_value);
+ if (res == NSPDFERROR_NOTFOUND) {
+ /* \todo get parent entry and extract key from that dictionary instead */
+ }
+ if (res != NSPDFERROR_OK) {
+ return res;
+ }
+ return cos_get_array(doc, dict_value, value_out);
+}
+
+nspdferror
cos_get_int(struct pdf_doc *doc,
struct cos_object *cobj,
int64_t *value_out)
@@ -242,3 +295,98 @@ cos_get_dictionary(struct pdf_doc *doc,
}
return res;
}
+
+nspdferror
+cos_get_array(struct pdf_doc *doc,
+ struct cos_object *cobj,
+ struct cos_object **value_out)
+{
+ nspdferror res;
+
+ res = xref_get_referenced(doc, &cobj);
+ if (res == NSPDFERROR_OK) {
+ if (cobj->type != COS_TYPE_ARRAY) {
+ res = NSPDFERROR_TYPE;
+ } else {
+ *value_out = cobj;
+ }
+ }
+ return res;
+}
+
+/*
+ * get a value for a key from a dictionary
+ */
+nspdferror
+cos_get_array_value(struct pdf_doc *doc,
+ struct cos_object *array,
+ unsigned int index,
+ struct cos_object **value_out)
+{
+ nspdferror res;
+ struct cos_array_entry *entry;
+
+ res = xref_get_referenced(doc, &array);
+ if (res == NSPDFERROR_OK) {
+ if (array->type != COS_TYPE_ARRAY) {
+ res = NSPDFERROR_TYPE;
+ } else {
+ unsigned int cur_index = 0;
+ res = NSPDFERROR_RANGE;
+
+ entry = array->u.array;
+ while (entry != NULL) {
+ if (cur_index == index) {
+ *value_out = entry->value;
+ res = NSPDFERROR_OK;
+ break;
+ }
+ cur_index++;
+ entry = entry->next;
+ }
+ }
+ }
+ return res;
+}
+
+nspdferror
+cos_get_array_dictionary(struct pdf_doc *doc,
+ struct cos_object *array,
+ unsigned int index,
+ struct cos_object **value_out)
+{
+ nspdferror res;
+ struct cos_object *array_value;
+
+ res = cos_get_array_value(doc, array, index, &array_value);
+ if (res != NSPDFERROR_OK) {
+ return res;
+ }
+ return cos_get_dictionary(doc, array_value, value_out);
+}
+
+nspdferror
+cos_get_array_size(struct pdf_doc *doc,
+ struct cos_object *cobj,
+ unsigned int *size_out)
+{
+ nspdferror res;
+ unsigned int array_size = 0;
+ struct cos_array_entry *array_entry;
+
+ res = xref_get_referenced(doc, &cobj);
+ if (res == NSPDFERROR_OK) {
+ if (cobj->type != COS_TYPE_ARRAY) {
+ res = NSPDFERROR_TYPE;
+ } else {
+ /* walk array list to enumerate entries */
+ array_entry = cobj->u.array;
+ while (array_entry != NULL) {
+ array_size++;
+ array_entry = array_entry->next;
+ }
+ *size_out = array_size;
+ }
+ }
+ return res;
+}