Thu, 13 Mar 2003 07:57:35 +0000
*** empty log message ***
eric@119 | 1 | /* |
eric@119 | 2 | * t2p: Create a PDF file from the contents of one or more TIFF |
eric@119 | 3 | * bilevel image files. The images in the resulting PDF file |
eric@119 | 4 | * will be compressed using ITU-T T.6 (G4) fax encoding. |
eric@119 | 5 | * |
eric@119 | 6 | * PDF routines |
eric@119 | 7 | * $Id: pdf_text.c,v 1.1 2003/03/12 23:57:21 eric Exp $ |
eric@119 | 8 | * Copyright 2003 Eric Smith <eric@brouhaha.com> |
eric@119 | 9 | * |
eric@119 | 10 | * This program is free software; you can redistribute it and/or modify |
eric@119 | 11 | * it under the terms of the GNU General Public License version 2 as |
eric@119 | 12 | * published by the Free Software Foundation. Note that permission is |
eric@119 | 13 | * not granted to redistribute this program under the terms of any |
eric@119 | 14 | * other version of the General Public License. |
eric@119 | 15 | * |
eric@119 | 16 | * This program is distributed in the hope that it will be useful, |
eric@119 | 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
eric@119 | 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
eric@119 | 19 | * GNU General Public License for more details. |
eric@119 | 20 | * |
eric@119 | 21 | * You should have received a copy of the GNU General Public License |
eric@119 | 22 | * along with this program; if not, write to the Free Software |
eric@119 | 23 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA |
eric@119 | 24 | */ |
eric@119 | 25 | |
eric@119 | 26 | |
eric@119 | 27 | #include <stdbool.h> |
eric@119 | 28 | #include <stdint.h> |
eric@119 | 29 | #include <stdio.h> |
eric@119 | 30 | #include <stdlib.h> |
eric@119 | 31 | #include <string.h> |
eric@119 | 32 | |
eric@119 | 33 | |
eric@119 | 34 | #include "bitblt.h" |
eric@119 | 35 | #include "pdf.h" |
eric@119 | 36 | #include "pdf_util.h" |
eric@119 | 37 | #include "pdf_prim.h" |
eric@119 | 38 | #include "pdf_private.h" |
eric@119 | 39 | |
eric@119 | 40 | |
eric@119 | 41 | |
eric@119 | 42 | static void pdf_write_text_content_callback (pdf_file_handle pdf_file, |
eric@119 | 43 | struct pdf_obj *stream, |
eric@119 | 44 | void *app_data) |
eric@119 | 45 | { |
eric@119 | 46 | pdf_stream_printf (pdf_file, stream, |
eric@119 | 47 | "BT /F1 24 Tf 100 100 Td (Hello World) Tj ET\r\n"); |
eric@119 | 48 | } |
eric@119 | 49 | |
eric@119 | 50 | |
eric@119 | 51 | static struct pdf_obj *pdf_create_font (pdf_page_handle pdf_page) |
eric@119 | 52 | { |
eric@119 | 53 | struct pdf_obj *font = pdf_new_ind_ref (pdf_page->pdf_file, |
eric@119 | 54 | pdf_new_obj (PT_DICTIONARY)); |
eric@119 | 55 | pdf_set_dict_entry (font, "Type", pdf_new_name ("Font")); |
eric@119 | 56 | pdf_set_dict_entry (font, "Subtype", pdf_new_name ("Type1")); |
eric@119 | 57 | pdf_set_dict_entry (font, "Name", pdf_new_name ("F1")); |
eric@119 | 58 | pdf_set_dict_entry (font, "BaseFont", pdf_new_name ("Helvetica")); |
eric@119 | 59 | pdf_set_dict_entry (font, "Encoding", pdf_new_name ("MacRomanEncoding")); |
eric@119 | 60 | |
eric@119 | 61 | return (font); |
eric@119 | 62 | } |
eric@119 | 63 | |
eric@119 | 64 | void pdf_write_text (pdf_page_handle pdf_page) |
eric@119 | 65 | { |
eric@119 | 66 | struct pdf_obj *font; |
eric@119 | 67 | struct pdf_obj *font_dict; |
eric@119 | 68 | struct pdf_obj *content_stream; |
eric@119 | 69 | |
eric@119 | 70 | font = pdf_create_font (pdf_page); |
eric@119 | 71 | |
eric@119 | 72 | font_dict = pdf_new_ind_ref (pdf_page->pdf_file, |
eric@119 | 73 | pdf_new_obj (PT_DICTIONARY)); |
eric@119 | 74 | |
eric@119 | 75 | pdf_set_dict_entry (font_dict, "F1", font); |
eric@119 | 76 | |
eric@119 | 77 | pdf_set_dict_entry (pdf_page->resources, "Font", font_dict); |
eric@119 | 78 | |
eric@119 | 79 | pdf_add_array_elem_unique (pdf_page->procset, pdf_new_name ("Text")); |
eric@119 | 80 | |
eric@119 | 81 | content_stream = pdf_new_ind_ref (pdf_page->pdf_file, |
eric@119 | 82 | pdf_new_stream (pdf_page->pdf_file, |
eric@119 | 83 | pdf_new_obj (PT_DICTIONARY), |
eric@119 | 84 | & pdf_write_text_content_callback, |
eric@119 | 85 | NULL)); |
eric@119 | 86 | |
eric@119 | 87 | pdf_set_dict_entry (pdf_page->page_dict, "Contents", content_stream); |
eric@119 | 88 | |
eric@119 | 89 | pdf_write_ind_obj (pdf_page->pdf_file, content_stream); |
eric@119 | 90 | } |
eric@119 | 91 |