... 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  -  <[email protected]>  -  http://www.f-hauri.ch
_______________________________________________
gull mailing list
[email protected]
http://forum.linux-gull.ch/mailman/listinfo/gull

Répondre à