home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1994 March / Source_Code_CD-ROM_Walnut_Creek_March_1994.iso / compsrcs / misc / volume34 / xvertext / part01 < prev    next >
Encoding:
Text File  |  1992-12-11  |  66.1 KB  |  2,289 lines

  1. Newsgroups: comp.sources.misc
  2. From: mppa3@syma.sussex.ac.uk (Alan Richardson)
  3. Subject:  v34i022:  xvertext - painting vertical text in an X Window, Part01/01
  4. Message-ID: <1992Dec12.203837.2888@sparky.imd.sterling.com>
  5. X-Md4-Signature: 7a5895308d1ea94947ecb00c665546de
  6. Date: Sat, 12 Dec 1992 20:38:37 GMT
  7. Approved: kent@sparky.imd.sterling.com
  8.  
  9. Submitted-by: mppa3@syma.sussex.ac.uk (Alan Richardson)
  10. Posting-number: Volume 34, Issue 22
  11. Archive-name: xvertext/part01
  12. Environment: UNIX, X11
  13.  
  14. This is xvertext 2.0
  15. ~~~~~~~~~~~~~~~~~~~~
  16. This package contains a number of functions to facilitate the painting of 
  17. vertical and upside-down text in an X Window, plus an example prog.
  18.  
  19. Alan Richardson
  20. ------------------------------------------------------------------------------
  21. #! /bin/sh
  22. # This is a shell archive.  Remove anything before this line, then unpack
  23. # it by saving it into a file and typing "sh file".  To overwrite existing
  24. # files, type "sh file -c".  You can also feed this as standard input via
  25. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  26. # will see the following message at the end:
  27. #        "End of shell archive."
  28. # Contents:  xvertext.2.0 xvertext.2.0/CHANGES xvertext.2.0/INSTALL
  29. #   xvertext.2.0/Imakefile xvertext.2.0/Makefile.std
  30. #   xvertext.2.0/README xvertext.2.0/example.c xvertext.2.0/man
  31. #   xvertext.2.0/rotated.c xvertext.2.0/rotated.h
  32. #   xvertext.2.0/man/XRotDrawAlignedString.3
  33. #   xvertext.2.0/man/XRotDrawString.3 xvertext.2.0/man/XRotLoadFont.3
  34. #   xvertext.2.0/man/xvertext.3
  35. # Wrapped by mppa3@tbird1 on Sat Dec 12 16:31:04 1992
  36. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  37. if test ! -d 'xvertext.2.0' ; then
  38.     echo shar: Creating directory \"'xvertext.2.0'\"
  39.     mkdir 'xvertext.2.0'
  40. fi
  41. if test -f 'xvertext.2.0/CHANGES' -a "${1}" != "-c" ; then 
  42.   echo shar: Will not clobber existing file \"'xvertext.2.0/CHANGES'\"
  43. else
  44. echo shar: Extracting \"'xvertext.2.0/CHANGES'\" \(1122 characters\)
  45. sed "s/^X//" >'xvertext.2.0/CHANGES' <<'END_OF_FILE'
  46. X   This is version 2.0 of xvertext
  47. X   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  48. X
  49. X   Two previous versions of xvertext were posted to alt.sources, for
  50. Xbeta testing. The posting threw up several problems, which have been
  51. Xcorrected for this release:
  52. X
  53. X   o  A bug has been corrected which prevented operation on certain
  54. X      monitors. Thanks to envbvs@epb9.lbl.gov (Brian V. Smith) for
  55. X      help on this.
  56. X
  57. X   o  The routines were behaving in an unfriendly manner, such as 
  58. X      exit()ing on an error instead of returning NULL. Thanks to
  59. X      tonyf@ims.com for pointing this out. An `errno' type variable has
  60. X      been added, indicating the type of problem that caused any failure.
  61. X
  62. X   o  My original copyright was too restrictive to allow the inclusion
  63. X      of the routines in widely-distributed programs. This has been replaced
  64. X      by a more MIT-like one. If you want to use the routines in your
  65. X      program, all I ask is that you acknowledge my efforts (and let me know
  66. X      you're using the code).
  67. X
  68. X
  69. X   Alan Richardson, 12/12/92 (mppa3@uk.ac.sussex.syma)
  70. X   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~   
  71. X
  72. X
  73. X       
  74. END_OF_FILE
  75. if test 1122 -ne `wc -c <'xvertext.2.0/CHANGES'`; then
  76.     echo shar: \"'xvertext.2.0/CHANGES'\" unpacked with wrong size!
  77. fi
  78. # end of 'xvertext.2.0/CHANGES'
  79. fi
  80. if test -f 'xvertext.2.0/INSTALL' -a "${1}" != "-c" ; then 
  81.   echo shar: Will not clobber existing file \"'xvertext.2.0/INSTALL'\"
  82. else
  83. echo shar: Extracting \"'xvertext.2.0/INSTALL'\" \(2280 characters\)
  84. sed "s/^X//" >'xvertext.2.0/INSTALL' <<'END_OF_FILE'
  85. X   How to compile this stuff
  86. X   ~~~~~~~~~~~~~~~~~~~~~~~~~
  87. X
  88. X   Included in this package are an Imakefile and a Makefile.std.
  89. XThree things need editing before you can compile:
  90. X
  91. X   o  Choose and uncomment the appropriate compiler lines , either cc or gcc.
  92. X
  93. X   o  The optimal method of implementing `XDrawImage' behaviour depends
  94. X      on using the Xlib call `XGetGCValues()' to obtain and switch
  95. X      foreground and background colours. This function is only present
  96. X      as of Release 4; if you're using Release 3 uncomment the
  97. X      appropriate line. This will use a slightly slower fudge.
  98. X
  99. X   o  Edit the target directories for the linking library, header file
  100. X      and manual pages.
  101. X
  102. X   1) Example program
  103. X   ------------------
  104. X   To make the example program, either type
  105. X
  106. X      xmkmf
  107. X      make
  108. X
  109. X   if you have xmkmf, or if not
  110. X      make -f Makefile.std
  111. X   
  112. X   to use the Makefile included. If all else fails, type
  113. X
  114. X      cc -o example rotated.c example.c -lX11 -O 
  115. X   adding -DX11R3 if need be. Type `example' to run.
  116. X
  117. X   2) Installing `libXrot.a' and the header file
  118. X   ---------------------------------------------
  119. X   If you wish to create and install the linking library `libXrot.a' and 
  120. Xheader file `rotated.h', make sure the target directories given in the
  121. XMakefile are correct then type
  122. X
  123. X      make install-lib
  124. X
  125. X   or
  126. X
  127. X      make -f Makefile.std install-lib
  128. X
  129. X   If this fails, resort to something like:
  130. X
  131. X      ar cq libXrot.a rotated.o
  132. X      ranlib libXrot.a
  133. X      mkdir <target lib dir>
  134. X      mv libXrot.a <target lib dir>
  135. X      mkdir <target include dir>
  136. X      cp rotated.h <target include dir>
  137. X
  138. X   3) Installing the manual pages
  139. X   ------------------------------
  140. X   Make sure the target directory in the Makefile is correct, then type
  141. X
  142. X      make install-man
  143. X
  144. X   or
  145. X
  146. X      make -f Makefile.std install-man
  147. X
  148. X   If this fails, you can do it by hand. See the appropriate section
  149. Xin the Makefile, and follow what happens.
  150. X
  151. X   Successful compilations
  152. X   ~~~~~~~~~~~~~~~~~~~~~~~
  153. X   
  154. X   The programs in this package have been successfully compiled and
  155. Xrun on:
  156. X
  157. X   o HP 9000s300, 9000s700 and 9000s800 machines
  158. X   o A SPARCstation10 running SunOS 4.1.3 
  159. X   o Solbournes running SunOS 4.1.1
  160. X   o A Sequent Symmetry running DYNIX
  161. X
  162. X   Good luck with anything else :-)
  163. X   
  164. END_OF_FILE
  165. if test 2280 -ne `wc -c <'xvertext.2.0/INSTALL'`; then
  166.     echo shar: \"'xvertext.2.0/INSTALL'\" unpacked with wrong size!
  167. fi
  168. # end of 'xvertext.2.0/INSTALL'
  169. fi
  170. if test -f 'xvertext.2.0/Imakefile' -a "${1}" != "-c" ; then 
  171.   echo shar: Will not clobber existing file \"'xvertext.2.0/Imakefile'\"
  172. else
  173. echo shar: Extracting \"'xvertext.2.0/Imakefile'\" \(2319 characters\)
  174. sed "s/^X//" >'xvertext.2.0/Imakefile' <<'END_OF_FILE'
  175. X#############################################################################
  176. X
  177. X# Which compiler to use? 
  178. X
  179. X# cc:
  180. X             CC = cc
  181. X         FFLAGS = -O 
  182. X
  183. X# gcc:
  184. X#            CC = gcc
  185. X#        FFLAGS = -traditional -O2
  186. X
  187. X#############################################################################
  188. X
  189. X# If your Xlib is Release 3, uncomment this:
  190. X
  191. X#      RDEFINES = -DX11R3
  192. X
  193. X#############################################################################
  194. X
  195. X# This is where the library and header files will go, if you use
  196. X#  `make install.lib' to install them. Change as required:
  197. X
  198. X      THELIBDIR = ./lib
  199. X      THEINCDIR = ./include
  200. X
  201. X#############################################################################
  202. X
  203. X# This is where the manual pages will go:
  204. X# (you'll want something ending in man/man3 since the manual page
  205. X#  for `foo' will be installed as `foo.3')
  206. X
  207. X      THEMANDIR = ./man/man3
  208. X
  209. X#############################################################################
  210. X
  211. X# OK, that should do it. 
  212. X
  213. X#############################################################################
  214. X
  215. X           OBJS = example.o rotated.o
  216. X        DEPLIBS = $(USRLIBDIR)/libX11.a
  217. XLOCAL_LIBRARIES = -lX11
  218. X         CFLAGS = $(FFLAGS) $(RDEFINES)
  219. XComplexProgramTarget(example)
  220. X
  221. Xlib: rotated.o
  222. X $(RM) libXrot.a
  223. X $(AR) libXrot.a rotated.o
  224. X ranlib libXrot.a
  225. X
  226. Xinstall-lib: rotated.o
  227. X $(RM) libXrot.a
  228. X $(AR) libXrot.a rotated.o
  229. X ranlib libXrot.a
  230. X @if [ -d $(THELIBDIR) ]; then set +x; \
  231. X else (set -x; $(MKDIRHIER) $(THELIBDIR)); fi
  232. X $(INSTALL) -c libXrot.a $(THELIBDIR)
  233. X @if [ -d $(THEINCDIR) ]; then set +x; \
  234. X else (set -x; $(MKDIRHIER) $(THEINCDIR)); fi
  235. X $(INSTALL) -c rotated.h $(THEINCDIR)
  236. X
  237. Xinstall-man:
  238. X @if [ -d $(THEMANDIR) ]; then set +x; \
  239. X else (set -x; $(MKDIRHIER) $(THEMANDIR)); fi
  240. X $(CP) man/XRotDrawAlignedString.3 $(THEMANDIR)/XRotDrawAlignedImageString.3
  241. X $(CP) man/XRotDrawAlignedString.3 $(THEMANDIR)/XRotDrawAlignedString.3
  242. X $(CP) man/XRotDrawString.3 $(THEMANDIR)/XRotDrawString.3
  243. X $(CP) man/XRotDrawString.3 $(THEMANDIR)/XRotDrawImageString.3
  244. X $(CP) man/XRotLoadFont.3 $(THEMANDIR)/XRotLoadFont.3
  245. X $(CP) man/XRotLoadFont.3 $(THEMANDIR)/XRotUnloadFont.3
  246. X $(CP) man/XRotLoadFont.3 $(THEMANDIR)/XRotVersion.3
  247. X $(CP) man/XRotLoadFont.3 $(THEMANDIR)/XRotTextWidth.3
  248. X $(CP) man/xvertext.3 $(THEMANDIR)/xvertext.3
  249. X
  250. X$(OBJS): rotated.h
  251. X
  252. X
  253. END_OF_FILE
  254. if test 2319 -ne `wc -c <'xvertext.2.0/Imakefile'`; then
  255.     echo shar: \"'xvertext.2.0/Imakefile'\" unpacked with wrong size!
  256. fi
  257. # end of 'xvertext.2.0/Imakefile'
  258. fi
  259. if test -f 'xvertext.2.0/Makefile.std' -a "${1}" != "-c" ; then 
  260.   echo shar: Will not clobber existing file \"'xvertext.2.0/Makefile.std'\"
  261. else
  262. echo shar: Extracting \"'xvertext.2.0/Makefile.std'\" \(2344 characters\)
  263. sed "s/^X//" >'xvertext.2.0/Makefile.std' <<'END_OF_FILE'
  264. X#############################################################################
  265. X
  266. X# Which compiler to use? 
  267. X
  268. X# cc:
  269. X             CC = cc
  270. X         FFLAGS = -O 
  271. X
  272. X# gcc:
  273. X#            CC = gcc
  274. X#        FFLAGS = -traditional -O2
  275. X
  276. X#############################################################################
  277. X
  278. X# If your Xlib is Release 3, uncomment this:
  279. X
  280. X#      RDEFINES = -DX11R3
  281. X
  282. X#############################################################################
  283. X
  284. X# This is where the library and header files will go, if you use
  285. X#  `make install.lib' to install them. Change as required:
  286. X
  287. X      THELIBDIR = ./lib
  288. X      THEINCDIR = ./include
  289. X
  290. X#############################################################################
  291. X
  292. X# This is where the manual pages will go:
  293. X# (you'll want something ending in man/man3 since the manual page
  294. X#  for `foo' will be installed as `foo.3')
  295. X
  296. X      THEMANDIR = ./man/man3
  297. X
  298. X#############################################################################
  299. X
  300. X# OK, that should do it. 
  301. X
  302. X#############################################################################
  303. X
  304. X           OBJS = rotated.o example.o
  305. XLOCAL_LIBRARIES = -lX11
  306. X         CFLAGS = $(FFLAGS) $(RDEFINES)
  307. X          SHELL = /bin/sh
  308. X
  309. Xall: example
  310. X
  311. Xexample: $(OBJS)
  312. X    $(CC) $(CFLAGS) -o example $(OBJS) $(LOCAL_LIBRARIES)
  313. X
  314. Xlib: rotated.o
  315. X    rm -f libXrot.a
  316. X    ar cq libXrot.a rotated.o 
  317. X    ranlib libXrot.a
  318. X
  319. Xinstall-lib: rotated.o
  320. X    rm -f libXrot.a
  321. X    ar cq libXrot.a rotated.o
  322. X    ranlib libXrot.a  
  323. X    @if [ -d $(THELIBDIR) ]; then set +x; \
  324. X    else (set -x; mkdir $(THELIBDIR)); fi
  325. X    cp libXrot.a $(THELIBDIR)
  326. X    @if [ -d $(THEINCDIR) ]; then set +x; \
  327. X    else (set -x; mkdir $(THEINCDIR)); fi
  328. X    cp rotated.h $(THEINCDIR)
  329. X
  330. Xclean:
  331. X    rm -f $(OBJS) example example~ libXrot.a
  332. X
  333. Xinstall-man:
  334. X    @if [ -d $(THEMANDIR) ]; then set +x; \
  335. X    else (set -x; mkdir $(THEMANDIR)); fi
  336. X    cp man/XRotDrawAlignedString.3 $(THEMANDIR)/XRotDrawAlignedImageString.3
  337. X    cp man/XRotDrawAlignedString.3 $(THEMANDIR)/XRotDrawAlignedString.3
  338. X    cp man/XRotDrawString.3 $(THEMANDIR)/XRotDrawString.3
  339. X    cp man/XRotDrawString.3 $(THEMANDIR)/XRotDrawImageString.3
  340. X    cp man/XRotLoadFont.3 $(THEMANDIR)/XRotLoadFont.3
  341. X    cp man/XRotLoadFont.3 $(THEMANDIR)/XRotUnloadFont.3
  342. X    cp man/XRotLoadFont.3 $(THEMANDIR)/XRotVersion.3
  343. X    cp man/XRotLoadFont.3 $(THEMANDIR)/XRotTextWidth.3
  344. X    cp man/xvertext.3 $(THEMANDIR)/xvertext.3
  345. X
  346. X$(OBJS): rotated.h
  347. X
  348. END_OF_FILE
  349. if test 2344 -ne `wc -c <'xvertext.2.0/Makefile.std'`; then
  350.     echo shar: \"'xvertext.2.0/Makefile.std'\" unpacked with wrong size!
  351. fi
  352. # end of 'xvertext.2.0/Makefile.std'
  353. fi
  354. if test -f 'xvertext.2.0/README' -a "${1}" != "-c" ; then 
  355.   echo shar: Will not clobber existing file \"'xvertext.2.0/README'\"
  356. else
  357. echo shar: Extracting \"'xvertext.2.0/README'\" \(4611 characters\)
  358. sed "s/^X//" >'xvertext.2.0/README' <<'END_OF_FILE'
  359. X   This is version 2.0 of xvertext (12/12/92)
  360. X   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  361. X   The routines in this package are designed to facilitate the production
  362. Xof vertical and upside-down text in an X Window. They have been written
  363. Xprincipally for speed and portability.
  364. X   The routines have their origin in `xrotfont', a program for
  365. Xany-angle rotation released to comp.sources.x in May '92. After seeing that
  366. Xprogram, many people asked for a faster method of doing just vertical
  367. Xtext. This is the best I could do ...
  368. X
  369. X
  370. X   OVERVIEW
  371. X   --------
  372. X   Writing vertical text has been split into two parts:
  373. X
  374. X   i) Loading the font
  375. X      ----------------
  376. X      This involves taking each character of a normal X server bitmap
  377. Xfont in turn, using XImages to produce per-character bitmaps
  378. Xrotated at 90, 180 or 270 degrees from the horizontal. Each font only
  379. Xhas to be loaded once in any particular direction, and it can later
  380. Xbe unloaded freeing server memory.
  381. X
  382. X  ii) Painting the text
  383. X      -----------------
  384. X      Given an already loaded font, a string is broken down into its
  385. Xconstituent characters. Each character's rotated bitmap is painted in turn.
  386. X
  387. X
  388. X   ROUTINES
  389. X   --------
  390. X   The system has been written to mimic to some extent Xlib's own
  391. Xfont handling technique. Thus, rotated fonts are described by a structure
  392. X`XRotFontStruct' which contains per char information as well as some
  393. Xoverall font information. An XRotFontStruct structure is obtained by
  394. Xcalling XRotLoadFont(); the returned structure is then used to describe
  395. Xthe font in all the other routines. A font is unloaded using XRotUnloadFont().
  396. X   In sympathy with Xlib, two routines exist for drawing simple
  397. Xstrings: XRotDrawString() and XRotDrawImageString(). They differ in that
  398. Xthe former leaves background pixels untouched, whilst the latter fills
  399. Xin the background.
  400. X   Going further than Xlib, two routines are provided which align
  401. Xsingle or multi-line strings (ie containing newline characters) in some
  402. Xspecified way: XRotDrawAlignedString() and XRotDrawAlignedImageString().
  403. XAlignment is passed as one of: TLEFT, TCENTRE, TRIGHT, MLEFT, MCENTRE, MRIGHT,
  404. XBLEFT, BCENTRE, BRIGHT. These indicate which part of the string should
  405. Xcoincide with the specified (x,y) point - eg TLEFT means the top left corner.
  406. XThese functions are likely to be those the user actually calls.
  407. X   The miscellaneous function XRotTextWidth() returns the width of a
  408. Xstring given a rotated font.
  409. X
  410. X   Fuller details of function arguments can be found in the manual pages
  411. Xinclude in the package.
  412. X
  413. X
  414. X   TEXT `THE RIGHT WAY UP'
  415. X   -----------------------
  416. X   Text to be written the right way up obviously doesn't require any
  417. Xrotation. However for completeness it would be nice to use the
  418. Xabove routines with such text and so this has been built in. When the
  419. Xangle given to XRotLoadFont() is zero degrees, no rotation is done
  420. Xand the XRotFontStruct is essentially empty apart from the XFontStruct
  421. Xwhich is retained. Text is then drawn using Xlib's XDrawText() and
  422. XXDrawImageText() routines, giving very fast performance. 
  423. X
  424. X
  425. X   BUT HOW FAST IS IT?
  426. X   -------------------
  427. X   The speed with which these routines work depends heavily on the speed
  428. Xof your X server. Loading the font involves the manipulation of XImages,
  429. Xwhich is a notorious tortoise. Painting a string should be faster. I've
  430. Xtried the routines on servers which do both jobs in the blink of an eye,
  431. Xand some which take several seconds. 
  432. X
  433. X
  434. X   SO WHAT'S IN THIS PACKAGE?
  435. X   -------------------------
  436. X   Included in this package are the source file containing the text
  437. Xhandling routines (`rotated.c'), a header file (`rotated.h'), and an
  438. Xexample program (`example.c'). The directory `man' contains,
  439. Xsurprisingly, the manual pages. 
  440. X   The example program can be made using the Makefile (see `INSTALL').
  441. XIt displays a simple message in many different fonts at different angles
  442. Xwith different alignment.
  443. X
  444. X
  445. X   HOW DO I USE THE ROUTINES MYSELF?
  446. X   ---------------------------------
  447. X   To use the routines in a program of your own, you have two choices.
  448. XYou can either:
  449. X
  450. X   a) Copy the files `rotated.c' and `rotated.h' to sit with your
  451. Xprogram's source files and compile them all together. Or:
  452. X
  453. X   b) Type `make install.lib' to create a linking library and install
  454. Xit and the header file into directories of your choice. You then specify
  455. X`-lXrot' prior to `-lX11' when linking your program. Remember that if you
  456. Xdon't install in a standard place like /usr/lib, you'll need to use the
  457. X-L and -I compiler options.
  458. X
  459. X
  460. X   Alan Richardson, 5/10/92 (mppa3@uk.ac.sussex.syma)
  461. X   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~   
  462. END_OF_FILE
  463. if test 4611 -ne `wc -c <'xvertext.2.0/README'`; then
  464.     echo shar: \"'xvertext.2.0/README'\" unpacked with wrong size!
  465. fi
  466. # end of 'xvertext.2.0/README'
  467. fi
  468. if test -f 'xvertext.2.0/example.c' -a "${1}" != "-c" ; then 
  469.   echo shar: Will not clobber existing file \"'xvertext.2.0/example.c'\"
  470. else
  471. echo shar: Extracting \"'xvertext.2.0/example.c'\" \(7901 characters\)
  472. sed "s/^X//" >'xvertext.2.0/example.c' <<'END_OF_FILE'
  473. X/* ************************************************************************ */
  474. X
  475. X
  476. X/* This is an example program designed to utilise and manipulate the
  477. X   `xvertext' routines.
  478. X
  479. X   Copyright (c) 1992 Alan Richardson (mppa3@uk.ac.sussex.syma) */
  480. X
  481. X
  482. X/* ************************************************************************ */
  483. X
  484. X
  485. X#include <X11/Xlib.h>
  486. X#include <X11/Xutil.h>
  487. X#include <stdio.h>
  488. X#include <signal.h>
  489. X#include "rotated.h"
  490. X
  491. X  
  492. X/* ---------------------------------------------------------------------- */
  493. X  
  494. X
  495. Xextern char    *getenv();
  496. X
  497. Xlong         AllocNamedColor();
  498. Xvoid         ShowFontName();
  499. Xvoid         PaintMessage();
  500. Xvoid         Advance();
  501. X
  502. X
  503. X/* ---------------------------------------------------------------------- */
  504. X
  505. X
  506. X#define INFO_FONT \
  507. X    "-adobe-helvetica-bold-o-normal--14-140-75-75-p-82-iso8859-1"
  508. X
  509. X#define NFONTS    18
  510. X
  511. Xchar        *fonts[]={
  512. X    "-adobe-helvetica-medium-r-normal--18-180-75-75-p-98-iso8859-1",
  513. X    "-adobe-helvetica-bold-r-normal--12-120-75-75-p-70-iso8859-1",
  514. X    "-adobe-helvetica-medium-r-normal--10-100-75-75-p-56-iso8859-1",
  515. X    "-adobe-courier-bold-o-normal--18-180-75-75-m-110-iso8859-1",
  516. X    "-adobe-courier-medium-o-normal--12-120-75-75-m-70-iso8859-1",
  517. X    "-adobe-courier-bold-o-normal--10-100-75-75-m-60-iso8859-1",
  518. X    "-adobe-times-medium-r-normal--18-180-75-75-p-94-iso8859-1",
  519. X    "-adobe-times-bold-r-normal--12-120-75-75-p-67-iso8859-1",
  520. X    "-adobe-times-medium-r-normal--10-100-75-75-p-54-iso8859-1",
  521. X    "-adobe-helvetica-bold-o-normal--18-180-75-75-p-98-iso8859-1",
  522. X    "-adobe-helvetica-medium-o-normal--12-120-75-75-p-67-iso8859-1",
  523. X    "-adobe-helvetica-bold-o-normal--10-100-75-75-p-57-iso8859-1",
  524. X    "-adobe-courier-medium-r-normal--18-180-75-75-m-110-iso8859-1",
  525. X    "-adobe-courier-bold-r-normal--12-120-75-75-m-70-iso8859-1",
  526. X    "-adobe-courier-medium-r-normal--10-100-75-75-m-60-iso8859-1",
  527. X    "-adobe-times-bold-i-normal--18-180-75-75-p-94-iso8859-1",
  528. X    "-adobe-times-medium-i-normal--12-120-75-75-p-63-iso8859-1",
  529. X    "-adobe-times-bold-i-normal--10-100-75-75-p-52-iso8859-1"
  530. X};
  531. X
  532. Xchar        *message={"\
  533. XThis is a system for doing\n\
  534. X(fairly) fast vertical and\n\
  535. Xupside down text\n\
  536. Xin an X Window.\n\
  537. XIt handles\n\
  538. Xboth fixed width and\n\
  539. Xproportional fonts.\n\n\
  540. XBut it will cry\n\
  541. Xif you shout at it."
  542. X};
  543. X
  544. X
  545. X/* ---------------------------------------------------------------------- */
  546. X  
  547. X
  548. XGC info_gc, message_gc;
  549. XDisplay    *dpy;
  550. XWindow window;  
  551. Xint depth, screen;
  552. XXRotFontStruct *font1=NULL, *font2=NULL;
  553. Xint ifont, ipos;
  554. X
  555. X
  556. X/* ---------------------------------------------------------------------- */
  557. X
  558. X
  559. X/* *** Allocates a colour from the default colour map *** */
  560. X
  561. Xlong AllocNamedColor(colname)  
  562. X char *colname;    
  563. X{
  564. X XColor scrncol, excol;
  565. X             
  566. X if(depth==1)
  567. X     return WhitePixel(dpy, screen);
  568. X
  569. X if(XAllocNamedColor(dpy, DefaultColormap(dpy, screen), colname,
  570. X                     &scrncol, &excol))
  571. X     return scrncol.pixel;
  572. X
  573. X else
  574. X     return WhitePixel(dpy, screen);
  575. X}
  576. X  
  577. X
  578. X/* ---------------------------------------------------------------------- */
  579. X
  580. X
  581. X/* *** Main routine *** */
  582. X
  583. Xmain(argc, argv)
  584. X int argc;
  585. X char *argv[];
  586. X{
  587. X XEvent ev;
  588. X char *host;
  589. X char buf[1];
  590. X float version;
  591. X char copyright[100];
  592. X version=XRotVersion(copyright, 100);
  593. X fprintf(stderr, "%s - version %.1f\n", copyright, version);
  594. X
  595. X /* establish connection to display ... */
  596. X if((host=getenv("DISPLAY"))==NULL) {
  597. X     fprintf(stderr,"%s : Error : Can't connect to host\n", argv[0]);
  598. X     exit(); 
  599. X }
  600. X
  601. X /* open connection to display ... */
  602. X if((dpy=XOpenDisplay(host))==NULL) {
  603. X     fprintf(stderr,"%s : Error : Can't open display\n", argv[0]);
  604. X     exit(); 
  605. X }
  606. X screen=DefaultScreen(dpy);
  607. X depth=DefaultDepth(dpy, screen);
  608. X
  609. X /* create a window ... */
  610. X window=XCreateWindow(dpy, DefaultRootWindow(dpy), 0, 0, 700, 700,
  611. X                      0, depth, InputOutput, DefaultVisual(dpy, screen),
  612. X                      0, NULL);
  613. X
  614. X XSelectInput(dpy, window, ExposureMask|KeyPressMask);
  615. X XSetWindowBackground(dpy, window, BlackPixel(dpy, screen));
  616. X XMapWindow(dpy, window);
  617. X
  618. X info_gc=XCreateGC(dpy, window, NULL, 0);
  619. X XSetBackground(dpy, info_gc, BlackPixel(dpy, screen));
  620. X XSetForeground(dpy, info_gc, AllocNamedColor("cyan"));
  621. X
  622. X message_gc=XCreateGC(dpy, window, NULL, 0);
  623. X if(depth>1)
  624. X     XSetBackground(dpy, message_gc, AllocNamedColor("red"));
  625. X else
  626. X     XSetBackground(dpy, message_gc, BlackPixel(dpy, screen));
  627. X XSetForeground(dpy, message_gc, AllocNamedColor("yellow"));
  628. X /* load a font for showing the current font name ... */
  629. X font2=XRotLoadFont(dpy, INFO_FONT, 0.);
  630. X if(font2==NULL) {
  631. X     if(xv_errno==XV_NOFONT) {
  632. X         fprintf(stderr,"no font `%s'\n", INFO_FONT);
  633. X         font2=XRotLoadFont(dpy, "fixed", 0.);
  634. X     }
  635. X     else {
  636. X         if(xv_errno==XV_NOMEM)
  637. X             fprintf(stderr, "malloc problem - can't continue\n");
  638. X         else
  639. X             fprintf(stderr, "XImage problem - can't continue\n");
  640. X         exit(1);
  641. X     }
  642. X }
  643. X
  644. X /* set the alarm for the first time ... */ 
  645. X ifont=-1;
  646. X ipos=8;  
  647. X Advance(0, 0, (struct sigcontext *)NULL);
  648. X
  649. X /* simple event loop ... */
  650. X for(;;) {
  651. X     XNextEvent(dpy, &ev);
  652. X
  653. X     switch(ev.type) {
  654. X         case Expose:
  655. X             if(ev.xexpose.count==0) {
  656. X                 ShowFontName(False);
  657. X                 PaintMessage(); 
  658. X             }
  659. X             break;
  660. X
  661. X         case KeyPress: 
  662. X             XLookupString(&ev.xkey, buf, 1, NULL, NULL);
  663. X             if(buf[0]=='q' || buf[0]=='Q')
  664. X                 exit(0);
  665. X             break;
  666. X
  667. X        default:
  668. X             break;  
  669. X     }
  670. X }
  671. X}
  672. X
  673. X
  674. X/* ---------------------------------------------------------------------- */
  675. X   
  676. X  
  677. X/* *** Display the current font name in the top left corner *** */
  678. X
  679. Xvoid ShowFontName(loading)
  680. X Bool loading;
  681. X{
  682. X char str[300];
  683. X
  684. X if(loading)
  685. X     sprintf(str, "FONT: %s ... loading", fonts[ifont]);
  686. X else
  687. X     sprintf(str, "FONT: %s                         ", fonts[ifont]);
  688. X XRotDrawAlignedImageString(dpy, font2, window, info_gc, 0, 0, str, TLEFT);
  689. X
  690. X XFlush(dpy);
  691. X}
  692. X   
  693. X/* ---------------------------------------------------------------------- */
  694. X                     
  695. X
  696. X/* *** Paint the message in the appropriate place *** */
  697. X
  698. Xvoid PaintMessage()
  699. X{
  700. X static int alignment[]={
  701. X    TLEFT, TCENTRE, TRIGHT, MLEFT, MCENTRE, MRIGHT, BLEFT, BCENTRE, BRIGHT
  702. X };
  703. X
  704. X /* draw some centered crosshairs ... */
  705. X XDrawLine(dpy, window, info_gc, 350, 200, 350, 500);
  706. X XDrawLine(dpy, window, info_gc, 200, 350, 500, 350);
  707. X
  708. X /* draw the message ... */
  709. X if(ifont%2==0)
  710. X     XRotDrawAlignedString(dpy, font1, window, message_gc, 350, 350,
  711. X                           message, alignment[ipos]);
  712. X else 
  713. X     XRotDrawAlignedImageString(dpy, font1, window, message_gc, 350, 350,
  714. X                                message, alignment[ipos]);
  715. X
  716. X XFlush(dpy);
  717. X}
  718. X
  719. X
  720. X/* ---------------------------------------------------------------------- */
  721. X
  722. X
  723. X/* *** Change the font, position and/or rotation *** */
  724. X
  725. Xvoid Advance(sig, code, scp)
  726. X int sig, code;
  727. X struct sigcontext * scp;
  728. X{
  729. X /* advance position ... */
  730. X if((ipos+=2)>=9) {
  731. X    if(++ifont==NFONTS) ifont=0;
  732. X
  733. X    ipos=(ifont%2);
  734. X    /* finished with this font ... */
  735. X    if(font1!=NULL)
  736. X        XRotUnloadFont(dpy, font1);
  737. X
  738. X    /* load a new font ... */
  739. X    ShowFontName(True);
  740. X
  741. X    font1=XRotLoadFont(dpy, fonts[ifont], (float)(ifont%4)*90.);
  742. X    if(font1==NULL) {
  743. X        if(xv_errno==XV_NOFONT) {
  744. X            fprintf(stderr,"no font `%s'\n", fonts[ifont]);
  745. X            font1=XRotLoadFont(dpy, "fixed", (float)(ifont%4)*90.);
  746. X        }
  747. X        else {
  748. X            if(xv_errno==XV_NOMEM)
  749. X                fprintf(stderr, "malloc problem - can't continue\n");
  750. X            else
  751. X                fprintf(stderr, "XImage problem - can't continue\n");
  752. X            exit(1);
  753. X        }
  754. X    }
  755. X    ShowFontName(False);
  756. X }
  757. X
  758. X /* delete old message and draw new ... */
  759. X XClearArea(dpy, window, 0, font2->height+1, 700, 700-font2->height, False);
  760. X PaintMessage();
  761. X
  762. X /* reset alarm ... */
  763. X signal(SIGALRM, Advance);
  764. X alarm(1);
  765. X}
  766. X
  767. END_OF_FILE
  768. if test 7901 -ne `wc -c <'xvertext.2.0/example.c'`; then
  769.     echo shar: \"'xvertext.2.0/example.c'\" unpacked with wrong size!
  770. fi
  771. # end of 'xvertext.2.0/example.c'
  772. fi
  773. if test ! -d 'xvertext.2.0/man' ; then
  774.     echo shar: Creating directory \"'xvertext.2.0/man'\"
  775.     mkdir 'xvertext.2.0/man'
  776. fi
  777. if test -f 'xvertext.2.0/rotated.c' -a "${1}" != "-c" ; then 
  778.   echo shar: Will not clobber existing file \"'xvertext.2.0/rotated.c'\"
  779. else
  780. echo shar: Extracting \"'xvertext.2.0/rotated.c'\" \(21724 characters\)
  781. sed "s/^X//" >'xvertext.2.0/rotated.c' <<'END_OF_FILE'
  782. X/* ********************************************************************** */
  783. X
  784. X/* xvertext, Copyright (c) 1992 Alan Richardson (mppa3@uk.ac.sussex.syma)
  785. X *
  786. X * Permission to use, copy, modify, and distribute this software and its
  787. X * documentation for any purpose and without fee is hereby granted, provided
  788. X * that the above copyright notice appear in all copies and that both the
  789. X * copyright notice and this permission notice appear in supporting
  790. X * documentation.  All work developed as a consequence of the use of
  791. X * this program should duly acknowledge such use. No representations are
  792. X * made about the suitability of this software for any purpose.  It is
  793. X * provided "as is" without express or implied warranty.
  794. X */
  795. X
  796. X/* ********************************************************************** */
  797. X
  798. X
  799. X#include <X11/Xlib.h>
  800. X#include <X11/Xutil.h>
  801. X#include <stdio.h>
  802. X#include "rotated.h"
  803. X
  804. X
  805. X/* ---------------------------------------------------------------------- */
  806. X
  807. X
  808. Xstatic char        *my_strdup();
  809. Xstatic char        *my_strtok();
  810. X
  811. Xfloat             XRotVersion();
  812. XXRotFontStruct         *XRotLoadFont();
  813. Xvoid              XRotUnloadFont();
  814. Xint               XRotTextWidth();
  815. Xvoid             XRotDrawString();
  816. Xvoid               XRotDrawImageString();
  817. Xvoid                     XRotPaintString();
  818. Xvoid               XRotDrawAlignedString();
  819. Xvoid                     XRotDrawAlignedImageString();
  820. Xvoid                     XRotPaintAlignedString();
  821. X
  822. X
  823. X/* ---------------------------------------------------------------------- */  
  824. X
  825. X
  826. X/* *** Routine to mimic `strdup()' (some machines don't have it) *** */
  827. X
  828. Xstatic char *my_strdup(str)
  829. X char *str;
  830. X{
  831. X char *s;
  832. X
  833. X if(str==NULL)
  834. X     return NULL;
  835. X
  836. X s=(char *)malloc((unsigned)(strlen(str)+1));
  837. X /* this error is highly unlikely ... */
  838. X if(s==NULL) {
  839. X     fprintf(stderr, "Fatal error: my_strdup(): Couldn't do malloc (gulp!)\n");
  840. X     exit(1); 
  841. X }
  842. X
  843. X strcpy(s, str);
  844. X return s;
  845. X}
  846. X
  847. X
  848. X/* ---------------------------------------------------------------------- */
  849. X
  850. X
  851. X/* *** Routine to replace `strtok' : this one returns a zero
  852. X       length string if it encounters two consecutive delimiters *** */
  853. X
  854. Xstatic char *my_strtok(str1, str2)
  855. X char *str1, *str2;
  856. X{
  857. X char *ret;
  858. X int i, j, stop;
  859. X static int start, len;
  860. X static char *stext;
  861. X
  862. X /* this error should never occur ... */
  863. X if(str2==NULL) {
  864. X     fprintf(stderr,
  865. X             "Fatal error: my_strdup(): recieved null delimiter string\n");
  866. X     exit(1);
  867. X }
  868. X
  869. X /* initialise if str1 not NULL ... */
  870. X if(str1!=NULL) {
  871. X     start=0;
  872. X     stext=str1;
  873. X     len=strlen(str1);
  874. X }
  875. X
  876. X /* run out of tokens ? ... */
  877. X if(start>=len)
  878. X     return NULL;
  879. X
  880. X /* loop through characters ... */
  881. X for(i=start; i<len; i++) {
  882. X     /* loop through delimiters ... */
  883. X     stop=0;
  884. X     for(j=0; j<strlen(str2); j++)
  885. X         if(stext[i]==str2[j]) 
  886. X              stop=1;
  887. X     if(stop)
  888. X         break;
  889. X }
  890. X
  891. X stext[i]='\0';
  892. X
  893. X ret=stext+start;
  894. X
  895. X start=i+1;
  896. X
  897. X return ret;
  898. X}
  899. X
  900. X
  901. X/* ---------------------------------------------------------------------- */
  902. X  
  903. X
  904. X/* *** Routine to return version/copyright information *** */
  905. X
  906. Xfloat XRotVersion(str, n)
  907. X char *str;
  908. X int n;
  909. X{
  910. X if(str!=NULL)
  911. X     strncpy(str, XV_COPYRIGHT, n);
  912. X return XV_VERSION;
  913. X}
  914. X
  915. X
  916. X/* ---------------------------------------------------------------------- */
  917. X
  918. X
  919. X/* *** Load the rotated version of a given font *** */
  920. XXRotFontStruct *XRotLoadFont(dpy, fontname, angle)
  921. X Display *dpy;
  922. X char *fontname;
  923. X float angle;
  924. X{
  925. X char val;
  926. X XImage    *I1, *I2;
  927. X Pixmap canvas;
  928. X Window root;
  929. X int screen;
  930. X GC font_gc;
  931. X char text[3], errstr[300];
  932. X XFontStruct *fontstruct;
  933. X XRotFontStruct    *rotfont;
  934. X int ichar, i, j, index, boxlen=60, dir;
  935. X int vert_w, vert_h, vert_len, bit_w, bit_h, bit_len;
  936. X int min_char, max_char;
  937. X unsigned char *vertdata, *bitdata;
  938. X int ascent, descent, lbearing, rbearing;
  939. X int on=1, off=0;
  940. X
  941. X /* make angle positive ... */
  942. X if(angle<0)
  943. X     do angle+=360; while(angle<0);
  944. X
  945. X /* get nearest vertical or horizontal direction ... */
  946. X dir=(int)((angle+45.)/90.)%4;
  947. X
  948. X /* useful macros ... */
  949. X screen=DefaultScreen(dpy);
  950. X root=DefaultRootWindow(dpy);
  951. X
  952. X /* create the depth 1 canvas bitmap ... */
  953. X canvas=XCreatePixmap(dpy, root, boxlen, boxlen, 1);
  954. X /* create a GC ... */
  955. X font_gc=XCreateGC(dpy, canvas, NULL, 0);
  956. X XSetBackground(dpy, font_gc, off);
  957. X
  958. X /* load the font ... */
  959. X fontstruct=XLoadQueryFont(dpy, fontname);
  960. X if(fontstruct==NULL) {
  961. X     xv_errno=XV_NOFONT;
  962. X     return NULL;
  963. X }
  964. X XSetFont(dpy, font_gc, fontstruct->fid);
  965. X
  966. X /* allocate space for rotated font ... */
  967. X rotfont=(XRotFontStruct *)malloc((unsigned)sizeof(XRotFontStruct));
  968. X if(rotfont==NULL) {
  969. X     xv_errno=XV_NOMEM;
  970. X     return NULL;
  971. X }
  972. X   
  973. X /* determine which characters are defined in font ... */
  974. X min_char=fontstruct->min_char_or_byte2; 
  975. X max_char=fontstruct->max_char_or_byte2;
  976. X /* we only want printing characters ... */
  977. X if(min_char<32)  min_char=32;
  978. X if(max_char>126) max_char=126;
  979. X     
  980. X /* some overall font data ... */
  981. X rotfont->name=my_strdup(fontname);
  982. X rotfont->dir=dir;
  983. X rotfont->min_char=min_char;
  984. X rotfont->max_char=max_char;
  985. X rotfont->max_ascent=fontstruct->max_bounds.ascent;
  986. X rotfont->max_descent=fontstruct->max_bounds.descent;   
  987. X rotfont->height=rotfont->max_ascent+rotfont->max_descent;
  988. X
  989. X /* remember xfontstruct for `normal' text ... */
  990. X if(dir==0) 
  991. X     rotfont->xfontstruct=fontstruct;
  992. X
  993. X else {
  994. X     /* font needs rotation ... */
  995. X     /* loop through each character ... */
  996. X     for(ichar=min_char; ichar<=max_char; ichar++) {
  997. X
  998. X         index=ichar-fontstruct->min_char_or_byte2;
  999. X         /* per char dimensions ... */
  1000. X         ascent=  rotfont->per_char[ichar-32].ascent=
  1001. X                          fontstruct->per_char[index].ascent;
  1002. X         descent= rotfont->per_char[ichar-32].descent=
  1003. X                          fontstruct->per_char[index].descent;
  1004. X         lbearing=rotfont->per_char[ichar-32].lbearing=
  1005. X                          fontstruct->per_char[index].lbearing;
  1006. X         rbearing=rotfont->per_char[ichar-32].rbearing=
  1007. X                          fontstruct->per_char[index].rbearing;
  1008. X                  rotfont->per_char[ichar-32].width=
  1009. X                          fontstruct->per_char[index].width;
  1010. X
  1011. X         /* some space chars have zero body, but a bitmap can't have ... */
  1012. X         if(!ascent && !descent)   
  1013. X             ascent=  rotfont->per_char[ichar-32].ascent=  1;
  1014. X         if(!lbearing && !rbearing) 
  1015. X             rbearing=rotfont->per_char[ichar-32].rbearing=1;
  1016. X
  1017. X         /* glyph width and height when vertical ... */
  1018. X         vert_w=rbearing-lbearing;
  1019. X         vert_h=ascent+descent;
  1020. X
  1021. X         /* width in bytes ... */
  1022. X         vert_len=(vert_w-1)/8+1;   
  1023. X         XSetForeground(dpy, font_gc, off);
  1024. X         XFillRectangle(dpy, canvas, font_gc, 0, 0, boxlen, boxlen);
  1025. X
  1026. X         /* draw the character centre top right on canvas ... */
  1027. X         sprintf(text, "%c", ichar);
  1028. X         XSetForeground(dpy, font_gc, on);
  1029. X         XDrawImageString(dpy, canvas, font_gc, boxlen/2-lbearing,
  1030. X                          boxlen/2-descent, text, 1);
  1031. X
  1032. X         /* reserve memory for first XImage ... */
  1033. X         vertdata=(unsigned char *) malloc((unsigned)(vert_len*vert_h));
  1034. X         if(vertdata==NULL) {
  1035. X             xv_errno=XV_NOMEM;
  1036. X             return NULL;
  1037. X         }
  1038. X  
  1039. X         /* create the XImage ... */
  1040. X         I1=XCreateImage(dpy, DefaultVisual(dpy, screen), 1, XYBitmap,
  1041. X                         0, vertdata, vert_w, vert_h, 8, 0);
  1042. X
  1043. X         if(I1==NULL) {
  1044. X             xv_errno=XV_NOXIMAGE;
  1045. X             return NULL;
  1046. X          }
  1047. X  
  1048. X         I1->byte_order=I1->bitmap_bit_order=MSBFirst;
  1049. X   
  1050. X         /* extract character from canvas ... */
  1051. X         XGetSubImage(dpy, canvas, boxlen/2, boxlen/2-vert_h,
  1052. X                      vert_w, vert_h, 1, XYPixmap, I1, 0, 0);
  1053. X         I1->format=XYBitmap; 
  1054. X         /* width, height of rotated character ... */
  1055. X         if(dir==2) { 
  1056. X             bit_w=vert_w;
  1057. X             bit_h=vert_h; 
  1058. X         }
  1059. X         else {
  1060. X             bit_w=vert_h;
  1061. X             bit_h=vert_w; 
  1062. X         }
  1063. X
  1064. X         /* width in bytes ... */
  1065. X         bit_len=(bit_w-1)/8+1;
  1066. X   
  1067. X         rotfont->per_char[ichar-32].glyph.bit_w=bit_w;
  1068. X         rotfont->per_char[ichar-32].glyph.bit_h=bit_h;
  1069. X
  1070. X         /* reserve memory for the rotated image ... */
  1071. X         bitdata=(unsigned char *)calloc((unsigned)(bit_h*bit_len), 1);
  1072. X         if(bitdata==NULL) {
  1073. X             xv_errno=XV_NOMEM;
  1074. X             return NULL;
  1075. X         }
  1076. X
  1077. X         /* create the image ... */
  1078. X         I2=XCreateImage(dpy, DefaultVisual(dpy, screen), 1, XYBitmap, 0,
  1079. X                         bitdata, bit_w, bit_h, 8, 0); 
  1080. X         if(I2==NULL) {
  1081. X             xv_errno=XV_NOXIMAGE;
  1082. X             return NULL;
  1083. X         }
  1084. X
  1085. X         I2->byte_order=I2->bitmap_bit_order=MSBFirst;
  1086. X         /* map vertical data to rotated character ... */
  1087. X         for(j=0; j<bit_h; j++) {
  1088. X             for(i=0; i<bit_w; i++) {
  1089. X                 /* map bits ... */
  1090. X                 if(dir==1)
  1091. X                     val=vertdata[i*vert_len + (vert_w-j-1)/8] &
  1092. X                         (128>>((vert_w-j-1)%8));
  1093. X   
  1094. X                 else if(dir==2)
  1095. X                     val=vertdata[(vert_h-j-1)*vert_len + (vert_w-i-1)/8] &
  1096. X                         (128>>((vert_w-i-1)%8));
  1097. X                    
  1098. X                 else 
  1099. X                     val=vertdata[(vert_h-i-1)*vert_len + j/8] & 
  1100. X                         (128>>(j%8));
  1101. X        
  1102. X                 if(val) 
  1103. X                     bitdata[j*bit_len + i/8] = bitdata[j*bit_len + i/8] |
  1104. X                                                (128>>(i%8));
  1105. X             }
  1106. X         }
  1107. X   
  1108. X         /* create this character's bitmap ... */
  1109. X         rotfont->per_char[ichar-32].glyph.bm=
  1110. X           XCreatePixmap(dpy, root, bit_w, bit_h, 1);
  1111. X     
  1112. X         /* put the image into the bitmap ... */
  1113. X         XPutImage(dpy, rotfont->per_char[ichar-32].glyph.bm, 
  1114. X                   font_gc, I2, 0, 0, 0, 0, bit_w, bit_h);
  1115. X  
  1116. X         /* free the image and data ... */
  1117. X         XDestroyImage(I1);
  1118. X         XDestroyImage(I2);
  1119. X         free((char *)bitdata);
  1120. X         free((char *)vertdata);
  1121. X     }
  1122. X
  1123. X     XFreeFont(dpy, fontstruct);
  1124. X }
  1125. X
  1126. X /* free pixmap and GC ... */
  1127. X XFreePixmap(dpy, canvas);
  1128. X XFreeGC(dpy, font_gc);
  1129. X
  1130. X return rotfont;
  1131. X}
  1132. X
  1133. X
  1134. X/* ---------------------------------------------------------------------- */
  1135. X
  1136. X
  1137. X/* *** Free the resources associated with a rotated font *** */
  1138. X
  1139. Xvoid XRotUnloadFont(dpy, rotfont)
  1140. X Display *dpy;
  1141. X XRotFontStruct *rotfont;
  1142. X{
  1143. X int ichar;
  1144. X
  1145. X if(rotfont->dir==0)
  1146. X     XFreeFont(dpy, rotfont->xfontstruct);
  1147. X
  1148. X else
  1149. X     /* loop through each character, freeing its pixmap ... */
  1150. X     for(ichar=rotfont->min_char-32; ichar<=rotfont->max_char-32; ichar++)
  1151. X         XFreePixmap(dpy, rotfont->per_char[ichar].glyph.bm);
  1152. X
  1153. X /* rotfont should never be referenced again ... */
  1154. X free((char *)rotfont);
  1155. X}
  1156. X
  1157. X
  1158. X/* ---------------------------------------------------------------------- */
  1159. X   
  1160. X
  1161. X/* *** Return the width of a string *** */
  1162. X
  1163. Xint XRotTextWidth(rotfont, str, len)
  1164. X XRotFontStruct *rotfont;
  1165. X char *str;
  1166. X int len;
  1167. X{
  1168. X int i, width=0, ichar;
  1169. X
  1170. X if(str==NULL) 
  1171. X     return 0;
  1172. X
  1173. X if(rotfont->dir==0)
  1174. X     width=XTextWidth(rotfont->xfontstruct, str, strlen(str));
  1175. X
  1176. X else
  1177. X     for(i=0; i<len; i++) {
  1178. X         ichar=str[i]-32;
  1179. X  
  1180. X         /* make sure it's a printing character ... */
  1181. X         if(ichar>=0 && ichar<95) 
  1182. X             width+=rotfont->per_char[ichar].width;
  1183. X     }
  1184. X
  1185. X return width;
  1186. X}
  1187. X
  1188. X
  1189. X/* ---------------------------------------------------------------------- */
  1190. X
  1191. X
  1192. X/* *** A front end to XRotPaintString : mimics XDrawString *** */
  1193. X
  1194. Xvoid XRotDrawString(dpy, rotfont, drawable, gc, x, y, str, len)
  1195. X Display *dpy;
  1196. X XRotFontStruct *rotfont;
  1197. X Drawable drawable;
  1198. X GC gc;
  1199. X int x, y;
  1200. X char *str;
  1201. X int len;
  1202. X{
  1203. X XRotPaintString(dpy, rotfont, drawable, gc, x, y, str, len, False);
  1204. X}
  1205. X
  1206. X
  1207. X/* ---------------------------------------------------------------------- */
  1208. X
  1209. X/* *** A front end to XRotPaintString : mimics XDrawImageString *** */
  1210. X
  1211. Xvoid XRotDrawImageString(dpy, rotfont, drawable, gc, x, y, str, len)
  1212. X Display *dpy;
  1213. X XRotFontStruct *rotfont;
  1214. X Drawable drawable;
  1215. X GC gc;
  1216. X int x, y;
  1217. X char *str;
  1218. X int len;
  1219. X{
  1220. X XRotPaintString(dpy, rotfont, drawable, gc, x, y, str, len, True);
  1221. X}
  1222. X
  1223. X
  1224. X/* ---------------------------------------------------------------------- */
  1225. X              
  1226. X              
  1227. X/* *** Paint a simple string with a rotated font *** */
  1228. X
  1229. X/* *** The user should use one of the two front ends above *** */
  1230. X
  1231. Xvoid XRotPaintString(dpy, rotfont, drawable, gc, x, y, str, len, paintbg)
  1232. X Display *dpy;
  1233. X XRotFontStruct *rotfont;
  1234. X Drawable drawable;
  1235. X GC gc;
  1236. X int x, y;
  1237. X char *str;
  1238. X int len;
  1239. X Bool paintbg;
  1240. X{            
  1241. X static GC my_gc=0;
  1242. X XGCValues values;
  1243. X int i, xp, yp, dir, ichar, width;
  1244. X#ifdef X11R3
  1245. X static Pixmap empty_stipple=0;
  1246. X#endif 
  1247. X
  1248. X if(str==NULL || len<1)
  1249. X     return;
  1250. X
  1251. X dir=rotfont->dir;
  1252. X
  1253. X if(my_gc==0)
  1254. X     my_gc=XCreateGC(dpy, drawable, NULL, 0);
  1255. X
  1256. X XCopyGC(dpy, gc, GCForeground|GCBackground, my_gc);
  1257. X
  1258. X /* a horizontal string is easy ... */
  1259. X if(dir==0) {
  1260. X     XSetFillStyle(dpy, my_gc, FillSolid);
  1261. X     XSetFont(dpy, my_gc, rotfont->xfontstruct->fid);
  1262. X     if(!paintbg)
  1263. X         XDrawString(dpy, drawable, my_gc, x, y, str, len);
  1264. X     else
  1265. X         XDrawImageString(dpy, drawable, my_gc, x, y, str, len);
  1266. X     return;
  1267. X }
  1268. X
  1269. X /* vertical or upside down ... */
  1270. X
  1271. X /* to draw an `image string' we need to fill the background ... */
  1272. X if(paintbg) {
  1273. X
  1274. X#ifdef X11R3
  1275. X     /* Release 3 doesn't have XGetGCValues(), so this is a
  1276. X        slightly slower fudge ... */
  1277. X     {
  1278. X      GC stipple_gc;
  1279. X      int bestw, besth;
  1280. X
  1281. X      if(empty_stipple==0) {
  1282. X          XQueryBestStipple(dpy, drawable, 1, 1, &bestw, &besth);
  1283. X          empty_stipple=XCreatePixmap(dpy, drawable, bestw, besth, 1);
  1284. X
  1285. X          stipple_gc=XCreateGC(dpy, empty_stipple, NULL, 0);
  1286. X          XSetForeground(dpy, stipple_gc, 0);
  1287. X
  1288. X          XFillRectangle(dpy, empty_stipple, stipple_gc, 0, 0,
  1289. X                         bestw+1, besth+1);
  1290. X          XFreeGC(dpy, stipple_gc);
  1291. X      }
  1292. X
  1293. X      XSetStipple(dpy, my_gc, empty_stipple);
  1294. X      XSetFillStyle(dpy, my_gc, FillOpaqueStippled);
  1295. X     }    
  1296. X#else
  1297. X     /* get the foreground and background colors
  1298. X        ( note that this is not a round trip -> little speed penalty ) */
  1299. X     XGetGCValues(dpy, my_gc, GCForeground|GCBackground, &values);
  1300. X
  1301. X     XSetForeground(dpy, my_gc, values.background);
  1302. X     XSetFillStyle(dpy, my_gc, FillSolid);
  1303. X#endif 
  1304. X
  1305. X     width=XRotTextWidth(rotfont, str, strlen(str));
  1306. X     if(dir==1)
  1307. X         XFillRectangle(dpy, drawable, my_gc, x-rotfont->max_ascent+1, y-width,
  1308. X                        rotfont->height-1, width);
  1309. X     else if(dir==2)
  1310. X         XFillRectangle(dpy, drawable, my_gc, x-width, y-rotfont->max_descent+1,
  1311. X                        width, rotfont->height-1);
  1312. X     else
  1313. X         XFillRectangle(dpy, drawable, my_gc, x-rotfont->max_descent+1,
  1314. X                        y, rotfont->height-1, width);
  1315. X
  1316. X#ifndef X11R3
  1317. X   XSetForeground(dpy, my_gc, values.foreground);
  1318. X#endif 
  1319. X }
  1320. X
  1321. X XSetFillStyle(dpy, my_gc, FillStippled);
  1322. X
  1323. X /* loop through each character in string ... */
  1324. X for(i=0; i<len; i++) {
  1325. X     ichar=str[i]-32;
  1326. X
  1327. X     /* make sure it's a printing character ... */
  1328. X     if(ichar>=0 && ichar<95) {
  1329. X         /* suitable offset ... */
  1330. X         if(dir==1) {
  1331. X             xp=x-rotfont->per_char[ichar].ascent;
  1332. X             yp=y-rotfont->per_char[ichar].rbearing; 
  1333. X         }
  1334. X         else if(dir==2) {
  1335. X             xp=x-rotfont->per_char[ichar].rbearing;
  1336. X             yp=y-rotfont->per_char[ichar].descent+1; 
  1337. X         }
  1338. X         else {
  1339. X             xp=x-rotfont->per_char[ichar].descent+1;  
  1340. X             yp=y+rotfont->per_char[ichar].lbearing; 
  1341. X         }
  1342. X                   
  1343. X         /* draw the glyph ... */
  1344. X         XSetStipple(dpy, my_gc, rotfont->per_char[ichar].glyph.bm);
  1345. X    
  1346. X         XSetTSOrigin(dpy, my_gc, xp, yp);
  1347. X      
  1348. X         XFillRectangle(dpy, drawable, my_gc, xp, yp,
  1349. X                        rotfont->per_char[ichar].glyph.bit_w,
  1350. X                        rotfont->per_char[ichar].glyph.bit_h);
  1351. X    
  1352. X         /* advance position ... */
  1353. X         if(dir==1)
  1354. X             y-=rotfont->per_char[ichar].width;
  1355. X         else if(dir==2)
  1356. X             x-=rotfont->per_char[ichar].width;
  1357. X         else 
  1358. X             y+=rotfont->per_char[ichar].width;
  1359. X         }
  1360. X     }
  1361. X}
  1362. X  
  1363. X    
  1364. X/* ---------------------------------------------------------------------- */
  1365. X
  1366. X
  1367. X/* *** A front end to XRotPaintAlignedString : uses XRotDrawString *** */
  1368. X
  1369. Xvoid XRotDrawAlignedString(dpy, rotfont, drawable, gc, x, y,
  1370. X                                  text, align)
  1371. X Display *dpy;                    
  1372. X XRotFontStruct *rotfont;
  1373. X Drawable drawable;
  1374. X GC gc;
  1375. X int x, y;
  1376. X char *text;
  1377. X int align;
  1378. X{
  1379. X XRotPaintAlignedString(dpy, rotfont, drawable, gc, x, y, text, align, False);
  1380. X}
  1381. X
  1382. X
  1383. X/* ---------------------------------------------------------------------- */
  1384. X
  1385. X
  1386. X/* *** A front end to XRotPaintAlignedString : uses XRotDrawImageString *** */
  1387. X
  1388. Xvoid XRotDrawAlignedImageString(dpy, rotfont, drawable, gc, x, y,
  1389. X                                  text, align)
  1390. X Display *dpy;
  1391. X XRotFontStruct *rotfont;
  1392. X Drawable drawable;  
  1393. X GC gc;
  1394. X int x, y;
  1395. X char *text;
  1396. X int align;
  1397. X{
  1398. X XRotPaintAlignedString(dpy, rotfont, drawable, gc, x, y, text, align, True);
  1399. X}
  1400. X
  1401. X
  1402. X/* ---------------------------------------------------------------------- */
  1403. X                   
  1404. X                   
  1405. X/* *** Routine to paint a string, possibly containing newline characters,
  1406. X                                                       with alignment *** */
  1407. X
  1408. X/* *** The user should use one of the front ends above *** */
  1409. X
  1410. Xvoid XRotPaintAlignedString(dpy, rotfont, drawable, gc, x, y, text,
  1411. X                            align, paintbg)
  1412. X Display *dpy;
  1413. X XRotFontStruct *rotfont;
  1414. X Drawable drawable;
  1415. X GC gc;
  1416. X int x, y;
  1417. X char *text;
  1418. X int align;
  1419. X Bool paintbg;
  1420. X{  
  1421. X int xp, yp, dir;
  1422. X int i, nl=1, max_width=0, this_width;
  1423. X char *str1, *str2="\n\0", *str3;
  1424. X
  1425. X if(text==NULL) 
  1426. X     return;
  1427. X  
  1428. X dir=rotfont->dir;
  1429. X
  1430. X /* count number of sections in string ... */
  1431. X for(i=0; i<strlen(text); i++) 
  1432. X     if(text[i]=='\n') 
  1433. X         nl++;
  1434. X
  1435. X /* find width of longest section ... */
  1436. X str1=my_strdup(text);
  1437. X str3=my_strtok(str1, str2);
  1438. X max_width=XRotTextWidth(rotfont, str3, strlen(str3));
  1439. X
  1440. X do {
  1441. X     str3=my_strtok((char *)NULL, str2);
  1442. X     if(str3!=NULL)
  1443. X         if(XRotTextWidth(rotfont, str3, strlen(str3))>max_width)
  1444. X             max_width=XRotTextWidth(rotfont, str3, strlen(str3));
  1445. X }
  1446. X while(str3!=NULL);
  1447. X /* calculate vertical starting point according to alignment policy and
  1448. X      rotation angle ... */
  1449. X if(dir==0) {
  1450. X     if(align==TLEFT || align==TCENTRE || align==TRIGHT)
  1451. X         yp=y+rotfont->max_ascent;
  1452. X
  1453. X     else if(align==BLEFT || align==BCENTRE || align==BRIGHT)
  1454. X         yp=y-(nl-1)*rotfont->height - rotfont->max_descent;
  1455. X
  1456. X     else 
  1457. X         yp=y-(nl-1)/2*rotfont->height + rotfont->max_ascent -
  1458. X            rotfont->height/2 - ( (nl%2==0)?rotfont->height/2:0 ); 
  1459. X }
  1460. X
  1461. X else if(dir==1) {
  1462. X     if(align==TLEFT || align==TCENTRE || align==TRIGHT)
  1463. X         xp=x+rotfont->max_ascent;
  1464. X
  1465. X     else if(align==BLEFT || align==BCENTRE || align==BRIGHT)
  1466. X         xp=x-(nl-1)*rotfont->height - rotfont->max_descent;
  1467. X
  1468. X     else 
  1469. X         xp=x-(nl-1)/2*rotfont->height + rotfont->max_ascent -
  1470. X            rotfont->height/2 - ( (nl%2==0)?rotfont->height/2:0 ); 
  1471. X }
  1472. X
  1473. X else if(dir==2) {
  1474. X     if(align==TLEFT || align==TCENTRE || align==TRIGHT)
  1475. X         yp=y-rotfont->max_ascent;
  1476. X     
  1477. X     else if(align==BLEFT || align==BCENTRE || align==BRIGHT)
  1478. X         yp=y+(nl-1)*rotfont->height + rotfont->max_descent;
  1479. X     
  1480. X     else 
  1481. X         yp=y+(nl-1)/2*rotfont->height - rotfont->max_ascent +
  1482. X            rotfont->height/2 + ( (nl%2==0)?rotfont->height/2:0 ); 
  1483. X }
  1484. X
  1485. X else {
  1486. X     if(align==TLEFT || align==TCENTRE || align==TRIGHT)
  1487. X         xp=x-rotfont->max_ascent;
  1488. X    
  1489. X     else if(align==BLEFT || align==BCENTRE || align==BRIGHT)
  1490. X         xp=x+(nl-1)*rotfont->height + rotfont->max_descent;
  1491. X  
  1492. X     else 
  1493. X         xp=x+(nl-1)/2*rotfont->height - rotfont->max_ascent +
  1494. X            rotfont->height/2 + ( (nl%2==0)?rotfont->height/2:0 ); 
  1495. X }
  1496. X
  1497. X str1=my_strdup(text);
  1498. X str3=my_strtok(str1, str2);
  1499. X  
  1500. X /* loop through each section in the string ... */
  1501. X do {
  1502. X     /* width of this section ... */
  1503. X     this_width=XRotTextWidth(rotfont, str3, strlen(str3));
  1504. X
  1505. X     /* horizontal alignment ... */
  1506. X     if(dir==0) {
  1507. X         if(align==TLEFT || align==MLEFT || align==BLEFT)
  1508. X             xp=x;
  1509. X  
  1510. X         else if(align==TCENTRE || align==MCENTRE || align==BCENTRE)
  1511. X             xp=x-this_width/2;
  1512. X         else 
  1513. X             xp=x-max_width; 
  1514. X     }   
  1515. X
  1516. X     else if(dir==1) {
  1517. X         if(align==TLEFT || align==MLEFT || align==BLEFT)
  1518. X             yp=y;
  1519. X
  1520. X         else if(align==TCENTRE || align==MCENTRE || align==BCENTRE)
  1521. X             yp=y+this_width/2;
  1522. X
  1523. X         else 
  1524. X             yp=y+max_width; 
  1525. X     }
  1526. X
  1527. X     else if(dir==2) {
  1528. X         if(align==TLEFT || align==MLEFT || align==BLEFT)
  1529. X             xp=x;
  1530. X  
  1531. X         else if(align==TCENTRE || align==MCENTRE || align==BCENTRE)
  1532. X             xp=x+this_width/2;
  1533. X         else 
  1534. X             xp=x+max_width; 
  1535. X     }
  1536. X
  1537. X     else {
  1538. X         if(align==TLEFT || align==MLEFT || align==BLEFT)  
  1539. X             yp=y;
  1540. X     
  1541. X         else if(align==TCENTRE || align==MCENTRE || align==BCENTRE)
  1542. X             yp=y-this_width/2;
  1543. X     
  1544. X         else 
  1545. X             yp=y-max_width; 
  1546. X     }
  1547. X
  1548. X     /* draw the section ... */
  1549. X     if(!paintbg)
  1550. X         XRotDrawString(dpy, rotfont, drawable, gc, xp, yp,
  1551. X                        str3, strlen(str3));
  1552. X     else
  1553. X         XRotDrawImageString(dpy, rotfont, drawable, gc, xp, yp, 
  1554. X                             str3, strlen(str3));  
  1555. X
  1556. X     str3=my_strtok((char *)NULL, str2);
  1557. X
  1558. X     /* advance position ... */
  1559. X     if(dir==0)
  1560. X         yp+=rotfont->height;
  1561. X     else if(dir==1)
  1562. X         xp+=rotfont->height;
  1563. X     else if(dir==2)
  1564. X         yp-=rotfont->height;
  1565. X     else 
  1566. X         xp-=rotfont->height;
  1567. X }
  1568. X while(str3!=NULL);
  1569. X}
  1570. X
  1571. END_OF_FILE
  1572. if test 21724 -ne `wc -c <'xvertext.2.0/rotated.c'`; then
  1573.     echo shar: \"'xvertext.2.0/rotated.c'\" unpacked with wrong size!
  1574. fi
  1575. # end of 'xvertext.2.0/rotated.c'
  1576. fi
  1577. if test -f 'xvertext.2.0/rotated.h' -a "${1}" != "-c" ; then 
  1578.   echo shar: Will not clobber existing file \"'xvertext.2.0/rotated.h'\"
  1579. else
  1580. echo shar: Extracting \"'xvertext.2.0/rotated.h'\" \(2116 characters\)
  1581. sed "s/^X//" >'xvertext.2.0/rotated.h' <<'END_OF_FILE'
  1582. X/* ************************************************************************ */
  1583. X
  1584. X
  1585. X/* Header file for the `xvertext' routines.
  1586. X
  1587. X   Copyright (c) 1992 Alan Richardson (mppa3@uk.ac.sussex.syma) */
  1588. X
  1589. X
  1590. X/* ************************************************************************ */
  1591. X
  1592. X
  1593. X#ifndef _XVERTEXT_INCLUDED_ 
  1594. X#define _XVERTEXT_INCLUDED_
  1595. X
  1596. X
  1597. X#define XV_VERSION      2.0
  1598. X#define XV_COPYRIGHT    "xvertext routines Copyright (c) 1992 Alan Richardson"
  1599. X
  1600. X
  1601. X/* ---------------------------------------------------------------------- */
  1602. X
  1603. X
  1604. X/* *** The font structures *** */
  1605. X
  1606. Xtypedef struct {
  1607. X    int             bit_w;
  1608. X    int             bit_h;
  1609. X
  1610. X    Pixmap bm;
  1611. X} BitmapStruct;
  1612. X
  1613. Xtypedef struct {
  1614. X    int             ascent;
  1615. X    int             descent;
  1616. X    int             lbearing;
  1617. X    int             rbearing;
  1618. X    int             width;
  1619. X
  1620. X    BitmapStruct     glyph;
  1621. X} XRotCharStruct;
  1622. X
  1623. Xtypedef struct {
  1624. X    int             dir;
  1625. X    int             height;
  1626. X    int             max_ascent;
  1627. X    int             max_descent;
  1628. X    int             max_char;
  1629. X    int             min_char;
  1630. X    char         *name;
  1631. X
  1632. X    XFontStruct        *xfontstruct;
  1633. X
  1634. X    XRotCharStruct     per_char[95];
  1635. X} XRotFontStruct;
  1636. X
  1637. X
  1638. X/* ---------------------------------------------------------------------- */
  1639. X
  1640. X
  1641. Xextern float         XRotVersion();
  1642. Xextern XRotFontStruct    *XRotLoadFont();
  1643. Xextern void              XRotUnloadFont();
  1644. Xextern int               XRotTextWidth();
  1645. Xextern void              XRotDrawString();
  1646. Xextern void              XRotDrawImageString();
  1647. Xextern void              XRotDrawAlignedString();
  1648. Xextern void              XRotDrawAlignedImageString();
  1649. X
  1650. X
  1651. X/* ---------------------------------------------------------------------- */
  1652. X
  1653. X
  1654. X#define TLEFT          1
  1655. X#define TCENTRE          2
  1656. X#define TRIGHT          3
  1657. X#define MLEFT          4
  1658. X#define MCENTRE          5
  1659. X#define MRIGHT          6
  1660. X#define BLEFT          7
  1661. X#define BCENTRE          8
  1662. X#define BRIGHT          9
  1663. X
  1664. X
  1665. X/* ---------------------------------------------------------------------- */
  1666. X
  1667. X
  1668. Xint             xv_errno;
  1669. X
  1670. X#define XV_NOFONT     1  /* no such font on X server */
  1671. X#define XV_NOMEM     2  /* couldn't do malloc */
  1672. X#define XV_NOXIMAGE     3  /* couldn't create an XImage */
  1673. X
  1674. X
  1675. X/* ---------------------------------------------------------------------- */
  1676. X
  1677. X#else
  1678. X
  1679. Xextern int         xv_errno;
  1680. X
  1681. X#endif 
  1682. END_OF_FILE
  1683. if test 2116 -ne `wc -c <'xvertext.2.0/rotated.h'`; then
  1684.     echo shar: \"'xvertext.2.0/rotated.h'\" unpacked with wrong size!
  1685. fi
  1686. # end of 'xvertext.2.0/rotated.h'
  1687. fi
  1688. if test -f 'xvertext.2.0/man/XRotDrawAlignedString.3' -a "${1}" != "-c" ; then 
  1689.   echo shar: Will not clobber existing file \"'xvertext.2.0/man/XRotDrawAlignedString.3'\"
  1690. else
  1691. echo shar: Extracting \"'xvertext.2.0/man/XRotDrawAlignedString.3'\" \(2956 characters\)
  1692. sed "s/^X//" >'xvertext.2.0/man/XRotDrawAlignedString.3' <<'END_OF_FILE'
  1693. X.\" @(#)XRotDrawAlignedString 1.3 8/12/92; Copyright (c) 1992 Alan Richardson
  1694. X.TH XRotDrawAlignedString 3 "8 Dec 1992" "xvertext routines"
  1695. X.SH NAME
  1696. XXRotDrawAlignedString, XRotDrawAlignedImageString \- draw strings 
  1697. Xcontaining newlines in a rotated font, with alignment
  1698. X.SH SYNOPSIS
  1699. X.B void XRotDrawAlignedString(dpy, rotfont, drawable, gc, x,
  1700. X.B y, text, align)
  1701. X.br
  1702. X.B Display *dpy;
  1703. X.br
  1704. X.B XRotFontStruct *rotfont;
  1705. X.br
  1706. X.B Drawable drawable;
  1707. X.br
  1708. X.B GC gc;
  1709. X.br
  1710. X.B int x, y;
  1711. X.br
  1712. X.B char *text;
  1713. X.br
  1714. X.B int align
  1715. X.PP
  1716. X.B void XRotDrawAlignedImageString(dpy, rotfont, drawable, gc, x,
  1717. X.B y, text, align)
  1718. X.br
  1719. X.B Display *dpy;
  1720. X.br
  1721. X.B XRotFontStruct *rotfont;
  1722. X.br
  1723. X.B Drawable drawable;
  1724. X.br
  1725. X.B GC gc;
  1726. X.br
  1727. X.B int x, y;
  1728. X.br
  1729. X.B char *text;
  1730. X.br
  1731. X.B int align
  1732. X.SH ARGUMENTS
  1733. X.IP \fIdisplay\fP 1i     
  1734. XSpecifies the connection to the X server.
  1735. X.IP \fIrotfont\fP 1i
  1736. XAn XRotFontStruct structure, returned by \fIXRotLoadFont\fP,
  1737. Xdescribing a rotated font. 
  1738. X.IP \fIdrawable\fP 1i
  1739. XThe window or pixmap in which to paint the text.
  1740. X.IP \fIgc\fP 1i
  1741. XThe graphics context to use when painting text.
  1742. X.IP \fIx\,\ y\fP 1i
  1743. XCoordinates whose relation to the postion of the painted text is given
  1744. Xby \fIalign\fP.
  1745. X.IP \fItext\fP 1i
  1746. XA character string.
  1747. X.IP \fIalign\fP 1i
  1748. XDescribes the alignment with which to draw the string.
  1749. X.SH DESCRIPTION
  1750. X.PP
  1751. XThe
  1752. X.I XRotDrawAlignedString
  1753. Xand
  1754. X.I XRotDrawAlignedImageString
  1755. Xfunctions are both used to paint the character string
  1756. X.I text
  1757. Xin the rotated font described
  1758. Xby
  1759. X.I rotfont.
  1760. X.PP
  1761. XThese functions are capable of drawing strings containing newline
  1762. Xcharacters, by treating these newlines as delimiters to
  1763. Xsubstrings. A substring is painted above, below, left or right of the
  1764. Xprevious substring depending on the font direction.
  1765. X.PP
  1766. XThe alignment argument
  1767. X.I align
  1768. Xdescribes how to position the block of substrings in relation to the point
  1769. X.I (x\,\ y).
  1770. X.I Align
  1771. Xcan take one of the values:
  1772. X.I TLEFT, TCENTRE, TRIGHT, MLEFT, MCENTRE, MRIGHT,
  1773. X.I BLEFT, BCENTRE, BRIGHT.
  1774. XNote that alignment refers to a
  1775. X.I rotated set of axes;
  1776. Xe.g. for a font rotated at 90 degrees, the `vertical' direction
  1777. Xactually runs East-West on the screen.
  1778. XThe first character describes how the block is positioned `vertically'
  1779. Xwith respect to the reference point;
  1780. XT=Top, M=Middle, B=Bottom. The remaining phrase describes 'horizontal'
  1781. Xpositioning;
  1782. XLEFT, CENTRE or RIGHT. The value
  1783. X.I MCENTRE
  1784. X centres the block at the
  1785. Xreference point. See the manual page for
  1786. X.I xvertext
  1787. Xfor more details of alignment.
  1788. X.PP
  1789. XThe two functions differ in that
  1790. X.I XRotDrawAlignedString
  1791. Xleaves the background pixels untouched, drawing the text in the
  1792. Xforeground colours of
  1793. X.I gc.
  1794. X.I XRotDrawAlignedImageString
  1795. Xfills the background in with the background colour of 
  1796. X.I gc
  1797. Xbefore painting the text. Note that only the foreground and background
  1798. Xattributes of
  1799. X.I gc
  1800. Xare used by these functions.
  1801. X.SH SEE ALSO
  1802. Xxvertext,
  1803. XXRotVersion,
  1804. XXRotLoadFont,
  1805. XXRotUnloadFont, 
  1806. XXRotTextWidth,
  1807. XXRotDrawString,
  1808. XXRotDrawImageString.
  1809. END_OF_FILE
  1810. if test 2956 -ne `wc -c <'xvertext.2.0/man/XRotDrawAlignedString.3'`; then
  1811.     echo shar: \"'xvertext.2.0/man/XRotDrawAlignedString.3'\" unpacked with wrong size!
  1812. fi
  1813. # end of 'xvertext.2.0/man/XRotDrawAlignedString.3'
  1814. fi
  1815. if test -f 'xvertext.2.0/man/XRotDrawString.3' -a "${1}" != "-c" ; then 
  1816.   echo shar: Will not clobber existing file \"'xvertext.2.0/man/XRotDrawString.3'\"
  1817. else
  1818. echo shar: Extracting \"'xvertext.2.0/man/XRotDrawString.3'\" \(2092 characters\)
  1819. sed "s/^X//" >'xvertext.2.0/man/XRotDrawString.3' <<'END_OF_FILE'
  1820. X.\" @(#)XRotDrawString 1.3 8/12/92; Copyright (c) 1992 Alan Richardson
  1821. X.TH XRotDrawString 3 "8 Dec 1992" "xvertext routines"
  1822. X.SH NAME
  1823. XXRotDrawString, XRotDrawImageString \- draw simple strings in a 
  1824. Xrotated font
  1825. X.SH SYNOPSIS
  1826. X.B void XRotDrawString(dpy, rotfont, drawable, gc, x,
  1827. X.B y, str, len)
  1828. X.br
  1829. X.B Display *dpy;
  1830. X.br
  1831. X.B XRotFontStruct *rotfont;
  1832. X.br
  1833. X.B Drawable drawable;
  1834. X.br
  1835. X.B GC gc;
  1836. X.br
  1837. X.B int x, y;
  1838. X.br
  1839. X.B char *str;
  1840. X.br
  1841. X.B int len;
  1842. X.PP
  1843. X.B void XRotDrawImageString(dpy, rotfont, drawable, gc, x,
  1844. X.B y, str, len)
  1845. X.br
  1846. X.B Display *dpy;
  1847. X.br
  1848. X.B XRotFontStruct *rotfont;
  1849. X.br
  1850. X.B Drawable drawable;
  1851. X.br
  1852. X.B GC gc;
  1853. X.br
  1854. X.B int x, y
  1855. X.br
  1856. X.B char *str;
  1857. X.br
  1858. X.B int len;
  1859. X.SH ARGUMENTS
  1860. X.IP \fIdisplay\fP 1i     
  1861. XSpecifies the connection to the X server.
  1862. X.IP \fIrotfont\fP 1i
  1863. XAn XRotFontStruct structure, returned by \fIXRotLoadFont\fP,
  1864. Xdescribing a rotated font. 
  1865. X.IP \fIdrawable\fP 1i
  1866. XThe window or pixmap in which to paint the text.
  1867. X.IP \fIgc\fP 1i
  1868. XThe graphics context to use when painting text.
  1869. X.IP \fIx\,\ y\fP 1i
  1870. XThe coordinates of the lower left hand corner of the leftmost character in
  1871. X\fIstr\fP.
  1872. X.IP \fIstr\fP 1i
  1873. XA character string.
  1874. X.IP \fIlen\fP 1i
  1875. XThe number of characters in \fIstr\fP.
  1876. X.SH DESCRIPTION
  1877. X.PP
  1878. XThe
  1879. X.I XRotDrawString
  1880. Xand
  1881. X.I XRotDrawImageString
  1882. Xfunctions are both used to paint the simple string
  1883. X.I str
  1884. Xin the rotated font described
  1885. Xby
  1886. X.I rotfont.
  1887. XSimple in this case means containing no newline characters. No alignment
  1888. Xis performed \- the string is always painted with the lower left
  1889. Xhand corner of the leftmost character at the position 
  1890. X.I (x\,\ y).
  1891. X.PP
  1892. XThe two functions differ in that 
  1893. X.I XRotDrawString
  1894. Xleaves the background pixels untouched, drawing the text in the foreground
  1895. Xcolour of 
  1896. X.I gc.
  1897. X.I XRotDrawImageString
  1898. Xfills the background in with the background colour of
  1899. X.I gc\,
  1900. Xbefore painting the text in the foreground
  1901. Xcolour of
  1902. X.I gc.
  1903. XNote that only the foreground and background attributes of 
  1904. X.I gc
  1905. Xare used by these functions.
  1906. X.SH SEE ALSO
  1907. Xxvertext,
  1908. XXRotVersion,
  1909. XXRotLoadFont,
  1910. XXRotUnloadFont,   
  1911. XXRotTextWidth,
  1912. XXRotDrawAlignedString,
  1913. XXRotDrawAlignedImageString.
  1914. X
  1915. X
  1916. X
  1917. END_OF_FILE
  1918. if test 2092 -ne `wc -c <'xvertext.2.0/man/XRotDrawString.3'`; then
  1919.     echo shar: \"'xvertext.2.0/man/XRotDrawString.3'\" unpacked with wrong size!
  1920. fi
  1921. # end of 'xvertext.2.0/man/XRotDrawString.3'
  1922. fi
  1923. if test -f 'xvertext.2.0/man/XRotLoadFont.3' -a "${1}" != "-c" ; then 
  1924.   echo shar: Will not clobber existing file \"'xvertext.2.0/man/XRotLoadFont.3'\"
  1925. else
  1926. echo shar: Extracting \"'xvertext.2.0/man/XRotLoadFont.3'\" \(4250 characters\)
  1927. sed "s/^X//" >'xvertext.2.0/man/XRotLoadFont.3' <<'END_OF_FILE'
  1928. X.\" @(#)XRotLoadFont 1.3 8/12/92; Copyright (c) 1992 Alan Richardson
  1929. X.TH XRotLoadFont 3 "8 Dec 1992" "xvertext routines"
  1930. X.SH NAME
  1931. XXRotVersion, XRotLoadFont, XRotUnloadFont, XRotTextWidth - manipulate rotated fonts
  1932. X.SH SYNOPSIS
  1933. X.B float XRotVersion(copyright, nmax)
  1934. X.br
  1935. X.B "   " char *copyright;
  1936. X.br
  1937. X.B "   " int nmax;
  1938. X.PP
  1939. X.B XRotFontStruct *XRotLoadFont(dpy, fontname, angle)
  1940. X.br
  1941. X.B "   " Display *dpy;
  1942. X.br
  1943. X.B "   " char *fontname;
  1944. X.br
  1945. X.B "   " float angle;
  1946. X.PP
  1947. X.B void XRotUnloadFont(dpy, rotfont)
  1948. X.br
  1949. X.B "   " Display *dpy;
  1950. X.br
  1951. X.B "   " XRotFontStruct *rotfont; 
  1952. X.PP
  1953. X.B int XRotTextWidth(rotfont, str, len)
  1954. X.br
  1955. X.B "   " XRotFontStruct *rotfont;
  1956. X.br
  1957. X.B "   " char *str;
  1958. X.br
  1959. X.B "   " int len;
  1960. X.SH ARGUMENTS
  1961. X.IP \fIcopyright\fP 1i
  1962. XA character string to hold copyright information.
  1963. X.IP \fInmax\fP 1i
  1964. XThe maximum number of characters to be placed in \fIcopyright\fP.
  1965. X.IP \fIdisplay\fP 1i     
  1966. XSpecifies the connection to the X server.
  1967. X.IP \fIfontname\fP 1i
  1968. XName of the font to load and rotate.
  1969. X.IP \fIangle\fP 1i
  1970. XAngle of rotation desired in degrees.
  1971. X.IP \fIrotfont\fP 1i
  1972. XAn XRotFontStruct structure, returned by \fIXRotLoadFont\fP,
  1973. Xdescribing a rotated font. 
  1974. X.IP \fIstr\fP 1i
  1975. XA character string.
  1976. X.IP \fIlen\fP 1i
  1977. XThe number of characters in \fIstr\fP.
  1978. X.SH DESCRIPTION
  1979. X.PP
  1980. XThe
  1981. X.I XRotVersion
  1982. Xfunction returns the current version number of the xvertext routines.
  1983. XIt also places into
  1984. X.I copyright
  1985. Xat most
  1986. X.I nmax
  1987. Xcharacters of a copyright string.
  1988. X.PP
  1989. XThe
  1990. X.I XRotLoadFont
  1991. Xfunction loads the font described by 
  1992. X.I fontname
  1993. Xand rotates each printing character in turn by the given angle.
  1994. X.I Angle
  1995. Xshould be a whole multiple of 90
  1996. Xdegrees, otherwise it is rounded to the nearest such multiple.
  1997. XPositive angles are deemed to be anticlockwise, negative angles clockwise.
  1998. X.I XRotLoadFont 
  1999. Xreturns an
  2000. X.I XRotFontStruct
  2001. Xstructure containing a complete description of the rotated font.
  2002. X.PP
  2003. XThe
  2004. X.I XRotUnloadFont
  2005. Xfunction frees the resources associated with the given 
  2006. X.I XRotFontStruct 
  2007. Xstructure. This font should not be referenced again.
  2008. X.PP
  2009. XThe
  2010. X.I XRotTextWidth
  2011. Xfunction calculates the length of a string in pixels if painted in
  2012. Xa particular rotated font. In fact, this is just the length the Xlib function
  2013. X.I XTextWidth
  2014. Xwould return if the font were not rotated.
  2015. XThe height of the tallest character in a font is given by the
  2016. X.I height
  2017. Xmember of the
  2018. X.I XRotFontStruct
  2019. Xstructure (see below).
  2020. X.SH STRUCTURES
  2021. XThe 
  2022. X.I XRotFontStruct
  2023. Xstructure is loosely modeled on the Xlib structure
  2024. X.I XFontStruct,
  2025. Xwith some unnecessary information omitted:
  2026. X.PP
  2027. Xtypedef struct {
  2028. X    int                  dir;
  2029. X    int                  height;
  2030. X    int                  max_ascent;
  2031. X    int                  max_descent;
  2032. X    int                  max_char;
  2033. X    int                  min_char;
  2034. X    char                *name;
  2035. X
  2036. X    XFontStruct         *xfontstruct;
  2037. X
  2038. X    XRotCharStruct       per_char[95];
  2039. X} XRotFontStruct;
  2040. X.PP
  2041. XThe value of dir is 0,1,2 or 3 corresponding to 0, 90, 180 and 270 degrees.
  2042. XThe members height, max_ascent, and max_descent are overall font 
  2043. Xdimensions. The values max_char and min_char describe which characters in this
  2044. Xfont are defined. The xfontstruct member is only used for direction 0
  2045. X(`normal') text, when no rotation is required.
  2046. X.PP
  2047. XThe
  2048. X.I XRotCharStruct
  2049. Xstructure contains:
  2050. X
  2051. Xtypedef struct {
  2052. X    int                  ascent;
  2053. X    int                  descent;
  2054. X    int                  lbearing;
  2055. X    int                  rbearing;
  2056. X    int                  width;
  2057. X
  2058. X    BitmapStruct         glyph;
  2059. X} XRotCharStruct;
  2060. X.PP
  2061. XThis gives per-character size information; the
  2062. X.I BitmapStruct
  2063. Xstructure holds the rotated bitmap for a particular character:
  2064. X
  2065. Xtypedef struct {
  2066. X    int                  bit_w;
  2067. X    int                  bit_h;
  2068. X
  2069. X    Pixmap               bm;
  2070. X} BitmapStruct;
  2071. X
  2072. X.SH DIAGNOSTICS
  2073. X.I XRotLoadFont
  2074. Xreturns 
  2075. X.I NULL
  2076. Xif it fails. The integer 
  2077. X.I xv_errno,
  2078. Xdeclared in
  2079. X.I rotated.h,
  2080. Xis set to a value describing the reason for failure:
  2081. X.IP \fIXV_NOFONT\fP 1i
  2082. XNo font called \fIfontname\fP could be loaded by the X server.
  2083. X.IP \fIXV_NOMEM\fP 1i
  2084. XA call to \fImalloc\fP failed.
  2085. X.IP \fIXV_NOXIMAGE\fP 1i
  2086. XA call to \fIXCreateImage\fP failed.
  2087. X.SH SEE ALSO
  2088. Xxvertext,
  2089. XXRotDrawString,
  2090. XXRotDrawImageString,
  2091. XXRotDrawAlignedString,
  2092. XXRotDrawAlignedImageString.
  2093. X
  2094. END_OF_FILE
  2095. if test 4250 -ne `wc -c <'xvertext.2.0/man/XRotLoadFont.3'`; then
  2096.     echo shar: \"'xvertext.2.0/man/XRotLoadFont.3'\" unpacked with wrong size!
  2097. fi
  2098. # end of 'xvertext.2.0/man/XRotLoadFont.3'
  2099. fi
  2100. if test -f 'xvertext.2.0/man/xvertext.3' -a "${1}" != "-c" ; then 
  2101.   echo shar: Will not clobber existing file \"'xvertext.2.0/man/xvertext.3'\"
  2102. else
  2103. echo shar: Extracting \"'xvertext.2.0/man/xvertext.3'\" \(4280 characters\)
  2104. sed "s/^X//" >'xvertext.2.0/man/xvertext.3' <<'END_OF_FILE'
  2105. X.\" @(#)xvertext 1.3 8/12/92; Copyright (c) 1992 Alan Richardson
  2106. X.TH xvertext 3 "8 Dec 1992" "xvertext routines"
  2107. X.SH NAME
  2108. Xxvertext - a collection of functions for rendering vertical text in an
  2109. XX window
  2110. X.SH GENERAL
  2111. XAs of version 2.0 there are 8 functions in the xvertext package 
  2112. Xintended for general use. These are
  2113. X.I XRotVersion,
  2114. X.I XRotLoadFont,
  2115. X.I XRotUnloadFont,
  2116. X.I XRotTextWidth,
  2117. X.I XRotDrawString,
  2118. X.I XRotDrawImageString,
  2119. X.I XRotDrawAlignedString
  2120. Xand
  2121. X.I XRotDrawAlignedImageString.
  2122. X.SH USAGE
  2123. X.I XRotVersion 
  2124. Xis used to obtain the current release number and a copyright string.
  2125. X.PP
  2126. XA program using the 
  2127. X.I xvertext
  2128. Xroutines will invariably start with a call to 
  2129. X.I XRotLoadFont,
  2130. Xsince this loads and rotates a font. For example:
  2131. X
  2132. XDisplay *dpy;
  2133. X.br
  2134. XXRotFontStruct *rotfont;
  2135. X.br
  2136. Xchar *fontname=
  2137. X"lucidasans-bolditalic-10";
  2138. X.PP
  2139. X/* dpy obtained by calling XOpenDisplay() elsewhere in program */
  2140. X.PP
  2141. Xrotfont=XRotLoadFont(dpy, fontname, 90.);
  2142. X.br
  2143. Xif(rotfont==NULL) {
  2144. X.br
  2145. X    if(xv_errno==XV_NOFONT)
  2146. X        rotfont=XRotLoadFont(dpy, "fixed", 90.);
  2147. X    else {
  2148. X        if(xv_errno==XV_NOMEM)
  2149. X            fprintf(stderr, "malloc problem - can't continue");
  2150. X        else
  2151. X            fprintf(stderr, "XImage problem - can't continue");
  2152. X        exit(1);
  2153. X    }
  2154. X.br
  2155. X}
  2156. X.PP
  2157. XThis code segment attempts to load the font "lucidasans-bolditalic-10"
  2158. Xrotated at 90 degrees anticlockwise. If this fails, xv_errno is checked
  2159. Xto find the reason. A value of XV_NOFONT indicates "lucidasans-bolditalic-10"
  2160. Xisn't around, and the sure-bet font "fixed" is loaded instead. The 
  2161. Xother two errors, XV_NOMEM and XV_NOXIMAGE, indicate memory or XImage
  2162. Xfailures (and are unlikely to happen).
  2163. X.PP
  2164. XThe other calls a user is most likely to make are to
  2165. X.I XRotDrawAlignedString
  2166. Xor
  2167. X.I XRotDrawAlignedImageString.
  2168. XThese are the most general purpose text drawing functions in the package,
  2169. Xallowing the painting of strings containing newlines and specification
  2170. Xof alignment. Typical usage might be:
  2171. X.PP
  2172. XDisplay *dpy;
  2173. X.br
  2174. XXRotFontStruct *rotfont;
  2175. X.br
  2176. XWindow window;
  2177. X.br
  2178. XGC gc;
  2179. X.br
  2180. Xchar *message="This\\nis\\nno\\nordinary\\ntest";
  2181. X.PP
  2182. X/* dpy obtained by calling XOpenDisplay() elsewhere in program */
  2183. X.br
  2184. X/* window already opened */
  2185. X.br
  2186. X/* rotfont obtained as described above */
  2187. X.PP
  2188. Xgc=XCreateGC(dpy, window, NULL, 0);
  2189. X.br
  2190. XXSetForeground(dpy, gc, WhitePixel(dpy, DefaultScreen(dpy)));
  2191. X.br
  2192. XXSetBackground(dpy, gc, BlackPixel(dpy, DefaultScreen(dpy)));
  2193. X.PP
  2194. XXRotDrawAlignedImageString(dpy, rotfont, window,
  2195. Xgc, 200, 200,
  2196. X.br
  2197. X                           message, MLEFT);
  2198. X.PP
  2199. XThis example paints a five line message in white, filling the background
  2200. Xin black. The reference point is (200, 200) and with an alignment of
  2201. XMLEFT the output for a horizontal font would be (crosshairs mark
  2202. X(200, 200)):
  2203. X.PP
  2204. X                              |This
  2205. X                              |is
  2206. X                     ---------+no-------
  2207. X                              |ordinary
  2208. X                              |test
  2209. X.PP
  2210. XAlignments of MCENTER and MRIGHT would result in:
  2211. X.PP
  2212. X                 |                                   |
  2213. X                This                         This    |
  2214. X                 is                          is      |
  2215. X         --------no--------                 -no------+---------
  2216. X              ordinary                       ordinary|
  2217. X                test                         test    |
  2218. X                 |                                   |
  2219. X.PP
  2220. XThe lower level functions
  2221. X.I XRotDrawString
  2222. Xand
  2223. X.I XRotDrawImageString
  2224. Xdo not handle newline characters or apply any alignment. They
  2225. Xdraw a one line string with the lower left hand corner at a specified
  2226. Xposition. They are called by 
  2227. X.I XRotDrawAlignedString
  2228. Xand
  2229. X.I XRotDrawAlignedImageString.
  2230. X.PP
  2231. XThe function
  2232. X.I XRotTextWidth
  2233. Xis provided to enable the width of strings painted in a certain rotated
  2234. Xfont to be found. It is called by the
  2235. X.I XRotDrawAlignedString
  2236. Xand
  2237. X.I XRotDrawAlignedImageString
  2238. Xfunctions.
  2239. X.PP
  2240. XOnce a rotated font has been finished with it may be freed by calling
  2241. X.I XRotUnloadFont.
  2242. XThis frees the bitmaps representing each rotated character, or the
  2243. X.I XFontStruct
  2244. Xstructure held for `right way up' fonts.
  2245. X.SH SEE ALSO
  2246. XXRotVersion,
  2247. XXRotLoadFont,
  2248. XXRotUnloadFont,
  2249. XXRotTextWidth,
  2250. XXRotDrawString,
  2251. XXRotDrawImageString,
  2252. XXRotDrawAlignedString,
  2253. XXRotDrawAlignedImageString.
  2254. X
  2255. END_OF_FILE
  2256. if test 4280 -ne `wc -c <'xvertext.2.0/man/xvertext.3'`; then
  2257.     echo shar: \"'xvertext.2.0/man/xvertext.3'\" unpacked with wrong size!
  2258. fi
  2259. # end of 'xvertext.2.0/man/xvertext.3'
  2260. fi
  2261. echo shar: End of shell archive.
  2262. exit 0
  2263.  
  2264. exit 0 # Just in case...
  2265.