pdf_text.c

Wed, 19 Mar 2003 15:39:55 +0000

author
eric
date
Wed, 19 Mar 2003 15:39:55 +0000
changeset 139
ec2a06d8a2a6
parent 125
e2ef1c2f9eca
permissions
-rw-r--r--

more JPEG support.

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