Package: libpaper1
Version: 1.1.16
Severity: important
Tags: patch

Hi,

as noted in libpaper1.config comments:
  # PROBLEM: it doesn't work for page sizes that aren't exact millimeter 
multiple
  # since libpaper database is using decimal numbers, while i18n database is 
rounded
  # to integer.

Here is a patch.  It fixes other problems too:
 * Title was wrongly set (see #270103).  It is mostly useless, so drop it.
 * Locales can also be selected by $LANG and $LC_ALL environment variables
 * Looking at locale source files is fragile, it does not work with most
   locales.  Use the locale program instead.

Please run debconf-updatepo after applying this patch.

Denis
diff -ur debian.orig/libpaper1.config debian/libpaper1.config
--- debian.orig/libpaper1.config        2006-05-13 16:35:56.000000000 +0200
+++ debian/libpaper1.config     2006-05-17 02:06:54.000000000 +0200
@@ -4,75 +4,23 @@
 
 db_version 2.0
 db_capb backup
-db_settitle libpaper/defaultpaper
 
+paper=
 if [ -f /etc/papersize ]; then
    paper=`head -n 1 /etc/papersize`
-   db_set libpaper/defaultpaper $paper
-
-elif [ -n "$LC_PAPER" ]
-then
-
-   #
-   # Find the name of the i18n locale file
-   #
-
-   if [ -e /usr/share/i18n/locales/"$LC_PAPER" ]
-   then
-       f=/usr/share/i18n/locales/"$LC_PAPER"
-   else
-       nocharset=${LC_PAPER%.*}
-       if [ -e /usr/share/i18n/locales/"$nocharset" ]
-       then
-           f=/usr/share/i18n/locales/"$nocharset"
-       else
-           nocountry=${LC_PAPER%_*}
-           if [ -e /usr/share/i18n/locales/"$nocountry" ]
-           then
-               f=/usr/share/i18n/locales/"$nocountry"
-           fi
-       fi
-   fi
-
-   #
-   # look for pagesize information in that file
-   #
-
-   if [ -n "$f" ]
-   then
-
-      # Look in the locales definition file
-      # for width and height of default paper.
+else
+   loc=${LC_ALL:-${LC_PAPER:-$LANG}}
+   if [ -n "$loc" ] && [ "$loc" != C ]; then
       # This is always in millimeters.
-      wh=$(awk 'BEGIN {noPAP=1;}
-/^LC_PAPER/ {noPAP=0;}
-/^height/   { if (noPAP==0) {h=$2} }
-/^width/   { if (noPAP==0) {w=$2} }
-/^END LC_PAPER/ {print w " mm " h " mm"; exit 0}' "$f" )
-
-      # Next look into libpaper database and see if we find a matching paper 
size
-      # and, eventually, find its name.
-      #
-      # PROBLEM: it doesn't work for page sizes that aren't exact millimeter 
multiple
-      # since libpaper database is using decimal numbers, while i18n database 
is rounded
-      # to integer.
+      wh=$(locale width height 2>/dev/null | tr '\n' ' ' | sed -e 's/ / mm /g' 
| sed -e 's/ $//')
 
-      [ -n "$wh" ] && line=$(paperconf -asm | grep -n "$wh" | sed -e 
's/\(^[^:]*\):.*$/\1/')
-      [ -n "$line" ] && paper=$(paperconf -a | head -$line | head -1)
-      [ -n "$paper" ] && db_set libpaper/defaultpaper $paper
+      # Next look into libpaper database and see if we find a matching
+      # paper size and, eventually, find its name.
+      [ -n "$wh" ] && line=$(paperconf -asm | LC_ALL=C awk '{printf "%d mm %d 
mm\n", $1+0.5, $3+0.5}' | grep -n "$wh" | sed -e 's/\(^[^:]*\):.*$/\1/' -e 1q)
+      [ -n "$line" ] && paper=$(paperconf -a | sed -e ${line}'!d')
    fi
-
-   #
-   # handle special cases
-   #
-
-   case "${LC_PAPER%.*}" in
-       *_US | *_CA)
-           db_set libpaper/defaultpaper letter
-           ;;
-   esac
-
 fi
+[ -n "$paper" ] && db_set libpaper/defaultpaper $paper
 
 db_input medium libpaper/defaultpaper
 db_go
diff -ur debian.orig/libpaper1.templates debian/libpaper1.templates
--- debian.orig/libpaper1.templates     2004-07-16 19:05:50.000000000 +0200
+++ debian/libpaper1.templates  2006-05-17 02:10:25.000000000 +0200
@@ -6,7 +6,3 @@
  Please select which paper size to use as the default on your system.
  Various programs on your system will use this configuration option to
  determine how to print output.  The default is typically correct.
-
-Template: libpaper/title
-Type: title
-_Description: Paper Size Configuration

Reply via email to