Thu, 13 Mar 2003 07:57:21 +0000
added pdf_write_text(), just a placeholder/debugging tool at the moment.
Makefile | file | annotate | diff | revisions | |
pdf.h | file | annotate | diff | revisions | |
pdf_text.c | file | annotate | diff | revisions |
1.1 --- a/Makefile Thu Mar 13 06:56:57 2003 +0000 1.2 +++ b/Makefile Thu Mar 13 07:57:21 2003 +0000 1.3 @@ -1,6 +1,6 @@ 1.4 # t2p: build a PDF file out of one or more TIFF Class F Group 4 files 1.5 # Makefile 1.6 -# $Id: Makefile,v 1.27 2003/03/12 19:39:38 eric Exp $ 1.7 +# $Id: Makefile,v 1.28 2003/03/12 23:57:21 eric Exp $ 1.8 # Copyright 2001, 2002, 2003 Eric Smith <eric@brouhaha.com> 1.9 # 1.10 # This program is free software; you can redistribute it and/or modify 1.11 @@ -55,7 +55,7 @@ 1.12 # let me know why so I can improve this Makefile. 1.13 # ----------------------------------------------------------------------------- 1.14 1.15 -VERSION = 0.22 1.16 +VERSION = 0.23 1.17 1.18 PACKAGE = t2p 1.19 1.20 @@ -64,7 +64,7 @@ 1.21 CSRCS = t2p.c semantics.c \ 1.22 bitblt.c bitblt_table_gen.c bitblt_g4.c g4_table_gen.c \ 1.23 pdf.c pdf_util.c pdf_prim.c pdf_bookmark.c pdf_name_tree.c \ 1.24 - pdf_g4.c pdf_jpeg.c 1.25 + pdf_text.c pdf_g4.c pdf_jpeg.c 1.26 OSRCS = scanner.l parser.y 1.27 HDRS = t2p.h semantics.h bitblt.h bitblt_tables.h \ 1.28 pdf.h pdf_private.h pdf_util.h pdf_prim.h pdf_name_tree.h 1.29 @@ -88,7 +88,7 @@ 1.30 t2p: t2p.o scanner.o semantics.o parser.tab.o \ 1.31 bitblt.o bitblt_g4.o bitblt_tables.o g4_tables.o \ 1.32 pdf.o pdf_util.o pdf_prim.o pdf_bookmark.o pdf_name_tree.o \ 1.33 - pdf_g4.o pdf_jpeg.o 1.34 + pdf_text.o pdf_g4.o pdf_jpeg.o 1.35 $(LINK.o) $^ $(LOADLIBES) $(LDLIBS) -o $@ 1.36 ifndef DEBUG 1.37 strip $@
2.1 --- a/pdf.h Thu Mar 13 06:56:57 2003 +0000 2.2 +++ b/pdf.h Thu Mar 13 07:57:21 2003 +0000 2.3 @@ -4,7 +4,7 @@ 2.4 * will be compressed using ITU-T T.6 (G4) fax encoding. 2.5 * 2.6 * PDF routines 2.7 - * $Id: pdf.h,v 1.7 2003/03/12 02:57:55 eric Exp $ 2.8 + * $Id: pdf.h,v 1.8 2003/03/12 23:57:21 eric Exp $ 2.9 * Copyright 2001, 2002, 2003 Eric Smith <eric@brouhaha.com> 2.10 * 2.11 * This program is free software; you can redistribute it and/or modify 2.12 @@ -57,6 +57,9 @@ 2.13 void pdf_close_page (pdf_page_handle pdf_page); 2.14 2.15 2.16 +void pdf_write_text (pdf_page_handle pdf_page); 2.17 + 2.18 + 2.19 /* The length of the data must be Rows * rowbytes. 2.20 Note that rowbytes must be at least (Columns+7)/8, but may be arbitrarily 2.21 large. */
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 3.2 +++ b/pdf_text.c Thu Mar 13 07:57:21 2003 +0000 3.3 @@ -0,0 +1,91 @@ 3.4 +/* 3.5 + * t2p: Create a PDF file from the contents of one or more TIFF 3.6 + * bilevel image files. The images in the resulting PDF file 3.7 + * will be compressed using ITU-T T.6 (G4) fax encoding. 3.8 + * 3.9 + * PDF routines 3.10 + * $Id: pdf_text.c,v 1.1 2003/03/12 23:57:21 eric Exp $ 3.11 + * Copyright 2003 Eric Smith <eric@brouhaha.com> 3.12 + * 3.13 + * This program is free software; you can redistribute it and/or modify 3.14 + * it under the terms of the GNU General Public License version 2 as 3.15 + * published by the Free Software Foundation. Note that permission is 3.16 + * not granted to redistribute this program under the terms of any 3.17 + * other version of the General Public License. 3.18 + * 3.19 + * This program is distributed in the hope that it will be useful, 3.20 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 3.21 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 3.22 + * GNU General Public License for more details. 3.23 + * 3.24 + * You should have received a copy of the GNU General Public License 3.25 + * along with this program; if not, write to the Free Software 3.26 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA 3.27 + */ 3.28 + 3.29 + 3.30 +#include <stdbool.h> 3.31 +#include <stdint.h> 3.32 +#include <stdio.h> 3.33 +#include <stdlib.h> 3.34 +#include <string.h> 3.35 + 3.36 + 3.37 +#include "bitblt.h" 3.38 +#include "pdf.h" 3.39 +#include "pdf_util.h" 3.40 +#include "pdf_prim.h" 3.41 +#include "pdf_private.h" 3.42 + 3.43 + 3.44 + 3.45 +static void pdf_write_text_content_callback (pdf_file_handle pdf_file, 3.46 + struct pdf_obj *stream, 3.47 + void *app_data) 3.48 +{ 3.49 + pdf_stream_printf (pdf_file, stream, 3.50 + "BT /F1 24 Tf 100 100 Td (Hello World) Tj ET\r\n"); 3.51 +} 3.52 + 3.53 + 3.54 +static struct pdf_obj *pdf_create_font (pdf_page_handle pdf_page) 3.55 +{ 3.56 + struct pdf_obj *font = pdf_new_ind_ref (pdf_page->pdf_file, 3.57 + pdf_new_obj (PT_DICTIONARY)); 3.58 + pdf_set_dict_entry (font, "Type", pdf_new_name ("Font")); 3.59 + pdf_set_dict_entry (font, "Subtype", pdf_new_name ("Type1")); 3.60 + pdf_set_dict_entry (font, "Name", pdf_new_name ("F1")); 3.61 + pdf_set_dict_entry (font, "BaseFont", pdf_new_name ("Helvetica")); 3.62 + pdf_set_dict_entry (font, "Encoding", pdf_new_name ("MacRomanEncoding")); 3.63 + 3.64 + return (font); 3.65 +} 3.66 + 3.67 +void pdf_write_text (pdf_page_handle pdf_page) 3.68 +{ 3.69 + struct pdf_obj *font; 3.70 + struct pdf_obj *font_dict; 3.71 + struct pdf_obj *content_stream; 3.72 + 3.73 + font = pdf_create_font (pdf_page); 3.74 + 3.75 + font_dict = pdf_new_ind_ref (pdf_page->pdf_file, 3.76 + pdf_new_obj (PT_DICTIONARY)); 3.77 + 3.78 + pdf_set_dict_entry (font_dict, "F1", font); 3.79 + 3.80 + pdf_set_dict_entry (pdf_page->resources, "Font", font_dict); 3.81 + 3.82 + pdf_add_array_elem_unique (pdf_page->procset, pdf_new_name ("Text")); 3.83 + 3.84 + content_stream = pdf_new_ind_ref (pdf_page->pdf_file, 3.85 + pdf_new_stream (pdf_page->pdf_file, 3.86 + pdf_new_obj (PT_DICTIONARY), 3.87 + & pdf_write_text_content_callback, 3.88 + NULL)); 3.89 + 3.90 + pdf_set_dict_entry (pdf_page->page_dict, "Contents", content_stream); 3.91 + 3.92 + pdf_write_ind_obj (pdf_page->pdf_file, content_stream); 3.93 +} 3.94 +