|
-
July 13th, 2005, 03:22 PM
#1
text above any line
Hi
Does anybody know how can I draw a text above any arbitrary line?
I have only line coordinates and its angle and I want to draw the text centered in the middle of the line and above it.
Thanks.
-
July 13th, 2005, 04:28 PM
#2
Re: text above any line
You'll have to be much clearer as to what you're doing. For instance, what are you using to render text? Windows API functions? And when you say that you have the line's "angle," do you mean that you want to draw text at the same slope as the line?
-
July 13th, 2005, 04:51 PM
#3
Re: text above any line
In order to write some text with an angle, you take advantage of the "nEscapement" argument in the "CreateFont" API (don't use the "nOrientation" argument). Here is an example:
Code:
HFONT hfont, hfont_old;
char buf[200]; int angle;
strcpy(buf, "This is a test");
// Draw line with a slope of 45 degrees
MoveToEx(hdc, 10, 20, NULL);
LineTo(hdc, 110, 120);
// Create a font with letters having an angle
angle = 3150; // (360 minus 45 degrees) * 10
hfont = CreateFont(12, 0, angle, 0, FW_NORMAL,
0, 0, 0, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS,
CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, FF_DONTCARE, "Arial");
hfont_old = (HFONT) SelectObject(hdc, hfont);
// Draw Text above the line
SetTextAlign(hdc, TA_CENTER | TA_BOTTOM); // The reference point will be aligned horizontally with the center and the bottom of the bounding rectangle
TextOut(hdc, (110 - 10) / 2 + 10, (120 - 20) / 2 + 20, buf, strlen(buf)); // x and y are chosen to be on the middle of the line
// Remove the font
SelectObject(hdc, hfont_old);
DeleteObject(hfont);
-
July 14th, 2005, 05:40 PM
#4
Re: text above any line
Thanks a lot.
It helped me much.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|