FreeType 1.31.1

This commit is contained in:
2023-08-27 18:03:45 +02:00
commit 5edbb7a80a
454 changed files with 173977 additions and 0 deletions

View File

@@ -0,0 +1,3 @@
t1asm
ttf2pfb
Makefile

View File

@@ -0,0 +1,16 @@
# Makefile for ttf2pfb and t1asm
all: ttf2pfb.exe t1asm.exe
ttf2pfb.exe: ttf2pfb.o
gcc -O -o ttf2pfb.exe ttf2pfb.o -lttf
ttf2pfb.o: ttf2pfb.c
gcc -O -c ttf2pfb.c
t1asm.exe: t1asm.o
gcc -O -o t1asm.exe t1asm.o -lttf
t1asm.o: t1asm.c
gcc -O -c t1asm.c

View File

@@ -0,0 +1,74 @@
# Makefile for ttf2pfb
#
# This Makefile assumes that you've already built and installed
# the FreeType library.
VPATH = @srcdir@
srcdir = @srcdir@
RM = @RM@
RMF = @RM@ -f
INSTALL = @INSTALL@
INSTALL_DATA = @INSTALL_DATA@
INSTALL_PROGRAM = @INSTALL_PROGRAM@
CC = @CC@
CPP = @CPP@
LIBTOOL = ../../libtool
MKINSTALLDIRS = $(srcdir)/../../mkinstalldirs
prefix = @prefix@
exec_prefix = @exec_prefix@
bindir = @bindir@
mandir = @mandir@
CFLAGS = @CFLAGS@ @XX_CFLAGS@
CPPFLAGS = @CPPFLAGS@ @DEFS@
FT_CFLAGS = $(CFLAGS) $(CPPFLAGS)
LDFLAGS = @LDFLAGS@ @LIBS@
LIBDIR = ../../lib
SRC = t1asm.c ttf2pfb.c
PROGRAMS = t1asm ttf2pfb
default all: $(PROGRAMS)
t1asm: t1asm.c
$(CC) $(CFLAGS) -o $@ $<
ttf2pfb: ttf2pfb.o $(LIBDIR)/libttf.la
$(LIBTOOL) --mode=link $(CC) $(FT_CFLAGS) -o $@ $< \
$(LIBDIR)/libttf.la $(LDFLAGS)
clean:
$(RMF) *.o *BAK *CKP *~ a.out core
realclean: clean
$(RMF) $(PROGRAMS)
$(RM) -rf .libs/
distclean: realclean
$(RMF) *~ *.orig core *.core
$(RMF) config.cache config.log config.status Makefile
.c.o:
$(CC) -c $(FT_CFLAGS) $<
install: $(PROGRAMS)
$(MKINSTALLDIRS) $(bindir)
for P in $(PROGRAMS) ; do \
$(LIBTOOL) --mode=install $(INSTALL_PROGRAM) $$P $(bindir)/$$P ; \
done
$(INSTALL_PROGRAM) $(srcdir)/getafm $(bindir)/getafm
uninstall:
-for P in $(PROGRAMS) ; do \
$(LIBTOOL) --mode=uninstall $(RM) $(bindir)/$$P ; \
done
.PHONY: all clean realclean distclean install uninstall
# end of Makefile

40
contrib/ttf2pfb/TODO Normal file
View File

