pdf_page_label.c

Mon, 14 Dec 2009 15:51:53 +0000

author
Philip Pemberton <philpem@philpem.me.uk>
date
Mon, 14 Dec 2009 15:51:53 +0000
changeset 166
301f6f17c364
parent 132
ccf1c28a2940
permissions
-rw-r--r--

Patched to add PNG and JP2 support.

Created-By: Daniel Glöckner <daniel-gl at gmx.net>


The attached patch adds PNG and JP2 support to tumble.

PNG:
As the deflated data is directly copied into the PDF, there are some
limitations to the list of supported images:
- bit depth <= 8
- no alpha channel
- no interlace

JP2:
The PDF Reference says JP2 is just a subset of the allowed JPX
format. I don't have a copy of the official standard, so I don't know
what to change to cover JPXes as well.
You'll need the Adobe Acrobat Reader 6 to display those images.
Xpdf and Ghostscript are missing the ColorSpace key in the image
dictionary, which is optional for JPXDecode and IMHO not just a matter
of a few lines of code.
One thing left to do is to change the PDF version to 1.5 if a JP2 file
has been given to tumble - maybe using the Version key in the Catalog
if seeking is not possible.
Using the resolution info in a JP2 (resc/resd boxes) is implemented but
untested. Jasper doesn't write those boxes.

I had to change the string handling to allow black in PNG palettes.
And there was a double free in tumble_input.c which happens when not
using control files.

Daniel

     1 /*
     2  * tumble: build a PDF file from image files
     3  *
     4  * PDF routines
     5  * $Id: pdf_page_label.c,v 1.2 2003/03/14 00:56:38 eric Exp $
     6  * Copyright 2003 Eric Smith <eric@brouhaha.com>
     7  *
     8  * This program is free software; you can redistribute it and/or modify
     9  * it under the terms of the GNU General Public License version 2 as
    10  * published by the Free Software Foundation.  Note that permission is
    11  * not granted to redistribute this program under the terms of any
    12  * other version of the General Public License.
    13  *
    14  * This program is distributed in the hope that it will be useful,
    15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
    16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    17  * GNU General Public License for more details.
    18  *
    19  * You should have received a copy of the GNU General Public License
    20  * along with this program; if not, write to the Free Software
    21  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA
    22  */
    25 #include <stdbool.h>
    26 #include <stdint.h>
    27 #include <stdio.h>
    28 #include <stdlib.h>
    29 #include <string.h>
    32 #include "bitblt.h"
    33 #include "pdf.h"
    34 #include "pdf_util.h"
    35 #include "pdf_prim.h"
    36 #include "pdf_private.h"
    37 #include "pdf_name_tree.h"
    40 void pdf_new_page_label (pdf_file_handle pdf_file,
    41 			 int page_index,
    42 			 int base,
    43 			 int count,
    44 			 char style,
    45 			 char *prefix)
    46 {
    47   struct pdf_obj *label_dict;
    48   char style_str [2] = { style, '\0' };
    50   if (! pdf_file->page_label_tree)
    51     {
    52       pdf_file->page_label_tree = pdf_new_name_tree (pdf_file, 1);
    53     }
    55   label_dict = pdf_new_obj (PT_DICTIONARY);
    56   pdf_set_dict_entry (label_dict, "S", pdf_new_name (style_str));
    57   if (prefix)
    58     pdf_set_dict_entry (label_dict, "P", pdf_new_string (prefix));
    59   if (base != 1)
    60     pdf_set_dict_entry (label_dict, "St", pdf_new_integer (base));
    62   pdf_add_number_tree_element (pdf_file->page_label_tree,
    63 			       page_index,
    64 			       label_dict);
    65 }