Example #1
0
void
pdf_dict_put_val_null(fz_context *ctx, pdf_obj *obj, int idx)
{
	RESOLVE(obj);
	if (!OBJ_IS_DICT(obj))
		fz_throw(ctx, FZ_ERROR_GENERIC, "not a dict (%s)", pdf_objkindstr(obj));
	if (idx < 0 || idx >= DICT(obj)->len)
		fz_throw(ctx, FZ_ERROR_GENERIC, "index out of bounds");

	prepare_object_for_alteration(ctx, obj, NULL);
	pdf_drop_obj(ctx, DICT(obj)->items[idx].v);
	DICT(obj)->items[idx].v = PDF_OBJ_NULL;
}
Example #2
0
void
pdf_array_delete(fz_context *ctx, pdf_obj *obj, int i)
{
	RESOLVE(obj);
	if (!OBJ_IS_ARRAY(obj))
		fz_throw(ctx, FZ_ERROR_GENERIC, "not an array (%s)", pdf_objkindstr(obj));
	if (i < 0 || i >= ARRAY(obj)->len)
		fz_throw(ctx, FZ_ERROR_GENERIC, "index out of bounds");
	prepare_object_for_alteration(ctx, obj, NULL);
	pdf_drop_obj(ctx, ARRAY(obj)->items[i]);
	ARRAY(obj)->items[i] = 0;
	ARRAY(obj)->len--;
	memmove(ARRAY(obj)->items + i, ARRAY(obj)->items + i + 1, (ARRAY(obj)->len - i) * sizeof(pdf_obj*));
}
Example #3
0
void
pdf_array_insert(fz_context *ctx, pdf_obj *obj, pdf_obj *item, int i)
{
	RESOLVE(obj);
	if (!OBJ_IS_ARRAY(obj))
		fz_throw(ctx, FZ_ERROR_GENERIC, "not an array (%s)", pdf_objkindstr(obj));
	if (i < 0 || i > ARRAY(obj)->len)
		fz_throw(ctx, FZ_ERROR_GENERIC, "index out of bounds");
	prepare_object_for_alteration(ctx, obj, item);
	if (ARRAY(obj)->len + 1 > ARRAY(obj)->cap)
		pdf_array_grow(ctx, ARRAY(obj));
	memmove(ARRAY(obj)->items + i + 1, ARRAY(obj)->items + i, (ARRAY(obj)->len - i) * sizeof(pdf_obj*));
	ARRAY(obj)->items[i] = pdf_keep_obj(ctx, item);
	ARRAY(obj)->len++;
}
Example #4
0
void
pdf_array_push(fz_context *ctx, pdf_obj *obj, pdf_obj *item)
{
	RESOLVE(obj);
	if (!OBJ_IS_ARRAY(obj))
		fz_throw(ctx, FZ_ERROR_GENERIC, "not an array (%s)", pdf_objkindstr(obj));

	if (!item)
		item = PDF_OBJ_NULL;

	prepare_object_for_alteration(ctx, obj, item);
	if (ARRAY(obj)->len + 1 > ARRAY(obj)->cap)
		pdf_array_grow(ctx, ARRAY(obj));
	ARRAY(obj)->items[ARRAY(obj)->len] = pdf_keep_obj(ctx, item);
	ARRAY(obj)->len++;
}
Example #5
0
void
pdf_array_push(pdf_obj *obj, pdf_obj *item)
{
	RESOLVE(obj);

	if (!obj)
		return; /* Can't warn :( */
	if (obj->kind != PDF_ARRAY)
		fz_warn(obj->ctx, "assert: not an array (%s)", pdf_objkindstr(obj));
	else
	{
		if (obj->u.a.len + 1 > obj->u.a.cap)
			pdf_array_grow(obj);
		obj->u.a.items[obj->u.a.len] = pdf_keep_obj(item);
		obj->u.a.len++;
	}
}
Example #6
0
void
pdf_array_put(fz_context *ctx, pdf_obj *obj, int i, pdf_obj *item)
{
	RESOLVE(obj);
	if (!OBJ_IS_ARRAY(obj))
		fz_throw(ctx, FZ_ERROR_GENERIC, "not an array (%s)", pdf_objkindstr(obj));
	if (i == ARRAY(obj)->len)
	{
		pdf_array_push(ctx, obj, item);
		return;
	}
	if (i < 0 || i > ARRAY(obj)->len)
		fz_throw(ctx, FZ_ERROR_GENERIC, "index out of bounds");
	prepare_object_for_alteration(ctx, obj, item);
	pdf_drop_obj(ctx, ARRAY(obj)->items[i]);
	ARRAY(obj)->items[i] = pdf_keep_obj(ctx, item);
}
Example #7
0
void
pdf_array_delete(fz_context *ctx, pdf_obj *obj, int i)
{
	RESOLVE(obj);
	if (obj)
	{
		if (obj->kind != PDF_ARRAY)
			fz_warn(ctx, "assert: not an array (%s)", pdf_objkindstr(obj));
		else
		{
			pdf_drop_obj(ctx, obj->u.a.items[i]);
			obj->u.a.items[i] = 0;
			obj->u.a.len--;
			memmove(obj->u.a.items + i, obj->u.a.items + i + 1, (obj->u.a.len - i) * sizeof(pdf_obj*));
		}
	}
	return; /* Can't warn :( */
}
Example #8
0
void
pdf_array_put(pdf_obj *obj, int i, pdf_obj *item)
{
	RESOLVE(obj);

	if (!obj)
		return; /* Can't warn :( */
	if (obj->kind != PDF_ARRAY)
		fz_warn(obj->ctx, "assert: not an array (%s)", pdf_objkindstr(obj));
	else if (i < 0)
		fz_warn(obj->ctx, "assert: index %d < 0", i);
	else if (i >= obj->u.a.len)
		fz_warn(obj->ctx, "assert: index %d > length %d", i, obj->u.a.len);
	else
	{
		pdf_drop_obj(obj->u.a.items[i]);
		obj->u.a.items[i] = pdf_keep_obj(item);
	}
}
Example #9
0
pdf_obj *
pdf_copy_dict(fz_context *ctx, pdf_obj *obj)
{
	pdf_document *doc;
	pdf_obj *dict;
	int i, n;

	RESOLVE(obj);
	if (!OBJ_IS_DICT(obj))
		fz_throw(ctx, FZ_ERROR_GENERIC, "not a dict (%s)", pdf_objkindstr(obj));

	doc = DICT(obj)->doc;
	n = pdf_dict_len(ctx, obj);
	dict = pdf_new_dict(ctx, doc, n);
	for (i = 0; i < n; i++)
		pdf_dict_put(ctx, dict, pdf_dict_get_key(ctx, obj, i), pdf_dict_get_val(ctx, obj, i));

	return dict;
}
Example #10
0
pdf_obj *
pdf_copy_dict(fz_context *ctx, pdf_obj *obj)
{
	pdf_obj *dict;
	int i, n;

	RESOLVE(obj);
	if (!obj)
		return NULL; /* Can't warn :( */
	if (obj->kind != PDF_DICT)
		fz_warn(ctx, "assert: not a dict (%s)", pdf_objkindstr(obj));

	n = pdf_dict_len(obj);
	dict = pdf_new_dict(ctx, n);
	for (i = 0; i < n; i++)
		fz_dict_put(dict, pdf_dict_get_key(obj, i), pdf_dict_get_val(obj, i));

	return dict;
}
Example #11
0
void
pdf_array_push(fz_context *ctx, pdf_obj *obj, pdf_obj *item)
{
	RESOLVE(obj);
	if (obj)
	{
		if (obj->kind != PDF_ARRAY)
			fz_warn(ctx, "assert: not an array (%s)", pdf_objkindstr(obj));
		else
		{
			if (obj->u.a.len + 1 > obj->u.a.cap)
				pdf_array_grow(ctx, obj);
			obj->u.a.items[obj->u.a.len] = pdf_keep_obj(ctx, item);
			obj->u.a.len++;
		}

		object_altered(ctx, obj, item);
	}
	return; /* Can't warn :( */
}
Example #12
0
void
pdf_array_push(fz_context *ctx, pdf_obj *obj, pdf_obj *item)
{
	RESOLVE(obj);
	if (obj >= PDF_OBJ__LIMIT)
	{
		prepare_object_for_alteration(ctx, obj, item);

		if (obj->kind != PDF_ARRAY)
			fz_warn(ctx, "assert: not an array (%s)", pdf_objkindstr(obj));
		else
		{
			if (ARRAY(obj)->len + 1 > ARRAY(obj)->cap)
				pdf_array_grow(ctx, ARRAY(obj));
			ARRAY(obj)->items[ARRAY(obj)->len] = pdf_keep_obj(ctx, item);
			ARRAY(obj)->len++;
		}
	}
	return; /* Can't warn :( */
}
Example #13
0
pdf_obj *
pdf_copy_array(fz_context *ctx, pdf_obj *obj)
{
	pdf_obj *arr;
	int i;
	int n;

	RESOLVE(obj);
	if (!obj)
		return NULL; /* Can't warn :( */
	if (obj->kind != PDF_ARRAY)
		fz_warn(ctx, "assert: not an array (%s)", pdf_objkindstr(obj));

	arr = pdf_new_array(ctx, pdf_array_len(obj));
	n = pdf_array_len(obj);
	for (i = 0; i < n; i++)
		pdf_array_push(arr, pdf_array_get(obj, i));

	return arr;
}
Example #14
0
pdf_obj *
pdf_copy_array(fz_context *ctx, pdf_obj *obj)
{
	pdf_document *doc;
	pdf_obj *arr;
	int i;
	int n;

	RESOLVE(obj);
	if (obj < PDF_OBJ__LIMIT || obj->kind != PDF_ARRAY)
		fz_throw(ctx, FZ_ERROR_GENERIC, "assert: not an array (%s)", pdf_objkindstr(obj));

	doc = ARRAY(obj)->doc;

	n = pdf_array_len(ctx, obj);
	arr = pdf_new_array(ctx, doc, n);
	for (i = 0; i < n; i++)
		pdf_array_push(ctx, arr, pdf_array_get(ctx, obj, i));

	return arr;
}
Example #15
0
void
pdf_array_put(fz_context *ctx, pdf_obj *obj, int i, pdf_obj *item)
{
	RESOLVE(obj);
	if (obj >= PDF_OBJ__LIMIT)
	{
		prepare_object_for_alteration(ctx, obj, item);

		if (obj->kind != PDF_ARRAY)
			fz_warn(ctx, "assert: not an array (%s)", pdf_objkindstr(obj));
		else if (i < 0)
			fz_warn(ctx, "assert: index %d < 0", i);
		else if (i >= ARRAY(obj)->len)
			fz_warn(ctx, "assert: index %d > length %d", i, ARRAY(obj)->len);
		else
		{
			pdf_drop_obj(ctx, ARRAY(obj)->items[i]);
			ARRAY(obj)->items[i] = pdf_keep_obj(ctx, item);
		}
	}
	return; /* Can't warn :( */
}
Example #16
0
void
pdf_array_put(fz_context *ctx, pdf_obj *obj, int i, pdf_obj *item)
{
	RESOLVE(obj);
	if (obj)
	{
		if (obj->kind != PDF_ARRAY)
			fz_warn(ctx, "assert: not an array (%s)", pdf_objkindstr(obj));
		else if (i < 0)
			fz_warn(ctx, "assert: index %d < 0", i);
		else if (i >= obj->u.a.len)
			fz_warn(ctx, "assert: index %d > length %d", i, obj->u.a.len);
		else
		{
			pdf_drop_obj(ctx, obj->u.a.items[i]);
			obj->u.a.items[i] = pdf_keep_obj(ctx, item);
		}

		object_altered(ctx, obj, item);
	}
	return; /* Can't warn :( */
}
Example #17
0
void
pdf_array_insert(fz_context *ctx, pdf_obj *obj, pdf_obj *item, int i)
{
	RESOLVE(obj);
	if (obj)
	{
		if (obj->kind != PDF_ARRAY)
			fz_warn(ctx, "assert: not an array (%s)", pdf_objkindstr(obj));
		else
		{
			if (i < 0 || i > obj->u.a.len)
				fz_throw(ctx, FZ_ERROR_GENERIC, "attempt to insert object %d in array of length %d", i, obj->u.a.len);
			if (obj->u.a.len + 1 > obj->u.a.cap)
				pdf_array_grow(ctx, obj);
			memmove(obj->u.a.items + i + 1, obj->u.a.items + i, (obj->u.a.len - i) * sizeof(pdf_obj*));
			obj->u.a.items[i] = pdf_keep_obj(ctx, item);
			obj->u.a.len++;
		}

		object_altered(ctx, obj, item);
	}
	return; /* Can't warn :( */
}
Example #18
0
pdf_obj *
pdf_copy_dict(fz_context *ctx, pdf_obj *obj)
{
	pdf_obj *dict;
	int i, n;

	RESOLVE(obj);
	if (obj >= PDF_OBJ__LIMIT)
	{
		pdf_document *doc = DICT(obj)->doc;

		if (obj->kind != PDF_DICT)
			fz_warn(ctx, "assert: not a dict (%s)", pdf_objkindstr(obj));

		n = pdf_dict_len(ctx, obj);
		dict = pdf_new_dict(ctx, doc, n);
		for (i = 0; i < n; i++)
			pdf_dict_put(ctx, dict, pdf_dict_get_key(ctx, obj, i), pdf_dict_get_val(ctx, obj, i));

		return dict;
	}
	return NULL; /* Can't warn :( */
}
Example #19
0
void
pdf_array_insert(fz_context *ctx, pdf_obj *obj, pdf_obj *item, int i)
{
	RESOLVE(obj);
	if (obj >= PDF_OBJ__LIMIT)
	{
		prepare_object_for_alteration(ctx, obj, item);

		if (obj->kind != PDF_ARRAY)
			fz_warn(ctx, "assert: not an array (%s)", pdf_objkindstr(obj));
		else
		{
			if (i < 0 || i > ARRAY(obj)->len)
				fz_throw(ctx, FZ_ERROR_GENERIC, "attempt to insert object %d in array of length %d", i, ARRAY(obj)->len);
			if (ARRAY(obj)->len + 1 > ARRAY(obj)->cap)
				pdf_array_grow(ctx, ARRAY(obj));
			memmove(ARRAY(obj)->items + i + 1, ARRAY(obj)->items + i, (ARRAY(obj)->len - i) * sizeof(pdf_obj*));
			ARRAY(obj)->items[i] = pdf_keep_obj(ctx, item);
			ARRAY(obj)->len++;
		}
	}
	return; /* Can't warn :( */
}