Rotating Text in Small Area

About Box Prob
This is a desktop problem and I think PC. This is also the only time I have drawn text on a Canvas.
Above the Telephone is a T on this image.
The T is in a canvas with a box drawn around it.
The above About Box is on a Mac, but on my PC it is somewhere off to the side.
What could be causing this?

The below is the code

Dim ss As New TextShape

ss.Value = "T"
ss.FontName = DispFont
ss.FontSize = 25

ss.HorizontalAlignment = TextShape.Alignment.Center
ss.VerticalAlignment = TextShape.Alignment.Center

ss.Rotation = 3.14159
g.DrawingColor = CBLck
g.DrawRectangle( 0, 0, 40, 40 )
g.DrawingColor = CBLck
g.DrawObject(ss, g.Width \ 2, g.Height \ 2)

Make sure the DrawingColor is what you think it is.

Only other thing I can think of is that the font can’t be drawn into a vector object. Try another one.

I checked the font and it works, but something else is the problem.
Also the color is black.

This is the T rotated only 2 radians
About Box 2 Radians

You can see the bottom of the T off to the right.

I don’t understand but I need for X and Y -20. If I put an x and y in it works on the PC.

ss.X = -20
ss.Y = -20

And yes, for the Mac, the T is off in some other place.

So I wonder what the actual X and Y 0 (zero) points are.

TextShape on Windows does not rotate around correct center-point

If you are using 2021r1 or newer you can rotate the entire canvas, so you can invert the T by first drawing it and then rotating the canvas: Graphics.Rotate - Xojo Documentation

Hi Arthur,
I’ve rtied your code Aand it gave me something wird. The upside down T was off my canvas.
So i have tied to do it in my code and this is what i came up with:
//draw your rectangle
g.DrawingColor = &c000000
g.DrawRectangle( 0, 0, 40, 40 )

//Upside Down T
g.DrawingColor = &c000000
g.FontSize = 25
g.DrawText(“T”, -26, -11)

the -26 and the -11 are the mirrored X and Y axes because your T needs to be
upside down.
Hope it helps.

This message was left on Feedback and I can share as it is marked everyone. The project is on the hyperlink.
Robin Lauryssen-Mitchell

April 19, 2021 - 9:19am UTC

For Aruther,
A lightly modified version of your sample project.
Just to make it a little easier to see what is going on.
Also see the ‘Graphics and Multimedia’ example project ‘Obj2DTextRotation.xojo_binary_project’.

Hi Arthur,
I know that rotation isn’t centered as that example shows.I had that problem too. I though you wanted an upside down T.If you want to know what the problem is with the example you let me downloaded, it doesn’t recalculate the center of the T to the canvas.
Recalulate the position of the chr T and keep it to the center of the canvas.

Here’s the file I uploaded. It’s without stuff like what Robin added.

You can test it on Mac and PC and Linux if you like.

i would say it is a bug in the Rotation. it came after update from 2020r21 to 2021r1
put your canvas left,top at 0,0 it looks good.
use a rotate property and a timer and add + 0.0174533 to Rotation
then use invalidate you can follow the T :wink:
if your canvas is in the middle of the screen it goes wrong.


Clockwise rotation, in radians, around the X, Y point. Only set the rotation after you have drawn all your objects.

what ever this means: “Only set the rotation after you have drawn all your objects.”

me used 2021r1 at windows 10 and it looks not correct in this version.

Sub Paint(g As Graphics, areas() As REALbasic.Rect) Handles Paint
  Dim ss As New TextShape
  ss.Value = "T"
  ss.FontName = "Arial"
  ss.FontSize = 25
  ss.X = 0
  ss.Y = 0
  ss.HorizontalAlignment = TextShape.Alignment.Center
  ss.VerticalAlignment = TextShape.Alignment.Center
  ss.Rotation = Self.Rotate ' 3.14159
  Self.Rotate = Self.Rotate + 0.0174533
  g.DrawingColor = Color.Black
  g.DrawRectangle( 0.0, 0.0, g.Width, g.Height )
  g.DrawingColor = Color.Black
  g.DrawObject(ss, g.Width / 2.0, g.Height / 2.0)
End Sub

I didn’t see the upside down T.
I have adjusted that code and this is what i came up with:

use the open event of the canvas:
var ss As New TextShape
var myPicture As picture

ss.FillColor = &c000000

ss.Value = “T”
ss.FontName = “Arial”
ss.FontSize = 25

ss.Rotation = 3.14159

myPicture = New Picture(40, 40)
myPicture.Graphics.DrawObject(ss, 20, 10)

me.Backdrop = myPicture


In the paint you draw the border of your canvas.
I got an upside down T.

before it rotate around the center


Thanks. I was trying to figure out the takeaway and what was important about Object2D.Rotation.

I am not sure how that would be different. How?

I don’t understand but I need for X and Y -20. If I put an x and y in it works on the PC.

if me set the canvas to the top,left edge of the window it rotates correct.
that does not solve your problem but you can see what happens.
i think the problem came because now we can rotate the graphics too.
there must be any changes in xojo framework.
the math just go wrong.

should be fixed in next release :grinning:

1 Like
Forum for Xojo Programming Language and IDE. Copyright © 2021 Xojo, Inc.