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