I am developing a display that contains X-Y plots. The display requirements call for the vertical axis labels for the plot to be displayed vertically. By this, I mean that the axis label text is to be "turned on its edge" so that it can be read from bottom to top. This is not the same as simply displaying the text as a series of characters that are still oriented horizontally but with one character per line.
Ideally, what I would like to be able to do is to create an XmLabel widget containing the axis label string (oriented left-to-right), and I would like to be able to "rotate" the label widget to be vertical (i.e. stand it on its end). However, I do not think that is possible, and I`m not quite sure how else to accomplish what I need to do. Any suggestions would be appreciated.
Vertically Oriented Text
I have done exactly what you wanted. This trick is to set the labe type resource of the XmLabelWidget to be pixmap type. You create a pixmap of the size of the label widget but with the width and height flipped. You draw your text as image into this pixmap as you would do regularly. The key is then you do a 90 degree rotation operation on this pixmap to get a new pixmap. Use the rotated pixmap as the XmNlabelPixmap resource value.
Vertically Oriented Text
OK... I`ve created my label with a label type of pixmap, and I`ve created a pixmap. I`ve drawn the label string to the pixmap using XDrawString. However, I can`t figure out how to rotate the pixmap. Any ideas?
Thanks.
Vertically Oriented Text
Pick up the xvertext sources. There`s a description of what they do in the old comp.windows.x FAQ, available on http//www.x.org and http//www.faqs.org .
Of course, if you`re already going to the trouble of drawing into pixmaps, you don`t need the XmLabel; just draw into the same pixmap that you`re doing your plotting into, and be prepared to redraw the label as necessary. You can also draw it as an overlay, if you want to be fancier.
Vertically Oriented Text
Here is the algorithm to use
Pixmap RotatePixmap(Widget wid, Pixmap p, GC gc, int direction)
{
Get the width and height geometry of the original pixmap
create a new pixmap with the width and height filpped.
for (int i = 0; i < width; i++)
for(int j = 0; j < height; j++)
{
int x, y;
if ( direction == - 1) // for counter clock wise rotation
{
x = j;
y = width -1;
}
else // for clock wise rotation
{
x = height - j;
y = i;
}
// copy the pixel at (i, j) of p to (x, y) of pix_return
XCopyArea(display, p, pix_return, gc, i, j, 1,1,x,y);
}
}
return pix_return;
}
}
Vertically Oriented Text
I made a mistake in my algorithm. y = width -1 should be y =width -i;
Vertically Oriented Text
It is useful code nontheless, although I would make two changes
1) I would iterate over the destination data, transforming from the source. This way, if the code ever needs to support rotations other than 90-degree ones, you won`t wind up with holes in the target destination.
2) it is more efficient to retrieve the data as an XImage and to do the transformations as images on the client side, rather than flood the X server with gobs of pixmap copies.
Note, also, that the CTL (Complex Text Layout (?)) extension to Motif 2.0 handles vertical text for the XmText, specifically.
Vertically Oriented Text
I would say you are right. My algorithm is not generic enough for any kind of rotation. What I tried to illustrate here is how simple the mathmatics of a 90 degree rotation operation is. Manipulating XImage data instead of using XCopyArea is really good point. Anyhow, my algorithm should be used only for simple and relatively small pixmap.
I want to do the same thing
I want to do the same thing of rotating the text for y label in x-y graph. I just wonder if there are functions of motif that can be called in the newer versions of motif to do this or still I need to do based on the replies posted to this question ?
Some 3-rd party Motif
Some 3-rd party Motif widgets allow vertical text. For example, if you are using XdtPlotter you can draw the y-axis label vertically.
The're are 2
The're are 2 steps:
.verticaltext{
font: bold 13px Arial;
position: absolute;
right: 3px;
top: 20px;
width: 15px;
writing-mode: tb-rl;
}
and
/***********************************************
* Vertical Text script- © Dynamic Drive DHTML code library (www.dynamicdrive.com)
* Visit http://www.dynamicDrive.com for hundreds of DHTML scripts
* This notice must stay intact for legal use
***********************************************/
//Enter desired vertical text:
var myverticaltext='This page copyright © 1998-2004 Dynamic Drive.'
var bodycache=document.body
if (bodycache && bodycache.currentStyle && bodycache.currentStyle.writingMode)
document.write(myverticaltext)