File: uprint

package info (click to toggle)
mined 2000.15.4-1
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 16,616 kB
  • ctags: 2,957
  • sloc: ansic: 123,254; sh: 10,042; makefile: 266; sed: 221; perl: 172; cpp: 30
file content (221 lines) | stat: -rwxr-xr-x 4,824 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
#! /bin/sh

#############################################################################
# print preprocessor for invocation of uniprint
# usage: uprint [-font <font>] [-size <size>] filename ...
# print layout configuration:
#   FONT=<font>
#       the name of a font file, e.g. LucidaBrightRegular or bodoni.ttf
#       the file must reside in the configured font path
#   FONTSIZE=<size>
#   FONTPATH=<font directory search path>
#       for use with uniprint only; separate directory names with ":"
#   $HOME/.fonts.conf (file)
#       Pango font configuration file, for use with paps;
#       here you can specify:
#       * directories with font files
#       * preferred fonts for styles "serif", "sans-serif", "monospace"
#       see http://fontconfig.org/fontconfig-user.html for patterns
#
# spooling configuration:
#   LPR=<optional print spooling command instead of lpr or lp>
#       if you need to spool files not using the operating system's spooler
#   PRINTER=<printer>


#############################################################################
# detect remove-after print option
case "$1" in
-r)	remove=-r
	shift;;
*)	remove=;;
esac


#############################################################################
# print multiple files
case "$2" in
?*)	for f in "$@"
	do	$0 $remove $f
	done
	exit;;
esac


#############################################################################
# determine print layout program
if type paps
then	paps=true
	# determine print spooling program
	case "$LPR" in
	"")	if type lpr
		then LPR=lpr
		elif type lp
		then LPR=lp
		else LPR=print
		fi;;
	esac
else	paps=false
fi


#############################################################################
# set font and size preference
#font=code2000
font=cyberbit
if $paps
then	font=monospace
	size=10
fi

font=${FONT-$font}

size=${FONTSIZE-$size}

# additional font directories to search for desired font (with uniprint)
morefonts="$HOME/fonts:$HOME/ttfonts:$HOME/opt/fonts:$HOME/opt/ttfonts:/usr/ttfonts:/usr/X11/lib/X11/fonts/truetype"


#############################################################################
# setup up parameters

# font directories to search for desired font
FONTPATH=${FONTPATH-$YUDITDATA}
case "$FONTPATH" in
"")	FONTPATH="$morefonts";;
*)	FONTPATH="$FONTPATH:$morefonts";;
esac


# try to extract font and size specificatios from command line parameters
params=
while
    case "$1" in
    -f|-font)	font="$2"
		shift; shift
		true;;
    -s|-size)	size="$2"
		shift; shift
		true;;
    -*)		params="$params $1"
		shift
		true;;
    *)		false;;
    esac
do	true
done


if $paps
then	true
else	# try to find font file
	font=`basename $font .ttf`
	fontfiles=`echo ${FONTPATH}: | sed -e "s,:,/$font.ttf ,g"`
	fontfile=`ls $fontfiles 2> /dev/null | sed -e 1q`
fi


#############################################################################
# construct parameters for paps / uniprint

if $paps
then
	papsopt=

	case "$size" in
	"")	sizepaps=
		;;
	*)	sizepaps="--font_scale $size"
		;;
	esac

	# add header option if configurable header available
	#if paps --help | grep -- --header > /dev/null
	#then	papsopt="$papsopt --header"
	#fi

	# add font spec in proper syntax for paps version
	if paps --help | grep -- --family > /dev/null
	then	papsfontpar=--family
		papsfont="$font"
		papsopt="$papsopt $sizepaps"
	elif paps --help | grep -- --font= > /dev/null
	then	papsfontpar=--font
		papsfont="$font $size"
	fi

	# add dpi spec for old paps version
	if paps --help | grep -- --dpi > /dev/null
	then	papsopt="$papsopt --dpi 300"
	fi

else

	case "$fontfile" in
	"")	fontspec=;;
	*)	fontspec="-font $fontfile";;
	esac

	case "$size" in
	"")	sizespec=
		;;
	*)	sizespec="-size $size"
		;;
	esac

fi


#############################################################################
# print

printed=true

if $paps
then	if [ -n "$papsfontpar" ]
	then	paps $papsfontpar "$papsfont" $papsopt "$1" | $LPR
	else	paps $papsopt "$1" | $LPR
	fi
elif type uniprint
then	if [ "$LPR" != "" ]
	then	uniprint $params -wrap $fontspec $sizespec -out - "$1" | $LPR
		#$LPR "$1.ps"
		#rm -f "$1.ps"
	else	uniprint $params -wrap $fontspec $sizespec "$1"
	fi
else	case `uname` in
	CYGWIN*|Windows*)
		if type notepad
		then
			dir=`dirname "$1"`
			base=`basename "$1"`
			cd "$dir"
			if type cmd.exe > /dev/null
			then	cmd.exe /c start /min notepad /p "$base"
			elif type command.com > /dev/null
			then	command.com /c start /min notepad /p "$base"
			else	notepad /p "$base"
			fi
		else	printed=false
		fi
		;;
	*)	printed=false
		;;
	esac
fi

if $printed
then
  case "$remove" in
  -r)	case "$1" in
	/tmp/*|/???/tmp/*|${MINEDTMP--}/*|${TMPDIR--}/*|${TMP--}/*|${TEMP--}/*)
		rm -f "$1";;
	esac;;
  esac
else
  false
fi


#############################################################################
# end