From c679b863e981fde63b6b021fb1051d9253cf5d56 Mon Sep 17 00:00:00 2001 From: Gustavo Arnosti Neves Date: Thu, 12 Apr 2018 06:55:03 -0300 Subject: [PATCH] v2.3.6 - fix grep detection method fail on some rare cases, would make execution fail instead of fail-safing --- pdfScale.sh | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/pdfScale.sh b/pdfScale.sh index 1e3a18e..3e1b958 100755 --- a/pdfScale.sh +++ b/pdfScale.sh @@ -1359,8 +1359,10 @@ getPageSizeCatGrep() { # Get MediaBox data if possible local mediaBox="$("$GREPBIN" -a -e '/MediaBox' -m 1 "$INFILEPDF" 2>/dev/null)" - mediaBox="${mediaBox##*/MediaBox[}" + mediaBox="${mediaBox##*/MediaBox}" + mediaBox="${mediaBox##*[}" mediaBox="${mediaBox%%]*}" + #echo "mediaBox=$mediaBox" # No page size data available if isEmpty "$mediaBox" && isNotAdaptiveMode; then @@ -1369,15 +1371,11 @@ getPageSizeCatGrep() { return $FALSE fi - # remove chars [ and ] - #mediaBox="${mediaBox//[}" - #mediaBox="${mediaBox//]}" - mediaBox=($mediaBox) # make it an array mbCount=${#mediaBox[@]} # array size # sanity - if [[ $mbCount -lt 4 ]] || ! isFloat "${mediaBox[2]}" || ! isFloat "${mediaBox[3]}"; then + if [[ $mbCount -lt 4 ]] || ! isFloat "${mediaBox[2]}" || ! isFloat "${mediaBox[3]}" || isZero "${mediaBox[2]}" || isZero "${mediaBox[3]}"; then if isNotAdaptiveMode; then notAdaptiveFailed $'Error when reading the page size!\nThe page size information is invalid!' fi @@ -1388,9 +1386,18 @@ getPageSizeCatGrep() { PGWIDTH=$(printf '%.0f' "${mediaBox[2]}") # Get Round Width PGHEIGHT=$(printf '%.0f' "${mediaBox[3]}") # Get Round Height + #echo "PGWIDTH=$PGWIDTH // PGHEIGHT=$PGHEIGHT" return $TRUE } +isZero() { + [[ "$1" == "0" ]] && return $TRUE + [[ "$1" == "0.0" ]] && return $TRUE + [[ "$1" == "0.00" ]] && return $TRUE + [[ "$1" == "0.000" ]] && return $TRUE + return $FALSE +} + # Prints error message and exits execution notAdaptiveFailed() { local errProgram="$2"