Skip to content
Snippets Groups Projects
Commit 19a9ee36 authored by Hartmut Henkel's avatar Hartmut Henkel
Browse files

separate pdf_begin_stream() from dictionary writing,

rm pdf_newline_char macro
parent e8314d6d
No related branches found
No related tags found
No related merge requests found
Showing
with 79 additions and 22 deletions
......@@ -346,6 +346,8 @@ int write_tounicode(PDF pdf, char **glyph_names, char *name)
objnum = pdf_new_objnum(pdf);
pdf_begin_obj(pdf, objnum, 0);
pdf_begin_dict(pdf);
pdf_dict_add_stream(pdf);
pdf_end_dict(pdf);
pdf_begin_stream(pdf);
pdf_printf(pdf, "%%!PS-Adobe-3.0 Resource-CMap\n"@/
"%%%%DocumentNeededResources: ProcSet (CIDInit)\n"@/
......@@ -492,6 +494,8 @@ int write_cid_tounicode(PDF pdf, fo_entry * fo, internal_font_number f)
objnum = pdf_new_objnum(pdf);
pdf_begin_obj(pdf, objnum, 0);
pdf_begin_dict(pdf);
pdf_dict_add_stream(pdf);
pdf_end_dict(pdf);
pdf_begin_stream(pdf);
pdf_printf(pdf, "%%!PS-Adobe-3.0 Resource-CMap\n"@/
"%%%%DocumentNeededResources: ProcSet (CIDInit)\n"@/
......
......@@ -3181,6 +3181,8 @@ void write_cff(PDF pdf, cff_font * cffont, fd_entry * fd)
}
pdf_begin_obj(pdf, cidset, 0);
pdf_begin_dict(pdf);
pdf_dict_add_stream(pdf);
pdf_end_dict(pdf);
pdf_begin_stream(pdf);
pdf_out_block(pdf, stream, l);
pdf_end_stream(pdf);
......
......@@ -462,6 +462,8 @@ static void write_fontfile(PDF pdf, fd_entry * fd)
else
assert(0);
}
pdf_dict_add_stream(pdf);
pdf_end_dict(pdf);
pdf_begin_stream(pdf);
fb_flush(pdf);
pdf_end_stream(pdf);
......
......@@ -189,6 +189,8 @@ static boolean writepk(PDF pdf, internal_font_number f)
t3_glyph_num++;
t3_char_procs[cd.charcode] = pdf_new_obj(pdf, obj_type_others, 0, 0);
pdf_begin_dict(pdf);
pdf_dict_add_stream(pdf);
pdf_end_dict(pdf);
pdf_begin_stream(pdf);
pdf_print_real(pdf, (int) t3_char_widths[cd.charcode], 2);
pdf_printf(pdf, " 0 %i %i %i %i d1\n",
......
......@@ -413,6 +413,8 @@ void make_tt_subset(PDF pdf, fd_entry * fd, unsigned char *buffer, int buflen)
}
pdf_begin_obj(pdf, cidset, 0);
pdf_begin_dict(pdf);
pdf_dict_add_stream(pdf);
pdf_end_dict(pdf);
pdf_begin_stream(pdf);
pdf_out_block(pdf, stream, l);
pdf_end_stream(pdf);
......
/* epdf.h
Copyright 1996-2006 Han The Thanh <thanh@pdftex.org>
Copyright 2006-2010 Taco Hoekwater <taco@luatex.org>
Copyright 2006-2011 Taco Hoekwater <taco@luatex.org>
This file is part of LuaTeX.
LuaTeX is free software; you can redistribute it and/or modify it under
......@@ -89,6 +89,7 @@ extern "C" {
extern void pdf_end_dict(PDF);
extern void pdf_begin_array(PDF);
extern void pdf_end_array(PDF);
extern void pdf_dict_add_stream(PDF);
extern void pdf_begin_stream(PDF);
extern void pdf_end_stream(PDF);
extern void pdf_room(PDF, int);
......
......@@ -819,6 +819,8 @@ void write_epdf(PDF pdf, image_dict * idict)
pdf_end_stream(pdf);
pdf_end_obj(pdf);
} else if (contents.isArray()) {
pdf_dict_add_stream(pdf);
pdf_end_dict(pdf);
pdf_begin_stream(pdf);
for (i = 0, l = contents.arrayGetLength(); i < l; ++i) {
copyStreamStream(pdf, (contents.arrayGet(i, &obj1))->getStream());
......@@ -832,6 +834,8 @@ void write_epdf(PDF pdf, image_dict * idict)
pdf_end_stream(pdf);
pdf_end_obj(pdf);
} else { // the contents are optional, but we need to include an empty stream
pdf_dict_add_stream(pdf);
pdf_end_dict(pdf);
pdf_begin_stream(pdf);
pdf_end_stream(pdf);
pdf_end_obj(pdf);
......
% writeimg.w
% Copyright 1996-2006 Han The Thanh <thanh@@pdftex.org>
% Copyright 2006-2010 Taco Hoekwater <taco@@luatex.org>
% Copyright 2006-2011 Taco Hoekwater <taco@@luatex.org>
% This file is part of LuaTeX.
......@@ -644,6 +644,8 @@ void write_pdfstream(PDF pdf, image_dict * idict)
int2bp(img_bbox(idict)[1]), int2bp(img_bbox(idict)[2]),
int2bp(img_bbox(idict)[3]));
pdf_printf(pdf, stripzeros(s));
pdf_dict_add_stream(pdf);
pdf_end_dict(pdf);
pdf_begin_stream(pdf);
if (img_pdfstream_stream(idict) != NULL)
pdf_puts(pdf, img_pdfstream_stream(idict));
......
% writejpg.w
% Copyright 1996-2006 Han The Thanh <thanh@@pdftex.org>
% Copyright 2006-2010 Taco Hoekwater <taco@@luatex.org>
% Copyright 2006-2011 Taco Hoekwater <taco@@luatex.org>
% This file is part of LuaTeX.
......
% writepng.w
% Copyright 1996-2006 Han The Thanh <thanh@@pdftex.org>
% Copyright 2006-2010 Taco Hoekwater <taco@@luatex.org>
% Copyright 2006-2011 Taco Hoekwater <taco@@luatex.org>
% This file is part of LuaTeX.
......@@ -190,6 +190,8 @@ static void write_png_palette(PDF pdf, image_dict * idict)
pdf_printf(pdf, "[/Indexed /DeviceRGB %i %i 0 R]\n",
(int) (num_palette - 1), (int) palette_objnum);
}
pdf_dict_add_stream(pdf);
pdf_end_dict(pdf);
pdf_begin_stream(pdf);
if (png_get_interlace_type(png_p, info_p) == PNG_INTERLACE_NONE) {
row = xtalloc(png_get_rowbytes(png_p, info_p), png_byte);
......@@ -211,6 +213,8 @@ static void write_png_palette(PDF pdf, image_dict * idict)
if (palette_objnum > 0) {
pdf_begin_obj(pdf, palette_objnum, 0);
pdf_begin_dict(pdf);
pdf_dict_add_stream(pdf);
pdf_end_dict(pdf);
pdf_begin_stream(pdf);
for (i = 0; i < num_palette; i++) {
pdf_room(pdf, 3);
......@@ -235,6 +239,8 @@ static void write_png_gray(PDF pdf, image_dict * idict)
} else {
pdf_puts(pdf, "/DeviceGray\n");
}
pdf_dict_add_stream(pdf);
pdf_end_dict(pdf);
pdf_begin_stream(pdf);
if (png_get_interlace_type(png_p, info_p) == PNG_INTERLACE_NONE) {
row = xtalloc(png_get_rowbytes(png_p, info_p), png_byte);
......@@ -276,6 +282,8 @@ static void write_png_gray_alpha(PDF pdf, image_dict * idict)
pdf_printf(pdf, "/SMask %i 0 R\n", (int) smask_objnum);
smask_size = (int) ((png_get_rowbytes(png_p, info_p) / 2) * png_get_image_height (png_p, info_p));
smask = xtalloc((unsigned) smask_size, png_byte);
pdf_dict_add_stream(pdf);
pdf_end_dict(pdf);
pdf_begin_stream(pdf);
if (png_get_interlace_type(png_p, info_p) == PNG_INTERLACE_NONE) {
row = xtalloc(png_get_rowbytes(png_p, info_p), png_byte);
......@@ -315,6 +323,8 @@ static void write_png_gray_alpha(PDF pdf, image_dict * idict)
(int) png_get_image_height (png_p, info_p),
(bitdepth == 16 ? 8 : bitdepth));
pdf_puts(pdf, "/ColorSpace /DeviceGray\n");
pdf_dict_add_stream(pdf);
pdf_end_dict(pdf);
pdf_begin_stream(pdf);
for (i = 0; i < smask_size; i++) {
if (i % 8 == 0)
......@@ -340,6 +350,8 @@ static void write_png_rgb(PDF pdf, image_dict * idict)
} else {
pdf_puts(pdf, "/DeviceRGB\n");
}
pdf_dict_add_stream(pdf);
pdf_end_dict(pdf);
pdf_begin_stream(pdf);
if (png_get_interlace_type(png_p, info_p) == PNG_INTERLACE_NONE) {
row = xtalloc(png_get_rowbytes(png_p, info_p), png_byte);
......@@ -381,6 +393,8 @@ static void write_png_rgb_alpha(PDF pdf, image_dict * idict)
pdf_printf(pdf, "/SMask %i 0 R\n", (int) smask_objnum);
smask_size = (int) ((png_get_rowbytes (png_p, info_p) / 4) * png_get_image_height (png_p, info_p));
smask = xtalloc((unsigned) smask_size, png_byte);
pdf_dict_add_stream(pdf);
pdf_end_dict(pdf);
pdf_begin_stream(pdf);
if (png_get_interlace_type(png_p, info_p) == PNG_INTERLACE_NONE) {
row = xtalloc(png_get_rowbytes(png_p, info_p), png_byte);
......@@ -421,6 +435,8 @@ static void write_png_rgb_alpha(PDF pdf, image_dict * idict)
(int) png_get_image_height (png_p, info_p),
(bitdepth == 16 ? 8 : bitdepth));
pdf_puts(pdf, "/ColorSpace /DeviceGray\n");
pdf_dict_add_stream(pdf);
pdf_end_dict(pdf);
pdf_begin_stream(pdf);
for (i = 0; i < smask_size; i++) {
if (i % 8 == 0)
......@@ -619,6 +635,8 @@ void write_png(PDF pdf, image_dict * idict)
if (palette_objnum > 0) {
pdf_begin_obj(pdf, palette_objnum, 0);
pdf_begin_dict(pdf);
pdf_dict_add_stream(pdf);
pdf_end_dict(pdf);
pdf_begin_stream(pdf);
for (i = 0; i < num_palette; i++) {
pdf_room(pdf, 3);
......
......@@ -157,6 +157,8 @@ static int l_immediateobj(lua_State * L)
if (st3.s[st3.l - 1] != '\n')
pdf_puts(static_pdf, "\n");
}
pdf_dict_add_stream(static_pdf);
pdf_end_dict(static_pdf);
pdf_begin_stream(static_pdf);
if (st1.l == 6 && strncmp((const char *) st1.s, "stream", 6) == 0) {
pdf_out_block(static_pdf, st2.s, st2.l);
......@@ -401,6 +403,8 @@ static int table_obj(lua_State * L)
}
if (compress_level > -1)
static_pdf->compress_level = compress_level;
pdf_dict_add_stream(static_pdf);
pdf_end_dict(static_pdf);
pdf_begin_stream(static_pdf);
} else {
set_obj_obj_is_stream(static_pdf, k);
......
......@@ -116,10 +116,8 @@ printing ones but the output is going to PDF buffer. Subroutines with
suffix |_ln| append a new-line character to the PDF output.
*/
# define pdf_newline_char 10 /* new-line character '\n' for UNIX platforms */
/* output a new-line character to PDF buffer */
# define pdf_print_nl(pdf) pdf_out(pdf,pdf_newline_char)
# define pdf_print_nl(pdf) pdf_out(pdf, '\n')
/* print out a string to PDF buffer followed by a new-line character */
# define pdf_print_ln(pdf,A) do { \
......@@ -143,6 +141,8 @@ extern void pdf_print_int(PDF, longinteger);
extern void pdf_print_real(PDF, int, int);
extern void pdf_print_str(PDF, const char *);
extern void pdf_dict_add_stream(PDF);
extern void pdf_begin_stream(PDF);
extern void pdf_end_stream(PDF);
extern void pdf_remove_last_space(PDF);
......
% pdfgen.w
% Copyright 2009-2010 Taco Hoekwater <taco@@luatex.org>
% Copyright 2009-2011 Taco Hoekwater <taco@@luatex.org>
% This file is part of LuaTeX.
......@@ -599,24 +599,32 @@ void pdf_print_str(PDF pdf, const char *s)
pdf_puts(pdf, orig); /* it was a hex string after all */
}
@ begin a stream
@ add stream length and filter entries to a stream dictionary,
remember file position for seek
@c
void pdf_begin_stream(PDF pdf)
void pdf_dict_add_stream(PDF pdf)
{
assert(pdf->os_mode == false);
pdf_puts(pdf, "/Length \n");
pdf->seek_write_length = true; /* fill in length at |pdf_end_stream| call */
pdf->stream_length_offset = pdf_offset(pdf) - 11;
if (pdf->compress_level > 0)
pdf_puts(pdf, "/Filter /FlateDecode\n");
}
@ begin a stream (needs to have a stream dictionary also)
@c
void pdf_begin_stream(PDF pdf)
{
assert(pdf->os_mode == false);
assert(pdf->seek_write_length == true);
pdf->stream_length = 0;
pdf->last_byte = 0;
if (pdf->compress_level > 0) {
pdf_puts(pdf, "/Filter /FlateDecode\n");
pdf_end_dict(pdf);
pdf_puts(pdf, "stream\n");
pdf_flush(pdf);
pdf->zip_write_state = zip_writing;
} else {
pdf_end_dict(pdf);
pdf_puts(pdf, "stream\n");
pdf_save_offset(pdf);
}
......@@ -647,8 +655,8 @@ void pdf_end_stream(PDF pdf)
write_stream_length(pdf, (int) pdf->stream_length,
pdf->stream_length_offset);
pdf->seek_write_length = false;
if (pdf->last_byte != pdf_newline_char)
pdf_out(pdf, pdf_newline_char);
if (pdf->last_byte != '\n')
pdf_out(pdf, '\n');
pdf_puts(pdf, "endstream\n");
}
......@@ -1163,7 +1171,7 @@ static void pdf_os_write_objstream(PDF pdf)
pdf_printf(pdf, "%d %d", (int) pdf->os_obj[i].num,
(int) pdf->os_obj[i].off);
if (j == 9) { /* print out in groups of ten for better readability */
pdf_out(pdf, pdf_newline_char);
pdf_out(pdf, '\n');
j = 0;
} else {
pdf_out(pdf, ' ');
......@@ -1171,13 +1179,15 @@ static void pdf_os_write_objstream(PDF pdf)
}
i++;
}
pdf->buf[pdf->ptr - 1] = pdf_newline_char; /* no risk of flush, as we are in |pdf_os_mode| */
pdf->buf[pdf->ptr - 1] = '\n'; /* no risk of flush, as we are in |pdf_os_mode| */
q = pdf->ptr;
pdf_begin_obj(pdf, pdf->os_cur_objnum, 0); /* switch to PDF stream writing */
pdf_begin_dict(pdf);
pdf_puts(pdf, "/Type /ObjStm\n");
pdf_printf(pdf, "/N %d\n", (int) (pdf->os_idx + 1));
pdf_printf(pdf, "/First %d\n", (int) (q - p));
pdf_dict_add_stream(pdf);
pdf_end_dict(pdf);
pdf_begin_stream(pdf);
/* write object number and byte offset pairs;
|q - p| should always fit into the PDF output buffer */
......@@ -1260,8 +1270,8 @@ void pdf_end_obj(PDF pdf)
if (pdf->os_idx == pdf_os_max_objs - 1)
pdf_os_write_objstream(pdf);
} else {
if (pdf->last_byte != pdf_newline_char)
pdf_out(pdf, pdf_newline_char);
if (pdf->last_byte != '\n')
pdf_out(pdf, '\n');
pdf_puts(pdf, "endobj\n"); /* end a PDF object */
}
}
......@@ -1785,6 +1795,8 @@ void pdf_begin_page(PDF pdf)
pdf_indirect_ln(pdf, "Resources", pdf->page_resources->last_resources);
}
/* Start stream of page/form contents */
pdf_dict_add_stream(pdf);
pdf_end_dict(pdf);
pdf_begin_stream(pdf);
if (global_shipping_mode == SHIPPING_PAGE) {
/* Adjust transformation matrix for the magnification ratio */
......@@ -2401,6 +2413,8 @@ void finish_pdf_file(PDF pdf, int luatex_version, str_number luatex_revision)
}
print_ID(pdf, pdf->file_name);
pdf_print_nl(pdf);
pdf_dict_add_stream(pdf);
pdf_end_dict(pdf);
pdf_begin_stream(pdf);
for (k = 0; k <= pdf->obj_ptr; k++) {
if (!is_obj_written(pdf, k)) { /* a free object */
......
% pdfglyph.w
% Copyright 2009-2010 Taco Hoekwater <taco@@luatex.org>
% Copyright 2009-2011 Taco Hoekwater <taco@@luatex.org>
% This file is part of LuaTeX.
......
% pdfobj.w
% Copyright 2009-2010 Taco Hoekwater <taco@@luatex.org>
% Copyright 2009-2011 Taco Hoekwater <taco@@luatex.org>
% This file is part of LuaTeX.
......@@ -61,6 +61,8 @@ void pdf_write_obj(PDF pdf, int k)
luaL_unref(Luas, LUA_REGISTRYINDEX, l);
obj_obj_stream_attr(pdf, k) = LUA_NOREF;
}
pdf_dict_add_stream(pdf);
pdf_end_dict(pdf);
pdf_begin_stream(pdf);
} else
pdf_begin_obj(pdf, k, os_level);
......
% pdfpage.w
% Copyright 2006-2010 Taco Hoekwater <taco@@luatex.org>
% Copyright 2006-2011 Taco Hoekwater <taco@@luatex.org>
% This file is part of LuaTeX.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment