1
0
mirror of synced 2026-01-13 07:20:22 +00:00

added pdf_write_text(), just a placeholder/debugging tool at the moment.

This commit is contained in:
Eric Smith 2003-03-13 07:57:21 +00:00
parent dcee44c614
commit b48791c77d
3 changed files with 99 additions and 5 deletions

View File

@ -1,6 +1,6 @@
# t2p: build a PDF file out of one or more TIFF Class F Group 4 files
# Makefile
# $Id: Makefile,v 1.27 2003/03/12 19:39:38 eric Exp $
# $Id: Makefile,v 1.28 2003/03/12 23:57:21 eric Exp $
# Copyright 2001, 2002, 2003 Eric Smith <eric@brouhaha.com>
#
# This program is free software; you can redistribute it and/or modify
@ -55,7 +55,7 @@ YFLAGS = -d -v
# let me know why so I can improve this Makefile.
# -----------------------------------------------------------------------------
VERSION = 0.22
VERSION = 0.23
PACKAGE = t2p
@ -64,7 +64,7 @@ TARGETS = t2p
CSRCS = t2p.c semantics.c \
bitblt.c bitblt_table_gen.c bitblt_g4.c g4_table_gen.c \
pdf.c pdf_util.c pdf_prim.c pdf_bookmark.c pdf_name_tree.c \
pdf_g4.c pdf_jpeg.c
pdf_text.c pdf_g4.c pdf_jpeg.c
OSRCS = scanner.l parser.y
HDRS = t2p.h semantics.h bitblt.h bitblt_tables.h \
pdf.h pdf_private.h pdf_util.h pdf_prim.h pdf_name_tree.h
@ -88,7 +88,7 @@ all: $(TARGETS) $(TEST_TARGETS)
t2p: t2p.o scanner.o semantics.o parser.tab.o \
bitblt.o bitblt_g4.o bitblt_tables.o g4_tables.o \
pdf.o pdf_util.o pdf_prim.o pdf_bookmark.o pdf_name_tree.o \
pdf_g4.o pdf_jpeg.o
pdf_text.o pdf_g4.o pdf_jpeg.o
$(LINK.o) $^ $(LOADLIBES) $(LDLIBS) -o $@
ifndef DEBUG
strip $@

5
pdf.h
View File

@ -4,7 +4,7 @@
* will be compressed using ITU-T T.6 (G4) fax encoding.
*
* PDF routines
* $Id: pdf.h,v 1.7 2003/03/12 02:57:55 eric Exp $
* $Id: pdf.h,v 1.8 2003/03/12 23:57:21 eric Exp $
* Copyright 2001, 2002, 2003 Eric Smith <eric@brouhaha.com>
*
* This program is free software; you can redistribute it and/or modify
@ -57,6 +57,9 @@ pdf_page_handle pdf_new_page (pdf_file_handle pdf_file,
void pdf_close_page (pdf_page_handle pdf_page);
void pdf_write_text (pdf_page_handle pdf_page);
/* The length of the data must be Rows * rowbytes.
Note that rowbytes must be at least (Columns+7)/8, but may be arbitrarily
large. */

91
pdf_text.c Normal file
View File

@ -0,0 +1,91 @@
/*
* t2p: Create a PDF file from the contents of one or more TIFF
* bilevel image files. The images in the resulting PDF file
* will be compressed using ITU-T T.6 (G4) fax encoding.
*
* PDF routines
* $Id: pdf_text.c,v 1.1 2003/03/12 23:57:21 eric Exp $
* Copyright 2003 Eric Smith <eric@brouhaha.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation. Note that permission is
* not granted to redistribute this program under the terms of any
* other version of the General Public License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA
*/
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "bitblt.h"
#include "pdf.h"
#include "pdf_util.h"
#include "pdf_prim.h"
#include "pdf_private.h"
static void pdf_write_text_content_callback (pdf_file_handle pdf_file,
struct pdf_obj *stream,
void *app_data)
{
pdf_stream_printf (pdf_file, stream,
"BT /F1 24 Tf 100 100 Td (Hello World) Tj ET\r\n");
}
static struct pdf_obj *pdf_create_font (pdf_page_handle pdf_page)
{
struct pdf_obj *font = pdf_new_ind_ref (pdf_page->pdf_file,
pdf_new_obj (PT_DICTIONARY));
pdf_set_dict_entry (font, "Type", pdf_new_name ("Font"));
pdf_set_dict_entry (font, "Subtype", pdf_new_name ("Type1"));
pdf_set_dict_entry (font, "Name", pdf_new_name ("F1"));
pdf_set_dict_entry (font, "BaseFont", pdf_new_name ("Helvetica"));
pdf_set_dict_entry (font, "Encoding", pdf_new_name ("MacRomanEncoding"));
return (font);
}
void pdf_write_text (pdf_page_handle pdf_page)
{
struct pdf_obj *font;
struct pdf_obj *font_dict;
struct pdf_obj *content_stream;
font = pdf_create_font (pdf_page);
font_dict = pdf_new_ind_ref (pdf_page->pdf_file,
pdf_new_obj (PT_DICTIONARY));
pdf_set_dict_entry (font_dict, "F1", font);
pdf_set_dict_entry (pdf_page->resources, "Font", font_dict);
pdf_add_array_elem_unique (pdf_page->procset, pdf_new_name ("Text"));
content_stream = pdf_new_ind_ref (pdf_page->pdf_file,
pdf_new_stream (pdf_page->pdf_file,
pdf_new_obj (PT_DICTIONARY),
& pdf_write_text_content_callback,
NULL));
pdf_set_dict_entry (pdf_page->page_dict, "Contents", content_stream);
pdf_write_ind_obj (pdf_page->pdf_file, content_stream);
}