home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / x / volume18 / xrotfont / part01 / README < prev   
Encoding:
Text File  |  1992-07-14  |  3.7 KB  |  84 lines

  1.    Xrotfont
  2.    --------
  3.    The idea behind `xrotfont' is to illustrate a couple of ways of drawing
  4. rotated text in an X window. This topic is always cropping up in
  5. comp.sources.X
  6.  
  7.    The code can rotate either a normal server font or an outline font.
  8. Individual characters in a server font are described by a bitmap, whilst
  9. those in an outline font are described by the positions of the vertices
  10. making up the figure. Clearly they're two completely different kettle of
  11. fish, and so require different approaches to rotate them.
  12.  
  13.    Server font
  14.    -----------
  15.    A server font is rotated using a technique described by der Mouse in
  16. the FAQ - namely using a couple of XImage structures to manipulate the
  17. text. The full method is as follows:
  18.  
  19.    i)   Draw the text into a bitmap (pixmap of depth 1) using XDrawString.
  20.    ii)  Capture this bitmap within an XImage structure (I1) using XGetImage.
  21.    iii) Create another XImage structure (I2) which will hold the rotated
  22.         text.
  23.     iv) Copy each pixel in I1 into I2, rotating the coordinates of the
  24.         pixel in I1 to get its coordinates in I2.
  25.      v) Place the rotated text in I2 into a further bitmap using XPutImage.
  26.     vi) Make this bitmap the stipple in a graphics context and thus render
  27.         the rotated text.
  28.  
  29.    This method has several drawbacks, namely:
  30.  
  31.      a) XImages are notoriously slow to use and thus long strings take
  32. a significant time to render. The usual method of speeding this up -
  33. manipulating the XImage data directly using bitwise operators - has to
  34. be applied sparingly if portablity is to be maintained.
  35.  
  36.      b) Long strings require large bitmaps.
  37.  
  38.      c) Text rendered at angles close to 45 degrees look `ghosty', as
  39. an inevitable consequence of rotating a bitmap. Try drawing two adjacent
  40. lines on graph paper first vertical then at 45 degrees - blank pixels
  41. appear between the lines at 45 degrees. This problem could probably be
  42. rectified with some thought. (Text rendered at 90 degrees looks perfect!)
  43.  
  44.    Outline font
  45.    ------------
  46.    An outline font is easy to rotate, since all one has to do is rotate 
  47. the coordinates of all the vertices in a character. Lines are draw between
  48. the vertices using XDrawLine, which is a rapid function resulting is
  49. an overall fast procedure. 
  50.  
  51.    The outline fonts included here are the Hershey fonts, widely available
  52. throughout the public domain. The fonts are found in the directory
  53. `hersheyfonts', as seperate files containing ASCII-ordered complete fonts.
  54. See the file `hershey.doc' in that directory for more information.
  55.  
  56.    Apart from speed, the text produced by this method is easily scalable
  57. to any size. Drawbacks of this method include:
  58.  
  59.      a) Poor appearance of very small text.
  60.  
  61.      b) The difficulty of filling in a figure to produce solid text (this
  62. is not attempted here!)
  63.  
  64.    The code should I hope be fairly self explanatory. The text rotating
  65. functions appear in the source files `imagetext.c' and
  66. `hersheytext.c', and have been written to be pretty transparent to the
  67. rest of the program. Various parameters can be passed to each function
  68. including colour and an allignment argument (centre, or left or right
  69. allign).
  70.  
  71.    As it stands, all drawing is done to the background pixmap of the window,
  72. thus eliminating the need for redraws on an expose event. 
  73.  
  74.    The available Hershey fonts are listed at the start of `hersheytext.c',
  75. whilst available server fonts can be found using `xlsfonts'.
  76.  
  77.    I hope this code will inspire people to use (sparingly!) rotated text
  78. in their applications. Apart from a little sacrifice in speed and a little
  79. extra code there's really little reason not too!
  80.  
  81.    This program is copyright (c) 1992 Alan Richardson. If you have any
  82. comments (good or bad) you can reach me as mppa3@uk.ac.sussex.syma.
  83.  
  84.