summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/mupdf/fitz/output.h3
-rw-r--r--platform/x11/pdfapp.c2
-rw-r--r--source/fitz/output-pcl.c8
-rw-r--r--source/fitz/output-ps.c12
-rw-r--r--source/pdf/pdf-appearance.c32
-rw-r--r--source/pdf/pdf-device.c28
-rw-r--r--source/pdf/pdf-op-buffer.c198
7 files changed, 144 insertions, 139 deletions
diff --git a/include/mupdf/fitz/output.h b/include/mupdf/fitz/output.h
index d1282352..023153a9 100644
--- a/include/mupdf/fitz/output.h
+++ b/include/mupdf/fitz/output.h
@@ -273,8 +273,9 @@ static inline void fz_write_rune(fz_context *ctx, fz_output *out, int rune)
/*
fz_vsnprintf: Our customised vsnprintf routine. Takes %c, %d, %o, %s, %u, %x, as usual.
Modifiers are not supported except for zero-padding ints (e.g. %02d, %03o, %04x, etc).
- %f and %g both output in "as short as possible hopefully lossless non-exponent" form,
+ %g output in "as short as possible hopefully lossless non-exponent" form,
see fz_ftoa for specifics.
+ %f and %e output as usual.
%C outputs a utf8 encoded int.
%M outputs a fz_matrix*. %R outputs a fz_rect*. %P outputs a fz_point*.
%q and %( output escaped strings in C/PDF syntax.
diff --git a/platform/x11/pdfapp.c b/platform/x11/pdfapp.c
index be7c0ac0..6f9e7a5a 100644
--- a/platform/x11/pdfapp.c
+++ b/platform/x11/pdfapp.c
@@ -247,7 +247,7 @@ static int make_fake_doc(pdfapp_t *app)
contents = fz_new_buffer(ctx, 100);
- fz_append_printf(ctx, contents, "1 0 0 RG %f w 0 0 m %f %f l 0 %f m %f 0 l s\n",
+ fz_append_printf(ctx, contents, "1 0 0 RG %g w 0 0 m %g %g l 0 %g m %g 0 l s\n",
fz_min(mediabox.x1, mediabox.y1) / 20,
mediabox.x1, mediabox.y1,
mediabox.y1, mediabox.x1);
diff --git a/source/fitz/output-pcl.c b/source/fitz/output-pcl.c
index ab95f6aa..e26b8c34 100644
--- a/source/fitz/output-pcl.c
+++ b/source/fitz/output-pcl.c
@@ -736,7 +736,7 @@ color_pcl_write_header(fz_context *ctx, fz_band_writer *writer_)
/* Raster presentation */
/* Print in orientation of the logical page */
- fz_write_printf(ctx, out, "\033&r0F");
+ fz_write_string(ctx, out, "\033&r0F");
/* Set color mode */
fz_write_data(ctx, out, "\033*v6W"
@@ -762,11 +762,11 @@ color_pcl_write_header(fz_context *ctx, fz_band_writer *writer_)
/* start raster graphics */
/* 0 = start at default left graphics margin */
- fz_write_printf(ctx, out, "\033*r0A");
+ fz_write_string(ctx, out, "\033*r0A");
/* Now output the actual bitmap */
/* Adaptive Compression */
- fz_write_printf(ctx, out, "\033*b5M");
+ fz_write_string(ctx, out, "\033*b5M");
}
static void
@@ -921,7 +921,7 @@ color_pcl_write_trailer(fz_context *ctx, fz_band_writer *writer_)
}
/* End Raster Graphics */
- fz_write_printf(ctx, out, "\033*rC");
+ fz_write_string(ctx, out, "\033*rC");
}
static void
diff --git a/source/fitz/output-ps.c b/source/fitz/output-ps.c
index 9b6aeb06..ef90dadc 100644
--- a/source/fitz/output-ps.c
+++ b/source/fitz/output-ps.c
@@ -81,13 +81,13 @@ ps_write_header(fz_context *ctx, fz_band_writer *writer_)
switch(n)
{
case 1:
- fz_write_printf(ctx, out, "/DeviceGray setcolorspace\n");
+ fz_write_string(ctx, out, "/DeviceGray setcolorspace\n");
break;
case 3:
- fz_write_printf(ctx, out, "/DeviceRGB setcolorspace\n");
+ fz_write_string(ctx, out, "/DeviceRGB setcolorspace\n");
break;
case 4:
- fz_write_printf(ctx, out, "/DeviceCMYK setcolorspace\n");
+ fz_write_string(ctx, out, "/DeviceCMYK setcolorspace\n");
break;
default:
fz_throw(ctx, FZ_ERROR_GENERIC, "Unexpected colorspace for ps output");
@@ -97,7 +97,7 @@ ps_write_header(fz_context *ctx, fz_band_writer *writer_)
"/ImageType 1\n"
"/Width %d\n"
"/Height %d\n"
- "/ImageMatrix [ %f 0 0 -%f 0 %d ]\n"
+ "/ImageMatrix [ %g 0 0 -%g 0 %d ]\n"
"/MultipleDataSources false\n"
"/DataSource DataFile\n"
"/BitsPerComponent 8\n"
@@ -124,8 +124,8 @@ ps_write_trailer(fz_context *ctx, fz_band_writer *writer_)
if (err != Z_STREAM_END)
fz_throw(ctx, FZ_ERROR_GENERIC, "compression error %d", err);
- fz_write(ctx, out, writer->output, writer->output_size - writer->stream.avail_out);
- fz_write_printf(ctx, out, "\nshowpage\n%%%%PageTrailer\n%%%%EndPageTrailer\n\n");
+ fz_write_data(ctx, out, writer->output, writer->output_size - writer->stream.avail_out);
+ fz_write_string(ctx, out, "\nshowpage\n%%%%PageTrailer\n%%%%EndPageTrailer\n\n");
}
static void
diff --git a/source/pdf/pdf-appearance.c b/source/pdf/pdf-appearance.c
index e011fdc9..32047b8b 100644
--- a/source/pdf/pdf-appearance.c
+++ b/source/pdf/pdf-appearance.c
@@ -47,20 +47,20 @@ typedef struct text_widget_info_s
int max_len;
} text_widget_info;
-static const char *fmt_re = "%f %f %f %f re\n";
+static const char *fmt_re = "%g %g %g %g re\n";
static const char *fmt_f = "f\n";
static const char *fmt_s = "s\n";
-static const char *fmt_g = "%f g\n";
-static const char *fmt_m = "%f %f m\n";
-static const char *fmt_l = "%f %f l\n";
-static const char *fmt_w = "%f w\n";
+static const char *fmt_g = "%g g\n";
+static const char *fmt_m = "%g %g m\n";
+static const char *fmt_l = "%g %g l\n";
+static const char *fmt_w = "%g w\n";
static const char *fmt_Tx_BMC = "/Tx BMC\n";
static const char *fmt_q = "q\n";
static const char *fmt_W = "W\n";
static const char *fmt_n = "n\n";
static const char *fmt_BT = "BT\n";
-static const char *fmt_Tm = "%f %f %f %f %f %f Tm\n";
-static const char *fmt_Td = "%f %f Td\n";
+static const char *fmt_Tm = "%g %g %g %g %g %g Tm\n";
+static const char *fmt_Td = "%g %g Td\n";
static const char *fmt_Tj = " Tj\n";
static const char *fmt_ET = "ET\n";
static const char *fmt_Q = "Q\n";
@@ -208,15 +208,15 @@ void pdf_fzbuf_print_da(fz_context *ctx, fz_buffer *fzbuf, pdf_da_info *di)
switch (di->col_size)
{
case 1:
- fz_append_printf(ctx, fzbuf, " %f g", di->col[0]);
+ fz_append_printf(ctx, fzbuf, " %g g", di->col[0]);
break;
case 3:
- fz_append_printf(ctx, fzbuf, " %f %f %f rg", di->col[0], di->col[1], di->col[2]);
+ fz_append_printf(ctx, fzbuf, " %g %g %g rg", di->col[0], di->col[1], di->col[2]);
break;
case 4:
- fz_append_printf(ctx, fzbuf, " %f %f %f %f k", di->col[0], di->col[1], di->col[2], di->col[3]);
+ fz_append_printf(ctx, fzbuf, " %g %g %g %g k", di->col[0], di->col[1], di->col[2], di->col[3]);
break;
default:
@@ -242,17 +242,17 @@ static void fzbuf_print_color(fz_context *ctx, fz_buffer *fzbuf, pdf_obj *arr, i
switch (pdf_array_len(ctx, arr))
{
case 1:
- fz_append_printf(ctx, fzbuf, stroke?"%f G\n":"%f g\n",
+ fz_append_printf(ctx, fzbuf, stroke?"%g G\n":"%g g\n",
pdf_to_real(ctx, pdf_array_get(ctx, arr, 0)) + adj);
break;
case 3:
- fz_append_printf(ctx, fzbuf, stroke?"%f %f %f RG\n":"%f %f %f rg\n",
+ fz_append_printf(ctx, fzbuf, stroke?"%g %g %g RG\n":"%g %g %g rg\n",
pdf_to_real(ctx, pdf_array_get(ctx, arr, 0)) + adj,
pdf_to_real(ctx, pdf_array_get(ctx, arr, 1)) + adj,
pdf_to_real(ctx, pdf_array_get(ctx, arr, 2)) + adj);
break;
case 4:
- fz_append_printf(ctx, fzbuf, stroke?"%f %f %f %f K\n":"%f %f %f %f k\n",
+ fz_append_printf(ctx, fzbuf, stroke?"%g %g %g %g K\n":"%g %g %g %g k\n",
pdf_to_real(ctx, pdf_array_get(ctx, arr, 0)),
pdf_to_real(ctx, pdf_array_get(ctx, arr, 1)),
pdf_to_real(ctx, pdf_array_get(ctx, arr, 2)),
@@ -274,13 +274,13 @@ static void fzbuf_print_rect_fill(fz_context *ctx, fz_buffer *fzbuf, const fz_re
switch (col_size)
{
case 1:
- fz_append_printf(ctx, fzbuf, "%f g\n", col[0]);
+ fz_append_printf(ctx, fzbuf, "%g g\n", col[0]);
break;
case 3:
- fz_append_printf(ctx, fzbuf, "%f %f %f rg\n", col[0], col[1], col[2]);
+ fz_append_printf(ctx, fzbuf, "%g %g %g rg\n", col[0], col[1], col[2]);
break;
case 4:
- fz_append_printf(ctx, fzbuf, "%f %f %f %f k\n", col[0], col[1], col[2], col[3]);
+ fz_append_printf(ctx, fzbuf, "%g %g %g %g k\n", col[0], col[1], col[2], col[3]);
break;
default:
break;
diff --git a/source/pdf/pdf-device.c b/source/pdf/pdf-device.c
index 1857cc4c..8a5b17e2 100644
--- a/source/pdf/pdf-device.c
+++ b/source/pdf/pdf-device.c
@@ -107,7 +107,7 @@ pdf_dev_stroke_state(fz_context *ctx, pdf_device *pdev, const fz_stroke_state *s
return;
if (!gs->stroke_state || gs->stroke_state->linewidth != stroke_state->linewidth)
{
- fz_append_printf(ctx, gs->buf, "%f w\n", stroke_state->linewidth);
+ fz_append_printf(ctx, gs->buf, "%g w\n", stroke_state->linewidth);
}
if (!gs->stroke_state || gs->stroke_state->start_cap != stroke_state->start_cap)
{
@@ -126,7 +126,7 @@ pdf_dev_stroke_state(fz_context *ctx, pdf_device *pdev, const fz_stroke_state *s
}
if (!gs->stroke_state || gs->stroke_state->miterlimit != stroke_state->miterlimit)
{
- fz_append_printf(ctx, gs->buf, "%f M\n", stroke_state->miterlimit);
+ fz_append_printf(ctx, gs->buf, "%g M\n", stroke_state->miterlimit);
}
if (gs->stroke_state == NULL && stroke_state->dash_len == 0)
{}
@@ -140,9 +140,9 @@ pdf_dev_stroke_state(fz_context *ctx, pdf_device *pdev, const fz_stroke_state *s
{
if (i > 0)
fz_append_byte(ctx, gs->buf, ' ');
- fz_append_printf(ctx, gs->buf, "%f", stroke_state->dash_list[i]);
+ fz_append_printf(ctx, gs->buf, "%g", stroke_state->dash_list[i]);
}
- fz_append_printf(ctx, gs->buf, "]%f d\n", stroke_state->dash_phase);
+ fz_append_printf(ctx, gs->buf, "]%g d\n", stroke_state->dash_phase);
}
fz_drop_stroke_state(ctx, gs->stroke_state);
gs->stroke_state = fz_keep_stroke_state(ctx, stroke_state);
@@ -158,28 +158,28 @@ static void
pdf_dev_path_moveto(fz_context *ctx, void *arg, float x, float y)
{
fz_buffer *buf = (fz_buffer *)arg;
- fz_append_printf(ctx, buf, "%f %f m\n", x, y);
+ fz_append_printf(ctx, buf, "%g %g m\n", x, y);
}
static void
pdf_dev_path_lineto(fz_context *ctx, void *arg, float x, float y)
{
fz_buffer *buf = (fz_buffer *)arg;
- fz_append_printf(ctx, buf, "%f %f l\n", x, y);
+ fz_append_printf(ctx, buf, "%g %g l\n", x, y);
}
static void
pdf_dev_path_curveto(fz_context *ctx, void *arg, float x1, float y1, float x2, float y2, float x3, float y3)
{
fz_buffer *buf = (fz_buffer *)arg;
- fz_append_printf(ctx, buf, "%f %f %f %f %f %f c\n", x1, y1, x2, y2, x3, y3);
+ fz_append_printf(ctx, buf, "%g %g %g %g %g %g c\n", x1, y1, x2, y2, x3, y3);
}
static void
pdf_dev_path_close(fz_context *ctx, void *arg)
{
fz_buffer *buf = (fz_buffer *)arg;
- fz_append_printf(ctx, buf, "h\n");
+ fz_append_string(ctx, buf, "h\n");
}
static const fz_path_walker pdf_dev_path_proc =
@@ -256,22 +256,22 @@ pdf_dev_color(fz_context *ctx, pdf_device *pdev, fz_colorspace *colorspace, cons
switch (cspace + stroke*8)
{
case 1:
- fz_append_printf(ctx, gs->buf, "%f g\n", color[0]);
+ fz_append_printf(ctx, gs->buf, "%g g\n", color[0]);
break;
case 3:
- fz_append_printf(ctx, gs->buf, "%f %f %f rg\n", color[0], color[1], color[2]);
+ fz_append_printf(ctx, gs->buf, "%g %g %g rg\n", color[0], color[1], color[2]);
break;
case 4:
- fz_append_printf(ctx, gs->buf, "%f %f %f %f k\n", color[0], color[1], color[2], color[3]);
+ fz_append_printf(ctx, gs->buf, "%g %g %g %g k\n", color[0], color[1], color[2], color[3]);
break;
case 1+8:
- fz_append_printf(ctx, gs->buf, "%f G\n", color[0]);
+ fz_append_printf(ctx, gs->buf, "%g G\n", color[0]);
break;
case 3+8:
- fz_append_printf(ctx, gs->buf, "%f %f %f RG\n", color[0], color[1], color[2]);
+ fz_append_printf(ctx, gs->buf, "%g %g %g RG\n", color[0], color[1], color[2]);
break;
case 4+8:
- fz_append_printf(ctx, gs->buf, "%f %f %f %f K\n", color[0], color[1], color[2], color[3]);
+ fz_append_printf(ctx, gs->buf, "%g %g %g %g K\n", color[0], color[1], color[2], color[3]);
break;
}
}
diff --git a/source/pdf/pdf-op-buffer.c b/source/pdf/pdf-op-buffer.c
index b916ea3f..e3becc13 100644
--- a/source/pdf/pdf-op-buffer.c
+++ b/source/pdf/pdf-op-buffer.c
@@ -17,7 +17,7 @@ pdf_out_w(fz_context *ctx, pdf_processor *proc, float linewidth)
{
fz_output *out = ((pdf_output_processor*)proc)->out;
if (!((pdf_output_processor*)proc)->extgstate)
- fz_write_printf(ctx, out, "%f w\n", linewidth);
+ fz_write_printf(ctx, out, "%g w\n", linewidth);
}
static void
@@ -41,7 +41,7 @@ pdf_out_M(fz_context *ctx, pdf_processor *proc, float a)
{
fz_output *out = ((pdf_output_processor*)proc)->out;
if (!((pdf_output_processor*)proc)->extgstate)
- fz_write_printf(ctx, out, "%f M\n", a);
+ fz_write_printf(ctx, out, "%g M\n", a);
}
static void
@@ -51,7 +51,7 @@ pdf_out_d(fz_context *ctx, pdf_processor *proc, pdf_obj *array, float phase)
if (!((pdf_output_processor*)proc)->extgstate)
{
pdf_print_obj(ctx, out, array, 1);
- fz_write_printf(ctx, out, " %f d\n", phase);
+ fz_write_printf(ctx, out, " %g d\n", phase);
}
}
@@ -68,7 +68,7 @@ pdf_out_i(fz_context *ctx, pdf_processor *proc, float flatness)
{
fz_output *out = ((pdf_output_processor*)proc)->out;
if (!((pdf_output_processor*)proc)->extgstate)
- fz_write_printf(ctx, out, "%f i\n", flatness);
+ fz_write_printf(ctx, out, "%g i\n", flatness);
}
static void
@@ -91,21 +91,21 @@ static void
pdf_out_q(fz_context *ctx, pdf_processor *proc)
{
fz_output *out = ((pdf_output_processor*)proc)->out;
- fz_write_printf(ctx, out, "q\n");
+ fz_write_string(ctx, out, "q\n");
}
static void
pdf_out_Q(fz_context *ctx, pdf_processor *proc)
{
fz_output *out = ((pdf_output_processor*)proc)->out;
- fz_write_printf(ctx, out, "Q\n");
+ fz_write_string(ctx, out, "Q\n");
}
static void
pdf_out_cm(fz_context *ctx, pdf_processor *proc, float a, float b, float c, float d, float e, float f)
{
fz_output *out = ((pdf_output_processor*)proc)->out;
- fz_write_printf(ctx, out, "%f %f %f %f %f %f cm\n", a, b, c, d, e, f);
+ fz_write_printf(ctx, out, "%g %g %g %g %g %g cm\n", a, b, c, d, e, f);
}
/* path construction */
@@ -114,49 +114,49 @@ static void
pdf_out_m(fz_context *ctx, pdf_processor *proc, float x, float y)
{
fz_output *out = ((pdf_output_processor*)proc)->out;
- fz_write_printf(ctx, out, "%f %f m\n", x, y);
+ fz_write_printf(ctx, out, "%g %g m\n", x, y);
}
static void
pdf_out_l(fz_context *ctx, pdf_processor *proc, float x, float y)
{
fz_output *out = ((pdf_output_processor*)proc)->out;
- fz_write_printf(ctx, out, "%f %f l\n", x, y);
+ fz_write_printf(ctx, out, "%g %g l\n", x, y);
}
static void
pdf_out_c(fz_context *ctx, pdf_processor *proc, float x1, float y1, float x2, float y2, float x3, float y3)
{
fz_output *out = ((pdf_output_processor*)proc)->out;
- fz_write_printf(ctx, out, "%f %f %f %f %f %f c\n", x1, y1, x2, y2, x3, y3);
+ fz_write_printf(ctx, out, "%g %g %g %g %g %g c\n", x1, y1, x2, y2, x3, y3);
}
static void
pdf_out_v(fz_context *ctx, pdf_processor *proc, float x2, float y2, float x3, float y3)
{
fz_output *out = ((pdf_output_processor*)proc)->out;
- fz_write_printf(ctx, out, "%f %f %f %f v\n", x2, y2, x3, y3);
+ fz_write_printf(ctx, out, "%g %g %g %g v\n", x2, y2, x3, y3);
}
static void
pdf_out_y(fz_context *ctx, pdf_processor *proc, float x1, float y1, float x3, float y3)
{
fz_output *out = ((pdf_output_processor*)proc)->out;
- fz_write_printf(ctx, out, "%f %f %f %f y\n", x1, y1, x3, y3);
+ fz_write_printf(ctx, out, "%g %g %g %g y\n", x1, y1, x3, y3);
}
static void
pdf_out_h(fz_context *ctx, pdf_processor *proc)
{
fz_output *out = ((pdf_output_processor*)proc)->out;
- fz_write_printf(ctx, out, "h\n");
+ fz_write_string(ctx, out, "h\n");
}
static void
pdf_out_re(fz_context *ctx, pdf_processor *proc, float x, float y, float w, float h)
{
fz_output *out = ((pdf_output_processor*)proc)->out;
- fz_write_printf(ctx, out, "%f %f %f %f re\n", x, y, w, h);
+ fz_write_printf(ctx, out, "%g %g %g %g re\n", x, y, w, h);
}
/* path painting */
@@ -165,70 +165,70 @@ static void
pdf_out_S(fz_context *ctx, pdf_processor *proc)
{
fz_output *out = ((pdf_output_processor*)proc)->out;
- fz_write_printf(ctx, out, "S\n");
+ fz_write_string(ctx, out, "S\n");
}
static void
pdf_out_s(fz_context *ctx, pdf_processor *proc)
{
fz_output *out = ((pdf_output_processor*)proc)->out;
- fz_write_printf(ctx, out, "s\n");
+ fz_write_string(ctx, out, "s\n");
}
static void
pdf_out_F(fz_context *ctx, pdf_processor *proc)
{
fz_output *out = ((pdf_output_processor*)proc)->out;
- fz_write_printf(ctx, out, "F\n");
+ fz_write_string(ctx, out, "F\n");
}
static void
pdf_out_f(fz_context *ctx, pdf_processor *proc)
{
fz_output *out = ((pdf_output_processor*)proc)->out;
- fz_write_printf(ctx, out, "f\n");
+ fz_write_string(ctx, out, "f\n");
}
static void
pdf_out_fstar(fz_context *ctx, pdf_processor *proc)
{
fz_output *out = ((pdf_output_processor*)proc)->out;
- fz_write_printf(ctx, out, "f*\n");
+ fz_write_string(ctx, out, "f*\n");
}
static void
pdf_out_B(fz_context *ctx, pdf_processor *proc)
{
fz_output *out = ((pdf_output_processor*)proc)->out;
- fz_write_printf(ctx, out, "B\n");
+ fz_write_string(ctx, out, "B\n");
}
static void
pdf_out_Bstar(fz_context *ctx, pdf_processor *proc)
{
fz_output *out = ((pdf_output_processor*)proc)->out;
- fz_write_printf(ctx, out, "B*\n");
+ fz_write_string(ctx, out, "B*\n");
}
static void
pdf_out_b(fz_context *ctx, pdf_processor *proc)
{
fz_output *out = ((pdf_output_processor*)proc)->out;
- fz_write_printf(ctx, out, "b\n");
+ fz_write_string(ctx, out, "b\n");
}
static void
pdf_out_bstar(fz_context *ctx, pdf_processor *proc)
{
fz_output *out = ((pdf_output_processor*)proc)->out;
- fz_write_printf(ctx, out, "b*\n");
+ fz_write_string(ctx, out, "b*\n");
}
static void
pdf_out_n(fz_context *ctx, pdf_processor *proc)
{
fz_output *out = ((pdf_output_processor*)proc)->out;
- fz_write_printf(ctx, out, "n\n");
+ fz_write_string(ctx, out, "n\n");
}
/* clipping paths */
@@ -237,14 +237,14 @@ static void
pdf_out_W(fz_context *ctx, pdf_processor *proc)
{
fz_output *out = ((pdf_output_processor*)proc)->out;
- fz_write_printf(ctx, out, "W\n");
+ fz_write_string(ctx, out, "W\n");
}
static void
pdf_out_Wstar(fz_context *ctx, pdf_processor *proc)
{
fz_output *out = ((pdf_output_processor*)proc)->out;
- fz_write_printf(ctx, out, "W*\n");
+ fz_write_string(ctx, out, "W*\n");
}
/* text objects */
@@ -253,14 +253,14 @@ static void
pdf_out_BT(fz_context *ctx, pdf_processor *proc)
{
fz_output *out = ((pdf_output_processor*)proc)->out;
- fz_write_printf(ctx, out, "BT\n");
+ fz_write_string(ctx, out, "BT\n");
}
static void
pdf_out_ET(fz_context *ctx, pdf_processor *proc)
{
fz_output *out = ((pdf_output_processor*)proc)->out;
- fz_write_printf(ctx, out, "ET\n");
+ fz_write_string(ctx, out, "ET\n");
}
/* text state */
@@ -269,28 +269,28 @@ static void
pdf_out_Tc(fz_context *ctx, pdf_processor *proc, float charspace)
{
fz_output *out = ((pdf_output_processor*)proc)->out;
- fz_write_printf(ctx, out, "%f Tc\n", charspace);
+ fz_write_printf(ctx, out, "%g Tc\n", charspace);
}
static void
pdf_out_Tw(fz_context *ctx, pdf_processor *proc, float wordspace)
{
fz_output *out = ((pdf_output_processor*)proc)->out;
- fz_write_printf(ctx, out, "%f Tw\n", wordspace);
+ fz_write_printf(ctx, out, "%g Tw\n", wordspace);
}
static void
pdf_out_Tz(fz_context *ctx, pdf_processor *proc, float scale)
{
fz_output *out = ((pdf_output_processor*)proc)->out;
- fz_write_printf(ctx, out, "%f Tz\n", scale);
+ fz_write_printf(ctx, out, "%g Tz\n", scale);
}
static void
pdf_out_TL(fz_context *ctx, pdf_processor *proc, float leading)
{
fz_output *out = ((pdf_output_processor*)proc)->out;
- fz_write_printf(ctx, out, "%f TL\n", leading);
+ fz_write_printf(ctx, out, "%g TL\n", leading);
}
static void
@@ -298,7 +298,7 @@ pdf_out_Tf(fz_context *ctx, pdf_processor *proc, const char *name, pdf_font_desc
{
fz_output *out = ((pdf_output_processor*)proc)->out;
if (!((pdf_output_processor*)proc)->extgstate)
- fz_write_printf(ctx, out, "/%s %f Tf\n", name, size);
+ fz_write_printf(ctx, out, "/%s %g Tf\n", name, size);
}
static void
@@ -312,7 +312,7 @@ static void
pdf_out_Ts(fz_context *ctx, pdf_processor *proc, float rise)
{
fz_output *out = ((pdf_output_processor*)proc)->out;
- fz_write_printf(ctx, out, "%f Ts\n", rise);
+ fz_write_printf(ctx, out, "%g Ts\n", rise);
}
/* text positioning */
@@ -321,34 +321,34 @@ static void
pdf_out_Td(fz_context *ctx, pdf_processor *proc, float tx, float ty)
{
fz_output *out = ((pdf_output_processor*)proc)->out;
- fz_write_printf(ctx, out, "%f %f Td\n", tx, ty);
+ fz_write_printf(ctx, out, "%g %g Td\n", tx, ty);
}
static void
pdf_out_TD(fz_context *ctx, pdf_processor *proc, float tx, float ty)
{
fz_output *out = ((pdf_output_processor*)proc)->out;
- fz_write_printf(ctx, out, "%f %f TD\n", tx, ty);
+ fz_write_printf(ctx, out, "%g %g TD\n", tx, ty);
}
static void
pdf_out_Tm(fz_context *ctx, pdf_processor *proc, float a, float b, float c, float d, float e, float f)
{
fz_output *out = ((pdf_output_processor*)proc)->out;
- fz_write_printf(ctx, out, "%f %f %f %f %f %f Tm\n", a, b, c, d, e, f);
+ fz_write_printf(ctx, out, "%g %g %g %g %g %g Tm\n", a, b, c, d, e, f);
}
static void
pdf_out_Tstar(fz_context *ctx, pdf_processor *proc)
{
fz_output *out = ((pdf_output_processor*)proc)->out;
- fz_write_printf(ctx, out, "T*\n");
+ fz_write_string(ctx, out, "T*\n");
}
/* text showing */
static void
-put_string(fz_context *ctx, fz_output *out, const unsigned char *str, int len)
+fz_write_pdf_string(fz_context *ctx, fz_output *out, const unsigned char *str, int len)
{
int i;
@@ -358,14 +358,18 @@ put_string(fz_context *ctx, fz_output *out, const unsigned char *str, int len)
if (i < len)
{
- fz_write_printf(ctx, out, "<");
+ fz_write_byte(ctx, out, '<');
for (i = 0; i < len; ++i)
- fz_write_printf(ctx, out, "%02x", str[i]);
- fz_write_printf(ctx, out, ">");
+ {
+ unsigned char c = str[i];
+ fz_write_byte(ctx, out, "0123456789abcdef"[(c>>4)&15]);
+ fz_write_byte(ctx, out, "0123456789abcdef"[(c)&15]);
+ }
+ fz_write_byte(ctx, out, '>');
}
else
{
- fz_write_printf(ctx, out, "(");
+ fz_write_byte(ctx, out, '(');
for (i = 0; i < len; ++i)
{
unsigned char c = str[i];
@@ -373,7 +377,7 @@ put_string(fz_context *ctx, fz_output *out, const unsigned char *str, int len)
fz_write_byte(ctx, out, '\\');
fz_write_byte(ctx, out, c);
}
- fz_write_printf(ctx, out, ")");
+ fz_write_byte(ctx, out, ')');
}
}
@@ -382,32 +386,32 @@ pdf_out_TJ(fz_context *ctx, pdf_processor *proc, pdf_obj *array)
{
fz_output *out = ((pdf_output_processor*)proc)->out;
pdf_print_obj(ctx, out, array, 1);
- fz_write_printf(ctx, out, " TJ\n");
+ fz_write_string(ctx, out, " TJ\n");
}
static void
pdf_out_Tj(fz_context *ctx, pdf_processor *proc, char *str, int len)
{
fz_output *out = ((pdf_output_processor*)proc)->out;
- put_string(ctx, out, (const unsigned char *)str, len);
- fz_write_printf(ctx, out, " Tj\n");
+ fz_write_pdf_string(ctx, out, (const unsigned char *)str, len);
+ fz_write_string(ctx, out, " Tj\n");
}
static void
pdf_out_squote(fz_context *ctx, pdf_processor *proc, char *str, int len)
{
fz_output *out = ((pdf_output_processor*)proc)->out;
- put_string(ctx, out, (const unsigned char *)str, len);
- fz_write_printf(ctx, out, " '\n");
+ fz_write_pdf_string(ctx, out, (const unsigned char *)str, len);
+ fz_write_string(ctx, out, " '\n");
}
static void
pdf_out_dquote(fz_context *ctx, pdf_processor *proc, float aw, float ac, char *str, int len)
{
fz_output *out = ((pdf_output_processor*)proc)->out;
- fz_write_printf(ctx, out, "%f %f ", aw, ac);
- put_string(ctx, out, (const unsigned char *)str, len);
- fz_write_printf(ctx, out, " \"\n");
+ fz_write_printf(ctx, out, "%g %g ", aw, ac);
+ fz_write_pdf_string(ctx, out, (const unsigned char *)str, len);
+ fz_write_string(ctx, out, " \"\n");
}
/* type 3 fonts */
@@ -416,14 +420,14 @@ static void
pdf_out_d0(fz_context *ctx, pdf_processor *proc, float wx, float wy)
{
fz_output *out = ((pdf_output_processor*)proc)->out;
- fz_write_printf(ctx, out, "%f %f d0\n", wx, wy);
+ fz_write_printf(ctx, out, "%g %g d0\n", wx, wy);
}
static void
pdf_out_d1(fz_context *ctx, pdf_processor *proc, float wx, float wy, float llx, float lly, float urx, float ury)
{
fz_output *out = ((pdf_output_processor*)proc)->out;
- fz_write_printf(ctx, out, "%f %f %f %f %f %f d1\n", wx, wy, llx, lly, urx, ury);
+ fz_write_printf(ctx, out, "%g %g %g %g %g %g d1\n", wx, wy, llx, lly, urx, ury);
}
/* color */
@@ -448,7 +452,7 @@ pdf_out_SC_pattern(fz_context *ctx, pdf_processor *proc, const char *name, pdf_p
fz_output *out = ((pdf_output_processor*)proc)->out;
int i;
for (i = 0; i < n; ++i)
- fz_write_printf(ctx, out, "%f ", color[i]);
+ fz_write_printf(ctx, out, "%g ", color[i]);
fz_write_printf(ctx, out, "/%s SCN\n", name);
}
@@ -458,7 +462,7 @@ pdf_out_sc_pattern(fz_context *ctx, pdf_processor *proc, const char *name, pdf_p
fz_output *out = ((pdf_output_processor*)proc)->out;
int i;
for (i = 0; i < n; ++i)
- fz_write_printf(ctx, out, "%f ", color[i]);
+ fz_write_printf(ctx, out, "%g ", color[i]);
fz_write_printf(ctx, out, "/%s scn\n", name);
}
@@ -482,8 +486,8 @@ pdf_out_SC_color(fz_context *ctx, pdf_processor *proc, int n, float *color)
fz_output *out = ((pdf_output_processor*)proc)->out;
int i;
for (i = 0; i < n; ++i)
- fz_write_printf(ctx, out, "%f ", color[i]);
- fz_write_printf(ctx, out, "SCN\n");
+ fz_write_printf(ctx, out, "%g ", color[i]);
+ fz_write_string(ctx, out, "SCN\n");
}
static void
@@ -492,50 +496,50 @@ pdf_out_sc_color(fz_context *ctx, pdf_processor *proc, int n, float *color)
fz_output *out = ((pdf_output_processor*)proc)->out;
int i;
for (i = 0; i < n; ++i)
- fz_write_printf(ctx, out, "%f ", color[i]);
- fz_write_printf(ctx, out, "scn\n");
+ fz_write_printf(ctx, out, "%g ", color[i]);
+ fz_write_string(ctx, out, "scn\n");
}
static void
pdf_out_G(fz_context *ctx, pdf_processor *proc, float g)
{
fz_output *out = ((pdf_output_processor*)proc)->out;
- fz_write_printf(ctx, out, "%f G\n", g);
+ fz_write_printf(ctx, out, "%g G\n", g);
}
static void
pdf_out_g(fz_context *ctx, pdf_processor *proc, float g)
{
fz_output *out = ((pdf_output_processor*)proc)->out;
- fz_write_printf(ctx, out, "%f g\n", g);
+ fz_write_printf(ctx, out, "%g g\n", g);
}
static void
pdf_out_RG(fz_context *ctx, pdf_processor *proc, float r, float g, float b)
{
fz_output *out = ((pdf_output_processor*)proc)->out;
- fz_write_printf(ctx, out, "%f %f %f RG\n", r, g, b);
+ fz_write_printf(ctx, out, "%g %g %g RG\n", r, g, b);
}
static void
pdf_out_rg(fz_context *ctx, pdf_processor *proc, float r, float g, float b)
{
fz_output *out = ((pdf_output_processor*)proc)->out;
- fz_write_printf(ctx, out, "%f %f %f rg\n", r, g, b);
+ fz_write_printf(ctx, out, "%g %g %g rg\n", r, g, b);
}
static void
pdf_out_K(fz_context *ctx, pdf_processor *proc, float c, float m, float y, float k)
{
fz_output *out = ((pdf_output_processor*)proc)->out;
- fz_write_printf(ctx, out, "%f %f %f %f K\n", c, m, y, k);
+ fz_write_printf(ctx, out, "%g %g %g %g K\n", c, m, y, k);
}
static void
pdf_out_k(fz_context *ctx, pdf_processor *proc, float c, float m, float y, float k)
{
fz_output *out = ((pdf_output_processor*)proc)->out;
- fz_write_printf(ctx, out, "%f %f %f %f k\n", c, m, y, k);
+ fz_write_printf(ctx, out, "%g %g %g %g k\n", c, m, y, k);
}
/* shadings, images, xobjects */
@@ -560,30 +564,30 @@ pdf_out_BI(fz_context *ctx, pdf_processor *proc, fz_image *img)
if (buf == NULL)
return;
- fz_write_printf(ctx, out, "BI\n");
+ fz_write_string(ctx, out, "BI\n");
fz_write_printf(ctx, out, "/W %d\n", img->w);
fz_write_printf(ctx, out, "/H %d\n", img->h);
fz_write_printf(ctx, out, "/BPC %d\n", img->bpc);
if (img->imagemask)
- fz_write_printf(ctx, out, "/IM true\n");
+ fz_write_string(ctx, out, "/IM true\n");
else if (img->colorspace == fz_device_gray(ctx))
- fz_write_printf(ctx, out, "/CS/G\n");
+ fz_write_string(ctx, out, "/CS/G\n");
else if (img->colorspace == fz_device_rgb(ctx))
- fz_write_printf(ctx, out, "/CS/RGB\n");
+ fz_write_string(ctx, out, "/CS/RGB\n");
else if (img->colorspace == fz_device_cmyk(ctx))
- fz_write_printf(ctx, out, "/CS/CMYK\n");
+ fz_write_string(ctx, out, "/CS/CMYK\n");
else if (fz_colorspace_is_indexed(ctx, img->colorspace))
- fz_write_printf(ctx, out, "/CS/I\n");
+ fz_write_string(ctx, out, "/CS/I\n");
if (img->interpolate)
- fz_write_printf(ctx, out, "/I true\n");
- fz_write_printf(ctx, out, "/D[");
+ fz_write_string(ctx, out, "/I true\n");
+ fz_write_string(ctx, out, "/D[");
for (i = 0; i < img->n * 2; ++i)
{
if (i > 0)
fz_write_byte(ctx, out, ' ');
fz_write_printf(ctx, out, "%g", img->decode[i]);
}
- fz_write_printf(ctx, out, "]\n");
+ fz_write_string(ctx, out, "]\n");
switch (cbuf->params.type)
{
@@ -592,47 +596,47 @@ pdf_out_BI(fz_context *ctx, pdf_processor *proc, fz_image *img)
break;
case FZ_IMAGE_JPEG:
- fz_write_printf(ctx, out, ahx ? "/F[/AHx/DCT]\n" : "/F/DCT\n");
+ fz_write_string(ctx, out, ahx ? "/F[/AHx/DCT]\n" : "/F/DCT\n");
if (cbuf->params.u.jpeg.color_transform != -1)
fz_write_printf(ctx, out, "/DP<</ColorTransform %d>>\n",
cbuf->params.u.jpeg.color_transform);
break;
case FZ_IMAGE_FAX:
- fz_write_printf(ctx, out, ahx ? "/F[/AHx/CCF]\n/DP[null<<\n" : "/F/CCF\n/DP<<\n");
+ fz_write_string(ctx, out, ahx ? "/F[/AHx/CCF]\n/DP[null<<\n" : "/F/CCF\n/DP<<\n");
fz_write_printf(ctx, out, "/K %d\n", cbuf->params.u.fax.k);
if (cbuf->params.u.fax.columns != 1728)
fz_write_printf(ctx, out, "/Columns %d\n", cbuf->params.u.fax.columns);
if (cbuf->params.u.fax.rows > 0)
fz_write_printf(ctx, out, "/Rows %d\n", cbuf->params.u.fax.rows);
if (cbuf->params.u.fax.end_of_line)
- fz_write_printf(ctx, out, "/EndOfLine true\n");
+ fz_write_string(ctx, out, "/EndOfLine true\n");
if (cbuf->params.u.fax.encoded_byte_align)
- fz_write_printf(ctx, out, "/EncodedByteAlign true\n");
+ fz_write_string(ctx, out, "/EncodedByteAlign true\n");
if (!cbuf->params.u.fax.end_of_block)
- fz_write_printf(ctx, out, "/EndOfBlock false\n");
+ fz_write_string(ctx, out, "/EndOfBlock false\n");
if (cbuf->params.u.fax.black_is_1)
- fz_write_printf(ctx, out, "/BlackIs1 true\n");
+ fz_write_string(ctx, out, "/BlackIs1 true\n");
if (cbuf->params.u.fax.damaged_rows_before_error > 0)
fz_write_printf(ctx, out, "/DamagedRowsBeforeError %d\n",
cbuf->params.u.fax.damaged_rows_before_error);
- fz_write_printf(ctx, out, ahx ? ">>]\n" : ">>\n");
+ fz_write_string(ctx, out, ahx ? ">>]\n" : ">>\n");
break;
case FZ_IMAGE_RAW:
if (ahx)
- fz_write_printf(ctx, out, "/F/AHx\n");
+ fz_write_string(ctx, out, "/F/AHx\n");
break;
case FZ_IMAGE_RLD:
- fz_write_printf(ctx, out, ahx ? "/F[/AHx/RL]\n" : "/F/RL\n");
+ fz_write_string(ctx, out, ahx ? "/F[/AHx/RL]\n" : "/F/RL\n");
break;
case FZ_IMAGE_FLATE:
- fz_write_printf(ctx, out, ahx ? "/F[/AHx/Fl]\n" : "/F/Fl\n");
+ fz_write_string(ctx, out, ahx ? "/F[/AHx/Fl]\n" : "/F/Fl\n");
if (cbuf->params.u.flate.predictor > 1)
{
- fz_write_printf(ctx, out, ahx ? "/DP[null<<\n" : "/DP<<\n");
+ fz_write_string(ctx, out, ahx ? "/DP[null<<\n" : "/DP<<\n");
fz_write_printf(ctx, out, "/Predictor %d\n", cbuf->params.u.flate.predictor);
if (cbuf->params.u.flate.columns != 1)
fz_write_printf(ctx, out, "/Columns %d\n", cbuf->params.u.flate.columns);
@@ -640,15 +644,15 @@ pdf_out_BI(fz_context *ctx, pdf_processor *proc, fz_image *img)
fz_write_printf(ctx, out, "/Colors %d\n", cbuf->params.u.flate.colors);
if (cbuf->params.u.flate.bpc != 8)
fz_write_printf(ctx, out, "/BitsPerComponent %d\n", cbuf->params.u.flate.bpc);
- fz_write_printf(ctx, out, ahx ? ">>]\n" : ">>\n");
+ fz_write_string(ctx, out, ahx ? ">>]\n" : ">>\n");
}
break;
case FZ_IMAGE_LZW:
- fz_write_printf(ctx, out, ahx ? "/F[/AHx/LZW]\n" : "/F/LZW\n");
+ fz_write_string(ctx, out, ahx ? "/F[/AHx/LZW]\n" : "/F/LZW\n");
if (cbuf->params.u.lzw.predictor > 1)
{
- fz_write_printf(ctx, out, ahx ? "/DP[<<null\n" : "/DP<<\n");
+ fz_write_string(ctx, out, ahx ? "/DP[<<null\n" : "/DP<<\n");
fz_write_printf(ctx, out, "/Predictor %d\n", cbuf->params.u.lzw.predictor);
if (cbuf->params.u.lzw.columns != 1)
fz_write_printf(ctx, out, "/Columns %d\n", cbuf->params.u.lzw.columns);
@@ -658,12 +662,12 @@ pdf_out_BI(fz_context *ctx, pdf_processor *proc, fz_image *img)
fz_write_printf(ctx, out, "/BitsPerComponent %d\n", cbuf->params.u.lzw.bpc);
if (cbuf->params.u.lzw.early_change != 1)
fz_write_printf(ctx, out, "/EarlyChange %d\n", cbuf->params.u.lzw.early_change);
- fz_write_printf(ctx, out, ahx ? ">>]\n" : ">>\n");
+ fz_write_string(ctx, out, ahx ? ">>]\n" : ">>\n");
}
break;
}
- fz_write_printf(ctx, out, "ID\n");
+ fz_write_string(ctx, out, "ID\n");
len = fz_buffer_storage(ctx, buf, &data);
if (ahx)
{
@@ -682,7 +686,7 @@ pdf_out_BI(fz_context *ctx, pdf_processor *proc, fz_image *img)
{
fz_write_data(ctx, out, data, len);
}
- fz_write_printf(ctx, out, "\nEI\n");
+ fz_write_string(ctx, out, "\nEI\n");
}
static void
@@ -721,7 +725,7 @@ pdf_out_DP(fz_context *ctx, pdf_processor *proc, const char *tag, pdf_obj *raw,
fz_output *out = ((pdf_output_processor*)proc)->out;
fz_write_printf(ctx, out, "/%s ", tag);
pdf_print_obj(ctx, out, raw, 1);
- fz_write_printf(ctx, out, " DP\n");
+ fz_write_string(ctx, out, " DP\n");
}
static void
@@ -737,14 +741,14 @@ pdf_out_BDC(fz_context *ctx, pdf_processor *proc, const char *tag, pdf_obj *raw,
fz_output *out = ((pdf_output_processor*)proc)->out;
fz_write_printf(ctx, out, "/%s ", tag);
pdf_print_obj(ctx, out, raw, 1);
- fz_write_printf(ctx, out, " BDC\n");
+ fz_write_string(ctx, out, " BDC\n");
}
static void
pdf_out_EMC(fz_context *ctx, pdf_processor *proc)
{
fz_output *out = ((pdf_output_processor*)proc)->out;
- fz_write_printf(ctx, out, "EMC\n");
+ fz_write_string(ctx, out, "EMC\n");
}
/* compatibility */
@@ -753,14 +757,14 @@ static void
pdf_out_BX(fz_context *ctx, pdf_processor *proc)
{
fz_output *out = ((pdf_output_processor*)proc)->out;
- fz_write_printf(ctx, out, "BX\n");
+ fz_write_string(ctx, out, "BX\n");
}
static void
pdf_out_EX(fz_context *ctx, pdf_processor *proc)
{
fz_output *out = ((pdf_output_processor*)proc)->out;
- fz_write_printf(ctx, out, "EX\n");
+ fz_write_string(ctx, out, "EX\n");
}
static void