[gull] {Content?} Etiquette codebarre
felix
felix at f-hauri.ch
Mon Sep 5 15:24:02 CEST 2016
... Mon dernier post contient un buggue. Vu la nature du .ps généré par
barcode, ce script sera plus efficace et mieux adapté.
On Mon, Sep 05, 2016 at 11:29:35AM +0200, felix wrote:
> C'est plus du Postscript que du Bash...
Voire du bash qui edite du postscript...
#!/bin/bash
# Ce script utilise des bashismes qui nécessitent une version 4.3 de bash
code=$1 string="$2"
pstextfmt='%%!\n/Helvetica findfont 12 scalefont setfont'
pstextfmt+=' newpath %f %f moveto (%s) show\n'
while IFS=:\ read cmd v1 v2 v3 v4 foo; do
[ "$cmd" = "%%HiResBoundingBox" ] && read cwidth < <(bc -l <<<"$v3-$v1")
[ "$cmd" = "%%BoundingBox" ] && ytop=$((v4+4)) xwidth=$v3
done < <(
gs -q -dNOPAUSE -dSAFER -sDEVICE=bbox <(
barcode -b "$code" -E -g 150x50
) -c quit 2>&1 )
read xtop < <(
gs -q -sDEVICE=bbox -dNOPAUSE <(
printf "${pstextfmt}showpage\n" 0 0 "$string"
) -c quit 2>&1 |
sed -ne 's/^..Hi.*Box: \+[0-9.]\+ \+[0-9.]\+ \+\([0-9.]\+\) .*$/('"\
$cwidth"'-\1)\/2+10/p' |
bc -l )
while IFS= read line ; do
[ "$line" ] && [ -z "${line%%%%BoundingBox*}" ] &&
line="${line%% *} 0 0 $xwidth $[ytop+12]"
echo "$line"
[ "$line" ] && [ -z "${line##*fontsize}" ] &&
printf " [(%s) %f %d 12]\n" "$string" $xtop $ytop
done < <( barcode -b "$code" -E -g 150x50 )
--
Félix Hauri - <felix at f-hauri.ch> - http://www.f-hauri.ch
More information about the gull
mailing list