Thursday, 5 November 2020

Using the Chess Alpha Font


I modified my Python program to use my fixed version of the Chess Alpha font. As you can see, the appearance of the chess board has been greatly improved. Here is the latest Python code. If you have problems setting up the Chess Alpha font, you can use the old version of the unicode_board function:

def unicode_board(ascii):
    ''' Return a Unicode version of the simple Ascii board.
    '''
    uni_sym = {' ': ' ', '\n': '\n', '.': u'\u00B7',
        'R': u'♖', 'r': u'♜', 'N': u'♘', 'n': u'♞',
        'B': u'♗', 'b': u'♝', 'Q': u'♕', 'q': u'♛',
        'K': u'♔', 'k': u'♚', 'P': u'♙', 'p': u'♟'}
    return ''.join([uni_sym[char] for char in str(ascii)])

and set the font in position_label to 'Dejavu Sans Mono'.

Fixing the Chess Alpha Font

My program worked well using the Unicode chess symbols in the 'Dejavu Sans Mono' font, but I wanted to use the more attractive 'Chess Alpha' font. There are free downloads for Chess Alpha on several sites. I downloaded the Chess Alpha font and unzipped it. I created a directory called .fonts in my home directory using the file manager and moved Alpha.ttf into this directory. (The procedure for installing fonts is different on Windows.) I found that there was no empty light square symbol in the font, which made it useless for displaying chess positions. (The space character was too narrow.) I viewed the font using:

http://mathew-kurian.github.io/CharacterMap/

(Note that the fixed width chess board pieces are in the middle of their surrounding boxes. The variable width figurine chess pieces are at the bottom of their surrounding boxes.)

The font file did not open with BirdFont. I was able to open it with FontForge, and I managed to fix the font.

Select View > Label Glyth By > Unicode

Many of the glyphs were encoded by several Unicodes (02c7 was encoded by many Unicodes). There were no free Unicodes that I could use to add a space glyph with the same width as the other board symbols (which was 2048). The solution suggested on the web was to use an encoding that did have free space. I tried the first one in the list.

Select Encoding > Reencode > ISO 8859-1 (Latin1)

https://en.wikipedia.org/wiki/ISO/IEC_8859-1

Some of the Glytyh boxes now had no Unicode and a grey cross in the box. Right click on the first one. Select Glyph Info... Replace the character in the Unicode Char field with a space. Glyph Name then becomes "space" and Unicode Value becomes "U+0020". Click OK.

The Glyth box now showed 0020 as the Unicode. Right click on the box and select Set Width. Set Width To: shows as 2048. Click OK. The cross disappears from the 0020 box.

Select File > Generate Fonts... Click the Generate button. Ignore the warnings. FontForge said that it had fixed an error that would cause problems with Windows (something to do with OS/2). That error does not appear to be related to my changes. There is no need to save a FontForge file.

The Chess Alpha font now worked beautifully for displaying a chess position. I did not test the figurine symbols or the board edgings.

Firing up the Citrine Again

I recently set up my Novag Citrine, and connected it to my desktop PC, which is running Xubuntu 20.04 (a flavour of Ubuntu Linux). My PC has an integrated serial port, so I used that. I found the serial port with:

dmesg | grep tty
[    0.074100] printk: console [tty0] enabled
[    0.364954] 00:06: ttyS0 at I/O 0x3f8 (irq = 4, base_baud = 115200) is a 16550A

It was ttyS0.

Initially, I had to run CuteCom using:

sudo cutecom

I selected 57600 Baud, keeping 8 Data bits and 1 Stop bit. I left the Handshake boxes unticked. I found that I also needed to select "CR.LF".

I tried to run the first Python program that I posted in this blog. It was unable to access the serial port. I fixed that with:

sudo chmod 666 /dev/ttyS0

(666 means that anyone can read and write, but not execute.) I no longer needed sudo to launch CuteCom from the terminal, and was able to run the simple Python program with no trouble.

I hit problems when I tried to run the more complicated Citrine interface program. The python-chess module had changed. I fixed the problems, and made several enhancements, some of which will be described in subsequent posts. Here is the latest Python code.

My computer desk was now very crowded with the Citrine in place. The Citrine was not at all convenient to use in that location, but I had a solution in mind.