home *** CD-ROM | disk | FTP | other *** search
- Xrotfont
- --------
- The idea behind `xrotfont' is to illustrate a couple of ways of drawing
- rotated text in an X window. This topic is always cropping up in
- comp.sources.X
-
- The code can rotate either a normal server font or an outline font.
- Individual characters in a server font are described by a bitmap, whilst
- those in an outline font are described by the positions of the vertices
- making up the figure. Clearly they're two completely different kettle of
- fish, and so require different approaches to rotate them.
-
- Server font
- -----------
- A server font is rotated using a technique described by der Mouse in
- the FAQ - namely using a couple of XImage structures to manipulate the
- text. The full method is as follows:
-
- i) Draw the text into a bitmap (pixmap of depth 1) using XDrawString.
- ii) Capture this bitmap within an XImage structure (I1) using XGetImage.
- iii) Create another XImage structure (I2) which will hold the rotated
- text.
- iv) Copy each pixel in I1 into I2, rotating the coordinates of the
- pixel in I1 to get its coordinates in I2.
- v) Place the rotated text in I2 into a further bitmap using XPutImage.
- vi) Make this bitmap the stipple in a graphics context and thus render
- the rotated text.
-
- This method has several drawbacks, namely:
-
- a) XImages are notoriously slow to use and thus long strings take
- a significant time to render. The usual method of speeding this up -
- manipulating the XImage data directly using bitwise operators - has to
- be applied sparingly if portablity is to be maintained.
-
- b) Long strings require large bitmaps.
-
- c) Text rendered at angles close to 45 degrees look `ghosty', as
- an inevitable consequence of rotating a bitmap. Try drawing two adjacent
- lines on graph paper first vertical then at 45 degrees - blank pixels
- appear between the lines at 45 degrees. This problem could probably be
- rectified with some thought. (Text rendered at 90 degrees looks perfect!)
-
- Outline font
- ------------
- An outline font is easy to rotate, since all one has to do is rotate
- the coordinates of all the vertices in a character. Lines are draw between
- the vertices using XDrawLine, which is a rapid function resulting is
- an overall fast procedure.
-
- The outline fonts included here are the Hershey fonts, widely available
- throughout the public domain. The fonts are found in the directory
- `hersheyfonts', as seperate files containing ASCII-ordered complete fonts.
- See the file `hershey.doc' in that directory for more information.
-
- Apart from speed, the text produced by this method is easily scalable
- to any size. Drawbacks of this method include:
-
- a) Poor appearance of very small text.
-
- b) The difficulty of filling in a figure to produce solid text (this
- is not attempted here!)
-
- The code should I hope be fairly self explanatory. The text rotating
- functions appear in the source files `imagetext.c' and
- `hersheytext.c', and have been written to be pretty transparent to the
- rest of the program. Various parameters can be passed to each function
- including colour and an allignment argument (centre, or left or right
- allign).
-
- As it stands, all drawing is done to the background pixmap of the window,
- thus eliminating the need for redraws on an expose event.
-
- The available Hershey fonts are listed at the start of `hersheytext.c',
- whilst available server fonts can be found using `xlsfonts'.
-
- I hope this code will inspire people to use (sparingly!) rotated text
- in their applications. Apart from a little sacrifice in speed and a little
- extra code there's really little reason not too!
-
- This program is copyright (c) 1992 Alan Richardson. If you have any
- comments (good or bad) you can reach me as mppa3@uk.ac.sussex.syma.
-
-