groff
[Top][All Lists]
Advanced

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

[Groff] fix for bad tables


From: Gaius Mulley
Subject: [Groff] fix for bad tables
Date: Fri, 21 Dec 2001 12:02:42 +0000

Hi,

I believe that this patch should fix the behaviour observed by Rick
and Ralph. Grohtml will now examine devps/DESC and set the appropriate
vertical offset at runtime. I've tested it for letter and A4 on my
machine but it would be good to confirm that this patch works elsewhere.

please test.. Thanks

Gaius


*** groff-cvs/src/preproc/html/pre-html.cc      Mon Dec 10 22:00:54 2001
--- groff-html/src/preproc/html/pre-html.cc     Fri Dec 21 11:47:32 2001
***************
*** 58,71 ****
  #include "html-strings.h"
  
  #define DEFAULT_IMAGE_RES         80   // 80 pixels per inch resolution
! #ifdef PAGEA4
! #  define DEFAULT_VERTICAL_OFFSET  0   // DEFAULT_VERTICAL_OFFSET/72 of an 
inch
! #else
! #  define DEFAULT_VERTICAL_OFFSET 50   // DEFAULT_VERTICAL_OFFSET/72 of an 
inch
! #endif
  #define IMAGE_BOARDER_PIXELS       2
  #define MAX_WIDTH                  8   // inches
  #define INLINE_LEADER_CHAR      '\\'
  
  #define TRANSPARENT  "-background white -transparent white"
  
--- 58,71 ----
  #include "html-strings.h"
  
  #define DEFAULT_IMAGE_RES         80   // 80 pixels per inch resolution
! #define DEFAULT_VERTICAL_OFFSET    0   // DEFAULT_VERTICAL_OFFSET/72 of an 
inch
  #define IMAGE_BOARDER_PIXELS       2
  #define MAX_WIDTH                  8   // inches
  #define INLINE_LEADER_CHAR      '\\'
+ #define A4_LENGTH             841890   // taken from devps/Makefile.sub
+ #define LETTER_LENGTH         792000   // taken from devps/Makefile.sub
+ #define A4_OFFSET                  0
+ #define LETTER_OFFSET             50   // 50/72 of an inch
  
  #define TRANSPARENT  "-background white -transparent white"
  
***************
*** 100,109 ****
  static char *imagePageStem  = NULL;             // stem of all files 
containing page images
  static char *image_device   = "pnmraw";
  static int   image_res      = DEFAULT_IMAGE_RES;
! static int   vertical_offset= DEFAULT_VERTICAL_OFFSET;
  static char *image_template = NULL;             // image template filename
  static int   troff_arg      = 0;                // troff arg index
  static char *image_dir      = NULL;             // user specified image 
directory
  #if defined(DEBUGGING)
  static int   debug          = FALSE;
  static char *troffFileName  = NULL;             // output of pre-html output 
which is sent to troff -Tps
--- 100,110 ----
  static char *imagePageStem  = NULL;             // stem of all files 
containing page images
  static char *image_device   = "pnmraw";
  static int   image_res      = DEFAULT_IMAGE_RES;
! static int   vertical_offset= 0;
  static char *image_template = NULL;             // image template filename
  static int   troff_arg      = 0;                // troff arg index
  static char *image_dir      = NULL;             // user specified image 
directory
+ static char *gsPaper        = NULL;             // the paper size that gs 
must use
  #if defined(DEBUGGING)
  static int   debug          = FALSE;
  static char *troffFileName  = NULL;             // output of pre-html output 
which is sent to troff -Tps
***************
*** 139,155 ****
   *  get_resolution - returns the postscript resolution from devps/DESC
   */
  
! static int get_resolution (void)
  {
    char *pathp;
    FILE *f;
!   unsigned long int res;
    int n;
    int c;
    f = font_path.open_file("devps/DESC", &pathp);
    if (f == 0) sys_fatal("fopen");
    while (1) {
!     n = fscanf(f, " res %lu", &res);
      if (n < 0) sys_fatal("EOF");
      if (n >= 1) {
        fclose(f);
--- 140,156 ----
   *  get_resolution - returns the postscript resolution from devps/DESC
   */
  
! static unsigned int get_resolution (void)
  {
    char *pathp;
    FILE *f;
!   unsigned int res;
    int n;
    int c;
    f = font_path.open_file("devps/DESC", &pathp);
    if (f == 0) sys_fatal("fopen");
    while (1) {
!     n = fscanf(f, " res %u", &res);
      if (n < 0) sys_fatal("EOF");
      if (n >= 1) {
        fclose(f);
***************
*** 161,166 ****
--- 162,213 ----
  }
  
  /*
+  *  get_papersize - returns an integer determining the paper length from 
devps/DESC
+  */
+ 
+ static int get_papersize (void)
+ {
+   char *pathp;
+   FILE *f;
+   int res;
+   int n;
+   int c;
+   f = font_path.open_file("devps/DESC", &pathp);
+   if (f == 0) sys_fatal("fopen");
+   while (1) {
+     n = fscanf(f, " paperlength %d", &res);
+     if (n < 0) sys_fatal("EOF");
+     if (n >= 1) {
+       fclose(f);
+       return res;
+     }
+     while (( c = getc(f) ) != '\n')
+       if (c == EOF) sys_fatal("EOF");
+   }
+ }
+ 
+ /*
+  *  determine_vertical_offset - works out the default vertical offset from
+  *                              the page length
+  */
+ 
+ static void determine_vertical_offset (void)
+ {
+   int length      = get_papersize();
+   int near_a4     = abs(A4_LENGTH-length);
+   int near_letter = abs(LETTER_LENGTH-length);
+ 
+   if (near_a4 < near_letter) {
+     vertical_offset = A4_OFFSET;
+     gsPaper = "-sPAPERSIZE=a4";
+   }
+   else {
+     vertical_offset = LETTER_OFFSET;
+     gsPaper = "-sPAPERSIZE=a4";
+   }
+ }
+ 
+ /*
   *  html_system - a wrapper for system()
   */
  
***************
*** 734,742 ****
    }
  
    s = make_message("echo showpage | "
!                  "gs%s -q -dSAFER -sDEVICE=%s -r%d "
                   "-sOutputFile=%s/%%d %s -",
                   EXE_EXT,
                   image_device,
                   image_res,
                   imagePageStem,
--- 781,790 ----
    }
  
    s = make_message("echo showpage | "
!                  "gs%s %s -q -dSAFER -sDEVICE=%s -r%d "
                   "-sOutputFile=%s/%%d %s -",
                   EXE_EXT,
+                  gsPaper,
                   image_device,
                   image_res,
                   imagePageStem,
***************
*** 1233,1238 ****
--- 1281,1287 ----
        break;
      case 'o':
        vertical_offset = atoi(optarg);
+       gsPaper = "";  // do not specify the paper size now
        break;
      case 'd':
  #if defined(DEBUGGING)
***************
*** 1322,1327 ****
--- 1371,1377 ----
    int found=0;
    int ok=1;
  
+   determine_vertical_offset();
    i = scanArguments(argc, argv);
    postscriptRes = get_resolution();
    checkImageDir();

reply via email to

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