steve@wizard.UUCP (Steve Mansour) (06/24/89)
Hello, I am working on some code that will require rotating, reflecting, and scaling text for drawings. Rotations of 90, 180, and 270 degrees are required, arbitrary rotation angles are desired. There are no specific font requirements, so vector text is OK, but arbitrary font support is desired. I would like to know if anyone has done rotated (and/or reflected) text with X. If so, how fast is it? Any special fonts, etc? Any hints or suggestions as to how this might be done and how to make it fast would be appreciated. Any sample code would be greatly appreciated. Steve Mansour
stergios@Jessica.stanford.edu (stergios marinopoulos) (06/25/89)
Print text to a pixmap, grab the image, rotate it, send it back over the wire. Here is how to rotate a bitmap image. Simply iterate over the origonal and apply the rotation tranformation for each pixel. unsigned char image[WIDTH][HEIGHT]; rotate(angle) double angle; /* rotate image 'angle' degrees */ { int color; int xx,yy; for(y = 0;y < HEIGHT; y ++) for(x = 0;x < WIDTH; x ++) { color = image[xx][yy]; xx = x * cos(angle) - y * sin(angle); yy = x * sin(angle) + y * cos(angle); setpixel(xx,yy,color); } } This method will leave "holes" in the rotated image since there is no strict mapping of integral values between arbitary coordinate systems. This algorithm can be generalized and improved (eliminating the `holes') quite easily; simply iterate over the output points rather than the input points. Thus, for (P = each point in the output) { P2 = TRANSFORM(P) ; /* can include rotations, scaling, etc */ setpixel(destination, P, getpixel(source, P2)) ; } TRANSFORM is the usual six-element matrix, that rounds the point after it's done. The resulting bitmap won't be beautiful. Better results can often be obtained by interpolating between source pixels. For instance, if the unrounded transformed result was (2.3, 4.6), then a better looking image might be obtained by using .3[.6[g(2,4),g(2,5)],.6[g(3,4),g(3,5)]] where n[a,b] means ((1-n) * a + n * b) and g(x,y) means the value of the source at pixel (x,y). The image may be more `blurry' this way, though . . . If you are scaling up (to more bits), this type of interpolation is probably not a bad idea. If you are scaling down (to less bits), it can give odd effects; you might want to high-pass filter the image before scaling it down. A lot of the good info above comes from Tom Rokicki (rokicki@polya.stanford.edu) sm stergios@jessica.stanford.edu
rbj@DSYS.NCSL.NIST.GOV (Root Boy Jim) (06/26/89)
? Print text to a pixmap, grab the image, rotate it, send it back over ? the wire. ? Here is how to rotate a bitmap image. Simply iterate over the origonal ? and apply the rotation tranformation for each pixel. [code deleted] You may want to consider using a more general transformation matrix as PostScript does, to rotate, scale, and translate all in one operation. ? stergios@jessica.stanford.edu Root Boy Jim is what I am Are you what you are or what?