| 1 |
#!/bin/bash |
| 2 |
|
| 3 |
# |
| 4 |
# Copyright (c) 2017 Samuel Thibault <[email protected]> |
| 5 |
# |
| 6 |
# Permission is hereby granted, free of charge, to any person obtaining a copy |
| 7 |
# of this software and associated documentation files (the "Software"), to deal |
| 8 |
# in the Software without restriction, including without limitation the rights |
| 9 |
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 10 |
# copies of the Software, and to permit persons to whom the Software is |
| 11 |
# furnished to do so, subject to the following conditions: |
| 12 |
# |
| 13 |
# |
| 14 |
# The above copyright notice and this permission notice shall be included in |
| 15 |
# all copies or substantial portions of the Software. |
| 16 |
# |
| 17 |
# |
| 18 |
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 19 |
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 20 |
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 21 |
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 22 |
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 23 |
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| 24 |
# THE SOFTWARE. |
| 25 |
# |
| 26 |
|
| 27 |
# Make sure we have enough options |
| 28 |
if [ $# != 5 -a $# != 6 ]; then |
| 29 |
echo "ERROR: $0 jobid user name nb options [filename]" >&2 |
| 30 |
exit 1 |
| 31 |
fi |
| 32 |
|
| 33 |
NB=$4 |
| 34 |
OPTIONS=$5 |
| 35 |
FILE=$6 |
| 36 |
|
| 37 |
case $0 in |
| 38 |
*svgtopdf*) INPUT_FORMAT=svg ;; |
| 39 |
*xfigtopdf*) INPUT_FORMAT=fig ;; |
| 40 |
*wmftopdf*) INPUT_FORMAT=wmf ;; |
| 41 |
*emftopdf*) INPUT_FORMAT=emf ;; |
| 42 |
*cgmtopdf*) INPUT_FORMAT=cgm ;; |
| 43 |
*cmxtopdf*) INPUT_FORMAT=cmx ;; |
| 44 |
esac |
| 45 |
|
| 46 |
trap -- 'rm -f "$FILE_FORMAT" "$FILE_PDF"' EXIT |
| 47 |
FILE_FORMAT=$(mktemp "${TMPDIR:-/tmp}/vectortopdf.XXXXXX.${INPUT_FORMAT}") |
| 48 |
FILE_PDF=$(mktemp "${TMPDIR:-/tmp}/vectortopdf.XXXXXX.pdf") |
| 49 |
|
| 50 |
if [ -z "$FILE" ] |
| 51 |
then |
| 52 |
# Get input from stdin |
| 53 |
cat > "$FILE_FORMAT" |
| 54 |
else |
| 55 |
cat "$FILE" > "$FILE_FORMAT" |
| 56 |
fi |
| 57 |
|
| 58 |
. @CUPS_DATADIR@/braille/cups-braille.sh |
| 59 |
|
| 60 |
checkTool inkscape inkscape "embossing ${INPUT_FORMAT} vector images" |
| 61 |
|
| 62 |
INKSCAPE="inkscape --export-area-drawing" |
| 63 |
|
| 64 |
echo "INFO: Converting image" 1>&2 |
| 65 |
printf "DEBUG: Calling $INKSCAPE on '%s'\n" "$FILE_FORMAT" 1>&2 |
| 66 |
|
| 67 |
CURR_VERSION=$(inkscape --version | awk '{print $2}') |
| 68 |
NEW_VERSION='1.0' |
| 69 |
|
| 70 |
printf "DEBUG: Inkscape version: '%s'\n" "$CURR_VERSION" 1>&2 |
| 71 |
|
| 72 |
# Inkscape versions 1.0.x and greater do not support '-A' flag |
| 73 |
|
| 74 |
if [ $(printf '%s\n' "$NEW_VERSION" "$CURR_VERSION" | sort -V | head -n1) = "$NEW_VERSION" ]; then |
| 75 |
$INKSCAPE --export-type=pdf --export-filename="$FILE_PDF" "$FILE_FORMAT" |
| 76 |
else |
| 77 |
$INSCKAPE -z -A "$FILE_PDF" "$FILE_FORMAT" |
| 78 |
fi |
| 79 |
|
| 80 |
cat "$FILE_PDF" |
| 81 |
|
| 82 |
echo "INFO: Ready" >&2 |