bug-groff
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: setting page size


From: Werner LEMBERG
Subject: Re: setting page size
Date: Thu, 28 Dec 2000 12:18:24 +0100 (CET)

> Sorry for being dense, but I can't figure out how to set the output
> page size.  I want to create letter and A4 PS versions of some of
> our man pages.  Can someone loan me a clue?

[I'm talking about groff version 1.16.1.]

Currently, there is no possibility to do that at run-time.  I've got a
patch already from Ruslan which I can't apply yet due to
not-yet-received copyright assignment papers (this is a real nuisance,
I know, but one of the rules of GNU).  See below for his changes.

Without this patch, you have to manually edit the file font/devps/DESC
to switch the paperlength between 792000 (for Letter) and 841890 (for
A4).  In addition, you must add `-ma4' to groff's command line to set
up correct page dimensions:

  groff -Tps -ma4 -man -rC1 -rD1 -rS11 foo.man bar.man ... > manuals.ps

`-rC1' assures that you have continuous page numbering if you call
more than one manual page, `-rD1' will activate headers for
double-sided printing, and `-rS11' will select 11pt font size.

Check groff_man.man or groff.texinfo for a complete reference to man.


    Werner


======================================================================


DESCRIPTION OF INCORRECT BEHAVIOUR:
grops(1) does not allow run-time configuration of page length as
grolj4(1) and grolbp(1) do.  It also does not provide -p option.
Ideally, all these postprocessors should have the ability to set
paper size from the system-wide file, e.g. /etc/papersize.
Currently, only grolbp(1) allows this.

SUGGESTED FIX:
Index: ps.cc
===================================================================
RCS file: /home/ncvs/src/contrib/groff/grops/ps.cc,v
retrieving revision 1.1.1.3
diff -p -c -r1.1.1.3 ps.cc
*** ps.cc       2000/12/05 18:49:34     1.1.1.3
--- ps.cc       2000/12/13 14:44:26
*************** static int guess_flag = 0;
*** 38,43 ****
--- 38,52 ----
  static int bflag = 0;
  unsigned broken_flags = 0;
  
+ static struct {
+   const char *name;
+   int size;
+ } paper_table[] = {
+   { "letter", 792000 },
+   { "A4", 841890 },
+ };
+ static int paper_length = -1;
+ 
  #define DEFAULT_LINEWIDTH 40  /* in ems/1000 */
  #define MAX_LINE_LENGTH 72
  #define FILL_MAX 1000
*************** void ps_font::handle_unknown_font_comman
*** 404,409 ****
--- 413,427 ----
    }
  }
  
+ static
+ int lookup_paper_length(const char *s)
+ {
+   for (int i = 0; i < sizeof(paper_table)/sizeof(paper_table[0]); i++) {
+     if (strcasecmp(s, paper_table[i].name) == 0)
+       return paper_table[i].size;
+   }
+   return -1;
+ }
  static void handle_unknown_desc_command(const char *command, const char *arg,
                                        const char *filename, int lineno)
  {
*************** static void handle_unknown_desc_command(
*** 414,419 ****
--- 432,450 ----
      else if (!bflag)
        broken_flags = atoi(arg);
    }
+   else if (strcmp(command, "papersize") == 0) {
+     if (arg == 0)
+       error_with_file_and_line(filename, lineno,
+                              "`papersize' command requires an argument");
+     else if (paper_length < 0) {
+       int n = lookup_paper_length(arg);
+       if (n < 0)
+       error_with_file_and_line(filename, lineno,
+                                "unknown paper size `%1'", arg);
+       else
+       paper_length = n;
+     }
+   }
  }
  
  struct style {
*************** class ps_printer : public printer {
*** 453,459 ****
    int res;
    int space_char_index;
    int pages_output;
-   int paper_length;
    int equalise_spaces;
    enum { SBUF_SIZE = 256 };
    char sbuf[SBUF_SIZE];
--- 484,489 ----
*************** ps_printer::ps_printer()
*** 544,550 ****
    res = r;
    out.set_fixed_point(point);
    space_char_index = font::name_to_index("space");
!   paper_length = font::paperlength;
    if (paper_length == 0)
      paper_length = 11*font::res;
    equalise_spaces = font::res >= 72000;
--- 574,581 ----
    res = r;
    out.set_fixed_point(point);
    space_char_index = font::name_to_index("space");
!   if (paper_length < 0)
!     paper_length = font::paperlength;
    if (paper_length == 0)
      paper_length = 11*font::res;
    equalise_spaces = font::res >= 72000;
*************** int main(int argc, char **argv)
*** 1475,1481 ****
    static char stderr_buf[BUFSIZ];
    setbuf(stderr, stderr_buf);
    int c;
!   while ((c = getopt(argc, argv, "F:glmc:w:vb:")) != EOF)
      switch(c) {
      case 'v':
        {
--- 1506,1512 ----
    static char stderr_buf[BUFSIZ];
    setbuf(stderr, stderr_buf);
    int c;
!   while ((c = getopt(argc, argv, "F:glmc:p:w:vb:")) != EOF)
      switch(c) {
      case 'v':
        {
*************** int main(int argc, char **argv)
*** 1499,1504 ****
--- 1530,1544 ----
      case 'm':
        manual_feed_flag = 1;
        break;
+     case 'p':
+       {
+       int n = lookup_paper_length(optarg);
+       if (n < 0)
+         error("unknown paper size `%1'", optarg);
+       else
+         paper_length = n;
+       break;
+       }
      case 'F':
        font::command_line_font_dir(optarg);
        break;



reply via email to

[Prev in Thread] Current Thread [Next in Thread]