Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!cs.utexas.edu!uunet!mcvax!ukc!acorn!ixi!clive From: clive@ixi.UUCP (Clive Feather) Newsgroups: comp.windows.x Subject: Re: Rotated text Summary: It ain't that simple Message-ID: <169@ixi.UUCP> Date: 19 May 89 07:26:04 GMT References: <105466@sun.Eng.Sun.COM> Reply-To: clive@ixi.uucp (Clive Feather) Organization: IXI Limited Lines: 109 Expires: Sender: Followup-To: In article <105466@sun.Eng.Sun.COM> argv@sun (Dan Heller) writes: >Now that I'm talking about fonts, inspection of the code *appears* >to be just shy of giving XDrawString the ability to render rotated >text. The following changes would need to happen: there needs to >be a height field in the XCharStruct data structure, and there needs >to be an ability to communicate this new information about the font >changes to the server. The application is responsible for rotating >the glyphs of the characters, of course. Firstly, changing the XCharStruct data structure means changing the protocol, and there's no way that the real world out there is going to let you (yes, I know that there have been changes from R1 to R2 to R3, but they were subtle and upwards compatible - this would be *totally* incompatible). Next, isn't the "width" and "height" of the character going to change as you change the angle ? Far more important - how is the application going to rotate the glyphs ? They're not in the XFontStruct or anything that hangs off it. This means that to get hold of them, you need to do something on the lines of: create a pixmap just big enough to hold the largest character in the font, and depth 1; create a GC for working on this pixmap; for (each character c in the font) { XSetForeground (GC, 0); XFillRectangle (the whole pixmap); XSetForeground (GC, 1); XDrawString (pixmap, an appropriate position, a string of length 1 holding c); glyph [c] = XGetImage (the pixmap); } BTW, please describe an algorithm for rotating the characters *neatly*. Finally, there is no way to turn these rotated glyphs back into a font ! The nearest that you can do is something like: Rotate the glyphs. Write them out in BDF (Bitmap Distribution Format), wrapped up to form a font. Run bdftosnf on the font. Install the font in an appropriate directory. Run mkfontdir on that directory. Reboot your server (or possibly, mess around with XSetFontPath). If you just want to write the characters at an angle, without rotating the glyphs, then the following might be of use to you: WARNING: Untested (and uncompiled) code follows. =============================== 8< ================================== /* DISCLAIMER: I am not interested in bug fixes or any other comments on this code. This has been written just to make a point. This is not supported code of IXI Limited. COPYRIGHT: This code is in the public domain (or whatever the equivalent is in English law). DESCRIPTION: XDrawAngledString (display, d, gc, fs, x, y, angle, string, length) Arguments as XDrawString, except "fs", which is the XFontStruct for the font, and "angle", which is a double. This function draws a string, placing the glyphs along a line at an angle to the horizontal, spaced at the correct distance along that line but not rotating the glyphs. */ XDrawAngledString (display, d, gc, fs, x, y, angle, string, length) Display *display; Drawable d; GC gc; XFontStruct *fs; int x, y; double angle; char *string; int length; { int i; int xx = x; int xx = y; double si = sin (angle); double co = cos (angle); char *c; for (i = 0, c = string; i < length; i++, c++) { int w; XDrawString (display, d, gc, xx, yy, c, 1); w = XTextWidth (fs, c, 1); xx += si * w; yy += co * w; } } =============================== 8< ================================== -- Clive D.W. Feather clive@ixi.uucp IXI Limited ...!mcvax!ukc!ixi!clive (riskier) +44 223 462 131