Greg Hewgill (ghewgill) wrote,
Greg Hewgill

xearth bmp output, true colour, and fonts

Xearth has long had the ability to draw markers and labels on the image when it draws in a "live" context, that is in a GUI like X. However, it uses the native text drawing and font support to do this, so it never allowed the -label option when drawing to a bitmap file.

I hacked support for labels into the Windows port a long time ago, using the Windows GDI support to draw text onto an in-memory device context. While this worked for bitmap files, it wasn't very flexible and was done at the wrong layer.

I have just added support for drawing text to the base xearth code. This uses an in-memory representation of a bitmap font, and draws the text before the output functions even run. The text output works for all kinds of image file output now.

While I was looking for a description of the internals of Windows .fon files (which are a convenient source of bitmap fonts), I came across Simon Tatham's Fonts Page which has some utilities for reading and writing FON files. Not only was there code to read FON files, but there was a public domain version of the X "fixed" 6x13 font which is a handy default font to use in xearth.

As an aside, Simon Tatham is the author of the popular PuTTY terminal program, but also has some other cool stuff on his site. A really slick collection of puzzle games is his Portable Puzzle Collection, which are written in C for GTK, Windows, or OS X but with some clever wizardry can also run as Java applets.

Anyway, another thing I added to xearth this week was BMP output file support. This is done without reference to the actual Windows header files, so that xearth on any platform can create BMP output files. I'll need this when I finally merge in the Windows port code.

Finally, I added a -ncolors true option that enables 24-bit colour output for PNG and BMP files (GIF files are limited to 256 colours, and JPEG files are always true colour). Using the -overlayfile option automatically enables true colour output, because no assumptions are made about the colour palette of the overlay file. This implies that -gif cannot be combined with -overlayfile, but that's an inconsequential limitation.

As always, you can find the latest xearth code in xearth on Github.
  • Post a new comment


    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

    Your IP address will be recorded