Search the FAQ Archives

3 - A - B - C - D - E - F - G - H - I - J - K - L - M
N - O - P - Q - R - S - T - U - V - W - X - Y - Z
faqs.org - Internet FAQ Archives

comp.windows.x Frequently Asked Questions (FAQ) 7/7
Section - 193) How do I render rotated text?

( Part1 - Part2 - Part3 - Part4 - Part5 - Part6 - Part7 - Single Page )
[ Usenet FAQs | Web FAQs | Documents | RFC Index | Business Photos and Profiles ]


Top Document: comp.windows.x Frequently Asked Questions (FAQ) 7/7
Previous Document: 192) How do I get a double-click in Xlib?
Next Document: 194) Why doesn't my multi-threaded X program work (sic) ?
See reader questions & answers on this topic! - Help others by sharing your knowledge

The X Logical Font Description was enhanced for R6 to allow embedding a
transformation matrix in certain fields of an XLFD name.  Thus arbitrary
rotation, scaling, shearing, etc. are possible.  To draw text along an
arbitrarily sloped line, open a font with the appropriate rotation
transformation and individually place and draw each character.  Drawing text
along a curve requires a different font for each character orientation
needed.  The overhead of opening so many fonts is somewhat mitigated by
another XLFD extension which allows you to ask for a subset of the
characters.  See section 4 of xc/doc/specs/XLFD/xlfd.tbl.ms in the R6
distribution.  Also see The X Resource, Issue Nine, p. 211, "New Font
Technology for X11R6," by Nathan Meyers.  (Note: due to changes after
publication deadline, the information in the Meyers paper about the syntax of
character set subsetting is out of date.) These capabilities are also
available to an R5 X server using an R6 font server.

If you are not using R6, your only choice, if you want to stay within the
core X protocol, is to render the text into a pixmap, read it back via
XGetImage(), rotate it "by hand" with whatever matrices you want, and put it
back to the server via XPutImage(); more specifically:

	1) create a bitmap B and write your text to it.
	2) create an XYBitmap image I from B (via XGetImage).
	3) create an XYBitmap Image I2 big enough to handle the transformation.
	4) for each x,y in I2, I2(x,y) = I(a,b) where 
		a = x * cos(theta) - y * sin(theta)
		b = x * sin(theta) + y * cos(theta)
	5) render I2

Note that you should be careful how you implement this not to lose bits; an
algorithm based on shear transformations may in fact be better.

The high-level server-extensions and graphics packages available for X also
permit rendering of rotated text: Display PostScript, PEX, PHiGS, and GKS,
although most are not capable of arbitrary rotation and probably do not use
the same fonts that would be found on a printer.

In addition, if you have enough access to the server to install a font on it,
you can create a font which consists of letters rotated at some predefined
angle. Your application can then itself figure out placement of each glyph.

[courtesy der Mouse (mouse@larry.mcrcim.mcgill.edu), Eric Taylor
(etaylor@wilkins.bmc.tmc.edu), and Ken Lee (now kenton@esd.sgi.com), 11/90;
Liam Quin (lee@sq.com), 12/90; Dave Wiggins (dpw@x.org), 5/94.]

InterViews (C++ UI toolkit, in the X contrib software) has support for
rendering rotated fonts in X.  It could be one source of example code.
[Brian R. Smith (brsmith@cs.umn.edu), 3/91]

Another possibility is to use the Hershey Fonts; they are stroke-rendered and
can be used by X by converting them into XDrawLine requests.
[eric@pencom.com, 10/91]

The xrotfont program by Alan Richardson (mppa3@syma.sussex.ac.uk) (posted to
comp.sources.x July 14 1992) paints a rotated font by implementing the method
above and by using an outline (Hershey) font.

The xvertext package by Alan Richardson (mppa3@syma.sussex.ac.uk) is a set of
functions to facilitate the writing of text at any angle.  It is on ftp.x.org
as R5contrib/xvertext.5.0.shar.Z.

O'Reilly's X Resource issue 3 includes information from HP about
modifications to the X fonts server which provide for rotated and scaled
text.  The modifications are on ftp.x.org in R5contrib/hp_xlfd_enhancements/.

Bristol Technology's XPrinter product has extensions to Xlib to rotate text.
Send email to info@bristol.com for more details.

User Contributions:

Comment about this article, ask questions, or add new information about this topic:

CAPTCHA




Top Document: comp.windows.x Frequently Asked Questions (FAQ) 7/7
Previous Document: 192) How do I get a double-click in Xlib?
Next Document: 194) Why doesn't my multi-threaded X program work (sic) ?

Part1 - Part2 - Part3 - Part4 - Part5 - Part6 - Part7 - Single Page

[ Usenet FAQs | Web FAQs | Documents | RFC Index ]

Send corrections/additions to the FAQ Maintainer:
faq%craft@uunet.uu.net (X FAQ maintenance address)





Last Update March 27 2014 @ 02:12 PM