home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / x / volume10 / bdf2ps / part01 next >
Encoding:
Internet Message Format  |  1991-01-27  |  25.2 KB

  1. Path: uunet!samsung!zaphod.mps.ohio-state.edu!usc!apple!netcom!amdcad!sun!exodus!NMSU.Edu!mleisher
  2. From: mleisher@NMSU.Edu
  3. Newsgroups: comp.sources.x
  4. Subject: REPOST: v10i076: BDF to Postscript program, Part01/01
  5. Message-ID: <6686@exodus.Eng.Sun.COM>
  6. Date: 27 Jan 91 01:55:35 GMT
  7. Sender: news@exodus.Eng.Sun.COM
  8. Lines: 823
  9. Approved: argv@sun.com
  10.  
  11. Submitted-by: mleisher@NMSU.Edu
  12. Posting-number: Volume 10, Issue 76
  13. Archive-name: bdf2ps/part01
  14.  
  15. This program makes a Postscript font out from a BDF font.  It will not
  16. work with large, two byte BDF fonts such as Chinese or Japanese BDF
  17. fonts.  It also ignores any entries that have an ENCODING value less
  18. than zero.
  19.  
  20. You might want to tune some of the Postscript parameters by hand to
  21. get the output closer to what you want.  There is a short description
  22. of this in the man page.
  23.  
  24. This program depends heavily on the SWIDTH entry for each character.
  25. Please see the "Bitmaps Distribution Format 2.1" document for details
  26. on SWIDTH.  You can also send me email for a copy of this document.
  27.  
  28. Please send bug reports, enhancements, etc. to:
  29. Internet: mleisher@nmsu.edu
  30. Bitnet  : mleisher@nmsu.bitnet
  31.  
  32. #!/bin/sh
  33. # This is bdftops-1.0/part, a shell archive (produced by shar 3.49)
  34. # To extract the files from this archive, save it to a file, remove
  35. # everything above the "!/bin/sh" line above, and type "sh file_name".
  36. #
  37. # made 11/19/1990 17:54 UTC by mleisher@nmsu.edu
  38. # Source directory /tmp_mnt/home/nikita1/X11R4/contrib/fonts/bdftops-1.0
  39. #
  40. # existing files will NOT be overwritten unless -c is specified
  41. #
  42. # This shar contains:
  43. # length  mode       name
  44. # ------ ---------- ------------------------------------------
  45. #    337 -rw-rw-r-- Imakefile
  46. #   9117 -rw-rw-r-- Makefile
  47. #   1587 -rw-rw-r-- README
  48. #   7704 -rw-rw-r-- bdftops.c
  49. #   2082 -rw-rw-r-- bdftops.man
  50. #     22 -rw-rw-r-- patchlevel.h
  51. #
  52. # ============= Imakefile ==============
  53. if test -f 'Imakefile' -a X"$1" != X"-c"; then
  54.     echo 'x - skipping Imakefile (File already exists)'
  55. else
  56. echo 'x - extracting Imakefile (Text)'
  57. sed 's/^X//' << 'SHAR_EOF' > 'Imakefile' &&
  58. #
  59. # Make file for the BDF font to Postscript font converter
  60. #
  61. # If TOP is incorrectly defined, uncomment and change the following
  62. # line to point at the X11 distribution source.
  63. X
  64. #        TOP = /usr/local/src/X11/mit
  65. X
  66. X      SRCS  = bdftops.c
  67. X      OBJS  = bdftops.o
  68. X   INCLUDES = -I.
  69. X   PROGRAM  = bdftops
  70. X
  71. ComplexProgramTarget(bdftops)
  72. SHAR_EOF
  73. chmod 0664 Imakefile ||
  74. echo 'restore of Imakefile failed'
  75. Wc_c="`wc -c < 'Imakefile'`"
  76. test 337 -eq "$Wc_c" ||
  77.     echo 'Imakefile: original size 337, current size' "$Wc_c"
  78. fi
  79. # ============= Makefile ==============
  80. if test -f 'Makefile' -a X"$1" != X"-c"; then
  81.     echo 'x - skipping Makefile (File already exists)'
  82. else
  83. echo 'x - extracting Makefile (Text)'
  84. sed 's/^X//' << 'SHAR_EOF' > 'Makefile' &&
  85. # Makefile generated by imake - do not edit!
  86. # $XConsortium: imake.c,v 1.51 89/12/12 12:37:30 jim Exp $
  87. #
  88. # The cpp used on this machine replaces all newlines and multiple tabs and
  89. # spaces in a macro expansion with a single space.  Imake tries to compensate
  90. # for this, but is not always successful.
  91. #
  92. X
  93. ###########################################################################
  94. # Makefile generated from "Imake.tmpl" and </tmp/IIf.a09492>
  95. # $XConsortium: Imake.tmpl,v 1.77 89/12/18 17:01:37 jim Exp $
  96. #
  97. # Platform-specific parameters may be set in the appropriate .cf
  98. # configuration files.  Site-wide parameters may be set in the file
  99. # site.def.  Full rebuilds are recommended if any parameters are changed.
  100. #
  101. # If your C preprocessor doesn't define any unique symbols, you'll need
  102. # to set BOOTSTRAPCFLAGS when rebuilding imake (usually when doing
  103. # "make Makefile", "make Makefiles", or "make World").
  104. #
  105. # If you absolutely can't get imake to work, you'll need to set the
  106. # variables at the top of each Makefile as well as the dependencies at the
  107. # bottom (makedepend will do this automatically).
  108. #
  109. X
  110. ###########################################################################
  111. # platform-specific configuration parameters - edit sun.cf to change
  112. X
  113. # platform:  $XConsortium: sun.cf,v 1.38 89/12/23 16:10:10 jim Exp $
  114. # operating system:  SunOS 4.1
  115. X
  116. ###########################################################################
  117. # site-specific configuration parameters - edit site.def to change
  118. X
  119. # site:  $XConsortium: site.def,v 1.21 89/12/06 11:46:50 jim Exp $
  120. X
  121. X            SHELL = /bin/sh
  122. X
  123. X              TOP = /usr/local/src/X11/mit
  124. X      CURRENT_DIR = .
  125. X
  126. X               AR = ar clq
  127. X  BOOTSTRAPCFLAGS =
  128. X               CC = cc
  129. X
  130. X         COMPRESS = compress
  131. X              CPP = /lib/cpp $(STD_CPP_DEFINES)
  132. X    PREPROCESSCMD = cc -E $(STD_CPP_DEFINES)
  133. X          INSTALL = install
  134. X               LD = ld
  135. X             LINT = lint
  136. X      LINTLIBFLAG = -C
  137. X         LINTOPTS = -axz
  138. X               LN = ln -s
  139. X             MAKE = make
  140. X               MV = mv
  141. X               CP = cp
  142. X           RANLIB = ranlib
  143. X  RANLIBINSTFLAGS =
  144. X               RM = rm -f
  145. X     STD_INCLUDES =
  146. X  STD_CPP_DEFINES =
  147. X      STD_DEFINES =
  148. X EXTRA_LOAD_FLAGS =
  149. X  EXTRA_LIBRARIES =
  150. X             TAGS = ctags
  151. X
  152. X    SHAREDCODEDEF = -DSHAREDCODE
  153. X         SHLIBDEF = -DSUNSHLIB
  154. X
  155. X    PROTO_DEFINES =
  156. X
  157. X     INSTPGMFLAGS =
  158. X
  159. X     INSTBINFLAGS = -m 0755
  160. X     INSTUIDFLAGS = -m 4755
  161. X     INSTLIBFLAGS = -m 0664
  162. X     INSTINCFLAGS = -m 0444
  163. X     INSTMANFLAGS = -m 0444
  164. X     INSTDATFLAGS = -m 0444
  165. X    INSTKMEMFLAGS = -m 4755
  166. X
  167. X          DESTDIR =
  168. X
  169. X     TOP_INCLUDES = -I$(INCROOT)
  170. X
  171. X      CDEBUGFLAGS = -O
  172. X        CCOPTIONS =
  173. X      COMPATFLAGS = -DXAW_BC
  174. X
  175. X      ALLINCLUDES = $(STD_INCLUDES) $(TOP_INCLUDES) $(INCLUDES) $(EXTRA_INCLUDES)
  176. X       ALLDEFINES = $(ALLINCLUDES) $(STD_DEFINES) $(PROTO_DEFINES) $(DEFINES) $(COMPATFLAGS)
  177. X           CFLAGS = $(CDEBUGFLAGS) $(CCOPTIONS) $(ALLDEFINES)
  178. X        LINTFLAGS = $(LINTOPTS) -DLINT $(ALLDEFINES)
  179. X           LDLIBS = $(SYS_LIBRARIES) $(EXTRA_LIBRARIES)
  180. X        LDOPTIONS = $(CDEBUGFLAGS) $(CCOPTIONS)
  181. X   LDCOMBINEFLAGS = -X -r
  182. X
  183. X        MACROFILE = sun.cf
  184. X           RM_CMD = $(RM) *.CKP *.ln *.BAK *.bak *.o core errs ,* *~ *.a .emacs_* tags TAGS make.log MakeOut
  185. X
  186. X    IMAKE_DEFINES =
  187. X
  188. X         IRULESRC = $(CONFIGDIR)
  189. X        IMAKE_CMD = $(IMAKE) -DUseInstalled -I$(IRULESRC) $(IMAKE_DEFINES)
  190. X
  191. X     ICONFIGFILES = $(IRULESRC)/Imake.tmpl $(IRULESRC)/Imake.rules \
  192. X            $(IRULESRC)/Project.tmpl $(IRULESRC)/site.def \
  193. X            $(IRULESRC)/$(MACROFILE) $(EXTRA_ICONFIGFILES)
  194. X
  195. ###########################################################################
  196. # X Window System Build Parameters
  197. # $XConsortium: Project.tmpl,v 1.63 89/12/18 16:46:44 jim Exp $
  198. X
  199. ###########################################################################
  200. # X Window System make variables; this need to be coordinated with rules
  201. # $XConsortium: Project.tmpl,v 1.63 89/12/18 16:46:44 jim Exp $
  202. X
  203. X          PATHSEP = /
  204. X        USRLIBDIR = /usr/local/lib/X11R4
  205. X           BINDIR = /usr/local/bin/X11R4
  206. X          INCROOT = /usr/include/X11
  207. X     BUILDINCROOT = $(TOP)
  208. X      BUILDINCDIR = $(BUILDINCROOT)/X11
  209. X      BUILDINCTOP = ..
  210. X           INCDIR = $(INCROOT)/X11
  211. X           ADMDIR = $(DESTDIR)/usr/adm
  212. X           LIBDIR = /usr/local/lib/X11R4
  213. X        CONFIGDIR = $(LIBDIR)/config
  214. X       LINTLIBDIR = $(USRLIBDIR)/lint
  215. X
  216. X          FONTDIR = /usr/local/lib/X11R4/fonts
  217. X         XINITDIR = $(LIBDIR)/xinit
  218. X           XDMDIR = $(LIBDIR)/xdm
  219. X           AWMDIR = $(LIBDIR)/awm
  220. X           TWMDIR = $(LIBDIR)/twm
  221. X           GWMDIR = $(LIBDIR)/gwm
  222. X          MANPATH = $(DESTDIR)/usr/local/man
  223. X    MANSOURCEPATH = $(MANPATH)/man
  224. X           MANDIR = /usr/local/man/man1
  225. X        LIBMANDIR = $(MANSOURCEPATH)3X
  226. X      XAPPLOADDIR = $(LIBDIR)/app-defaults
  227. X
  228. X        SOXLIBREV = 4.2
  229. X          SOXTREV = 4.0
  230. X         SOXAWREV = 4.0
  231. X        SOOLDXREV = 4.0
  232. X         SOXMUREV = 4.0
  233. X        SOXEXTREV = 4.0
  234. X
  235. X       FONTCFLAGS = -t
  236. X
  237. X     INSTAPPFLAGS = $(INSTDATFLAGS)
  238. X
  239. X            IMAKE = imake
  240. X           DEPEND = makedepend
  241. X              RGB = rgb
  242. X            FONTC = bdftosnf
  243. X        MKFONTDIR = mkfontdir
  244. X        MKDIRHIER = /bin/sh $(BINDIR)/mkdirhier.sh
  245. X
  246. X        CONFIGSRC = $(TOP)/config
  247. X        CLIENTSRC = $(TOP)/clients
  248. X          DEMOSRC = $(TOP)/demos
  249. X           LIBSRC = $(TOP)/lib
  250. X          FONTSRC = $(TOP)/fonts
  251. X       INCLUDESRC = $(TOP)/X11
  252. X        SERVERSRC = $(TOP)/server
  253. X          UTILSRC = $(TOP)/util
  254. X        SCRIPTSRC = $(UTILSRC)/scripts
  255. X       EXAMPLESRC = $(TOP)/examples
  256. X       CONTRIBSRC = $(TOP)/../contrib
  257. X           DOCSRC = $(TOP)/doc
  258. X           RGBSRC = $(TOP)/rgb
  259. X        DEPENDSRC = $(UTILSRC)/makedepend
  260. X         IMAKESRC = $(CONFIGSRC)
  261. X         XAUTHSRC = $(LIBSRC)/Xau
  262. X          XLIBSRC = $(LIBSRC)/X
  263. X           XMUSRC = $(LIBSRC)/Xmu
  264. X       TOOLKITSRC = $(LIBSRC)/Xt
  265. X       AWIDGETSRC = $(LIBSRC)/Xaw
  266. X       OLDXLIBSRC = $(LIBSRC)/oldX
  267. X      XDMCPLIBSRC = $(LIBSRC)/Xdmcp
  268. X      BDFTOSNFSRC = $(FONTSRC)/bdftosnf
  269. X     MKFONTDIRSRC = $(FONTSRC)/mkfontdir
  270. X     EXTENSIONSRC = $(TOP)/extensions
  271. X
  272. X  DEPEXTENSIONLIB = $(USRLIBDIR)/libXext.a
  273. X     EXTENSIONLIB =  -lXext
  274. X
  275. X          DEPXLIB = $(DEPEXTENSIONLIB)
  276. X             XLIB = $(EXTENSIONLIB) -lX11
  277. X
  278. X      DEPXAUTHLIB = $(USRLIBDIR)/libXau.a
  279. X         XAUTHLIB =  -lXau
  280. X
  281. X        DEPXMULIB =
  282. X           XMULIB = -lXmu
  283. X
  284. X       DEPOLDXLIB =
  285. X          OLDXLIB = -loldX
  286. X
  287. X      DEPXTOOLLIB =
  288. X         XTOOLLIB = -lXt
  289. X
  290. X        DEPXAWLIB =
  291. X           XAWLIB = -lXaw
  292. X
  293. X LINTEXTENSIONLIB = $(USRLIBDIR)/llib-lXext.ln
  294. X         LINTXLIB = $(USRLIBDIR)/llib-lX11.ln
  295. X          LINTXMU = $(USRLIBDIR)/llib-lXmu.ln
  296. X        LINTXTOOL = $(USRLIBDIR)/llib-lXt.ln
  297. X          LINTXAW = $(USRLIBDIR)/llib-lXaw.ln
  298. X
  299. X          DEPLIBS = $(DEPXAWLIB) $(DEPXMULIB) $(DEPXTOOLLIB) $(DEPXLIB)
  300. X
  301. X         DEPLIBS1 = $(DEPLIBS)
  302. X         DEPLIBS2 = $(DEPLIBS)
  303. X         DEPLIBS3 = $(DEPLIBS)
  304. X
  305. ###########################################################################
  306. # Imake rules for building libraries, programs, scripts, and data files
  307. # rules:  $XConsortium: Imake.rules,v 1.67 89/12/18 17:14:15 jim Exp $
  308. X
  309. ###########################################################################
  310. # start of Imakefile
  311. X
  312. #
  313. # Make file for the BDF font to Postscript font converter
  314. #
  315. # If TOP is incorrectly defined, uncomment and change the following
  316. # line to point at the X11 distribution source.
  317. X
  318. #        TOP = /usr/local/src/X11/mit
  319. X
  320. X      SRCS  = bdftops.c
  321. X      OBJS  = bdftops.o
  322. X   INCLUDES = -I.
  323. X   PROGRAM  = bdftops
  324. X
  325. X PROGRAM = bdftops
  326. X
  327. all:: bdftops
  328. X
  329. bdftops: $(OBJS)
  330. X    $(RM) $@
  331. X    $(CC) -o $@ $(OBJS) $(LDOPTIONS) $(LOCAL_LIBRARIES) $(LDLIBS) $(EXTRA_LOAD_FLAGS)
  332. X
  333. saber_bdftops:
  334. X    #load $(ALLDEFINES) $(SRCS) $(LOCAL_LIBRARIES) $(SYS_LIBRARIES) $(EXTRA_LIBRARIES)
  335. X
  336. osaber_bdftops:
  337. X    #load $(ALLDEFINES) $(OBJS) $(LOCAL_LIBRARIES) $(SYS_LIBRARIES) $(EXTRA_LIBRARIES)
  338. X
  339. install:: bdftops
  340. X    $(INSTALL) -c $(INSTPGMFLAGS)   bdftops $(BINDIR)
  341. X
  342. install.man:: bdftops.man
  343. X    $(INSTALL) -c $(INSTMANFLAGS) bdftops.man $(MANDIR)/bdftops.1
  344. X
  345. depend::
  346. X    $(DEPEND) -s "# DO NOT DELETE" -- $(ALLDEFINES) -- $(SRCS)
  347. X
  348. lint:
  349. X    $(LINT) $(LINTFLAGS) $(SRCS) $(LINTLIBS)
  350. lint1:
  351. X    $(LINT) $(LINTFLAGS) $(FILE) $(LINTLIBS)
  352. X
  353. clean::
  354. X    $(RM) $(PROGRAM)
  355. X
  356. ###########################################################################
  357. # common rules for all Makefiles - do not edit
  358. X
  359. emptyrule::
  360. X
  361. clean::
  362. X    $(RM_CMD) \#*
  363. X
  364. Makefile::
  365. X    -@if [ -f Makefile ]; then \
  366. X    echo "    $(RM) Makefile.bak; $(MV) Makefile Makefile.bak"; \
  367. X    $(RM) Makefile.bak; $(MV) Makefile Makefile.bak; \
  368. X    else exit 0; fi
  369. X    $(IMAKE_CMD) -DTOPDIR=$(TOP) -DCURDIR=$(CURRENT_DIR)
  370. X
  371. tags::
  372. X    $(TAGS) -w *.[ch]
  373. X    $(TAGS) -xw *.[ch] > TAGS
  374. X
  375. saber:
  376. X    #load $(ALLDEFINES) $(SRCS)
  377. X
  378. osaber:
  379. X    #load $(ALLDEFINES) $(OBJS)
  380. X
  381. ###########################################################################
  382. # empty rules for directories that do not have SUBDIRS - do not edit
  383. X
  384. install::
  385. X    @echo "install in $(CURRENT_DIR) done"
  386. X
  387. install.man::
  388. X    @echo "install.man in $(CURRENT_DIR) done"
  389. X
  390. Makefiles::
  391. X
  392. includes::
  393. X
  394. ###########################################################################
  395. # dependencies generated by makedepend
  396. X
  397. SHAR_EOF
  398. chmod 0664 Makefile ||
  399. echo 'restore of Makefile failed'
  400. Wc_c="`wc -c < 'Makefile'`"
  401. test 9117 -eq "$Wc_c" ||
  402.     echo 'Makefile: original size 9117, current size' "$Wc_c"
  403. fi
  404. # ============= README ==============
  405. if test -f 'README' -a X"$1" != X"-c"; then
  406.     echo 'x - skipping README (File already exists)'
  407. else
  408. echo 'x - extracting README (Text)'
  409. sed 's/^X//' << 'SHAR_EOF' > 'README' &&
  410. --------------------------------------------------------------------
  411. Copyright (C) 1990 Mark Leisher.
  412. X
  413. Author: Mark Leisher (mleisher@nmsu.edu)
  414. X
  415. This program is free software; you can redistribute it and/or modify
  416. it under the terms of the GNU General Public License as published by
  417. the Free Software Foundation; either version 1, or (at your option)
  418. any later version.
  419. X
  420. This program is distributed in the hope that it will be useful,
  421. but WITHOUT ANY WARRANTY; without even the implied warranty of
  422. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  423. GNU General Public License for more details.
  424. X
  425. A copy of the GNU General Public License can be obtained from this
  426. program's author (send electronic mail to mleisher@nmsu.edu) or from
  427. the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA
  428. 02139, USA.
  429. --------------------------------------------------------------------
  430. X
  431. This program makes a Postscript font out from a BDF font.  It will not
  432. work with large, two byte BDF fonts such as Chinese or Japanese BDF
  433. fonts.  It also ignores any entries that have an ENCODING value less
  434. than zero.
  435. X
  436. You might want to tune some of the Postscript parameters by hand to
  437. get the output closer to what you want.  There is a short description
  438. of this in the man page.
  439. X
  440. This program depends heavily on the SWIDTH entry for each character.
  441. Please see the "Bitmaps Distribution Format 2.1" document for details
  442. on SWIDTH.  You can also send me email for a copy of this document.
  443. X
  444. Please send bug reports, enhancements, etc. to:
  445. Internet: mleisher@nmsu.edu
  446. Bitnet  : mleisher@nmsu.bitnet
  447. SHAR_EOF
  448. chmod 0664 README ||
  449. echo 'restore of README failed'
  450. Wc_c="`wc -c < 'README'`"
  451. test 1587 -eq "$Wc_c" ||
  452.     echo 'README: original size 1587, current size' "$Wc_c"
  453. fi
  454. # ============= bdftops.c ==============
  455. if test -f 'bdftops.c' -a X"$1" != X"-c"; then
  456.     echo 'x - skipping bdftops.c (File already exists)'
  457. else
  458. echo 'x - extracting bdftops.c (Text)'
  459. sed 's/^X//' << 'SHAR_EOF' > 'bdftops.c' &&
  460. /*
  461. X *
  462. X * File:         bdftops.c
  463. X * Description:  Make a Postscript font from a BDF font
  464. X * Author:       Mark Leisher
  465. X * Created:      Mon Nov 19 10:27:38 1990
  466. X * Modified:     Mon Nov 19 10:27:42 1990
  467. X *
  468. X */
  469. X
  470. /*
  471. X * Copyright (C) 1990 Mark Leisher.
  472. X *
  473. X * Author: Mark Leisher (mleisher@nmsu.edu)
  474. X *
  475. X * This program is free software; you can redistribute it and/or modify
  476. X * it under the terms of the GNU General Public License as published by
  477. X * the Free Software Foundation; either version 1, or (at your option)
  478. X * any later version.
  479. X *
  480. X * This program is distributed in the hope that it will be useful,
  481. X * but WITHOUT ANY WARRANTY; without even the implied warranty of
  482. X * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  483. X * GNU General Public License for more details.
  484. X *
  485. X * A copy of the GNU General Public License can be obtained from this
  486. X * program's author (send electronic mail to mleisher@nmsu.edu) or from
  487. X * the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA
  488. X * 02139, USA.
  489. X *
  490. X */
  491. X
  492. #include <stdio.h>
  493. #include <X11/Xos.h>
  494. #include "patchlevel.h"
  495. X
  496. #define BDFTOPS_VERSION 1
  497. #define AUTHOR_STRING "mleisher@nmsu.edu (Mark Leisher)"
  498. #define BDF_VERSION "2.1"
  499. X
  500. char *program, *fontname;
  501. char buff[128];
  502. int fontno = 1;
  503. X
  504. int w, h, psize, resX, resY;
  505. double width_scale;
  506. X
  507. char *
  508. get_fontname(str)
  509. char *str;
  510. {
  511. X    int len;
  512. X    char *ptr, *tmp_name;
  513. X
  514. X    if (str == NULL) {
  515. X        tmp_name = (char *)malloc(20 * sizeof(char));
  516. X        sprintf(tmp_name, "BDF FONT %d", fontno++);
  517. X        return(tmp_name);
  518. X    }
  519. X    len = strlen(str);
  520. X    ptr = str + (len - 1);
  521. X    while(ptr > str && *ptr != '.')
  522. X      ptr--;
  523. X    if (ptr == str)
  524. X      return(str);
  525. X    ptr++;
  526. X    if (!strncmp(ptr, "bdf", 3)) {
  527. X        ptr--;
  528. X        tmp_name = (char *)malloc(((ptr-str) + 1) * sizeof(char));
  529. X        strncpy(tmp_name, str, (ptr-str));
  530. X        tmp_name[ptr-str] = '\0';
  531. X        return(tmp_name);
  532. X    }
  533. X    return(str);
  534. }
  535. X
  536. void
  537. header(in)
  538. FILE *in;
  539. {
  540. X    int dx, dy;
  541. X    int i, count, ndx, ndy;
  542. X    double llx, lly, urx, ury;
  543. X    time_t clock;
  544. X
  545. X    printf("%%!PS-Adobe-2.0\n");
  546. X    printf("%%%% GENERATED BY \"bdftops %d.%d\"\n", BDFTOPS_VERSION,
  547. X           patchlevel);
  548. X    printf("%%%% AUTHOR %s\n", AUTHOR_STRING);
  549. X
  550. X    time(&clock);
  551. X    printf("%%%% DATE %s\n", ctime(&clock));
  552. X
  553. X    printf("10 dict dup begin\n");
  554. X    printf("/FontType 3 def\n");
  555. X    printf("/FontMatrix [1 0 0 1 0 0] def\n");
  556. X
  557. X    fscanf(in, "%[^\n]\n", buff);
  558. X
  559. X    if (strcmp(buff, "STARTFONT 2.1")) {
  560. X        fprintf(stderr, "%s: incorrect BDF format \"%s\"\n", program,
  561. X                buff);
  562. X        exit(1);
  563. X    }
  564. X
  565. X    while(!feof(in) && strncmp(buff, "SIZE", 4))
  566. X      fscanf(in, "%[^\n]\n", buff);
  567. X    if (strncmp(buff, "SIZE", 4)) {
  568. X        fprintf(stderr, "%s: missing SIZE\n", program);
  569. X        exit(1);
  570. X    }
  571. X    sscanf(buff, "SIZE %d %d %d", &psize, &resX, &resY);
  572. X
  573. X    width_scale = (((double)psize)/1000.0) * (((double)resX)/72.27);
  574. X
  575. X    while(!feof(in) && strncmp(buff, "FONTBOUNDINGBOX", 15))
  576. X      fscanf(in, "%[^\n]\n", buff);
  577. X    if (strncmp(buff, "FONTBOUNDINGBOX", 15)) {
  578. X        fprintf(stderr, "%s: missing FONTBOUNDINGBOX\n", program);
  579. X        exit(1);
  580. X    }
  581. X    sscanf(buff, "FONTBOUNDINGBOX %d %d %d %d", &w, &h, &dx, &dy);
  582. X
  583. X    ndx = (dx < 0) ? -(dx) : dx;
  584. X    ndy = (dy < 0) ? -(dy) : dy;
  585. X    if (w == 0)
  586. X      llx = urx = 0.0;
  587. X    else {
  588. X        llx = ((double)(w + ndx)) / ((double) w);
  589. X        urx = ((double) dx) / ((double) w);
  590. X    }
  591. X    if (h == 0)
  592. X      lly = ury = 0.0;
  593. X    else {
  594. X        lly = ((double)(h + ndy)) / ((double) h);
  595. X        ury = ((double) dy) / ((double) h);
  596. X    }
  597. X    printf("/FontBBox [%g %g %g %g] def\n", llx, lly, urx, ury);
  598. X    printf("/Encoding 256 array def\n");
  599. X    printf("0 1 255 {Encoding exch /.notdef put} for\n");
  600. X    printf("Encoding\n");
  601. X    count = 0;
  602. X    for (i = 32; i < 255; i++) {
  603. X        printf("dup %d /char%d put\t", i, i);
  604. X        count++;
  605. X        if (count % 3 == 0) {
  606. X            count = 0;
  607. X            printf("\n");
  608. X        }
  609. X    }
  610. X    printf("255 /char255 put\n");
  611. X    printf("/BuildChar\n{0 begin\n/char exch def\n/fontdict exch def\n");
  612. X    printf("/charname fontdict /Encoding get char get def\n");
  613. X    printf("/charinfo fontdict /CharData get charname get def\n");
  614. X    printf("/wx charinfo 0 get def\n");
  615. X    printf("/charbbox charinfo 1 4 getinterval def\n");
  616. X    printf("wx 0 charbbox aload pop setcachedevice\n");
  617. X    printf("charinfo 5 get charinfo 6 get true\n");
  618. X    printf("fontdict /imagemaskmatrix get\n");
  619. X    printf("dup 4 charinfo 7 get put\n");
  620. X    printf("dup 5 charinfo 8 get put\n");
  621. X    printf("charinfo 9 1 getinterval cvx imagemask\n");
  622. X    printf("end } def\n");
  623. X    printf("/BuildChar load 0 6 dict put\n");
  624. X    printf("/imagemaskmatrix [%d 0 0 -%d 0 0] def\n", w, h);
  625. X    printf("/CharData 224 dict def\nCharData begin\n");
  626. }
  627. X
  628. void
  629. gen_chars(in)
  630. FILE *in;
  631. {
  632. X    int cw, ch, dx, dy, dx1, dy1, encoding, i;
  633. X    int sw, dummy;
  634. X    double wx, llx, lly, urx, ury, ndx, ndy, tdx;
  635. X
  636. X    fscanf(in, "%[^\n]\n", buff);
  637. X    while(!feof(in)) {
  638. X        while(!feof(in) && strncmp(buff, "ENCODING", 8))
  639. X          fscanf(in, "%[^\n]\n", buff);
  640. X        if (feof(in))
  641. X          break;
  642. X        sscanf(buff, "ENCODING %d", &encoding);
  643. X
  644. X        while(!feof(in) && strncmp(buff, "SWIDTH", 6))
  645. X          fscanf(in, "%[^\n]\n", buff);
  646. X        if (feof(in))
  647. X          break;
  648. X        sscanf(buff, "SWIDTH %d %d", &sw, &dummy);
  649. X
  650. X        sw = (int)(((double)sw) * width_scale);
  651. X        sw++;
  652. X
  653. X        if (!feof(in) && encoding >= 32) {
  654. X            while(!feof(in) && strncmp(buff, "BBX", 3))
  655. X              fscanf(in, "%[^\n]\n", buff);
  656. X            if (feof(in))
  657. X              break;
  658. X            sscanf(buff, "BBX %d %d %d %d", &cw, &ch, &dx, &dy);
  659. X            dx1 = (dx < 0) ? -(dx) : dx;
  660. X            dy1 = (dy < 0) ? -(dy) : dy;
  661. X            ndx = 2.0 * (((double) dx1) - 0.5);
  662. X            wx = (((double) sw) + ndx) / ((double) w);
  663. X            if (wx == 0)
  664. X              wx = ((double)w) * 0.01;
  665. X            if (w == 0)
  666. X              llx = urx = 0.0;
  667. X            else {
  668. X                urx = ((double)(sw + dx1)) / ((double) sw);
  669. X                llx = ((double) dx) / ((double) sw);
  670. X            }
  671. X            if (h == 0)
  672. X              lly = ury = 0.0;
  673. X            else {
  674. X                ury = ((double)(ch + dy1)) / ((double) ch);
  675. X                lly = ((double) dy) / ((double) ch);
  676. X            }
  677. X            ndx = ((double)dx1) - 0.5;
  678. X            ndy = ((double)ch) - 0.5;
  679. X            printf("/char%d [%g %g %g %g %g %d %d %g %g\n<", encoding, wx, llx,
  680. X                   lly, urx, ury, cw, ch, ndx, ndy);
  681. X
  682. X            fscanf(in, "%[^\n]\n", buff);
  683. X            while(!feof(in) && strncmp(buff, "BITMAP", 6))
  684. X              fscanf(in, "%[^\n]\n", buff);
  685. X            if (feof(in))
  686. X              break;
  687. X            for (i = 0; i < ch; i++) {
  688. X                fscanf(in, "%[^\n]", buff);
  689. X                printf("%s", buff);
  690. X                getc(in);  /* kill the EOL */
  691. X            }
  692. X            printf(">] def\n");
  693. X        } else
  694. X          fscanf(in, "%[^\n]\n", buff);
  695. X    }
  696. X    printf("/.notdef [%g 0 0 0 0 1 0 0 <>] def\n", ((double) w) * .01);
  697. X    printf("end\nend\n/%s exch definefont pop\n", fontname);
  698. }
  699. X
  700. X
  701. main(argc, argv)
  702. int argc;
  703. char **argv;
  704. {
  705. X    FILE *in = stdin;
  706. X
  707. X    program = argv[0];
  708. X
  709. X    argc--;
  710. X    *argv++;
  711. X    while(argc) {
  712. X        if (!(in = fopen(argv[0], "r")))
  713. X          fprintf(stderr, "%s: problem with %s\n", program, argv[0]);
  714. X        else {
  715. X            fontname = get_fontname(argv[0]);
  716. X            header(in);
  717. X            gen_chars(in);
  718. X            fclose(in);
  719. X            in = NULL;
  720. X        }
  721. X        argc--;
  722. X        *argv++;
  723. X    }
  724. X    if (in != NULL) {
  725. X        header(in);
  726. X        gen_chars(in);
  727. X    }
  728. }
  729. SHAR_EOF
  730. chmod 0664 bdftops.c ||
  731. echo 'restore of bdftops.c failed'
  732. Wc_c="`wc -c < 'bdftops.c'`"
  733. test 7704 -eq "$Wc_c" ||
  734.     echo 'bdftops.c: original size 7704, current size' "$Wc_c"
  735. fi
  736. # ============= bdftops.man ==============
  737. if test -f 'bdftops.man' -a X"$1" != X"-c"; then
  738.     echo 'x - skipping bdftops.man (File already exists)'
  739. else
  740. echo 'x - extracting bdftops.man (Text)'
  741. sed 's/^X//' << 'SHAR_EOF' > 'bdftops.man' &&
  742. .TH BDFTOPS 1 "Release 4" "X Version 11"
  743. .SH NAME
  744. bdftops - BDF font to Postscript font generator
  745. .SH SYNOPSIS
  746. .B "bdftops"
  747. [bdf-file(s)]
  748. .SH DESCRIPTION
  749. .PP
  750. .B bdftops
  751. reads a Bitmap Distribution Format (BDF) file (or from standard input
  752. if no file is specified on the command line) and produces a
  753. Postscript font on standard output.
  754. .sp
  755. .B bdftops
  756. will use the font filename minus the \fI.bdf\fP extension as
  757. the name of the font, the full font filename if the \fI.bdf\fP extension is
  758. not there, or a font name of "\fBBDF-FONT-\fIn\fP", where \fIn\fP is a
  759. number, when a font file is read from standard input.
  760. .SH "TUNING FONTS"
  761. .B bdftops
  762. depends on the SWIDTH (scalable width) x value heavily.  If this value
  763. is not correct, then the horizontal offsets will be a little too
  764. small, especially with variable width fonts.  Details of the SWIDTH
  765. entry are described in the "Bitmap Distribution Format 2.1" document.
  766. .sp
  767. Variable width fonts will probably need a small amount of hand tuning
  768. to get correct kerning.
  769. .sp
  770. An example of a Postscript character definition from the Adobe
  771. Times-Roman 24(timR24.bdf) font:
  772. .nf
  773. \f(CW/char116 [0.230769 0 0 1 1 7 15 -0.5 14.5
  774. <103070FE303030303030303030321C>] def\fP
  775. .fi
  776. .sp
  777. The first number is the horziontal offset of the character that
  778. follows this one, the next four numbers are the character's bounding
  779. box for the font cacheing mechanism, the next two numbers are the
  780. bitmap's width and height, and the last two numbers are horizontal and
  781. vertical translations of the bitmap with .5 subtracted to handle
  782. Postscript rounding errors.
  783. .sp
  784. This example in particular is a lower case ``t''.  The horizontal
  785. offset of the next character is not quite right.  So the 0.230769
  786. needs to be increased a little so that the character following the
  787. ``t'' is kerned correctly.
  788. .SH "SEE ALSO"
  789. XX(1), Xserver(1), bdftosnf(1)
  790. .br
  791. "Bitmap Distribution Format 2.1"
  792. .SH AUTHOR
  793. Internet: mleisher@nmsu.edu     Bitnet: mleisher@nmsu.bitnet
  794. .br
  795. Mark Leisher
  796. .br
  797. Computing Research Lab
  798. .br
  799. New Mexico State University
  800. .br
  801. Las Cruces, NM 88003
  802. .br
  803. (505) 646-5711
  804. X
  805. SHAR_EOF
  806. chmod 0664 bdftops.man ||
  807. echo 'restore of bdftops.man failed'
  808. Wc_c="`wc -c < 'bdftops.man'`"
  809. test 2082 -eq "$Wc_c" ||
  810.     echo 'bdftops.man: original size 2082, current size' "$Wc_c"
  811. fi
  812. # ============= patchlevel.h ==============
  813. if test -f 'patchlevel.h' -a X"$1" != X"-c"; then
  814.     echo 'x - skipping patchlevel.h (File already exists)'
  815. else
  816. echo 'x - extracting patchlevel.h (Text)'
  817. sed 's/^X//' << 'SHAR_EOF' > 'patchlevel.h' &&
  818. #define patchlevel 0
  819. X
  820. SHAR_EOF
  821. chmod 0664 patchlevel.h ||
  822. echo 'restore of patchlevel.h failed'
  823. Wc_c="`wc -c < 'patchlevel.h'`"
  824. test 22 -eq "$Wc_c" ||
  825.     echo 'patchlevel.h: original size 22, current size' "$Wc_c"
  826. fi
  827. exit 0
  828.  
  829. --
  830. dan
  831. ----------------------------------------------------
  832. O'Reilly && Associates   argv@sun.com / argv@ora.com
  833. Opinions expressed reflect those of the author only.
  834.