]> git.ipfire.org Git - thirdparty/cups-filters.git/commitdiff
braille: Add support for page-ranges option 12/head
authorSamuel Thibault <samuel.thibault@ens-lyon.org>
Sun, 17 Dec 2017 19:20:01 +0000 (20:20 +0100)
committerSamuel Thibault <samuel.thibault@ens-lyon.org>
Sun, 17 Dec 2017 19:21:19 +0000 (20:21 +0100)
drv/generic-brf.drv
drv/generic-ubrl.drv
drv/indexv3.drv
drv/indexv4.drv
filter/braille/filters/brftopagedbrf.in [new file with mode: 0755]
filter/braille/filters/cups-braille.sh.in
mime/braille.convs
mime/braille.types

index 6f35d91244d936ffe6d35c6fd0099045096cb874..4b9431a4ca588f461042dfe59215d1f74359daeb 100644 (file)
@@ -35,7 +35,7 @@ Version 1.0
 
 Throughput 1
 
-Filter application/vnd.cups-brf 0 brftoembosser
+Filter application/vnd.cups-paged-brf 0 brftoembosser
 Filter image/vnd.cups-brf 0 brftoembosser
 
 MediaSize Legal
index 4e273aa4d498caf0adf0af6e0dc3454f1e0ae2be..d18a6300553d5369b4aeaeec0a28d9ef2aa97b1d 100644 (file)
@@ -35,7 +35,7 @@ Version 1.0
 
 Throughput 1
 
-Filter text/vnd.cups-ubrl 0 -
+Filter text/vnd.cups-paged-ubrl 0 -
 Filter image/vnd.cups-ubrl 0 -
 
 MediaSize Legal
index 3ce675a0a6f7c3226d25190845070e228936a529..8e2feec6985efc2dcfd77a209660ee86fc32cb4a 100644 (file)
@@ -34,7 +34,7 @@
 Manufacturer "Index"
 Version 1.0
 
-Filter application/vnd.cups-brf 0 textbrftoindexv3
+Filter application/vnd.cups-paged-brf 0 textbrftoindexv3
 Filter image/vnd.cups-ubrl 0 imageubrltoindexv3
 
 //
index e38655de1932ec38aee40ed535842145f0a0f0f1..db08efd7f1d799a3165a7c2acd96c85afed18e04 100644 (file)
@@ -34,7 +34,7 @@
 Manufacturer "Index"
 Version 1.0
 
-Filter application/vnd.cups-brf 0 textbrftoindexv4
+Filter application/vnd.cups-paged-brf 0 textbrftoindexv4
 Filter image/vnd.cups-ubrl 0 imageubrltoindexv4
 
 //
