[comp.windows.x] X Bitmap to Postscript

kwan@maui.cs.ucla.edu (Edmund Kwan) (07/08/89)

	Is there a way to print bitmaps (X11 format) on an apple laser
printer?  Thanks.

kevinj@boulder.Colorado.EDU (Kevin M. Jackson) (07/08/89)

In article <25539@shemp.CS.UCLA.EDU> kwan@cs.ucla.edu (Edmund Kwan) writes:
>
>	Is there a way to print bitmaps (X11 format) on an apple laser
>printer?  Thanks.

This should do the trick.  It was given to me by a friend I work with.  I
give no guarantees as to it's useability ;-)

--------------------------- cut here ----------------------------------------
#!/bin/csh
#
# Xitops - Convert X icon to postscript printable file
#
# 4 Apr 1989 Hibachi
#

if ($#argv != 2) then
  echo 'usage: xitops source dest'
  exit
endif

set src=$argv[1]
set dst=$argv[2]

set width=`fgrep width $src | awk '{print $3}'`
set height=`fgrep height $src | awk '{print $3}'`

echo "doing $src --> $dst dims $width x $height"

@ bytwid = $width / 8

echo '%\!' > $dst
echo "/picstr $bytwid string def" >> $dst
echo '72 dup translate' >> $dst
echo '3 72 mul dup scale' >> $dst
echo "$width $height 1" >> $dst
echo "[$width 0 0 -$height 0 $height]" >> $dst
echo '{currentfile picstr readhexstring pop}' >> $dst
echo 'image' >> $dst

tail +4 $src | tr -d ' 	,;}' | sed 's/0x\(.\)\(.\)\(.\)\(.\)/\4\3\2\1/g' | tr '0123456789abcdefABCDEF' '084c2a6e195d3b7f5d3b7f' >> $dst

echo 'showpage' >> $dst

echo 'yo, done...'

ali@apollo.COM (Ali Reza Alipour) (01/25/91)

Is there a public domain software to convert X bitmap to postscript?

Ali Alipour - ali@apollo.hp.com
-------

don@zardoz.coral.COM (Don Dewar) (02/04/91)

Yes.  Get pbmplus.  It contains a plethora of conversion filters.
Using a combination of them you can do what you want.

  +---------+
  | Coral   |
  |@@@@@*@**|
  |@@*@@**@@|     Don Dewar
  |*@@**@@@@|     Coral Network Corporation, Marlborough, MA
  |@***@@@@@|     Internet: don@coral.com
  |@@**@@@@@|     Phone:    (508) 460-6010
  |*********|     Fax:      (508) 481-6258
  |Networks |
  +---------+

neilb@dcs.leeds.ac.UK (Neil Bowers) (02/04/91)

Ali Alipour - ali@apollo.hp.com - asked
> Is there a public domain software to convert X bitmap to postscript?

Gennady Moshkovich asked
> Subject: HOW TO PRINT A BITMAP ????????
> [ ... ]
> I need to print a bitmap from X background.
> Is there any way way to translate to EPS or PS

A while back I picked up a script 'Xitops' by Hibachi --
I made a few changes, and renamed it xbm2ps.

If Hibachi is out there, I hope you don't mind me posting this --
I didn't have any email address for you.

Enjoy!

Neil
(neilb@uk.ac.leeds.dcs)

PS You need to have a sed with decent regular expression handling.
   GNU sed will do.

------------------------ xbm2ps ------------------------------------
#!/bin/csh -f
#
# xbm2ps -- translate X bitmap to postscript
#
# Usage xbm2ps [ -width w | -height h ] <source> <destination>
#
# Neil Bowers (neilb@uk.ac.leeds.dcs)
# from the script 'Xitops' by Hibachi
#

# parse args
while ($#argv > 0)
	switch ($argv[1])
		case -width:
			if ($#argv < 2) goto Usage
			shift
			set pswidth = $argv[1]
			breaksw

		case -height:
			if ($#argv < 2) goto Usage
			shift
			set psheight = $argv[1]
			breaksw

		case -*:
			echo unknown option: $argv[1]
			exit

		default:
			if (! $?src) then
				set src = $argv[1]
			else if (! $?dst) then
				set dst = $argv[1]
			else
				goto Usage:
			endif
			breaksw
	endsw
	shift
end

# Both source and destination must be specified
if ((! $?src) || (! $?dst)) goto Usage

if ($?pswidth && $?psheight) then
	echo Only one of -height and -width can be specified
	exit
endif

if (! -f $src) then
	echo xbm2ps: $src not found
	exit
endif

if ($src == $dst) then
	echo "xbm2ps: source and destination are the same\!"
	exit
endif

# Get dimensions of bitmap
set width=`fgrep width $src | awk '$print $3'`
set height=`fgrep height $src | awk '$print $3'`

# if no output dimensions specified,
# largest output dimension set to default (3in)
if (! $?pswidth && ! $?psheight) then
	if ($width > $height) then
		set pswidth = 3
	else
		set psheight = 3
	endif
endif

if ($?pswidth) then
	set xscale = "$pswidth 72 mul"
	set yscale = "$pswidth 72 mul $height mul $width div"
else
	set xscale = "$psheight 72 mul $width mul $height div"
	set yscale = "$psheight 72 mul"
endif

@ bytwid = $width / 8

echo '%\!' > $dst
echo "/picstr $bytwid string def" >> $dst
echo '72 dup translate' >> $dst
echo "$xscale $yscale scale" >> $dst
echo "$width $height 1" >> $dst
echo "[$width 0 0 -$height 0 $height]" >> $dst
echo '$currentfile picstr readhexstring pop' >> $dst
echo 'image' >> $dst

sed -e '/#define/d' -e '/_bits/d' $src | \
        tr -d '         ,;' | \
        sed 's/0x\(.\)\(.\)/\2\1/g' | \
        tr '0123456789abcdefABCDEF' 'f7b3d591e6a2c480a2c480' >> $dst

echo 'showpage' >> $dst

exit

Usage:
	echo "Usage: foobar [-width w | -height h] source destination"