From a4fcf2873df1caceeba4b74f62d27106389868e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakobus=20Sch=C3=BCrz?= Date: Sun, 30 Aug 2020 21:50:45 +0200 Subject: [PATCH] take pstoricohddst-gdi from ustinov, fix dash in fedora32 the original was not working any longer. Use version from ustinov and change %03d-page.pbm to %03d.page.pbm, because formatstring with dash was not working any longer. don't know why. --- ricoh-sp100/pstoricohddst-gdi | 189 ------------------ .../usr/lib/cups/filter/pstoricohddst-gdi | 129 ++++++------ 2 files changed, 72 insertions(+), 246 deletions(-) delete mode 100644 ricoh-sp100/pstoricohddst-gdi diff --git a/ricoh-sp100/pstoricohddst-gdi b/ricoh-sp100/pstoricohddst-gdi deleted file mode 100644 index 71d0f8d..0000000 --- a/ricoh-sp100/pstoricohddst-gdi +++ /dev/null @@ -1,189 +0,0 @@ -#!/bin/bash - -# Debug mode: change to 'yes' to enable -DEBUG=${DEBUG-no} - -function log() { - [ "${DEBUG}" = "yes" ] && echo $* | logger -t "$0[$$]" -} - -function logpipe() { - [ "${DEBUG}" = "yes" ] && echo $* | logger -t "$0[$$]" -} - -function trapINT() { - log "trapINT()" - [ "x$trp" = "x" ] && trp="yes" || return - sleep 30 && { [ ! "${DEBUG}" = "yes" ] && rm -rf $uid; log "Cleanup complete"; } & - exit -} - -function stop() { - log "Stop stop page"; - echo "stop" > $uid/999999999-page.pbm -} - -function output_page() { - # Converting page to JBIG format (parameters are very special for this printer!) - pbmtojbg -p 72 -o 3 -m 0 -q < $page > $uid/raster.jbig - - # Taking image size - jsize=`wc -c < $uid/raster.jbig` - - # Taking image dimensions - x=($(identify -format "%w %h %[fx:mean] " $page)) - ## - # The %[fx:mean] gives the average colour in the image which for - # monochrome is the number of white pixels divided by the size - # - # So the formula gives the number of black pixels. The final - # /1 causes bc to round to the nearest integer because scale=0 - ## - dots=$(echo "(${x[0]}*${x[1]}*(1-${x[2]}))/1"|bc) - ## - # FIX: toner cartridge runs out way too fast with this dots - # calculation above and once it decides it's empty, you - # can't force it to print. So set dots to an artificially - # low number - dots=$(echo "$dots/10"|bc) - - # Flushing page header - cat <$uid/output.stream #> >(tee $uid/output.stream) - -[ -x "$(which inotifywait)" ] && { - log "Asynchronous variant" - - ( - stage="empty" - inotifywait -q -m -r -e close_write --format '%f' $uid | grep --line-buffered 'page.pbm$' | while read page; do - log "Page submitted" - [ "$stage" = "empty" ] && { - log "1st stage. Flushing PJL header" - output_header - stage="printing" - } - [ "$page" = "999999999-page.pbm" ] && { - log "Last stage. Flushing PJL footer" - output_footer - pid=`ps ax | grep $uid | grep -v grep | awk ' { print $1 } '` - [ ! "x$pid" = "x" ] && kill $pid - break - } - [ "$stage" = "printing" ] && { - page=$uid/$page - output_page - } - done - ) & - - # Converting from PostScript to PostScript-monochrome, then to PBM image format (per page) - #gs -sDEVICE=ps2write -sOutputFile=- -r$resolution -dQUIET -dBATCH -dNOPAUSE - | - gs -sDEVICE=pbmraw -sOutputFile=${uid}/%03d-page.pbm -r$resolution -dQUIET -dBATCH -dNOPAUSE - - - stop - wait - - trapINT -} || { - log "Synchronous variant" - - # Converting from PostScript to PostScript-monochrome, then to PBM image format (per page) - log "Converting document to pages" - gs -sDEVICE=ps2write -sOutputFile=- -r$resolution -dQUIET -dBATCH -dNOPAUSE - | gs -sDEVICE=pbmraw -sOutputFile=${uid}/%03d-page.pbm -r$resolution -dQUIET -dBATCH -dNOPAUSE - - log "Conversion complete" - - output_header - - for page in ${uid}/*-page.pbm; do - output_page - done - - # Flushing PJL footer - output_footer - -} - -# only remove the output dir if not debugging -[ ! "${DEBUG}" = "yes" ] && rm -rf $uid; - -exit 0 diff --git a/ricoh-sp100/usr/lib/cups/filter/pstoricohddst-gdi b/ricoh-sp100/usr/lib/cups/filter/pstoricohddst-gdi index 71d0f8d..7f0d694 100755 --- a/ricoh-sp100/usr/lib/cups/filter/pstoricohddst-gdi +++ b/ricoh-sp100/usr/lib/cups/filter/pstoricohddst-gdi @@ -1,7 +1,19 @@ #!/bin/bash +#Next four lines must be uncommented in MacOS +#GS=/opt/local/bin/gs +#PBMTOJBG=/opt/local/bin/pbmtojbg +#IDENTIFY=/opt/local/bin/identify +#uid="/var/spool/cups/tmp/pstoricohddst-gdi-`uuidgen`" + +# Next four lines must be uncommented in Linux +GS=gs +PBMTOJBG=pbmtojbg +IDENTIFY=identify +uid="/tmp/pstoricohddst-gdi-`uuidgen`" + # Debug mode: change to 'yes' to enable -DEBUG=${DEBUG-no} +DEBUG=${DEBUG+no} function log() { [ "${DEBUG}" = "yes" ] && echo $* | logger -t "$0[$$]" @@ -20,58 +32,52 @@ function trapINT() { function stop() { log "Stop stop page"; - echo "stop" > $uid/999999999-page.pbm + echo "stop" > $uid/999999999.page.pbm } -function output_page() { - # Converting page to JBIG format (parameters are very special for this printer!) - pbmtojbg -p 72 -o 3 -m 0 -q < $page > $uid/raster.jbig +function pageOutput() { - # Taking image size - jsize=`wc -c < $uid/raster.jbig` +# Converting page to JBIG format (parameters are very special for this printer!) +$PBMTOJBG -p 72 -o 3 -m 0 -q < $uid/$page > $uid/raster.jbig - # Taking image dimensions - x=($(identify -format "%w %h %[fx:mean] " $page)) - ## - # The %[fx:mean] gives the average colour in the image which for - # monochrome is the number of white pixels divided by the size - # - # So the formula gives the number of black pixels. The final - # /1 causes bc to round to the nearest integer because scale=0 - ## - dots=$(echo "(${x[0]}*${x[1]}*(1-${x[2]}))/1"|bc) - ## - # FIX: toner cartridge runs out way too fast with this dots - # calculation above and once it decides it's empty, you - # can't force it to print. So set dots to an artificially - # low number - dots=$(echo "$dots/10"|bc) +# Taking image size +jsize=`wc -c < $uid/raster.jbig | awk ' { printf($1); }' ` - # Flushing page header - cat <$uid/output.stream #> >(tee $uid/output.stream) +[ "${DEBUG}" = "yes" ] && exec >$uid/output.stream #> >(tee $uid/output.stream) #does not work under MacOS -[ -x "$(which inotifywait)" ] && { +if [ -x "$(which inotifywait)" ]; then { log "Asynchronous variant" ( @@ -139,51 +145,60 @@ mkdir -p $uid log "Page submitted" [ "$stage" = "empty" ] && { log "1st stage. Flushing PJL header" - output_header + pjlHeader; + stage="printing" } - [ "$page" = "999999999-page.pbm" ] && { + [ "$page" = "999999999.page.pbm" ] && { log "Last stage. Flushing PJL footer" - output_footer + pjlFooter; + pid=`ps ax | grep $uid | grep -v grep | awk ' { print $1 } '` [ ! "x$pid" = "x" ] && kill $pid break } [ "$stage" = "printing" ] && { - page=$uid/$page - output_page + pageOutput; } done ) & # Converting from PostScript to PostScript-monochrome, then to PBM image format (per page) - #gs -sDEVICE=ps2write -sOutputFile=- -r$resolution -dQUIET -dBATCH -dNOPAUSE - | - gs -sDEVICE=pbmraw -sOutputFile=${uid}/%03d-page.pbm -r$resolution -dQUIET -dBATCH -dNOPAUSE - + #$GS -sDEVICE=ps2write -sOutputFile=- -r$resolution -dQUIET -dBATCH -dNOPAUSE - | + $GS -sDEVICE=pbmraw -sOutputFile=${uid}/%03d.page.pbm -r$resolution -dQUIET -dBATCH -dNOPAUSE - stop wait trapINT -} || { + } +else { log "Synchronous variant" + mkdir ${uid}/gs-temp + export TEMP=${uid}/gs-temp # Converting from PostScript to PostScript-monochrome, then to PBM image format (per page) log "Converting document to pages" - gs -sDEVICE=ps2write -sOutputFile=- -r$resolution -dQUIET -dBATCH -dNOPAUSE - | gs -sDEVICE=pbmraw -sOutputFile=${uid}/%03d-page.pbm -r$resolution -dQUIET -dBATCH -dNOPAUSE - + $GS -sDEVICE=ps2write -sOutputFile=- -r$resolution -dQUIET -dBATCH -dNOPAUSE - | $GS -sDEVICE=pbmraw -sOutputFile=${uid}/%03d.page.pbm -r$resolution -dQUIET -dBATCH -dNOPAUSE - log "Conversion complete" - output_header + pjlHeader; + + ls -1 $uid | grep "page.pbm" | while read page; do + #for page in ${uid}/*.page.pbm; do #looks untested - does not work + log "Page $page" + + pageOutput; - for page in ${uid}/*-page.pbm; do - output_page done # Flushing PJL footer - output_footer - -} - -# only remove the output dir if not debugging -[ ! "${DEBUG}" = "yes" ] && rm -rf $uid; + pjlFooter; + + if [ ! "${DEBUG}" = "yes" ]; then + rm -rf $uid + fi + } +fi exit 0