Subject: Presenting: Chinese Chess font/macros for LaTeX

From: [email-masked] (Richer Jacques)
Date: Fri, 11 Mar 1994 21:12:34 GMT

For those of you interested in writing/publishing about Chinese Chess,
and with some knowledge of the TeX typesetting system, here is a font
and LaTeX code for producing quality board drawings, using TeX+LaTeX+dvips.
This text was also sent to the TeX newsgroup. Knowledge of TeX/LaTeX is 
essential.

Over the last few months, I have spent several nights coding a Chinese 
chess (xiangqi) font.  I had a cheap chess set I bought in Montreal's 
Chinatown a long time ago; 
in spite of the fact that I only paid 1US$ for it, its pieces have a 
nice pleasing look.  So I have undertaken to reproduce it as faithfully as I 
could.  The set was made in (communist) China, and bears no copyright 
mark of any kind; in the true communist spirit, I now distribute this font 
to you, and hope no one will try to sue me for it!  

I tried to be true to the original design, although no two pieces of the same
kind really looked the same under close examination.  I had to guess the
intent of the designer.  The model pieces were made of pale wood, about 3/4"
in diameter, with etched characters painted red and dark green.

This was my first serious METAFONT experience, and my lack of 
experience can be seen transpiring throughout the code.  The style of my 
coding evolved slightly as I progressed but I could not afford to redo the 
first pieces; so the code suffers from some inconsistency in style.  I also 
got a little tired in the end, and decided to cut short some 
descriptions; for example, all corners of the earlier pieces are rounded to 
various degrees.  This was intentional: I wanted the font to look like 
painted characters (on the real pieces, paint always produced rounded 
corners, in spite of the etching).  In the last pieces I coded, I used a few 
overlapping paths, which produce sharper corners at intersection points.  I 
kept those to a minimum, using them only for brush strokes that are 
clearly intersecting ones.

I called the pieces RED and BLACK.  The red pieces are generated as black 
on a white background, inside a thin black circle.  The black pieces are 
generated as white on a black circular background, with a thin white 
circle near the edge; these look like negatives of the original green pieces.

For those who might prefer the look of pieces painted on a white 
background (like in the original set), I added a modified copy of the black 
pieces, in which they are generated as black on a white background, 
surrounded by TWO circles;  this gives the edge a much darker look, and 
makes clear the distinction between black and red.  These could be used to 
produce colored pieces on a white background, and still be recognizable if 
printed only in black and white.  I recommend printing the whole font with 
one of the =fonttable.tex= utilities.

I also added two filled pieces that might be useful as masks.

The encoding is a simple and natural one for the regular pieces,
using capital letters for BLACK, lowercase for RED; for the third set of 
pieces (let's call it "alternate-black"), I had to use the remaining letters 
of the alphabet; I opted for consecutive ones.  Here they are, with some of 
their common names:

   K,k,S : king, general,
   G,g,T : guard, assistant
   B,b,U : bishop, elephant
   N,n,V : knight,horse
   R,r,W : rook, chariot, car
   C,c,X : cannon, gun, gunner
   P,p,Y : pawn, foot-soldier

   [J,0: masks  (not part of the game)]

BOARD DRAWING CODE:

If used as ordinary letters in text, the circular pieces will be nearly 
tangent to the baseline.  I defined a macro to place them CENTERED at the 
current point in a picture environment.  With the unit length properly 
chosen, one can then easily draw a Chinese chess board, and place any 
piece at any  board position by simply =\putting= the piece letter  (the 
macro will change the font) at the desired (x,y) integer valued coordinates 
(x=1..9, y=1..10)  (it should be easy to change this to the usual 
numerical/alphabetical notation).

  Example:   \piece{8}{10}{N}    places a black knight in  file 8, rank 10.

I have included a LaTeX file to draw such a board, with each piece in its 
starting position.  Only the last lines need changing (in an obvious way) to 
draw an arbitrary game situation (the board could do with a little decoration
in the river!).

Printer fonts normally behave like dark characters on a ***transparent*** 
background.  When placing a piece on the chessboard, one has to ERASE ANY 
UNDERLYING LINES FIRST. I could not think of a way of doing  this using only 
TeX and/or METAFONT.  So my piece placing macro uses a little bit of 
PostScript code to do this.  For that reason, it will only work with DVI -> 
PS converters that support  dvips=s raw-PS code insertion command 
(\special{! ...} and \special{! ...}).

Unfortunately, the font size (46pt) is presently hardcoded into this LaTeX
file.  To print smaller boards, one would have to change a small number of
dimension parameters (margins, picture unitlength, PS mask size) as well as
the font size.  I have not had time to implement and test automatic scaling
relations at the LaTeX level.

I have set the font normal and quad spaces to the diameter of the pieces,
and the font x height to half that diameter.  These can be used for kerning,
instead of using the width/height/depth of character boxes.  All characters
have the same box dimensions.

THE PACKAGE:

It consists in 3 files, appended at the end of this text, in this order
(look for the "cut here" lines):

1) the LaTeX file  cchessboard.tex  for drawing a starting board 
   (or any other game position)

2) the METAFONT driver file   cchess46.mf   for generating the  46pt cchess 
   font used by  cchessboard.tex

3) the main METAFONT character definition file,  ccpieces.mf

Some comments are in English, some are in French (I like to believe that
my native and favorite language is not dead yet). They are not important
since the whole thing is very simple.

Before I end, I would like to thank Barry Smith, of Blue Sky Research, for 
helping me during my early attempts at generating fonts on a Macintosh 
(MacPlus!), using their METAFONT implementation.

  Jacques Richer, Ph.D.  (Physics)               
  Centre de Recherche en Calcul Applique 
  5160, boul. Decarie, bureau 434,       
  Montreal, PQ, CANADA  H3X 2H9

  TEL: (514) 369-5234
  FAX: (514) 343-3880
  INTERNET: [email-masked]

(my address at work could change very soon)

 Home address:
  7029, rue Marquette
  Montreal, Quebec,
  CANADA  H2E 2C6

cut here------8<------- cchessboard.tex ------8<------------------
cut here------8<---- cchess46.mf ----8<----------------------- 
cut here------8<-----ccpieces.mf-----8<----------------------- 
cut here------8<----------------------8<-----------------------