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