summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--source/fitz/archive.c17
-rw-r--r--source/fitz/draw-glyph.c25
-rw-r--r--source/fitz/image.c119
-rw-r--r--source/fitz/load-pnm.c35
-rw-r--r--source/fitz/output-png.c8
-rw-r--r--source/fitz/output.c8
-rw-r--r--source/pdf/pdf-write.c61
7 files changed, 116 insertions, 157 deletions
diff --git a/source/fitz/archive.c b/source/fitz/archive.c
index 5bd3434b..96e70073 100644
--- a/source/fitz/archive.c
+++ b/source/fitz/archive.c
@@ -59,17 +59,12 @@ fz_open_archive_with_stream(fz_context *ctx, fz_stream *file)
{
fz_archive *arch = NULL;
- fz_try(ctx)
- {
- if (fz_is_zip_archive(ctx, file))
- arch = fz_open_zip_archive_with_stream(ctx, file);
- else if (fz_is_tar_archive(ctx, file))
- arch = fz_open_tar_archive_with_stream(ctx, file);
- else
- fz_throw(ctx, FZ_ERROR_GENERIC, "cannot recognize archive");
- }
- fz_catch(ctx)
- fz_rethrow(ctx);
+ if (fz_is_zip_archive(ctx, file))
+ arch = fz_open_zip_archive_with_stream(ctx, file);
+ else if (fz_is_tar_archive(ctx, file))
+ arch = fz_open_tar_archive_with_stream(ctx, file);
+ else
+ fz_throw(ctx, FZ_ERROR_GENERIC, "cannot recognize archive");
return arch;
}
diff --git a/source/fitz/draw-glyph.c b/source/fitz/draw-glyph.c
index dacee540..9c0a1b70 100644
--- a/source/fitz/draw-glyph.c
+++ b/source/fitz/draw-glyph.c
@@ -429,25 +429,18 @@ fz_render_glyph_pixmap(fz_context *ctx, fz_font *font, int gid, fz_matrix *ctm,
return NULL;
}
- fz_try(ctx)
+ if (is_ft_font)
{
- if (is_ft_font)
- {
- val = fz_render_ft_glyph_pixmap(ctx, font, gid, &subpix_ctm, aa);
- }
- else if (fz_font_t3_procs(ctx, font))
- {
- val = fz_render_t3_glyph_pixmap(ctx, font, gid, &subpix_ctm, NULL, scissor, aa);
- }
- else
- {
- fz_warn(ctx, "assert: uninitialized font structure");
- val = NULL;
- }
+ val = fz_render_ft_glyph_pixmap(ctx, font, gid, &subpix_ctm, aa);
}
- fz_catch(ctx)
+ else if (fz_font_t3_procs(ctx, font))
+ {
+ val = fz_render_t3_glyph_pixmap(ctx, font, gid, &subpix_ctm, NULL, scissor, aa);
+ }
+ else
{
- fz_rethrow(ctx);
+ fz_warn(ctx, "assert: uninitialized font structure");
+ val = NULL;
}
return val;
diff --git a/source/fitz/image.c b/source/fitz/image.c
index 9eedea8a..3ac2afeb 100644
--- a/source/fitz/image.c
+++ b/source/fitz/image.c
@@ -909,70 +909,65 @@ fz_new_image_from_buffer(fz_context *ctx, fz_buffer *buffer)
/* Note: cspace is only ever a borrowed reference here */
- fz_try(ctx)
+ if (buf[0] == 'P' && buf[1] >= '1' && buf[1] <= '7')
{
- if (buf[0] == 'P' && buf[1] >= '1' && buf[1] <= '7')
- {
- type = FZ_IMAGE_PNM;
- fz_load_pnm_info(ctx, buf, len, &w, &h, &xres, &yres, &cspace);
- }
- else if (buf[0] == 0xff && buf[1] == 0x4f)
- {
- type = FZ_IMAGE_JPX;
- fz_load_jpx_info(ctx, buf, len, &w, &h, &xres, &yres, &cspace);
- }
- else if (buf[0] == 0x00 && buf[1] == 0x00 && buf[2] == 0x00 && buf[3] == 0x0c && buf[4] == 0x6a && buf[5] == 0x50 && buf[6] == 0x20 && buf[7] == 0x20)
- {
- type = FZ_IMAGE_JPX;
- fz_load_jpx_info(ctx, buf, len, &w, &h, &xres, &yres, &cspace);
- }
- else if (buf[0] == 0xff && buf[1] == 0xd8)
- {
- type = FZ_IMAGE_JPEG;
- fz_load_jpeg_info(ctx, buf, len, &w, &h, &xres, &yres, &cspace);
- }
- else if (memcmp(buf, "\211PNG\r\n\032\n", 8) == 0)
- {
- type = FZ_IMAGE_PNG;
- fz_load_png_info(ctx, buf, len, &w, &h, &xres, &yres, &cspace);
- }
- else if (buf[0] == 'I' && buf[1] == 'I' && buf[2] == 0xBC)
- {
- type = FZ_IMAGE_JXR;
- fz_load_jxr_info(ctx, buf, len, &w, &h, &xres, &yres, &cspace);
- }
- else if (buf[0] == 'I' && buf[1] == 'I' && buf[2] == 42 && buf[3] == 0)
- {
- type = FZ_IMAGE_TIFF;
- fz_load_tiff_info(ctx, buf, len, &w, &h, &xres, &yres, &cspace);
- }
- else if (buf[0] == 'M' && buf[1] == 'M' && buf[2] == 0 && buf[3] == 42)
- {
- type = FZ_IMAGE_TIFF;
- fz_load_tiff_info(ctx, buf, len, &w, &h, &xres, &yres, &cspace);
- }
- else if (memcmp(buf, "GIF", 3) == 0)
- {
- type = FZ_IMAGE_GIF;
- fz_load_gif_info(ctx, buf, len, &w, &h, &xres, &yres, &cspace);
- }
- else if (memcmp(buf, "BM", 2) == 0)
- {
- type = FZ_IMAGE_BMP;
- fz_load_bmp_info(ctx, buf, len, &w, &h, &xres, &yres, &cspace);
- }
- else
- fz_throw(ctx, FZ_ERROR_GENERIC, "unknown image file format");
-
- bc = fz_malloc_struct(ctx, fz_compressed_buffer);
- bc->buffer = fz_keep_buffer(ctx, buffer);
- bc->params.type = type;
- if (type == FZ_IMAGE_JPEG)
- bc->params.u.jpeg.color_transform = -1;
- image = fz_new_image_from_compressed_buffer(ctx, w, h, 8, cspace, xres, yres, 0, 0, NULL, NULL, bc, NULL);
+ type = FZ_IMAGE_PNM;
+ fz_load_pnm_info(ctx, buf, len, &w, &h, &xres, &yres, &cspace);
}
- fz_catch(ctx)
- fz_rethrow(ctx);
+ else if (buf[0] == 0xff && buf[1] == 0x4f)
+ {
+ type = FZ_IMAGE_JPX;
+ fz_load_jpx_info(ctx, buf, len, &w, &h, &xres, &yres, &cspace);
+ }
+ else if (buf[0] == 0x00 && buf[1] == 0x00 && buf[2] == 0x00 && buf[3] == 0x0c && buf[4] == 0x6a && buf[5] == 0x50 && buf[6] == 0x20 && buf[7] == 0x20)
+ {
+ type = FZ_IMAGE_JPX;
+ fz_load_jpx_info(ctx, buf, len, &w, &h, &xres, &yres, &cspace);
+ }
+ else if (buf[0] == 0xff && buf[1] == 0xd8)
+ {
+ type = FZ_IMAGE_JPEG;
+ fz_load_jpeg_info(ctx, buf, len, &w, &h, &xres, &yres, &cspace);
+ }
+ else if (memcmp(buf, "\211PNG\r\n\032\n", 8) == 0)
+ {
+ type = FZ_IMAGE_PNG;
+ fz_load_png_info(ctx, buf, len, &w, &h, &xres, &yres, &cspace);
+ }
+ else if (buf[0] == 'I' && buf[1] == 'I' && buf[2] == 0xBC)
+ {
+ type = FZ_IMAGE_JXR;
+ fz_load_jxr_info(ctx, buf, len, &w, &h, &xres, &yres, &cspace);
+ }
+ else if (buf[0] == 'I' && buf[1] == 'I' && buf[2] == 42 && buf[3] == 0)
+ {
+ type = FZ_IMAGE_TIFF;
+ fz_load_tiff_info(ctx, buf, len, &w, &h, &xres, &yres, &cspace);
+ }
+ else if (buf[0] == 'M' && buf[1] == 'M' && buf[2] == 0 && buf[3] == 42)
+ {
+ type = FZ_IMAGE_TIFF;
+ fz_load_tiff_info(ctx, buf, len, &w, &h, &xres, &yres, &cspace);
+ }
+ else if (memcmp(buf, "GIF", 3) == 0)
+ {
+ type = FZ_IMAGE_GIF;
+ fz_load_gif_info(ctx, buf, len, &w, &h, &xres, &yres, &cspace);
+ }
+ else if (memcmp(buf, "BM", 2) == 0)
+ {
+ type = FZ_IMAGE_BMP;
+ fz_load_bmp_info(ctx, buf, len, &w, &h, &xres, &yres, &cspace);
+ }
+ else
+ fz_throw(ctx, FZ_ERROR_GENERIC, "unknown image file format");
+
+ bc = fz_malloc_struct(ctx, fz_compressed_buffer);
+ bc->buffer = fz_keep_buffer(ctx, buffer);
+ bc->params.type = type;
+ if (type == FZ_IMAGE_JPEG)
+ bc->params.u.jpeg.color_transform = -1;
+ image = fz_new_image_from_compressed_buffer(ctx, w, h, 8, cspace, xres, yres, 0, 0, NULL, NULL, bc, NULL);
return image;
}
diff --git a/source/fitz/load-pnm.c b/source/fitz/load-pnm.c
index 36493823..c30d0688 100644
--- a/source/fitz/load-pnm.c
+++ b/source/fitz/load-pnm.c
@@ -392,30 +392,25 @@ pam_binary_read_header(fz_context *ctx, struct info *pnm, unsigned char *p, unsi
{
int token = TOKEN_UNKNOWN;
- fz_try(ctx)
+ while (p < e && token != TOKEN_ENDHDR)
{
- while (p < e && token != TOKEN_ENDHDR)
+ p = pnm_read_token(ctx, p, e, &token);
+ p = pnm_read_white(ctx, p, e, 0);
+ switch (token)
{
- p = pnm_read_token(ctx, p, e, &token);
- p = pnm_read_white(ctx, p, e, 0);
- switch (token)
- {
- case TOKEN_WIDTH: p = pnm_read_number(ctx, p, e, &pnm->width); break;
- case TOKEN_HEIGHT: p = pnm_read_number(ctx, p, e, &pnm->height); break;
- case TOKEN_DEPTH: p = pnm_read_number(ctx, p, e, &pnm->depth); break;
- case TOKEN_MAXVAL: p = pnm_read_number(ctx, p, e, &pnm->maxval); break;
- case TOKEN_TUPLTYPE: p = pnm_read_tupletype(ctx, p, e, &pnm->tupletype); break;
- case TOKEN_ENDHDR: break;
- default:
- fz_throw(ctx, FZ_ERROR_GENERIC, "unknown header token in pnm image");
- }
-
- if (token != TOKEN_ENDHDR)
- p = pnm_read_white(ctx, p, e, 0);
+ case TOKEN_WIDTH: p = pnm_read_number(ctx, p, e, &pnm->width); break;
+ case TOKEN_HEIGHT: p = pnm_read_number(ctx, p, e, &pnm->height); break;
+ case TOKEN_DEPTH: p = pnm_read_number(ctx, p, e, &pnm->depth); break;
+ case TOKEN_MAXVAL: p = pnm_read_number(ctx, p, e, &pnm->maxval); break;
+ case TOKEN_TUPLTYPE: p = pnm_read_tupletype(ctx, p, e, &pnm->tupletype); break;
+ case TOKEN_ENDHDR: break;
+ default:
+ fz_throw(ctx, FZ_ERROR_GENERIC, "unknown header token in pnm image");
}
+
+ if (token != TOKEN_ENDHDR)
+ p = pnm_read_white(ctx, p, e, 0);
}
- fz_catch(ctx)
- fz_rethrow(ctx);
return p;
}
diff --git a/source/fitz/output-png.c b/source/fitz/output-png.c
index afda42f3..f67b1de0 100644
--- a/source/fitz/output-png.c
+++ b/source/fitz/output-png.c
@@ -356,13 +356,7 @@ fz_buffer *
fz_new_buffer_from_image_as_png(fz_context *ctx, fz_image *image, const fz_color_params *color_params)
{
fz_pixmap *pix = fz_get_pixmap_from_image(ctx, image, NULL, NULL, NULL, NULL);
- fz_buffer *buf = NULL;
-
- fz_try(ctx)
- buf = png_from_pixmap(ctx, pix, color_params, 1);
- fz_catch(ctx)
- fz_rethrow(ctx);
- return buf;
+ return png_from_pixmap(ctx, pix, color_params, 1);
}
fz_buffer *
diff --git a/source/fitz/output.c b/source/fitz/output.c
index a0f7fdee..44efc414 100644
--- a/source/fitz/output.c
+++ b/source/fitz/output.c
@@ -178,7 +178,6 @@ fz_new_output_with_file_ptr(fz_context *ctx, FILE *file, int close)
fz_output *
fz_new_output_with_path(fz_context *ctx, const char *filename, int append)
{
- fz_output *out = NULL;
FILE *file;
if (!strcmp(filename, "/dev/null") || !fz_strcasecmp(filename, "nul:"))
@@ -196,12 +195,7 @@ fz_new_output_with_path(fz_context *ctx, const char *filename, int append)
if (!file)
fz_throw(ctx, FZ_ERROR_GENERIC, "cannot open file '%s': %s", filename, strerror(errno));
- fz_try(ctx)
- out = fz_new_output_with_file_ptr(ctx, file, 1);
- fz_catch(ctx)
- fz_rethrow(ctx);
-
- return out;
+ return fz_new_output_with_file_ptr(ctx, file, 1);
}
static void
diff --git a/source/pdf/pdf-write.c b/source/pdf/pdf-write.c
index 5183b285..1111c0ff 100644
--- a/source/pdf/pdf-write.c
+++ b/source/pdf/pdf-write.c
@@ -1968,46 +1968,39 @@ static void writexref(fz_context *ctx, pdf_document *doc, pdf_write_state *opts,
fz_var(trailer);
- fz_try(ctx)
+ if (opts->do_incremental)
{
- if (opts->do_incremental)
- {
- trailer = pdf_keep_obj(ctx, pdf_trailer(ctx, doc));
- pdf_dict_put_drop(ctx, trailer, PDF_NAME_Size, pdf_new_int(ctx, doc, pdf_xref_len(ctx, doc)));
- pdf_dict_put_drop(ctx, trailer, PDF_NAME_Prev, pdf_new_int(ctx, doc, doc->startxref));
- doc->startxref = startxref;
- }
- else
- {
- trailer = pdf_new_dict(ctx, doc, 5);
+ trailer = pdf_keep_obj(ctx, pdf_trailer(ctx, doc));
+ pdf_dict_put_drop(ctx, trailer, PDF_NAME_Size, pdf_new_int(ctx, doc, pdf_xref_len(ctx, doc)));
+ pdf_dict_put_drop(ctx, trailer, PDF_NAME_Prev, pdf_new_int(ctx, doc, doc->startxref));
+ doc->startxref = startxref;
+ }
+ else
+ {
+ trailer = pdf_new_dict(ctx, doc, 5);
- nobj = pdf_new_int(ctx, doc, to);
- pdf_dict_put_drop(ctx, trailer, PDF_NAME_Size, nobj);
+ nobj = pdf_new_int(ctx, doc, to);
+ pdf_dict_put_drop(ctx, trailer, PDF_NAME_Size, nobj);
- if (first)
- {
- obj = pdf_dict_get(ctx, pdf_trailer(ctx, doc), PDF_NAME_Info);
- if (obj)
- pdf_dict_put(ctx, trailer, PDF_NAME_Info, obj);
+ if (first)
+ {
+ obj = pdf_dict_get(ctx, pdf_trailer(ctx, doc), PDF_NAME_Info);
+ if (obj)
+ pdf_dict_put(ctx, trailer, PDF_NAME_Info, obj);
- obj = pdf_dict_get(ctx, pdf_trailer(ctx, doc), PDF_NAME_Root);
- if (obj)
- pdf_dict_put(ctx, trailer, PDF_NAME_Root, obj);
+ obj = pdf_dict_get(ctx, pdf_trailer(ctx, doc), PDF_NAME_Root);
+ if (obj)
+ pdf_dict_put(ctx, trailer, PDF_NAME_Root, obj);
- obj = pdf_dict_get(ctx, pdf_trailer(ctx, doc), PDF_NAME_ID);
- if (obj)
- pdf_dict_put(ctx, trailer, PDF_NAME_ID, obj);
- }
- if (main_xref_offset != 0)
- {
- nobj = pdf_new_int(ctx, doc, main_xref_offset);
- pdf_dict_put_drop(ctx, trailer, PDF_NAME_Prev, nobj);
- }
+ obj = pdf_dict_get(ctx, pdf_trailer(ctx, doc), PDF_NAME_ID);
+ if (obj)
+ pdf_dict_put(ctx, trailer, PDF_NAME_ID, obj);
+ }
+ if (main_xref_offset != 0)
+ {
+ nobj = pdf_new_int(ctx, doc, main_xref_offset);
+ pdf_dict_put_drop(ctx, trailer, PDF_NAME_Prev, nobj);
}
- }
- fz_catch(ctx)
- {
- fz_rethrow(ctx);
}
fz_write_string(ctx, opts->out, "trailer\n");