How to draw circular text

I am trying to create a program to print text in a circle around a current transformer that is 2.5 inches in diameter. Fortunately, there is a flat surface for printing. The only thing I can think of is to use StringShape to rotate each letter a small amount but getting everything positioned correctly looks like a big task.

Windows or Mac?
It’s been a long time but I recall using VB5 to embed WordArt as an OLE object, and it had that functionality built in.
Trying to work out the kerning and the correct amount of rotation, letter by letter, would be a nightmare.

I take it that the text can vary?
If not, you could just create a bitmap once using an online tool, and use that.
eg

I’ve been looking at WordArt in Word. If I can get it to merge in a unique serial number on each one, it may work. It wants to complete the circle and adding spaces at the end doesn’t leave enough room for the logo that needs to be there. Even non-break spaces seem to be ignored. Perhaps I can add some extra text I can edit out later with GIMP then just use the static image and write the serial number in with Xojo. That way up to 40 units can be put the the laser engraver each time.

I looked at the Curved Text generator and found that I can’t change the font size so if I enter too much text, it overwrites earlier text.

I’ve written some Xojo code that addresses part of the problem. If you give me a day or two, I may be able to post something that does what you want.

1 Like

Robert Weaver

I’ve written some Xojo code that addresses part of the problem. If you give me a day or two, I may be able to post something that does what you want.

That would be fabulous. Thank you.

It’s possible to use the graphics translations to draw the text on an angle, it doesn’t curve the actual characters.

The following code translates the context to the center position of each character, rotates the context, draws the character and then resets the context for the next character.

  g.saveState
  g.translate labelMinValue.x, labelMinValue.y
  g.rotate labelMinValue.angle // As a radian
  g.drawtext labelMinValue.caption, 0 - labelMinValue.halfWidth, 0
  g.restoreState

This following function will calculate the X, Y position from a center position, distance from center and angle.

Protected Sub pointFromCenter(centerX as double, centerY as double, distance as double, angle as double, byRef outX as double, byRef outY as double)
  Dim angleV as double = ( 3.14159265358979323846264338327950 / 180 ) * ( angle )
  outX                 = ( distance * cos( angleV ) ) + centerX
  outY                 = ( distance * sin( angleV ) ) + centerY 
End Sub

This function will convert an angle to a radian (used for rotating the graphics context).

Public Function radian(value as double) As double
  return value * 0.01745329251994
End Function

I do it in my app “e.Tampon” which is available for Windows and macOS.
The app runs as demo version without code.
Try it and if it is what you want, I can isolate the code to draw circular text.

1 Like

https://documentation.xojo.com/versions/2022r2/api/graphics/textshape.html

?

a.k.a. Object2D’s TextShape.
https://docs.xojo.com/TextShape

Worked fine when I used it two or thee years ago.

Nota: I had hard time finding it in the Documentation.

1 Like

Eric Pousse

I do it in my app “e.Tampon ” which is available for Windows and macOS.
The app runs as demo version without code.
Try it and if it is what you want, I can isolate the code to draw circular text

This is exactly what I want to do. Some sample code would be very helpful. The docs for TextShape include ArcShape without any explanation of how to use them together.

hello,
an old example of text in a circle

https://www.dropbox.com/s/ai9l9mxz37fqz11/Text-im-Kreis.xojo_binary_project?dl=1

Here is an example

There is perhaps some extra code which could be deleted.

1 Like

Eric Pousse
Here is an example

There is perhaps some extra code which could be deleted

Perfect! Exactly what I needed. Thank you you Eric And thanks to everyone else you replied.