Forum > Graphics
[Solved] Centering of rotated text on Canvas !
(1/1)
loaded:
Hi All,
I have a method that prints the distance and angle information of the line on the midpoint of the lines. It was working until now. I wanted to retouch the method and give it a slightly nicer look.
But if I want to rotate the texts and print them as they are, there is no problem.
But if I want to rotate it and center its position so that it is in the middle of the line, an offset occurs according to the angle.
I'm probably making a calculation error.
I also need to multiply by 10 when passing the angle of rotation to the font method. What could be the reason for this?
Before I dwell on the subject in detail, I would like to benefit from your experiences.
Respects.
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---procedure TForm1.Button1Click(Sender: TObject);begin with image1.canvas do begin Brush.Color:=clBlack; Brush.Style:=bsClear; FillRect(ClipRect); pen.Color:=clGreen; Line(181,122,520,122); pen.Color:=clblue; Ellipse(340,117,350,127); //center font.Orientation:=0; font.Color:=clSkyBlue;TextOut(345-round(GetTextWidth('0.0000')/2),122,'0.0000'); // Rotated text pen.Color:=clGreen; Line(181,122,287,407); pen.Color:=clYellow; Ellipse(229,260,239,270); //center font.Orientation:=round(290.40167*10); font.Color:=clSkyBlue; TextOut(234-round(GetTextWidth('290.40167')/2),265,'290.40167'); end;end;
wp:
Basically, text drawing in the LCL always starts at the top/left corner of the text, even for rotated text. Therefore, you need a rotation procedure to calculate the position of the top/left corner after rotation around the rotation center. Just study the attached sample project which rotates horizontally and vertically aligned text around the paintbox center by an arbitrary angle.
Note that Windows at least seems to displace the text vertically when the text angle is neither horizontal nor vertical. It should be possible to correct this by means of some of the TextMetric parameters. But I did not want to go through this detail.
loaded:
Thank you very much for your reply wp. You have been a great help as always in solving my problem. Respects.
Navigation
[0] Message Index