summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVincent Sanders <vince@kyllikki.org>2018-01-23 22:56:24 +0000
committerVincent Sanders <vince@kyllikki.org>2018-01-23 22:56:24 +0000
commit04517ee5560353cab1ecf5d24a1cb6301d3a8b05 (patch)
tree5fa1cf66a8bb751a93e0fdf905d712110a4af077
parent3fe413e5838eaf9d8bc30a9a49f0d7707e84db35 (diff)
downloadlibnspdf-04517ee5560353cab1ecf5d24a1cb6301d3a8b05.tar.gz
libnspdf-04517ee5560353cab1ecf5d24a1cb6301d3a8b05.tar.bz2
rename cos object name entry
-rw-r--r--src/cos_object.c28
-rw-r--r--src/cos_object.h17
-rw-r--r--src/cos_parse.c2
3 files changed, 41 insertions, 6 deletions
diff --git a/src/cos_object.c b/src/cos_object.c
index 7a02ebd..0c97190 100644
--- a/src/cos_object.c
+++ b/src/cos_object.c
@@ -29,7 +29,7 @@ nspdferror cos_free_object(struct cos_object *cos_obj)
switch (cos_obj->type) {
case COS_TYPE_NAME:
- free(cos_obj->u.n);
+ free(cos_obj->u.name);
break;
case COS_TYPE_STRING:
@@ -92,7 +92,7 @@ cos_extract_dictionary_value(struct cos_object *dict,
prev = &dict->u.dictionary;
entry = *prev;
while (entry != NULL) {
- if (strcmp(entry->key->u.n, key) == 0) {
+ if (strcmp(entry->key->u.name, key) == 0) {
*value_out = entry->value;
*prev = entry->next;
cos_free_object(entry->key);
@@ -127,7 +127,7 @@ cos_get_dictionary_value(struct nspdf_doc *doc,
entry = dict->u.dictionary;
while (entry != NULL) {
- if (strcmp(entry->key->u.n, key) == 0) {
+ if (strcmp(entry->key->u.name, key) == 0) {
*value_out = entry->value;
res = NSPDFERROR_OK;
break;
@@ -275,6 +275,26 @@ cos_get_int(struct nspdf_doc *doc,
}
nspdferror
+cos_get_number(struct nspdf_doc *doc,
+ struct cos_object *cobj,
+ float *value_out)
+{
+ nspdferror res;
+
+ res = nspdf__xref_get_referenced(doc, &cobj);
+ if (res == NSPDFERROR_OK) {
+ if (cobj->type == COS_TYPE_INT) {
+ *value_out = (float)cobj->u.i;
+ } else if (cobj->type == COS_TYPE_REAL) {
+ *value_out = cobj->u.real;
+ } else {
+ res = NSPDFERROR_TYPE;
+ }
+ }
+ return res;
+}
+
+nspdferror
cos_get_name(struct nspdf_doc *doc,
struct cos_object *cobj,
const char **value_out)
@@ -286,7 +306,7 @@ cos_get_name(struct nspdf_doc *doc,
if (cobj->type != COS_TYPE_NAME) {
res = NSPDFERROR_TYPE;
} else {
- *value_out = cobj->u.n;
+ *value_out = cobj->u.name;
}
}
return res;
diff --git a/src/cos_object.h b/src/cos_object.h
index c5b85fa..56c2179 100644
--- a/src/cos_object.h
+++ b/src/cos_object.h
@@ -101,7 +101,7 @@ struct cos_object {
float real;
/** name */
- char *n;
+ char *name;
/** string */
struct cos_string *s;
@@ -200,6 +200,21 @@ nspdferror cos_get_array_dictionary(struct nspdf_doc *doc, struct cos_object *ar
nspdferror cos_get_int(struct nspdf_doc *doc, struct cos_object *cobj, int64_t *value_out);
/**
+ * get the float value of a cos object.
+ *
+ * Get the value from a cos object, if the object is an object reference it
+ * will be dereferenced first. The dereferencing will parse any previously
+ * unreferenced indirect objects as required.
+ *
+ * \param doc The document the cos object belongs to.
+ * \param cobj A cos object of integer type.
+ * \param value_out The result value.
+ * \return NSERROR_OK and \p value_out updated,
+ * NSERROR_TYPE if the \p cobj is not an integer
+ */
+nspdferror cos_get_number(struct nspdf_doc *doc, struct cos_object *cobj, float *value_out);
+
+/**
* get the name value of a cos object.
*
* Get the value from a cos object, if the object is an object reference it
diff --git a/src/cos_parse.c b/src/cos_parse.c
index 46282ca..1881e6a 100644
--- a/src/cos_parse.c
+++ b/src/cos_parse.c
@@ -569,7 +569,7 @@ cos_parse_name(struct cos_stream *stream,
}
cosobj->type = COS_TYPE_NAME;
- cosobj->u.n = strdup(name);
+ cosobj->u.name = strdup(name);
*cosobj_out = cosobj;