summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSam James <sam@gentoo.org>2022-09-21 14:18:08 +0100
committerSam James <sam@gentoo.org>2022-10-02 04:31:25 +0100
commita529111f77ff46f4836fe7312e70953bc16587cf (patch)
tree9dc3924cb1a6ef3ef853b7bb45f735365e0b4e6d /pdf/pdf_obj.h
parentImport Ghostscript 9.56.1 (diff)
downloadghostscript-gpl-patches-a529111f77ff46f4836fe7312e70953bc16587cf.tar.gz
ghostscript-gpl-patches-a529111f77ff46f4836fe7312e70953bc16587cf.tar.bz2
ghostscript-gpl-patches-a529111f77ff46f4836fe7312e70953bc16587cf.zip
Import Ghostscript 10.0ghostscript-10.0ghostscript-10
Signed-off-by: Sam James <sam@gentoo.org>
Diffstat (limited to 'pdf/pdf_obj.h')
-rw-r--r--pdf/pdf_obj.h88
1 files changed, 87 insertions, 1 deletions
diff --git a/pdf/pdf_obj.h b/pdf/pdf_obj.h
index 99c9a178..eb512db9 100644
--- a/pdf/pdf_obj.h
+++ b/pdf/pdf_obj.h
@@ -1,4 +1,4 @@
-/* Copyright (C) 2020-2021 Artifex Software, Inc.
+/* Copyright (C) 2020-2022 Artifex Software, Inc.
All Rights Reserved.
This software is provided AS-IS with no warranty, either express or
@@ -25,4 +25,90 @@ int pdfi_obj_charstr_to_name(pdf_context *ctx, const char *charstr, pdf_name **n
int pdfi_obj_get_label(pdf_context *ctx, pdf_obj *obj, char **label);
int pdfi_num_alloc(pdf_context *ctx, double d, pdf_num **num);
+static inline int
+pdfi_obj_to_real(pdf_context *ctx, pdf_obj *obj, double *d)
+{
+ pdf_num *num = (pdf_num *)obj;
+
+ switch (pdfi_type_of(num)) {
+ case PDF_INT:
+ *d = (double)num->value.i;
+ break;
+ case PDF_REAL:
+ *d = num->value.d;
+ break;
+ default:
+ return_error(gs_error_typecheck);
+ }
+
+ return 0;
+}
+
+static inline int
+pdfi_obj_to_float(pdf_context *ctx, pdf_obj *obj, float *f)
+{
+ pdf_num *num = (pdf_num *)obj;
+
+ switch (pdfi_type_of(num)) {
+ case PDF_INT:
+ *f = (float)num->value.i;
+ break;
+ case PDF_REAL:
+ *f = (float)num->value.d;
+ break;
+ default:
+ return_error(gs_error_typecheck);
+ }
+
+ return 0;
+}
+
+static inline int
+pdfi_obj_to_int(pdf_context *ctx, pdf_obj *obj, int64_t *i)
+{
+ pdf_num *num = (pdf_num *)obj;
+ int64_t tmp;
+
+ switch (pdfi_type_of(num)) {
+ case PDF_INT:
+ *i = num->value.i;
+ break;
+ case PDF_REAL:
+ /* We shouldn't be given a real here. We will grudgingly accept
+ * (with a warning) an int given as a real, but will error out
+ * otherwise. If we find a case where we need to accept reals
+ * as ints, we'll do a new version of this function called something
+ * like pdfi_obj_real_as_int what will just cast it down. */
+ tmp = (int64_t)num->value.d;
+ if ((double)tmp != num->value.d) {
+ return_error(gs_error_typecheck);
+ }
+ pdfi_set_warning(ctx, 0, NULL, W_PDF_INT_AS_REAL, "pdfi_obj_to_int", NULL);
+ *i = tmp;
+ break;
+ default:
+ return_error(gs_error_typecheck);
+ }
+
+ return 0;
+}
+
+/* NOTE: the buffer object takes ownership of "data" */
+static inline int
+pdfi_buffer_set_data(pdf_obj *o, byte *data, int32_t length)
+{
+ pdf_buffer *b = (pdf_buffer *)o;
+ if (pdfi_type_of(b) != PDF_BUFFER) {
+ return_error(gs_error_typecheck);
+ }
+
+ if (b->data) {
+ gs_free_object(OBJ_MEMORY(b), b->data, "pdfi_buffer_set_data(data)");
+ }
+ b->data = data;
+ b->length = length;
+ return 0;
+}
+
+
#endif