groff
[Top][All Lists]
Advanced

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

Re: [Groff] small caps :-)


From: Thomas Baruchel
Subject: Re: [Groff] small caps :-)
Date: Sun, 24 Sep 2000 18:29:49 +0200
User-agent: Mutt/1.2.5i

On Sat, Sep 23, 2000 at 12:04:55AM +0100, Ted Harding wrote:
> On 22-Sep-00 Thomas Baruchel wrote:
> > - soon comes a preprocessor for smallcaps following Adobe specification
> > in the blue book (sorry, Ted, I like your way of solving the
> > problem, but I am not completely happy with the idea of having
> > thiner letters with my small caps).
> 
> Well, a comparison should be interesting ... !

OK : could you have a look at the ps file attached. The troff input was this:
=============================================================================
.ps 16
  .  MAKE-SMALLCAPS \[Hugo] \HUGO
Victor \[Hugo].
.MAKE-SMALLCAPS \[Valentin] \VALENTIN
.MAKE-SMALLCAPS \[ton] \AVALON
\[Valentin] à \[ton]
=============================================================================
the troff code re-arranged by my pre-processor (written in C) has 102 lines :-(

The C code is the following (probably not definitive):
save the code as smallcaps.c
compile it with:
  gcc -o smallcaps smallcaps.c
use it either with the standard input or with a name of a file:
  cat file | ./smallcaps        or       ./smallcaps file
=============================================================================
#include <stdio.h>
/* Choose your language: 1=english 2=french */
#define LANGUAGE 2
#if LANGUAGE == 1
  #define ERRORFILE "Error while opening the file"
  #define ERRORSYN "Syntax error in the .SMALLCAPS definition"
#endif
#if LANGUAGE == 2
  #define ERRORFILE "Erreur dans l'ouverture du fichier"
  #define ERRORSYN "Erreur de syntaxe dans la définition .SMALLCAPS"
#endif


int erreurfile()
{ puts(ERRORFILE);
  exit(0);
}

int erreursyn(int l)
{ fprintf(stderr,"[%d] ",l);
  fprintf(stderr, ERRORSYN);
  fprintf(stderr, "\n");
}

void smallcaps(char nom[80], char arg[255], int lig)
{ int i = 0;
  int l;
  char sc=0;
  char sn=0;
  char c = 0;
  char n = arg[0];
  if (n == '\\')
  { sn = 1;
    n = arg[1];
    if (n == 0) erreursyn(lig);
  }
  puts(".nr mkscXXX \\w'X'");
  printf(".nr mksc%dXmax \\n[rst]\n",lig);
  puts(".nr mkscXXX \\w'x'");
  printf(".nr mksc%dXmin \\n[rst]",lig);
  puts(".rr mkscXXX");
  printf(".char \\[mkscc%dx0]\n",lig);
  for (l=sn; l<strlen(arg); l++)
  { sc = sn;
    sn = 0;
    c = n;
    n = arg[l+1];
    if (n == '\\')
    { sn = 1;
      n = arg[l+2];
      l++;
      if (n == 0) erreursyn(lig);
    }
    i++;
    if (sc ==0)
    { printf(".nr mksc%dx%d (\\w'%c%c'-\\w'%c')*9/10\n",lig,i,c,n,n); }
    else
    { if (sn == 1)
      { printf(".nr mksc%dx%d \\w'%c%c'-\\w'%c'\n",lig,i,c,n,n); }
      else
      { printf(".nr mksc%dx%d (\\w'%c%c'-\\w'%c')*975/1000\n",lig,i,c,n,n); }
    }
    printf(".char \\[mkscc%dx%d] \\[mkscc%dx%d]",lig,i,lig,i-1);
    if (sc == 1)
    { printf("\\Z'%c'\\h'\\n[mksc%dx%d]u'\n",c,lig,i); }
    else
    { printf("\\Z'\\X'ps: exec gsave currentfont \\\n[.9 0 0 ",nom);
      printf("\\n[mksc%dXmin] \\n[mksc%dXmax] \\n[mksc%dXmin] sub",lig,lig,lig);
      printf(" 3 div add \\\n\\n[mksc%dXmax] div 0 0] makefont setfont",lig);
      printf(" (%c) show grestore''\\\n\\h'\\n[mksc%dx%d]u'\n",c,lig,i);
    }
  }
  printf(".char %s \\[mkscc%dx%d]\n",nom,lig,i);
}

int main(int argc, char *argv[])
{ char buf[BUFSIZ];
  char com[80];
  char nom[80];
  char arg[255];
  FILE *fp;
  int i = 0;
  switch(argc)
  { case 1: { fp = stdin; break; }
    case 2: { fp = fopen(argv[1],"r"); break; }
    default: erreurfile(); }
  if (fp == NULL) erreurfile();
  while(fgets(buf,BUFSIZ,fp) != NULL)
  { i++;
    if (sscanf(buf," .%s %s %s",&com,&nom,&arg) > 0)
    { if (strcmp(com,"MAKE-SMALLCAPS") == 0)
      { smallcaps(nom,arg,i);
        buf[0] = 0;
      }
    }
    nom[0] = 0;
    arg[0] = 0;
    printf("%s",buf);
  }
}

Attachment: essai.ps.gz
Description: application/gunzip


reply via email to

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