From 4eeb254e1e7e63dbbde76d0917ba6e26ba81c13d Mon Sep 17 00:00:00 2001 From: Michael Prokop Date: Sun, 18 Mar 2007 19:35:15 +0100 Subject: [PATCH] Added alignmargins --- debian/changelog | 8 ++ debian/dirs | 1 + debian/rules | 3 +- manpages/alignmargins.8 | 27 +++++ manpages/getsf.1 | 2 +- manpages/grml-iptstate.8 | 2 +- manpages/grml-setkeyboard.8 | 2 +- manpages/grml-setlang.8 | 2 +- manpages/grml-setservices.8 | 2 +- manpages/gsuggest.1 | 2 +- manpages/gtf.1 | 2 +- manpages/random-hostname.1 | 2 +- usr_sbin/alignmargins | 275 ++++++++++++++++++++++++++++++++++++++++++++ usr_share/align.ps | 227 ++++++++++++++++++++++++++++++++++++ 14 files changed, 548 insertions(+), 9 deletions(-) create mode 100644 manpages/alignmargins.8 create mode 100755 usr_sbin/alignmargins create mode 100644 usr_share/align.ps diff --git a/debian/changelog b/debian/changelog index 15244ee..f8c7abe 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,11 @@ +grml-scripts (0.9.32) unstable; urgency=low + + * Added alignmargins (adjust the margins and the position of the printed + contents on the paper). Thanks for suggestion, Moritz Augsburger! + [Closes: issue146] + + -- Michael Prokop Sun, 18 Mar 2007 19:34:12 +0100 + grml-scripts (0.9.31) unstable; urgency=low * Added xlockmore to suggests, added check for vlock in grml-lock. diff --git a/debian/dirs b/debian/dirs index d53d4bb..1063344 100644 --- a/debian/dirs +++ b/debian/dirs @@ -4,3 +4,4 @@ etc/postfix usr/bin usr/sbin sbin +usr/share/grml-scripts diff --git a/debian/rules b/debian/rules index 5c40c09..badd419 100755 --- a/debian/rules +++ b/debian/rules @@ -33,6 +33,7 @@ install: build # Add here commands to install the package into debian/grml-scripts. cp usr_bin/* debian/grml-scripts/usr/bin/ cp usr_sbin/* debian/grml-scripts/usr/sbin/ + cp usr_share/* debian/grml-scripts/usr/share/grml-scripts/ cp makefile.postfix debian/grml-scripts/etc/postfix/Makefile install -m 755 compile/align debian/grml-scripts/usr/bin/align install -m 755 compile/cpu-screen debian/grml-scripts/usr/bin/cpu-screen @@ -56,7 +57,7 @@ binary-arch: build install dh_installman manpages/grml-scripts.1 manpages/reread_partition_table.8 manpages/gtf.1 manpages/random-hostname.1 \ manpages/grml-setkeyboard.8 manpages/grml-setlang.8 manpages/getsf.1 manpages/grml-iptstate.8 manpages/qma.1 manpages/grml-swapon.8 \ manpages/grml2ram.8 manpages/gsuggest.1 manpages/dirvish-setup.8 manpages/grml-setservices.8 manpages/grml-quickconfig.8 \ - manpages/iso-term.1 + manpages/iso-term.1 manpages/alignmargins.8 # cp --no-dereference man/*.1.gz debian/grml-scripts/usr/share/man/man1/ dh_link /usr/sbin/blacklist /usr/sbin/unblacklist \ /usr/share/man/man1/grml-scripts.1.gz /usr/share/man/man1/align.1.gz \ diff --git a/manpages/alignmargins.8 b/manpages/alignmargins.8 new file mode 100644 index 0000000..92515d8 --- /dev/null +++ b/manpages/alignmargins.8 @@ -0,0 +1,27 @@ +.TH alignmargins 8 +.SH "NAME" +alignmargins \- adjust the margins and the position of the printed contents on the paper +.SH SYNOPSIS +.B alignmargins [/path/to/align.ps] +.SH DESCRIPTION +This manual page documents briefly the +.B alignmargins +command. +.SH OPTIONS +alignmargins does not support any options. +.SH PURPOSE OF alignmargins +With this program you can adjust the margins and the position of the +printed contents on the paper. This way you get well-centered printouts and +you can make use of the whole imageable area of your printer, The driver +settings are overridden when this adjustment is used. + +This is especially important when your printer is used with a driver for +another printer to which yours is compatible (for example many laser +printers are compatible to the HP LaserJet printers). Your printer prints +with this driver, but the non-printable margins are usually different or the +contents is even not centered. With this program you can fix these problems +.SH AUTHOR +alignmargins was written by Till Kamppeter. +.PP +This manual page was written by Michael Prokop + for the grml project (but may be used by others). diff --git a/manpages/getsf.1 b/manpages/getsf.1 index ca9fb5f..7961f91 100644 --- a/manpages/getsf.1 +++ b/manpages/getsf.1 @@ -25,4 +25,4 @@ Download htop version 0.6.3 from mirror puzzle. getsf was written by Michael Prokop . .PP This manual page was written by Michael Prokop - for the Debian project (but may be used by others). + for the grml project (but may be used by others). diff --git a/manpages/grml-iptstate.8 b/manpages/grml-iptstate.8 index 203fa34..013b597 100644 --- a/manpages/grml-iptstate.8 +++ b/manpages/grml-iptstate.8 @@ -21,4 +21,4 @@ to load it (just answer with yes or no, by default yes will be assumed). grml-iptstate was written by Michael Prokop . .PP This manual page was written by Michael Prokop - for the Debian project (but may be used by others). + for the grml project (but may be used by others). diff --git a/manpages/grml-setkeyboard.8 b/manpages/grml-setkeyboard.8 index 038936e..9fea2b1 100644 --- a/manpages/grml-setkeyboard.8 +++ b/manpages/grml-setkeyboard.8 @@ -22,4 +22,4 @@ Invoke the interface. grml-setkeyboard was written by Michael Prokop . .PP This manual page was written by Michael Prokop - for the Debian project (but may be used by others). + for the grml project (but may be used by others). diff --git a/manpages/grml-setlang.8 b/manpages/grml-setlang.8 index 71433d4..ecddc8b 100644 --- a/manpages/grml-setlang.8 +++ b/manpages/grml-setlang.8 @@ -28,4 +28,4 @@ Write austrian environment variables LANGUAGE, LANG, LC_MESSAGES, COUNTRY, CHARS grml-setlang was written by Michael Prokop . .PP This manual page was written by Michael Prokop - for the Debian project (but may be used by others). + for the grml project (but may be used by others). diff --git a/manpages/grml-setservices.8 b/manpages/grml-setservices.8 index 45b376f..61f41d4 100644 --- a/manpages/grml-setservices.8 +++ b/manpages/grml-setservices.8 @@ -27,4 +27,4 @@ Invoke the interface. grml-setservices was written by Michael Prokop . .PP This manual page was written by Michael Prokop - for the Debian project (but may be used by others). + for the grml project (but may be used by others). diff --git a/manpages/gsuggest.1 b/manpages/gsuggest.1 index 7bbaf80..b0e8679 100644 --- a/manpages/gsuggest.1 +++ b/manpages/gsuggest.1 @@ -22,4 +22,4 @@ gsuggest.pl does not support any options. gsuggest.pl was written by Michael Prokop . .PP This manual page was written by Michael Prokop -for the Debian project (but may be used by others). +for the grml project (but may be used by others). diff --git a/manpages/gtf.1 b/manpages/gtf.1 index 6a4da0e..6b54a0e 100644 --- a/manpages/gtf.1 +++ b/manpages/gtf.1 @@ -31,4 +31,4 @@ gtf was written by Andy Ritger . Taken from http://osdn.dl.sourceforge.net/sourceforge/gtf/gtf.c .PP This manual page was written by #USERNAME# <#EMAIL#>, -for the Debian project (but may be used by others). +for the grml project (but may be used by others). diff --git a/manpages/random-hostname.1 b/manpages/random-hostname.1 index 1cf7b19..e5b727b 100644 --- a/manpages/random-hostname.1 +++ b/manpages/random-hostname.1 @@ -17,4 +17,4 @@ Print a random hostname to stdout. random-hostname was written by Michael Prokop . .PP This manual page was written by Michael Prokop - for the Debian project (but may be used by others). + for the grml project (but may be used by others). diff --git a/usr_sbin/alignmargins b/usr_sbin/alignmargins new file mode 100755 index 0000000..3dcccb2 --- /dev/null +++ b/usr_sbin/alignmargins @@ -0,0 +1,275 @@ +#! /usr/bin/perl +# Filename: alignmargins +# Purpose: adjust the margins and the position of the printed contents on the paper +# Authors: (C) 2001 by Till Kamppeter +# Bug-Reports: see http://grml.org/bugs/ +# License: Free software under the terms of the GNU General Public License (GPL) +# Latest change: Son Mär 18 19:31:15 CET 2007 [mika] +################################################################################ +# Downloaded from http://www.linuxprinting.org/download/printing/alignmargins + +$0 =~ m!^(.*)/[^/]+$!; +my $programpath = $1; +my $printcommand = '/usr/bin/lpr -P '; +my $egrep = '/bin/egrep'; +my $cat = '/bin/cat'; +my $cut = '/usr/bin/cut'; +my $head = '/usr/bin/head'; +my $tail = '/usr/bin/tail'; +my $wc = '/usr/bin/wc'; +my $adjustmentpagename = 'align.ps'; +my $adjustmentpagepath = ($programpath ? "${programpath}:" : "") . '.:~:/usr/share/grml-scripts:/usr/share/alignmargins:/usr/local/share/alignmargins:/usr/share:/usr/local/share:/usr/share/printer-testpages:/usr/local/share/printer-testpages:/usr/share/ghostscript/*/lib:/usr/local/share/ghostscript/*/lib'; +my $ppddir = '/etc/cups/ppd'; +my $printerconffile = '/etc/cups/printers.conf'; + +# Find "ælign.ps" + +my $adjustmentpage; +for $path (split(":", $adjustmentpagepath)) { + if (-r "$path/$adjustmentpagename") { + $adjustmentpage = "$path/$adjustmentpagename"; + last; + } +} + +# Are we running as root? + +if (!(-w $printerconffile)) {die "\"alignmargins\" must be run logged in as \"root\"!";} + +# Check whether there are local printer queues + +open NUMBEROFQUEUES, "$cat $printerconffile | $egrep '; +close NUMBEROFQUEUES; + +# Ask the user which printer he wants to align + +print "\n"; +print "CUPS printer margin and offset alignment\n"; +print "----------------------------------------\n"; +print "\n"; +print "(C) 2001 by Till Kamppeter\n"; +print "Free software under the terms of the GNU General Public License (GPL)\n"; +my $queue = ""; + +do { + print "\n"; + print "With this program you can adjust the margins and the position of the\n"; + print "printed contents on the paper. This way you get well-centered printouts and\n"; + print "you can make use of the whole imageable area of your printer, The driver\n"; + print "settings are overridden when this adjustment is used.\n"; + print "\n"; + print "This is especially important when your printer is used with a driver for\n"; + print "another printer to which yours is compatible (for example many laser\n"; + print "printers are compatible to the HP LaserJet printers). Your printer prints\n"; + print "with this driver, but the non-printable margins are usually different or the\n"; + print "contents is even not centered. With this program you can fix these problems\n"; + print "\n"; + print "The program can only be applied to local printer queues. The following\n"; + print "queues are available:\n"; + print "\n"; + + system "$cat $printerconffile | $egrep '' -f 1 | $cat -n"; + + print "\n"; + print "Please enter the number of the desired printer and make sure that it is\n"; + print "connected to your computer and turned on.\n"; + print "\n"; + + print "Number: "; + my $input = ; + + if ( $input =~ m/^\s*(\d+)\D*/ ) { + my $number = $1; + if (($number > 0) && ($number <= $nqueues)) { + open QUEUE, "$cat $printerconffile | $egrep '' -f 1| $head -$number | $tail -1 |"; + if (!$?) { + $queue = ; + close QUEUE; + } + } + } else { + print "\nWrong input, try again!\n"; + } +} until ($queue ne ""); + +chomp $queue; + +print "\n"; +print "Printing margin/offset adjustment page ...\n"; +print "\n"; + +# The "%!" which is needed in a file to be recognized as a PostScript file +# is missing in the adjustment page, therefore it is preceeded to the file +# here. +if (system "(echo %!; $cat $adjustmentpage) | $printcommand$queue") { +die "Could not print the adjustment page."; +} + +print "Please read the instructions on the margin adjustment page and determine the\n"; +print "six numbers mentioned there. If you measure in cm and not in inches, devide\n"; +print "the measured quantities by 2.54 before you insert them into the equations\n"; +print "shown on the page. You do not need to create any file with PostScript\n"; +print "commands, this program will insert your settings into your printer's\n"; +print "configuration.\n"; +print "\n"; +print "If the adjustment page did not come out of your printer, this method cannot\n"; +print "be applied, press Ctrl + C to stop this program. This can especially happen\n"; +print "with very old PostScript printers.\n"; +print "\n"; +print "Note also that this adjustment does not necessarily work with every driver.\n"; +print "The concept is taken from GhostScript and the implementation of this program\n"; +print "is not much tested yet.\n"; +print "\n"; + +print "Please enter your results now:\n"; +print "\n"; + +my $ml = 9999999.; +my $mb = 9999999.; +my $mr = 9999999.; +my $mt = 9999999.; +my $x = 9999999.; +my $y = 9999999.; + +do { + print "ml: "; + my $input = ; + + if ( $input =~ m/^\s*([+-]?[\d\.]+)\D*/ ) { + my $number = $1; + if (($number >= -100000) && ($number <= 100000)) { + $ml = $number * 1.; + } + } else { + print "Wrong input, try again!\n"; + } +} until ($ml != 9999999.); + +do { + print "mb: "; + my $input = ; + + if ( $input =~ m/^\s*([+-]?[\d\.]+)\D*/ ) { + my $number = $1; + if (($number >= -100000) && ($number <= 100000)) { + $mb = $number * 1.; + } + } else { + print "Wrong input, try again!\n"; + } +} until ($mb != 9999999.); + +do { + print "mr: "; + my $input = ; + + if ( $input =~ m/^\s*([+-]?[\d\.]+)\D*/ ) { + my $number = $1; + if (($number >= -100000) && ($number <= 100000)) { + $mr = $number * 1.; + } + } else { + print "Wrong input, try again!\n"; + } +} until ($mr != 9999999.); + +do { + print "mt: "; + my $input = ; + + if ( $input =~ m/^\s*([+-]?[\d\.]+)\D*/ ) { + my $number = $1; + if (($number >= -100000) && ($number <= 100000)) { + $mt = $number * 1.; + } + } else { + print "Wrong input, try again!\n"; + } +} until ($mt != 9999999.); + +do { + print "x: "; + my $input = ; + + if ( $input =~ m/^\s*([+-]?[\d\.]+)\D*/ ) { + my $number = $1; + if (($number >= -100000) && ($number <= 100000)) { + $x = $number * 1.; + } + } else { + print "Wrong input, try again!\n"; + } +} until ($x != 9999999.); + +do { + print "y: "; + my $input = ; + + if ( $input =~ m/^\s*([+-]?[\d\.]+)\D*/ ) { + my $number = $1; + if (($number >= -100000) && ($number <= 100000)) { + $y = $number * 1.; + } + } else { + print "Wrong input, try again!\n"; + } +} until ($y != 9999999.); + +my $ppdfilename = "$ppddir/$queue.ppd"; +print "\n"; +print "Saving your settings in $ppdfilename ...\n"; +print "\n"; + +my @marginsoption = ( + "*OpenUI *Margins/Page Margins/Offsets: PickOne\n", + "*DefaultMargins: Custom\n", + "*Margins Default/Driver Default: \"\"\n", + "*Margins Custom/Custom (set with 'alignmargins'): \"<>setpagedevice\"\n", + "*CloseUI: *Margins\n" +); + +# Read PPD file of the chosen printer + +if (!(-f $ppdfilename)) {die "No PPD file $ppdfilename!"}; +open PPDFILE, "$ppdfilename" or die "Can't open $ppdfilename!"; +my @ppdfile = ; +close PPDFILE; + +# Remove an old margin adjustment option + +($_ =~ m!^\s*\*OpenUI\s*\*Margins/.*:! and $_="") foreach @ppdfile; +($_ =~ m!^\s*\*DefaultMargins:! and $_="") foreach @ppdfile; +($_ =~ m!^\s*\*Margins\s*.*/.*:! and $_="") foreach @ppdfile; +($_ =~ m!^\s*\*CloseUI:\s*\*Margins! and $_="") foreach @ppdfile; + +# Insert the new margin adjustment option + +splice(@ppdfile,-1,0,@marginsoption); + +# Write back PPD file + +open PPDFILE, ">$ppdfilename" or die "Can't open $ppdfilename"; +print PPDFILE @ppdfile; +close PPDFILE; + +# Re-initialize CUPS (must be done after a "manual" change on the PPD file) + +system("killall -HUP cupsd"); + +print "\n"; +print "Done.\n"; +print "\n"; +print "Now your printer \"$queue\" will use the new margin and offset settings by\n"; +print "default. You can turn them off by switching the option \"Page Margins/Offsets\"\n"; +print "to \"Driver Default\" in kprinter, GTKlp, or XPP.\n"; +print "\n"; +print "On the command line (\"lpr\", \"lp\", \"lpoptions\", ...) use the option\n"; +print "\"-o Margins=Default\" to turn off and \"-o Margins=Custom\" to turn on your\n"; +print "settings.\n"; +print "\n"; + +exit 0; + +## END OF FILE ################################################################# diff --git a/usr_share/align.ps b/usr_share/align.ps new file mode 100644 index 0000000..2e0d816 --- /dev/null +++ b/usr_share/align.ps @@ -0,0 +1,227 @@ +%!PS-Adobe-3.0 +%%Pages: 1 +%%Title: Alignment testpage for Ghostscript +%%Creator: Dieter Stueken () +%%BeginProlog +% Source: http://www.geocrawler.com/archives/3/378/1997/1/50/2064509/ + +/rectdraw % rectdraw - + { exch 4 -1 roll exch 2 array astore {0 moveto 0 PH rlineto stroke} forall + 2 array astore {0 exch moveto PW 0 rlineto stroke} forall + } bind def + +/arrow % arrow + { gsave translate rotate + 0 0 moveto 20 60 lineto -20 60 lineto closepath stroke + 0 0 moveto 0 80 lineto stroke + grestore + } bind def + +/triangle { % len ang x y + gsave translate dup rotate exch + 0 setlinewidth + 0 0 moveto + dup 0 lineto + dup 0.98 mul dup 10 div lineto + closepath + gsave 0.65 setgray fill grestore stroke + 100 10 moveto + 100 100 2 index { + gsave 0 -12 rmoveto 0 24 rlineto stroke grestore + gsave 0 24 rmoveto 10 div 2 index neg rotate + cvi =string cvs -6 -4 rmoveto show grestore + 100 10 rmoveto + } for + 0 0 moveto + 0 10 2 index { + pop + gsave 0 -6 rmoveto 0 12 rlineto stroke grestore + 10 1 rmoveto + } for + pop pop + grestore +} bind def + +/round {dup 3 1 roll mul cvi exch div} def + +/Show { % print value or unfold array + dup type /realtype eq {100 round} if + dup type /nulltype eq + { pop (-NULL-) show} + {dup type /arraytype eq + { ([ ) show {Show} forall ( ]) show} + {=string cvs show ( ) show} + ifelse } + ifelse +} bind def + +/Pval { % key val, move down 1 line + gsave exch + gsave Show (:) show grestore + 150 0 rmoveto Show + grestore + 0 -12 rmoveto +} bind def + +/showtext { + /S 80 string def + { currentfile S readline pop dup (%END) eq { pop exit } if + gsave show grestore 0 -12 rmoveto + } loop +} bind def + +/.knownget { 2 copy known { get true } { pop pop false } ifelse } bind def + +%%EndProlog +%%BeginSetup + +% you may try different settings here, but start with default settings first +%<< +% /.HWMargins [8.5 38.0 10.5 12.5] +% /Margins [-35 -51] +%>> setpagedevice +% + +%%EndSetup +%%Page: 1 + +% printout all values + +/Helvetica findfont +12 scalefont setfont +120 756 moveto + +showtext +Current settings: + +%END + +[/OutputDevice + /Margins + /.HWMargins + /.MarginsHWResolution + /HWResolution + /PageOffset + /PageSize +] { currentpagedevice 1 index + .knownget not {(-undefined-)} if Pval +} forall + +showtext + +Graphics alignment: + +Let the distance in inches from the left edge of the page to the +vertical line be H, and from the bottom edge to the horizontal line +be V. You may define the alignment of your page to the paper by + + << /Margins [x y] >> setpagedevice +with +%END + +gsave +/res currentpagedevice /.MarginsHWResolution .knownget not {600} if def +( x = (1 - H) * ) show res 0 get =string cvs show +(, y = (V - 1) * ) show res 1 get =string cvs show +grestore 0 -12 rmoveto + +showtext + +If set correctly the drawn arrows should extend into the +papers corners (not the clipping corners). After archieving +that, you may continue with the clipping edges. + +The clipping edges may be set by + + << /.HWMargins [ml mb mr mt] >> setpagedevice + +where [ml mb mr mt] are the distances of the clipped edges of +your graphics relative to the papers edges (left bottom right top) +measured in 1/72 inches. The wedge shaped rules may be used to +define these values very accurately as its intersections are in +1/72 inches. Take the value at the cutoff point from the scale to +the next clockwise edge. + +Start setting the margin values to all zero to see the natural hardware +clipping of your printer. You should then define the margins just as big +enough to keep the defined margins within your printers real hardware +clipping. This is archieved if you can see the thin line drawn all around +your defined margin. In addition the thin drawn arrows are just touching +the margin and should be totally visible. + +When you put this settings into your inititializing file "gs_init.ps" +you may want to apply this setting to a specific printer device only. +Here is an example of a printer specific setup: + +<< + /ljet4 << % make entries for some device + /.HWMargins [16.0 13.2 13.0 11.1] + /Margins [-132 -92] + >> + /ljet2p << % and for an other devices, too + /.HWMargins [14.4 6.8 14.5 17.5] + /Margins [-60 -23] + >> +>> currentpagedevice /OutputDevice get +.knownget {setpagedevice} if +%END + +% get page size +currentpagedevice /PageSize get aload pop +/PH exch def +/PW exch def + +1 setlinewidth +PW 0 0 0 triangle +PH 90 PW 0 triangle +PW 180 PW PH triangle +PH 270 0 PH triangle + +% get clipping values +clippath pathbbox newpath + +% show clipping box +gsave +1 setlinewidth % 0.65 setgray +4 copy rectdraw +grestore + +/CT exch def +/CR exch def +/CB exch def +/CL exch def + +% draw the alignment lines +0 setlinewidth +72 0 moveto 0 CT rlineto stroke +0 72 moveto CR 0 rlineto stroke + +2 setlinewidth +1 setlinejoin +1 setlinecap + +0 200 moveto 71 0 rlineto -24 -12 rlineto 0 24 rlineto 24 -12 rlineto stroke +34 206 moveto (H) show + +144 0 moveto 0 71 rlineto -12 -24 rlineto 24 0 rlineto -12 24 rlineto stroke +150 34 moveto (V) show + + +% draw arrows into to the papers corners +1 setlinewidth +45 +90 sub dup 0 0 arrow +90 sub dup 0 PH arrow +90 sub dup PW PH arrow +90 sub dup PW 0 arrow +pop %45 + +% draw arrows touching the clipping edges +0 setlinewidth + 0 PW 2 div CB arrow +180 PW 2 div CT arrow +-90 CL PH 2 div arrow + 90 CR PH 2 div arrow + +showpage +%%EOF \ No newline at end of file -- 2.1.4