1.1 diff -r c22e1c0a64fd -r cbc382d73a86 pdf_text.c 1.2 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.3 +++ b/pdf_text.c Thu Mar 13 07:57:21 2003 +0000 1.4 @@ -0,0 +1,91 @@ 1.5 +/* 1.6 + * t2p: Create a PDF file from the contents of one or more TIFF 1.7 + * bilevel image files. The images in the resulting PDF file 1.8 + * will be compressed using ITU-T T.6 (G4) fax encoding. 1.9 + * 1.10 + * PDF routines 1.11 + * $Id: pdf_text.c,v 1.1 2003/03/12 23:57:21 eric Exp $ 1.12 + * Copyright 2003 Eric Smith <eric@brouhaha.com> 1.13 + * 1.14 + * This program is free software; you can redistribute it and/or modify 1.15 + * it under the terms of the GNU General Public License version 2 as 1.16 + * published by the Free Software Foundation. Note that permission is 1.17 + * not granted to redistribute this program under the terms of any 1.18 + * other version of the General Public License. 1.19 + * 1.20 + * This program is distributed in the hope that it will be useful, 1.21 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 1.22 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1.23 + * GNU General Public License for more details. 1.24 + * 1.25 + * You should have received a copy of the GNU General Public License 1.26 + * along with this program; if not, write to the Free Software 1.27 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA 1.28 + */ 1.29 + 1.30 + 1.31 +#include <stdbool.h> 1.32 +#include <stdint.h> 1.33 +#include <stdio.h> 1.34 +#include <stdlib.h> 1.35 +#include <string.h> 1.36 + 1.37 + 1.38 +#include "bitblt.h" 1.39 +#include "pdf.h" 1.40 +#include "pdf_util.h" 1.41 +#include "pdf_prim.h" 1.42 +#include "pdf_private.h" 1.43 + 1.44 + 1.45 + 1.46 +static void pdf_write_text_content_callback (pdf_file_handle pdf_file, 1.47 + struct pdf_obj *stream, 1.48 + void *app_data) 1.49 +{ 1.50 + pdf_stream_printf (pdf_file, stream, 1.51 + "BT /F1 24 Tf 100 100 Td (Hello World) Tj ET\r\n"); 1.52 +} 1.53 + 1.54 + 1.55 +static struct pdf_obj *pdf_create_font (pdf_page_handle pdf_page) 1.56 +{ 1.57 + struct pdf_obj *font = pdf_new_ind_ref (pdf_page->pdf_file, 1.58 + pdf_new_obj (PT_DICTIONARY)); 1.59 + pdf_set_dict_entry (font, "Type", pdf_new_name ("Font")); 1.60 + pdf_set_dict_entry (font, "Subtype", pdf_new_name ("Type1")); 1.61 + pdf_set_dict_entry (font, "Name", pdf_new_name ("F1")); 1.62 + pdf_set_dict_entry (font, "BaseFont", pdf_new_name ("Helvetica")); 1.63 + pdf_set_dict_entry (font, "Encoding", pdf_new_name ("MacRomanEncoding")); 1.64 + 1.65 + return (font); 1.66 +} 1.67 + 1.68 +void pdf_write_text (pdf_page_handle pdf_page) 1.69 +{ 1.70 + struct pdf_obj *font; 1.71 + struct pdf_obj *font_dict; 1.72 + struct pdf_obj *content_stream; 1.73 + 1.74 + font = pdf_create_font (pdf_page); 1.75 + 1.76 + font_dict = pdf_new_ind_ref (pdf_page->pdf_file, 1.77 + pdf_new_obj (PT_DICTIONARY)); 1.78 + 1.79 + pdf_set_dict_entry (font_dict, "F1", font); 1.80 + 1.81 + pdf_set_dict_entry (pdf_page->resources, "Font", font_dict); 1.82 + 1.83 + pdf_add_array_elem_unique (pdf_page->procset, pdf_new_name ("Text")); 1.84 + 1.85 + content_stream = pdf_new_ind_ref (pdf_page->pdf_file, 1.86 + pdf_new_stream (pdf_page->pdf_file, 1.87 + pdf_new_obj (PT_DICTIONARY), 1.88 + & pdf_write_text_content_callback, 1.89 + NULL)); 1.90 + 1.91 + pdf_set_dict_entry (pdf_page->page_dict, "Contents", content_stream); 1.92 + 1.93 + pdf_write_ind_obj (pdf_page->pdf_file, content_stream); 1.94 +} 1.95 +