diff --git a/filter/braille/filters/brftopagedbrf.in b/filter/braille/filters/brftopagedbrf.in
new file mode 100755 (executable)
index 0000000..138c900
--- /dev/null
@@ -0,0 +1,144 @@
+#!/bin/bash
+
+#
+# Copyright (c) 2015-2017 Samuel Thibault <samuel.thibault@ens-lyon.org>
+# 
+# Permission is hereby granted, free of charge, to any person obtaining a copy
+# of this software and associated documentation files (the "Software"), to deal
+# in the Software without restriction, including without limitation the rights
+# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+# copies of the Software, and to permit persons to whom the Software is
+# furnished to do so, subject to the following conditions:
+# 
+# 
+# The above copyright notice and this permission notice shall be included in
+# all copies or substantial portions of the Software.
+# 
+# 
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+# THE SOFTWARE.
+# 
+
+# Make sure we have enough options
+if [ $# != 5 -a $# != 6 ]; then
+  echo "ERROR: $0 jobid user name nb options [filename]" >&2
+  exit 1
+fi
+
+NB=$4
+OPTIONS=$5
+FILE=$6
+
+. @CUPS_DATADIR@/braille/cups-braille.sh
+
+shopt -s extglob
+
+# Construct list of pages from PAGERANGES
+
+PAGES=" "   # Explicit list of pages
+AFTER=      # All pages including and after this
+BEFORE=     # All pages before and including this
+
+while [ -n "${PAGERANGES}" ]
+do
+  PAGERANGE=${PAGERANGES/,*}
+  PAGERANGE=${PAGERANGE%%*( )}
+  PAGERANGE=${PAGERANGE##*( )}
+  if [ -n "${PAGERANGES/*,*}" ]
+  then
+    # last range
+    PAGERANGES=""
+  else
+    # Remove leading range
+    PAGERANGES="${PAGERANGES#*,}"
+  fi
+
+  if [ -n "${PAGERANGE/*-*}" ]
+  then
+    # single-page
+    PAGES="$PAGES$PAGERANGE "
+
+  elif [ -z "${PAGERANGE%%*-}" ]
+  then
+    # To the end
+    FIRST=${PAGERANGE%%-*}
+    if [ -z "$AFTER" ] || [ "$FIRST" -lt "$AFTER" ]
+    then
+      AFTER="$FIRST"
+    fi
+
+  elif [ -z "${PAGERANGE##-*}" ]
+  then
+    # From the beginning
+    LAST=${PAGERANGE##*-}
+    if [ -z "$BEFORE" ] || [ "$LAST" -gt "$BEFORE" ]
+    then
+      BEFORE="$LAST"
+    fi
+
+  else
+    # page range
+    FIRST=${PAGERANGE/-*}
+    LAST=${PAGERANGE/*-}
+    PAGES="$PAGES$(seq "$FIRST" "$LAST" | tr $'\012' ' ')"
+
+  fi
+done
+
+# Determine whether to print this page
+doprint() {
+  PAGE="$1"
+  if [ -n "$BEFORE" ] && [ "$PAGE" -le "$BEFORE" ]
+  then
+    echo 1
+    return
+  elif [ -n "$AFTER" ] && [ "$PAGE" -ge "$AFTER" ]
+  then
+    echo 1
+    return
+  fi
+  case "$PAGES" in
+    *\ $PAGE\ *)
+      echo 1
+      return
+      ;;
+  esac
+  echo 0
+}
+
+if [ -z "$FILE" ]
+then
+  cat
+else
+  cat "$FILE"
+fi | (
+  P=1
+  DOPRINT=$(doprint $P)
+  while IFS=$'\n' read -r LINE
+  do
+    while [ -z "${LINE/*$'\014'*}" ]
+    do
+      # Possibly print before FF
+      HEAD=${LINE%%$'\014'*}
+      [ $DOPRINT == 0 ] || printf %s "$HEAD"$'\014'
+
+      # Next page 
+      P=$(($P + 1))
+      DOPRINT=$(doprint $P)
+
+      # Drop head of line
+      LINE=${LINE#*$'\014'}
+    done
+
+    # Remainder of line
+    [ $DOPRINT == 0 ] || printf "%s\n" "$LINE"
+  done
+)
+
+echo "INFO: Ready" >&2
+exit 0
index 704c9a4be35bafc4b0223fff82b5108ef0d4cc38..433b6fe14aef270b7a78528b1e38ad6f1f32943d 100644 (file)
@@ -85,7 +85,9 @@ getOptionNumber () {
   printf "%s" "$VALUE"
 }
 
+# Printing options: number of copies and page ranges
 [ -z "$NB" ] && NB=1
+PAGERANGES=$(getOption page-ranges)
 
 #
 # Page size
index 660fe33ee398933c47c6eb8dee6fdf4443154fa3..662cf0f4b03f87b310e365c24f80af15632e31fe 100644 (file)
@@ -30,6 +30,9 @@ application/xhtml     application/vnd.cups-brf        10      texttobrf
 application/xml                application/vnd.cups-brf        10      texttobrf
 application/sgml       application/vnd.cups-brf        10      texttobrf
 
+application/vnd.cups-brf       application/vnd.cups-paged-brf  0       brftopagedbrf
+application/vnd.cups-ubrl      application/vnd.cups-paged-ubrl 0       brftopagedbrf
+
 application/vnd.recordare.musicxml+xml application/vnd.cups-brf        30      musicxmltobrf
 
 application/vnd.oasis.opendocument.chart                       application/vnd.cups-brf        30      texttobrf
index a5051d295166e713b434032771599a0258b50c7e..32ee84bd8e91ac939d8ea0039cbf27573338ee64 100644 (file)
@@ -28,6 +28,9 @@ image/vnd.cups-brf
 image/vnd.cups-ubrl
 image/vnd.cups-pdf
 
+application/vnd.cups-paged-brf
+application/vnd.cups-paged-ubrl
+
 application/sgml       sgml
 
 application/vnd.recordare.musicxml+xml xml contains(0,1000,"<score-partwise")