Comments (3)
I am not sure we should ever get a negative value in pdfScale's use case.
I would still like to fix the function though, but I would probably add the extra code inside de function.
pdfScale already uses BC for many things. It is already a requirement, so it would not be a problem to use a BC solution (if it is better).
How about just changing >
to -gt
as suggested?
I will need to test this a bit, before fixing it.
from pdfscale.
Ok, was able to test it properly now.
The old function isFloatBiggerThanZero()
was indeed busted. Changing to -gt
just makes it worse, since it breaks execution when it finds a point (eg 2.8).
Made this little script to test and be sure
#!/bin/bash
TRUE=0 # Silly stuff
FALSE=1
# Test script for float functions
# Returns $TRUE if $1 is a floating point number (or an integer), $FALSE otherwise
isFloat() {
[[ -n "$1" && "$1" =~ ^-?[0-9]*([.][0-9]+)?$ ]] && return $TRUE
return $FALSE
}
# Returns $TRUE if $1 is a floating point number bigger than zero, $FALSE otherwise
isFloatBiggerThanZero() {
isFloat "$1" && [[ "$1" =~ ^0*[1-9] || "$1" =~ ^0*[.]0*[1-9] ]] && return $TRUE
return $FALSE
}
# Returns $TRUE if $1 is a floating point number between 0 and 1, $FALSE otherwise
isFloatPercentage() {
[[ -n "$1" && "$1" =~ ^-?[0]*([.][0-9]+)?$ ]] && return $TRUE
[[ "$1" == "1" ]] && return $TRUE
return $FALSE
}
syes() { echo 'yes => '"$1" ; }
sno() { echo 'no => '"$1" ; }
v='text' ; isFloat "$v" && syes "$v" || sno "$v"
v=3 ; isFloat "$v" && syes "$v" || sno "$v"
v='1.2' ; isFloat "$v" && syes "$v" || sno "$v"
v='0.5' ; isFloat "$v" && syes "$v" || sno "$v"
v='-0.7' ; isFloat "$v" && syes "$v" || sno "$v"
v='-2.5' ; isFloat "$v" && syes "$v" || sno "$v"
echo '----------------'
v='text' ; isFloatBiggerThanZero "$v" && syes "$v" || sno "$v"
v=3 ; isFloatBiggerThanZero "$v" && syes "$v" || sno "$v"
v='1.2' ; isFloatBiggerThanZero "$v" && syes "$v" || sno "$v"
v='0.5' ; isFloatBiggerThanZero "$v" && syes "$v" || sno "$v"
v='-0.7' ; isFloatBiggerThanZero "$v" && syes "$v" || sno "$v"
v='-2.5' ; isFloatBiggerThanZero "$v" && syes "$v" || sno "$v"
echo '----------------'
v='text' ; isFloatPercentage "$v" && syes "$v" || sno "$v"
v=3 ; isFloatPercentage "$v" && syes "$v" || sno "$v"
v='1.2' ; isFloatPercentage "$v" && syes "$v" || sno "$v"
v='0.5' ; isFloatPercentage "$v" && syes "$v" || sno "$v"
v='-0.7' ; isFloatPercentage "$v" && syes "$v" || sno "$v"
v='-2.5' ; isFloatPercentage "$v" && syes "$v" || sno "$v"
Outputs
$ ./testFloat.sh
no => text
yes => 3
yes => 1.2
yes => 0.5
yes => -0.7
yes => -2.5
----------------
no => text
yes => 3
yes => 1.2
yes => 0.5
no => -0.7
no => -2.5
----------------
no => text
no => 3
no => 1.2
yes => 0.5
yes => -0.7
no => -2.5
Pls note that my isFloatPercentage
only returns $TRUE
if it is a value from 0 to 1. That is by design for what the script needs. I don't remember if it had to be positive as well 🤣, but if that is the case I can just also run the isFloatBiggerThanZero
on top of it.
I will push the changes now. Thanks for the function prototype!
Cheers!
Gus
from pdfscale.
Fixed on 1edc9d5
v2.5.8
from pdfscale.
Related Issues (20)
- Donation methods HOT 1
- Losing links HOT 3
- Issue with PDF output size HOT 20
- Resize and not preserve scale HOT 5
- Can you resize and fill the page instead of fitting the image? HOT 4
- Architectural paper size names in command line arguments rejected as invalid. HOT 1
- Licence missing HOT 1
- a specific png is being compressed into a jpeg... HOT 4
- Centering objects in resize mode seems to be broken HOT 2
- typo: milimeters -> millimeters HOT 1
- typo: used used -> used HOT 1
- misspelling: usefull -> useful HOT 1
- Unquoted $0 in basename $0 - basename: extra operand issues HOT 2
- How to decrease pdfscale execution time? HOT 1
- Export-Import PDF Metadata - Geospatial data not written to output HOT 5
- Ghostscript complains about the old PDF interpreter being deprecated HOT 4
- pdfscale custom resize appears to generate different flavor of pdf that interferes with gs PDFX (?) HOT 1
- what license? HOT 2
- [BUG]: `-dNEWDPF` deprecated?! Page drawing error! HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pdfscale.