• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/sh
2
3# This script generates the CustomMedia lines for the Generic IPP
4# Everywhere Printer PPD file in cupsfilters.drv based on the paper
5# size info in cups/pwg-media.c of the CUPS source code.
6
7# The script needs sed and bc
8
9while read line; do
10    if printf "%s" "$line" | grep -q '^_PWG_MEDIA_'; then
11	eval "$(printf "%s" "$line" | sed -nre 's/^_PWG_MEDIA_(\S+)\((\S+),\s*(\S+),\s*(\S+),\s*(\S+),\s*(\S+)\s*\)\s*,?\s*$/unit="\1"; pwgname="\2"; ippname="\3"; ppdname="\4"; width="\5"; height="\6"/p')"
12	if [ "$unit" = "IN" ]; then
13	    widthpt="$(printf "scale=8; (%s)*72.0\n" "$width" | bc)"
14	    heightpt="$(printf "scale=8; (%s)*72.0\n" "$height" | bc)"
15	fi
16	if [ "$unit" = "MM" ]; then
17	    widthpt="$(printf "scale=8; (%s)*72.0/25.4\n" "$width" | bc)"
18	    heightpt="$(printf "scale=8; (%s)*72.0/25.4\n" "$height" | bc)"
19	fi
20	if [ "$ppdname" != "NULL" ]; then
21	    shortname="$ppdname"
22	elif [ "$ippname" != "NULL" ]; then
23	    shortname="$ippname"
24	elif [ "$pwgname" != "NULL" ]; then
25	    shortname="$pwgname"
26	else
27	    continue
28	fi
29	if [ "$ppdname" != "NULL" ]; then
30	    longname="$ppdname"
31	elif [ "$ippname" != "NULL" ]; then
32	    longname="$ippname"
33	elif [ "$pwgname" != "NULL" ]; then
34	    longname="$pwgname"
35	else
36	    continue
37	fi
38      	#printf "%s %s %s %f %f %s %.0f %.0f PT %s/%s\n" $pwgname $ippname $ppdname $width $height $unit $widthpt $heightpt $shortname $longname
39	printf "  CustomMedia \"%s/%s\" %.2f %.2f 0 0 0 0 \"<</PageSize[%.2f %.2f]/ImagingBBox null>>setpagedevice\"\n\t\"<</PageSize[%.2f %.2f]/ImagingBBox null>>setpagedevice\"\n" $shortname $longname $widthpt $heightpt $widthpt $heightpt $widthpt $heightpt
40    fi
41done
42