@@ -0,0 +1,40 @@
ttf2pfb is oriented towards support for CJK fonts containing several
thousand glyphs to be splitted into subfonts with 256 characters each usable
by TeX. Nevertheless, it is quite generic and works with normal ttf files
too.
Some features are still missing or should be added for convenience:
. Documentation. ttf2pbf explains itself; t1asm is a filter which converts
the (disassembled) pseudo font created by ttf2pfb into a real PFA font
(or PFB if you use the `-b' command line switch).
Example for an ordinary font:
ttf2pfb -v -m -enc Uni-T1.enc -f FooBar -o foobar.ps foobar.ttf
t1asm -b < foobar.ps > foobar.pfb
printafm foobar.pfb > foobar.afm
afm2tfm foobar.afm
Example for a CJK font in Big 5 encoding to be used with the CJK package
for LaTeX (note that the call creates just the first subfont):
ttf2pfb -c -pid 3 -eid 4 -plane 1 -f FooBar01 -o foobar01.ps foobar.ttf
t1asm -b < foobar01.ps > foobar01.pfb
printafm foobar01.pfb > foobar01.afm
afm2tfm foobar01.afm
. Inclusion of t1asm and t1binary into ttf2pfb so that ttf2pfb can directly
produce PFA and PFB files.
. Overlapping outlines produce incorrect shapes: The overlapping areas
appear white instead of black.
. A more flexible encoding file format (maybe similar to ttf2tfm) which can
handle glyph names.
. [t1asm has been slightly patched to allow partial font downloading with
dvips.]
. Note that compiling ttf2pfb with `-O2' doesn't work, most probably due to
a compiler bug (we've tested with gcc 2.7.2.1 and 2.7.2.3).

397
contrib/ttf2pfb/Uni-T1.enc Normal file
View File

@@ -0,0 +1,397 @@
#
# This file is a hack to provide some mapping for standard (non-CJK)
# TrueType fonts. It is intended as an intermediate step towards a
# `correct' implementation as in ttf2tfm.
#
# Here, we have Unicode to LaTeX's T1 encoding. An example call would be
#
# ttf2pfb -m -enc Uni-T1.enc ...
#
# Glyph names which can't be represented in Unicode have the character code
# 0xfffe.
# 0x00
0x00:
0x60 # /grave
0xb4 # /acute
0x02:
0xc6 # /circumflex
0xdc # /tilde
0x00:
0xa8 # /dieresis
0x02:
0xdd # /hungarumlaut
0xda # /ring
0xc7 # /caron
0xd8 # /breve
0xc9 # /macron
0xd9 # /dotaccent
0x00:
0xb8 # /cedilla
0x02:
0xdb # /ogonek
0x20:
0x1a # /quotesinglbase
0x39 # /guilsinglleft
0x3a # /guilsinglright
# 0x10
0x1c # /quotedblleft
0x1d # /quotedblright
0x1e # /quotedblbase
0x00:
0xab # /guillemotleft
0xbb # /guillemotright
0x20:
0x13 # /endash
0x14 # /emdash
0xff:
0xfe # /compwordmark
0xfe # /perthousandzero
0x01:
0x31 # /dotlessi
0xff:
0xfe # /dotlessj
0xfe # /ff
0xf0:
0x01 # /fi
0x02 # /fl
0xff:
0xfe # /ffi
0xfe # /ffl
# 0x20
0xfe # /visualspace
0x00:
0x21 # /exclam
0x22 # /quotedbl
0x23 # /numbersign
0x24 # /dollar
0x25 # /percent
0x26 # /ampersand
0x20:
0x19 # /quoteright
0x00:
0x28 # /parenleft
0x29 # /parenright
0x2a # /asterisk
0x2b # /plus
0x2c # /comma
0x2d # /hyphen
0x2e # /period
0x2f # /slash
# 0x30
0x30 # /zero
0x31 # /one
0x32 # /two
0x33 # /three
0x34 # /four
0x35 # /five
0x36 # /six
0x37 # /seven
0x38 # /eight
0x39 # /nine
0x3a # /colon
0x3b # /semicolon
0x3c # /less
0x3d # /equal
0x3e # /greater
0x3f # /question
# 0x40
0x40 # /at
0x41 # /A
0x42 # /B
0x43 # /C
0x44 # /D
0x45 # /E
0x46 # /F
0x47 # /G
0x48 # /H
0x49 # /I
0x4a # /J
0x4b # /K
0x4c # /L
0x4d # /M
0x4e # /N
0x4f # /O
# 0x50
0x50 # /P
0x51 # /Q
0x52 # /R
0x53 # /S
0x54 # /T
0x55 # /U
0x56 # /V
0x57 # /W
0x58 # /X
0x59 # /Y
0x5a # /Z
0x5b # /bracketleft
0x5c # /backslash
0x5d # /bracketright
0x5e # /asciicircum
0x5f # /underscore
# 0x60
0x20:
0x18 # /quoteleft
0x00:
0x61 # /a
0x62 # /b
0x63 # /c
0x64 # /d
0x65 # /e
0x66 # /f
0x67 # /g
0x68 # /h
0x69 # /i
0x6a # /j
0x6b # /k
0x6c # /l
0x6d # /m
0x6e # /n
0x6f # /o
# 0x70
0x70 # /p
0x71 # /q
0x72 # /r
0x73 # /s
0x74 # /t
0x75 # /u
0x76 # /v
0x77 # /w
0x78 # /x
0x79 # /y
0x7a # /z
0x7b # /braceleft
0x7c # /bar
0x7d # /braceright
0x7e # /asciitilde
0x2d # /hyphen
# 0x80
0x01:
0x02 # /Abreve
0x04 # /Aogonek
0x06 # /Cacute
0x0c # /Ccaron
0x0e # /Dcaron
0x1a # /Ecaron
0x18 # /Eogonek
0x1e # /Gbreve
0x39 # /Lacute
0x3d # /Lcaron
0x41 # /Lslash
0x43 # /Nacute
0x47 # /Ncaron
0x4a # /Eng
0x50 # /Odblacute
0x54 # /Racute
# 0x90
0x58 # /Rcaron
0x5a # /Sacute
0x60 # /Scaron
0x5e # /Scedilla
0x64 # /Tcaron
0x62 # /Tcedilla
0x70 # /Udblacute
0x6e # /Uring
0x78 # /Ydieresis
0x79 # /Zacute
0x7d # /Zcaron
0x7b # /Zdot
0x32 # /IJ
0x30 # /Idot
0x11 # /dmacron
0x00:
0xa7 # /section
# 0xA0
0x01:
0x03 # /abreve
0x05 # /aogonek
0x07 # /cacute
0x0d # /ccaron
0x0f # /dcaron
0x1b # /ecaron
0x19 # /eogonek
0x1f # /gbreve
0x3a # /lacute
0x3e # /lcaron
0x42 # /lslash
0x44 # /nacute
0x48 # /ncaron
0x4b # /eng
0x51 # /odblacute
0x55 # /racute
# 0xB0
0x59 # /rcaron
0x5b # /sacute
0x61 # /scaron
0x5f # /scedilla
0x65 # /tcaron
0x63 # /tcedilla
0x71 # /udblacute
0x6f # /uring
0x00:
0xff # /ydieresis
0x01:
0x7a # /zacute
0x7e # /zcaron
0x7c # /zdot
0x33 # /ij
0x00:
0xa1 # /exclamdown
0xbf # /questiondown
0xa3 # /sterling
# 0xC0
0xc0 # /Agrave
0xc1 # /Aacute
0xc2 # /Acircumflex
0xc3 # /Atilde
0xc4 # /Adieresis
0xc5 # /Aring
0xc6 # /AE
0xc7 # /Ccedilla
0xc8 # /Egrave
0xc9 # /Eacute
0xca # /Ecircumflex
0xcb # /Edieresis
0xcc # /Igrave
0xcd # /Iacute
0xce # /Icircumflex
0xcf # /Idieresis
# 0xD0
0xd0 # /Eth
0xd1 # /Ntilde
0xd2 # /Ograve
0xd3 # /Oacute
0xd4 # /Ocircumflex
0xd5 # /Otilde
0xd6 # /Odieresis
0x01:
0x52 # /OE
0x00:
0xd8 # /Oslash
0xd9 # /Ugrave
0xda # /Uacute
0xdb # /Ucircumflex
0xdc # /Udieresis
0xdd # /Yacute
0xde # /Thorn
0xff:
0xfe # /Germandbls
# 0xE0
0x00:
0xe0 # /agrave
0xe1 # /aacute
0xe2 # /acircumflex
0xe3 # /atilde
0xe4 # /adieresis
0xe5 # /aring
0xe6 # /ae
0xe7 # /ccedilla
0xe8 # /egrave
0xe9 # /eacute
0xea # /ecircumflex
0xeb # /edieresis
0xec # /igrave
0xed # /iacute
0xee # /icircumflex
0xef # /idieresis
# 0xF0
0xf0 # /eth
0xf1 # /ntilde
0xf2 # /ograve
0xf3 # /oacute
0xf4 # /ocircumflex
0xf5 # /otilde
0xf6 # /odieresis
0x01:
0x53 # /oe
0x00:
0xf8 # /oslash
0xf9 # /ugrave
0xfa # /uacute
0xfb # /ucircumflex
0xfc # /udieresis
0xfd # /yacute
0xfe # /thorn
0xdf # /germandbls
#eof

1553
contrib/ttf2pfb/configure vendored Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,45 @@
dnl Process this file with autoconf to produce a configure script.
AC_INIT(../../lib/freetype.h)
AC_CANONICAL_SYSTEM
AC_PROG_CC
AC_PROG_CPP
CFLAGS="-g -O -DDEBUG"
OLDLIBS=$LIBS
LIBS="$LIBS -L../../lib/.libs"
CPPFLAGS="-I$srcdir/../../lib $CPPFLAGS"
AC_CHECK_LIB(ttf, TT_Init_FreeType, LIBS="$LIBS -lttf",[
AC_MSG_ERROR([Can't find ttf library! Compile FreeType first.])])
LIBS=$OLDLIBS
dnl get Compiler flags right.
if test "x$CC" = xgcc; then
XX_CFLAGS="-Wall -ansi -pedantic"
else
case "$host" in
alpha-dec-osf*)
XX_CFLAGS="-std1 -O2 -g3"
;;
*)
XX_CFLAGS=
;;
esac
fi
AC_SUBST(XX_CFLAGS)
AC_CHECK_PROG(RM, rm, rm)
AC_PROG_INSTALL
AC_STRUCT_TM
dnl Checks for header files.
AC_HEADER_STDC
AC_CHECK_HEADERS(unistd.h)
AC_OUTPUT(Makefile)
dnl end of configure.in

364
contrib/ttf2pfb/getafm Normal file
View File

@@ -0,0 +1,364 @@
#!/bin/sh
if [ $# -ne 1 ]; then
echo "usage: $0 font-name | gsnd -q - >font-name.afm" >&2
exit 1
fi
cat << EOF
%!
% produce .afm for $1
% (c) 1993 by Robert Joop <rj@rainbow.in-berlin.de>
% inspired by two other versions of this theme which are
% getafm 1.00 (c) AJCD
% and getafm.ps by an unknown author,
% modified by J. Daniel Smith <dsmith@mailhost.aa.cad.slb.com>
%
% modified by Joachim H. Kaiser <jhk@cmpnetmail.com>:
% - suggest a quiet gs run in usage
% - get font version info (from 'version', not 'Version')
% - add copyright field to output
% Metrics dictionary code added by AJCD, 7/6/93
/getafmdict 100 dict dup begin
/buf 256 string def
/buf2 16 string def
/prany % dict dictname printname -> dict
{
2 index 2 index cvn known
{
print % printname
( ) print
1 index exch cvn get =
}
{
(Comment /FontInfo contains no /) print
2 copy eq
{
= % printname
pop % dictname
}
{
exch
print % dictname
(, therefore no ) print
= % printname
}
ifelse
}
ifelse
}
bind def
/printfontname
{
(FontName)dup prany
}
bind def
/printfontinfo
{
dup /FontInfo known
{
dup /FontInfo get
(FullName)dup prany
(FamilyName)dup prany
(Weight)dup prany
(ItalicAngle)dup prany
(isFixedPitch)(IsFixedPitch) prany
(UnderlinePosition)dup prany
(UnderlineThickness)dup prany
(version)(Version) prany
(Notice)dup prany
(Copyright)dup prany
pop
}
{
(Comment Font lacks a /FontInfo!)=
}
ifelse
}
bind def
/prbbox % llx lly urx ury -> -
{
4 1 roll 3 1 roll exch % swap top 4 elements
4 { ( ) print buf cvs print } repeat
}
bind def
/getbbox % fontdict chardict character -> fontdict chardict llx lly urx ury
{
gsave
2 index setfont 0 0 moveto
false charpath flattenpath pathbbox
grestore
}
bind def
/printmiscinfo
{
dup /FontBBox known
{
(FontBBox) print
dup /FontBBox get aload pop prbbox ()=
}
{
(Comment missing required /FontBBox)=
quit
}
ifelse
2 copy exch get
dup /H known
1 index /x known and
1 index /d known and
1 index /p known and
dup /looksRoman exch def
{
(CapHeight ) print
(H) getbbox
ceiling cvi = pop pop pop
(XHeight ) print
(x) getbbox
ceiling cvi = pop pop pop
(Ascender ) print
(d) getbbox
ceiling cvi = pop pop pop
(Descender ) print
(p) getbbox
pop pop floor cvi = pop
}
{
(Comment font doesn't contain H, x, d and p; therefore no CapHeight, XHeight, Ascender and Descender)=
}
ifelse
pop
dup /Encoding get
[
[ (ISOLatin1Encoding) /ISOLatin1Encoding ]
[ (AdobeStandardEncoding) /StandardEncoding ]
]
{
aload pop dup where
{
exch get 2 index eq
{
(EncodingScheme ) print
buf cvs =
}
{
pop
}
ifelse
}
{
pop pop
}
ifelse
}
forall
pop
}
bind def
/printcharmetric
{
% chardictname fontdict charnamedict encoding charindex charname
4 index dup length dict dup begin exch
{
1 index /FID ne
2 index /UniqueID ne
and
{
1 index /Encoding eq { 256 array copy } if
def
}
{ pop pop }
ifelse
}
forall
end
dup /Encoding get 32 3 index put
/f2 exch definefont
setfont
(C ) print
1 index buf cvs print
( ; WX ) print
% Metrics entries are:
% 1 number: which is the character width
% an array of 2 numbers: which are the left sidebearing and width
% an array of 4 numbers: x & y left sidebearing, width and height
dup 5 index % /charname fontdict
dup /Metrics known {
/Metrics get exch 2 copy known {
get dup type /arraytype eq {
dup length 2 eq
{1 get} {2 get} ifelse
} if
round cvi buf cvs print
} {
pop pop ( ) stringwidth pop round cvi buf cvs print
} ifelse
} {
pop pop ( ) stringwidth pop round cvi buf cvs print
} ifelse
( ; N ) print
dup buf cvs print
( ; B) print
gsave
newpath 0 0 moveto
( ) true charpath flattenpath pathbbox
grestore
2 { ceiling cvi 4 1 roll } repeat
2 { floor cvi 4 1 roll } repeat
prbbox
looksRoman
{
[
[ /f [ /i /f /l ] ]
[ /ff [ /i /l ] ]
]
{
aload pop 1 index 3 index eq
{
{
1 index buf cvs
length
1 index buf2 cvs dup length
2 index add
buf
4 2 roll putinterval
buf 0
3 -1 roll getinterval
dup cvn
7 index
exch known
{
exch
( ; L ) print
buf2 cvs print
( ) print
print
}
{
pop pop
}
ifelse
}
forall
pop
}
{
pop pop
}
ifelse
}
forall
}
if
pop
( ;)=
}
bind def
/printcharmetrics
{
(StartCharMetrics ) print
2 copy exch get length 1 sub buf cvs =
256 dict dup begin
1 index /Encoding get
{ null def }
forall
end
% chardictname fontdict charnamedict
1 index /Encoding get
0 1 255
{
% encoding index
2 copy get
dup /.notdef eq { pop } { printcharmetric } ifelse
pop % index
} for
-1
3 index 5 index get
{
pop
dup /.notdef eq
{ pop }
{
% chardictname fontdict charnamedict encoding charindex charname
dup 4 index exch known
{ pop }
{ printcharmetric }
ifelse
}
ifelse
}
forall
% charnamedict encoding index
pop pop pop
(EndCharMetrics)=
}
bind def
/printfontmetrics
{
(StartFontMetrics 3.0)=
(Comment Produced by getafm 3.0 (which is by rj@rainbow.in-berlin.de))=
printfontname
printfontinfo
printmiscinfo
printcharmetrics
(EndFontMetrics)=
}
bind def
end def
/getafm
{
getafmdict begin
save exch
findfont 1000 scalefont
null
[ /CharDefs /CharData /CharProcs /CharStrings ]
{
2 index 1 index known { exch } if
pop
}
forall
dup null eq
{
(can't find dictionary with character data!)=
quit
}
if
exch % dictname fontdict
printfontmetrics
pop pop
restore
end
}
bind def
/$1 getafm
EOF

529
contrib/ttf2pfb/t1asm.c Normal file
View File

@@ -0,0 +1,529 @@
/* t1asm
**
** This program `assembles' Adobe Type-1 font programs in pseudo-PostScript
** form into either PFB or PFA format. The human readable/editable input is
** charstring- and eexec-encrypted as specified in the `Adobe Type 1 Font
** Format' version 1.1 (the `black book'). There is a companion program,
** t1disasm, which `disassembles' PFB and PFA files into a pseudo-PostScript
** file.
**
** Copyright (c) 1992 by I. Lee Hetherington, all rights reserved.
**
** Permission is hereby granted to use, modify, and distribute this program
** for any purpose provided this copyright notice and the one below remain
** intact.
**
** author: I. Lee Hetherington (ilh@lcs.mit.edu)
*/
#ifndef lint
static char sccsid[] =
"@(#) t1asm.c 1.2 10:09:46 5/22/92";
static char copyright[] =
"@(#) Copyright (c) 1992 by I. Lee Hetherington, all rights reserved.";
#endif
/* Note: this is ANSI C. */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#ifdef MSDOS
#define WB "wb"
#else
#define WB "w"
#endif
#define BANNER "This is t1asm 1.2.\n"
#define LINESIZE 256
#define MAXBLOCKLEN ((1<<17)-6)
#define MINBLOCKLEN ((1<<8)-6)
#define MARKER 128
#define ASCII 1
#define BINARY 2
#define DONE 3
typedef unsigned char byte;
static FILE *ifp = stdin;
static FILE *ofp = stdout;
/* flags */
static int pfb = 0;
static int active = 0;
static int start_charstring = 0;
static int in_eexec = 0;
static char line[LINESIZE + 1];
/* lenIV and charstring start command */
static int lenIV = 4;
static char cs_start[10];
/* for charstring buffering */
static byte charstring_buf[65535];
static byte *charstring_bp;
/* for PFB block buffering */
static byte blockbuf[MAXBLOCKLEN];
static int blocklen = MAXBLOCKLEN;
static int blockpos = -1;
static int blocktyp = ASCII;
/* decryption stuff */
static unsigned short er, cr;
static unsigned short c1 = 52845, c2 = 22719;
/* table of charstring commands */
static struct command {
char *name;
int one, two;
} command_table[] = {
{ "callothersubr", 12, 16 },
{ "callsubr", 10, -1 },
{ "closepath", 9, -1 },
{ "div", 12, 12 },
{ "dotsection", 12, 0 },
{ "endchar", 14, -1 },
{ "escape", 12, -1 },
{ "hlineto", 6, -1 },
{ "hmoveto", 22, -1 },
{ "hsbw", 13, -1 },
{ "hstem", 1, -1 },
{ "hstem3", 12, 2 },
{ "hvcurveto", 31, -1 },
{ "pop", 12, 17 },
{ "return", 11, -1 },
{ "rlineto", 5, -1 },
{ "rmoveto", 21, -1 },
{ "rrcurveto", 8, -1 },
{ "sbw", 12, 7 },
{ "seac", 12, 6 },
{ "setcurrentpoint", 12, 33 },
{ "vhcurveto", 30, -1 },
{ "vlineto", 7, -1 },
{ "vmoveto", 4, -1 },
{ "vstem", 3, -1 },
{ "vstem3", 12, 1 },
}; /* alphabetical */
/* Two separate decryption functions because eexec and charstring decryption
must proceed in parallel. */
static byte eencrypt(byte plain)
{
byte cipher;
cipher = (plain ^ (er >> 8));
er = (cipher + er) * c1 + c2;
return cipher;
}
static byte cencrypt(byte plain)
{
byte cipher;
cipher = (plain ^ (cr >> 8));
cr = (cipher + cr) * c1 + c2;
return cipher;
}
/* This function flushes a buffered PFB block. */
static void output_block()
{
int i;
/* output four-byte block length */
fputc(blockpos & 0xff, ofp);
fputc((blockpos >> 8) & 0xff, ofp);
fputc((blockpos >> 16) & 0xff, ofp);
fputc((blockpos >> 24) & 0xff, ofp);
/* output block data */
for (i = 0; i < blockpos; i++)
fputc(blockbuf[i], ofp);
/* mark block buffer empty and uninitialized */
blockpos = -1;
}
/* This function outputs a single byte. If output is in PFB format then output
is buffered through blockbuf[]. If output is in PFA format, then output
will be hexadecimal if in_eexec is set, ASCII otherwise. */
static void output_byte(byte b)
{
static char *hexchar = "0123456789ABCDEF";
static int hexcol = 0;
if (pfb) {
/* PFB */
if (blockpos < 0) {
fputc(MARKER, ofp);
fputc(blocktyp, ofp);
blockpos = 0;
}
blockbuf[blockpos++] = b;
if (blockpos == blocklen)
output_block();
} else {
/* PFA */
if (in_eexec) {
/* trim hexadecimal lines to 64 columns */
if (hexcol >= 64) {
fputc('\n', ofp);
hexcol = 0;
}
fputc(hexchar[(b >> 4) & 0xf], ofp);
fputc(hexchar[b & 0xf], ofp);
hexcol += 2;
} else {
fputc(b, ofp);
}
}
}
/* This function outputs a byte through possible eexec encryption. */
static void eexec_byte(byte b)
{
if (in_eexec)
output_byte(eencrypt(b));
else
output_byte(b);
}
/* This function outputs a null-terminated string through possible eexec
encryption. */
static void eexec_string(char *string)
{
while (*string)
eexec_byte((byte) *string++);
}
/* This function gets ready for the eexec-encrypted data. If output is in
PFB format then flush current ASCII block and get ready for binary block.
We start encryption with four random (zero) bytes. */
static void eexec_start()
{
eexec_string(line);
if (pfb) {
output_block();
blocktyp = BINARY;
}
in_eexec = 1;
er = 55665;
eexec_byte(0);
eexec_byte(0);
eexec_byte(0);
eexec_byte(0);
}
/* This function wraps-up the eexec-encrypted data and writes ASCII trailer.
If output is in PFB format then this entails flushing binary block and
starting an ASCII block. */
static void eexec_end()
{
int i, j;
if (pfb) {
output_block();
blocktyp = ASCII;
} else {
fputc('\n', ofp);
}
in_eexec = 0;
for (i = 0; i < 7; i++) {
for (j = 0; j < 64; j++)
eexec_byte('0');
eexec_byte('\n');
}
eexec_string("cleartomark\n");
if (pfb) {
output_block();
fputc(MARKER, ofp);
fputc(DONE, ofp);
}
}
/* This function returns an input line of characters. A line is terminated by
length (including terminating null) greater than LINESIZE, a newline \n, or
when active (looking for charstrings) by '{'. When terminated by a newline
the newline is put into line[]. When terminated by '{', the '{' is not put
into line[], and the flag start_charstring is set to 1. */
static void getline()
{
int c;
char *p = line;
int comment = 0;
start_charstring = 0;
while (p < line + LINESIZE) {
c = fgetc(ifp);
if (c == EOF)
break;
if (c == '%')
comment = 1;
if (active && !comment && c == '{') {
start_charstring = 1;
break;
}
*p++ = (char) c;
if (c == '\n')
break;
}
*p = '\0';
}
/* This function is used by the binary search, bsearch(), for command names in
the command table. */
static int command_compare(const void *key, const void *item)
{
return strcmp((char *) key, ((struct command *) item)->name);
}
/* This function returns 1 if the string is an integer and 0 otherwise. */
static int is_integer(char *string)
{
if (isdigit(string[0]) || string[0] == '-' || string[0] == '+') {
while (*++string && isdigit(*string))
; /* deliberately empty */
if (!*string)
return 1;
}
return 0;
}
/* This function initializes charstring encryption. Note that this is called
at the beginning of every charstring. */
static void charstring_start()
{
int i;
charstring_bp = charstring_buf;
cr = 4330;
for (i = 0; i < lenIV; i++)
*charstring_bp++ = cencrypt((byte) 0);
}
/* This function encrypts and buffers a single byte of charstring data. */
static void charstring_byte(v)
int v;
{
byte b = ((unsigned int)v) & 0xff;
if (charstring_bp - charstring_buf > sizeof(charstring_buf)) {
fprintf(stderr, "error: charstring_buf full (%d bytes)\n",
sizeof(charstring_buf));
exit(1);
}
*charstring_bp++ = cencrypt(b);
}
/* This function outputs buffered, encrypted charstring data through possible
eexec encryption. */
static void charstring_end()
{
byte *bp;
sprintf(line, "%d %s ", charstring_bp - charstring_buf, cs_start);
eexec_string(line);
for (bp = charstring_buf; bp < charstring_bp; bp++)
eexec_byte(*bp);
}
/* This function generates the charstring representation of an integer. */
static void charstring_int(int num)
{
int x;
if (num >= -107 && num <= 107) {
charstring_byte(num + 139);
} else if (num >= 108 && num <= 1131) {
x = num - 108;
charstring_byte(x / 256 + 247);
charstring_byte(x % 256);
} else if (num >= -1131 && num <= -108) {
x = abs(num) - 108;
charstring_byte(x / 256 + 251);
charstring_byte(x % 256);
} else if (num >= (-2147483647-1) && num <= 2147483647) {
charstring_byte(255);
charstring_byte(num >> 24);
charstring_byte(num >> 16);
charstring_byte(num >> 8);
charstring_byte(num);
} else {
fprintf(stderr,
"error: cannot format the integer %d, too large\n", num);
exit(1);
}
}
/* This function parses an entire charstring into integers and commands,
outputting bytes through the charstring buffer. */
static void parse_charstring()
{
struct command *cp;
charstring_start();
while (fscanf(ifp, "%s", line) == 1) {
if (line[0] == '%') {
/* eat comment to end of line */
while (fgetc(ifp) != '\n' && !feof(ifp))
; /* deliberately empty */
continue;
}
if (line[0] == '}')
break;
if (is_integer(line)) {
charstring_int(atoi(line));
} else {
cp = (struct command *)
bsearch((void *) line, (void *) command_table,
sizeof(command_table) / sizeof(struct command),
sizeof(struct command),
command_compare);
if (cp) {
charstring_byte(cp->one);
if (cp->two >= 0)
charstring_byte(cp->two);
} else {
fprintf(stderr, "error: cannot use `%s' in charstring\n", cp->name);
exit(1);
}
}
}
charstring_end();
}
static void usage()
{
fprintf(stderr,
"usage: t1asm [-b] [-l block-length] [input [output]]\n");
fprintf(stderr,
"\n-b means output in PFB format, otherwise PFA format.\n");
fprintf(stderr,
"The block length applies to the length of blocks in the\n");
fprintf(stderr,
"PFB output file; the default is to use the largest possible.\n");
exit(1);
}
int main(int argc, char **argv)
{
char *p, *q, *r;
int c;
extern char *optarg;
extern int optind;
extern int getopt(int argc, char **argv, char *optstring);
fprintf(stderr, "%s", BANNER);
/* interpret command line arguments using getopt */
while ((c = getopt(argc, argv, "bl:")) != -1)
switch (c) {
case 'b':
pfb = 1;
break;
case 'l':
blocklen = atoi(optarg);
if (blocklen < MINBLOCKLEN) {
blocklen = MINBLOCKLEN;
fprintf(stderr,
"warning: using minimum block length of %d\n",
blocklen);
} else if (blocklen > MAXBLOCKLEN) {
blocklen = MAXBLOCKLEN;
fprintf(stderr,
"warning: using maximum block length of %d\n",
blocklen);
}
break;
default:
usage();
break;
}
if (argc - optind > 2)
usage();
/* possibly open input & output files */
if (argc - optind >= 1) {
ifp = fopen(argv[optind], "r");
if (!ifp) {
fprintf(stderr, "error: cannot open %s for reading\n", argv[1]);
exit(1);
}
}
if (argc - optind >= 2) {
ofp = fopen(argv[optind + 1], WB);
if (!ofp) {
fprintf(stderr, "error: cannot open %s for writing\n", argv[2]);
exit(1);
}
}
/* Finally, we loop until no more input. Some special things to look for
are the `currentfile eexec' line, the beginning of the `/Subrs'
definition, the definition of `/lenIV', and the definition of the
charstring start command which has `...string currentfile...' in it. */
while (!feof(ifp) && !ferror(ifp)) {
getline();
if (strcmp(line, "currentfile eexec\n") == 0) {
eexec_start();
continue;
} else if (strstr(line, "/Subrs") && isspace(line[6])) {
active = 1;
} else if ((p = strstr(line, "/lenIV"))) {
sscanf(p, "%*s %d", &lenIV);
} else if ((p = strstr(line, "string currentfile"))) {
/* locate the name of the charstring start command */
*p = '\0'; /* damage line[] */
q = strrchr(line, '/');
if (q) {
r = cs_start;
++q;
while (!isspace(*q) && *q != '{')
*r++ = *q++;
*r = '\0';
}
*p = 's'; /* repair line[] */
}
/* output line data */
eexec_string(line);
if (start_charstring) {
if (!cs_start[0]) {
fprintf(stderr, "error: couldn't find charstring start command\n");
exit(1);
}
parse_charstring();
}
}
eexec_end();
fclose(ifp);
fclose(ofp);
return 0;
}

1725
contrib/ttf2pfb/ttf2pfb.c Normal file

File diff suppressed because it is too large Load Diff